[infinispan-dev] Protostream marshaller support for optional fields
Adrian Nistor
anistor at redhat.com
Tue Oct 24 07:43:38 EDT 2017
Hi Galder,
There's nothing special about optional fields. It is the required fields
that are special: they do not allow null (in the read/write methods).
If a field is optional in your protobuf schema you can write a null
value and protostream will happily interpret that as a missing value and
will not write any tag in the output protobuf stream.
Reading a missing value will return a null. The required/optional status
of a field is checked against the schema at runtime, so you cannot cheat :).
None of the above holds true for a required field. Writes will only
accept non-nulls (an exception is thrown immediately). Reads will always
return a non-null value, so you can safely use a
primitive-type-returning read method. If the input stream does not
contain a required field (probably because the encoder that produced it
was violating the schema) an exception is thrown.
Adrian
On 10/23/2017 06:51 PM, Galder Zamarreño wrote:
> Hey Adrian,
>
> Quick q: how is a protostream marshaller supposed to deal with optional fields?
>
> I don't see any writer methods that deal with those... is it up to the user to put something on the wire to decide at read time whether the optional field follows or not?
>
> Cheers,
> --
> Galder Zamarreño
> Infinispan, Red Hat
>
More information about the infinispan-dev
mailing list