1mod bare_conduit;
12pub use bare_conduit::*;
13pub use vox_types::TransportMode;
14
15mod handshake;
16pub use handshake::*;
17
18mod into_conduit;
19pub use into_conduit::*;
20
21mod operation_store;
22pub use operation_store::*;
23
24mod transport_prologue;
25pub use transport_prologue::*;
26
27#[cfg(not(target_arch = "wasm32"))]
28mod stable_conduit;
29#[cfg(not(target_arch = "wasm32"))]
30pub use stable_conduit::*;
31
32#[cfg(not(target_arch = "wasm32"))]
33mod memory_link;
34#[cfg(not(target_arch = "wasm32"))]
35pub use memory_link::*;
36
37mod session;
38pub use session::*;
39
40mod driver;
41pub use driver::*;
42
43use facet_reflect::Partial;
44use vox_types::{Backing, SelfRef};
45
46pub struct MessagePlan {
52 pub plan: vox_postcard::plan::TranslationPlan,
53 pub registry: vox_types::SchemaRegistry,
54}
55
56impl MessagePlan {
57 pub fn from_handshake(result: &vox_types::HandshakeResult) -> Result<Self, String> {
59 use vox_postcard::plan::{PlanInput, SchemaSet, build_plan};
60
61 if result.peer_schema.is_empty() || result.our_schema.is_empty() {
62 let plan = vox_postcard::build_identity_plan(
64 <vox_types::Message<'static> as facet::Facet<'static>>::SHAPE,
65 );
66 return Ok(MessagePlan {
67 plan,
68 registry: vox_types::SchemaRegistry::new(),
69 });
70 }
71
72 let remote = SchemaSet::from_schemas(result.peer_schema.clone());
73 let local = SchemaSet::from_schemas(result.our_schema.clone());
74
75 let plan = build_plan(&PlanInput {
76 remote: &remote,
77 local: &local,
78 })
79 .map_err(|e| format!("failed to build message translation plan: {e}"))?;
80
81 Ok(MessagePlan {
82 plan,
83 registry: remote.registry,
84 })
85 }
86}
87
88pub(crate) fn deserialize_postcard<T: facet::Facet<'static>>(
92 backing: Backing,
93) -> Result<SelfRef<T>, vox_postcard::DeserializeError> {
94 let plan = vox_postcard::build_identity_plan(T::SHAPE);
95 let registry = vox_types::SchemaRegistry::new();
96 deserialize_postcard_with_plan(backing, &plan, ®istry)
97}
98
99pub(crate) fn deserialize_postcard_with_plan<T: facet::Facet<'static>>(
103 backing: Backing,
104 plan: &vox_postcard::plan::TranslationPlan,
105 registry: &vox_types::SchemaRegistry,
106) -> Result<SelfRef<T>, vox_postcard::DeserializeError> {
107 SelfRef::try_new(backing, |bytes| {
110 let mut value = std::mem::MaybeUninit::<T>::uninit();
111 let ptr = facet_core::PtrUninit::from_maybe_uninit(&mut value);
112
113 #[allow(unsafe_code)]
115 let partial: Partial<'_, true> = unsafe { Partial::from_raw_with_shape(ptr, T::SHAPE) }
116 .map_err(|e| vox_postcard::DeserializeError::ReflectError(e.to_string()))?;
117
118 let partial = vox_postcard::deserialize_into(partial, bytes, plan, registry)?;
119
120 partial
121 .finish_in_place()
122 .map_err(|e| vox_postcard::DeserializeError::ReflectError(e.to_string()))?;
123
124 #[allow(unsafe_code)]
126 Ok(unsafe { value.assume_init() })
127 })
128}
129
130pub mod testing;
131
132#[cfg(test)]
133mod tests;