Пример #1
0
        private bool handleMessage(StreamBuffer buffer)
        {
            bool isHandled = false;

            _unmarshalStream.replace(buffer);
            MessageType.Value mt = (MessageType.Value)_unmarshalStream.readByte();
            if (mt == MessageType.Value.csmtRpc)
            {
                UInt32 rpcIdValue = _unmarshalStream.readUInt32();
                isHandled = handleRpc(rpcIdValue, _unmarshalStream);
                if (!isHandled)
                {
                    throw new MessageException(string.Format("RPC({0}) not found", rpcIdValue));
                }
            }
            else
            {
                MessageCallback msgCallback;
                if (_messageCallbackMap.TryGetValue(mt, out msgCallback))
                {
                    Message message = MessageCache.query(msgCallback._messageClassType);
                    message.serialize(_unmarshalStream);
                    msgCallback._callback(message);

                    isHandled = true;
                }
                else
                {
                    throw new MessageException(string.Format("Message({0}) not found", mt.ToString()));
                }
            }
            ++receivePacketCount;
            return(isHandled);
        }
Пример #2
0
        public void registerMessageCallback(MessageType.Value mt, Action <Message> callback,
                                            Type messageClassType)
        {
            MessageCallback msgCallback = new MessageCallback();

            msgCallback._messageClassType = messageClassType;
            msgCallback._callback         = callback;
            _messageCallbackMap.Add(mt, msgCallback);
        }
Пример #3
0
        public bool parse()
        {
            if (isValid())
            {
                return(true); // 이미 헤더를 받은 경우
            }

            if (_inputStream.size() < packetHeaderSize)
            {
                return(false);
            }

            _bodySize    = _inputStream.readUInt16();
            _messageType = (MessageType.Value)_inputStream.readByte();
            return(true);
        }
Пример #4
0
 public void reset()
 {
     _bodySize    = 0;
     _messageType = MessageType.Value.csmtUnknown;
 }