1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// WARNING: This file is machine generated by measure-tape.

use inner::MeasurableAll;

#[derive(Debug, Eq, PartialEq)]
pub struct Size {
  pub num_bytes: usize,
  pub num_handles: usize,
}

pub trait Measurable {
  fn measure(&self) -> Size;
}


impl Measurable for fidl_fuchsia_logger::LogMessage {
  fn measure(&self) -> Size {
    let mut size_agg = inner::SizeAgg { maxed_out: false, num_bytes: 0, num_handles: 0 };
    self.measure_all(&mut size_agg);
    size_agg.to_size()
  }
}


mod inner {
#![allow(unused_imports)]
#![allow(unused_mut)]

use {
  crate::Size,
  fidl::encoding::round_up_to_align,
  fidl_fuchsia_logger,
  fuchsia_zircon_types as zx,
};

pub struct SizeAgg {
  pub maxed_out: bool,
  pub num_bytes: usize,
  pub num_handles: usize,
}

impl SizeAgg {
  #[inline(always)]
  fn add_num_bytes(&mut self, num_bytes: usize) {
    self.num_bytes += num_bytes;
  }

  #[inline(always)]
  #[allow(dead_code)]
  fn add_num_handles(&mut self, num_handles: usize) {
    self.num_handles += num_handles;
  }

  #[inline(always)]
  pub fn to_size(&self) -> Size {
    if self.maxed_out {
      return Size {
        num_bytes: zx::ZX_CHANNEL_MAX_MSG_BYTES as usize,
        num_handles: zx::ZX_CHANNEL_MAX_MSG_HANDLES as usize,
      };
    }
    return Size { num_bytes: self.num_bytes, num_handles: self.num_handles };
  }
}

pub trait MeasurableAll {
  fn measure_all(&self, size_agg: &mut SizeAgg);
}

trait MeasurableOutOfLine {
  fn measure_out_of_line(&self, size_agg: &mut SizeAgg);
}

trait MeasurableHandles {
  fn measure_handles(&self, size_agg: &mut SizeAgg);
}

impl MeasurableAll for fidl_fuchsia_logger::LogMessage {
  #[inline]
  #[allow(unused_variables)]
  fn measure_all(&self, size_agg: &mut SizeAgg) {
    let value = self;
    size_agg.add_num_bytes(round_up_to_align(64, 8));
    value.measure_out_of_line(size_agg);
  }
}

impl MeasurableOutOfLine for fidl_fuchsia_logger::LogMessage {
  #[inline]
  #[allow(unused_variables)]
  fn measure_out_of_line(&self, size_agg: &mut SizeAgg) {
    let value = self;
    for tags_elem in value.tags.iter() {
      size_agg.add_num_bytes(16);
      size_agg.add_num_bytes(round_up_to_align(tags_elem.len(), 8));
    }
    size_agg.add_num_bytes(round_up_to_align(value.msg.len(), 8));
  }
}
}