eRPC API Reference  Rev. 1.12.0
NXP Semiconductors
erpc_codec.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Freescale Semiconductor, Inc.
3  * Copyright 2016-2021 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.hpp"
16 #include "erpc_transport.hpp"
17 
18 #include <cstdint>
19 #include <cstring>
20 
27 // Classes
30 
31 namespace erpc {
35 enum class message_type_t
36 {
37  kInvocationMessage = 0,
38  kOnewayMessage,
39  kReplyMessage,
40  kNotificationMessage
41 };
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) : m_cursor(), m_status(kErpcStatus_Success) {}
62 
66  virtual ~Codec(void) {}
67 
73  MessageBuffer getBuffer(void) { return m_cursor.getBuffer(); }
74 
75  MessageBuffer &getBufferRef(void) { return m_cursor.getBufferRef(); }
76 
83  virtual void setBuffer(MessageBuffer &buf, uint8_t skip = 0)
84  {
85  m_cursor.setBuffer(buf, skip);
86  m_status = kErpcStatus_Success;
87  }
88 
94  virtual void reset(uint8_t skip = 0)
95  {
96  MessageBuffer buffer = m_cursor.getBuffer();
97  m_cursor.setBuffer(buffer, skip);
98  m_status = kErpcStatus_Success;
99  }
100 
106  erpc_status_t getStatus(void) { return m_status; }
107 
114  bool isStatusOk(void) { return (m_status == kErpcStatus_Success); }
115 
122  {
123  if (isStatusOk())
124  {
125  m_status = status;
126  }
127  }
128 
130 
131 
140  virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence) = 0;
141 
147  virtual void write(bool value) = 0;
148 
154  virtual void write(int8_t value) = 0;
155 
161  virtual void write(int16_t value) = 0;
162 
168  virtual void write(int32_t value) = 0;
169 
175  virtual void write(int64_t value) = 0;
176 
182  virtual void write(uint8_t value) = 0;
183 
189  virtual void write(uint16_t value) = 0;
190 
196  virtual void write(uint32_t value) = 0;
197 
203  virtual void write(uint64_t value) = 0;
204 
210  virtual void write(float value) = 0;
211 
217  virtual void write(double value) = 0;
218 
224  virtual void writePtr(uintptr_t value) = 0;
225 
232  virtual void writeString(uint32_t length, const char *value) = 0;
233 
240  virtual void writeBinary(uint32_t length, const uint8_t *value) = 0;
241 
247  virtual void startWriteList(uint32_t length) = 0;
248 
254  virtual void startWriteUnion(int32_t discriminator) = 0;
255 
261  virtual void writeNullFlag(bool isNull) = 0;
263 
265 
266 
275  virtual void startReadMessage(message_type_t &type, uint32_t &service, uint32_t &request, uint32_t &sequence) = 0;
276 
282  virtual void read(bool &value) = 0;
283 
289  virtual void read(int8_t &value) = 0;
290 
296  virtual void read(int16_t &value) = 0;
297 
303  virtual void read(int32_t &value) = 0;
304 
310  virtual void read(int64_t &value) = 0;
311 
317  virtual void read(uint8_t &value) = 0;
318 
324  virtual void read(uint16_t &value) = 0;
325 
331  virtual void read(uint32_t &value) = 0;
332 
338  virtual void read(uint64_t &value) = 0;
339 
345  virtual void read(float &value) = 0;
346 
352  virtual void read(double &value) = 0;
353 
359  virtual void readPtr(uintptr_t &value) = 0;
360 
367  virtual void readString(uint32_t &length, char **value) = 0;
368 
375  virtual void readBinary(uint32_t &length, uint8_t **value) = 0;
376 
382  virtual void startReadList(uint32_t &length) = 0;
383 
389  virtual void startReadUnion(int32_t &discriminator) = 0;
390 
396  virtual void readNullFlag(bool &isNull) = 0;
397 
398 protected:
401 };
402 
409 {
410 public:
414  CodecFactory(void) {}
415 
419  virtual ~CodecFactory(void) {}
420 
426  virtual Codec *create(void) = 0;
427 
433  virtual void dispose(Codec *codec) = 0;
434 };
435 
436 } // namespace erpc
437 
440 #endif // _EMBEDDED_RPC__CODEC_H_
MessageBuffer getBuffer(void)
Return message buffer used for read and write data.
Definition: erpc_codec.hpp:73
erpc_status_t m_status
Definition: erpc_codec.hpp:400
virtual void setBuffer(MessageBuffer &buf, uint8_t skip=0)
Prototype for set message buffer used for read and write data.
Definition: erpc_codec.hpp:83
message_type_t
Types of messages that can be encoded.
Definition: erpc_codec.hpp:35
virtual void reset(uint8_t skip=0)
Reset the codec to initial state.
Definition: erpc_codec.hpp:94
No error occurred.
Definition: erpc_common.h:27
erpc_status_t getStatus(void)
Return current status of eRPC message processing.
Definition: erpc_codec.hpp:106
enum _erpc_status erpc_status_t
Type used for all status and error return values.
Definition: erpc_common.h:85
Abstract serialization encoder/decoder interface.
Definition: erpc_codec.hpp:53
virtual ~Codec(void)
Codec destructor.
Definition: erpc_codec.hpp:66
Cursor within a MessageBuffer.
Definition: erpc_message_buffer.hpp:187
Abstract interface for codec factory.
Definition: erpc_codec.hpp:408
virtual ~CodecFactory(void)
CodecFactory destructor.
Definition: erpc_codec.hpp:419
void updateStatus(erpc_status_t status)
Set current status of eRPC message processing to given value.
Definition: erpc_codec.hpp:121
Represents a memory buffer containing a message.
Definition: erpc_message_buffer.hpp:37
Definition: erpc_arbitrated_client_manager.hpp:25
CodecFactory(void)
Constructor.
Definition: erpc_codec.hpp:414
Codec(void)
Constructor.
Definition: erpc_codec.hpp:61
bool isStatusOk(void)
Return bool value representing current status.
Definition: erpc_codec.hpp:114
Cursor m_cursor
Definition: erpc_codec.hpp:399