kekbit_codecs/
codecs.rs

1use std::io::Write;
2///A data format that can be use by a kekbit channel
3pub trait DataFormat {
4    ///Returns the unique identifer of this data format. As a convention `'standard`
5    /// data formats must have an id below 2^32, while application specific formats
6    /// should have an id equal or greater with 2^32
7    fn id() -> u64;
8    /// Returns the media type associated with this codec. This value is just informative.
9    /// E.g for a Json encoder should return "`application/json`
10    fn media_type() -> &'static str;
11}
12
13///An entity which can be written in a channel using the specified data format
14pub trait Encodable<D: DataFormat> {
15    fn encode_to(&self, d: &D, w: &mut impl Write) -> std::io::Result<usize>;
16}
17
18// struct JsonDataFormat;
19
20// impl DataFormat for JsonDataFormat {
21//     fn id() -> u64 {
22//         17
23//     }
24//     fn media_type() -> &'static str {
25//         "application/json"
26//     }
27// }
28
29// impl<T: Serialize> Encodable<JsonDataFormat> for T {
30//     fn encode_to(&self, _format: &JsonDataFormat, w: &mut impl Write) {
31//         to_writer(w, self).unwrap();
32//     }
33// }
34
35pub mod raw;
36pub mod text;