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.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactory.java

License:Open Source License

@Override
public void serialize(BundleAddMessage input, ByteBuf outBuffer) {
    outBuffer.writeInt(input.getBundleId().getValue().intValue());
    outBuffer.writeZero(2);/*from  w  ww.  ja  v  a 2s.c om*/
    writeBundleFlags(input.getFlags(), outBuffer);

    int msgStart = outBuffer.writerIndex();
    serializeInnerMessage(input.getMessage(), outBuffer, input.getMessage().getImplementedInterface());
    int msgLength = outBuffer.writerIndex() - msgStart;

    List<BundleProperty> bundleProperties = input.getBundleProperty();
    if (bundleProperties != null && !bundleProperties.isEmpty()) {
        outBuffer.writeZero(paddingNeeded(msgLength));
        writeBundleProperties(input.getBundleProperty(), outBuffer);
    }
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF10VendorActionSerializer.java

License:Open Source License

@Override
public void serialize(Action action, ByteBuf outBuffer) {
    int startIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
    int lengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
    outBuffer.writeInt(experimenter.getExperimenter().intValue());
    byte[] data = experimenter.getData();
    if (data != null) {
        outBuffer.writeBytes(data);// ww w.  j  a va 2  s  . c o  m
    }
    outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13ExperimenterActionSerializer.java

License:Open Source License

@Override
public void serialize(Action action, ByteBuf outBuffer) {
    int actionStartIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
    int actionLengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    ExperimenterAction expAction = action.getAugmentation(ExperimenterAction.class);
    outBuffer.writeInt(expAction.getExperimenter().intValue());
    if (expAction.getData() != null) {
        outBuffer.writeBytes(expAction.getData());
    }/*from ww w  . j  a va2 s . c  o m*/
    outBuffer.setShort(actionLengthIndex, outBuffer.writerIndex() - actionStartIndex);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13ExperimenterInstructionSerializer.java

License:Open Source License

@Override
public void serialize(Instruction instruction, ByteBuf outBuffer) {
    int startIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
    int lengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class);
    outBuffer.writeInt(experimenter.getExperimenter().intValue());
    if (experimenter.getData() != null) {
        outBuffer.writeBytes(experimenter.getData());
    }//from www .j a v a  2 s. c  o  m
    outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13MeterBandExperimenterSerializer.java

License:Open Source License

@Override
public void serialize(MeterBandExperimenter meterBand, ByteBuf outBuffer) {
    int startIndex = outBuffer.writerIndex();
    outBuffer.writeShort(meterBand.getType().getIntValue());
    int lengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeInt(meterBand.getRate().intValue());
    outBuffer.writeInt(meterBand.getBurstSize().intValue());
    outBuffer.writeInt(meterBand.getExperimenter().intValue());
    if (meterBand.getData() != null) {
        outBuffer.writeBytes(meterBand.getData());
    }//  w ww . java2 s  .  c  o m
    outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13TableFeatExpSerializer.java

License:Open Source License

@Override
public void serialize(TableFeatureProperties property, ByteBuf outBuffer) {
    int startIndex = outBuffer.writerIndex();
    if (property.getType().equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) {
        outBuffer.writeShort(EXPERIMENTER_CODE);
    } else {// www . j  a va  2  s  .  c o m
        outBuffer.writeShort(EXPERIMENTER_MISS_CODE);
    }
    int lengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    ExperimenterRelatedTableFeatureProperty exp = property
            .getAugmentation(ExperimenterRelatedTableFeatureProperty.class);
    outBuffer.writeInt(exp.getExperimenter().intValue());
    outBuffer.writeInt(exp.getExpType().intValue());
    byte[] data = exp.getData();
    if (data != null) {
        outBuffer.writeBytes(data);
    }
    int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING;
    if (paddingRemainder != 0) {
        int padding = EncodeConstants.PADDING - paddingRemainder;
        ByteBufUtils.padBuffer(padding, outBuffer);
    }
    outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory.java

License:Open Source License

@Override
public void messageToBuffer(short version, ByteBuf out, HelloInput message) {
    int startWriterIndex = out.writerIndex();
    ByteBufUtils.writeOFHeader(instance, message, out);
    encodeElementsList(message, out);/*  w w  w  .  j  a  va2s  .c  o  m*/
    int endWriterIndex = out.writerIndex();
    int writtenBytesDiff = computeLength(message) - (endWriterIndex - startWriterIndex);
    ByteBufUtils.padBuffer(writtenBytesDiff, out);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.instruction.AbstractActionInstructionSerializer.java

License:Open Source License

protected void writeActions(final List<Action> actions, final ByteBuf outBuffer, int startIndex) {
    int lengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    ListSerializer.serializeList(actions, ACTION_KEY_MAKER, getRegistry(), outBuffer);
    int instructionLength = outBuffer.writerIndex() - startIndex;
    outBuffer.setShort(lengthIndex, instructionLength);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.instruction.ApplyActionsInstructionSerializer.java

License:Open Source License

@Override
public void serialize(final Instruction instruction, final ByteBuf outBuffer) {
    int startIndex = outBuffer.writerIndex();
    outBuffer.writeShort(getType());/* w  w  w  .java2  s.co m*/
    ApplyActionsCase actionsCase = (ApplyActionsCase) instruction.getInstructionChoice();
    if (actionsCase != null) {
        List<Action> actions = actionsCase.getApplyActions().getAction();
        writeActions(actions, outBuffer, startIndex);
    } else {
        outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);
        outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    }
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.instruction.WriteActionsInstructionSerializer.java

License:Open Source License

@Override
public void serialize(final Instruction instruction, final ByteBuf outBuffer) {
    int startIndex = outBuffer.writerIndex();
    outBuffer.writeShort(getType());//from w  w  w.ja v  a2  s. co  m
    WriteActionsCase actionsCase = (WriteActionsCase) instruction.getInstructionChoice();
    if (actionsCase != null) {
        List<Action> actions = actionsCase.getWriteActions().getAction();
        writeActions(actions, outBuffer, startIndex);
    } else {
        outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);
        outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    }
}