// // 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/piksi/test_MsgThreadState.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_piksi_msg_thread_state() { { let mut payload = Cursor::new(vec![ 85, 23, 0, 246, 215, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 9, 0, 0, 73, 138, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2460, "incorrect value for stack_free, expected 2460, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 246, 215, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 2, 36, 0, 0, 0, 151, 20, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 595, "incorrect value for cpu, expected 595, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 36, "incorrect value for stack_free, expected 36, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 246, 215, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 116, 4, 0, 0, 226, 60, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 14, "incorrect value for cpu, expected 14, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 1140, "incorrect value for stack_free, expected 1140, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 246, 215, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 196, 19, 0, 0, 90, 169, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 1, "incorrect value for cpu, expected 1, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 5060, "incorrect value for stack_free, expected 5060, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 246, 215, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 20, 9, 0, 0, 47, 75, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 7, "incorrect value for cpu, expected 7, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2324, "incorrect value for stack_free, expected 2324, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 195, 4, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 148, 9, 0, 0, 195, 212, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2452, "incorrect value for stack_free, expected 2452, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 195, 4, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 1, 36, 0, 0, 0, 225, 18, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 484, "incorrect value for cpu, expected 484, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 36, "incorrect value for stack_free, expected 36, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 195, 4, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 1, 92, 7, 0, 0, 166, 116, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 394, "incorrect value for cpu, expected 394, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 1884, "incorrect value for stack_free, expected 1884, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 195, 4, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, 12, 0, 0, 229, 174, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 1, "incorrect value for cpu, expected 1, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 3076, "incorrect value for stack_free, expected 3076, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 124, 9, 0, 0, 52, 2, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 10, "incorrect value for cpu, expected 10, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2428, "incorrect value for stack_free, expected 2428, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ 85, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 9, 0, 0, 122, 54, ]); // 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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[ 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0 ], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[ 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0 ], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2332, "incorrect value for stack_free, expected 2332, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; 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_piksi_msg_thread_state() { { let json_input = r#"{"sender": 55286, "msg_type": 23, "cpu": 0, "crc": 35401, "length": 26, "stack_free": 2460, "preamble": 85, "payload": "bWFpbgAAAAAAAAAAAAAAAAAAAAAAAJwJAAA=", "name": "main\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2460, "incorrect value for stack_free, expected 2460, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 55286, "msg_type": 23, "cpu": 595, "crc": 5271, "length": 26, "stack_free": 36, "preamble": 85, "payload": "aWRsZQAAAAAAAAAAAAAAAAAAAABTAiQAAAA=", "name": "idle\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 595, "incorrect value for cpu, expected 595, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 36, "incorrect value for stack_free, expected 36, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 55286, "msg_type": 23, "cpu": 14, "crc": 15586, "length": 26, "stack_free": 1140, "preamble": 85, "payload": "TkFQIElTUgAAAAAAAAAAAAAAAAAOAHQEAAA=", "name": "NAP ISR\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 14, "incorrect value for cpu, expected 14, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 1140, "incorrect value for stack_free, expected 1140, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 55286, "msg_type": 23, "cpu": 1, "crc": 43354, "length": 26, "stack_free": 5060, "preamble": 85, "payload": "U0JQAAAAAAAAAAAAAAAAAAAAAAABAMQTAAA=", "name": "SBP\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 1, "incorrect value for cpu, expected 1, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 5060, "incorrect value for stack_free, expected 5060, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 55286, "msg_type": 23, "cpu": 7, "crc": 19247, "length": 26, "stack_free": 2324, "preamble": 85, "payload": "bWFuYWdlIGFjcQAAAAAAAAAAAAAHABQJAAA=", "name": "manage acq\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 7, "incorrect value for cpu, expected 7, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2324, "incorrect value for stack_free, expected 2324, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 1219, "msg_type": 23, "cpu": 0, "crc": 54467, "length": 26, "stack_free": 2452, "preamble": 85, "payload": "bWFpbgAAAAAAAAAAAAAAAAAAAAAAAJQJAAA=", "name": "main\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2452, "incorrect value for stack_free, expected 2452, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 1219, "msg_type": 23, "cpu": 484, "crc": 4833, "length": 26, "stack_free": 36, "preamble": 85, "payload": "aWRsZQAAAAAAAAAAAAAAAAAAAADkASQAAAA=", "name": "idle\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 484, "incorrect value for cpu, expected 484, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 36, "incorrect value for stack_free, expected 36, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 1219, "msg_type": 23, "cpu": 394, "crc": 29862, "length": 26, "stack_free": 1884, "preamble": 85, "payload": "TkFQIElTUgAAAAAAAAAAAAAAAACKAVwHAAA=", "name": "NAP ISR\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 394, "incorrect value for cpu, expected 394, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 1884, "incorrect value for stack_free, expected 1884, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 1219, "msg_type": 23, "cpu": 1, "crc": 44773, "length": 26, "stack_free": 3076, "preamble": 85, "payload": "U0JQAAAAAAAAAAAAAAAAAAAAAAABAAQMAAA=", "name": "SBP\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 1, "incorrect value for cpu, expected 1, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 3076, "incorrect value for stack_free, expected 3076, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 1219, "msg_type": 23, "cpu": 10, "crc": 564, "length": 26, "stack_free": 2428, "preamble": 85, "payload": "bWFuYWdlIGFjcQAAAAAAAAAAAAAKAHwJAAA=", "name": "manage acq\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 10, "incorrect value for cpu, expected 10, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2428, "incorrect value for stack_free, expected 2428, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } { let json_input = r#"{"sender": 1219, "msg_type": 23, "cpu": 0, "crc": 13946, "length": 26, "stack_free": 2332, "preamble": 85, "payload": "bWFuYWdlIHRyYWNrAAAAAAAAAAAAABwJAAA=", "name": "manage track\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}"#.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::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[ 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0 ], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[ 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0 ], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2332, "incorrect value for stack_free, expected 2332, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; } } /// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON /// /// Assumes: /// - [`self::test_auto_check_sbp_piksi_msg_thread_state`] passes /// /// Asserts: /// - SBP fields equates to that of the field /// - Payload is identical #[test] #[cfg(feature = "json")] fn test_sbp2json_auto_check_sbp_piksi_msg_thread_state() { { let mut payload = Cursor::new(vec![ 85, 23, 0, 246, 215, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 9, 0, 0, 73, 138, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2460, "incorrect value for stack_free, expected 2460, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 246, 215, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 2, 36, 0, 0, 0, 151, 20, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 595, "incorrect value for cpu, expected 595, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 36, "incorrect value for stack_free, expected 36, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 246, 215, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 116, 4, 0, 0, 226, 60, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 14, "incorrect value for cpu, expected 14, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 1140, "incorrect value for stack_free, expected 1140, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 246, 215, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 196, 19, 0, 0, 90, 169, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 1, "incorrect value for cpu, expected 1, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 5060, "incorrect value for stack_free, expected 5060, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 246, 215, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 20, 9, 0, 0, 47, 75, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0xd7f6, "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert_eq!( msg.cpu, 7, "incorrect value for cpu, expected 7, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2324, "incorrect value for stack_free, expected 2324, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 195, 4, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 148, 9, 0, 0, 195, 212, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2452, "incorrect value for stack_free, expected 2452, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 195, 4, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 1, 36, 0, 0, 0, 225, 18, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 484, "incorrect value for cpu, expected 484, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 36, "incorrect value for stack_free, expected 36, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 195, 4, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 1, 92, 7, 0, 0, 166, 116, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 394, "incorrect value for cpu, expected 394, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 1884, "incorrect value for stack_free, expected 1884, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 195, 4, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, 12, 0, 0, 229, 174, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 1, "incorrect value for cpu, expected 1, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 3076, "incorrect value for stack_free, expected 3076, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 124, 9, 0, 0, 52, 2, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 10, "incorrect value for cpu, expected 10, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2428, "incorrect value for stack_free, expected 2428, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // 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, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 9, 0, 0, 122, 54, ]); // 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::MsgThreadState( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() .to_string() .as_str(), ) .unwrap(), ); match &sbp_msg { sbp::messages::Sbp::MsgThreadState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( msg_type, 0x17, "Incorrect message type, expected 0x17, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( sender_id, 0x4c3, "incorrect sender id, expected 0x4c3, is {sender_id}" ); assert_eq!( msg.cpu, 0, "incorrect value for cpu, expected 0, is {}", msg.cpu ); assert_eq!( msg.name.as_bytes(), &[ 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0 ], "incorrect value for msg.name, expected string '{:?}', is '{:?}'", &[ 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0 ], msg.name.as_bytes() ); assert_eq!( msg.stack_free, 2332, "incorrect value for stack_free, expected 2332, is {}", msg.stack_free ); } _ => panic!("Invalid message type! Expected a MsgThreadState"), }; // Check payload is still identical let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } }