コード例 #1
0
        static ArraySegment <Byte> _Parse(ArraySegment <Byte> bytes, List <MsgPackValue> values, int parentIndex)
        {
            MsgPackType formatType = GetFormat(bytes);

            if (formatType.IsArray())
            {
                var index  = values.Count;
                var offset = bytes.Offset;
                values.Add(new MsgPackValue(bytes, parentIndex));

                uint count;
                bytes = GetItemCount(bytes, formatType, out count);
                for (var i = 0; i < count; ++i)
                {
                    bytes = _Parse(bytes, values, index);
                }

                values[index] = new MsgPackValue(
                    new ArraySegment <byte>(bytes.Array,
                                            offset, bytes.Offset - offset),
                    parentIndex);
            }
            else if (formatType.IsMap())
            {
                var index  = values.Count;
                var offset = bytes.Offset;
                values.Add(new MsgPackValue(bytes, parentIndex));

                uint count;
                bytes = GetItemCount(bytes, formatType, out count);
                for (var i = 0; i < count; ++i)
                {
                    // key
                    bytes = _Parse(bytes, values, index);

                    // value
                    bytes = _Parse(bytes, values, index);
                }

                values[index] = new MsgPackValue(
                    new ArraySegment <byte>(bytes.Array,
                                            offset, bytes.Offset - offset),
                    parentIndex);
            }
            else
            {
                var body       = GetBody(bytes, formatType);
                var headerSize = body.Offset - bytes.Offset;
                var size       = headerSize + body.Count;
                values.Add(new MsgPackValue(bytes.Take(size), parentIndex));
                bytes = bytes.Advance(size);
            }
            return(bytes);
        }
コード例 #2
0
ファイル: MsgPackParser.cs プロジェクト: gpsnmeajp/Oredayo4V
        static ListTreeNode <MsgPackValue> _Parse(ListTreeNode <MsgPackValue> tree, ArraySegment <Byte> bytes)
        {
            MsgPackType formatType = GetFormat(bytes);

            if (formatType.IsArray())
            {
                var array = tree.AddValue(bytes, ValueNodeType.Array);

                uint count;
                bytes = GetItemCount(bytes, formatType, out count);
                for (var i = 0; i < count; ++i)
                {
                    var child = _Parse(array, bytes);
                    bytes = bytes.Advance(child.Value.Bytes.Count);
                }

                array.SetValueBytesCount(bytes.Offset - array.Value.Bytes.Offset);

                return(array);
            }
            else if (formatType.IsMap())
            {
                var obj = tree.AddValue(bytes, ValueNodeType.Object);

                uint count;
                bytes = GetItemCount(bytes, formatType, out count);
                for (var i = 0; i < count; ++i)
                {
                    // key
                    var key = _Parse(obj, bytes);
                    bytes = bytes.Advance(key.Value.Bytes.Count);

                    // value
                    var value = _Parse(obj, bytes);
                    bytes = bytes.Advance(value.Value.Bytes.Count);
                }

                obj.SetValueBytesCount(bytes.Offset - obj.Value.Bytes.Offset);

                return(obj);
            }
            else
            {
                var body       = GetBody(bytes, formatType);
                var headerSize = body.Offset - bytes.Offset;
                var size       = headerSize + body.Count;

                var value = tree.AddValue(bytes.Take(size), ValueNodeType.Null);
                return(value);
            }
        }
コード例 #3
0
        public static ParserValueType ToParserValueType(this MsgPackType formatType)
        {
            switch (formatType)
            {
            case MsgPackType.FLOAT:
                return(ParserValueType.Float);

            case MsgPackType.DOUBLE:
                return(ParserValueType.Double);

            case MsgPackType.TRUE:
            case MsgPackType.FALSE:
                return(ParserValueType.Boolean);
            }
            if (formatType.IsArray())
            {
                return(ParserValueType.List);
            }
            else if (formatType.IsMap())
            {
                return(ParserValueType.Map);
            }
            else if (formatType.IsInteger())
            {
                return(ParserValueType.Integer);
            }
            else if (formatType.IsString())
            {
                return(ParserValueType.String);
            }
            else if (formatType.IsBinary())
            {
                return(ParserValueType.Bytes);
            }
            else
            {
                return(ParserValueType.Unknown);
            }
        }