mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-28 02:51:00 +00:00
move debug_serialize to garage_util::encode
This commit is contained in:
parent
8d5505514f
commit
a54b67740d
4 changed files with 18 additions and 17 deletions
|
@ -14,7 +14,7 @@ use tokio::sync::{mpsc, watch};
|
|||
|
||||
use garage_util::background::*;
|
||||
use garage_util::data::*;
|
||||
use garage_util::encode::nonversioned_encode;
|
||||
use garage_util::encode::{nonversioned_encode, debug_serialize};
|
||||
use garage_util::error::{Error, OkOrMessage};
|
||||
|
||||
use garage_rpc::ring::*;
|
||||
|
|
|
@ -140,19 +140,3 @@ pub fn fasthash(data: &[u8]) -> FastHash {
|
|||
pub fn gen_uuid() -> Uuid {
|
||||
rand::thread_rng().gen::<[u8; 32]>().into()
|
||||
}
|
||||
|
||||
/// Serialize to JSON, truncating long result
|
||||
pub fn debug_serialize<T: Serialize>(x: T) -> String {
|
||||
match serde_json::to_string(&x) {
|
||||
Ok(ss) => {
|
||||
if ss.len() > 100 {
|
||||
// TODO this can panic if 100 is not a codepoint boundary, but inside a 2 Bytes
|
||||
// (or more) codepoint
|
||||
ss[..100].to_string()
|
||||
} else {
|
||||
ss
|
||||
}
|
||||
}
|
||||
Err(e) => format!("<JSON serialization error: {}>", e),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,3 +24,19 @@ where
|
|||
{
|
||||
rmp_serde::decode::from_read_ref::<_, T>(bytes)
|
||||
}
|
||||
|
||||
/// Serialize to JSON, truncating long result
|
||||
pub fn debug_serialize<T: Serialize>(x: T) -> String {
|
||||
match serde_json::to_string(&x) {
|
||||
Ok(ss) => {
|
||||
if ss.len() > 100 {
|
||||
// TODO this can panic if 100 is not a codepoint boundary, but inside a 2 Bytes
|
||||
// (or more) codepoint
|
||||
ss[..100].to_string()
|
||||
} else {
|
||||
ss
|
||||
}
|
||||
}
|
||||
Err(e) => format!("<JSON serialization error: {}>", e),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use err_derive::Error;
|
|||
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use crate::data::*;
|
||||
use crate::encode::debug_serialize;
|
||||
|
||||
/// Regroup all Garage errors
|
||||
#[derive(Debug, Error)]
|
||||
|
|
Loading…
Reference in a new issue