Add constraints to the grammar
This is a proposal to add constraints to fields of protocol messages. The generated encoders and decoders would make sure the constraints are met.
Just to get a discussion going, one possible syntax would be to follow an item with
:: followed by a comma-separated list of constraints. Different types would have different constraints. The
optional keyword would be moved into the constraint grammar.
||all||Marks the field as optional|
||int, double||Restricts the range of the integer or double. Only one range can be specified for a field.|
|string, array, binary||Restricts the size of the string/array/binary. The range can be omitted and a single number used to fix the size.|
The various integer types would go away and we would only have
int (with appropriate constraints to emulate the removed types.) We could add a
type keyword to define aliases and then pre-define a few, like:
type int16 = int :: -32768 .. 32767; type uint16 = int :: 0 .. 65535;