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_BASE, SNAPSHOT_KIND_PG_INBOUND_OFFSETS_U32,
9 SNAPSHOT_KIND_PG_INBOUND_TARGETS_BASE, SNAPSHOT_KIND_PG_INBOUND_TARGETS_U32,
10 SNAPSHOT_KIND_PG_METADATA,
11};
12use oxgraph_snapshot::Snapshot;
13pub use sections::{attach_metadata, attach_postgres_sections};
14
15use crate::error::{BuildError, PostgresGraphError};
16
17pub fn load_snapshot_bytes(bytes: &[u8]) -> Result<Snapshot<'_>, PostgresGraphError> {
27 Snapshot::open(bytes).map_err(PostgresGraphError::from)
28}
29
30pub fn validate_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
40 let _ = Snapshot::open(bytes)?;
41 Ok(bytes.to_vec())
42}
43
44pub fn read_metadata(snapshot: &Snapshot<'_>) -> Result<PostgresMetadata, PostgresGraphError> {
55 metadata::read_postgres_metadata(snapshot).map_err(|error| match error {
56 PostgresSectionError::Snapshot(snapshot_error) => {
57 PostgresGraphError::Snapshot(snapshot_error)
58 }
59 PostgresSectionError::MissingSection => {
60 PostgresGraphError::Build(BuildError::MissingMetadataSection)
61 }
62 PostgresSectionError::Malformed(message) => {
63 PostgresGraphError::Build(BuildError::MalformedMetadata(message))
64 }
65 })
66}
67
68pub fn write_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
78 validate_snapshot_bytes(bytes)
79}