#[repr(transparent)]pub struct PrefixedArray<T>(pub Vec<T>);Expand description
A sequence prefixed by its element count as a VarInt.
The Minecraft protocol Prefixed Array wire representation is a
non-negative VarInt length followed by exactly that many T values:
VarInt(length) + T[0] + T[1] + ... + T[length - 1]A zero length is encoded as 0x00 and has no element payload. Since the
prefix is a signed 32-bit VarInt, arrays cannot contain more than
2,147,483,647 elements. This type supports all context-independent
protocol values through T: TypeCodec.
§Examples
use mcproto_types::{TypeCodec, basic::UnsignedByte};
use mcproto_types::contextual::PrefixedArray;
let values = PrefixedArray(vec![UnsignedByte(1), UnsignedByte(2)]);
let mut encoded = Vec::new();
values.encode(&mut encoded)?;
assert_eq!(encoded, [0x02, 0x01, 0x02]);
let mut input = encoded.as_slice();
assert_eq!(PrefixedArray::<UnsignedByte>::decode(&mut input)?, values);
assert!(input.is_empty());Tuple Fields§
§0: Vec<T>The array elements.
Implementations§
Source§impl<T> PrefixedArray<T>
impl<T> PrefixedArray<T>
Trait Implementations§
Source§impl<T: Clone> Clone for PrefixedArray<T>
impl<T: Clone> Clone for PrefixedArray<T>
Source§fn clone(&self) -> PrefixedArray<T>
fn clone(&self) -> PrefixedArray<T>
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<T: Debug> Debug for PrefixedArray<T>
impl<T: Debug> Debug for PrefixedArray<T>
Source§impl<T: Default> Default for PrefixedArray<T>
impl<T: Default> Default for PrefixedArray<T>
Source§fn default() -> PrefixedArray<T>
fn default() -> PrefixedArray<T>
Returns the “default value” for a type. Read more
impl<T: Eq> Eq for PrefixedArray<T>
Source§impl<T> From<PrefixedArray<T>> for Vec<T>
impl<T> From<PrefixedArray<T>> for Vec<T>
Source§fn from(values: PrefixedArray<T>) -> Self
fn from(values: PrefixedArray<T>) -> Self
Converts to this type from the input type.
Source§impl<T> From<Vec<T>> for PrefixedArray<T>
impl<T> From<Vec<T>> for PrefixedArray<T>
Source§impl<T: Hash> Hash for PrefixedArray<T>
impl<T: Hash> Hash for PrefixedArray<T>
Source§impl<T: PartialEq> PartialEq for PrefixedArray<T>
impl<T: PartialEq> PartialEq for PrefixedArray<T>
impl<T: PartialEq> StructuralPartialEq for PrefixedArray<T>
Auto Trait Implementations§
impl<T> Freeze for PrefixedArray<T>
impl<T> RefUnwindSafe for PrefixedArray<T>where
T: RefUnwindSafe,
impl<T> Send for PrefixedArray<T>where
T: Send,
impl<T> Sync for PrefixedArray<T>where
T: Sync,
impl<T> Unpin for PrefixedArray<T>where
T: Unpin,
impl<T> UnsafeUnpin for PrefixedArray<T>
impl<T> UnwindSafe for PrefixedArray<T>where
T: UnwindSafe,
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.