public abstract WriteCode ( int code ) : void | ||
code | int | |
Résultat | void |
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 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; } }