Skip to content

Commit

Permalink
Add VAG deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
adriantombu committed Jun 21, 2024
1 parent 886512e commit 5dffc62
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 27,733 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aeroweb"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
authors = ["Adrian Tombu <[email protected]>"]
keywords = ["meteo", "meteorology", "aeronautics", "aviation", "metar"]
Expand Down
27,220 changes: 10 additions & 27,210 deletions data/cartes.xml

Large diffs are not rendered by default.

444 changes: 12 additions & 432 deletions data/dossier.xml

Large diffs are not rendered by default.

32 changes: 0 additions & 32 deletions data/opmet.xml

This file was deleted.

46 changes: 0 additions & 46 deletions data/sigmet.xml

This file was deleted.

2 changes: 1 addition & 1 deletion data/vag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</VAG>
<VAG date_reception='20240423195200' oaci='RJTD' nom='TOKYO'>
<lien>
<![CDATA[/FR/aviation/affiche_vagtcag.php?login=ebO5r6yBvHOOh7AK4GqcYWdrlmdnZ2rd1uE%3D&layer=vag/rjtd&echeance=20240423195200]]></lien>
<![CDATA[/FR/aviation/affiche_vagtcag.php]]></lien>
</VAG>
</groupe>
1 change: 1 addition & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pub mod sw;
pub mod tca;
pub mod tcag;
pub mod vaa;
pub mod vag;
2 changes: 1 addition & 1 deletion src/types/predec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::Deserialize;
// Definition file : https://aviation.meteo.fr/FR/aviation/XSD/predec.xsd
// pub fn fetch() -> Result<Predec, AerowebError> {}

/// Parses the XML string into an `Predec` struct.
/// Parses the XML string into a `Predec` struct.
///
/// # Errors
///
Expand Down
2 changes: 1 addition & 1 deletion src/types/sigmet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::Deserialize;
// Definition file : https://aviation.meteo.fr/FR/aviation/XSD/sigmet.xsd
// pub fn fetch() -> Result<Sigmet, AerowebError> {}

/// Parses the XML string into an `Sigmet` struct.
/// Parses the XML string into a `Sigmet` struct.
///
/// # Errors
///
Expand Down
2 changes: 1 addition & 1 deletion src/types/sw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::Deserialize;
/// Space weather is advisory information on space weather phenomena expected to affect high-frequency radio communications, satellite communications, and GNSS-based navigation and surveillance systems, or will create a radiation hazard to aircraft occupants.
// pub fn fetch() -> Result<SpaceWeather, AerowebError> {}

/// Parses the XML string into an `SpaceWeather` struct.
/// Parses the XML string into a `SpaceWeather` struct.
///
/// # Errors
///
Expand Down
2 changes: 1 addition & 1 deletion src/types/tca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::Deserialize;
// Definition file : https://aviation.meteo.fr/FR/aviation/XSD/tca.xsd
// pub fn fetch() -> Result<Tca, AerowebError> {}

/// Parses the XML string into an `Tca` struct.
/// Parses the XML string into a `Tca` struct.
///
/// # Errors
///
Expand Down
2 changes: 1 addition & 1 deletion src/types/tcag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::Deserialize;
// Definition file : https://aviation.meteo.fr/FR/aviation/XSD/tcag.xsd
// pub fn fetch() -> Result<Tcag, AerowebError> {}

/// Parses the XML string into an `Tcag` struct.
/// Parses the XML string into a `Tcag` struct.
///
/// # Errors
///
Expand Down
2 changes: 1 addition & 1 deletion src/types/vaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::Deserialize;
// Definition file : https://aviation.meteo.fr/FR/aviation/XSD/vaa.xsd
// pub fn fetch() -> Result<Vaa, AerowebError> {}

/// Parses the XML string into an `Vaa` struct.
/// Parses the XML string into a `Vaa` struct.
///
/// # Errors
///
Expand Down
56 changes: 56 additions & 0 deletions src/types/vag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::error::Aeroweb;
use crate::types::helpers::{de_option_link, de_option_string};
use serde::Deserialize;

/// Retrieves volcanic hash warning graphics for a list of producing centers:
/// - FMEE (La Réunion)
/// - RJTD (Tokyo)
// Definition file : https://aviation.meteo.fr/FR/aviation/XSD/vag.xsd
// pub fn fetch() -> Result<Vag, AerowebError> {}

/// Parses the XML string into a `Vag` struct.
///
/// # Errors
///
/// Returns an error if the XML string cannot be parsed.
///
pub fn parse(xml: &str) -> Result<Vag, Aeroweb> {
quick_xml::de::from_str(xml).map_err(Aeroweb::Deserialize)
}

#[derive(Debug, Deserialize)]
pub struct Vag {
#[serde(default, rename = "VAG")]
pub centers: Vec<Center>,
}

#[derive(Debug, Deserialize)]
pub struct Center {
/// e.g. FMEE, RJTD
#[serde(rename = "@oaci")]
pub oaci: String,

/// e.g. LA REUNION, TOKYO
#[serde(rename = "@nom")]
pub nom: String,

/// e.g. 20240620210000
#[serde(rename = "@date_reception", deserialize_with = "de_option_string")]
pub date_reception: Option<String>,

#[serde(default, deserialize_with = "de_option_link")]
pub lien: Option<String>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_dossier() {
let data = std::fs::read_to_string("./data/vag.xml").unwrap();
let res = parse(&data);

assert!(res.is_ok());
}
}

0 comments on commit 5dffc62

Please sign in to comment.