1#![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;
13use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result};
14use quick_protobuf::sizeofs::*;
15use super::*;
16
17#[allow(clippy::derive_partial_eq_without_eq)]
18#[derive(Debug, Default, PartialEq, Clone)]
19pub struct LogContent<'a> {
20 pub key: Cow<'a, str>,
21 pub value: Cow<'a, str>,
22}
23
24impl<'a> MessageRead<'a> for LogContent<'a> {
25 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
26 let mut msg = Self::default();
27 while !r.is_eof() {
28 match r.next_tag(bytes) {
29 Ok(10) => msg.key = r.read_string(bytes).map(Cow::Borrowed)?,
30 Ok(18) => msg.value = r.read_string(bytes).map(Cow::Borrowed)?,
31 Ok(t) => { r.read_unknown(bytes, t)?; }
32 Err(e) => return Err(e),
33 }
34 }
35 Ok(msg)
36 }
37}
38
39impl<'a> MessageWrite for LogContent<'a> {
40 fn get_size(&self) -> usize {
41 0
42 + 1 + sizeof_len((&self.key).len())
43 + 1 + sizeof_len((&self.value).len())
44 }
45
46 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
47 w.write_with_tag(10, |w| w.write_string(&**&self.key))?;
48 w.write_with_tag(18, |w| w.write_string(&**&self.value))?;
49 Ok(())
50 }
51}
52
53#[allow(clippy::derive_partial_eq_without_eq)]
54#[derive(Debug, Default, PartialEq, Clone)]
55pub struct Log<'a> {
56 pub time: u32,
57 pub contents: Vec<internal::LogContent<'a>>,
58 pub time_ns: Option<u32>,
59}
60
61impl<'a> MessageRead<'a> for Log<'a> {
62 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
63 let mut msg = Self::default();
64 while !r.is_eof() {
65 match r.next_tag(bytes) {
66 Ok(8) => msg.time = r.read_uint32(bytes)?,
67 Ok(18) => msg.contents.push(r.read_message::<internal::LogContent>(bytes)?),
68 Ok(37) => msg.time_ns = Some(r.read_fixed32(bytes)?),
69 Ok(t) => { r.read_unknown(bytes, t)?; }
70 Err(e) => return Err(e),
71 }
72 }
73 Ok(msg)
74 }
75}
76
77impl<'a> MessageWrite for Log<'a> {
78 fn get_size(&self) -> usize {
79 0
80 + 1 + sizeof_varint(*(&self.time) as u64)
81 + self.contents.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
82 + self.time_ns.as_ref().map_or(0, |_| 1 + 4)
83 }
84
85 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
86 w.write_with_tag(8, |w| w.write_uint32(*&self.time))?;
87 for s in &self.contents { w.write_with_tag(18, |w| w.write_message(s))?; }
88 if let Some(ref s) = self.time_ns { w.write_with_tag(37, |w| w.write_fixed32(*s))?; }
89 Ok(())
90 }
91}
92
93#[allow(clippy::derive_partial_eq_without_eq)]
94#[derive(Debug, Default, PartialEq, Clone)]
95pub struct LogTag<'a> {
96 pub key: Cow<'a, str>,
97 pub value: Cow<'a, str>,
98}
99
100impl<'a> MessageRead<'a> for LogTag<'a> {
101 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
102 let mut msg = Self::default();
103 while !r.is_eof() {
104 match r.next_tag(bytes) {
105 Ok(10) => msg.key = r.read_string(bytes).map(Cow::Borrowed)?,
106 Ok(18) => msg.value = r.read_string(bytes).map(Cow::Borrowed)?,
107 Ok(t) => { r.read_unknown(bytes, t)?; }
108 Err(e) => return Err(e),
109 }
110 }
111 Ok(msg)
112 }
113}
114
115impl<'a> MessageWrite for LogTag<'a> {
116 fn get_size(&self) -> usize {
117 0
118 + 1 + sizeof_len((&self.key).len())
119 + 1 + sizeof_len((&self.value).len())
120 }
121
122 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
123 w.write_with_tag(10, |w| w.write_string(&**&self.key))?;
124 w.write_with_tag(18, |w| w.write_string(&**&self.value))?;
125 Ok(())
126 }
127}
128
129#[allow(clippy::derive_partial_eq_without_eq)]
130#[derive(Debug, Default, PartialEq, Clone)]
131pub struct LogGroup<'a> {
132 pub logs: Vec<internal::Log<'a>>,
133 pub topic: Option<Cow<'a, str>>,
134 pub source: Option<Cow<'a, str>>,
135 pub log_tags: Vec<internal::LogTag<'a>>,
136}
137
138impl<'a> MessageRead<'a> for LogGroup<'a> {
139 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
140 let mut msg = Self::default();
141 while !r.is_eof() {
142 match r.next_tag(bytes) {
143 Ok(10) => msg.logs.push(r.read_message::<internal::Log>(bytes)?),
144 Ok(26) => msg.topic = Some(r.read_string(bytes).map(Cow::Borrowed)?),
145 Ok(34) => msg.source = Some(r.read_string(bytes).map(Cow::Borrowed)?),
146 Ok(50) => msg.log_tags.push(r.read_message::<internal::LogTag>(bytes)?),
147 Ok(t) => { r.read_unknown(bytes, t)?; }
148 Err(e) => return Err(e),
149 }
150 }
151 Ok(msg)
152 }
153}
154
155impl<'a> MessageWrite for LogGroup<'a> {
156 fn get_size(&self) -> usize {
157 0
158 + self.logs.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
159 + self.topic.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
160 + self.source.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
161 + self.log_tags.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
162 }
163
164 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
165 for s in &self.logs { w.write_with_tag(10, |w| w.write_message(s))?; }
166 if let Some(ref s) = self.topic { w.write_with_tag(26, |w| w.write_string(&**s))?; }
167 if let Some(ref s) = self.source { w.write_with_tag(34, |w| w.write_string(&**s))?; }
168 for s in &self.log_tags { w.write_with_tag(50, |w| w.write_message(s))?; }
169 Ok(())
170 }
171}
172
173#[allow(clippy::derive_partial_eq_without_eq)]
174#[derive(Debug, Default, PartialEq, Clone)]
175pub struct LogGroupList<'a> {
176 pub(crate) log_groups: Vec<internal::LogGroup<'a>>,
177}
178
179impl<'a> MessageRead<'a> for LogGroupList<'a> {
180 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
181 let mut msg = Self::default();
182 while !r.is_eof() {
183 match r.next_tag(bytes) {
184 Ok(10) => msg.log_groups.push(r.read_message::<internal::LogGroup>(bytes)?),
185 Ok(t) => { r.read_unknown(bytes, t)?; }
186 Err(e) => return Err(e),
187 }
188 }
189 Ok(msg)
190 }
191}
192
193impl<'a> MessageWrite for LogGroupList<'a> {
194 fn get_size(&self) -> usize {
195 0
196 + self.log_groups.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
197 }
198
199 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
200 for s in &self.log_groups { w.write_with_tag(10, |w| w.write_message(s))?; }
201 Ok(())
202 }
203}
204