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

Method Write

lib/mdflib/mdflib/src/cn4block.cpp:494–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

492}
493
494uint64_t Cn4Block::Write(std::streambuf& buffer) {
495 const bool update = FilePosition() > 0; // True if already written to file
496 if (update) {
497 return block_length_;
498 }
499 nof_attachments_ = static_cast<uint16_t>(attachment_list_.size());
500 const auto default_x = (flags_ & CnFlag::DefaultX) != 0;
501
502 block_type_ = "##CN";
503 block_length_ = static_cast<uint64_t>(24 + 8 * 8);
504 block_length_ += static_cast<uint64_t>(nof_attachments_) * 8;
505 if (default_x) {
506 block_length_ += 3 * 8;
507 }
508 block_length_ += 1 + 1 + 1 + 1 + 4 + 4 + 4 + 4 + 1 + 1 + 2 + (6 * 8);
509 link_list_.resize(8 + nof_attachments_ + (default_x ? 1 : 0), 0);
510 WriteLink4List(buffer, cx_list_, kIndexCx,
511 UpdateOption::DoNotUpdateWrittenBlock);
512 WriteTx4(buffer, kIndexName, name_);
513 WriteBlock4(buffer, si_block_, kIndexSi);
514 WriteBlock4(buffer, cc_block_, kIndexCc);
515 // The signal data shall not be stored here. Instead, the function
516 // WriteSignalData() should be used. It is called by the Mdf(4)Writer class
517 // when the measurement is finalized.
518 WriteBlock4(buffer, unit_, kIndexUnit);
519 WriteMdComment(buffer, kIndexMd);
520 for (size_t index_at = 0; index_at < attachment_list_.size(); ++index_at) {
521 const auto index = 8 + index_at;
522 const auto *at4 = attachment_list_[index_at];
523 link_list_[index] = at4 != nullptr ? at4->Index() : 0;
524 }
525 if (default_x) {
526 const auto index = 8 + nof_attachments_;
527 const auto *dg4 = default_x_.data_group;
528 const auto *cg4 = default_x_.channel_group;
529 const auto *cn4 = default_x_.channel;
530 link_list_[index] = dg4 != nullptr ? dg4->Index() : 0;
531 link_list_[index] = cg4 != nullptr ? cg4->Index() : 0;
532 link_list_[index] = cn4 != nullptr ? cn4->Index() : 0;
533 }
534
535 uint64_t bytes = MdfBlock::Write(buffer);
536 bytes += WriteNumber(buffer, type_);
537 bytes += WriteNumber(buffer, sync_type_);
538 bytes += WriteNumber(buffer, data_type_);
539 bytes += WriteNumber(buffer, bit_offset_);
540 bytes += WriteNumber(buffer, byte_offset_);
541 bytes += WriteNumber(buffer, bit_count_);
542 bytes += WriteNumber(buffer, flags_);
543 bytes += WriteNumber(buffer, invalid_bit_pos_);
544 bytes += WriteNumber(buffer, precision_);
545
546 bytes += WriteBytes(buffer, 1);
547 bytes += WriteNumber(buffer, nof_attachments_);
548 bytes += WriteNumber(buffer, range_min_);
549 bytes += WriteNumber(buffer, range_max_);
550 bytes += WriteNumber(buffer, limit_min_);
551 bytes += WriteNumber(buffer, limit_max_);

Callers 1

WriteSignalDataMethod · 0.45

Calls 4

WriteBytesFunction · 0.85
sizeMethod · 0.45
resizeMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected