ihedvall / mdflib

Implementation of the ASAM MDF data file.
https://ihedvall.github.io/mdflib/
MIT License
57 stars 26 forks source link

About CnFlag and ChannelType #23

Closed Simplxss closed 11 months ago

Simplxss commented 11 months ago

In cn4block.cpp

void Cn4Block::PrepareForWriting(size_t offset) {
  bit_offset_ = 0;
  byte_offset_ = offset;
  data_list_.clear(); // Temporary storage of signal data (SD)
  data_map_.clear();
  // The bit count may be set by the user.
  bool use_index = false;
  switch (Type()) {
    case ChannelType::MaxLength:
    case ChannelType::Sync:
    case ChannelType::Master:
    case ChannelType::FixedLength:
      // Length fixed below or by user
      // Always store invalid bit
      flags_ |= CnFlag::InvalidValid;
      break;

    case ChannelType::VariableLength:
      // Store unsigned 32/64-bit index to variable block
      flags_ |= CnFlag::InvalidValid;
      if (bit_count_ == 0) {
        bit_count_ = 8 * 8;
      }
      return;

    case ChannelType::VirtualData:
    case ChannelType::VirtualMaster:
      // Sample index * CC sets the channel value. No valid bits
      bit_count_ = 0;
      flags_ &= ~CnFlag::InvalidValid;
      return;
  }
  // ...
}

It's not necessary that add InvalidValid to flags. In fact most FixedLength value don't store invalid bit, and Master value even can't contain invalid bit.

ihedvall commented 11 months ago

It's OK. I can remove this flag. I can fix this. It's relative easy (2 places) but some of the unit tests need to be updated as well,

ihedvall commented 11 months ago

Fixed so the user selects the invalid flag usage.