Exemple #1
0
        private static void OutputHeadRes(PackageResHead headRes)
        {
            var msg = string.Format(
                "HeadRes: \n ActionId:{0},Des:{1},MsgId:{2},SesId:{3},Code{4},St:{5},UserId:{6}",
                headRes.ActionId,
                headRes.Description,
                headRes.MsgId,
                headRes.SessionId,
                headRes.StatusCode,
                headRes.StrTime,
                headRes.UserId);

            Console.WriteLine(msg);
        }
Exemple #2
0
        public static bool Unpack(byte[] data, out PackageResHead head, out string res)
        {
            head = null;
            byte[] bodyBytes;
            res = null;

            int pos        = 0;
            int dataLength = GetInt(data, ref pos);

            if (dataLength != data.Length)
            {
                return(false);
            }

            head             = new PackageResHead();
            head.StatusCode  = GetInt(data, ref pos);
            head.MsgId       = GetInt(data, ref pos);
            head.Description = GetString(data, ref pos);
            head.ActionId    = GetInt(data, ref pos);
            head.StrTime     = GetString(data, ref pos);
            //int bodyLen = data.Length - pos;
            int bodyLen = GetInt(data, ref pos);

            if (bodyLen > 0)
            {
                bodyBytes = new byte[bodyLen];
                Buffer.BlockCopy(data, pos, bodyBytes, 0, bodyLen);
                string str = Encoding.UTF8.GetString(bodyBytes);
                Console.WriteLine("Res: {0}", str);
                //res = JsonMapper.ToObject<BaseResData>(str);
                res = str;
            }
            else
            {
                bodyBytes = new byte[0];
            }
            return(true);
        }