[erlang-questions] UBF and JSON Protocols
Joseph Wayne Norton
norton@REDACTED
Sun Feb 15 15:30:46 CET 2009
Joe -
Using the decoder/encoder of the erlang-rfc46267
(http://www.lshift.net/blog/2007/02/17/json-and-json-rpc-for-erlang)
module, here is an informal description for *one* approach to encode
"erlang" UBF into JSON (and vice versa). Comments and feedback are
welcome.
thanks,
- Joe N.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% encode(ubf::value()) -> json::value()
%%
%% ubf::tuple() = {obj, [{"$T", ubf::list()}]}
%%
%% ubf::list() = [value()]
%%
%% ubf::number() = integer() | float()
%%
%% ubf::string() = {obj, [{"$S", binary()}]}
%%
%% ubf::binary() = binary()
%%
%% ubf::true() = true
%% ubf::false() = false
%% ubf::undefined() = null
%%
%% ubf::atom() = {obj, [{"$A", atomname()}
%% atomname() = binary() % a.k.a. list_to_binary(atom_to_list()) for
the actual atom
%%
%% ubf::record() = {obj, [{"$R", recordname()}] ++ [recordpair()]}
%% recordname = binary() % a.k.a. list_to_binary(atom_to_list()) for
the record's name
%% recordpair() = {recordkey(), value()}
%% recordkey() = binary() % a.k.a. list_to_binary(atom_to_list())
for the record key's name
%%
%% value() = ubf::tuple() | ubf::list() | ubf::number() | ubf::string() |
ubf::binary() | ubf::true() | ubf::false() | ubf::undefined() |
ubf::atom() | ubf::record()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ubf
%%
%% ubf::tuple() = tuple()
%%
%% ubf::list() = list()
%%
%% ubf::number = integer() | float()
%%
%% ubf::string() = {'$S', [integer()]}
%%
%% ubf::binary() = binary()
%%
%% ubf::true() = true
%% ubf::false() = false
%% ubf::undefined() = undefined
%%
%% ubf::atom() = atom()
%%
%% ubf::record() = record()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% erlang-rfc46267
%%
%% json::object() = {obj, [json::pair()]}
%%
%% json::pair() = {string(), json::value()}
%% string() = [byte()]
%% byte() = integer()
%%
%% json::array() = [json::value()]
%%
%% json::value() = json::object() | json::array() | json::number() |
json::string() | json::true() | json::false() | json::null()
%%
%% json::number() = integer() | float()
%%
%% json::string() = binary()
%%
%% json::true() = true
%% json::false() = false
%% json::null() = null
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% json
%%
%% object
%% {}
%% { members }
%% members
%% pair
%% pair, members
%% pair
%% string : value
%% array
%% []
%% [ elements ]
%% elements
%% value
%% value, elements
%% value
%% string
%% number
%% object
%% true (atom)
%% false (atom)
%% null (atom)
On Sun, 15 Feb 2009 20:39:10 +0900, Joe Armstrong <erlang@REDACTED> wrote:
> For a long time I have been interested in describing protocols. In
> 2002 I published a contract system called UBF for defining protocols.
> This scheme was never widely adopted - perhaps it was just to
> strange...
>
> I have revised UBF and recast it in a form which I call JSON Protocols
> - since JSON is widely implemented, this method of described protocols
> might be more acceptable...
>
> Read the remainder of this on
>
> http://armstrongonsoftware.blogspot.com/2009/02/json-protocols-part-1.html
>
> /Joe Armstrong
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
--
norton@REDACTED
More information about the erlang-questions
mailing list