3 #include <kafka/Project.h>
19 #if COMPILER_SUPPORTS_CPP_17
22 using Optional = std::optional<T>;
24 #include <boost/optional.hpp>
25 #include <boost/optional/optional_io.hpp>
27 using Optional = boost::optional<T>;
37 explicit ConstBuffer(
const void* data =
nullptr, std::size_t size = 0): _data(data), _size(size) {}
38 const void* data()
const {
return _data; }
39 std::size_t size()
const {
return _size; }
40 std::string toString()
const
42 if (_size == 0)
return _data ?
"[empty]" :
"[null]";
44 std::ostringstream oss;
46 auto printChar = [&oss](
const unsigned char c) {
47 if (std::isprint(c)) {
50 oss <<
"[0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(c) <<
"]";
53 const auto* beg =
static_cast<const unsigned char*
>(_data);
54 std::for_each(beg, beg + _size, printChar);
67 #if COMPILER_SUPPORTS_CPP_17
68 const inline std::chrono::milliseconds InfiniteTimeout = (std::chrono::milliseconds::max)();
70 const static std::chrono::milliseconds InfiniteTimeout = (std::chrono::milliseconds::max)();
77 using Topic = std::string;
82 using Partition = std::int32_t;
87 using Offset = std::int64_t;
92 using Key = ConstBuffer;
93 using KeySize = std::size_t;
98 #if COMPILER_SUPPORTS_CPP_17
99 const inline Key NullKey = Key{};
101 const static Key NullKey = Key{};
107 using Value = ConstBuffer;
108 using ValueSize = std::size_t;
113 #if COMPILER_SUPPORTS_CPP_17
114 const inline Value NullValue = Value{};
116 const static Value NullValue = Value{};
122 using Topics = std::set<Topic>;
127 using TopicPartition = std::pair<Topic, Partition>;
132 using TopicPartitions = std::set<TopicPartition>;
137 using TopicPartitionOffset = std::tuple<Topic, Partition, Offset>;
142 using TopicPartitionOffsets = std::map<TopicPartition, Offset>;
148 inline std::string toString(
const Topics& topics)
151 std::for_each(topics.cbegin(), topics.cend(),
152 [&ret](
const auto& topic) {
153 ret.append(ret.empty() ?
"" :
",").append(topic);
161 inline std::string toString(
const TopicPartition& tp)
163 return tp.first + std::string(
"-") + std::to_string(tp.second);
169 inline std::string toString(
const TopicPartitions& tps)
172 std::for_each(tps.cbegin(), tps.cend(),
173 [&ret](
const auto& tp) {
174 ret.append((ret.empty() ?
"" :
",") + tp.first +
"-" + std::to_string(tp.second));
182 inline std::string toString(
const TopicPartitionOffset& tpo)
184 return std::get<0>(tpo) +
"-" + std::to_string(std::get<1>(tpo)) +
":" + std::to_string(std::get<2>(tpo));
190 inline std::string toString(
const TopicPartitionOffsets& tpos)
193 std::for_each(tpos.cbegin(), tpos.cend(),
194 [&ret](
const auto& tp_o) {
195 const TopicPartition& tp = tp_o.first;
196 const Offset& o = tp_o.second;
197 ret.append((ret.empty() ?
"" :
",") + tp.first +
"-" + std::to_string(tp.second) +
":" + std::to_string(o));