Skip to content

[nodes] Support bit granularity in type nodes #93

@lorisleiva

Description

@lorisleiva

This is a proposal that needs further discussion before implementing.


Currently, the smallest granularity that Codama supports when it comes to type definition is one byte.

However, there may be cases were, within a byte, some bits are being used for different things. For instance, a byte could be used to store 8 booleans using bit flags.

There are several ways we could achieve this.

From one end of the spectrum, we could analyse the concrete use-cases where such thing would be needed and offer specific type nodes from them. For instance, a BitFlagTypeNode could represent an array or struct of booleans such that each boolean is store in a single bit.

On the other end of the spectrum, we could reduce the overall number granularity supported by Codama by adding number formats such as u1, u2, etc. This makes the whole type system a lot more flexible as we can now construct things like bit flats using TupleTypeNodes or even StructTypeNodes if we wanted them to be named. The issue with the approach is we now need to handle bit-granularity at every level (Codecs for JS, custom types for Rust, etc.) and ensure we do not end up with incomplete bytes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalSuggesting a change / new featurev2Something to look into when updating the Codama standard to v2

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions