serializeSpans method
AttributedSpans(attributions:
SpanMarker(attribution: LinkAttribution(url: Uri.parse("www.google.com")), offset: 0, markerType: SpanMarkerType.start),
SpanMarker(attribution: LinkAttribution(url: Uri.parse("www.google.com")), offset: 7, markerType: SpanMarkerType.end),
)
TO:
{ "spans" : [ { "type":"start", "offset":0 "keyAttribution": { "keyAttributionId":"link", "keyAttributionLink":"www.google.com" } }, { "type":"end", "offset":7 "keyAttribution": { "keyAttributionId":"link", "keyAttributionLink":"www.google.com" } } }
Implementation
List<dynamic> serializeSpans(AttributedSpans spans,
{AttributionSerializeBuilder? serializeBuilder}) {
List<dynamic> spansList = [];
List<AttributionSerializeBuilder?> builders = [
serializeBuilder,
_customAttributionSerializeBuilder,
defaultAttributionSerializeBuilder
];
for (var marker in spans.markers) {
final attrMap = <String, dynamic>{};
final attribution = marker.attribution;
var attributionMap = _handleAttributionSerialize(builders, attribution);
if (attributionMap == null) {
throw '无法序列化 $attribution';
}
//Span类型
final type = marker.markerType;
//Span偏移量
final offset = marker.offset;
attrMap[keyAttribution] = attributionMap;
attrMap[keySpanType] = type.name;
attrMap[keySpanOffset] = offset;
spansList.add(attrMap);
}
return spansList;
}