BencodeReaderOptions Struct
Definition
Defines the customizations applied when creating a Utf8BencodeReader.
public struct BencodeReaderOptions
- Inherited Members
- Extension Methods
Remarks
Bencode has no comment syntax and no trailing-comma concept; the options relax the two dictionary-key rules that older real-world encoders are known to violate: AllowUnsortedKeys and AllowDuplicateKeys. Both default to the strict canonical behaviour.
// Torrents in the wild are not always canonical - relax the reader when ingesting,
// keep the defaults when validating.
var reader = new Utf8BencodeReader(torrentBytes, new BencodeReaderOptions
{
AllowUnsortedKeys = true,
AllowDuplicateKeys = false,
MaxDepth = 32,
});
Properties
AllowDuplicateKeys
Gets or sets a value indicating whether a dictionary may contain more than one entry for the same key.
public bool AllowDuplicateKeys { readonly get; set; }
Property Value
- bool
true to accept duplicate keys; the default of false rejects them with BencodeFormatException.
Remarks
The reader reports every entry it reads regardless of this option; which occurrence wins is decided by the consuming surface (the document model returns the first match from lookups, while the node tree and the serializer bind last-wins).
AllowUnsortedKeys
Gets or sets a value indicating whether dictionary keys may appear out of ascending bytewise order.
public bool AllowUnsortedKeys { readonly get; set; }
Property Value
- bool
true to accept unsorted keys; the default of false rejects them with BencodeFormatException.
Remarks
BEP 3 requires keys sorted by raw byte order, but documents produced by older encoders occasionally violate this. Unless AllowDuplicateKeys is also set, duplicate keys are still rejected.
MaxDepth
Gets or sets the maximum container nesting depth the reader will accept.
public int MaxDepth { readonly get; set; }
Property Value
- int
The maximum container nesting depth;
0selects the default of 64.
Remarks
The effective depth is clamped to the hard ceiling Bodu.Text.Bencode.BencodeLimits.AbsoluteMaxDepth; a document nested past the effective limit throws BencodeFormatException rather than risking a StackOverflowException.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |