fromBytes static method

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

Implementation

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

    // Length validation
    if((length < 3) || ((offset + length) > bytes.length)) {
        throw FormatException('Invalid AFSDB record: expected at least 3 bytes, got ${bytes.length}.');
    }

    late String hostname;
    final int subtype = (bytes[offset + 0] << 8) | bytes[offset + 1]; // Uint8
    (_, hostname) = DNSHelper.parseDomainName(bytes, offset + 2);

    return AFSDBResponseRecord(
        name: name,
        ttl: ttl,
        subtype: subtype,
        hostname: hostname);
}