Store room user variable count under a room metadata space

This commit is contained in:
projectmoon 2020-10-23 15:53:35 +00:00 committed by ProjectMoon
parent d482046b9b
commit 9f8ef281de
1 changed files with 11 additions and 1 deletions

View File

@ -12,6 +12,7 @@ use zerocopy::{AsBytes, LayoutVerified};
/// read. /// read.
type LittleEndianI32Layout<'a> = LayoutVerified<&'a [u8], I32<LittleEndian>>; type LittleEndianI32Layout<'a> = LayoutVerified<&'a [u8], I32<LittleEndian>>;
const METADATA_KEY: &'static str = "metadata";
const VARIABLE_COUNT_KEY: &'static str = "variable_count"; const VARIABLE_COUNT_KEY: &'static str = "variable_count";
#[derive(Clone)] #[derive(Clone)]
@ -69,8 +70,17 @@ fn to_key(room_id: &str, username: &str, variable_name: &str) -> Vec<u8> {
key key
} }
fn metadata_key(room_id: &str, username: &str, metadata_key: &str) -> Vec<u8> {
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<u8> { fn room_variable_count_key(room_id: &str, username: &str) -> Vec<u8> {
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<u8> { fn to_prefix(room_id: &str, username: &str) -> Vec<u8> {