// Deserialization public UInt16 Deserialize() { // Read info about storage format Int16StorageFormats format = (Int16StorageFormats)SerializerStorage.ReadStorageFormatId(Int16StorageBase.FormatIdSizeInBits); // Is it default value if (format == Int16StorageFormats.DefaultValue) { return(0); } if (format == Int16StorageFormats.ValueInConfig) { ValueInConfig valInConfig = new ValueInConfig(); valInConfig.FormatConfig.Bits = SerializerStorage.ReadStorageFormatData(ValueInConfig.UsedConfigBitsForValue); return((UInt16)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((UInt16)BitToolkit.ConvertByteArrayToInt16(encodedValue)); }
// Deserialization of Int16 public static UInt16 DeserializeUInt16(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((UInt16)((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((UInt16)BitToolkit.ConvertByteArrayToInt16(serializedData, 1)); // case 00: default: return(0); } }