本文整理了Java中io.vertx.core.buffer.Buffer.appendInt()
方法的一些代码示例,展示了Buffer.appendInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.appendInt()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:appendInt
[英]Appends the specified int to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.
Returns a reference to this so multiple operations can be appended together.
[中]将指定的int追加到缓冲区的末尾。缓冲区将根据需要扩展以容纳写入的任何字节。
返回对此的引用,以便可以将多个操作附加在一起。
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, Integer i) {
buffer.appendInt(i);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAppendInt() {
Buffer b = Buffer.buffer(TestUtils.randomByteArray(100));
b.appendInt(Integer.MAX_VALUE);
assertEquals(104, b.length());
b.appendIntLE(Integer.MAX_VALUE);
assertEquals(108, b.length());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, byte[] byteArray) {
buffer.appendInt(byteArray.length);
buffer.appendBytes(byteArray);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testLE() {
checkBEAndLE(2, Buffer.buffer().appendShort(Short.MAX_VALUE), Buffer.buffer().appendShortLE(Short.MAX_VALUE));
checkBEAndLE(2, Buffer.buffer().appendUnsignedShort(Short.MAX_VALUE), Buffer.buffer().appendUnsignedShortLE(Short.MAX_VALUE));
checkBEAndLE(3, Buffer.buffer().appendMedium(Integer.MAX_VALUE / 2), Buffer.buffer().appendMediumLE(Integer.MAX_VALUE / 2));
checkBEAndLE(4, Buffer.buffer().appendInt(Integer.MAX_VALUE), Buffer.buffer().appendIntLE(Integer.MAX_VALUE));
checkBEAndLE(4, Buffer.buffer().appendUnsignedInt(Integer.MAX_VALUE), Buffer.buffer().appendUnsignedIntLE(Integer.MAX_VALUE));
checkBEAndLE(8, Buffer.buffer().appendLong(Long.MAX_VALUE), Buffer.buffer().appendLongLE(Long.MAX_VALUE));
}
代码示例来源:origin: eclipse-vertx/vert.x
private void writeString(Buffer buff, String str) {
byte[] strBytes = str.getBytes(CharsetUtil.UTF_8);
buff.appendInt(strBytes.length);
buff.appendBytes(strBytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, String s) {
byte[] strBytes = s.getBytes(CharsetUtil.UTF_8);
buffer.appendInt(strBytes.length);
buffer.appendBytes(strBytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void writeToBuffer(Buffer buffer) {
String encoded = encode();
byte[] bytes = encoded.getBytes(StandardCharsets.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void writeToBuffer(Buffer buffer) {
String encoded = encode();
byte[] bytes = encoded.getBytes();
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void writeToBuffer(Buffer buff) {
buff.appendInt(this.length());
buff.appendBuffer(this);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, Buffer b) {
buffer.appendInt(b.length());
buffer.appendBuffer(b);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, JsonObject jsonObject) {
Buffer encoded = jsonObject.toBuffer();
buffer.appendInt(encoded.length());
buffer.appendBuffer(encoded);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void writeToBuffer(Buffer buffer) {
buffer.appendInt(str.length());
buffer.appendString(str);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, JsonArray jsonArray) {
Buffer encoded = jsonArray.toBuffer();
buffer.appendInt(encoded.length());
buffer.appendBuffer(encoded);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, ReplyException body) {
buffer.appendByte((byte)body.failureType().toInt());
buffer.appendInt(body.failureCode());
if (body.getMessage() == null) {
buffer.appendByte((byte)0);
} else {
buffer.appendByte((byte)1);
byte[] encoded = body.getMessage().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(encoded.length);
buffer.appendBytes(encoded);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
private Buffer loadJsonAsBuffer(URL url) {
try {
Buffer encoded = new JsonObject(Json.mapper.readValue(url, Map.class)).toBuffer();
return Buffer.buffer().appendInt(encoded.length()).appendBuffer(encoded);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, MyPOJO myPOJO) {
byte[] bytes = myPOJO.getStr().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, MyPOJO myPOJO) {
byte[] bytes = myPOJO.getStr().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
private void viaString(JsonObject jsonObject) throws Exception {
Buffer buffer = Buffer.buffer();
String strJson = jsonObject.encode();
byte[] encoded = strJson.getBytes(CharsetUtil.UTF_8);
buffer.appendInt(encoded.length);
Buffer buff = Buffer.buffer(encoded);
buffer.appendBuffer(buff);
consume(buffer);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, MyReplyException body) {
buffer.appendInt(body.failureCode());
if (body.getMessage() == null) {
buffer.appendByte((byte)0);
} else {
buffer.appendByte((byte)1);
byte[] encoded = body.getMessage().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(encoded.length);
buffer.appendBytes(encoded);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
private void direct(JsonObject jsonObject) throws Exception {
Buffer buffer = Buffer.buffer();
Buffer encoded = jsonObject.toBuffer();
buffer.appendInt(encoded.length());
buffer.appendBuffer(encoded);
consume(buffer);
}
}
内容来源于网络,如有侵权,请联系作者删除!