9
9
*/
10
10
11
11
#include " erpc_basic_codec.hpp"
12
+
12
13
#include " erpc_config_internal.h"
13
14
#include ENDIANNESS_HEADER
14
15
#include " erpc_manually_constructed.hpp"
@@ -36,7 +37,7 @@ void BasicCodec::startWriteMessage(message_type_t type, uint32_t service, uint32
36
37
write (sequence);
37
38
}
38
39
39
- void BasicCodec::writeData (const void *value, uint32_t length )
40
+ void BasicCodec::writeData (uint32_t length, const void *value)
40
41
{
41
42
if (isStatusOk ())
42
43
{
@@ -49,73 +50,73 @@ void BasicCodec::write(bool value)
49
50
// Make sure the bool is a single byte.
50
51
uint8_t v = (uint8_t )value;
51
52
52
- writeData (&v, sizeof (v));
53
+ writeData (sizeof (v), &v );
53
54
}
54
55
55
56
void BasicCodec::write (int8_t value)
56
57
{
57
- writeData (&value, sizeof (value));
58
+ writeData (sizeof (value), &value );
58
59
}
59
60
60
61
void BasicCodec::write (int16_t value)
61
62
{
62
63
ERPC_WRITE_AGNOSTIC_16 (value);
63
64
64
- writeData (&value, sizeof (value));
65
+ writeData (sizeof (value), &value );
65
66
}
66
67
67
68
void BasicCodec::write (int32_t value)
68
69
{
69
70
ERPC_WRITE_AGNOSTIC_32 (value);
70
71
71
- writeData (&value, sizeof (value));
72
+ writeData (sizeof (value), &value );
72
73
}
73
74
74
75
void BasicCodec::write (int64_t value)
75
76
{
76
77
ERPC_WRITE_AGNOSTIC_64 (value);
77
78
78
- writeData (&value, sizeof (value));
79
+ writeData (sizeof (value), &value );
79
80
}
80
81
81
82
void BasicCodec::write (uint8_t value)
82
83
{
83
- writeData (&value, sizeof (value));
84
+ writeData (sizeof (value), &value );
84
85
}
85
86
86
87
void BasicCodec::write (uint16_t value)
87
88
{
88
89
ERPC_WRITE_AGNOSTIC_16 (value);
89
90
90
- writeData (&value, sizeof (value));
91
+ writeData (sizeof (value), &value );
91
92
}
92
93
93
94
void BasicCodec::write (uint32_t value)
94
95
{
95
96
ERPC_WRITE_AGNOSTIC_32 (value);
96
97
97
- writeData (&value, sizeof (value));
98
+ writeData (sizeof (value), &value );
98
99
}
99
100
100
101
void BasicCodec::write (uint64_t value)
101
102
{
102
103
ERPC_WRITE_AGNOSTIC_64 (value);
103
104
104
- writeData (&value, sizeof (value));
105
+ writeData (sizeof (value), &value );
105
106
}
106
107
107
108
void BasicCodec::write (float value)
108
109
{
109
110
ERPC_WRITE_AGNOSTIC_FLOAT (value);
110
111
111
- writeData (&value, sizeof (value));
112
+ writeData (sizeof (value), &value );
112
113
}
113
114
114
115
void BasicCodec::write (double value)
115
116
{
116
117
ERPC_WRITE_AGNOSTIC_DOUBLE (value);
117
118
118
- writeData (&value, sizeof (value));
119
+ writeData (sizeof (value), &value );
119
120
}
120
121
121
122
void BasicCodec::writePtr (uintptr_t value)
@@ -126,7 +127,7 @@ void BasicCodec::writePtr(uintptr_t value)
126
127
127
128
ERPC_WRITE_AGNOSTIC_PTR (value);
128
129
129
- writeData (&value, ptrSize );
130
+ writeData (ptrSize, &value );
130
131
}
131
132
132
133
void BasicCodec::writeString (uint32_t length, const char *value)
@@ -140,7 +141,7 @@ void BasicCodec::writeBinary(uint32_t length, const uint8_t *value)
140
141
// Write the blob length as a u32.
141
142
write (length);
142
143
143
- writeData (value, length );
144
+ writeData (length, value );
144
145
}
145
146
146
147
void BasicCodec::startWriteList (uint32_t length)
@@ -191,11 +192,11 @@ void BasicCodec::writeCallback(funPtr callback1, funPtr callback2)
191
192
}
192
193
}
193
194
194
- void BasicCodec::startReadMessage (message_type_t * type, uint32_t * service, uint32_t * request, uint32_t * sequence)
195
+ void BasicCodec::startReadMessage (message_type_t & type, uint32_t & service, uint32_t & request, uint32_t & sequence)
195
196
{
196
197
uint32_t header;
197
198
198
- read (& header);
199
+ read (header);
199
200
200
201
if (((header >> 24 ) & 0xffU ) != kBasicCodecVersion )
201
202
{
@@ -204,150 +205,150 @@ void BasicCodec::startReadMessage(message_type_t *type, uint32_t *service, uint3
204
205
205
206
if (isStatusOk ())
206
207
{
207
- * service = ((header >> 16 ) & 0xffU );
208
- * request = ((header >> 8 ) & 0xffU );
209
- * type = static_cast <message_type_t >(header & 0xffU );
208
+ service = ((header >> 16 ) & 0xffU );
209
+ request = ((header >> 8 ) & 0xffU );
210
+ type = static_cast <message_type_t >(header & 0xffU );
210
211
211
212
read (sequence);
212
213
}
213
214
}
214
215
215
- void BasicCodec::readData (void *value, uint32_t length )
216
+ void BasicCodec::readData (uint32_t length, void *value )
216
217
{
217
218
if (isStatusOk ())
218
219
{
219
220
m_status = m_cursor.read (value, length);
220
221
}
221
222
}
222
223
223
- void BasicCodec::read (bool * value)
224
+ void BasicCodec::read (bool & value)
224
225
{
225
226
uint8_t v = 0 ;
226
227
227
- readData (&v, sizeof (v));
228
+ readData (sizeof (v), &v );
228
229
if (isStatusOk ())
229
230
{
230
- * value = (bool )v;
231
+ value = (bool )v;
231
232
}
232
233
}
233
234
234
- void BasicCodec::read (int8_t * value)
235
+ void BasicCodec::read (int8_t & value)
235
236
{
236
- readData (value, sizeof (* value));
237
+ readData (sizeof (value), &value );
237
238
}
238
239
239
- void BasicCodec::read (int16_t * value)
240
+ void BasicCodec::read (int16_t & value)
240
241
{
241
- readData (value, sizeof (* value));
242
+ readData (sizeof (value), &value );
242
243
if (isStatusOk ())
243
244
{
244
245
ERPC_READ_AGNOSTIC_16 (*value);
245
246
}
246
247
}
247
248
248
- void BasicCodec::read (int32_t * value)
249
+ void BasicCodec::read (int32_t & value)
249
250
{
250
- readData (value, sizeof (* value));
251
+ readData (sizeof (value), &value );
251
252
if (isStatusOk ())
252
253
{
253
254
ERPC_READ_AGNOSTIC_32 (*value);
254
255
}
255
256
}
256
257
257
- void BasicCodec::read (int64_t * value)
258
+ void BasicCodec::read (int64_t & value)
258
259
{
259
- readData (value, sizeof (* value));
260
+ readData (sizeof (value), &value );
260
261
if (isStatusOk ())
261
262
{
262
263
ERPC_READ_AGNOSTIC_64 (*value);
263
264
}
264
265
}
265
266
266
- void BasicCodec::read (uint8_t * value)
267
+ void BasicCodec::read (uint8_t & value)
267
268
{
268
- readData (value, sizeof (* value));
269
+ readData (sizeof (value), &value );
269
270
}
270
271
271
- void BasicCodec::read (uint16_t * value)
272
+ void BasicCodec::read (uint16_t & value)
272
273
{
273
- readData (value, sizeof (* value));
274
+ readData (sizeof (value), &value );
274
275
if (isStatusOk ())
275
276
{
276
277
ERPC_READ_AGNOSTIC_16 (*value);
277
278
}
278
279
}
279
280
280
- void BasicCodec::read (uint32_t * value)
281
+ void BasicCodec::read (uint32_t & value)
281
282
{
282
- readData (value, sizeof (* value));
283
+ readData (sizeof (value), &value );
283
284
if (isStatusOk ())
284
285
{
285
286
ERPC_READ_AGNOSTIC_32 (*value);
286
287
}
287
288
}
288
289
289
- void BasicCodec::read (uint64_t * value)
290
+ void BasicCodec::read (uint64_t & value)
290
291
{
291
- readData (value, sizeof (* value));
292
+ readData (sizeof (value), &value );
292
293
if (isStatusOk ())
293
294
{
294
295
ERPC_READ_AGNOSTIC_64 (*value);
295
296
}
296
297
}
297
298
298
- void BasicCodec::read (float * value)
299
+ void BasicCodec::read (float & value)
299
300
{
300
- readData (value, sizeof (* value));
301
+ readData (sizeof (value), &value );
301
302
if (isStatusOk ())
302
303
{
303
304
ERPC_READ_AGNOSTIC_FLOAT (*value);
304
305
}
305
306
}
306
307
307
- void BasicCodec::read (double * value)
308
+ void BasicCodec::read (double & value)
308
309
{
309
- readData (value, sizeof (* value));
310
+ readData (sizeof (value), &value );
310
311
if (isStatusOk ())
311
312
{
312
313
ERPC_READ_AGNOSTIC_DOUBLE (*value);
313
314
}
314
315
}
315
316
316
- void BasicCodec::readPtr (uintptr_t * value)
317
+ void BasicCodec::readPtr (uintptr_t & value)
317
318
{
318
319
uint8_t ptrSize;
319
320
320
- read (& ptrSize);
321
+ read (ptrSize);
321
322
322
- if (ptrSize > sizeof (* value))
323
+ if (ptrSize > sizeof (value))
323
324
{
324
325
updateStatus (kErpcStatus_BadAddressScale );
325
326
}
326
327
327
- readData (value, ptrSize );
328
+ readData (ptrSize, &value );
328
329
if (isStatusOk ())
329
330
{
330
331
ERPC_READ_AGNOSTIC_PTR (*value);
331
332
}
332
333
}
333
334
334
- void BasicCodec::readString (uint32_t * length, char **value)
335
+ void BasicCodec::readString (uint32_t & length, char **value)
335
336
{
336
337
readBinary (length, reinterpret_cast <uint8_t **>(value));
337
338
}
338
339
339
- void BasicCodec::readBinary (uint32_t * length, uint8_t **value)
340
+ void BasicCodec::readBinary (uint32_t & length, uint8_t **value)
340
341
{
341
342
// Read length first as u32.
342
343
read (length);
343
344
344
345
if (isStatusOk ())
345
346
{
346
- if (m_cursor.getRemainingUsed () < * length)
347
+ if (m_cursor.getRemainingUsed () < length)
347
348
{
348
349
m_status = kErpcStatus_Fail ;
349
350
}
350
- else if (m_cursor.getRemaining () < * length)
351
+ else if (m_cursor.getRemaining () < length)
351
352
{
352
353
m_status = kErpcStatus_BufferOverrun ;
353
354
}
@@ -357,41 +358,41 @@ void BasicCodec::readBinary(uint32_t *length, uint8_t **value)
357
358
*value = m_cursor.get ();
358
359
359
360
// Skip over data.
360
- m_cursor += (uint16_t )* length;
361
+ m_cursor += (uint16_t )length;
361
362
}
362
363
}
363
364
if (!isStatusOk ())
364
365
{
365
- * length = 0 ;
366
+ length = 0 ;
366
367
*value = NULL ;
367
368
}
368
369
}
369
370
370
- void BasicCodec::startReadList (uint32_t * length)
371
+ void BasicCodec::startReadList (uint32_t & length)
371
372
{
372
373
// Read list length as u32.
373
374
read (length);
374
375
375
376
if (!isStatusOk ())
376
377
{
377
- * length = 0 ;
378
+ length = 0 ;
378
379
}
379
380
}
380
381
381
- void BasicCodec::startReadUnion (int32_t * discriminator)
382
+ void BasicCodec::startReadUnion (int32_t & discriminator)
382
383
{
383
384
// Read union discriminator as u32.
384
385
read (discriminator);
385
386
}
386
387
387
- void BasicCodec::readNullFlag (bool * isNull)
388
+ void BasicCodec::readNullFlag (bool & isNull)
388
389
{
389
390
uint8_t flag;
390
391
391
- read (& flag);
392
+ read (flag);
392
393
if (isStatusOk ())
393
394
{
394
- * isNull = (flag == (uint8_t )kIsNull );
395
+ isNull = (flag == (uint8_t )kIsNull );
395
396
}
396
397
}
397
398
@@ -402,7 +403,7 @@ void BasicCodec::readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, f
402
403
erpc_assert (callbacksCount > 1U );
403
404
404
405
// callbacks = callbacks table
405
- read (& _tmp_local);
406
+ read (_tmp_local);
406
407
if (isStatusOk ())
407
408
{
408
409
if (_tmp_local < callbacksCount)
0 commit comments