add CBOR support to database schema
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
1f31e74024
commit
0c96891008
6 changed files with 60 additions and 2 deletions
|
@ -40,6 +40,8 @@ conduwuit-core.workspace = true
|
|||
const-str.workspace = true
|
||||
futures.workspace = true
|
||||
log.workspace = true
|
||||
minicbor.workspace = true
|
||||
minicbor-serde.workspace = true
|
||||
rust-rocksdb.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
|
|
@ -248,6 +248,10 @@ impl<'a, 'de: 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
|||
{
|
||||
match name {
|
||||
| "$serde_json::private::RawValue" => visitor.visit_map(self),
|
||||
| "Cbor" => visitor
|
||||
.visit_newtype_struct(&mut minicbor_serde::Deserializer::new(self.record_trail()))
|
||||
.map_err(|e| Self::Error::SerdeDe(e.to_string().into())),
|
||||
|
||||
| _ => visitor.visit_newtype_struct(self),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub use self::{
|
|||
handle::Handle,
|
||||
keyval::{serialize_key, serialize_val, KeyVal, Slice},
|
||||
map::{compact, Map},
|
||||
ser::{serialize, serialize_to, serialize_to_vec, Interfix, Json, Separator, SEP},
|
||||
ser::{serialize, serialize_to, serialize_to_vec, Cbor, Interfix, Json, Separator, SEP},
|
||||
};
|
||||
pub(crate) use self::{
|
||||
engine::{context::Context, Engine},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::io::Write;
|
||||
|
||||
use conduwuit::{debug::type_name, err, result::DebugInspect, utils::exchange, Error, Result};
|
||||
use serde::{ser, Serialize};
|
||||
use serde::{ser, Deserialize, Serialize};
|
||||
|
||||
use crate::util::unhandled;
|
||||
|
||||
|
@ -55,6 +55,10 @@ pub(crate) struct Serializer<'a, W: Write> {
|
|||
#[derive(Debug, Serialize)]
|
||||
pub struct Json<T>(pub T);
|
||||
|
||||
/// Newtype for CBOR serialization.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Cbor<T>(pub T);
|
||||
|
||||
/// Directive to force separator serialization specifically for prefix keying
|
||||
/// use. This is a quirk of the database schema and prefix iterations.
|
||||
#[derive(Debug, Serialize)]
|
||||
|
@ -189,6 +193,14 @@ impl<W: Write> ser::Serializer for &mut Serializer<'_, W> {
|
|||
|
||||
match name {
|
||||
| "Json" => serde_json::to_writer(&mut self.out, value).map_err(Into::into),
|
||||
| "Cbor" => {
|
||||
use minicbor::encode::write::Writer;
|
||||
use minicbor_serde::Serializer;
|
||||
|
||||
value
|
||||
.serialize(&mut Serializer::new(&mut Writer::new(&mut self.out)))
|
||||
.map_err(|e| Self::Error::SerdeSer(e.to_string().into()))
|
||||
},
|
||||
| _ => unhandled!("Unrecognized serialization Newtype {name:?}"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue