Consider adding a tagless boolean encoding #331
Labels
minor-tweaks
Small changes that might be considered before finalizing 1.1 spec, time permitting.
specification 1.1
Ion 1.1 specification work
Tagless encodings help to minimize the space for encoding the arguments to an e-expression. The tagless types in the spec right now focus on encoding values that have an opcode followed by additional data. However, I think boolean values represent an opportunity as well.
Assuming that we can create a macro-shaped parameter using a macro that itself has no parameters, here is an example of how one could create a 2-bit representation of a boolean value.
And then one could invoke this macro in text and binary, respectively:
The text representation is not very human-friendly because we are abusing the absence/presence of an argument to indicate whether the value should be true or false. In binary, we get 4 arguments represented in only 1 byte (via the argument encoding bitmap).
We should consider adding an official, non-hacky way for users to achieve this. Perhaps we could define a special tagless type called
bool_flag
that can only be used with?
or!
cardinalities. Then, in text, it can accepttrue
andfalse
, and in binary, it can be encoded using the argument encoding bits:If #330 is adopted, then we could instead say that
bool_flag
parameters must always be!
and we can simply use0
forfalse
and1
fortrue
, which is a truly minimal encoding for boolean values.The text was updated successfully, but these errors were encountered: