[][src]Struct exonum_proto::ProtobufBase64

pub struct 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]

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]

Deserializes Vec<u8> using the provided serializer.

Trait Implementations

impl Debug for ProtobufBase64[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.