use crate::plugin::tables::data::{Key, Value};
use crate::plugin::tables::entry::raw::RawEntry;
use crate::plugin::tables::table::raw::RawTable;
use crate::plugin::tables::vtable::reader::TableReader;
use crate::plugin::tables::vtable::writer::TableWriter;
use crate::plugin::tables::vtable::TablesInput;
use falco_plugin_api::ss_plugin_table_t;
use std::sync::Arc;
pub trait TableMetadata: Sized {
fn new(raw_table: &RawTable, tables_input: &TablesInput) -> Result<Self, anyhow::Error>;
}
impl<M: TableMetadata> TableMetadata for Arc<M> {
fn new(raw_table: &RawTable, tables_input: &TablesInput) -> Result<Self, anyhow::Error> {
Ok(Arc::new(M::new(raw_table, tables_input)?))
}
}
pub trait Entry {
type Metadata: TableMetadata + Clone;
fn new(raw_entry: RawEntry, table: *mut ss_plugin_table_t, metadata: Self::Metadata) -> Self;
fn get_metadata(&self) -> &Self::Metadata;
fn into_raw(self) -> RawEntry;
}
pub trait EntryWrite<F, V: Value<AssocData = ()> + ?Sized> {
fn write_field(
&self,
writer: &impl TableWriter,
field: F,
val: &V,
) -> Result<(), anyhow::Error>;
}
pub trait TableAccess: Sized {
type Key;
type Entry;
type Metadata: TableMetadata + Clone;
fn new(raw_table: RawTable, metadata: Self::Metadata, is_nested: bool) -> Self;
fn get_entry(
&self,
reader_vtable: &impl TableReader,
key: &Self::Key,
) -> Result<Self::Entry, anyhow::Error>
where
Self::Key: Key,
Self::Entry: Entry;
}
pub trait RawFieldValueType {
type TableValue: ?Sized;
type EntryValue<'a>
where
Self: 'a;
}