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

Method WriteVlsdSample

lib/mdflib/mdflib/src/cg4block.cpp:575–630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573}
574
575uint64_t Cg4Block::WriteVlsdSample(std::streambuf& buffer, uint8_t record_id_size,
576 const std::vector<uint8_t> &source) {
577 const uint64_t vlsd_index = vlsd_index_; // Temporary store the old index
578 uint64_t total_count = nof_invalid_bytes_;
579 total_count <<= 32;
580 total_count += nof_data_bytes_;
581
582 switch (record_id_size) {
583 case 0:
584 // No Record ID to store
585 break;
586
587 case 1: {
588 const auto id = static_cast<uint8_t>(RecordId());
589 WriteNumber(buffer, id);
590 break;
591 }
592
593 case 2: {
594 const auto id = static_cast<uint16_t>(RecordId());
595 WriteNumber(buffer, id);
596 break;
597 }
598
599 case 4: {
600 const auto id = static_cast<uint32_t>(RecordId());
601 WriteNumber(buffer, id);
602 break;
603 }
604
605 default: {
606 const auto id = RecordId();
607 WriteNumber(buffer, id);
608 break;
609 }
610
611 }
612 const auto length = static_cast<uint32_t>(source.size());
613 const LittleBuffer buff(length);
614 const auto length_count = buffer.sputn(
615 reinterpret_cast<const char*>(buff.data()),
616 sizeof(length) );
617 // total_count += length_count;
618 const auto buffer_count = buffer.sputn(
619 reinterpret_cast<const char*>(source.data()),
620 static_cast<std::streamsize>(source.size()) );
621 total_count += buffer_count;
622 IncrementSample(); // Increment internal sample counter
623 NofSamples(Sample());
624
625 vlsd_index_ += length_count + buffer_count; // Happens to be the VLSD CG
626 // length. So update it as well
627 nof_data_bytes_ = static_cast<uint32_t>(total_count & 0xFFFFFFFF);
628 nof_invalid_bytes_ = static_cast<uint32_t>(total_count >> 32);
629 return vlsd_index; // Note it returns the old index
630}
631
632uint64_t Cg4Block::WriteCompressedVlsdSample(std::vector<uint8_t>& dest,

Callers 2

SaveQueueMethod · 0.80
SaveQueueMethod · 0.80

Calls 2

sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected