This commit is contained in:
parent
d8ffd4a9bd
commit
a61dc3d878
1 changed files with 3 additions and 7 deletions
|
@ -102,7 +102,7 @@ fn decode_map(
|
|||
) -> DecoderResult(List(#(DecodedValue, DecodedValue))) {
|
||||
use #(length, rest) <- try(decode_int(bits))
|
||||
use #(entries, remainder) <- try(decode_next_n([], rest, length * 2))
|
||||
use pairs <- try(into_pairs(entries))
|
||||
use pairs <- try(into_pairs([], entries))
|
||||
Ok(#(pairs, remainder))
|
||||
}
|
||||
|
||||
|
@ -128,18 +128,14 @@ fn decode_simple(bits: BitArray) -> DecodeResult {
|
|||
}
|
||||
}
|
||||
|
||||
fn into_pairs(list: List(a)) -> Result(List(#(a, a)), DecodeError) {
|
||||
into_pairs_aggr([], list)
|
||||
}
|
||||
|
||||
fn into_pairs_aggr(
|
||||
fn into_pairs(
|
||||
accum: List(#(a, a)),
|
||||
remaining: List(a),
|
||||
) -> Result(List(#(a, a)), DecodeError) {
|
||||
case remaining {
|
||||
[] -> Ok(reverse(accum))
|
||||
[_] -> Error(Malformed)
|
||||
[key, value, ..rest] -> into_pairs_aggr([#(key, value), ..accum], rest)
|
||||
[key, value, ..rest] -> into_pairs([#(key, value), ..accum], rest)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue