Zserio C++17 runtime library  0.5.0
Built for Zserio 2.17.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 <string_view>
5 
7 #include "zserio/SerializeUtil.h"
8 #include "zserio/Span.h"
9 #include "zserio/Types.h"
10 #include "zserio/Vector.h"
11 #include "zserio/View.h"
12 
13 namespace zserio
14 {
15 
21 template <typename ALLOC = std::allocator<uint8_t>>
23 {
24 public:
26  virtual ~IBasicServiceData() = default;
27 
34 
40  virtual Span<const uint8_t> getData() const = 0;
41 };
42 
44 template <typename ALLOC = std::allocator<uint8_t>>
45 using IBasicServiceDataPtr = std::shared_ptr<IBasicServiceData<ALLOC>>;
46 
53 template <typename ZSERIO_OBJECT, typename ALLOC = std::allocator<uint8_t>>
55 {
56 public:
63  explicit BasicIntrospectableServiceData(ZSERIO_OBJECT&& response, const ALLOC& allocator = ALLOC()) :
64  m_response(std::move(response)),
65  m_introspectable(introspectable(View(m_response), allocator)),
66  m_data(allocator)
67  {}
68 
70  {
71  return m_introspectable;
72  }
73 
79  Span<const uint8_t> getData() const override
80  {
81  if (m_introspectable && m_data.getBitSize() == 0)
82  {
83  // lazy initialization
84  m_data = m_introspectable->serialize(m_data.get_allocator());
85  }
86  return m_data.getData();
87  }
88 
89 private:
90  ZSERIO_OBJECT m_response;
92  mutable BasicBitBuffer<ALLOC> m_data;
93 };
94 
98 template <typename ALLOC = std::allocator<uint8_t>>
100 {
101 public:
108  template <typename ZSERIO_OBJECT>
109  explicit BasicObjectServiceData(const ZSERIO_OBJECT& object, const ALLOC& allocator = ALLOC()) :
110  m_data(zserio::serialize(object, allocator))
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 
219  std::string_view methodName, Span<const uint8_t> requestData, void* context) = 0;
220 };
221 
225 template <typename ALLOC = std::allocator<uint8_t>>
227 {
228 public:
229  virtual ~IBasicServiceClient() = default;
230 
243  std::string_view methodName, const IBasicServiceData<ALLOC>& requestData, void* context) = 0;
244 };
245 
256 template <typename ZSERIO_OBJECT>
263 } // namespace zserio
264 
265 #endif // ifndef ZSERIO_ISERVICE_H_INC
BasicIntrospectableServiceData(ZSERIO_OBJECT &&response, const ALLOC &allocator=ALLOC())
Definition: IService.h:63
Span< const uint8_t > getData() const override
Definition: IService.h:79
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:69
BasicObjectServiceData(const ZSERIO_OBJECT &object, const ALLOC &allocator=ALLOC())
Definition: IService.h:109
Span< const uint8_t > getData() const override
Definition: IService.h:118
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:113
Span< const uint8_t > getData() const override
Definition: IService.h:157
BasicRawServiceDataHolder(Vector< uint8_t, ALLOC > &&rawData)
Definition: IService.h:148
BasicRawServiceDataHolder(const Vector< uint8_t, ALLOC > &rawData)
Definition: IService.h:139
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:152
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:184
Span< const uint8_t > getData() const override
Definition: IService.h:189
BasicRawServiceDataView(zserio::Span< const uint8_t > rawData)
Definition: IService.h:180
virtual Vector< uint8_t, ALLOC > callMethod(std::string_view methodName, const IBasicServiceData< ALLOC > &requestData, void *context)=0
virtual ~IBasicServiceClient()=default
virtual IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const =0
virtual Span< const uint8_t > getData() const =0
virtual ~IBasicServiceData()=default
virtual ~IBasicService()=default
virtual IBasicServiceDataPtr< ALLOC > callMethod(std::string_view methodName, Span< const uint8_t > requestData, void *context)=0
Definition: BitBuffer.h:602
IBasicIntrospectableViewConstPtr< ALLOC > introspectable(const View< T > &view, const ALLOC &allocator=ALLOC())
std::vector< T, ALLOC > Vector
Definition: Vector.h:13
BasicBitBuffer< ALLOC > serialize(const T &data, const ALLOC &allocator, ARGS &&... arguments)
Definition: SerializeUtil.h:53
IBasicServiceDataPtr<> IServiceDataPtr
Definition: IService.h:249
typename IBasicIntrospectableView< ALLOC >::ConstPtr IBasicIntrospectableViewConstPtr
std::shared_ptr< IBasicServiceData< ALLOC > > IBasicServiceDataPtr
Definition: IService.h:45