Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 40 lines (35 sloc) 1.208 kb
c6b257c @trung added mochiweb server to capture amf requests
authored
1 -module(uint29).
2 -compile(export_all).
3
4 encode_int29(I) when I >= -16#10000000, I < 0 ->
5 encode_uint29(16#20000000 + I);
6 encode_int29(I) when I =< 16#0FFFFFFF ->
7 encode_uint29(I);
8 encode_int29(_) ->
9 throw(badrange).
10
11 encode_uint29(I) when I >= 16#00000000, I =< 16#0000007F ->
12 <<I>>;
13 encode_uint29(I) when I >= 16#00000080, I =< 16#00003FFF ->
14 X1 = 16#80 bor (I bsr 7),
15 X2 = I band 16#7F,
16 <<X1, X2>>;
17 encode_uint29(I) when I >= 16#00004000, I =< 16#001FFFFF ->
18 X1 = 16#80 bor (I bsr 14),
19 X2 = 16#80 bor (I bsr 7),
20 X3 = I band 16#7F,
21 <<X1, X2, X3>>;
22 encode_uint29(I) when I >= 16#00200000, I =< 16#1FFFFFFF ->
23 X1 = 16#80 bor (I bsr 22),
24 X2 = 16#80 bor (I bsr 15),
25 X3 = 16#80 bor (I bsr 8),
26 X4 = I band 16#FF,
27 <<X1, X2, X3, X4>>;
28 encode_uint29(_) ->
29 throw(badrange).
30
31 decode_uint29(Data) ->
32 decode_uint29(Data, 0, 0).
33
34 decode_uint29(<<1:1, Num:7, Data/binary>>, Result, N) when N < 3 ->
35 decode_uint29(Data, (Result bsl 7) bor Num, N + 1);
36 decode_uint29(<<0:1, Num:7, Data/binary>>, Result, N) when N < 3 ->
37 {(Result bsl 7) bor Num, Data};
38 decode_uint29(<<Byte, Data/binary>>, Result, _N) ->
39 {(Result bsl 8) bor Byte, Data}.
Something went wrong with that request. Please try again.