use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct SerializationOptions {
pub pretty_print: bool,
pub compact: bool,
pub prefixes: HashMap<String, String>,
pub base_iri: Option<String>,
pub indent_string: String,
pub streaming: bool,
pub compression: CompressionType,
pub buffer_size: usize,
pub batch_size: usize,
pub parallel: bool,
pub max_threads: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompressionType {
None,
Gzip,
Zstd,
Lz4,
}
#[derive(Debug, Clone)]
pub struct StreamingConfig {
pub chunk_size: usize,
pub memory_threshold: usize,
pub enable_buffering: bool,
pub buffer_capacity: usize,
pub compress_chunks: bool,
}
impl Default for StreamingConfig {
fn default() -> Self {
Self {
chunk_size: 10000,
memory_threshold: 64 * 1024 * 1024, enable_buffering: true,
buffer_capacity: 1024 * 1024, compress_chunks: false,
}
}
}
impl Default for SerializationOptions {
fn default() -> Self {
Self {
pretty_print: true,
compact: false,
prefixes: HashMap::new(),
base_iri: None,
indent_string: " ".to_string(),
streaming: false,
compression: CompressionType::None,
buffer_size: 1024 * 1024, batch_size: 10000,
parallel: false,
max_threads: 4,
}
}
}
#[derive(Debug, Default)]
pub(crate) struct SerializationContext {
pub(crate) prefixes: HashMap<String, String>,
#[allow(dead_code)]
pub(crate) base_iri: Option<String>,
pub(crate) pretty_print: bool,
pub(crate) indent_level: usize,
pub(crate) indent_string: String,
}
impl SerializationContext {
pub(crate) fn new() -> Self {
Self {
prefixes: HashMap::new(),
base_iri: None,
pretty_print: true,
indent_level: 0,
indent_string: " ".to_string(),
}
}
pub(crate) fn add_prefix(&mut self, prefix: &str, namespace: &str) {
self.prefixes
.insert(prefix.to_string(), namespace.to_string());
}
pub(crate) fn current_indent(&self) -> String {
self.indent_string.repeat(self.indent_level)
}
pub(crate) fn increase_indent(&mut self) {
self.indent_level += 1;
}
pub(crate) fn decrease_indent(&mut self) {
if self.indent_level > 0 {
self.indent_level -= 1;
}
}
pub(crate) fn compress_iri(&self, iri: &str) -> String {
for (prefix, namespace) in &self.prefixes {
if iri.starts_with(namespace) {
let local = &iri[namespace.len()..];
return format!("{prefix}:{local}");
}
}
format!("<{iri}>")
}
}