store: bring back old key methods to reproduce data migration
This commit is contained in:
@@ -32,6 +32,39 @@ pub mod pmmr;
|
||||
pub mod prune_list;
|
||||
pub mod types;
|
||||
|
||||
const SEP: u8 = b':';
|
||||
|
||||
use byteorder::{BigEndian, WriteBytesExt};
|
||||
|
||||
/// Build a db key from a prefix and a byte vector identifier.
|
||||
pub fn to_key<K: AsRef<[u8]>>(prefix: u8, k: K) -> Vec<u8> {
|
||||
let k = k.as_ref();
|
||||
let mut res = Vec::with_capacity(k.len() + 2);
|
||||
res.push(prefix);
|
||||
res.push(SEP);
|
||||
res.extend_from_slice(k);
|
||||
res
|
||||
}
|
||||
|
||||
/// Build a db key from a prefix and a byte vector identifier and numeric identifier
|
||||
pub fn to_key_u64<K: AsRef<[u8]>>(prefix: u8, k: K, val: u64) -> Vec<u8> {
|
||||
let k = k.as_ref();
|
||||
let mut res = Vec::with_capacity(k.len() + 10);
|
||||
res.push(prefix);
|
||||
res.push(SEP);
|
||||
res.extend_from_slice(k);
|
||||
res.write_u64::<BigEndian>(val).unwrap();
|
||||
res
|
||||
}
|
||||
/// Build a db key from a prefix and a numeric identifier.
|
||||
pub fn u64_to_key(prefix: u8, val: u64) -> Vec<u8> {
|
||||
let mut res = Vec::with_capacity(10);
|
||||
res.push(prefix);
|
||||
res.push(SEP);
|
||||
res.write_u64::<BigEndian>(val).unwrap();
|
||||
res
|
||||
}
|
||||
|
||||
pub use crate::lmdb::*;
|
||||
|
||||
use std::ffi::OsStr;
|
||||
|
||||
Reference in New Issue
Block a user