mod metadata;
mod sections;
pub use metadata::{
PostgresMetadata, PostgresSectionError, SNAPSHOT_KIND_PG_CATALOG,
SNAPSHOT_KIND_PG_INBOUND_OFFSETS_U32, SNAPSHOT_KIND_PG_INBOUND_TARGETS_U32,
SNAPSHOT_KIND_PG_METADATA,
};
use oxgraph_snapshot::Snapshot;
pub use sections::{attach_metadata, attach_postgres_sections};
use crate::error::{BuildError, PostgresGraphError};
pub fn load_snapshot_bytes(bytes: &[u8]) -> Result<Snapshot<'_>, PostgresGraphError> {
Snapshot::open(bytes).map_err(PostgresGraphError::from)
}
pub fn validate_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
let _ = Snapshot::open(bytes)?;
Ok(bytes.to_vec())
}
pub fn read_metadata(snapshot: &Snapshot<'_>) -> Result<PostgresMetadata, PostgresGraphError> {
metadata::read_postgres_metadata(snapshot).map_err(|error| match error {
PostgresSectionError::Snapshot(snapshot_error) => {
PostgresGraphError::Snapshot(snapshot_error)
}
PostgresSectionError::MissingSection => {
PostgresGraphError::Build(BuildError::MissingMetadataSection)
}
PostgresSectionError::Malformed(message) => {
PostgresGraphError::Build(BuildError::MalformedMetadata(message))
}
})
}
pub fn write_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
validate_snapshot_bytes(bytes)
}