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.
- checksums.yaml +4 -4
- data/ext/slow_blink/ext_schema_parser/lexer.c +2793 -839
- data/ext/slow_blink/ext_schema_parser/lexer.h +14 -137
- data/ext/slow_blink/ext_schema_parser/parser.c +616 -670
- data/ext/slow_blink/ext_schema_parser/parser.h +6 -4
- data/ext/slow_blink/message/ext_compact_encoder/blink_compact.c +642 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_compact.h +411 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_debug.h +46 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_stream.c +314 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_stream.h +185 -0
- data/ext/slow_blink/message/ext_compact_encoder/ext_compact_encoder.c +382 -269
- data/lib/slow_blink/definition.rb +18 -53
- data/lib/slow_blink/dynamic_group.rb +8 -0
- data/lib/slow_blink/enum.rb +101 -0
- data/lib/slow_blink/field.rb +63 -33
- data/lib/slow_blink/generate_c/model.rb +89 -0
- data/lib/slow_blink/group.rb +119 -100
- data/lib/slow_blink/message/binary.rb +3 -4
- data/lib/slow_blink/message/boolean.rb +3 -4
- data/lib/slow_blink/message/date.rb +3 -4
- data/lib/slow_blink/message/decimal.rb +3 -5
- data/lib/slow_blink/message/{enumeration.rb → enum.rb} +17 -17
- data/lib/slow_blink/message/field.rb +77 -27
- data/lib/slow_blink/message/fixed.rb +5 -21
- data/lib/slow_blink/message/floating_point.rb +3 -4
- data/lib/slow_blink/message/group.rb +90 -161
- data/lib/slow_blink/message/integer.rb +24 -32
- data/lib/slow_blink/message/model.rb +50 -110
- data/lib/slow_blink/message/string.rb +3 -4
- data/lib/slow_blink/message/time.rb +5 -5
- data/lib/slow_blink/message/time_of_day.rb +5 -12
- data/lib/slow_blink/ref.rb +22 -71
- data/lib/slow_blink/schema.rb +64 -85
- data/lib/slow_blink/schema_buffer.rb +1 -4
- data/lib/slow_blink/static_group.rb +37 -0
- data/lib/slow_blink/string.rb +4 -5
- data/lib/slow_blink/sym.rb +8 -28
- data/lib/slow_blink/type.rb +10 -19
- data/lib/slow_blink/version.rb +1 -1
- data/lib/slow_blink.rb +1 -0
- data/test/tc_compact_encoder.rb +114 -147
- data/test/tc_inputs.rb +2 -4
- data/test/tc_model_string.rb +29 -0
- data/test/tc_schema_new.rb +212 -0
- metadata +17 -26
- data/ext/slow_blink/ext_schema_parser/common.h +0 -27
- data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.c +0 -258
- data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.h +0 -92
- data/lib/slow_blink/annotatable.rb +0 -48
- data/lib/slow_blink/annotation.rb +0 -47
- data/lib/slow_blink/enumeration.rb +0 -90
- data/lib/slow_blink/incremental_annotation.rb +0 -151
- data/lib/slow_blink/log.rb +0 -51
- data/lib/slow_blink/message/sequence.rb +0 -98
- data/lib/slow_blink/name_with_id.rb +0 -49
- data/lib/slow_blink/namespace.rb +0 -143
- data/lib/slow_blink/sequence.rb +0 -57
- data/test/tc_field.rb +0 -94
- data/test/tc_group.rb +0 -114
- data/test/tc_incr_annote.rb +0 -22
- data/test/tc_namespace.rb +0 -8
- data/test/tc_types.rb +0 -218
| @@ -1,8 +1,8 @@ | |
| 1 | 
            -
            /* A Bison parser, made by GNU Bison 3.0. | 
| 1 | 
            +
            /* A Bison parser, made by GNU Bison 3.0.4.  */
         | 
| 2 2 |  | 
| 3 3 | 
             
            /* Skeleton interface for Bison GLR parsers in C
         | 
| 4 4 |  | 
| 5 | 
            -
               Copyright (C) 2002- | 
| 5 | 
            +
               Copyright (C) 2002-2015 Free Software Foundation, Inc.
         | 
| 6 6 |  | 
| 7 7 | 
             
               This program is free software: you can redistribute it and/or modify
         | 
| 8 8 | 
             
               it under the terms of the GNU General Public License as published by
         | 
| @@ -34,7 +34,7 @@ | |
| 34 34 | 
             
            # define YY_YY_EXT_SLOW_BLINK_EXT_SCHEMA_PARSER_PARSER_H_INCLUDED
         | 
| 35 35 | 
             
            /* Debug traces.  */
         | 
| 36 36 | 
             
            #ifndef YYDEBUG
         | 
| 37 | 
            -
            # define YYDEBUG  | 
| 37 | 
            +
            # define YYDEBUG 0
         | 
| 38 38 | 
             
            #endif
         | 
| 39 39 | 
             
            #if YYDEBUG
         | 
| 40 40 | 
             
            extern int yydebug;
         | 
| @@ -45,6 +45,7 @@ extern int yydebug; | |
| 45 45 | 
             
            # define YYTOKENTYPE
         | 
| 46 46 | 
             
              enum yytokentype
         | 
| 47 47 | 
             
              {
         | 
| 48 | 
            +
                TOK_EOF = 0,
         | 
| 48 49 | 
             
                TOK_I8 = 258,
         | 
| 49 50 | 
             
                TOK_I16 = 259,
         | 
| 50 51 | 
             
                TOK_I32 = 260,
         | 
| @@ -77,7 +78,8 @@ extern int yydebug; | |
| 77 78 | 
             
                TOK_NC_NAME = 287,
         | 
| 78 79 | 
             
                TOK_ESCAPED_NC_NAME = 288,
         | 
| 79 80 | 
             
                TOK_C_NAME = 289,
         | 
| 80 | 
            -
                TOK_LITERAL = 290
         | 
| 81 | 
            +
                TOK_LITERAL = 290,
         | 
| 82 | 
            +
                TOK_UNKNOWN = 291
         | 
| 81 83 | 
             
              };
         | 
| 82 84 | 
             
            #endif
         | 
| 83 85 |  | 
| @@ -0,0 +1,642 @@ | |
| 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_compact.h"
         | 
| 26 | 
            +
            #include "blink_debug.h"
         | 
| 27 | 
            +
            #include "blink_stream.h"
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            #include <string.h>
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            /* static function prototypes *****************************************/
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            static bool encodeVLC(uint64_t in, bool isSigned, blink_stream_t out);
         | 
| 34 | 
            +
            static bool decodeVLC(blink_stream_t in, bool isSigned, uint64_t *out, bool *isNull);
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            /* functions **********************************************************/
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            bool BLINK_Compact_encodeNull(blink_stream_t out)
         | 
| 39 | 
            +
            {
         | 
| 40 | 
            +
                uint8_t in = 0xc0U;
         | 
| 41 | 
            +
                return BLINK_Stream_write(out, &in, sizeof(in));
         | 
| 42 | 
            +
            }
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            bool BLINK_Compact_encodePresent(blink_stream_t out)
         | 
| 45 | 
            +
            {
         | 
| 46 | 
            +
                uint8_t in = 0x01U;
         | 
| 47 | 
            +
                return BLINK_Stream_write(out, &in, sizeof(in));
         | 
| 48 | 
            +
            }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            bool BLINK_Compact_decodeBool(blink_stream_t in, bool *out, bool *isNull)
         | 
| 51 | 
            +
            {
         | 
| 52 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                uint64_t number;
         | 
| 55 | 
            +
                bool retval = false;
         | 
| 56 | 
            +
                
         | 
| 57 | 
            +
                if(decodeVLC(in, false, &number, isNull)){
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    if(*isNull){
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                        retval = true;
         | 
| 62 | 
            +
                    }
         | 
| 63 | 
            +
                    else{        
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                        if(number <= (uint64_t)UINT8_MAX){
         | 
| 66 | 
            +
                            
         | 
| 67 | 
            +
                            if((number == 0x00U) || (number == 0x01U)){
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                                *out = (number == 0x00U) ? false : true;
         | 
| 70 | 
            +
                                retval = true;
         | 
| 71 | 
            +
                            }
         | 
| 72 | 
            +
                            else{
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                                BLINK_ERROR("W11: boolean must be 0x00 or 0x01")              
         | 
| 75 | 
            +
                            }
         | 
| 76 | 
            +
                        }
         | 
| 77 | 
            +
                        else{
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                            BLINK_ERROR("W3: out of range")
         | 
| 80 | 
            +
                        }
         | 
| 81 | 
            +
                    }
         | 
| 82 | 
            +
                }
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                return retval;
         | 
| 85 | 
            +
            }
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            bool BLINK_Compact_decodeU8(blink_stream_t in, uint8_t *out, bool *isNull)
         | 
| 88 | 
            +
            {
         | 
| 89 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                uint64_t number;
         | 
| 92 | 
            +
                bool retval = false;
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                if(decodeVLC(in, false, &number, isNull)){
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                    if(*isNull){
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                        retval = true;
         | 
| 99 | 
            +
                    }
         | 
| 100 | 
            +
                    else{
         | 
| 101 | 
            +
                    
         | 
| 102 | 
            +
                        if(number <= (uint64_t)UINT8_MAX){
         | 
| 103 | 
            +
                            
         | 
| 104 | 
            +
                            *out = (uint8_t)number;
         | 
| 105 | 
            +
                            retval = true;
         | 
| 106 | 
            +
                        }
         | 
| 107 | 
            +
                        else{
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                            BLINK_ERROR("W3: out of range")
         | 
| 110 | 
            +
                        }
         | 
| 111 | 
            +
                    }
         | 
| 112 | 
            +
                }
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                return retval;
         | 
| 115 | 
            +
            }
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            bool BLINK_Compact_decodeU16(blink_stream_t in, uint16_t *out, bool *isNull)
         | 
| 118 | 
            +
            {
         | 
| 119 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                uint64_t number;
         | 
| 122 | 
            +
                bool retval = false;
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                if(decodeVLC(in, false, &number, isNull)){
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                    if(*isNull){
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                        retval = true;
         | 
| 129 | 
            +
                    }
         | 
| 130 | 
            +
                    else{
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                        if(number <= (uint64_t)UINT16_MAX){
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                            *out = (uint16_t)number;
         | 
| 135 | 
            +
                            retval = true;
         | 
| 136 | 
            +
                        }
         | 
| 137 | 
            +
                        else{
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                            BLINK_ERROR("W3: out of range")
         | 
| 140 | 
            +
                        }
         | 
| 141 | 
            +
                    }
         | 
| 142 | 
            +
                }
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                return retval;
         | 
| 145 | 
            +
            }
         | 
| 146 | 
            +
             | 
| 147 | 
            +
            bool BLINK_Compact_decodeU32(blink_stream_t in, uint32_t *out, bool *isNull)
         | 
| 148 | 
            +
            {
         | 
| 149 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                uint64_t number;
         | 
| 152 | 
            +
                bool retval = false;
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                if(decodeVLC(in, false, &number, isNull)){
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                    if(*isNull){
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                        retval = true;
         | 
| 159 | 
            +
                    }
         | 
| 160 | 
            +
                    else{
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                        if(number <= UINT32_MAX){
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                            *out = (uint32_t)number;
         | 
| 165 | 
            +
                            retval = true;
         | 
| 166 | 
            +
                        }
         | 
| 167 | 
            +
                        else{
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                            BLINK_ERROR("W3: out of range")
         | 
| 170 | 
            +
                        }
         | 
| 171 | 
            +
                    }
         | 
| 172 | 
            +
                }
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                return retval;
         | 
| 175 | 
            +
            }
         | 
| 176 | 
            +
             | 
| 177 | 
            +
            bool BLINK_Compact_decodeU64(blink_stream_t in, uint64_t *out, bool *isNull)
         | 
| 178 | 
            +
            {
         | 
| 179 | 
            +
                return decodeVLC(in, false, out, isNull);
         | 
| 180 | 
            +
            }
         | 
| 181 | 
            +
             | 
| 182 | 
            +
            bool BLINK_Compact_decodeI8(blink_stream_t in, int8_t *out, bool *isNull)
         | 
| 183 | 
            +
            {
         | 
| 184 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 185 | 
            +
                
         | 
| 186 | 
            +
                int64_t number;
         | 
| 187 | 
            +
                bool retval = false;
         | 
| 188 | 
            +
             | 
| 189 | 
            +
                if(decodeVLC(in, true, (uint64_t *)&number, isNull)){
         | 
| 190 | 
            +
             | 
| 191 | 
            +
                    if(*isNull){
         | 
| 192 | 
            +
             | 
| 193 | 
            +
                        retval = true;
         | 
| 194 | 
            +
                    }
         | 
| 195 | 
            +
                    else{
         | 
| 196 | 
            +
             | 
| 197 | 
            +
                        if((number <= INT8_MAX) && (number >= INT8_MIN)){
         | 
| 198 | 
            +
                            
         | 
| 199 | 
            +
                            *out = (int8_t)number;
         | 
| 200 | 
            +
                            retval = true;
         | 
| 201 | 
            +
                        }
         | 
| 202 | 
            +
                        else{
         | 
| 203 | 
            +
             | 
| 204 | 
            +
                            BLINK_ERROR("W3: out of range")
         | 
| 205 | 
            +
                        }
         | 
| 206 | 
            +
                    }
         | 
| 207 | 
            +
                }
         | 
| 208 | 
            +
             | 
| 209 | 
            +
                return retval;
         | 
| 210 | 
            +
            }
         | 
| 211 | 
            +
             | 
| 212 | 
            +
            bool BLINK_Compact_decodeI16(blink_stream_t in, int16_t *out, bool *isNull)
         | 
| 213 | 
            +
            {
         | 
| 214 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 215 | 
            +
                
         | 
| 216 | 
            +
                int64_t number;
         | 
| 217 | 
            +
                bool retval = false;
         | 
| 218 | 
            +
             | 
| 219 | 
            +
                if(decodeVLC(in, true, (uint64_t *)&number, isNull)){
         | 
| 220 | 
            +
             | 
| 221 | 
            +
                    if(*isNull){
         | 
| 222 | 
            +
             | 
| 223 | 
            +
                        retval = true;
         | 
| 224 | 
            +
                    }
         | 
| 225 | 
            +
                    else{
         | 
| 226 | 
            +
             | 
| 227 | 
            +
                        if((number <= INT16_MAX) && (number >= INT16_MIN)){
         | 
| 228 | 
            +
             | 
| 229 | 
            +
                            *out = (int16_t)number;
         | 
| 230 | 
            +
                            retval = true;
         | 
| 231 | 
            +
                        }
         | 
| 232 | 
            +
                        else{
         | 
| 233 | 
            +
             | 
| 234 | 
            +
                            BLINK_ERROR("W3: out of range")
         | 
| 235 | 
            +
                        }
         | 
| 236 | 
            +
                    }
         | 
| 237 | 
            +
                }
         | 
| 238 | 
            +
             | 
| 239 | 
            +
                return retval;
         | 
| 240 | 
            +
            }
         | 
| 241 | 
            +
             | 
| 242 | 
            +
            bool BLINK_Compact_decodeI32(blink_stream_t in, int32_t *out, bool *isNull)
         | 
| 243 | 
            +
            {
         | 
| 244 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 245 | 
            +
                
         | 
| 246 | 
            +
                int64_t number;
         | 
| 247 | 
            +
                bool retval = false;
         | 
| 248 | 
            +
             | 
| 249 | 
            +
                if(decodeVLC(in, true, (uint64_t *)&number, isNull)){
         | 
| 250 | 
            +
             | 
| 251 | 
            +
                    if(*isNull){
         | 
| 252 | 
            +
             | 
| 253 | 
            +
                        retval = true;
         | 
| 254 | 
            +
                    }
         | 
| 255 | 
            +
                    else{
         | 
| 256 | 
            +
             | 
| 257 | 
            +
                        if((number <= INT32_MAX) && (number >= INT32_MIN)){
         | 
| 258 | 
            +
             | 
| 259 | 
            +
                            *out = (int32_t)number;
         | 
| 260 | 
            +
                            retval = true;
         | 
| 261 | 
            +
                        }
         | 
| 262 | 
            +
                        else{
         | 
| 263 | 
            +
             | 
| 264 | 
            +
                            BLINK_ERROR("W3: out of range")
         | 
| 265 | 
            +
                        }
         | 
| 266 | 
            +
                    }
         | 
| 267 | 
            +
                }
         | 
| 268 | 
            +
             | 
| 269 | 
            +
                return retval;
         | 
| 270 | 
            +
            }
         | 
| 271 | 
            +
             | 
| 272 | 
            +
            bool BLINK_Compact_decodeI64(blink_stream_t in, int64_t *out, bool *isNull)
         | 
| 273 | 
            +
            {
         | 
| 274 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 275 | 
            +
                
         | 
| 276 | 
            +
                return decodeVLC(in, true, (uint64_t *)out, isNull);
         | 
| 277 | 
            +
            }
         | 
| 278 | 
            +
             | 
| 279 | 
            +
            bool BLINK_Compact_decodeDecimal(blink_stream_t in, int64_t *mantissa, int8_t *exponent, bool *isNull)
         | 
| 280 | 
            +
            {
         | 
| 281 | 
            +
                BLINK_ASSERT(mantissa != NULL)
         | 
| 282 | 
            +
                BLINK_ASSERT(exponent != NULL)
         | 
| 283 | 
            +
             | 
| 284 | 
            +
                bool retval = false;
         | 
| 285 | 
            +
                
         | 
| 286 | 
            +
                if(BLINK_Compact_decodeI8(in, exponent, isNull)){
         | 
| 287 | 
            +
             | 
| 288 | 
            +
                    if(*isNull){
         | 
| 289 | 
            +
             | 
| 290 | 
            +
                        retval = true;
         | 
| 291 | 
            +
                    }
         | 
| 292 | 
            +
                    else{
         | 
| 293 | 
            +
             | 
| 294 | 
            +
                        if(BLINK_Compact_decodeI64(in, mantissa, isNull)){
         | 
| 295 | 
            +
             | 
| 296 | 
            +
                            if(*isNull){
         | 
| 297 | 
            +
             | 
| 298 | 
            +
                                BLINK_ERROR("mantissa cannot be NULL")
         | 
| 299 | 
            +
                            }
         | 
| 300 | 
            +
                            else{
         | 
| 301 | 
            +
             | 
| 302 | 
            +
                                retval = true;
         | 
| 303 | 
            +
                            }        
         | 
| 304 | 
            +
                        }
         | 
| 305 | 
            +
                    }
         | 
| 306 | 
            +
                }
         | 
| 307 | 
            +
             | 
| 308 | 
            +
                return retval;
         | 
| 309 | 
            +
            }
         | 
| 310 | 
            +
             | 
| 311 | 
            +
            bool BLINK_Compact_decodeF64(blink_stream_t in, double *out, bool *isNull)
         | 
| 312 | 
            +
            {
         | 
| 313 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 314 | 
            +
             | 
| 315 | 
            +
                bool retval = false;
         | 
| 316 | 
            +
                uint64_t result;
         | 
| 317 | 
            +
             | 
| 318 | 
            +
                if(BLINK_Compact_decodeU64(in, &result, isNull)){
         | 
| 319 | 
            +
             | 
| 320 | 
            +
                    retval = true;
         | 
| 321 | 
            +
             | 
| 322 | 
            +
                    if(*isNull == false){
         | 
| 323 | 
            +
             | 
| 324 | 
            +
                        *out = (double)result;        
         | 
| 325 | 
            +
                    }
         | 
| 326 | 
            +
                }
         | 
| 327 | 
            +
             | 
| 328 | 
            +
                return retval;
         | 
| 329 | 
            +
            }
         | 
| 330 | 
            +
             | 
| 331 | 
            +
            bool BLINK_Compact_decodePresent(blink_stream_t in, bool *out)
         | 
| 332 | 
            +
            {
         | 
| 333 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 334 | 
            +
             | 
| 335 | 
            +
                bool isNull;
         | 
| 336 | 
            +
                uint64_t value;
         | 
| 337 | 
            +
                bool retval = false;
         | 
| 338 | 
            +
                
         | 
| 339 | 
            +
                if(decodeVLC(in, false, &value, &isNull)){
         | 
| 340 | 
            +
             | 
| 341 | 
            +
                    if(isNull || (value == 0x01U)){
         | 
| 342 | 
            +
             | 
| 343 | 
            +
                        *out = (isNull) ? false : true;
         | 
| 344 | 
            +
                        retval = true;
         | 
| 345 | 
            +
                    }
         | 
| 346 | 
            +
                    else{
         | 
| 347 | 
            +
             | 
| 348 | 
            +
                        BLINK_ERROR("W9: presence flag must be 0xc0 or 0x01")
         | 
| 349 | 
            +
                    }
         | 
| 350 | 
            +
                }
         | 
| 351 | 
            +
             | 
| 352 | 
            +
                return retval;
         | 
| 353 | 
            +
            }
         | 
| 354 | 
            +
             | 
| 355 | 
            +
            bool BLINK_Compact_encodeBool(bool in, blink_stream_t out)
         | 
| 356 | 
            +
            {
         | 
| 357 | 
            +
                return encodeVLC((in ? 0x01U : 0x00U), false, out);
         | 
| 358 | 
            +
            }
         | 
| 359 | 
            +
             | 
| 360 | 
            +
            bool BLINK_Compact_encodeU8(uint8_t in, blink_stream_t out)
         | 
| 361 | 
            +
            {
         | 
| 362 | 
            +
                return encodeVLC((uint64_t)in, false, out);
         | 
| 363 | 
            +
            }
         | 
| 364 | 
            +
             | 
| 365 | 
            +
            bool BLINK_Compact_encodeU16(uint16_t in, blink_stream_t out)
         | 
| 366 | 
            +
            {
         | 
| 367 | 
            +
                return encodeVLC((uint64_t)in, false, out);
         | 
| 368 | 
            +
            }
         | 
| 369 | 
            +
             | 
| 370 | 
            +
            bool BLINK_Compact_encodeU32(uint32_t in, blink_stream_t out)
         | 
| 371 | 
            +
            {
         | 
| 372 | 
            +
                return encodeVLC((uint64_t)in, false, out);
         | 
| 373 | 
            +
            }
         | 
| 374 | 
            +
             | 
| 375 | 
            +
            bool BLINK_Compact_encodeU64(uint64_t in, blink_stream_t out)
         | 
| 376 | 
            +
            {
         | 
| 377 | 
            +
                return encodeVLC(in, false, out);
         | 
| 378 | 
            +
            }
         | 
| 379 | 
            +
             | 
| 380 | 
            +
            bool BLINK_Compact_encodeI8(int8_t in, blink_stream_t out)
         | 
| 381 | 
            +
            {
         | 
| 382 | 
            +
                return encodeVLC((uint64_t)in, true, out);
         | 
| 383 | 
            +
            }
         | 
| 384 | 
            +
             | 
| 385 | 
            +
            bool BLINK_Compact_encodeI16(int16_t in, blink_stream_t out)
         | 
| 386 | 
            +
            {
         | 
| 387 | 
            +
                return encodeVLC((uint64_t)in, true, out);
         | 
| 388 | 
            +
            }
         | 
| 389 | 
            +
             | 
| 390 | 
            +
            bool BLINK_Compact_encodeI32(int32_t in, blink_stream_t out)
         | 
| 391 | 
            +
            {
         | 
| 392 | 
            +
                return encodeVLC((uint64_t)in, true, out);
         | 
| 393 | 
            +
            }
         | 
| 394 | 
            +
             | 
| 395 | 
            +
            bool BLINK_Compact_encodeI64(int64_t in, blink_stream_t out)
         | 
| 396 | 
            +
            {
         | 
| 397 | 
            +
                return encodeVLC((uint64_t)in, true, out);
         | 
| 398 | 
            +
            }
         | 
| 399 | 
            +
             | 
| 400 | 
            +
            bool BLINK_Compact_encodeF64(double in, blink_stream_t out)
         | 
| 401 | 
            +
            {
         | 
| 402 | 
            +
                uint64_t *value = (uint64_t *)∈  /*lint !e740 !e9087 double cast to uint64_t */
         | 
| 403 | 
            +
                
         | 
| 404 | 
            +
                return encodeVLC(*value, false, out);
         | 
| 405 | 
            +
            }
         | 
| 406 | 
            +
             | 
| 407 | 
            +
            bool BLINK_Compact_encodeDecimal(int64_t mantissa, int8_t exponent, blink_stream_t out)
         | 
| 408 | 
            +
            {
         | 
| 409 | 
            +
                bool retval = false;
         | 
| 410 | 
            +
                
         | 
| 411 | 
            +
                if(encodeVLC((uint64_t)exponent, true, out)){
         | 
| 412 | 
            +
             | 
| 413 | 
            +
                    if(encodeVLC(mantissa, true, out)){
         | 
| 414 | 
            +
             | 
| 415 | 
            +
                        retval = true;
         | 
| 416 | 
            +
                    }
         | 
| 417 | 
            +
                }
         | 
| 418 | 
            +
             | 
| 419 | 
            +
                return retval;
         | 
| 420 | 
            +
            }
         | 
| 421 | 
            +
             | 
| 422 | 
            +
            uint8_t BLINK_Compact_sizeofUnsigned(uint64_t value)
         | 
| 423 | 
            +
            {
         | 
| 424 | 
            +
                uint8_t retval;
         | 
| 425 | 
            +
             | 
| 426 | 
            +
                if(value <= 0x7fUL){
         | 
| 427 | 
            +
                    retval = 1U;
         | 
| 428 | 
            +
                }
         | 
| 429 | 
            +
                else if(value <= 0x3fffUL){
         | 
| 430 | 
            +
                    retval = 2U;            
         | 
| 431 | 
            +
                }
         | 
| 432 | 
            +
                else if(value <= 0xffffUL){
         | 
| 433 | 
            +
                    retval = 3U;
         | 
| 434 | 
            +
                }
         | 
| 435 | 
            +
                else if(value <= 0xffffffUL){
         | 
| 436 | 
            +
                    retval = 4U;
         | 
| 437 | 
            +
                }
         | 
| 438 | 
            +
                else if(value <= 0xffffffffUL){
         | 
| 439 | 
            +
                    retval = 5U;
         | 
| 440 | 
            +
                }
         | 
| 441 | 
            +
                else if(value <= 0xffffffffffUL){
         | 
| 442 | 
            +
                    retval = 6U;
         | 
| 443 | 
            +
                }
         | 
| 444 | 
            +
                else if(value <= 0xffffffffffffUL){
         | 
| 445 | 
            +
                    retval = 7U;
         | 
| 446 | 
            +
                }
         | 
| 447 | 
            +
                else if(value <= 0xffffffffffffffUL){
         | 
| 448 | 
            +
                    retval = 8U;
         | 
| 449 | 
            +
                }
         | 
| 450 | 
            +
                else{
         | 
| 451 | 
            +
                    retval = 9U;
         | 
| 452 | 
            +
                }
         | 
| 453 | 
            +
             | 
| 454 | 
            +
                return retval;
         | 
| 455 | 
            +
            }
         | 
| 456 | 
            +
             | 
| 457 | 
            +
            uint8_t BLINK_Compact_sizeofSigned(int64_t value)
         | 
| 458 | 
            +
            {
         | 
| 459 | 
            +
                uint8_t retval;
         | 
| 460 | 
            +
             | 
| 461 | 
            +
                if(value < 0){
         | 
| 462 | 
            +
             | 
| 463 | 
            +
                    if(value >= -64){
         | 
| 464 | 
            +
                        retval = 1U;
         | 
| 465 | 
            +
                    }
         | 
| 466 | 
            +
                    else if(value >= -8192){
         | 
| 467 | 
            +
                        retval = 2U;
         | 
| 468 | 
            +
                    }
         | 
| 469 | 
            +
                    else if(value >= -32768){
         | 
| 470 | 
            +
                        retval = 3U;
         | 
| 471 | 
            +
                    }
         | 
| 472 | 
            +
                    else if(value >= -8388608){
         | 
| 473 | 
            +
                        retval = 4U;
         | 
| 474 | 
            +
                    }
         | 
| 475 | 
            +
                    else if(value >= -2147483648){
         | 
| 476 | 
            +
                        retval = 5U;
         | 
| 477 | 
            +
                    }            
         | 
| 478 | 
            +
                    else if(value >= -549755813888){
         | 
| 479 | 
            +
                        retval = 6U;
         | 
| 480 | 
            +
                    }            
         | 
| 481 | 
            +
                    else if(value >= -140737488355328){
         | 
| 482 | 
            +
                        retval = 7U;
         | 
| 483 | 
            +
                    }            
         | 
| 484 | 
            +
                    else if(value >= -36028797018963968){
         | 
| 485 | 
            +
                        retval = 8U;
         | 
| 486 | 
            +
                    }            
         | 
| 487 | 
            +
                    else{
         | 
| 488 | 
            +
                        retval = 9U;
         | 
| 489 | 
            +
                    }
         | 
| 490 | 
            +
                }
         | 
| 491 | 
            +
                else{
         | 
| 492 | 
            +
             | 
| 493 | 
            +
                    if(value <= 0x3fL){
         | 
| 494 | 
            +
                        retval = 1U;
         | 
| 495 | 
            +
                    }
         | 
| 496 | 
            +
                    else if(value <= 0x1fffL){
         | 
| 497 | 
            +
                        retval = 2U;            
         | 
| 498 | 
            +
                    }
         | 
| 499 | 
            +
                    else if(value <= 0x7fffL){
         | 
| 500 | 
            +
                        retval = 3U;
         | 
| 501 | 
            +
                    }
         | 
| 502 | 
            +
                    else if(value <= 0x7fffffL){
         | 
| 503 | 
            +
                        retval = 4U;
         | 
| 504 | 
            +
                    }
         | 
| 505 | 
            +
                    else if(value <= 0x7fffffffL){
         | 
| 506 | 
            +
                        retval = 5U;
         | 
| 507 | 
            +
                    }
         | 
| 508 | 
            +
                    else if(value <= 0x7fffffffffL){
         | 
| 509 | 
            +
                        retval = 6U;
         | 
| 510 | 
            +
                    }
         | 
| 511 | 
            +
                    else if(value <= 0x7fffffffffffL){
         | 
| 512 | 
            +
                        retval = 7U;
         | 
| 513 | 
            +
                    }
         | 
| 514 | 
            +
                    else if(value <= 0x7fffffffffffffL){
         | 
| 515 | 
            +
                        retval = 8U;
         | 
| 516 | 
            +
                    }
         | 
| 517 | 
            +
                    else{
         | 
| 518 | 
            +
                        retval = 9U;
         | 
| 519 | 
            +
                    }
         | 
| 520 | 
            +
                }
         | 
| 521 | 
            +
             | 
| 522 | 
            +
                return retval;
         | 
| 523 | 
            +
            }
         | 
| 524 | 
            +
             | 
| 525 | 
            +
            /* static functions ***************************************************/
         | 
| 526 | 
            +
             | 
| 527 | 
            +
            static bool encodeVLC(uint64_t in, bool isSigned, blink_stream_t out)
         | 
| 528 | 
            +
            {
         | 
| 529 | 
            +
                uint8_t buffer[9U];
         | 
| 530 | 
            +
                uint8_t bytes = (isSigned) ? BLINK_Compact_sizeofSigned((int64_t)in) : BLINK_Compact_sizeofUnsigned(in);
         | 
| 531 | 
            +
                uint8_t i;
         | 
| 532 | 
            +
             | 
| 533 | 
            +
                if(bytes == 1U){
         | 
| 534 | 
            +
             | 
| 535 | 
            +
                    *buffer = (uint8_t)(in & 0x7fU);
         | 
| 536 | 
            +
                }
         | 
| 537 | 
            +
                else if(bytes == 2U){
         | 
| 538 | 
            +
             | 
| 539 | 
            +
                    buffer[0] = 0x80U | (uint8_t)(in & 0x3fU);
         | 
| 540 | 
            +
                    buffer[1] = (uint8_t)(in >> 6);   
         | 
| 541 | 
            +
                }
         | 
| 542 | 
            +
                else{
         | 
| 543 | 
            +
                    
         | 
| 544 | 
            +
                    buffer[0] = 0xC0U | (bytes-1U);
         | 
| 545 | 
            +
                    for(i=1; i < bytes; i++){
         | 
| 546 | 
            +
             | 
| 547 | 
            +
                        buffer[i] = (uint8_t)(in >> ((i-1U)*8U));
         | 
| 548 | 
            +
                    }            
         | 
| 549 | 
            +
                }
         | 
| 550 | 
            +
                
         | 
| 551 | 
            +
                return BLINK_Stream_write(out, buffer, bytes);    
         | 
| 552 | 
            +
            }
         | 
| 553 | 
            +
             | 
| 554 | 
            +
            static bool decodeVLC(blink_stream_t in, bool isSigned, uint64_t *out, bool *isNull)
         | 
| 555 | 
            +
            {
         | 
| 556 | 
            +
                BLINK_ASSERT(out != NULL)
         | 
| 557 | 
            +
                BLINK_ASSERT(isNull != NULL)
         | 
| 558 | 
            +
             | 
| 559 | 
            +
                uint8_t buffer[9U];
         | 
| 560 | 
            +
                bool retval = false;
         | 
| 561 | 
            +
                uint8_t bytes;
         | 
| 562 | 
            +
                uint8_t i;
         | 
| 563 | 
            +
             | 
| 564 | 
            +
                *isNull = false;
         | 
| 565 | 
            +
             | 
| 566 | 
            +
                if(BLINK_Stream_read(in, buffer, 1U)){
         | 
| 567 | 
            +
             | 
| 568 | 
            +
                    if(buffer[0] < 0xc0U){
         | 
| 569 | 
            +
             | 
| 570 | 
            +
                        if(buffer[0] < 0x80U){
         | 
| 571 | 
            +
             | 
| 572 | 
            +
                            if(isSigned && ((buffer[0] & 0x40U) == 0x40U)){
         | 
| 573 | 
            +
             | 
| 574 | 
            +
                                *out = 0xffffffffffffffc0U;                           
         | 
| 575 | 
            +
                            }
         | 
| 576 | 
            +
                            else{
         | 
| 577 | 
            +
                                
         | 
| 578 | 
            +
                                *out = 0x0U;
         | 
| 579 | 
            +
                            }
         | 
| 580 | 
            +
                            *out |= (uint64_t)(buffer[0] & 0x7fU);
         | 
| 581 | 
            +
                            retval = true;  
         | 
| 582 | 
            +
                        }
         | 
| 583 | 
            +
                        else{
         | 
| 584 | 
            +
             | 
| 585 | 
            +
                            if(BLINK_Stream_read(in, &buffer[1], 1U)){
         | 
| 586 | 
            +
             | 
| 587 | 
            +
                                if(isSigned && ((buffer[1] & 0x80U) == 0x80U)){
         | 
| 588 | 
            +
             | 
| 589 | 
            +
                                    *out = 0xffffffffffffff00U;                               
         | 
| 590 | 
            +
                                }
         | 
| 591 | 
            +
                                else{
         | 
| 592 | 
            +
                                    
         | 
| 593 | 
            +
                                    *out = 0x0U;
         | 
| 594 | 
            +
                                }
         | 
| 595 | 
            +
                                *out |= (uint64_t)buffer[1];
         | 
| 596 | 
            +
                                *out <<= 6U;
         | 
| 597 | 
            +
                                *out |= (uint64_t)(buffer[0] & 0x3fU);
         | 
| 598 | 
            +
                                retval = true;
         | 
| 599 | 
            +
                            }
         | 
| 600 | 
            +
                        }
         | 
| 601 | 
            +
                    }
         | 
| 602 | 
            +
                    else if(buffer[0] == 0xc0U){
         | 
| 603 | 
            +
             | 
| 604 | 
            +
                        *isNull = true;
         | 
| 605 | 
            +
                        retval = true;
         | 
| 606 | 
            +
                    }
         | 
| 607 | 
            +
                    else{
         | 
| 608 | 
            +
             | 
| 609 | 
            +
                        bytes = buffer[0] & 0x3fU;
         | 
| 610 | 
            +
             | 
| 611 | 
            +
                        if(bytes <= 8U){
         | 
| 612 | 
            +
             | 
| 613 | 
            +
                            if(BLINK_Stream_read(in, &buffer[1], bytes)){
         | 
| 614 | 
            +
             | 
| 615 | 
            +
                                if(isSigned && ((buffer[bytes] & 0x80U) == 0x80U)){
         | 
| 616 | 
            +
                                    
         | 
| 617 | 
            +
                                    *out = 0xffffffffffff00U | buffer[bytes];
         | 
| 618 | 
            +
                                }
         | 
| 619 | 
            +
                                else{
         | 
| 620 | 
            +
             | 
| 621 | 
            +
                                    *out = buffer[bytes];
         | 
| 622 | 
            +
                                }
         | 
| 623 | 
            +
             | 
| 624 | 
            +
                                for(i=bytes-1U; i != 0U; i--){
         | 
| 625 | 
            +
             | 
| 626 | 
            +
                                    *out <<= 8;
         | 
| 627 | 
            +
                                    *out |= buffer[i];                        
         | 
| 628 | 
            +
                                }
         | 
| 629 | 
            +
             | 
| 630 | 
            +
                                retval = true;
         | 
| 631 | 
            +
                            }
         | 
| 632 | 
            +
                        }
         | 
| 633 | 
            +
                        else{
         | 
| 634 | 
            +
             | 
| 635 | 
            +
                            /* VLC too large */
         | 
| 636 | 
            +
                            BLINK_ERROR("cannot handle a VLC field larger than 8 bytes")
         | 
| 637 | 
            +
                        }
         | 
| 638 | 
            +
                    }
         | 
| 639 | 
            +
                }
         | 
| 640 | 
            +
             | 
| 641 | 
            +
                return retval;
         | 
| 642 | 
            +
            }
         |