Esempio n. 1
0
        public static void TransformFloat(float val, byte[] buffer, int index)
        {
            var floatBytes         = EndianAwareBitConverter.GetBytes(val, Endianness.Big);
            var intForm            = (uint)EndianAwareBitConverter.ToInt32(floatBytes, Endianness.Big);
            var transformedIntForm = (intForm << 1) | (intForm >> 31); // Rotate left 1 bit
            var transformedBytes   = EndianAwareBitConverter.GetBytes((int)transformedIntForm, Endianness.Big);

            Array.Copy(transformedBytes, 0, buffer, index, sizeof(float));
        }
Esempio n. 2
0
        public static float ReverseTransformFloat(byte[] buffer, int index)
        {
            var bytes = new byte[sizeof(float)];

            Array.Copy(buffer, index, bytes, 0, sizeof(float));
            var intForm            = (uint)EndianAwareBitConverter.ToInt32(bytes, Endianness.Big);
            var transformedIntForm = (intForm >> 1) | (intForm << 31); // Rotate right 1 bit
            var transformedBytes   = EndianAwareBitConverter.GetBytes((int)transformedIntForm, Endianness.Big);

            return(EndianAwareBitConverter.ToSingle(transformedBytes, Endianness.Big));
        }
Esempio n. 3
0
        public static byte[] TransformInt32Array(int[] data)
        {
            var bytes = new byte[data.Length * sizeof(int)];

            for (var i = 0; i < data.Length; i++)
            {
                var transformed = TransformInt32(data[i]);
                var valueBytes  = EndianAwareBitConverter.GetBytes(transformed, Endianness.Big);
                Array.Copy(valueBytes, 0, bytes, i * sizeof(int), sizeof(int));
            }

            var interleaved = InterleaveBytes(bytes, sizeof(int));

            return(interleaved);
        }
Esempio n. 4
0
        public static void WriteReferentArray(EndianAwareBinaryWriter writer, int[] values)
        {
            var bytes = new byte[values.Length * sizeof(int)];

            var last = 0;

            for (var i = 0; i < values.Length; i++)
            {
                var val         = values[i] - last;
                var transformed = TransformInt32(val);
                var valBytes    = EndianAwareBitConverter.GetBytes(transformed, Endianness.Big);
                last = values[i];
                Array.Copy(valBytes, 0, bytes, i * sizeof(int), sizeof(int));
            }

            var interleaved = InterleaveBytes(bytes, sizeof(int));

            writer.WriteBytes(interleaved);
        }
Esempio n. 5
0
 public static void WriteEnumerationArray(EndianAwareBinaryWriter writer, int[] values)
 {
     WriteInterleavedPropertyDataHelper(writer, values, sizeof(int), val => EndianAwareBitConverter.GetBytes(val, Endianness.Big));
 }
Esempio n. 6
0
 public static void WriteBrickColorArray(EndianAwareBinaryWriter writer, BrickColor[] values)
 {
     WriteInterleavedPropertyDataHelper(writer, values, sizeof(int), val => EndianAwareBitConverter.GetBytes((int)val, Endianness.Big));
 }