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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/// Encodes a 64-bit unsigned integer (`u64`) into its varint representation.
///
/// Varints are a compact encoding scheme for integers that uses a variable number of bytes
/// depending on the magnitude of the value. Smaller values require fewer bytes for encoding.
///
/// The encoding process follows these steps:
/// 1. Take the least significant 7 bits of the value and set the most significant bit to 0.
/// 2. If there are remaining bits in the value, set the most significant bit of the current byte to 1.
/// 3. Append the current byte to the buffer.
/// 4. Shift the value right by 7 bits.
/// 5. Repeat steps 1-4 until the value becomes 0.
///
/// # Arguments
///
/// * `value` - The `u64` value to be encoded as a varint.
///
/// # Returns
///
/// A `Vec<u8>` containing the varint-encoded bytes of the input value.
///
/// # Example
///
/// ```
/// use rustwire::encode_varint;
///
/// let value: u64 = 42;
/// let encoded = encode_varint(value);
/// assert_eq!(encoded, vec![0x2A]);
/// ```
/// Encodes a single-precision floating-point number (`f32`) into its binary representation.
///
/// The encoding process converts the `f32` value into its little-endian byte representation
/// and appends the bytes to a buffer.
///
/// # Arguments
///
/// * `value` - The `f32` value to be encoded.
///
/// # Returns
///
/// A `Vec<u8>` containing the binary representation of the input `f32` value.
///
/// # Example
///
/// ```
/// use rustwire::encode_float;
///
/// let value: f32 = 3.14;
/// let encoded = encode_float(value);
/// assert_eq!(encoded, vec![0xC3, 0xF5, 0x48, 0x40]);
/// ```
/// Encodes a double-precision floating-point number (`f64`) into its binary representation.
///
/// The encoding process converts the `f64` value into its little-endian byte representation
/// and appends the bytes to a buffer.
///
/// # Arguments
///
/// * `value` - The `f64` value to be encoded.
///
/// # Returns
///
/// A `Vec<u8>` containing the binary representation of the input `f64` value.
///
/// # Example
///
/// ```
/// use rustwire::encode_double;
///
/// let value: f64 = 2.71828;
/// let encoded = encode_double(value);
/// assert_eq!(encoded, vec![0x90, 0xF7, 0xAA, 0x95, 0x9, 0xBF, 0x5, 0x40]);
/// ```