#![forbid(unsafe_code)]
#[cfg(feature = "host")]
pub mod host;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct ConsolePage {
pub columns: Vec<String>,
pub rows: Vec<Vec<String>>,
pub next: Option<Vec<u8>>,
pub examined: u32,
pub fetched: u32,
pub output_bytes: u32,
}
#[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize)]
pub struct PayloadFilters {
pub minimum: Option<Vec<u8>>,
pub maximum: Option<Vec<u8>>,
pub prefix: Option<Vec<u8>>,
pub suffix: Option<Vec<u8>>,
pub contains: Option<Vec<u8>>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryRequest {
pub entity: String,
pub cursor: Option<Vec<u8>>,
pub limit: u32,
pub minimum: Option<u64>,
pub category: Option<u64>,
pub entry_id: Option<u64>,
pub order: Vec<String>,
pub descending: bool,
pub work: u32,
pub bytes: u32,
pub select: String,
pub options: QueryOptions,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryOptions {
pub distinct: bool,
pub group_bounds: (Option<String>, Option<String>),
pub group_order: Option<String>,
pub filters: RowFilters,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Status {
pub schema: [u8; 32],
pub incarnation: [u8; 16],
pub revision: u64,
pub pages: u64,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SchemaResponse {
pub status: Status,
pub entities: Vec<EntityView>,
pub types: Vec<TypeView>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct EntityView {
pub name: String,
pub id: u32,
pub primary: String,
pub fields: Vec<FieldView>,
pub indexes: Vec<IndexView>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct FieldView {
pub name: String,
pub kind: String,
pub optional: bool,
pub info: String,
pub reference: Option<(String, String)>,
}
pub type IndexView = (String, Vec<String>, bool, bool);
pub type TypeView = (String, String, Vec<(String, String, bool, String)>);
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct RowFilters {
pub payload: PayloadFilters,
pub compare: Option<[String; 3]>,
pub length: Option<(String, String, u32)>,
pub present: Option<String>,
pub absent: Option<String>,
pub text: Option<[String; 3]>,
pub boolean: Option<(String, bool)>,
pub between_fields: Option<[String; 3]>,
pub not_between_fields: Option<[String; 3]>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct RetainedSelection {
pub entity: String,
pub select: String,
pub entity_filters: (Option<u64>, Option<u64>, Option<u64>),
pub limit: u32,
pub group_bounds: (Option<String>, Option<String>),
pub group_order: Option<String>,
pub filters: RowFilters,
pub order: (Vec<String>, bool),
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct RetainedResume {
pub selection: RetainedSelection,
pub handle: Vec<u8>,
pub sequence: u64,
pub work: u32,
pub bytes: u32,
pub page_size: u32,
pub after: Option<Vec<u8>>,
}
pub type RetainedOutput = (Vec<String>, Vec<Vec<String>>, Option<Vec<u8>>);
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct RetainedProgress {
pub sequence: u64,
pub examined: u64,
pub input_bytes: u64,
pub output_bytes: u64,
pub phase: RetainedPhase,
}
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum RetainedPhase {
Running,
Complete(RetainedOutput),
Invalidated,
Expired,
}
impl RetainedPhase {
#[must_use]
pub const fn label(&self) -> &'static str {
match self {
Self::Running => "Running",
Self::Complete(_) => "Complete",
Self::Invalidated => "Invalidated",
Self::Expired => "Expired",
}
}
}
#[must_use]
pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
const DIGITS: &[u8; 16] = b"0123456789abcdef";
let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
output.push_str(prefix);
for &byte in bytes {
output.push(char::from(DIGITS[usize::from(byte >> 4)]));
output.push(char::from(DIGITS[usize::from(byte & 15)]));
}
output
}