diff --git a/Cargo.lock b/Cargo.lock index 4ca4358..97f811d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -528,7 +528,7 @@ dependencies = [ [[package]] name = "directip" -version = "0.2.6" +version = "0.2.7" dependencies = [ "byteorder", "chrono", @@ -538,6 +538,7 @@ dependencies = [ "serde_bytes", "serde_json", "thiserror", + "tracing", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9237f60..235dec7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ thiserror = "1.0" derive_builder = "0.11.2" serde = { version = "1.0.147", optional = true, default-features = false, features=["serde_derive"]} serde_bytes = { version = "0.11.8", optional = true } +tracing = { workspace = true } [workspace.dependencies] chrono = "0.4.31" diff --git a/src/mo/location.rs b/src/mo/location.rs index 3683cf9..8e9e6f9 100644 --- a/src/mo/location.rs +++ b/src/mo/location.rs @@ -67,6 +67,13 @@ struct Coordinate { } impl Coordinate { + fn from_reader(mut rdr: R) -> Result { + let mut buffer = [0u8; 7]; + rdr.read_exact(&mut buffer)?; + let coordinate = Coordinate::decode(&buffer); + Ok(coordinate) + } + #[allow(dead_code)] fn encode(&self) -> [u8; 7] { let mut buf = [0u8; 7]; @@ -153,6 +160,21 @@ pub(super) struct Location { } impl Location { + pub(super) fn from_reader(mut rdr: R) -> Result { + let iei = rdr.read_u8()?; + assert_eq!(iei, 0x03); + let len = rdr.read_u16::()?; + assert_eq!(len, 11); + + let coordinate = Coordinate::from_reader(&mut rdr)?; + let cep_radius = rdr.read_u32::()?; + + Ok(Location { + coordinate, + cep_radius, + }) + } + #[allow(dead_code)] fn decode(buffer: &[u8]) -> Result { if buffer.len() < 3 { diff --git a/src/mo/mod.rs b/src/mo/mod.rs index c158eef..3137300 100644 --- a/src/mo/mod.rs +++ b/src/mo/mod.rs @@ -87,7 +87,15 @@ impl InformationElementType { let payload = Payload::from_reader(buffer).unwrap(); InformationElementType::P(payload) } - _ => return Err(Error::Undefined), + 0x03 => { + let location = Location::from_reader(buffer).unwrap(); + tracing::debug!("Parsed an MO::Location element"); + InformationElementType::L(location) + } + _ => { + tracing::debug!("Not a valid MO IEI ({})", &iei); + return Err(Error::Undefined); + } }; Ok(element) }