Skip to content

sile/erl-amf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ErlAMF

hex.pm version Build Status Code Coverage License: MIT

ErlAMF is an AMF(Action Message Format) encoding/deconding library written in Erlang.

EDoc Documentation

Usage

Build

ErlAMF uses rebar3 as build tool.

# build
$ git clone git://github.com/sile/erl-amf.git
$ cd erl-amf
$ rebar3 compile

# run unit tests
$ rebar3 eunit

Examples

$ erl -pa ebin

%%%
%%% Encode and Decode
%%%
%%% AMF3 encode
1> {ok, IoList} = amf:encode(amf3, [1,2,3]).
{ok,[9,7,[1],[[4,1],[4,2],[4,3]]]}

%% AMF3 decode
2> amf:decode(amf3, list_to_binary(IoList)).
{ok,[1,2,3],<<>>}

%%%
%%% AMF values
%%%
%% Load records
%% (Records are defined in "erl-amf/include/amf.hrl")
3> rr(amf).
[amf_array,amf_avmplus_object,amf_byte_array,amf_date,
 amf_dictionary,amf_exception,amf_object,amf_vector,amf_xml,
 amf_xml_document]

%% Anonymous object
4> amf:object([{<<"one">>, 1}, {<<"two">>, 2}]).
#amf_object{class = undefined,dynamic = true,
            sealed_fields = [],
            members = [{<<"one">>,1},{<<"two">>,2}]}

5> amf:encode(amf0, v(4)).
{ok,[3,
     [<<0,3>>, <<"one">>,
      [0,<<63,240,0,0,0,0,0,0>>],
      <<0,3>>, <<"two">>,
      [0,<<64,0,0,0,0,0,0,0>>]],
      0,0,9]}

%% Date
6> amf:encode(amf0, amf:date(now())).
{ok,[11,<<66,115,221,102,242,183,208,0,0,0>>]}

%%%
%%% Error
%%%
%% The encode/2(and decode/2) function returns an amf_exception() instance as error reason
7> amf:encode(amf0, can_not_encode).
{error,#amf_exception{type = unsupported,
                      message = {value,can_not_encode}}}

8> amf:decode(amf0, <<>>).
{error,#amf_exception{type = partial,
                      message = {marker,<<>>}}}

Mapping between Erlang Values and AMF types(markers)

Erlang ValueAMF0 MarkerAMF3 Marker
10numberinteger
10.5numberdouble
truebooleantrue
falsebooleanfalse
nullnullnull
undefinedundefinedundefined
<<"string">>string | long-stringstring
movieclip
recordset
unsupported
amf:date(now())datedate
amf:xml(<<"xml">>)xml
amf:xml_document(<<"xml">>)xml-documentxml-doc
amf:byte_array(<<"bytes">>)byte-array
amf:vector(int, [-1,2,-3])vector-int
amf:vector(uint, [1,2,3])vector-uint
amf:vector(double, [-1.0,2.0,-3.0])vector-double
amf:vector(<<"type_name">>, [1,<<"2">>,[3]])vector-object
[1,2,3]strict-arrayarray (only dense element)
amf:array([{<<"key">>, <<"value">>}])ecma-arrayarray (only associative element)
amf:array([1,2,3], [{<<"key">>, <<"value">>}])array (mixed)
amf:object([{<<"key">>, <<"value">>}])objectobject (anonymous)
amf:typed_object(<<"type">>, [{<<"key">>, <<"value">>}])typed-objectobject (typed)
amf:dictionary([{1,2}, {true, false}])dictionary
amf:avmplus_object([1,2,3])avmplus-object

Limitations

ErlAMF doesn't support following features:

  • Circular reference objects
  • flash.utils.IExternalizable interface
  • No Object/Trait/String reference is used in encoding process
  • Special double value (e.g. NaN, Infinity)

Reference

About

An Erlang library to encode/decode AMF

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages