aboutsummaryrefslogtreecommitdiff
path: root/database/src/kv/binning.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-02-18 13:24:44 +0100
committermetamuffin <metamuffin@disroot.org>2026-02-18 13:24:44 +0100
commit3bbedf5ab337d8c6d608ed0b24b9c656b0ee1004 (patch)
treebf0cda90ed493af37569a7b3f27374decfcddb10 /database/src/kv/binning.rs
parentb176a9f7c36bf26f0e42d8b1bc30e214de9f14c9 (diff)
downloadjellything-3bbedf5ab337d8c6d608ed0b24b9c656b0ee1004.tar
jellything-3bbedf5ab337d8c6d608ed0b24b9c656b0ee1004.tar.bz2
jellything-3bbedf5ab337d8c6d608ed0b24b9c656b0ee1004.tar.zst
dynamic typed db match values
Diffstat (limited to 'database/src/kv/binning.rs')
-rw-r--r--database/src/kv/binning.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/database/src/kv/binning.rs b/database/src/kv/binning.rs
index 42e58fc..c41d6e9 100644
--- a/database/src/kv/binning.rs
+++ b/database/src/kv/binning.rs
@@ -4,7 +4,7 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use crate::Filter;
+use crate::{Filter, Value};
use jellyobject::{Object, Path};
/// Sorted list of components to bin objects by filtered values.
@@ -88,8 +88,7 @@ impl Filter {
Filter::Match(path, value) => {
vec![vec![(BinningComponent::Match(path.to_owned()), {
let mut co = Vec::new();
- co.extend((value.len() as u32).to_be_bytes());
- co.extend(value);
+ value.write_with_len(&mut co);
co
})]]
}
@@ -100,6 +99,37 @@ impl Filter {
}
}
+impl Value {
+ pub fn write_with_len(&self, out: &mut Vec<u8>) {
+ match self {
+ Value::Tag(tag) => {
+ out.extend(4u32.to_be_bytes());
+ out.extend(tag.0.to_be_bytes());
+ }
+ Value::U32(x) => {
+ out.extend(4u32.to_be_bytes());
+ out.extend(x.to_be_bytes());
+ }
+ Value::U64(x) => {
+ out.extend(8u32.to_be_bytes());
+ out.extend(x.to_be_bytes());
+ }
+ Value::I64(x) => {
+ out.extend(8u32.to_be_bytes());
+ out.extend(x.to_be_bytes());
+ }
+ Value::String(s) => {
+ out.extend((s.len() as u32).to_be_bytes());
+ out.extend(s.as_bytes());
+ }
+ Value::Binary(s) => {
+ out.extend((s.len() as u32).to_be_bytes());
+ out.extend(s);
+ }
+ }
+ }
+}
+
#[cfg(test)]
mod test {
use jellyobject::{Path, Tag};