Zserio C++ runtime library  1.1.0
Built for Zserio 2.15.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/Span.h"
6 #include "zserio/StringView.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 IBasicReflectableConstPtr<ALLOC>& reflectable, const ALLOC& allocator = ALLOC()) :
62  m_reflectable(reflectable),
63  m_data(allocator)
64  {}
65 
67  {
68  return m_reflectable;
69  }
70 
76  Span<const uint8_t> getData() const override
77  {
78  if (m_reflectable && m_data.getBitSize() == 0)
79  {
80  // lazy initialization
81  m_data = BasicBitBuffer<ALLOC>(m_reflectable->bitSizeOf(), m_data.get_allocator());
82  BitStreamWriter writer(m_data);
83  m_reflectable->write(writer);
84  }
85  return m_data.getData();
86  }
87 
88 private:
90  mutable BasicBitBuffer<ALLOC> m_data;
91 };
92 
96 template <typename ALLOC = std::allocator<uint8_t>>
98 {
99 public:
106  template <typename ZSERIO_OBJECT>
107  explicit BasicObjectServiceData(ZSERIO_OBJECT& object, const ALLOC& allocator = ALLOC()) :
108  m_data(object.bitSizeOf(), allocator)
109  {
110  BitStreamWriter writer(m_data);
111  object.write(writer);
112  }
113 
115  {
116  return nullptr;
117  }
118 
119  Span<const uint8_t> getData() const override
120  {
121  return m_data.getData();
122  }
123 
124 private:
125  BasicBitBuffer<ALLOC> m_data;
126 };
127 
131 template <typename ALLOC = std::allocator<uint8_t>>
133 {
134 public:
141  m_data(rawData)
142  {}
143 
150  m_data(std::move(rawData))
151  {}
152 
154  {
155  return nullptr;
156  }
157 
158  Span<const uint8_t> getData() const override
159  {
160  return m_data;
161  }
162 
163 private:
164  vector<uint8_t, ALLOC> m_data;
165 };
166 
172 template <typename ALLOC = std::allocator<uint8_t>>
174 {
175 public:
182  m_data(rawData)
183  {}
184 
186  {
187  return nullptr;
188  }
189 
190  Span<const uint8_t> getData() const override
191  {
192  return m_data;
193  }
194 
195 private:
196  Span<const uint8_t> m_data;
197 };
198 
202 template <typename ALLOC = std::allocator<uint8_t>>
204 {
205 public:
206  virtual ~IBasicService() = default;
207 
220  StringView methodName, Span<const uint8_t> requestData, void* context) = 0;
221 };
222 
226 template <typename ALLOC = std::allocator<uint8_t>>
228 {
229 public:
230  virtual ~IBasicServiceClient() = default;
231 
244  StringView methodName, const IBasicServiceData<ALLOC>& requestData, void* context) = 0;
245 };
246 
263 } // namespace zserio
264 
265 #endif // ifndef ZSERIO_ISERVICE_H_INC
Span< const uint8_t > getData() const override
Definition: IService.h:119
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:114
BasicObjectServiceData(ZSERIO_OBJECT &object, const ALLOC &allocator=ALLOC())
Definition: IService.h:107
Span< const uint8_t > getData() const override
Definition: IService.h:158
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:153
BasicRawServiceDataHolder(vector< uint8_t, ALLOC > &&rawData)
Definition: IService.h:149
BasicRawServiceDataHolder(const vector< uint8_t, ALLOC > &rawData)
Definition: IService.h:140
Span< const uint8_t > getData() const override
Definition: IService.h:190
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:185
BasicRawServiceDataView(zserio::Span< const uint8_t > rawData)
Definition: IService.h:181
IBasicReflectableConstPtr< ALLOC > getReflectable() const override
Definition: IService.h:66
BasicReflectableServiceData(const IBasicReflectableConstPtr< ALLOC > &reflectable, const ALLOC &allocator=ALLOC())
Definition: IService.h:60
Span< const uint8_t > getData() const override
Definition: IService.h:76
virtual vector< uint8_t, ALLOC > callMethod(StringView methodName, const IBasicServiceData< ALLOC > &requestData, void *context)=0
virtual ~IBasicServiceClient()=default
virtual IBasicReflectableConstPtr< ALLOC > getReflectable() const =0
virtual Span< const uint8_t > getData() const =0
virtual ~IBasicServiceData()=default
virtual IBasicServiceDataPtr< ALLOC > callMethod(StringView methodName, Span< const uint8_t > requestData, void *context)=0
virtual ~IBasicService()=default
IBasicServiceDataPtr<> IServiceDataPtr
Definition: IService.h:250
std::vector< T, RebindAlloc< ALLOC, T > > vector
Definition: Vector.h:17
std::shared_ptr< IBasicServiceData< ALLOC > > IBasicServiceDataPtr
Definition: IService.h:42
size_t bitSizeOf(T value)
typename IBasicReflectable< ALLOC >::ConstPtr IBasicReflectableConstPtr
Definition: IReflectable.h:534