Struct Msg

Source
pub struct Msg {
    pub header: Option<Header>,
    pub body: Option<Body>,
}

Fields§

§header: Option<Header>§body: Option<Body>

Implementations§

Source§

impl Msg

Implementation of some extension methods for Msgs

Source

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

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

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

§Arguments
  • bytes - A slice of bytes containing the Protobuf encoded USP Message
§Example
use rusp_lib::usp::Msg;
let msg =
    Msg::from_bytes(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ])
    .unwrap();
Source

pub fn msg_id(&self) -> &str

Retrieves the message ID from a Msg structure

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ]);
assert_eq!(msg.unwrap().msg_id(), "AXSS-1544114045.442596");
Source

pub const fn is_request(&self) -> bool

Checks whether the body contains a message of type request

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert_eq!(msg.is_request(), true);
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ]).unwrap();
assert_eq!(msg.is_request(), false);
Source

pub const fn is_notify_request(&self) -> bool

Checks whether the body contains a message of type notify (request)

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert_eq!(msg.is_notify_request(), true);
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ]).unwrap();
assert_eq!(msg.is_notify_request(), false);
Source

pub const fn get_notify_request(&self) -> Option<&Notify>

Retrieves the notify request from the Msg

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert!(msg.get_notify_request().is_some());
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ]).unwrap();
assert!(msg.get_notify_request().is_none());
Source

pub const fn is_response(&self) -> bool

Checks whether the body contains a message of type response

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert_eq!(msg.is_response(), false);
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ]).unwrap();
assert_eq!(msg.is_response(), true);
Source

pub fn is_error(&self) -> bool

Checks whether the body contains a message of type response

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert_eq!(msg.is_error(), false);
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ]).unwrap();
assert_eq!(msg.is_error(), false);
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x05, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x12,
        0x17, 0x1a, 0x15, 0x0d, 0x5b, 0x1b, 0x00, 0x00,
        0x12, 0x0e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e,
        0x61, 0x6c, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72,
    ]).unwrap();
assert_eq!(msg.is_error(), true);
Source

pub fn get_error(&self) -> Option<Error>

Retrieves the notify request from the Msg

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert!(msg.get_error().is_none());
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x1a, 0x0a, 0x16, 0x41, 0x58, 0x53, 0x53, 0x2d, 0x31, 0x35, 0x34,
        0x34, 0x31, 0x31, 0x34, 0x30, 0x34, 0x35, 0x2e, 0x34, 0x34, 0x32, 0x35,
        0x39, 0x36, 0x10, 0x02, 0x12, 0x46, 0x12, 0x44, 0x0a, 0x42, 0x0a, 0x40,
        0x0a, 0x22, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x63,
        0x61, 0x6c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x54, 0x50, 0x2e,
        0x31, 0x2e, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e,
        0x15, 0x62, 0x1b, 0x00, 0x00, 0x1a, 0x15, 0x55, 0x6e, 0x73, 0x75, 0x70,
        0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
        0x65, 0x74, 0x65, 0x72
    ]).unwrap();
assert!(msg.get_error().is_none());
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x05, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x12,
        0x17, 0x1a, 0x15, 0x0d, 0x5b, 0x1b, 0x00, 0x00,
        0x12, 0x0e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e,
        0x61, 0x6c, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72,
    ]).unwrap();
assert!(msg.get_error().is_some());
Source

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

Checks the validity of this Msg 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_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x09, 0x0a, 0x07, 0x6e, 0x6f, 0x2d, 0x62,
        0x6f, 0x64, 0x79, 0x12, 0x00,
    ]).unwrap();
assert!(msg.check_validity().is_err());
Source§

impl Msg

Implementation of some extension methods for Msgs

Source

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

Encode the Msg as JSON format

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert_eq!(msg.to_json().unwrap(), "{\"Header\":{\"msg_id\":\"test\",\"msg_type\":\"NOTIFY\"},\"Body\":{\"Request\":{\"Notify\":{\"subscription_id\":\"notif\",\"send_resp\":true,\"on_board_req\":{\"oui\":\"0044FF\",\"product_class\":\"Foo\",\"serial_number\":\"01234\",\"agent_supported_protocol_versions\":\"1.3\"}}}}}");
Source

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

Encode the Msg in pretty printed JSON format

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let msg =
    try_decode_msg(&[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ]).unwrap();
assert_eq!(msg.to_json_pretty().unwrap(), "{\n  \"Header\": {\n    \"msg_id\": \"test\",\n    \"msg_type\": \"NOTIFY\"\n  },\n  \"Body\": {\n    \"Request\": {\n      \"Notify\": {\n        \"subscription_id\": \"notif\",\n        \"send_resp\": true,\n        \"on_board_req\": {\n          \"oui\": \"0044FF\",\n          \"product_class\": \"Foo\",\n          \"serial_number\": \"01234\",\n          \"agent_supported_protocol_versions\": \"1.3\"\n        }\n      }\n    }\n  }\n}");
Source

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

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

§Arguments
  • self - A decoded USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let bytes = &[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ];
let msg = try_decode_msg(bytes).unwrap();
assert_eq!(msg.to_vec().unwrap(), bytes);
Source

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

Render the Msg into a raw C string representation

§Arguments
  • self - A USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let bytes = &[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ];
let msg = try_decode_msg(bytes).unwrap();
assert_eq!(msg.to_c_str().unwrap(), "\"\\x0a\\x08\\x0a\\x04test\\x10\\x03\\x12(\\x0a\\x26B\\x24\\x0a\\x05notif\\x10\\x01B\\x19\\x0a\\x060044FF\\x12\\x03Foo\\x1a\\x0501234\\x22\\x031.3\"\n");
Source

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

Render the Msg into a raw C array representation

§Arguments
  • self - A USP Msg structure
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let bytes = &[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ];
let msg = try_decode_msg(bytes).unwrap();
assert_eq!(msg.to_c_array().unwrap(), "unsigned int pb_len = 52;\nconst char pb[] = {\n  0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, /* ____test */\n  0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24, /* ___(__B_ */\n  0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10, /* __notif_ */\n  0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34, /* _B___004 */\n  0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f, /* 4FF__Foo */\n  0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22, /* __01234\" */\n  0x03, 0x31, 0x2e, 0x33,                         /* _1.3 */\n};\n");
Source

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

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

§Arguments
  • self - A USP Msg structure
  • name - The variable name prefix used in the rendered output
§Example
use rusp_lib::usp_decoder::try_decode_msg;
let bytes = &[
        0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74,
        0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24,
        0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10,
        0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34,
        0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f,
        0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22,
        0x03, 0x31, 0x2e, 0x33,
    ];
let msg = try_decode_msg(bytes).unwrap();
assert_eq!(msg.to_c_array_custom("msg").unwrap(), "unsigned int msg_len = 52;\nconst char msg[] = {\n  0x0a, 0x08, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, /* ____test */\n  0x10, 0x03, 0x12, 0x28, 0x0a, 0x26, 0x42, 0x24, /* ___(__B_ */\n  0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x10, /* __notif_ */\n  0x01, 0x42, 0x19, 0x0a, 0x06, 0x30, 0x30, 0x34, /* _B___004 */\n  0x34, 0x46, 0x46, 0x12, 0x03, 0x46, 0x6f, 0x6f, /* 4FF__Foo */\n  0x1a, 0x05, 0x30, 0x31, 0x32, 0x33, 0x34, 0x22, /* __01234\" */\n  0x03, 0x31, 0x2e, 0x33,                         /* _1.3 */\n};\n");

Trait Implementations§

Source§

impl Clone for Msg

Source§

fn clone(&self) -> Msg

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 Msg

Source§

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

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

impl Default for Msg

Source§

fn default() -> Msg

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

impl<'a> MessageRead<'a> for Msg

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 Msg

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 Msg

Source§

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

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 Msg

Auto Trait Implementations§

§

impl Freeze for Msg

§

impl RefUnwindSafe for Msg

§

impl Send for Msg

§

impl Sync for Msg

§

impl Unpin for Msg

§

impl UnwindSafe for Msg

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.