MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / packBools

Function packBools

pj_datastore/src/encoding.cpp:351–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349// ---------------------------------------------------------------------------
350
351PackedBools packBools(Span<const uint8_t> values) {
352 const std::size_t count = values.size();
353 PackedBools result;
354 result.count = count;
355
356 if (count == 0) {
357 return result;
358 }
359
360 std::size_t num_bytes = (count + 7) / 8;
361 result.bits.resize(num_bytes);
362
363 uint8_t* bit_data = result.bits.mutableData();
364 std::memset(bit_data, 0, num_bytes);
365
366 for (std::size_t i = 0; i < count; ++i) {
367 if (values[i] != 0) {
368 std::size_t byte_idx = i / 8;
369 std::size_t bit_idx = i % 8;
370 bit_data[byte_idx] |= static_cast<uint8_t>(1u << bit_idx);
371 }
372 }
373
374 return result;
375}
376
377bool unpackBool(const PackedBools& packed, std::size_t index) {
378 std::size_t byte_idx = index / 8;

Callers 2

sealMethod · 0.85
TESTFunction · 0.85

Calls 3

mutableDataMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45

Tested by 1

TESTFunction · 0.68