Zserio C++17 runtime library  1.1.0
Built for Zserio 2.18.1
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(const ZSERIO_OBJECT& object, const ALLOC& allocator = ALLOC()) :
64  m_object(object),
65  m_introspectable(introspectable(View(m_object), allocator)),
66  m_data(allocator)
67  {}
68 
75  explicit BasicIntrospectableServiceData(ZSERIO_OBJECT&& object, const ALLOC& allocator = ALLOC()) :
76  m_object(std::move(object)),
77  m_introspectable(introspectable(View(m_object), allocator)),
78  m_data(allocator)
79  {}
80 
82  {
83  return m_introspectable;
84  }
85 
91  Span<const uint8_t> getData() const override
92  {
93  if (m_introspectable && m_data.getBitSize() == 0)
94  {
95  // lazy initialization
96  m_data = m_introspectable->serialize(m_data.get_allocator());
97  }
98  return m_data.getData();
99  }
100 
101 private:
102  ZSERIO_OBJECT m_object;
104  mutable BasicBitBuffer<ALLOC> m_data;
105 };
106 
110 template <typename ALLOC = std::allocator<uint8_t>>
112 {
113 public:
120  template <typename ZSERIO_OBJECT>
121  explicit BasicObjectServiceData(const ZSERIO_OBJECT& object, const ALLOC& allocator = ALLOC()) :
122  m_data(zserio::serialize(object, allocator))
123  {}
124 
126  {
127  return nullptr;
128  }
129 
130  Span<const uint8_t> getData() const override
131  {
132  return m_data.getData();
133  }
134 
135 private:
136  BasicBitBuffer<ALLOC> m_data;
137 };
138 
142 template <typename ALLOC = std::allocator<uint8_t>>
144 {
145 public:
152  m_data(rawData)
153  {}
154 
161  m_data(std::move(rawData))
162  {}
163 
165  {
166  return nullptr;
167  }
168 
169  Span<const uint8_t> getData() const override
170  {
171  return m_data;
172  }
173 
174 private:
175  Vector<uint8_t, ALLOC> m_data;
176 };
177 
183 template <typename ALLOC = std::allocator<uint8_t>>
185 {
186 public:
193  m_data(rawData)
194  {}
195 
197  {
198  return nullptr;
199  }
200 
201  Span<const uint8_t> getData() const override
202  {
203  return m_data;
204  }
205 
206 private:
207  Span<const uint8_t> m_data;
208 };
209 
213 template <typename ALLOC = std::allocator<uint8_t>>
215 {
216 public:
217  virtual ~IBasicService() = default;
218 
231  std::string_view methodName, Span<const uint8_t> requestData, void* context) = 0;
232 };
233 
237 template <typename ALLOC = std::allocator<uint8_t>>
239 {
240 public:
241  virtual ~IBasicServiceClient() = default;
242 
255  std::string_view methodName, const IBasicServiceData<ALLOC>& requestData, void* context) = 0;
256 };
257 
268 template <typename ZSERIO_OBJECT>
275 } // namespace zserio
276 
277 #endif // ifndef ZSERIO_ISERVICE_H_INC
BasicIntrospectableServiceData(const ZSERIO_OBJECT &object, const ALLOC &allocator=ALLOC())
Definition: IService.h:63
BasicIntrospectableServiceData(ZSERIO_OBJECT &&object, const ALLOC &allocator=ALLOC())
Definition: IService.h:75
Span< const uint8_t > getData() const override
Definition: IService.h:91
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:81
BasicObjectServiceData(const ZSERIO_OBJECT &object, const ALLOC &allocator=ALLOC())
Definition: IService.h:121
Span< const uint8_t > getData() const override
Definition: IService.h:130
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:125
Span< const uint8_t > getData() const override
Definition: IService.h:169
BasicRawServiceDataHolder(Vector< uint8_t, ALLOC > &&rawData)
Definition: IService.h:160
BasicRawServiceDataHolder(const Vector< uint8_t, ALLOC > &rawData)
Definition: IService.h:151
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:164
IBasicIntrospectableViewConstPtr< ALLOC > getIntrospectable() const override
Definition: IService.h:196
Span< const uint8_t > getData() const override
Definition: IService.h:201
BasicRawServiceDataView(zserio::Span< const uint8_t > rawData)
Definition: IService.h:192
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:261
typename IBasicIntrospectableView< ALLOC >::ConstPtr IBasicIntrospectableViewConstPtr
std::shared_ptr< IBasicServiceData< ALLOC > > IBasicServiceDataPtr
Definition: IService.h:45