Exemple #1
0
        // Deserialization
        public Single Deserialize()
        {
            // Read info about storage format
            SingleStorageFormats format = (SingleStorageFormats)SerializerStorage.ReadStorageFormatId(SingleStorageBase.FormatIdSizeInBits);

            // Is it default value
            if (format == SingleStorageFormats.DefaultValue)
            {
                return(0);
            }

            // Deserialize full data

            // Read config byte - 4 bits for 4 bytes
            byte config = (byte)SerializerStorage.ReadStorageFormatData(4);

            // Single bytes
            byte[] singleBytes = new byte[4];

            // Conversion - we check out bits for all the bytes (4 bytes)
            for (int bitPos = 0; bitPos < 4; ++bitPos)
            {
                // If bit is set (has value 1) then we put this byte on proper position
                if ((config & (1 << bitPos)) > 0)
                {
                    singleBytes[bitPos] = SerializerStorage.ReadPackedDataByte();
                }
            }

            // Return result
            return(BitConverter.ToSingle(singleBytes, 0));
        }
 // Constructor that requires config case value
 public SingleStorageBase(SingleStorageFormats confCase, byte usedConfigBits) : base((byte)confCase, FormatIdSizeInBits, usedConfigBits)
 {
 }