BrewPi / firmware

Brewing temperature control firmware for the BrewPi Spark (Particle Photon inside)
http://www.brewpi.com
GNU Affero General Public License v3.0
97 stars 55 forks source link

Sparse data implementation for protobuf is not compatible with protobufs omission of default values #83

Closed elcojacobs closed 6 years ago

elcojacobs commented 6 years ago

The protobuf spec defines that default values are omitted from a message: if the receiver does not receive a value, it is assumed to be default.

I implemented sparse updates by only overwriting values in the object that are present in the message, but this is wrong. In the protobuf spec, there is no way to distinguish an omitted member from a member that is set to its default value.

A possible workaround is to set the default value to something outside of the normal data range. This complicates the design because:

To update a single nested value the client can read the object, change a value and write the object back.

A future implementation to support sparse updates in a way that is compatible with the protobuf spec is to include a field mask in the message. The field mask, when present, indicates which values should be copied from the message.