fromOctets static method

ParseOutcome<IpAddressFailure, IpAddress> fromOctets(
  1. Uint8List octets
)

Builds an IpAddress from its octets, 4 for v4 or 16 for v6, reporting IpAddressWrongOctetCount on any other count. The inverse of octets.

Implementation

static ParseOutcome<IpAddressFailure, IpAddress> fromOctets(Uint8List octets) {
  if (octets.length == _ipv4OctetCount) return ParseSuccess(._(octets.join(_octetSeparator)));
  if (octets.length != _ipv6OctetCount) {
    return ParseFailure(IpAddressWrongOctetCount(octets.length));
  }

  return ParseSuccess(._(_canonicalIpv6(.tryParseFromInt(_bigIntOf(octets))!)));
}