lemma/serialization/mod.rs
1//! Serialization module for converting external data formats to Lemma values.
2//!
3//! These functions convert data from external formats (JSON, MsgPack, Protobuf)
4//! into typed `LiteralValue`s ready for use with `ExecutionPlan::with_typed_values()`.
5//!
6//! The serializers are flexible about input formats while being strict about output types:
7//! - **Text facts** accept any JSON type (strings pass through, others serialize to JSON)
8//! - **Number facts** accept JSON numbers or parseable strings
9//! - **Percentage facts** accept JSON numbers or strings (with or without %)
10//! - **Boolean facts** accept JSON booleans or keyword strings
11//! - **null values** are skipped (treated as "fact not provided")
12//!
13//! # Example
14//!
15//! ```ignore
16//! use lemma::serialization::from_json;
17//!
18//! let json = br#"{"discount": 21, "config": {"key": "value"}, "name": null}"#;
19//! let values = from_json(json, &execution_plan)?;
20//! // discount -> Percentage(21)
21//! // config -> Text("{\"key\":\"value\"}") (if config is a text fact)
22//! // name -> skipped (null)
23//! let plan = execution_plan.with_typed_values(values, &limits)?;
24//! ```
25
26mod json;
27mod msgpack;
28mod protobuf;
29
30pub use json::from_json;
31pub use json::{
32 deserialize_fact_doc_ref_map, deserialize_fact_path_map, deserialize_fact_path_set,
33 deserialize_fact_source_map, deserialize_fact_type_map, deserialize_fact_value_map,
34 serialize_fact_doc_ref_map, serialize_fact_path_map, serialize_fact_path_set,
35 serialize_fact_source_map, serialize_fact_type_map, serialize_fact_value_map,
36 serialize_literal_value, serialize_operation_result,
37};
38pub use msgpack::from_msgpack;
39pub use protobuf::from_protobuf;