near / borsh-rs

Rust implementation of Binary Object Representation Serializer for Hashing
https://borsh.io/
Apache License 2.0
299 stars 65 forks source link

feat!: add `length_width` to `schema::Definition::Sequence` #229

Closed mina86 closed 11 months ago

mina86 commented 11 months ago

Add Definition::Sequence::length_width field which allows specifying the width of the length tag for dynamically-sized arrays. This allows defining custom schema where length is, say, one-byte.

Furthermore, support length_width being zero which indicates untagged sequences. Use that as a new way to describe a fixed-length arrays thus making Definition::Array no longer necessary.

Lastly, zero length_width with length range which is more than just one value allows to document a custom encoding which cannot be fully specified with the schema.

resolves #211 (VarInt and SmallVec<T>)

dj8yfo commented 11 months ago

Duplicate of #228

dj8yfo commented 11 months ago

@mina86, can you make #229 identical in content (with respect to code and tests, modify doc freely) to #228? We'll then merge #229.