diff options
author | Alex Auvolat <alex@adnab.me> | 2023-01-03 15:29:29 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-01-03 15:29:29 +0100 |
commit | a54b67740d08e3fabeb1652a1bed14d78fea4b74 (patch) | |
tree | dc672e5ff9ab83b95635f2ff30c17cd8c2bcedce | |
parent | 8d5505514f950dc1ca1249a3385c9913b5b5e8e0 (diff) | |
download | garage-a54b67740d08e3fabeb1652a1bed14d78fea4b74.tar.gz garage-a54b67740d08e3fabeb1652a1bed14d78fea4b74.zip |
move debug_serialize to garage_util::encode
-rw-r--r-- | src/table/sync.rs | 2 | ||||
-rw-r--r-- | src/util/data.rs | 16 | ||||
-rw-r--r-- | src/util/encode.rs | 16 | ||||
-rw-r--r-- | src/util/error.rs | 1 |
4 files changed, 18 insertions, 17 deletions
diff --git a/src/table/sync.rs b/src/table/sync.rs index c66c863f..1f23d3a1 100644 --- a/src/table/sync.rs +++ b/src/table/sync.rs @@ -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::*; diff --git a/src/util/data.rs b/src/util/data.rs index b2a52e25..3f61e301 100644 --- a/src/util/data.rs +++ b/src/util/data.rs @@ -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), - } -} diff --git a/src/util/encode.rs b/src/util/encode.rs index 724e482a..1cd3198f 100644 --- a/src/util/encode.rs +++ b/src/util/encode.rs @@ -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), + } +} diff --git a/src/util/error.rs b/src/util/error.rs index 9995c746..3fcee71d 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -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)] |