Exemplo n.º 1
0
        private void WriteEndContainer(BionMarker container)
        {
            Write(container);

            // End Index is bytes written *after* end marker, so seek will find the next thing
            _containerIndex?.End(_writer.BytesWritten);
        }
Exemplo n.º 2
0
        private void WriteStartContainer(BionMarker container)
        {
            // Start Index is bytes written *before* start marker, so seek will find the start marker
            _containerIndex?.Start(_writer.BytesWritten);

            Write(container);
        }
Exemplo n.º 3
0
        private void WriteFixedInteger(BionMarker marker, ulong value, byte length)
        {
            _writer.EnsureSpace(length + 1);
            int index = _writer.Index++;

            NumberConverter.WriteSevenBitFixed(_writer, value, length);
            _writer.Buffer[index] = (byte)(marker + length);
        }
Exemplo n.º 4
0
        private void WriteVariableInteger(BionMarker marker, ulong value)
        {
            _writer.EnsureSpace(11);
            int index = _writer.Index++;

            byte length = NumberConverter.WriteSevenBitExplicit(_writer, value);

            _writer.Buffer[index] = (byte)(marker + length);
        }
Exemplo n.º 5
0
        public bool Read()
        {
            _reader.EnsureSpace(20);

            // Check for end (after reading one thing at the root depth)
            if (_reader.EndOfStream)
            {
                TokenType = BionToken.None;
                return(false);
            }

            // Read the marker
            byte marker = _reader.Buffer[_reader.Index++];

            // Identify the token type and length
            _currentMarker = (BionMarker)marker;
            _currentLength = LengthLookup[marker];
            TokenType      = TokenLookup[marker];

            if (_currentLength < 0)
            {
                _currentLength                = LengthIncludingTerminator();
                _currentDecodedString         = null;
                _currentCompressedStringStart = _reader.Index;
                _reader.Index += _currentLength;
            }
            else if (_currentLength > 0)
            {
                // Read value (non-string) or length (string)
                _currentDecodedNumber = NumberConverter.ReadSevenBitExplicit(_reader, _currentLength);

                // Read value (string)
                if (marker >= 0xF0)
                {
                    _currentCompressedStringStart = -1;
                    _currentDecodedString         = null;
                    _currentLength = (int)_currentDecodedNumber;

                    _reader.EnsureSpace(_currentLength);
                    _currentString = String8.Reference(_reader.Buffer, _reader.Index, _currentLength);
                    _reader.Index += _currentLength;
                }
            }
            else
            {
                // Adjust depth (length 0 tokens only)
                _currentDepth += DepthLookup[marker];
            }

            if (TokenType == BionToken.None)
            {
                throw new BionSyntaxException($"Invalid Bion Token 0x{_currentMarker:X2} @{BytesRead:n0}.");
            }
            return(true);
        }
Exemplo n.º 6
0
 private void Write(BionMarker marker, byte lengthOrValue)
 {
     Write((byte)((byte)marker | lengthOrValue));
 }
Exemplo n.º 7
0
 private void Write(BionMarker marker)
 {
     Write((byte)marker);
 }