@Test public void testInvalid() { ByteBuffer bb = ByteBuffer.wrap(StringConverter.hexStringToArray("8182838485")); try { VarIntUtil.readVarInt32(bb); fail("Should have thrown an exception"); } catch (DecodingException e) { } }
public static int readVarInt32(ByteBuffer bb) throws DecodingException { byte b = bb.get(); int v = b &0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { if(shift>28) throw new DecodingException("Invalid VarInt32: more than 5 bytes!"); b = bb.get(); v |= (b & 0x7F) << shift; } return v; }
VarIntUtil { public static int readVarInt32(ByteBuffer bb) throws DecodingException { byte b = bb.get(); int v = b &0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { if(shift>28) throw new DecodingException("Invalid VarInt32: more than 5 bytes!"); b = bb.get(); v |= (b & 0x7F) << shift; } return v; } }
VarIntUtil { public static int readVarInt32(ByteBuffer bb) throws DecodingException { byte b = bb.get(); int v = b &0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { if(shift>28) throw new DecodingException("Invalid VarInt32: more than 5 bytes!"); b = bb.get(); v |= (b & 0x7F) << shift; } return v; }  }
VarIntUtil { public static int readVarInt32(ByteBuffer bb) throws DecodingException { byte b = bb.get(); int v = b &0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { if(shift>28) throw new DecodingException("Invalid VarInt32: more than 5 bytes!"); b = bb.get(); v |= (b & 0x7F) << shift; } return v; }  static int writeVarInt32(byte[] buf, int pos, int x); static void writeVarInt32(ByteBuffer bb, int x); static void writeVarInt64(ByteBuffer bb, long x); static int readVarInt32(ByteBuffer bb); static long readVarInt64(ByteBuffer bb); static void writeSignedVarint32(ByteBuffer bb, int x); static int readSignedVarInt32(ByteBuffer bb); static int encodeSigned(byte[] buf, int pos, int x); static ArrayDecoder newArrayDecoder(byte[] buf); static int decodeZigZag(int x); static int encodeZigZag(int x); static void writeSizeDelimitedString(ByteBuffer bb, String s); static String readSizeDelimitedString(ByteBuffer bb); static int[] encodeDeltaDeltaZigZag(int x[]); static int[] decodeDeltaDeltaZigZag(int ddz[]); static int[] encodeDeltaDeltaZigZag(SortedIntArray a); static int[] encodeDeltaDeltaZigZag(IntArray a); static int getEncodedSize(int value); static byte[] encodeDeltaIntArray(IntArray s); static IntArray decodeDeltaIntArray(byte[] buf); }
VarIntUtil { public static int readVarInt32(ByteBuffer bb) throws DecodingException { byte b = bb.get(); int v = b &0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { if(shift>28) throw new DecodingException("Invalid VarInt32: more than 5 bytes!"); b = bb.get(); v |= (b & 0x7F) << shift; } return v; }  static int writeVarInt32(byte[] buf, int pos, int x); static void writeVarInt32(ByteBuffer bb, int x); static void writeVarInt64(ByteBuffer bb, long x); static int readVarInt32(ByteBuffer bb); static long readVarInt64(ByteBuffer bb); static void writeSignedVarint32(ByteBuffer bb, int x); static int readSignedVarInt32(ByteBuffer bb); static int encodeSigned(byte[] buf, int pos, int x); static ArrayDecoder newArrayDecoder(byte[] buf); static int decodeZigZag(int x); static int encodeZigZag(int x); static void writeSizeDelimitedString(ByteBuffer bb, String s); static String readSizeDelimitedString(ByteBuffer bb); static int[] encodeDeltaDeltaZigZag(int x[]); static int[] decodeDeltaDeltaZigZag(int ddz[]); static int[] encodeDeltaDeltaZigZag(SortedIntArray a); static int[] encodeDeltaDeltaZigZag(IntArray a); static int getEncodedSize(int value); static byte[] encodeDeltaIntArray(IntArray s); static IntArray decodeDeltaIntArray(byte[] buf);  }