List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:org.opendaylight.protocol.bgp.flowspec.Util.java
License:Open Source License
/** * Given the integer values, this method instead of writing the value * in 4B field, compresses the value to lowest required byte field * depending on the value./*from w w w . j ava 2 s. c om*/ * * @param value integer to be written * @param buffer ByteBuf where the value will be written */ protected static void writeShortest(final int value, final ByteBuf buffer) { if (value <= Values.UNSIGNED_BYTE_MAX_VALUE) { buffer.writeByte(UnsignedBytes.checkedCast(value)); } else if (value <= Values.UNSIGNED_SHORT_MAX_VALUE) { ByteBufWriteUtil.writeUnsignedShort(value, buffer); } else if (value <= Values.UNSIGNED_INT_MAX_VALUE) { ByteBufWriteUtil.writeUnsignedInt(UnsignedInts.toLong(value), buffer); } else { buffer.writeLong(value); } }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser.java
License:Open Source License
/** * Serializes Linkstate NLRI to byte array. We need this as NLRI serves as a key in upper layers. * * @param destination Linkstate NLRI to be serialized * @param buffer where Linkstate NLRI will be serialized */// ww w .j a v a2 s.c o m public static void serializeNlri(final CLinkstateDestination destination, final ByteBuf buffer) { final ByteBuf nlriByteBuf = Unpooled.buffer(); if (destination.getDistinguisher() != null) { nlriByteBuf.writeBytes(destination.getDistinguisher().getValue().toByteArray()); } nlriByteBuf.writeByte(destination.getProtocolId().getIntValue()); nlriByteBuf.writeLong(destination.getIdentifier().getValue().longValue()); final ByteBuf ldescs = Unpooled.buffer(); final ObjectType ot = destination.getObjectType(); NlriType nlriType = null; if (ot instanceof PrefixCase) { final PrefixCase pCase = (PrefixCase) destination.getObjectType(); NodeNlriParser.serializeNodeIdentifier(pCase.getAdvertisingNodeDescriptors(), ldescs); TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS_TYPE, ldescs, nlriByteBuf); if (pCase.getPrefixDescriptors() != null) { PrefixNlriParser.serializePrefixDescriptors(pCase.getPrefixDescriptors(), nlriByteBuf); if (pCase.getPrefixDescriptors().getIpReachabilityInformation().getIpv4Prefix() != null) { nlriType = NlriType.Ipv4Prefix; } else { nlriType = NlriType.Ipv6Prefix; } } } else if (ot instanceof LinkCase) { final LinkCase lCase = (LinkCase) destination.getObjectType(); NodeNlriParser.serializeNodeIdentifier(lCase.getLocalNodeDescriptors(), ldescs); NodeNlriParser.serializeEpeNodeDescriptors(lCase.getLocalNodeDescriptors(), ldescs); TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS_TYPE, ldescs, nlriByteBuf); final ByteBuf rdescs = Unpooled.buffer(); NodeNlriParser.serializeNodeIdentifier(lCase.getRemoteNodeDescriptors(), rdescs); NodeNlriParser.serializeEpeNodeDescriptors(lCase.getRemoteNodeDescriptors(), rdescs); TlvUtil.writeTLV(REMOTE_NODE_DESCRIPTORS_TYPE, rdescs, nlriByteBuf); if (lCase.getLinkDescriptors() != null) { LinkNlriParser.serializeLinkDescriptors(lCase.getLinkDescriptors(), nlriByteBuf); } nlriType = NlriType.Link; } else if (ot instanceof NodeCase) { final NodeCase nCase = (NodeCase) destination.getObjectType(); NodeNlriParser.serializeNodeIdentifier(nCase.getNodeDescriptors(), ldescs); TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS_TYPE, ldescs, nlriByteBuf); nlriType = NlriType.Node; } else if (ot instanceof TeLspCase) { final TeLspCase teLSP = (TeLspCase) destination.getObjectType(); final AddressFamily afi = teLSP.getAddressFamily(); nlriType = TeLspNlriParser.serializeIpvTSA(afi, ldescs); TeLspNlriParser.serializeTunnelID(teLSP.getTunnelId(), ldescs); TeLspNlriParser.serializeLspID(teLSP.getLspId(), ldescs); TeLspNlriParser.serializeTEA(afi, ldescs); } else { LOG.warn("Unknown NLRI Type."); } TlvUtil.writeTLV(nlriType.getIntValue(), nlriByteBuf, buffer); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.AigpAttributeParser.java
License:Open Source License
/** * Transform AIGP attribute data from instance of Aigp class into byte buffer representation. * * @param aigp//from w w w . j av a 2 s . c om * instance of Aigp class * @return * byte buffer representation or empty buffer if AIGP TLV is null */ private static ByteBuf serializeAigpTLV(final Aigp aigp) { final AigpTlv tlv = aigp.getAigpTlv(); if (tlv == null) { return Unpooled.EMPTY_BUFFER; } final ByteBuf value = Unpooled.buffer(AIGP_TLV_SIZE); value.writeByte(AIGP_TLV_TYPE); value.writeShort(AIGP_TLV_SIZE); value.writeLong(tlv.getMetric().getValue().longValue()); return value; }
From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java
License:Open Source License
/** * Writes 64-bit long <code>value</code> if not null, otherwise writes zeros * to the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by * 8./* w ww.j a va 2 s .c o m*/ * * @param value * Long value to be written to the output. * @param output * ByteBuf, where value or zeros are written. */ public static void writeLong(final Long value, final ByteBuf output) { if (value != null) { output.writeLong(value); } else { output.writeZero(LONG_BYTES_LENGTH); } }
From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java
License:Open Source License
/** * Writes unsigned 64-bit integer <code>value</code> if not null, otherwise * writes zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is * increased by 8./* w w w . j a v a 2 s . c o m*/ * * @param value * BigInteger value to be written to the output. * @param output * ByteBuf, where value or zeros are written. */ public static void writeUnsignedLong(final BigInteger value, final ByteBuf output) { if (value != null) { output.writeLong(value.longValue()); } else { output.writeZero(LONG_BYTES_LENGTH); } }
From source file:org.projectfloodlight.openflow.protocol.ver13.OFBsnEnhancedHashTypeSerializerVer13.java
public static void writeTo(ByteBuf bb, Set<OFBsnEnhancedHashType> set) { bb.writeLong(toWireValue(set)); }
From source file:org.projectfloodlight.openflow.protocol.ver13.OFBsnHashPacketFieldSerializerVer13.java
public static void writeTo(ByteBuf bb, Set<OFBsnHashPacketField> set) { bb.writeLong(toWireValue(set)); }
From source file:org.projectfloodlight.openflow.protocol.ver13.OFBsnTunnelTypeSerializerVer13.java
public static void writeTo(ByteBuf bb, Set<OFBsnTunnelType> set) { bb.writeLong(toWireValue(set)); }
From source file:org.projectfloodlight.openflow.protocol.ver14.OFBsnMiscCapabilitiesSerializerVer14.java
public static void writeTo(ByteBuf bb, Set<OFBsnMiscCapabilities> set) { bb.writeLong(toWireValue(set)); }
From source file:org.projectfloodlight.openflow.protocol.ver14.OFBsnSpeedCapabilitiesSerializerVer14.java
public static void writeTo(ByteBuf bb, Set<OFBsnSpeedCapabilities> set) { bb.writeLong(toWireValue(set)); }