當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelBuffer.writerIndex方法代碼示例

本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.writerIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.writerIndex方法的具體用法?Java ChannelBuffer.writerIndex怎麽用?Java ChannelBuffer.writerIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.buffer.ChannelBuffer的用法示例。


在下文中一共展示了ChannelBuffer.writerIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encodeContent

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 12 + 56);

        buf.writeBytes(
                ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII));
        buf.writeByte(0);
        buf.writeShort(buf.capacity());
        buf.writeShort(NoranProtocolDecoder.MSG_CONTROL);
        buf.writeInt(0); // gis ip
        buf.writeShort(0); // gis port
        buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
        buf.writerIndex(buf.writerIndex() + 50 - content.length());
        buf.writeBytes(
                ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII));

        return buf;
    }
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:19,代碼來源:NoranProtocolEncoder.java

示例2: packOptionalTlv

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Returns writer index.
 *
 * @param cb of type channel buffer.
 * @return writer index
 */
protected int packOptionalTlv(ChannelBuffer cb) {
    int startIndex = cb.writerIndex();

    LinkedList<PcepValueType> llOptionalTlv = this.llOptionalTlv;
    ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
    while (listIterator.hasNext()) {
        PcepValueType tlv = listIterator.next();
        if (tlv == null) {
            log.debug("TLV is null from OptionalTlv list");
            continue;
        }

        tlv.write(cb);

        // need to take care of padding
        int pad = tlv.getLength() % 4;

        if (0 != pad) {
            pad = 4 - pad;
            for (int i = 0; i < pad; ++i) {
                cb.writeByte((byte) 0);
            }
        }
    }
    return cb.writerIndex() - startIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:33,代碼來源:PcepOpenObjectVer1.java

示例3: initiateMessageTest12

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv)
 * objects in PcInitiate message.
 */
@Test
public void initiateMessageTest12() throws PcepParseException, PcepOutOfBoundMessageException {

    /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv).
     */
    byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x3c,
            0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv
            0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv
            (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01,
            (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20,
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00 //SymbolicPathNameTlv
    };

    byte[] testInitiateDeletionMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(initiateDeletionMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;


    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepInitiateMsg.class));

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

    message.writeTo(buf);

    testInitiateDeletionMsg = buf.array();

    int iReadLen = buf.writerIndex();
    testInitiateDeletionMsg = new byte[iReadLen];
    buf.readBytes(testInitiateDeletionMsg, 0, iReadLen);

    assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:43,代碼來源:PcepInitiateMsgTest.java

示例4: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeLong(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:9,代碼來源:PcepLabelDbVerTlv.java

示例5: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeByte(FLOW_SPEC_TYPE);

    for (BgpFsOperatorValue fsOperVal : operatorValue) {
        cb.writeByte(fsOperVal.option());
        cb.writeBytes(fsOperVal.value());
    }

    return cb.writerIndex() - iLenStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:13,代碼來源:BgpFsDestinationPortNum.java

示例6: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer c) {
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeLong(rawValue);
    return c.writerIndex();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:8,代碼來源:StatefulLspDbVerTlv.java

示例7: pcepUpdateMsgTest14

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object,LSPA
 * metric object in PcepUpdate message.
 */
@Test
public void pcepUpdateMsgTest14() throws PcepParseException, PcepOutOfBoundMessageException {
    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x60,
            0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv
            (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01,
            (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20,
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x01, 0x04, 0x00,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00,
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object

    byte[] testupdateMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepUpdateMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testupdateMsg = buf.array();

    int readLen = buf.writerIndex() - 0;
    testupdateMsg = new byte[readLen];
    buf.readBytes(testupdateMsg, 0, readLen);

    assertThat(testupdateMsg, is(updateMsg));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:40,代碼來源:PcepUpdateMsgExtTest.java

示例8: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
    int iLenStartIndex = cb.writerIndex();
    //PCEP LSPA object is optional
    if (this.isLspaObjectSet) {
        this.lspaObject.write(cb);
    }

    //PCEP BANDWIDTH object is optional
    if (this.isBandwidthObjectSet) {
        this.bandwidthObject.write(cb);
    }

    //PCEP Metric list is optional
    if (this.isMetricListSet) {
        ListIterator<PcepMetricObject> listIterator = this.llMetricList.listIterator();
        while (listIterator.hasNext()) {
            listIterator.next().write(cb);
        }
    }

    //PCEP  IRO object is optional
    if (this.isIroObjectSet) {
        this.iroObject.write(cb);
    }
    return cb.writerIndex() - iLenStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:28,代碼來源:PcepAttributeVer1.java

示例9: reportMessageTest44

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Tests PCRpt msg with Path-Setup-Type TLV as "without SR and without signalling".
 *
 * @throws PcepParseException
 * @throws PcepOutOfBoundMessageException
 */
@Test
public void reportMessageTest44() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x3C,
            0x21, 0x10, 0x00, 0x14,  0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x01, //SRP object
            0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
            0x00, 0x00, 0x00, 0x02,
            0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
            0x07, 0x10, 0x00, 0x14, //ERO object
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, //ERO IPv4 subobjects
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
            };

    byte[] testReportMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(reportMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);
    assertThat(message, instanceOf(PcepReportMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);

    int readLen = buf.writerIndex();
    testReportMsg = new byte[readLen];
    buf.readBytes(testReportMsg, 0, readLen);

    assertThat(testReportMsg, is(reportMsg));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:39,代碼來源:PcepReportMsgExtTest.java

示例10: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:9,代碼來源:MaximumLinkBandwidthSubTlv.java

示例11: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    int objStartIndex = cb.writerIndex();

    //Write common header
    int objLenIndex = fecObjHeader.write(cb);
    cb.writeInt(localIPv4Address);
    cb.writeInt(remoteIPv4Address);

    //Now write FEC IPv4 Adjacency Object Length
    cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
    return cb.writerIndex();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:15,代碼來源:PcepFecObjectIPv4AdjacencyVer1.java

示例12: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
 *
 * @param cb of type channel buffer
 * @return object length index in channel buffer
 */
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeShort((short) 0);
    cb.writeByte(this.objClassNum);
    cb.writeByte(this.objClassType);
    return cb.writerIndex() - iLenStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:14,代碼來源:PcepRsvpObjectHeader.java

示例13: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();

    cb.writeByte(FLOW_SPEC_TYPE);

    for (BgpFsOperatorValue fsOperVal : operatorValue) {
        cb.writeByte(fsOperVal.option());
        cb.writeBytes(fsOperVal.value());
    }

    return cb.writerIndex() - iLenStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:14,代碼來源:BgpFsPacketLength.java

示例14: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public void write(ChannelBuffer cb, PcepErrorMsgVer1 message) throws PcepParseException {
    int startIndex = cb.writerIndex();
    // first 3 bits set to version
    cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
    // message type 0xC
    cb.writeByte(MSG_TYPE.getType());
    // length is length of variable message, will be updated at the end
    // Store the position of message
    // length in buffer
    int msgLenIndex = cb.writerIndex();
    cb.writeShort(0);
    ErrorObjListWithOpen errObjListWithOpen = message.getErrorObjListWithOpen();
    PcepErrorInfo errInfo = message.getPcepErrorInfo();

    // write ( <error-obj-list> [<Open>] ) if exists.
    // otherwise write <error> [<error-list>]

    if ((errObjListWithOpen != null)
            && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
        errObjListWithOpen.write(cb);
    } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) {
        errInfo.write(cb);
    } else {
        throw new PcepParseException("Empty PCEP-ERROR message.");
    }
    // PcepErrorMessage message length field
    int length = cb.writerIndex() - startIndex;
    cb.setShort(msgLenIndex, (short) length);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:31,代碼來源:PcepErrorMsgVer1.java

示例15: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public void write(ChannelBuffer cb, PcepInitiateMsgVer1 message) throws PcepParseException {

    boolean isDelLspRequest = false;
    int startIndex = cb.writerIndex();
    // first 3 bits set to version
    cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
    // message type 0xC
    cb.writeByte(MSG_TYPE.getType());
    // length is length of variable message, will be updated at the end
    // Store the position of message
    // length in buffer
    int msgLenIndex = cb.writerIndex();
    cb.writeShort(0);

    ListIterator<PcInitiatedLspRequest> listIterator = message.llPcInitiatedLspRequestList.listIterator();

    while (listIterator.hasNext()) {

        PcInitiatedLspRequest listReq = listIterator.next();

        //Srp Object is mandatory
        PcepSrpObject srpObj = listReq.getSrpObject();
        if (srpObj != null) {
            isDelLspRequest = srpObj.getRFlag();
            srpObj.write(cb);
        } else {
            throw new PcepParseException("SRP Object is mandatory for PcInitiate message.");
        }

        //LSP Object is mandatory
        PcepLspObject lspObj = listReq.getLspObject();
        if (lspObj != null) {
            lspObj.write(cb);
        } else {
            throw new PcepParseException("LSP Object is mandatory for PcInitiate message.");
        }

        /* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects
         * so if R bit is not set then we should read for Ero and EndPoint objects also.
         */

        if (!isDelLspRequest) {

            //EndPoints object is mandatory
            PcepEndPointsObject endPointObj = listReq.getEndPointsObject();
            if (endPointObj != null) {
                endPointObj.write(cb);
            } else {
                throw new PcepParseException("End points Object is mandatory for PcInitiate message.");
            }

            //Ero object is mandatory
            PcepEroObject eroObj = listReq.getEroObject();
            if (eroObj != null) {
                eroObj.write(cb);
            } else {
                throw new PcepParseException("ERO Object is mandatory for PcInitiate message.");
            }

            //PcepAttribute is optional
            PcepAttribute pcepAttribute = listReq.getPcepAttribute();
            if (pcepAttribute != null) {
                pcepAttribute.write(cb);
            }
        }
    }

    // PCInitiate message length field
    int length = cb.writerIndex() - startIndex;
    cb.setShort(msgLenIndex, (short) length);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:73,代碼來源:PcepInitiateMsgVer1.java


注:本文中的org.jboss.netty.buffer.ChannelBuffer.writerIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。