示例#1
0
 public MeasurementStreamFileReading()
 {
     Value       = new UnionValues();
     m_points    = new List <PointMetaData>();
     m_buffer    = new ByteBuffer(4096);
     m_bitStream = new BitStreamReader(this);
     NewMeasurementRegisteredMetadata = new byte[16];
     UserCommandData = new byte[16];
 }
 public MeasurementStreamFileReading()
 {
     Value = new UnionValues();
     m_points = new List<PointMetaData>();
     m_buffer = new ByteBuffer(4096);
     m_bitStream = new BitStreamReader(this);
     NewMeasurementRegisteredMetadata = new byte[16];
     UserCommandData = new byte[16];
 }
示例#3
0
 public abstract void ReadValue(int code, UnionValues outValue);
示例#4
0
 public abstract void WriteValue(UnionValues currentValue);
 public abstract void ReadValue(int code, UnionValues outValue);
 public abstract void WriteValue(UnionValues currentValue);
        public override void WriteValue(UnionValues currentValue)
        {
            ulong valueRaw = currentValue.ValueUInt64;

            if (PrevValue1 == valueRaw)
            {
                BitStream.WriteCode(Codes64.Value1);
            }
            else if (PrevValue2 == valueRaw)
            {
                BitStream.WriteCode(Codes64.Value2);
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (PrevValue3 == valueRaw)
            {
                BitStream.WriteCode(Codes64.Value3);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (valueRaw == 0)
            {
                BitStream.WriteCode(Codes64.ValueZero);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = 0;
            }
            else
            {
                ulong bitsChanged = valueRaw ^ PrevValue1;

                if (bitsChanged == Bits0)
                {
                    throw new Exception("Programming Error");
                }
                else if (bitsChanged <= Bits8)
                {
                    BitStream.WriteCode(Codes64.ValueXOR8);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Position++;
                }
                else if (bitsChanged <= Bits16)
                {
                    BitStream.WriteCode(Codes64.ValueXOR16);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Position = Buffer.Position + 2;
                }
                else if (bitsChanged <= Bits24)
                {
                    BitStream.WriteCode(Codes64.ValueXOR24);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Position = Buffer.Position + 3;
                }
                else if (bitsChanged <= Bits32)
                {
                    BitStream.WriteCode(Codes64.ValueXOR32);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Position = Buffer.Position + 4;
                }
                else if (bitsChanged <= Bits40)
                {
                    BitStream.WriteCode(Codes64.ValueXOR40);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Position = Buffer.Position + 5;
                }
                else if (bitsChanged <= Bits48)
                {
                    BitStream.WriteCode(Codes64.ValueXOR48);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Data[Buffer.Position + 5] = (byte)(bitsChanged >> 40);
                    Buffer.Position = Buffer.Position + 6;
                }
                else if (bitsChanged <= Bits56)
                {
                    BitStream.WriteCode(Codes64.ValueXOR56);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Data[Buffer.Position + 5] = (byte)(bitsChanged >> 40);
                    Buffer.Data[Buffer.Position + 6] = (byte)(bitsChanged >> 48);
                    Buffer.Position = Buffer.Position + 7;
                }
                else
                {
                    BitStream.WriteCode(Codes64.ValueXOR64);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Data[Buffer.Position + 5] = (byte)(bitsChanged >> 40);
                    Buffer.Data[Buffer.Position + 6] = (byte)(bitsChanged >> 48);
                    Buffer.Data[Buffer.Position + 7] = (byte)(bitsChanged >> 56);
                    Buffer.Position = Buffer.Position + 8;
                }

                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }

        }
 public override void ReadValue(int code, UnionValues outValue)
 {
     throw new NotImplementedException();
 }
示例#9
0
        public override void WriteValue(UnionValues currentValue)
        {
            ulong valueRaw = currentValue.ValueUInt64;

            if (PrevValue1 == valueRaw)
            {
                BitStream.WriteCode(Codes64.Value1);
            }
            else if (PrevValue2 == valueRaw)
            {
                BitStream.WriteCode(Codes64.Value2);
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (PrevValue3 == valueRaw)
            {
                BitStream.WriteCode(Codes64.Value3);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (valueRaw == 0)
            {
                BitStream.WriteCode(Codes64.ValueZero);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = 0;
            }
            else
            {
                ulong bitsChanged = valueRaw ^ PrevValue1;

                if (bitsChanged == Bits0)
                {
                    throw new Exception("Programming Error");
                }
                else if (bitsChanged <= Bits8)
                {
                    BitStream.WriteCode(Codes64.ValueXOR8);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Position++;
                }
                else if (bitsChanged <= Bits16)
                {
                    BitStream.WriteCode(Codes64.ValueXOR16);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Position = Buffer.Position + 2;
                }
                else if (bitsChanged <= Bits24)
                {
                    BitStream.WriteCode(Codes64.ValueXOR24);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Position = Buffer.Position + 3;
                }
                else if (bitsChanged <= Bits32)
                {
                    BitStream.WriteCode(Codes64.ValueXOR32);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Position = Buffer.Position + 4;
                }
                else if (bitsChanged <= Bits40)
                {
                    BitStream.WriteCode(Codes64.ValueXOR40);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Position = Buffer.Position + 5;
                }
                else if (bitsChanged <= Bits48)
                {
                    BitStream.WriteCode(Codes64.ValueXOR48);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Data[Buffer.Position + 5] = (byte)(bitsChanged >> 40);
                    Buffer.Position = Buffer.Position + 6;
                }
                else if (bitsChanged <= Bits56)
                {
                    BitStream.WriteCode(Codes64.ValueXOR56);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Data[Buffer.Position + 5] = (byte)(bitsChanged >> 40);
                    Buffer.Data[Buffer.Position + 6] = (byte)(bitsChanged >> 48);
                    Buffer.Position = Buffer.Position + 7;
                }
                else
                {
                    BitStream.WriteCode(Codes64.ValueXOR64);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Data[Buffer.Position + 4] = (byte)(bitsChanged >> 32);
                    Buffer.Data[Buffer.Position + 5] = (byte)(bitsChanged >> 40);
                    Buffer.Data[Buffer.Position + 6] = (byte)(bitsChanged >> 48);
                    Buffer.Data[Buffer.Position + 7] = (byte)(bitsChanged >> 56);
                    Buffer.Position = Buffer.Position + 8;
                }

                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
        }
示例#10
0
 public override void ReadValue(int code, UnionValues outValue)
 {
     throw new NotImplementedException();
 }
        public override void ReadValue(int code, UnionValues outValue)
        {
            uint valueRaw = 0;

            if (code == Codes32.Value1)
            {
                valueRaw = PrevValue1;
            }
            else if (code == Codes32.Value2)
            {
                valueRaw = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (code == Codes32.Value3)
            {
                valueRaw = PrevValue3;
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (code == Codes32.ValueZero)
            {
                valueRaw = 0;
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else
            {
                switch (code)
                {
                    case Codes32.ValueXOR4:
                        valueRaw = (uint)BitStream.ReadBits4() ^ PrevValue1;
                        break;
                    case Codes32.ValueXOR8:
                        valueRaw = Buffer.Data[Buffer.Position] ^ PrevValue1;
                        Buffer.Position = Buffer.Position + 1;
                        break;
                    case Codes32.ValueXOR12:
                        valueRaw = (uint)BitStream.ReadBits4() ^ (uint)(Buffer.Data[Buffer.Position] << 4) ^ PrevValue1;
                        Buffer.Position = Buffer.Position + 1;
                        break;
                    case Codes32.ValueXOR16:
                        valueRaw = Buffer.Data[Buffer.Position] ^ (uint)(Buffer.Data[Buffer.Position + 1] << 8) ^ PrevValue1;
                        Buffer.Position = Buffer.Position + 2;
                        break;
                    case Codes32.ValueXOR20:
                        valueRaw = (uint)BitStream.ReadBits4() ^ (uint)(Buffer.Data[Buffer.Position] << 4) ^ (uint)(Buffer.Data[Buffer.Position + 1] << 12) ^ PrevValue1;
                        Buffer.Position = Buffer.Position + 2;
                        break;
                    case Codes32.ValueXOR24:
                        valueRaw = Buffer.Data[Buffer.Position] ^ (uint)(Buffer.Data[Buffer.Position + 1] << 8) ^ (uint)(Buffer.Data[Buffer.Position + 2] << 16) ^ PrevValue1;
                        Buffer.Position = Buffer.Position + 3;
                        break;
                    case Codes32.ValueXOR28:
                        valueRaw = (uint)BitStream.ReadBits4() ^ (uint)(Buffer.Data[Buffer.Position] << 4) ^ (uint)(Buffer.Data[Buffer.Position + 1] << 12) ^ (uint)(Buffer.Data[Buffer.Position + 2] << 20) ^ PrevValue1;
                        Buffer.Position = Buffer.Position + 3;
                        break;
                    case Codes32.ValueXOR32:
                        valueRaw = Buffer.Data[Buffer.Position] ^ (uint)(Buffer.Data[Buffer.Position + 1] << 8) ^ (uint)(Buffer.Data[Buffer.Position + 2] << 16) ^ (uint)(Buffer.Data[Buffer.Position + 3] << 24) ^ PrevValue1;
                        Buffer.Position = Buffer.Position + 4;
                        break;
                    default:
                        throw new Exception("Code not valid");
                }

                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            
            outValue.ValueUInt32 = valueRaw;
        }
        public override void WriteValue(UnionValues currentValue)
        {
            uint value = currentValue.ValueUInt32;

            if (PrevValue1 == value)
            {
                BitStream.WriteCode(Codes32.Value1);
            }
            else if (PrevValue2 == value)
            {
                BitStream.WriteCode(Codes32.Value2);
                PrevValue2 = PrevValue1;
                PrevValue1 = value;
            }
            else if (PrevValue3 == value)
            {
                BitStream.WriteCode(Codes32.Value3);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = value;
            }
            else if (value == 0)
            {
                BitStream.WriteCode(Codes32.ValueZero);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = 0;
            }
            else
            {
                uint bitsChanged = value ^ PrevValue1;

                if (bitsChanged == Bits0)
                {
                    throw new Exception("Programming Error");
                }
                else if (bitsChanged <= Bits4)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR4, (byte)bitsChanged);
                }
                else if (bitsChanged <= Bits8)
                {
                    BitStream.WriteCode(Codes32.ValueXOR8);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Position++;
                }
                else if (bitsChanged <= Bits12)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR12, (byte)bitsChanged);

                    Buffer.Data[Buffer.Position] = (byte)(bitsChanged >> 4);
                    Buffer.Position++;
                }
                else if (bitsChanged <= Bits16)
                {
                    BitStream.WriteCode(Codes32.ValueXOR16);
                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Position = Buffer.Position + 2;
                }
                else if (bitsChanged <= Bits20)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR20, (byte)bitsChanged);

                    Buffer.Data[Buffer.Position] = (byte)(bitsChanged >> 4);
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 12);
                    Buffer.Position = Buffer.Position + 2;
                }
                else if (bitsChanged <= Bits24)
                {
                    BitStream.WriteCode(Codes32.ValueXOR24);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Position = Buffer.Position + 3;
                }
                else if (bitsChanged <= Bits28)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR28, (byte)bitsChanged);

                    Buffer.Data[Buffer.Position] = (byte)(bitsChanged >> 4);
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 12);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 20);
                    Buffer.Position = Buffer.Position + 3;
                }
                else
                {
                    BitStream.WriteCode(Codes32.ValueXOR32);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Position = Buffer.Position + 4;
                }

                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = value;
            }
        }
示例#13
0
        public override void ReadValue(int code, UnionValues outValue)
        {
            uint valueRaw = 0;

            if (code == Codes32.Value1)
            {
                valueRaw = PrevValue1;
            }
            else if (code == Codes32.Value2)
            {
                valueRaw   = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (code == Codes32.Value3)
            {
                valueRaw   = PrevValue3;
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else if (code == Codes32.ValueZero)
            {
                valueRaw   = 0;
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }
            else
            {
                switch (code)
                {
                case Codes32.ValueXOR4:
                    valueRaw = (uint)BitStream.ReadBits4() ^ PrevValue1;
                    break;

                case Codes32.ValueXOR8:
                    valueRaw        = Buffer.Data[Buffer.Position] ^ PrevValue1;
                    Buffer.Position = Buffer.Position + 1;
                    break;

                case Codes32.ValueXOR12:
                    valueRaw        = (uint)BitStream.ReadBits4() ^ (uint)(Buffer.Data[Buffer.Position] << 4) ^ PrevValue1;
                    Buffer.Position = Buffer.Position + 1;
                    break;

                case Codes32.ValueXOR16:
                    valueRaw        = Buffer.Data[Buffer.Position] ^ (uint)(Buffer.Data[Buffer.Position + 1] << 8) ^ PrevValue1;
                    Buffer.Position = Buffer.Position + 2;
                    break;

                case Codes32.ValueXOR20:
                    valueRaw        = (uint)BitStream.ReadBits4() ^ (uint)(Buffer.Data[Buffer.Position] << 4) ^ (uint)(Buffer.Data[Buffer.Position + 1] << 12) ^ PrevValue1;
                    Buffer.Position = Buffer.Position + 2;
                    break;

                case Codes32.ValueXOR24:
                    valueRaw        = Buffer.Data[Buffer.Position] ^ (uint)(Buffer.Data[Buffer.Position + 1] << 8) ^ (uint)(Buffer.Data[Buffer.Position + 2] << 16) ^ PrevValue1;
                    Buffer.Position = Buffer.Position + 3;
                    break;

                case Codes32.ValueXOR28:
                    valueRaw        = (uint)BitStream.ReadBits4() ^ (uint)(Buffer.Data[Buffer.Position] << 4) ^ (uint)(Buffer.Data[Buffer.Position + 1] << 12) ^ (uint)(Buffer.Data[Buffer.Position + 2] << 20) ^ PrevValue1;
                    Buffer.Position = Buffer.Position + 3;
                    break;

                case Codes32.ValueXOR32:
                    valueRaw        = Buffer.Data[Buffer.Position] ^ (uint)(Buffer.Data[Buffer.Position + 1] << 8) ^ (uint)(Buffer.Data[Buffer.Position + 2] << 16) ^ (uint)(Buffer.Data[Buffer.Position + 3] << 24) ^ PrevValue1;
                    Buffer.Position = Buffer.Position + 4;
                    break;

                default:
                    throw new Exception("Code not valid");
                }

                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = valueRaw;
            }

            outValue.ValueUInt32 = valueRaw;
        }
示例#14
0
        public override void WriteValue(UnionValues currentValue)
        {
            uint value = currentValue.ValueUInt32;

            if (PrevValue1 == value)
            {
                BitStream.WriteCode(Codes32.Value1);
            }
            else if (PrevValue2 == value)
            {
                BitStream.WriteCode(Codes32.Value2);
                PrevValue2 = PrevValue1;
                PrevValue1 = value;
            }
            else if (PrevValue3 == value)
            {
                BitStream.WriteCode(Codes32.Value3);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = value;
            }
            else if (value == 0)
            {
                BitStream.WriteCode(Codes32.ValueZero);
                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = 0;
            }
            else
            {
                uint bitsChanged = value ^ PrevValue1;

                if (bitsChanged == Bits0)
                {
                    throw new Exception("Programming Error");
                }
                else if (bitsChanged <= Bits4)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR4, (byte)bitsChanged);
                }
                else if (bitsChanged <= Bits8)
                {
                    BitStream.WriteCode(Codes32.ValueXOR8);

                    Buffer.Data[Buffer.Position] = (byte)bitsChanged;
                    Buffer.Position++;
                }
                else if (bitsChanged <= Bits12)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR12, (byte)bitsChanged);

                    Buffer.Data[Buffer.Position] = (byte)(bitsChanged >> 4);
                    Buffer.Position++;
                }
                else if (bitsChanged <= Bits16)
                {
                    BitStream.WriteCode(Codes32.ValueXOR16);
                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Position = Buffer.Position + 2;
                }
                else if (bitsChanged <= Bits20)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR20, (byte)bitsChanged);

                    Buffer.Data[Buffer.Position]     = (byte)(bitsChanged >> 4);
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 12);
                    Buffer.Position = Buffer.Position + 2;
                }
                else if (bitsChanged <= Bits24)
                {
                    BitStream.WriteCode(Codes32.ValueXOR24);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Position = Buffer.Position + 3;
                }
                else if (bitsChanged <= Bits28)
                {
                    BitStream.WriteCode4(Codes32.ValueXOR28, (byte)bitsChanged);

                    Buffer.Data[Buffer.Position]     = (byte)(bitsChanged >> 4);
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 12);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 20);
                    Buffer.Position = Buffer.Position + 3;
                }
                else
                {
                    BitStream.WriteCode(Codes32.ValueXOR32);

                    Buffer.Data[Buffer.Position]     = (byte)bitsChanged;
                    Buffer.Data[Buffer.Position + 1] = (byte)(bitsChanged >> 8);
                    Buffer.Data[Buffer.Position + 2] = (byte)(bitsChanged >> 16);
                    Buffer.Data[Buffer.Position + 3] = (byte)(bitsChanged >> 24);
                    Buffer.Position = Buffer.Position + 4;
                }

                PrevValue3 = PrevValue2;
                PrevValue2 = PrevValue1;
                PrevValue1 = value;
            }
        }