// same as DataOutput.writeVLong but accepts negative values
 internal static void WriteVLong(DataOutput @out, long i)
 {
     int k = 0;
     while ((i & ~0x7FL) != 0L && k++ < 8)
     {
         @out.WriteByte(unchecked((byte)(sbyte)((i & 0x7FL) | 0x80L)));
         i = (long)((ulong)i >> 7);
     }
     @out.WriteByte((byte)(sbyte)i);
 }
Ejemplo n.º 2
0
        private static void EncodeLiterals(byte[] bytes, int token, int anchor, int literalLen, DataOutput @out)
        {
            @out.WriteByte((byte)(sbyte)token);

            // encode literal length
            if (literalLen >= 0x0F)
            {
                EncodeLen(literalLen - 0x0F, @out);
            }

            // encode literals
            @out.WriteBytes(bytes, anchor, literalLen);
        }
Ejemplo n.º 3
0
        private static void EncodeSequence(byte[] bytes, int anchor, int matchRef, int matchOff, int matchLen, DataOutput @out)
        {
            int literalLen = matchOff - anchor;
            Debug.Assert(matchLen >= 4);
            // encode token
            int token = (Math.Min(literalLen, 0x0F) << 4) | Math.Min(matchLen - 4, 0x0F);
            EncodeLiterals(bytes, token, anchor, literalLen, @out);

            // encode match dec
            int matchDec = matchOff - matchRef;
            Debug.Assert(matchDec > 0 && matchDec < 1 << 16);
            @out.WriteByte((byte)(sbyte)matchDec);
            @out.WriteByte((byte)(sbyte)((int)((uint)matchDec >> 8)));

            // encode match len
            if (matchLen >= MIN_MATCH + 0x0F)
            {
                EncodeLen(matchLen - 0x0F - MIN_MATCH, @out);
            }
        }
Ejemplo n.º 4
0
 private static void EncodeLen(int l, DataOutput @out)
 {
     while (l >= 0xFF)
     {
         @out.WriteByte(unchecked((byte)(sbyte)0xFF));
         l -= 0xFF;
     }
     @out.WriteByte((byte)(sbyte)l);
 }