Skip to main content

fidius_core/
wire.rs

1// Copyright 2026 Colliery, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Wire format serialization for Fidius plugin FFI boundary.
16//!
17//! Fidius uses bincode as the single wire format for all FFI data. Prior to
18//! 0.1.0 the format varied by build profile (JSON in debug, bincode in
19//! release) — that was removed because profile-mixed host/plugin load
20//! rejections caused repeated dev-loop friction with no real inspection
21//! benefit to offset them.
22
23use serde::de::DeserializeOwned;
24use serde::Serialize;
25
26/// Errors that can occur during wire serialization or deserialization.
27#[derive(Debug, thiserror::Error)]
28pub enum WireError {
29    /// Bincode serialization/deserialization error.
30    #[error("bincode wire error: {0}")]
31    Bincode(#[from] bincode::Error),
32}
33
34/// Serialize a value as bincode for transport across the FFI boundary.
35pub fn serialize<T: Serialize>(val: &T) -> Result<Vec<u8>, WireError> {
36    bincode::serialize(val).map_err(WireError::Bincode)
37}
38
39/// Deserialize a value from bincode bytes received across the FFI boundary.
40pub fn deserialize<T: DeserializeOwned>(bytes: &[u8]) -> Result<T, WireError> {
41    bincode::deserialize(bytes).map_err(WireError::Bincode)
42}