pub struct EntityMetadata { /* private fields */ }Expand description
A complete 0xff-terminated entity metadata sequence.
Entry indices are unique and can only be in 0..=254; the list codec always
appends 0xff and consumes no bytes after that terminator. Metadata fields
may be omitted, so an empty value is encoded as the terminator alone.
§Examples
use mcproto_types::{
Byte, EntityMetadata, EntityMetadataEntry, EntityMetadataValue, TypeCodec,
};
let metadata = EntityMetadata::new(vec![EntityMetadataEntry::try_new(
0,
EntityMetadataValue::Byte(Byte(0x20)),
)?])?;
let mut encoded = Vec::new();
metadata.encode(&mut encoded)?;
assert_eq!(encoded, [0x00, 0x00, 0x20, 0xff]);
let mut input = encoded.as_slice();
assert_eq!(EntityMetadata::decode(&mut input)?, metadata);
assert!(input.is_empty());See the official Entity Metadata Format documentation.
Implementations§
Source§impl EntityMetadata
impl EntityMetadata
Sourcepub fn new(
entries: Vec<EntityMetadataEntry>,
) -> Result<Self, DuplicateEntityMetadataIndex>
pub fn new( entries: Vec<EntityMetadataEntry>, ) -> Result<Self, DuplicateEntityMetadataIndex>
Creates a metadata sequence after checking that all indices are unique.
Sourcepub fn entries(&self) -> &[EntityMetadataEntry]
pub fn entries(&self) -> &[EntityMetadataEntry]
Returns the entries in wire order.
Sourcepub fn into_entries(self) -> Vec<EntityMetadataEntry>
pub fn into_entries(self) -> Vec<EntityMetadataEntry>
Extracts the entries in wire order.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of metadata entries, excluding the terminator.
Sourcepub fn get(&self, index: EntityMetadataIndex) -> Option<&EntityMetadataEntry>
pub fn get(&self, index: EntityMetadataIndex) -> Option<&EntityMetadataEntry>
Returns the entry at index, if present.
Sourcepub fn push(
&mut self,
entry: EntityMetadataEntry,
) -> Result<(), DuplicateEntityMetadataIndex>
pub fn push( &mut self, entry: EntityMetadataEntry, ) -> Result<(), DuplicateEntityMetadataIndex>
Appends an entry if its index is not already present.
Trait Implementations§
Source§impl Clone for EntityMetadata
impl Clone for EntityMetadata
Source§fn clone(&self) -> EntityMetadata
fn clone(&self) -> EntityMetadata
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for EntityMetadata
impl Debug for EntityMetadata
Source§impl Default for EntityMetadata
impl Default for EntityMetadata
Source§fn default() -> EntityMetadata
fn default() -> EntityMetadata
Returns the “default value” for a type. Read more
Source§impl PartialEq for EntityMetadata
impl PartialEq for EntityMetadata
impl StructuralPartialEq for EntityMetadata
Auto Trait Implementations§
impl Freeze for EntityMetadata
impl RefUnwindSafe for EntityMetadata
impl Send for EntityMetadata
impl Sync for EntityMetadata
impl Unpin for EntityMetadata
impl UnsafeUnpin for EntityMetadata
impl UnwindSafe for EntityMetadata
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.