Hey!
Can someone from protobuf team explain to me the rationale behind the Java code for string fields processing produced by protoc? Protoc generates Java *Object* field for each proto string field and protobuf uses it to store either *ByteString* or *java.util.String* (dunno why). Also each string field gets two accessor methods: *getXxx* for *String* and *getXxxBytes* for *ByteString.* The suspicious part begins inside generated methods *getSerializedSize* and *writeTo.* For both of these methods *getXxxBytes* will be called disregarding the current type of an instance stored in *Object* field which leads to unnecessary *ByteString* allocation when actual type is *java.util.String* (and this is the common case from my perspective). It looks even more peculiar if we will take into account the fact that in both methods we may see a usage of dual-type-aware *GeneratedMessageV3.writeString*/*GeneratedMessageV3.computeStringSize* literally in the next line after *getXxxBytes* calls. Is it a bug or an intentional decision? Recently, I've opened an issue on github <https://github.com/protocolbuffers/protobuf/issues/6719>, but did not get any comments so far. -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/5e80c22f-e13b-45be-8ecd-f75a7a870d38%40googlegroups.com.
