Java Code Examples for org.jboss.netty.buffer.ChannelBuffer.writeInt()

The following are Jave code examples for showing how to use writeInt() of the org.jboss.netty.buffer.ChannelBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: traccar-service   File: EelinkProtocolEncoder.java   Source Code and License Vote up 6 votes
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

        buf.writeByte(0x67);
        buf.writeByte(0x67);
        buf.writeByte(EelinkProtocolDecoder.MSG_DOWNLINK);
        buf.writeShort(2 + 1 + 4 + content.length()); // length
        buf.writeShort(0); // index

        buf.writeByte(0x01); // command
        buf.writeInt(0); // server id
        buf.writeBytes(content.getBytes(StandardCharsets.UTF_8));

        return buf;
    }
 
Example 2
Project: athena   File: LsCapabilityTlv.java   Source Code and License Vote up 6 votes
@Override
public int write(ChannelBuffer c) {
    int iStartIndex = c.writerIndex();
    int temp = 0;
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    if (isRawValueSet) {
        c.writeInt(rawValue);
    } else {
        if (rFlag) {
            temp = temp | RFLAG_CHECK;
        }
        c.writeInt(temp);
    }
    return c.writerIndex() - iStartIndex;
}
 
Example 3
Project: athena   File: PcepNaiUnnumberedAdjacencyIpv4.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer bb) {
    int iLenStartIndex = bb.writerIndex();
    bb.writeInt(localNodeId);
    bb.writeInt(localInterfaceId);
    bb.writeInt(remoteNodeId);
    bb.writeInt(remoteInterfaceId);
    return bb.writerIndex() - iLenStartIndex;
}
 
Example 4
Project: traccar-service   File: ProgressProtocolDecoder.java   Source Code and License Vote up 5 votes
private void requestArchive(Channel channel) {
    if (lastIndex == 0) {
        lastIndex = newIndex;
    } else if (newIndex > lastIndex) {
        ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 12);
        request.writeShort(MSG_LOG_SYNC);
        request.writeShort(4);
        request.writeInt((int) lastIndex);
        request.writeInt(0);
        channel.write(request);
    }
}
 
Example 5
Project: athena   File: BgpOpenMsgVer4.java   Source Code and License Vote up 5 votes
@Override
public void write(ChannelBuffer cb, BgpOpenMsgVer4 message) throws BgpParseException {

    int optParaLen = 0;
    int as4num = 0;

    int startIndex = cb.writerIndex();

    // write common header and get msg length index
    int msgLenIndex = message.bgpMsgHeader.write(cb);

    if (msgLenIndex <= 0) {
        throw new BgpParseException("Unable to write message header.");
    }

    // write version in 1-octet
    cb.writeByte(message.version);

    // get as4num if LS Capability is set
    if (message.isLargeAsCapabilitySet) {
        LinkedList<BgpValueType> capabilityTlv = message
                .getCapabilityTlv();
        ListIterator<BgpValueType> listIterator = capabilityTlv
                .listIterator();

        while (listIterator.hasNext()) {
            BgpValueType tlv = listIterator.next();
            if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
                as4num = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
                break;
            }
        }
    }

    if ((message.isLargeAsCapabilitySet) && (as4num > 65535)) {
        // write As number as AS_TRANS
        cb.writeShort(AS_TRANS);
    } else {
        // write AS number in next 2-octet
        cb.writeShort((short) message.asNumber);
    }

    // write HoldTime in next 2-octet
    cb.writeShort(message.holdTime);

    // write BGP Identifier in next 4-octet
    cb.writeInt(message.bgpId);

    // store the index of Optional parameter length
    int optParaLenIndex = cb.writerIndex();

    // set optional parameter length as 0
    cb.writeByte(0);

    // Pack capability TLV
    optParaLen = message.packCapabilityTlv(cb, message);

    if (optParaLen != 0) {
        // Update optional parameter length
        cb.setByte(optParaLenIndex, (byte) (optParaLen + 2)); //+2 for optional parameter type.
    }

    // write OPEN Object Length
    int length = cb.writerIndex() - startIndex;
    cb.setShort(msgLenIndex, (short) length);
    message.bgpMsgHeader.setLength((short) length);
}
 
Example 6
Project: athena   File: PcepFecObjectIPv4Ver1.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    int objStartIndex = cb.writerIndex();

    //write common header
    int objLenIndex = fecObjHeader.write(cb);
    cb.writeInt(nodeID);

    //now write FEC IPv4 Object Length
    cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
    return cb.writerIndex();
}
 
Example 7
Project: athena   File: BgpFsDestinationPrefix.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeByte(FLOW_SPEC_TYPE);
    cb.writeByte(length);
    cb.writeInt(ipPrefix.getIp4Prefix().address().toInt());
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 8
Project: athena   File: BgpFsSourcePrefix.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeByte(FLOW_SPEC_TYPE);
    cb.writeByte(length);
    cb.writeInt(ipPrefix.getIp4Prefix().address().toInt());
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 9
Project: athena   File: AutonomousSystemSubTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 10
Project: athena   File: SrPceCapabilityTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(msd);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 11
Project: athena   File: SharedRiskLinkGroupSubTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(hLength);
    for (int b : srlgValue) {
        c.writeInt(b);
    }
    return c.writerIndex() - iLenStartIndex;
}
 
Example 12
Project: athena   File: PcepRPObjectVer1.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    //write Object header
    int objStartIndex = cb.writerIndex();

    int objLenIndex = rpObjHeader.write(cb);

    if (objLenIndex <= 0) {
        throw new PcepParseException("ObjectLength Index is " + objLenIndex);
    }
    int iTemp;
    iTemp = (yPriFlag);

    iTemp = (bOFlag) ? (iTemp | OFLAG_SHIFT_VALUE) : iTemp;
    iTemp = (bBFlag) ? (iTemp | BFLAG_SHIFT_VALUE) : iTemp;
    iTemp = (bRFlag) ? (iTemp | RFLAG_SHIFT_VALUE) : iTemp;

    cb.writeInt(iTemp);
    cb.writeInt(iRequestIdNum);

    // Add optional TLV
    packOptionalTlv(cb);

    //Update object length now
    int length = cb.writerIndex() - objStartIndex;

    //will be helpful during print().
    rpObjHeader.setObjLen((short) length);

    cb.setShort(objLenIndex, (short) length);
    return cb.writerIndex();
}
 
Example 13
Project: athena   File: IPv4SubObject.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    byte bValue = LBIT;
    bValue = (byte) (bValue << SHIFT_LBIT_POSITION);
    bValue = (byte) (bValue | TYPE);
    c.writeByte(bValue);
    c.writeByte(OBJ_LENGTH);
    c.writeInt(ipAddress);
    c.writeByte(prefixLen);
    c.writeByte(resvd);

    return c.writerIndex() - iLenStartIndex;
}
 
Example 14
Project: athena   File: GmplsCapabilityTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 15
Project: athena   File: AdministrativeGroupSubTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 16
Project: athena   File: BgpLSIdentifierTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(bgpLsIdentifier);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 17
Project: athena   File: PcepSrpObjectVer1.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    int objStartIndex = cb.writerIndex();

    //write common header
    int objLenIndex = srpObjHeader.write(cb);

    //write Flags
    byte bFlag;

    bFlag = (bRFlag) ? BBIT_SET : BBIT_RESET;
    bFlag |= (((bSFlag) ? BBIT_SET : BBIT_RESET) << 1);

    cb.writeInt(bFlag);

    //write SrpId
    cb.writeInt(srpId);

    // Add optional TLV
    if (!packOptionalTlv(cb)) {
        throw new PcepParseException("Failed to write srp tlv to channel buffer.");
    }

    //now write SRP Object Length
    cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));

    return cb.writerIndex();
}
 
Example 18
Project: athena   File: NexthopUnnumberedIPv4IDTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);

    c.writeInt(nodeID);
    c.writeInt(interfaceID);

    return c.writerIndex() - iLenStartIndex;
}
 
Example 19
Project: athena   File: PcepLspObjectVer1.java   Source Code and License Vote up 4 votes
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    //write Object header
    int objStartIndex = cb.writerIndex();

    int objLenIndex = lspObjHeader.write(cb);

    if (objLenIndex <= 0) {
        throw new PcepParseException("Failed to write lsp object header. Index " + objLenIndex);
    }

    int iTemp = iPlspId << PLSPID_SHIFT_VALUE;

    iTemp = iTemp | (((bCFlag) ? BIT_SET : BIT_RESET) << CFLAG_SHIFT_VALUE);

    iTemp = iTemp | (yOFlag << OFLAG_SHIFT_VALUE);
    byte bFlag;
    iTemp = bAFlag ? (iTemp | AFLAG_TEMP_SHIFT_VALUE) : iTemp;

    bFlag = (bRFlag) ? (byte) BIT_SET : BIT_RESET;
    iTemp = iTemp | (bFlag << RFLAG_SHIFT_VALUE);
    bFlag = (bSFlag) ? (byte) BIT_SET : BIT_RESET;
    iTemp = iTemp | (bFlag << SFLAG_SHIFT_VALUE);
    bFlag = (bDFlag) ? (byte) BIT_SET : BIT_RESET;
    iTemp = iTemp | bFlag;
    cb.writeInt(iTemp);

    // Add optional TLV
    packOptionalTlv(cb);

    //Update object length now
    int length = cb.writerIndex() - objStartIndex;
    //will be helpful during print().
    lspObjHeader.setObjLen((short) length);
    // As per RFC the length of object should be
    // multiples of 4

    cb.setShort(objLenIndex, (short) length);

    return length;
}
 
Example 20
Project: athena   File: PcepNaiIpv4NodeId.java   Source Code and License Vote up 4 votes
@Override
public int write(ChannelBuffer bb) {
    int iLenStartIndex = bb.writerIndex();
    bb.writeInt(identifier);
    return bb.writerIndex() - iLenStartIndex;
}