pulsar-client-cpp
Loading...
Searching...
No Matches
TypedMessage.h
1
19#pragma once
20
21#include <pulsar/Message.h>
22
23#include <functional>
24
25namespace pulsar {
26
27template <typename T>
28class TypedMessage : public Message {
29 public:
30 using Decoder = std::function<T(const char*, std::size_t)>;
31
32 TypedMessage() = default;
33
35 const Message& message, Decoder decoder = [](const char*, std::size_t) { return T{}; })
36 : Message(message), decoder_(decoder) {}
37
38 T getValue() const { return decoder_(static_cast<const char*>(getData()), getLength()); }
39
40 TypedMessage& setDecoder(Decoder decoder) {
41 decoder_ = decoder;
42 return *this;
43 }
44
45 private:
46 Decoder decoder_;
47};
48
49} // namespace pulsar
Definition Message.h:44
std::size_t getLength() const
const void * getData() const
Definition TypedMessage.h:28
Definition Authentication.h:31