-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy patherpc_basic_codec.h
More file actions
400 lines (346 loc) · 10.4 KB
/
Copy patherpc_basic_codec.h
File metadata and controls
400 lines (346 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__BASIC_SERIALIZATION_H_
#define _EMBEDDED_RPC__BASIC_SERIALIZATION_H_
#include "erpc_codec.h"
/*!
* @addtogroup infra_codec
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Values of the uint8 flag prefixing nullable values.
*/
enum _null_flag
{
kNotNull = 0,
kIsNull
};
/*!
* @brief Simple binary serialization format.
*
* @ingroup infra_codec
*/
class BasicCodec : public Codec
{
public:
static const uint8_t kBasicCodecVersion; /*!< Codec version. */
BasicCodec(void)
: Codec()
{
}
//! @name Encoding
//@{
/*!
* @brief Prototype for write header of message.
*
* @param[in] type Type of message.
* @param[in] service Which interface is requested.
* @param[in] request Which function need be called.
* @param[in] sequence Send sequence number to be sure that
* received message is reply for current request. or write function.
*/
virtual void startWriteMessage(message_type_t type, uint32_t service, const Md5Hash request, uint32_t sequence) override;
/*!
* @brief Prototype for write data stream.
*
* @param[in] value Pointer to data stream.
* @param[in] length Size of data stream in bytes.
*/
virtual void writeData(const void *value, uint32_t length);
/*!
* @brief Prototype for write boolean value.
*
* @param[in] value Boolean typed value to write.
*/
virtual void write(bool value) override;
/*!
* @brief Prototype for write int8_t value.
*
* @param[in] value int8_t typed value to write.
*/
virtual void write(int8_t value) override;
/*!
* @brief Prototype for write int16_t value.
*
* @param[in] value int16_t typed value to write.
*/
virtual void write(int16_t value) override;
/*!
* @brief Prototype for write int32_t value.
*
* @param[in] value int32_t typed value to write.
*/
virtual void write(int32_t value) override;
/*!
* @brief Prototype for write int64_t value.
*
* @param[in] value int64_t typed value to write.
*/
virtual void write(int64_t value) override;
/*!
* @brief Prototype for write uint8_t value.
*
* @param[in] value uint8_t typed value to write.
*/
virtual void write(uint8_t value) override;
/*!
* @brief Prototype for write uint16_t value.
*
* @param[in] value uint16_t typed value to write.
*/
virtual void write(uint16_t value) override;
/*!
* @brief Prototype for write uint32_t value.
*
* @param[in] value uint32_t typed value to write.
*/
virtual void write(uint32_t value) override;
/*!
* @brief Prototype for write uint64_t value.
*
* @param[in] value uint64_t typed value to write.
*/
virtual void write(uint64_t value) override;
/*!
* @brief Prototype for write float value.
*
* @param[in] value float typed value to write.
*/
virtual void write(float value) override;
/*!
* @brief Prototype for write double value.
*
* @param[in] value double typed value to write.
*/
virtual void write(double value) override;
/*!
* @brief Prototype for write uintptr value.
*
* @param[in] value uintptr typed value to write.
*/
virtual void writePtr(uintptr_t value) override;
/*!
* @brief Prototype for write string value.
*
* @param[in] length of string.
* @param[in] value string value to write.
*/
virtual void writeString(uint32_t length, const char *value) override;
/*!
* @brief Prototype for write binary value.
*
* @param[in] length of binary.
* @param[in] value Binary value to write.
*/
virtual void writeBinary(uint32_t length, const uint8_t *value) override;
/*!
* @brief Prototype for start write list.
*
* @param[in] length Length of list.
*/
virtual void startWriteList(uint32_t length) override;
/*!
* @brief Prototype for start write union.
*
* @param[in] discriminator Discriminator of union.
*/
virtual void startWriteUnion(int32_t discriminator) override;
/*!
* @brief Writes a flag indicating whether the next value is null.
*
* @param[in] isNull Null flag to send.
*/
virtual void writeNullFlag(bool isNull) override;
/*!
* @brief Writes an order ID of callback function.
*
* @param[in] callbacks Pointer to array of callbacks.
* @param[in] callbacksCount Size of array of callbacks.
* @param[in] callback Callback which ID should be serialized.
*/
virtual void writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback) override;
/*!
* @brief Writes an order ID of callback function.
*
* @param[in] callback1 Pointer to existing callback.
* @param[out] callback2 Callback which ID should be serialized.
*/
virtual void writeCallback(funPtr callback1, funPtr callback2) override;
//@}
//! @name Decoding
//@{
/*!
* @brief Prototype for read header of message.
*
* @param[out] type Type of message.
* @param[out] service Which interface was used.
* @param[out] request Which function was called.
* @param[out] sequence Returned sequence number to be sure that
* received message is reply for current request.
*/
virtual void startReadMessage(message_type_t *type, uint32_t *service, Md5Hash request,
uint32_t *sequence) override;
/*!
* @brief Prototype for read data stream.
*
* @param[in] value Pointer to data stream to be read.
* @param[in] length Size of data stream in bytes to be read.
*/
virtual void readData(void *value, uint32_t length);
/*!
* @brief Prototype for read boolean value.
*
* @param[out] value Boolean typed value to read.
*/
virtual void read(bool *value) override;
/*!
* @brief Prototype for read int8_t value.
*
* @param[out] value int8_t typed value to read.
*/
virtual void read(int8_t *value) override;
/*!
* @brief Prototype for read int16_t value.
*
* @param[out] value int16_t typed value to read.
*/
virtual void read(int16_t *value) override;
/*!
* @brief Prototype for read int32_t value.
*
* @param[out] value int32_t typed value to read.
*/
virtual void read(int32_t *value) override;
/*!
* @brief Prototype for read int64_t value.
*
* @param[out] value int64_t typed value to read.
*/
virtual void read(int64_t *value) override;
/*!
* @brief Prototype for read uint8_t value.
*
* @param[out] value uint8_t typed value to read.
*/
virtual void read(uint8_t *value) override;
/*!
* @brief Prototype for read uint16_t value.
*
* @param[out] value uint16_t typed value to read.
*/
virtual void read(uint16_t *value) override;
/*!
* @brief Prototype for read uint32_t value.
*
* @param[out] value uint32_t typed value to read.
*/
virtual void read(uint32_t *value) override;
/*!
* @brief Prototype for read uint64_t value.
*
* @param[out] value uint64_t typed value to read.
*/
virtual void read(uint64_t *value) override;
/*!
* @brief Prototype for read float value.
*
* @param[out] value float typed value to read.
*/
virtual void read(float *value) override;
/*!
* @brief Prototype for read double value.
*
* @param[out] value double typed value to read.
*/
virtual void read(double *value) override;
/*!
* @brief Prototype for read uintptr value.
*
* @param[out] value uintptr typed value to read.
*/
virtual void readPtr(uintptr_t *value) override;
/*!
* @brief Prototype for read string value.
*
* @param[out] length of string.
* @param[out] value String value to read.
*/
virtual void readString(uint32_t *length, char **value) override;
/*!
* @brief Prototype for read binary value.
*
* @param[out] length of binary.
* @param[out] value Binary value to read.
*/
virtual void readBinary(uint32_t *length, uint8_t **value) override;
/*!
* @brief Prototype for start read list.
*
* @param[out] length Length of list.
*/
virtual void startReadList(uint32_t *length) override;
/*!
* @brief Prototype for start read union.
*
* @param[in] discriminator Discriminator of union.
*/
virtual void startReadUnion(int32_t *discriminator) override;
/*!
* @brief Reads a flag indicating whether the next value is null.
*
* @param[in] isNull Null flag to read.
*/
virtual void readNullFlag(bool *isNull) override;
/*!
* @brief Read an callback function id and return address of callback function.
*
* @param[in] callbacks Pointer to array of callbacks.
* @param[in] callbacksCount Size of array of callbacks.
* @param[out] callback Callback which is deserialized.
*/
virtual void readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback) override;
/*!
* @brief Read an callback function id and return address of callback function.
*
* @param[in] callback1 Pointer to existing callback.
* @param[out] callback2 Callback which is deserialized.
*/
virtual void readCallback(funPtr callbacks1, funPtr *callback2) override;
//@}
};
/*!
* @brief Basic codec factory implements functions from codec factory.
*
* @ingroup infra_codec
*/
class BasicCodecFactory : public CodecFactory
{
public:
/*!
* @brief Return created codec.
*
* @return Pointer to created codec.
*/
virtual Codec *create(void) override;
/*!
* @brief Dispose codec.
*
* @param[in] codec Codec to dispose.
*/
virtual void dispose(Codec *codec) override;
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__BASIC_SERIALIZATION_H_