From 9f8ef281de548f4711589b4b3aceffaf3fc293a2 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Fri, 23 Oct 2020 15:53:35 +0000 Subject: [PATCH] Store room user variable count under a room metadata space --- src/db.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/db.rs b/src/db.rs index 4bd4fc1..fb426c7 100644 --- a/src/db.rs +++ b/src/db.rs @@ -12,6 +12,7 @@ use zerocopy::{AsBytes, LayoutVerified}; /// read. type LittleEndianI32Layout<'a> = LayoutVerified<&'a [u8], I32>; +const METADATA_KEY: &'static str = "metadata"; const VARIABLE_COUNT_KEY: &'static str = "variable_count"; #[derive(Clone)] @@ -69,8 +70,17 @@ fn to_key(room_id: &str, username: &str, variable_name: &str) -> Vec { key } +fn metadata_key(room_id: &str, username: &str, metadata_key: &str) -> Vec { + let mut key = vec![]; + key.extend_from_slice(room_id.as_bytes()); + key.extend_from_slice(METADATA_KEY.as_bytes()); + key.extend_from_slice(username.as_bytes()); + key.extend_from_slice(metadata_key.as_bytes()); + key +} + fn room_variable_count_key(room_id: &str, username: &str) -> Vec { - to_key(room_id, username, VARIABLE_COUNT_KEY) + metadata_key(room_id, username, VARIABLE_COUNT_KEY) } fn to_prefix(room_id: &str, username: &str) -> Vec {