use crate::{
db::{
cursor::{CursorBoundary, token::IndexRangeCursorAnchor},
direction::Direction,
},
value::Value,
};
use serde::{Deserialize, Serialize};
pub(in crate::db::cursor::token) const MAX_CONTINUATION_TOKEN_BYTES: usize = 8 * 1024;
pub(in crate::db::cursor::token) const MAX_GROUPED_CONTINUATION_TOKEN_BYTES: usize = 8 * 1024;
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub(in crate::db::cursor::token) struct ContinuationTokenWire {
pub(in crate::db::cursor::token) signature: [u8; 32],
pub(in crate::db::cursor::token) boundary: CursorBoundary,
#[serde(default)]
pub(in crate::db::cursor::token) direction: Direction,
#[serde(default)]
pub(in crate::db::cursor::token) initial_offset: u32,
#[serde(default)]
pub(in crate::db::cursor::token) index_range_anchor: Option<IndexRangeCursorAnchorWire>,
}
#[derive(Serialize)]
pub(in crate::db::cursor::token) struct ContinuationTokenWireRef<'a> {
pub(in crate::db::cursor::token) signature: [u8; 32],
pub(in crate::db::cursor::token) boundary: &'a CursorBoundary,
#[serde(default)]
pub(in crate::db::cursor::token) direction: Direction,
#[serde(default)]
pub(in crate::db::cursor::token) initial_offset: u32,
#[serde(default)]
pub(in crate::db::cursor::token) index_range_anchor: Option<IndexRangeCursorAnchorWireRef<'a>>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub(in crate::db::cursor::token) struct GroupedContinuationTokenWire {
pub(in crate::db::cursor::token) signature: [u8; 32],
pub(in crate::db::cursor::token) last_group_key: Vec<Value>,
#[serde(default)]
pub(in crate::db::cursor::token) direction: Direction,
#[serde(default)]
pub(in crate::db::cursor::token) initial_offset: u32,
}
#[derive(Serialize)]
pub(in crate::db::cursor::token) struct GroupedContinuationTokenWireRef<'a> {
pub(in crate::db::cursor::token) signature: [u8; 32],
pub(in crate::db::cursor::token) last_group_key: &'a [Value],
#[serde(default)]
pub(in crate::db::cursor::token) direction: Direction,
#[serde(default)]
pub(in crate::db::cursor::token) initial_offset: u32,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub(in crate::db::cursor::token) struct IndexRangeCursorAnchorWire {
last_raw_key: Vec<u8>,
}
#[derive(Serialize)]
pub(in crate::db::cursor::token) struct IndexRangeCursorAnchorWireRef<'a> {
last_raw_key: &'a [u8],
}
impl From<&IndexRangeCursorAnchor> for IndexRangeCursorAnchorWire {
fn from(anchor: &IndexRangeCursorAnchor) -> Self {
Self {
last_raw_key: anchor.last_raw_key().to_vec(),
}
}
}
impl<'a> From<&'a IndexRangeCursorAnchor> for IndexRangeCursorAnchorWireRef<'a> {
fn from(anchor: &'a IndexRangeCursorAnchor) -> Self {
Self {
last_raw_key: anchor.last_raw_key(),
}
}
}
impl IndexRangeCursorAnchorWire {
pub(in crate::db::cursor::token) fn into_anchor(self) -> IndexRangeCursorAnchor {
IndexRangeCursorAnchor::new(self.last_raw_key)
}
}