Esempio n. 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));
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
        // Deserialization
        public Decimal Deserialize()
        {
            // Read info about storage format
            DecimalStorageFormats format = (DecimalStorageFormats)SerializerStorage.ReadStorageFormatId(DecimalStorageBase.FormatIdSizeInBits);

            // Is it default value
            if (format == DecimalStorageFormats.DefaultValue)
            {
                return(Decimal.Zero);
            }

            // Size of data in buffer
            PositiveValueInDataStream positiveValueInDataStream = new PositiveValueInDataStream();

            positiveValueInDataStream.FormatConfig.Bits = SerializerStorage.ReadStorageFormatData(PositiveValueInDataStream.UsedConfigBitsForCase);
            byte packedDataSize = (byte)positiveValueInDataStream.PackedDataSize;

            // Data
            byte[] packedData = SerializerStorage.ReadPackedData(packedDataSize);

            // Buffer
            int[] decimalBuffer = new int[4];

            int intPos    = 0;
            int byteShift = 0;

            // Restore value
            for (int pos = 0; pos < packedDataSize; pos++)
            {
                decimalBuffer[intPos] |= packedData[pos] << byteShift;

                byteShift += 8;
                byteShift %= 8;

                if (byteShift == 0)
                {
                    intPos++;
                }
            }

            // Is it NegativeValueInDataStream) storage case
            if (format == DecimalStorageFormats.NegativeValueInDataStream)
            {
                return(new Decimal(decimalBuffer) * (-1));
            }

            // Is it PositiveValueInDataStream storage case
            // DecimalStorageFormats.PositiveValueInDataStream
            return(new Decimal(decimalBuffer));
        }