Thalweg · API reference ← Main docs

Crate twg_schema_bridge

Crate twg_schema_bridge 

Source
Expand description

Convert schemas between formats through a neutral hub (ADR-0064): every format converts to/from twg_contract_core::schema::SchemaModel (structure) so N formats cost N adapters, not N².

Implemented today: the protobuf → ODCS spoke — FileDescriptorSet (.pb) → neutral schema → ODCS v3.1.0. The reverse (ODCS → proto + .pb) and further spokes (JSON Schema, Avro) are planned; the JSON Schema / Avro leaf-type mappings already exist in twg-type-map, which becomes the leaf-type hub when those spokes are built.

use twg_schema_bridge::{descriptor_set_to_odcs, OdcsEmitOptions};

let pb = std::fs::read("bundle.pb").unwrap();
let opts = OdcsEmitOptions { id: "orders".into(), ..OdcsEmitOptions::default() };
let contract = descriptor_set_to_odcs(&pb, &opts)?;
std::fs::write("orders.odcs.json", contract.to_json_pretty().unwrap()).unwrap();

Structs§

Field
One field of a SchemaObject.
OdcsContract
A minimal ODCS v3.1.0 data contract, sufficient to describe a schema.
OdcsEmitOptions
Contract-level metadata for the emitted ODCS document.
SchemaModel
A complete set of schema objects that may reference each other by name.
SchemaObject
One named record/message type.

Enums§

BridgeError
Anything that can go wrong converting between schema formats.
Cardinality
How many values a field holds.
LogicalType
A leaf (scalar or reference) type, format-neutral but precise enough to reconstruct a source type (width/signedness preserved).

Functions§

descriptor_set_to_odcs
Convert a FileDescriptorSet (.pb) directly into an ODCS v3.1.0 contract.
descriptor_set_to_schema_model
Decode a FileDescriptorSet into the neutral schema model.
schema_model_to_odcs
Render a neutral schema model as an ODCS v3.1.0 contract.