[Pitch] Safe loading of integer values from `RawSpan`

I am not sure that we have ascertained the endianness options on RawSpan are the way we want to go:

  • There is no Span variant that lets you control endianness; it’s annoying that we would say “use Span if you’re cool with native endianness, and if you don’t, the blessed pattern is to use RawSpan and count your offsets by hand”
  • There is no way to control endianness for anything other than integers, which creates a weird cliff if you’re trying to load a struct (assuming that one day we do get to that fully inhabited protocol)
    • There are binary formats that use different endianness in different parts (or even for two integers next to one another), like Photoshop documents, so there is just no coherent way that specifying endianness for a struct can work in all cases
  • Integers already have init(bigEndian:) and init(littleEndian:) for endianness conversion, which are good ways to deal with the problem (floating point types don’t, but they should)

I think this pushes RawSpan into parsing territory more than being the primitive for working with untyped memory, so I’m less hot for it.

1 Like