ofdsdk
ofdsdk is a Rust SDK for OFD documents.
Chinese version: README_cn.md
Goals
- Generate strongly typed Rust structures from OFD XSD files.
- Provide stable XML deserialization and serialization.
- Provide OFD package reading and saving when the
partsfeature is enabled. - Keep real-world compatibility differences in generated data, not scattered runtime special cases.
Current version: 0.1.1.
Capabilities
- Rust schema types generated from
schemas/ - XML deserialization from strings and readers
- XML serialization
- OFD package reading and saving with the
partsfeature - Sample-based integration coverage for OFD packages
This repository contains three crates:
crates/ofdsdk: runtime library for consumerscrates/ofdsdk-build: code generatorcrates/ofdsdk-test: integration tests and sample validation
Installation
If you only need XML schema types:
[]
= "0.1.1"
If you also need to read .ofd archives:
[]
= { = "0.1.1", = ["parts"] }
The current minimum supported Rust version is 1.88.
Quick Start
1. Parse and write OFD XML
use Ofd;
2. Read an OFD package
use OfdPackage;
API Overview
Common entry points:
ofdsdk::schemas::*ofdsdk::deserializers::*ofdsdk::serializers::*ofdsdk::parts::*whenpartsis enabled
In short:
schemascontains the generated data typesdeserializerscontains XML input logicserializerscontains XML output logicpartscontains OFD package assembly and loading logic
Design Notes
1. schemas/ is the source of truth
The OFD models are derived from the XSD files under schemas/.
The generation flow is:
- Read the XSD files.
- Generate
sdk_data/schemas/*.json. - Generate
crates/ofdsdk/src/schemas/. - Generate the matching deserializers, serializers, and parts code.
2. Compatibility is data, not ad hoc runtime branching
Compatibility rules live in:
sdk_data/compatibility.json
The goal is not to accept everything blindly. The goal is to record known real-world differences explicitly and absorb them during generation.
3. parts describes package assembly
The parts metadata lives in:
sdk_data/parts/*.json
It describes:
- the root type of each part
- how paths are resolved
- how child parts are assembled recursively
- which parts depend on surrounding context
Current Status
0.1.1 is suitable for:
- OFD schema mapping
- XML round-trip testing
- validation against a set of real sample packages
It is still best treated as a low-level, engineering-focused SDK rather than a generic OFD reader that promises to handle everything.
Development
Common commands:
If you modify any of the following:
schemas/*.xsdsdk_data/compatibility.jsonsdk_data/parts/*.jsoncrates/ofdsdk-build
regenerate the code and review the generated diff.
License
This project is dual-licensed under:
- MIT
- Apache-2.0
You may use it under either license.