| eRPC API Reference Rev. 1.8.1 NXP Semiconductors

- Main Page
- API Reference
- Classes
- Files

- File List
- File Members

erpc_codec.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2014, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017 NXP
4 * Copyright 2021 ACRIOS Systems s.r.o.
5 * All rights reserved.
6 *
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10
11 #ifndef _EMBEDDED_RPC__CODEC_H_
12 #define _EMBEDDED_RPC__CODEC_H_
13
14 #include "erpc_common.h"
15 #include "erpc_message_buffer.h"
16 #include "erpc_transport.h"
17
18 #include <cstring>
19 #include <stdint.h>
20
27 // Classes
30
31 namespace erpc {
35 typedef enum _message_type
36 {
37 kInvocationMessage = 0,
38 kOnewayMessage,
39 kReplyMessage,
40 kNotificationMessage
41 } message_type_t;
42
43 typedef void *funPtr; // Pointer to functions
44 typedef funPtr *arrayOfFunPtr; // Pointer to array of functions
45
53 class Codec
54 {
55 public:
61 Codec(void)
62 : m_buffer()
63 , m_cursor()
64 , m_status(kErpcStatus_Success)
65 {
66 }
67
71 virtual ~Codec(void) {}
72
78 MessageBuffer *getBuffer(void) { return &m_buffer; }
79
85 virtual void setBuffer(MessageBuffer &buf)
86 {
87 m_buffer = buf;
88 m_cursor.set(&m_buffer);
89 m_status = kErpcStatus_Success;
90 }
91
93 virtual void reset(void)
94 {
95 m_cursor.set(&m_buffer);
96 m_status = kErpcStatus_Success;
97 }
98
104 erpc_status_t getStatus(void) { return m_status; }
105
112 bool isStatusOk(void) { return (m_status == kErpcStatus_Success); }
113
119 void updateStatus(erpc_status_t status)
120 {
121 if (!m_status)
122 {
123 m_status = status;
124 }
125 }
126
128
129
138 virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence) = 0;
139
145 virtual void write(bool value) = 0;
146
152 virtual void write(int8_t value) = 0;
153
159 virtual void write(int16_t value) = 0;
160
166 virtual void write(int32_t value) = 0;
167
173 virtual void write(int64_t value) = 0;
174
180 virtual void write(uint8_t value) = 0;
181
187 virtual void write(uint16_t value) = 0;
188
194 virtual void write(uint32_t value) = 0;
195
201 virtual void write(uint64_t value) = 0;
202
208 virtual void write(float value) = 0;
209
215 virtual void write(double value) = 0;
216
222 virtual void writePtr(uintptr_t value) = 0;
223
230 virtual void writeString(uint32_t length, const char *value) = 0;
231
238 virtual void writeBinary(uint32_t length, const uint8_t *value) = 0;
239
245 virtual void startWriteList(uint32_t length) = 0;
246
252 virtual void startWriteUnion(int32_t discriminator) = 0;
253
259 virtual void writeNullFlag(bool isNull) = 0;
260
268 virtual void writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback) = 0;
269
276 virtual void writeCallback(funPtr callback1, funPtr callback2) = 0;
278
280
281
290 virtual void startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request, uint32_t *sequence) = 0;
291
297 virtual void read(bool *value) = 0;
298
304 virtual void read(int8_t *value) = 0;
305
311 virtual void read(int16_t *value) = 0;
312
318 virtual void read(int32_t *value) = 0;
319
325 virtual void read(int64_t *value) = 0;
326
332 virtual void read(uint8_t *value) = 0;
333
339 virtual void read(uint16_t *value) = 0;
340
346 virtual void read(uint32_t *value) = 0;
347
353 virtual void read(uint64_t *value) = 0;
354
360 virtual void read(float *value) = 0;
361
367 virtual void read(double *value) = 0;
368
374 virtual void readPtr(uintptr_t *value) = 0;
375
382 virtual void readString(uint32_t *length, char **value) = 0;
383
390 virtual void readBinary(uint32_t *length, uint8_t **value) = 0;
391
397 virtual void startReadList(uint32_t *length) = 0;
398
404 virtual void startReadUnion(int32_t *discriminator) = 0;
405
411 virtual void readNullFlag(bool *isNull) = 0;
412
420 virtual void readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback) = 0;
421
428 virtual void readCallback(funPtr callbacks1, funPtr *callback2) = 0;
429
430 protected:
431 MessageBuffer m_buffer;
432 MessageBuffer::Cursor m_cursor;
433 erpc_status_t m_status;
434 };
435
441 class CodecFactory
442 {
443 public:
447 CodecFactory(void) {}
448
452 virtual ~CodecFactory(void) {}
453
459 virtual Codec *create(void) = 0;
460
466 virtual void dispose(Codec *codec) = 0;
467 };
468
469 } // namespace erpc
470
473 #endif // _EMBEDDED_RPC__CODEC_H_
erpc::Codec::startReadMessage
virtual void startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request, uint32_t *sequence)=0
Prototype for read header of message.
erpc::Codec::m_status
erpc_status_t m_status
Definition: erpc_codec.h:433
erpc::Codec::getBuffer
MessageBuffer * getBuffer(void)
Return message buffer used for read and write data.
Definition: erpc_codec.h:78
erpc::message_type_t
message_type_t
Types of messages that can be encoded.
Definition: erpc_codec.h:35
erpc::Codec::read
virtual void read(bool *value)=0
Prototype for read boolean value.
erpc::Codec::writePtr
virtual void writePtr(uintptr_t value)=0
Prototype for write uintptr value.
erpc::Codec::writeCallback
virtual void writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback)=0
Writes an order ID of callback function.
kErpcStatus_Success
No error occurred.
Definition: erpc_common.h:29
erpc::Codec::getStatus
erpc_status_t getStatus(void)
Return current status of eRPC message processing.
Definition: erpc_codec.h:104
erpc_status_t
enum _erpc_status erpc_status_t
Type used for all status and error return values.
Definition: erpc_common.h:87
erpc::Codec::m_cursor
MessageBuffer::Cursor m_cursor
Definition: erpc_codec.h:432
erpc::Codec::writeBinary
virtual void writeBinary(uint32_t length, const uint8_t *value)=0
Prototype for write binary value.
erpc::Codec
Abstract serialization encoder/decoder interface.
Definition: erpc_codec.h:53
erpc::Codec::~Codec
virtual ~Codec(void)
Codec destructor.
Definition: erpc_codec.h:71
erpc::Codec::readBinary
virtual void readBinary(uint32_t *length, uint8_t **value)=0
Prototype for read binary value.
erpc::MessageBuffer::Cursor
Cursor within a MessageBuffer.
Definition: erpc_message_buffer.h:189
erpc::Codec::writeNullFlag
virtual void writeNullFlag(bool isNull)=0
Writes a flag indicating whether the next value is null.
erpc::Codec::readPtr
virtual void readPtr(uintptr_t *value)=0
Prototype for read uintptr value.
erpc::CodecFactory
Abstract interface for codec factory.
Definition: erpc_codec.h:441
erpc::Codec::writeString
virtual void writeString(uint32_t length, const char *value)=0
Prototype for write string value.
erpc_transport.h
erpc::Codec::startReadUnion
virtual void startReadUnion(int32_t *discriminator)=0
Prototype for start read union.
erpc::CodecFactory::~CodecFactory
virtual ~CodecFactory(void)
CodecFactory destructor.
Definition: erpc_codec.h:452
erpc::Codec::readCallback
virtual void readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback)=0
Read an callback function id and return address of callback function.
erpc::Codec::readNullFlag
virtual void readNullFlag(bool *isNull)=0
Reads a flag indicating whether the next value is null.
erpc::Codec::startReadList
virtual void startReadList(uint32_t *length)=0
Prototype for start read list.
erpc::MessageBuffer::Cursor::set
void set(MessageBuffer *buffer)
Set message buffer.
Definition: erpc_message_buffer.cpp:89
erpc::Codec::updateStatus
void updateStatus(erpc_status_t status)
Set current status of eRPC message processing to given value.
Definition: erpc_codec.h:119
erpc::Codec::readString
virtual void readString(uint32_t *length, char **value)=0
Prototype for read string value.
erpc::Codec::startWriteUnion
virtual void startWriteUnion(int32_t discriminator)=0
Prototype for start write union.
erpc::Codec::startWriteList
virtual void startWriteList(uint32_t length)=0
Prototype for start write list.
erpc::MessageBuffer
Represents a memory buffer containing a message.
Definition: erpc_message_buffer.h:37
erpc::Codec::startWriteMessage
virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence)=0
Prototype for write header of message.
erpc
Definition: erpc_arbitrated_client_manager.h:25
erpc::Codec::write
virtual void write(bool value)=0
Prototype for write boolean value.
erpc::Codec::setBuffer
virtual void setBuffer(MessageBuffer &buf)
Prototype for set message buffer used for read and write data.
Definition: erpc_codec.h:85
erpc_message_buffer.h
erpc::CodecFactory::CodecFactory
CodecFactory(void)
Constructor.
Definition: erpc_codec.h:447
erpc::Codec::reset
virtual void reset(void)
Reset the codec to initial state.
Definition: erpc_codec.h:93
erpc::Codec::Codec
Codec(void)
Constructor.
Definition: erpc_codec.h:61
erpc::Codec::m_buffer
MessageBuffer m_buffer
Definition: erpc_codec.h:431
erpc::Codec::isStatusOk
bool isStatusOk(void)
Return bool value representing current status.
Definition: erpc_codec.h:112