pub struct ProtobufBase64(/* private fields */);
Expand description
Marker type for use with #[serde(with)]
, which provides Protobuf-compatible base64 encoding
and decoding. For now, works only on Vec<u8>
fields.
The encoder uses the standard base64 alphabet (i.e., 0..9A..Za..z+/
) with no padding.
The decoder accepts any of the 4 possible combinations: the standard or the URL-safe alphabet
with or without padding.
If the (de)serializer is not human-readable (e.g., CBOR or bincode
), the bytes will be
(de)serialized without base64 transform, directly as a byte slice.
§Examples
use exonum_proto::ProtobufBase64;
#[derive(Serialize, Deserialize)]
struct Test {
/// Corresponds to a `bytes buffer = ...` field in Protobuf.
#[serde(with = "ProtobufBase64")]
buffer: Vec<u8>,
// other fields...
}
let test = Test {
buffer: b"Hello!".to_vec(),
// ...
};
let obj = serde_json::to_value(&test)?;
assert_eq!(obj, json!({ "buffer": "SGVsbG8h", /* ... */ }));
Implementations§
Source§impl ProtobufBase64
impl ProtobufBase64
Sourcepub fn serialize<S, T>(bytes: &T, serializer: S) -> Result<S::Ok, S::Error>
pub fn serialize<S, T>(bytes: &T, serializer: S) -> Result<S::Ok, S::Error>
Serializes the provided bytes
with the serializer
.
Sourcepub fn decode(value: &str) -> Result<Vec<u8>, DecodeError>
pub fn decode(value: &str) -> Result<Vec<u8>, DecodeError>
Decodes bytes from any of four base64 variations supported as per Protobuf spec (standard or URL-safe alphabet, with or without padding).
Sourcepub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>where
D: Deserializer<'de>,
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>where
D: Deserializer<'de>,
Deserializes Vec<u8>
using the provided serializer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ProtobufBase64
impl RefUnwindSafe for ProtobufBase64
impl Send for ProtobufBase64
impl Sync for ProtobufBase64
impl Unpin for ProtobufBase64
impl UnwindSafe for ProtobufBase64
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more