decodeValue static method

String decodeValue(
  1. Protocol protocol,
  2. Uint8List bytes
)

Decodes a protocol value from bytes

Implementation

static String decodeValue(Protocol protocol, Uint8List bytes) {
  switch (protocol.name) {
    case 'ip4':
      return _decodeIP4(bytes);
    case 'ip6':
      return _decodeIP6(bytes);
    case 'tcp':
    case 'udp':
      return _decodePort(bytes);
    case 'unix':
      return _decodePath(bytes);
    default:
      if (protocol.size == 0) { // Protocol has no value component
        return '';
      }
      if (protocol.isVariableSize) { // Protocol has a variable-length string value
        return _decodeString(bytes);
      }
      // Protocol has a fixed, non-zero size but is not handled by a specific case
      throw ArgumentError('Unsupported protocol for decoding: ${protocol.name}');
  }
}