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

Add aligned byteorder types #254

Open
joshlf opened this issue Aug 13, 2023 · 0 comments
Open

Add aligned byteorder types #254

joshlf opened this issue Aug 13, 2023 · 0 comments
Labels
compatibility-breaking Changes that are (likely to be) breaking

Comments

@joshlf
Copy link
Member

joshlf commented Aug 13, 2023

Any design for this issue will interact with other issues tracked by #885; make sure to read that issue when tackling this one.

All of the types in the byteorder module have no alignment requirement since they were designed for packet parsing, where values may appear at any alignment. For some applications, it's still useful to support byte-order conversion, but in a context in which alignment is guaranteed. In these cases, being able to guarantee alignment can result in faster and smaller code on some platforms. We should consider adding types which are like the existing ones, but have the same alignment as their native equivalents. Alternatively, we could modify the existing types to support both alignment modes.

Another thing to consider is that, currently, the byteorder module conflates alignment concerns and byteorder concerns. These happen to often be relevant at the same time (e.g. in the context of packet parsing), but they are conceptually distinct. Now that we have the Unalign type, the unaligned property is arguably unnecessary - we could just provide a) byte order-aware types, b) the Unalign type and, perhaps, c) convenience type aliases for unaligned byte order-aware types (e.g., type Foo<O> = Unalign<U32<O>>). We would need to think about how to avoid the combinatorial explosion of the following dimensions:

  • The type itself (U8, U16, etc)
  • Byte order (big endian, little endian, and maybe also network endian and native endian if we're concerned with aliases)
  • Alignment ("normal" vs wrapped in Unalign)
@joshlf joshlf added the compatibility-breaking Changes that are (likely to be) breaking label Aug 13, 2023
@joshlf joshlf mentioned this issue Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-breaking Changes that are (likely to be) breaking
Projects
None yet
Development

No branches or pull requests

1 participant