Record Simplification
- For the
Defaultimplementation forRecordData, changedRecordDatatoSelfto improve code interpretability and to make the code more idiomatic. - Refactored the checksum into a
struct. This provides better type-safety (this prevents us from accidentally passing in au32for something else when what we really want is aChecksum). This also makes the code more readable, as if we see aChecksumbeing passed around it is much clearer than an unnamedu32, additionally this will catch errors in future version, improving how maintenanceable the code is.- Updated the corresponding types and update the parsing.
- Removed the
databasefield from theRecordDatastruct as it is never actually used for anything and is always a blank string. This simplifies the code base as there are less ambigious things. - Removed the
locationfield as it was either zero but was never read or written. - Removed the
location_typefield as it was always zero and never written or read. - Added a constructor for creating
RecordCharacteristicswhere everything is zeroed except for the counter number which seems to be a common pattern. - Changed methods in
RecordDatathat are intended to takePath-like objects to accept these objects instead of just strings. This makes the code more flexible and it is clearer that paths are intended, while not breaking existing code. - Moved the
save_hash_databasemethod inside of the same module asRecordDataand made it private as the intention of the save method on theRecordDataclass is for the function to be called on the struct directly, improving code readability. - This was also done for
load_hash_databaseandload_hash_database_readonly, although the latter was removed as it is the first but just reaonly, it is quicker to just callRecordData::load(x).read_only()to get the readonly version. This removes code duplication and removes the surface for bugs.- These were converted into the struct methods
RecordData::loadandRecordData::load_read_onlyrespectively. This is much more readable and when modifying there are not many disjoint methods that do the same thing. (load_hash_databaseandload_hash_database_readonlydid the same thing, just made a slight change to the result as at the end.) - When loading databases, they now take the generic
PwherePis something that can be referenced to get aPath. This has the same advantages as when it was done for the save methods.
- These were converted into the struct methods