本文整理了Java中io.netty.buffer.ByteBuf.writerIndex()
方法的一些代码示例,展示了ByteBuf.writerIndex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.writerIndex()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:writerIndex
[英]Returns the writerIndex of this buffer.
[中]返回此缓冲区的writerIndex。
代码示例来源:origin: neo4j/neo4j
private void startNewChunk()
{
currentChunkStartIndex = buffer.writerIndex();
// write empty chunk header
buffer.writeShort( 0 );
chunkOpen = true;
}
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(int type, ByteBuf content) {
ByteBuf buf = Unpooled.buffer();
buf.writeShort(1 + content.readableBytes());
buf.writeByte(100 + type);
buf.writeBytes(content);
buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.nioBuffer(2, buf.writerIndex() - 2)));
return buf;
}
代码示例来源:origin: qunarcorp/qmq
@Override
protected void encode(ChannelHandlerContext ctx, Datagram msg, ByteBuf out) throws Exception {
int start = out.writerIndex();
int headerStart = start + RemotingHeader.LENGTH_FIELD;
out.ensureWritable(RemotingHeader.LENGTH_FIELD);
out.writerIndex(headerStart);
final RemotingHeader header = msg.getHeader();
encodeHeader(header, out);
int headerSize = out.writerIndex() - headerStart;
msg.writeBody(out);
int end = out.writerIndex();
int total = end - start - RemotingHeader.TOTAL_SIZE_LEN;
out.writerIndex(start);
out.writeInt(total);
out.writeShort((short) headerSize);
out.writerIndex(end);
}
代码示例来源: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);
final int bodyStart = out.writerIndex() + 4;
out.ensureWritable(4);
out.writerIndex(bodyStart);
final int bodyEnd = out.writerIndex();
final int messageEnd = out.writerIndex();
out.writeInt(bodyLen);
out.writerIndex(crcIndex);
out.writeLong(messageCrc(out, messageStart, messageLength));
out.writerIndex(messageEnd);
代码示例来源: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 sendResponse(Channel channel) {
if (channel != null) {
ByteBuf response = Unpooled.buffer(2 * BLOCK_LENGTH);
response.writeByte(At2000ProtocolDecoder.MSG_ACKNOWLEDGEMENT);
response.writeMedium(1);
response.writeByte(0x00); // success
response.writerIndex(2 * BLOCK_LENGTH);
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
代码示例来源:origin: traccar/traccar
private static void sendResponse(Channel channel, ByteBuf buf) {
if (channel != null) {
ByteBuf response = Unpooled.buffer(4);
response.writeByte('*');
response.writeShort(buf.getUnsignedShort(buf.writerIndex() - 2));
response.writeByte(buf.getUnsignedByte(buf.writerIndex() - 3));
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
代码示例来源:origin: org.opendaylight.bgpcep/pcep-spi
public static void formatTlv(final int type,final ByteBuf body, final ByteBuf out) {
out.writeShort(type);
out.writeShort(body.writerIndex());
out.writeBytes(body);
out.writeZero(getPadding(HEADER_SIZE + body.writerIndex(), PADDED_TO));
}
代码示例来源: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: wildfly/wildfly
public void encodeHeadersAndProperties(final ByteBuf buffer) {
checkProperties();
messageIDPosition = buffer.writerIndex();
buffer.writeLong(messageID);
SimpleString.writeNullableSimpleString(buffer, address);
if (userID == null) {
buffer.writeByte(DataConstants.NULL);
} else {
buffer.writeByte(DataConstants.NOT_NULL);
buffer.writeBytes(userID.asBytes());
}
buffer.writeByte(type);
buffer.writeBoolean(durable);
buffer.writeLong(expiration);
buffer.writeLong(timestamp);
buffer.writeByte(priority);
properties.encode(buffer);
}
代码示例来源:origin: wildfly/wildfly
out.writeShort((short) len);
out.ensureWritable(len);
final byte[] bytes = out.array();
final int writerIndex = out.writerIndex();
final int index = out.arrayOffset() + writerIndex;
if (PlatformDependent.hasUnsafe()) {
writeUTF(str, bytes, index, stringLength);
out.writerIndex(writerIndex + len);
} else {
if (PlatformDependent.hasUnsafe() && out.hasMemoryAddress()) {
out.ensureWritable(len);
final long addressBytes = out.memoryAddress();
final int writerIndex = out.writerIndex();
unsafeOffHeapWriteUTF(str, addressBytes, writerIndex, stringLength);
out.writerIndex(writerIndex + len);
} else {
final StringUtilBuffer buffer = UTF8Util.getThreadLocalBuffer();
代码示例来源:origin: kompics/kompics
ByteBuf out = ctx.alloc().buffer(NettyNetwork.INITIAL_BUFFER_SIZE, NettyNetwork.SEND_BUFFER_SIZE);
component.extLog.trace("Trying to encode outgoing data to {} from {}: {}.", ctx.channel().remoteAddress(), ctx.channel().localAddress(), msgw.msg.getClass());
int startIdx = out.writerIndex();
out.writeBytes(LENGTH_PLACEHOLDER);
int endIdx = out.writerIndex();
int diff = endIdx - startIdx - LENGTH_PLACEHOLDER.length;
if (diff > 65532) { //2^16 - 2bytes for the length header (snappy wants no more than 65536 bytes uncompressed)
throw new Exception("Can't encode message longer than 65532 bytes!");
out.setShort(startIdx, diff);
代码示例来源:origin: org.apache.cassandra/cassandra-all
public static void writeString(String str, ByteBuf cb)
{
int writerIndex = cb.writerIndex();
cb.writeShort(0);
int lengthBytes = ByteBufUtil.writeUtf8(cb, str);
cb.setShort(writerIndex, lengthBytes);
}
代码示例来源:origin: digitalpetri/ethernet-ip
private void encode(ByteBuf buffer) {
int serviceCount = currentServices.size();
buffer.writeShort(serviceCount);
int[] offsets = new int[serviceCount];
int offsetsStartIndex = buffer.writerIndex();
buffer.writeZero(serviceCount * 2);
for (int i = 0; i < serviceCount; i++) {
offsets[i] = buffer.writerIndex() - offsetsStartIndex + 2;
currentServices.get(i).encodeRequest(buffer);
}
buffer.markWriterIndex();
buffer.writerIndex(offsetsStartIndex);
for (int offset : offsets) {
buffer.writeShort(offset);
}
buffer.resetWriterIndex();
}
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(long deviceId, int command, int data1, int data2) {
ByteBuf buf = Unpooled.buffer(0);
buf.writeByte('M');
buf.writeByte('C');
buf.writeByte('G');
buf.writeByte('P');
buf.writeByte(0);
buf.writeIntLE(Integer.parseInt(getUniqueId(deviceId)));
buf.writeByte(0); // command numerator
buf.writeIntLE(0); // authentication code
buf.writeByte(command);
buf.writeByte(command);
buf.writeByte(data1);
buf.writeByte(data1);
buf.writeByte(data2);
buf.writeByte(data2);
buf.writeIntLE(0); // command specific data
byte checksum = 0;
for (int i = 4; i < buf.writerIndex(); i++) {
checksum += buf.getByte(i);
}
buf.writeByte(checksum);
return buf;
}
代码示例来源:origin: netty/netty
final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH);
final int outputIdx = out.writerIndex();
out.setMedium(outputIdx, MAGIC_NUMBER);
int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0);
chunkLength = compressedLength;
out.setShort(outputOffset, chunkLength);
outputOffset += 2;
} else {
out.setShort(outputOffset, length);
out.writerIndex(outputOffset + 2 + chunkLength);
in.skipBytes(length);
代码示例来源: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.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: redisson/redisson
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 static void sendRequest(Channel channel) {
if (channel != null) {
ByteBuf response = Unpooled.buffer(BLOCK_LENGTH);
response.writeByte(MSG_TRACK_REQUEST);
response.writeMedium(0);
response.writerIndex(BLOCK_LENGTH);
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
内容来源于网络,如有侵权,请联系作者删除!