mick_jaeger/protocol/
zipkincore.rs

1// Copied from https://github.com/open-telemetry/opentelemetry-rust/blob/master/opentelemetry-jaeger/src/thrift/jaeger.rs
2// Covered by the license of https://github.com/open-telemetry/opentelemetry-rust (Apache2)
3
4// Autogenerated by Thrift Compiler (0.13.0)
5// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
6
7#![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
33#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
34pub enum AnnotationType {
35  Bool = 0,
36  Bytes = 1,
37  I16 = 2,
38  I32 = 3,
39  I64 = 4,
40  Double = 5,
41  String = 6,
42}
43
44impl AnnotationType {
45  pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
46    o_prot.write_i32(*self as i32)
47  }
48  pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<AnnotationType> {
49    let enum_value = i_prot.read_i32()?;
50    AnnotationType::try_from(enum_value)  }
51}
52
53impl TryFrom<i32> for AnnotationType {
54  type Error = thrift::Error;  fn try_from(i: i32) -> Result<Self, Self::Error> {
55    match i {
56      0 => Ok(AnnotationType::Bool),
57      1 => Ok(AnnotationType::Bytes),
58      2 => Ok(AnnotationType::I16),
59      3 => Ok(AnnotationType::I32),
60      4 => Ok(AnnotationType::I64),
61      5 => Ok(AnnotationType::Double),
62      6 => Ok(AnnotationType::String),
63      _ => {
64        Err(
65          thrift::Error::Protocol(
66            ProtocolError::new(
67              ProtocolErrorKind::InvalidData,
68              format!("cannot convert enum constant {} to AnnotationType", i)
69            )
70          )
71        )
72      },
73    }
74  }
75}
76
77//
78// Endpoint
79//
80
81/// Indicates the network context of a service recording an annotation with two
82/// exceptions.
83///
84/// When a BinaryAnnotation, and key is CLIENT_ADDR or SERVER_ADDR,
85/// the endpoint indicates the source or destination of an RPC. This exception
86/// allows zipkin to display network context of uninstrumented services, or
87/// clients such as web browsers.
88#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
89pub struct Endpoint {
90  /// IPv4 host address packed into 4 bytes.
91  ///
92  /// Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4
93  pub ipv4: Option<i32>,
94  /// IPv4 port
95  ///
96  /// Note: this is to be treated as an unsigned integer, so watch for negatives.
97  ///
98  /// Conventionally, when the port isn't known, port = 0.
99  pub port: Option<i16>,
100  /// Service name in lowercase, such as "memcache" or "zipkin-web"
101  ///
102  /// Conventionally, when the service name isn't known, service_name = "unknown".
103  pub service_name: Option<String>,
104  /// IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes()
105  pub ipv6: Option<Vec<u8>>,
106}
107
108impl Endpoint {
109  pub fn new<F1, F2, F3, F4>(ipv4: F1, port: F2, service_name: F3, ipv6: F4) -> Endpoint where F1: Into<Option<i32>>, F2: Into<Option<i16>>, F3: Into<Option<String>>, F4: Into<Option<Vec<u8>>> {
110    Endpoint {
111      ipv4: ipv4.into(),
112      port: port.into(),
113      service_name: service_name.into(),
114      ipv6: ipv6.into(),
115    }
116  }
117  pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<Endpoint> {
118    i_prot.read_struct_begin()?;
119    let mut f_1: Option<i32> = Some(0);
120    let mut f_2: Option<i16> = Some(0);
121    let mut f_3: Option<String> = Some("".to_owned());
122    let mut f_4: Option<Vec<u8>> = None;
123    loop {
124      let field_ident = i_prot.read_field_begin()?;
125      if field_ident.field_type == TType::Stop {
126        break;
127      }
128      let field_id = field_id(&field_ident)?;
129      match field_id {
130        1 => {
131          let val = i_prot.read_i32()?;
132          f_1 = Some(val);
133        },
134        2 => {
135          let val = i_prot.read_i16()?;
136          f_2 = Some(val);
137        },
138        3 => {
139          let val = i_prot.read_string()?;
140          f_3 = Some(val);
141        },
142        4 => {
143          let val = i_prot.read_bytes()?;
144          f_4 = Some(val);
145        },
146        _ => {
147          i_prot.skip(field_ident.field_type)?;
148        },
149      };
150      i_prot.read_field_end()?;
151    }
152    i_prot.read_struct_end()?;
153    let ret = Endpoint {
154      ipv4: f_1,
155      port: f_2,
156      service_name: f_3,
157      ipv6: f_4,
158    };
159    Ok(ret)
160  }
161  pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
162    let struct_ident = TStructIdentifier::new("Endpoint");
163    o_prot.write_struct_begin(&struct_ident)?;
164    if let Some(fld_var) = self.ipv4 {
165      o_prot.write_field_begin(&TFieldIdentifier::new("ipv4", TType::I32, 1))?;
166      o_prot.write_i32(fld_var)?;
167      o_prot.write_field_end()?;
168      ()
169    } else {
170      ()
171    }
172    if let Some(fld_var) = self.port {
173      o_prot.write_field_begin(&TFieldIdentifier::new("port", TType::I16, 2))?;
174      o_prot.write_i16(fld_var)?;
175      o_prot.write_field_end()?;
176      ()
177    } else {
178      ()
179    }
180    if let Some(ref fld_var) = self.service_name {
181      o_prot.write_field_begin(&TFieldIdentifier::new("service_name", TType::String, 3))?;
182      o_prot.write_string(fld_var)?;
183      o_prot.write_field_end()?;
184      ()
185    } else {
186      ()
187    }
188    if let Some(ref fld_var) = self.ipv6 {
189      o_prot.write_field_begin(&TFieldIdentifier::new("ipv6", TType::String, 4))?;
190      o_prot.write_bytes(fld_var)?;
191      o_prot.write_field_end()?;
192      ()
193    } else {
194      ()
195    }
196    o_prot.write_field_stop()?;
197    o_prot.write_struct_end()
198  }
199}
200
201impl Default for Endpoint {
202  fn default() -> Self {
203    Endpoint{
204      ipv4: Some(0),
205      port: Some(0),
206      service_name: Some("".to_owned()),
207      ipv6: Some(Vec::new()),
208    }
209  }
210}
211
212//
213// Annotation
214//
215
216/// An annotation is similar to a log statement. It includes a host field which
217/// allows these events to be attributed properly, and also aggregatable.
218#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
219pub struct Annotation {
220  /// Microseconds from epoch.
221  ///
222  /// This value should use the most precise value possible. For example,
223  /// gettimeofday or syncing nanoTime against a tick of currentTimeMillis.
224  pub timestamp: Option<i64>,
225  pub value: Option<String>,
226  /// Always the host that recorded the event. By specifying the host you allow
227  /// rollup of all events (such as client requests to a service) by IP address.
228  pub host: Option<Endpoint>,
229}
230
231impl Annotation {
232  pub fn new<F1, F2, F3>(timestamp: F1, value: F2, host: F3) -> Annotation where F1: Into<Option<i64>>, F2: Into<Option<String>>, F3: Into<Option<Endpoint>> {
233    Annotation {
234      timestamp: timestamp.into(),
235      value: value.into(),
236      host: host.into(),
237    }
238  }
239  pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<Annotation> {
240    i_prot.read_struct_begin()?;
241    let mut f_1: Option<i64> = Some(0);
242    let mut f_2: Option<String> = Some("".to_owned());
243    let mut f_3: Option<Endpoint> = None;
244    loop {
245      let field_ident = i_prot.read_field_begin()?;
246      if field_ident.field_type == TType::Stop {
247        break;
248      }
249      let field_id = field_id(&field_ident)?;
250      match field_id {
251        1 => {
252          let val = i_prot.read_i64()?;
253          f_1 = Some(val);
254        },
255        2 => {
256          let val = i_prot.read_string()?;
257          f_2 = Some(val);
258        },
259        3 => {
260          let val = Endpoint::read_from_in_protocol(i_prot)?;
261          f_3 = Some(val);
262        },
263        _ => {
264          i_prot.skip(field_ident.field_type)?;
265        },
266      };
267      i_prot.read_field_end()?;
268    }
269    i_prot.read_struct_end()?;
270    let ret = Annotation {
271      timestamp: f_1,
272      value: f_2,
273      host: f_3,
274    };
275    Ok(ret)
276  }
277  pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
278    let struct_ident = TStructIdentifier::new("Annotation");
279    o_prot.write_struct_begin(&struct_ident)?;
280    if let Some(fld_var) = self.timestamp {
281      o_prot.write_field_begin(&TFieldIdentifier::new("timestamp", TType::I64, 1))?;
282      o_prot.write_i64(fld_var)?;
283      o_prot.write_field_end()?;
284      ()
285    } else {
286      ()
287    }
288    if let Some(ref fld_var) = self.value {
289      o_prot.write_field_begin(&TFieldIdentifier::new("value", TType::String, 2))?;
290      o_prot.write_string(fld_var)?;
291      o_prot.write_field_end()?;
292      ()
293    } else {
294      ()
295    }
296    if let Some(ref fld_var) = self.host {
297      o_prot.write_field_begin(&TFieldIdentifier::new("host", TType::Struct, 3))?;
298      fld_var.write_to_out_protocol(o_prot)?;
299      o_prot.write_field_end()?;
300      ()
301    } else {
302      ()
303    }
304    o_prot.write_field_stop()?;
305    o_prot.write_struct_end()
306  }
307}
308
309impl Default for Annotation {
310  fn default() -> Self {
311    Annotation{
312      timestamp: Some(0),
313      value: Some("".to_owned()),
314      host: None,
315    }
316  }
317}
318
319//
320// BinaryAnnotation
321//
322
323/// Binary annotations are tags applied to a Span to give it context. For
324/// example, a binary annotation of "http.uri" could the path to a resource in a
325/// RPC call.
326///
327/// Binary annotations of type STRING are always queryable, though more a
328/// historical implementation detail than a structural concern.
329///
330/// Binary annotations can repeat, and vary on the host. Similar to Annotation,
331/// the host indicates who logged the event. This allows you to tell the
332/// difference between the client and server side of the same key. For example,
333/// the key "http.uri" might be different on the client and server side due to
334/// rewriting, like "/api/v1/myresource" vs "/myresource. Via the host field,
335/// you can see the different points of view, which often help in debugging.
336#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
337pub struct BinaryAnnotation {
338  pub key: Option<String>,
339  pub value: Option<Vec<u8>>,
340  pub annotation_type: Option<AnnotationType>,
341  /// The host that recorded tag, which allows you to differentiate between
342  /// multiple tags with the same key. There are two exceptions to this.
343  ///
344  /// When the key is CLIENT_ADDR or SERVER_ADDR, host indicates the source or
345  /// destination of an RPC. This exception allows zipkin to display network
346  /// context of uninstrumented services, or clients such as web browsers.
347  pub host: Option<Endpoint>,
348}
349
350impl BinaryAnnotation {
351  pub fn new<F1, F2, F3, F4>(key: F1, value: F2, annotation_type: F3, host: F4) -> BinaryAnnotation where F1: Into<Option<String>>, F2: Into<Option<Vec<u8>>>, F3: Into<Option<AnnotationType>>, F4: Into<Option<Endpoint>> {
352    BinaryAnnotation {
353      key: key.into(),
354      value: value.into(),
355      annotation_type: annotation_type.into(),
356      host: host.into(),
357    }
358  }
359  pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<BinaryAnnotation> {
360    i_prot.read_struct_begin()?;
361    let mut f_1: Option<String> = Some("".to_owned());
362    let mut f_2: Option<Vec<u8>> = Some(Vec::new());
363    let mut f_3: Option<AnnotationType> = None;
364    let mut f_4: Option<Endpoint> = None;
365    loop {
366      let field_ident = i_prot.read_field_begin()?;
367      if field_ident.field_type == TType::Stop {
368        break;
369      }
370      let field_id = field_id(&field_ident)?;
371      match field_id {
372        1 => {
373          let val = i_prot.read_string()?;
374          f_1 = Some(val);
375        },
376        2 => {
377          let val = i_prot.read_bytes()?;
378          f_2 = Some(val);
379        },
380        3 => {
381          let val = AnnotationType::read_from_in_protocol(i_prot)?;
382          f_3 = Some(val);
383        },
384        4 => {
385          let val = Endpoint::read_from_in_protocol(i_prot)?;
386          f_4 = Some(val);
387        },
388        _ => {
389          i_prot.skip(field_ident.field_type)?;
390        },
391      };
392      i_prot.read_field_end()?;
393    }
394    i_prot.read_struct_end()?;
395    let ret = BinaryAnnotation {
396      key: f_1,
397      value: f_2,
398      annotation_type: f_3,
399      host: f_4,
400    };
401    Ok(ret)
402  }
403  pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
404    let struct_ident = TStructIdentifier::new("BinaryAnnotation");
405    o_prot.write_struct_begin(&struct_ident)?;
406    if let Some(ref fld_var) = self.key {
407      o_prot.write_field_begin(&TFieldIdentifier::new("key", TType::String, 1))?;
408      o_prot.write_string(fld_var)?;
409      o_prot.write_field_end()?;
410      ()
411    } else {
412      ()
413    }
414    if let Some(ref fld_var) = self.value {
415      o_prot.write_field_begin(&TFieldIdentifier::new("value", TType::String, 2))?;
416      o_prot.write_bytes(fld_var)?;
417      o_prot.write_field_end()?;
418      ()
419    } else {
420      ()
421    }
422    if let Some(ref fld_var) = self.annotation_type {
423      o_prot.write_field_begin(&TFieldIdentifier::new("annotation_type", TType::I32, 3))?;
424      fld_var.write_to_out_protocol(o_prot)?;
425      o_prot.write_field_end()?;
426      ()
427    } else {
428      ()
429    }
430    if let Some(ref fld_var) = self.host {
431      o_prot.write_field_begin(&TFieldIdentifier::new("host", TType::Struct, 4))?;
432      fld_var.write_to_out_protocol(o_prot)?;
433      o_prot.write_field_end()?;
434      ()
435    } else {
436      ()
437    }
438    o_prot.write_field_stop()?;
439    o_prot.write_struct_end()
440  }
441}
442
443impl Default for BinaryAnnotation {
444  fn default() -> Self {
445    BinaryAnnotation{
446      key: Some("".to_owned()),
447      value: Some(Vec::new()),
448      annotation_type: None,
449      host: None,
450    }
451  }
452}
453
454//
455// Span
456//
457
458/// A trace is a series of spans (often RPC calls) which form a latency tree.
459///
460/// The root span is where trace_id = id and parent_id = Nil. The root span is
461/// usually the longest interval in the trace, starting with a SERVER_RECV
462/// annotation and ending with a SERVER_SEND.
463#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
464pub struct Span {
465  pub trace_id: Option<i64>,
466  /// Span name in lowercase, rpc method for example
467  ///
468  /// Conventionally, when the span name isn't known, name = "unknown".
469  pub name: Option<String>,
470  pub id: Option<i64>,
471  pub parent_id: Option<i64>,
472  pub annotations: Option<Vec<Annotation>>,
473  pub binary_annotations: Option<Vec<BinaryAnnotation>>,
474  pub debug: Option<bool>,
475  /// Microseconds from epoch of the creation of this span.
476  ///
477  /// This value should be set directly by instrumentation, using the most
478  /// precise value possible. For example, gettimeofday or syncing nanoTime
479  /// against a tick of currentTimeMillis.
480  ///
481  /// For compatibilty with instrumentation that precede this field, collectors
482  /// or span stores can derive this via Annotation.timestamp.
483  /// For example, SERVER_RECV.timestamp or CLIENT_SEND.timestamp.
484  ///
485  /// This field is optional for compatibility with old data: first-party span
486  /// stores are expected to support this at time of introduction.
487  pub timestamp: Option<i64>,
488  /// Measurement of duration in microseconds, used to support queries.
489  ///
490  /// This value should be set directly, where possible. Doing so encourages
491  /// precise measurement decoupled from problems of clocks, such as skew or NTP
492  /// updates causing time to move backwards.
493  ///
494  /// For compatibilty with instrumentation that precede this field, collectors
495  /// or span stores can derive this by subtracting Annotation.timestamp.
496  /// For example, SERVER_SEND.timestamp - SERVER_RECV.timestamp.
497  ///
498  /// If this field is persisted as unset, zipkin will continue to work, except
499  /// duration query support will be implementation-specific. Similarly, setting
500  /// this field non-atomically is implementation-specific.
501  ///
502  /// This field is i64 vs i32 to support spans longer than 35 minutes.
503  pub duration: Option<i64>,
504  /// Optional unique 8-byte additional identifier for a trace. If non zero, this
505  /// means the trace uses 128 bit traceIds instead of 64 bit.
506  pub trace_id_high: Option<i64>,
507}
508
509impl Span {
510  pub fn new<F1, F3, F4, F5, F6, F8, F9, F10, F11, F12>(trace_id: F1, name: F3, id: F4, parent_id: F5, annotations: F6, binary_annotations: F8, debug: F9, timestamp: F10, duration: F11, trace_id_high: F12) -> Span where F1: Into<Option<i64>>, F3: Into<Option<String>>, F4: Into<Option<i64>>, F5: Into<Option<i64>>, F6: Into<Option<Vec<Annotation>>>, F8: Into<Option<Vec<BinaryAnnotation>>>, F9: Into<Option<bool>>, F10: Into<Option<i64>>, F11: Into<Option<i64>>, F12: Into<Option<i64>> {
511    Span {
512      trace_id: trace_id.into(),
513      name: name.into(),
514      id: id.into(),
515      parent_id: parent_id.into(),
516      annotations: annotations.into(),
517      binary_annotations: binary_annotations.into(),
518      debug: debug.into(),
519      timestamp: timestamp.into(),
520      duration: duration.into(),
521      trace_id_high: trace_id_high.into(),
522    }
523  }
524  pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<Span> {
525    i_prot.read_struct_begin()?;
526    let mut f_1: Option<i64> = Some(0);
527    let mut f_3: Option<String> = Some("".to_owned());
528    let mut f_4: Option<i64> = Some(0);
529    let mut f_5: Option<i64> = None;
530    let mut f_6: Option<Vec<Annotation>> = Some(Vec::new());
531    let mut f_8: Option<Vec<BinaryAnnotation>> = Some(Vec::new());
532    let mut f_9: Option<bool> = None;
533    let mut f_10: Option<i64> = None;
534    let mut f_11: Option<i64> = None;
535    let mut f_12: Option<i64> = None;
536    loop {
537      let field_ident = i_prot.read_field_begin()?;
538      if field_ident.field_type == TType::Stop {
539        break;
540      }
541      let field_id = field_id(&field_ident)?;
542      match field_id {
543        1 => {
544          let val = i_prot.read_i64()?;
545          f_1 = Some(val);
546        },
547        3 => {
548          let val = i_prot.read_string()?;
549          f_3 = Some(val);
550        },
551        4 => {
552          let val = i_prot.read_i64()?;
553          f_4 = Some(val);
554        },
555        5 => {
556          let val = i_prot.read_i64()?;
557          f_5 = Some(val);
558        },
559        6 => {
560          let list_ident = i_prot.read_list_begin()?;
561          let mut val: Vec<Annotation> = Vec::with_capacity(list_ident.size as usize);
562          for _ in 0..list_ident.size {
563            let list_elem_0 = Annotation::read_from_in_protocol(i_prot)?;
564            val.push(list_elem_0);
565          }
566          i_prot.read_list_end()?;
567          f_6 = Some(val);
568        },
569        8 => {
570          let list_ident = i_prot.read_list_begin()?;
571          let mut val: Vec<BinaryAnnotation> = Vec::with_capacity(list_ident.size as usize);
572          for _ in 0..list_ident.size {
573            let list_elem_1 = BinaryAnnotation::read_from_in_protocol(i_prot)?;
574            val.push(list_elem_1);
575          }
576          i_prot.read_list_end()?;
577          f_8 = Some(val);
578        },
579        9 => {
580          let val = i_prot.read_bool()?;
581          f_9 = Some(val);
582        },
583        10 => {
584          let val = i_prot.read_i64()?;
585          f_10 = Some(val);
586        },
587        11 => {
588          let val = i_prot.read_i64()?;
589          f_11 = Some(val);
590        },
591        12 => {
592          let val = i_prot.read_i64()?;
593          f_12 = Some(val);
594        },
595        _ => {
596          i_prot.skip(field_ident.field_type)?;
597        },
598      };
599      i_prot.read_field_end()?;
600    }
601    i_prot.read_struct_end()?;
602    let ret = Span {
603      trace_id: f_1,
604      name: f_3,
605      id: f_4,
606      parent_id: f_5,
607      annotations: f_6,
608      binary_annotations: f_8,
609      debug: f_9,
610      timestamp: f_10,
611      duration: f_11,
612      trace_id_high: f_12,
613    };
614    Ok(ret)
615  }
616  pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
617    let struct_ident = TStructIdentifier::new("Span");
618    o_prot.write_struct_begin(&struct_ident)?;
619    if let Some(fld_var) = self.trace_id {
620      o_prot.write_field_begin(&TFieldIdentifier::new("trace_id", TType::I64, 1))?;
621      o_prot.write_i64(fld_var)?;
622      o_prot.write_field_end()?;
623      ()
624    } else {
625      ()
626    }
627    if let Some(ref fld_var) = self.name {
628      o_prot.write_field_begin(&TFieldIdentifier::new("name", TType::String, 3))?;
629      o_prot.write_string(fld_var)?;
630      o_prot.write_field_end()?;
631      ()
632    } else {
633      ()
634    }
635    if let Some(fld_var) = self.id {
636      o_prot.write_field_begin(&TFieldIdentifier::new("id", TType::I64, 4))?;
637      o_prot.write_i64(fld_var)?;
638      o_prot.write_field_end()?;
639      ()
640    } else {
641      ()
642    }
643    if let Some(fld_var) = self.parent_id {
644      o_prot.write_field_begin(&TFieldIdentifier::new("parent_id", TType::I64, 5))?;
645      o_prot.write_i64(fld_var)?;
646      o_prot.write_field_end()?;
647      ()
648    } else {
649      ()
650    }
651    if let Some(ref fld_var) = self.annotations {
652      o_prot.write_field_begin(&TFieldIdentifier::new("annotations", TType::List, 6))?;
653      o_prot.write_list_begin(&TListIdentifier::new(TType::Struct, fld_var.len() as i32))?;
654      for e in fld_var {
655        e.write_to_out_protocol(o_prot)?;
656        o_prot.write_list_end()?;
657      }
658      o_prot.write_field_end()?;
659      ()
660    } else {
661      ()
662    }
663    if let Some(ref fld_var) = self.binary_annotations {
664      o_prot.write_field_begin(&TFieldIdentifier::new("binary_annotations", TType::List, 8))?;
665      o_prot.write_list_begin(&TListIdentifier::new(TType::Struct, fld_var.len() as i32))?;
666      for e in fld_var {
667        e.write_to_out_protocol(o_prot)?;
668        o_prot.write_list_end()?;
669      }
670      o_prot.write_field_end()?;
671      ()
672    } else {
673      ()
674    }
675    if let Some(fld_var) = self.debug {
676      o_prot.write_field_begin(&TFieldIdentifier::new("debug", TType::Bool, 9))?;
677      o_prot.write_bool(fld_var)?;
678      o_prot.write_field_end()?;
679      ()
680    } else {
681      ()
682    }
683    if let Some(fld_var) = self.timestamp {
684      o_prot.write_field_begin(&TFieldIdentifier::new("timestamp", TType::I64, 10))?;
685      o_prot.write_i64(fld_var)?;
686      o_prot.write_field_end()?;
687      ()
688    } else {
689      ()
690    }
691    if let Some(fld_var) = self.duration {
692      o_prot.write_field_begin(&TFieldIdentifier::new("duration", TType::I64, 11))?;
693      o_prot.write_i64(fld_var)?;
694      o_prot.write_field_end()?;
695      ()
696    } else {
697      ()
698    }
699    if let Some(fld_var) = self.trace_id_high {
700      o_prot.write_field_begin(&TFieldIdentifier::new("trace_id_high", TType::I64, 12))?;
701      o_prot.write_i64(fld_var)?;
702      o_prot.write_field_end()?;
703      ()
704    } else {
705      ()
706    }
707    o_prot.write_field_stop()?;
708    o_prot.write_struct_end()
709  }
710}
711
712impl Default for Span {
713  fn default() -> Self {
714    Span{
715      trace_id: Some(0),
716      name: Some("".to_owned()),
717      id: Some(0),
718      parent_id: Some(0),
719      annotations: Some(Vec::new()),
720      binary_annotations: Some(Vec::new()),
721      debug: Some(false),
722      timestamp: Some(0),
723      duration: Some(0),
724      trace_id_high: Some(0),
725    }
726  }
727}
728
729//
730// Response
731//
732
733#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
734pub struct Response {
735  pub ok: bool,
736}
737
738impl Response {
739  pub fn new(ok: bool) -> Response {
740    Response {
741      ok,
742
743    }
744  }
745  pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<Response> {
746    i_prot.read_struct_begin()?;
747    let mut f_1: Option<bool> = None;
748    loop {
749      let field_ident = i_prot.read_field_begin()?;
750      if field_ident.field_type == TType::Stop {
751        break;
752      }
753      let field_id = field_id(&field_ident)?;
754      match field_id {
755        1 => {
756          let val = i_prot.read_bool()?;
757          f_1 = Some(val);
758        },
759        _ => {
760          i_prot.skip(field_ident.field_type)?;
761        },
762      };
763      i_prot.read_field_end()?;
764    }
765    i_prot.read_struct_end()?;
766    verify_required_field_exists("Response.ok", &f_1)?;
767    let ret = Response {
768      ok: f_1.expect("auto-generated code should have checked for presence of required fields"),
769    };
770    Ok(ret)
771  }
772  pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
773    let struct_ident = TStructIdentifier::new("Response");
774    o_prot.write_struct_begin(&struct_ident)?;
775    o_prot.write_field_begin(&TFieldIdentifier::new("ok", TType::Bool, 1))?;
776    o_prot.write_bool(self.ok)?;
777    o_prot.write_field_end()?;
778    o_prot.write_field_stop()?;
779    o_prot.write_struct_end()
780  }
781}
782
783pub const C_L_I_E_N_T_S_E_N_D: &str = "cs";
784
785pub const C_L_I_E_N_T_R_E_C_V: &str = "cr";
786
787pub const S_E_R_V_E_R_S_E_N_D: &str = "ss";
788
789pub const S_E_R_V_E_R_R_E_C_V: &str = "sr";
790
791pub const M_E_S_S_A_G_E_S_E_N_D: &str = "ms";
792
793pub const M_E_S_S_A_G_E_R_E_C_V: &str = "mr";
794
795pub const W_I_R_E_S_E_N_D: &str = "ws";
796
797pub const W_I_R_E_R_E_C_V: &str = "wr";
798
799pub const C_L_I_E_N_T_S_E_N_D_F_R_A_G_M_E_N_T: &str = "csf";
800
801pub const C_L_I_E_N_T_R_E_C_V_F_R_A_G_M_E_N_T: &str = "crf";
802
803pub const S_E_R_V_E_R_S_E_N_D_F_R_A_G_M_E_N_T: &str = "ssf";
804
805pub const S_E_R_V_E_R_R_E_C_V_F_R_A_G_M_E_N_T: &str = "srf";
806
807pub const L_O_C_A_L_C_O_M_P_O_N_E_N_T: &str = "lc";
808
809pub const C_L_I_E_N_T_A_D_D_R: &str = "ca";
810
811pub const S_E_R_V_E_R_A_D_D_R: &str = "sa";
812
813pub const M_E_S_S_A_G_E_A_D_D_R: &str = "ma";
814
815//
816// ZipkinCollector service client
817//
818
819pub trait TZipkinCollectorSyncClient {
820  fn submit_zipkin_batch(&mut self, spans: Vec<Span>) -> thrift::Result<Vec<Response>>;
821}
822
823pub trait TZipkinCollectorSyncClientMarker {}
824
825pub struct ZipkinCollectorSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
826  _i_prot: IP,
827  _o_prot: OP,
828  _sequence_number: i32,
829}
830
831impl <IP, OP> ZipkinCollectorSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
832  pub fn new(input_protocol: IP, output_protocol: OP) -> ZipkinCollectorSyncClient<IP, OP> {
833    ZipkinCollectorSyncClient { _i_prot: input_protocol, _o_prot: output_protocol, _sequence_number: 0 }
834  }
835}
836
837impl <IP, OP> TThriftClient for ZipkinCollectorSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
838  fn i_prot_mut(&mut self) -> &mut dyn TInputProtocol { &mut self._i_prot }
839  fn o_prot_mut(&mut self) -> &mut dyn TOutputProtocol { &mut self._o_prot }
840  fn sequence_number(&self) -> i32 { self._sequence_number }
841  fn increment_sequence_number(&mut self) -> i32 { self._sequence_number += 1; self._sequence_number }
842}
843
844impl <IP, OP> TZipkinCollectorSyncClientMarker for ZipkinCollectorSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {}
845
846impl <C: TThriftClient + TZipkinCollectorSyncClientMarker> TZipkinCollectorSyncClient for C {
847  fn submit_zipkin_batch(&mut self, spans: Vec<Span>) -> thrift::Result<Vec<Response>> {
848    (
849      {
850        self.increment_sequence_number();
851        let message_ident = TMessageIdentifier::new("submitZipkinBatch", TMessageType::Call, self.sequence_number());
852        let call_args = ZipkinCollectorSubmitZipkinBatchArgs { spans };
853        self.o_prot_mut().write_message_begin(&message_ident)?;
854        call_args.write_to_out_protocol(self.o_prot_mut())?;
855        self.o_prot_mut().write_message_end()?;
856        self.o_prot_mut().flush()
857      }
858    )?;
859    {
860      let message_ident = self.i_prot_mut().read_message_begin()?;
861      verify_expected_sequence_number(self.sequence_number(), message_ident.sequence_number)?;
862      verify_expected_service_call("submitZipkinBatch", &message_ident.name)?;
863      if message_ident.message_type == TMessageType::Exception {
864        let remote_error = thrift::Error::read_application_error_from_in_protocol(self.i_prot_mut())?;
865        self.i_prot_mut().read_message_end()?;
866        return Err(thrift::Error::Application(remote_error))
867      }
868      verify_expected_message_type(TMessageType::Reply, message_ident.message_type)?;
869      let result = ZipkinCollectorSubmitZipkinBatchResult::read_from_in_protocol(self.i_prot_mut())?;
870      self.i_prot_mut().read_message_end()?;
871      result.ok_or()
872    }
873  }
874}
875
876//
877// ZipkinCollector service processor
878//
879
880pub trait ZipkinCollectorSyncHandler {
881  fn handle_submit_zipkin_batch(&self, spans: Vec<Span>) -> thrift::Result<Vec<Response>>;
882}
883
884pub struct ZipkinCollectorSyncProcessor<H: ZipkinCollectorSyncHandler> {
885  handler: H,
886}
887
888impl <H: ZipkinCollectorSyncHandler> ZipkinCollectorSyncProcessor<H> {
889  pub fn new(handler: H) -> ZipkinCollectorSyncProcessor<H> {
890    ZipkinCollectorSyncProcessor {
891      handler,
892    }
893  }
894  fn process_submit_zipkin_batch(&self, incoming_sequence_number: i32, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
895    TZipkinCollectorProcessFunctions::process_submit_zipkin_batch(&self.handler, incoming_sequence_number, i_prot, o_prot)
896  }
897}
898
899pub struct TZipkinCollectorProcessFunctions;
900
901impl TZipkinCollectorProcessFunctions {
902  pub fn process_submit_zipkin_batch<H: ZipkinCollectorSyncHandler>(handler: &H, incoming_sequence_number: i32, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
903    let args = ZipkinCollectorSubmitZipkinBatchArgs::read_from_in_protocol(i_prot)?;
904    match handler.handle_submit_zipkin_batch(args.spans) {
905      Ok(handler_return) => {
906        let message_ident = TMessageIdentifier::new("submitZipkinBatch", TMessageType::Reply, incoming_sequence_number);
907        o_prot.write_message_begin(&message_ident)?;
908        let ret = ZipkinCollectorSubmitZipkinBatchResult { result_value: Some(handler_return) };
909        ret.write_to_out_protocol(o_prot)?;
910        o_prot.write_message_end()?;
911        o_prot.flush()
912      },
913      Err(e) => {
914        match e {
915          thrift::Error::Application(app_err) => {
916            let message_ident = TMessageIdentifier::new("submitZipkinBatch", TMessageType::Exception, incoming_sequence_number);
917            o_prot.write_message_begin(&message_ident)?;
918            thrift::Error::write_application_error_to_out_protocol(&app_err, o_prot)?;
919            o_prot.write_message_end()?;
920            o_prot.flush()
921          },
922          _ => {
923            let ret_err = {
924              ApplicationError::new(
925                ApplicationErrorKind::Unknown,
926                e.to_string()
927              )
928            };
929            let message_ident = TMessageIdentifier::new("submitZipkinBatch", TMessageType::Exception, incoming_sequence_number);
930            o_prot.write_message_begin(&message_ident)?;
931            thrift::Error::write_application_error_to_out_protocol(&ret_err, o_prot)?;
932            o_prot.write_message_end()?;
933            o_prot.flush()
934          },
935        }
936      },
937    }
938  }
939}
940
941impl <H: ZipkinCollectorSyncHandler> TProcessor for ZipkinCollectorSyncProcessor<H> {
942  fn process(&self, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
943    let message_ident = i_prot.read_message_begin()?;
944    let res = match &*message_ident.name {
945      "submitZipkinBatch" => {
946        self.process_submit_zipkin_batch(message_ident.sequence_number, i_prot, o_prot)
947      },
948      method => {
949        Err(
950          thrift::Error::Application(
951            ApplicationError::new(
952              ApplicationErrorKind::UnknownMethod,
953              format!("unknown method {}", method)
954            )
955          )
956        )
957      },
958    };
959    thrift::server::handle_process_result(&message_ident, res, o_prot)
960  }
961}
962
963//
964// ZipkinCollectorSubmitZipkinBatchArgs
965//
966
967#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
968struct ZipkinCollectorSubmitZipkinBatchArgs {
969  spans: Vec<Span>,
970}
971
972impl ZipkinCollectorSubmitZipkinBatchArgs {
973  fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<ZipkinCollectorSubmitZipkinBatchArgs> {
974    i_prot.read_struct_begin()?;
975    let mut f_1: Option<Vec<Span>> = None;
976    loop {
977      let field_ident = i_prot.read_field_begin()?;
978      if field_ident.field_type == TType::Stop {
979        break;
980      }
981      let field_id = field_id(&field_ident)?;
982      match field_id {
983        1 => {
984          let list_ident = i_prot.read_list_begin()?;
985          let mut val: Vec<Span> = Vec::with_capacity(list_ident.size as usize);
986          for _ in 0..list_ident.size {
987            let list_elem_2 = Span::read_from_in_protocol(i_prot)?;
988            val.push(list_elem_2);
989          }
990          i_prot.read_list_end()?;
991          f_1 = Some(val);
992        },
993        _ => {
994          i_prot.skip(field_ident.field_type)?;
995        },
996      };
997      i_prot.read_field_end()?;
998    }
999    i_prot.read_struct_end()?;
1000    verify_required_field_exists("ZipkinCollectorSubmitZipkinBatchArgs.spans", &f_1)?;
1001    let ret = ZipkinCollectorSubmitZipkinBatchArgs {
1002      spans: f_1.expect("auto-generated code should have checked for presence of required fields"),
1003    };
1004    Ok(ret)
1005  }
1006  fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
1007    let struct_ident = TStructIdentifier::new("submitZipkinBatch_args");
1008    o_prot.write_struct_begin(&struct_ident)?;
1009    o_prot.write_field_begin(&TFieldIdentifier::new("spans", TType::List, 1))?;
1010    o_prot.write_list_begin(&TListIdentifier::new(TType::Struct, self.spans.len() as i32))?;
1011    for e in &self.spans {
1012      e.write_to_out_protocol(o_prot)?;
1013      o_prot.write_list_end()?;
1014    }
1015    o_prot.write_field_end()?;
1016    o_prot.write_field_stop()?;
1017    o_prot.write_struct_end()
1018  }
1019}
1020
1021//
1022// ZipkinCollectorSubmitZipkinBatchResult
1023//
1024
1025#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
1026struct ZipkinCollectorSubmitZipkinBatchResult {
1027  result_value: Option<Vec<Response>>,
1028}
1029
1030impl ZipkinCollectorSubmitZipkinBatchResult {
1031  fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<ZipkinCollectorSubmitZipkinBatchResult> {
1032    i_prot.read_struct_begin()?;
1033    let mut f_0: Option<Vec<Response>> = None;
1034    loop {
1035      let field_ident = i_prot.read_field_begin()?;
1036      if field_ident.field_type == TType::Stop {
1037        break;
1038      }
1039      let field_id = field_id(&field_ident)?;
1040      match field_id {
1041        0 => {
1042          let list_ident = i_prot.read_list_begin()?;
1043          let mut val: Vec<Response> = Vec::with_capacity(list_ident.size as usize);
1044          for _ in 0..list_ident.size {
1045            let list_elem_3 = Response::read_from_in_protocol(i_prot)?;
1046            val.push(list_elem_3);
1047          }
1048          i_prot.read_list_end()?;
1049          f_0 = Some(val);
1050        },
1051        _ => {
1052          i_prot.skip(field_ident.field_type)?;
1053        },
1054      };
1055      i_prot.read_field_end()?;
1056    }
1057    i_prot.read_struct_end()?;
1058    let ret = ZipkinCollectorSubmitZipkinBatchResult {
1059      result_value: f_0,
1060    };
1061    Ok(ret)
1062  }
1063  fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
1064    let struct_ident = TStructIdentifier::new("ZipkinCollectorSubmitZipkinBatchResult");
1065    o_prot.write_struct_begin(&struct_ident)?;
1066    if let Some(ref fld_var) = self.result_value {
1067      o_prot.write_field_begin(&TFieldIdentifier::new("result_value", TType::List, 0))?;
1068      o_prot.write_list_begin(&TListIdentifier::new(TType::Struct, fld_var.len() as i32))?;
1069      for e in fld_var {
1070        e.write_to_out_protocol(o_prot)?;
1071        o_prot.write_list_end()?;
1072      }
1073      o_prot.write_field_end()?;
1074      ()
1075    } else {
1076      ()
1077    }
1078    o_prot.write_field_stop()?;
1079    o_prot.write_struct_end()
1080  }
1081  fn ok_or(self) -> thrift::Result<Vec<Response>> {
1082    if self.result_value.is_some() {
1083      Ok(self.result_value.unwrap())
1084    } else {
1085      Err(
1086        thrift::Error::Application(
1087          ApplicationError::new(
1088            ApplicationErrorKind::MissingResult,
1089            "no result received for ZipkinCollectorSubmitZipkinBatch"
1090          )
1091        )
1092      )
1093    }
1094  }
1095}
1096