Modern C++ Kafka API
Header.h
1 #pragma once
2 
3 #include <kafka/Project.h>
4 
5 #include <kafka/Types.h>
6 
7 #include <algorithm>
8 #include <string>
9 #include <vector>
10 
11 
12 namespace KAFKA_API {
13 
17 struct Header
18 {
19  using Key = std::string;
20  using Value = ConstBuffer;
21 
22  Header() = default;
23  Header(Key k, Value v): key(std::move(k)), value(v) {}
24 
28  std::string toString() const
29  {
30  return (key.empty() ? "[null]" : key) + ":" + value.toString();
31  }
32 
33  Key key;
34  Value value;
35 };
36 
40 using Headers = std::vector<Header>;
41 
45 #if COMPILER_SUPPORTS_CPP_17
46 const inline Headers NullHeaders = Headers{};
47 #else
48 const static Headers NullHeaders = Headers{};
49 #endif
50 
54 inline std::string toString(const Headers& headers)
55 {
56  std::string ret;
57  std::for_each(headers.cbegin(), headers.cend(),
58  [&ret](const auto& header) {
59  ret.append(ret.empty() ? "" : ",").append(header.toString());
60  });
61  return ret;
62 }
63 
64 } // end of KAFKA_API
65 
Message Header (with a key value pair)
Definition: Header.h:18
std::string toString() const
Obtains explanatory string.
Definition: Header.h:28