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); }
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); }
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); }
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); }
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); }
private void Write(BionMarker marker, byte lengthOrValue) { Write((byte)((byte)marker | lengthOrValue)); }
private void Write(BionMarker marker) { Write((byte)marker); }