@Test public void testDecodeInt() throws Exception { InputStream in = new ByteArrayInputStream(new byte[] { (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x01 }); Decoder decoder = new MemcmpDecoder(in); int i = decoder.readInt(); assertEquals(1, i); in = new ByteArrayInputStream(new byte[] { (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff }); decoder = new MemcmpDecoder(in); i = decoder.readInt(); assertEquals(-1, i); in = new ByteArrayInputStream(new byte[] { (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00 }); decoder = new MemcmpDecoder(in); i = decoder.readInt(); assertEquals(0, i); }
@Override public int readInt() throws IOException { byte[] intBytes = new byte[4]; int i = in.read(intBytes); if (i < 4) { throw new EOFException(); } intBytes[0] = (byte) (intBytes[0] ^ 0x80); int value = 0; for (int j = 0; j < intBytes.length; ++j) { value = (value << 8) + (intBytes[j] & 0xff); } return value; }
MemcmpDecoder extends Decoder { @Override public int readInt() throws IOException { byte[] intBytes = new byte[4]; int i = in.read(intBytes); if (i < 4) { throw new EOFException(); } intBytes[0] = (byte) (intBytes[0] ^ 0x80); int value = 0; for (int j = 0; j < intBytes.length; ++j) { value = (value << 8) + (intBytes[j] & 0xff); } return value; } }
MemcmpDecoder extends Decoder { @Override public int readInt() throws IOException { byte[] intBytes = new byte[4]; int i = in.read(intBytes); if (i < 4) { throw new EOFException(); } intBytes[0] = (byte) (intBytes[0] ^ 0x80); int value = 0; for (int j = 0; j < intBytes.length; ++j) { value = (value << 8) + (intBytes[j] & 0xff); } return value; } MemcmpDecoder(InputStream in); }
MemcmpDecoder extends Decoder { @Override public int readInt() throws IOException { byte[] intBytes = new byte[4]; int i = in.read(intBytes); if (i < 4) { throw new EOFException(); } intBytes[0] = (byte) (intBytes[0] ^ 0x80); int value = 0; for (int j = 0; j < intBytes.length; ++j) { value = (value << 8) + (intBytes[j] & 0xff); } return value; } MemcmpDecoder(InputStream in); @Override void readNull(); @Override boolean readBoolean(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override Utf8 readString(Utf8 old); @Override String readString(); @Override void skipString(); @Override ByteBuffer readBytes(ByteBuffer old); void skipBytes(); @Override void readFixed(byte[] bytes, int start, int length); @Override void skipFixed(int length); @Override int readEnum(); @Override long readArrayStart(); @Override long arrayNext(); @Override long skipArray(); @Override long readMapStart(); @Override long mapNext(); @Override long skipMap(); @Override int readIndex(); }
MemcmpDecoder extends Decoder { @Override public int readInt() throws IOException { byte[] intBytes = new byte[4]; int i = in.read(intBytes); if (i < 4) { throw new EOFException(); } intBytes[0] = (byte) (intBytes[0] ^ 0x80); int value = 0; for (int j = 0; j < intBytes.length; ++j) { value = (value << 8) + (intBytes[j] & 0xff); } return value; } MemcmpDecoder(InputStream in); @Override void readNull(); @Override boolean readBoolean(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override Utf8 readString(Utf8 old); @Override String readString(); @Override void skipString(); @Override ByteBuffer readBytes(ByteBuffer old); void skipBytes(); @Override void readFixed(byte[] bytes, int start, int length); @Override void skipFixed(int length); @Override int readEnum(); @Override long readArrayStart(); @Override long arrayNext(); @Override long skipArray(); @Override long readMapStart(); @Override long mapNext(); @Override long skipMap(); @Override int readIndex();  }