Compact API improvements
These additions have all been proposed or suggested or weakly asked for.
-
Adding a
pad_tag
/spoil_tag_bits
/we. The idea being to be able to reserve tags for future uses or align on half-byte boundaries or what have you. Currently you can make a 1 element union and use the additional parameters to achieve the same effect. It'd be nicer to havewith_hollow_tag_bits : int -> 'a t -> 'a t
. -
Adding
conv_with_guard
andwith_decoding_gurad
combinators. See !70 (comment 852675568) -
Adding an ultra compact list where the small tags of consecutive running elements are bundled togther. So essentially, considering
type u
and compact encodingu_c : u t
which uses 2 bits of tag, then a list[u0;u1;u2;u3;u4;u5;u6]
would be encoded asONE_BYTE_TAG_FOR(u0–u3) . u0 . u1 . u2. u3 . ONE_BYTE_TAG_FOR(u4–u6) . u4 . u5 . u6
and the second tag would have two meaningless bits. -
Adding an
array
combinator mimicking thelist
one but for compacts. (Currently,conv
+list
works.) -
Making some of the optional parameters (e.g.,
make
'stag_size
) non-optional. These are important to get right and it might be better to force the user to specify them.Alternatively, @mbouaziz suggests to make some even more optional (in that a default wouldn't be needed and that an
`Auto
variant could be used instead). See !70 (comment 855131547) -
Making several int32 compact encodings with several splits of the int32 space (or possibly, add a parameter to chose the splitting). The current scheme is
0–255
(uint8),256–65???
(uint16),the rest
(int32). But we could do-128–127
(int8),-33???–33???
(int16), the rest. We could even use a tag for 3-bytes int32s.Similarly, the int64 encoding could be given multiple variants. Including, one that uses 3 bits of tag? See !70 (comment 854441602)
-
Allow the
list
combinator to specify thekind
of itsdynamic_size
case. More specifically, we should replaceEncoding.list e
byEncoding.(dynamic_size ?kind (Variable.list e)
and passkind
as parameter to the combinator. The same change could be made the theEncoding
module, also forarray
. -
Support sub-byte int sizes which are stored in the shared tag. Something along the lines of
val tiny_int: bits:int -> int t
which usesbits
bits of tag and 0 bytes outside. Alsoval tiny_uint: bits:int -> int t
. See !70 (comment 854441618) -
Bounded bytes with bound dispatch. As per tezos/tezos!4509 (merged) we could have a compact union (two bits of tag) of bytes which are distinguished by bounds so that the different bounds fit in different integer sizes.
-
Adding a
?max_length
parameter toCompact.list
which- Avoids generating the
Long_list
case if not needed. SoList ~bits:2 e
has tags for length0, length1, length2, length+, butList ~bits:2 ?max_length:3
has tags for length0, length1, length2, length3. - Adds dynamic checks like those of vanilla Data_encoding.
- Avoids generating the