surrealdb_sql/
serde.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use bincode::Options;
use bincode::Result;
use serde::{Deserialize, Serialize};

pub fn serialize<T: ?Sized>(value: &T) -> Result<Vec<u8>>
where
	T: Serialize,
{
	bincode::options()
		.with_no_limit()
		.with_little_endian()
		.with_varint_encoding()
		.reject_trailing_bytes()
		.serialize(value)
}

pub fn deserialize<'a, T>(bytes: &'a [u8]) -> Result<T>
where
	T: Deserialize<'a>,
{
	bincode::options()
		.with_no_limit()
		.with_little_endian()
		.with_varint_encoding()
		// Ignore extra fields so we can pull out the ID only from responses that fail to deserialise
		.allow_trailing_bytes()
		.deserialize(bytes)
}