Class BencodeWriter
A writer that provides generation of bencoded data.
Inheritance
System.Object
BencodeWriter
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ItsyBitsy.Bencoding
Assembly: ItsyBitsy.Bencoding.dll
Syntax
public sealed class BencodeWriter
Constructors
| Improve this Doc View SourceBencodeWriter(IBufferWriter<Byte>, Boolean)
Initializes a new BencodeWriter instance using the specified destination
buffer.
Declaration
public BencodeWriter(IBufferWriter<byte> destination, bool skipValidation = false)
Parameters
Type | Name | Description |
---|---|---|
System.Buffers.IBufferWriter<System.Byte> | destination | The destination to write the encoded data into. |
System.Boolean | skipValidation | If true, keys are not checked for mis-ordering and duplication as they are being written. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | destination is
null. |
Properties
| Improve this Doc View SourceBufferedLength
Gets the number of bytes that have been written but not yet flushed to the underlying
System.Buffers.IBufferWriter<T>.
Declaration
public int BufferedLength { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceCreateSpanWriter()
Gets a BencodeSpanWriter that continues from the current state of this
writer.
Declaration
public BencodeSpanWriter CreateSpanWriter()
Returns
Type | Description |
---|---|
BencodeSpanWriter | A BencodeSpanWriter that continues from the current state of this writer. |
Remarks
Do not operate on this writer again until after calling
Dispose() on the BencodeSpanWriter.
|
Improve this Doc
View Source
Flush(Boolean)
Advances the underlying System.Buffers.IBufferWriter<T>.
Declaration
public void Flush(bool final = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | final | Indicates whether the value should be complete. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | final is
true and the value is incomplete. |
WriteDictionaryHead()
Writes the beginning of a dictionary.
Declaration
public void WriteDictionaryHead()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The writer is not in a state that allows a dictionary head to be written. |
System.InvalidOperationException | The writer reached the end of the destination buffer while writing the dictionary head. |
WriteDictionaryTail()
Writes the end of a dictionary.
Declaration
public void WriteDictionaryTail()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The writer is not in a state that allows a dictionary tail to be written. |
System.InvalidOperationException | The writer reached the end of the destination buffer while writing the dictionary tail. |
WriteInteger(Int64)
Writes an integer.
Declaration
public void WriteInteger(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | The integer to write. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The writer is not in a state that allows an integer to be written. |
System.InvalidOperationException | The writer reached the end of the destination buffer while writing the integer. |
WriteKey(ReadOnlySpan<Byte>)
Writes a key.
Declaration
public void WriteKey(ReadOnlySpan<byte> key)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | key | The key to write. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The writer is not in a state that allows a key to be written. |
System.InvalidOperationException | The writer reached the end of the destination buffer while writing the key. |
System.InvalidOperationException | The writer was constructed with validation enabled and the key being written is mis-ordered or duplicated. |
WriteListHead()
Writes the beginning of a list.
Declaration
public void WriteListHead()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The writer is not in a state that allows a list head to be written. |
System.InvalidOperationException | The writer reached the end of the destination buffer while writing the list head. |
WriteListTail()
Writes the end of a list.
Declaration
public void WriteListTail()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The writer is not in a state that allows a list tail to be written. |
System.InvalidOperationException | The writer reached the end of the destination buffer while writing the list tail. |
WriteString(ReadOnlySpan<Byte>)
Writes a string.
Declaration
public void WriteString(ReadOnlySpan<byte> value)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | value | The string to write. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The writer is not in a state that allows a string to be written. |
System.InvalidOperationException | The writer reached the end of the destination buffer while writing the string. |