Are you using syntax = "proto3" in your file? I believe the docs state that proto3 does not require unknown fields to be preserved when a message is de-serialized and re-serialized. So this behavior, IIRC, only works for messages generated from proto2 files.
---- *Josh Humphries* [email protected] On Sun, Mar 5, 2017 at 2:10 PM, jkg589ih <[email protected]> wrote: > Hi, > > Developers guide says: > > "Messages created by your new code can be parsed by your old code: old > binaries simply ignore the new field when parsing. However, the unknown > fields are not discarded, and if the message is later serialized, the > unknown fields are serialized along with it – so if the message is passed > on to new code, the new fields are still available." > > > I'm interested in exactly this scenario - old client gets a message from > the new client, changes something, and sends it back. > > I gave it a try, and what I saw is that new proto fields are stored in > unknownFields. But when I do build(), these fields are discarded. > > So when the message is serialized, the new fields are gone. Am I doing it > wrong ? > > > I found that I could simply serialize the message, and then separately > serialize the unknownFieldSet, so they are concatenated to the message. > > But this doesn't feel like the right way. Is it ? > > > I also found this: https://github.com/bivas/protobuf-java-format/pull/26, > but last activity was a year ago. > > > What's the right way of having the old client serialize a message > including fields it doesn't understand ? > > > Thanks, > > Alex > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/protobuf. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
