Skip to main content

FixedSizeEncoding

Trait FixedSizeEncoding 

Source
pub trait FixedSizeEncoding<const BYTE_LEN: usize, const FD_LEN: usize> {
    const BYTE_LEN: usize = BYTE_LEN;
    const FD_LEN: usize = FD_LEN;

    // Required methods
    fn encode(&self) -> ([u8; BYTE_LEN], [BorrowedFd<'_>; FD_LEN]);
    fn decode(bytes: [u8; BYTE_LEN], fds: [OwnedFd; FD_LEN]) -> Self;
}
Expand description

Encoding/decoding functionality that relies on each message being encoded to a constant (and small) “packet” size, allowing the use of 1:1 sendmsg and recvmsg calls, i.e. removing the need for any kind of “packet framing” that a SOCK_STREAM needs to soundly handle receiving a message’s fds through multiple recvmsg calls.

Provided Associated Constants§

Source

const BYTE_LEN: usize = BYTE_LEN

Source

const FD_LEN: usize = FD_LEN

Required Methods§

Source

fn encode(&self) -> ([u8; BYTE_LEN], [BorrowedFd<'_>; FD_LEN])

Source

fn decode(bytes: [u8; BYTE_LEN], fds: [OwnedFd; FD_LEN]) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FixedSizeEncoding<0, 1> for OwnedFd

Source§

fn encode(&self) -> ([u8; 0], [BorrowedFd<'_>; 1])

Source§

fn decode([]: [u8; 0], [fd]: [OwnedFd; 1]) -> Self

Source§

impl FixedSizeEncoding<{(Self::BITS / 8) as usize}, 0> for u16

Source§

fn encode(&self) -> ([u8; 2], [BorrowedFd<'_>; 0])

Source§

fn decode(bytes: [u8; 2], []: [OwnedFd; 0]) -> Self

Source§

impl FixedSizeEncoding<{(Self::BITS / 8) as usize}, 0> for u32

Source§

fn encode(&self) -> ([u8; 4], [BorrowedFd<'_>; 0])

Source§

fn decode(bytes: [u8; 4], []: [OwnedFd; 0]) -> Self

Source§

impl FixedSizeEncoding<{(Self::BITS / 8) as usize}, 0> for u64

Source§

fn encode(&self) -> ([u8; 8], [BorrowedFd<'_>; 0])

Source§

fn decode(bytes: [u8; 8], []: [OwnedFd; 0]) -> Self

Source§

impl FixedSizeEncoding<{(Self::BITS / 8) as usize}, 0> for u128

Source§

fn encode(&self) -> ([u8; 16], [BorrowedFd<'_>; 0])

Source§

fn decode(bytes: [u8; 16], []: [OwnedFd; 0]) -> Self

Source§

impl<const BYTE_LEN: usize, const FD_LEN: usize, A: FixedSizeEncoding<BYTE_LEN, 0>, B: FixedSizeEncoding<0, FD_LEN>> FixedSizeEncoding<BYTE_LEN, FD_LEN> for (A, B)

Source§

fn encode(&self) -> ([u8; BYTE_LEN], [BorrowedFd<'_>; FD_LEN])

Source§

fn decode(bytes: [u8; BYTE_LEN], fds: [OwnedFd; FD_LEN]) -> Self

Implementors§

Source§

impl FixedSizeEncoding<{u64::BYTE_LEN}, 0> for PresentableImageId