Skip to content

Commit

Permalink
Make ownerPID a standalone header field
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Jul 10, 2024
1 parent bc613e9 commit e745b38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/TIVarFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace tivars

const auto signature = this->get_string_bytes(sizeof(var_header_t::signature));
const auto sig_extra = this->get_raw_bytes(sizeof(var_header_t::sig_extra));
this->header.ownerPID = this->get_raw_byte();
const auto comment = this->get_string_bytes(sizeof(var_header_t::comment));
std::copy(signature.begin(), signature.end(), this->header.signature);
std::copy(sig_extra.begin(), sig_extra.end(), this->header.sig_extra);
Expand Down Expand Up @@ -376,6 +377,7 @@ namespace tivars
{
bin_data.insert(bin_data.end(), this->header.signature, this->header.signature + sizeof(var_header_t::signature));
bin_data.insert(bin_data.end(), this->header.sig_extra, this->header.sig_extra + sizeof(var_header_t::sig_extra));
bin_data.push_back(this->header.ownerPID);
bin_data.insert(bin_data.end(), this->header.comment, this->header.comment + sizeof(var_header_t::comment));
bin_data.push_back((uint8_t) (this->header.entries_len & 0xFF)); bin_data.push_back((uint8_t) ((this->header.entries_len >> 8) & 0xFF));
}
Expand Down
5 changes: 3 additions & 2 deletions src/TIVarFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace tivars
struct var_header_t
{
uint8_t signature[8] = {};
uint8_t sig_extra[3] = { 0x1A, 0x0A, OWNER_PID_NONE };
uint8_t sig_extra[2] = { 0x1A, 0x0A }; // this never actually changes
uint8_t ownerPID = OWNER_PID_NONE; // informational - may reflect what's on the version field in the var entries
uint8_t comment[42] = {};
uint16_t entries_len = 0;
};
Expand All @@ -48,7 +49,7 @@ namespace tivars
};

// comes right after the var header, so == its size
static const constexpr uint16_t firstVarEntryOffset = sizeof(var_header_t::signature) + sizeof(var_header_t::sig_extra) + sizeof(var_header_t::comment) + sizeof(var_header_t::entries_len);
static const constexpr uint16_t firstVarEntryOffset = sizeof(var_header_t::signature) + sizeof(var_header_t::sig_extra) + sizeof(var_header_t::ownerPID) + sizeof(var_header_t::comment) + sizeof(var_header_t::entries_len);
static_assert(firstVarEntryOffset == 55, "firstVarEntryOffset size needs to be 55");

static const constexpr uint16_t varEntryOldLength = sizeof(var_entry_t::data_length) + sizeof(var_entry_t::typeID) + sizeof(var_entry_t::varname);
Expand Down

0 comments on commit e745b38

Please sign in to comment.