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

Consider using Typed Binary schemas for describing packets #41

Open
mkapal opened this issue May 8, 2024 · 1 comment
Open

Consider using Typed Binary schemas for describing packets #41

mkapal opened this issue May 8, 2024 · 1 comment
Labels

Comments

@mkapal
Copy link
Member

mkapal commented May 8, 2024

As of now, every packet has its properties annotated by decorators according to their binary representation. For instance, an 8-bit unsigned integer is represented by the @byte() decorator. Each decorator holds a unique character which is then used when packing or unpacking binary data.

The downsides of this approach is that there is a lot of "magic" code inside the base Struct and Packet classes and several as typecasts, making the code less readable and maintainable.

The idea is to define a schema for each packet and have the type definition inferred from the schema. This can be done using the Typed Binary library: https://github.com/iwoplaza/typed-binary

It includes several binary schema types, a buffer writer and a reader to pack/unpack binary data into the schema structure.

So far it lacks all ArrayBuffer binary types like 16-bit integers or an unsigned 32-bit float. I've created an issue for it: iwoplaza/typed-binary#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant