add BinaryString

This commit is contained in:
hinto.janai 2024-06-19 18:29:34 -04:00
parent 15a80be526
commit f7be3e127a
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
5 changed files with 42 additions and 18 deletions

View file

@ -46,15 +46,17 @@ TODO: fix doc links when types are ready.
# Mixed types # Mixed types
Note that some types within [`other`] mix JSON & binary together, i.e., Note that some types within [`other`] mix JSON & binary together, i.e.,
the message overall is JSON, however some fields contain binary the message overall is JSON, however some fields contain binary
values, for example: values inside JSON strings, for example:
```json ```json
{ {
"string": "", "string": "",
"float": 30.0, "float": 30.0,
"integer": 30, "integer": 30,
"binary": /* serialized binary */ "binary": "<serialized 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. TODO: list the specific types.

View file

@ -1,11 +0,0 @@
//! Data structures that appear in other types.
//---------------------------------------------------------------------------------------------------- Import
//---------------------------------------------------------------------------------------------------- TODO
//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {
// use super::*;
}

View file

@ -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"<22>\b<><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
/// let json = format!("{{\"key\":\"{binary}\"}}");
/// let key = from_str::<Key>(&json).unwrap();
/// let binary: BinaryString = key.key;
/// ```
pub type BinaryString = String;
//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {
// use super::*;
}

View file

@ -0,0 +1,6 @@
//! Data structures that appear in other types.
//!
//! TODO
mod binary_string;
pub use binary_string::BinaryString;

View file

@ -95,14 +95,12 @@
)] )]
//---------------------------------------------------------------------------------------------------- Use //---------------------------------------------------------------------------------------------------- Use
// Misc types. mod macros;
mod status; mod status;
pub use status::Status; pub use status::Status;
// Internal modules.
mod macros;
// Request/response JSON/binary/other types.
pub mod bin; pub mod bin;
pub mod data;
pub mod json; pub mod json;
pub mod other; pub mod other;