Example #1
0
        // Deserialization
        public Int64 Deserialize()
        {
            // Read info about storage format
            Int64StorageFormats format = (Int64StorageFormats)SerializerStorage.ReadStorageFormatId(Int64StorageBase.FormatIdSizeInBits);

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

            if (format == Int64StorageFormats.ValueInConfig)
            {
                ValueInConfig valInConfig = new ValueInConfig();
                valInConfig.FormatConfig.Bits = SerializerStorage.ReadStorageFormatData(ValueInConfig.UsedConfigBitsForValue);
                return((Int64)valInConfig.Value);
            }

            // Value stored in PackedData
            ValueInDataStream valInDataStream = new ValueInDataStream();

            valInDataStream.FormatConfig.Bits = SerializerStorage.ReadStorageFormatData(ValueInDataStream.UsedConfigBitsForCase);
            byte[] encodedValue = SerializerStorage.ReadPackedData(valInDataStream.PackedDataSize);

            // Return decoded value
            return(BitToolkit.ConvertByteArrayToInt64(encodedValue));
        }
Example #2
0
        // Deserialization of Int64
        public static Int64 DeserializeInt64(byte[] serializedData)
        {
            // 1 or 2 bits for config (lsb)
            // x1 - stored in this byte (on rest 7 bits)
            // 00 - has default value 0
            // 10 - stored in next few bytes - then next 2 bits says on how many bytes the value has been stored


            // Read config byte
            byte config = serializedData[0];

            // Is it value stored in config byte?
            if ((config & 0x01) > 0)
            {
                return((config >> 1) + 1);
            }

            // Rest config cases
            byte configCase = (byte)(config & 0x03); // Mask 2 lsb bits

            switch (configCase)
            {
            case 2:     // 10 - stored in next few bytes - then next 2 bits says on how many bytes the value has been stored
                return(BitToolkit.ConvertByteArrayToInt64(serializedData, 1));

            // case 00:
            default:
                return(0);
            }
        }