get method
Returns the JSON value at key.
Throws ZenohException (enriched with upstream detail where available) if the key is absent or invalid (rc-checked). Throws StateError if the config has been disposed or consumed.
⚠️ The message may echo your config text. On the unstable variant
it carries canon's own words for the failure, and canon's json5 parser
echoes the offending value and the surrounding source line — adjacent
intact secrets included — with a caret pointing at the offending token.
Do not forward this message into a log, a crash report or a bug
report without deciding redaction first. No redaction is applied here;
see ZenohException.enriched for why a general one is not implementable
at this seam. On the default stable variant no upstream detail is
carried at all, so the message is the base text alone.
Implementation
String get(String key) {
_ensureNotDisposed();
_ensureNotConsumed();
final nativeKey = key.toNativeUtf8();
final ownedStr = calloc.allocate<Void>(bindings.zd_string_sizeof());
try {
final result = _withDetailBuffer(
(errBuf, errCap, errLen) => bindings.zd_config_get(
_ptr.cast(),
nativeKey.cast(),
ownedStr.cast(),
errBuf,
errCap,
errLen,
),
);
if (result.rc != 0) {
throw ZenohException.enriched(
'Failed to get config key "$key"',
result.rc,
result.detail,
);
}
final loanedStr = bindings.zd_string_loan(ownedStr.cast());
final data = bindings.zd_string_data(loanedStr);
final len = bindings.zd_string_len(loanedStr);
return data.cast<Utf8>().toDartString(length: len);
} finally {
bindings.zd_string_drop(ownedStr.cast());
calloc.free(ownedStr);
malloc.free(nativeKey);
}
}