Zserio C++ runtime library  1.0.0
Built for Zserio 2.13.0
IService.h
Go to the documentation of this file.
1 #ifndef ZSERIO_ISERVICE_H_INC
2 #define ZSERIO_ISERVICE_H_INC
3 
4 #include "zserio/IReflectable.h"
5 #include "zserio/StringView.h"
6 #include "zserio/Span.h"
7 #include "zserio/Types.h"
8 #include "zserio/Vector.h"
9 
10 namespace zserio
11 {
12 
18 template <typename ALLOC = std::allocator<uint8_t>>
20 {
21 public:
23  virtual ~IBasicServiceData() = default;
24 
31 
37  virtual Span<const uint8_t> getData() const = 0;
38 };
39 
41 template <typename ALLOC = std::allocator<uint8_t>>
42 using IBasicServiceDataPtr = std::shared_ptr<IBasicServiceData<ALLOC>>;
43 
50 template <typename ALLOC = std::allocator<uint8_t>>
52 {
53 public:
61  const ALLOC& allocator = ALLOC()) :
62  m_reflectable(reflectable), m_data(allocator)
63  {}
64 
66  {
67  return m_reflectable;
68  }
69 
75  Span<const uint8_t> getData() const override
76  {
77  if (m_reflectable && m_data.getBitSize() == 0)
78  {
79  // lazy initialization
80  m_data = BasicBitBuffer<ALLOC>(m_reflectable->bitSizeOf(), m_data.get_allocator());
81  BitStreamWriter writer(m_data);
82  m_reflectable->write(writer);
83  }
84  return m_data.getData();
85  }
86 
87 private:
89  mutable BasicBitBuffer<ALLOC> m_data;
90 };
91 
95 template <typename ALLOC = std::allocator<uint8_t>>
97 {
98 public:
105  template <typename ZSERIO_OBJECT>
106  explicit BasicObjectServiceData(ZSERIO_OBJECT& object, const ALLOC& allocator = ALLOC()) :
107  m_data(object.bitSizeOf(), allocator)
108  {
109  BitStreamWriter writer(m_data);
110  object.write(writer);
111  }
112 
114  {
115  return nullptr;
116  }
117 
118  Span<const uint8_t> getData() const override
119  {
120  return m_data.getData();
121  }
122 
123 private:
124  BasicBitBuffer<ALLOC> m_data;
125 };
126 
130 template <typename ALLOC = std::allocator<uint8_t>>
132 {
133 public:
140  : m_data(rawData)
141  {}
142 
149  : m_data(std::move(rawData))
150  {}
151 
153  {
154  return nullptr;
155  }
156 
157  Span<const uint8_t> getData() const override
158  {
159  return m_data;
160  }
161 
162 private:
163  vector<uint8_t, ALLOC> m_data;
164 };
165 
171 template <typename ALLOC = std::allocator<uint8_t>>
173 {
174 public:
181  : m_data(rawData)
182  {}
183 
185  {
186  return nullptr;
187  }
188 
189  Span<const uint8_t> getData() const override
190  {
191  return m_data;
192  }
193 
194 private:
195  Span<const uint8_t> m_data;
196 };
197 
201 template <typename ALLOC = std::allocator<uint8_t>>
203 {
204 public:
205  virtual ~IBasicService() = default;
206 
218  virtual IBasicServiceDataPtr<ALLOC> callMethod(
219  StringView methodName,
220  Span<const uint8_t> requestData,
221  void* context) = 0;
222 };
223 
227 template <typename ALLOC = std::allocator<uint8_t>>
229 {
230 public:
231  virtual ~IBasicServiceClient() = default;
232 
244  virtual vector<uint8_t, ALLOC> callMethod(
245  StringView methodName,
246  const IBasicServiceData<ALLOC>& requestData,
247  void* context) = 0;
248 };
249 
266 } // namespace zserio
267 
268 #endif // ifndef ZSERIO_ISERVICE_H_INC
typename IBasicReflectable< ALLOC >::ConstPtr IBasicReflectableConstPtr
Definition: IReflectable.h:519
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:65
BasicRawServiceDataView(zserio::Span< const uint8_t > rawData)
Definition: IService.h:180
IBasicServiceDataPtr<> IServiceDataPtr
Definition: IService.h:253
BasicReflectableServiceData(const IBasicReflectableConstPtr< ALLOC > &reflectable, const ALLOC &allocator=ALLOC())
Definition: IService.h:60
virtual Span< const uint8_t > getData() const =0
Span< const uint8_t > getData() const override
Definition: IService.h:189
Span< const uint8_t > getData() const override
Definition: IService.h:75
BasicObjectServiceData(ZSERIO_OBJECT &object, const ALLOC &allocator=ALLOC())
Definition: IService.h:106
Span< const uint8_t > getData() const override
Definition: IService.h:157
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:184
BasicRawServiceDataHolder(vector< uint8_t, ALLOC > &&rawData)
Definition: IService.h:148
virtual ~IBasicServiceData()=default
Span< const uint8_t > getData() const override
Definition: IService.h:118
std::vector< T, RebindAlloc< ALLOC, T >> vector
Definition: Vector.h:16
BasicRawServiceDataHolder(const vector< uint8_t, ALLOC > &rawData)
Definition: IService.h:139
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:152
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:113
size_t bitSizeOf(T value)
virtual IBasicReflectableConstPtr< ALLOC > getReflectable() const =0
std::shared_ptr< IBasicServiceData< ALLOC >> IBasicServiceDataPtr
Definition: IService.h:42