Skip to content
BitVecTryFromBytesAlloc

BitVecTryFromBytesAlloc

Description

Build a bitvector from raw bytes using an explicit allocator.

Parameters

Name Direction Description
out out Destination bitvector.
bytes in Source byte buffer.
bit_len in Number of bits to read from bytes.
alloc in Allocator to bind to the destination bitvector.

Success

Returns true and initializes out.

Failure

Returns false if allocation fails.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        if (!BitVecTryFromBytesAlloc(INT_BITS(&result), bytes, len * 8, result.bits.allocator)) {
            return result;
        }
    }
    
    bool BitVecTryFromBytesAlloc(BitVec *out, const u8 *bytes, u64 bit_len, Allocator alloc) {
        if (!bytes) {
            LOG_FATAL("bytes is NULL");
        BitVec result;
    
        if (!BitVecTryFromBytesAlloc(&result, bytes, bit_len, alloc)) {
            result = BitVecInit(alloc);
        }
    #define BITVEC_TRY_FROM_BYTES_HAS_ARGS(...)                             BITVEC_TRY_FROM_BYTES_HAS_ARGS_IMPL(__VA_ARGS__, 4, 3, 2, 1, 0)
    #define BitVecTryFromBytes(...)                                         CONCAT(BitVecTryFromBytes_, BITVEC_TRY_FROM_BYTES_HAS_ARGS(__VA_ARGS__))(__VA_ARGS__)
    #define BitVecTryFromBytes_3(out, bytes, bit_len)                       BitVecTryFromBytesAlloc((out), (bytes), (bit_len), DefaultAllocator())
    #define BitVecTryFromBytes_4(out, bytes, bit_len, alloc)                BitVecTryFromBytesAlloc((out), (bytes), (bit_len), (alloc))
    #define BitVecTryFromBytes(...)                                         CONCAT(BitVecTryFromBytes_, BITVEC_TRY_FROM_BYTES_HAS_ARGS(__VA_ARGS__))(__VA_ARGS__)
    #define BitVecTryFromBytes_3(out, bytes, bit_len)                       BitVecTryFromBytesAlloc((out), (bytes), (bit_len), DefaultAllocator())
    #define BitVecTryFromBytes_4(out, bytes, bit_len, alloc)                BitVecTryFromBytesAlloc((out), (bytes), (bit_len), (alloc))
    
    ///
Last updated on