toJson method

Map<String, Object?> toJson(
  1. CapturedDraw draw, {
  2. bool includeBytes = false,
})

Metadata plus the decoded members when resolvable; includeBytes adds the packed bytes as base64 so a loaded capture can still show them.

Implementation

Map<String, Object?> toJson(CapturedDraw draw, {bool includeBytes = false}) {
  final name = nameFor(draw);
  final decoded = resolvedValues != null
      ? [
          for (final value in resolvedValues!)
            {'name': value.name, 'type': value.type, 'values': value.values},
        ]
      : decode(draw)?.map((v) => v.toJson()).toList();
  return {
    'bytes': byteLength,
    if (name != null) 'name': name,
    if (decoded != null) 'values': decoded,
    if (name == null)
      'candidates': [for (final c in candidatesFor(draw)) c.name],
    if (includeBytes)
      'data': base64Encode(
        bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes),
      ),
  };
}