private void testSetInt(Buffer buff) throws Exception { for (int i = 0; i < numSets; i++) { buff.setInt(i * 4, i); } for (int i = 0; i < numSets; i++) { assertEquals(i, buff.getInt(i * 4)); } }
private void testGetSetInt(boolean isLE) throws Exception { int numInts = 100; Buffer b = Buffer.buffer(numInts * 4); for (int i = 0; i < numInts; i++) { if (isLE) { b.setIntLE(i * 4, i); } else { b.setInt(i * 4, i); } } for (int i = 0; i < numInts; i++) { if (isLE) { assertEquals(i, b.getIntLE(i * 4)); } else { assertEquals(i, b.getInt(i * 4)); } } }
@Override public BatchStream write(Batch batch) { if (batch == null) { if (exceptionHandler != null) { exceptionHandler.handle(new NullPointerException()); } } else { Buffer protocol = Buffer.buffer(); protocol.appendInt(0); protocol.appendByte((byte) batch.getType()); protocol.appendBuffer(batch.getRaw()); protocol.setInt(0, protocol.length() - 4); writeStream.write(protocol); } return this; }
private void testGetSetInt(boolean isLE) throws Exception { int numInts = 100; Buffer b = Buffer.buffer(numInts * 4); for (int i = 0; i < numInts; i++) { if (isLE) { b.setIntLE(i * 4, i); } else { b.setInt(i * 4, i); } } for (int i = 0; i < numInts; i++) { if (isLE) { assertEquals(i, b.getIntLE(i * 4)); } else { assertEquals(i, b.getInt(i * 4)); } } }
@Test public void testSetGetInt() throws Exception { final int size = 10; Buffer buffer = Buffer.buffer(size); for (int i = 0; i < size; i++) { buffer.setInt(i * 4, (i + 1) * 10); } for (int i = 0; i < size; i++) { assertEquals((i + 1) * 10, buffer.getInt(i * 4)); } }
private void encodeHeaders(Buffer buffer) { if (headers != null && !headers.isEmpty()) { int headersLengthPos = buffer.length(); buffer.appendInt(0); buffer.appendInt(headers.size()); List<Map.Entry<String, String>> entries = headers.entries(); for (Map.Entry<String, String> entry: entries) { writeString(buffer, entry.getKey()); writeString(buffer, entry.getValue()); } int headersEndPos = buffer.length(); buffer.setInt(headersLengthPos, headersEndPos - headersLengthPos); } else { buffer.appendInt(4); } }
public Buffer encodeToWire() { int length = 1024; // TODO make this configurable Buffer buffer = Buffer.buffer(length); buffer.appendInt(0); buffer.appendByte(WIRE_PROTOCOL_VERSION); byte systemCodecID = messageCodec.systemCodecID(); buffer.appendByte(systemCodecID); if (systemCodecID == -1) { // User codec writeString(buffer, messageCodec.name()); } buffer.appendByte(send ? (byte)0 : (byte)1); writeString(buffer, address); if (replyAddress != null) { writeString(buffer, replyAddress); } else { buffer.appendInt(0); } buffer.appendInt(sender.port); writeString(buffer, sender.host); encodeHeaders(buffer); writeBody(buffer); buffer.setInt(0, buffer.length() - 4); return buffer; }
@Test public void testCopy() throws Exception { Buffer buff = TestUtils.randomBuffer(100); assertEquals(buff, buff.copy()); Buffer copy = buff.getBuffer(0, buff.length()); assertEquals(buff, copy); //Make sure they don't share underlying buffer Buffer copy2 = buff.copy(); buff.setInt(0, 1); assertEquals(copy, copy2); }
@Test public void testIdleTimeoutInfiniteSkipOfControlCharactersState() throws Exception { server.close(); server = vertx.createHttpServer(new HttpServerOptions() .setPort(DEFAULT_HTTP_PORT) .setHost(DEFAULT_HTTP_HOST) .setIdleTimeout(1)); server.requestHandler(req -> { testComplete(); }); startServer(); NetClient client = vertx.createNetClient(); client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(so -> { long id = vertx.setPeriodic(1, timerID -> { so.write(Buffer.buffer().setInt(0, 0xD)); }); so.closeHandler(v -> { vertx.cancelTimer(id); testComplete(); }); })); await(); }
@Test public void testSetOutOfBounds() throws Exception { Buffer b = Buffer.buffer(numSets); assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0)); assertIndexOutOfBoundsException(() -> b.setInt(-1, 0)); assertIndexOutOfBoundsException(() -> b.setLong(-1, 0)); assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0)); assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0)); assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1))); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1)); assertIndexOutOfBoundsException(() -> b.setString(-1, "")); assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8")); }
private void testSetInt(Buffer buff) throws Exception { for (int i = 0; i < numSets; i++) { buff.setInt(i * 4, i); } for (int i = 0; i < numSets; i++) { assertEquals(i, buff.getInt(i * 4)); } }
@Test public void testSetGetInt() throws Exception { final int size = 10; Buffer buffer = Buffer.buffer(size); for (int i = 0; i < size; i++) { buffer.setInt(i * 4, (i + 1) * 10); } for (int i = 0; i < size; i++) { assertEquals((i + 1) * 10, buffer.getInt(i * 4)); } }
private void encodeHeaders(Buffer buffer) { if (headers != null && !headers.isEmpty()) { int headersLengthPos = buffer.length(); buffer.appendInt(0); buffer.appendInt(headers.size()); List<Map.Entry<String, String>> entries = headers.entries(); for (Map.Entry<String, String> entry: entries) { writeString(buffer, entry.getKey()); writeString(buffer, entry.getValue()); } int headersEndPos = buffer.length(); buffer.setInt(headersLengthPos, headersEndPos - headersLengthPos); } else { buffer.appendInt(4); } }
/** * Sets the <code>int</code> at position <code>pos</code> in the Buffer to the value <code>i</code>.<p> * The buffer will expand as necessary to accommodate any value written. * @param pos * @param i * @return */ public io.vertx.rxjava.core.buffer.Buffer setInt(int pos, int i) { delegate.setInt(pos, i); return this; }
/** * Sets the <code>int</code> at position <code>pos</code> in the Buffer to the value <code>i</code>.<p> * The buffer will expand as necessary to accommodate any value written. * @param pos * @param i * @return */ public io.vertx.rxjava.core.buffer.Buffer setInt(int pos, int i) { delegate.setInt(pos, i); return this; }
@Override public void setInt(int i, int value) { buffer.setInt(i, value); }
public Buffer encodeToWire() { int length = 1024; // TODO make this configurable Buffer buffer = Buffer.buffer(length); buffer.appendInt(0); buffer.appendByte(WIRE_PROTOCOL_VERSION); byte systemCodecID = messageCodec.systemCodecID(); buffer.appendByte(systemCodecID); if (systemCodecID == -1) { // User codec writeString(buffer, messageCodec.name()); } buffer.appendByte(send ? (byte)0 : (byte)1); writeString(buffer, address); if (replyAddress != null) { writeString(buffer, replyAddress); } else { buffer.appendInt(0); } buffer.appendInt(sender.port); writeString(buffer, sender.host); encodeHeaders(buffer); writeBody(buffer); buffer.setInt(0, buffer.length() - 4); return buffer; }
@Test public void testCopy() throws Exception { Buffer buff = TestUtils.randomBuffer(100); assertEquals(buff, buff.copy()); Buffer copy = buff.getBuffer(0, buff.length()); assertEquals(buff, copy); //Make sure they don't share underlying buffer Buffer copy2 = buff.copy(); buff.setInt(0, 1); assertEquals(copy, copy2); }
@Test public void testIdleTimeoutInfiniteSkipOfControlCharactersState() throws Exception { server.close(); server = vertx.createHttpServer(new HttpServerOptions() .setPort(DEFAULT_HTTP_PORT) .setHost(DEFAULT_HTTP_HOST) .setIdleTimeout(1)); server.requestHandler(req -> { testComplete(); }); startServer(); NetClient client = vertx.createNetClient(); client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(so -> { long id = vertx.setPeriodic(1, timerID -> { so.write(Buffer.buffer().setInt(0, 0xD)); }); so.closeHandler(v -> { vertx.cancelTimer(id); testComplete(); }); })); await(); }
@Test public void testSetOutOfBounds() throws Exception { Buffer b = Buffer.buffer(numSets); assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0)); assertIndexOutOfBoundsException(() -> b.setInt(-1, 0)); assertIndexOutOfBoundsException(() -> b.setLong(-1, 0)); assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0)); assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0)); assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1))); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1)); assertIndexOutOfBoundsException(() -> b.setString(-1, "")); assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8")); }