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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use {Error, Settings};
use hint;
use std::io::prelude::*;
use std::io;
pub trait Parcel : Sized
{
const TYPE_NAME: &'static str;
fn read(read: &mut dyn Read,
settings: &Settings) -> Result<Self, Error> {
Self::read_field(read, settings, &mut hint::Hints::default())
}
fn read_field(read: &mut dyn Read,
settings: &Settings,
hints: &mut hint::Hints) -> Result<Self, Error>;
fn write(&self, write: &mut dyn Write,
settings: &Settings) -> Result<(), Error> {
self.write_field(write, settings, &mut hint::Hints::default())
}
fn write_field(&self, write: &mut dyn Write,
settings: &Settings,
hints: &mut hint::Hints) -> Result<(), Error>;
fn into_stream(self, settings: &Settings)
-> Result<io::Cursor<Vec<u8>>, Error> {
self.raw_bytes(settings).map(io::Cursor::new)
}
fn from_raw_bytes(bytes: &[u8],
settings: &Settings) -> Result<Self, Error> {
let mut hints = hint::Hints::default();
Self::field_from_raw_bytes(bytes, settings, &mut hints)
}
fn field_from_raw_bytes(bytes: &[u8],
settings: &Settings,
hints: &mut hint::Hints) -> Result<Self, Error> {
let mut buffer = ::std::io::Cursor::new(bytes);
Self::read_field(&mut buffer, settings, hints)
}
fn raw_bytes(&self, settings: &Settings) -> Result<Vec<u8>, Error> {
self.raw_bytes_field(settings, &mut hint::Hints::default())
}
fn raw_bytes_field(&self,
settings: &Settings,
hints: &mut hint::Hints) -> Result<Vec<u8>, Error> {
let mut buffer = io::Cursor::new(Vec::new());
self.write_field(&mut buffer, settings, hints)?;
Ok(buffer.into_inner())
}
fn type_name(&self) -> &'static str { Self::TYPE_NAME }
}