blob: 5eb8f2a8a6b95da07c2ee282d8909df1e66809d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#[derive(Debug)]
pub enum SerializeErr {
FailedJsonEncode(String),
InconsistentPlayerActions(String)
}
pub type SerializeResult = Result<(), SerializeErr>;
pub trait Serialize: Sized {
fn mc_serialize<S: Serializer>(&self, to: &mut S) -> SerializeResult;
}
pub trait Serializer: Sized {
fn serialize_bytes(&mut self, data: &[u8]) -> SerializeResult;
fn serialize_byte(&mut self, byte: u8) -> SerializeResult {
self.serialize_bytes(vec!(byte).as_slice())
}
fn serialize_other<S: Serialize>(&mut self, other: &S) -> SerializeResult {
other.mc_serialize(self)
}
}
|