Skip to content

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

@MierenManz

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions