use crate::obis::Obis;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
#[allow(missing_docs)]
pub enum AttrType {
Any,
OctetString,
VisibleString,
Utf8String,
Boolean,
BitString,
Integer,
Long,
DoubleLong,
Long64,
Unsigned,
LongUnsigned,
DoubleLongUnsigned,
Long64Unsigned,
Enum,
Float32,
Float64,
DateTime,
Date,
Time,
Array,
Structure,
ScalerUnit,
ObisCode,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DefaultAccess {
Read,
ReadWrite,
Write,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AttributeInfo {
pub index: i8,
pub name: &'static str,
pub ty: AttrType,
pub access: DefaultAccess,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MethodInfo {
pub index: i8,
pub name: &'static str,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ClassDescriptor {
pub class_id: u16,
pub version: u8,
pub name: &'static str,
pub attributes: &'static [AttributeInfo],
pub methods: &'static [MethodInfo],
}
impl ClassDescriptor {
#[must_use]
pub fn attribute(&self, index: i8) -> Option<&'static AttributeInfo> {
self.attributes.iter().find(|a| a.index == index)
}
#[must_use]
pub fn method(&self, index: i8) -> Option<&'static MethodInfo> {
self.methods.iter().find(|m| m.index == index)
}
#[must_use]
pub const fn is_name_only(&self) -> bool {
self.attributes.is_empty()
}
}
pub trait InterfaceClass {
const CLASS_ID: u16;
const VERSION: u8;
const NAME: &'static str;
fn descriptor() -> &'static ClassDescriptor;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ObjectRef {
pub class_id: u16,
pub version: u8,
pub logical_name: Obis,
}
impl ObjectRef {
#[must_use]
pub const fn new(class_id: u16, version: u8, logical_name: Obis) -> Self {
Self { class_id, version, logical_name }
}
#[must_use]
pub fn describe(&self) -> Option<&'static ClassDescriptor> {
super::registry::describe(self.class_id, self.version)
}
}