Java Code Examples for io.netty.buffer.ByteBuf#writeZero()
The following examples show how to use
io.netty.buffer.ByteBuf#writeZero() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FtdcProtocol.java From ftdc with Apache License 2.0 | 6 votes |
private ByteBuf uncompress() { ByteBuf buffer = Unpooled.buffer(); for(;bodyBuf.readerIndex() < bodyBuf.writerIndex();) { short b = bodyBuf.readUnsignedByte(); if((b >> 4) != 14) { buffer.writeByte(b); }else { int size = b & 15; if(size == 0) { buffer.writeByte(bodyBuf.readByte()); } else { buffer.writeZero(size); } } } return buffer; }
Example 2
Source File: EROIpv4PrefixSubobjectParser.java From bgpcep with Eclipse Public License 1.0 | 6 votes |
@Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); final IpPrefix prefix = specObj.getIpPrefix(); final Ipv6Prefix ipv6prefix = prefix.getIpv6Prefix(); if (ipv6prefix != null) { EROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6prefix); return; } final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH); checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory."); Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body); body.writeZero(RESERVED); EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer); }
Example 3
Source File: DnsAddressEndpointGroupTest.java From armeria with Apache License 2.0 | 5 votes |
private static DnsRecord newMappedAddressRecord(String name, String ipV4Addr) { final ByteBuf content = Unpooled.buffer(); content.writeZero(10); content.writeShort(0xFFFF); content.writeBytes(NetUtil.createByteArrayFromIpAddressString(ipV4Addr)); return new DefaultDnsRawRecord(name, AAAA, 60, content); }
Example 4
Source File: SrPrefixAttributesParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
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)); }
Example 5
Source File: PCEPExcludeRouteObjectParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
@Override public void serializeObject(final Object object, final ByteBuf buffer) { checkArgument(object instanceof Xro, "Wrong instance of PCEPObject. Passed %s. Needed XroObject.", object.getClass()); final Xro obj = (Xro) object; final ByteBuf body = Unpooled.buffer(); body.writeZero(FLAGS_OFFSET); final Flags flags = obj.getFlags(); body.writeBoolean(flags != null && Boolean.TRUE.equals(flags.isFail())); serializeSubobject(obj.getSubobject(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }
Example 6
Source File: EncapsulationEC.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
@Override public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) { Preconditions.checkArgument(extendedCommunity instanceof EncapsulationCase, "The extended community %s is not EncapsulationCase type.", extendedCommunity); final EncapsulationExtendedCommunity encap = ((EncapsulationCase) extendedCommunity).getEncapsulationExtendedCommunity(); body.writeZero(RESERVED_SIZE); body.writeShort(encap.getTunnelType().getIntValue()); }
Example 7
Source File: RsvpTeP2MpLspParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
@Override public int serialize(final RsvpTeP2mpLsp tunnelIdentifier, final ByteBuf buffer) { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev200120.pmsi.tunnel.pmsi .tunnel.tunnel.identifier.rsvp.te.p2mp.lsp .RsvpTeP2mpLsp rsvpTeP2mpLsp = tunnelIdentifier.getRsvpTeP2mpLsp(); ByteBufUtils.writeOrZero(buffer, rsvpTeP2mpLsp.getP2mpId()); buffer.writeZero(RESERVED); ByteBufUtils.writeOrZero(buffer, rsvpTeP2mpLsp.getTunnelId()); serializeIpAddress(rsvpTeP2mpLsp.getExtendedTunnelId(), buffer); return getType(); }
Example 8
Source File: InitialHandshakeCommandCodec.java From vertx-sql-client with Apache License 2.0 | 5 votes |
private void sendSslRequest() { ByteBuf packet = allocateBuffer(36); // encode packet header packet.writeMediumLE(32); packet.writeByte(sequenceId); // encode SSLRequest payload packet.writeIntLE(encoder.clientCapabilitiesFlag); packet.writeIntLE(PACKET_PAYLOAD_LENGTH_LIMIT); packet.writeByte(cmd.collation().collationId()); packet.writeZero(23); // filler sendNonSplitPacket(packet); }
Example 9
Source File: SrNodeAttributesParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
public static void serializeSrCapabilities(final SrCapabilities caps, final ByteBuf buffer) { final BitArray bs = new BitArray(FLAGS_SIZE); bs.set(MPLS_IPV4, caps.isMplsIpv4()); bs.set(MPLS_IPV6, caps.isMplsIpv6()); bs.set(SR_IPV6, caps.isSrIpv6()); bs.toByteBuf(buffer); buffer.writeZero(RESERVERED); Uint24ByteBufUtils.writeUint24(buffer, caps.getRangeSize()); TlvUtil.writeTLV(SID_TYPE, SidLabelIndexParser.serializeSidValue(caps.getSidLabelIndex()), buffer); }
Example 10
Source File: PathSetupTypeTlvParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
@Override public void serializeTlv(final Tlv tlv, final ByteBuf buffer) { checkArgument(tlv instanceof PathSetupType, "PathSetupType is mandatory."); final PathSetupType pstTlv = (PathSetupType) tlv; checkArgument(checkPST(pstTlv.getPst()), UNSUPPORTED_PST); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); body.writeZero(OFFSET); ByteBufUtils.writeOrZero(body, pstTlv.getPst()); TlvUtil.formatTlv(TYPE, body, buffer); }
Example 11
Source File: Stateful07RSVPErrorSpecTlvParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
private static void serializerUserError(final UserError ue, final ByteBuf body) { final String description = ue.getDescription(); final byte[] desc = description == null ? new byte[0] : description.getBytes(StandardCharsets.UTF_8); final ByteBuf userErrorBuf = Unpooled.buffer(); final EnterpriseNumber enterprise = ue.getEnterprise(); checkArgument(enterprise != null, "EnterpriseNumber is mandatory"); ByteBufUtils.write(userErrorBuf, enterprise.getValue()); ByteBufUtils.writeOrZero(userErrorBuf, ue.getSubOrg()); userErrorBuf.writeByte(desc.length); ByteBufUtils.writeMandatory(userErrorBuf, ue.getValue(), "Value"); userErrorBuf.writeBytes(desc); userErrorBuf.writeZero(TlvUtil.getPadding(desc.length, TlvUtil.PADDED_TO)); formatRSVPObject(USER_ERROR_CLASS_NUM, USER_ERROR_CLASS_TYPE, userErrorBuf, body); }
Example 12
Source File: PCEPObjectiveFunctionObjectParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
@Override public void serializeObject(final Object object, final ByteBuf buffer) { checkArgument(object instanceof Of, "Wrong instance of PCEPObject. Passed %s. Needed OfObject.", object.getClass()); final Of specObj = (Of) object; final ByteBuf body = Unpooled.buffer(); final OfId code = specObj.getCode(); checkArgument(code != null, "Code is mandatory"); ByteBufUtils.write(body, code.getValue()); body.writeZero(RESERVED); serializeTlvs(specObj.getTlvs(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }
Example 13
Source File: PCEPMetricObjectParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
@Override public void serializeObject(final Object object, final ByteBuf buffer) { checkArgument(object instanceof Metric, "Wrong instance of PCEPObject. Passed %s. Needed MetricObject.", object.getClass()); final Metric mObj = (Metric) object; final ByteBuf body = Unpooled.buffer(SIZE); body.writeZero(RESERVED); final BitArray flags = new BitArray(FLAGS_SIZE); flags.set(C_FLAG_OFFSET, mObj.isComputed()); flags.set(B_FLAG_OFFSET, mObj.isBound()); flags.toByteBuf(body); ByteBufUtils.writeMandatory(body, mObj.getMetricType(), "MetricType"); writeFloat32(mObj.getValue(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }
Example 14
Source File: TrafficActionEcHandler.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
@Override public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) { checkArgument(extendedCommunity instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang .bgp.flowspec.rev200120.TrafficActionExtendedCommunity, "The extended community %s is not TrafficActionExtendedCommunityCase type.", extendedCommunity); final TrafficActionExtendedCommunity trafficAction = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml .ns.yang.bgp.flowspec.rev200120.TrafficActionExtendedCommunity) extendedCommunity) .getTrafficActionExtendedCommunity(); byteAggregator.writeZero(RESERVED); final BitArray flags = new BitArray(FLAGS_SIZE); flags.set(SAMPLE_BIT, trafficAction.isSample()); flags.set(TERMINAL_BIT, trafficAction.isTerminalAction()); flags.toByteBuf(byteAggregator); }
Example 15
Source File: BindingSidLabelParser.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
public static void serializeBindingSidAttributes(final Weight weight, final Flags flags, final List<BindingSubTlvs> bindingSubTlvs, final ByteBuf aggregator) { aggregator.writeByte(weight.getValue().toJava()); final BitArray bitFlags = serializeBindingSidFlags(flags); bitFlags.toByteBuf(aggregator); aggregator.writeZero(RESERVED_BINDING_SID); SimpleBindingSubTlvsRegistry.getInstance().serializeBindingSubTlvs(bindingSubTlvs, aggregator); }
Example 16
Source File: TlvUtil.java From bgpcep with Eclipse Public License 1.0 | 4 votes |
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)); }
Example 17
Source File: Ipv6SrPrefixAttributesParser.java From bgpcep with Eclipse Public License 1.0 | 4 votes |
public static void serializePrefixAttributes(final Algorithm algorithm, final ByteBuf buffer) { buffer.writeZero(FLAGS_SIZE); buffer.writeByte(algorithm.getIntValue()); }
Example 18
Source File: InitialHandshakeCommandCodec.java From vertx-sql-client with Apache License 2.0 | 4 votes |
private void sendHandshakeResponseMessage(String username, String password, String database, byte[] nonce, String authMethodName, Map<String, String> clientConnectionAttributes) { ByteBuf packet = allocateBuffer(); // encode packet header int packetStartIdx = packet.writerIndex(); packet.writeMediumLE(0); // will set payload length later by calculation packet.writeByte(sequenceId); // encode packet payload int clientCapabilitiesFlags = encoder.clientCapabilitiesFlag; packet.writeIntLE(clientCapabilitiesFlags); packet.writeIntLE(PACKET_PAYLOAD_LENGTH_LIMIT); packet.writeByte(cmd.collation().collationId()); packet.writeZero(23); // filler BufferUtils.writeNullTerminatedString(packet, username, StandardCharsets.UTF_8); if (password.isEmpty()) { packet.writeByte(0); } else { byte[] scrambledPassword; switch (authMethodName) { case "mysql_native_password": scrambledPassword = Native41Authenticator.encode(password.getBytes(StandardCharsets.UTF_8), nonce); break; case "caching_sha2_password": scrambledPassword = CachingSha2Authenticator.encode(password.getBytes(StandardCharsets.UTF_8), nonce); break; default: completionHandler.handle(CommandResponse.failure(new UnsupportedOperationException("Unsupported authentication method: " + authMethodName))); return; } if ((clientCapabilitiesFlags & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA) != 0) { BufferUtils.writeLengthEncodedInteger(packet, scrambledPassword.length); packet.writeBytes(scrambledPassword); } else if ((clientCapabilitiesFlags & CLIENT_SECURE_CONNECTION) != 0) { packet.writeByte(scrambledPassword.length); packet.writeBytes(scrambledPassword); } else { packet.writeByte(0); } } if ((clientCapabilitiesFlags & CLIENT_CONNECT_WITH_DB) != 0) { BufferUtils.writeNullTerminatedString(packet, database, StandardCharsets.UTF_8); } if ((clientCapabilitiesFlags & CLIENT_PLUGIN_AUTH) != 0) { BufferUtils.writeNullTerminatedString(packet, authMethodName, StandardCharsets.UTF_8); } if ((clientCapabilitiesFlags & CLIENT_CONNECT_ATTRS) != 0) { encodeConnectionAttributes(clientConnectionAttributes, packet); } // set payload length int payloadLength = packet.writerIndex() - packetStartIdx - 4; packet.setMediumLE(packetStartIdx, payloadLength); sendPacket(packet, payloadLength); }
Example 19
Source File: Stateful07SrpObjectParser.java From bgpcep with Eclipse Public License 1.0 | 4 votes |
protected void serializeFlags(final Srp srp, final ByteBuf body) { body.writeZero(FLAGS_SIZE / Byte.SIZE); }
Example 20
Source File: EROIpv6PrefixSubobjectParser.java From bgpcep with Eclipse Public License 1.0 | 4 votes |
static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6prefix) { final ByteBuf body = Unpooled.buffer(); Ipv6Util.writeIpv6Prefix(ipv6prefix, body); body.writeZero(RESERVED); EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer); }