Skip to content

Commit

Permalink
add specs and type exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
hio committed Jan 28, 2012
1 parent 2449c37 commit 5f2b9f1
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/json.erl
Expand Up @@ -3,10 +3,38 @@
-module(json).
-export([encode/1, decode/1, decode/2]).
-export_type([decode_options/0]).
-export_type([encode_options/0]).
-export_type([value/0]).
-export_type([object/2]).
-export_type([key/0]).
-export_type([array/1]).
-export_type([json_string/0]).
-export_type([json_number/0]).
-export_type([text/0]).

-on_load(init/0).

-type value() :: json_string()
| json_number()
| object(key(), value())
| array(value())
| boolean()
| null
.
-type object(K,T) :: {[ {K, T} ]}.
-type key() :: json_string().
-type array(T) :: [T].
-type json_string() :: unicode:unicode_binary().
-type json_number() :: integer() | float().
-type text() :: iodata().

-type decode_options() :: [ decode_option() ].
-type decode_option() :: allow_comments | {allow_comments, boolean()}.
-type decode_option() ::
allow_comments
| {allow_comments, boolean()}
.

-type encode_options() :: [].

init() ->
PrivDir = case code:priv_dir(?MODULE) of
Expand All @@ -19,12 +47,15 @@ init() ->
end,
erlang:load_nif(filename:join(PrivDir, "json"), 0).

-spec decode(text()) -> {ok, value()} | {error, term()}.
decode(JsonText) ->
erlang:nif_error(module_not_loaded, [JsonText]).

-spec decode(text(), decode_options()) -> {ok, value()} | {error, term()}.
decode(JsonText, Options) ->
erlang:nif_error(module_not_loaded, [JsonText, Options]).

-spec encode(value()) -> {ok, text()} | {error, term()}.
encode(JsonTerm) ->
erlang:nif_error(module_not_loaded, [JsonTerm]).

0 comments on commit 5f2b9f1

Please sign in to comment.