TraceState.fromString constructor

TraceState.fromString(
  1. String traceState
)

Implementation

TraceState.fromString(String traceState) {
  final stateElements = traceState.split(',');

  // Incoming state doesn't contain valid matchings of comma-separated
  // "key=value,key=value" pairs. Note: an invalid value with both a = and
  // a comma will still be converted, incorrectly.
  if (!stateElements.every((element) => element.contains('='))) {
    return;
  }

  for (final element in stateElements) {
    final entry = element.split('=');
    if (entry.length == 2) {
      put(entry.first, entry.last);
    }
  }
}