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
//! Implementation of marshaller for protobuf parameter types.

use bytes::Bytes;

use marshall::Marshaller;

use protobuf_lib::CodedInputStream;
use protobuf_lib::Message;

use result;

pub struct MarshallerProtobuf;

impl<M: Message> Marshaller<M> for MarshallerProtobuf {
    fn write(&self, m: &M) -> result::Result<Vec<u8>> {
        Ok(m.write_to_bytes()?)
    }

    fn read(&self, buf: Bytes) -> result::Result<M> {
        // TODO: make protobuf simple
        let mut is = CodedInputStream::from_carllerche_bytes(&buf);
        let mut r: M = M::new();
        r.merge_from(&mut is)?;
        r.check_initialized()?;
        Ok(r)
    }
}