mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-07 03:19:43 +00:00
add BinaryString
This commit is contained in:
parent
15a80be526
commit
f7be3e127a
5 changed files with 42 additions and 18 deletions
|
@ -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.
|
|
@ -1,11 +0,0 @@
|
||||||
//! Data structures that appear in other types.
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TODO
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Tests
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
// use super::*;
|
|
||||||
}
|
|
29
rpc/types/src/data/binary_string.rs
Normal file
29
rpc/types/src/data/binary_string.rs
Normal 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::*;
|
||||||
|
}
|
6
rpc/types/src/data/mod.rs
Normal file
6
rpc/types/src/data/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
//! Data structures that appear in other types.
|
||||||
|
//!
|
||||||
|
//! TODO
|
||||||
|
|
||||||
|
mod binary_string;
|
||||||
|
pub use binary_string::BinaryString;
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue