@Override public Character decodeFromWire(int pos, Buffer buffer) { return (char)buffer.getShort(pos); }
private void testGetSetShort(boolean isLE) throws Exception { int numShorts = 100; Buffer b = Buffer.buffer(numShorts * 2); for (short i = 0; i < numShorts; i++) { if (isLE) { b.setShortLE(i * 2, i); } else { b.setShort(i * 2, i); } } for (short i = 0; i < numShorts; i++) { if (isLE) { assertEquals(i, b.getShortLE(i * 2)); } else { assertEquals(i, b.getShort(i * 2)); } } }
@Override public Short decodeFromWire(int pos, Buffer buffer) { return buffer.getShort(pos); }
private void testGetSetShort(boolean isLE) throws Exception { int numShorts = 100; Buffer b = Buffer.buffer(numShorts * 2); for (short i = 0; i < numShorts; i++) { if (isLE) { b.setShortLE(i * 2, i); } else { b.setShort(i * 2, i); } } for (short i = 0; i < numShorts; i++) { if (isLE) { assertEquals(i, b.getShortLE(i * 2)); } else { assertEquals(i, b.getShort(i * 2)); } } }
private void testSetShort(Buffer buff) throws Exception { for (int i = 0; i < numSets; i++) { buff.setShort(i * 2, (short) i); } for (int i = 0; i < numSets; i++) { assertEquals(i, buff.getShort(i * 2)); } }
@Override public Character decodeFromWire(int pos, Buffer buffer) { return (char)buffer.getShort(pos); }
@Override public Short decodeFromWire(int pos, Buffer buffer) { return buffer.getShort(pos); }
public static String readString(final Buffer buffer, final int[] location) { final short size = buffer.getShort(location[0]); int start = location[0] + 2; int end = start + size; final String utf_8 = buffer.getString(start, end, StandardCharsets.UTF_8.displayName()); location[0] = end; return utf_8; }
assertIndexOutOfBoundsException(() -> b.getDouble(-1)); assertIndexOutOfBoundsException(() -> b.getDouble(-100)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getShort(-1)); assertIndexOutOfBoundsException(() -> b.getShort(-100)); assertIndexOutOfBoundsException(() -> b.getBytes(bytesLen + 1, bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getBytes(bytesLen + 100, bytesLen + 100));
public static MultiMap<String, String> readMap(Buffer buffer, int[] locationHolder) { int location = locationHolder[0]; final short size = buffer.getShort(location); MultiMap<String, String> map = size > 0 ? new MultiMapImpl<>() : MultiMap.EMPTY; location += 2; locationHolder[0] = location; for (int index = 0; index < size; index++) { String key = readString(buffer, locationHolder); location = locationHolder[0]; short valuesSize = buffer.getShort(location); location += 2; locationHolder[0] = location; for (int valueIndex = 0; valueIndex < valuesSize; valueIndex++) { String value = readString(buffer, locationHolder); map.add(key, value); } } return map; }
private void testSetShort(Buffer buff) throws Exception { for (int i = 0; i < numSets; i++) { buff.setShort(i * 2, (short) i); } for (int i = 0; i < numSets; i++) { assertEquals(i, buff.getShort(i * 2)); } }
@Test public void testWriteString() throws Exception { Buffer buffer = Buffer.buffer(); BufferUtils.writeString(buffer, "hi mom"); final short size = buffer.getShort(0); ok = size == 6 || die(); final String utf_8 = buffer.getString(2, size + 2, StandardCharsets.UTF_8.displayName()); puts(utf_8); ok = utf_8.equals("hi mom") || die(); }
/** * Returns the <code>short</code> at position <code>pos</code> in the Buffer. * @param pos * @return */ public short getShort(int pos) { short ret = delegate.getShort(pos); return ret; }
/** * Returns the <code>short</code> at position <code>pos</code> in the Buffer. * @param pos * @return */ public short getShort(int pos) { short ret = delegate.getShort(pos); return ret; }
public static String readString(final Buffer buffer, final int[] location) { final short size = buffer.getShort(location[0]); int start = location[0] + 2; int end = start + size; final String utf_8 = buffer.getString(start, end, StandardCharsets.UTF_8.displayName()); location[0] = end; return utf_8; }
public static MultiMap<String, String> readMap(Buffer buffer, int[] locationHolder) { int location = locationHolder[0]; final short size = buffer.getShort(location); MultiMap<String, String> map = size > 0 ? new MultiMapImpl<>() : MultiMap.EMPTY; location += 2; locationHolder[0] = location; for (int index = 0; index < size; index++) { String key = readString(buffer, locationHolder); location = locationHolder[0]; short valuesSize = buffer.getShort(location); location += 2; locationHolder[0] = location; for (int valueIndex = 0; valueIndex < valuesSize; valueIndex++) { String value = readString(buffer, locationHolder); map.add(key, value); } } return map; }
assertIndexOutOfBoundsException(() -> b.getDouble(-1)); assertIndexOutOfBoundsException(() -> b.getDouble(-100)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getShort(-1)); assertIndexOutOfBoundsException(() -> b.getShort(-100)); assertIndexOutOfBoundsException(() -> b.getBytes(bytesLen + 1, bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getBytes(bytesLen + 100, bytesLen + 100));