slow_blink 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_compact_encoder/compact_encoder.c +258 -0
  3. data/ext/slow_blink/ext_compact_encoder/compact_encoder.h +92 -0
  4. data/ext/slow_blink/ext_compact_encoder/ext_compact_encoder.c +555 -0
  5. data/ext/slow_blink/ext_compact_encoder/extconf.rb +4 -0
  6. data/ext/slow_blink/ext_schema_parser/lexer.c +59 -59
  7. data/ext/slow_blink/ext_schema_parser/lexer.h +2 -2
  8. data/ext/slow_blink/ext_schema_parser/parser.c +380 -367
  9. data/ext/slow_blink/ext_schema_parser/parser.h +1 -1
  10. data/lib/slow_blink/annotatable.rb +1 -1
  11. data/lib/slow_blink/annotation.rb +5 -5
  12. data/lib/slow_blink/binary.rb +26 -0
  13. data/lib/slow_blink/boolean.rb +26 -0
  14. data/lib/slow_blink/compact_encoder.rb +45 -71
  15. data/lib/slow_blink/date.rb +25 -0
  16. data/lib/slow_blink/decimal.rb +26 -0
  17. data/lib/slow_blink/definition.rb +19 -10
  18. data/lib/slow_blink/enumeration.rb +14 -36
  19. data/lib/slow_blink/error.rb +19 -0
  20. data/lib/slow_blink/field.rb +3 -16
  21. data/lib/slow_blink/fixed.rb +26 -0
  22. data/lib/slow_blink/floating_point.rb +27 -0
  23. data/lib/slow_blink/group.rb +30 -43
  24. data/lib/slow_blink/incremental_annotation.rb +75 -21
  25. data/lib/slow_blink/integer.rb +65 -0
  26. data/lib/slow_blink/message/binary.rb +87 -0
  27. data/lib/slow_blink/message/boolean.rb +68 -0
  28. data/lib/slow_blink/message/date.rb +33 -0
  29. data/lib/slow_blink/message/decimal.rb +25 -0
  30. data/lib/slow_blink/message/enumeration.rb +69 -0
  31. data/lib/slow_blink/message/field.rb +73 -0
  32. data/lib/slow_blink/message/fixed.rb +84 -0
  33. data/lib/slow_blink/message/floating_point.rb +68 -0
  34. data/lib/slow_blink/message/group.rb +260 -0
  35. data/lib/slow_blink/message/integer.rb +217 -0
  36. data/lib/slow_blink/message/model.rb +202 -0
  37. data/lib/slow_blink/message/sequence.rb +85 -0
  38. data/lib/slow_blink/message/string.rb +95 -0
  39. data/lib/slow_blink/message/time.rb +78 -0
  40. data/lib/slow_blink/message/time_of_day.rb +132 -0
  41. data/lib/slow_blink/name_with_id.rb +2 -1
  42. data/lib/slow_blink/namespace.rb +140 -0
  43. data/lib/slow_blink/object.rb +29 -0
  44. data/lib/slow_blink/ref.rb +93 -0
  45. data/lib/slow_blink/schema.rb +94 -68
  46. data/lib/slow_blink/{component_reference.rb → schema_buffer.rb} +11 -22
  47. data/lib/slow_blink/sequence.rb +58 -0
  48. data/lib/slow_blink/string.rb +40 -0
  49. data/lib/slow_blink/sym.rb +4 -0
  50. data/lib/slow_blink/time.rb +30 -0
  51. data/lib/slow_blink/time_of_day.rb +30 -0
  52. data/lib/slow_blink/type.rb +7 -402
  53. data/lib/slow_blink/version.rb +1 -1
  54. data/lib/slow_blink.rb +1 -0
  55. data/rakefile +14 -3
  56. data/test/{integration/capture_stderr.rb → capture_stderr.rb} +0 -0
  57. data/test/tc_compact_encoder.rb +341 -0
  58. data/test/tc_field.rb +53 -0
  59. data/test/tc_group.rb +122 -0
  60. data/test/tc_incr_annote.rb +27 -0
  61. data/test/{integration/tc_inputs.rb → tc_inputs.rb} +7 -11
  62. data/test/tc_model.rb +65 -0
  63. data/test/tc_model_encode.rb +63 -0
  64. data/test/tc_namespace.rb +8 -0
  65. data/test/tc_types.rb +198 -0
  66. metadata +58 -11
  67. data/ext/slow_blink/ext_schema_parser/parser.l +0 -139
  68. data/ext/slow_blink/ext_schema_parser/parser.y +0 -932
  69. data/lib/slow_blink/message.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a066eebd8343e1b39f830aca8e55abe9292fca7
4
- data.tar.gz: 088028f907b7d90cf50bdcfb2229cc959d9b61f2
3
+ metadata.gz: a0f953862ef21dcc727dc64f03f495d0d09a576b
4
+ data.tar.gz: e2353718568db19d5161af4bafb11277cb7f9ec6
5
5
  SHA512:
6
- metadata.gz: c955cf6e36a9850c86ae042164c698a33fe34bf2cdadb8a37e94eea8c74f31912fdf3029ba28a7daf67f20bd8a3e375b41d6a353521c3b56b0189b0007ea662f
7
- data.tar.gz: a9bc364db8c76454869f3a4b26dd5734612e25d5a36b372c8682a4797102a9544fa1d816e4cc407976af88a60f81e7676be6bda0e01f1053a51b818781591c81
6
+ metadata.gz: f7e880f50a5dcc9f8ed3237e3d47b6cd80000158d020d39d0f6bb4e236ec27f94733637caa46d3798dbe84b70c7f23f5f666f0d304d47bac605b208818f95790
7
+ data.tar.gz: 24dff5e19b2c3b619b42ca9d01bbb64c07255f66fb199bbeedd50a2983fdd10de408214c4e616606d860fc5c704704c26058349a28d3aa2f56f6eabfe8110b12
@@ -0,0 +1,258 @@
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 "compact_encoder.h"
26
+
27
+ /* functions **********************************************************/
28
+
29
+ uint8_t BLINK_putNull(uint8_t *out, uint32_t outMax)
30
+ {
31
+ uint8_t retval = 0U;
32
+
33
+ if(outMax > 0){
34
+
35
+ *out = 0xC0U;
36
+ retval = 1U;
37
+ }
38
+
39
+ return retval;
40
+ }
41
+
42
+ uint8_t BLINK_getSizeUnsigned(uint64_t value)
43
+ {
44
+ uint8_t retval;
45
+
46
+ if(value <= 0x7fUL){
47
+ retval = 1U;
48
+ }
49
+ else if(value <= 0x3fffUL){
50
+ retval = 2U;
51
+ }
52
+ else if(value <= 0xffffUL){
53
+ retval = 3U;
54
+ }
55
+ else if(value <= 0xffffffUL){
56
+ retval = 4U;
57
+ }
58
+ else if(value <= 0xffffffffUL){
59
+ retval = 5U;
60
+ }
61
+ else if(value <= 0xffffffffffUL){
62
+ retval = 6U;
63
+ }
64
+ else if(value <= 0xffffffffffffUL){
65
+ retval = 7U;
66
+ }
67
+ else if(value <= 0xffffffffffffffUL){
68
+ retval = 8U;
69
+ }
70
+ else{
71
+ retval = 9U;
72
+ }
73
+
74
+ return retval;
75
+ }
76
+
77
+ uint8_t BLINK_getSizeSigned(int64_t value)
78
+ {
79
+ uint8_t retval;
80
+ uint8_t i;
81
+
82
+ if(value < 0){
83
+
84
+ if(value >= -64){
85
+
86
+ retval = 1U;
87
+ }
88
+ else if(value >= -8192){
89
+
90
+ retval = 2U;
91
+ }
92
+ else{
93
+
94
+ int64_t min = -32768;
95
+ retval = 3U;
96
+
97
+ for(i=0; i < 6; i++){
98
+
99
+ if((min << (i*8)) <= value){
100
+
101
+ break;
102
+ }
103
+ else{
104
+
105
+ retval++;
106
+ }
107
+ }
108
+ }
109
+ }
110
+ else{
111
+
112
+ if(value <= 0x3fL){
113
+ retval = 1U;
114
+ }
115
+ else if(value <= 0x1fffL){
116
+ retval = 2U;
117
+ }
118
+ else if(value <= 0x7fffL){
119
+ retval = 3U;
120
+ }
121
+ else if(value < 0x7fffffffL){
122
+ retval = 4U;
123
+ }
124
+ else if(value < 0x7fffffffffL){
125
+ retval = 5U;
126
+ }
127
+ else if(value < 0x7fffffffffffL){
128
+ retval = 6U;
129
+ }
130
+ else if(value < 0x7fffffffffffffL){
131
+ retval = 7U;
132
+ }
133
+ else if(value < 0x7fffffffffffffffL){
134
+ retval = 8U;
135
+ }
136
+ else{
137
+ retval = 9U;
138
+ }
139
+ }
140
+
141
+ return retval;
142
+ }
143
+
144
+ uint8_t BLINK_putVLC(uint64_t in, bool isSigned, uint8_t *out, uint32_t outMax)
145
+ {
146
+ uint8_t bytes = (isSigned) ? BLINK_getSizeSigned((int64_t)in) : BLINK_getSizeUnsigned(in);
147
+ uint8_t retval = 0U;
148
+ uint8_t i;
149
+
150
+ if(outMax >= bytes){
151
+
152
+ if(bytes == 1){
153
+
154
+ *out = (uint8_t)(in & 0x7f);
155
+ }
156
+ else if(bytes == 2){
157
+
158
+ out[0] = 0x80 | (uint8_t)(in & 0x3f);
159
+ out[1] = (uint8_t)(in >> 6);
160
+ }
161
+ else{
162
+
163
+ out[0] = 0xC0U | bytes-1;
164
+ for(i=1; i < bytes; i++){
165
+
166
+ out[i] = (uint8_t)(in >> ((i-1)*8));
167
+ }
168
+ }
169
+ retval = bytes;
170
+ }
171
+
172
+ return retval;
173
+ }
174
+
175
+ uint8_t BLINK_getVLC(const uint8_t *in, uint32_t inLen, bool isSigned, uint64_t *out, bool *isNull)
176
+ {
177
+ uint8_t retval = 0U;
178
+ uint8_t bytes;
179
+ uint8_t i;
180
+
181
+ *isNull = false;
182
+
183
+ if(inLen > 0){
184
+
185
+ if(*in < 0xc0){
186
+
187
+ if(*in < 0x80){
188
+
189
+ if(isSigned && ((*in & 0x40) == 0x40)){
190
+
191
+ *out = 0xffffffffffffffc0;
192
+ }
193
+ else{
194
+
195
+ *out = 0x0;
196
+ }
197
+ *out |= (uint64_t)(*in & 0x7f);
198
+ retval = 1U;
199
+ }
200
+ else{
201
+
202
+ if(inLen >= 2){
203
+
204
+ if(isSigned && ((in[1] & 0x80) == 0x80)){
205
+
206
+ *out = 0xffffffffffffff00;
207
+ }
208
+ else{
209
+
210
+ *out = 0x0;
211
+ }
212
+ *out |= (uint64_t)in[1];
213
+ *out <<= 6;
214
+ *out |= (uint64_t)(in[0] & 0x3fU);
215
+ retval = 2U;
216
+ }
217
+ }
218
+ }
219
+ else if(*in == 0xc0){
220
+
221
+ *isNull = true;
222
+ retval = 1U;
223
+ }
224
+ else{
225
+
226
+ bytes = *in & 0x3fU;
227
+
228
+ if(inLen >= (1U + bytes)){
229
+
230
+ if(bytes <= 8U){
231
+
232
+ if(isSigned && ((in[bytes] & 0x80U) == 0x80U)){
233
+
234
+ *out = 0xffffffffffff00U | in[bytes];
235
+ }
236
+ else{
237
+
238
+ *out = in[bytes];
239
+ }
240
+
241
+ for(i=bytes-1; i != 0U; i--){
242
+
243
+ *out <<= 8;
244
+ *out |= in[i];
245
+ }
246
+
247
+ retval = bytes + 1U;
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ return retval;
254
+ }
255
+
256
+
257
+
258
+
@@ -0,0 +1,92 @@
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 COMPACT_ENCODER_H
24
+ #define COMPACT_ENCODER_H
25
+
26
+
27
+ /* includes ***********************************************************/
28
+
29
+ #include <stdint.h>
30
+ #include <stdbool.h>
31
+
32
+ /* functions **********************************************************/
33
+
34
+ /**
35
+ * Encode a VLC null
36
+ *
37
+ * @param[out] out output buffer
38
+ * @param[in] outMax maximum byte length of `out`
39
+ *
40
+ * @return bytes successfully written to `out`
41
+ *
42
+ * */
43
+ uint8_t BLINK_putNull(uint8_t *out, uint32_t outMax);
44
+
45
+ /**
46
+ * Return minimum number of bytes required to VLC encode unsigned integer value
47
+ *
48
+ * @param[in] value value to encode as VLC
49
+ *
50
+ * @return minimum bytes to VLC encode value
51
+ *
52
+ * */
53
+ uint8_t BLINK_getSizeUnsigned(uint64_t value);
54
+
55
+ /**
56
+ * Return minimum number of bytes required to VLC encode signed integer value
57
+ *
58
+ * @param[in] value value to encode as VLC
59
+ *
60
+ * @return minimum bytes to VLC encode value
61
+ *
62
+ * */
63
+ uint8_t BLINK_getSizeSigned(int64_t value);
64
+
65
+ /**
66
+ * Encode signed/unsigned integer as VLC
67
+ *
68
+ * @param[in] value signed or unsigned value to encode
69
+ * @param[in] isSigned `true` to indicated `value` is a signed integer
70
+ * @param[out] out output buffer
71
+ * @param[in] outMax maximum byte lenght of `out`
72
+ *
73
+ * @return bytes successfully written to `out`
74
+ *
75
+ * */
76
+ uint8_t BLINK_putVLC(uint64_t in, bool isSigned, uint8_t *out, uint32_t outMax);
77
+
78
+ /**
79
+ * Decode signed/unsigned integer as VLC
80
+ *
81
+ * @param[in] in input buffer
82
+ * @param[in] inLen byte length of `in`
83
+ * @param[in] isSigned integer shall be intepreted as 2s complement
84
+ * @param[out] out output integer buffer
85
+ * @param[out] isNull set `true` if `in` decodes to NULL
86
+ *
87
+ * @return bytes successfully read from `in`
88
+ *
89
+ * */
90
+ uint8_t BLINK_getVLC(const uint8_t *in, uint32_t inLen, bool isSigned, uint64_t *out, bool *isNull);
91
+
92
+ #endif