59 lines
1.4 KiB
Dart
59 lines
1.4 KiB
Dart
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
part 'udp_package.g.dart';
|
|
|
|
@JsonSerializable()
|
|
class UdpPackage {
|
|
final String id;
|
|
final String name;
|
|
final String data;
|
|
|
|
// Support for multiple IP addresses
|
|
final List<String> ipAddresses;
|
|
|
|
// Broadcast mode flag
|
|
@JsonKey(defaultValue: false)
|
|
final bool isBroadcast;
|
|
|
|
// Legacy field for backward compatibility - kept for migration
|
|
@JsonKey(includeFromJson: true, includeToJson: false)
|
|
final String? ipAddress;
|
|
|
|
UdpPackage({
|
|
required this.id,
|
|
required this.name,
|
|
required this.data,
|
|
List<String>? ipAddresses,
|
|
this.isBroadcast = false,
|
|
this.ipAddress,
|
|
}) : ipAddresses = ipAddresses ?? (ipAddress != null ? [ipAddress] : ['127.0.0.1']);
|
|
|
|
factory UdpPackage.fromJson(Map<String, dynamic> json) {
|
|
// Handle migration from old format
|
|
if (json.containsKey('ipAddress') && !json.containsKey('ipAddresses')) {
|
|
json['ipAddresses'] = [json['ipAddress']];
|
|
}
|
|
return _$UdpPackageFromJson(json);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => _$UdpPackageToJson(this);
|
|
|
|
UdpPackage copyWith({
|
|
String? id,
|
|
String? name,
|
|
String? data,
|
|
List<String>? ipAddresses,
|
|
bool? isBroadcast,
|
|
}) {
|
|
return UdpPackage(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
data: data ?? this.data,
|
|
ipAddresses: ipAddresses ?? this.ipAddresses,
|
|
isBroadcast: isBroadcast ?? this.isBroadcast,
|
|
);
|
|
}
|
|
}
|
|
|
|
|