1 // Copyright 2020 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 #include <cstring>
16
17 #include "pw_bloat/bloat_this_binary.h"
18 #include "pw_protobuf/decoder.h"
19
20 namespace {
21 // clang-format off
22 constexpr uint8_t encoded_proto[] = {
23 // type=int32, k=1, v=42
24 0x08, 0x2a,
25 // type=sint32, k=2, v=-13
26 0x10, 0x19,
27 };
28 // clang-format on
29 } // namespace
30
31 int* volatile non_optimizable_pointer;
32
main()33 int main() {
34 pw::bloat::BloatThisBinary();
35
36 int32_t test_int32, test_sint32;
37 std::string_view str;
38 float f;
39 double d;
40
41 pw::protobuf::Decoder decoder(pw::as_bytes(pw::span(encoded_proto)));
42 while (decoder.Next().ok()) {
43 switch (decoder.FieldNumber()) {
44 case 1:
45 decoder.ReadInt32(&test_int32).IgnoreError();
46 break;
47 case 2:
48 decoder.ReadSint32(&test_sint32).IgnoreError();
49 break;
50 case 3:
51 decoder.ReadString(&str).IgnoreError();
52 break;
53 case 4:
54 decoder.ReadFloat(&f).IgnoreError();
55 break;
56 case 5:
57 decoder.ReadDouble(&d).IgnoreError();
58 break;
59 }
60 }
61
62 *non_optimizable_pointer = test_int32 + test_sint32;
63
64 return 0;
65 }
66