protozero
Minimalistic protocol buffer decoder and encoder in C++.
pbf_message.hpp
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 
13 #include <type_traits>
14 
15 #include <protozero/pbf_reader.hpp>
16 #include <protozero/pbf_types.hpp>
17 
18 namespace protozero {
19 
20 template <typename T>
21 class pbf_message : public pbf_reader {
22 
23  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");
24 
25 public:
26 
27  using enum_type = T;
28 
29  template <typename... Args>
30  pbf_message(Args&&... args) noexcept :
31  pbf_reader(std::forward<Args>(args)...) {
32  }
33 
34  inline bool next() {
35  return pbf_reader::next();
36  }
37 
38  inline bool next(T tag) {
39  return pbf_reader::next(pbf_tag_type(tag));
40  }
41 
42  inline T tag() const noexcept {
43  return T(pbf_reader::tag());
44  }
45 
46 };
47 
48 } // end namespace protozero
49 
50 #endif // PROTOZERO_PBF_MESSAGE_HPP
pbf_reader() noexcept=default
Contains the declaration of low-level types used in the pbf format.
uint32_t pbf_tag_type
Definition: pbf_types.hpp:26
Definition: pbf_message.hpp:21
Contains the pbf_reader class.
pbf_tag_type tag() const noexcept
Definition: pbf_reader.hpp:885
Definition: pbf_reader.hpp:66
bool next()
Definition: pbf_reader.hpp:856
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:15