You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Given
Country country = Country.newBuilder()
.setName("Argentina")
.build();
Exchange exchange = Exchange.newBuilder()
.setCountry1(country)
.setCountry2(country)
.build();
//When
byte[] bytes = exchange.toByteArray();
//Then
Exchange exchange1 = Exchange.parseFrom(bytes);
Country country1 = exchange1.getCountry1();
Country country2 = exchange1.getCountry2();
assertThat(country1, sameInstance(country2));
It would be nice if that assertion was true, unfortunatelly it isn't, I wonder why if I set the same nested message several times the serializer doesn't use a pointer to avoid wasting bytes (every time that I add a reference to the country, the resulting byte[] is bigger by the size of the serialized country +2, what I guess is the serialized field number) into the wire and also maintain identity after deserialize.
The text was updated successfully, but these errors were encountered:
Protobuf wire format is very simple (see: https://developers.google.com/protocol-buffers/docs/encoding) and does not support cross links. There is no plan to change the wire format as it breaks compatibility. For your use case if you really want to save a few bytes, you can serialize the county messages in a separate repeated field and make the Exchange message store indices into that repeated field.
Given the following unit test
It would be nice if that assertion was true, unfortunatelly it isn't, I wonder why if I set the same nested message several times the serializer doesn't use a pointer to avoid wasting bytes (every time that I add a reference to the country, the resulting byte[] is bigger by the size of the serialized country +2, what I guess is the serialized field number) into the wire and also maintain identity after deserialize.
The text was updated successfully, but these errors were encountered: