❔ Runtime Endianness for Reading Structured Binary Data
Is there a standard way to deal with reading structured binary data in from a stream where the endianness is known only at runtime? In other words, it would be great if there was something with the same API as the
I'm pretty new to C# so I didn't know if there was a idiomatic way to do this. In go I have used the
From my research, I have discovered (correct me if I'm wrong) that everything in dotnet is little endian. I have also found the
BinaryReader but where the endianness for the reader could be set. I'm pretty new to C# so I didn't know if there was a idiomatic way to do this. In go I have used the
binary.Read (https://pkg.go.dev/encoding/binary#Read) API to allow for reading in primitive types while specifying the endianness. Similarly, I have used the Java ByteBuffer type (https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html) to accomplish this on the JVM. From my research, I have discovered (correct me if I'm wrong) that everything in dotnet is little endian. I have also found the
BinaryPrimatives class which offers different methods for reading/writing binary primitives with different endiannesses. However, using this would require conditional statements wherever a read is performed. I wasn't sure if there was an extant class that provides a sleeker API for this. I know I could wrap it myself, but didn't want to reinvent the wheel if it was just something I missed