debugEncode static method
JSON-encodes diagnostic the way the registered extension responds.
Exposed for tests and for anyone building a DevTools panel against this bridge — a plain function, independent of VM service registration.
Implementation
@visibleForTesting
static String debugEncode(GlassAdaptiveDiagnostic? diagnostic) {
if (diagnostic == null) return '{"available":false}';
final buffer = StringBuffer('{')
..write('"available":true,')
..write('"from":"${diagnostic.from.name}",')
..write('"to":"${diagnostic.to.name}",')
..write('"reason":"${diagnostic.reason.name}",')
..write('"phase":"${diagnostic.phase.name}"');
if (diagnostic.p75Ms != null) {
buffer.write(',"p75Ms":${diagnostic.p75Ms}');
}
if (diagnostic.p95Ms != null) {
buffer.write(',"p95Ms":${diagnostic.p95Ms}');
}
if (diagnostic.framesMeasured != null) {
buffer.write(',"framesMeasured":${diagnostic.framesMeasured}');
}
buffer.write('}');
return buffer.toString();
}