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

Function getWord32Array

src/simplicity/deserialize.c:16–27  ·  view source on GitHub ↗

Fetches 'len' 'uint32_t's from 'stream' into 'result'. * The bits in each 'uint32_t' are set from the MSB to the LSB and the 'uint32_t's of 'result' are set from 0 up to 'len'. * Returns 'SIMPLICITY_ERR_BITSTREAM_EOF' if not enough bits are available ('result' may be modified). * Returns 'SIMPLICITY_NO_ERROR' if successful. * * Precondition: uint32_t result[len]; * NULL != stre

Source from the content-addressed store, hash-verified

14 * NULL != stream
15 */
16static simplicity_err getWord32Array(uint32_t* result, const size_t len, bitstream* stream) {
17 for (size_t i = 0; i < len; ++i) {
18 /* Due to error codes, readNBits cannot fetch 32 bits at once. Instead we fetch two groups of 16 bits. */
19 int32_t bits16 = simplicity_readNBits(16, stream);
20 if (bits16 < 0) return (simplicity_err)bits16;
21 result[i] = (uint32_t)bits16 << 16;
22 bits16 = simplicity_readNBits(16, stream);
23 if (bits16 < 0) return (simplicity_err)bits16;
24 result[i] |= (uint32_t)bits16;
25 }
26 return SIMPLICITY_NO_ERROR;
27}
28
29/* Fetches a 256-bit hash value from 'stream' into 'result'.
30 * Returns 'SIMPLICITY_ERR_BITSTREAM_EOF' if not enough bits are available ('result' may be modified).

Callers 1

getHashFunction · 0.85

Calls 1

simplicity_readNBitsFunction · 0.85

Tested by

no test coverage detected