@Test public void testUnsignedSize() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(baos); int expectedSize = 0; for (int exponent = 0; exponent <= 62; exponent++) { Varint.writeUnsignedVarLong(1L << exponent, out); expectedSize += 1 + exponent / 7; assertEquals(expectedSize, baos.size()); } }
public static void writeUnsignedVarLong(long value, DataOutput out) throws IOException { while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) { out.writeByte(((int) value & 0x7F) | 0x80); value >>>= 7; } out.writeByte((int) value & 0x7F); }
Varint { public static void writeUnsignedVarLong(long value, DataOutput out) throws IOException { while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) { out.writeByte(((int) value & 0x7F) | 0x80); value >>>= 7; } out.writeByte((int) value & 0x7F); } }
Varint { public static void writeUnsignedVarLong(long value, DataOutput out) throws IOException { while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) { out.writeByte(((int) value & 0x7F) | 0x80); value >>>= 7; } out.writeByte((int) value & 0x7F); } private  Varint(); }
Varint { public static void writeUnsignedVarLong(long value, DataOutput out) throws IOException { while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) { out.writeByte(((int) value & 0x7F) | 0x80); value >>>= 7; } out.writeByte((int) value & 0x7F); } private  Varint(); static void writeSignedVarLong(long value, DataOutput out); static void writeUnsignedVarLong(long value, DataOutput out); static void writeSignedVarInt(int value, DataOutput out); static void writeUnsignedVarInt(int value, DataOutput out); static long readSignedVarLong(DataInput in); static long readUnsignedVarLong(DataInput in); static long readUnsignedVarLong(byte[] bytes, int start, int length); static int readSignedVarInt(DataInput in); static int readUnsignedVarInt(DataInput in); static int readUnsignedVarInt(byte[] bytes, int start, int length); }
Varint { public static void writeUnsignedVarLong(long value, DataOutput out) throws IOException { while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) { out.writeByte(((int) value & 0x7F) | 0x80); value >>>= 7; } out.writeByte((int) value & 0x7F); } private  Varint(); static void writeSignedVarLong(long value, DataOutput out); static void writeUnsignedVarLong(long value, DataOutput out); static void writeSignedVarInt(int value, DataOutput out); static void writeUnsignedVarInt(int value, DataOutput out); static long readSignedVarLong(DataInput in); static long readUnsignedVarLong(DataInput in); static long readUnsignedVarLong(byte[] bytes, int start, int length); static int readSignedVarInt(DataInput in); static int readUnsignedVarInt(DataInput in); static int readUnsignedVarInt(byte[] bytes, int start, int length);  }