evanw/pbjs

Default values

ricardobeat opened this issue · 0 comments

Hi! The readme for this project states that

this library doesn't write out default values. This makes it possible to tell if a field has been written at all or not, which allows for efficient encoding of maps

My understanding is that the protocol itself makes this impossible, as default values will not be sent over the wire at all [1]:

for scalar message fields, once a message is parsed there's no way of telling whether a field was explicitly set to the default value (for example whether a boolean was set to false) or just not set at all: you should bear this in mind when defining your message types

How is this possible in this library?

[1] https://developers.google.com/protocol-buffers/docs/proto3#default