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

Function decodeUpto1Bit

src/simplicity/bitstream.c:62–73  ·  view source on GitHub ↗

Decode an encoded bitstring up to length 1. * 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

60 * NULL != stream
61 */
62static int32_t decodeUpto1Bit(int32_t* result, bitstream* stream) {
63 *result = read1Bit(stream);
64 if (*result <= 0) return *result;
65
66 *result = read1Bit(stream);
67 if (*result < 0) return *result;
68 if (0 != *result) return SIMPLICITY_ERR_DATA_OUT_OF_RANGE;
69
70 *result = read1Bit(stream);
71 if (*result < 0) return *result;
72 return 1;
73}
74
75/* Decode an encoded number between 1 and 3 inclusive.
76 * When successful returns the decoded result.

Callers 1

decodeUpto3Function · 0.85

Calls 1

read1BitFunction · 0.85

Tested by

no test coverage detected