mod paths;
mod views;
use alloc::vec::Vec;
use oxirush_utils::tree::Value;
use crate::Error;
pub use crate::json::Form;
pub use paths::{
EDITED, Members, check_path, enumerated_at, extended, insert, listed_ies, member_shape,
named_ies, of_a_transfer, open, paths, remove, select, set, written_ie,
};
pub use views::{Parts, of_the_pdu, tree, tree_parts, view, view_of_jer, view_parts};
pub type Decoded = (Value, bool, Option<Error>);
#[derive(Clone, Copy)]
pub struct Typed {
pub decode: fn(&[u8]) -> Result<Decoded, Error>,
pub encode: fn(&Value) -> Result<Vec<u8>, Error>,
}
pub type Message = (
&'static str,
u8,
&'static str,
fn() -> Typed,
&'static [(u16, bool)],
&'static str,
);
pub type Transfer = (
&'static str,
&'static str,
&'static [(u16, bool)],
&'static [(u16, &'static str)],
);
pub struct Protocol {
pub name: &'static str,
pub root: &'static str,
pub types: &'static [(&'static str, Kind)],
pub messages: &'static [Message],
pub ie_names: &'static [(u16, &'static str)],
pub ie_types: &'static [(u16, &'static str, &'static str)],
pub extension_types: &'static [(u16, &'static str, &'static str)],
pub carried: &'static [(u16, &'static str, &'static str)],
pub enumerations: &'static [(&'static str, &'static [&'static str])],
pub item_criticalities: &'static [(u16, &'static str)],
pub message_ie_criticalities: &'static [(&'static str, &'static [(u16, &'static str)])],
pub transfers: &'static [Transfer],
pub ie_id: fn(&str) -> Option<u16>,
pub kind_of: fn(&str) -> Option<&'static Kind>,
pub procedure_criticalities: &'static [(u8, &'static str)],
pub ie_typed: fn(u16) -> Result<Typed, Error>,
pub extension_typed: fn(u16, &str) -> Option<Typed>,
pub ie_contents: fn(u16) -> Option<Typed>,
pub type_form: fn(&str) -> Option<Form>,
pub transfer_fields: &'static [&'static str],
pub transfer_typed: fn(&str) -> Result<Typed, Error>,
pub carried_typed: fn(&str) -> Option<Typed>,
pub any_message: fn() -> Typed,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub enum Shape {
#[default]
Unknown,
Undecoded,
Pdu(Option<Sent>),
Message(Sent),
AnyMessage,
Plain,
Null,
Bits,
Named(&'static str),
List(&'static Shape),
Ies(Option<Sent>),
Extensions(&'static str),
Ie(Option<u16>),
Extension(Option<u16>, &'static str),
Transfer(&'static str),
Carrier(u16),
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Sent {
pub(crate) name: &'static str,
pub(crate) ty: &'static str,
pub(crate) ies: &'static [(u16, bool)],
}
pub type Member = (&'static str, Shape, bool);
#[derive(Debug)]
pub enum Kind {
Sequence(&'static [Member]),
Choice(&'static [Member]),
Is(Shape),
}
pub fn same_name(a: &str, b: &str) -> bool {
oxirush_utils::tree::same_name(a, b)
}
pub fn type_name(path: &'static str) -> &'static str {
let name = path.rsplit(':').next().unwrap_or(path);
name.split('<').next().unwrap_or(name).trim()
}