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

The following examples show how to use org.jboss.netty.buffer.ChannelBuffer#writeByte() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemcachedBinaryResponseEncoder.java    From fqueue with Apache License 2.0 6 votes vote down vote up
public ChannelBuffer constructHeader(MemcachedBinaryCommandDecoder.BinaryCommand bcmd, ChannelBuffer extrasBuffer, ChannelBuffer keyBuffer, ChannelBuffer valueBuffer, short responseCode, int opaqueValue, long casUnique) {
    // take the ResponseMessage and turn it into a binary payload.
    ChannelBuffer header = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 24);
    header.writeByte((byte)0x81);  // magic
    header.writeByte(bcmd.code); // opcode
    short keyLength = (short) (keyBuffer != null ? keyBuffer.capacity() :0);

    header.writeShort(keyLength);
    int extrasLength = extrasBuffer != null ? extrasBuffer.capacity() : 0;
    header.writeByte((byte) extrasLength); // extra length = flags + expiry
    header.writeByte((byte)0); // data type unused
    header.writeShort(responseCode); // status code

    int dataLength = valueBuffer != null ? valueBuffer.capacity() : 0;
    header.writeInt(dataLength + keyLength + extrasLength); // data length
    header.writeInt(opaqueValue); // opaque

    header.writeLong(casUnique);

    return header;
}
 
Example 2
Source File: PcepLabelRangeObjectVer1.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Pack optional tlvs.
 *
 * @param cb of channel buffer
 * @return true
 */
protected boolean packOptionalTlv(ChannelBuffer cb) {

    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 true;
}
 
Example 3
Source File: OFFlowRemoved.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    super.writeTo(data);
    this.match.writeTo(data);
    data.writeLong(cookie);
    data.writeShort(priority);
    data.writeByte((byte) this.reason.ordinal());
    data.writeByte((byte) 0);
    data.writeInt(this.durationSeconds);
    data.writeInt(this.durationNanoseconds);
    data.writeShort(idleTimeout);
    data.writeByte((byte) 0); // pad
    data.writeByte((byte) 0); // pad
    data.writeLong(this.packetCount);
    data.writeLong(this.byteCount);
}
 
Example 4
Source File: FourOctetAsNumCapabilityTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeByte(TYPE);
    cb.writeByte(LENGTH);
    cb.writeInt(rawValue);
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 5
Source File: PcepOpenObjectVer1.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    int objStartIndex = cb.writerIndex();

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

    if (objLenIndex <= 0) {
        throw new PcepParseException("Unable to write Open object header.");
    }

    cb.writeByte((byte) (OPEN_OBJECT_VERSION << PcepMessageVer1.SHIFT_FLAG));
    cb.writeByte(this.keepAliveTime);
    cb.writeByte(this.deadTime);
    cb.writeByte(this.sessionId);

    //Pack optional TLV
    packOptionalTlv(cb);

    //now write OPEN Object Length
    int length = cb.writerIndex() - objStartIndex;
    cb.setShort(objLenIndex, (short) length);
    //will be helpful during print().
    this.openObjHeader.setObjLen((short) length);

    return length;
}
 
Example 6
Source File: OFActionMirror.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    super.writeTo(data);
    data.writeInt(this.destPort);
    data.writeInt(this.vlanTag);
    data.writeByte(this.copyStage);
    data.writeByte(this.pad0);
    data.writeByte(this.pad1);
    data.writeByte(this.pad2);
}
 
Example 7
Source File: IPReachabilityInformationTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeShort(TYPE);
    cb.writeShort(length);
    cb.writeByte(prefixLen);
    cb.writeBytes(ipPrefix);
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 8
Source File: ControlMessageEncoder.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private void encodeMap(Map<?, ?> map, ChannelBuffer out) throws ProtocolException {
    out.writeByte((byte) ControlMessageProtocolConstant.CONTROL_CHARACTER_MAP_START);
    for (Object element : map.entrySet()) {
        Map.Entry<?, ?> entry = (Map.Entry<?, ?>) element;
        encode(entry.getKey(), out);
        encode(entry.getValue(), out);
    }
    out.writeByte((byte) ControlMessageProtocolConstant.CONTROL_CHARACTER_MAP_END);
}
 
Example 9
Source File: IsIsPseudonode.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeBytes(isoNodeID, 0, LENGTH - 1);
    c.writeByte(psnIdentifier);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 10
Source File: PcepRsvpUserErrorSpec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int objLenIndex = objHeader.write(cb);
    cb.writeInt(enterpriseNum);
    cb.writeByte(subOrg);
    cb.writeByte(errDescLen);
    cb.writeShort(userErrorValue);
    cb.writeBytes(errDesc);

    if (llRsvpUserSpecSubObj != null) {

        ListIterator<PcepValueType> listIterator = llRsvpUserSpecSubObj.listIterator();

        while (listIterator.hasNext()) {
            PcepValueType tlv = listIterator.next();
            if (tlv == null) {
                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);
                }
            }
        }
    }
    short objLen = (short) (cb.writerIndex() - objLenIndex);
    cb.setShort(objLenIndex, objLen);
    return objLen;
}
 
Example 11
Source File: PcepErrorMsgVer1.java    From onos with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 12
Source File: BgpFsFragment.java    From onos with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: BgpFlowSpecNlri.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Update buffer with non-identical flow types.
 *
 * @param cb channel buffer
 * @param bgpFlowSpecNlri flow specification
 */
public static void updateBufferNonIdenticalFlowTypes(ChannelBuffer cb, BgpFlowSpecNlri bgpFlowSpecNlri) {
    ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer();
    List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    ListIterator<BgpValueType> listIterator = flowSpec.listIterator();
    int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex();

    flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    listIterator = flowSpec.listIterator();

    while (listIterator.hasNext()) {
        BgpValueType tlv = listIterator.next();
        writeFlowType(tlv, flowSpecTmpBuff);
    }

    /* RFC 5575: section 4,  If the NLRI length value is smaller than 240 (0xf0 hex), the length
                             field can be encoded as a single octet.  Otherwise, it is encoded as
                             an extended-length 2-octet values */
    int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx;
    if (len >= FLOW_SPEC_LEN) {
        cb.writeShort(len);
    } else {
        cb.writeByte(len);
    }
    //Copy from bynamic buffer to channel buffer
    cb.writeBytes(flowSpecTmpBuff);
}
 
Example 14
Source File: PcepLspObjectVer1.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * returns writer index.
 *
 * @param cb of type channel buffer
 * @return length of bytes written to channel buffer
 */
protected int packOptionalTlv(ChannelBuffer cb) {

    ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
    int startIndex = cb.writerIndex();

    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;
}
 
Example 15
Source File: ControlMessageEncoder.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private void encodeBoolean(boolean value, ChannelBuffer out) {
    if (value) {
        out.writeByte((byte) ControlMessageProtocolConstant.TYPE_CHARACTER_BOOL_TRUE);
    } else {
        out.writeByte((byte) ControlMessageProtocolConstant.TYPE_CHARACTER_BOOL_FALSE);
    }
}
 
Example 16
Source File: NextHop.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeByte(FLAGS);
    cb.writeByte(getType());
    if (!isNextHopSet()) {
        cb.writeByte(0);
    } else {
        cb.writeInt(nextHop.toInt());
    }

    return cb.writerIndex() - iLenStartIndex;
}
 
Example 17
Source File: PcepRsvpIpv6ErrorSpec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int objLenIndex = objHeader.write(cb);
    cb.writeBytes(ipv6Addr);
    cb.writeByte(flags);
    cb.writeByte(errCode);
    cb.writeShort(errValue);
    short objLen = (short) (cb.writerIndex() - objLenIndex);
    cb.setShort(objLenIndex, objLen);
    return objLen;
}
 
Example 18
Source File: BgpFsSourcePrefix.java    From onos with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: BgpFsTcpFlags.java    From onos with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 20
Source File: Message.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public void writeCString( String str, ChannelBuffer buffer ) {
    if ( str != null ) {
        buffer.writeBytes( str.getBytes( Charset.forName( "UTF-8" ) ) );
    }
    buffer.writeByte( 0 );
}