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

Function decodeUpto3

src/simplicity/bitstream.c:83–89  ·  view source on GitHub ↗

Decode an encoded number between 1 and 3 inclusive. * When successful returns the decoded result. * If the decoded value would be too large, 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' is returned. * If more bits are needed than available in the 'stream', 'SIMPLICITY_ERR_BITSTRING_EOF' is returned. * If an I/O error occurs when reading from the 'stream', 'SIMPLICITY_ERR_BISTRING_ERROR' is returned. *

Source from the content-addressed store, hash-verified

81 * Precondition: NULL != stream
82 */
83static int32_t decodeUpto3(bitstream* stream) {
84 int32_t result;
85 int32_t len = decodeUpto1Bit(&result, stream);
86 if (len < 0) return len;
87 result |= 1 << len;
88 return result;
89}
90
91/* Decode an encoded bitstring up to length 3.
92 * If successful returns the length of the bitstring and 'result' contains the decoded bits.

Callers 1

decodeUpto3BitsFunction · 0.85

Calls 1

decodeUpto1BitFunction · 0.85

Tested by

no test coverage detected