This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrtMessage.h
253 lines (226 loc) · 6.32 KB
/
rtMessage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* Copyright [2017] [Comcast, Corp.]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RT_MESSAGING_H__
#define __RT_MESSAGING_H__
#include "rtError.h"
#ifdef __cplusplus
extern "C" {
#endif
struct _rtMessage;
typedef struct _rtMessage* rtMessage;
/**
* Allocate storage and initializes it as new message
* @param pointer to the new message
* @return rtError
**/
rtError
rtMessage_Create(rtMessage* message);
/**
* Copies only the data within the fields of the message
* @param message to be copied
* @param pointer to new copy of the message
* @return rtError
*/
rtError
rtMessage_Clone(rtMessage const message, rtMessage* copy);
/* Allocates storage and initializes it as new message
* @param pointer to the new message
* @param fill the new message with this data
* @return rtError
**/
rtError
rtMessage_FromBytes(rtMessage* message, uint8_t const* buff, int n);
/**
* Extract the data from a message as a byte sequence.
* @param extract the data bytes from this message.
* @param pointer to the byte sequence location
* @param pointer to number of bytes in the message
* @return rtError
**/
rtError
rtMessage_ToByteArray(rtMessage message, uint8_t** buff, uint32_t* n);
/**
* Add string field to the message
* @param message to be modified
* @param name of the field to be added
* @param value of the field to be added
* @return void
**/
void
rtMessage_SetString(rtMessage message, char const* name, char const* value);
/**
* Add string field to array in message
* @param message to be modified
* @param name of the field to be added
* @param value of the field to be added
* @return rtError
**/
rtError
rtMessage_AddString(rtMessage message, char const* name, char const* value);
/**
* Add message field to array in message
* @param message to be modified
* @param name of the field to be added
* @param message to be added
* @return rtError
**/
rtError
rtMessage_AddMessage(rtMessage m, char const* name, rtMessage const item);
/**
* Get length of array from message
* @param message to get array length from
* @param name of the array
* @param fill length of array
* @return rtError
**/
rtError
rtMessage_GetArrayLength(rtMessage const m, char const* name, int32_t* length);
/**
* Get string item from array in message
* @param message to get string item from
* @param name of the string item
* @param index of array
* @param value obtained
* @param length of string item
* @return rtError
**/
rtError
rtMessage_GetStringItem(rtMessage const m, char const* name, int32_t idx, char* value, int len);
/**
* Get message item from array in parent message
* @param message to get message item from
* @param name of message item
* @param index of array
* @param message obtained
* @return rtError
**/
rtError
rtMessage_GetMessageItem(rtMessage const m, char const* name, int32_t idx, rtMessage* msg);
/**
* Add integer field to the message
* @param message to be modified
* @param name of the field to be added
* @param integer value of the field to be added
* @return void
**/
void
rtMessage_SetInt32(rtMessage message, char const* name, int32_t value);
/**
* Add double field to the message
* @param message to be modified
* @param name of the field to be added
* @param double value of the field to be added
* @return void
**/
void
rtMessage_SetDouble(rtMessage message, char const* name, double value);
/**
* Add sub message field to the message
* @param message to be modified
* @param name of the field to be added
* @param new message item to be added
* @return rtError
**/
rtError
rtMessage_SetMessage(rtMessage message, char const* name, rtMessage item);
/**
* Get field value of type string using field name.
* @param message to get field
* @param name of the field
* @param pointer to string value obtained.
* @return rtError
**/
rtError
rtMessage_GetString(rtMessage const m, char const* name, char const** value);
/**
* Get field value of type string using field name.
* @param message to get field
* @param name of the field
* @param pointer to string value obtained.
* @param size of value obtained
* @return rtError
**/
rtError
rtMessage_GetStringValue(rtMessage const m, char const* name, char* value, int n);
/**
* Get field value of type integer using field name.
* @param message to get field
* @param name of the field
* @param pointer to integer value obtained.
* @return rtError
**/
rtError
rtMessage_GetInt32(rtMessage const m, char const* name, int32_t* value);
/**
* Get field value of type double using field name.
* @param message to get field
* @param name of the field
* @param pointer to double value obtained.
* @return rtError
**/
rtError
rtMessage_GetDouble(rtMessage const m, char const* name, double* value);
/**
* Get field value of type message using name
* @param message to get field
* @param name of the field
* @param message obtained
* @return rtError
**/
rtError
rtMessage_GetMessage(rtMessage const m, char const* name, rtMessage* item);
/**
* Format a message as string
* @param message to be formatted
* @param pointer to a string where message is to be stored
* @param string length
* @return rtError
**/
rtError
rtMessage_ToString(rtMessage m, char** s, uint32_t* n);
/**
* Get topic of message to be sent
* @param message to get topic
* @param name of the topic
* @return rtError
**/
rtError
rtMessage_GetSendTopic(rtMessage const m, char* topic);
/**
* Set topic of message to be sent
* @param message to set topic
* @param name of the topic
* @return rtError
**/
rtError
rtMessage_SetSendTopic(rtMessage m, char const* topic);
/**
* Increase reference count of message by 1
* @param message
* @return rtError
**/
rtError
rtMessage_Retain(rtMessage m);
/**
* Decrease reference count of message by 1 and destroy message if count is 0
* @param message
* @return rtError
**/
rtError
rtMessage_Release(rtMessage m);
#ifdef __cplusplus
}
#endif
#endif