Config.fromStr constructor
- String json
Creates a configuration from a JSON5 json string.
The resulting config has the same lifecycle as a default Config: it may
be passed to Session.open (which consumes it) or disposed.
Throws ZenohException (enriched with upstream detail where available)
if json is not valid config JSON5.
⚠️ 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
factory Config.fromStr(String json) {
final nativeJson = json.toNativeUtf8();
try {
return Config._build(
'Failed to create config from string',
(ptr, errBuf, errCap, errLen) => bindings.zd_config_from_str(
ptr.cast(),
nativeJson.cast(),
errBuf,
errCap,
errLen,
),
);
} finally {
malloc.free(nativeJson);
}
}