Beispiel #1
0
        public void ByteVector_Skip()
        {
            byte[] sample = Enumerable.Repeat((byte)0, 255).ToArray();
            sample[0] = (byte)BionToken.StartArray;
            sample[1] = (byte)BionToken.StartObject;

            sample[10] = (byte)BionToken.StartArray;
            sample[11] = (byte)BionToken.EndArray;

            sample[250] = (byte)BionToken.EndObject;
            sample[251] = (byte)BionToken.EndArray;

            uint depth;

            // Inside Object, find end
            depth = 1;
            Assert.AreEqual(250, ByteVector.Skip(sample, 2, sample.Length, ref depth));

            // Inside Object, find parent end (array)
            depth = 2;
            Assert.AreEqual(251, ByteVector.Skip(sample, 2, sample.Length, ref depth));

            // Inside array, find end
            depth = 1;
            Assert.AreEqual(251, ByteVector.Skip(sample, 1, sample.Length, ref depth));

            // Inside nothing, find end (not enough ends)
            depth = 1;
            Assert.AreEqual(255, ByteVector.Skip(sample, 0, sample.Length, ref depth));
        }
Beispiel #2
0
        public void SkipRest()
        {
            int depth = _currentDepth;

            // Find the closing container for the container we're in
            int innerDepth = 1;

            while (!_reader.EndOfStream)
            {
                _reader.EnsureSpace(16 * 1024);
                int endIndex = ByteVector.Skip(_reader.Buffer, _reader.Index, _reader.Length, ref innerDepth);

                if (endIndex < _reader.Length)
                {
                    _reader.Index = endIndex + 1;
                    _currentDepth = depth - 1;
                    return;
                }

                _reader.Index = _reader.Length;
            }
        }