equals method

Future<bool> equals(
  1. IdentifySnapshot other
)

Returns true if this snapshot is equal to another snapshot

Implementation

Future<bool> equals(IdentifySnapshot other) async {
  final currentRecord = record is Future ? await record : record;
  final otherRecord = other.record is Future ? await other.record : other.record;

  final hasRecord = currentRecord != null;
  final otherHasRecord = otherRecord != null;

  if (hasRecord != otherHasRecord) {
    return false;
  }

  if (hasRecord) {
    // Assuming Envelope has an 'equals' method or can be compared directly
    // If Envelope.equals is also async, it needs to be awaited.
    // For now, assuming it's synchronous or direct comparison is valid.
    bool recordsAreEqual;
    if (currentRecord is Envelope && otherRecord is Envelope) {
      // If Envelope has a proper 'equals' method:
      // recordsAreEqual = currentRecord.equals(otherRecord);
      // For now, let's assume direct comparison or a placeholder if no .equals()
      // This might need further refinement based on Envelope's actual API
      // For a simple placeholder, if they are not the same instance, assume not equal
      // A proper deep comparison or hash comparison would be better.
      // Let's assume Envelope has a synchronous .equals() for now.
      // If not, this part needs to be adapted.
      // Based on core/record/envelope.dart, Envelope does not have an equals method.
      // We might need to compare marshalled bytes or specific fields.
      // For now, to fix the immediate Future.equals error, we'll compare marshalled bytes.
      try {
        final currentRecordBytes = await currentRecord.marshal();
        final otherRecordBytes = await otherRecord.marshal();
        if (currentRecordBytes.length != otherRecordBytes.length) {
          recordsAreEqual = false;
        } else {
          recordsAreEqual = true;
          for (int i = 0; i < currentRecordBytes.length; i++) {
            if (currentRecordBytes[i] != otherRecordBytes[i]) {
              recordsAreEqual = false;
              break;
            }
          }
        }
      } catch (e) {
        // If marshalling fails, consider them not equal
        recordsAreEqual = false;
      }
    } else {
      recordsAreEqual = (currentRecord == otherRecord); // Fallback for non-Envelope or if one is null
    }
    if (!recordsAreEqual) {
      return false;
    }
  }

  if (protocols.length != other.protocols.length) {
    return false;
  }

  for (var i = 0; i < protocols.length; i++) {
    if (protocols[i] != other.protocols[i]) {
      return false;
    }
  }

  if (addrs.length != other.addrs.length) {
    return false;
  }

  for (var i = 0; i < addrs.length; i++) {
    if (!addrs[i].equals(other.addrs[i])) {
      return false;
    }
  }

  return true;
}