Example #1
0
    /// <summary>
    /// Decode the message.
    /// </summary>
    /// <returns>
    /// The message.
    /// </returns>
    /// <param name='msg'>
    /// MessageObject.
    /// </param>
    /// <param name='proto'>
    /// MessageObject.
    /// </param>
    /// <param name='length'>
    /// int.
    /// </param>
    private MessageObject DecodeMsg(MessageObject msg, MessageObject proto, int length)
    {
        while (this.offset < length)
        {
            Dictionary <string, int> head = this.GetHead();
            int tag;
            if (head.TryGetValue("tag", out tag))
            {
                object _tags = null;
                if (proto.TryGetValue("__tags", out _tags))
                {
                    object name;
                    if (((MessageObject)_tags).TryGetValue(tag.ToString(), out name))
                    {
                        object value;
                        if (proto.TryGetValue(name.ToString(), out value))
                        {
                            object option;
                            if (((MessageObject)(value)).TryGetValue("option", out option))
                            {
                                switch (option.ToString())
                                {
                                case "optional":
                                case "required":
                                    object type;
                                    if (((MessageObject)(value)).TryGetValue("type", out type))
                                    {
                                        msg.Add(name.ToString(), this.DecodeProp(type.ToString(), proto));
                                    }
                                    break;

                                case "repeated":
                                    object _name;
                                    if (!msg.TryGetValue(name.ToString(), out _name))
                                    {
                                        msg.Add(name.ToString(), new List <object>());
                                    }
                                    object value_type;
                                    if (msg.TryGetValue(name.ToString(), out _name) && ((MessageObject)(value)).TryGetValue("type", out value_type))
                                    {
                                        DecodeArray((List <object>)_name, value_type.ToString(), proto);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return(msg);
    }
    internal void _onError(string reason)
    {
        MessageObject jsonObj = new MessageObject();

        jsonObj.Add("reason", reason);
        Message msg = new Message(enMessageType.Sys, ErrorEvent, jsonObj);

        receiveMsgQueue.Enqueue(msg);
    }
    internal void _onDisconnect(string reason)
    {
        netWorkState = enNetWorkState.Disconnected;

        MessageObject jsonObj = new MessageObject();

        jsonObj.Add("reason", reason);
        Message msg = new Message(enMessageType.Sys, DisconnectEvent, jsonObj);

        receiveMsgQueue.Enqueue(msg);

        m_socket.Close();
        m_socket = null;
    }