public static void writeRawVarInt32(int value, final byte[] buf, int offset) throws IOException
    {
        while (true)
        {
            if ((value & ~0x7F) == 0)
            {
                buf[offset] = (byte) value;
                return;
            }
            else
            {
                buf[offset++] = (byte) ((value & 0x7F) | 0x80);
                value >>>= 7;
            }
        }
    }
Encode and write a varint to the byte array
protostuff-core/src/main/java/io/protostuff/ProtobufOutput.java