fromBytes static method

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

Implementation

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

    if (length != 8 || offset + 8 > bytes.length) {
        throw FormatException('Invalid EUI-48 record: expected 6 bytes, got $length.');
    }

    final Uint8List mac = bytes.sublist(offset, offset + 8);
    final String macStr = mac.map((b) => b.toRadixString(16).padLeft(2, '0').toUpperCase()).join('-');

    return EUI64ResponseRecord(
        name: name,
        ttl: ttl,
        macBytes: mac,
        macAddress: macStr);
}