• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 // Code generated by "measure-tape"; DO NOT EDIT.
16 //
17 // See tools/fidl/measure-tape/README.md
18 
19 // clang-format off
20 #include "hlcpp_measure_tape_for_read_by_type_result.h"
21 
22 #include <fuchsia/bluetooth/gatt2/cpp/fidl.h>
23 #include <zircon/types.h>
24 
25 
26 namespace measure_tape {
27 namespace fuchsia {
28 namespace bluetooth {
29 namespace gatt2 {
30 
31 namespace {
32 
33 class MeasuringTape {
34  public:
35   MeasuringTape() = default;
36 
Measure(const::fuchsia::bluetooth::gatt2::Handle & value)37   void Measure(const ::fuchsia::bluetooth::gatt2::Handle& value) {
38     num_bytes_ += FIDL_ALIGN(8);
39   }
40 
Measure(const::fuchsia::bluetooth::gatt2::ReadByTypeResult & value)41   void Measure(const ::fuchsia::bluetooth::gatt2::ReadByTypeResult& value) {
42     num_bytes_ += 16;
43     MeasureOutOfLine(value);
44   }
45 
MeasureOutOfLine(const::fuchsia::bluetooth::gatt2::ReadByTypeResult & value)46   void MeasureOutOfLine(const ::fuchsia::bluetooth::gatt2::ReadByTypeResult& value) {
47     int32_t max_ordinal = 0;
48     if (value.has_handle()) {
49       Measure(value.handle());
50       max_ordinal = 1;
51     }
52     if (value.has_value()) {
53       Measure(value.value());
54       max_ordinal = 2;
55     }
56     if (value.has_error()) {
57       max_ordinal = 3;
58     }
59     num_bytes_ += 8 * max_ordinal;
60   }
61 
Measure(const::fuchsia::bluetooth::gatt2::ReadValue & value)62   void Measure(const ::fuchsia::bluetooth::gatt2::ReadValue& value) {
63     num_bytes_ += 16;
64     MeasureOutOfLine(value);
65   }
66 
MeasureOutOfLine(const::fuchsia::bluetooth::gatt2::ReadValue & value)67   void MeasureOutOfLine(const ::fuchsia::bluetooth::gatt2::ReadValue& value) {
68     int32_t max_ordinal = 0;
69     if (value.has_handle()) {
70       Measure(value.handle());
71       max_ordinal = 1;
72     }
73     if (value.has_value()) {
74       num_bytes_ += 16;
75       num_bytes_ += FIDL_ALIGN(value.value().size() * 1);
76       max_ordinal = 2;
77     }
78     if (value.has_maybe_truncated()) {
79       max_ordinal = 3;
80     }
81     num_bytes_ += 8 * max_ordinal;
82   }
83 
Done()84   Size Done() {
85     if (maxed_out_) {
86       return Size(ZX_CHANNEL_MAX_MSG_BYTES, ZX_CHANNEL_MAX_MSG_HANDLES);
87     }
88     return Size(num_bytes_, num_handles_);
89   }
90 
91 private:
MaxOut()92   void MaxOut() { maxed_out_ = true; }
93 
94   bool maxed_out_ = false;
95   int64_t num_bytes_ = 0;
96   int64_t num_handles_ = 0;
97 };
98 
99 }  // namespace
100 
101 
Measure(const::fuchsia::bluetooth::gatt2::ReadByTypeResult & value)102 Size Measure(const ::fuchsia::bluetooth::gatt2::ReadByTypeResult& value) {
103   MeasuringTape tape;
104   tape.Measure(value);
105   return tape.Done();
106 }
107 
108 
109 
110 }  // gatt2
111 }  // bluetooth
112 }  // fuchsia
113 }  // measure_tape
114 
115