Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sugarcoat for constructing compound types #50

Open
MierenManz opened this issue Feb 3, 2025 · 1 comment
Open

Sugarcoat for constructing compound types #50

MierenManz opened this issue Feb 3, 2025 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@MierenManz
Copy link
Collaborator

Copied from From #45

NeKzor

I have another idea for declaring sized arrays. How about mapping a tuple to SizedArrayType/ArrayType or maybe even TypedArray?
Here is an example:

new Struct({
    foo: [u8, 100], // length 100
});

MierenManz

I've considered stuff like this in the past and eventho I really like how much cleaner it is compared to new SizedArrayType(u8, 100). I am conflicted if this magic is something we should want for the library.

MierenManz

Maybe this is something we could do with decorators so that the magic spaghetti for it would be in a optional decorator somehow?

@MierenManz MierenManz added enhancement New feature or request help wanted Extra attention is needed labels Feb 3, 2025
@MierenManz MierenManz mentioned this issue Feb 3, 2025
@MierenManz
Copy link
Collaborator Author

I've been playing around with this but it seems like there are the following issue's we would need to sort out.

  1. Array's and Struct's are easy to do. They're essentially objects and arrays in js which we can easily convert. The problem comes when we start looking at BitFlags, Tuple, Union and TaggedUnion types. These also use objects or arrays as descriptor which means it is not safe to directly map a js object to a Struct type or a js array to ArrayType

  2. There are also complex types that do not have a js equivalent to describe them like PrefixedString(lengthCodec) & FixedLengthString(len). These don't have descriptors and are described by constructing specific instances.

  3. This will likely always incur a performance hit when constructing any object, with the sugarcoat or not, because we still have to detect the sugarcoat.

Until we can solve 1 and 2 (and hopefully 3 aswell) I don't think it should be implemented in byte type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant