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


Java ChannelBuffer.writeByte方法代碼示例

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


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

示例1: sendPhotoRequest

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void sendPhotoRequest(Channel channel, int pictureId) {
    if (channel != null) {
        ChannelBuffer photo = photos.get(pictureId);
        ChannelBuffer response = ChannelBuffers.dynamicBuffer();
        response.writeShort(0x7878); // header
        response.writeByte(15); // size
        response.writeByte(MSG_X1_PHOTO_DATA);
        response.writeInt(pictureId);
        response.writeInt(photo.writerIndex());
        response.writeShort(Math.min(photo.writableBytes(), 1024));
        response.writeShort(++serverIndex);
        response.writeShort(Checksum.crc16(Checksum.CRC16_X25,
                response.toByteBuffer(2, response.writerIndex() - 2)));
        response.writeByte('\r'); response.writeByte('\n'); // ending
        channel.write(response);
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:18,代碼來源:Gt06ProtocolDecoder.java

示例2: prepareBgpUpdateNotificationDataPayload

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Prepares BGP UPDATE Notification data payload.
 *
 * @param attrTypeCode the attribute type code
 * @param attrLen the attribute length (in octets)
 * @param attrFlags the attribute flags
 * @param message the message with the data
 * @return the buffer with the data payload for the BGP UPDATE Notification
 */
private static ChannelBuffer prepareBgpUpdateNotificationDataPayload(
                                    int attrTypeCode,
                                    int attrLen,
                                    int attrFlags,
                                    ChannelBuffer message) {
    // Compute the attribute length field octets
    boolean extendedLengthBit = ((0x10 & attrFlags) != 0);
    int attrLenOctets = 1;
    if (extendedLengthBit) {
        attrLenOctets = 2;
    }
    ChannelBuffer data =
        ChannelBuffers.buffer(attrLen + attrLenOctets + 1);
    data.writeByte(attrTypeCode);
    if (extendedLengthBit) {
        data.writeShort(attrLen);
    } else {
        data.writeByte(attrLen);
    }
    data.writeBytes(message, attrLen);
    return data;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:32,代碼來源:BgpUpdate.java

示例3: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public void write(ChannelBuffer cb, PcepOpenMsgVer1 message) throws PcepParseException {
    int startIndex = cb.writerIndex();
    // first 3 bits set to version
    cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
    // message type
    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);

    message.getPcepOpenObject().write(cb);

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

示例4: processArray

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private Object processArray(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
    List<Position> positions = new LinkedList<>();
    int count = buf.readUnsignedByte();

    for (int i = 0; i < count; i++) {
        Position position = parsePosition(deviceSession, buf).getPosition();
        if (position.getFixTime() != null) {
            positions.add(position);
        }
    }

    ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8);
    response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<A", StandardCharsets.US_ASCII));
    response.writeByte(count);
    sendReply(channel, response);

    if (positions.isEmpty()) {
        return null;
    }

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

示例5: encodePackedPrefixes

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Encodes a collection of IPv4 network prefixes in a packed format.
 * <p>
 * The IPv4 prefixes are encoded in the form:
 * <Length, Prefix> where Length is the length in bits of the IPv4 prefix,
 * and Prefix is the IPv4 prefix (padded with trailing bits to the end
 * of an octet).
 *
 * @param prefixes the prefixes to encode
 * @return the buffer with the encoded prefixes
 */
private ChannelBuffer encodePackedPrefixes(Collection<Ip4Prefix> prefixes) {
    ChannelBuffer message =
        ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);

    // Write each of the prefixes
    for (Ip4Prefix prefix : prefixes) {
        int prefixBitlen = prefix.prefixLength();
        int prefixBytelen = (prefixBitlen + 7) / 8;         // Round-up
        message.writeByte(prefixBitlen);

        Ip4Address address = prefix.address();
        long value = address.toInt() & 0xffffffffL;
        for (int i = 0; i < Ip4Address.BYTE_LENGTH; i++) {
            if (prefixBytelen-- == 0) {
                break;
            }
            long nextByte =
                (value >> ((Ip4Address.BYTE_LENGTH - i - 1) * 8)) & 0xff;
            message.writeByte((int) nextByte);
        }
    }

    return message;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:36,代碼來源:TestBgpPeerChannelHandler.java

示例6: sendResponse

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void sendResponse(Channel channel, String type, String... arguments) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.dynamicBuffer();
        response.writeBytes(ChannelBuffers.copiedBuffer(type, StandardCharsets.US_ASCII));
        for (String argument : arguments) {
            response.writeByte(argument.length());
            response.writeBytes(ChannelBuffers.copiedBuffer(argument, StandardCharsets.US_ASCII));
        }
        response.writeByte(0);
        channel.write(response);
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:13,代碼來源:TlvProtocolDecoder.java

示例7: sendReply

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void sendReply(Channel channel, int checksum) {
    ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3);
    reply.writeByte(0x02);
    reply.writeShort((short) checksum);
    if (channel != null) {
        channel.write(reply);
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:9,代碼來源:BlackKiteProtocolDecoder.java

示例8: 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,代碼來源:BgpFsTcpFlags.java

示例9: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public int write(ChannelBuffer c) {
    int tlvStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    int tlvLenIndex = c.writerIndex();
    hLength = 0;
    c.writeShort(hLength);

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

    while (listIterator.hasNext()) {
        PcepValueType tlv = listIterator.next();

        tlv.write(c);

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

        if (0 != pad) {
            pad = 4 - pad;
            for (int i = 0; i < pad; ++i) {
                c.writeByte((byte) 0);
            }
        }
    }

    hLength = (short) (c.writerIndex() - tlvStartIndex);
    c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH));

    return c.writerIndex() - tlvStartIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:32,代碼來源:NodeAttributesTlv.java

示例10: 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,代碼來源:BgpFsSourcePortNum.java

示例11: write

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

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

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

    //Convert to bytes per second
    float bwBytes = iBandwidth / 8.0f;
    //Bytes/sec to IEEE floating format
    int bandwidth = Float.floatToIntBits(bwBytes);

    cb.writeByte(bandwidth >>> 24);
    cb.writeByte(bandwidth >> 16 & 0xff);
    cb.writeByte(bandwidth >> 8 & 0xff);
    cb.writeByte(bandwidth & 0xff);

    short hLength = (short) (cb.writerIndex() - objStartIndex);
    cb.setShort(objLenIndex, hLength);
    //will be helpful during print().
    bandwidthObjHeader.setObjLen(hLength);

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

示例12: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@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;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:34,代碼來源:PcepRsvpUserErrorSpec.java

示例13: write

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Writes Byte stream of BGP header to channel buffer.
 *
 * @param cb ChannelBuffer
 * @return length index of message header
 */
public int write(ChannelBuffer cb) {

    cb.writeBytes(getMarker(), 0, MARKER_LENGTH);

    int headerLenIndex = cb.writerIndex();
    cb.writeShort((short) 0);
    cb.writeByte(type);

    return headerLenIndex;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:17,代碼來源:BgpHeader.java

示例14: encodeAsPath

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Encodes an AS path.
 *
 * @param asPath the AS path to encode
 * @return the buffer with the encoded AS path
 */
private ChannelBuffer encodeAsPath(BgpRouteEntry.AsPath asPath) {
    ChannelBuffer message =
        ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);

    for (BgpRouteEntry.PathSegment pathSegment : asPath.getPathSegments()) {
        message.writeByte(pathSegment.getType());
        message.writeByte(pathSegment.getSegmentAsNumbers().size());
        for (Long asNumber : pathSegment.getSegmentAsNumbers()) {
            message.writeShort(asNumber.intValue());
        }
    }

    return message;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:21,代碼來源:TestBgpPeerChannelHandler.java

示例15: encodeCommand

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object encodeCommand(Command command) {

    ChannelBuffer content = ChannelBuffers.dynamicBuffer();

    switch (command.getType()) {
        case Command.TYPE_POSITION_SINGLE:
            return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_REQUEST, content);
        case Command.TYPE_POSITION_PERIODIC:
            content.writeShort(command.getInteger(Command.KEY_FREQUENCY));
            return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
        case Command.TYPE_POSITION_STOP:
            content.writeShort(0);
            return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
        case Command.TYPE_SET_TIMEZONE:
            int timezone = TimeZone.getTimeZone(command.getString(Command.KEY_TIMEZONE)).getRawOffset() / 60000;
            if (timezone < 0) {
                content.writeByte(1);
            } else {
                content.writeByte(0);
            }
            content.writeShort(Math.abs(timezone));
            return encodeContent(CityeasyProtocolDecoder.MSG_TIMEZONE, content);
        default:
            Log.warning(new UnsupportedOperationException(command.getType()));
            break;
    }

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


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