eRPC API Reference  Rev. 1.7.0
NXP Semiconductors
erpc_codec.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted (subject to the limitations in the disclaimer below) provided
10  * that the following conditions are met:
11  *
12  * o Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  *
15  * o Redistributions in binary form must reproduce the above copyright notice, this
16  * list of conditions and the following disclaimer in the documentation and/or
17  * other materials provided with the distribution.
18  *
19  * o Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _EMBEDDED_RPC__CODEC_H_
37 #define _EMBEDDED_RPC__CODEC_H_
38 
39 #include "erpc_common.h"
40 #include "erpc_message_buffer.h"
41 #include "erpc_transport.h"
42 #include <cstring>
43 #include <stdint.h>
44 
51 // Classes
54 
55 namespace erpc {
59 typedef enum _message_type {
60  kInvocationMessage = 0,
61  kOnewayMessage,
62  kReplyMessage,
63  kNotificationMessage
65 
66 typedef void *funPtr; // Pointer to functions
67 typedef funPtr *arrayOfFunPtr; // Pointer to array of functions
68 
76 class Codec
77 {
78 public:
84  Codec(void)
85  : m_buffer()
86  , m_cursor()
88  {
89  }
90 
94  virtual ~Codec(void) {}
95 
101  MessageBuffer *getBuffer(void) { return &m_buffer; }
102 
108  virtual void setBuffer(MessageBuffer &buf)
109  {
110  m_buffer = buf;
113  }
114 
116  virtual void reset(void)
117  {
120  }
121 
122  erpc_status_t getStatus(void) { return m_status; }
123 
124  void updateStatus(erpc_status_t status)
125  {
126  if (!m_status)
127  {
128  m_status = status;
129  }
130  }
131 
133 
134 
143  virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence) = 0;
144 
150  virtual void write(bool value) = 0;
151 
157  virtual void write(int8_t value) = 0;
158 
164  virtual void write(int16_t value) = 0;
165 
171  virtual void write(int32_t value) = 0;
172 
178  virtual void write(int64_t value) = 0;
179 
185  virtual void write(uint8_t value) = 0;
186 
192  virtual void write(uint16_t value) = 0;
193 
199  virtual void write(uint32_t value) = 0;
200 
206  virtual void write(uint64_t value) = 0;
207 
213  virtual void write(float value) = 0;
214 
220  virtual void write(double value) = 0;
221 
227  virtual void writePtr(uintptr_t value) = 0;
228 
235  virtual void writeString(uint32_t length, const char *value) = 0;
236 
243  virtual void writeBinary(uint32_t length, const uint8_t *value) = 0;
244 
250  virtual void startWriteList(uint32_t length) = 0;
251 
257  virtual void startWriteUnion(int32_t discriminator) = 0;
258 
264  virtual void writeNullFlag(bool isNull) = 0;
265 
273  virtual void writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback) = 0;
274 
281  virtual void writeCallback(funPtr callback1, funPtr callback2) = 0;
283 
285 
286 
295  virtual void startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request, uint32_t *sequence) = 0;
296 
302  virtual void read(bool *value) = 0;
303 
309  virtual void read(int8_t *value) = 0;
310 
316  virtual void read(int16_t *value) = 0;
317 
323  virtual void read(int32_t *value) = 0;
324 
330  virtual void read(int64_t *value) = 0;
331 
337  virtual void read(uint8_t *value) = 0;
338 
344  virtual void read(uint16_t *value) = 0;
345 
351  virtual void read(uint32_t *value) = 0;
352 
358  virtual void read(uint64_t *value) = 0;
359 
365  virtual void read(float *value) = 0;
366 
372  virtual void read(double *value) = 0;
373 
379  virtual void readPtr(uintptr_t *value) = 0;
380 
387  virtual void readString(uint32_t *length, char **value) = 0;
388 
395  virtual void readBinary(uint32_t *length, uint8_t **value) = 0;
396 
402  virtual void startReadList(uint32_t *length) = 0;
403 
409  virtual void startReadUnion(int32_t *discriminator) = 0;
410 
416  virtual void readNullFlag(bool *isNull) = 0;
417 
425  virtual void readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback) = 0;
426 
433  virtual void readCallback(funPtr callbacks1, funPtr *callback2) = 0;
434 
435 protected:
439 };
440 
447 {
448 public:
452  CodecFactory(void) {}
453 
457  virtual ~CodecFactory(void) {}
458 
464  virtual Codec *create(void) = 0;
465 
471  virtual void dispose(Codec *codec) = 0;
472 };
473 
474 } // namespace erpc
475 
478 #endif // _EMBEDDED_RPC__CODEC_H_
virtual void startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request, uint32_t *sequence)=0
Prototype for read header of message.
erpc_status_t m_status
Definition: erpc_codec.h:438
int32_t erpc_status_t
Type used for all status and error return values.
Definition: erpc_common.h:112
MessageBuffer * getBuffer(void)
Return message buffer used for read and write data.
Definition: erpc_codec.h:101
message_type_t
Types of messages that can be encoded.
Definition: erpc_codec.h:59
virtual void read(bool *value)=0
Prototype for read boolean value.
virtual void writePtr(uintptr_t value)=0
Prototype for write uintptr value.
virtual void writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback)=0
Writes an order ID of callback function.
No error occurred.
Definition: erpc_common.h:54
MessageBuffer::Cursor m_cursor
Definition: erpc_codec.h:437
virtual void writeBinary(uint32_t length, const uint8_t *value)=0
Prototype for write binary value.
Abstract serialization encoder/decoder interface.
Definition: erpc_codec.h:76
virtual ~Codec(void)
Codec destructor.
Definition: erpc_codec.h:94
virtual void readBinary(uint32_t *length, uint8_t **value)=0
Prototype for read binary value.
Cursor within a MessageBuffer.
Definition: erpc_message_buffer.h:214
virtual void writeNullFlag(bool isNull)=0
Writes a flag indicating whether the next value is null.
virtual void readPtr(uintptr_t *value)=0
Prototype for read uintptr value.
Abstract interface for codec factory.
Definition: erpc_codec.h:446
virtual void writeString(uint32_t length, const char *value)=0
Prototype for write string value.
virtual void startReadUnion(int32_t *discriminator)=0
Prototype for start read union.
virtual ~CodecFactory(void)
CodecFactory destructor.
Definition: erpc_codec.h:457
virtual void readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback)=0
Read an callback function id and return address of callback function.
virtual void readNullFlag(bool *isNull)=0
Reads a flag indicating whether the next value is null.
virtual void startReadList(uint32_t *length)=0
Prototype for start read list.
void set(MessageBuffer *buffer)
Set message buffer.
Definition: erpc_message_buffer.cpp:98
virtual void readString(uint32_t *length, char **value)=0
Prototype for read string value.
virtual void startWriteUnion(int32_t discriminator)=0
Prototype for start write union.
virtual void startWriteList(uint32_t length)=0
Prototype for start write list.
Represents a memory buffer containing a message.
Definition: erpc_message_buffer.h:62
virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence)=0
Prototype for write header of message.
Definition: erpc_arbitrated_client_manager.h:51
virtual void write(bool value)=0
Prototype for write boolean value.
virtual void setBuffer(MessageBuffer &buf)
Prototype for set message buffer used for read and write data.
Definition: erpc_codec.h:108
CodecFactory(void)
Constructor.
Definition: erpc_codec.h:452
virtual void reset(void)
Reset the codec to initial state.
Definition: erpc_codec.h:116
Codec(void)
Constructor.
Definition: erpc_codec.h:84
MessageBuffer m_buffer
Definition: erpc_codec.h:436