-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Currently the standard is pretty open on how the payload can be encoded and provides the meta section for handling the sections encoded at different offsets and sizes. While this allows it to work with a variety of different systems and implementations, I think it would be beneficial if there also was a canonical representation for the payload (meaning the same data always produces the same payload).
At the very least it would make it easy to share a test suite of canonical data between implementations that could be validated, but would also make it easier to allow for payloads to be signed and shared.
This wouldn't have to come at the expense of the current non-canonical representation, it could just be a separate set of restrictions listed in addition that are required to make the encoded payload canonical and implementors could choose whether they want to make a canonical encoder or not.
Reading the spec I can think of the following restrictions being needed to make it canonical.
- The meta section is always an empty map
- The encoding is always meta, main, aux (the current spec doesn't restrict you from having it be meta, aux, main).
- Keys in maps must be in ascending order.
enum_arraymust encode the values in ascending order.color_rgbamust always be encoded in 4 bytes with RGBA.- byte strings should be defined as always one kind (definite or indefinite).
number types is probably the trickiest with the current spec because it allows for all possible kinds of numbers. I honestly think it would be more useful if number was split up into three types (signed, unsigned, real) because it's not particularly useful for example that fields like filament_diameter or the weight fields can be negative and be considered valid tags but that's probably a separate issue.
Number could be made canonical with following rules
- All positive integers must be encoded as unsigned integers
- All negative integers must be encoded as signed integers
- All real numbers within ±65,504 must be encoded as half floats.
- All real numbers exceeding ±65,504 must be encoded as floats.