duplicate field is sent for an optional field

87 views
Skip to first unread message

itay perry

unread,
Nov 11, 2020, 2:36:19 AM11/11/20
to Protocol Buffers
I understand that using parsefromArray or parseFromString, and the field is not duplicated I get only the last value. 
is there a way to get all values, or at least know that multiple values were sent ? 

thanks 

Nadav Samet

unread,
Nov 11, 2020, 11:44:01 AM11/11/20
to itay perry, Protocol Buffers
Hi Itay, I am not aware of a straightforward way, but I can think of two ways to accomplish that. I've used the first one for testing purposes.

1. Create a new message definition that is identical to the original, but where the optional field is changed to repeated. Thanks to binary representation compatibility, all messages that conform to the original schema, will be accepted by the new schema, and you'll get all the repeated fields instead of only the last value.
2. If the field is a top level field, you can use CodedInputStream to parse the bytes and look for a tag number that repeats twice.

-Nadav

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/a0bed358-3d16-4f28-806c-b2e82091fb21n%40googlegroups.com.


--
-Nadav
Reply all
Reply to author
Forward
0 new messages