grpc_protobuf/
lib.rs

1#![deny(intra_doc_link_resolution_failure)]
2
3//! Implementation of marshaller for rust-protobuf parameter types.
4
5use bytes::Bytes;
6
7use grpc::marshall::Marshaller;
8
9use protobuf::CodedInputStream;
10use protobuf::Message;
11
12pub struct MarshallerProtobuf;
13
14impl<M: Message> Marshaller<M> for MarshallerProtobuf {
15    fn write_size_estimate(&self, _m: &M) -> grpc::Result<u32> {
16        // TODO: implement it
17        Ok(0)
18    }
19
20    fn write(&self, m: &M, _size_esimate: u32, out: &mut Vec<u8>) -> grpc::Result<()> {
21        m.write_to_vec(out)
22            .map_err(|e| grpc::Error::Marshaller(Box::new(e)))
23    }
24
25    fn read(&self, buf: Bytes) -> grpc::Result<M> {
26        // TODO: make protobuf simple
27        let mut is = CodedInputStream::from_carllerche_bytes(&buf);
28        let mut r: M = M::new();
29        r.merge_from(&mut is)
30            .map_err(|e| grpc::Error::Marshaller(Box::new(e)))?;
31        r.check_initialized()
32            .map_err(|e| grpc::Error::Marshaller(Box::new(e)))?;
33        Ok(r)
34    }
35}