Struct rusp::usp_record::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<'a> Record

Implementation of some extension methods for Records

source

pub fn to_json(&'a self) -> Result<String>

Render the Record into JSON

§Arguments
  • self - A USP Record structure
§Example
use rusp::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_json().unwrap(), "{\"version\":\"1.3\",\"to_id\":\"doc::to\",\"from_id\":\"doc::from\",\"payload_security\":\"PLAINTEXT\",\"mac_signature\":[],\"sender_cert\":[],\"mqtt_connect\":{\"version\":\"V5\",\"subscribed_topic\":\"topic\"}}");
source

pub fn to_json_pretty(&'a self) -> Result<String>

Render the Record into pretty printed JSON

§Arguments
  • self - A USP Record structure
§Example
use rusp::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_json_pretty().unwrap(), "{\n  \"version\": \"1.3\",\n  \"to_id\": \"doc::to\",\n  \"from_id\": \"doc::from\",\n  \"payload_security\": \"PLAINTEXT\",\n  \"mac_signature\": [],\n  \"sender_cert\": [],\n  \"mqtt_connect\": {\n    \"version\": \"V5\",\n    \"subscribed_topic\": \"topic\"\n  }\n}");
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::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);
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::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");
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::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");

Trait Implementations§

source§

impl Clone for Record

source§

fn clone(&self) -> Record

Returns a copy 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.