#include <cstdint>
#include <filesystem>
#include <nlohmann/json.hpp>
#include <string>
#include <string_view>
#include <vector>
Go to the source code of this file.
◆ clearOdCache()
Deletes every object dictionary cache file in the data directory.
Deleted are the files in <data-dir>/od-cache whose names have the layout of odCacheFilePath(), and the files of the earlier layout <data-dir>/0x<vendor>/0x<product>/0x<revision>.json. Other files are not touched. A folder that is empty afterwards is deleted as well.
- Parameters
-
| data_dir | The data directory, see –data-dir. A directory that does not exist holds no cache, and the result is empty. |
- Returns
- The deleted files and the files that could not be deleted.
◆ makeOdCacheDocument()
Builds the content of a cache file.
- Parameters
-
| identity | What the dictionary was read from. |
| entries | The dictionary entries, as serialized. |
- Returns
- The document with the format version, the identity and the entries.
◆ odCacheDirectory()
| std::filesystem::path odCacheDirectory |
( |
const std::filesystem::path & | data_dir | ) |
|
The folder of the object dictionary cache: <data-dir>/od-cache.
◆ odCacheDocumentMatches()
Tells whether a cache file applies to a device.
It applies when it has the current format version and the same vendor ID, product code and full firmware version. A file in an older format, such as a bare list of entries, does not apply.
- Parameters
-
| document | The parsed cache file. |
| identity | The identity of the device. |
- Returns
- Whether the entries of the file may be used for the device.
◆ odCacheFilePath()
| std::filesystem::path odCacheFilePath |
( |
const std::filesystem::path & | data_dir, |
|
|
const OdCacheIdentity & | identity ) |
Returns the path of the object dictionary cache file of a device.
The file is <data-dir>/od-cache/0x<vendor>0x<product><version>.json, with the vendor ID and the product code written as 8 lowercase hex digits and the version reduced by sanitizeFirmwareVersion(). The SII revision is not part of the name, because on Jasper firmware it does not follow the dictionary.
- Parameters
-
| data_dir | The data directory, see –data-dir. |
| identity | The device identity and the firmware version. |
- Returns
- The path of the cache file. The file need not exist.
◆ sanitizeFirmwareVersion()
| std::string sanitizeFirmwareVersion |
( |
std::string_view | version | ) |
|
Reduces a firmware version to the characters a file name may hold.
Every character other than A-Z, a-z, 0-9, '.', '' and '-' becomes '', and the result is at most 64 characters long. Two versions can reduce to the same name, for example "v10.0.4+41" and "v10.0.4_41", so the cache file also stores the full version, see odCacheDocumentMatches().
- Parameters
-
| version | The firmware version, as read from 0x100A. |
- Returns
- The version as it appears in the file name.
◆ trimObjectString()
| std::string trimObjectString |
( |
std::string_view | raw | ) |
|
Removes the padding of a string read from the object dictionary.
A device can pad a visible string with null bytes or spaces. The string ends at the first null byte, and trailing white space is removed.
- Parameters
-
| raw | The bytes of the string as read. |
- Returns
- The string without its padding.
◆ kOdCacheFormatVersion
| int kOdCacheFormatVersion = 2 |
|
inlineconstexpr |
The format version of a cache file. A file with another version is not loaded.