本文整理了Java中io.netty.buffer.ByteBuf.setShort()
方法的一些代码示例,展示了ByteBuf.setShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.setShort()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:setShort
[英]Sets the specified 16-bit short integer at the specified absolute index in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modify readerIndex or writerIndex of this buffer.
[中]在此缓冲区中指定的绝对索引处设置指定的16位短整数。指定值的16个高位将被忽略。此方法不修改此缓冲区的readerIndex或writerIndex。
代码示例来源: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: com.netflix.sstableadaptor/sstable-adaptor-cassandra
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: org.opendaylight.openflowjava/openflow-protocol-impl
protected void writeActions(final List<Action> actions, final ByteBuf outBuffer, int startIndex) {
int lengthIndex = outBuffer.writerIndex();
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
ListSerializer.serializeList(actions, ACTION_KEY_MAKER, getRegistry(), outBuffer);
int instructionLength = outBuffer.writerIndex() - startIndex;
outBuffer.setShort(lengthIndex, instructionLength);
}
代码示例来源: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.carbondata/carbondata-core
public void writeData(ByteBuf byteBuf) {
int startIndex = byteBuf.writerIndex();
// Just reserve the bytes to add length of header at last.
byteBuf.writeShort(Short.MAX_VALUE);
byte[] tableIdBytes =
tableUniqueId.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
byteBuf.writeInt(tableIdBytes.length);
byteBuf.writeBytes(tableIdBytes);
byte[] colBytes = columnName.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
byteBuf.writeInt(colBytes.length);
byteBuf.writeBytes(colBytes);
byteBuf.writeByte(type.getType());
if (dictionaryValue > 0) {
byteBuf.writeByte(0);
byteBuf.writeInt(dictionaryValue);
} else {
byteBuf.writeByte(1);
byte[] dataBytes = data.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
byteBuf.writeInt(dataBytes.length);
byteBuf.writeBytes(dataBytes);
}
int endIndex = byteBuf.writerIndex();
// Add the length of message at the starting.it is required while decoding as in TCP protocol
// it not guarantee that we receive all data in one packet, so we need to wait to receive all
// packets before proceeding to process the message.Based on the length it waits.
byteBuf.setShort(startIndex, endIndex - startIndex - 2);
}
代码示例来源:origin: redisson/redisson
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: com.strapdata.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: org.opendaylight.openflowjava/openflow-protocol-impl
private static void writeNextTableRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property,
final byte code) {
int startIndex = output.writerIndex();
output.writeShort(code);
int lengthIndex = output.writerIndex();
output.writeShort(EncodeConstants.EMPTY_LENGTH);
List<NextTableIds> nextTableIds = property.getAugmentation(NextTableRelatedTableFeatureProperty.class)
.getNextTableIds();
if (nextTableIds != null) {
for (NextTableIds next : nextTableIds) {
output.writeByte(next.getTableId());
}
}
int length = output.writerIndex() - startIndex;
output.setShort(lengthIndex, length);
output.writeZero(paddingNeeded(length));
}
代码示例来源:origin: wildfly/wildfly
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: 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: org.opendaylight.openflowjava/openflow-protocol-impl
private static void writeNextTableRelatedTableProperty(final ByteBuf output,
final TableFeatureProperties property, final byte code) {
int startIndex = output.writerIndex();
output.writeShort(code);
int lengthIndex = output.writerIndex();
output.writeShort(EncodeConstants.EMPTY_LENGTH);
List<NextTableIds> nextTableIds = property.
getAugmentation(NextTableRelatedTableFeatureProperty.class).getNextTableIds();
if (nextTableIds != null) {
for (NextTableIds next : nextTableIds) {
output.writeByte(next.getTableId());
}
}
int length = output.writerIndex() - startIndex;
output.setShort(lengthIndex, length);
output.writeZero(paddingNeeded(length));
}
代码示例来源:origin: org.neo4j/neo4j-bolt-transport-socket
private void closeChunkIfOpen()
{
if ( chunkOpen )
{
int chunkSize = buffer.writerIndex() - (currentChunkHeaderOffset + CHUNK_HEADER_SIZE);
buffer.setShort( currentChunkHeaderOffset, chunkSize );
chunkOpen = false;
}
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(Match match, ByteBuf outBuffer) {
if (match == null) {
LOG.debug("Match is null");
return;
}
int matchStartIndex = outBuffer.writerIndex();
serializeType(match, outBuffer);
int matchLengthIndex = outBuffer.writerIndex();
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
serializeMatchEntries(match.getMatchEntry(), outBuffer);
// Length of ofp_match (excluding padding)
int matchLength = outBuffer.writerIndex() - matchStartIndex;
outBuffer.setShort(matchLengthIndex, matchLength);
int paddingRemainder = matchLength % EncodeConstants.PADDING;
if (paddingRemainder != 0) {
outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
}
}
代码示例来源:origin: org.neo4j/neo4j-ndp-transport-socket
private void closeChunkIfOpen()
{
if ( chunkOpen )
{
int chunkSize = buffer.writerIndex() - (currentChunkHeaderOffset + CHUNK_HEADER_SIZE);
buffer.setShort( currentChunkHeaderOffset, chunkSize );
chunkOpen = false;
}
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
private void serializerBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
if (buckets != null) {
for (BucketsList currentBucket : buckets) {
int bucketLengthIndex = outBuffer.writerIndex();
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
outBuffer.writeShort(currentBucket.getWeight().shortValue());
outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());
outBuffer.writeInt(currentBucket.getWatchGroup().intValue());
outBuffer.writeZero(PADDING_IN_BUCKET);
ListSerializer.serializeList(currentBucket.getAction(), TypeKeyMakerFactory
.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex);
}
}
}
代码示例来源:origin: io.netty/netty-codec
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: org.opendaylight.openflowjava/openflow-protocol-impl
private void writeActionsRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property,
final byte code) {
int startIndex = output.writerIndex();
output.writeShort(code);
int lengthIndex = output.writerIndex();
output.writeShort(EncodeConstants.EMPTY_LENGTH);
List<Action> actions = property.getAugmentation(ActionRelatedTableFeatureProperty.class).getAction();
if (actions != null) {
TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
ListSerializer.serializeHeaderList(actions, keyMaker, registry, output);
}
int length = output.writerIndex() - startIndex;
output.setShort(lengthIndex, length);
output.writeZero(paddingNeeded(length));
}
代码示例来源:origin: apache/activemq-artemis
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: org.opendaylight.openflowjava/openflow-protocol-impl
private void serializeQueueBody(MultipartReplyBody body, ByteBuf outBuffer) {
MultipartReplyQueueCase queueCase = (MultipartReplyQueueCase) body;
MultipartReplyQueue queue = queueCase.getMultipartReplyQueue();
for (QueueStats queueStats : queue.getQueueStats()) {
ByteBuf queueStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
queueStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
queueStatsBuff.writeZero(QUEUE_PADDING);
queueStatsBuff.writeInt(queueStats.getQueueId().intValue());
queueStatsBuff.writeLong(queueStats.getTxBytes().longValue());
queueStatsBuff.writeLong(queueStats.getTxPackets().longValue());
queueStatsBuff.writeLong(queueStats.getTxErrors().longValue());
queueStatsBuff.setShort(QUEUE_STATS_LENGTH_INDEX, queueStatsBuff.readableBytes());
outBuffer.writeBytes(queueStatsBuff);
}
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
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);
内容来源于网络,如有侵权,请联系作者删除!