Struct Record

Source
pub struct Record {
    pub version: String,
    pub to_id: String,
    pub from_id: String,
    pub payload_security: PayloadSecurity,
    pub mac_signature: Vec<u8>,
    pub sender_cert: Vec<u8>,
    pub record_type: OneOfrecord_type,
}

Fields§

§version: String§to_id: String§from_id: String§payload_security: PayloadSecurity§mac_signature: Vec<u8>§sender_cert: Vec<u8>§record_type: OneOfrecord_type

Implementations§

Source§

impl Record

Source

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

Tries to decode a slice of bytes containing a Protobuf encoded USP Record

This function also performs additional checks required by the USP specification, see also Record::check_validity

§Arguments
  • bytes - A slice of bytes containing the Protobuf encoded USP Record
§Example
use rusp_lib::usp_record::Record;
let record =
    Record::from_bytes(&[
        0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64,
        0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09,
        0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f,
        0x6d, 0x3a, 0x35, 0x12, 0x33, 0x0a, 0x07, 0x0a,
        0x03, 0x67, 0x65, 0x74, 0x10, 0x01, 0x12, 0x28,
        0x0a, 0x26, 0x0a, 0x24, 0x0a, 0x22, 0x44, 0x65,
        0x76, 0x69, 0x63, 0x65, 0x2e, 0x44, 0x65, 0x76,
        0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x2e,
        0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
        0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x2e,
    ])
    .unwrap();
Source

pub fn check_validity(&self) -> Result<()>

Checks the validity of this Record according to the USP specification

Although the type itself guarantees its validity against the protobuf schema, the USP specification places additional constrains on the values used

§Example
use rusp_lib::usp_decoder::try_decode_record;
let no_session_empty_payload =
    try_decode_record(&[
        0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64,
        0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09,
        0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f,
        0x6d, 0x3a, 0x00,
    ]).unwrap();
assert!(no_session_empty_payload.check_validity().is_err());
Source

pub fn payload_flatten(&mut self) -> Option<&mut Vec<u8>>

Flattens the payload of the Record and returns a mutable reference to it

This function will return None for Record types that do not contain a payload

Source§

impl Record

Implementation of some extension methods for Records

Source

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

Encode the Record into a Protobuf byte stream returned as Vec<[u8]>

§Arguments
  • self - A USP Record structure
§Example
use rusp_lib::usp_decoder::try_decode_record;
let bytes = &[
        0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64,
        0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09,
        0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f,
        0x6d, 0x52, 0x09, 0x08, 0x01, 0x12, 0x05, 0x74,
        0x6f, 0x70, 0x69, 0x63,
    ];
let record = try_decode_record(bytes).unwrap();
assert_eq!(record.to_vec().unwrap(), bytes);
§Errors

This function will return Err containing a textual description of the encountered error if the Record cannot be serialized into a Protobuf representation

Source

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

Render the Record into a raw C string representation

§Arguments
  • self - A USP Record structure
§Example
use rusp_lib::usp_decoder::try_decode_record;
let record =
    try_decode_record(&[
        0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64,
        0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09,
        0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f,
        0x6d, 0x52, 0x09, 0x08, 0x01, 0x12, 0x05, 0x74,
        0x6f, 0x70, 0x69, 0x63,
    ]).unwrap();
assert_eq!(record.to_c_str().unwrap(), "\"\\x0a\\x031.3\\x12\\x07doc\\x3a\\x3ato\\x1a\\x09doc\\x3a\\x3afromR\\x09\\x08\\x01\\x12\\x05topic\"\n");
§Errors

This function will return Err containing a textual description of the encountered error if the Record cannot be serialized into a C string representation

Source

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

Render the Record into a raw C array representation

§Arguments
  • self - A USP Record structure
§Example
use rusp_lib::usp_decoder::try_decode_record;
let record =
    try_decode_record(&[
        0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64,
        0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09,
        0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f,
        0x6d, 0x52, 0x09, 0x08, 0x01, 0x12, 0x05, 0x74,
        0x6f, 0x70, 0x69, 0x63,
    ]).unwrap();
assert_eq!(record.to_c_array().unwrap(), "unsigned int pb_len = 36;\nconst char pb[] = {\n  0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64, /* __1.3__d */\n  0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09, /* oc__to__ */\n  0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f, /* doc__fro */\n  0x6d, 0x52, 0x09, 0x08, 0x01, 0x12, 0x05, 0x74, /* mR_____t */\n  0x6f, 0x70, 0x69, 0x63,                         /* opic */\n};\n");
§Errors

This function will return Err containing a textual description of the encountered error if the Record cannot be serialized into a C array representation

Source

pub fn to_c_array_custom(&self, name: &str) -> Result<String>

Render the Record into a raw C array representation with a custom name

§Arguments
  • self - A USP Record structure
  • name - The variable name prefix used in the rendered output
§Example
use rusp_lib::usp_decoder::try_decode_record;
let record =
    try_decode_record(&[
        0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64,
        0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09,
        0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f,
        0x6d, 0x52, 0x09, 0x08, 0x01, 0x12, 0x05, 0x74,
        0x6f, 0x70, 0x69, 0x63,
    ]).unwrap();
assert_eq!(record.to_c_array_custom("rec").unwrap(), "unsigned int rec_len = 36;\nconst char rec[] = {\n  0x0a, 0x03, 0x31, 0x2e, 0x33, 0x12, 0x07, 0x64, /* __1.3__d */\n  0x6f, 0x63, 0x3a, 0x3a, 0x74, 0x6f, 0x1a, 0x09, /* oc__to__ */\n  0x64, 0x6f, 0x63, 0x3a, 0x3a, 0x66, 0x72, 0x6f, /* doc__fro */\n  0x6d, 0x52, 0x09, 0x08, 0x01, 0x12, 0x05, 0x74, /* mR_____t */\n  0x6f, 0x70, 0x69, 0x63,                         /* opic */\n};\n");
§Errors

This function will return Err containing a textual description of the encountered error if the Record cannot be serialized into a C array representation

Trait Implementations§

Source§

impl Clone for Record

Source§

fn clone(&self) -> Record

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 Record

Source§

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

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

impl Default for Record

Source§

fn default() -> Record

Returns the “default value” for a type. Read more
Source§

impl<'a> MessageRead<'a> for Record

Source§

fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self>

Constructs an instance of Self by reading from the given bytes via the given reader. Read more
Source§

impl MessageWrite for Record

Source§

fn get_size(&self) -> usize

Computes necessary binary size of self once serialized in protobuf
Source§

fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()>

Writes Self into W writer
Source§

fn write_file<P>(&self, p: P) -> Result<(), Error>
where P: AsRef<Path>,

Writes self into a file
Source§

impl PartialEq for Record

Source§

fn eq(&self, other: &Record) -> 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 Serialize for Record

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Record

Auto Trait Implementations§

§

impl Freeze for Record

§

impl RefUnwindSafe for Record

§

impl Send for Record

§

impl Sync for Record

§

impl Unpin for Record

§

impl UnwindSafe for Record

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.