blob: 19696026cf45f36d881452e8f825af656a6679fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
-module (binary_native).
-export ([int_to_u32/1, int_from_u32/1, part/3]).
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}.
|