diff --git a/src/protobin.gleam b/src/protobin.gleam index f1227fb..32f7bb5 100644 --- a/src/protobin.gleam +++ b/src/protobin.gleam @@ -190,9 +190,10 @@ fn parse_varint_acc(bits: BitArray, acc: BitArray, pos: BytePos) -> ValueResult } } -/// Size must be a multiple of 8. +/// Size is in bits, usually either 32 or 64. +/// +/// Size must be a multiple of 8, or the returned position will be incorrect. pub fn read_fixed(size: Int) -> ValueParser { - assert size % 8 == 0 fn(bits: BitArray, pos: BytePos) -> ValueResult { case bits { <> -> @@ -211,9 +212,6 @@ fn read_len(bits: BitArray, len_pos: BytePos) -> ValueResult { )) let len = util.bit_array_to_uint(len) - // Just decoded a uint, so should be safe - assert len > 0 - use value <- result.try( bit_array.slice(from: bits, at: 0, take: len) |> result.map_error(fn(_) { diff --git a/src/protobin/internal/util.gleam b/src/protobin/internal/util.gleam index 8d91e7c..a958a15 100644 --- a/src/protobin/internal/util.gleam +++ b/src/protobin/internal/util.gleam @@ -3,6 +3,7 @@ import gleam/bit_array pub fn bit_array_to_uint(bits: BitArray) -> Int { let size = bit_array.bit_size(bits) // Interpert the entire bit array as an unsigned int + // It is impossible for this to crash, it interperts the entire bit array let assert <> = bits n }