pub struct Packer { /* private fields */ }
Expand description

Implementations§

source§

impl Packer

source§

impl Packer

source

pub fn pack_ip(&self, ip_addr: IpAddr, port: u16) -> Result<()>

Writes the “IP” value at the offset in 16-byte representation and increments the offset afterwards. ref. “avalanchego/utils/wrappers.Packer.PackIP” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackIP ref. https://doc.rust-lang.org/std/net/enum.IpAddr.html ref. https://doc.rust-lang.org/std/net/struct.Ipv4Addr.html ref. https://doc.rust-lang.org/std/net/struct.Ipv6Addr.html

source

pub fn unpack_ip(&self) -> Result<(IpAddr, u16)>

Unpacks the “IP” in the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackIP” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackIP

source

pub fn pack_ips(&self, ips: &[(IpAddr, u16)]) -> Result<()>

Writes the list of “IP” values at the offset in 16-byte representation and increments the offset afterwards. ref. “avalanchego/utils/wrappers.Packer.PackIPs” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackIPs

source

pub fn unpack_ips(&self) -> Result<Vec<(IpAddr, u16)>>

Unpacks the list of “IP“s in the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackIPs” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackIPs

source§

impl Packer

source

pub fn new(max_size: usize, initial_cap: usize) -> Self

source

pub fn new_with_header(max_size: usize, initial_cap: usize) -> Self

Creates a new Packer with 32-bit message length header.

source

pub fn load_bytes_for_pack(max_size: usize, b: &[u8]) -> Self

Create a new packer from the existing bytes. Resets the offset to the end of the existing bytes.

source

pub fn load_bytes_for_unpack(max_size: usize, b: &[u8]) -> Self

Create a new packer from the existing bytes. Resets the offset to the beginning of the existing bytes.

source

pub fn take_bytes(&self) -> Bytes

Returns the current bytes array as an immutable bytes array. If the packer header is set to “true”, the first 4-byte represents the message length in the big-endian order. The returned bytes length will be 4-byte + message.

Be cautious! Once bytes are taken out, the “bytes” field is set to default (empty). To continue to write to bytes, remember to put it back with “set_bytes” because “bytes.take” leaves the field as “Default::default()”. TODO: make sure this does shallow copy!

source

pub fn set_bytes(&self, b: &[u8])

Sets the current bytes array as an immutable bytes array. Useful to reuse packer after calling “take_bytes”, which makes the “bytes” field default (empty).

source

pub fn get_offset(&self) -> usize

Returns the “offset” value.

source

pub fn bytes_len(&self) -> usize

Returns the current length of the bytes array.

source

pub fn bytes_cap(&self) -> usize

Returns the current capacity of the bytes array.

source

pub fn expand(&self, n: usize) -> Result<()>

Ensures the remaining capacity of the bytes array so it can write “n” bytes to the array. ref. “avalanchego/utils/wrappers.Packer.Expand” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.Expand

source

pub fn pack_byte(&self, v: u8) -> Result<()>

Writes the “u8” value at the offset and increments the offset afterwards. ref. “avalanchego/utils/wrappers.Packer.PackByte” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackByte

source

pub fn unpack_byte(&self) -> Result<u8>

Unpacks the byte in the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackByte” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackByte

source

pub fn pack_u16(&self, v: u16) -> Result<()>

Writes the “u16” value at the offset and increments the offset afterwards. ref. “avalanchego/utils/wrappers.Packer.PackShort” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackShort

source

pub fn unpack_u16(&self) -> Result<u16>

Unpacks the u16 from the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackShort” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackShort

source

pub fn pack_u32(&self, v: u32) -> Result<()>

Writes the “u32” value at the offset and increments the offset afterwards. This is also used for encoding the type IDs from codec. ref. “avalanchego/utils/wrappers.Packer.PackInt” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackInt

source

pub fn unpack_u32(&self) -> Result<u32>

Unpacks the u32 from the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackInt” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackInt

source

pub fn pack_u64(&self, v: u64) -> Result<()>

Writes the “u64” value at the offset and increments the offset afterwards. ref. “avalanchego/utils/wrappers.Packer.PackLong” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackLong

source

pub fn unpack_u64(&self) -> Result<u64>

Unpacks the u64 from the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackLong” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackLong

source

pub fn pack_bool(&self, v: bool) -> Result<()>

Writes the “bool” value at the offset and increments the offset afterwards. ref. “avalanchego/utils/wrappers.Packer.PackBool” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackBool

source

pub fn unpack_bool(&self) -> Result<bool>

Unpacks the bool in the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackBool” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackBool

source

pub fn pack_bytes(&self, v: &[u8]) -> Result<()>

Writes the “u8” fixed-size array from the offset and increments the offset as much. ref. “avalanchego/utils/wrappers.Packer.PackFixedBytes” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackFixedBytes

source

pub fn unpack_bytes(&self, n: usize) -> Result<Vec<u8>>

Unpacks the “u8” fixed-size array from the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackFixedBytes” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackFixedBytes

source

pub fn pack_bytes_with_header(&self, v: &[u8]) -> Result<()>

Writes the “u8” slice from the offset and increments the offset as much. The first 4-byte is used for encoding length header. ref. “avalanchego/utils/wrappers.Packer.PackBytes” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackBytes

source

pub fn unpack_bytes_with_header(&self) -> Result<Vec<u8>>

Unpacks the “u8” slice from the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackBytes” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackBytes

source

pub fn pack_2d_bytes(&self, v: Vec<Vec<u8>>) -> Result<()>

Writes the two-dimensional “u8” slice from the offset and increments the offset as much. ref. “avalanchego/utils/wrappers.Packer.PackFixedByteSlices” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackFixedByteSlices

source

pub fn unpack_2d_bytes(&self, n: usize) -> Result<Vec<Vec<u8>>>

Unpacks the two-dimensional “u8” slice from the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.UnpackFixedByteSlices” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackFixedByteSlices

source

pub fn pack_2d_bytes_with_header(&self, v: Vec<Vec<u8>>) -> Result<()>

Writes the two-dimensional “u8” slice from the offset and increments the offset as much. ref. “avalanchego/utils/wrappers.Packer.Pack2DByteSlice” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.Pack2DByteSlice

source

pub fn unpack_2d_bytes_with_header(&self) -> Result<Vec<Vec<u8>>>

Unpacks the two-dimensional “u8” slice from the “offset” position, and advances the cursor and offset. ref. “avalanchego/utils/wrappers.Packer.Unpack2DByteSlice” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.Unpack2DByteSlice

source

pub fn pack_str(&self, v: &str) -> Result<()>

Writes str from the offset and increments the offset as much. ref. “avalanchego/utils/wrappers.Packer.PackStr” ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.PackStr

source

pub fn unpack_str(&self) -> Result<String>

Unpacks str from the offset. ref. “avalanchego/utils/wrappers.Packer.UnpackStr”

TODO: Go “UnpackStr” does deep-copy of bytes to “string” cast Can we bypass deep-copy by passing around bytes? ref. https://github.com/golang/go/issues/25484

ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/wrappers#Packer.UnpackStr

Auto Trait Implementations§

§

impl !RefUnwindSafe for Packer

§

impl Send for Packer

§

impl !Sync for Packer

§

impl Unpin for Packer

§

impl UnwindSafe for Packer

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more