decode method

IpPacket<IpAddress> decode(
  1. RawReader reader
)

Returns IPv4Packet or IPv6Packet depending on the initial byte.

Implementation

static IpPacket decode(RawReader reader) {
  final version = reader.previewUint8(0) >> 4;
  switch (version) {
    case 4:
      final result = Ip4Packet();
      result.decodeSelf(reader);
      return result;
    case 6:
      final result = Ip6Packet();
      result.decodeSelf(reader);
      return result;
    default:
      throw ArgumentError("Invalid IP version number");
  }
}