I tried YourProtocolMessage.getDefaultInstance() and as you said it is
of zero byte size. I've a required field called ID with default cluase
in pnroto file (with default value set to -1). When i send the default
instance, I see ID set to -1 (which is default value specified in
proto file) but on the client side while parsing it says required
field ID is not initialized. It looks like if we specify required
field in proto file then we can't return default instance. Then i
tried creating a proto message with -1 value in ID and as you said it
doesn't much cost. On the client side if ID is -1 then i assume it's a
null response.

Thanks for your response.

Regards,
Prakash

On Aug 16, 8:46 pm, Evan Jones <ev...@mit.edu> wrote:
> On Aug 16, 2010, at 10:56 , Prakash Rao wrote:
>
> > I'm just looking for a easy way to write null response if data is not
> > present in DB and write proto message object if data is present &
> > parse these in client side appropriately. I didn't get a easy way to
> > do this using CodedInputStream. Currently i'm creating a empty proto
> > object on server side and checking for key attribute at client side as
> > stated above.
>
> The "empty" protocol buffer message serializes to zero bytes, so if  
> your message has no content, you could just send a zero byte message.  
> This would avoid creating a protocol buffer message. However, I  
> suspect that isn't really a big overhead. You can also use  
> YourProtocolMessage.getDefaultInstance() to avoid creating a message.
>
> Hope this helps,
>
> Evan Jones
>
> --
> Evan Joneshttp://evanjones.ca/

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to