Skip to main content

reddb_server/wire/
protocol.rs

1//! Server-side adapter for the legacy RedDB binary protocol.
2//!
3//! The byte-level contract lives in `reddb-wire::legacy`. This module
4//! only converts between protocol `WireValue` and engine `Value`.
5
6use crate::storage::schema::Value;
7use reddb_wire::legacy::WireValue;
8
9// The `WireValue`<->`Value` conversion impls moved to `reddb-wire`'s
10// `legacy` module (ADR 0052, #1061): once `Value` was re-homed to the
11// keystone crate below wire, the orphan rule required those impls to live
12// in `WireValue`'s home crate. The helper functions below still drive the
13// legacy codec and rely on those impls being in scope via `reddb_wire`.
14
15#[inline]
16pub fn encode_value(buf: &mut Vec<u8>, value: &Value) {
17    reddb_wire::legacy::encode_value(buf, &WireValue::from(value));
18}
19
20#[inline]
21pub fn decode_value(data: &[u8], pos: &mut usize) -> Value {
22    try_decode_value(data, pos).unwrap_or(Value::Null)
23}
24
25#[inline]
26pub fn try_decode_value(data: &[u8], pos: &mut usize) -> Result<Value, &'static str> {
27    let value = reddb_wire::legacy::try_decode_value(data, pos)?;
28    Value::try_from(value)
29}