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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#[cfg(feature = "std")]
use std::fs::File;
#[cfg(feature = "std")]
use std::io::BufWriter;
#[cfg(feature = "std")]
use std::path::Path;
use crate::errors::Result;
use crate::reader::BytesReader;
use crate::writer::{Writer, WriterBackend};
pub trait MessageWrite: Sized {
fn write_message<W: WriterBackend>(&self, _: &mut Writer<W>) -> Result<()> {
Ok(())
}
fn get_size(&self) -> usize {
0
}
#[cfg(feature = "std")]
fn write_file<P: AsRef<Path>>(&self, p: P) -> Result<()> {
let file = BufWriter::new(File::create(p)?);
let mut writer = Writer::new(file);
self.write_message(&mut writer)
}
}
pub trait MessageRead<'a>: Sized {
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self>;
}
pub trait MessageInfo {
const PATH: &'static str;
}