aboutsummaryrefslogtreecommitdiff
path: root/src/gleam/binary_native.erl
blob: c7dfad784c03f133ed6afcbdb56f2e676f8fc267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-module (binary_native).
-export ([int_to_u32/1, int_from_u32/1, append/2, part/3]).

append(First, Second) ->
  <<First/binary, Second/binary>>.

part(Bin, Pos, Len) ->
  try {ok, binary:part(Bin, Pos, Len)} catch
    error:badarg -> {error, nil}
  end.

int_to_u32(I) when 0 =< I, I < 4294967296 ->
  {ok, <<I:32>>};
int_to_u32(_) ->
  {error, nil}.

int_from_u32(<<I:32>>) ->
  {ok, I};
int_from_u32(_) ->
  {error, nil}.