[][src]Struct roughenough::RtMessage

pub struct RtMessage { /* fields omitted */ }

A Roughtime protocol message; a map of u32 tags to arbitrary byte-strings.

Methods

impl RtMessage[src]

pub fn new(num_fields: u32) -> Self[src]

Construct a new RtMessage

Arguments

  • num_fields - Reserve space for this many fields.

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>[src]

Construct a new RtMessage from the on-the-wire representation in bytes

Arguments

  • bytes - On-the-wire representation

pub fn new_deliberately_invalid(tags: Vec<Tag>, values: Vec<Vec<u8>>) -> Self[src]

Dangerous: construct a new RtMessage without validation or error checking.

Intended only for construction of deliberately bogus responses as part of Roughtime's ecosystem.

pub fn add_field(&mut self, tag: Tag, value: &[u8]) -> Result<(), Error>[src]

Add a field to this RtMessage

Arguments

pub fn get_field(&self, tag: Tag) -> Option<&[u8]>[src]

Retrieve the value associated with tag, if present.

Arguments

  • tag - The Tag to try and retrieve.

pub fn num_fields(&self) -> u32[src]

Returns the number of tag/value pairs in the message

pub fn tags(&self) -> &[Tag][src]

Returns a slice of the tags in the message

pub fn values(&self) -> &[Vec<u8>][src]

Returns a slice of the values in the message

pub fn into_hash_map(self) -> HashMap<Tag, Vec<u8>>[src]

Converts the message into a HashMap mapping each tag to its value

pub fn encode(&self) -> Result<Vec<u8>, Error>[src]

Encode this message into its on-the-wire representation.

pub fn encoded_size(&self) -> usize[src]

Returns the length in bytes of this message's on-the-wire representation.

pub fn pad_to_kilobyte(&mut self)[src]

Adds a PAD tag to the end of this message, with a length set such that the final encoded size of this message is 1KB

If the encoded size of this message is already >= 1KB, this method does nothing

Trait Implementations

impl Clone for RtMessage[src]

impl Debug for RtMessage[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.