Package net.hasor.rsf.protocol.block

Examples of net.hasor.rsf.protocol.block.ResponseSocketBlock


        //* byte[1]  keepData                             保留区
        buf.skipBytes(1);
        //* byte[3]  contentLength                        内容大小
        buf.skipBytes(3);//.readUnsignedMedium()
        //
        ResponseSocketBlock res = new ResponseSocketBlock();
        res.setVersion(version);
        res.setRequestID(requestID);
        //* --------------------------------------------------------bytes =8
        //* byte[2]  status                               响应状态
        res.setStatus(buf.readShort());
        //* byte[2]  serializeType-(attr-index)           序列化策略
        res.setSerializeType(buf.readShort());
        //* byte[2]  returnType-(attr-index)              返回类型
        res.setReturnType(buf.readShort());
        //* byte[2]  returnData-(attr-index)              返回数据
        res.setReturnData(buf.readShort());
        //* --------------------------------------------------------bytes =1 ~ 1021
        //* byte[1]  optionCount                          选项参数总数
        byte optionCount = buf.readByte();
        for (int i = 0; i < optionCount; i++) {
            //* byte[4]  attr-0-(attr-index,attr-index)   选项参数
            int mergeData = buf.readInt();
            res.addOption(mergeData);
        }
        //* --------------------------------------------------------bytes =6 ~ 8192
        //* byte[2]  attrPool-size (Max = 2047)           池大小
        short attrPoolSize = buf.readShort();
        for (int i = 0; i < attrPoolSize; i++) {
            //* byte[4] att-length                        属性1大小
            int length = buf.readInt();
            res.addPoolData(length);
        }
        //* --------------------------------------------------------bytes =n
        //* dataBody                                      数据内容
        res.fillFrom(buf.readBytes(res.getPoolSize()));
        return res;
    }
View Full Code Here


        }
        return socketMsg;
    };
    /**将{@link ResponseMsg}转换为{@link ResponseSocketBlock}消息。*/
    public static ResponseSocketBlock responseToBlock(ResponseMsg msg) {
        ResponseSocketBlock socketMsg = new ResponseSocketBlock();
        //1.基本信息
        byte version = ProtocolUtils.finalVersionForResponse(msg.getVersion());
        socketMsg.setVersion(version);//协议版本
        socketMsg.setRequestID(msg.getRequestID());//请求ID
        socketMsg.setStatus(msg.getStatus());//响应状态
        socketMsg.setSerializeType(pushString(socketMsg, msg.getSerializeType()));//序列化策略
        socketMsg.setReturnType(pushString(socketMsg, msg.getReturnType()));//返回类型
        socketMsg.setReturnData(socketMsg.pushData(msg.getReturnData()));//返回值
        //2.Opt参数
        String[] optKeys = msg.getOptionKeys();
        for (int i = 0; i < optKeys.length; i++) {
            socketMsg.addOption(//
                    pushString(socketMsg, optKeys[i]), pushString(socketMsg, msg.getOption(optKeys[i])));
        }
        return socketMsg;
    };
View Full Code Here

        }
        if (pType == ProtocolType.Response) {
            //response
            Protocol<ResponseSocketBlock> responseProtocol = ProtocolUtils.responseProtocol(version);
            if (responseProtocol != null) {
                ResponseSocketBlock block = responseProtocol.decode(frame);
                ResponseMsg resMetaData = TransferUtils.responseToMessage(block);
                ctx.fireChannelRead(resMetaData);
                return null;/*正常处理后返回*/
            }
        }
View Full Code Here

            RequestSocketBlock request = (RequestSocketBlock) msg;
            Protocol<RequestSocketBlock> requestProtocol = ProtocolUtils.requestProtocol(request.getVersion());
            requestProtocol.encode((RequestSocketBlock) msg, out);//request
        }
        if (msg instanceof ResponseSocketBlock) {
            ResponseSocketBlock response = (ResponseSocketBlock) msg;
            Protocol<ResponseSocketBlock> responseProtocol = ProtocolUtils.responseProtocol(response.getVersion());
            responseProtocol.encode((ResponseSocketBlock) msg, out);//response
        }
    }
View Full Code Here

TOP

Related Classes of net.hasor.rsf.protocol.block.ResponseSocketBlock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.