oxgraph_postgres/artifact/
mod.rs1mod metadata;
4mod sections;
5
6pub use metadata::{
7 PostgresMetadata, PostgresSectionError, SNAPSHOT_KIND_PG_CATALOG,
8 SNAPSHOT_KIND_PG_INBOUND_OFFSETS_U32, SNAPSHOT_KIND_PG_INBOUND_TARGETS_U32,
9 SNAPSHOT_KIND_PG_METADATA,
10};
11use oxgraph_snapshot::Snapshot;
12pub use sections::{attach_metadata, attach_postgres_sections};
13
14use crate::error::{BuildError, PostgresGraphError};
15
16pub fn load_snapshot_bytes(bytes: &[u8]) -> Result<Snapshot<'_>, PostgresGraphError> {
26 Snapshot::open(bytes).map_err(PostgresGraphError::from)
27}
28
29pub fn validate_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
39 let _ = Snapshot::open(bytes)?;
40 Ok(bytes.to_vec())
41}
42
43pub fn read_metadata(snapshot: &Snapshot<'_>) -> Result<PostgresMetadata, PostgresGraphError> {
54 metadata::read_postgres_metadata(snapshot).map_err(|error| match error {
55 PostgresSectionError::Snapshot(snapshot_error) => {
56 PostgresGraphError::Snapshot(snapshot_error)
57 }
58 PostgresSectionError::MissingSection => {
59 PostgresGraphError::Build(BuildError::MissingMetadataSection)
60 }
61 PostgresSectionError::Malformed(message) => {
62 PostgresGraphError::Build(BuildError::MalformedMetadata(message))
63 }
64 })
65}
66
67pub fn write_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
77 validate_snapshot_bytes(bytes)
78}