当前位置: 首页>>代码示例>>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;未经允许,请勿转载。