mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-24 06:49:38 -05:00
schema work
This commit is contained in:
parent
37ed0239f3
commit
b9aa268f71
@ -22,11 +22,13 @@ extension ValidateDFLT on DHTSchemaDFLT {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int subkeyCount() => oCnt;
|
||||
}
|
||||
|
||||
extension ValidateSMPL on DHTSchemaSMPL {
|
||||
bool validate() {
|
||||
final totalsv = members.fold(0, (acc, v) => acc + v.mCnt) + oCnt;
|
||||
final totalsv = subkeyCount();
|
||||
if (totalsv > 65535) {
|
||||
return false;
|
||||
}
|
||||
@ -35,6 +37,28 @@ extension ValidateSMPL on DHTSchemaSMPL {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int subkeyCount() => members.fold(0, (acc, v) => acc + v.mCnt) + oCnt;
|
||||
}
|
||||
|
||||
extension Validate on DHTSchema {
|
||||
bool validate() {
|
||||
if (this is DHTSchemaDFLT) {
|
||||
return (this as DHTSchemaDFLT).validate();
|
||||
} else if (this is DHTSchemaSMPL) {
|
||||
return (this as DHTSchemaSMPL).validate();
|
||||
}
|
||||
throw TypeError();
|
||||
}
|
||||
|
||||
int subkeyCount() {
|
||||
if (this is DHTSchemaDFLT) {
|
||||
return (this as DHTSchemaDFLT).subkeyCount();
|
||||
} else if (this is DHTSchemaSMPL) {
|
||||
return (this as DHTSchemaSMPL).subkeyCount();
|
||||
}
|
||||
throw TypeError();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -115,6 +139,14 @@ class ValueSubkeyRange with _$ValueSubkeyRange {
|
||||
_$ValueSubkeyRangeFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
extension ValueSubkeyRangeExt on ValueSubkeyRange {
|
||||
bool contains(int v) => low <= v && v <= high;
|
||||
}
|
||||
|
||||
extension ListValueSubkeyRangeExt on List<ValueSubkeyRange> {
|
||||
bool containsSubkey(int v) => indexWhere((e) => e.contains(v)) != -1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
/// ValueData
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user