surrealdb_core/sql/
serde.rs

1use bincode::Options;
2use bincode::Result;
3use serde::{Deserialize, Serialize};
4
5pub fn serialize<T>(value: &T) -> Result<Vec<u8>>
6where
7	T: ?Sized + Serialize,
8{
9	bincode::options()
10		// Don't specify a byte limit
11		.with_no_limit()
12		// Use little-endian data ordering
13		.with_little_endian()
14		// Use variable-sized integer encoding
15		.with_varint_encoding()
16		// Serialize the value
17		.serialize(value)
18}
19
20pub fn deserialize<'a, T>(bytes: &'a [u8]) -> Result<T>
21where
22	T: Deserialize<'a>,
23{
24	bincode::options()
25		// Don't specify a byte limit
26		.with_no_limit()
27		// Use little-endian data ordering
28		.with_little_endian()
29		// Use variable-sized integer encoding
30		.with_varint_encoding()
31		// Allow any remaining unused data
32		.allow_trailing_bytes()
33		// Deserialize the value
34		.deserialize(bytes)
35}