1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef INCLUDE_PERFETTO_PROTOZERO_PROTO_FIELD_DESCRIPTOR_H_
18#define INCLUDE_PERFETTO_PROTOZERO_PROTO_FIELD_DESCRIPTOR_H_
19
20#include <stdint.h>
21
22namespace protozero {
23
24// Used for minimal reflection support in auto-generated .pbzero.h files.
25class ProtoFieldDescriptor {
26 public:
27  enum Type {
28    TYPE_INVALID = 0,
29    TYPE_DOUBLE = 1,
30    TYPE_FLOAT = 2,
31    TYPE_INT64 = 3,
32    TYPE_UINT64 = 4,
33    TYPE_INT32 = 5,
34    TYPE_FIXED64 = 6,
35    TYPE_FIXED32 = 7,
36    TYPE_BOOL = 8,
37    TYPE_STRING = 9,
38    TYPE_MESSAGE = 11,
39    // TYPE_GROUP = 10 is not supported.
40    TYPE_BYTES = 12,
41    TYPE_UINT32 = 13,
42    TYPE_ENUM = 14,
43    TYPE_SFIXED32 = 15,
44    TYPE_SFIXED64 = 16,
45    TYPE_SINT32 = 17,
46    TYPE_SINT64 = 18,
47  };
48
49  ProtoFieldDescriptor(const char* name,
50                       Type type,
51                       uint32_t number,
52                       bool is_repeated)
53      : name_(name), type_(type), number_(number), is_repeated_(is_repeated) {}
54
55  const char* name() const { return name_; }
56  Type type() const { return type_; }
57  uint32_t number() const { return number_; }
58  bool is_repeated() const { return is_repeated_; }
59  bool is_valid() const { return type_ != Type::TYPE_INVALID; }
60
61 private:
62  const char* const name_;
63  const Type type_;
64  const uint32_t number_;
65  const bool is_repeated_;
66};
67
68}  // namespace protozero
69
70#endif  // INCLUDE_PERFETTO_PROTOZERO_PROTO_FIELD_DESCRIPTOR_H_
71