protozero
Minimalistic protocol buffer decoder and encoder in C++.
pbf_message.hpp
Go to the documentation of this file.
1 #ifndef PROTOZERO_PBF_MESSAGE_HPP
2 #define PROTOZERO_PBF_MESSAGE_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 
19 #include <type_traits>
20 
21 #include <protozero/pbf_reader.hpp>
22 #include <protozero/types.hpp>
23 
24 namespace protozero {
25 
64 template <typename T>
65 class pbf_message : public pbf_reader {
66 
67  static_assert(std::is_same<pbf_tag_type, typename std::underlying_type<T>::type>::value, "T must be enum with underlying type protozero::pbf_tag_type");
68 
69 public:
70 
71  using enum_type = T;
72 
73  template <typename... Args>
74  pbf_message(Args&&... args) noexcept :
75  pbf_reader(std::forward<Args>(args)...) {
76  }
77 
78  bool next() {
79  return pbf_reader::next();
80  }
81 
82  bool next(T next_tag) {
83  return pbf_reader::next(pbf_tag_type(next_tag));
84  }
85 
86  bool next(T next_tag, pbf_wire_type type) {
87  return pbf_reader::next(pbf_tag_type(next_tag), type);
88  }
89 
90  T tag() const noexcept {
91  return T(pbf_reader::tag());
92  }
93 
94 }; // class pbf_message
95 
96 } // end namespace protozero
97 
98 #endif // PROTOZERO_PBF_MESSAGE_HPP
Contains the declaration of low-level types used in the pbf format.
pbf_reader() noexcept=default
pbf_wire_type
Definition: types.hpp:40
Definition: pbf_message.hpp:65
Contains the pbf_reader class.
uint32_t pbf_tag_type
Definition: types.hpp:33
pbf_tag_type tag() const noexcept
Definition: pbf_reader.hpp:390
Definition: pbf_reader.hpp:60
bool next()
Definition: pbf_reader.hpp:276
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:24