// // Copyright (C) 2019-2021 Swift Navigation Inc. // Contact: https://support.swiftnav.com // // This source is subject to the license found in the file 'LICENSE' which must // be distributed together with this source. All other rights reserved. // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. // This file was auto-generated from spec/tests/yaml/swiftnav/sbp/navigation/test_MsgGPSTimeGNSS.yaml by generate.py. Do not modify by hand! use crate::*; /// Tests [`sbp::iter_messages`], from payload into SBP messages /// /// Asserts: /// - SBP fields equates to that of the field /// - Payload is identical #[test] fn test_auto_check_sbp_navigation_msg_gps_time_gnss() { { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 40, 244, 122, 19, 244, 139, 2, 0, 0, 153, 88, ]); // Test the round trip payload parsing let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 166900, "incorrect value for ns_residual, expected 166900, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326825000, "incorrect value for tow, expected 326825000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 28, 246, 122, 19, 126, 234, 3, 0, 0, 250, 195, ]); // Test the round trip payload parsing let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 256638, "incorrect value for ns_residual, expected 256638, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326825500, "incorrect value for tow, expected 326825500, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 16, 248, 122, 19, 129, 12, 4, 0, 0, 183, 148, ]); // Test the round trip payload parsing let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 265345, "incorrect value for ns_residual, expected 265345, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326826000, "incorrect value for tow, expected 326826000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 4, 250, 122, 19, 137, 204, 4, 0, 0, 137, 101, ]); // Test the round trip payload parsing let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 314505, "incorrect value for ns_residual, expected 314505, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326826500, "incorrect value for tow, expected 326826500, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 248, 251, 122, 19, 181, 137, 5, 0, 0, 15, 225, ]); // Test the round trip payload parsing let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 362933, "incorrect value for ns_residual, expected 362933, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326827000, "incorrect value for tow, expected 326827000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } } /// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message /// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. /// /// Asserts: /// - SBP message constructed via payload is identical to from fields /// - SBP fields equates to that of the field /// - Payload is identical #[test] #[cfg(feature = "json")] fn test_json2sbp_auto_check_sbp_navigation_msg_gps_time_gnss() { { let json_input = r#"{"sender": 35027, "msg_type": 260, "wn": 1920, "tow": 326825000, "crc": 22681, "length": 11, "flags": 0, "ns_residual": 166900, "preamble": 85, "payload": "gAco9HoT9IsCAAA="}"#.as_bytes(); let sbp_msg = { // JSON to SBP message from payload let mut iter = json2sbp_iter_msg(json_input); let from_payload = iter .next() .expect("no message found") .expect("failed to parse message"); // JSON to SBP message from fields let mut iter = iter_messages_from_fields(json_input); let from_fields = iter .next() .expect("no message found") .expect("failed to parse message"); assert_eq!(from_fields, from_payload); from_fields }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 166900, "incorrect value for ns_residual, expected 166900, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326825000, "incorrect value for tow, expected 326825000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; } { let json_input = r#"{"sender": 35027, "msg_type": 260, "wn": 1920, "tow": 326825500, "crc": 50170, "length": 11, "flags": 0, "ns_residual": 256638, "preamble": 85, "payload": "gAcc9noTfuoDAAA="}"#.as_bytes(); let sbp_msg = { // JSON to SBP message from payload let mut iter = json2sbp_iter_msg(json_input); let from_payload = iter .next() .expect("no message found") .expect("failed to parse message"); // JSON to SBP message from fields let mut iter = iter_messages_from_fields(json_input); let from_fields = iter .next() .expect("no message found") .expect("failed to parse message"); assert_eq!(from_fields, from_payload); from_fields }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 256638, "incorrect value for ns_residual, expected 256638, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326825500, "incorrect value for tow, expected 326825500, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; } { let json_input = r#"{"sender": 35027, "msg_type": 260, "wn": 1920, "tow": 326826000, "crc": 38071, "length": 11, "flags": 0, "ns_residual": 265345, "preamble": 85, "payload": "gAcQ+HoTgQwEAAA="}"#.as_bytes(); let sbp_msg = { // JSON to SBP message from payload let mut iter = json2sbp_iter_msg(json_input); let from_payload = iter .next() .expect("no message found") .expect("failed to parse message"); // JSON to SBP message from fields let mut iter = iter_messages_from_fields(json_input); let from_fields = iter .next() .expect("no message found") .expect("failed to parse message"); assert_eq!(from_fields, from_payload); from_fields }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 265345, "incorrect value for ns_residual, expected 265345, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326826000, "incorrect value for tow, expected 326826000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; } { let json_input = r#"{"sender": 35027, "msg_type": 260, "wn": 1920, "tow": 326826500, "crc": 25993, "length": 11, "flags": 0, "ns_residual": 314505, "preamble": 85, "payload": "gAcE+noTicwEAAA="}"#.as_bytes(); let sbp_msg = { // JSON to SBP message from payload let mut iter = json2sbp_iter_msg(json_input); let from_payload = iter .next() .expect("no message found") .expect("failed to parse message"); // JSON to SBP message from fields let mut iter = iter_messages_from_fields(json_input); let from_fields = iter .next() .expect("no message found") .expect("failed to parse message"); assert_eq!(from_fields, from_payload); from_fields }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 314505, "incorrect value for ns_residual, expected 314505, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326826500, "incorrect value for tow, expected 326826500, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; } { let json_input = r#"{"sender": 35027, "msg_type": 260, "wn": 1920, "tow": 326827000, "crc": 57615, "length": 11, "flags": 0, "ns_residual": 362933, "preamble": 85, "payload": "gAf4+3oTtYkFAAA="}"#.as_bytes(); let sbp_msg = { // JSON to SBP message from payload let mut iter = json2sbp_iter_msg(json_input); let from_payload = iter .next() .expect("no message found") .expect("failed to parse message"); // JSON to SBP message from fields let mut iter = iter_messages_from_fields(json_input); let from_fields = iter .next() .expect("no message found") .expect("failed to parse message"); assert_eq!(from_fields, from_payload); from_fields }; match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 362933, "incorrect value for ns_residual, expected 362933, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326827000, "incorrect value for tow, expected 326827000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; } } /// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON /// /// Assumes: /// - [`self::test_auto_check_sbp_navigation_msg_gps_time_gnss`] passes /// /// Asserts: /// - SBP fields equates to that of the field /// - Payload is identical #[test] #[cfg(feature = "json")] fn test_sbp2json_auto_check_sbp_navigation_msg_gps_time_gnss() { { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 40, 244, 122, 19, 244, 139, 2, 0, 0, 153, 88, ]); // Construct sbp message let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; let mut json_buffer = vec![]; // Populate json buffer, CompactFormatter sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) .send(&sbp_msg) .unwrap(); // Reconstruct Sbp message from json fields, roundtrip let sbp_msg = sbp::messages::Sbp::MsgGpsTimeGnss( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 166900, "incorrect value for ns_residual, expected 166900, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326825000, "incorrect value for tow, expected 326825000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; // Check payload is still identical let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 28, 246, 122, 19, 126, 234, 3, 0, 0, 250, 195, ]); // Construct sbp message let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; let mut json_buffer = vec![]; // Populate json buffer, CompactFormatter sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) .send(&sbp_msg) .unwrap(); // Reconstruct Sbp message from json fields, roundtrip let sbp_msg = sbp::messages::Sbp::MsgGpsTimeGnss( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 256638, "incorrect value for ns_residual, expected 256638, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326825500, "incorrect value for tow, expected 326825500, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; // Check payload is still identical let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 16, 248, 122, 19, 129, 12, 4, 0, 0, 183, 148, ]); // Construct sbp message let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; let mut json_buffer = vec![]; // Populate json buffer, CompactFormatter sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) .send(&sbp_msg) .unwrap(); // Reconstruct Sbp message from json fields, roundtrip let sbp_msg = sbp::messages::Sbp::MsgGpsTimeGnss( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 265345, "incorrect value for ns_residual, expected 265345, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326826000, "incorrect value for tow, expected 326826000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; // Check payload is still identical let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 4, 250, 122, 19, 137, 204, 4, 0, 0, 137, 101, ]); // Construct sbp message let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; let mut json_buffer = vec![]; // Populate json buffer, CompactFormatter sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) .send(&sbp_msg) .unwrap(); // Reconstruct Sbp message from json fields, roundtrip let sbp_msg = sbp::messages::Sbp::MsgGpsTimeGnss( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 314505, "incorrect value for ns_residual, expected 314505, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326826500, "incorrect value for tow, expected 326826500, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; // Check payload is still identical let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 4, 1, 211, 136, 11, 128, 7, 248, 251, 122, 19, 181, 137, 5, 0, 0, 15, 225, ]); // Construct sbp message let sbp_msg = { let mut msgs = iter_messages(&mut payload); msgs.next() .expect("no message found") .expect("failed to parse message") }; let mut json_buffer = vec![]; // Populate json buffer, CompactFormatter sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) .send(&sbp_msg) .unwrap(); // Reconstruct Sbp message from json fields, roundtrip let sbp_msg = sbp::messages::Sbp::MsgGpsTimeGnss( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgGpsTimeGnss(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x104, "Incorrect message type, expected 0x104, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x88d3, "incorrect sender id, expected 0x88d3, is {sender_id}" ); assert_eq!( msg.flags, 0, "incorrect value for flags, expected 0, is {}", msg.flags ); assert_eq!( msg.ns_residual, 362933, "incorrect value for ns_residual, expected 362933, is {}", msg.ns_residual ); assert_eq!( msg.tow, 326827000, "incorrect value for tow, expected 326827000, is {}", msg.tow ); assert_eq!( msg.wn, 1920, "incorrect value for wn, expected 1920, is {}", msg.wn ); } _ => panic!("Invalid message type! Expected a MsgGPSTimeGnss"), }; // Check payload is still identical let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } }