io.vertx.core.buffer.Buffer.setInt()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中io.vertx.core.buffer.Buffer.setInt()方法的一些代码示例,展示了Buffer.setInt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.setInt()方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:setInt

Buffer.setInt介绍

[英]Sets the int at position pos in the Buffer to the value i.

The buffer will expand as necessary to accommodate any value written.
[中]将缓冲区中位置pos处的int设置为值i。
缓冲区将根据需要扩展以容纳任何写入的值。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

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));
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

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));
  }
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@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;
}

代码示例来源:origin: io.vertx/vertx-core

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));
  }
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@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));
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

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);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

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;
}

代码示例来源:origin: eclipse-vertx/vert.x

@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);
}

代码示例来源:origin: eclipse-vertx/vert.x

@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();
}

代码示例来源:origin: eclipse-vertx/vert.x

@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"));
}

代码示例来源:origin: io.vertx/vertx-core

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));
 }
}

代码示例来源:origin: io.vertx/vertx-core

@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));
 }
}

代码示例来源:origin: io.vertx/vertx-core

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);
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * 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;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * 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;
}

代码示例来源:origin: net.consensys.cava/cava-bytes

@Override
public void setInt(int i, int value) {
 buffer.setInt(i, value);
}

代码示例来源:origin: io.vertx/vertx-core

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;
}

代码示例来源:origin: io.vertx/vertx-core

@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);
}

代码示例来源:origin: io.vertx/vertx-core

@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();
}

代码示例来源:origin: io.vertx/vertx-core

@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"));
}

相关文章