Table of Contents

BencodeWriterOptions Struct

Definition

Namespace
Bodu.Text.Bencode.Writer
Assembly
Bodu.Text.Bencode.dll
Package
Bodu.Text.Bencode 1.0.0
Source
BencodeWriterOptions.cs

Defines the customizations applied when creating a Utf8BencodeWriter.

public struct BencodeWriterOptions
Inherited Members
Extension Methods

Remarks

Bencode output is always canonical - dictionary keys are emitted in ascending bytewise order and there is no insignificant whitespace - so the options define no indentation or encoder settings.

var buffer = new ArrayBufferWriter<byte>();
var writer = new Utf8BencodeWriter(buffer, new BencodeWriterOptions
{
    MaxDepth = 32,
    AllowMultipleRootValues = false,   // one document per stream (the default)
});

Properties

AllowMultipleRootValues

Gets or sets a value indicating whether the writer accepts more than one value at the top level, concatenating the values in the output.

public bool AllowMultipleRootValues { readonly get; set; }

Property Value

bool

true to permit multiple root values; the default of false rejects a second root value with InvalidOperationException.

Remarks

A BEP 3 document is a single value, and the reader rejects trailing bytes after the root, so output produced with this option set cannot be re-read as one document. Enable it only for protocol framings that concatenate independent Bencode values on one stream.

MaxDepth

Gets or sets the maximum container nesting depth the writer will permit.

public int MaxDepth { readonly get; set; }

Property Value

int

The maximum container nesting depth; 0 selects the default of 64.

Remarks

The effective depth is clamped to the hard ceiling Bodu.Text.Bencode.BencodeLimits.AbsoluteMaxDepth; a larger value has no effect beyond it. Opening a list or dictionary nested past the effective limit throws BencodeSerializationException rather than risking a StackOverflowException.

Applies to

ProductVersions
.NET8, 10