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

Method Write

lib/mdflib/mdflib/src/cc3block.cpp:277–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277uint64_t Cc3Block::Write(std::streambuf& buffer) {
278 const bool update =
279 FilePosition() > 0; // Write or update the values inside the block
280 if (update) {
281 return block_size_;
282 }
283 // If text range conversion is in use, save the TX blocks first before writing
284 // the links to them.
285 for (auto &range : text_range_conversion_list_) {
286 uint32_t link = 0;
287 if (!range.text.empty()) {
288 Tx3Block temp;
289 temp.Init(*this);
290 temp.Write(buffer);
291 link = static_cast<uint32_t>(temp.FilePosition());
292 }
293 range.link_text = link;
294 }
295 block_type_ = "CC";
296 block_size_ = (2 + 2) + 2 + 2 * 8 + 20 + 2 +
297 2; // Will be updated at the end of the block write
298 link_list_.clear();
299 link_list_.shrink_to_fit();
300
301 uint64_t bytes = MdfBlock::Write(buffer);
302 bytes += WriteBool(buffer, range_valid_);
303 bytes += WriteNumber(buffer, min_);
304 bytes += WriteNumber(buffer, max_);
305 bytes += WriteStr(buffer, unit_, 20);
306 bytes += WriteNumber(buffer, conversion_type_);
307
308 switch (conversion_type_) {
309 case 0: // Parametric
310 case 6: // Polynomial
311 case 7: // Exponential
312 case 8: // Logarithmic
313 case 9: // Rational
314 nof_values_ = static_cast<uint16_t>(value_list_.size());
315 bytes += WriteNumber(buffer, nof_values_);
316 for (auto par : value_list_) {
317 bytes += WriteNumber(buffer, par);
318 }
319 break;
320
321 case 1: // Tabular interpolation
322 case 2: // Tabular
323 nof_values_ = static_cast<uint16_t>(value_list_.size() / 2);
324 bytes += WriteNumber(buffer, nof_values_);
325 for (auto par : value_list_) {
326 bytes += WriteNumber(buffer, par);
327 }
328 break;
329
330 case 10: // Text formula
331 nof_values_ = static_cast<uint16_t>(formula_.size());
332 bytes += WriteNumber(buffer, nof_values_);
333 WriteStr(buffer, formula_, formula_.size());
334 break;

Callers

nothing calls this directly

Calls 6

WriteStrFunction · 0.85
emptyMethod · 0.80
InitMethod · 0.45
FilePositionMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected