-module(types@vector). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([from_raw_data/2]). -export_type([vector/0]). -type vector() :: {vector, integer(), bitstring()}. -spec from_raw_data(integer(), bitstring()) -> {ok, vector()} | {error, binary()}. from_raw_data(Position, Raw_data) -> gleam@result:'try'( util:decode_u32leb128(Position, Raw_data), fun(_use0) -> {Vector_length, Vector_length_word_size} = _use0, gleam@bool:guard( ((Position + Vector_length_word_size) + Vector_length) > erlang:byte_size( Raw_data ), {error, <<<<<<<<"vector::from_raw_data: unexpected end of the vector's data. Expected = "/utf8, (gleam@int:to_string(Vector_length))/binary>>/binary, " bytes but got = "/utf8>>/binary, (gleam@int:to_string( (erlang:byte_size(Raw_data) - Vector_length_word_size) - Position ))/binary>>/binary, " bytes"/utf8>>}, fun() -> case gleam_stdlib:bit_array_slice( Raw_data, Position + Vector_length_word_size, Vector_length ) of {ok, Vector_data} -> {ok, {vector, Vector_length, Vector_data}}; {error, _} -> {error, <<"vector::from_raw_data: can't slice vector data"/utf8>>} end end ) end ).