Table of Contents

Struct Utf8Text64

Namespace
Typhon.Protocol
Assembly
Typhon.Protocol.dll

A UTF-8 string of at most 64 bytes, carried inside a message struct. See IInlineUtf8Text.

public struct Utf8Text64 : IInlineUtf8Text, IEquatable<Utf8Text64>
Implements
Inherited Members

Remarks

For a name beside a text in one command: two Utf8Text256 are 516 bytes, past the 512 a command may decode into (CommandRegistry), and a player's name is 32 bytes at most. A /tell is the first to need it.

Fields

Capacity

The largest number of UTF-8 bytes this type holds.

public const int Capacity = 64

Field Value

int

Properties

IsEmpty

Whether it holds no bytes. An empty text is a value, not an absence: it travels as a zero-length string.

public readonly bool IsEmpty { get; }

Property Value

bool

Length

The number of UTF-8 bytes in use.

public readonly int Length { get; }

Property Value

int

Utf8

The bytes in use, which alias this value — never outlive it, and never keep it across a copy.

public readonly ReadOnlySpan<byte> Utf8 { get; }

Property Value

ReadOnlySpan<byte>

Methods

Equals(object)

public override readonly bool Equals(object obj)

Parameters

obj object

Returns

bool

Equals(Utf8Text64)

public readonly bool Equals(Utf8Text64 other)

Parameters

other Utf8Text64

Returns

bool

From(string)

The text of value, encoded as UTF-8.

public static Utf8Text64 From(string value)

Parameters

value string

The text; null is empty.

Returns

Utf8Text64

The value.

Remarks

It refuses rather than truncating. Cutting a string to fit can split a multi-byte character, and a silent truncation reaches whoever reads it as a shorter message rather than as an error — discovered, if ever, by a player. A caller that means to shorten says so itself.

Exceptions

ArgumentException

Its UTF-8 encoding is longer than Capacity.

FromUtf8(ReadOnlySpan<byte>)

The UTF-8 bytes of utf8, copied in.

public static Utf8Text64 FromUtf8(ReadOnlySpan<byte> utf8)

Parameters

utf8 ReadOnlySpan<byte>

Valid UTF-8; validity is the caller's to guarantee, and the wire reader checks it before this is reached.

Returns

Utf8Text64

The value.

Exceptions

ArgumentException

It is longer than Capacity.

GetHashCode()

public override readonly int GetHashCode()

Returns

int

ToString()

The text, decoded. Allocates; Utf8 is the allocation-free read.

public override readonly string ToString()

Returns

string

The text.

Operators

operator ==(Utf8Text64, Utf8Text64)

Whether two values hold the same bytes.

public static bool operator ==(Utf8Text64 left, Utf8Text64 right)

Parameters

left Utf8Text64

One.

right Utf8Text64

The other.

Returns

bool

Whether they are equal.

operator !=(Utf8Text64, Utf8Text64)

Whether two values hold different bytes.

public static bool operator !=(Utf8Text64 left, Utf8Text64 right)

Parameters

left Utf8Text64

One.

right Utf8Text64

The other.

Returns

bool

Whether they differ.