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

Function decodeUpto3Bits

src/simplicity/bitstream.c:102–117  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

100 * NULL != stream
101 */
102static 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.

Callers 1

decodeUpto15Function · 0.85

Calls 3

read1BitFunction · 0.85
decodeUpto3Function · 0.85
simplicity_readNBitsFunction · 0.85

Tested by

no test coverage detected