Decode an encoded bitstring up to length 3. * 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 mo
| 100 | * NULL != stream |
| 101 | */ |
| 102 | static int32_t decodeUpto3Bits(int32_t* result, bitstream* stream) { |
| 103 | int32_t bit = read1Bit(stream); |
| 104 | if (bit < 0) return bit; |
| 105 | |
| 106 | *result = 0; |
| 107 | if (0 == bit) { |
| 108 | return 0; |
| 109 | } else { |
| 110 | int32_t n = decodeUpto3(stream); |
| 111 | if (0 <= n) { |
| 112 | *result = simplicity_readNBits(n, stream); |
| 113 | if (*result < 0) return *result; |
| 114 | } |
| 115 | return n; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /* Decode an encoded number between 1 and 15 inclusive. |
| 120 | * When successful returns the decoded result. |
no test coverage detected