-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
from_serialized_bytes
for WrappedNativeMsgUntyped
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use r2r::{WrappedNativeMsgUntyped, WrappedTypesupport}; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let msg = r2r::std_msgs::msg::String { | ||
data: "Hello, world".into(), | ||
}; | ||
|
||
let bytes = msg.to_serialized_bytes()?; | ||
|
||
// bytes to "untyped" r2r msg | ||
let mut native = WrappedNativeMsgUntyped::new_from("std_msgs/msg/String")?; | ||
native.from_serialized_bytes(&bytes)?; | ||
|
||
// "untyped" msg to json | ||
let json = native.to_json()?; | ||
|
||
println!("as json\n----\n{}", serde_json::to_string_pretty(&json)?); | ||
|
||
// bytes to r2r msg. | ||
let msg2 = r2r::std_msgs::msg::String::from_serialized_bytes(&bytes)?; | ||
|
||
println!("as r2r msg\n----\n{:#?}", msg2); | ||
|
||
// json to r2r msg | ||
let msg3: r2r::std_msgs::msg::String = serde_json::from_value(json)?; | ||
|
||
assert_eq!(msg, msg2); | ||
assert_eq!(msg2, msg3); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters