Example usage for io.netty.buffer ByteBuf writerIndex

List of usage examples for io.netty.buffer ByteBuf writerIndex

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writerIndex.

Prototype

public abstract int writerIndex();

Source Link

Document

Returns the writerIndex of this buffer.

Usage

From source file:org.opendaylight.protocol.bgp.parser.spi.CapabilityUtil.java

License:Open Source License

/**
 * Adds header to capability value./*from   w  w w . j av  a  2s. c  om*/
 *
 * @param code type of the capability
 * @param value capability value
 * @param buffer ByteBuf where the capability will be copied with its header
 */
public static void formatCapability(final int code, final ByteBuf value, final ByteBuf buffer) {
    buffer.writeByte(code);
    buffer.writeByte(value.writerIndex());
    buffer.writeBytes(value);
}

From source file:org.opendaylight.protocol.bgp.parser.spi.MessageUtil.java

License:Open Source License

/**
 * Adds header to message value.//from w  w  w .  jav  a  2  s.  co  m
 *
 * @param type of the message
 * @param body message body
 * @param buffer ByteBuf where the message will be copied with its header
 */
public static void formatMessage(final int type, final ByteBuf body, final ByteBuf buffer) {
    buffer.writeBytes(MARKER);
    buffer.writeShort(body.writerIndex() + COMMON_HEADER_LENGTH);
    buffer.writeByte(type);
    buffer.writeBytes(body);
}

From source file:org.opendaylight.protocol.bgp.parser.spi.ParameterUtil.java

License:Open Source License

/**
 * Adds header to parameter value.//from   w  w  w  .  j a v  a  2s  . com
 *
 * @param type of the parameter
 * @param value parameter value
 * @param buffer ByteBuf where the parameter will be copied with its header
 */
public static void formatParameter(final int type, final ByteBuf value, final ByteBuf buffer) {
    buffer.writeByte(type);
    buffer.writeByte(value.writerIndex());
    buffer.writeBytes(value);
}

From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleNlriRegistry.java

License:Open Source License

@Override
public void serializeMpReach(final MpReachNlri mpReachNlri, final ByteBuf byteAggregator) {
    final Class<? extends AddressFamily> afi = mpReachNlri.getAfi();
    final Class<? extends SubsequentAddressFamily> safi = mpReachNlri.getSafi();
    byteAggregator.writeShort(this.afiReg.numberForClass(afi));
    byteAggregator.writeByte(this.safiReg.numberForClass(safi));

    final CNextHop cNextHop = mpReachNlri.getCNextHop();
    if (cNextHop != null) {
        final Map.Entry<Class<? extends CNextHop>, BgpTableType> key = new AbstractMap.SimpleEntry(
                cNextHop.getImplementedInterface(), new BgpTableTypeImpl(afi, safi));
        final NextHopParserSerializer nextHopSerializer = this.nextHopSerializers.get(key);
        final ByteBuf nextHopBuffer = Unpooled.buffer();
        if (nextHopSerializer == null) {
            //TODO Remove once deprecated registerNlriParser is removed
            LOG.warn("NexHop Parser/Serializer for AFI/SAFI ({},{}) not bound", afi, safi);
            NextHopUtil.serializeNextHop(cNextHop, nextHopBuffer);
        } else {/*from   w ww.  j  av  a2 s.co  m*/
            nextHopSerializer.serializeNextHop(cNextHop, nextHopBuffer);
        }
        byteAggregator.writeByte(nextHopBuffer.writerIndex());
        byteAggregator.writeBytes(nextHopBuffer);

    } else {
        byteAggregator.writeZero(NEXT_HOP_LENGHT);
    }
    byteAggregator.writeZero(RESERVED);
}

From source file:org.opendaylight.protocol.bmp.spi.parser.AbstractBmpMessageParser.java

License:Open Source License

private void formatMessage(final ByteBuf body, final ByteBuf output) {
    output.writeByte(BMP_VERSION);//from  www .  j a va2 s .co  m
    ByteBufWriteUtil.writeInt(body.writerIndex() + COMMON_HEADER_LENGTH, output);
    output.writeByte(getBmpMessageType());
    output.writeBytes(body);
}

From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser.java

License:Open Source License

private static void formatRSVPObject(final int objClass, final int type, final ByteBuf body,
        final ByteBuf out) {
    out.writeShort(body.writerIndex() + HEADER_LENGTH);
    out.writeByte(objClass);//  ww w.  j a  v  a 2  s .c  o m
    out.writeByte(type);
    out.writeBytes(body);
}

From source file:org.opendaylight.protocol.pcep.spi.EROSubobjectUtil.java

License:Open Source License

public static void formatSubobject(final int type, final Boolean loose, final ByteBuf body,
        final ByteBuf buffer) {
    if (loose == null) {
        buffer.writeByte(type);//from w  w  w  .  j av  a 2 s.c om
    } else {
        buffer.writeByte(type | (loose ? 1 << LOOSE_BIT : 0));
    }
    buffer.writeByte(body.writerIndex() + HEADER_SIZE);
    buffer.writeBytes(body);
}

From source file:org.opendaylight.protocol.pcep.spi.MessageUtil.java

License:Open Source License

public static void formatMessage(final int messageType, final ByteBuf body, final ByteBuf out) {
    final int msgLength = body.writerIndex();
    out.writeByte(PCEPMessageConstants.PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH));
    out.writeByte(messageType);/*from   w  ww.j  av a 2 s. co  m*/
    out.writeShort(msgLength + PCEPMessageConstants.COMMON_HEADER_LENGTH);
    Preconditions.checkState(out.writerIndex() == PCEPMessageConstants.COMMON_HEADER_LENGTH);
    out.writeBytes(body);
}

From source file:org.opendaylight.protocol.pcep.spi.ObjectUtil.java

License:Open Source License

public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule,
        final Boolean ignore, final ByteBuf body, final ByteBuf out) {
    out.writeByte(objectClass);//from   w  w  w.  j a v  a2 s .  com
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(IGNORED, ignore);
    flags.set(PROCESSED, processingRule);
    final byte flagB = flags.toByte();
    final int typeByte = objectType << FLAGS_SIZE | flagB;
    out.writeByte(typeByte);
    out.writeShort(body.writerIndex() + HEADER_SIZE);
    out.writeBytes(body);
}

From source file:org.opendaylight.protocol.pcep.spi.RROSubobjectUtil.java

License:Open Source License

public static void formatSubobject(final int type, final ByteBuf body, final ByteBuf buffer) {
    buffer.writeByte(type);//from  w w w  .ja  v  a 2  s.com
    buffer.writeByte(body.writerIndex() + HEADER_SIZE);
    buffer.writeBytes(body);
}