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
27mod stable_conduit;
28pub use stable_conduit::*;
29
30#[cfg(not(target_arch = "wasm32"))]
31mod memory_link;
32#[cfg(not(target_arch = "wasm32"))]
33pub use memory_link::*;
34
35mod session;
36pub use session::*;
37
38mod driver;
39pub use driver::*;
40
41use facet_reflect::Partial;
42use vox_types::{Backing, SelfRef};
43
44pub struct MessagePlan {
50 pub plan: vox_postcard::plan::TranslationPlan,
51 pub registry: vox_types::SchemaRegistry,
52}
53
54impl MessagePlan {
55 pub fn from_handshake(result: &vox_types::HandshakeResult) -> Result<Self, String> {
57 use vox_postcard::plan::{PlanInput, SchemaSet, build_plan};
58
59 if result.peer_schema.is_empty() || result.our_schema.is_empty() {
60 let plan = vox_postcard::build_identity_plan(
62 <vox_types::Message<'static> as facet::Facet<'static>>::SHAPE,
63 );
64 return Ok(MessagePlan {
65 plan,
66 registry: vox_types::SchemaRegistry::new(),
67 });
68 }
69
70 let remote = SchemaSet::from_schemas(result.peer_schema.clone());
71 let local = SchemaSet::from_schemas(result.our_schema.clone());
72
73 let plan = build_plan(&PlanInput {
74 remote: &remote,
75 local: &local,
76 })
77 .map_err(|e| format!("failed to build message translation plan: {e}"))?;
78
79 Ok(MessagePlan {
80 plan,
81 registry: remote.registry,
82 })
83 }
84}
85
86pub(crate) fn deserialize_postcard<T: facet::Facet<'static>>(
90 backing: Backing,
91) -> Result<SelfRef<T>, vox_postcard::DeserializeError> {
92 let plan = vox_postcard::build_identity_plan(T::SHAPE);
93 let registry = vox_types::SchemaRegistry::new();
94 deserialize_postcard_with_plan(backing, &plan, ®istry)
95}
96
97pub(crate) fn deserialize_postcard_with_plan<T: facet::Facet<'static>>(
101 backing: Backing,
102 plan: &vox_postcard::plan::TranslationPlan,
103 registry: &vox_types::SchemaRegistry,
104) -> Result<SelfRef<T>, vox_postcard::DeserializeError> {
105 SelfRef::try_new(backing, |bytes| {
108 let mut value = std::mem::MaybeUninit::<T>::uninit();
109 let ptr = facet_core::PtrUninit::from_maybe_uninit(&mut value);
110
111 #[allow(unsafe_code)]
113 let partial: Partial<'_, true> = unsafe { Partial::from_raw_with_shape(ptr, T::SHAPE) }
114 .map_err(|e| vox_postcard::DeserializeError::ReflectError(e.to_string()))?;
115
116 let partial = vox_postcard::deserialize_into(partial, bytes, plan, registry)?;
117
118 partial
119 .finish_in_place()
120 .map_err(|e| vox_postcard::DeserializeError::ReflectError(e.to_string()))?;
121
122 #[allow(unsafe_code)]
124 Ok(unsafe { value.assume_init() })
125 })
126}
127
128pub mod testing;
129
130#[cfg(test)]
131mod tests;