slow_blink 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_schema_parser/lexer.c +2793 -839
  3. data/ext/slow_blink/ext_schema_parser/lexer.h +14 -137
  4. data/ext/slow_blink/ext_schema_parser/parser.c +616 -670
  5. data/ext/slow_blink/ext_schema_parser/parser.h +6 -4
  6. data/ext/slow_blink/message/ext_compact_encoder/blink_compact.c +642 -0
  7. data/ext/slow_blink/message/ext_compact_encoder/blink_compact.h +411 -0
  8. data/ext/slow_blink/message/ext_compact_encoder/blink_debug.h +46 -0
  9. data/ext/slow_blink/message/ext_compact_encoder/blink_stream.c +314 -0
  10. data/ext/slow_blink/message/ext_compact_encoder/blink_stream.h +185 -0
  11. data/ext/slow_blink/message/ext_compact_encoder/ext_compact_encoder.c +382 -269
  12. data/lib/slow_blink/definition.rb +18 -53
  13. data/lib/slow_blink/dynamic_group.rb +8 -0
  14. data/lib/slow_blink/enum.rb +101 -0
  15. data/lib/slow_blink/field.rb +63 -33
  16. data/lib/slow_blink/generate_c/model.rb +89 -0
  17. data/lib/slow_blink/group.rb +119 -100
  18. data/lib/slow_blink/message/binary.rb +3 -4
  19. data/lib/slow_blink/message/boolean.rb +3 -4
  20. data/lib/slow_blink/message/date.rb +3 -4
  21. data/lib/slow_blink/message/decimal.rb +3 -5
  22. data/lib/slow_blink/message/{enumeration.rb → enum.rb} +17 -17
  23. data/lib/slow_blink/message/field.rb +77 -27
  24. data/lib/slow_blink/message/fixed.rb +5 -21
  25. data/lib/slow_blink/message/floating_point.rb +3 -4
  26. data/lib/slow_blink/message/group.rb +90 -161
  27. data/lib/slow_blink/message/integer.rb +24 -32
  28. data/lib/slow_blink/message/model.rb +50 -110
  29. data/lib/slow_blink/message/string.rb +3 -4
  30. data/lib/slow_blink/message/time.rb +5 -5
  31. data/lib/slow_blink/message/time_of_day.rb +5 -12
  32. data/lib/slow_blink/ref.rb +22 -71
  33. data/lib/slow_blink/schema.rb +64 -85
  34. data/lib/slow_blink/schema_buffer.rb +1 -4
  35. data/lib/slow_blink/static_group.rb +37 -0
  36. data/lib/slow_blink/string.rb +4 -5
  37. data/lib/slow_blink/sym.rb +8 -28
  38. data/lib/slow_blink/type.rb +10 -19
  39. data/lib/slow_blink/version.rb +1 -1
  40. data/lib/slow_blink.rb +1 -0
  41. data/test/tc_compact_encoder.rb +114 -147
  42. data/test/tc_inputs.rb +2 -4
  43. data/test/tc_model_string.rb +29 -0
  44. data/test/tc_schema_new.rb +212 -0
  45. metadata +17 -26
  46. data/ext/slow_blink/ext_schema_parser/common.h +0 -27
  47. data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.c +0 -258
  48. data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.h +0 -92
  49. data/lib/slow_blink/annotatable.rb +0 -48
  50. data/lib/slow_blink/annotation.rb +0 -47
  51. data/lib/slow_blink/enumeration.rb +0 -90
  52. data/lib/slow_blink/incremental_annotation.rb +0 -151
  53. data/lib/slow_blink/log.rb +0 -51
  54. data/lib/slow_blink/message/sequence.rb +0 -98
  55. data/lib/slow_blink/name_with_id.rb +0 -49
  56. data/lib/slow_blink/namespace.rb +0 -143
  57. data/lib/slow_blink/sequence.rb +0 -57
  58. data/test/tc_field.rb +0 -94
  59. data/test/tc_group.rb +0 -114
  60. data/test/tc_incr_annote.rb +0 -22
  61. data/test/tc_namespace.rb +0 -8
  62. data/test/tc_types.rb +0 -218
@@ -0,0 +1,314 @@
1
+ /* Copyright (c) 2016 Cameron Harper
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ * this software and associated documentation files (the "Software"), to deal in
5
+ * the Software without restriction, including without limitation the rights to
6
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ * the Software, and to permit persons to whom the Software is furnished to do so,
8
+ * subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all
11
+ * copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+ *
20
+ *
21
+ * */
22
+
23
+ /* includes ***********************************************************/
24
+
25
+ #include "blink_stream.h"
26
+ #include "blink_debug.h"
27
+
28
+ #include <string.h>
29
+
30
+ /* static function prototypes *****************************************/
31
+
32
+ static bool adjustOffset(int32_t *pos, int32_t max, int32_t offset);
33
+
34
+ /* functions **********************************************************/
35
+
36
+ bool BLINK_Stream_write(blink_stream_t self, const void *buf, size_t nbyte)
37
+ {
38
+ BLINK_ASSERT(self != NULL)
39
+ BLINK_ASSERT((nbyte == 0U) || (buf != NULL))
40
+
41
+ bool retval = false;
42
+
43
+ if(nbyte <= (size_t)INT32_MAX){
44
+
45
+ switch(self->type){
46
+ case BLINK_STREAM_BUFFER:
47
+
48
+ if(self->value.buffer.out != NULL){
49
+ if((self->value.buffer.max - self->value.buffer.pos) >= (uint32_t)nbyte){
50
+
51
+ (void)memcpy(&self->value.buffer.out[self->value.buffer.pos], buf, nbyte);
52
+ self->value.buffer.pos += (uint32_t)nbyte;
53
+ retval = true;
54
+ }
55
+ }
56
+ break;
57
+
58
+ case BLINK_STREAM_USER:
59
+
60
+ if(self->value.user.fn.write != NULL){
61
+
62
+ retval = self->value.user.fn.write(self->value.user.state, buf, nbyte);
63
+ }
64
+ break;
65
+
66
+ default:
67
+ /* no action */
68
+ break;
69
+ }
70
+ }
71
+
72
+ return retval;
73
+ }
74
+
75
+ bool BLINK_Stream_read(blink_stream_t self, void *buf, size_t nbyte)
76
+ {
77
+ BLINK_ASSERT(self != NULL)
78
+ BLINK_ASSERT((nbyte == 0U) || (buf != NULL))
79
+
80
+ bool retval = false;
81
+
82
+ if(nbyte <= (size_t)INT32_MAX){
83
+
84
+ switch(self->type){
85
+ case BLINK_STREAM_BUFFER:
86
+
87
+ if(self->value.buffer.in != NULL){
88
+ if((self->value.buffer.max - self->value.buffer.pos) >= (uint32_t)nbyte){
89
+
90
+ (void)memcpy(buf, &self->value.buffer.in[self->value.buffer.pos], nbyte);
91
+ self->value.buffer.pos += (uint32_t)nbyte;
92
+ retval = true;
93
+ }
94
+ }
95
+ break;
96
+
97
+ case BLINK_STREAM_USER:
98
+
99
+ if(self->value.user.fn.read != NULL){
100
+
101
+ retval = self->value.user.fn.read(self->value.user.state, buf, nbyte);
102
+ }
103
+ break;
104
+
105
+ default:
106
+ /* no action */
107
+ break;
108
+ }
109
+ }
110
+
111
+ return retval;
112
+ }
113
+
114
+ bool BLINK_Stream_peek(blink_stream_t self, void *buf)
115
+ {
116
+ BLINK_ASSERT(self != NULL)
117
+ BLINK_ASSERT(buf != NULL)
118
+
119
+ bool retval = false;
120
+
121
+ switch(self->type){
122
+ case BLINK_STREAM_BUFFER:
123
+
124
+ if(self->value.buffer.in != NULL){
125
+
126
+ if((self->value.buffer.max - self->value.buffer.pos) >= 1U){
127
+
128
+ *((uint8_t *)buf) = self->value.buffer.in[self->value.buffer.pos];
129
+ retval = true;
130
+ }
131
+ }
132
+ break;
133
+
134
+ case BLINK_STREAM_USER:
135
+
136
+ if(self->value.user.fn.peek != NULL){
137
+
138
+ retval = self->value.user.fn.peek(self->value.user.state, buf);
139
+ }
140
+ break;
141
+
142
+ default:
143
+ /* no action */
144
+ break;
145
+ }
146
+
147
+
148
+ return retval;
149
+ }
150
+
151
+ blink_stream_t BLINK_Stream_initBufferReadOnly(struct blink_stream *self, const void *buf, uint32_t max)
152
+ {
153
+ BLINK_ASSERT(self != NULL)
154
+ BLINK_ASSERT((max == 0) || (buf != NULL))
155
+
156
+ blink_stream_t retval = NULL;
157
+
158
+ if(max <= (size_t)INT32_MAX){
159
+
160
+ (void)memset(self, 0, sizeof(*self));
161
+ self->type = BLINK_STREAM_BUFFER;
162
+ self->value.buffer.in = (uint8_t *)buf;
163
+ self->value.buffer.max = max;
164
+ retval = (blink_stream_t)self;
165
+ }
166
+
167
+ return retval;
168
+ }
169
+
170
+ blink_stream_t BLINK_Stream_initBuffer(struct blink_stream *self, void *buf, uint32_t max)
171
+ {
172
+ BLINK_ASSERT(self != NULL)
173
+ BLINK_ASSERT((max == 0) || (buf != NULL))
174
+
175
+ blink_stream_t retval = NULL;
176
+
177
+ if(max <= (uint32_t)INT32_MAX){
178
+
179
+ (void)memset(self, 0, sizeof(*self));
180
+ self->type = BLINK_STREAM_BUFFER;
181
+ self->value.buffer.out = buf;
182
+ self->value.buffer.in = (uint8_t *)buf;
183
+ self->value.buffer.max = max;
184
+ retval = (blink_stream_t)self;
185
+ }
186
+
187
+ return retval;
188
+ }
189
+
190
+ blink_stream_t BLINK_Stream_initUser(struct blink_stream *self, void *state, struct blink_stream_user fn)
191
+ {
192
+ BLINK_ASSERT(self != NULL)
193
+
194
+ (void)memset(self, 0, sizeof(*self));
195
+ self->type = BLINK_STREAM_USER;
196
+ self->value.user.state = state;
197
+ self->value.user.fn = fn;
198
+ return (blink_stream_t)self;
199
+ }
200
+
201
+ uint32_t BLINK_Stream_tell(blink_stream_t self)
202
+ {
203
+ BLINK_ASSERT(self != NULL)
204
+
205
+ uint32_t retval = 0U;
206
+
207
+ switch(self->type){
208
+ case BLINK_STREAM_BUFFER:
209
+
210
+ retval = (uint32_t)self->value.buffer.pos;
211
+ break;
212
+
213
+ case BLINK_STREAM_USER:
214
+
215
+ if(self->value.user.fn.tell != NULL){
216
+
217
+ retval = self->value.user.fn.tell(self->value.user.state);
218
+ }
219
+ break;
220
+
221
+ default:
222
+ /* no action */
223
+ break;
224
+ }
225
+
226
+ return retval;
227
+ }
228
+
229
+ bool BLINK_Stream_seekSet(blink_stream_t self, uint32_t offset)
230
+ {
231
+ BLINK_ASSERT(self != NULL)
232
+
233
+ bool retval = false;
234
+
235
+ if(offset < (uint32_t)INT32_MAX){
236
+
237
+ switch(self->type){
238
+ case BLINK_STREAM_BUFFER:
239
+ if(self->value.buffer.max >= offset){
240
+
241
+ self->value.buffer.pos = offset;
242
+ retval = true;
243
+ }
244
+ break;
245
+ case BLINK_STREAM_USER:
246
+ if(self->value.user.fn.seekSet != NULL){
247
+
248
+ retval = self->value.user.fn.seekSet(self->value.user.state, offset);
249
+ }
250
+ break;
251
+ default:
252
+ /* no action */
253
+ BLINK_ERROR("this stream cannot seek")
254
+ break;
255
+ }
256
+ }
257
+
258
+ return retval;
259
+ }
260
+
261
+ bool BLINK_Stream_seekCur(blink_stream_t self, int32_t offset)
262
+ {
263
+ BLINK_ASSERT(self != NULL)
264
+
265
+ bool retval = false;
266
+
267
+ switch(self->type){
268
+ case BLINK_STREAM_BUFFER:
269
+ retval = adjustOffset((int32_t *)&self->value.buffer.pos, (int32_t)self->value.buffer.max, offset);
270
+ break;
271
+ case BLINK_STREAM_USER:
272
+ if(self->value.user.fn.seekCur != NULL){
273
+
274
+ retval = self->value.user.fn.seekCur(self->value.user.state, offset);
275
+ }
276
+ break;
277
+ default:
278
+ /* no action */
279
+ BLINK_ERROR("this stream cannot seek")
280
+ break;
281
+ }
282
+
283
+ return retval;
284
+ }
285
+
286
+ /* static functions ***************************************************/
287
+
288
+ static bool adjustOffset(int32_t *pos, int32_t max, int32_t offset)
289
+ {
290
+ bool retval = false;
291
+
292
+ if(offset > 0){
293
+
294
+ if(((*pos + offset) > *pos) && ((*pos + offset) <= max)){
295
+
296
+ *pos += offset;
297
+ retval = true;
298
+ }
299
+ }
300
+ else if(offset > 0){
301
+
302
+ if((*pos - offset) < *pos){
303
+
304
+ *pos -= offset;
305
+ retval = true;
306
+ }
307
+ }
308
+ else{
309
+
310
+ retval = true;
311
+ }
312
+
313
+ return retval;
314
+ }
@@ -0,0 +1,185 @@
1
+ /* Copyright (c) 2016 Cameron Harper
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ * this software and associated documentation files (the "Software"), to deal in
5
+ * the Software without restriction, including without limitation the rights to
6
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ * the Software, and to permit persons to whom the Software is furnished to do so,
8
+ * subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all
11
+ * copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+ *
20
+ *
21
+ * */
22
+
23
+ #ifndef BLINK_STREAM_H
24
+ #define BLINK_STREAM_H
25
+
26
+ /**
27
+ * @defgroup blink_stream blink_stream
28
+ * @ingroup ublink
29
+ *
30
+ * Configurable IO streams.
31
+ *
32
+ * @{
33
+ *
34
+ * */
35
+
36
+ #ifdef __cplusplus
37
+ extern "C" {
38
+ #endif
39
+
40
+ /* includes ***********************************************************/
41
+
42
+ #include <stdint.h>
43
+ #include <stddef.h>
44
+ #include <stdbool.h>
45
+
46
+ /* types **************************************************************/
47
+
48
+ struct blink_stream_user {
49
+ bool (*read)(void *state, void *out, size_t bytesToRead);
50
+ bool (*write)(void *state, const void *in, size_t bytesToWrite);
51
+ uint32_t (*tell)(void *state);
52
+ bool (*peek)(void *state, void *c);
53
+ bool (*seekCur)(void *state, int32_t offset);
54
+ bool (*seekSet)(void *state, uint32_t offset);
55
+ };
56
+
57
+ struct blink_stream {
58
+ enum blink_stream_type {
59
+ BLINK_STREAM_NULL = 0, /**< uninitialised */
60
+ BLINK_STREAM_BUFFER, /**< buffer stream */
61
+ BLINK_STREAM_USER, /**< user stream */
62
+ } type;
63
+ union blink_stream_state {
64
+ struct {
65
+ const uint8_t *in; /**< readable buffer */
66
+ uint8_t *out; /**< writeable buffer */
67
+ uint32_t max; /**< maximum size of buffer */
68
+ uint32_t pos; /**< current position */
69
+ } buffer;
70
+ struct {
71
+ struct blink_stream_user fn;
72
+ void *state;
73
+ } user;
74
+ } value;
75
+ };
76
+
77
+ typedef struct blink_stream * blink_stream_t;
78
+
79
+
80
+ /* function prototypes ************************************************/
81
+
82
+ /** Write to a stream
83
+ *
84
+ * @param[in] self stream
85
+ * @param[in] buf buffer to write
86
+ * @param[in] nbyte number of bytes to write
87
+ *
88
+ * @return true if successful
89
+ *
90
+ * */
91
+ bool BLINK_Stream_write(blink_stream_t self, const void *buf, size_t nbyte);
92
+
93
+ /** Read from a stream
94
+ *
95
+ * @param[in] self stream
96
+ * @param[out] buf buffer of at least `nbyte` bytes
97
+ * @param[in] nbyte number of bytes to read
98
+ *
99
+ * @return true if successful
100
+ *
101
+ * */
102
+ bool BLINK_Stream_read(blink_stream_t self, void *buf, size_t nbyte);
103
+
104
+ /** Read next byte in stream without removing it
105
+ *
106
+ * @param[in] self input stream
107
+ * @param[out] buf single byte buffer
108
+ *
109
+ * @return true if successful
110
+ *
111
+ * */
112
+ bool BLINK_Stream_peek(blink_stream_t self, void *buf);
113
+
114
+ /** Init a read only buffer stream
115
+ *
116
+ * @param[in] self
117
+ * @param[in] buf buffer
118
+ * @param[in] max length of buffer
119
+ *
120
+ * @return stream
121
+ *
122
+ * */
123
+ blink_stream_t BLINK_Stream_initBufferReadOnly(struct blink_stream *self, const void *buf, uint32_t max);
124
+
125
+ /** Init a read/write buffer stream
126
+ *
127
+ * @param[in] self
128
+ * @param[in] buf buffer
129
+ * @param[in] max length of buffer
130
+ *
131
+ * @return stream
132
+ *
133
+ * */
134
+ blink_stream_t BLINK_Stream_initBuffer(struct blink_stream *self, void *buf, uint32_t max);
135
+
136
+ /** Init a user defined stream
137
+ *
138
+ * @param[in] self
139
+ * @param[in] user user state
140
+ * @param[in] fn user defined functions
141
+ *
142
+ * @return stream
143
+ *
144
+ * */
145
+ blink_stream_t BLINK_Stream_initUser(struct blink_stream *self, void *state, struct blink_stream_user fn);
146
+
147
+ /** Get current position
148
+ *
149
+ * @param[in] self
150
+ * @return stream position from origin
151
+ *
152
+ * */
153
+ uint32_t BLINK_Stream_tell(blink_stream_t self);
154
+
155
+ /** Set position to offset
156
+ *
157
+ * i.e. seek relative to start of stream
158
+ *
159
+ * @param[in] self
160
+ * @param[in] offset byte offset from origin
161
+ *
162
+ * @return true if position could be set to offset
163
+ *
164
+ * */
165
+ bool BLINK_Stream_seekSet(blink_stream_t self, uint32_t offset);
166
+
167
+ /** Add offset to current position
168
+ *
169
+ * i.e. seek relative to current stream position
170
+ *
171
+ * @param[in] self
172
+ * @param[in] offset byte offset to add to current position
173
+ *
174
+ * @return true if position could be modified by offset
175
+ *
176
+ * */
177
+ bool BLINK_Stream_seekCur(blink_stream_t self, int32_t offset);
178
+
179
+ #ifdef __cplusplus
180
+ }
181
+ #endif
182
+
183
+ /** @} */
184
+
185
+ #endif