use std::marker::PhantomData;
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum EncodingFormat {
DBus,
GVariant,
}
impl Default for EncodingFormat {
fn default() -> Self {
EncodingFormat::DBus
}
}
impl std::fmt::Display for EncodingFormat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
EncodingFormat::DBus => write!(f, "D-Bus"),
EncodingFormat::GVariant => write!(f, "GVariant"),
}
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct EncodingContext<B> {
format: EncodingFormat,
position: usize,
b: PhantomData<B>,
}
impl<B> EncodingContext<B>
where
B: byteorder::ByteOrder,
{
pub fn new(format: EncodingFormat, position: usize) -> Self {
Self {
format,
position,
b: PhantomData,
}
}
pub fn new_dbus(position: usize) -> Self {
Self::new(EncodingFormat::DBus, position)
}
pub fn new_gvariant(position: usize) -> Self {
Self::new(EncodingFormat::GVariant, position)
}
pub fn format(self) -> EncodingFormat {
self.format
}
pub fn position(self) -> usize {
self.position
}
}