1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! The adapters and encodings for bytes (see [`adapters`](super#bytes)).
use String;
use Vec;
use crateBytesFormat;
use crateState;
use crateError;
pub use ;
pub use ;
pub use ;
pub use decode_base64;
/// An encoding of bytes as string.
///
/// Encodings are types which are not instantiated. They are used with
/// [`BytesFormat::encoded`] and every encoding is an adapter which
/// represents bytes as strings in the encoding (see the
/// [adapters documentation](super#bytes)). With [`BytesFallback`] the encoding is
/// only used in formats without native bytes.
///
/// ```
/// use deser::adapters::BytesEncoding;
/// use deser::{Error, ErrorKind};
///
/// /// Writes bytes as decimal numbers separated by dots.
/// pub struct Dotted;
///
/// impl BytesEncoding for Dotted {
/// const NAME: &'static str = "dotted";
///
/// fn encode(bytes: &[u8], out: &mut String) {
/// for (idx, byte) in bytes.iter().enumerate() {
/// if idx > 0 {
/// out.push('.');
/// }
/// out.push_str(&byte.to_string());
/// }
/// }
///
/// fn decode(s: &str) -> Result<Vec<u8>, Error> {
/// if s.is_empty() {
/// return Ok(Vec::new());
/// }
/// s.split('.')
/// .map(|x| {
/// x.parse().map_err(|_| {
/// Error::new(ErrorKind::InvalidValue, "invalid byte")
/// })
/// })
/// .collect()
/// }
/// }
/// ```
/// Decodes a string into bytes with the format in the state.
pub