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

Feat(util): offsetOf and offsetOfPacked utility functions #51

Open
MierenManz opened this issue Feb 3, 2025 · 0 comments
Open

Feat(util): offsetOf and offsetOfPacked utility functions #51

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

Comments

@MierenManz
Copy link
Collaborator

NeKzor

a util like offsetOf would be useful so I can remove my current hack.

MierenManz

@NeKzor What is your current hack and what should offsetOf do? I assume it's something like this?

const codec = new SizedStruct({ byte: u8, word: u16 });
console.log(offsetOf(codec)) // Logs `{ aligned: 4, packed: 3 }`

NeKzor

I better not post my hack because I implemented it incorrectly lol
It would get the offset of a field inside a struct inspired by C++ and Rust. Something like this:

offsetOf({ byte: u8, word: u32le }, 'word'); // 4
offsetOfPacked({ byte: u8, word: u32le }, 'word'); // 1
@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
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