storage manager work
This commit is contained in:
@@ -2434,6 +2434,7 @@ pub struct DHTSchemaDFLT {
|
||||
}
|
||||
|
||||
impl DHTSchemaDFLT {
|
||||
/// Build the data representation of the schema
|
||||
pub fn compile(&self) -> Vec<u8> {
|
||||
let mut out = Vec::<u8>::with_capacity(6);
|
||||
// kind
|
||||
@@ -2442,6 +2443,11 @@ impl DHTSchemaDFLT {
|
||||
out.extend_from_slice(&self.o_cnt.to_le_bytes());
|
||||
out
|
||||
}
|
||||
|
||||
/// Get the number of subkeys this schema allocates
|
||||
pub fn subkey_count(&self) -> usize {
|
||||
self.o_cnt as usize
|
||||
}
|
||||
}
|
||||
|
||||
/// Simple DHT Schema (SMPL) Member
|
||||
@@ -2469,6 +2475,7 @@ pub struct DHTSchemaSMPL {
|
||||
}
|
||||
|
||||
impl DHTSchemaSMPL {
|
||||
/// Build the data representation of the schema
|
||||
pub fn compile(&self) -> Vec<u8> {
|
||||
let mut out = Vec::<u8>::with_capacity(6 + (self.members.len() * (PUBLIC_KEY_LENGTH + 2)));
|
||||
// kind
|
||||
@@ -2484,6 +2491,13 @@ impl DHTSchemaSMPL {
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Get the number of subkeys this schema allocates
|
||||
pub fn subkey_count(&self) -> usize {
|
||||
self.members
|
||||
.iter()
|
||||
.fold(o_cnt as usize, |acc, x| acc + (x.m_cnt as usize))
|
||||
}
|
||||
}
|
||||
|
||||
/// Enum over all the supported DHT Schemas
|
||||
@@ -2505,12 +2519,21 @@ impl DHTSchema {
|
||||
DHTSchema::SMPL(DHTSchemaSMPL { o_cnt, members })
|
||||
}
|
||||
|
||||
/// Build the data representation of the schema
|
||||
pub fn compile(&self) -> Vec<u8> {
|
||||
match self {
|
||||
DHTSchema::DFLT(d) => d.compile(),
|
||||
DHTSchema::SMPL(s) => s.compile(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the number of subkeys this schema allocates
|
||||
pub fn subkey_count(&self) -> usize {
|
||||
match self {
|
||||
DHTSchema::DFLT(d) => d.subkey_count(),
|
||||
DHTSchema::SMPL(s) => s.subkey_count(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// DHT Key Descriptor
|
||||
|
||||
Reference in New Issue
Block a user