Esempio n. 1
0
        public void Map(Action <IFlexBufferMapBuilder> map)
        {
            var start   = _buffer.StartVector();
            var builder = new FlexBufferMapBuilder(_buffer);

            map(builder);
            _buffer.SortAndEndMap(start);
        }
Esempio n. 2
0
        public void Map(string key, Action <IFlexBufferMapBuilder> map)
        {
            _buffer.AddKey(key);
            var start   = _buffer.StartVector();
            var builder = new FlexBufferMapBuilder(_buffer);

            map(builder);
            _buffer.SortAndEndMap(start);
        }
Esempio n. 3
0
        public static byte[] Map(Action <IFlexBufferMapBuilder> map)
        {
            var buffer  = new FlexBuffer();
            var start   = buffer.StartVector();
            var builder = new FlexBufferMapBuilder(buffer);

            map(builder);
            buffer.SortAndEndMap(start);
            return(buffer.Finish());
        }
        private void ReadObject(FlexBuffer flx)
        {
            _scanner.Assert('{');

            _scanner.SkipWhitespace();

            var start = flx.StartVector();

            if (_scanner.Peek() == '}')
            {
                _scanner.Read();
            }
            else
            {
                while (true)
                {
                    _scanner.SkipWhitespace();

                    ReadString(flx, true);

                    _scanner.SkipWhitespace();

                    _scanner.Assert(':');

                    _scanner.SkipWhitespace();

                    ReadJsonValue(flx);

                    _scanner.SkipWhitespace();

                    var next = _scanner.Read();

                    if (next == '}')
                    {
                        break;
                    }

                    if (next == ',')
                    {
                        continue;
                    }
                    throw new Exception($"Unexpected character {next} at position {_scanner.Position}");
                }
            }

            flx.SortAndEndMap(start);
        }
        private static void Process(FlexBuffer flx, XmlNode element)
        {
            var node = flx.StartVector();

            flx.AddKey("tagName");
            flx.Add(element.Name);
            var attributes = element.Attributes;

            if (attributes != null)
            {
                for (var i = 0; i < attributes.Count; i++)
                {
                    var att = attributes.Item(i);
                    flx.AddKey(att.Name);
                    flx.Add(att.Value);
                }
            }

            var children = element.ChildNodes;

            if (children.Count > 0)
            {
                flx.AddKey("children");
                var childVector = flx.StartVector();
                for (var i = 0; i < children.Count; i++)
                {
                    var child = children[i];
                    if (child.NodeType == XmlNodeType.Text || child.NodeType == XmlNodeType.CDATA)
                    {
                        flx.Add(child.Value);
                    }
                    else if (child.NodeType == XmlNodeType.Comment)
                    {
                    }
                    else
                    {
                        Process(flx, child);
                    }
                }

                flx.EndVector(childVector, false, false);
            }
            flx.SortAndEndMap(node);
        }