server_fn/codec/
bitcode.rs1use super::{Patch, Post, Put};
2use crate::{ContentType, Decodes, Encodes, Format, FormatType};
3use bytes::Bytes;
4
5pub struct BitcodeEncoding;
7
8impl ContentType for BitcodeEncoding {
9 const CONTENT_TYPE: &'static str = "application/bitcode";
10}
11
12impl FormatType for BitcodeEncoding {
13 const FORMAT_TYPE: Format = Format::Binary;
14}
15
16impl<T> Encodes<T> for BitcodeEncoding
17where
18 T: bitcode::Encode,
19{
20 type Error = std::convert::Infallible;
21
22 fn encode(value: &T) -> Result<Bytes, Self::Error> {
23 Ok(Bytes::from(bitcode::encode(value)))
24 }
25}
26
27impl<T> Decodes<T> for BitcodeEncoding
28where
29 T: bitcode::DecodeOwned,
30{
31 type Error = bitcode::Error;
32
33 fn decode(bytes: Bytes) -> Result<T, Self::Error> {
34 bitcode::decode(bytes.as_ref())
35 }
36}
37
38pub type Bitcode = Post<BitcodeEncoding>;
40
41pub type PatchBitcode = Patch<BitcodeEncoding>;
45
46pub type PutBitcode = Put<BitcodeEncoding>;