Replace local rlp with aeserialization repo. Use ref till first release is available.
This commit is contained in:
parent
c4410a2548
commit
d60eb5eab5
@ -3,10 +3,12 @@
|
|||||||
{erl_opts, [debug_info]}.
|
{erl_opts, [debug_info]}.
|
||||||
|
|
||||||
{deps, [ {eblake2, "1.0.0"}
|
{deps, [ {eblake2, "1.0.0"}
|
||||||
|
, {aeserialization, {git, "https://github.com/aeternity/aeserialization.git",
|
||||||
|
{ref, "b55c372"}}}
|
||||||
, {getopt, "1.0.1"}
|
, {getopt, "1.0.1"}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{escript_incl_apps, [aebytecode, eblake2, getopt]}.
|
{escript_incl_apps, [aebytecode, eblake2, aeserialization, getopt]}.
|
||||||
{escript_main_app, aebytecode}.
|
{escript_main_app, aebytecode}.
|
||||||
{escript_name, aefateasm}.
|
{escript_name, aefateasm}.
|
||||||
{escript_emu_args, "%%!"}.
|
{escript_emu_args, "%%!"}.
|
||||||
@ -30,6 +32,8 @@
|
|||||||
|
|
||||||
{profiles, [{binary, [
|
{profiles, [{binary, [
|
||||||
{deps, [ {eblake2, "1.0.0"}
|
{deps, [ {eblake2, "1.0.0"}
|
||||||
|
, {aeserialization, {git, "https://github.com/aeternity/aeserialization.git",
|
||||||
|
{ref, "b55c372"}}}
|
||||||
, {getopt, "1.0.1"}
|
, {getopt, "1.0.1"}
|
||||||
]},
|
]},
|
||||||
|
|
||||||
|
10
rebar.lock
10
rebar.lock
@ -1,5 +1,13 @@
|
|||||||
{"1.1.0",
|
{"1.1.0",
|
||||||
[{<<"eblake2">>,{pkg,<<"eblake2">>,<<"1.0.0">>},0},
|
[{<<"aeserialization">>,
|
||||||
|
{git,"https://github.com/aeternity/aeserialization.git",
|
||||||
|
{ref,"b55c3726f4a21063721c68d6fa7fda39121edf11"}},
|
||||||
|
0},
|
||||||
|
{<<"base58">>,
|
||||||
|
{git,"https://github.com/aeternity/erl-base58.git",
|
||||||
|
{ref,"60a335668a60328a29f9731b67c4a0e9e3d50ab6"}},
|
||||||
|
1},
|
||||||
|
{<<"eblake2">>,{pkg,<<"eblake2">>,<<"1.0.0">>},0},
|
||||||
{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}.
|
{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}.
|
||||||
[
|
[
|
||||||
{pkg_hash,[
|
{pkg_hash,[
|
||||||
|
@ -350,10 +350,10 @@ asm_to_bytecode(AssemblerCode, Options) ->
|
|||||||
Signatures = serialize_sigs(Env),
|
Signatures = serialize_sigs(Env),
|
||||||
SymbolTable = serialize_symbol_table(Env),
|
SymbolTable = serialize_symbol_table(Env),
|
||||||
Annotatations = serialize_annotations(Env),
|
Annotatations = serialize_annotations(Env),
|
||||||
ByteCode = << (aeb_rlp:encode(list_to_binary(ByteList)))/binary,
|
ByteCode = << (aeser_rlp:encode(list_to_binary(ByteList)))/binary,
|
||||||
(aeb_rlp:encode(list_to_binary(Signatures)))/binary,
|
(aeser_rlp:encode(list_to_binary(Signatures)))/binary,
|
||||||
(aeb_rlp:encode(SymbolTable))/binary,
|
(aeser_rlp:encode(SymbolTable))/binary,
|
||||||
(aeb_rlp:encode(Annotatations))/binary
|
(aeser_rlp:encode(Annotatations))/binary
|
||||||
>>,
|
>>,
|
||||||
|
|
||||||
case proplists:lookup(pp_hex_string, Options) of
|
case proplists:lookup(pp_hex_string, Options) of
|
||||||
@ -366,14 +366,14 @@ asm_to_bytecode(AssemblerCode, Options) ->
|
|||||||
{Env, ByteCode}.
|
{Env, ByteCode}.
|
||||||
|
|
||||||
strip(ByteCode) ->
|
strip(ByteCode) ->
|
||||||
{Code, _Rest} = aeb_rlp:decode_one(ByteCode),
|
{Code, _Rest} = aeser_rlp:decode_one(ByteCode),
|
||||||
Code.
|
Code.
|
||||||
|
|
||||||
bytecode_to_fate_code(Bytes, _Options) ->
|
bytecode_to_fate_code(Bytes, _Options) ->
|
||||||
{ByteCode, Rest1} = aeb_rlp:decode_one(Bytes),
|
{ByteCode, Rest1} = aeser_rlp:decode_one(Bytes),
|
||||||
{Signatures, Rest2} = aeb_rlp:decode_one(Rest1),
|
{Signatures, Rest2} = aeser_rlp:decode_one(Rest1),
|
||||||
{SymbolTable, Rest3} = aeb_rlp:decode_one(Rest2),
|
{SymbolTable, Rest3} = aeser_rlp:decode_one(Rest2),
|
||||||
{Annotations, <<>>} = aeb_rlp:decode_one(Rest3),
|
{Annotations, <<>>} = aeser_rlp:decode_one(Rest3),
|
||||||
|
|
||||||
Env1 = deserialize(ByteCode, #{ function => none
|
Env1 = deserialize(ByteCode, #{ function => none
|
||||||
, bb => 0
|
, bb => 0
|
||||||
|
@ -104,9 +104,9 @@ serialize(String) when ?IS_FATE_STRING(String),
|
|||||||
?FATE_STRING_SIZE(String) > 0,
|
?FATE_STRING_SIZE(String) > 0,
|
||||||
?FATE_STRING_SIZE(String) >= ?SHORT_STRING_SIZE ->
|
?FATE_STRING_SIZE(String) >= ?SHORT_STRING_SIZE ->
|
||||||
Bytes = ?FATE_STRING_VALUE(String),
|
Bytes = ?FATE_STRING_VALUE(String),
|
||||||
<<?LONG_STRING, (aeb_rlp:encode(Bytes))/binary>>;
|
<<?LONG_STRING, (aeser_rlp:encode(Bytes))/binary>>;
|
||||||
serialize(?FATE_ADDRESS(Address)) when is_binary(Address) ->
|
serialize(?FATE_ADDRESS(Address)) when is_binary(Address) ->
|
||||||
<<?ADDRESS, (aeb_rlp:encode(Address))/binary>>;
|
<<?ADDRESS, (aeser_rlp:encode(Address))/binary>>;
|
||||||
serialize(?FATE_TUPLE(T)) when size(T) > 0 ->
|
serialize(?FATE_TUPLE(T)) when size(T) > 0 ->
|
||||||
S = size(T),
|
S = size(T),
|
||||||
L = tuple_to_list(T),
|
L = tuple_to_list(T),
|
||||||
@ -148,7 +148,7 @@ serialize(?FATE_VARIANT(Size, Tag, Values)) when 0 =< Size
|
|||||||
%% -----------------------------------------------------
|
%% -----------------------------------------------------
|
||||||
|
|
||||||
rlp_integer(S) when S >= 0 ->
|
rlp_integer(S) when S >= 0 ->
|
||||||
aeb_rlp:encode(binary:encode_unsigned(S)).
|
aeser_rlp:encode(binary:encode_unsigned(S)).
|
||||||
|
|
||||||
serialize_integer(I) when ?IS_FATE_INTEGER(I) ->
|
serialize_integer(I) when ?IS_FATE_INTEGER(I) ->
|
||||||
V = ?FATE_INTEGER_VALUE(I),
|
V = ?FATE_INTEGER_VALUE(I),
|
||||||
@ -187,28 +187,28 @@ deserialize2(<<?POS_SIGN:1, I:6, ?SMALL_INT:1, Rest/binary>>) ->
|
|||||||
deserialize2(<<?NEG_SIGN:1, I:6, ?SMALL_INT:1, Rest/binary>>) ->
|
deserialize2(<<?NEG_SIGN:1, I:6, ?SMALL_INT:1, Rest/binary>>) ->
|
||||||
{?MAKE_FATE_INTEGER(-I), Rest};
|
{?MAKE_FATE_INTEGER(-I), Rest};
|
||||||
deserialize2(<<?NEG_BIG_INT, Rest/binary>>) ->
|
deserialize2(<<?NEG_BIG_INT, Rest/binary>>) ->
|
||||||
{Bint, Rest2} = aeb_rlp:decode_one(Rest),
|
{Bint, Rest2} = aeser_rlp:decode_one(Rest),
|
||||||
{?MAKE_FATE_INTEGER(-binary:decode_unsigned(Bint) - ?SMALL_INT_SIZE),
|
{?MAKE_FATE_INTEGER(-binary:decode_unsigned(Bint) - ?SMALL_INT_SIZE),
|
||||||
Rest2};
|
Rest2};
|
||||||
deserialize2(<<?POS_BIG_INT, Rest/binary>>) ->
|
deserialize2(<<?POS_BIG_INT, Rest/binary>>) ->
|
||||||
{Bint, Rest2} = aeb_rlp:decode_one(Rest),
|
{Bint, Rest2} = aeser_rlp:decode_one(Rest),
|
||||||
{?MAKE_FATE_INTEGER(binary:decode_unsigned(Bint) + ?SMALL_INT_SIZE),
|
{?MAKE_FATE_INTEGER(binary:decode_unsigned(Bint) + ?SMALL_INT_SIZE),
|
||||||
Rest2};
|
Rest2};
|
||||||
deserialize2(<<?NEG_BITS, Rest/binary>>) ->
|
deserialize2(<<?NEG_BITS, Rest/binary>>) ->
|
||||||
{Bint, Rest2} = aeb_rlp:decode_one(Rest),
|
{Bint, Rest2} = aeser_rlp:decode_one(Rest),
|
||||||
{?FATE_BITS(-binary:decode_unsigned(Bint)), Rest2};
|
{?FATE_BITS(-binary:decode_unsigned(Bint)), Rest2};
|
||||||
deserialize2(<<?POS_BITS, Rest/binary>>) ->
|
deserialize2(<<?POS_BITS, Rest/binary>>) ->
|
||||||
{Bint, Rest2} = aeb_rlp:decode_one(Rest),
|
{Bint, Rest2} = aeser_rlp:decode_one(Rest),
|
||||||
{?FATE_BITS(binary:decode_unsigned(Bint)), Rest2};
|
{?FATE_BITS(binary:decode_unsigned(Bint)), Rest2};
|
||||||
deserialize2(<<?LONG_STRING, Rest/binary>>) ->
|
deserialize2(<<?LONG_STRING, Rest/binary>>) ->
|
||||||
{String, Rest2} = aeb_rlp:decode_one(Rest),
|
{String, Rest2} = aeser_rlp:decode_one(Rest),
|
||||||
{?MAKE_FATE_STRING(String), Rest2};
|
{?MAKE_FATE_STRING(String), Rest2};
|
||||||
deserialize2(<<S:6, ?SHORT_STRING:2, Rest/binary>>) ->
|
deserialize2(<<S:6, ?SHORT_STRING:2, Rest/binary>>) ->
|
||||||
String = binary:part(Rest, 0, S),
|
String = binary:part(Rest, 0, S),
|
||||||
Rest2 = binary:part(Rest, byte_size(Rest), - (byte_size(Rest) - S)),
|
Rest2 = binary:part(Rest, byte_size(Rest), - (byte_size(Rest) - S)),
|
||||||
{?MAKE_FATE_STRING(String), Rest2};
|
{?MAKE_FATE_STRING(String), Rest2};
|
||||||
deserialize2(<<?ADDRESS, Rest/binary>>) ->
|
deserialize2(<<?ADDRESS, Rest/binary>>) ->
|
||||||
{A, Rest2} = aeb_rlp:decode_one(Rest),
|
{A, Rest2} = aeser_rlp:decode_one(Rest),
|
||||||
{?FATE_ADDRESS(A), Rest2};
|
{?FATE_ADDRESS(A), Rest2};
|
||||||
deserialize2(<<?TRUE, Rest/binary>>) ->
|
deserialize2(<<?TRUE, Rest/binary>>) ->
|
||||||
{?FATE_TRUE, Rest};
|
{?FATE_TRUE, Rest};
|
||||||
@ -223,7 +223,7 @@ deserialize2(<<?EMPTY_MAP, Rest/binary>>) ->
|
|||||||
deserialize2(<<?EMPTY_STRING, Rest/binary>>) ->
|
deserialize2(<<?EMPTY_STRING, Rest/binary>>) ->
|
||||||
{?FATE_EMPTY_STRING, Rest};
|
{?FATE_EMPTY_STRING, Rest};
|
||||||
deserialize2(<<?LONG_TUPLE, Rest/binary>>) ->
|
deserialize2(<<?LONG_TUPLE, Rest/binary>>) ->
|
||||||
{BSize, Rest1} = aeb_rlp:decode_one(Rest),
|
{BSize, Rest1} = aeser_rlp:decode_one(Rest),
|
||||||
N = binary:decode_unsigned(BSize) + ?SHORT_TUPLE_SIZE,
|
N = binary:decode_unsigned(BSize) + ?SHORT_TUPLE_SIZE,
|
||||||
{List, Rest2} = deserialize_elements(N, Rest1),
|
{List, Rest2} = deserialize_elements(N, Rest1),
|
||||||
{?FATE_TUPLE(list_to_tuple(List)), Rest2};
|
{?FATE_TUPLE(list_to_tuple(List)), Rest2};
|
||||||
@ -231,7 +231,7 @@ deserialize2(<<S:4, ?SHORT_TUPLE:4, Rest/binary>>) ->
|
|||||||
{List, Rest1} = deserialize_elements(S, Rest),
|
{List, Rest1} = deserialize_elements(S, Rest),
|
||||||
{?FATE_TUPLE(list_to_tuple(List)), Rest1};
|
{?FATE_TUPLE(list_to_tuple(List)), Rest1};
|
||||||
deserialize2(<<?LONG_LIST, Rest/binary>>) ->
|
deserialize2(<<?LONG_LIST, Rest/binary>>) ->
|
||||||
{BLength, Rest1} = aeb_rlp:decode_one(Rest),
|
{BLength, Rest1} = aeser_rlp:decode_one(Rest),
|
||||||
Length = binary:decode_unsigned(BLength) + ?SHORT_LIST_SIZE,
|
Length = binary:decode_unsigned(BLength) + ?SHORT_LIST_SIZE,
|
||||||
{List, Rest2} = deserialize_elements(Length, Rest1),
|
{List, Rest2} = deserialize_elements(Length, Rest1),
|
||||||
{?MAKE_FATE_LIST(List), Rest2};
|
{?MAKE_FATE_LIST(List), Rest2};
|
||||||
@ -239,7 +239,7 @@ deserialize2(<<S:4, ?SHORT_LIST:4, Rest/binary>>) ->
|
|||||||
{List, Rest1} = deserialize_elements(S, Rest),
|
{List, Rest1} = deserialize_elements(S, Rest),
|
||||||
{?MAKE_FATE_LIST(List), Rest1};
|
{?MAKE_FATE_LIST(List), Rest1};
|
||||||
deserialize2(<<?MAP, Rest/binary>>) ->
|
deserialize2(<<?MAP, Rest/binary>>) ->
|
||||||
{BSize, Rest1} = aeb_rlp:decode_one(Rest),
|
{BSize, Rest1} = aeser_rlp:decode_one(Rest),
|
||||||
Size = binary:decode_unsigned(BSize),
|
Size = binary:decode_unsigned(BSize),
|
||||||
{List, Rest2} = deserialize_elements(2*Size, Rest1),
|
{List, Rest2} = deserialize_elements(2*Size, Rest1),
|
||||||
Map = insert_kv(List, #{}),
|
Map = insert_kv(List, #{}),
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
%%%-------------------------------------------------------------------
|
|
||||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
|
||||||
%%% @doc
|
|
||||||
%%% Implementation of the Recursive Length Prefix.
|
|
||||||
%%%
|
|
||||||
%%% https://github.com/ethereum/wiki/wiki/RLP
|
|
||||||
%%%
|
|
||||||
%%% @end
|
|
||||||
%%%-------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(aeb_rlp).
|
|
||||||
-export([ decode/1
|
|
||||||
, decode_one/1
|
|
||||||
, encode/1
|
|
||||||
]).
|
|
||||||
|
|
||||||
-export_type([ encodable/0
|
|
||||||
, encoded/0
|
|
||||||
]).
|
|
||||||
|
|
||||||
-type encodable() :: [encodable()] | binary().
|
|
||||||
-type encoded() :: <<_:8, _:_*8>>.
|
|
||||||
|
|
||||||
-define(UNTAGGED_SIZE_LIMIT , 55).
|
|
||||||
-define(UNTAGGED_LIMIT , 127).
|
|
||||||
-define(BYTE_ARRAY_OFFSET , 128).
|
|
||||||
-define(LIST_OFFSET , 192).
|
|
||||||
|
|
||||||
|
|
||||||
-spec encode(encodable()) -> encoded().
|
|
||||||
encode(X) ->
|
|
||||||
encode(X, []).
|
|
||||||
|
|
||||||
encode(<<B>> = X,_Opts) when B =< ?UNTAGGED_LIMIT ->
|
|
||||||
%% An untagged value
|
|
||||||
X;
|
|
||||||
encode(X,_Opts) when is_binary(X) ->
|
|
||||||
%% Byte array
|
|
||||||
add_size(?BYTE_ARRAY_OFFSET, X);
|
|
||||||
encode(L, Opts) when is_list(L) ->
|
|
||||||
%% Lists items are encoded and concatenated
|
|
||||||
ByteArray = << << (encode(X, Opts))/binary >> || X <- L >>,
|
|
||||||
add_size(?LIST_OFFSET, ByteArray).
|
|
||||||
|
|
||||||
add_size(Offset, X) when byte_size(X) =< ?UNTAGGED_SIZE_LIMIT ->
|
|
||||||
%% The size fits in one tagged byte
|
|
||||||
<<(Offset + byte_size(X)), X/binary>>;
|
|
||||||
add_size(Offset, X) when is_binary(X) ->
|
|
||||||
%% The size itself needs to be encoded as a byte array
|
|
||||||
%% Add the tagged size of the size byte array
|
|
||||||
SizeBin = binary:encode_unsigned(byte_size(X)),
|
|
||||||
TaggedSize = ?UNTAGGED_SIZE_LIMIT + Offset + byte_size(SizeBin),
|
|
||||||
true = (TaggedSize < 256 ), %% Assert
|
|
||||||
<<TaggedSize, SizeBin/binary, X/binary>>.
|
|
||||||
|
|
||||||
-spec decode(encoded()) -> encodable().
|
|
||||||
decode(Bin) when is_binary(Bin), byte_size(Bin) > 0 ->
|
|
||||||
case decode_one(Bin) of
|
|
||||||
{X, <<>>} -> X;
|
|
||||||
{X, Left} -> error({trailing, X, Bin, Left})
|
|
||||||
end.
|
|
||||||
|
|
||||||
decode_one(<<X, B/binary>>) when X =< ?UNTAGGED_LIMIT ->
|
|
||||||
%% Untagged value
|
|
||||||
{<<X>>, B};
|
|
||||||
decode_one(<<L, _/binary>> = B) when L < ?LIST_OFFSET ->
|
|
||||||
%% Byte array
|
|
||||||
{Size, Rest} = decode_size(B, ?BYTE_ARRAY_OFFSET),
|
|
||||||
<<X:Size/binary, Tail/binary>> = Rest,
|
|
||||||
{X, Tail};
|
|
||||||
decode_one(<<_/binary>> = B) ->
|
|
||||||
%% List
|
|
||||||
{Size, Rest} = decode_size(B, ?LIST_OFFSET),
|
|
||||||
<<X:Size/binary, Tail/binary>> = Rest,
|
|
||||||
{decode_list(X), Tail}.
|
|
||||||
|
|
||||||
decode_size(<<L, B/binary>>, Offset) when L =< Offset + ?UNTAGGED_SIZE_LIMIT->
|
|
||||||
%% One byte tagged size.
|
|
||||||
{L - Offset, B};
|
|
||||||
decode_size(<<_, 0, _/binary>>,_Offset) ->
|
|
||||||
error(leading_zeroes_in_size);
|
|
||||||
decode_size(<<L, B/binary>>, Offset) ->
|
|
||||||
%% Actual size is in a byte array.
|
|
||||||
BinSize = L - Offset - ?UNTAGGED_SIZE_LIMIT,
|
|
||||||
<<Size:BinSize/unit:8, Rest/binary>> = B,
|
|
||||||
{Size, Rest}.
|
|
||||||
|
|
||||||
decode_list(<<>>) -> [];
|
|
||||||
decode_list(B) ->
|
|
||||||
{Element, Rest} = decode_one(B),
|
|
||||||
[Element|decode_list(Rest)].
|
|
@ -6,6 +6,7 @@
|
|||||||
[kernel,
|
[kernel,
|
||||||
stdlib,
|
stdlib,
|
||||||
eblake2,
|
eblake2,
|
||||||
|
aeserialization,
|
||||||
getopt
|
getopt
|
||||||
]},
|
]},
|
||||||
{env,[]},
|
{env,[]},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user