Skip to content

Commit

Permalink
Make generated code more cargo fmt friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Mobarak committed May 22, 2020
1 parent 95380b4 commit 3a7cc95
Show file tree
Hide file tree
Showing 23 changed files with 706 additions and 450 deletions.
1 change: 1 addition & 0 deletions generator/sbpg/targets/resources/sbp_messages_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct (((m.identifier|camel_case))) {
}

impl (((m.identifier|camel_case))) {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<(((m.identifier|camel_case))), crate::Error> {
Ok( (((m.identifier|camel_case))){
((*- if m.sbp_id *))
Expand Down
40 changes: 24 additions & 16 deletions rust/sbp/src/messages/acquisition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ pub struct AcqSvProfile {
}

impl AcqSvProfile {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<AcqSvProfile, crate::Error> {
Ok(AcqSvProfile {
Ok( AcqSvProfile{
job_type: _buf.read_u8()?,
status: _buf.read_u8()?,
cn0: _buf.read_u16::<LittleEndian>()?,
Expand All @@ -75,7 +76,7 @@ impl AcqSvProfile {
cf_max: _buf.read_i32::<LittleEndian>()?,
cf: _buf.read_i32::<LittleEndian>()?,
cp: _buf.read_u32::<LittleEndian>()?,
})
} )
}
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<AcqSvProfile>, crate::Error> {
let mut v = Vec::new();
Expand Down Expand Up @@ -164,8 +165,9 @@ pub struct AcqSvProfileDep {
}

impl AcqSvProfileDep {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<AcqSvProfileDep, crate::Error> {
Ok(AcqSvProfileDep {
Ok( AcqSvProfileDep{
job_type: _buf.read_u8()?,
status: _buf.read_u8()?,
cn0: _buf.read_u16::<LittleEndian>()?,
Expand All @@ -178,7 +180,7 @@ impl AcqSvProfileDep {
cf_max: _buf.read_i32::<LittleEndian>()?,
cf: _buf.read_i32::<LittleEndian>()?,
cp: _buf.read_u32::<LittleEndian>()?,
})
} )
}
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<AcqSvProfileDep>, crate::Error> {
let mut v = Vec::new();
Expand Down Expand Up @@ -259,14 +261,15 @@ pub struct MsgAcqResult {
}

impl MsgAcqResult {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResult, crate::Error> {
Ok(MsgAcqResult {
Ok( MsgAcqResult{
sender_id: None,
cn0: _buf.read_f32::<LittleEndian>()?,
cp: _buf.read_f32::<LittleEndian>()?,
cf: _buf.read_f32::<LittleEndian>()?,
sid: GnssSignal::parse(_buf)?,
})
} )
}
}
impl super::SBPMessage for MsgAcqResult {
Expand Down Expand Up @@ -329,14 +332,15 @@ pub struct MsgAcqResultDepA {
}

impl MsgAcqResultDepA {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepA, crate::Error> {
Ok(MsgAcqResultDepA {
Ok( MsgAcqResultDepA{
sender_id: None,
snr: _buf.read_f32::<LittleEndian>()?,
cp: _buf.read_f32::<LittleEndian>()?,
cf: _buf.read_f32::<LittleEndian>()?,
prn: _buf.read_u8()?,
})
} )
}
}
impl super::SBPMessage for MsgAcqResultDepA {
Expand Down Expand Up @@ -398,14 +402,15 @@ pub struct MsgAcqResultDepB {
}

impl MsgAcqResultDepB {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepB, crate::Error> {
Ok(MsgAcqResultDepB {
Ok( MsgAcqResultDepB{
sender_id: None,
snr: _buf.read_f32::<LittleEndian>()?,
cp: _buf.read_f32::<LittleEndian>()?,
cf: _buf.read_f32::<LittleEndian>()?,
sid: GnssSignalDep::parse(_buf)?,
})
} )
}
}
impl super::SBPMessage for MsgAcqResultDepB {
Expand Down Expand Up @@ -466,14 +471,15 @@ pub struct MsgAcqResultDepC {
}

impl MsgAcqResultDepC {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepC, crate::Error> {
Ok(MsgAcqResultDepC {
Ok( MsgAcqResultDepC{
sender_id: None,
cn0: _buf.read_f32::<LittleEndian>()?,
cp: _buf.read_f32::<LittleEndian>()?,
cf: _buf.read_f32::<LittleEndian>()?,
sid: GnssSignalDep::parse(_buf)?,
})
} )
}
}
impl super::SBPMessage for MsgAcqResultDepC {
Expand Down Expand Up @@ -529,11 +535,12 @@ pub struct MsgAcqSvProfile {
}

impl MsgAcqSvProfile {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqSvProfile, crate::Error> {
Ok(MsgAcqSvProfile {
Ok( MsgAcqSvProfile{
sender_id: None,
acq_sv_profile: AcqSvProfile::parse_array(_buf)?,
})
} )
}
}
impl super::SBPMessage for MsgAcqSvProfile {
Expand Down Expand Up @@ -582,11 +589,12 @@ pub struct MsgAcqSvProfileDep {
}

impl MsgAcqSvProfileDep {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqSvProfileDep, crate::Error> {
Ok(MsgAcqSvProfileDep {
Ok( MsgAcqSvProfileDep{
sender_id: None,
acq_sv_profile: AcqSvProfileDep::parse_array(_buf)?,
})
} )
}
}
impl super::SBPMessage for MsgAcqSvProfileDep {
Expand Down
30 changes: 20 additions & 10 deletions rust/sbp/src/messages/bootload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ pub struct MsgBootloaderHandshakeDepA {
}

impl MsgBootloaderHandshakeDepA {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgBootloaderHandshakeDepA, crate::Error> {
Ok(MsgBootloaderHandshakeDepA {
Ok( MsgBootloaderHandshakeDepA{
sender_id: None,
handshake: crate::parser::read_u8_array(_buf)?,
})
} )
}
}
impl super::SBPMessage for MsgBootloaderHandshakeDepA {
Expand Down Expand Up @@ -95,8 +96,11 @@ pub struct MsgBootloaderHandshakeReq {
}

impl MsgBootloaderHandshakeReq {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgBootloaderHandshakeReq, crate::Error> {
Ok(MsgBootloaderHandshakeReq { sender_id: None })
Ok( MsgBootloaderHandshakeReq{
sender_id: None,
} )
}
}
impl super::SBPMessage for MsgBootloaderHandshakeReq {
Expand Down Expand Up @@ -147,12 +151,13 @@ pub struct MsgBootloaderHandshakeResp {
}

impl MsgBootloaderHandshakeResp {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgBootloaderHandshakeResp, crate::Error> {
Ok(MsgBootloaderHandshakeResp {
Ok( MsgBootloaderHandshakeResp{
sender_id: None,
flags: _buf.read_u32::<LittleEndian>()?,
version: crate::parser::read_string(_buf)?,
})
} )
}
}
impl super::SBPMessage for MsgBootloaderHandshakeResp {
Expand Down Expand Up @@ -203,11 +208,12 @@ pub struct MsgBootloaderJumpToApp {
}

impl MsgBootloaderJumpToApp {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgBootloaderJumpToApp, crate::Error> {
Ok(MsgBootloaderJumpToApp {
Ok( MsgBootloaderJumpToApp{
sender_id: None,
jump: _buf.read_u8()?,
})
} )
}
}
impl super::SBPMessage for MsgBootloaderJumpToApp {
Expand Down Expand Up @@ -259,8 +265,11 @@ pub struct MsgNapDeviceDnaReq {
}

impl MsgNapDeviceDnaReq {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgNapDeviceDnaReq, crate::Error> {
Ok(MsgNapDeviceDnaReq { sender_id: None })
Ok( MsgNapDeviceDnaReq{
sender_id: None,
} )
}
}
impl super::SBPMessage for MsgNapDeviceDnaReq {
Expand Down Expand Up @@ -310,11 +319,12 @@ pub struct MsgNapDeviceDnaResp {
}

impl MsgNapDeviceDnaResp {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgNapDeviceDnaResp, crate::Error> {
Ok(MsgNapDeviceDnaResp {
Ok( MsgNapDeviceDnaResp{
sender_id: None,
dna: crate::parser::read_u8_array_limit(_buf, 8)?,
})
} )
}
}
impl super::SBPMessage for MsgNapDeviceDnaResp {
Expand Down
5 changes: 3 additions & 2 deletions rust/sbp/src/messages/ext_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ pub struct MsgExtEvent {
}

impl MsgExtEvent {
#[rustfmt::skip]
pub fn parse(_buf: &mut &[u8]) -> Result<MsgExtEvent, crate::Error> {
Ok(MsgExtEvent {
Ok( MsgExtEvent{
sender_id: None,
wn: _buf.read_u16::<LittleEndian>()?,
tow: _buf.read_u32::<LittleEndian>()?,
ns_residual: _buf.read_i32::<LittleEndian>()?,
flags: _buf.read_u8()?,
pin: _buf.read_u8()?,
})
} )
}
}
impl super::SBPMessage for MsgExtEvent {
Expand Down
Loading

0 comments on commit 3a7cc95

Please sign in to comment.