Skip to main content

MessageView

Struct MessageView 

Source
pub struct MessageView<'a> { /* private fields */ }
Expand description

A zero-copy view over an encoded ProtoCache message.

Implementations§

Source§

impl<'a> MessageView<'a>

Source

pub fn new(words: &'a [u32]) -> Option<Self>

Parses a message header from words.

The view may borrow a larger enclosing slice; call Self::detect when the exact encoded extent is needed.

Examples found in repository?
examples/basic.rs (line 9)
3fn main() {
4    let mut buffer = Buffer::new();
5    let name = serialize_str("Ada", &mut buffer).expect("name is encodable");
6    let mut fields = [serialize_scalar(42_i32), name];
7    serialize_message(&mut fields, &mut buffer).expect("message is encodable");
8
9    let view = MessageView::new(buffer.view()).expect("valid ProtoCache message");
10    let id = view.scalar::<i32>(0).expect("id field");
11    let name = view
12        .string(1)
13        .and_then(|value| value.as_str())
14        .expect("UTF-8 name field");
15
16    println!("id={id}, name={name}");
17}
Source

pub fn from_words(words: &'a [u32]) -> Option<Self>

Alias for Self::new used by generated bindings.

Source

pub fn raw_words(self) -> &'a [u32]

Returns the minimum message header/body slice retained by this view.

Source

pub fn detect_len(words: &'a [u32]) -> Option<usize>

Detects the complete encoded message length, including referenced data.

Source

pub fn detect(words: &'a [u32]) -> Option<&'a [u32]>

Returns the exact encoded slice occupied by a valid message.

Source

pub fn has_field(self, id: usize) -> bool

Returns whether the message contains the field with zero-based id.

Source

pub fn field(self, id: usize) -> Option<FieldView<'a>>

Returns a raw field view for zero-based id.

Source

pub fn expect_field(self, id: usize) -> FieldView<'a>

Source

pub fn scalar<T: Scalar>(self, id: usize) -> Option<T>

Examples found in repository?
examples/basic.rs (line 10)
3fn main() {
4    let mut buffer = Buffer::new();
5    let name = serialize_str("Ada", &mut buffer).expect("name is encodable");
6    let mut fields = [serialize_scalar(42_i32), name];
7    serialize_message(&mut fields, &mut buffer).expect("message is encodable");
8
9    let view = MessageView::new(buffer.view()).expect("valid ProtoCache message");
10    let id = view.scalar::<i32>(0).expect("id field");
11    let name = view
12        .string(1)
13        .and_then(|value| value.as_str())
14        .expect("UTF-8 name field");
15
16    println!("id={id}, name={name}");
17}
Source

pub fn string(self, id: usize) -> Option<StringView<'a>>

Examples found in repository?
examples/basic.rs (line 12)
3fn main() {
4    let mut buffer = Buffer::new();
5    let name = serialize_str("Ada", &mut buffer).expect("name is encodable");
6    let mut fields = [serialize_scalar(42_i32), name];
7    serialize_message(&mut fields, &mut buffer).expect("message is encodable");
8
9    let view = MessageView::new(buffer.view()).expect("valid ProtoCache message");
10    let id = view.scalar::<i32>(0).expect("id field");
11    let name = view
12        .string(1)
13        .and_then(|value| value.as_str())
14        .expect("UTF-8 name field");
15
16    println!("id={id}, name={name}");
17}
Source

pub fn bytes(self, id: usize) -> Option<&'a [u8]>

Source

pub fn bools(self, id: usize) -> Option<BoolArray<'a>>

Source

pub fn message(self, id: usize) -> Option<MessageView<'a>>

Source

pub fn array(self, id: usize) -> Option<ArrayView<'a>>

Source

pub fn map(self, id: usize) -> Option<MapView<'a>>

Trait Implementations§

Source§

impl<'a> Clone for MessageView<'a>

Source§

fn clone(&self) -> MessageView<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for MessageView<'a>

Source§

impl<'a> Debug for MessageView<'a>

Source§

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

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

impl<'a> FieldDecode<'a> for MessageView<'a>

Source§

fn decode(field: FieldView<'a>) -> Option<Self>

Returns None when the field does not have the expected shape.

Auto Trait Implementations§

§

impl<'a> Freeze for MessageView<'a>

§

impl<'a> RefUnwindSafe for MessageView<'a>

§

impl<'a> Send for MessageView<'a>

§

impl<'a> Sync for MessageView<'a>

§

impl<'a> Unpin for MessageView<'a>

§

impl<'a> UnsafeUnpin for MessageView<'a>

§

impl<'a> UnwindSafe for MessageView<'a>

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.