fromBytes static method

AResponseRecord fromBytes({
  1. required String name,
  2. required int ttl,
  3. required Uint8List bytes,
  4. required int offset,
  5. required int length,
})

Implementation

static AResponseRecord fromBytes({
    required String name,
    required int ttl,
    required Uint8List bytes,
    required int offset,
    required int length }) {

    // Length validation
    if((length != 4) || ((offset + length) > bytes.length)) {
        throw FormatException('Invalid bytes length for A record.');
    }

    // Create the IPv4
    final String ipString = bytes
        .sublist(offset, offset + length)
        .join('.');

    // Create instance
    return AResponseRecord(
        name: name,
        ttl: ttl,
        ip: InternetAddress.tryParse(ipString)!
    );
}