update method
MessageContainer?
update({
- required ODIDMessage message,
- required int receivedTimestamp,
- required MessageSource source,
- int? rssi,
Returns new MessageContainer updated with message. Null is returned if update is refused, because it contains duplicate or corrupted data.
Implementation
MessageContainer? update({
required ODIDMessage message,
required int receivedTimestamp,
required pigeon.MessageSource source,
int? rssi,
}) {
if (message.runtimeType == MessagePack) {
final messages = (message as MessagePack).messages;
var result = this;
for (var packMessage in messages) {
final update = result.update(
message: packMessage,
receivedTimestamp: receivedTimestamp,
source: source,
rssi: rssi,
);
if (update != null) result = update;
}
return result;
}
// update pack only if new data differ from saved ones
return switch (message.runtimeType) {
LocationMessage => locationMessage != null &&
locationMessage!.containsEqualData(message as LocationMessage)
? null
: copyWith(
locationMessage: message as LocationMessage,
lastMessageRssi: rssi,
lastUpdate:
DateTime.fromMillisecondsSinceEpoch(receivedTimestamp),
source: source,
),
BasicIDMessage => _updateBasicIDMessages(
message: message as BasicIDMessage,
receivedTimestamp: receivedTimestamp,
source: source,
rssi: rssi,
),
SelfIDMessage => selfIdMessage != null &&
selfIdMessage!.containsEqualData(message as SelfIDMessage)
? null
: copyWith(
selfIdMessage: message as SelfIDMessage,
lastMessageRssi: rssi,
lastUpdate:
DateTime.fromMillisecondsSinceEpoch(receivedTimestamp),
source: source,
),
OperatorIDMessage => operatorIdMessage != null &&
operatorIdMessage!.containsEqualData(message as OperatorIDMessage)
? null
: copyWith(
operatorIdMessage: message as OperatorIDMessage,
lastMessageRssi: rssi,
lastUpdate:
DateTime.fromMillisecondsSinceEpoch(receivedTimestamp),
source: source,
),
AuthMessage => authenticationMessage != null &&
authenticationMessage!.containsEqualData(message as AuthMessage)
? null
: copyWith(
authenticationMessage: message as AuthMessage,
lastMessageRssi: rssi,
lastUpdate:
DateTime.fromMillisecondsSinceEpoch(receivedTimestamp),
source: source,
),
SystemMessage => systemDataMessage != null &&
systemDataMessage!.containsEqualData(message as SystemMessage)
? null
: copyWith(
systemDataMessage: message as SystemMessage,
lastMessageRssi: rssi,
lastUpdate:
DateTime.fromMillisecondsSinceEpoch(receivedTimestamp),
source: source,
),
_ => null
};
}