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
// ---------------- [ File: bitcoin-asmap/src/bits.rs ]
/*!
This function, `decode_bits`, decodes a value from
a provided iterator of boolean values using the
given bit sizes. The iterator `bitpos` represents
the current position in the ASMAP data, and
`endpos` represents the end position of the
data. The `minval` parameter is the minimum value
of the decoded result, and the `bit_sizes` vector
contains the list of bit sizes to be used for
decoding. The purpose of this function is to
decode a value from the compact representation in
the ASMAP data.
Here's a brief explanation of the C++ code:
1. It initializes the `val` variable with the
provided `minval`.
2. It iterates through the `bit_sizes` vector,
using a nested loop to decode the value based
on the bits in the ASMAP data.
3. If the iterator reaches the end position
(`endpos`) during decoding, it returns
`INVALID`. This means that the decoding has
reached the end of the file or an unexpected
position, and the resulting value is considered
invalid.
4. If the decoding completes successfully, it
returns the decoded value `val`.
In Rust, the `decode_bits` function will have
a similar structure. It will decode a value from
the given iterator, end position, minimum value,
and bit sizes vector. The `todo!();` macro is
a placeholder that should be replaced with the
Rust implementation that follows the same logic as
the C++ code provided.
*/
crateix!;
/// Core bit‑stream decoder, mirroring the C++ implementation in behaviour.