fromString static method

TracingId fromString(
  1. String? id,
  2. TracingIdRepresentation representation
)

Implementation

static TracingId fromString(
    String? id, TracingIdRepresentation representation) {
  if (id == null) {
    return TracingId(BigInt.zero);
  }

  switch (representation) {
    case TracingIdRepresentation.lowDecimal:
    case TracingIdRepresentation.decimal:
      final value = BigInt.tryParse(id);
      if (value != null) {
        return TracingId(value);
      }
      break;
    case TracingIdRepresentation.hex:
    case TracingIdRepresentation.hex16Chars:
    case TracingIdRepresentation.hex32Chars:
      final value = BigInt.tryParse(id, radix: 16);
      if (value != null) {
        return TracingId(value);
      }
      break;
    case TracingIdRepresentation.highHex16Chars:
      // Take only the last 16 chars
      if (id.length > 16) {
        id = id.substring(id.length - 16);
      }
      final value = BigInt.tryParse(id, radix: 16);
      if (value != null) {
        return TracingId(value);
      }
      break;
  }

  return TracingId(BigInt.zero);
}