1
+ /*
2
+ This file is part of the ArduinoIoTCloud library.
3
+
4
+ Copyright (c) 2024 Arduino SA
5
+
6
+ This Source Code Form is subject to the terms of the Mozilla Public
7
+ License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+
11
+ #pragma once
12
+ #include < message/Models.h>
13
+ #include < stdint.h>
14
+
15
+ // using encoderFactory=std::function<Encoder*()>;
16
+
17
+ class Encoder {
18
+ public:
19
+ enum Status: uint8_t {
20
+ Complete,
21
+ InProgress,
22
+ Error
23
+ };
24
+
25
+ /* *
26
+ * Encode a message into a buffer in a single shot
27
+ * @param msg: the message that needs to be encoded
28
+ * @param buf: the buffer the message will be encoded into
29
+ * @param len: the length of the provided buffer, value will be updated with the consumed len of the buffer
30
+ * @return SUCCESS: if the message is encoded correctly
31
+ * ERROR: error during the encoding of the message
32
+ */
33
+ virtual Status encode (Message* msg, uint8_t * buf, size_t & len) = 0;
34
+
35
+ /* *
36
+ * sets the message that needs to be encoded, before iterativley encoding it
37
+ * @param Message the message that needs to be encoded
38
+ */
39
+ virtual void setMessage (Message* msg) = 0;
40
+
41
+ /* *
42
+ * after having the Message struct set call this function to encode the message into a buffer
43
+ * this action is performed incrementally into chunks of buffers
44
+ * @param buf: the buffer the message will be encoded into
45
+ * @param len: the length of the provided buffer, value will be updated with the consumed len of the buffer
46
+ * @return SUCCESS: the message is completely encoded
47
+ * IN_PROGRESS: the message is encoded correctly so far, provide another buffer to continue
48
+ * ERROR: error during the encoding of the message
49
+ */
50
+ virtual Status encode (uint8_t * buf, size_t & len) = 0;
51
+ };
0 commit comments