openiap_proto/
upload.rs

1#![warn(missing_docs)]
2use super::openiap::{Envelope, UploadRequest, BeginStream, EndStream, Stream};
3impl UploadRequest {
4    /// Creates a new `UploadRequest` with the given `workitem`.
5    pub fn filename(filename: &str) -> Self {
6        Self {
7            collectionname: "fs.files".to_string(),
8            filename: filename.to_string(),
9            ..Default::default()
10        }
11    }
12    /// Creates a new `UploadRequest` with the given `workitem`.
13    pub fn by_filename(collectionname: &str, filename: &str) -> Self {
14        Self {
15            collectionname: collectionname.to_string(),
16            filename: filename.to_string(),
17            ..Default::default()
18        }
19    }
20}
21impl UploadRequest {
22    /// Creates a new `UploadRequest` with the given `workitem`.
23    pub fn to_envelope(&self) -> Envelope {
24        let any_message = prost_types::Any {
25            type_url: "type.googleapis.com/openiap.UploadRequest".to_string(),
26            value: {
27                let mut buf = Vec::new();
28                prost::Message::encode(self, &mut buf).unwrap_or(());
29                buf
30            },
31        };
32        Envelope {
33            command: "upload".into(),
34            data: Some(any_message.clone()),
35            ..Default::default() 
36        }
37    }
38}
39impl BeginStream {
40    /// Creates a new `BeginStream` with the given `workitem`.
41    pub fn to_envelope(&self, rid:String) -> Envelope {
42        let any_message = prost_types::Any {
43            type_url: "type.googleapis.com/openiap.BeginStream".to_string(),
44            value: {
45                let mut buf = Vec::new();
46                prost::Message::encode(self, &mut buf).unwrap_or(());
47                buf
48            },
49        };
50        Envelope {
51            command: "beginstream".into(),
52            data: Some(any_message.clone()),
53            rid,
54            ..Default::default() 
55        }
56    }
57    /// Creates a new `BeginStream` with the given `workitem`.
58    pub fn from_rid(rid:String) -> Envelope {
59        let req = BeginStream {
60            checksum: "".to_string(),
61            ..Default::default()
62        };
63        let envelope = req.to_envelope(rid);
64        let mut buf = Vec::new();
65        prost::Message::encode(&envelope, &mut buf).unwrap_or(());
66        envelope
67    }   
68}
69impl EndStream {
70    /// Creates a new `EndStream` with the given `workitem`.
71    pub fn to_envelope(&self, rid:String) -> Envelope {
72        let any_message = prost_types::Any {
73            type_url: "type.googleapis.com/openiap.EndStream".to_string(),
74            value: {
75                let mut buf = Vec::new();
76                prost::Message::encode(self, &mut buf).unwrap_or(());
77                buf
78            },
79        };
80        Envelope {
81            command: "endstream".into(),
82            data: Some(any_message.clone()),
83            rid,
84            ..Default::default() 
85        }
86    }
87    /// Creates a new `EndStream` with the given `workitem`.
88    pub fn from_rid(rid:String) -> Envelope {
89        let req = EndStream {            
90        };
91        let envelope = req.to_envelope(rid);
92        let mut buf = Vec::new();
93        prost::Message::encode(&envelope, &mut buf).unwrap_or(());
94        envelope
95    }   
96}
97impl Stream {
98    /// Creates a new `Stream` with the given `workitem`.
99    pub fn to_envelope(&self, rid:String) -> Envelope {
100        let any_message = prost_types::Any {
101            type_url: "type.googleapis.com/openiap.Stream".to_string(),
102            value: {
103                let mut buf = Vec::new();
104                prost::Message::encode(self, &mut buf).unwrap_or(());
105                buf
106            },
107        };
108        Envelope {
109            command: "stream".into(),
110            data: Some(any_message.clone()),
111            rid,
112            ..Default::default() 
113        }
114    }
115    /// Creates a new `Stream` with the given `workitem`.
116    pub fn from_rid(data: Vec<u8>, rid:String) -> Envelope {
117        let req = Stream {
118            data
119        };
120        let envelope = req.to_envelope(rid);
121        let mut buf = Vec::new();
122        prost::Message::encode(&envelope, &mut buf).unwrap_or(());
123        envelope
124    }    
125}