1 #ifndef PROTOZERO_TYPES_HPP
2 #define PROTOZERO_TYPES_HPP
3
4 /*****************************************************************************
5
6 protozero - Minimalistic protocol buffer decoder and encoder in C++.
7
8 This file is from https://github.com/mapbox/protozero where you can find more
9 documentation.
10
11 *****************************************************************************/
12
13 /**
14 * @file types.hpp
15 *
16 * @brief Contains the declaration of low-level types used in the pbf format.
17 */
18
19 #include "config.hpp"
20
21 #include <algorithm>
22 #include <cstddef>
23 #include <cstdint>
24 #include <cstring>
25 #include <string>
26 #include <utility>
27
28 namespace protozero {
29
30 /**
31 * The type used for field tags (field numbers).
32 */
33 using pbf_tag_type = uint32_t;
34
35 /**
36 * The type used to encode type information.
37 * See the table on
38 * https://developers.google.com/protocol-buffers/docs/encoding
39 */
40 enum class pbf_wire_type : uint32_t {
41 varint = 0, // int32/64, uint32/64, sint32/64, bool, enum
42 fixed64 = 1, // fixed64, sfixed64, double
43 length_delimited = 2, // string, bytes, nested messages, packed repeated fields
44 fixed32 = 5, // fixed32, sfixed32, float
45 unknown = 99 // used for default setting in this library
46 };
47
48 /**
49 * Get the tag and wire type of the current field in one integer suitable
50 * for comparison with a switch statement.
51 *
52 * See pbf_reader.tag_and_type() for an example how to use this.
53 */
54 template <typename T>
tag_and_type(T tag,pbf_wire_type wire_type)55 constexpr inline uint32_t tag_and_type(T tag, pbf_wire_type wire_type) noexcept {
56 return (static_cast<uint32_t>(static_cast<pbf_tag_type>(tag)) << 3U) | static_cast<uint32_t>(wire_type);
57 }
58
59 /**
60 * The type used for length values, such as the length of a field.
61 */
62 using pbf_length_type = uint32_t;
63
64 } // end namespace protozero
65
66 #endif // PROTOZERO_TYPES_HPP
67