1#![allow(unused_imports)]
8#![allow(unused_extern_crates)]
9#![cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments, clippy::type_complexity))]
10#![cfg_attr(rustfmt, rustfmt_skip)]
11
12extern crate thrift;
13
14use thrift::OrderedFloat;
15use std::cell::RefCell;
16use std::collections::{BTreeMap, BTreeSet};
17use std::convert::{From, TryFrom};
18use std::default::Default;
19use std::error::Error;
20use std::fmt;
21use std::fmt::{Display, Formatter};
22use std::rc::Rc;
23
24use thrift::{ApplicationError, ApplicationErrorKind, ProtocolError, ProtocolErrorKind, TThriftClient};
25use thrift::protocol::{TFieldIdentifier, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TInputProtocol, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType};
26use thrift::protocol::field_id;
27use thrift::protocol::verify_expected_message_type;
28use thrift::protocol::verify_expected_sequence_number;
29use thrift::protocol::verify_expected_service_call;
30use thrift::protocol::verify_required_field_exists;
31use thrift::server::TProcessor;
32
33use super::jaeger;
34use super::zipkincore;
35
36pub trait TAgentSyncClient {
41 fn emit_zipkin_batch(&mut self, spans: Vec<zipkincore::Span>) -> thrift::Result<()>;
42 fn emit_batch(&mut self, batch: jaeger::Batch) -> thrift::Result<()>;
43}
44
45pub trait TAgentSyncClientMarker {}
46
47pub struct AgentSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
48 _i_prot: IP,
49 _o_prot: OP,
50 _sequence_number: i32,
51}
52
53impl <IP, OP> AgentSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
54 pub fn new(input_protocol: IP, output_protocol: OP) -> AgentSyncClient<IP, OP> {
55 AgentSyncClient { _i_prot: input_protocol, _o_prot: output_protocol, _sequence_number: 0 }
56 }
57}
58
59impl <IP, OP> TThriftClient for AgentSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
60 fn i_prot_mut(&mut self) -> &mut dyn TInputProtocol { &mut self._i_prot }
61 fn o_prot_mut(&mut self) -> &mut dyn TOutputProtocol { &mut self._o_prot }
62 fn sequence_number(&self) -> i32 { self._sequence_number }
63 fn increment_sequence_number(&mut self) -> i32 { self._sequence_number += 1; self._sequence_number }
64}
65
66impl <IP, OP> TAgentSyncClientMarker for AgentSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {}
67
68impl <C: TThriftClient + TAgentSyncClientMarker> TAgentSyncClient for C {
69 fn emit_zipkin_batch(&mut self, spans: Vec<zipkincore::Span>) -> thrift::Result<()> {
70 (
71 {
72 self.increment_sequence_number();
73 let message_ident = TMessageIdentifier::new("emitZipkinBatch", TMessageType::OneWay, self.sequence_number());
74 let call_args = AgentEmitZipkinBatchArgs { spans };
75 self.o_prot_mut().write_message_begin(&message_ident)?;
76 call_args.write_to_out_protocol(self.o_prot_mut())?;
77 self.o_prot_mut().write_message_end()?;
78 self.o_prot_mut().flush()
79 }
80 )?;
81 Ok(())
82 }
83 fn emit_batch(&mut self, batch: jaeger::Batch) -> thrift::Result<()> {
84 (
85 {
86 self.increment_sequence_number();
87 let message_ident = TMessageIdentifier::new("emitBatch", TMessageType::OneWay, self.sequence_number());
88 let call_args = AgentEmitBatchArgs { batch };
89 self.o_prot_mut().write_message_begin(&message_ident)?;
90 call_args.write_to_out_protocol(self.o_prot_mut())?;
91 self.o_prot_mut().write_message_end()?;
92 self.o_prot_mut().flush()
93 }
94 )?;
95 Ok(())
96 }
97}
98
99pub trait AgentSyncHandler {
104 fn handle_emit_zipkin_batch(&self, spans: Vec<zipkincore::Span>) -> thrift::Result<()>;
105 fn handle_emit_batch(&self, batch: jaeger::Batch) -> thrift::Result<()>;
106}
107
108pub struct AgentSyncProcessor<H: AgentSyncHandler> {
109 handler: H,
110}
111
112impl <H: AgentSyncHandler> AgentSyncProcessor<H> {
113 pub fn new(handler: H) -> AgentSyncProcessor<H> {
114 AgentSyncProcessor {
115 handler,
116 }
117 }
118 fn process_emit_zipkin_batch(&self, incoming_sequence_number: i32, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
119 TAgentProcessFunctions::process_emit_zipkin_batch(&self.handler, incoming_sequence_number, i_prot, o_prot)
120 }
121 fn process_emit_batch(&self, incoming_sequence_number: i32, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
122 TAgentProcessFunctions::process_emit_batch(&self.handler, incoming_sequence_number, i_prot, o_prot)
123 }
124}
125
126pub struct TAgentProcessFunctions;
127
128impl TAgentProcessFunctions {
129 pub fn process_emit_zipkin_batch<H: AgentSyncHandler>(handler: &H, _: i32, i_prot: &mut dyn TInputProtocol, _: &mut dyn TOutputProtocol) -> thrift::Result<()> {
130 let args = AgentEmitZipkinBatchArgs::read_from_in_protocol(i_prot)?;
131 match handler.handle_emit_zipkin_batch(args.spans) {
132 Ok(_) => {
133 Ok(())
134 },
135 Err(e) => {
136 match e {
137 thrift::Error::Application(app_err) => {
138 Err(thrift::Error::Application(app_err))
139 },
140 _ => {
141 let ret_err = {
142 ApplicationError::new(
143 ApplicationErrorKind::Unknown,
144 e.to_string()
145 )
146 };
147 Err(thrift::Error::Application(ret_err))
148 },
149 }
150 },
151 }
152 }
153 pub fn process_emit_batch<H: AgentSyncHandler>(handler: &H, _: i32, i_prot: &mut dyn TInputProtocol, _: &mut dyn TOutputProtocol) -> thrift::Result<()> {
154 let args = AgentEmitBatchArgs::read_from_in_protocol(i_prot)?;
155 match handler.handle_emit_batch(args.batch) {
156 Ok(_) => {
157 Ok(())
158 },
159 Err(e) => {
160 match e {
161 thrift::Error::Application(app_err) => {
162 Err(thrift::Error::Application(app_err))
163 },
164 _ => {
165 let ret_err = {
166 ApplicationError::new(
167 ApplicationErrorKind::Unknown,
168 e.to_string()
169 )
170 };
171 Err(thrift::Error::Application(ret_err))
172 },
173 }
174 },
175 }
176 }
177}
178
179impl <H: AgentSyncHandler> TProcessor for AgentSyncProcessor<H> {
180 fn process(&self, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
181 let message_ident = i_prot.read_message_begin()?;
182 let res = match &*message_ident.name {
183 "emitZipkinBatch" => {
184 self.process_emit_zipkin_batch(message_ident.sequence_number, i_prot, o_prot)
185 },
186 "emitBatch" => {
187 self.process_emit_batch(message_ident.sequence_number, i_prot, o_prot)
188 },
189 method => {
190 Err(
191 thrift::Error::Application(
192 ApplicationError::new(
193 ApplicationErrorKind::UnknownMethod,
194 format!("unknown method {}", method)
195 )
196 )
197 )
198 },
199 };
200 thrift::server::handle_process_result(&message_ident, res, o_prot)
201 }
202}
203
204#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
209struct AgentEmitZipkinBatchArgs {
210 spans: Vec<zipkincore::Span>,
211}
212
213impl AgentEmitZipkinBatchArgs {
214 fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<AgentEmitZipkinBatchArgs> {
215 i_prot.read_struct_begin()?;
216 let mut f_1: Option<Vec<zipkincore::Span>> = None;
217 loop {
218 let field_ident = i_prot.read_field_begin()?;
219 if field_ident.field_type == TType::Stop {
220 break;
221 }
222 let field_id = field_id(&field_ident)?;
223 match field_id {
224 1 => {
225 let list_ident = i_prot.read_list_begin()?;
226 let mut val: Vec<zipkincore::Span> = Vec::with_capacity(list_ident.size as usize);
227 for _ in 0..list_ident.size {
228 let list_elem_0 = zipkincore::Span::read_from_in_protocol(i_prot)?;
229 val.push(list_elem_0);
230 }
231 i_prot.read_list_end()?;
232 f_1 = Some(val);
233 },
234 _ => {
235 i_prot.skip(field_ident.field_type)?;
236 },
237 };
238 i_prot.read_field_end()?;
239 }
240 i_prot.read_struct_end()?;
241 verify_required_field_exists("AgentEmitZipkinBatchArgs.spans", &f_1)?;
242 let ret = AgentEmitZipkinBatchArgs {
243 spans: f_1.expect("auto-generated code should have checked for presence of required fields"),
244 };
245 Ok(ret)
246 }
247 fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
248 let struct_ident = TStructIdentifier::new("emitZipkinBatch_args");
249 o_prot.write_struct_begin(&struct_ident)?;
250 o_prot.write_field_begin(&TFieldIdentifier::new("spans", TType::List, 1))?;
251 o_prot.write_list_begin(&TListIdentifier::new(TType::Struct, self.spans.len() as i32))?;
252 for e in &self.spans {
253 e.write_to_out_protocol(o_prot)?;
254 o_prot.write_list_end()?;
255 }
256 o_prot.write_field_end()?;
257 o_prot.write_field_stop()?;
258 o_prot.write_struct_end()
259 }
260}
261
262#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
267struct AgentEmitBatchArgs {
268 batch: jaeger::Batch,
269}
270
271impl AgentEmitBatchArgs {
272 fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<AgentEmitBatchArgs> {
273 i_prot.read_struct_begin()?;
274 let mut f_1: Option<jaeger::Batch> = None;
275 loop {
276 let field_ident = i_prot.read_field_begin()?;
277 if field_ident.field_type == TType::Stop {
278 break;
279 }
280 let field_id = field_id(&field_ident)?;
281 match field_id {
282 1 => {
283 let val = jaeger::Batch::read_from_in_protocol(i_prot)?;
284 f_1 = Some(val);
285 },
286 _ => {
287 i_prot.skip(field_ident.field_type)?;
288 },
289 };
290 i_prot.read_field_end()?;
291 }
292 i_prot.read_struct_end()?;
293 verify_required_field_exists("AgentEmitBatchArgs.batch", &f_1)?;
294 let ret = AgentEmitBatchArgs {
295 batch: f_1.expect("auto-generated code should have checked for presence of required fields"),
296 };
297 Ok(ret)
298 }
299 fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
300 let struct_ident = TStructIdentifier::new("emitBatch_args");
301 o_prot.write_struct_begin(&struct_ident)?;
302 o_prot.write_field_begin(&TFieldIdentifier::new("batch", TType::Struct, 1))?;
303 self.batch.write_to_out_protocol(o_prot)?;
304 o_prot.write_field_end()?;
305 o_prot.write_field_stop()?;
306 o_prot.write_struct_end()
307 }
308}