2022-06-15 07:41:23 +00:00
|
|
|
use derive::Key;
|
2022-01-13 17:40:20 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-06-15 07:41:23 +00:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
2023-04-29 16:44:09 +00:00
|
|
|
pub struct Ev<'a> {
|
2022-03-16 15:33:43 +00:00
|
|
|
__: u8,
|
|
|
|
_a: u8,
|
2023-04-29 16:44:09 +00:00
|
|
|
pub ns: &'a str,
|
2022-03-16 15:33:43 +00:00
|
|
|
_b: u8,
|
2023-04-29 16:44:09 +00:00
|
|
|
pub db: &'a str,
|
2022-03-16 15:33:43 +00:00
|
|
|
_c: u8,
|
2023-04-29 16:44:09 +00:00
|
|
|
pub tb: &'a str,
|
2022-03-16 15:33:43 +00:00
|
|
|
_d: u8,
|
|
|
|
_e: u8,
|
|
|
|
_f: u8,
|
2023-04-29 16:44:09 +00:00
|
|
|
pub ev: &'a str,
|
2022-01-13 17:40:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-29 16:44:09 +00:00
|
|
|
pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ev: &'a str) -> Ev<'a> {
|
|
|
|
Ev::new(ns, db, tb, ev)
|
2022-01-13 17:40:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 07:21:22 +00:00
|
|
|
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
|
|
|
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
|
|
|
k.extend_from_slice(&[0x21, 0x65, 0x76, 0x00]);
|
|
|
|
k
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
|
|
|
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
|
|
|
k.extend_from_slice(&[0x21, 0x65, 0x76, 0xff]);
|
|
|
|
k
|
|
|
|
}
|
|
|
|
|
2023-04-29 16:44:09 +00:00
|
|
|
impl<'a> Ev<'a> {
|
|
|
|
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ev: &'a str) -> Self {
|
|
|
|
Self {
|
2022-03-16 15:33:43 +00:00
|
|
|
__: 0x2f, // /
|
|
|
|
_a: 0x2a, // *
|
2022-01-13 17:40:20 +00:00
|
|
|
ns,
|
2022-03-16 15:33:43 +00:00
|
|
|
_b: 0x2a, // *
|
2022-01-13 17:40:20 +00:00
|
|
|
db,
|
2022-03-16 15:33:43 +00:00
|
|
|
_c: 0x2a, // *
|
2022-01-13 17:40:20 +00:00
|
|
|
tb,
|
2022-03-16 15:33:43 +00:00
|
|
|
_d: 0x21, // !
|
|
|
|
_e: 0x65, // e
|
|
|
|
_f: 0x76, // v
|
2022-01-13 17:40:20 +00:00
|
|
|
ev,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn key() {
|
|
|
|
use super::*;
|
|
|
|
#[rustfmt::skip]
|
|
|
|
let val = Ev::new(
|
2023-04-29 16:44:09 +00:00
|
|
|
"test",
|
|
|
|
"test",
|
|
|
|
"test",
|
|
|
|
"test",
|
2022-01-13 17:40:20 +00:00
|
|
|
);
|
|
|
|
let enc = Ev::encode(&val).unwrap();
|
|
|
|
let dec = Ev::decode(&enc).unwrap();
|
|
|
|
assert_eq!(val, dec);
|
|
|
|
}
|
|
|
|
}
|