MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / PrepareForWriting

Method PrepareForWriting

lib/mdflib/mdflib/src/cg4block.cpp:428–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426}
427
428void Cg4Block::PrepareForWriting() {
429 nof_data_bytes_ = 0;
430 vlsd_index_ = 0;
431 if (Flags() & CgFlag::VlsdChannel) {
432 // This is a specialized CG (VLSD) group with variable length
433 // channel. Some channels in other groups may reference this group.
434 // This group does not contain any channels.
435 nof_invalid_bytes_ = 0;
436 sample_buffer_.clear();
437 sample_buffer_.shrink_to_fit();
438 return;
439 }
440
441 // Calculates number of data bytes. Note that some channels may
442 // be a so-called array channel. Little bit complicated but the
443 // referenced channel have a channel array (CA) block.
444 uint64_t byte_offset = 0;
445 uint64_t invalid_bit_offset = 0;
446 for (const auto &channel : cn_list_) {
447 if (!channel) {
448 continue;
449 }
450 channel->PrepareForWriting(byte_offset);
451 const auto value_size = static_cast<uint32_t>(channel->DataBytes());
452 const uint64_t array_size = channel->ArraySize();
453 if (array_size > 1) {
454 nof_data_bytes_ += static_cast<uint32_t>(value_size * array_size);
455 byte_offset += static_cast<uint32_t>(value_size * array_size);
456 } else {
457 // Not an array
458 nof_data_bytes_ += static_cast<uint32_t>(value_size);
459 byte_offset += static_cast<uint32_t>(value_size);
460 }
461
462 if (channel->Flags() & CnFlag::InvalidValid) {
463 channel->SetInvalidOffset(invalid_bit_offset);
464 if (array_size > 1) {
465 invalid_bit_offset += array_size;
466 } else {
467 ++invalid_bit_offset;
468 }
469 }
470 }
471
472 if (invalid_bit_offset == 0) {
473 nof_invalid_bytes_ = 0;
474 } else if ((invalid_bit_offset % 8) > 0) {
475 nof_invalid_bytes_ = static_cast<uint32_t>((invalid_bit_offset / 8) + 1);
476 } else {
477 nof_invalid_bytes_ = static_cast<uint32_t>(invalid_bit_offset / 8);
478 }
479
480 if (const auto total_size = nof_invalid_bytes_ + nof_data_bytes_;
481 total_size > 0) {
482 sample_buffer_.resize(total_size,0);
483 } else {
484 sample_buffer_.clear();
485 sample_buffer_.shrink_to_fit();

Callers

nothing calls this directly

Calls 6

SetInvalidOffsetMethod · 0.80
clearMethod · 0.45
DataBytesMethod · 0.45
ArraySizeMethod · 0.45
FlagsMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected