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);
        }
Esempio n. 2
0
        public static byte[] SingleValue(long x, long y)
        {
            var buffer = new FlexBuffer(20);
            var start  = buffer.StartVector();

            buffer.Add(x);
            buffer.Add(y);
            buffer.EndVector(start, true, true);
            return(buffer.Finish());
        }
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());
        }
Esempio n. 4
0
        public static byte[] Vector(Action <IFlexBufferVectorBuilder> vector)
        {
            var buffer  = new FlexBuffer();
            var start   = buffer.StartVector();
            var builder = new FlexBufferVectorBuilder(buffer);

            vector(builder);
            buffer.EndVector(start, false, false);
            return(buffer.Finish());
        }
Esempio n. 5
0
        public static byte[] SingleValue(double x, double y, double z)
        {
            var buffer = new FlexBuffer(28);
            var start  = buffer.StartVector();

            buffer.Add(x);
            buffer.Add(y);
            buffer.Add(z);
            buffer.EndVector(start, true, true);
            return(buffer.Finish());
        }
Esempio n. 6
0
        public static byte[] SingleValue(ulong x, ulong y, ulong z, ulong w)
        {
            var buffer = new FlexBuffer(36);
            var start  = buffer.StartVector();

            buffer.Add(x);
            buffer.Add(y);
            buffer.Add(z);
            buffer.Add(w);
            buffer.EndVector(start, true, true);
            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 void ReadArray(FlexBuffer flx)
        {
            _scanner.Assert('[');

            var start = flx.StartVector();

            _scanner.SkipWhitespace();

            if (_scanner.Peek() == ']')
            {
                _scanner.Read();
            }
            else
            {
                while (true)
                {
                    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.EndVector(start, false, false);
        }
        public static byte[] Convert(string csv, char separator = ',')
        {
            var flx              = new FlexBuffer();
            var sb               = new StringBuilder();
            var outerVec         = flx.StartVector();
            var innerVec         = -1;
            var isInDoubleQuotes = false;

            for (var offset = 0; offset < csv.Length;)
            {
                if (innerVec == -1)
                {
                    innerVec = flx.StartVector();
                }

                if (csv[offset] == '"')
                {
                    if (isInDoubleQuotes == false)
                    {
                        isInDoubleQuotes = true;
                        offset++;
                    }
                    else
                    {
                        if (csv.Length > offset + 1 && csv[offset + 1] == '"')
                        {
                            sb.Append('"');
                            offset += 2;
                        }
                        else
                        {
                            isInDoubleQuotes = false;
                            offset++;
                        }
                    }
                }
                else if (csv[offset] == separator && isInDoubleQuotes == false)
                {
                    flx.Add(sb.ToString());
                    sb.Clear();
                    offset++;
                }
                else if (csv[offset] == '\n' && isInDoubleQuotes == false)
                {
                    flx.Add(sb.ToString());
                    flx.EndVector(innerVec, false, false);
                    innerVec = -1;
                    sb.Clear();
                    offset++;
                }
                else if (csv[offset] == '\r' && csv.Length > offset + 1 && csv[offset + 1] == '\n' && isInDoubleQuotes == false)
                {
                    flx.Add(sb.ToString());
                    flx.EndVector(innerVec, false, false);
                    innerVec = -1;
                    sb.Clear();
                    offset += 2;
                }
                else
                {
                    sb.Append(csv[offset]);
                    offset++;
                }
            }

            if (innerVec != -1)
            {
                flx.Add(sb.ToString());
                flx.EndVector(innerVec, false, false);
            }
            flx.EndVector(outerVec, false, false);
            return(flx.Finish());
        }
Esempio n. 10
0
        public void Add(long x, long y)
        {
            var start = _buffer.StartVector();

            _buffer.Add(x);
            _buffer.Add(y);
            _buffer.EndVector(start, true, true);
        }
Esempio n. 11
0
        public void Add(string key, long x, long y)
        {
            _buffer.AddKey(key);
            var start = _buffer.StartVector();

            _buffer.Add(x);
            _buffer.Add(y);
            _buffer.EndVector(start, true, true);
        }