Struct Utf8Text256
A UTF-8 string of at most 256 bytes, carried inside a message struct. See IInlineUtf8Text.
public struct Utf8Text256 : IInlineUtf8Text, IEquatable<Utf8Text256>
- Implements
- Inherited Members
Fields
Capacity
The largest number of UTF-8 bytes this type holds.
public const int Capacity = 256
Field Value
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
Length
The number of UTF-8 bytes in use.
public readonly int Length { get; }
Property Value
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
Methods
Equals(object)
public override readonly bool Equals(object obj)
Parameters
objobject
Returns
Equals(Utf8Text256)
public readonly bool Equals(Utf8Text256 other)
Parameters
otherUtf8Text256
Returns
From(string)
The text of value, encoded as UTF-8.
public static Utf8Text256 From(string value)
Parameters
Returns
- Utf8Text256
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 Utf8Text256 FromUtf8(ReadOnlySpan<byte> utf8)
Parameters
utf8ReadOnlySpan<byte>Valid UTF-8; validity is the caller's to guarantee, and the wire reader checks it before this is reached.
Returns
- Utf8Text256
The value.
Exceptions
- ArgumentException
It is longer than Capacity.
GetHashCode()
public override readonly int GetHashCode()
Returns
ToString()
The text, decoded. Allocates; Utf8 is the allocation-free read.
public override readonly string ToString()
Returns
- string
The text.
Operators
operator ==(Utf8Text256, Utf8Text256)
Whether two values hold the same bytes.
public static bool operator ==(Utf8Text256 left, Utf8Text256 right)
Parameters
leftUtf8Text256One.
rightUtf8Text256The other.
Returns
- bool
Whether they are equal.
operator !=(Utf8Text256, Utf8Text256)
Whether two values hold different bytes.
public static bool operator !=(Utf8Text256 left, Utf8Text256 right)
Parameters
leftUtf8Text256One.
rightUtf8Text256The other.
Returns
- bool
Whether they differ.