tencentcloud_cls_sdk_rust/
cls_log.rs

1// Automatically generated rust module for 'log.proto' file
2
3#![allow(non_snake_case)]
4#![allow(non_upper_case_globals)]
5#![allow(non_camel_case_types)]
6#![allow(unused_imports)]
7#![allow(unknown_lints)]
8#![allow(clippy::all)]
9#![cfg_attr(rustfmt, rustfmt_skip)]
10
11
12use std::borrow::Cow;
13
14use bytes::Bytes;
15use quick_protobuf::{BytesReader, MessageInfo, MessageRead, MessageWrite, Result, Writer, WriterBackend};
16use quick_protobuf::sizeofs::*;
17
18use super::*;
19
20#[allow(clippy::derive_partial_eq_without_eq)]
21#[derive(Debug, Default, PartialEq, Clone)]
22pub struct Log<'a> {
23    pub time: i64,
24    pub contents: Vec<cls_log::mod_Log::Content<'a>>,
25    pub collectTime: Option<i64>,
26}
27
28impl<'a> MessageRead<'a> for Log<'a> {
29    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
30        let mut msg = Self::default();
31        while !r.is_eof() {
32            match r.next_tag(bytes) {
33                Ok(8) => msg.time = r.read_int64(bytes)?,
34                Ok(18) => msg.contents.push(r.read_message::<cls_log::mod_Log::Content>(bytes)?),
35                Ok(24) => msg.collectTime = Some(r.read_int64(bytes)?),
36                Ok(t) => { r.read_unknown(bytes, t)?; }
37                Err(e) => return Err(e),
38            }
39        }
40        Ok(msg)
41    }
42}
43
44impl<'a> MessageWrite for Log<'a> {
45    fn get_size(&self) -> usize {
46        0
47        + 1 + sizeof_varint(*(&self.time) as u64)
48        + self.contents.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
49        + self.collectTime.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64))
50    }
51
52    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
53        w.write_with_tag(8, |w| w.write_int64(*&self.time))?;
54        for s in &self.contents { w.write_with_tag(18, |w| w.write_message(s))?; }
55        if let Some(ref s) = self.collectTime { w.write_with_tag(24, |w| w.write_int64(*s))?; }
56        Ok(())
57    }
58}
59
60pub mod mod_Log {
61    use std::borrow::Cow;
62    
63    use super::*;
64    
65    #[allow(clippy::derive_partial_eq_without_eq)]
66#[derive(Debug, Default, PartialEq, Clone)]
67pub struct Content<'a> {
68    pub key: Cow<'a, str>,
69    pub value: Cow<'a, str>,
70}
71
72impl<'a> Content<'a> {
73    pub fn new(key: &'a str, value: &'a str) -> Self {
74        Self {
75            key: Cow::Borrowed(key),
76            value: Cow::Borrowed(value)
77        }
78    }
79}
80
81impl<'a> MessageRead<'a> for Content<'a> {
82    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
83        let mut msg = Self::default();
84        while !r.is_eof() {
85            match r.next_tag(bytes) {
86                Ok(10) => msg.key = r.read_string(bytes).map(Cow::Borrowed)?,
87                Ok(18) => msg.value = r.read_string(bytes).map(Cow::Borrowed)?,
88                Ok(t) => { r.read_unknown(bytes, t)?; }
89                Err(e) => return Err(e),
90            }
91        }
92        Ok(msg)
93    }
94}
95
96impl<'a> MessageWrite for Content<'a> {
97    fn get_size(&self) -> usize {
98        0
99        + 1 + sizeof_len((&self.key).len())
100        + 1 + sizeof_len((&self.value).len())
101    }
102
103    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
104        w.write_with_tag(10, |w| w.write_string(&**&self.key))?;
105        w.write_with_tag(18, |w| w.write_string(&**&self.value))?;
106        Ok(())
107    }
108}
109
110}
111
112#[allow(clippy::derive_partial_eq_without_eq)]
113#[derive(Debug, Default, PartialEq, Clone)]
114pub struct LogTag<'a> {
115    pub key: Cow<'a, str>,
116    pub value: Cow<'a, str>,
117}
118
119impl<'a> MessageRead<'a> for LogTag<'a> {
120    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
121        let mut msg = Self::default();
122        while !r.is_eof() {
123            match r.next_tag(bytes) {
124                Ok(10) => msg.key = r.read_string(bytes).map(Cow::Borrowed)?,
125                Ok(18) => msg.value = r.read_string(bytes).map(Cow::Borrowed)?,
126                Ok(t) => { r.read_unknown(bytes, t)?; }
127                Err(e) => return Err(e),
128            }
129        }
130        Ok(msg)
131    }
132}
133
134impl<'a> MessageWrite for LogTag<'a> {
135    fn get_size(&self) -> usize {
136        0
137        + 1 + sizeof_len((&self.key).len())
138        + 1 + sizeof_len((&self.value).len())
139    }
140
141    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
142        w.write_with_tag(10, |w| w.write_string(&**&self.key))?;
143        w.write_with_tag(18, |w| w.write_string(&**&self.value))?;
144        Ok(())
145    }
146}
147
148#[allow(clippy::derive_partial_eq_without_eq)]
149#[derive(Debug, Default, PartialEq, Clone)]
150pub struct LogGroup<'a> {
151    pub logs: Vec<cls_log::Log<'a>>,
152    pub contextFlow: Option<Cow<'a, str>>,
153    pub filename: Option<Cow<'a, str>>,
154    pub source: Option<Cow<'a, str>>,
155    pub logTags: Vec<cls_log::LogTag<'a>>,
156    pub hostname: Option<Cow<'a, str>>,
157}
158
159impl<'a> MessageRead<'a> for LogGroup<'a> {
160    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
161        let mut msg = Self::default();
162        while !r.is_eof() {
163            match r.next_tag(bytes) {
164                Ok(10) => msg.logs.push(r.read_message::<cls_log::Log>(bytes)?),
165                Ok(18) => msg.contextFlow = Some(r.read_string(bytes).map(Cow::Borrowed)?),
166                Ok(26) => msg.filename = Some(r.read_string(bytes).map(Cow::Borrowed)?),
167                Ok(34) => msg.source = Some(r.read_string(bytes).map(Cow::Borrowed)?),
168                Ok(42) => msg.logTags.push(r.read_message::<cls_log::LogTag>(bytes)?),
169                Ok(50) => msg.hostname = Some(r.read_string(bytes).map(Cow::Borrowed)?),
170                Ok(t) => { r.read_unknown(bytes, t)?; }
171                Err(e) => return Err(e),
172            }
173        }
174        Ok(msg)
175    }
176}
177
178impl<'a> MessageWrite for LogGroup<'a> {
179    fn get_size(&self) -> usize {
180        0
181        + self.logs.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
182        + self.contextFlow.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
183        + self.filename.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
184        + self.source.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
185        + self.logTags.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
186        + self.hostname.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
187    }
188
189    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
190        for s in &self.logs { w.write_with_tag(10, |w| w.write_message(s))?; }
191        if let Some(ref s) = self.contextFlow { w.write_with_tag(18, |w| w.write_string(&**s))?; }
192        if let Some(ref s) = self.filename { w.write_with_tag(26, |w| w.write_string(&**s))?; }
193        if let Some(ref s) = self.source { w.write_with_tag(34, |w| w.write_string(&**s))?; }
194        for s in &self.logTags { w.write_with_tag(42, |w| w.write_message(s))?; }
195        if let Some(ref s) = self.hostname { w.write_with_tag(50, |w| w.write_string(&**s))?; }
196        Ok(())
197    }
198}
199
200#[allow(clippy::derive_partial_eq_without_eq)]
201#[derive(Debug, Default, PartialEq, Clone)]
202pub struct LogGroupList<'a> {
203    pub logGroupList: Vec<cls_log::LogGroup<'a>>,
204}
205
206impl<'a> LogGroupList<'a> {
207    pub fn encode(&self) -> Result<Bytes> {
208        let mut buf = Vec::with_capacity(self.get_size());
209        let mut writer = Writer::new(&mut buf);
210        self.write_message(&mut writer)?;
211        Ok(Bytes::from(buf))
212    }
213}
214
215impl<'a> MessageRead<'a> for LogGroupList<'a> {
216    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
217        let mut msg = Self::default();
218        while !r.is_eof() {
219            match r.next_tag(bytes) {
220                Ok(10) => msg.logGroupList.push(r.read_message::<cls_log::LogGroup>(bytes)?),
221                Ok(t) => { r.read_unknown(bytes, t)?; }
222                Err(e) => return Err(e),
223            }
224        }
225        Ok(msg)
226    }
227}
228
229impl<'a> MessageWrite for LogGroupList<'a> {
230    fn get_size(&self) -> usize {
231        0
232        + self.logGroupList.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
233    }
234
235    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
236        for s in &self.logGroupList { w.write_with_tag(10, |w| w.write_message(s))?; }
237        Ok(())
238    }
239}
240