mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-07-28 01:15:23 -04:00
schema work
This commit is contained in:
parent
37ed0239f3
commit
b9aa268f71
1 changed files with 33 additions and 1 deletions
|
@ -22,11 +22,13 @@ extension ValidateDFLT on DHTSchemaDFLT {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int subkeyCount() => oCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ValidateSMPL on DHTSchemaSMPL {
|
extension ValidateSMPL on DHTSchemaSMPL {
|
||||||
bool validate() {
|
bool validate() {
|
||||||
final totalsv = members.fold(0, (acc, v) => acc + v.mCnt) + oCnt;
|
final totalsv = subkeyCount();
|
||||||
if (totalsv > 65535) {
|
if (totalsv > 65535) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +37,28 @@ extension ValidateSMPL on DHTSchemaSMPL {
|
||||||
}
|
}
|
||||||
return true;
|
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>);
|
_$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
|
/// ValueData
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue