GameFramework.JsonGmMessageDispatcher.DecodeJsonMessage C# (CSharp) Method

DecodeJsonMessage() static private method

static private DecodeJsonMessage ( byte data ) : JsonMessage
data byte
return JsonMessage
        internal static JsonMessage DecodeJsonMessage(byte[] data)
        {
            JsonMessage msg = null;
              if (s_Inited) {
            string msgStr = null;
            try {
              msgStr = System.Text.Encoding.UTF8.GetString(data);
              int ix = msgStr.IndexOf('|');
              if (ix > 0) {
            int id = int.Parse(msgStr.Substring(0, ix));
            int ix2 = msgStr.IndexOf('|', ix + 1);
            msg = new JsonMessage(id);
            if (ix2 > 0) {
              string jsonStr = msgStr.Substring(ix + 1, ix2 - ix - 1);
              string protoStr = msgStr.Substring(ix2 + 1);
              msg.m_JsonData = JsonMapper.ToObject(jsonStr);
              Type t = s_MessageHandlers[id].m_ProtoType;
              if (null != t) {
                byte[] bytes = Convert.FromBase64String(protoStr);
                msg.m_ProtoData = Encoding.Decode(t, bytes);
              }
            } else {
              string jsonStr = msgStr.Substring(ix + 1);
              msg.m_JsonData = JsonMapper.ToObject(jsonStr);
            }
              }
            } catch (Exception ex) {
              if (null == msgStr) {
            LogSys.Log(LOG_TYPE.ERROR, "[Exception] DecodeJsonMessage:{0}\n{1}", ex.Message, ex.StackTrace);
              } else {
            LogSys.Log(LOG_TYPE.ERROR, "[Exception] DecodeJsonMessage:{0} {1}\n{2}", msgStr, ex.Message, ex.StackTrace);
              }
            }
              }
              return msg;
        }