[−][src]Struct exonum_proto::ProtobufBase64
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", /* ... */ }));
Methods
impl ProtobufBase64
[src]
pub fn serialize<S, T: ?Sized>(
bytes: &T,
serializer: S
) -> Result<S::Ok, S::Error> where
S: Serializer,
T: AsRef<[u8]>,
[src]
bytes: &T,
serializer: S
) -> Result<S::Ok, S::Error> where
S: Serializer,
T: AsRef<[u8]>,
Serializes the provided bytes
with the serializer
.
pub fn decode(value: &str) -> Result<Vec<u8>, DecodeError>
[src]
Decodes bytes from any of four base64 variations supported as per Protobuf spec (standard or URL-safe alphabet, with or without padding).
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Deserializes Vec<u8>
using the provided serializer.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ProtobufBase64
impl Send for ProtobufBase64
impl Sync for ProtobufBase64
impl Unpin for ProtobufBase64
impl UnwindSafe for ProtobufBase64
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,