blob: dde067f322b2ff0d81e0ec18d6d678ecad1a9140 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use crate::RowNum;
use anyhow::Result;
pub fn write_counter(txn: &mut dyn jellykv::Transaction, t: &[u8], value: u64) -> Result<()> {
txn.set(t, &value.to_be_bytes())
}
pub fn read_counter(txn: &dyn jellykv::Transaction, t: &[u8], default: u64) -> Result<u64> {
Ok(txn
.get(t)?
.map(|k| k.as_slice().try_into().map(RowNum::from_be_bytes).ok())
.flatten()
.unwrap_or(default))
}
|