Files
accounts
async_stream
async_stream_impl
base64
blocks
bytes
cadence_json
cfg_if
collections
crunchy
darling
darling_core
darling_macro
events
flow_sdk
fnv
futures_channel
futures_core
futures_macro
futures_sink
futures_task
futures_timer
futures_util
gen_keypair
get_account_info
getrandom
h2
hashbrown
helloworld
hex
http
http_body
httparse
httpdate
hyper
hyper_timeout
ident_case
indexmap
instant
itoa
lazy_static
libc
lock_api
log
memchr
mio
num_bigint
num_cpus
num_integer
num_traits
once_cell
otopr
otopr_derive
parking_lot
parking_lot_core
parse_transaction_arguments
percent_encoding
pin_project
pin_project_internal
pin_project_lite
pin_utils
ppv_lite86
proc_macro2
proc_macro_hack
proc_macro_nested
quote
rand
rand_chacha
rand_core
rlp
rustc_hex
rustversion
ryu
scopeguard
scripts
secp256k1
secp256k1_sys
serde
serde_derive
serde_json
serde_with
serde_with_macros
signal_hook_registry
slab
smallvec
socket2
strsim
syn
thiserror
thiserror_impl
tiny_keccak
tokio
fs
future
io
loom
macros
net
park
process
runtime
signal
sync
task
time
util
tokio_io_timeout
tokio_macros
tokio_stream
tokio_util
tonic
tower
tower_layer
tower_service
tracing
tracing_attributes
tracing_core
tracing_futures
transactions
try_lock
unicode_xid
want
 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
78
79
80
81
82
83
84
use bytes::BufMut;

use crate::{
    decoding::{Decodable, DecodingError},
    encoding::Encodable,
    traits::Signable,
    wire_types::*,
    Fixed32, Fixed64, VarInt,
};

macro_rules! signable {
    ($($id:ident($storage: ty)),*) => {$(
        impl Signable for $id {
            type Storage = $storage;
            type From = Self;
            fn zigzag_encode(this: Self) -> $storage {
                const BITS_M1: u32 = <$id>::BITS - 1;
                ((this << 1) ^ (this >> BITS_M1)) as $storage
            }
        }
    )*};
    ($($id:ident($storage: ty) = $signed:ident),*) => {$(
        impl Signable for $id {
            type Storage = $storage;
            type From = $signed;
            fn zigzag_encode(this: $signed) -> $storage {
                const BITS_M1: u32 = <$signed>::BITS - 1;
                ((this << 1) ^ (this >> BITS_M1)) as $storage
            }
        }
    )*};
}

signable!(i32(u32), i64(u64));
signable!(Fixed32(u32) = i32, Fixed64(u32) = i64);

crate::seal! {
    for u64,
    for u32,
    for i64,
    for i32,
    for u16,
    for u8,
    for usize,
    for Fixed32,
    for Fixed64,
}

impl Encodable for str {
    type Wire = LengthDelimitedWire;

    fn encoded_size<V: VarInt>(&self, field_number: V) -> usize {
        field_number.size() + self.len().size() + self.len()
    }
    fn encode(&self, s: &mut crate::encoding::ProtobufSerializer<impl BufMut>) {
        s.write_str(self)
    }
}

impl Encodable for bool {
    type Wire = VarIntWire;

    fn encoded_size<V: VarInt>(&self, field_number: V) -> usize {
        field_number.size() + 1
    }

    fn encode(&self, s: &mut crate::encoding::ProtobufSerializer<impl BufMut>) {
        s.write_u8(*self as u8);
    }
}

impl Decodable<'_> for bool {
    type Wire = VarIntWire;

    fn decode<B: bytes::Buf>(
        deserializer: &mut crate::decoding::Deserializer<'_, B>,
    ) -> crate::decoding::Result<Self> {
        match deserializer.get_u8() {
            0b0000_0001 => Ok(true),
            0b0000_0000 => Ok(false),
            _ => Err(DecodingError::VarIntOverflow),
        }
    }
}