pub enum IdSet {
Tag(Identifier),
Inline(Vec<i32>),
}Expand description
A set of registry IDs represented inline or by reference to a tag.
The registry itself is implied by the enclosing packet or field. The
Minecraft protocol ID Set wire representation starts with a VarInt
type value:
0is followed by anIdentifiernaming a registry tag;- a positive value
nis followed byn - 1registry IDs encoded as VarInts.
VarInt(0) + Identifier(tag_name)
VarInt(ids.len() + 1) + VarInt(ids[0]) + ... + VarInt(ids[len - 1])An empty inline set therefore uses type value 1. Registry IDs must be
non-negative, and an inline set may contain at most i32::MAX - 1 IDs.
§Examples
use mcproto_types::{TypeCodec, basic::Identifier};
use mcproto_types::contextual::IdSet;
let inline = IdSet::inline(vec![3, 7]);
let mut encoded = Vec::new();
inline.encode(&mut encoded)?;
assert_eq!(encoded, [0x03, 0x03, 0x07]);
let mut input = encoded.as_slice();
assert_eq!(IdSet::decode(&mut input)?, inline);
let tagged = IdSet::tag(Identifier::new("minecraft:logs")?);
assert!(tagged.is_tag());Variants§
Tag(Identifier)
A named set of IDs defined by a registry tag.
Inline(Vec<i32>)
An ad-hoc set of zero-based registry IDs enumerated inline.
Implementations§
Source§impl IdSet
impl IdSet
Sourcepub const fn tag(tag_name: Identifier) -> Self
pub const fn tag(tag_name: Identifier) -> Self
Creates an ID set that refers to a registry tag.
Sourcepub const fn tag_name(&self) -> Option<&Identifier>
pub const fn tag_name(&self) -> Option<&Identifier>
Returns the registry tag name, if this is a tag reference.
Sourcepub fn into_tag(self) -> Option<Identifier>
pub fn into_tag(self) -> Option<Identifier>
Extracts the registry tag name, if this is a tag reference.
Trait Implementations§
impl Eq for IdSet
Source§impl From<Identifier> for IdSet
impl From<Identifier> for IdSet
Source§fn from(tag_name: Identifier) -> Self
fn from(tag_name: Identifier) -> Self
Converts to this type from the input type.
impl StructuralPartialEq for IdSet
Auto Trait Implementations§
impl Freeze for IdSet
impl RefUnwindSafe for IdSet
impl Send for IdSet
impl Sync for IdSet
impl Unpin for IdSet
impl UnsafeUnpin for IdSet
impl UnwindSafe for IdSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.