bitwarden_ipc/
serde_utils.rs

1//! Global serialization and deserialization utilities for IPC messages.
2//! This module provides functions to serialize and deserialize IPC messages in one place,
3//! ensuring consistency and reducing code duplication across the IPC crate.
4
5use serde::{de::DeserializeOwned, Serialize};
6
7pub(crate) type SerializeError = serde_json::Error;
8pub(crate) type DeserializeError = serde_json::Error;
9
10pub(crate) fn to_vec<T: Serialize>(value: &T) -> Result<Vec<u8>, serde_json::Error> {
11    serde_json::to_vec(value)
12}
13
14pub(crate) fn from_slice<T: DeserializeOwned>(data: &[u8]) -> Result<T, serde_json::Error> {
15    serde_json::from_slice(data)
16}