Exemplo n.º 1
0
 public static bool IsAlreadyDesiredEndianness(BinaryEndianness endianness)
 {
     return(endianness switch {
         BinaryEndianness.LittleEndian => BitConverter.IsLittleEndian,
         BinaryEndianness.BigEndian => !BitConverter.IsLittleEndian,
         _ => throw new NotImplementedException()
     });
Exemplo n.º 2
0
        public static byte ReadByte(byte[] buffer, int startIndex, BinaryEndianness endianness)
        {
            // I don't think this actually does anything since BinaryPrimitives.ReverseEndianness says it does nothing for bytes?
            byte value = buffer[startIndex];

            return(IsAlreadyDesiredEndianness(endianness) ? value : BinaryPrimitives.ReverseEndianness(value));
        }
Exemplo n.º 3
0
 public static Vector3 ReadVector3(byte[] buffer, int offset, BinaryEndianness endianness)
 {
     return(new Vector3(
                ReadFloat(buffer, offset, endianness),
                ReadFloat(buffer, offset + sizeof(float), endianness),
                ReadFloat(buffer, offset + sizeof(float) * 2, endianness)
                ));
 }
Exemplo n.º 4
0
        public static double ReadDouble(byte[] buffer, int startIndex, BinaryEndianness endianness)
        {
            long value = BitConverter.ToInt64(buffer, startIndex);

            return(BitConverter.Int64BitsToDouble(IsAlreadyDesiredEndianness(endianness)
                                                ? value
                                                : BinaryPrimitives.ReverseEndianness(value)));
        }
Exemplo n.º 5
0
        public static float ReadFloat(byte[] buffer, int startIndex, BinaryEndianness endianness)
        {
            int value = BitConverter.ToInt32(buffer, startIndex);

            return(BitConverter.Int32BitsToSingle(IsAlreadyDesiredEndianness(endianness)
                                                ? value
                                                : BinaryPrimitives.ReverseEndianness(value)));
        }
Exemplo n.º 6
0
        public static ushort ReadUInt16(byte[] buffer, int startIndex, BinaryEndianness endianness)
        {
            ushort value = BitConverter.ToUInt16(buffer, startIndex);

            return(IsAlreadyDesiredEndianness(endianness) ? value : BinaryPrimitives.ReverseEndianness(value));
        }