diff --git a/generator/sbpg/targets/resources/sbp_messages_mod.rs b/generator/sbpg/targets/resources/sbp_messages_mod.rs index d56653c5b1..088b6419d3 100644 --- a/generator/sbpg/targets/resources/sbp_messages_mod.rs +++ b/generator/sbpg/targets/resources/sbp_messages_mod.rs @@ -26,6 +26,7 @@ use self::unknown::Unknown; use serde::{Serialize, Deserialize}; use crate::serialize::SbpSerialize; use crate::framer::FramerError; +use crate::parser::SbpParse; pub trait SBPMessage: SbpSerialize { fn get_message_type(&self) -> u16; @@ -48,7 +49,7 @@ impl SBP { let x: Result = match msg_id { ((*- for m in msgs *)) (((m.sbp_id))) => { - let mut msg = (((m.identifier|camel_case)))::parse(payload)?; + let mut msg: (((m.identifier|camel_case))) = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::(((m.identifier|camel_case)))(msg)) }, diff --git a/generator/sbpg/targets/resources/sbp_messages_template.rs b/generator/sbpg/targets/resources/sbp_messages_template.rs index 1c36c7df21..d23516836b 100644 --- a/generator/sbpg/targets/resources/sbp_messages_template.rs +++ b/generator/sbpg/targets/resources/sbp_messages_template.rs @@ -15,14 +15,11 @@ //! (((description | replace("\n", "\n//! ")))) -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian,ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Serialize, Deserialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, UnboundedSbpString, BoundedSbpString}; ((*- for i in includes *)) use super::(((i)))::*; @@ -50,36 +47,18 @@ pub struct (((m.identifier|camel_case))) { ((*- endfor *)) } -impl (((m.identifier|camel_case))) { +impl SbpParse<(((m.identifier|camel_case)))> for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result<(((m.identifier|camel_case))), crate::Error> { + fn parse(&mut self) -> crate::Result<(((m.identifier|camel_case)))> { Ok( (((m.identifier|camel_case))){ ((*- if m.is_real_message *)) sender_id: None, ((*- endif *)) ((*- for f in m.fields *)) - (((f.identifier))): (((f|parse_type)))?, + (((f.identifier))): self.parse()?, ((*- endfor *)) } ) } - - ((*- if not m.is_real_message *)) - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push( (((m.identifier|camel_case)))::parse(buf)? ); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push( (((m.identifier|camel_case)))::parse(buf)? ); - } - Ok(v) - } - ((*- endif *)) } ((*- if m.is_real_message *)) diff --git a/generator/sbpg/targets/rust.py b/generator/sbpg/targets/rust.py index be9400b55a..ba55f4d9a9 100644 --- a/generator/sbpg/targets/rust.py +++ b/generator/sbpg/targets/rust.py @@ -52,15 +52,22 @@ def commentify(value): 's32': 'i32', 's64': 'i64', 'float': 'f32', - 'double': 'f64', - 'string': 'SbpString'} + 'double': 'f64'} def type_map(field): if field.type_id in TYPE_MAP: return TYPE_MAP[field.type_id] elif field.type_id == 'array': t = field.options['fill'].value - return "Vec<{}>".format(TYPE_MAP.get(t, t)) + if field.options.get('size', None): + return "[{}; {}]".format(TYPE_MAP.get(t,t), field.options.get('size').value) + else: + return "Vec<{}>".format(TYPE_MAP.get(t, t)) + elif field.type_id == 'string': + if field.options.get('size', None): + return "BoundedSbpString<{}>".format(field.options.get('size').value) + else: + return "UnboundedSbpString" else: return field.type_id @@ -88,12 +95,12 @@ def parse_type(field): t = field.options['fill'].value if t in TYPE_MAP.keys(): if 'size' in field.options: - return 'crate::parser::read_%s_array_limit(_buf, %d)' % (t, field.options['size'].value) + return 'crate::parser::read_%s_array_fixed(_buf)' % t else: return 'crate::parser::read_%s_array(_buf)' % t else: if 'size' in field.options: - return '%s::parse_array_limit(_buf, %d)' % (t, field.options['size'].value) + return '%s::parse_array_fixed(_buf)' % t else: return '%s::parse_array(_buf)' % t else: diff --git a/rust/sbp/src/lib.rs b/rust/sbp/src/lib.rs index cf63ebf17f..1b9d5a7abc 100644 --- a/rust/sbp/src/lib.rs +++ b/rust/sbp/src/lib.rs @@ -10,7 +10,7 @@ pub mod serialize; #[cfg(feature = "sbp2json")] pub mod sbp2json; -use std::convert::{From, Into}; +use std::convert::{From, Into, TryFrom}; use std::error; use std::fmt; use std::result; @@ -22,66 +22,157 @@ pub type Result = result::Result; pub const SBP_MAX_PAYLOAD_SIZE: usize = 255; +pub trait SbpString { + fn as_bytes(&self) -> &[u8]; + fn to_string(&self) -> String; +} + #[derive(Debug, Clone)] -pub struct SbpString(Vec); +pub struct UnboundedSbpString(Vec); -impl SbpString { - pub fn as_bytes(&self) -> &[u8] { +impl SbpString for UnboundedSbpString { + fn as_bytes(&self) -> &[u8] { &self.0 } - pub fn to_string(&self) -> String { + fn to_string(&self) -> String { String::from_utf8_lossy(&self.0).into() } } +impl fmt::Display for UnboundedSbpString { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "SbpString({})", SbpString::to_string(self)) + } +} + +#[cfg(feature = "sbp_serde")] +impl<'de> Deserialize<'de> for UnboundedSbpString { + fn deserialize(deserializer: D) -> result::Result + where + D: Deserializer<'de>, + { + Deserialize::deserialize(deserializer).map(|s: String| UnboundedSbpString::from(s)) + } +} + #[cfg(feature = "sbp_serde")] -impl Serialize for SbpString { +impl Serialize for UnboundedSbpString { fn serialize(&self, serializer: S) -> result::Result where S: Serializer, { - let s: String = self.clone().into(); + let s = SbpString::to_string(self); serializer.serialize_str(&s) } } +impl From for String { + fn from(s: UnboundedSbpString) -> String { + SbpString::to_string(&s) + } +} + +impl From for Vec { + fn from(s: UnboundedSbpString) -> Vec { + s.0 + } +} + +impl From for UnboundedSbpString { + fn from(s: String) -> UnboundedSbpString { + UnboundedSbpString(s.into_bytes()) + } +} + +impl TryFrom<&mut &[u8]> for UnboundedSbpString { + type Error = Error; + fn try_from(buf: &mut &[u8]) -> Result { + let amount = buf.len(); + let (head, tail) = buf.split_at(amount); + *buf = tail; + Ok(UnboundedSbpString(head.to_vec())) + } +} + +#[derive(Debug, Clone)] +pub struct BoundedSbpString([u8; SIZE]); + +impl SbpString for BoundedSbpString { + fn as_bytes(&self) -> &[u8] { + &self.0 + } + fn to_string(&self) -> String { + String::from_utf8_lossy(&self.0).into() + } +} + +impl Default for BoundedSbpString { + fn default() -> BoundedSbpString { + BoundedSbpString([0; SIZE]) + } +} + +impl fmt::Display for BoundedSbpString { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "SbpString({})", SbpString::to_string(self)) + } +} + #[cfg(feature = "sbp_serde")] -impl<'de> Deserialize<'de> for SbpString { +impl<'de, const SIZE: usize> Deserialize<'de> for BoundedSbpString { fn deserialize(deserializer: D) -> result::Result where D: Deserializer<'de>, { - Deserialize::deserialize(deserializer).map(|s: String| SbpString::from(s)) + Deserialize::deserialize(deserializer).map(|s: String| BoundedSbpString::::from(s)) } } -impl From for SbpString { - fn from(s: String) -> SbpString { - SbpString(s.as_bytes().to_vec()) +#[cfg(feature = "sbp_serde")] +impl Serialize for BoundedSbpString { + fn serialize(&self, serializer: S) -> result::Result + where + S: Serializer, + { + let s = SbpString::to_string(self); + serializer.serialize_str(&s) } } -impl Into for SbpString { - fn into(self) -> String { - self.to_string() +impl From> for String { + fn from(s: BoundedSbpString) -> String { + SbpString::to_string(&s) } } -impl Into for &SbpString { - fn into(self) -> String { - self.to_string() +impl From> for Vec { + fn from(s: BoundedSbpString) -> Vec { + s.0.into() } } -impl Into> for SbpString { - fn into(self) -> Vec { - self.0 +impl From for BoundedSbpString { + fn from(s: String) -> BoundedSbpString { + let len = std::cmp::min(SIZE, s.len()); + let s = &s[..len]; + + let mut result = BoundedSbpString::::default(); + result.0[..len].copy_from_slice(s.as_bytes()); + result } } -impl fmt::Display for SbpString { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "SbpString({})", Into::::into(self.clone())) +impl TryFrom<&mut &[u8]> for BoundedSbpString { + type Error = Error; + fn try_from(buf: &mut &[u8]) -> Result> { + let amount = std::cmp::min(SIZE, buf.len()); + let (head, tail) = buf.split_at(amount); + + let mut s = BoundedSbpString::::default(); + s.0[..amount].copy_from_slice(head); + *buf = tail; + + Ok(s) } } @@ -127,6 +218,8 @@ impl From for Error { #[cfg(test)] mod tests { + use crate::{SbpString, UnboundedSbpString}; + #[test] fn baseline_ecef() { let baseline_ecef_payload = [ @@ -330,15 +423,13 @@ mod tests { #[test] fn sbp_string() { - use crate::SbpString; - - let sbp_str = SbpString(b"1234".to_vec()); - let s = sbp_str.to_string(); + let sbp_str = UnboundedSbpString(b"1234".to_vec()); + let s = SbpString::to_string(&sbp_str); assert_eq!("1234", s); - let sbp_str = SbpString(b"1234\xFF".to_vec()); - let s = sbp_str.to_string(); + let sbp_str = UnboundedSbpString(b"1234\xFF".to_vec()); + let s = SbpString::to_string(&sbp_str); assert_eq!("1234\u{FFFD}", s); } diff --git a/rust/sbp/src/messages/acquisition.rs b/rust/sbp/src/messages/acquisition.rs index 4a41a32671..b677f9008a 100644 --- a/rust/sbp/src/messages/acquisition.rs +++ b/rust/sbp/src/messages/acquisition.rs @@ -14,15 +14,12 @@ //****************************************************************************/ //! Satellite acquisition messages from the device. -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; use super::gnss::*; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Acq perfomance measurement and debug /// @@ -60,39 +57,24 @@ pub struct AcqSvProfile { pub cp: u32, } -impl AcqSvProfile { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( AcqSvProfile{ - job_type: _buf.read_u8()?, - status: _buf.read_u8()?, - cn0: _buf.read_u16::()?, - int_time: _buf.read_u8()?, - sid: GnssSignal::parse(_buf)?, - bin_width: _buf.read_u16::()?, - timestamp: _buf.read_u32::()?, - time_spent: _buf.read_u32::()?, - cf_min: _buf.read_i32::()?, - cf_max: _buf.read_i32::()?, - cf: _buf.read_i32::()?, - cp: _buf.read_u32::()?, + job_type: self.parse()?, + status: self.parse()?, + cn0: self.parse()?, + int_time: self.parse()?, + sid: self.parse()?, + bin_width: self.parse()?, + timestamp: self.parse()?, + time_spent: self.parse()?, + cf_min: self.parse()?, + cf_max: self.parse()?, + cf: self.parse()?, + cp: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(AcqSvProfile::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(AcqSvProfile::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for AcqSvProfile { @@ -164,42 +146,24 @@ pub struct AcqSvProfileDep { pub cp: u32, } -impl AcqSvProfileDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( AcqSvProfileDep{ - job_type: _buf.read_u8()?, - status: _buf.read_u8()?, - cn0: _buf.read_u16::()?, - int_time: _buf.read_u8()?, - sid: GnssSignalDep::parse(_buf)?, - bin_width: _buf.read_u16::()?, - timestamp: _buf.read_u32::()?, - time_spent: _buf.read_u32::()?, - cf_min: _buf.read_i32::()?, - cf_max: _buf.read_i32::()?, - cf: _buf.read_i32::()?, - cp: _buf.read_u32::()?, + job_type: self.parse()?, + status: self.parse()?, + cn0: self.parse()?, + int_time: self.parse()?, + sid: self.parse()?, + bin_width: self.parse()?, + timestamp: self.parse()?, + time_spent: self.parse()?, + cf_min: self.parse()?, + cf_max: self.parse()?, + cf: self.parse()?, + cp: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(AcqSvProfileDep::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(AcqSvProfileDep::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for AcqSvProfileDep { @@ -260,15 +224,15 @@ pub struct MsgAcqResult { pub sid: GnssSignal, } -impl MsgAcqResult { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAcqResult{ sender_id: None, - cn0: _buf.read_f32::()?, - cp: _buf.read_f32::()?, - cf: _buf.read_f32::()?, - sid: GnssSignal::parse(_buf)?, + cn0: self.parse()?, + cp: self.parse()?, + cf: self.parse()?, + sid: self.parse()?, } ) } } @@ -331,15 +295,15 @@ pub struct MsgAcqResultDepA { pub prn: u8, } -impl MsgAcqResultDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAcqResultDepA{ sender_id: None, - snr: _buf.read_f32::()?, - cp: _buf.read_f32::()?, - cf: _buf.read_f32::()?, - prn: _buf.read_u8()?, + snr: self.parse()?, + cp: self.parse()?, + cf: self.parse()?, + prn: self.parse()?, } ) } } @@ -401,15 +365,15 @@ pub struct MsgAcqResultDepB { pub sid: GnssSignalDep, } -impl MsgAcqResultDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAcqResultDepB{ sender_id: None, - snr: _buf.read_f32::()?, - cp: _buf.read_f32::()?, - cf: _buf.read_f32::()?, - sid: GnssSignalDep::parse(_buf)?, + snr: self.parse()?, + cp: self.parse()?, + cf: self.parse()?, + sid: self.parse()?, } ) } } @@ -470,15 +434,15 @@ pub struct MsgAcqResultDepC { pub sid: GnssSignalDep, } -impl MsgAcqResultDepC { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAcqResultDepC{ sender_id: None, - cn0: _buf.read_f32::()?, - cp: _buf.read_f32::()?, - cf: _buf.read_f32::()?, - sid: GnssSignalDep::parse(_buf)?, + cn0: self.parse()?, + cp: self.parse()?, + cf: self.parse()?, + sid: self.parse()?, } ) } } @@ -534,12 +498,12 @@ pub struct MsgAcqSvProfile { pub acq_sv_profile: Vec, } -impl MsgAcqSvProfile { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAcqSvProfile{ sender_id: None, - acq_sv_profile: AcqSvProfile::parse_array(_buf)?, + acq_sv_profile: self.parse()?, } ) } } @@ -588,12 +552,12 @@ pub struct MsgAcqSvProfileDep { pub acq_sv_profile: Vec, } -impl MsgAcqSvProfileDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAcqSvProfileDep{ sender_id: None, - acq_sv_profile: AcqSvProfileDep::parse_array(_buf)?, + acq_sv_profile: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/bootload.rs b/rust/sbp/src/messages/bootload.rs index 918c1620cf..5f0a85003a 100644 --- a/rust/sbp/src/messages/bootload.rs +++ b/rust/sbp/src/messages/bootload.rs @@ -19,14 +19,11 @@ //! host request and the device response. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Deprecated /// @@ -41,12 +38,12 @@ pub struct MsgBootloaderHandshakeDepA { pub handshake: Vec, } -impl MsgBootloaderHandshakeDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBootloaderHandshakeDepA{ sender_id: None, - handshake: crate::parser::read_u8_array(_buf)?, + handshake: self.parse()?, } ) } } @@ -95,9 +92,9 @@ pub struct MsgBootloaderHandshakeReq { pub sender_id: Option, } -impl MsgBootloaderHandshakeReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBootloaderHandshakeReq{ sender_id: None, } ) @@ -147,16 +144,16 @@ pub struct MsgBootloaderHandshakeResp { /// Bootloader flags pub flags: u32, /// Bootloader version number - pub version: SbpString, + pub version: UnboundedSbpString, } -impl MsgBootloaderHandshakeResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBootloaderHandshakeResp{ sender_id: None, - flags: _buf.read_u32::()?, - version: crate::parser::read_string(_buf)?, + flags: self.parse()?, + version: self.parse()?, } ) } } @@ -207,12 +204,12 @@ pub struct MsgBootloaderJumpToApp { pub jump: u8, } -impl MsgBootloaderJumpToApp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBootloaderJumpToApp{ sender_id: None, - jump: _buf.read_u8()?, + jump: self.parse()?, } ) } } @@ -264,9 +261,9 @@ pub struct MsgNapDeviceDnaReq { pub sender_id: Option, } -impl MsgNapDeviceDnaReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgNapDeviceDnaReq{ sender_id: None, } ) @@ -315,15 +312,15 @@ impl crate::serialize::SbpSerialize for MsgNapDeviceDnaReq { pub struct MsgNapDeviceDnaResp { pub sender_id: Option, /// 57-bit SwiftNAP FPGA Device ID. Remaining bits are padded on the right. - pub dna: Vec, + pub dna: [u8; 8], } -impl MsgNapDeviceDnaResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgNapDeviceDnaResp{ sender_id: None, - dna: crate::parser::read_u8_array_limit(_buf, 8)?, + dna: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/ext_events.rs b/rust/sbp/src/messages/ext_events.rs index ef8d32e730..5768b7324b 100644 --- a/rust/sbp/src/messages/ext_events.rs +++ b/rust/sbp/src/messages/ext_events.rs @@ -16,14 +16,11 @@ //! e.g. camera shutter time. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Reports timestamped external pin event /// @@ -48,16 +45,16 @@ pub struct MsgExtEvent { pub pin: u8, } -impl MsgExtEvent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgExtEvent{ sender_id: None, - wn: _buf.read_u16::()?, - tow: _buf.read_u32::()?, - ns_residual: _buf.read_i32::()?, - flags: _buf.read_u8()?, - pin: _buf.read_u8()?, + wn: self.parse()?, + tow: self.parse()?, + ns_residual: self.parse()?, + flags: self.parse()?, + pin: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/file_io.rs b/rust/sbp/src/messages/file_io.rs index cae71f5cd8..32fa22c4da 100644 --- a/rust/sbp/src/messages/file_io.rs +++ b/rust/sbp/src/messages/file_io.rs @@ -22,14 +22,11 @@ //! host request and the device response. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Request advice on the optimal configuration for FileIO. /// @@ -47,12 +44,12 @@ pub struct MsgFileioConfigReq { pub sequence: u32, } -impl MsgFileioConfigReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioConfigReq{ sender_id: None, - sequence: _buf.read_u32::()?, + sequence: self.parse()?, } ) } } @@ -111,15 +108,15 @@ pub struct MsgFileioConfigResp { pub fileio_version: u32, } -impl MsgFileioConfigResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioConfigResp{ sender_id: None, - sequence: _buf.read_u32::()?, - window_size: _buf.read_u32::()?, - batch_size: _buf.read_u32::()?, - fileio_version: _buf.read_u32::()?, + sequence: self.parse()?, + window_size: self.parse()?, + batch_size: self.parse()?, + fileio_version: self.parse()?, } ) } } @@ -184,17 +181,17 @@ pub struct MsgFileioReadDirReq { /// The offset to skip the first n elements of the file list pub offset: u32, /// Name of the directory to list - pub dirname: SbpString, + pub dirname: UnboundedSbpString, } -impl MsgFileioReadDirReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioReadDirReq{ sender_id: None, - sequence: _buf.read_u32::()?, - offset: _buf.read_u32::()?, - dirname: crate::parser::read_string(_buf)?, + sequence: self.parse()?, + offset: self.parse()?, + dirname: self.parse()?, } ) } } @@ -254,13 +251,13 @@ pub struct MsgFileioReadDirResp { pub contents: Vec, } -impl MsgFileioReadDirResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioReadDirResp{ sender_id: None, - sequence: _buf.read_u32::()?, - contents: crate::parser::read_u8_array(_buf)?, + sequence: self.parse()?, + contents: self.parse()?, } ) } } @@ -321,18 +318,18 @@ pub struct MsgFileioReadReq { /// Chunk size to read pub chunk_size: u8, /// Name of the file to read from - pub filename: SbpString, + pub filename: UnboundedSbpString, } -impl MsgFileioReadReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioReadReq{ sender_id: None, - sequence: _buf.read_u32::()?, - offset: _buf.read_u32::()?, - chunk_size: _buf.read_u8()?, - filename: crate::parser::read_string(_buf)?, + sequence: self.parse()?, + offset: self.parse()?, + chunk_size: self.parse()?, + filename: self.parse()?, } ) } } @@ -393,13 +390,13 @@ pub struct MsgFileioReadResp { pub contents: Vec, } -impl MsgFileioReadResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioReadResp{ sender_id: None, - sequence: _buf.read_u32::()?, - contents: crate::parser::read_u8_array(_buf)?, + sequence: self.parse()?, + contents: self.parse()?, } ) } } @@ -450,15 +447,15 @@ impl crate::serialize::SbpSerialize for MsgFileioReadResp { pub struct MsgFileioRemove { pub sender_id: Option, /// Name of the file to delete - pub filename: SbpString, + pub filename: UnboundedSbpString, } -impl MsgFileioRemove { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioRemove{ sender_id: None, - filename: crate::parser::read_string(_buf)?, + filename: self.parse()?, } ) } } @@ -515,20 +512,20 @@ pub struct MsgFileioWriteReq { /// Offset into the file at which to start writing in bytes pub offset: u32, /// Name of the file to write to - pub filename: SbpString, + pub filename: UnboundedSbpString, /// Variable-length array of data to write pub data: Vec, } -impl MsgFileioWriteReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioWriteReq{ sender_id: None, - sequence: _buf.read_u32::()?, - offset: _buf.read_u32::()?, - filename: crate::parser::read_string(_buf)?, - data: crate::parser::read_u8_array(_buf)?, + sequence: self.parse()?, + offset: self.parse()?, + filename: self.parse()?, + data: self.parse()?, } ) } } @@ -587,12 +584,12 @@ pub struct MsgFileioWriteResp { pub sequence: u32, } -impl MsgFileioWriteResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFileioWriteResp{ sender_id: None, - sequence: _buf.read_u32::()?, + sequence: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/flash.rs b/rust/sbp/src/messages/flash.rs index df7e4bbe19..5fe72f4021 100644 --- a/rust/sbp/src/messages/flash.rs +++ b/rust/sbp/src/messages/flash.rs @@ -19,14 +19,11 @@ //! to Piksi Multi. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Flash response message (host <= device). /// @@ -44,12 +41,12 @@ pub struct MsgFlashDone { pub response: u8, } -impl MsgFlashDone { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFlashDone{ sender_id: None, - response: _buf.read_u8()?, + response: self.parse()?, } ) } } @@ -104,13 +101,13 @@ pub struct MsgFlashErase { pub sector_num: u32, } -impl MsgFlashErase { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFlashErase{ sender_id: None, - target: _buf.read_u8()?, - sector_num: _buf.read_u32::()?, + target: self.parse()?, + sector_num: self.parse()?, } ) } } @@ -165,22 +162,22 @@ pub struct MsgFlashProgram { /// Target flags pub target: u8, /// Starting address offset to program - pub addr_start: Vec, + pub addr_start: [u8; 3], /// Length of set of addresses to program, counting up from starting address pub addr_len: u8, /// Data to program addresses with, with length N=addr_len pub data: Vec, } -impl MsgFlashProgram { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFlashProgram{ sender_id: None, - target: _buf.read_u8()?, - addr_start: crate::parser::read_u8_array_limit(_buf, 3)?, - addr_len: _buf.read_u8()?, - data: crate::parser::read_u8_array(_buf)?, + target: self.parse()?, + addr_start: self.parse()?, + addr_len: self.parse()?, + data: self.parse()?, } ) } } @@ -240,19 +237,19 @@ pub struct MsgFlashReadReq { /// Target flags pub target: u8, /// Starting address offset to read from - pub addr_start: Vec, + pub addr_start: [u8; 3], /// Length of set of addresses to read, counting up from starting address pub addr_len: u8, } -impl MsgFlashReadReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFlashReadReq{ sender_id: None, - target: _buf.read_u8()?, - addr_start: crate::parser::read_u8_array_limit(_buf, 3)?, - addr_len: _buf.read_u8()?, + target: self.parse()?, + addr_start: self.parse()?, + addr_len: self.parse()?, } ) } } @@ -310,19 +307,19 @@ pub struct MsgFlashReadResp { /// Target flags pub target: u8, /// Starting address offset to read from - pub addr_start: Vec, + pub addr_start: [u8; 3], /// Length of set of addresses to read, counting up from starting address pub addr_len: u8, } -impl MsgFlashReadResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFlashReadResp{ sender_id: None, - target: _buf.read_u8()?, - addr_start: crate::parser::read_u8_array_limit(_buf, 3)?, - addr_len: _buf.read_u8()?, + target: self.parse()?, + addr_start: self.parse()?, + addr_len: self.parse()?, } ) } } @@ -373,15 +370,15 @@ impl crate::serialize::SbpSerialize for MsgFlashReadResp { pub struct MsgM25FlashWriteStatus { pub sender_id: Option, /// Byte to write to the M25 flash status register - pub status: Vec, + pub status: [u8; 1], } -impl MsgM25FlashWriteStatus { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgM25FlashWriteStatus{ sender_id: None, - status: crate::parser::read_u8_array_limit(_buf, 1)?, + status: self.parse()?, } ) } } @@ -431,12 +428,12 @@ pub struct MsgStmFlashLockSector { pub sector: u32, } -impl MsgStmFlashLockSector { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgStmFlashLockSector{ sender_id: None, - sector: _buf.read_u32::()?, + sector: self.parse()?, } ) } } @@ -486,12 +483,12 @@ pub struct MsgStmFlashUnlockSector { pub sector: u32, } -impl MsgStmFlashUnlockSector { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgStmFlashUnlockSector{ sender_id: None, - sector: _buf.read_u32::()?, + sector: self.parse()?, } ) } } @@ -542,9 +539,9 @@ pub struct MsgStmUniqueIdReq { pub sender_id: Option, } -impl MsgStmUniqueIdReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgStmUniqueIdReq{ sender_id: None, } ) @@ -592,15 +589,15 @@ impl crate::serialize::SbpSerialize for MsgStmUniqueIdReq { pub struct MsgStmUniqueIdResp { pub sender_id: Option, /// Device unique ID - pub stm_id: Vec, + pub stm_id: [u8; 12], } -impl MsgStmUniqueIdResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgStmUniqueIdResp{ sender_id: None, - stm_id: crate::parser::read_u8_array_limit(_buf, 12)?, + stm_id: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/gnss.rs b/rust/sbp/src/messages/gnss.rs index 80de4e7102..f841d8a859 100644 --- a/rust/sbp/src/messages/gnss.rs +++ b/rust/sbp/src/messages/gnss.rs @@ -14,14 +14,11 @@ //****************************************************************************/ //! Various structs shared between modules -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// GNSS carrier phase measurement. /// @@ -40,29 +37,14 @@ pub struct CarrierPhase { pub f: u8, } -impl CarrierPhase { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( CarrierPhase{ - i: _buf.read_i32::()?, - f: _buf.read_u8()?, + i: self.parse()?, + f: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(CarrierPhase::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(CarrierPhase::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for CarrierPhase { @@ -100,30 +82,15 @@ pub struct GPSTime { pub wn: u16, } -impl GPSTime { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GPSTime{ - tow: _buf.read_u32::()?, - ns_residual: _buf.read_i32::()?, - wn: _buf.read_u16::()?, + tow: self.parse()?, + ns_residual: self.parse()?, + wn: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GPSTime::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GPSTime::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GPSTime { @@ -159,29 +126,14 @@ pub struct GPSTimeDep { pub wn: u16, } -impl GPSTimeDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GPSTimeDep{ - tow: _buf.read_u32::()?, - wn: _buf.read_u16::()?, + tow: self.parse()?, + wn: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GPSTimeDep::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GPSTimeDep::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GPSTimeDep { @@ -215,29 +167,14 @@ pub struct GPSTimeSec { pub wn: u16, } -impl GPSTimeSec { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GPSTimeSec{ - tow: _buf.read_u32::()?, - wn: _buf.read_u16::()?, + tow: self.parse()?, + wn: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GPSTimeSec::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GPSTimeSec::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GPSTimeSec { @@ -270,29 +207,14 @@ pub struct GnssSignal { pub code: u8, } -impl GnssSignal { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GnssSignal{ - sat: _buf.read_u8()?, - code: _buf.read_u8()?, + sat: self.parse()?, + code: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GnssSignal::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GnssSignal::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GnssSignal { @@ -328,33 +250,15 @@ pub struct GnssSignalDep { pub reserved: u8, } -impl GnssSignalDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GnssSignalDep{ - sat: _buf.read_u16::()?, - code: _buf.read_u8()?, - reserved: _buf.read_u8()?, + sat: self.parse()?, + code: self.parse()?, + reserved: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GnssSignalDep::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GnssSignalDep::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GnssSignalDep { @@ -389,29 +293,14 @@ pub struct SvId { pub constellation: u8, } -impl SvId { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( SvId{ - satId: _buf.read_u8()?, - constellation: _buf.read_u8()?, + satId: self.parse()?, + constellation: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(SvId::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(SvId::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for SvId { diff --git a/rust/sbp/src/messages/imu.rs b/rust/sbp/src/messages/imu.rs index b3f5f8882f..ac3e5cd221 100644 --- a/rust/sbp/src/messages/imu.rs +++ b/rust/sbp/src/messages/imu.rs @@ -14,14 +14,11 @@ //****************************************************************************/ //! Inertial Measurement Unit (IMU) messages. -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Auxiliary IMU data /// @@ -42,14 +39,14 @@ pub struct MsgImuAux { pub imu_conf: u8, } -impl MsgImuAux { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgImuAux{ sender_id: None, - imu_type: _buf.read_u8()?, - temp: _buf.read_i16::()?, - imu_conf: _buf.read_u8()?, + imu_type: self.parse()?, + temp: self.parse()?, + imu_conf: self.parse()?, } ) } } @@ -124,19 +121,19 @@ pub struct MsgImuRaw { pub gyr_z: i16, } -impl MsgImuRaw { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgImuRaw{ sender_id: None, - tow: _buf.read_u32::()?, - tow_f: _buf.read_u8()?, - acc_x: _buf.read_i16::()?, - acc_y: _buf.read_i16::()?, - acc_z: _buf.read_i16::()?, - gyr_x: _buf.read_i16::()?, - gyr_y: _buf.read_i16::()?, - gyr_z: _buf.read_i16::()?, + tow: self.parse()?, + tow_f: self.parse()?, + acc_x: self.parse()?, + acc_y: self.parse()?, + acc_z: self.parse()?, + gyr_x: self.parse()?, + gyr_y: self.parse()?, + gyr_z: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/linux.rs b/rust/sbp/src/messages/linux.rs index d7b9d6dd22..2400467677 100644 --- a/rust/sbp/src/messages/linux.rs +++ b/rust/sbp/src/messages/linux.rs @@ -15,14 +15,11 @@ //! Linux state monitoring. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// List CPU state on the system /// @@ -41,21 +38,21 @@ pub struct MsgLinuxCpuState { /// percent of cpu used, expressed as a fraction of 256 pub pcpu: u8, /// fixed length string representing the thread name - pub tname: SbpString, + pub tname: BoundedSbpString<15>, /// the command line (as much as it fits in the remaining packet) - pub cmdline: SbpString, + pub cmdline: UnboundedSbpString, } -impl MsgLinuxCpuState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxCpuState{ sender_id: None, - index: _buf.read_u8()?, - pid: _buf.read_u16::()?, - pcpu: _buf.read_u8()?, - tname: crate::parser::read_string_limit(_buf, 15)?, - cmdline: crate::parser::read_string(_buf)?, + index: self.parse()?, + pid: self.parse()?, + pcpu: self.parse()?, + tname: self.parse()?, + cmdline: self.parse()?, } ) } } @@ -116,21 +113,21 @@ pub struct MsgLinuxMemState { /// percent of memory used, expressed as a fraction of 256 pub pmem: u8, /// fixed length string representing the thread name - pub tname: SbpString, + pub tname: BoundedSbpString<15>, /// the command line (as much as it fits in the remaining packet) - pub cmdline: SbpString, + pub cmdline: UnboundedSbpString, } -impl MsgLinuxMemState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxMemState{ sender_id: None, - index: _buf.read_u8()?, - pid: _buf.read_u16::()?, - pmem: _buf.read_u8()?, - tname: crate::parser::read_string_limit(_buf, 15)?, - cmdline: crate::parser::read_string(_buf)?, + index: self.parse()?, + pid: self.parse()?, + pmem: self.parse()?, + tname: self.parse()?, + cmdline: self.parse()?, } ) } } @@ -190,18 +187,18 @@ pub struct MsgLinuxProcessFdCount { /// a count of the number of file descriptors opened by the process pub fd_count: u16, /// the command line of the process in question - pub cmdline: SbpString, + pub cmdline: UnboundedSbpString, } -impl MsgLinuxProcessFdCount { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxProcessFdCount{ sender_id: None, - index: _buf.read_u8()?, - pid: _buf.read_u16::()?, - fd_count: _buf.read_u16::()?, - cmdline: crate::parser::read_string(_buf)?, + index: self.parse()?, + pid: self.parse()?, + fd_count: self.parse()?, + cmdline: self.parse()?, } ) } } @@ -259,16 +256,16 @@ pub struct MsgLinuxProcessFdSummary { /// being reported. That is, in C string syntax /// "32\0/var/log/syslog\012\0/tmp/foo\0" with the end of the list being 2 /// NULL terminators in a row. - pub most_opened: SbpString, + pub most_opened: UnboundedSbpString, } -impl MsgLinuxProcessFdSummary { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxProcessFdSummary{ sender_id: None, - sys_fd_count: _buf.read_u32::()?, - most_opened: crate::parser::read_string(_buf)?, + sys_fd_count: self.parse()?, + most_opened: self.parse()?, } ) } } @@ -330,20 +327,20 @@ pub struct MsgLinuxProcessSocketCounts { /// (listen), 0x400 (closing), 0x800 (unconnected), and 0x8000 (unknown) pub socket_states: u16, /// the command line of the process in question - pub cmdline: SbpString, + pub cmdline: UnboundedSbpString, } -impl MsgLinuxProcessSocketCounts { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxProcessSocketCounts{ sender_id: None, - index: _buf.read_u8()?, - pid: _buf.read_u16::()?, - socket_count: _buf.read_u16::()?, - socket_types: _buf.read_u16::()?, - socket_states: _buf.read_u16::()?, - cmdline: crate::parser::read_string(_buf)?, + index: self.parse()?, + pid: self.parse()?, + socket_count: self.parse()?, + socket_types: self.parse()?, + socket_states: self.parse()?, + cmdline: self.parse()?, } ) } } @@ -416,24 +413,24 @@ pub struct MsgLinuxProcessSocketQueues { pub socket_states: u16, /// Address of the largest queue, remote or local depending on the /// directionality of the connection. - pub address_of_largest: SbpString, + pub address_of_largest: BoundedSbpString<64>, /// the command line of the process in question - pub cmdline: SbpString, + pub cmdline: UnboundedSbpString, } -impl MsgLinuxProcessSocketQueues { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxProcessSocketQueues{ sender_id: None, - index: _buf.read_u8()?, - pid: _buf.read_u16::()?, - recv_queued: _buf.read_u16::()?, - send_queued: _buf.read_u16::()?, - socket_types: _buf.read_u16::()?, - socket_states: _buf.read_u16::()?, - address_of_largest: crate::parser::read_string_limit(_buf, 64)?, - cmdline: crate::parser::read_string(_buf)?, + index: self.parse()?, + pid: self.parse()?, + recv_queued: self.parse()?, + send_queued: self.parse()?, + socket_types: self.parse()?, + socket_states: self.parse()?, + address_of_largest: self.parse()?, + cmdline: self.parse()?, } ) } } @@ -499,22 +496,22 @@ pub struct MsgLinuxSocketUsage { /// A count for each socket type reported in the `socket_types_reported` /// field, the first entry corresponds to the first enabled bit in /// `types_reported`. - pub socket_state_counts: Vec, + pub socket_state_counts: [u16; 16], /// A count for each socket type reported in the `socket_types_reported` /// field, the first entry corresponds to the first enabled bit in /// `types_reported`. - pub socket_type_counts: Vec, + pub socket_type_counts: [u16; 16], } -impl MsgLinuxSocketUsage { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxSocketUsage{ sender_id: None, - avg_queue_depth: _buf.read_u32::()?, - max_queue_depth: _buf.read_u32::()?, - socket_state_counts: crate::parser::read_u16_array_limit(_buf, 16)?, - socket_type_counts: crate::parser::read_u16_array_limit(_buf, 16)?, + avg_queue_depth: self.parse()?, + max_queue_depth: self.parse()?, + socket_state_counts: self.parse()?, + socket_type_counts: self.parse()?, } ) } } @@ -579,17 +576,17 @@ pub struct MsgLinuxSysState { pub pid_count: u16, } -impl MsgLinuxSysState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLinuxSysState{ sender_id: None, - mem_total: _buf.read_u16::()?, - pcpu: _buf.read_u8()?, - pmem: _buf.read_u8()?, - procs_starting: _buf.read_u16::()?, - procs_stopping: _buf.read_u16::()?, - pid_count: _buf.read_u16::()?, + mem_total: self.parse()?, + pcpu: self.parse()?, + pmem: self.parse()?, + procs_starting: self.parse()?, + procs_stopping: self.parse()?, + pid_count: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/logging.rs b/rust/sbp/src/messages/logging.rs index 7d4c29f852..47e293719c 100644 --- a/rust/sbp/src/messages/logging.rs +++ b/rust/sbp/src/messages/logging.rs @@ -15,14 +15,11 @@ //! Logging and debugging messages from the device. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Wrapper for FWD a separate stream of information over SBP /// @@ -44,17 +41,17 @@ pub struct MsgFwd { /// protocol identifier pub protocol: u8, /// variable length wrapped binary message - pub fwd_payload: SbpString, + pub fwd_payload: UnboundedSbpString, } -impl MsgFwd { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFwd{ sender_id: None, - source: _buf.read_u8()?, - protocol: _buf.read_u8()?, - fwd_payload: crate::parser::read_string(_buf)?, + source: self.parse()?, + protocol: self.parse()?, + fwd_payload: self.parse()?, } ) } } @@ -108,16 +105,16 @@ pub struct MsgLog { /// Logging level pub level: u8, /// Human-readable string - pub text: SbpString, + pub text: UnboundedSbpString, } -impl MsgLog { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgLog{ sender_id: None, - level: _buf.read_u8()?, - text: crate::parser::read_string(_buf)?, + level: self.parse()?, + text: self.parse()?, } ) } } @@ -165,15 +162,15 @@ impl crate::serialize::SbpSerialize for MsgLog { pub struct MsgPrintDep { pub sender_id: Option, /// Human-readable string - pub text: SbpString, + pub text: UnboundedSbpString, } -impl MsgPrintDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPrintDep{ sender_id: None, - text: crate::parser::read_string(_buf)?, + text: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/mag.rs b/rust/sbp/src/messages/mag.rs index b27a4812df..632242cb0c 100644 --- a/rust/sbp/src/messages/mag.rs +++ b/rust/sbp/src/messages/mag.rs @@ -14,14 +14,11 @@ //****************************************************************************/ //! Magnetometer (mag) messages. -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Raw magnetometer data /// @@ -45,16 +42,16 @@ pub struct MsgMagRaw { pub mag_z: i16, } -impl MsgMagRaw { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgMagRaw{ sender_id: None, - tow: _buf.read_u32::()?, - tow_f: _buf.read_u8()?, - mag_x: _buf.read_i16::()?, - mag_y: _buf.read_i16::()?, - mag_z: _buf.read_i16::()?, + tow: self.parse()?, + tow_f: self.parse()?, + mag_x: self.parse()?, + mag_y: self.parse()?, + mag_z: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/mod.rs b/rust/sbp/src/messages/mod.rs index eaeb44b2d5..0fd67c4668 100644 --- a/rust/sbp/src/messages/mod.rs +++ b/rust/sbp/src/messages/mod.rs @@ -228,6 +228,7 @@ use self::vehicle::MsgOdometry; use self::vehicle::MsgWheeltick; use crate::framer::FramerError; +use crate::parser::SbpParse; use crate::serialize::SbpSerialize; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; @@ -443,972 +444,972 @@ impl SBP { pub fn parse(msg_id: u16, sender_id: u16, payload: &mut &[u8]) -> Result { let x: Result = match msg_id { 16 => { - let mut msg = MsgPrintDep::parse(payload)?; + let mut msg: MsgPrintDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPrintDep(msg)) } 17 => { - let mut msg = MsgTrackingStateDetailedDep::parse(payload)?; + let mut msg: MsgTrackingStateDetailedDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingStateDetailedDep(msg)) } 19 => { - let mut msg = MsgTrackingStateDepB::parse(payload)?; + let mut msg: MsgTrackingStateDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingStateDepB(msg)) } 20 => { - let mut msg = MsgAcqResultDepB::parse(payload)?; + let mut msg: MsgAcqResultDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAcqResultDepB(msg)) } 21 => { - let mut msg = MsgAcqResultDepA::parse(payload)?; + let mut msg: MsgAcqResultDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAcqResultDepA(msg)) } 22 => { - let mut msg = MsgTrackingStateDepA::parse(payload)?; + let mut msg: MsgTrackingStateDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingStateDepA(msg)) } 23 => { - let mut msg = MsgThreadState::parse(payload)?; + let mut msg: MsgThreadState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgThreadState(msg)) } 24 => { - let mut msg = MsgUartStateDepa::parse(payload)?; + let mut msg: MsgUartStateDepa = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgUartStateDepa(msg)) } 25 => { - let mut msg = MsgIarState::parse(payload)?; + let mut msg: MsgIarState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgIarState(msg)) } 26 => { - let mut msg = MsgEphemerisDepA::parse(payload)?; + let mut msg: MsgEphemerisDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisDepA(msg)) } 27 => { - let mut msg = MsgMaskSatelliteDep::parse(payload)?; + let mut msg: MsgMaskSatelliteDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgMaskSatelliteDep(msg)) } 28 => { - let mut msg = MsgTrackingIqDepA::parse(payload)?; + let mut msg: MsgTrackingIqDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingIqDepA(msg)) } 29 => { - let mut msg = MsgUartState::parse(payload)?; + let mut msg: MsgUartState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgUartState(msg)) } 30 => { - let mut msg = MsgAcqSvProfileDep::parse(payload)?; + let mut msg: MsgAcqSvProfileDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAcqSvProfileDep(msg)) } 31 => { - let mut msg = MsgAcqResultDepC::parse(payload)?; + let mut msg: MsgAcqResultDepC = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAcqResultDepC(msg)) } 33 => { - let mut msg = MsgTrackingStateDetailedDepA::parse(payload)?; + let mut msg: MsgTrackingStateDetailedDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingStateDetailedDepA(msg)) } 34 => { - let mut msg = MsgResetFilters::parse(payload)?; + let mut msg: MsgResetFilters = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgResetFilters(msg)) } 35 => { - let mut msg = MsgInitBaseDep::parse(payload)?; + let mut msg: MsgInitBaseDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgInitBaseDep(msg)) } 43 => { - let mut msg = MsgMaskSatellite::parse(payload)?; + let mut msg: MsgMaskSatellite = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgMaskSatellite(msg)) } 44 => { - let mut msg = MsgTrackingIqDepB::parse(payload)?; + let mut msg: MsgTrackingIqDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingIqDepB(msg)) } 45 => { - let mut msg = MsgTrackingIq::parse(payload)?; + let mut msg: MsgTrackingIq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingIq(msg)) } 46 => { - let mut msg = MsgAcqSvProfile::parse(payload)?; + let mut msg: MsgAcqSvProfile = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAcqSvProfile(msg)) } 47 => { - let mut msg = MsgAcqResult::parse(payload)?; + let mut msg: MsgAcqResult = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAcqResult(msg)) } 65 => { - let mut msg = MsgTrackingState::parse(payload)?; + let mut msg: MsgTrackingState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgTrackingState(msg)) } 67 => { - let mut msg = MsgObsDepB::parse(payload)?; + let mut msg: MsgObsDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgObsDepB(msg)) } 68 => { - let mut msg = MsgBasePosLLH::parse(payload)?; + let mut msg: MsgBasePosLLH = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBasePosLLH(msg)) } 69 => { - let mut msg = MsgObsDepA::parse(payload)?; + let mut msg: MsgObsDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgObsDepA(msg)) } 70 => { - let mut msg = MsgEphemerisDepB::parse(payload)?; + let mut msg: MsgEphemerisDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisDepB(msg)) } 71 => { - let mut msg = MsgEphemerisDepC::parse(payload)?; + let mut msg: MsgEphemerisDepC = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisDepC(msg)) } 72 => { - let mut msg = MsgBasePosECEF::parse(payload)?; + let mut msg: MsgBasePosECEF = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBasePosECEF(msg)) } 73 => { - let mut msg = MsgObsDepC::parse(payload)?; + let mut msg: MsgObsDepC = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgObsDepC(msg)) } 74 => { - let mut msg = MsgObs::parse(payload)?; + let mut msg: MsgObs = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgObs(msg)) } 80 => { - let mut msg = MsgSpecanDep::parse(payload)?; + let mut msg: MsgSpecanDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSpecanDep(msg)) } 81 => { - let mut msg = MsgSpecan::parse(payload)?; + let mut msg: MsgSpecan = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSpecan(msg)) } 97 => { - let mut msg = MsgMeasurementState::parse(payload)?; + let mut msg: MsgMeasurementState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgMeasurementState(msg)) } 104 => { - let mut msg = MsgSetTime::parse(payload)?; + let mut msg: MsgSetTime = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSetTime(msg)) } 105 => { - let mut msg = MsgAlmanac::parse(payload)?; + let mut msg: MsgAlmanac = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAlmanac(msg)) } 112 => { - let mut msg = MsgAlmanacGPSDep::parse(payload)?; + let mut msg: MsgAlmanacGPSDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAlmanacGPSDep(msg)) } 113 => { - let mut msg = MsgAlmanacGloDep::parse(payload)?; + let mut msg: MsgAlmanacGloDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAlmanacGloDep(msg)) } 114 => { - let mut msg = MsgAlmanacGPS::parse(payload)?; + let mut msg: MsgAlmanacGPS = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAlmanacGPS(msg)) } 115 => { - let mut msg = MsgAlmanacGlo::parse(payload)?; + let mut msg: MsgAlmanacGlo = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAlmanacGlo(msg)) } 117 => { - let mut msg = MsgGloBiases::parse(payload)?; + let mut msg: MsgGloBiases = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGloBiases(msg)) } 128 => { - let mut msg = MsgEphemerisDepD::parse(payload)?; + let mut msg: MsgEphemerisDepD = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisDepD(msg)) } 129 => { - let mut msg = MsgEphemerisGPSDepE::parse(payload)?; + let mut msg: MsgEphemerisGPSDepE = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGPSDepE(msg)) } 130 => { - let mut msg = MsgEphemerisSbasDepA::parse(payload)?; + let mut msg: MsgEphemerisSbasDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisSbasDepA(msg)) } 131 => { - let mut msg = MsgEphemerisGloDepA::parse(payload)?; + let mut msg: MsgEphemerisGloDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGloDepA(msg)) } 132 => { - let mut msg = MsgEphemerisSbasDepB::parse(payload)?; + let mut msg: MsgEphemerisSbasDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisSbasDepB(msg)) } 133 => { - let mut msg = MsgEphemerisGloDepB::parse(payload)?; + let mut msg: MsgEphemerisGloDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGloDepB(msg)) } 134 => { - let mut msg = MsgEphemerisGPSDepF::parse(payload)?; + let mut msg: MsgEphemerisGPSDepF = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGPSDepF(msg)) } 135 => { - let mut msg = MsgEphemerisGloDepC::parse(payload)?; + let mut msg: MsgEphemerisGloDepC = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGloDepC(msg)) } 136 => { - let mut msg = MsgEphemerisGloDepD::parse(payload)?; + let mut msg: MsgEphemerisGloDepD = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGloDepD(msg)) } 137 => { - let mut msg = MsgEphemerisBds::parse(payload)?; + let mut msg: MsgEphemerisBds = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisBds(msg)) } 138 => { - let mut msg = MsgEphemerisGPS::parse(payload)?; + let mut msg: MsgEphemerisGPS = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGPS(msg)) } 139 => { - let mut msg = MsgEphemerisGlo::parse(payload)?; + let mut msg: MsgEphemerisGlo = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGlo(msg)) } 140 => { - let mut msg = MsgEphemerisSbas::parse(payload)?; + let mut msg: MsgEphemerisSbas = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisSbas(msg)) } 141 => { - let mut msg = MsgEphemerisGal::parse(payload)?; + let mut msg: MsgEphemerisGal = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGal(msg)) } 142 => { - let mut msg = MsgEphemerisQzss::parse(payload)?; + let mut msg: MsgEphemerisQzss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisQzss(msg)) } 144 => { - let mut msg = MsgIono::parse(payload)?; + let mut msg: MsgIono = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgIono(msg)) } 145 => { - let mut msg = MsgSvConfigurationGPSDep::parse(payload)?; + let mut msg: MsgSvConfigurationGPSDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSvConfigurationGPSDep(msg)) } 146 => { - let mut msg = MsgGroupDelayDepA::parse(payload)?; + let mut msg: MsgGroupDelayDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGroupDelayDepA(msg)) } 147 => { - let mut msg = MsgGroupDelayDepB::parse(payload)?; + let mut msg: MsgGroupDelayDepB = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGroupDelayDepB(msg)) } 148 => { - let mut msg = MsgGroupDelay::parse(payload)?; + let mut msg: MsgGroupDelay = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGroupDelay(msg)) } 149 => { - let mut msg = MsgEphemerisGalDepA::parse(payload)?; + let mut msg: MsgEphemerisGalDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgEphemerisGalDepA(msg)) } 150 => { - let mut msg = MsgGnssCapb::parse(payload)?; + let mut msg: MsgGnssCapb = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGnssCapb(msg)) } 151 => { - let mut msg = MsgSvAzEl::parse(payload)?; + let mut msg: MsgSvAzEl = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSvAzEl(msg)) } 160 => { - let mut msg = MsgSettingsWrite::parse(payload)?; + let mut msg: MsgSettingsWrite = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsWrite(msg)) } 161 => { - let mut msg = MsgSettingsSave::parse(payload)?; + let mut msg: MsgSettingsSave = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsSave(msg)) } 162 => { - let mut msg = MsgSettingsReadByIndexReq::parse(payload)?; + let mut msg: MsgSettingsReadByIndexReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsReadByIndexReq(msg)) } 163 => { - let mut msg = MsgFileioReadResp::parse(payload)?; + let mut msg: MsgFileioReadResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioReadResp(msg)) } 164 => { - let mut msg = MsgSettingsReadReq::parse(payload)?; + let mut msg: MsgSettingsReadReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsReadReq(msg)) } 165 => { - let mut msg = MsgSettingsReadResp::parse(payload)?; + let mut msg: MsgSettingsReadResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsReadResp(msg)) } 166 => { - let mut msg = MsgSettingsReadByIndexDone::parse(payload)?; + let mut msg: MsgSettingsReadByIndexDone = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsReadByIndexDone(msg)) } 167 => { - let mut msg = MsgSettingsReadByIndexResp::parse(payload)?; + let mut msg: MsgSettingsReadByIndexResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsReadByIndexResp(msg)) } 168 => { - let mut msg = MsgFileioReadReq::parse(payload)?; + let mut msg: MsgFileioReadReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioReadReq(msg)) } 169 => { - let mut msg = MsgFileioReadDirReq::parse(payload)?; + let mut msg: MsgFileioReadDirReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioReadDirReq(msg)) } 170 => { - let mut msg = MsgFileioReadDirResp::parse(payload)?; + let mut msg: MsgFileioReadDirResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioReadDirResp(msg)) } 171 => { - let mut msg = MsgFileioWriteResp::parse(payload)?; + let mut msg: MsgFileioWriteResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioWriteResp(msg)) } 172 => { - let mut msg = MsgFileioRemove::parse(payload)?; + let mut msg: MsgFileioRemove = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioRemove(msg)) } 173 => { - let mut msg = MsgFileioWriteReq::parse(payload)?; + let mut msg: MsgFileioWriteReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioWriteReq(msg)) } 174 => { - let mut msg = MsgSettingsRegister::parse(payload)?; + let mut msg: MsgSettingsRegister = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsRegister(msg)) } 175 => { - let mut msg = MsgSettingsWriteResp::parse(payload)?; + let mut msg: MsgSettingsWriteResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsWriteResp(msg)) } 176 => { - let mut msg = MsgBootloaderHandshakeDepA::parse(payload)?; + let mut msg: MsgBootloaderHandshakeDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBootloaderHandshakeDepA(msg)) } 177 => { - let mut msg = MsgBootloaderJumpToApp::parse(payload)?; + let mut msg: MsgBootloaderJumpToApp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBootloaderJumpToApp(msg)) } 178 => { - let mut msg = MsgResetDep::parse(payload)?; + let mut msg: MsgResetDep = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgResetDep(msg)) } 179 => { - let mut msg = MsgBootloaderHandshakeReq::parse(payload)?; + let mut msg: MsgBootloaderHandshakeReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBootloaderHandshakeReq(msg)) } 180 => { - let mut msg = MsgBootloaderHandshakeResp::parse(payload)?; + let mut msg: MsgBootloaderHandshakeResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBootloaderHandshakeResp(msg)) } 181 => { - let mut msg = MsgDeviceMonitor::parse(payload)?; + let mut msg: MsgDeviceMonitor = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgDeviceMonitor(msg)) } 182 => { - let mut msg = MsgReset::parse(payload)?; + let mut msg: MsgReset = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgReset(msg)) } 184 => { - let mut msg = MsgCommandReq::parse(payload)?; + let mut msg: MsgCommandReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCommandReq(msg)) } 185 => { - let mut msg = MsgCommandResp::parse(payload)?; + let mut msg: MsgCommandResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCommandResp(msg)) } 186 => { - let mut msg = MsgNetworkStateReq::parse(payload)?; + let mut msg: MsgNetworkStateReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgNetworkStateReq(msg)) } 187 => { - let mut msg = MsgNetworkStateResp::parse(payload)?; + let mut msg: MsgNetworkStateResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgNetworkStateResp(msg)) } 188 => { - let mut msg = MsgCommandOutput::parse(payload)?; + let mut msg: MsgCommandOutput = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCommandOutput(msg)) } 189 => { - let mut msg = MsgNetworkBandwidthUsage::parse(payload)?; + let mut msg: MsgNetworkBandwidthUsage = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgNetworkBandwidthUsage(msg)) } 190 => { - let mut msg = MsgCellModemStatus::parse(payload)?; + let mut msg: MsgCellModemStatus = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCellModemStatus(msg)) } 191 => { - let mut msg = MsgFrontEndGain::parse(payload)?; + let mut msg: MsgFrontEndGain = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFrontEndGain(msg)) } 192 => { - let mut msg = MsgCwResults::parse(payload)?; + let mut msg: MsgCwResults = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCwResults(msg)) } 193 => { - let mut msg = MsgCwStart::parse(payload)?; + let mut msg: MsgCwStart = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCwStart(msg)) } 221 => { - let mut msg = MsgNapDeviceDnaResp::parse(payload)?; + let mut msg: MsgNapDeviceDnaResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgNapDeviceDnaResp(msg)) } 222 => { - let mut msg = MsgNapDeviceDnaReq::parse(payload)?; + let mut msg: MsgNapDeviceDnaReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgNapDeviceDnaReq(msg)) } 224 => { - let mut msg = MsgFlashDone::parse(payload)?; + let mut msg: MsgFlashDone = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFlashDone(msg)) } 225 => { - let mut msg = MsgFlashReadResp::parse(payload)?; + let mut msg: MsgFlashReadResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFlashReadResp(msg)) } 226 => { - let mut msg = MsgFlashErase::parse(payload)?; + let mut msg: MsgFlashErase = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFlashErase(msg)) } 227 => { - let mut msg = MsgStmFlashLockSector::parse(payload)?; + let mut msg: MsgStmFlashLockSector = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgStmFlashLockSector(msg)) } 228 => { - let mut msg = MsgStmFlashUnlockSector::parse(payload)?; + let mut msg: MsgStmFlashUnlockSector = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgStmFlashUnlockSector(msg)) } 229 => { - let mut msg = MsgStmUniqueIdResp::parse(payload)?; + let mut msg: MsgStmUniqueIdResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgStmUniqueIdResp(msg)) } 230 => { - let mut msg = MsgFlashProgram::parse(payload)?; + let mut msg: MsgFlashProgram = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFlashProgram(msg)) } 231 => { - let mut msg = MsgFlashReadReq::parse(payload)?; + let mut msg: MsgFlashReadReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFlashReadReq(msg)) } 232 => { - let mut msg = MsgStmUniqueIdReq::parse(payload)?; + let mut msg: MsgStmUniqueIdReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgStmUniqueIdReq(msg)) } 243 => { - let mut msg = MsgM25FlashWriteStatus::parse(payload)?; + let mut msg: MsgM25FlashWriteStatus = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgM25FlashWriteStatus(msg)) } 256 => { - let mut msg = MsgGPSTimeDepA::parse(payload)?; + let mut msg: MsgGPSTimeDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGPSTimeDepA(msg)) } 257 => { - let mut msg = MsgExtEvent::parse(payload)?; + let mut msg: MsgExtEvent = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgExtEvent(msg)) } 258 => { - let mut msg = MsgGPSTime::parse(payload)?; + let mut msg: MsgGPSTime = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGPSTime(msg)) } 259 => { - let mut msg = MsgUtcTime::parse(payload)?; + let mut msg: MsgUtcTime = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgUtcTime(msg)) } 260 => { - let mut msg = MsgGPSTimeGnss::parse(payload)?; + let mut msg: MsgGPSTimeGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGPSTimeGnss(msg)) } 261 => { - let mut msg = MsgUtcTimeGnss::parse(payload)?; + let mut msg: MsgUtcTimeGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgUtcTimeGnss(msg)) } 431 => { - let mut msg = MsgSettingsRegisterResp::parse(payload)?; + let mut msg: MsgSettingsRegisterResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSettingsRegisterResp(msg)) } 512 => { - let mut msg = MsgPosECEFDepA::parse(payload)?; + let mut msg: MsgPosECEFDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosECEFDepA(msg)) } 513 => { - let mut msg = MsgPosLLHDepA::parse(payload)?; + let mut msg: MsgPosLLHDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosLLHDepA(msg)) } 514 => { - let mut msg = MsgBaselineECEFDepA::parse(payload)?; + let mut msg: MsgBaselineECEFDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBaselineECEFDepA(msg)) } 515 => { - let mut msg = MsgBaselineNEDDepA::parse(payload)?; + let mut msg: MsgBaselineNEDDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBaselineNEDDepA(msg)) } 516 => { - let mut msg = MsgVelECEFDepA::parse(payload)?; + let mut msg: MsgVelECEFDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelECEFDepA(msg)) } 517 => { - let mut msg = MsgVelNEDDepA::parse(payload)?; + let mut msg: MsgVelNEDDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelNEDDepA(msg)) } 518 => { - let mut msg = MsgDopsDepA::parse(payload)?; + let mut msg: MsgDopsDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgDopsDepA(msg)) } 519 => { - let mut msg = MsgBaselineHeadingDepA::parse(payload)?; + let mut msg: MsgBaselineHeadingDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBaselineHeadingDepA(msg)) } 520 => { - let mut msg = MsgDops::parse(payload)?; + let mut msg: MsgDops = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgDops(msg)) } 521 => { - let mut msg = MsgPosECEF::parse(payload)?; + let mut msg: MsgPosECEF = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosECEF(msg)) } 522 => { - let mut msg = MsgPosLLH::parse(payload)?; + let mut msg: MsgPosLLH = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosLLH(msg)) } 523 => { - let mut msg = MsgBaselineECEF::parse(payload)?; + let mut msg: MsgBaselineECEF = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBaselineECEF(msg)) } 524 => { - let mut msg = MsgBaselineNED::parse(payload)?; + let mut msg: MsgBaselineNED = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBaselineNED(msg)) } 525 => { - let mut msg = MsgVelECEF::parse(payload)?; + let mut msg: MsgVelECEF = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelECEF(msg)) } 526 => { - let mut msg = MsgVelNED::parse(payload)?; + let mut msg: MsgVelNED = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelNED(msg)) } 527 => { - let mut msg = MsgBaselineHeading::parse(payload)?; + let mut msg: MsgBaselineHeading = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgBaselineHeading(msg)) } 528 => { - let mut msg = MsgAgeCorrections::parse(payload)?; + let mut msg: MsgAgeCorrections = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAgeCorrections(msg)) } 529 => { - let mut msg = MsgPosLLHCov::parse(payload)?; + let mut msg: MsgPosLLHCov = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosLLHCov(msg)) } 530 => { - let mut msg = MsgVelNEDCov::parse(payload)?; + let mut msg: MsgVelNEDCov = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelNEDCov(msg)) } 531 => { - let mut msg = MsgVelBody::parse(payload)?; + let mut msg: MsgVelBody = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelBody(msg)) } 532 => { - let mut msg = MsgPosECEFCov::parse(payload)?; + let mut msg: MsgPosECEFCov = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosECEFCov(msg)) } 533 => { - let mut msg = MsgVelECEFCov::parse(payload)?; + let mut msg: MsgVelECEFCov = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelECEFCov(msg)) } 534 => { - let mut msg = MsgProtectionLevel::parse(payload)?; + let mut msg: MsgProtectionLevel = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgProtectionLevel(msg)) } 544 => { - let mut msg = MsgOrientQuat::parse(payload)?; + let mut msg: MsgOrientQuat = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgOrientQuat(msg)) } 545 => { - let mut msg = MsgOrientEuler::parse(payload)?; + let mut msg: MsgOrientEuler = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgOrientEuler(msg)) } 546 => { - let mut msg = MsgAngularRate::parse(payload)?; + let mut msg: MsgAngularRate = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgAngularRate(msg)) } 553 => { - let mut msg = MsgPosECEFGnss::parse(payload)?; + let mut msg: MsgPosECEFGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosECEFGnss(msg)) } 554 => { - let mut msg = MsgPosLLHGnss::parse(payload)?; + let mut msg: MsgPosLLHGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosLLHGnss(msg)) } 557 => { - let mut msg = MsgVelECEFGnss::parse(payload)?; + let mut msg: MsgVelECEFGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelECEFGnss(msg)) } 558 => { - let mut msg = MsgVelNEDGnss::parse(payload)?; + let mut msg: MsgVelNEDGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelNEDGnss(msg)) } 561 => { - let mut msg = MsgPosLLHCovGnss::parse(payload)?; + let mut msg: MsgPosLLHCovGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosLLHCovGnss(msg)) } 562 => { - let mut msg = MsgVelNEDCovGnss::parse(payload)?; + let mut msg: MsgVelNEDCovGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelNEDCovGnss(msg)) } 564 => { - let mut msg = MsgPosECEFCovGnss::parse(payload)?; + let mut msg: MsgPosECEFCovGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgPosECEFCovGnss(msg)) } 565 => { - let mut msg = MsgVelECEFCovGnss::parse(payload)?; + let mut msg: MsgVelECEFCovGnss = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgVelECEFCovGnss(msg)) } 1024 => { - let mut msg = MsgNdbEvent::parse(payload)?; + let mut msg: MsgNdbEvent = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgNdbEvent(msg)) } 1025 => { - let mut msg = MsgLog::parse(payload)?; + let mut msg: MsgLog = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLog(msg)) } 1026 => { - let mut msg = MsgFwd::parse(payload)?; + let mut msg: MsgFwd = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFwd(msg)) } 1500 => { - let mut msg = MsgSsrOrbitClockDepA::parse(payload)?; + let mut msg: MsgSsrOrbitClockDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrOrbitClockDepA(msg)) } 1501 => { - let mut msg = MsgSsrOrbitClock::parse(payload)?; + let mut msg: MsgSsrOrbitClock = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrOrbitClock(msg)) } 1505 => { - let mut msg = MsgSsrCodeBiases::parse(payload)?; + let mut msg: MsgSsrCodeBiases = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrCodeBiases(msg)) } 1510 => { - let mut msg = MsgSsrPhaseBiases::parse(payload)?; + let mut msg: MsgSsrPhaseBiases = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrPhaseBiases(msg)) } 1515 => { - let mut msg = MsgSsrStecCorrectionDepA::parse(payload)?; + let mut msg: MsgSsrStecCorrectionDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrStecCorrectionDepA(msg)) } 1520 => { - let mut msg = MsgSsrGriddedCorrectionNoStdDepA::parse(payload)?; + let mut msg: MsgSsrGriddedCorrectionNoStdDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrGriddedCorrectionNoStdDepA(msg)) } 1525 => { - let mut msg = MsgSsrGridDefinitionDepA::parse(payload)?; + let mut msg: MsgSsrGridDefinitionDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrGridDefinitionDepA(msg)) } 1526 => { - let mut msg = MsgSsrTileDefinition::parse(payload)?; + let mut msg: MsgSsrTileDefinition = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrTileDefinition(msg)) } 1530 => { - let mut msg = MsgSsrGriddedCorrectionDepA::parse(payload)?; + let mut msg: MsgSsrGriddedCorrectionDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrGriddedCorrectionDepA(msg)) } 1531 => { - let mut msg = MsgSsrStecCorrection::parse(payload)?; + let mut msg: MsgSsrStecCorrection = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrStecCorrection(msg)) } 1532 => { - let mut msg = MsgSsrGriddedCorrection::parse(payload)?; + let mut msg: MsgSsrGriddedCorrection = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSsrGriddedCorrection(msg)) } 1600 => { - let mut msg = MsgOsr::parse(payload)?; + let mut msg: MsgOsr = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgOsr(msg)) } 2048 => { - let mut msg = MsgUserData::parse(payload)?; + let mut msg: MsgUserData = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgUserData(msg)) } 2304 => { - let mut msg = MsgImuRaw::parse(payload)?; + let mut msg: MsgImuRaw = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgImuRaw(msg)) } 2305 => { - let mut msg = MsgImuAux::parse(payload)?; + let mut msg: MsgImuAux = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgImuAux(msg)) } 2306 => { - let mut msg = MsgMagRaw::parse(payload)?; + let mut msg: MsgMagRaw = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgMagRaw(msg)) } 2307 => { - let mut msg = MsgOdometry::parse(payload)?; + let mut msg: MsgOdometry = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgOdometry(msg)) } 2308 => { - let mut msg = MsgWheeltick::parse(payload)?; + let mut msg: MsgWheeltick = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgWheeltick(msg)) } 4097 => { - let mut msg = MsgFileioConfigReq::parse(payload)?; + let mut msg: MsgFileioConfigReq = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioConfigReq(msg)) } 4098 => { - let mut msg = MsgFileioConfigResp::parse(payload)?; + let mut msg: MsgFileioConfigResp = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgFileioConfigResp(msg)) } 30583 => { - let mut msg = MsgSbasRaw::parse(payload)?; + let mut msg: MsgSbasRaw = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSbasRaw(msg)) } 32512 => { - let mut msg = MsgLinuxCpuState::parse(payload)?; + let mut msg: MsgLinuxCpuState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxCpuState(msg)) } 32513 => { - let mut msg = MsgLinuxMemState::parse(payload)?; + let mut msg: MsgLinuxMemState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxMemState(msg)) } 32514 => { - let mut msg = MsgLinuxSysState::parse(payload)?; + let mut msg: MsgLinuxSysState = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxSysState(msg)) } 32515 => { - let mut msg = MsgLinuxProcessSocketCounts::parse(payload)?; + let mut msg: MsgLinuxProcessSocketCounts = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxProcessSocketCounts(msg)) } 32516 => { - let mut msg = MsgLinuxProcessSocketQueues::parse(payload)?; + let mut msg: MsgLinuxProcessSocketQueues = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxProcessSocketQueues(msg)) } 32517 => { - let mut msg = MsgLinuxSocketUsage::parse(payload)?; + let mut msg: MsgLinuxSocketUsage = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxSocketUsage(msg)) } 32518 => { - let mut msg = MsgLinuxProcessFdCount::parse(payload)?; + let mut msg: MsgLinuxProcessFdCount = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxProcessFdCount(msg)) } 32519 => { - let mut msg = MsgLinuxProcessFdSummary::parse(payload)?; + let mut msg: MsgLinuxProcessFdSummary = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgLinuxProcessFdSummary(msg)) } 65280 => { - let mut msg = MsgStartup::parse(payload)?; + let mut msg: MsgStartup = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgStartup(msg)) } 65282 => { - let mut msg = MsgDgnssStatus::parse(payload)?; + let mut msg: MsgDgnssStatus = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgDgnssStatus(msg)) } 65283 => { - let mut msg = MsgInsStatus::parse(payload)?; + let mut msg: MsgInsStatus = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgInsStatus(msg)) } 65284 => { - let mut msg = MsgCsacTelemetry::parse(payload)?; + let mut msg: MsgCsacTelemetry = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCsacTelemetry(msg)) } 65285 => { - let mut msg = MsgCsacTelemetryLabels::parse(payload)?; + let mut msg: MsgCsacTelemetryLabels = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgCsacTelemetryLabels(msg)) } 65286 => { - let mut msg = MsgInsUpdates::parse(payload)?; + let mut msg: MsgInsUpdates = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgInsUpdates(msg)) } 65287 => { - let mut msg = MsgGnssTimeOffset::parse(payload)?; + let mut msg: MsgGnssTimeOffset = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGnssTimeOffset(msg)) } 65290 => { - let mut msg = MsgGroupMeta::parse(payload)?; + let mut msg: MsgGroupMeta = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgGroupMeta(msg)) } 65294 => { - let mut msg = MsgSolnMeta::parse(payload)?; + let mut msg: MsgSolnMeta = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSolnMeta(msg)) } 65295 => { - let mut msg = MsgSolnMetaDepA::parse(payload)?; + let mut msg: MsgSolnMetaDepA = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgSolnMetaDepA(msg)) } 65535 => { - let mut msg = MsgHeartbeat::parse(payload)?; + let mut msg: MsgHeartbeat = payload.parse()?; msg.set_sender_id(sender_id); Ok(SBP::MsgHeartbeat(msg)) } diff --git a/rust/sbp/src/messages/navigation.rs b/rust/sbp/src/messages/navigation.rs index 4ef4c95492..74f150af91 100644 --- a/rust/sbp/src/messages/navigation.rs +++ b/rust/sbp/src/messages/navigation.rs @@ -38,14 +38,11 @@ //! but not a Time of Measurement. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Age of corrections /// @@ -63,13 +60,13 @@ pub struct MsgAgeCorrections { pub age: u16, } -impl MsgAgeCorrections { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAgeCorrections{ sender_id: None, - tow: _buf.read_u32::()?, - age: _buf.read_u16::()?, + tow: self.parse()?, + age: self.parse()?, } ) } } @@ -136,18 +133,18 @@ pub struct MsgBaselineECEF { pub flags: u8, } -impl MsgBaselineECEF { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBaselineECEF{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -224,18 +221,18 @@ pub struct MsgBaselineECEFDepA { pub flags: u8, } -impl MsgBaselineECEFDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBaselineECEFDepA{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -304,15 +301,15 @@ pub struct MsgBaselineHeadingDepA { pub flags: u8, } -impl MsgBaselineHeadingDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBaselineHeadingDepA{ sender_id: None, - tow: _buf.read_u32::()?, - heading: _buf.read_u32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + heading: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -386,19 +383,19 @@ pub struct MsgBaselineNED { pub flags: u8, } -impl MsgBaselineNED { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBaselineNED{ sender_id: None, - tow: _buf.read_u32::()?, - n: _buf.read_i32::()?, - e: _buf.read_i32::()?, - d: _buf.read_i32::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + n: self.parse()?, + e: self.parse()?, + d: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -480,19 +477,19 @@ pub struct MsgBaselineNEDDepA { pub flags: u8, } -impl MsgBaselineNEDDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBaselineNEDDepA{ sender_id: None, - tow: _buf.read_u32::()?, - n: _buf.read_i32::()?, - e: _buf.read_i32::()?, - d: _buf.read_i32::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + n: self.parse()?, + e: self.parse()?, + d: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -570,18 +567,18 @@ pub struct MsgDops { pub flags: u8, } -impl MsgDops { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgDops{ sender_id: None, - tow: _buf.read_u32::()?, - gdop: _buf.read_u16::()?, - pdop: _buf.read_u16::()?, - tdop: _buf.read_u16::()?, - hdop: _buf.read_u16::()?, - vdop: _buf.read_u16::()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + gdop: self.parse()?, + pdop: self.parse()?, + tdop: self.parse()?, + hdop: self.parse()?, + vdop: self.parse()?, + flags: self.parse()?, } ) } } @@ -654,17 +651,17 @@ pub struct MsgDopsDepA { pub vdop: u16, } -impl MsgDopsDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgDopsDepA{ sender_id: None, - tow: _buf.read_u32::()?, - gdop: _buf.read_u16::()?, - pdop: _buf.read_u16::()?, - tdop: _buf.read_u16::()?, - hdop: _buf.read_u16::()?, - vdop: _buf.read_u16::()?, + tow: self.parse()?, + gdop: self.parse()?, + pdop: self.parse()?, + tdop: self.parse()?, + hdop: self.parse()?, + vdop: self.parse()?, } ) } } @@ -742,15 +739,15 @@ pub struct MsgGPSTime { pub flags: u8, } -impl MsgGPSTime { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGPSTime{ sender_id: None, - wn: _buf.read_u16::()?, - tow: _buf.read_u32::()?, - ns_residual: _buf.read_i32::()?, - flags: _buf.read_u8()?, + wn: self.parse()?, + tow: self.parse()?, + ns_residual: self.parse()?, + flags: self.parse()?, } ) } } @@ -824,15 +821,15 @@ pub struct MsgGPSTimeDepA { pub flags: u8, } -impl MsgGPSTimeDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGPSTimeDepA{ sender_id: None, - wn: _buf.read_u16::()?, - tow: _buf.read_u32::()?, - ns_residual: _buf.read_i32::()?, - flags: _buf.read_u8()?, + wn: self.parse()?, + tow: self.parse()?, + ns_residual: self.parse()?, + flags: self.parse()?, } ) } } @@ -906,15 +903,15 @@ pub struct MsgGPSTimeGnss { pub flags: u8, } -impl MsgGPSTimeGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGPSTimeGnss{ sender_id: None, - wn: _buf.read_u16::()?, - tow: _buf.read_u32::()?, - ns_residual: _buf.read_i32::()?, - flags: _buf.read_u8()?, + wn: self.parse()?, + tow: self.parse()?, + ns_residual: self.parse()?, + flags: self.parse()?, } ) } } @@ -988,18 +985,18 @@ pub struct MsgPosECEF { pub flags: u8, } -impl MsgPosECEF { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosECEF{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_f64::()?, - y: _buf.read_f64::()?, - z: _buf.read_f64::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1090,23 +1087,23 @@ pub struct MsgPosECEFCov { pub flags: u8, } -impl MsgPosECEFCov { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosECEFCov{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_f64::()?, - y: _buf.read_f64::()?, - z: _buf.read_f64::()?, - cov_x_x: _buf.read_f32::()?, - cov_x_y: _buf.read_f32::()?, - cov_x_z: _buf.read_f32::()?, - cov_y_y: _buf.read_f32::()?, - cov_y_z: _buf.read_f32::()?, - cov_z_z: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + cov_x_x: self.parse()?, + cov_x_y: self.parse()?, + cov_x_z: self.parse()?, + cov_y_y: self.parse()?, + cov_y_z: self.parse()?, + cov_z_z: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1207,23 +1204,23 @@ pub struct MsgPosECEFCovGnss { pub flags: u8, } -impl MsgPosECEFCovGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosECEFCovGnss{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_f64::()?, - y: _buf.read_f64::()?, - z: _buf.read_f64::()?, - cov_x_x: _buf.read_f32::()?, - cov_x_y: _buf.read_f32::()?, - cov_x_z: _buf.read_f32::()?, - cov_y_y: _buf.read_f32::()?, - cov_y_z: _buf.read_f32::()?, - cov_z_z: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + cov_x_x: self.parse()?, + cov_x_y: self.parse()?, + cov_x_z: self.parse()?, + cov_y_y: self.parse()?, + cov_y_z: self.parse()?, + cov_z_z: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1313,18 +1310,18 @@ pub struct MsgPosECEFDepA { pub flags: u8, } -impl MsgPosECEFDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosECEFDepA{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_f64::()?, - y: _buf.read_f64::()?, - z: _buf.read_f64::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1404,18 +1401,18 @@ pub struct MsgPosECEFGnss { pub flags: u8, } -impl MsgPosECEFGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosECEFGnss{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_f64::()?, - y: _buf.read_f64::()?, - z: _buf.read_f64::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1497,19 +1494,19 @@ pub struct MsgPosLLH { pub flags: u8, } -impl MsgPosLLH { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosLLH{ sender_id: None, - tow: _buf.read_u32::()?, - lat: _buf.read_f64::()?, - lon: _buf.read_f64::()?, - height: _buf.read_f64::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + lat: self.parse()?, + lon: self.parse()?, + height: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1601,23 +1598,23 @@ pub struct MsgPosLLHCov { pub flags: u8, } -impl MsgPosLLHCov { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosLLHCov{ sender_id: None, - tow: _buf.read_u32::()?, - lat: _buf.read_f64::()?, - lon: _buf.read_f64::()?, - height: _buf.read_f64::()?, - cov_n_n: _buf.read_f32::()?, - cov_n_e: _buf.read_f32::()?, - cov_n_d: _buf.read_f32::()?, - cov_e_e: _buf.read_f32::()?, - cov_e_d: _buf.read_f32::()?, - cov_d_d: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + lat: self.parse()?, + lon: self.parse()?, + height: self.parse()?, + cov_n_n: self.parse()?, + cov_n_e: self.parse()?, + cov_n_d: self.parse()?, + cov_e_e: self.parse()?, + cov_e_d: self.parse()?, + cov_d_d: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1717,23 +1714,23 @@ pub struct MsgPosLLHCovGnss { pub flags: u8, } -impl MsgPosLLHCovGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosLLHCovGnss{ sender_id: None, - tow: _buf.read_u32::()?, - lat: _buf.read_f64::()?, - lon: _buf.read_f64::()?, - height: _buf.read_f64::()?, - cov_n_n: _buf.read_f32::()?, - cov_n_e: _buf.read_f32::()?, - cov_n_d: _buf.read_f32::()?, - cov_e_e: _buf.read_f32::()?, - cov_e_d: _buf.read_f32::()?, - cov_d_d: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + lat: self.parse()?, + lon: self.parse()?, + height: self.parse()?, + cov_n_n: self.parse()?, + cov_n_e: self.parse()?, + cov_n_d: self.parse()?, + cov_e_e: self.parse()?, + cov_e_d: self.parse()?, + cov_d_d: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1825,19 +1822,19 @@ pub struct MsgPosLLHDepA { pub flags: u8, } -impl MsgPosLLHDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosLLHDepA{ sender_id: None, - tow: _buf.read_u32::()?, - lat: _buf.read_f64::()?, - lon: _buf.read_f64::()?, - height: _buf.read_f64::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + lat: self.parse()?, + lon: self.parse()?, + height: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -1921,19 +1918,19 @@ pub struct MsgPosLLHGnss { pub flags: u8, } -impl MsgPosLLHGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgPosLLHGnss{ sender_id: None, - tow: _buf.read_u32::()?, - lat: _buf.read_f64::()?, - lon: _buf.read_f64::()?, - height: _buf.read_f64::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + lat: self.parse()?, + lon: self.parse()?, + height: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2010,18 +2007,18 @@ pub struct MsgProtectionLevel { pub flags: u8, } -impl MsgProtectionLevel { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgProtectionLevel{ sender_id: None, - tow: _buf.read_u32::()?, - vpl: _buf.read_u16::()?, - hpl: _buf.read_u16::()?, - lat: _buf.read_f64::()?, - lon: _buf.read_f64::()?, - height: _buf.read_f64::()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + vpl: self.parse()?, + hpl: self.parse()?, + lat: self.parse()?, + lon: self.parse()?, + height: self.parse()?, + flags: self.parse()?, } ) } } @@ -2099,20 +2096,20 @@ pub struct MsgUtcTime { pub ns: u32, } -impl MsgUtcTime { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgUtcTime{ sender_id: None, - flags: _buf.read_u8()?, - tow: _buf.read_u32::()?, - year: _buf.read_u16::()?, - month: _buf.read_u8()?, - day: _buf.read_u8()?, - hours: _buf.read_u8()?, - minutes: _buf.read_u8()?, - seconds: _buf.read_u8()?, - ns: _buf.read_u32::()?, + flags: self.parse()?, + tow: self.parse()?, + year: self.parse()?, + month: self.parse()?, + day: self.parse()?, + hours: self.parse()?, + minutes: self.parse()?, + seconds: self.parse()?, + ns: self.parse()?, } ) } } @@ -2194,20 +2191,20 @@ pub struct MsgUtcTimeGnss { pub ns: u32, } -impl MsgUtcTimeGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgUtcTimeGnss{ sender_id: None, - flags: _buf.read_u8()?, - tow: _buf.read_u32::()?, - year: _buf.read_u16::()?, - month: _buf.read_u8()?, - day: _buf.read_u8()?, - hours: _buf.read_u8()?, - minutes: _buf.read_u8()?, - seconds: _buf.read_u8()?, - ns: _buf.read_u32::()?, + flags: self.parse()?, + tow: self.parse()?, + year: self.parse()?, + month: self.parse()?, + day: self.parse()?, + hours: self.parse()?, + minutes: self.parse()?, + seconds: self.parse()?, + ns: self.parse()?, } ) } } @@ -2301,23 +2298,23 @@ pub struct MsgVelBody { pub flags: u8, } -impl MsgVelBody { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelBody{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - cov_x_x: _buf.read_f32::()?, - cov_x_y: _buf.read_f32::()?, - cov_x_z: _buf.read_f32::()?, - cov_y_y: _buf.read_f32::()?, - cov_y_z: _buf.read_f32::()?, - cov_z_z: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + cov_x_x: self.parse()?, + cov_x_y: self.parse()?, + cov_x_z: self.parse()?, + cov_y_y: self.parse()?, + cov_y_z: self.parse()?, + cov_z_z: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2402,18 +2399,18 @@ pub struct MsgVelECEF { pub flags: u8, } -impl MsgVelECEF { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelECEF{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2498,23 +2495,23 @@ pub struct MsgVelECEFCov { pub flags: u8, } -impl MsgVelECEFCov { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelECEFCov{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - cov_x_x: _buf.read_f32::()?, - cov_x_y: _buf.read_f32::()?, - cov_x_z: _buf.read_f32::()?, - cov_y_y: _buf.read_f32::()?, - cov_y_z: _buf.read_f32::()?, - cov_z_z: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + cov_x_x: self.parse()?, + cov_x_y: self.parse()?, + cov_x_z: self.parse()?, + cov_y_y: self.parse()?, + cov_y_z: self.parse()?, + cov_z_z: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2609,23 +2606,23 @@ pub struct MsgVelECEFCovGnss { pub flags: u8, } -impl MsgVelECEFCovGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelECEFCovGnss{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - cov_x_x: _buf.read_f32::()?, - cov_x_y: _buf.read_f32::()?, - cov_x_z: _buf.read_f32::()?, - cov_y_y: _buf.read_f32::()?, - cov_y_z: _buf.read_f32::()?, - cov_z_z: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + cov_x_x: self.parse()?, + cov_x_y: self.parse()?, + cov_x_z: self.parse()?, + cov_y_y: self.parse()?, + cov_y_z: self.parse()?, + cov_z_z: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2710,18 +2707,18 @@ pub struct MsgVelECEFDepA { pub flags: u8, } -impl MsgVelECEFDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelECEFDepA{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2796,18 +2793,18 @@ pub struct MsgVelECEFGnss { pub flags: u8, } -impl MsgVelECEFGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelECEFGnss{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2885,19 +2882,19 @@ pub struct MsgVelNED { pub flags: u8, } -impl MsgVelNED { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelNED{ sender_id: None, - tow: _buf.read_u32::()?, - n: _buf.read_i32::()?, - e: _buf.read_i32::()?, - d: _buf.read_i32::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + n: self.parse()?, + e: self.parse()?, + d: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -2987,23 +2984,23 @@ pub struct MsgVelNEDCov { pub flags: u8, } -impl MsgVelNEDCov { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelNEDCov{ sender_id: None, - tow: _buf.read_u32::()?, - n: _buf.read_i32::()?, - e: _buf.read_i32::()?, - d: _buf.read_i32::()?, - cov_n_n: _buf.read_f32::()?, - cov_n_e: _buf.read_f32::()?, - cov_n_d: _buf.read_f32::()?, - cov_e_e: _buf.read_f32::()?, - cov_e_d: _buf.read_f32::()?, - cov_d_d: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + n: self.parse()?, + e: self.parse()?, + d: self.parse()?, + cov_n_n: self.parse()?, + cov_n_e: self.parse()?, + cov_n_d: self.parse()?, + cov_e_e: self.parse()?, + cov_e_d: self.parse()?, + cov_d_d: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -3101,23 +3098,23 @@ pub struct MsgVelNEDCovGnss { pub flags: u8, } -impl MsgVelNEDCovGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelNEDCovGnss{ sender_id: None, - tow: _buf.read_u32::()?, - n: _buf.read_i32::()?, - e: _buf.read_i32::()?, - d: _buf.read_i32::()?, - cov_n_n: _buf.read_f32::()?, - cov_n_e: _buf.read_f32::()?, - cov_n_d: _buf.read_f32::()?, - cov_e_e: _buf.read_f32::()?, - cov_e_d: _buf.read_f32::()?, - cov_d_d: _buf.read_f32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + n: self.parse()?, + e: self.parse()?, + d: self.parse()?, + cov_n_n: self.parse()?, + cov_n_e: self.parse()?, + cov_n_d: self.parse()?, + cov_e_e: self.parse()?, + cov_e_d: self.parse()?, + cov_d_d: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -3205,19 +3202,19 @@ pub struct MsgVelNEDDepA { pub flags: u8, } -impl MsgVelNEDDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelNEDDepA{ sender_id: None, - tow: _buf.read_u32::()?, - n: _buf.read_i32::()?, - e: _buf.read_i32::()?, - d: _buf.read_i32::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + n: self.parse()?, + e: self.parse()?, + d: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -3297,19 +3294,19 @@ pub struct MsgVelNEDGnss { pub flags: u8, } -impl MsgVelNEDGnss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgVelNEDGnss{ sender_id: None, - tow: _buf.read_u32::()?, - n: _buf.read_i32::()?, - e: _buf.read_i32::()?, - d: _buf.read_i32::()?, - h_accuracy: _buf.read_u16::()?, - v_accuracy: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + n: self.parse()?, + e: self.parse()?, + d: self.parse()?, + h_accuracy: self.parse()?, + v_accuracy: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/ndb.rs b/rust/sbp/src/messages/ndb.rs index cdbcc26ce0..58b1435a5b 100644 --- a/rust/sbp/src/messages/ndb.rs +++ b/rust/sbp/src/messages/ndb.rs @@ -15,15 +15,12 @@ //! Messages for logging NDB events. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; use super::gnss::*; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Navigation DataBase Event /// @@ -59,19 +56,19 @@ pub struct MsgNdbEvent { pub original_sender: u16, } -impl MsgNdbEvent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgNdbEvent{ sender_id: None, - recv_time: _buf.read_u64::()?, - event: _buf.read_u8()?, - object_type: _buf.read_u8()?, - result: _buf.read_u8()?, - data_source: _buf.read_u8()?, - object_sid: GnssSignal::parse(_buf)?, - src_sid: GnssSignal::parse(_buf)?, - original_sender: _buf.read_u16::()?, + recv_time: self.parse()?, + event: self.parse()?, + object_type: self.parse()?, + result: self.parse()?, + data_source: self.parse()?, + object_sid: self.parse()?, + src_sid: self.parse()?, + original_sender: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/observation.rs b/rust/sbp/src/messages/observation.rs index dde1b09844..4912e1209f 100644 --- a/rust/sbp/src/messages/observation.rs +++ b/rust/sbp/src/messages/observation.rs @@ -14,15 +14,12 @@ //****************************************************************************/ //! Satellite observation messages from the device. -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; use super::gnss::*; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; #[cfg_attr(feature = "sbp_serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone)] @@ -51,36 +48,18 @@ pub struct AlmanacCommonContent { pub health_bits: u8, } -impl AlmanacCommonContent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( AlmanacCommonContent{ - sid: GnssSignal::parse(_buf)?, - toa: GPSTimeSec::parse(_buf)?, - ura: _buf.read_f64::()?, - fit_interval: _buf.read_u32::()?, - valid: _buf.read_u8()?, - health_bits: _buf.read_u8()?, + sid: self.parse()?, + toa: self.parse()?, + ura: self.parse()?, + fit_interval: self.parse()?, + valid: self.parse()?, + health_bits: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(AlmanacCommonContent::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(AlmanacCommonContent::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for AlmanacCommonContent { @@ -133,36 +112,18 @@ pub struct AlmanacCommonContentDep { pub health_bits: u8, } -impl AlmanacCommonContentDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( AlmanacCommonContentDep{ - sid: GnssSignalDep::parse(_buf)?, - toa: GPSTimeSec::parse(_buf)?, - ura: _buf.read_f64::()?, - fit_interval: _buf.read_u32::()?, - valid: _buf.read_u8()?, - health_bits: _buf.read_u8()?, + sid: self.parse()?, + toa: self.parse()?, + ura: self.parse()?, + fit_interval: self.parse()?, + valid: self.parse()?, + health_bits: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(AlmanacCommonContentDep::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(AlmanacCommonContentDep::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for AlmanacCommonContentDep { @@ -206,32 +167,14 @@ pub struct CarrierPhaseDepA { pub f: u8, } -impl CarrierPhaseDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( CarrierPhaseDepA{ - i: _buf.read_i32::()?, - f: _buf.read_u8()?, + i: self.parse()?, + f: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(CarrierPhaseDepA::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(CarrierPhaseDepA::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for CarrierPhaseDepA { @@ -266,29 +209,14 @@ pub struct Doppler { pub f: u8, } -impl Doppler { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( Doppler{ - i: _buf.read_i16::()?, - f: _buf.read_u8()?, + i: self.parse()?, + f: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(Doppler::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(Doppler::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for Doppler { @@ -325,36 +253,18 @@ pub struct EphemerisCommonContent { pub health_bits: u8, } -impl EphemerisCommonContent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( EphemerisCommonContent{ - sid: GnssSignal::parse(_buf)?, - toe: GPSTimeSec::parse(_buf)?, - ura: _buf.read_f32::()?, - fit_interval: _buf.read_u32::()?, - valid: _buf.read_u8()?, - health_bits: _buf.read_u8()?, + sid: self.parse()?, + toe: self.parse()?, + ura: self.parse()?, + fit_interval: self.parse()?, + valid: self.parse()?, + health_bits: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(EphemerisCommonContent::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(EphemerisCommonContent::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for EphemerisCommonContent { @@ -399,36 +309,18 @@ pub struct EphemerisCommonContentDepA { pub health_bits: u8, } -impl EphemerisCommonContentDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( EphemerisCommonContentDepA{ - sid: GnssSignalDep::parse(_buf)?, - toe: GPSTimeDep::parse(_buf)?, - ura: _buf.read_f64::()?, - fit_interval: _buf.read_u32::()?, - valid: _buf.read_u8()?, - health_bits: _buf.read_u8()?, + sid: self.parse()?, + toe: self.parse()?, + ura: self.parse()?, + fit_interval: self.parse()?, + valid: self.parse()?, + health_bits: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(EphemerisCommonContentDepA::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(EphemerisCommonContentDepA::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for EphemerisCommonContentDepA { @@ -473,36 +365,18 @@ pub struct EphemerisCommonContentDepB { pub health_bits: u8, } -impl EphemerisCommonContentDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( EphemerisCommonContentDepB{ - sid: GnssSignal::parse(_buf)?, - toe: GPSTimeSec::parse(_buf)?, - ura: _buf.read_f64::()?, - fit_interval: _buf.read_u32::()?, - valid: _buf.read_u8()?, - health_bits: _buf.read_u8()?, + sid: self.parse()?, + toe: self.parse()?, + ura: self.parse()?, + fit_interval: self.parse()?, + valid: self.parse()?, + health_bits: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(EphemerisCommonContentDepB::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(EphemerisCommonContentDepB::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for EphemerisCommonContentDepB { @@ -566,42 +440,27 @@ pub struct GnssCapb { pub gal_e5: u64, } -impl GnssCapb { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GnssCapb{ - gps_active: _buf.read_u64::()?, - gps_l2c: _buf.read_u64::()?, - gps_l5: _buf.read_u64::()?, - glo_active: _buf.read_u32::()?, - glo_l2of: _buf.read_u32::()?, - glo_l3: _buf.read_u32::()?, - sbas_active: _buf.read_u64::()?, - sbas_l5: _buf.read_u64::()?, - bds_active: _buf.read_u64::()?, - bds_d2nav: _buf.read_u64::()?, - bds_b2: _buf.read_u64::()?, - bds_b2a: _buf.read_u64::()?, - qzss_active: _buf.read_u32::()?, - gal_active: _buf.read_u64::()?, - gal_e5: _buf.read_u64::()?, + gps_active: self.parse()?, + gps_l2c: self.parse()?, + gps_l5: self.parse()?, + glo_active: self.parse()?, + glo_l2of: self.parse()?, + glo_l3: self.parse()?, + sbas_active: self.parse()?, + sbas_l5: self.parse()?, + bds_active: self.parse()?, + bds_d2nav: self.parse()?, + bds_b2: self.parse()?, + bds_b2a: self.parse()?, + qzss_active: self.parse()?, + gal_active: self.parse()?, + gal_e5: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GnssCapb::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GnssCapb::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GnssCapb { @@ -676,19 +535,19 @@ pub struct MsgAlmanacGlo { pub omega: f64, } -impl MsgAlmanacGlo { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAlmanacGlo{ sender_id: None, - common: AlmanacCommonContent::parse(_buf)?, - lambda_na: _buf.read_f64::()?, - t_lambda_na: _buf.read_f64::()?, - i: _buf.read_f64::()?, - t: _buf.read_f64::()?, - t_dot: _buf.read_f64::()?, - epsilon: _buf.read_f64::()?, - omega: _buf.read_f64::()?, + common: self.parse()?, + lambda_na: self.parse()?, + t_lambda_na: self.parse()?, + i: self.parse()?, + t: self.parse()?, + t_dot: self.parse()?, + epsilon: self.parse()?, + omega: self.parse()?, } ) } } @@ -769,19 +628,19 @@ pub struct MsgAlmanacGloDep { pub omega: f64, } -impl MsgAlmanacGloDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAlmanacGloDep{ sender_id: None, - common: AlmanacCommonContentDep::parse(_buf)?, - lambda_na: _buf.read_f64::()?, - t_lambda_na: _buf.read_f64::()?, - i: _buf.read_f64::()?, - t: _buf.read_f64::()?, - t_dot: _buf.read_f64::()?, - epsilon: _buf.read_f64::()?, - omega: _buf.read_f64::()?, + common: self.parse()?, + lambda_na: self.parse()?, + t_lambda_na: self.parse()?, + i: self.parse()?, + t: self.parse()?, + t_dot: self.parse()?, + epsilon: self.parse()?, + omega: self.parse()?, } ) } } @@ -865,21 +724,21 @@ pub struct MsgAlmanacGPS { pub af1: f64, } -impl MsgAlmanacGPS { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAlmanacGPS{ sender_id: None, - common: AlmanacCommonContent::parse(_buf)?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, + common: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, } ) } } @@ -967,21 +826,21 @@ pub struct MsgAlmanacGPSDep { pub af1: f64, } -impl MsgAlmanacGPSDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAlmanacGPSDep{ sender_id: None, - common: AlmanacCommonContentDep::parse(_buf)?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, + common: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, } ) } } @@ -1057,14 +916,14 @@ pub struct MsgBasePosECEF { pub z: f64, } -impl MsgBasePosECEF { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBasePosECEF{ sender_id: None, - x: _buf.read_f64::()?, - y: _buf.read_f64::()?, - z: _buf.read_f64::()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, } ) } } @@ -1125,14 +984,14 @@ pub struct MsgBasePosLLH { pub height: f64, } -impl MsgBasePosLLH { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBasePosLLH{ sender_id: None, - lat: _buf.read_f64::()?, - lon: _buf.read_f64::()?, - height: _buf.read_f64::()?, + lat: self.parse()?, + lon: self.parse()?, + height: self.parse()?, } ) } } @@ -1240,35 +1099,35 @@ pub struct MsgEphemerisBds { pub iodc: u16, } -impl MsgEphemerisBds { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisBds{ sender_id: None, - common: EphemerisCommonContent::parse(_buf)?, - tgd1: _buf.read_f32::()?, - tgd2: _buf.read_f32::()?, - c_rs: _buf.read_f32::()?, - c_rc: _buf.read_f32::()?, - c_uc: _buf.read_f32::()?, - c_us: _buf.read_f32::()?, - c_ic: _buf.read_f32::()?, - c_is: _buf.read_f32::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f32::()?, - af2: _buf.read_f32::()?, - toc: GPSTimeSec::parse(_buf)?, - iode: _buf.read_u8()?, - iodc: _buf.read_u16::()?, + common: self.parse()?, + tgd1: self.parse()?, + tgd2: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toc: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, } ) } } @@ -1417,37 +1276,37 @@ pub struct MsgEphemerisDepA { pub prn: u8, } -impl MsgEphemerisDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisDepA{ sender_id: None, - tgd: _buf.read_f64::()?, - c_rs: _buf.read_f64::()?, - c_rc: _buf.read_f64::()?, - c_uc: _buf.read_f64::()?, - c_us: _buf.read_f64::()?, - c_ic: _buf.read_f64::()?, - c_is: _buf.read_f64::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f64::()?, - toe_tow: _buf.read_f64::()?, - toe_wn: _buf.read_u16::()?, - toc_tow: _buf.read_f64::()?, - toc_wn: _buf.read_u16::()?, - valid: _buf.read_u8()?, - healthy: _buf.read_u8()?, - prn: _buf.read_u8()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toe_tow: self.parse()?, + toe_wn: self.parse()?, + toc_tow: self.parse()?, + toc_wn: self.parse()?, + valid: self.parse()?, + healthy: self.parse()?, + prn: self.parse()?, } ) } } @@ -1602,38 +1461,38 @@ pub struct MsgEphemerisDepB { pub iode: u8, } -impl MsgEphemerisDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisDepB{ sender_id: None, - tgd: _buf.read_f64::()?, - c_rs: _buf.read_f64::()?, - c_rc: _buf.read_f64::()?, - c_uc: _buf.read_f64::()?, - c_us: _buf.read_f64::()?, - c_ic: _buf.read_f64::()?, - c_is: _buf.read_f64::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f64::()?, - toe_tow: _buf.read_f64::()?, - toe_wn: _buf.read_u16::()?, - toc_tow: _buf.read_f64::()?, - toc_wn: _buf.read_u16::()?, - valid: _buf.read_u8()?, - healthy: _buf.read_u8()?, - prn: _buf.read_u8()?, - iode: _buf.read_u8()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toe_tow: self.parse()?, + toe_wn: self.parse()?, + toc_tow: self.parse()?, + toc_wn: self.parse()?, + valid: self.parse()?, + healthy: self.parse()?, + prn: self.parse()?, + iode: self.parse()?, } ) } } @@ -1798,40 +1657,40 @@ pub struct MsgEphemerisDepC { pub reserved: u32, } -impl MsgEphemerisDepC { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisDepC{ sender_id: None, - tgd: _buf.read_f64::()?, - c_rs: _buf.read_f64::()?, - c_rc: _buf.read_f64::()?, - c_uc: _buf.read_f64::()?, - c_us: _buf.read_f64::()?, - c_ic: _buf.read_f64::()?, - c_is: _buf.read_f64::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f64::()?, - toe_tow: _buf.read_f64::()?, - toe_wn: _buf.read_u16::()?, - toc_tow: _buf.read_f64::()?, - toc_wn: _buf.read_u16::()?, - valid: _buf.read_u8()?, - healthy: _buf.read_u8()?, - sid: GnssSignalDep::parse(_buf)?, - iode: _buf.read_u8()?, - iodc: _buf.read_u16::()?, - reserved: _buf.read_u32::()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toe_tow: self.parse()?, + toe_wn: self.parse()?, + toc_tow: self.parse()?, + toc_wn: self.parse()?, + valid: self.parse()?, + healthy: self.parse()?, + sid: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, + reserved: self.parse()?, } ) } } @@ -2000,40 +1859,40 @@ pub struct MsgEphemerisDepD { pub reserved: u32, } -impl MsgEphemerisDepD { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisDepD{ sender_id: None, - tgd: _buf.read_f64::()?, - c_rs: _buf.read_f64::()?, - c_rc: _buf.read_f64::()?, - c_uc: _buf.read_f64::()?, - c_us: _buf.read_f64::()?, - c_ic: _buf.read_f64::()?, - c_is: _buf.read_f64::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f64::()?, - toe_tow: _buf.read_f64::()?, - toe_wn: _buf.read_u16::()?, - toc_tow: _buf.read_f64::()?, - toc_wn: _buf.read_u16::()?, - valid: _buf.read_u8()?, - healthy: _buf.read_u8()?, - sid: GnssSignalDep::parse(_buf)?, - iode: _buf.read_u8()?, - iodc: _buf.read_u16::()?, - reserved: _buf.read_u32::()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toe_tow: self.parse()?, + toe_wn: self.parse()?, + toc_tow: self.parse()?, + toc_wn: self.parse()?, + valid: self.parse()?, + healthy: self.parse()?, + sid: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, + reserved: self.parse()?, } ) } } @@ -2193,36 +2052,36 @@ pub struct MsgEphemerisGal { pub source: u8, } -impl MsgEphemerisGal { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGal{ sender_id: None, - common: EphemerisCommonContent::parse(_buf)?, - bgd_e1e5a: _buf.read_f32::()?, - bgd_e1e5b: _buf.read_f32::()?, - c_rs: _buf.read_f32::()?, - c_rc: _buf.read_f32::()?, - c_uc: _buf.read_f32::()?, - c_us: _buf.read_f32::()?, - c_ic: _buf.read_f32::()?, - c_is: _buf.read_f32::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f32::()?, - toc: GPSTimeSec::parse(_buf)?, - iode: _buf.read_u16::()?, - iodc: _buf.read_u16::()?, - source: _buf.read_u8()?, + common: self.parse()?, + bgd_e1e5a: self.parse()?, + bgd_e1e5b: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toc: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, + source: self.parse()?, } ) } } @@ -2370,35 +2229,35 @@ pub struct MsgEphemerisGalDepA { pub iodc: u16, } -impl MsgEphemerisGalDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGalDepA{ sender_id: None, - common: EphemerisCommonContent::parse(_buf)?, - bgd_e1e5a: _buf.read_f32::()?, - bgd_e1e5b: _buf.read_f32::()?, - c_rs: _buf.read_f32::()?, - c_rc: _buf.read_f32::()?, - c_uc: _buf.read_f32::()?, - c_us: _buf.read_f32::()?, - c_ic: _buf.read_f32::()?, - c_is: _buf.read_f32::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f32::()?, - toc: GPSTimeSec::parse(_buf)?, - iode: _buf.read_u16::()?, - iodc: _buf.read_u16::()?, + common: self.parse()?, + bgd_e1e5a: self.parse()?, + bgd_e1e5b: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toc: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, } ) } } @@ -2502,31 +2361,31 @@ pub struct MsgEphemerisGlo { /// Equipment delay between L1 and L2 pub d_tau: f32, /// Position of the SV at tb in PZ-90.02 coordinates system - pub pos: Vec, + pub pos: [f64; 3], /// Velocity vector of the SV at tb in PZ-90.02 coordinates system - pub vel: Vec, + pub vel: [f64; 3], /// Acceleration vector of the SV at tb in PZ-90.02 coordinates sys - pub acc: Vec, + pub acc: [f32; 3], /// Frequency slot. FCN+8 (that is [1..14]). 0 or 0xFF for invalid pub fcn: u8, /// Issue of data. Equal to the 7 bits of the immediate data word t_b pub iod: u8, } -impl MsgEphemerisGlo { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGlo{ sender_id: None, - common: EphemerisCommonContent::parse(_buf)?, - gamma: _buf.read_f32::()?, - tau: _buf.read_f32::()?, - d_tau: _buf.read_f32::()?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_double_array_limit(_buf, 3)?, - acc: crate::parser::read_float_array_limit(_buf, 3)?, - fcn: _buf.read_u8()?, - iod: _buf.read_u8()?, + common: self.parse()?, + gamma: self.parse()?, + tau: self.parse()?, + d_tau: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, + fcn: self.parse()?, + iod: self.parse()?, } ) } } @@ -2598,24 +2457,24 @@ pub struct MsgEphemerisGloDepA { /// Correction to the SV time pub tau: f64, /// Position of the SV at tb in PZ-90.02 coordinates system - pub pos: Vec, + pub pos: [f64; 3], /// Velocity vector of the SV at tb in PZ-90.02 coordinates system - pub vel: Vec, + pub vel: [f64; 3], /// Acceleration vector of the SV at tb in PZ-90.02 coordinates sys - pub acc: Vec, + pub acc: [f64; 3], } -impl MsgEphemerisGloDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGloDepA{ sender_id: None, - common: EphemerisCommonContentDepA::parse(_buf)?, - gamma: _buf.read_f64::()?, - tau: _buf.read_f64::()?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_double_array_limit(_buf, 3)?, - acc: crate::parser::read_double_array_limit(_buf, 3)?, + common: self.parse()?, + gamma: self.parse()?, + tau: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, } ) } } @@ -2681,24 +2540,24 @@ pub struct MsgEphemerisGloDepB { /// Correction to the SV time pub tau: f64, /// Position of the SV at tb in PZ-90.02 coordinates system - pub pos: Vec, + pub pos: [f64; 3], /// Velocity vector of the SV at tb in PZ-90.02 coordinates system - pub vel: Vec, + pub vel: [f64; 3], /// Acceleration vector of the SV at tb in PZ-90.02 coordinates sys - pub acc: Vec, + pub acc: [f64; 3], } -impl MsgEphemerisGloDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGloDepB{ sender_id: None, - common: EphemerisCommonContentDepB::parse(_buf)?, - gamma: _buf.read_f64::()?, - tau: _buf.read_f64::()?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_double_array_limit(_buf, 3)?, - acc: crate::parser::read_double_array_limit(_buf, 3)?, + common: self.parse()?, + gamma: self.parse()?, + tau: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, } ) } } @@ -2766,28 +2625,28 @@ pub struct MsgEphemerisGloDepC { /// Equipment delay between L1 and L2 pub d_tau: f64, /// Position of the SV at tb in PZ-90.02 coordinates system - pub pos: Vec, + pub pos: [f64; 3], /// Velocity vector of the SV at tb in PZ-90.02 coordinates system - pub vel: Vec, + pub vel: [f64; 3], /// Acceleration vector of the SV at tb in PZ-90.02 coordinates sys - pub acc: Vec, + pub acc: [f64; 3], /// Frequency slot. FCN+8 (that is [1..14]). 0 or 0xFF for invalid pub fcn: u8, } -impl MsgEphemerisGloDepC { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGloDepC{ sender_id: None, - common: EphemerisCommonContentDepB::parse(_buf)?, - gamma: _buf.read_f64::()?, - tau: _buf.read_f64::()?, - d_tau: _buf.read_f64::()?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_double_array_limit(_buf, 3)?, - acc: crate::parser::read_double_array_limit(_buf, 3)?, - fcn: _buf.read_u8()?, + common: self.parse()?, + gamma: self.parse()?, + tau: self.parse()?, + d_tau: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, + fcn: self.parse()?, } ) } } @@ -2856,31 +2715,31 @@ pub struct MsgEphemerisGloDepD { /// Equipment delay between L1 and L2 pub d_tau: f64, /// Position of the SV at tb in PZ-90.02 coordinates system - pub pos: Vec, + pub pos: [f64; 3], /// Velocity vector of the SV at tb in PZ-90.02 coordinates system - pub vel: Vec, + pub vel: [f64; 3], /// Acceleration vector of the SV at tb in PZ-90.02 coordinates sys - pub acc: Vec, + pub acc: [f64; 3], /// Frequency slot. FCN+8 (that is [1..14]). 0 or 0xFF for invalid pub fcn: u8, /// Issue of data. Equal to the 7 bits of the immediate data word t_b pub iod: u8, } -impl MsgEphemerisGloDepD { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGloDepD{ sender_id: None, - common: EphemerisCommonContentDepB::parse(_buf)?, - gamma: _buf.read_f64::()?, - tau: _buf.read_f64::()?, - d_tau: _buf.read_f64::()?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_double_array_limit(_buf, 3)?, - acc: crate::parser::read_double_array_limit(_buf, 3)?, - fcn: _buf.read_u8()?, - iod: _buf.read_u8()?, + common: self.parse()?, + gamma: self.parse()?, + tau: self.parse()?, + d_tau: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, + fcn: self.parse()?, + iod: self.parse()?, } ) } } @@ -2997,34 +2856,34 @@ pub struct MsgEphemerisGPS { pub iodc: u16, } -impl MsgEphemerisGPS { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGPS{ sender_id: None, - common: EphemerisCommonContent::parse(_buf)?, - tgd: _buf.read_f32::()?, - c_rs: _buf.read_f32::()?, - c_rc: _buf.read_f32::()?, - c_uc: _buf.read_f32::()?, - c_us: _buf.read_f32::()?, - c_ic: _buf.read_f32::()?, - c_is: _buf.read_f32::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f32::()?, - af1: _buf.read_f32::()?, - af2: _buf.read_f32::()?, - toc: GPSTimeSec::parse(_buf)?, - iode: _buf.read_u8()?, - iodc: _buf.read_u16::()?, + common: self.parse()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toc: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, } ) } } @@ -3169,34 +3028,34 @@ pub struct MsgEphemerisGPSDepE { pub iodc: u16, } -impl MsgEphemerisGPSDepE { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGPSDepE{ sender_id: None, - common: EphemerisCommonContentDepA::parse(_buf)?, - tgd: _buf.read_f64::()?, - c_rs: _buf.read_f64::()?, - c_rc: _buf.read_f64::()?, - c_uc: _buf.read_f64::()?, - c_us: _buf.read_f64::()?, - c_ic: _buf.read_f64::()?, - c_is: _buf.read_f64::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f64::()?, - toc: GPSTimeDep::parse(_buf)?, - iode: _buf.read_u8()?, - iodc: _buf.read_u16::()?, + common: self.parse()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toc: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, } ) } } @@ -3338,34 +3197,34 @@ pub struct MsgEphemerisGPSDepF { pub iodc: u16, } -impl MsgEphemerisGPSDepF { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisGPSDepF{ sender_id: None, - common: EphemerisCommonContentDepB::parse(_buf)?, - tgd: _buf.read_f64::()?, - c_rs: _buf.read_f64::()?, - c_rc: _buf.read_f64::()?, - c_uc: _buf.read_f64::()?, - c_us: _buf.read_f64::()?, - c_ic: _buf.read_f64::()?, - c_is: _buf.read_f64::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f64::()?, - af1: _buf.read_f64::()?, - af2: _buf.read_f64::()?, - toc: GPSTimeSec::parse(_buf)?, - iode: _buf.read_u8()?, - iodc: _buf.read_u16::()?, + common: self.parse()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toc: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, } ) } } @@ -3508,34 +3367,34 @@ pub struct MsgEphemerisQzss { pub iodc: u16, } -impl MsgEphemerisQzss { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisQzss{ sender_id: None, - common: EphemerisCommonContent::parse(_buf)?, - tgd: _buf.read_f32::()?, - c_rs: _buf.read_f32::()?, - c_rc: _buf.read_f32::()?, - c_uc: _buf.read_f32::()?, - c_us: _buf.read_f32::()?, - c_ic: _buf.read_f32::()?, - c_is: _buf.read_f32::()?, - dn: _buf.read_f64::()?, - m0: _buf.read_f64::()?, - ecc: _buf.read_f64::()?, - sqrta: _buf.read_f64::()?, - omega0: _buf.read_f64::()?, - omegadot: _buf.read_f64::()?, - w: _buf.read_f64::()?, - inc: _buf.read_f64::()?, - inc_dot: _buf.read_f64::()?, - af0: _buf.read_f32::()?, - af1: _buf.read_f32::()?, - af2: _buf.read_f32::()?, - toc: GPSTimeSec::parse(_buf)?, - iode: _buf.read_u8()?, - iodc: _buf.read_u16::()?, + common: self.parse()?, + tgd: self.parse()?, + c_rs: self.parse()?, + c_rc: self.parse()?, + c_uc: self.parse()?, + c_us: self.parse()?, + c_ic: self.parse()?, + c_is: self.parse()?, + dn: self.parse()?, + m0: self.parse()?, + ecc: self.parse()?, + sqrta: self.parse()?, + omega0: self.parse()?, + omegadot: self.parse()?, + w: self.parse()?, + inc: self.parse()?, + inc_dot: self.parse()?, + af0: self.parse()?, + af1: self.parse()?, + af2: self.parse()?, + toc: self.parse()?, + iode: self.parse()?, + iodc: self.parse()?, } ) } } @@ -3623,28 +3482,28 @@ pub struct MsgEphemerisSbas { /// Values common for all ephemeris types pub common: EphemerisCommonContent, /// Position of the GEO at time toe - pub pos: Vec, + pub pos: [f64; 3], /// Velocity of the GEO at time toe - pub vel: Vec, + pub vel: [f32; 3], /// Acceleration of the GEO at time toe - pub acc: Vec, + pub acc: [f32; 3], /// Time offset of the GEO clock w.r.t. SBAS Network Time pub a_gf0: f32, /// Drift of the GEO clock w.r.t. SBAS Network Time pub a_gf1: f32, } -impl MsgEphemerisSbas { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisSbas{ sender_id: None, - common: EphemerisCommonContent::parse(_buf)?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_float_array_limit(_buf, 3)?, - acc: crate::parser::read_float_array_limit(_buf, 3)?, - a_gf0: _buf.read_f32::()?, - a_gf1: _buf.read_f32::()?, + common: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, + a_gf0: self.parse()?, + a_gf1: self.parse()?, } ) } } @@ -3698,28 +3557,28 @@ pub struct MsgEphemerisSbasDepA { /// Values common for all ephemeris types pub common: EphemerisCommonContentDepA, /// Position of the GEO at time toe - pub pos: Vec, + pub pos: [f64; 3], /// Velocity of the GEO at time toe - pub vel: Vec, + pub vel: [f64; 3], /// Acceleration of the GEO at time toe - pub acc: Vec, + pub acc: [f64; 3], /// Time offset of the GEO clock w.r.t. SBAS Network Time pub a_gf0: f64, /// Drift of the GEO clock w.r.t. SBAS Network Time pub a_gf1: f64, } -impl MsgEphemerisSbasDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisSbasDepA{ sender_id: None, - common: EphemerisCommonContentDepA::parse(_buf)?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_double_array_limit(_buf, 3)?, - acc: crate::parser::read_double_array_limit(_buf, 3)?, - a_gf0: _buf.read_f64::()?, - a_gf1: _buf.read_f64::()?, + common: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, + a_gf0: self.parse()?, + a_gf1: self.parse()?, } ) } } @@ -3778,28 +3637,28 @@ pub struct MsgEphemerisSbasDepB { /// Values common for all ephemeris types pub common: EphemerisCommonContentDepB, /// Position of the GEO at time toe - pub pos: Vec, + pub pos: [f64; 3], /// Velocity of the GEO at time toe - pub vel: Vec, + pub vel: [f64; 3], /// Acceleration of the GEO at time toe - pub acc: Vec, + pub acc: [f64; 3], /// Time offset of the GEO clock w.r.t. SBAS Network Time pub a_gf0: f64, /// Drift of the GEO clock w.r.t. SBAS Network Time pub a_gf1: f64, } -impl MsgEphemerisSbasDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgEphemerisSbasDepB{ sender_id: None, - common: EphemerisCommonContentDepB::parse(_buf)?, - pos: crate::parser::read_double_array_limit(_buf, 3)?, - vel: crate::parser::read_double_array_limit(_buf, 3)?, - acc: crate::parser::read_double_array_limit(_buf, 3)?, - a_gf0: _buf.read_f64::()?, - a_gf1: _buf.read_f64::()?, + common: self.parse()?, + pos: self.parse()?, + vel: self.parse()?, + acc: self.parse()?, + a_gf0: self.parse()?, + a_gf1: self.parse()?, } ) } } @@ -3869,16 +3728,16 @@ pub struct MsgGloBiases { pub l2p_bias: i16, } -impl MsgGloBiases { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGloBiases{ sender_id: None, - mask: _buf.read_u8()?, - l1ca_bias: _buf.read_i16::()?, - l1p_bias: _buf.read_i16::()?, - l2ca_bias: _buf.read_i16::()?, - l2p_bias: _buf.read_i16::()?, + mask: self.parse()?, + l1ca_bias: self.parse()?, + l1p_bias: self.parse()?, + l2ca_bias: self.parse()?, + l2p_bias: self.parse()?, } ) } } @@ -3933,13 +3792,13 @@ pub struct MsgGnssCapb { pub gc: GnssCapb, } -impl MsgGnssCapb { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGnssCapb{ sender_id: None, - t_nmct: GPSTimeSec::parse(_buf)?, - gc: GnssCapb::parse(_buf)?, + t_nmct: self.parse()?, + gc: self.parse()?, } ) } } @@ -3998,17 +3857,17 @@ pub struct MsgGroupDelay { pub isc_l2c: i16, } -impl MsgGroupDelay { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGroupDelay{ sender_id: None, - t_op: GPSTimeSec::parse(_buf)?, - sid: GnssSignal::parse(_buf)?, - valid: _buf.read_u8()?, - tgd: _buf.read_i16::()?, - isc_l1ca: _buf.read_i16::()?, - isc_l2c: _buf.read_i16::()?, + t_op: self.parse()?, + sid: self.parse()?, + valid: self.parse()?, + tgd: self.parse()?, + isc_l1ca: self.parse()?, + isc_l2c: self.parse()?, } ) } } @@ -4075,17 +3934,17 @@ pub struct MsgGroupDelayDepA { pub isc_l2c: i16, } -impl MsgGroupDelayDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGroupDelayDepA{ sender_id: None, - t_op: GPSTimeDep::parse(_buf)?, - prn: _buf.read_u8()?, - valid: _buf.read_u8()?, - tgd: _buf.read_i16::()?, - isc_l1ca: _buf.read_i16::()?, - isc_l2c: _buf.read_i16::()?, + t_op: self.parse()?, + prn: self.parse()?, + valid: self.parse()?, + tgd: self.parse()?, + isc_l1ca: self.parse()?, + isc_l2c: self.parse()?, } ) } } @@ -4152,17 +4011,17 @@ pub struct MsgGroupDelayDepB { pub isc_l2c: i16, } -impl MsgGroupDelayDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGroupDelayDepB{ sender_id: None, - t_op: GPSTimeSec::parse(_buf)?, - sid: GnssSignalDep::parse(_buf)?, - valid: _buf.read_u8()?, - tgd: _buf.read_i16::()?, - isc_l1ca: _buf.read_i16::()?, - isc_l2c: _buf.read_i16::()?, + t_op: self.parse()?, + sid: self.parse()?, + valid: self.parse()?, + tgd: self.parse()?, + isc_l1ca: self.parse()?, + isc_l2c: self.parse()?, } ) } } @@ -4231,20 +4090,20 @@ pub struct MsgIono { pub b3: f64, } -impl MsgIono { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgIono{ sender_id: None, - t_nmct: GPSTimeSec::parse(_buf)?, - a0: _buf.read_f64::()?, - a1: _buf.read_f64::()?, - a2: _buf.read_f64::()?, - a3: _buf.read_f64::()?, - b0: _buf.read_f64::()?, - b1: _buf.read_f64::()?, - b2: _buf.read_f64::()?, - b3: _buf.read_f64::()?, + t_nmct: self.parse()?, + a0: self.parse()?, + a1: self.parse()?, + a2: self.parse()?, + a3: self.parse()?, + b0: self.parse()?, + b1: self.parse()?, + b2: self.parse()?, + b3: self.parse()?, } ) } } @@ -4317,13 +4176,13 @@ pub struct MsgObs { pub obs: Vec, } -impl MsgObs { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgObs{ sender_id: None, - header: ObservationHeader::parse(_buf)?, - obs: PackedObsContent::parse_array(_buf)?, + header: self.parse()?, + obs: self.parse()?, } ) } } @@ -4376,13 +4235,13 @@ pub struct MsgObsDepA { pub obs: Vec, } -impl MsgObsDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgObsDepA{ sender_id: None, - header: ObservationHeaderDep::parse(_buf)?, - obs: PackedObsContentDepA::parse_array(_buf)?, + header: self.parse()?, + obs: self.parse()?, } ) } } @@ -4440,13 +4299,13 @@ pub struct MsgObsDepB { pub obs: Vec, } -impl MsgObsDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgObsDepB{ sender_id: None, - header: ObservationHeaderDep::parse(_buf)?, - obs: PackedObsContentDepB::parse_array(_buf)?, + header: self.parse()?, + obs: self.parse()?, } ) } } @@ -4505,13 +4364,13 @@ pub struct MsgObsDepC { pub obs: Vec, } -impl MsgObsDepC { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgObsDepC{ sender_id: None, - header: ObservationHeaderDep::parse(_buf)?, - obs: PackedObsContentDepC::parse_array(_buf)?, + header: self.parse()?, + obs: self.parse()?, } ) } } @@ -4564,13 +4423,13 @@ pub struct MsgOsr { pub obs: Vec, } -impl MsgOsr { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgOsr{ sender_id: None, - header: ObservationHeader::parse(_buf)?, - obs: PackedOsrContent::parse_array(_buf)?, + header: self.parse()?, + obs: self.parse()?, } ) } } @@ -4622,12 +4481,12 @@ pub struct MsgSvAzEl { pub azel: Vec, } -impl MsgSvAzEl { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSvAzEl{ sender_id: None, - azel: SvAzEl::parse_array(_buf)?, + azel: self.parse()?, } ) } } @@ -4678,13 +4537,13 @@ pub struct MsgSvConfigurationGPSDep { pub l2c_mask: u32, } -impl MsgSvConfigurationGPSDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSvConfigurationGPSDep{ sender_id: None, - t_nmct: GPSTimeSec::parse(_buf)?, - l2c_mask: _buf.read_u32::()?, + t_nmct: self.parse()?, + l2c_mask: self.parse()?, } ) } } @@ -4737,32 +4596,14 @@ pub struct ObservationHeader { pub n_obs: u8, } -impl ObservationHeader { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( ObservationHeader{ - t: GPSTime::parse(_buf)?, - n_obs: _buf.read_u8()?, + t: self.parse()?, + n_obs: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(ObservationHeader::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(ObservationHeader::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for ObservationHeader { @@ -4795,32 +4636,14 @@ pub struct ObservationHeaderDep { pub n_obs: u8, } -impl ObservationHeaderDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( ObservationHeaderDep{ - t: GPSTimeDep::parse(_buf)?, - n_obs: _buf.read_u8()?, + t: self.parse()?, + n_obs: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(ObservationHeaderDep::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(ObservationHeaderDep::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for ObservationHeaderDep { @@ -4875,37 +4698,19 @@ pub struct PackedObsContent { pub sid: GnssSignal, } -impl PackedObsContent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( PackedObsContent{ - P: _buf.read_u32::()?, - L: CarrierPhase::parse(_buf)?, - D: Doppler::parse(_buf)?, - cn0: _buf.read_u8()?, - lock: _buf.read_u8()?, - flags: _buf.read_u8()?, - sid: GnssSignal::parse(_buf)?, + P: self.parse()?, + L: self.parse()?, + D: self.parse()?, + cn0: self.parse()?, + lock: self.parse()?, + flags: self.parse()?, + sid: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(PackedObsContent::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(PackedObsContent::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for PackedObsContent { @@ -4955,35 +4760,17 @@ pub struct PackedObsContentDepA { pub prn: u8, } -impl PackedObsContentDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( PackedObsContentDepA{ - P: _buf.read_u32::()?, - L: CarrierPhaseDepA::parse(_buf)?, - cn0: _buf.read_u8()?, - lock: _buf.read_u16::()?, - prn: _buf.read_u8()?, + P: self.parse()?, + L: self.parse()?, + cn0: self.parse()?, + lock: self.parse()?, + prn: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(PackedObsContentDepA::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(PackedObsContentDepA::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for PackedObsContentDepA { @@ -5030,35 +4817,17 @@ pub struct PackedObsContentDepB { pub sid: GnssSignalDep, } -impl PackedObsContentDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( PackedObsContentDepB{ - P: _buf.read_u32::()?, - L: CarrierPhaseDepA::parse(_buf)?, - cn0: _buf.read_u8()?, - lock: _buf.read_u16::()?, - sid: GnssSignalDep::parse(_buf)?, + P: self.parse()?, + L: self.parse()?, + cn0: self.parse()?, + lock: self.parse()?, + sid: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(PackedObsContentDepB::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(PackedObsContentDepB::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for PackedObsContentDepB { @@ -5106,35 +4875,17 @@ pub struct PackedObsContentDepC { pub sid: GnssSignalDep, } -impl PackedObsContentDepC { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( PackedObsContentDepC{ - P: _buf.read_u32::()?, - L: CarrierPhase::parse(_buf)?, - cn0: _buf.read_u8()?, - lock: _buf.read_u16::()?, - sid: GnssSignalDep::parse(_buf)?, + P: self.parse()?, + L: self.parse()?, + cn0: self.parse()?, + lock: self.parse()?, + sid: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(PackedObsContentDepC::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(PackedObsContentDepC::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for PackedObsContentDepC { @@ -5189,38 +4940,20 @@ pub struct PackedOsrContent { pub range_std: u16, } -impl PackedOsrContent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( PackedOsrContent{ - P: _buf.read_u32::()?, - L: CarrierPhase::parse(_buf)?, - lock: _buf.read_u8()?, - flags: _buf.read_u8()?, - sid: GnssSignal::parse(_buf)?, - iono_std: _buf.read_u16::()?, - tropo_std: _buf.read_u16::()?, - range_std: _buf.read_u16::()?, + P: self.parse()?, + L: self.parse()?, + lock: self.parse()?, + flags: self.parse()?, + sid: self.parse()?, + iono_std: self.parse()?, + tropo_std: self.parse()?, + range_std: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(PackedOsrContent::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(PackedOsrContent::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for PackedOsrContent { @@ -5266,30 +4999,15 @@ pub struct SvAzEl { pub el: i8, } -impl SvAzEl { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( SvAzEl{ - sid: GnssSignal::parse(_buf)?, - az: _buf.read_u8()?, - el: _buf.read_i8()?, + sid: self.parse()?, + az: self.parse()?, + el: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(SvAzEl::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(SvAzEl::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for SvAzEl { diff --git a/rust/sbp/src/messages/orientation.rs b/rust/sbp/src/messages/orientation.rs index 4edeb4fb09..075cb0d58d 100644 --- a/rust/sbp/src/messages/orientation.rs +++ b/rust/sbp/src/messages/orientation.rs @@ -14,14 +14,11 @@ //****************************************************************************/ //! Orientation Messages -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Vehicle Body Frame instantaneous angular rates /// @@ -52,16 +49,16 @@ pub struct MsgAngularRate { pub flags: u8, } -impl MsgAngularRate { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAngularRate{ sender_id: None, - tow: _buf.read_u32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + flags: self.parse()?, } ) } } @@ -127,15 +124,15 @@ pub struct MsgBaselineHeading { pub flags: u8, } -impl MsgBaselineHeading { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgBaselineHeading{ sender_id: None, - tow: _buf.read_u32::()?, - heading: _buf.read_u32::()?, - n_sats: _buf.read_u8()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + heading: self.parse()?, + n_sats: self.parse()?, + flags: self.parse()?, } ) } } @@ -208,19 +205,19 @@ pub struct MsgOrientEuler { pub flags: u8, } -impl MsgOrientEuler { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgOrientEuler{ sender_id: None, - tow: _buf.read_u32::()?, - roll: _buf.read_i32::()?, - pitch: _buf.read_i32::()?, - yaw: _buf.read_i32::()?, - roll_accuracy: _buf.read_f32::()?, - pitch_accuracy: _buf.read_f32::()?, - yaw_accuracy: _buf.read_f32::()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + roll: self.parse()?, + pitch: self.parse()?, + yaw: self.parse()?, + roll_accuracy: self.parse()?, + pitch_accuracy: self.parse()?, + yaw_accuracy: self.parse()?, + flags: self.parse()?, } ) } } @@ -305,21 +302,21 @@ pub struct MsgOrientQuat { pub flags: u8, } -impl MsgOrientQuat { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgOrientQuat{ sender_id: None, - tow: _buf.read_u32::()?, - w: _buf.read_i32::()?, - x: _buf.read_i32::()?, - y: _buf.read_i32::()?, - z: _buf.read_i32::()?, - w_accuracy: _buf.read_f32::()?, - x_accuracy: _buf.read_f32::()?, - y_accuracy: _buf.read_f32::()?, - z_accuracy: _buf.read_f32::()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + w: self.parse()?, + x: self.parse()?, + y: self.parse()?, + z: self.parse()?, + w_accuracy: self.parse()?, + x_accuracy: self.parse()?, + y_accuracy: self.parse()?, + z_accuracy: self.parse()?, + flags: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/piksi.rs b/rust/sbp/src/messages/piksi.rs index 5607d03bf9..90942b4586 100644 --- a/rust/sbp/src/messages/piksi.rs +++ b/rust/sbp/src/messages/piksi.rs @@ -17,15 +17,12 @@ //! may no longer be used. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; use super::gnss::*; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Receiver-to-base station latency /// @@ -49,31 +46,16 @@ pub struct Latency { pub current: i32, } -impl Latency { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( Latency{ - avg: _buf.read_i32::()?, - lmin: _buf.read_i32::()?, - lmax: _buf.read_i32::()?, - current: _buf.read_i32::()?, + avg: self.parse()?, + lmin: self.parse()?, + lmax: self.parse()?, + current: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(Latency::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(Latency::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for Latency { @@ -107,9 +89,9 @@ pub struct MsgAlmanac { pub sender_id: Option, } -impl MsgAlmanac { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgAlmanac{ sender_id: None, } ) @@ -162,14 +144,14 @@ pub struct MsgCellModemStatus { pub reserved: Vec, } -impl MsgCellModemStatus { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCellModemStatus{ sender_id: None, - signal_strength: _buf.read_i8()?, - signal_error_rate: _buf.read_f32::()?, - reserved: crate::parser::read_u8_array(_buf)?, + signal_strength: self.parse()?, + signal_error_rate: self.parse()?, + reserved: self.parse()?, } ) } } @@ -224,16 +206,16 @@ pub struct MsgCommandOutput { /// Sequence number pub sequence: u32, /// Line of standard output or standard error - pub line: SbpString, + pub line: UnboundedSbpString, } -impl MsgCommandOutput { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCommandOutput{ sender_id: None, - sequence: _buf.read_u32::()?, - line: crate::parser::read_string(_buf)?, + sequence: self.parse()?, + line: self.parse()?, } ) } } @@ -285,16 +267,16 @@ pub struct MsgCommandReq { /// Sequence number pub sequence: u32, /// Command line to execute - pub command: SbpString, + pub command: UnboundedSbpString, } -impl MsgCommandReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCommandReq{ sender_id: None, - sequence: _buf.read_u32::()?, - command: crate::parser::read_string(_buf)?, + sequence: self.parse()?, + command: self.parse()?, } ) } } @@ -348,13 +330,13 @@ pub struct MsgCommandResp { pub code: i32, } -impl MsgCommandResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCommandResp{ sender_id: None, - sequence: _buf.read_u32::()?, - code: _buf.read_i32::()?, + sequence: self.parse()?, + code: self.parse()?, } ) } } @@ -405,9 +387,9 @@ pub struct MsgCwResults { pub sender_id: Option, } -impl MsgCwResults { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCwResults{ sender_id: None, } ) @@ -454,9 +436,9 @@ pub struct MsgCwStart { pub sender_id: Option, } -impl MsgCwStart { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCwStart{ sender_id: None, } ) @@ -513,16 +495,16 @@ pub struct MsgDeviceMonitor { pub fe_temperature: i16, } -impl MsgDeviceMonitor { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgDeviceMonitor{ sender_id: None, - dev_vin: _buf.read_i16::()?, - cpu_vint: _buf.read_i16::()?, - cpu_vaux: _buf.read_i16::()?, - cpu_temperature: _buf.read_i16::()?, - fe_temperature: _buf.read_i16::()?, + dev_vin: self.parse()?, + cpu_vint: self.parse()?, + cpu_vaux: self.parse()?, + cpu_temperature: self.parse()?, + fe_temperature: self.parse()?, } ) } } @@ -581,18 +563,18 @@ impl crate::serialize::SbpSerialize for MsgDeviceMonitor { pub struct MsgFrontEndGain { pub sender_id: Option, /// RF gain for each frontend channel - pub rf_gain: Vec, + pub rf_gain: [i8; 8], /// Intermediate frequency gain for each frontend channel - pub if_gain: Vec, + pub if_gain: [i8; 8], } -impl MsgFrontEndGain { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgFrontEndGain{ sender_id: None, - rf_gain: crate::parser::read_s8_array_limit(_buf, 8)?, - if_gain: crate::parser::read_s8_array_limit(_buf, 8)?, + rf_gain: self.parse()?, + if_gain: self.parse()?, } ) } } @@ -646,12 +628,12 @@ pub struct MsgIarState { pub num_hyps: u32, } -impl MsgIarState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgIarState{ sender_id: None, - num_hyps: _buf.read_u32::()?, + num_hyps: self.parse()?, } ) } } @@ -698,9 +680,9 @@ pub struct MsgInitBaseDep { pub sender_id: Option, } -impl MsgInitBaseDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgInitBaseDep{ sender_id: None, } ) @@ -750,13 +732,13 @@ pub struct MsgMaskSatellite { pub sid: GnssSignal, } -impl MsgMaskSatellite { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgMaskSatellite{ sender_id: None, - mask: _buf.read_u8()?, - sid: GnssSignal::parse(_buf)?, + mask: self.parse()?, + sid: self.parse()?, } ) } } @@ -809,13 +791,13 @@ pub struct MsgMaskSatelliteDep { pub sid: GnssSignalDep, } -impl MsgMaskSatelliteDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgMaskSatelliteDep{ sender_id: None, - mask: _buf.read_u8()?, - sid: GnssSignalDep::parse(_buf)?, + mask: self.parse()?, + sid: self.parse()?, } ) } } @@ -866,12 +848,12 @@ pub struct MsgNetworkBandwidthUsage { pub interfaces: Vec, } -impl MsgNetworkBandwidthUsage { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgNetworkBandwidthUsage{ sender_id: None, - interfaces: NetworkUsage::parse_array(_buf)?, + interfaces: self.parse()?, } ) } } @@ -919,9 +901,9 @@ pub struct MsgNetworkStateReq { pub sender_id: Option, } -impl MsgNetworkStateReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgNetworkStateReq{ sender_id: None, } ) @@ -967,11 +949,11 @@ impl crate::serialize::SbpSerialize for MsgNetworkStateReq { pub struct MsgNetworkStateResp { pub sender_id: Option, /// IPv4 address (all zero when unavailable) - pub ipv4_address: Vec, + pub ipv4_address: [u8; 4], /// IPv4 netmask CIDR notation pub ipv4_mask_size: u8, /// IPv6 address (all zero when unavailable) - pub ipv6_address: Vec, + pub ipv6_address: [u8; 16], /// IPv6 netmask CIDR notation pub ipv6_mask_size: u8, /// Number of Rx bytes @@ -979,24 +961,24 @@ pub struct MsgNetworkStateResp { /// Number of Tx bytes pub tx_bytes: u32, /// Interface Name - pub interface_name: SbpString, + pub interface_name: BoundedSbpString<16>, /// Interface flags from SIOCGIFFLAGS pub flags: u32, } -impl MsgNetworkStateResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgNetworkStateResp{ sender_id: None, - ipv4_address: crate::parser::read_u8_array_limit(_buf, 4)?, - ipv4_mask_size: _buf.read_u8()?, - ipv6_address: crate::parser::read_u8_array_limit(_buf, 16)?, - ipv6_mask_size: _buf.read_u8()?, - rx_bytes: _buf.read_u32::()?, - tx_bytes: _buf.read_u32::()?, - interface_name: crate::parser::read_string_limit(_buf, 16)?, - flags: _buf.read_u32::()?, + ipv4_address: self.parse()?, + ipv4_mask_size: self.parse()?, + ipv6_address: self.parse()?, + ipv6_mask_size: self.parse()?, + rx_bytes: self.parse()?, + tx_bytes: self.parse()?, + interface_name: self.parse()?, + flags: self.parse()?, } ) } } @@ -1060,12 +1042,12 @@ pub struct MsgReset { pub flags: u32, } -impl MsgReset { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgReset{ sender_id: None, - flags: _buf.read_u32::()?, + flags: self.parse()?, } ) } } @@ -1113,9 +1095,9 @@ pub struct MsgResetDep { pub sender_id: Option, } -impl MsgResetDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgResetDep{ sender_id: None, } ) @@ -1163,12 +1145,12 @@ pub struct MsgResetFilters { pub filter: u8, } -impl MsgResetFilters { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgResetFilters{ sender_id: None, - filter: _buf.read_u8()?, + filter: self.parse()?, } ) } } @@ -1216,9 +1198,9 @@ pub struct MsgSetTime { pub sender_id: Option, } -impl MsgSetTime { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSetTime{ sender_id: None, } ) @@ -1277,18 +1259,18 @@ pub struct MsgSpecan { pub amplitude_value: Vec, } -impl MsgSpecan { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSpecan{ sender_id: None, - channel_tag: _buf.read_u16::()?, - t: GPSTime::parse(_buf)?, - freq_ref: _buf.read_f32::()?, - freq_step: _buf.read_f32::()?, - amplitude_ref: _buf.read_f32::()?, - amplitude_unit: _buf.read_f32::()?, - amplitude_value: crate::parser::read_u8_array(_buf)?, + channel_tag: self.parse()?, + t: self.parse()?, + freq_ref: self.parse()?, + freq_step: self.parse()?, + amplitude_ref: self.parse()?, + amplitude_unit: self.parse()?, + amplitude_value: self.parse()?, } ) } } @@ -1361,18 +1343,18 @@ pub struct MsgSpecanDep { pub amplitude_value: Vec, } -impl MsgSpecanDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSpecanDep{ sender_id: None, - channel_tag: _buf.read_u16::()?, - t: GPSTimeDep::parse(_buf)?, - freq_ref: _buf.read_f32::()?, - freq_step: _buf.read_f32::()?, - amplitude_ref: _buf.read_f32::()?, - amplitude_unit: _buf.read_f32::()?, - amplitude_value: crate::parser::read_u8_array(_buf)?, + channel_tag: self.parse()?, + t: self.parse()?, + freq_ref: self.parse()?, + freq_step: self.parse()?, + amplitude_ref: self.parse()?, + amplitude_unit: self.parse()?, + amplitude_value: self.parse()?, } ) } } @@ -1432,7 +1414,7 @@ impl crate::serialize::SbpSerialize for MsgSpecanDep { pub struct MsgThreadState { pub sender_id: Option, /// Thread name (NULL terminated) - pub name: SbpString, + pub name: BoundedSbpString<20>, /// Percentage cpu use for this thread. Values range from 0 - 1000 and needs /// to be renormalized to 100 pub cpu: u16, @@ -1440,14 +1422,14 @@ pub struct MsgThreadState { pub stack_free: u32, } -impl MsgThreadState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgThreadState{ sender_id: None, - name: crate::parser::read_string_limit(_buf, 20)?, - cpu: _buf.read_u16::()?, - stack_free: _buf.read_u32::()?, + name: self.parse()?, + cpu: self.parse()?, + stack_free: self.parse()?, } ) } } @@ -1516,16 +1498,16 @@ pub struct MsgUartState { pub obs_period: Period, } -impl MsgUartState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgUartState{ sender_id: None, - uart_a: UARTChannel::parse(_buf)?, - uart_b: UARTChannel::parse(_buf)?, - uart_ftdi: UARTChannel::parse(_buf)?, - latency: Latency::parse(_buf)?, - obs_period: Period::parse(_buf)?, + uart_a: self.parse()?, + uart_b: self.parse()?, + uart_ftdi: self.parse()?, + latency: self.parse()?, + obs_period: self.parse()?, } ) } } @@ -1588,15 +1570,15 @@ pub struct MsgUartStateDepa { pub latency: Latency, } -impl MsgUartStateDepa { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgUartStateDepa{ sender_id: None, - uart_a: UARTChannel::parse(_buf)?, - uart_b: UARTChannel::parse(_buf)?, - uart_ftdi: UARTChannel::parse(_buf)?, - latency: Latency::parse(_buf)?, + uart_a: self.parse()?, + uart_b: self.parse()?, + uart_ftdi: self.parse()?, + latency: self.parse()?, } ) } } @@ -1660,35 +1642,20 @@ pub struct NetworkUsage { /// Number of bytes received within period pub tx_bytes: u32, /// Interface Name - pub interface_name: SbpString, + pub interface_name: BoundedSbpString<16>, } -impl NetworkUsage { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( NetworkUsage{ - duration: _buf.read_u64::()?, - total_bytes: _buf.read_u64::()?, - rx_bytes: _buf.read_u32::()?, - tx_bytes: _buf.read_u32::()?, - interface_name: crate::parser::read_string_limit(_buf, 16)?, + duration: self.parse()?, + total_bytes: self.parse()?, + rx_bytes: self.parse()?, + tx_bytes: self.parse()?, + interface_name: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(NetworkUsage::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(NetworkUsage::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for NetworkUsage { @@ -1735,31 +1702,16 @@ pub struct Period { pub current: i32, } -impl Period { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( Period{ - avg: _buf.read_i32::()?, - pmin: _buf.read_i32::()?, - pmax: _buf.read_i32::()?, - current: _buf.read_i32::()?, + avg: self.parse()?, + pmin: self.parse()?, + pmax: self.parse()?, + current: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(Period::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(Period::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for Period { @@ -1805,33 +1757,18 @@ pub struct UARTChannel { pub rx_buffer_level: u8, } -impl UARTChannel { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( UARTChannel{ - tx_throughput: _buf.read_f32::()?, - rx_throughput: _buf.read_f32::()?, - crc_error_count: _buf.read_u16::()?, - io_error_count: _buf.read_u16::()?, - tx_buffer_level: _buf.read_u8()?, - rx_buffer_level: _buf.read_u8()?, + tx_throughput: self.parse()?, + rx_throughput: self.parse()?, + crc_error_count: self.parse()?, + io_error_count: self.parse()?, + tx_buffer_level: self.parse()?, + rx_buffer_level: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(UARTChannel::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(UARTChannel::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for UARTChannel { diff --git a/rust/sbp/src/messages/sbas.rs b/rust/sbp/src/messages/sbas.rs index 14467cedb2..34e882d77d 100644 --- a/rust/sbp/src/messages/sbas.rs +++ b/rust/sbp/src/messages/sbas.rs @@ -14,15 +14,12 @@ //****************************************************************************/ //! SBAS data -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; use super::gnss::*; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Raw SBAS data /// @@ -41,18 +38,18 @@ pub struct MsgSbasRaw { /// SBAS message type (0-63) pub message_type: u8, /// Raw SBAS data field of 212 bits (last byte padded with zeros). - pub data: Vec, + pub data: [u8; 27], } -impl MsgSbasRaw { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSbasRaw{ sender_id: None, - sid: GnssSignal::parse(_buf)?, - tow: _buf.read_u32::()?, - message_type: _buf.read_u8()?, - data: crate::parser::read_u8_array_limit(_buf, 27)?, + sid: self.parse()?, + tow: self.parse()?, + message_type: self.parse()?, + data: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/settings.rs b/rust/sbp/src/messages/settings.rs index 08357e1881..69e75beb15 100644 --- a/rust/sbp/src/messages/settings.rs +++ b/rust/sbp/src/messages/settings.rs @@ -40,14 +40,11 @@ //! reference and example. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Finished reading settings (host <= device) /// @@ -60,9 +57,9 @@ pub struct MsgSettingsReadByIndexDone { pub sender_id: Option, } -impl MsgSettingsReadByIndexDone { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsReadByIndexDone{ sender_id: None, } ) @@ -112,12 +109,12 @@ pub struct MsgSettingsReadByIndexReq { pub index: u16, } -impl MsgSettingsReadByIndexReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsReadByIndexReq{ sender_id: None, - index: _buf.read_u16::()?, + index: self.parse()?, } ) } } @@ -176,16 +173,16 @@ pub struct MsgSettingsReadByIndexResp { pub index: u16, /// A NULL-terminated and delimited string with contents /// "SECTION_SETTING\0SETTING\0VALUE\0FORMAT_TYPE\0" - pub setting: SbpString, + pub setting: UnboundedSbpString, } -impl MsgSettingsReadByIndexResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsReadByIndexResp{ sender_id: None, - index: _buf.read_u16::()?, - setting: crate::parser::read_string(_buf)?, + index: self.parse()?, + setting: self.parse()?, } ) } } @@ -241,15 +238,15 @@ pub struct MsgSettingsReadReq { pub sender_id: Option, /// A NULL-terminated and NULL-delimited string with contents /// "SECTION_SETTING\0SETTING\0" - pub setting: SbpString, + pub setting: UnboundedSbpString, } -impl MsgSettingsReadReq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsReadReq{ sender_id: None, - setting: crate::parser::read_string(_buf)?, + setting: self.parse()?, } ) } } @@ -302,15 +299,15 @@ pub struct MsgSettingsReadResp { pub sender_id: Option, /// A NULL-terminated and NULL-delimited string with contents /// "SECTION_SETTING\0SETTING\0VALUE\0" - pub setting: SbpString, + pub setting: UnboundedSbpString, } -impl MsgSettingsReadResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsReadResp{ sender_id: None, - setting: crate::parser::read_string(_buf)?, + setting: self.parse()?, } ) } } @@ -359,15 +356,15 @@ pub struct MsgSettingsRegister { pub sender_id: Option, /// A NULL-terminated and delimited string with contents /// "SECTION_SETTING\0SETTING\0VALUE". - pub setting: SbpString, + pub setting: UnboundedSbpString, } -impl MsgSettingsRegister { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsRegister{ sender_id: None, - setting: crate::parser::read_string(_buf)?, + setting: self.parse()?, } ) } } @@ -420,16 +417,16 @@ pub struct MsgSettingsRegisterResp { /// A NULL-terminated and delimited string with contents /// "SECTION_SETTING\0SETTING\0VALUE". The meaning of value is defined /// according to the status field. - pub setting: SbpString, + pub setting: UnboundedSbpString, } -impl MsgSettingsRegisterResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsRegisterResp{ sender_id: None, - status: _buf.read_u8()?, - setting: crate::parser::read_string(_buf)?, + status: self.parse()?, + setting: self.parse()?, } ) } } @@ -479,9 +476,9 @@ pub struct MsgSettingsSave { pub sender_id: Option, } -impl MsgSettingsSave { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsSave{ sender_id: None, } ) @@ -532,15 +529,15 @@ pub struct MsgSettingsWrite { pub sender_id: Option, /// A NULL-terminated and NULL-delimited string with contents /// "SECTION_SETTING\0SETTING\0VALUE\0" - pub setting: SbpString, + pub setting: UnboundedSbpString, } -impl MsgSettingsWrite { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsWrite{ sender_id: None, - setting: crate::parser::read_string(_buf)?, + setting: self.parse()?, } ) } } @@ -595,16 +592,16 @@ pub struct MsgSettingsWriteResp { pub status: u8, /// A NULL-terminated and delimited string with contents /// "SECTION_SETTING\0SETTING\0VALUE\0" - pub setting: SbpString, + pub setting: UnboundedSbpString, } -impl MsgSettingsWriteResp { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSettingsWriteResp{ sender_id: None, - status: _buf.read_u8()?, - setting: crate::parser::read_string(_buf)?, + status: self.parse()?, + setting: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/solution_meta.rs b/rust/sbp/src/messages/solution_meta.rs index 485e2d45b4..eadc0c292d 100644 --- a/rust/sbp/src/messages/solution_meta.rs +++ b/rust/sbp/src/messages/solution_meta.rs @@ -14,14 +14,11 @@ //****************************************************************************/ //! Standardized Metadata messages for Fuzed Solution from Swift Navigation devices. -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Instruments the physical type of GNSS sensor input to the fuzed solution. /// @@ -36,31 +33,13 @@ pub struct GNSSInputType { pub flags: u8, } -impl GNSSInputType { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GNSSInputType{ - flags: _buf.read_u8()?, + flags: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GNSSInputType::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GNSSInputType::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GNSSInputType { @@ -89,28 +68,13 @@ pub struct IMUInputType { pub flags: u8, } -impl IMUInputType { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( IMUInputType{ - flags: _buf.read_u8()?, + flags: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(IMUInputType::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(IMUInputType::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for IMUInputType { @@ -164,18 +128,18 @@ pub struct MsgSolnMeta { pub sol_in: Vec, } -impl MsgSolnMeta { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSolnMeta{ sender_id: None, - tow: _buf.read_u32::()?, - pdop: _buf.read_u16::()?, - hdop: _buf.read_u16::()?, - vdop: _buf.read_u16::()?, - age_corrections: _buf.read_u16::()?, - age_gnss: _buf.read_u32::()?, - sol_in: SolutionInputType::parse_array(_buf)?, + tow: self.parse()?, + pdop: self.parse()?, + hdop: self.parse()?, + vdop: self.parse()?, + age_corrections: self.parse()?, + age_gnss: self.parse()?, + sol_in: self.parse()?, } ) } } @@ -261,20 +225,20 @@ pub struct MsgSolnMetaDepA { pub sol_in: Vec, } -impl MsgSolnMetaDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSolnMetaDepA{ sender_id: None, - pdop: _buf.read_u16::()?, - hdop: _buf.read_u16::()?, - vdop: _buf.read_u16::()?, - n_sats: _buf.read_u8()?, - age_corrections: _buf.read_u16::()?, - alignment_status: _buf.read_u8()?, - last_used_gnss_pos_tow: _buf.read_u32::()?, - last_used_gnss_vel_tow: _buf.read_u32::()?, - sol_in: SolutionInputType::parse_array(_buf)?, + pdop: self.parse()?, + hdop: self.parse()?, + vdop: self.parse()?, + n_sats: self.parse()?, + age_corrections: self.parse()?, + alignment_status: self.parse()?, + last_used_gnss_pos_tow: self.parse()?, + last_used_gnss_vel_tow: self.parse()?, + sol_in: self.parse()?, } ) } } @@ -339,28 +303,13 @@ pub struct OdoInputType { pub flags: u8, } -impl OdoInputType { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( OdoInputType{ - flags: _buf.read_u8()?, + flags: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(OdoInputType::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(OdoInputType::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for OdoInputType { @@ -395,32 +344,14 @@ pub struct SolutionInputType { pub flags: u8, } -impl SolutionInputType { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( SolutionInputType{ - sensor_type: _buf.read_u8()?, - flags: _buf.read_u8()?, + sensor_type: self.parse()?, + flags: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(SolutionInputType::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(SolutionInputType::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for SolutionInputType { diff --git a/rust/sbp/src/messages/ssr.rs b/rust/sbp/src/messages/ssr.rs index 86006a7978..512f5472cb 100644 --- a/rust/sbp/src/messages/ssr.rs +++ b/rust/sbp/src/messages/ssr.rs @@ -14,15 +14,12 @@ //****************************************************************************/ //! Precise State Space Representation (SSR) corrections format -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; use super::gnss::*; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// SSR code biases corrections for a particular satellite. /// @@ -39,32 +36,14 @@ pub struct CodeBiasesContent { pub value: i16, } -impl CodeBiasesContent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( CodeBiasesContent{ - code: _buf.read_u8()?, - value: _buf.read_i16::()?, + code: self.parse()?, + value: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(CodeBiasesContent::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(CodeBiasesContent::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for CodeBiasesContent { @@ -107,36 +86,18 @@ pub struct GridDefinitionHeaderDepA { pub seq_num: u8, } -impl GridDefinitionHeaderDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GridDefinitionHeaderDepA{ - region_size_inverse: _buf.read_u8()?, - area_width: _buf.read_u16::()?, - lat_nw_corner_enc: _buf.read_u16::()?, - lon_nw_corner_enc: _buf.read_u16::()?, - num_msgs: _buf.read_u8()?, - seq_num: _buf.read_u8()?, + region_size_inverse: self.parse()?, + area_width: self.parse()?, + lat_nw_corner_enc: self.parse()?, + lon_nw_corner_enc: self.parse()?, + num_msgs: self.parse()?, + seq_num: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GridDefinitionHeaderDepA::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GridDefinitionHeaderDepA::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GridDefinitionHeaderDepA { @@ -179,30 +140,15 @@ pub struct GridElement { pub stec_residuals: Vec, } -impl GridElement { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GridElement{ - index: _buf.read_u16::()?, - tropo_delay_correction: TroposphericDelayCorrection::parse(_buf)?, - stec_residuals: STECResidual::parse_array(_buf)?, + index: self.parse()?, + tropo_delay_correction: self.parse()?, + stec_residuals: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GridElement::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GridElement::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GridElement { @@ -239,33 +185,15 @@ pub struct GridElementNoStd { pub stec_residuals: Vec, } -impl GridElementNoStd { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GridElementNoStd{ - index: _buf.read_u16::()?, - tropo_delay_correction: TroposphericDelayCorrectionNoStd::parse(_buf)?, - stec_residuals: STECResidualNoStd::parse_array(_buf)?, + index: self.parse()?, + tropo_delay_correction: self.parse()?, + stec_residuals: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GridElementNoStd::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GridElementNoStd::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GridElementNoStd { @@ -315,38 +243,20 @@ pub struct GriddedCorrectionHeader { pub tropo_quality_indicator: u8, } -impl GriddedCorrectionHeader { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GriddedCorrectionHeader{ - tile_set_id: _buf.read_u16::()?, - tile_id: _buf.read_u16::()?, - time: GPSTimeSec::parse(_buf)?, - num_msgs: _buf.read_u16::()?, - seq_num: _buf.read_u16::()?, - update_interval: _buf.read_u8()?, - iod_atmo: _buf.read_u8()?, - tropo_quality_indicator: _buf.read_u8()?, + tile_set_id: self.parse()?, + tile_id: self.parse()?, + time: self.parse()?, + num_msgs: self.parse()?, + seq_num: self.parse()?, + update_interval: self.parse()?, + iod_atmo: self.parse()?, + tropo_quality_indicator: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GriddedCorrectionHeader::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GriddedCorrectionHeader::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GriddedCorrectionHeader { @@ -402,36 +312,18 @@ pub struct GriddedCorrectionHeaderDepA { pub tropo_quality_indicator: u8, } -impl GriddedCorrectionHeaderDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( GriddedCorrectionHeaderDepA{ - time: GPSTimeSec::parse(_buf)?, - num_msgs: _buf.read_u16::()?, - seq_num: _buf.read_u16::()?, - update_interval: _buf.read_u8()?, - iod_atmo: _buf.read_u8()?, - tropo_quality_indicator: _buf.read_u8()?, + time: self.parse()?, + num_msgs: self.parse()?, + seq_num: self.parse()?, + update_interval: self.parse()?, + iod_atmo: self.parse()?, + tropo_quality_indicator: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(GriddedCorrectionHeaderDepA::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(GriddedCorrectionHeaderDepA::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for GriddedCorrectionHeaderDepA { @@ -483,16 +375,16 @@ pub struct MsgSsrCodeBiases { pub biases: Vec, } -impl MsgSsrCodeBiases { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrCodeBiases{ sender_id: None, - time: GPSTimeSec::parse(_buf)?, - sid: GnssSignal::parse(_buf)?, - update_interval: _buf.read_u8()?, - iod_ssr: _buf.read_u8()?, - biases: CodeBiasesContent::parse_array(_buf)?, + time: self.parse()?, + sid: self.parse()?, + update_interval: self.parse()?, + iod_ssr: self.parse()?, + biases: self.parse()?, } ) } } @@ -553,13 +445,13 @@ pub struct MsgSsrGriddedCorrection { pub element: GridElement, } -impl MsgSsrGriddedCorrection { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrGriddedCorrection{ sender_id: None, - header: GriddedCorrectionHeader::parse(_buf)?, - element: GridElement::parse(_buf)?, + header: self.parse()?, + element: self.parse()?, } ) } } @@ -609,13 +501,13 @@ pub struct MsgSsrGriddedCorrectionDepA { pub element: GridElement, } -impl MsgSsrGriddedCorrectionDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrGriddedCorrectionDepA{ sender_id: None, - header: GriddedCorrectionHeaderDepA::parse(_buf)?, - element: GridElement::parse(_buf)?, + header: self.parse()?, + element: self.parse()?, } ) } } @@ -664,13 +556,13 @@ pub struct MsgSsrGriddedCorrectionNoStdDepA { pub element: GridElementNoStd, } -impl MsgSsrGriddedCorrectionNoStdDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrGriddedCorrectionNoStdDepA{ sender_id: None, - header: GriddedCorrectionHeaderDepA::parse(_buf)?, - element: GridElementNoStd::parse(_buf)?, + header: self.parse()?, + element: self.parse()?, } ) } } @@ -722,13 +614,13 @@ pub struct MsgSsrGridDefinitionDepA { pub rle_list: Vec, } -impl MsgSsrGridDefinitionDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrGridDefinitionDepA{ sender_id: None, - header: GridDefinitionHeaderDepA::parse(_buf)?, - rle_list: crate::parser::read_u8_array(_buf)?, + header: self.parse()?, + rle_list: self.parse()?, } ) } } @@ -810,25 +702,25 @@ pub struct MsgSsrOrbitClock { pub c2: i32, } -impl MsgSsrOrbitClock { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrOrbitClock{ sender_id: None, - time: GPSTimeSec::parse(_buf)?, - sid: GnssSignal::parse(_buf)?, - update_interval: _buf.read_u8()?, - iod_ssr: _buf.read_u8()?, - iod: _buf.read_u32::()?, - radial: _buf.read_i32::()?, - along: _buf.read_i32::()?, - cross: _buf.read_i32::()?, - dot_radial: _buf.read_i32::()?, - dot_along: _buf.read_i32::()?, - dot_cross: _buf.read_i32::()?, - c0: _buf.read_i32::()?, - c1: _buf.read_i32::()?, - c2: _buf.read_i32::()?, + time: self.parse()?, + sid: self.parse()?, + update_interval: self.parse()?, + iod_ssr: self.parse()?, + iod: self.parse()?, + radial: self.parse()?, + along: self.parse()?, + cross: self.parse()?, + dot_radial: self.parse()?, + dot_along: self.parse()?, + dot_cross: self.parse()?, + c0: self.parse()?, + c1: self.parse()?, + c2: self.parse()?, } ) } } @@ -927,25 +819,25 @@ pub struct MsgSsrOrbitClockDepA { pub c2: i32, } -impl MsgSsrOrbitClockDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrOrbitClockDepA{ sender_id: None, - time: GPSTimeSec::parse(_buf)?, - sid: GnssSignal::parse(_buf)?, - update_interval: _buf.read_u8()?, - iod_ssr: _buf.read_u8()?, - iod: _buf.read_u8()?, - radial: _buf.read_i32::()?, - along: _buf.read_i32::()?, - cross: _buf.read_i32::()?, - dot_radial: _buf.read_i32::()?, - dot_along: _buf.read_i32::()?, - dot_cross: _buf.read_i32::()?, - c0: _buf.read_i32::()?, - c1: _buf.read_i32::()?, - c2: _buf.read_i32::()?, + time: self.parse()?, + sid: self.parse()?, + update_interval: self.parse()?, + iod_ssr: self.parse()?, + iod: self.parse()?, + radial: self.parse()?, + along: self.parse()?, + cross: self.parse()?, + dot_radial: self.parse()?, + dot_along: self.parse()?, + dot_cross: self.parse()?, + c0: self.parse()?, + c1: self.parse()?, + c2: self.parse()?, } ) } } @@ -1043,20 +935,20 @@ pub struct MsgSsrPhaseBiases { pub biases: Vec, } -impl MsgSsrPhaseBiases { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrPhaseBiases{ sender_id: None, - time: GPSTimeSec::parse(_buf)?, - sid: GnssSignal::parse(_buf)?, - update_interval: _buf.read_u8()?, - iod_ssr: _buf.read_u8()?, - dispersive_bias: _buf.read_u8()?, - mw_consistency: _buf.read_u8()?, - yaw: _buf.read_u16::()?, - yaw_rate: _buf.read_i8()?, - biases: PhaseBiasesContent::parse_array(_buf)?, + time: self.parse()?, + sid: self.parse()?, + update_interval: self.parse()?, + iod_ssr: self.parse()?, + dispersive_bias: self.parse()?, + mw_consistency: self.parse()?, + yaw: self.parse()?, + yaw_rate: self.parse()?, + biases: self.parse()?, } ) } } @@ -1128,13 +1020,13 @@ pub struct MsgSsrStecCorrection { pub stec_sat_list: Vec, } -impl MsgSsrStecCorrection { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrStecCorrection{ sender_id: None, - header: STECHeader::parse(_buf)?, - stec_sat_list: STECSatElement::parse_array(_buf)?, + header: self.parse()?, + stec_sat_list: self.parse()?, } ) } } @@ -1183,13 +1075,13 @@ pub struct MsgSsrStecCorrectionDepA { pub stec_sat_list: Vec, } -impl MsgSsrStecCorrectionDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrStecCorrectionDepA{ sender_id: None, - header: STECHeaderDepA::parse(_buf)?, - stec_sat_list: STECSatElement::parse_array(_buf)?, + header: self.parse()?, + stec_sat_list: self.parse()?, } ) } } @@ -1283,20 +1175,20 @@ pub struct MsgSsrTileDefinition { pub bitmask: u64, } -impl MsgSsrTileDefinition { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgSsrTileDefinition{ sender_id: None, - tile_set_id: _buf.read_u16::()?, - tile_id: _buf.read_u16::()?, - corner_nw_lat: _buf.read_i16::()?, - corner_nw_lon: _buf.read_i16::()?, - spacing_lat: _buf.read_u16::()?, - spacing_lon: _buf.read_u16::()?, - rows: _buf.read_u16::()?, - cols: _buf.read_u16::()?, - bitmask: _buf.read_u64::()?, + tile_set_id: self.parse()?, + tile_id: self.parse()?, + corner_nw_lat: self.parse()?, + corner_nw_lon: self.parse()?, + spacing_lat: self.parse()?, + spacing_lon: self.parse()?, + rows: self.parse()?, + cols: self.parse()?, + bitmask: self.parse()?, } ) } } @@ -1370,35 +1262,17 @@ pub struct PhaseBiasesContent { pub bias: i32, } -impl PhaseBiasesContent { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( PhaseBiasesContent{ - code: _buf.read_u8()?, - integer_indicator: _buf.read_u8()?, - widelane_integer_indicator: _buf.read_u8()?, - discontinuity_counter: _buf.read_u8()?, - bias: _buf.read_i32::()?, + code: self.parse()?, + integer_indicator: self.parse()?, + widelane_integer_indicator: self.parse()?, + discontinuity_counter: self.parse()?, + bias: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(PhaseBiasesContent::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(PhaseBiasesContent::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for PhaseBiasesContent { @@ -1449,34 +1323,19 @@ pub struct STECHeader { pub iod_atmo: u8, } -impl STECHeader { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( STECHeader{ - tile_set_id: _buf.read_u16::()?, - tile_id: _buf.read_u16::()?, - time: GPSTimeSec::parse(_buf)?, - num_msgs: _buf.read_u8()?, - seq_num: _buf.read_u8()?, - update_interval: _buf.read_u8()?, - iod_atmo: _buf.read_u8()?, + tile_set_id: self.parse()?, + tile_id: self.parse()?, + time: self.parse()?, + num_msgs: self.parse()?, + seq_num: self.parse()?, + update_interval: self.parse()?, + iod_atmo: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(STECHeader::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(STECHeader::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for STECHeader { @@ -1527,35 +1386,17 @@ pub struct STECHeaderDepA { pub iod_atmo: u8, } -impl STECHeaderDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( STECHeaderDepA{ - time: GPSTimeSec::parse(_buf)?, - num_msgs: _buf.read_u8()?, - seq_num: _buf.read_u8()?, - update_interval: _buf.read_u8()?, - iod_atmo: _buf.read_u8()?, + time: self.parse()?, + num_msgs: self.parse()?, + seq_num: self.parse()?, + update_interval: self.parse()?, + iod_atmo: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(STECHeaderDepA::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(STECHeaderDepA::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for STECHeaderDepA { @@ -1596,30 +1437,15 @@ pub struct STECResidual { pub stddev: u8, } -impl STECResidual { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( STECResidual{ - sv_id: SvId::parse(_buf)?, - residual: _buf.read_i16::()?, - stddev: _buf.read_u8()?, + sv_id: self.parse()?, + residual: self.parse()?, + stddev: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(STECResidual::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(STECResidual::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for STECResidual { @@ -1653,32 +1479,14 @@ pub struct STECResidualNoStd { pub residual: i16, } -impl STECResidualNoStd { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( STECResidualNoStd{ - sv_id: SvId::parse(_buf)?, - residual: _buf.read_i16::()?, + sv_id: self.parse()?, + residual: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(STECResidualNoStd::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(STECResidualNoStd::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for STECResidualNoStd { @@ -1710,36 +1518,18 @@ pub struct STECSatElement { /// in units of TECU instead of m. pub stec_quality_indicator: u8, /// Coefficents of the STEC polynomial in the order of C00, C01, C10, C11 - pub stec_coeff: Vec, + pub stec_coeff: [i16; 4], } -impl STECSatElement { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( STECSatElement{ - sv_id: SvId::parse(_buf)?, - stec_quality_indicator: _buf.read_u8()?, - stec_coeff: crate::parser::read_s16_array_limit(_buf, 4)?, + sv_id: self.parse()?, + stec_quality_indicator: self.parse()?, + stec_coeff: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(STECSatElement::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(STECSatElement::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for STECSatElement { @@ -1776,33 +1566,15 @@ pub struct TroposphericDelayCorrection { pub stddev: u8, } -impl TroposphericDelayCorrection { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( TroposphericDelayCorrection{ - hydro: _buf.read_i16::()?, - wet: _buf.read_i8()?, - stddev: _buf.read_u8()?, + hydro: self.parse()?, + wet: self.parse()?, + stddev: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(TroposphericDelayCorrection::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(TroposphericDelayCorrection::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for TroposphericDelayCorrection { @@ -1836,34 +1608,14 @@ pub struct TroposphericDelayCorrectionNoStd { pub wet: i8, } -impl TroposphericDelayCorrectionNoStd { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( TroposphericDelayCorrectionNoStd{ - hydro: _buf.read_i16::()?, - wet: _buf.read_i8()?, + hydro: self.parse()?, + wet: self.parse()?, } ) } - pub fn parse_array( - buf: &mut &[u8], - ) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(TroposphericDelayCorrectionNoStd::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(TroposphericDelayCorrectionNoStd::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for TroposphericDelayCorrectionNoStd { diff --git a/rust/sbp/src/messages/system.rs b/rust/sbp/src/messages/system.rs index aa970cd86d..2f7aa121d5 100644 --- a/rust/sbp/src/messages/system.rs +++ b/rust/sbp/src/messages/system.rs @@ -14,14 +14,11 @@ //****************************************************************************/ //! Standardized system messages from Swift Navigation devices. -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Experimental telemetry message /// @@ -38,16 +35,16 @@ pub struct MsgCsacTelemetry { /// defined. pub id: u8, /// Comma separated list of values as defined by the index - pub telemetry: SbpString, + pub telemetry: UnboundedSbpString, } -impl MsgCsacTelemetry { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCsacTelemetry{ sender_id: None, - id: _buf.read_u8()?, - telemetry: crate::parser::read_string(_buf)?, + id: self.parse()?, + telemetry: self.parse()?, } ) } } @@ -100,16 +97,16 @@ pub struct MsgCsacTelemetryLabels { /// defined. pub id: u8, /// Comma separated list of telemetry field values - pub telemetry_labels: SbpString, + pub telemetry_labels: UnboundedSbpString, } -impl MsgCsacTelemetryLabels { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgCsacTelemetryLabels{ sender_id: None, - id: _buf.read_u8()?, - telemetry_labels: crate::parser::read_string(_buf)?, + id: self.parse()?, + telemetry_labels: self.parse()?, } ) } } @@ -165,18 +162,18 @@ pub struct MsgDgnssStatus { /// Number of signals from base station pub num_signals: u8, /// Corrections source string - pub source: SbpString, + pub source: UnboundedSbpString, } -impl MsgDgnssStatus { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgDgnssStatus{ sender_id: None, - flags: _buf.read_u8()?, - latency: _buf.read_u16::()?, - num_signals: _buf.read_u8()?, - source: crate::parser::read_string(_buf)?, + flags: self.parse()?, + latency: self.parse()?, + num_signals: self.parse()?, + source: self.parse()?, } ) } } @@ -239,15 +236,15 @@ pub struct MsgGnssTimeOffset { pub flags: u8, } -impl MsgGnssTimeOffset { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGnssTimeOffset{ sender_id: None, - weeks: _buf.read_i16::()?, - milliseconds: _buf.read_i32::()?, - microseconds: _buf.read_i16::()?, - flags: _buf.read_u8()?, + weeks: self.parse()?, + milliseconds: self.parse()?, + microseconds: self.parse()?, + flags: self.parse()?, } ) } } @@ -310,15 +307,15 @@ pub struct MsgGroupMeta { pub group_msgs: Vec, } -impl MsgGroupMeta { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgGroupMeta{ sender_id: None, - group_id: _buf.read_u8()?, - flags: _buf.read_u8()?, - n_group_msgs: _buf.read_u8()?, - group_msgs: crate::parser::read_u16_array(_buf)?, + group_id: self.parse()?, + flags: self.parse()?, + n_group_msgs: self.parse()?, + group_msgs: self.parse()?, } ) } } @@ -382,12 +379,12 @@ pub struct MsgHeartbeat { pub flags: u32, } -impl MsgHeartbeat { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgHeartbeat{ sender_id: None, - flags: _buf.read_u32::()?, + flags: self.parse()?, } ) } } @@ -437,12 +434,12 @@ pub struct MsgInsStatus { pub flags: u32, } -impl MsgInsStatus { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgInsStatus{ sender_id: None, - flags: _buf.read_u32::()?, + flags: self.parse()?, } ) } } @@ -504,18 +501,18 @@ pub struct MsgInsUpdates { pub zerovel: u8, } -impl MsgInsUpdates { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgInsUpdates{ sender_id: None, - tow: _buf.read_u32::()?, - gnsspos: _buf.read_u8()?, - gnssvel: _buf.read_u8()?, - wheelticks: _buf.read_u8()?, - speed: _buf.read_u8()?, - nhc: _buf.read_u8()?, - zerovel: _buf.read_u8()?, + tow: self.parse()?, + gnsspos: self.parse()?, + gnssvel: self.parse()?, + wheelticks: self.parse()?, + speed: self.parse()?, + nhc: self.parse()?, + zerovel: self.parse()?, } ) } } @@ -583,14 +580,14 @@ pub struct MsgStartup { pub reserved: u16, } -impl MsgStartup { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgStartup{ sender_id: None, - cause: _buf.read_u8()?, - startup_type: _buf.read_u8()?, - reserved: _buf.read_u16::()?, + cause: self.parse()?, + startup_type: self.parse()?, + reserved: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/tracking.rs b/rust/sbp/src/messages/tracking.rs index c0867cff4c..15eae6eb28 100644 --- a/rust/sbp/src/messages/tracking.rs +++ b/rust/sbp/src/messages/tracking.rs @@ -15,15 +15,12 @@ //! Satellite code and carrier-phase tracking messages from the device. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; use super::gnss::*; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Measurement Engine signal tracking channel states /// @@ -40,12 +37,12 @@ pub struct MsgMeasurementState { pub states: Vec, } -impl MsgMeasurementState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgMeasurementState{ sender_id: None, - states: MeasurementState::parse_array(_buf)?, + states: self.parse()?, } ) } } @@ -96,17 +93,17 @@ pub struct MsgTrackingIq { /// GNSS signal identifier pub sid: GnssSignal, /// Early, Prompt and Late correlations - pub corrs: Vec, + pub corrs: [TrackingChannelCorrelation; 3], } -impl MsgTrackingIq { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingIq{ sender_id: None, - channel: _buf.read_u8()?, - sid: GnssSignal::parse(_buf)?, - corrs: TrackingChannelCorrelation::parse_array_limit(_buf, 3)?, + channel: self.parse()?, + sid: self.parse()?, + corrs: self.parse()?, } ) } } @@ -160,17 +157,17 @@ pub struct MsgTrackingIqDepA { /// GNSS signal identifier pub sid: GnssSignalDep, /// Early, Prompt and Late correlations - pub corrs: Vec, + pub corrs: [TrackingChannelCorrelationDep; 3], } -impl MsgTrackingIqDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingIqDepA{ sender_id: None, - channel: _buf.read_u8()?, - sid: GnssSignalDep::parse(_buf)?, - corrs: TrackingChannelCorrelationDep::parse_array_limit(_buf, 3)?, + channel: self.parse()?, + sid: self.parse()?, + corrs: self.parse()?, } ) } } @@ -225,17 +222,17 @@ pub struct MsgTrackingIqDepB { /// GNSS signal identifier pub sid: GnssSignal, /// Early, Prompt and Late correlations - pub corrs: Vec, + pub corrs: [TrackingChannelCorrelationDep; 3], } -impl MsgTrackingIqDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingIqDepB{ sender_id: None, - channel: _buf.read_u8()?, - sid: GnssSignal::parse(_buf)?, - corrs: TrackingChannelCorrelationDep::parse_array_limit(_buf, 3)?, + channel: self.parse()?, + sid: self.parse()?, + corrs: self.parse()?, } ) } } @@ -290,12 +287,12 @@ pub struct MsgTrackingState { pub states: Vec, } -impl MsgTrackingState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingState{ sender_id: None, - states: TrackingChannelState::parse_array(_buf)?, + states: self.parse()?, } ) } } @@ -344,12 +341,12 @@ pub struct MsgTrackingStateDepA { pub states: Vec, } -impl MsgTrackingStateDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingStateDepA{ sender_id: None, - states: TrackingChannelStateDepA::parse_array(_buf)?, + states: self.parse()?, } ) } } @@ -398,12 +395,12 @@ pub struct MsgTrackingStateDepB { pub states: Vec, } -impl MsgTrackingStateDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingStateDepB{ sender_id: None, - states: TrackingChannelStateDepB::parse_array(_buf)?, + states: self.parse()?, } ) } } @@ -498,32 +495,32 @@ pub struct MsgTrackingStateDetailedDep { pub misc_flags: u8, } -impl MsgTrackingStateDetailedDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingStateDetailedDep{ sender_id: None, - recv_time: _buf.read_u64::()?, - tot: GPSTimeDep::parse(_buf)?, - P: _buf.read_u32::()?, - P_std: _buf.read_u16::()?, - L: CarrierPhase::parse(_buf)?, - cn0: _buf.read_u8()?, - lock: _buf.read_u16::()?, - sid: GnssSignalDep::parse(_buf)?, - doppler: _buf.read_i32::()?, - doppler_std: _buf.read_u16::()?, - uptime: _buf.read_u32::()?, - clock_offset: _buf.read_i16::()?, - clock_drift: _buf.read_i16::()?, - corr_spacing: _buf.read_u16::()?, - acceleration: _buf.read_i8()?, - sync_flags: _buf.read_u8()?, - tow_flags: _buf.read_u8()?, - track_flags: _buf.read_u8()?, - nav_flags: _buf.read_u8()?, - pset_flags: _buf.read_u8()?, - misc_flags: _buf.read_u8()?, + recv_time: self.parse()?, + tot: self.parse()?, + P: self.parse()?, + P_std: self.parse()?, + L: self.parse()?, + cn0: self.parse()?, + lock: self.parse()?, + sid: self.parse()?, + doppler: self.parse()?, + doppler_std: self.parse()?, + uptime: self.parse()?, + clock_offset: self.parse()?, + clock_drift: self.parse()?, + corr_spacing: self.parse()?, + acceleration: self.parse()?, + sync_flags: self.parse()?, + tow_flags: self.parse()?, + track_flags: self.parse()?, + nav_flags: self.parse()?, + pset_flags: self.parse()?, + misc_flags: self.parse()?, } ) } } @@ -659,32 +656,32 @@ pub struct MsgTrackingStateDetailedDepA { pub misc_flags: u8, } -impl MsgTrackingStateDetailedDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgTrackingStateDetailedDepA{ sender_id: None, - recv_time: _buf.read_u64::()?, - tot: GPSTime::parse(_buf)?, - P: _buf.read_u32::()?, - P_std: _buf.read_u16::()?, - L: CarrierPhase::parse(_buf)?, - cn0: _buf.read_u8()?, - lock: _buf.read_u16::()?, - sid: GnssSignal::parse(_buf)?, - doppler: _buf.read_i32::()?, - doppler_std: _buf.read_u16::()?, - uptime: _buf.read_u32::()?, - clock_offset: _buf.read_i16::()?, - clock_drift: _buf.read_i16::()?, - corr_spacing: _buf.read_u16::()?, - acceleration: _buf.read_i8()?, - sync_flags: _buf.read_u8()?, - tow_flags: _buf.read_u8()?, - track_flags: _buf.read_u8()?, - nav_flags: _buf.read_u8()?, - pset_flags: _buf.read_u8()?, - misc_flags: _buf.read_u8()?, + recv_time: self.parse()?, + tot: self.parse()?, + P: self.parse()?, + P_std: self.parse()?, + L: self.parse()?, + cn0: self.parse()?, + lock: self.parse()?, + sid: self.parse()?, + doppler: self.parse()?, + doppler_std: self.parse()?, + uptime: self.parse()?, + clock_offset: self.parse()?, + clock_drift: self.parse()?, + corr_spacing: self.parse()?, + acceleration: self.parse()?, + sync_flags: self.parse()?, + tow_flags: self.parse()?, + track_flags: self.parse()?, + nav_flags: self.parse()?, + pset_flags: self.parse()?, + misc_flags: self.parse()?, } ) } } @@ -779,32 +776,14 @@ pub struct MeasurementState { pub cn0: u8, } -impl MeasurementState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MeasurementState{ - mesid: GnssSignal::parse(_buf)?, - cn0: _buf.read_u8()?, + mesid: self.parse()?, + cn0: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(MeasurementState::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(MeasurementState::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for MeasurementState { @@ -836,32 +815,14 @@ pub struct TrackingChannelCorrelation { pub Q: i16, } -impl TrackingChannelCorrelation { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( TrackingChannelCorrelation{ - I: _buf.read_i16::()?, - Q: _buf.read_i16::()?, + I: self.parse()?, + Q: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(TrackingChannelCorrelation::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(TrackingChannelCorrelation::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for TrackingChannelCorrelation { @@ -893,34 +854,14 @@ pub struct TrackingChannelCorrelationDep { pub Q: i32, } -impl TrackingChannelCorrelationDep { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( TrackingChannelCorrelationDep{ - I: _buf.read_i32::()?, - Q: _buf.read_i32::()?, + I: self.parse()?, + Q: self.parse()?, } ) } - pub fn parse_array( - buf: &mut &[u8], - ) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(TrackingChannelCorrelationDep::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(TrackingChannelCorrelationDep::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for TrackingChannelCorrelationDep { @@ -955,33 +896,15 @@ pub struct TrackingChannelState { pub cn0: u8, } -impl TrackingChannelState { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( TrackingChannelState{ - sid: GnssSignal::parse(_buf)?, - fcn: _buf.read_u8()?, - cn0: _buf.read_u8()?, + sid: self.parse()?, + fcn: self.parse()?, + cn0: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(TrackingChannelState::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(TrackingChannelState::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for TrackingChannelState { @@ -1017,33 +940,15 @@ pub struct TrackingChannelStateDepA { pub cn0: f32, } -impl TrackingChannelStateDepA { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( TrackingChannelStateDepA{ - state: _buf.read_u8()?, - prn: _buf.read_u8()?, - cn0: _buf.read_f32::()?, + state: self.parse()?, + prn: self.parse()?, + cn0: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(TrackingChannelStateDepA::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(TrackingChannelStateDepA::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for TrackingChannelStateDepA { @@ -1079,33 +984,15 @@ pub struct TrackingChannelStateDepB { pub cn0: f32, } -impl TrackingChannelStateDepB { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( TrackingChannelStateDepB{ - state: _buf.read_u8()?, - sid: GnssSignalDep::parse(_buf)?, - cn0: _buf.read_f32::()?, + state: self.parse()?, + sid: self.parse()?, + cn0: self.parse()?, } ) } - pub fn parse_array(buf: &mut &[u8]) -> Result, crate::Error> { - let mut v = Vec::new(); - while buf.len() > 0 { - v.push(TrackingChannelStateDepB::parse(buf)?); - } - Ok(v) - } - - pub fn parse_array_limit( - buf: &mut &[u8], - n: usize, - ) -> Result, crate::Error> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(TrackingChannelStateDepB::parse(buf)?); - } - Ok(v) - } } impl crate::serialize::SbpSerialize for TrackingChannelStateDepB { diff --git a/rust/sbp/src/messages/user.rs b/rust/sbp/src/messages/user.rs index 3c16aa3a02..ee9a5f4dba 100644 --- a/rust/sbp/src/messages/user.rs +++ b/rust/sbp/src/messages/user.rs @@ -15,14 +15,11 @@ //! Messages reserved for use by the user. //! -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// User data /// @@ -38,12 +35,12 @@ pub struct MsgUserData { pub contents: Vec, } -impl MsgUserData { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgUserData{ sender_id: None, - contents: crate::parser::read_u8_array(_buf)?, + contents: self.parse()?, } ) } } diff --git a/rust/sbp/src/messages/vehicle.rs b/rust/sbp/src/messages/vehicle.rs index 542811835a..cc63badbf6 100644 --- a/rust/sbp/src/messages/vehicle.rs +++ b/rust/sbp/src/messages/vehicle.rs @@ -14,14 +14,11 @@ //****************************************************************************/ //! Messages from a vehicle. -extern crate byteorder; -#[allow(unused_imports)] -use self::byteorder::{LittleEndian, ReadBytesExt}; #[cfg(feature = "sbp_serde")] use serde::{Deserialize, Serialize}; #[allow(unused_imports)] -use crate::SbpString; +use crate::{parser::SbpParse, BoundedSbpString, UnboundedSbpString}; /// Vehicle forward (x-axis) velocity /// @@ -49,14 +46,14 @@ pub struct MsgOdometry { pub flags: u8, } -impl MsgOdometry { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgOdometry{ sender_id: None, - tow: _buf.read_u32::()?, - velocity: _buf.read_i32::()?, - flags: _buf.read_u8()?, + tow: self.parse()?, + velocity: self.parse()?, + flags: self.parse()?, } ) } } @@ -129,15 +126,15 @@ pub struct MsgWheeltick { pub ticks: i32, } -impl MsgWheeltick { +impl SbpParse for &[u8] { #[rustfmt::skip] - pub fn parse(_buf: &mut &[u8]) -> Result { + fn parse(&mut self) -> crate::Result { Ok( MsgWheeltick{ sender_id: None, - time: _buf.read_u64::()?, - flags: _buf.read_u8()?, - source: _buf.read_u8()?, - ticks: _buf.read_i32::()?, + time: self.parse()?, + flags: self.parse()?, + source: self.parse()?, + ticks: self.parse()?, } ) } } diff --git a/rust/sbp/src/parser/mod.rs b/rust/sbp/src/parser/mod.rs index 3a9f4dcf75..4b8bac2f3d 100644 --- a/rust/sbp/src/parser/mod.rs +++ b/rust/sbp/src/parser/mod.rs @@ -10,8 +10,9 @@ use self::nom::multi::length_data; use self::nom::number::complete::{le_u16, le_u8}; use self::nom::sequence::tuple; use crate::messages::SBP; -use crate::Result; -use crate::SbpString; +use crate::{BoundedSbpString, UnboundedSbpString}; +use crate::{Error, Result}; +use std::convert::TryInto; use std::io::{BufReader, Read}; const MSG_HEADER_LEN: usize = 1 /*preamble*/ + 2 /*msg_type*/ + 2 /*sender_id*/ + 1 /*len*/; @@ -169,20 +170,114 @@ where } } -pub(crate) fn read_string(buf: &mut &[u8]) -> Result { - let amount = buf.len(); - let (head, tail) = buf.split_at(amount); - *buf = tail; - Ok(SbpString(head.to_vec())) +pub(crate) trait SbpParse { + fn parse(&mut self) -> Result; } -pub(crate) fn read_string_limit(buf: &mut &[u8], n: usize) -> Result { - let n = std::cmp::min(n, buf.len()); - let (mut head, tail) = buf.split_at(n); - read_string(&mut head).map(|sbp_string| { - *buf = tail; - sbp_string - }) +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_u8().map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_i8().map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_u16::() + .map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_i16::() + .map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_u32::() + .map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_i32::() + .map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_u64::() + .map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_i64::() + .map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_f32::() + .map_err(|e| Error::IoError(e)) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.read_f64::() + .map_err(|e| Error::IoError(e)) + } +} + +impl<'a, T, const SIZE: usize> SbpParse<[T; SIZE]> for &'a [u8] +where + &'a [u8]: SbpParse, +{ + fn parse(&mut self) -> Result<[T; SIZE]> { + let mut vec = Vec::new(); + for _ in 0..SIZE { + vec.push(self.parse()?); + } + vec.try_into().map_err(|_| crate::Error::ParseError) + } +} + +impl<'a, T> SbpParse> for &'a [u8] +where + &'a [u8]: SbpParse, +{ + fn parse(&mut self) -> Result> { + let mut vec = Vec::new(); + while self.len() > 0 { + vec.push(self.parse()?); + } + Ok(vec) + } +} + +impl SbpParse for &[u8] { + fn parse(&mut self) -> Result { + self.try_into() + } +} + +impl SbpParse> for &[u8] { + fn parse(&mut self) -> Result> { + self.try_into() + } } #[test] @@ -197,7 +292,7 @@ fn test_read_string_invalid_utf8() { let mut slice = &buf[..]; - let sbp_string = read_string(&mut slice).unwrap(); + let sbp_string: UnboundedSbpString = (&mut slice).parse().unwrap(); let string: String = sbp_string.clone().into(); let vec: Vec = sbp_string.into(); @@ -212,33 +307,28 @@ fn test_read_string() { let v = b"hi, imma string"; let mut slice = &v[..]; - let string: String = read_string(&mut slice).unwrap().into(); + let string: String = SbpParse::::parse(&mut slice) + .unwrap() + .into(); assert_eq!(string, "hi, imma string".to_string()); - let string: String = read_string(&mut slice).unwrap().into(); + let string: String = SbpParse::::parse(&mut slice) + .unwrap() + .into(); assert_eq!(string, "".to_string()); let v = b"hi, imma string"; let mut slice = &v[..]; - let string: String = read_string_limit(&mut slice, 8).unwrap().into(); + let string: String = SbpParse::>::parse(&mut slice) + .unwrap() + .into(); assert_eq!(string, "hi, imma".to_string()); - let string: String = read_string_limit(&mut slice, 8).unwrap().into(); - assert_eq!(string, " string".to_string()); -} - -pub(crate) fn read_u16_array(buf: &mut &[u8]) -> Result> { - // buf is in fact an array of u16, so at least 2 u8 elem, unless buf is empty - let iter = buf.chunks_exact(2); - // collect() guarantees that it will return Err if at least one Err is found while iterating over the Vec - // https://doc.rust-lang.org/std/iter/trait.FromIterator.html#method.from_iter-14 - // map_err necessary to convert the generic read_u16's Error into our Error enum type - // LittleEndian means chunks are read from right-to-left - let v = iter - .map(|mut x| x.read_u16::().map_err(|e| e.into())) - .collect(); - v + let string: String = SbpParse::>::parse(&mut slice) + .unwrap() + .into(); + assert_eq!(string, " string\0".to_string()); } #[test] @@ -249,58 +339,6 @@ fn test_read_u16_array() { // 0b00010000+0b00000001 expected_vec.push(4097); expected_vec.push(258); - let returned_vec = read_u16_array(&mut &mock_data[..]).unwrap(); + let returned_vec: Vec = (&mut &mock_data[..]).parse().unwrap(); assert_eq!(expected_vec, returned_vec); } - -pub(crate) fn read_u8_array(buf: &mut &[u8]) -> Result> { - Ok(buf.to_vec()) -} - -pub(crate) fn read_u8_array_limit(buf: &mut &[u8], n: usize) -> Result> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(buf.read_u8()?); - } - Ok(v) -} - -pub(crate) fn read_s8_array_limit(buf: &mut &[u8], n: usize) -> Result> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(buf.read_i8()?); - } - Ok(v) -} - -pub(crate) fn read_s16_array_limit(buf: &mut &[u8], n: usize) -> Result> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(buf.read_i16::()?); - } - Ok(v) -} - -pub(crate) fn read_u16_array_limit(buf: &mut &[u8], n: usize) -> Result> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(buf.read_u16::()?); - } - Ok(v) -} - -pub(crate) fn read_float_array_limit(buf: &mut &[u8], n: usize) -> Result> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(buf.read_f32::()?); - } - Ok(v) -} - -pub(crate) fn read_double_array_limit(buf: &mut &[u8], n: usize) -> Result> { - let mut v = Vec::new(); - for _ in 0..n { - v.push(buf.read_f64::()?); - } - Ok(v) -} diff --git a/rust/sbp/src/serialize.rs b/rust/sbp/src/serialize.rs index d902c2ab4e..2db9359609 100644 --- a/rust/sbp/src/serialize.rs +++ b/rust/sbp/src/serialize.rs @@ -107,28 +107,42 @@ impl SbpSerialize for f64 { } } -impl SbpSerialize for SbpString { +impl SbpSerialize for T { fn append_to_sbp_buffer(&self, buf: &mut Vec) { buf.extend(self.as_bytes()); } fn sbp_size(&self) -> usize { - self.0.len() + self.as_bytes().len() + } +} + +impl SbpSerialize for &'_ [T] { + fn append_to_sbp_buffer(&self, buf: &mut Vec) { + self.iter().for_each(|item| item.append_to_sbp_buffer(buf)); + } + + fn sbp_size(&self) -> usize { + self.iter().map(|item| item.sbp_size()).sum() } } impl SbpSerialize for Vec { fn append_to_sbp_buffer(&self, buf: &mut Vec) { - for item in self.into_iter() { - item.append_to_sbp_buffer(buf); - } + self.as_slice().append_to_sbp_buffer(buf) + } + + fn sbp_size(&self) -> usize { + self.as_slice().sbp_size() + } +} + +impl SbpSerialize for [T; SIZE] { + fn append_to_sbp_buffer(&self, buf: &mut Vec) { + self.as_ref().append_to_sbp_buffer(buf) } fn sbp_size(&self) -> usize { - let mut total = 0; - for item in self.iter() { - total += item.sbp_size(); - } - total + self.as_ref().sbp_size() } }