MCPcopy Create free account
hub / github.com/ElementsProject/elements / decodeUpto15Bits

Function decodeUpto15Bits

src/simplicity/bitstream.c:146–161  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

144 * NULL != stream
145 */
146static 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.

Callers 1

decodeUpto65535Function · 0.85

Calls 3

read1BitFunction · 0.85
decodeUpto15Function · 0.85
simplicity_readNBitsFunction · 0.85

Tested by

no test coverage detected