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
#![deny(intra_doc_link_resolution_failure)]
use bytes::Bytes;
use grpc::marshall::Marshaller;
use protobuf::CodedInputStream;
use protobuf::Message;
pub struct MarshallerProtobuf;
impl<M: Message> Marshaller<M> for MarshallerProtobuf {
fn write_size_estimate(&self, _m: &M) -> grpc::Result<u32> {
Ok(0)
}
fn write(&self, m: &M, _size_esimate: u32, out: &mut Vec<u8>) -> grpc::Result<()> {
m.write_to_vec(out)
.map_err(|e| grpc::Error::Marshaller(Box::new(e)))
}
fn read(&self, buf: Bytes) -> grpc::Result<M> {
let mut is = CodedInputStream::from_carllerche_bytes(&buf);
let mut r: M = M::new();
r.merge_from(&mut is)
.map_err(|e| grpc::Error::Marshaller(Box::new(e)))?;
r.check_initialized()
.map_err(|e| grpc::Error::Marshaller(Box::new(e)))?;
Ok(r)
}
}