pub struct Packet { /* private fields */ }Expand description
Bililive packet.
Packet can be used to encode/parse raw bilibili live packets, and extract information from it.
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn set_seq_id(&mut self, seq_id: u32)
pub fn set_seq_id(&mut self, seq_id: u32)
Set the sequence id. By default it’s 1.
Source§impl Packet
impl Packet
Sourcepub fn new<T: Into<Vec<u8>>>(
op: Operation,
protocol_version: Protocol,
data: T,
) -> Self
pub fn new<T: Into<Vec<u8>>>( op: Operation, protocol_version: Protocol, data: T, ) -> Self
Construct a new packet.
To construct a zlib-compressed packet, you should create a JSON/Int32BE packet first,
then call Packet::compress to convert it to a zlib one.
Sourcepub fn compress(self) -> Result<Self, ParseError>
pub fn compress(self) -> Result<Self, ParseError>
Source§impl Packet
impl Packet
pub fn new_room_enter(config: &StreamConfig) -> Self
Source§impl Packet
impl Packet
Sourcepub const fn packet_length(&self) -> u32
pub const fn packet_length(&self) -> u32
Get the packet length.
Sourcepub const fn header_length(&self) -> u16
pub const fn header_length(&self) -> u16
Get the header length.
Sourcepub fn json<'a, T: Deserialize<'a>>(&'a self) -> Result<T, ParseError>
pub fn json<'a, T: Deserialize<'a>>(&'a self) -> Result<T, ParseError>
Try to parse the body by json.
§Errors
It may fail if the model is incorrect or it’s not a json packet.
You may check the type of the packet by Packet::proto.
Sourcepub fn int32_be(&self) -> Result<i32, ParseError>
pub fn int32_be(&self) -> Result<i32, ParseError>
Try to parse the body by big endian int32.
§Errors
It may fail if it’s not a int packet.
You may check the type of the packet by Packet::proto.
Trait Implementations§
Source§impl<T, E> Sink<Packet> for HeartbeatStream<T, E>
impl<T, E> Sink<Packet> for HeartbeatStream<T, E>
Source§type Error = StreamError<E>
type Error = StreamError<E>
The type of value produced by the sink when an error occurs.
Source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Attempts to prepare the
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: Packet) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: Packet) -> Result<(), Self::Error>
Begin the process of sending a value to the sink.
Each call to this function must be preceded by a successful call to
poll_ready which returned Poll::Ready(Ok(())). Read moreimpl Eq for Packet
impl StructuralPartialEq for Packet
Auto Trait Implementations§
impl Freeze for Packet
impl RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnwindSafe for Packet
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