I believe you can concatenate two (serialized) messages together, 
yielding a message with all the fields from both messages.

So if all your fields are optional, you could create one instance of 
your message with just the fields common to both clients, and another 
instance with just the fields you want to send to client 2.  Serialize 
both instances, send instance 1 to client 1, and send the concatenation 
of instance 1 and instance 2 to client 2.

That way, there's no double serialization, and each client only gets the 
fields you want to send to them.

Jeremy Leader

edan wrote:
> I have kind of a funny requirement that I was hoping protobuf might 
> support in an elegant fashion:
> I have a message that I want to sent to 2 different clients.  They want 
> mostly the same stuff, but there are a few fields that can be fairly 
> large, that I only want to send to one of the clients, and spare the 
> work of passing on the wire and deserializing for the other client that 
> doesn't want them.
> Is there a way to define the fields in the .proto or change 
> serialization such that I don't serialize those fields for the client 
> that isn't interested in them?  I know I can clear the fields myself 
> after serializing for the first client, and then serialize again, but 
> this has disadvantages of double-serialization (which I could live with) 
> but also requires going through the message (some of the fields are on 
> repeated sub-messages) using iterators and clearing fields, so it's a 
> little messy.  I was hoping there is a prettier way?  Any help is 
> appreciated.
> --edan

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to