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_typeImplementations§
Source§impl Record
impl Record
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
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();Sourcepub fn check_validity(&self) -> Result<()>
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§impl Record
Implementation of some extension methods for Records
impl Record
Implementation of some extension methods for Records
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 USPRecordstructure
§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
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 USPRecordstructure
§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
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 USPRecordstructure
§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
Sourcepub fn to_c_array_custom(&self, name: &str) -> Result<String>
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 USPRecordstructurename- 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<'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>
Self by reading from the given bytes
via the given reader. Read more