Example #1
0
        /// <summary>
        /// 获取打印用的,具有可读性的字符串
        /// </summary>
        public string _GetDescription(int depth)
        {
            string blank     = LPCUtil.GetSpace(4 * depth);
            string blankNext = LPCUtil.GetSpace(4 * (depth + 1));

            // 如果没有成员,那么我们打印简单的形式
            if (Count == 0)
            {
                return(string.Format("{0}{1} {2}", blank, "({", "})"));
            }

            // 如果有成员,那么打印稍微复杂点的形式
            string str = string.Format("{0}{1} /* sizeof=={2} */ \n", blank, "({", this.Count);

            // 遍历每一个成员
            for (int i = 0; i < _list.Count; i++)
            {
                string childStr = _list [i]._GetDescription(depth + 1).Trim();
                str += string.Format("{0}{1},\n", blankNext, childStr);

                // 检查一下,不要太长
                if (str.Length > 40000)
                {
                    str += string.Format("{0}...\n", blankNext);
                    return(str);
                }
            }

            // 结束符号
            str += string.Format("{0}{1}\n", blank, "})");
            return(str);
        }
        /// <summary>
        /// 获取打印用的,具有可读性的字符串
        /// </summary>
        public string _GetDescription(int depth)
        {
            string blank     = LPCUtil.GetSpace(4 * depth);
            string blankNext = LPCUtil.GetSpace(4 * (depth + 1));

            // 如果为空mapping,那么我们打印一种简单的形式
            if (this.Count == 0)
            {
                return(string.Format("{0}([ ])", blank));
            }

            string str = string.Format("{0}([ /* sizeof=={1} */\n", blank, this.Count);

            // 遍历每一个成员 int
            if (_mapInt != null)
            {
                foreach (int key in _mapInt.Keys)
                {
                    string childValueStr = _mapInt[key]._GetDescription(depth + 1).TrimStart();

                    str += string.Format("{0}{1} : {2},\n", blankNext, key, childValueStr);

                    // 检查一下,不要太长
                    if (str.Length > 40000)
                    {
                        str += string.Format("{0}...\n", blankNext);
                        return(str);
                    }
                }
            }

            // 遍历每一个成员 string
            if (_mapStr != null)
            {
                foreach (string key in _mapStr.Keys)
                {
                    string childValueStr = _mapStr[key]._GetDescription(depth + 1).Trim();

                    str += string.Format("{0}\"{1}\" : {2},\n", blankNext, key, childValueStr);

                    // 检查一下,不要太长
                    if (str.Length > 40000)
                    {
                        str += string.Format("{0}...\n", blankNext);
                        return(str);
                    }
                }
            }

            // 结束符号
            str += string.Format("{0}])\n", blank);
            return(str);
        }
Example #3
0
        public string _GetDescription(int depth)
        {
            if (depth > 10)
            {
                throw new Exception("LPCValue层次太深(depth=" + depth + ")! 可能是出现自引用!");
            }

            string blank = LPCUtil.GetSpace(4 * depth);

            if (IsUndefined)
            {
                return(string.Format("{0}(undefined)", blank));
            }
            else if (IsInt)
            {
                return(string.Format("{0}{1}", blank, AsInt));
            }
            else if (IsFloat)
            {
                return(string.Format("{0}{1}", blank, AsFloat));
            }
            else if (IsString)
            {
                return(string.Format("{0}\"{1}\"", blank, AsString));
            }
            else if (IsBuffer)
            {
                return(string.Format("{0}<buffer:{1}>", blank, AsBuffer.Length));
            }
            else if (IsArray)
            {
                return(AsArray._GetDescription(depth));
            }
            else if (IsMapping)
            {
                return(AsMapping._GetDescription(depth));
            }

            Debug.Assert(false, "按理说不应该走到这里");
            return("");
        }
Example #4
0
        /// <summary>
        /// 将类型数据存储到指定的缓冲区中
        /// </summary>
        private static int _SaveTypeDataTo(int type, int len, byte[] buf, int offset)
        {
            Debug.Assert(type >= 0 && type < 15);

            int dataSize = LPCUtil.GetSaveBinaryIntSize(len);

            Debug.Assert(dataSize <= 15);

            // 打包第一个字节
            byte byte1 = ((byte)(type << 4));
            byte byte2 = ((byte)dataSize);

            buf [offset + 0] = (byte)(byte1 | byte2);

            // 打包长度,little endian
            for (int i = dataSize; i >= 1; i--)
            {
                buf [offset + i] = (byte)(len & 0xFF);
                len >>= 8;
            }

            // 保存了多少长度
            return(dataSize + 1);
        }