From f7be3e127a481808b40f355ae6edb27eecc6dde3 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Wed, 19 Jun 2024 18:29:34 -0400 Subject: [PATCH] add `BinaryString` --- rpc/types/README.md | 6 ++++-- rpc/types/src/data.rs | 11 ----------- rpc/types/src/data/binary_string.rs | 29 +++++++++++++++++++++++++++++ rpc/types/src/data/mod.rs | 6 ++++++ rpc/types/src/lib.rs | 8 +++----- 5 files changed, 42 insertions(+), 18 deletions(-) delete mode 100644 rpc/types/src/data.rs create mode 100644 rpc/types/src/data/binary_string.rs create mode 100644 rpc/types/src/data/mod.rs diff --git a/rpc/types/README.md b/rpc/types/README.md index 6dc269f..b783a34 100644 --- a/rpc/types/README.md +++ b/rpc/types/README.md @@ -46,15 +46,17 @@ TODO: fix doc links when types are ready. # Mixed types Note that some types within [`other`] mix JSON & binary together, i.e., the message overall is JSON, however some fields contain binary -values, for example: +values inside JSON strings, for example: ```json { "string": "", "float": 30.0, "integer": 30, - "binary": /* serialized binary */ + "binary": "" } ``` +`binary` here is (de)serialized as a normal [`String`]. In order to be clear on which fields contain binary data, the struct fields that have them will use [`crate::data::BinaryString`] instead of [`String`]. + TODO: list the specific types. \ No newline at end of file diff --git a/rpc/types/src/data.rs b/rpc/types/src/data.rs deleted file mode 100644 index 8b7548f..0000000 --- a/rpc/types/src/data.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Data structures that appear in other types. - -//---------------------------------------------------------------------------------------------------- Import - -//---------------------------------------------------------------------------------------------------- TODO - -//---------------------------------------------------------------------------------------------------- Tests -#[cfg(test)] -mod test { - // use super::*; -} diff --git a/rpc/types/src/data/binary_string.rs b/rpc/types/src/data/binary_string.rs new file mode 100644 index 0000000..68fdfdb --- /dev/null +++ b/rpc/types/src/data/binary_string.rs @@ -0,0 +1,29 @@ +//! TODO + +//---------------------------------------------------------------------------------------------------- Import + +//---------------------------------------------------------------------------------------------------- BinaryString +/// TODO +/// +/// ```rust +/// use serde::Deserialize; +/// use serde_json::from_str; +/// use cuprate_rpc_types::data::BinaryString; +/// +/// #[derive(Deserialize)] +/// struct Key { +/// key: BinaryString, +/// } +/// +/// let binary = r"�\b����������"; +/// let json = format!("{{\"key\":\"{binary}\"}}"); +/// let key = from_str::(&json).unwrap(); +/// let binary: BinaryString = key.key; +/// ``` +pub type BinaryString = String; + +//---------------------------------------------------------------------------------------------------- Tests +#[cfg(test)] +mod test { + // use super::*; +} diff --git a/rpc/types/src/data/mod.rs b/rpc/types/src/data/mod.rs new file mode 100644 index 0000000..a7a3609 --- /dev/null +++ b/rpc/types/src/data/mod.rs @@ -0,0 +1,6 @@ +//! Data structures that appear in other types. +//! +//! TODO + +mod binary_string; +pub use binary_string::BinaryString; diff --git a/rpc/types/src/lib.rs b/rpc/types/src/lib.rs index c3d7841..ec5f4c6 100644 --- a/rpc/types/src/lib.rs +++ b/rpc/types/src/lib.rs @@ -95,14 +95,12 @@ )] //---------------------------------------------------------------------------------------------------- Use -// Misc types. +mod macros; mod status; + pub use status::Status; -// Internal modules. -mod macros; - -// Request/response JSON/binary/other types. pub mod bin; +pub mod data; pub mod json; pub mod other;