RegistryOrInline<T>
readonly record struct
Represents a protocol value that is either a registry id or an inline value of type
T.
Declaration
public readonly record struct RegistryOrInline<T> : IProtocolType<RegistryOrInline<T>> where T : IProtocolType<T>
| Namespace | McProtoNet.Protocol |
| Assembly | McProtoNet.Protocol.dll |
| Source | src/McProtoNet.Protocol/RegistryOrInline.cs#L17 ↗ |
Implements: IProtocolType<RegistryOrInline<T>>
Remarks
The wire form is a VarInt discriminator. A discriminator of 0 means that an inline value
follows; any other value is the registry id plus one. The default instance of this type holds
neither a registry id nor an inline value.
Properties
| Signature | Description |
|---|---|
int Id | Gets the registry id that the current instance carries. |
bool IsInline | Gets a value indicating whether the current instance carries an inline value. |
bool IsRegistry | Gets a value indicating whether the current instance carries a registry id. |
T Value | Gets the inline value that the current instance carries. |
Id
public int Id { get; }
Gets the registry id that the current instance carries.
Returns: int - The registry id.
Exceptions: InvalidOperationException - The current instance does not carry a registry id.
IsInline
public bool IsInline { get; }
Gets a value indicating whether the current instance carries an inline value.
Returns: bool - true if the discriminator is zero; otherwise, false. The default instance of this type reports true although it carries no value.
IsRegistry
public bool IsRegistry { get; }
Gets a value indicating whether the current instance carries a registry id.
Returns: bool - true if the current instance carries a registry id; otherwise, false.
Value
public T Value { get; }
Gets the inline value that the current instance carries.
Returns: T - The inline value.
Exceptions: InvalidOperationException - The current instance does not carry an inline value.
Methods
| Signature | Description |
|---|---|
static RegistryOrInline<T> FromRegistry(int id) | Creates a value that refers to the specified registry id. |
static RegistryOrInline<T> Inline(T value) | Creates a value that carries the specified inline value. |
static RegistryOrInline<T> Read(ref MinecraftPrimitiveReader reader, int protocolVersion) | Reads a RegistryOrInline<T> from the specified reader. |
bool TryGetId(out int id) | Attempts to get the registry id that the current instance carries. |
bool TryGetValue(out T? value) | Attempts to get the inline value that the current instance carries. |
void Write(MinecraftPrimitiveWriter writer, int protocolVersion) | Writes the current value to the specified writer. |
FromRegistry(int)
public static RegistryOrInline<T> FromRegistry(int id)
Creates a value that refers to the specified registry id.
Parameters: id (int)
Returns: RegistryOrInline<T> - A RegistryOrInline<T> that holds id.
Exceptions: ArgumentOutOfRangeException - id is less than zero.
Inline(T)
public static RegistryOrInline<T> Inline(T value)
Creates a value that carries the specified inline value.
Parameters: value (T)
Returns: RegistryOrInline<T> - A RegistryOrInline<T> that holds value.
Exceptions: ArgumentNullException - value is null.
Read(ref MinecraftPrimitiveReader, int)
public static RegistryOrInline<T> Read(ref MinecraftPrimitiveReader reader, int protocolVersion)
Reads a RegistryOrInline<T> from the specified reader.
Parameters: reader (MinecraftPrimitiveReader), protocolVersion (int)
Returns: RegistryOrInline<T> - The value that was read.
Exceptions: InvalidOperationException - The discriminator read from reader is negative.
TryGetId(out int)
public bool TryGetId(out int id)
Attempts to get the registry id that the current instance carries.
Parameters: id (int)
Returns: bool - true if the current instance carries a registry id; otherwise, false.
TryGetValue(out T?)
public bool TryGetValue(out T? value)
Attempts to get the inline value that the current instance carries.
Parameters: value (T)
Returns: bool - true if the current instance carries an inline value; otherwise, false.
Write(MinecraftPrimitiveWriter, int)
public void Write(MinecraftPrimitiveWriter writer, int protocolVersion)
Writes the current value to the specified writer.
Parameters: writer (MinecraftPrimitiveWriter), protocolVersion (int)
Exceptions: InvalidOperationException - The current instance carries neither a registry id nor an inline value.