Decode an encoded bitstring up to length 15. * If successful returns the length of the bitstring and 'result' contains the decoded bits. * The decoded bitstring is stored in the LSBs of 'result', with the LSB being the last bit decoded. * Any remaining bits in 'result' are reset to 0. * If the decoded bitstring would be too long 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' is returned ('result' may be m
| 144 | * NULL != stream |
| 145 | */ |
| 146 | static int32_t decodeUpto15Bits(int32_t* result, bitstream* stream) { |
| 147 | int32_t bit = read1Bit(stream); |
| 148 | if (bit < 0) return bit; |
| 149 | |
| 150 | *result = 0; |
| 151 | if (0 == bit) { |
| 152 | return 0; |
| 153 | } else { |
| 154 | int32_t n = decodeUpto15(stream); |
| 155 | if (0 <= n) { |
| 156 | *result = simplicity_readNBits(n, stream); |
| 157 | if (*result < 0) return *result; |
| 158 | } |
| 159 | return n; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /* Decode an encoded number between 1 and 65535 inclusive. |
| 164 | * When successful returns the decoded result. |
no test coverage detected