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
impl<'a> Record
Implementation of some extension methods for Record
s
sourcepub fn to_json(&'a self) -> Result<String>
pub fn to_json(&'a self) -> Result<String>
Render the Record
into JSON
§Arguments
self
- A USPRecord
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\"}}");
sourcepub fn to_json_pretty(&'a self) -> Result<String>
pub fn to_json_pretty(&'a self) -> Result<String>
Render the Record
into pretty printed JSON
§Arguments
self
- A USPRecord
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}");
sourcepub fn to_vec(&self) -> Result<Vec<u8>>
pub fn to_vec(&self) -> Result<Vec<u8>>
Encode the Record into a Protobuf byte stream returned as Vec<[u8]>
§Arguments
self
- A USPRecord
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);
sourcepub fn to_c_str(&self) -> Result<String>
pub fn to_c_str(&self) -> Result<String>
Render the Record
into a raw C string representation
§Arguments
self
- A USPRecord
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");
sourcepub fn to_c_array(&self) -> Result<String>
pub fn to_c_array(&self) -> Result<String>
Render the Record
into a raw C array representation
§Arguments
self
- A USPRecord
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<'a> MessageRead<'a> for Record
impl<'a> MessageRead<'a> for Record
source§fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self>
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 moresource§impl MessageWrite for Record
impl MessageWrite for Record
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)