本文整理了Java中io.netty.buffer.ByteBuf.writeInt()
方法的一些代码示例,展示了ByteBuf.writeInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.writeInt()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:writeInt
[英]Sets the specified 32-bit integer at the current writerIndexand increases the writerIndex by 4 in this buffer.
[中]在当前writerIndex处设置指定的32位整数,并在此缓冲区中将writerIndex增加4。
代码示例来源:origin: wildfly/wildfly
@Override
public void write(final ByteBuf buffer) {
buffer.writeByte(DataConstants.INT);
buffer.writeInt(val);
}
代码示例来源:origin: alibaba/Sentinel
private void encodeString(String param, ByteBuf target) {
target.writeByte(ClusterConstants.PARAM_TYPE_STRING);
byte[] tmpChars = param.getBytes();
target.writeInt(tmpChars.length);
target.writeBytes(tmpChars);
}
代码示例来源:origin: netty/netty
/**
* Writes any remaining bits to the output {@link ByteBuf},
* zero padding to a whole byte as required.
*/
void flush(ByteBuf out) {
final int bitCount = this.bitCount;
if (bitCount > 0) {
final long bitBuffer = this.bitBuffer;
final int shiftToRight = 64 - bitCount;
if (bitCount <= 8) {
out.writeByte((int) (bitBuffer >>> shiftToRight << 8 - bitCount));
} else if (bitCount <= 16) {
out.writeShort((int) (bitBuffer >>> shiftToRight << 16 - bitCount));
} else if (bitCount <= 24) {
out.writeMedium((int) (bitBuffer >>> shiftToRight << 24 - bitCount));
} else {
out.writeInt((int) (bitBuffer >>> shiftToRight << 32 - bitCount));
}
}
}
}
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(String content) {
ByteBuf buf = Unpooled.buffer();
buf.writeInt(0);
buf.writeInt(content.length() + 10);
buf.writeByte(TeltonikaProtocolDecoder.CODEC_12);
buf.writeByte(1); // quantity
buf.writeByte(5); // type
buf.writeInt(content.length() + 2);
buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
buf.writeByte('\r');
buf.writeByte('\n');
buf.writeByte(1); // quantity
buf.writeInt(Checksum.crc16(Checksum.CRC16_IBM, buf.nioBuffer(8, buf.writerIndex() - 8)));
return buf;
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(GetFeaturesOutput message, ByteBuf outBuffer) {
ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
outBuffer.writeLong(message.getDatapathId().longValue());
outBuffer.writeInt(message.getBuffers().intValue());
outBuffer.writeByte(message.getTables().intValue());
outBuffer.writeByte(message.getAuxiliaryId().intValue());
outBuffer.writeZero(PADDING);
writeCapabilities(message.getCapabilities(), outBuffer);
outBuffer.writeInt(message.getReserved().intValue());
ByteBufUtils.updateOFHeaderLength(outBuffer);
}
代码示例来源:origin: qunarcorp/qmq
private void serializeMessage(BaseMessage message, ByteBuf out) {
int crcIndex = out.writerIndex();
out.writerIndex(crcIndex + 8);
final int messageStart = out.writerIndex();
flag = Flags.setTags(flag, hasTags(tags));
out.writeByte(flag);
out.writeInt(bodyLen);
代码示例来源:origin: mpusher/mpush
public void encodeBytes(ByteBuf body, byte[] field) {
if (field == null || field.length == 0) {
body.writeShort(0);
} else if (field.length < Short.MAX_VALUE) {
body.writeShort(field.length).writeBytes(field);
} else {
body.writeShort(Short.MAX_VALUE).writeInt(field.length - Short.MAX_VALUE).writeBytes(field);
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Recast the message as an 1.4 message
*/
@Override
public void sendBuffer_1X(ByteBuf sendBuffer) {
checkEncode();
ByteBuf tmpBuffer = buffer.duplicate();
sendBuffer.writeInt(endOfBodyPosition + DataConstants.SIZE_INT);
tmpBuffer.readerIndex(DataConstants.SIZE_INT);
tmpBuffer.readBytes(sendBuffer, endOfBodyPosition - BUFFER_HEADER_SPACE);
sendBuffer.writeInt(tmpBuffer.writerIndex() + DataConstants.SIZE_INT + BUFFER_HEADER_SPACE);
tmpBuffer.readBytes(sendBuffer, tmpBuffer.readableBytes());
sendBuffer.readerIndex(0);
}
代码示例来源:origin: netty/netty
if (dataLength > MIN_COMPRESSIBLE_LENGTH) {
for (;;) {
final int lengthIdx = out.writerIndex() + 1;
if (dataLength < MIN_COMPRESSIBLE_LENGTH) {
ByteBuf slice = in.readSlice(dataLength);
out.writeInt(0);
if (dataLength > Short.MAX_VALUE) {
ByteBuf slice = in.readSlice(Short.MAX_VALUE);
代码示例来源:origin: traccar/traccar
private void sendPhotoRequest(Channel channel, int pictureId) {
ByteBuf photo = photos.get(pictureId);
ByteBuf content = Unpooled.buffer();
content.writeInt(pictureId);
content.writeInt(photo.writerIndex());
content.writeShort(Math.min(photo.writableBytes(), 1024));
sendResponse(channel, false, MSG_X1_PHOTO_DATA, 0, content);
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
private static void serializeQueueBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
MultipartRequestQueueCase queueCase = (MultipartRequestQueueCase) multipartRequestBody;
MultipartRequestQueue queue = queueCase.getMultipartRequestQueue();
output.writeShort(queue.getPortNo().intValue());
output.writeZero(PADING_IN_QUEUE_BODY);
output.writeInt(queue.getQueueId().intValue());
}
代码示例来源:origin: atomix/atomix
/**
* Writes the protocol version to the given context.
*
* @param context the context to which to write the version
* @param version the version to write
*/
void writeProtocolVersion(ChannelHandlerContext context, ProtocolVersion version) {
ByteBuf buffer = context.alloc().buffer(6);
buffer.writeInt(preamble);
buffer.writeShort(version.version());
context.writeAndFlush(buffer);
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
private static void serializeMeterBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
MultipartRequestMeterCase meterCase = (MultipartRequestMeterCase) multipartRequestBody;
MultipartRequestMeter meter = meterCase.getMultipartRequestMeter();
output.writeInt(meter.getMeterId().getValue().intValue());
output.writeZero(PADDING_IN_MULTIPART_REQUEST_METER_BODY);
}
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(int type, ByteBuf content) {
ByteBuf buf = Unpooled.buffer();
buf.writeByte('S');
buf.writeByte('S');
buf.writeShort(2 + 2 + 2 + content.readableBytes() + 4 + 2 + 2);
buf.writeShort(type);
buf.writeBytes(content);
buf.writeInt(0x0B);
buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
return buf;
}
代码示例来源:origin: wildfly/wildfly
@Override
public void write(final ByteBuf buffer) {
buffer.writeByte(DataConstants.BYTES);
buffer.writeInt(val.length);
buffer.writeBytes(val);
}
代码示例来源:origin: mpusher/mpush
public byte calcLrc() {
byte[] data = Unpooled.buffer(HEADER_LEN - 1)
.writeInt(getBodyLength())
.writeByte(cmd)
.writeShort(cc)
.writeByte(flags)
.writeInt(sessionId)
.array();
byte lrc = 0;
for (int i = 0; i < data.length; i++) {
lrc ^= data[i];
}
return lrc;
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
private void serializeTableBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
MultipartReplyTableCase tableCase = (MultipartReplyTableCase) body;
MultipartReplyTable table = tableCase.getMultipartReplyTable();
for (TableStats tableStats : table.getTableStats()) {
outBuffer.writeByte(tableStats.getTableId());
outBuffer.writeZero(TABLE_PADDING);
outBuffer.writeInt(tableStats.getActiveCount().intValue());
outBuffer.writeLong(tableStats.getLookupCount().longValue());
outBuffer.writeLong(tableStats.getMatchedCount().longValue());
}
}
代码示例来源:origin: org.restcomm.protocols.ss7.m3ua/m3ua-impl
public void encode(ByteBuf byteBuf) {
byteBuf.writeByte(1);
byteBuf.writeByte(0);
byteBuf.writeByte(messageClass);
byteBuf.writeByte(messageType);
byteBuf.markWriterIndex();
byteBuf.writeInt(8);
int currIndex=byteBuf.writerIndex();
encodeParams(byteBuf);
int newIndex=byteBuf.writerIndex();
byteBuf.resetWriterIndex();
byteBuf.writeInt(newIndex-currIndex + 8);
byteBuf.writerIndex(newIndex);
}
代码示例来源:origin: wildfly/wildfly
@Override
public void write(final ByteBuf buffer) {
buffer.writeByte(DataConstants.FLOAT);
buffer.writeInt(Float.floatToIntBits(val));
}
代码示例来源:origin: redisson/redisson
@Override
public ByteBuf encode(Object in) throws IOException {
ByteBuf buf = innerCodec.getValueEncoder().encode(in);
ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
try {
int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE);
for (int i = 1; i <= chunksAmount; i++) {
int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes());
ByteBuf chunk = buf.readSlice(chunkSize);
int lenIndex = out.writerIndex();
out.writeInt(0);
snappyEncoder.get().encode(chunk, out, chunk.readableBytes());
int compressedDataLength = out.writerIndex() - 4 - lenIndex;
out.setInt(lenIndex, compressedDataLength);
}
return out;
} finally {
buf.release();
snappyEncoder.get().reset();
}
}
};
内容来源于网络,如有侵权,请联系作者删除!