Compare commits

...

4 Commits

Author SHA1 Message Date
99d3ea7b83 chore(submodules): update iKv pointer
All checks were successful
Build / unit-tests (push) Successful in 40s
Build / cmake-build (push) Successful in 46s
2026-06-19 17:02:08 -05:00
5500cd6984 feat(file): Expose API to inspect iKv file format and storage kind
Some checks failed
Build / cmake-build (push) Failing after 20s
Build / unit-tests (push) Failing after 24s
2026-06-19 16:50:55 -05:00
b5c13725de Update iKv submodule pointer 2026-06-19 15:56:32 -05:00
8ef02f9470 Expose underlying node pointer from ikv::Value wrapper 2026-06-19 15:56:30 -05:00
2 changed files with 37 additions and 0 deletions

View File

@@ -25,6 +25,19 @@ enum ValueType {
/// On-disk iKv format versions supported for explicit writes.
enum class Version : unsigned { v1 = 1, v2 = 2 };
/// Serialized storage kind of an iKv document.
enum class StorageKind : unsigned {
unknown = 0,
text,
binary
};
/// File format information reported by the library.
struct FileFormat {
StorageKind storage = StorageKind::unknown;
Version version = Version::v2;
};
/// Error raised for invalid types, unsupported operations, parse failures,
/// and I/O failures.
class Error : public std::runtime_error {
@@ -116,6 +129,8 @@ public:
double asDouble() const;
bool asBool() const;
ikv_node_t* get_node() const { return node_; }
/// Writes text or binary output, using iKv2 unless a version is specified.
void write(const std::string& path, Version version = Version::v2) const;
void writeBinary(const std::string& path, Version version = Version::v2) const;
@@ -143,4 +158,8 @@ private:
bool read_only_ = false;
};
/// Inspects an iKv file and reports whether it is text or binary plus its version.
/// Throws Error when the file cannot be identified.
FileFormat inspectFile(const std::string& path);
} // namespace ikv

View File

@@ -39,6 +39,10 @@ ValueType publicType(ikv_type_t type) noexcept {
}
}
Version publicVersion(ikv_version_t version) {
return version == IKV_VERSION_1 ? Version::v1 : Version::v2;
}
} // namespace
void Value::Deleter::operator()(ikv_node_t* node) const noexcept { ikv_free(node); }
@@ -251,4 +255,18 @@ void Value::refresh(const std::string& path) {
if (!ikv_refresh_from_path(node_, path.c_str())) throw Error("failed to refresh iKv root from: " + path);
}
FileFormat inspectFile(const std::string& path) {
if (ikv_version_t version = ikv_detect_file_version(path.c_str(), true);
version != IKV_VERSION_UNKNOWN) {
return {StorageKind::binary, publicVersion(version)};
}
if (ikv_version_t version = ikv_detect_file_version(path.c_str(), false);
version != IKV_VERSION_UNKNOWN) {
return {StorageKind::text, publicVersion(version)};
}
throw Error("failed to identify iKv file format: " + path);
}
} // namespace ikv