Skip to content

Commit 429e7a3

Browse files
committed
feat(imc): add C++ wrappers for clearState and copyState
Add bml::imc::clearState() and bml::imc::copyState() free functions to match the existing C API (PFN_BML_ImcClearState, PFN_BML_ImcCopyState) that previously had no C++ coverage.
1 parent 43fdc30 commit 429e7a3

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

include/bml_imc.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ namespace imc {
8585
return bus->ResetStats(bus->Context) == BML_RESULT_OK;
8686
}
8787

88+
/** @brief Clear retained state for a topic */
89+
inline bool clearState(TopicId id, const BML_ImcBusInterface *bus = nullptr) {
90+
if (!bus || !bus->Context || !bus->ClearState) return false;
91+
return bus->ClearState(bus->Context, id) == BML_RESULT_OK;
92+
}
93+
94+
/** @brief Copy retained state for a topic into caller-owned buffer */
95+
inline std::optional<std::vector<uint8_t>> copyState(TopicId id, const BML_ImcBusInterface *bus = nullptr) {
96+
if (!bus || !bus->Context || !bus->CopyState) return std::nullopt;
97+
size_t size = 0;
98+
BML_Result result = bus->CopyState(bus->Context, id, nullptr, 0, &size, nullptr);
99+
if (result != BML_RESULT_BUFFER_TOO_SMALL || size == 0) return std::nullopt;
100+
std::vector<uint8_t> buffer(size);
101+
result = bus->CopyState(bus->Context, id, buffer.data(), buffer.size(), &size, nullptr);
102+
if (result != BML_RESULT_OK) return std::nullopt;
103+
buffer.resize(size);
104+
return buffer;
105+
}
106+
88107
/** @brief Get topic info by ID */
89108
inline std::optional<BML_TopicInfo> getTopicInfo(TopicId id, const BML_ImcBusInterface *bus = nullptr) {
90109
if (!bus || !bus->Context || !bus->GetTopicInfo) return std::nullopt;

0 commit comments

Comments
 (0)