Skip to content

Make bitser endian safe #36

@gvx

Description

@gvx

Currently, bitser implicitly expects data to be deserialized on a computer with the same endianness as the computer that data was serialized on. If that is not the case, bitser is likely to either silently give you the wrong data or give confusing error messages.

Here's the potential solutions I can see to that:

  • Status quo. Simple, but a footgun waiting to happen.
  • Mark endianness, error if non-matching. Only slightly less simple and has the advantage of never producing the wrong data and at least allowing the error message to make more sense.
  • Mark endianness, byteswap when deserializing. Would result in additional complexity of the bitser internals (which I keep intentionally simple), but would completely solve the problem.
  • Make bitser serialize to little-endian by mandate, big-endian machines have to byteswap (or vice versa). A lot like the previous solution. Difference is that internals get to be slightly less complex (since byteswapping no longer depends on per-buffer state), the 2 or 3 bytes that the endianness marker takes up does not have to be added to the output, and for some platforms, both serializing and deserializing needs byteswapping in all cases.
  • Configurable endianness. This is going to be a whole can of worms on its own, so I'm not going to consider this for the moment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions