Current section
Files
Jump to
Current section
Files
src/util.erl
-module(util).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([decode_u32leb128/2]).
-spec decode_u32leb128(integer(), bitstring()) -> {ok, {integer(), integer()}} |
{error, binary()}.
decode_u32leb128(Position, Data) ->
U32leb128_max_length = 5,
Bytes_to_take = gleam@int:min(
U32leb128_max_length,
erlang:byte_size(Data) - Position
),
case gleam_stdlib:bit_array_slice(Data, Position, Bytes_to_take) of
{ok, U32leb128_raw_data} ->
gleam@result:'try'(
gleb128:decode_unsigned(U32leb128_raw_data),
fun(Section_length) -> {ok, Section_length} end
);
{error, _} ->
{error,
<<"util::decode_u32leb128: can't get section length raw data"/utf8>>}
end.