当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuf.getUnsignedInt方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBuf.getUnsignedInt方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.getUnsignedInt方法的具体用法?Java ByteBuf.getUnsignedInt怎么用?Java ByteBuf.getUnsignedInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.getUnsignedInt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUnadjustedFrameLength

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Decodes the specified region of the buffer into an unadjusted frame length.  The default implementation is
 * capable of decoding the specified region into an unsigned 8/16/24/32/64 bit integer.  Override this method to
 * decode the length field encoded differently.  Note that this method must not modify the state of the specified
 * buffer (e.g. {@code readerIndex}, {@code writerIndex}, and the content of the buffer.)
 *
 * @throws DecoderException
 *         if failed to decode the specified region
 */
protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) {
    buf = buf.order(order);
    long frameLength;
    switch (length) {
        case 1:
            frameLength = buf.getUnsignedByte(offset);
            break;
        case 2:
            frameLength = buf.getUnsignedShort(offset);
            break;
        case 3:
            frameLength = buf.getUnsignedMedium(offset);
            break;
        case 4:
            frameLength = buf.getUnsignedInt(offset);
            break;
        case 8:
            frameLength = buf.getLong(offset);
            break;
        default:
            throw new DecoderException(
                    "unsupported lengthFieldLength: " + lengthFieldLength + " (expected: 1, 2, 3, 4, or 8)");
    }
    return frameLength;
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:35,代码来源:LengthFieldBasedFrameDecoder.java

示例2: recvRpcMessage

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public byte[] recvRpcMessage(Socket socket) throws IOException, java.net.SocketTimeoutException {
    BufferedInputStream dataInput = new BufferedInputStream(socket.getInputStream());
    do {
        byte[] temp = new byte[Constants.BUFFER_SIZE];
        int n = dataInput.read(temp);
        if(n>0){
            readBuffer.write(temp,0,n);
        }
        if (n < 0 || n < Constants.BUFFER_SIZE) {
            break;
        }
    } while (true);
    byte[] readContent = readBuffer.toByteArray();
    ByteBuf in = Unpooled.buffer(readContent.length);
    in.writeBytes(readContent);
    int readable = in.readableBytes();
    int pos = 0;
    if (readable >= Constants.HEADER_SIZE) {
        // 检查Magic number
        if (in.getByte(pos) == 'N' && in.getByte(pos + 1) == 'R' && in.getByte(pos + 2) == 'P' && in.getByte(pos + 3) == 'C') {
        } else {
            logger.error("Wrong magic number!");
            closeSocket();
            throw new IOException("Wrong magic number!");
        }
        int totalSize = (int)in.getUnsignedInt(pos + 4);
        byte type = in.getByte(pos + 8);
        if (type == 0) {
            logger.debug("one request");
        } else if (type == 1) {
            logger.debug("one response");
        }
        if (readable < totalSize) {
            logger.warn("Not enough data");
            closeSocket();
            throw new IOException("Not enough data!");
        }
        // 开始解码报文
        in.skipBytes(Constants.HEADER_SIZE);
        byte[] dest = new byte[totalSize - Constants.HEADER_SIZE];
        in.readBytes(dest);
        return dest;
    } else {
        logger.warn("Not enough data header");
        closeSocket();
        throw new IOException("Not enough data header!");
    }
}
 
开发者ID:kevin-xu-158,项目名称:JavaNRPC,代码行数:49,代码来源:NrpcChannel.java

示例3: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    int readable = in.readableBytes();
    if (readable > Constants.MAX_FRAME_SIZE) {
        logger.error("Frame too big : {}, max is {}",new Object[]{readable,Constants.MAX_FRAME_SIZE});
        in.skipBytes(readable);
        ctx.close();
        throw new TooLongFrameException("Frame too big!");
    }
    int pos = 0;
    if(readable >= Constants.HEADER_SIZE){
        // 检查Magic number
        if(in.getByte(pos) == 'N' && in.getByte(pos+1) == 'R' && in.getByte(pos+2) == 'P' && in.getByte(pos+3) == 'C'){
        }else{
            logger.error("Wrong magic number!");
            in.skipBytes(readable);
            ctx.close();
            throw new WrongMagicNumException("Wrong magic number!");
        }
        int totalSize = (int)in.getUnsignedInt(pos+4);
        byte type = in.getByte(pos+8);
        if(type == 0){
            logger.debug("one request");
        }else if(type == 1){
            logger.debug("one response");
        }
        if(readable < totalSize ){
            return;
        }
        // 开始解码报文
        try{
            in.skipBytes(Constants.HEADER_SIZE);
            byte[] dest = new byte[totalSize-Constants.HEADER_SIZE];
            in.readBytes(dest);
            ByteArrayInputStream destByteInputStream = new ByteArrayInputStream(dest);
            NrpcMeta nrpcMeta = NrpcMeta.parseFrom(destByteInputStream);
            out.add(nrpcMeta);
        }catch(Exception ex) {
            logger.error(ex.getMessage(), ex);
            ctx.close();
            throw new DecodeException("NrpcMeta decode failed!");
        }
    }
}
 
开发者ID:kevin-xu-158,项目名称:JavaNRPC,代码行数:45,代码来源:NrpcDecoder.java


注:本文中的io.netty.buffer.ByteBuf.getUnsignedInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。