--
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 protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Going from proto3 to proto2 should be fine. There are some slight differences but I can't think of any major problems. The only thing that comes to mind is that proto2 handles unknown enum values a little bit differently from proto3. I doubt that would be a problem but if you want to be extra cautious you could double-check that you're not storing any unknown enum values.However, there is no need to downgrade to version 2.6.1 and if anything that would only introduce bugs and make the code slower. The proto2 semantics are still fully supported in all versions going forward, so all you have to do is put syntax = "proto2"; at the top of your .proto files. You can stick with 3.6.1 or even upgrade to any newer version.On Thu, Mar 14, 2019 at 10:21 AM Jason Huang <jasonhu...@gmail.com> wrote:i chose proto3 for cache (serialize) for my application , and it have run for several month . but now i wanna change my mind for proto2 , because the hasField is really needed .the problem is , there're still lots of data in the cache which are serialized with proto3 , if i can't deserialize with them with proto2 . it will be unacceptable .
Not exactly, by unknown enum value I mean an enum value that doesn't appear in the enum definition. For example let's say your enum has only values 0, 1, and 2 but you parse a 3. This could happen if the message was serialized by another binary using a newer version of the schema. Proto2 will store unknown enum values in the unknown field set whereas proto3 will just store them normally in the field.
Oh, I am talking about the binary format in particular. In that scenario it's important for unknown enum values to be handled in some way, since you might want to add a new enum value but it should still be parseable by older binaries.
That is true, in proto2 the default value of an enum field is the first value. But the behavior is more confusing than one might expect. Let's say the only enum values declared are 0, 1, and 2 but you parse a 3 from the wire. If you examine that field it will appear to be empty and you can read it to get the default value (0 in this case assuming that was the first value defined). But the 3 is still there, hidden in the unknown field set. Once you reserialize the proto, the 3 will be serialized again. Worse still, since unknown fields are serialized after known fields (that's not a requirement but typically happens in practice), the unknown enum value can overwrite a change that your code tried to make. This is why proto3 changed things so that unknown enum values are stored normally instead of in the unknown field set, and this makes it much easier to reason about.