Struct BencodeSpanReader
Represents a reader that provides access to bencoded data.
Inherited Members
System.ValueType.Equals(System.Object)
System.ValueType.GetHashCode()
System.ValueType.ToString()
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: ItsyBitsy.Bencoding
Assembly: ItsyBitsy.Bencoding.dll
Syntax
public struct BencodeSpanReader
Constructors
| Improve this Doc View SourceBencodeSpanReader(ReadOnlySpan<Byte>)
Initializes a new BencodeSpanReader instance using the specified encoded
data.
Declaration
public BencodeSpanReader(ReadOnlySpan<byte> source)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | source | The span to read encoded data from. |
Properties
| Improve this Doc View SourcePosition
Gets or sets the position of the reader in the source span.
Declaration
public int Position { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
Setting the position puts the reader into a state in which it can read a value. For
example, if the position of the reader is set to the position of an element in a list,
the reader will be able to read only that element and not any subsequent elements. If
the position of the reader is set to position of a key, the reader will be able to read
the key as a value using ReadString() rather than ReadKey().
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | value is negative.
|
Methods
| Improve this Doc View SourceDispose()
Restores the state of the parent reader.
Declaration
public void Dispose()
Remarks
It is only necessary to call Dispose() if the
BencodeSpanReader was created using
CreateSpanReader().
|
Improve this Doc
View Source
ReadDictionary(Boolean)
Reads a dictionary and returns a BencodeSpanDictionary.
Declaration
public BencodeSpanDictionary ReadDictionary(bool skipDuplicateKeys = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | skipDuplicateKeys | If true, duplicate keys are skipped rather than causing InvalidBencodeException to be thrown. |
Returns
Type | Description |
---|---|
BencodeSpanDictionary | The dictionary. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a dictionary to be read. |
InvalidBencodeException | The reader encountered a duplicate key while reading the dictionary. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a value. |
UnsupportedBencodeException | The reader encountered an integer that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a string with a length that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a key with a length that is not in the supported range. |
ReadDictionaryHead()
Reads the beginning of a dictionary.
Declaration
public void ReadDictionaryHead()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a dictionary head to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read the beginning of a dictionary. |
ReadDictionaryTail()
Reads the end of a dictionary.
Declaration
public void ReadDictionaryTail()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a dictionary tail to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read the end of a dictionary. |
ReadInteger()
Reads an integer.
Declaration
public long ReadInteger()
Returns
Type | Description |
---|---|
System.Int64 | The integer that was read. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows an integer to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read an integer. |
UnsupportedBencodeException | The reader encountered an integer that is not in the supported range. |
ReadKey()
Reads a key.
Declaration
public ReadOnlySpan<byte> ReadKey()
Returns
Type | Description |
---|---|
System.ReadOnlySpan<System.Byte> | The key that was read. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a key to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a key. |
UnsupportedBencodeException | The reader encountered a key with a length that is not in the supported range. |
ReadKeyLength()
Determines the length of the key to be read.
Declaration
public int ReadKeyLength()
Returns
Type | Description |
---|---|
System.Int32 | The length of the key. |
Remarks
ReadKeyLength() will continue to return the same result until the key is
read or skipped.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a key to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a key. |
UnsupportedBencodeException | The reader encountered a key with a length that is not in the supported range. |
ReadList()
Reads a list and returns the positions of the elements.
Declaration
public BencodeList ReadList()
Returns
Type | Description |
---|---|
BencodeList | The list of positions of the list element values. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a list to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a value. |
UnsupportedBencodeException | The reader encountered an integer that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a string with a length that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a key with a length that is not in the supported range. |
ReadListHead()
Reads the beginning of a list.
Declaration
public void ReadListHead()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a list head to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read the beginning of a list. |
ReadListTail()
Reads the end of a list.
Declaration
public void ReadListTail()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a list tail to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read the end of a list. |
ReadString()
Reads a string.
Declaration
public ReadOnlySpan<byte> ReadString()
Returns
Type | Description |
---|---|
System.ReadOnlySpan<System.Byte> | The string that was read. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a string to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a string. |
UnsupportedBencodeException | The reader encountered a string with a length that is not in the supported range. |
ReadStringLength()
Determines the length of the string to be read.
Declaration
public int ReadStringLength()
Returns
Type | Description |
---|---|
System.Int32 | The length of the string. |
Remarks
ReadStringLength() will continue to return the same result until the
string is read or skipped.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a string to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a string. |
UnsupportedBencodeException | The reader encountered a string with a length that is not in the supported range. |
ReadTokenType()
Determines the type of token that the reader must read next.
Declaration
public BencodeTokenType ReadTokenType()
Returns
Type | Description |
---|---|
BencodeTokenType | The type of token that the reader must read next. |
Remarks
ReadTokenType() will continue to return the same result until the token is read or skipped.
ReadTokenType() returns None if the reader has previously encountered an error or if the reader is positioned after the end of the value.
Exceptions
Type | Condition |
---|---|
InvalidBencodeException | The reader encountered invalid data while attempting to read a token discriminator. |
ReadValueTo(ref BencodeSpanWriter)
Reads a value and writes it to a bencode writer.
Declaration
public void ReadValueTo(ref BencodeSpanWriter writer)
Parameters
Type | Name | Description |
---|---|---|
BencodeSpanWriter | writer | The bencode writer that the value read from the reader is written to. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a value to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a value. |
UnsupportedBencodeException | The reader encountered an integer that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a string with a length that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a key with a length that is not in the supported range. |
System.InvalidOperationException | The writer is not in a state that allows a value to be written. |
ReadValueTo(BencodeWriter)
Reads a value and writes it to a bencode writer.
Declaration
public void ReadValueTo(BencodeWriter writer)
Parameters
Type | Name | Description |
---|---|---|
BencodeWriter | writer | The bencode writer that the value read from the reader is written to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | writer is
null. |
System.InvalidOperationException | The reader is not in a state that allows a value to be read. |
InvalidBencodeException | The reader encountered invalid data while attempting to read a value. |
UnsupportedBencodeException | The reader encountered an integer that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a string with a length that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a key with a length that is not in the supported range. |
System.InvalidOperationException | The writer is not in a state that allows a value to be written. |
SkipKey()
Skips a key.
Declaration
public void SkipKey()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a key to be skipped. |
InvalidBencodeException | The reader encountered invalid data while attempting to skip a key. |
UnsupportedBencodeException | The reader encountered a key with a length that is not in the supported range. |
SkipValue()
Skips a value.
Declaration
public void SkipValue()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The reader is not in a state that allows a value to be skipped. |
InvalidBencodeException | The reader encountered invalid data while attempting to skip a value. |
UnsupportedBencodeException | The reader encountered an integer that is not in the supported range. |
UnsupportedBencodeException | The reader encountered a string with a length that is not in the supported range. |