本文整理了Java中io.netty.buffer.ByteBuf.writeZero()
方法的一些代码示例,展示了ByteBuf.writeZero()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.writeZero()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:writeZero
[英]Fills this buffer with NUL (0x00) starting at the current writerIndex and increases the writerIndex by the specified length.
[中]使用从当前writerIndex开始的NUL(0x00)填充此缓冲区,并将writerIndex增加指定的长度。
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(long deviceId, short type, ByteBuf content) {
ByteBuf buf = Unpooled.buffer(0);
String uniqueId = Context.getIdentityManager().getById(deviceId).getUniqueId();
buf.writeByte('@');
buf.writeByte('@');
buf.writeShortLE(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length
buf.writeByte(1); // protocol version
buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII));
buf.writeZero(20 - uniqueId.length());
buf.writeShort(type);
buf.writeBytes(content);
buf.writeShortLE(Checksum.crc16(Checksum.CRC16_X25, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
return buf;
}
代码示例来源:origin: traccar/traccar
private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) {
if (channel != null) {
ByteBuf reply = Unpooled.buffer(28);
reply.writeByte('M');
reply.writeByte('C');
reply.writeByte('G');
reply.writeByte('P');
reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
reply.writeIntLE((int) deviceId);
reply.writeByte(commandCount++);
reply.writeIntLE(0); // authentication code
reply.writeByte(0);
reply.writeByte(packetNumber);
reply.writeZero(11);
byte checksum = 0;
for (int i = 4; i < 27; i++) {
checksum += reply.getByte(i);
}
reply.writeByte(checksum);
channel.writeAndFlush(new NetworkMessage(reply, 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: org.opendaylight.bgpcep/bgp-linkstate
public static void serializePrefixAttributes(final Flags flags, final Algorithm algorithm, final SidLabelIndex sidLabelIndex, final ByteBuf buffer) {
final BitArray bitFlags = serializePrefixFlags(flags, sidLabelIndex);
bitFlags.toByteBuf(buffer);
buffer.writeByte(algorithm.getIntValue());
buffer.writeZero(RESERVED_PREFIX);
buffer.writeBytes(SidLabelIndexParser.serializeSidValue(sidLabelIndex));
}
代码示例来源: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.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(Instruction instruction, ByteBuf outBuffer) {
outBuffer.writeShort(getType());
outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);
outBuffer.writeByte(((GotoTableCase) instruction.getInstructionChoice())
.getGotoTable().getTableId());
outBuffer.writeZero(InstructionConstants.PADDING_IN_GOTO_TABLE);
}
代码示例来源: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: org.opendaylight.openflowjava/openflow-protocol-impl
private void serializeExperimenterBody(ExperimenterIdQueueProperty body, ByteBuf outBuffer) {
// TODO: Experimenter Data is vendor specific that should implement its
// own serializer
outBuffer.writeInt(body.getExperimenter().getValue().intValue());
outBuffer.writeZero(PROPERTY_EXPERIMENTER_PADDING);
}
}
代码示例来源:origin: org.opendaylight.bgpcep/bgp-linkstate
public static void serializePrefixAttributes(final Algorithm algorithm, final ByteBuf buffer) {
buffer.writeZero(FLAGS_SIZE);
buffer.writeByte(algorithm.getIntValue());
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(Instruction instruction, ByteBuf outBuffer) {
outBuffer.writeShort(getType());
outBuffer.writeShort(InstructionConstants.WRITE_METADATA_LENGTH);
outBuffer.writeZero(InstructionConstants.PADDING_IN_WRITE_METADATA);
WriteMetadata metadata = ((WriteMetadataCase) instruction.getInstructionChoice())
.getWriteMetadata();
outBuffer.writeBytes(metadata.getMetadata());
outBuffer.writeBytes(metadata.getMetadataMask());
}
代码示例来源: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: org.opendaylight.openflowjava/openflow-protocol-impl
private static void serializePortBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
MultipartRequestPortStatsCase portstatsCase = (MultipartRequestPortStatsCase) multipartRequestBody;
MultipartRequestPortStats portstats = portstatsCase.getMultipartRequestPortStats();
output.writeShort(portstats.getPortNo().intValue());
output.writeZero(PADDING_IN_MULTIPART_REQUEST_PORT_BODY);
}
代码示例来源:origin: digitalpetri/ethernet-ip
int lengthStartIndex = buffer.writerIndex();
buffer.writeByte(0);
buffer.writeZero(1);
int dataStartIndex = buffer.writerIndex();
int bytesWritten = buffer.writerIndex() - dataStartIndex;
int wordsWritten = bytesWritten / 2;
buffer.markWriterIndex();
buffer.writerIndex(lengthStartIndex);
buffer.writeByte(wordsWritten);
buffer.resetWriterIndex();
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(HelloInput message, ByteBuf outBuffer) {
int startWriterIndex = outBuffer.writerIndex();
ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
serializeElementsList(message, outBuffer);
int endWriterIndex = outBuffer.writerIndex();
int paddingRemainder = (endWriterIndex - startWriterIndex) % EncodeConstants.PADDING;
if (paddingRemainder != 0) {
outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
}
ByteBufUtils.updateOFHeaderLength(outBuffer);
}
代码示例来源:origin: com.uber.tchannel/tchannel-core
@Override
protected void encode(ChannelHandlerContext ctx, TFrame frame, ByteBuf out) throws Exception {
// size:2
out.writeShort(frame.size + TFrame.FRAME_HEADER_LENGTH);
// type:1
out.writeByte(frame.type);
// reserved:1
out.writeZero(1);
// id:4
out.writeInt((int) frame.id);
// reserved:8
out.writeZero(8);
// payload:16+
out.writeBytes(frame.payload);
}
代码示例来源:origin: org.opendaylight.bgpcep/bgp-evpn
static ByteBuf serializeOrigRouteIp(final IpAddress origRouteIp) {
final ByteBuf body = Unpooled.buffer();
if (origRouteIp.getIpv4Address() != null) {
body.writeByte(Ipv4Util.IP4_BITS_LENGTH);
body.writeBytes(Ipv4Util.bytesForAddress(origRouteIp.getIpv4Address()));
} else if (origRouteIp.getIpv6Address() != null) {
body.writeByte(Ipv6Util.IPV6_BITS_LENGTH);
body.writeBytes(Ipv6Util.bytesForAddress(origRouteIp.getIpv6Address()));
} else {
body.writeZero(ZERO_BYTE);
}
return body;
}
}
代码示例来源: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: org.opendaylight.bgpcep/bgp-parser-impl
ByteBufWriteUtil.writeMinimalPrefix(prefix, withdrawnRoutesBuf);
messageBody.writeShort(withdrawnRoutesBuf.writerIndex());
messageBody.writeBytes(withdrawnRoutesBuf);
} else {
messageBody.writeZero(WITHDRAWN_ROUTES_LENGTH_SIZE);
messageBody.writeShort(pathAttributesBuf.writerIndex());
messageBody.writeBytes(pathAttributesBuf);
} else {
messageBody.writeZero(TOTAL_PATH_ATTR_LENGTH_SIZE);
代码示例来源:origin: org.opendaylight.openflowplugin/openflowjava-extension-nicira
static void serializeLearnHeader(final ByteBuf outBuffer, ActionLearn action) {
outBuffer.writeShort(action.getNxActionLearn().getIdleTimeout().shortValue());
outBuffer.writeShort(action.getNxActionLearn().getHardTimeout().shortValue());
outBuffer.writeShort(action.getNxActionLearn().getPriority().shortValue());
outBuffer.writeLong(action.getNxActionLearn().getCookie().longValue());
outBuffer.writeShort(action.getNxActionLearn().getFlags().shortValue());
outBuffer.writeByte(action.getNxActionLearn().getTableId().byteValue());
outBuffer.writeZero(1);
outBuffer.writeShort(action.getNxActionLearn().getFinIdleTimeout().shortValue());
outBuffer.writeShort(action.getNxActionLearn().getFinHardTimeout().shortValue());
}
代码示例来源:origin: org.opendaylight.openflowplugin/openflowjava-extension-nicira
@Override
public void serialize(final Action input, final ByteBuf outBuffer) {
ActionOutputReg action = ((ActionOutputReg) input.getActionChoice());
serializeHeader(LENGTH, SUBTYPE, outBuffer);
outBuffer.writeShort(action.getNxActionOutputReg().getNBits().shortValue());
outBuffer.writeInt(action.getNxActionOutputReg().getSrc().intValue());
outBuffer.writeShort(action.getNxActionOutputReg().getMaxLen().shortValue());
outBuffer.writeZero(6);
}
内容来源于网络,如有侵权,请联系作者删除!