pub struct PacketBuilder {
actions: VecDeque<BuildAction>,
}
Expand description
A builder to build a packet.
Fields§
§actions: VecDeque<BuildAction>
Queue of actions to process
Implementations§
Source§impl PacketBuilder
impl PacketBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Returns an empty Self, Self::default().
Then use chained method calls to build your Packet
.
§Example
let packet: Packet = PacketBuilder::new().append_varint(3).build()?;
Sourcepub fn build(
&self,
packet_id: i32,
name: Option<String>,
) -> Result<Packet, PacketError>
pub fn build( &self, packet_id: i32, name: Option<String>, ) -> Result<Packet, PacketError>
Builds a packet
Sourcepub fn append_bytes<T: AsRef<[u8]>>(&mut self, data: T) -> &mut Self
pub fn append_bytes<T: AsRef<[u8]>>(&mut self, data: T) -> &mut Self
Appends bytes to the back of the packet payload.
Sourcepub fn append_varint(&mut self, value: i32) -> &mut Self
pub fn append_varint(&mut self, value: i32) -> &mut Self
Appends value
as a VarInt to the back of the packet payload.
Sourcepub fn append_string<T: AsRef<str>>(&mut self, string: T) -> &mut Self
pub fn append_string<T: AsRef<str>>(&mut self, string: T) -> &mut Self
Appends string
as a String to the back of the packet payload.
Trait Implementations§
Source§impl Default for PacketBuilder
impl Default for PacketBuilder
Source§fn default() -> PacketBuilder
fn default() -> PacketBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PacketBuilder
impl RefUnwindSafe for PacketBuilder
impl Send for PacketBuilder
impl Sync for PacketBuilder
impl Unpin for PacketBuilder
impl UnwindSafe for PacketBuilder
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian()
.