示例#1
0
    private void onBlock(IByteBuffer data)
    {
        int sendId = data.readInt();

        if (this.responses.ContainsKey(sendId) == false)
        {
            return;
        }
        Response res = this.responses[sendId];
        // 移除
        this.responses.Remove(sendId);

        // 处理响应
        int typeId = data.readShort();
        //if (typeId == 200)
        //{
        //    res.onSuccess(data);
        //}
        //else
        //{
        //    data.setReadPos(data.getReadPos() - 2);
        //    res.onFault(data);
        //}
    }
示例#2
0
 /// <summary>
 /// 把数据划分成一个一个的包,以便上层解析
 /// 因为低是一个池子,所有的消息可能全黏在一起
 /// </summary>
 /// <param name="bytebuffer"></param>
 /// <returns></returns>
 public bool decode(IByteBuffer bytebuffer) 
 {
     if (bytebuffer.available() < 4)
         return false;
     int i = bytebuffer.getReadPos();
     int len = bytebuffer.readInt();
     if (len == 1014001516)
     {
         return true;
     }
     if (bytebuffer.available() < len)
     {
         bytebuffer.setReadPos(i);
         return false;
     }
     else
     {
         IByteBuffer message = ByteBufferManager.Instance.GetObj();
         message.writeByteBuffer(bytebuffer, len);
         bytebuffer.pack();
         recv(message);
         return true;
     }
 }