validateValue static method

void validateValue(
  1. Protocol protocol,
  2. String value
)

Validates a protocol value before encoding

Implementation

static void validateValue(Protocol protocol, String value) {
  switch (protocol.name) {
    case 'ip4':
      _validateIP4(value);
      break;
    case 'ip6':
      _validateIP6(value);
      break;
    case 'tcp':
    case 'udp':
      _validatePort(value);
      break;
    case 'dns4':
    case 'dns6':
    case 'dnsaddr':
      _validateDNS(value);
      break;
    case 'p2p':
      _validateP2P(value);
      break;
    case 'unix':
      _validateUnixPath(value);
      break;
    default:
      // Allow protocols with size 0 (no value to validate) or variable size.
      // Throw only if it's a fixed, non-zero size protocol not explicitly handled.
      // Protocols with size 0 (like udx, quic-v1) have no value part to validate.
      // Protocols with size -1 (variable, like dns, p2p) have their values validated by other means or not at all here.
      if (protocol.size > 0) {
        // This condition means it's a protocol with a fixed-size value that isn't one of the handled cases.
        throw ArgumentError('Unsupported protocol with fixed-size value: ${protocol.name}');
      }
      // If size is 0 or -1, and not handled by a specific case, validation passes here.
      break;
  }
}