asterix_parser 0.1.1

Playground do Protocolo ASTERIX
Documentation
use std::fs::OpenOptions;
use std::io::Read;

use super::{errors::ParseError, structures::DataRecord};

pub struct Loader;

impl Loader {
    pub fn load(filepath: &String) -> anyhow::Result<DataRecord> {
        let mut myfile = match OpenOptions::new()
        .read(true)
        .write(false)
        .create(false)
        .open(filepath) {
            Ok(f) => f,
            Err(_) => { return Err(ParseError::UapDefinitionNotFound { uap_name: filepath.clone() }.into())},
        };

        let mut raw_json = String::new();
        myfile.read_to_string(&mut raw_json).unwrap();

        let trimmed_json = raw_json.trim();
        let uap_definition = match serde_json::from_str(&trimmed_json) {
            Ok(d) => d,
            Err(_) => { return Err(ParseError::OpenUapJsonDefinitionError.into())}
        };

        Ok(uap_definition)
    }
}