private void EncodeOffset(int offset)
{
uint temp;
if (mode == SlidingWindowSize.EightKB)
{
// Offset value less than 64 is encoded as bits 1111 followed by the
// lower 6 bits of the value
if (offset < 64)
{
//offset < 64
temp = (uint)(((int)OffsetSymbol8k.LessThan64
<< (int)OffsetBitSizeWithoutSymbol8k.LessThan64)
+ offset - OffsetAdding8k.LessThan64);
EncodeData(temp, (int)OffsetBitSize8k.LessThan64);
}
else if (offset < 320)
{
// Offset value between 64 and 320 is encoded as bits 1110 followed by
// the lower 8 bits of the computation (value - 64).
temp = (uint)(((int)OffsetSymbol8k.Between64And320
<< (int)OffsetBitSizeWithoutSymbol8k.Between64And320)
+ offset - OffsetAdding8k.Between64And320);
EncodeData(temp, (int)OffsetBitSize8k.Between64And320);
}
else if (offset <= 8192)
{
// Offset value between 320 and 8191 is encoded as bits 110 followed
// by the lower 13 bits of the computation (value - 320).
temp = (uint)(((int)OffsetSymbol8k.Between320And8191
<< (int)OffsetBitSizeWithoutSymbol8k.Between320And8191)
+ offset - OffsetAdding8k.Between320And8191);
EncodeData(temp, (int)OffsetBitSize8k.Between320And8191);
}
else
{
// do nothing
// because offset is a reference to sliding window, so it won't be larger than
// sliding window's size.
}
}
else if (mode == SlidingWindowSize.SixtyFourKB)
{
if (offset < 64)
{
//if offset < 64, encoded as 11111 + lower 6 bits of offset
temp = (uint)(((int)OffsetSymbol64k.LessThan64
<<(int)OffsetBitSizeWithoutSymbol64k.LessThan64)
+ offset);
EncodeData(temp, (int)OffsetBitSize64k.LessThan64);
}
else if (offset < 320)
{
//if offset < 320, encoded as 11110 + lower 8 bits of (offset – 64)
temp = (uint)(((int)OffsetSymbol64k.Between64And319
<< (int)OffsetBitSizeWithoutSymbol64k.Between64And319)
+ offset - OffsetAdding64k.Between64And319);
EncodeData(temp, (int)OffsetBitSize64k.Between64And319);
}
else if (offset < 2368)
{
//if offset < 320, encoded as 1110 + lower 11 bits of (offset – 320)
temp = (uint)(((int)OffsetSymbol64k.Between320And2367
<< (int)OffsetBitSizeWithoutSymbol64k.Between320And2367)
+ offset - OffsetAdding64k.Between320And2367);
EncodeData(temp, (int)OffsetBitSize64k.Between320And2367);
}
else
{
//else, encoded as 110 + lower 16 bits of (offset – 2368)
temp = (uint)(((int)OffsetSymbol64k.LargerThan2368
<< (int)OffsetBitSizeWithoutSymbol64k.LargerThan2368)
+ offset - OffsetAdding64k.LargerThan2368);
EncodeData(temp, (int)OffsetBitSize64k.LargerThan2367);
}
}
}