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

Method Write

lib/mdflib/mdflib/src/cg3block.cpp:105–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105uint64_t Cg3Block::Write(std::streambuf& buffer) {
106 const bool update =
107 FilePosition() > 0; // Write or update the values inside the block
108 nof_channels_ = static_cast<uint16_t>(cn_list_.size());
109
110 if (!update) {
111 block_type_ = "CG";
112 block_size_ = (2 + 2) + (3 * 4) + 2 + 2 + 2 + 4 + 4;
113 link_list_.resize(
114 3, 0); // Note that an extra link is added at the end of the block.
115 }
116
117 int64_t sr_link =
118 0; // This link is added at the end of the block not at the beginning
119 for (size_t sr_index = 0; sr_index < sr_list_.size(); ++sr_index) {
120 auto &sr3 = sr_list_[sr_index];
121 if (!sr3 || sr3->FilePosition() > 0) {
122 continue;
123 }
124 sr3->Write(buffer);
125 if (sr_index == 0) {
126 sr_link = sr3->FilePosition();
127 } else {
128 if (auto &prev = sr_list_[sr_index - 1]; prev) {
129 prev->UpdateLink(buffer, kIndexNext, sr3->FilePosition());
130 }
131 }
132 }
133
134 uint64_t bytes = update ? MdfBlock::Update(buffer) : MdfBlock::Write(buffer);
135 if (!update) {
136 bytes += WriteNumber(buffer, record_id_);
137 bytes += WriteNumber(buffer, nof_channels_);
138 bytes += WriteNumber(buffer, size_of_data_record_);
139 bytes += WriteNumber(buffer, nof_records_);
140 bytes += WriteNumber(buffer, static_cast<uint32_t>(sr_link));
141 } else {
142 // Only nof_records and SR blocks may be added
143 bytes += StepFilePosition(buffer, sizeof(record_id_) + sizeof(nof_channels_) +
144 sizeof(size_of_data_record_));
145 bytes += WriteNumber(buffer, nof_records_);
146 // Check if any SR blocks been added. This typical happens after a
147 // measurement.
148 if (sr_link > 0) {
149 bytes += WriteNumber(buffer, static_cast<uint32_t>(sr_link));
150 } else {
151 bytes += StepFilePosition(buffer, sizeof(uint32_t));
152 }
153 }
154
155 for (size_t cn_index = 0; cn_index < cn_list_.size(); ++cn_index) {
156 auto &cn3 = cn_list_[cn_index];
157 if (!cn3 || cn3->FilePosition() > 0) {
158 continue;
159 }
160 cn3->Write(buffer);
161 if (cn_index == 0) {
162 UpdateLink(buffer, kIndexCn, cn3->FilePosition());

Callers

nothing calls this directly

Calls 7

StepFilePositionFunction · 0.85
UpdateLinkMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45
FilePositionMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected