mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-01-18 19:27:05 +00:00
dbe67c2f81
Co-authored-by: John Maguire <contact@johnmaguire.me>
27 lines
418 B
Dart
27 lines
418 B
Dart
class CIDR {
|
|
CIDR({this.ip = '', this.bits = 0});
|
|
|
|
String ip;
|
|
int bits;
|
|
|
|
@override
|
|
String toString() {
|
|
return '$ip/$bits';
|
|
}
|
|
|
|
String toJson() {
|
|
return toString();
|
|
}
|
|
|
|
factory CIDR.fromString(String val) {
|
|
final parts = val.split('/');
|
|
if (parts.length != 2) {
|
|
throw 'Invalid CIDR string';
|
|
}
|
|
|
|
return CIDR(
|
|
ip: parts[0],
|
|
bits: int.parse(parts[1]),
|
|
);
|
|
}
|
|
}
|