Table of Contents

BencodeProperty Struct

Definition

Namespace
Bodu.Text.Bencode.Document
Assembly
Bodu.Text.Bencode.dll
Package
Bodu.Text.Bencode 1.3.0
Source
BencodeProperty.cs

Represents a single key/value pair within an object BencodeElement. Instances are produced by BencodeElement.ObjectEnumerator.

public readonly struct BencodeProperty
Inherited Members
Extension Methods

Remarks

A Bencode dictionary key is a byte string, and need not be text: a tracker's scrape response, for example, keys its files by 20-byte info hashes. Name decodes the key as UTF-8 for convenience, so a key that is not valid UTF-8 reads with U+FFFD in place of each invalid sequence and two such keys can share a name. GetNameBytes() and NameEquals(ReadOnlySpan<byte>) read the key's exact bytes.

The Value and the key's bytes are views onto the owning BencodeDocument and are valid only for that document's lifetime; after the document is disposed, reading them throws ObjectDisposedException. Name is decoded when the property is produced and stays readable.

Properties

Name

Gets the property name, decoded from the dictionary key as UTF-8 text.

public string Name { get; }

Property Value

string

The property name. A key that is not valid UTF-8 decodes with U+FFFD in place of each invalid sequence; use GetNameBytes() or NameEquals(ReadOnlySpan<byte>) for the key's exact bytes.

Value

Gets the property value.

public BencodeElement Value { get; }

Property Value

BencodeElement

A BencodeElement view of the value.

Methods

GetNameBytes()

Copies the dictionary key's raw bytes to a new array.

public byte[] GetNameBytes()

Returns

byte[]

A copy of the key's bytes, exactly as they appear in the document.

Exceptions

InvalidOperationException

Thrown when this property is the default value and belongs to no document.

ObjectDisposedException

Thrown when the owning document has been disposed.

NameEquals(ReadOnlySpan<byte>)

Determines whether the dictionary key's raw bytes equal the supplied bytes, without allocating.

public bool NameEquals(ReadOnlySpan<byte> name)

Parameters

name ReadOnlySpan<byte>

The key bytes to compare with.

Returns

bool

true when the key's bytes equal name; otherwise false.

Exceptions

InvalidOperationException

Thrown when this property is the default value and belongs to no document.

ObjectDisposedException

Thrown when the owning document has been disposed.

ToString()

Returns the property name.

public override string ToString()

Returns

string

The value of Name.

Applies to

ProductVersions
.NET8, 10