List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:io.netlibs.bgp.netty.protocol.open.OpenPacket.java
License:Apache License
@Override protected ByteBuf encodePayload() { final ByteBuf buffer = Unpooled.buffer(BGPv4Constants.BGP_PACKET_MAX_LENGTH); buffer.writeByte(this.getProtocolVersion()); buffer.writeShort(this.getAutonomousSystem()); buffer.writeShort(this.getHoldTime()); buffer.writeInt((int) this.getBgpIdentifier()); final ByteBuf capabilities = CapabilityCodec.encodeCapabilities(this.getCapabilities()); if (capabilities.readableBytes() > 0) { buffer.writeByte(capabilities.readableBytes() + 2); // cap length + type byte + parameter length byte buffer.writeByte(BGPv4Constants.BGP_OPEN_PARAMETER_TYPE_CAPABILITY); // type byte buffer.writeByte(capabilities.readableBytes()); // parameter length buffer.writeBytes(capabilities); } else {// ww w.j av a2 s . co m buffer.writeByte(0); // no capabilites encoded --> optional parameter length equals 0 } return buffer; }
From source file:io.netlibs.bgp.netty.protocol.open.UnsupportedVersionNumberNotificationPacket.java
License:Apache License
@Override protected ByteBuf encodeAdditionalPayload() { final ByteBuf buffer = Unpooled.buffer(2); buffer.writeShort(this.supportedProtocolVersion); return buffer; }
From source file:io.netlibs.bgp.netty.protocol.refresh.RouteRefreshPacket.java
License:Apache License
@Override protected ByteBuf encodePayload() { final ByteBuf buffer = Unpooled.buffer(this.calculateEncodingLength()); buffer.writeShort(this.getAddressFamily().toCode()); buffer.writeByte(0);//from w w w . j a v a 2s . c o m buffer.writeByte(this.getSubsequentAddressFamily().toCode()); if (this.outboundRouteFilter != null) { buffer.writeByte(this.outboundRouteFilter.getRefreshType().toCode()); for (final ORFType type : this.outboundRouteFilter.getEntries().keySet()) { int entriesLength = 0; for (final ORFEntry entry : this.outboundRouteFilter.getEntries().get(type)) { entriesLength += ORFEntryCodec.calculateEncodingLength(entry); } buffer.writeByte(type.toCode()); buffer.writeShort(entriesLength); for (final ORFEntry entry : this.outboundRouteFilter.getEntries().get(type)) { buffer.writeBytes(ORFEntryCodec.encodeORFEntry(entry)); } } } return buffer; }
From source file:io.netlibs.bgp.netty.protocol.update.AggregatorPathAttributeCodecHandler.java
License:Apache License
@Override public ByteBuf encodeValue(final AggregatorPathAttribute attr) { final ByteBuf buffer = Unpooled.buffer(this.valueLength(attr)); if (attr.isFourByteASNumber()) { buffer.writeInt(attr.getAsNumber()); } else {/*from www .ja v a2s .co m*/ buffer.writeShort(attr.getAsNumber()); } buffer.writeBytes(attr.getAggregator().getAddress()); return buffer; }
From source file:io.netlibs.bgp.netty.protocol.update.CommunityPathAttributeCodecHandler.java
License:Apache License
@Override public ByteBuf encodeValue(final CommunityPathAttribute attr) { final ByteBuf buffer = Unpooled.buffer(this.valueLength(attr)); if (attr.getMembers() != null) { for (final CommunityMember member : attr.getMembers()) { buffer.writeShort(member.getAsNumber()); buffer.writeShort(member.getValue()); }//from www. ja va 2 s. c o m } return buffer; }
From source file:io.netlibs.bgp.netty.protocol.update.MultiProtocolReachableNLRICodecHandler.java
License:Apache License
@Override public ByteBuf encodeValue(final MultiProtocolReachableNLRI attr) { final ByteBuf buffer = Unpooled.buffer(this.valueLength(attr)); buffer.writeShort(attr.getAddressFamily().toCode()); buffer.writeByte(attr.getSubsequentAddressFamily().toCode()); if (attr.getNextHop() != null) { buffer.writeByte(attr.getNextHop().getAddress().length); buffer.writeBytes(attr.getNextHop().getAddress()); } else {//from w w w . j a v a 2 s .c o m buffer.writeByte(0); } buffer.writeByte(0); // write reserved field if (attr.getNlris() != null) { for (final NetworkLayerReachabilityInformation nlri : attr.getNlris()) { if ((nlri.getPrefix() != null) && (nlri.getPrefixLength() == nlri.getPrefix().length)) { buffer.writeByte(nlri.getPrefixLength()); buffer.writeBytes(nlri.getPrefix()); } else { buffer.writeBytes(NLRICodec.encodeNLRI(nlri)); } } } return buffer; }
From source file:io.netlibs.bgp.netty.protocol.update.MultiProtocolUnreachableNLRICodecHandler.java
License:Apache License
@Override public ByteBuf encodeValue(final MultiProtocolUnreachableNLRI attr) { final ByteBuf buffer = Unpooled.buffer(this.valueLength(attr)); buffer.writeShort(attr.getAddressFamily().toCode()); buffer.writeByte(attr.getSubsequentAddressFamily().toCode()); if (attr.getNlris() != null) { for (final NetworkLayerReachabilityInformation nlri : attr.getNlris()) { buffer.writeBytes(NLRICodec.encodeNLRI(nlri)); }/*from w w w .j av a 2s .co m*/ } return buffer; }
From source file:io.netlibs.bgp.netty.protocol.update.PathAttributeCodec.java
License:Apache License
/** * encode the path attribute for network transmission * * @return an encoded formatted path attribute */// w w w . ja v a 2 s. c om public static ByteBuf encodePathAttribute(final PathAttribute attr) { final ByteBuf buffer = Unpooled.buffer(BGPv4Constants.BGP_PACKET_MAX_LENGTH); final int valueLength = valueLength(attr); int attrFlagsCode = 0; if (attr.isOptional()) { attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_OPTIONAL_BIT; } if (attr.isTransitive()) { attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_TRANSITIVE_BIT; } if (attr.isPartial()) { attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_PARTIAL_BIT; } if (valueLength > 255) { attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_EXTENDED_LENGTH_BIT; } attrFlagsCode |= (typeCode(attr) & BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_MASK); buffer.writeShort(attrFlagsCode); if (valueLength > 255) { buffer.writeShort(valueLength); } else { buffer.writeByte(valueLength); } if (valueLength > 0) { buffer.writeBytes(encodeValue(attr)); } return buffer; }
From source file:io.netlibs.bgp.netty.protocol.update.UpdatePacket.java
License:Apache License
@Override protected ByteBuf encodePayload() { final ByteBuf buffer = Unpooled.buffer(BGPv4Constants.BGP_PACKET_MAX_LENGTH); final ByteBuf withdrawnBuffer = this.encodeWithdrawnRoutes(); final ByteBuf pathAttributesBuffer = this.encodePathAttributes(); buffer.writeShort(withdrawnBuffer.readableBytes()); buffer.writeBytes(withdrawnBuffer);/* ww w. j a v a 2s. c o m*/ buffer.writeShort(pathAttributesBuffer.readableBytes()); buffer.writeBytes(pathAttributesBuffer); buffer.writeBytes(this.encodeNlris()); return buffer; }
From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java
License:Apache License
private static void binaryEncodeINT2(Number value, ByteBuf buff) { buff.writeShort(value.shortValue()); }