nmea_kit/ais/messages/
static_b.rs1use crate::ais::armor::{extract_string, extract_u32};
4
5#[non_exhaustive]
11#[derive(Debug, Clone, PartialEq)]
12pub enum StaticDataReport {
13 PartA {
14 mmsi: u32,
15 vessel_name: String,
16 },
17 PartB {
18 mmsi: u32,
19 callsign: String,
20 ship_type: u8,
21 },
22}
23
24impl StaticDataReport {
25 pub fn decode(bits: &[u8]) -> Option<Self> {
27 if bits.len() < 160 {
28 return None;
29 }
30
31 let mmsi = extract_u32(bits, 8, 30)?;
32 let part_number = extract_u32(bits, 38, 2)?;
33
34 match part_number {
35 0 => {
36 let vessel_name = extract_string(bits, 40, 20)?;
38 Some(Self::PartA { mmsi, vessel_name })
39 }
40 1 => {
41 if bits.len() < 168 {
43 return None;
44 }
45 let callsign = extract_string(bits, 40, 7)?;
46 let ship_type = extract_u32(bits, 82, 8)? as u8;
47 Some(Self::PartB {
48 mmsi,
49 callsign,
50 ship_type,
51 })
52 }
53 _ => None,
54 }
55 }
56}