public int DecodeField(ref FieldEncodingData Data, byte FieldType, ref long Value) { long Prefix = 0, Width = 0; if (ReadBits(ref Data, 1, ref Value) == 0) { return(0); } if (Value == 0) { return(1); } if (ReadBits(ref Data, 2, ref Prefix) == 0) { return(0); } Width = Data.FieldWidths[FieldType * 4 + Prefix]; if (ReadBits(ref Data, (byte)Width, ref Value) == 0) { return(0); } Value |= -(Value & 1L << (byte)(Width - 1)); return(1); }
private int ReadBits(ref FieldEncodingData FieldData, byte Width, ref long Value) { while (FieldData.BitBufferCount < Width) { if (FieldData.ReadDataLength >= FieldData.EncodedDataLength) return 0; FieldData.BitBuffer <<= 8; FieldData.BitBuffer |= FieldData.EncodedData[FieldData.FieldDataCounter++]; FieldData.BitBufferCount += 8; FieldData.ReadDataLength++; } Value = FieldData.BitBuffer >> (FieldData.BitBufferCount - Width); Value &= (1L << Width) - 1; FieldData.BitBufferCount -= Width; return 1; }
private int ReadBits(ref FieldEncodingData FieldData, byte Width, ref long Value) { while (FieldData.BitBufferCount < Width) { if (FieldData.ReadDataLength >= FieldData.EncodedDataLength) { return(0); } FieldData.BitBuffer <<= 8; FieldData.BitBuffer |= FieldData.EncodedData[FieldData.FieldDataCounter++]; FieldData.BitBufferCount += 8; FieldData.ReadDataLength++; } Value = FieldData.BitBuffer >> (FieldData.BitBufferCount - Width); Value &= (1L << Width) - 1; FieldData.BitBufferCount -= Width; return(1); }
public int DecodeField(ref FieldEncodingData Data, byte FieldType, ref long Value) { long Prefix = 0, Width = 0; if(ReadBits(ref Data, 1, ref Value) == 0) return 0; if (Value == 0) return 1; if (ReadBits(ref Data, 2, ref Prefix) == 0) return 0; Width = Data.FieldWidths[FieldType * 4 + Prefix]; if(ReadBits(ref Data, (byte)Width, ref Value) == 0) return 0; Value |= -(Value & 1L << (byte)(Width - 1)); return 1; }