Packet

Struct Packet 

Source
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

Source

pub fn set_proto(&mut self, protocol_version: Protocol)

Set the protocol version.

Source

pub fn set_op(&mut self, op: Operation)

Set the operation.

Source

pub fn set_seq_id(&mut self, seq_id: u32)

Set the sequence id. By default it’s 1.

Source

pub fn set_data<T: Into<Vec<u8>>>(&mut self, data: T)

Set the packet body. Packet length will be updated automatically.

Source§

impl Packet

Source

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.

Source

pub fn compress(self) -> Result<Self, ParseError>

Convert a JSON/Int32BE packet to a zlib-compressed one.

§Errors

Return errors if compression fails.

Source§

impl Packet

Source

pub fn new_room_enter(config: &StreamConfig) -> Self

Source§

impl Packet

Source

pub const fn packet_length(&self) -> u32

Get the packet length.

Source

pub const fn header_length(&self) -> u16

Get the header length.

Source

pub const fn seq_id(&self) -> u32

Get the sequence id.

Source

pub const fn op(&self) -> Operation

Get the operation.

Source

pub const fn proto(&self) -> Protocol

Get the protocol version.

Source

pub fn bytes(&self) -> &[u8]

Get bytes of the body.

Source

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.

Source

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.

Source§

impl Packet

Source

pub fn encode(&self) -> Vec<u8>

Encode the packet into bytes ready to be sent to the server.

Source

pub fn parse(input: &[u8]) -> IncompleteResult<(&[u8], Self)>

Parse the packet received from Bilibili server.

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Packet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Packet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Packet

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Packet

Source§

fn eq(&self, other: &Packet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, E> Sink<Packet> for HeartbeatStream<T, E>
where T: Sink<Packet, Error = StreamError<E>> + Unpin, E: Error,

Source§

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>>

Attempts to prepare the Sink to receive a value. Read more
Source§

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 more
Source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
Source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
Source§

impl Eq for Packet

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,