AIS: More simplifying of packet length/validation code.

This commit is contained in:
Jared Boone 2015-12-08 13:38:40 -08:00
parent af74daf092
commit 0c1c0da8a5
2 changed files with 17 additions and 15 deletions

View File

@ -183,21 +183,7 @@ size_t Packet::length() const {
} }
bool Packet::is_valid() const { bool Packet::is_valid() const {
if( data_and_fcs_length() < 38 ) { return length_valid() && crc_ok();
return false;
}
const size_t extra_bits = data_and_fcs_length() & 7;
if( extra_bits != 0 ) {
return false;
}
PacketLengthValidator packet_length_valid;
if( !packet_length_valid(message_id(), data_length()) ) {
return false;
}
return crc_ok();
} }
rtc::RTC Packet::received_at() const { rtc::RTC Packet::received_at() const {
@ -279,6 +265,20 @@ size_t Packet::data_length() const {
return data_and_fcs_length() - fcs_length; return data_and_fcs_length() - fcs_length;
} }
bool Packet::length_valid() const {
const size_t extra_bits = data_and_fcs_length() & 7;
if( extra_bits != 0 ) {
return false;
}
const PacketLengthValidator packet_length_valid;
if( !packet_length_valid(message_id(), data_length()) ) {
return false;
}
return true;
}
} /* namespace ais */ } /* namespace ais */
} /* namespace baseband */ } /* namespace baseband */

View File

@ -106,6 +106,8 @@ private:
size_t data_and_fcs_length() const; size_t data_and_fcs_length() const;
size_t data_length() const; size_t data_length() const;
bool length_valid() const;
}; };
} /* namespace ais */ } /* namespace ais */