Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Specs and types for marshalling

  • Loading branch information...
commit 829980ba540885a59e30e092f11d6896e771faeb 1 parent d59bd18
@lafka authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 src/tavern_marshal_xml.erl
View
7 src/tavern_marshal_xml.erl
@@ -2,10 +2,10 @@
-export([decode/1, encode/1]).
--compile([export_all]).
-
+-include("types.hrl").
-include_lib("eunit/include/eunit.hrl").
+-spec decode(binary()) -> {ok, Data :: tree()} | {error, Error :: atom()}.
decode(Payload) ->
case erlsom:simple_form(Payload) of
{ok, {_, _, NodeList}, _} ->
@@ -19,15 +19,18 @@ decode(Payload) ->
_ -> {error, 'xml unserialization failed'}
end.
+-spec encode(tree()) -> {ok, Data :: binary()} | {error, Error :: atom()}.
encode(Payload) ->
case (catch xmerl:export_simple(encode_list(Payload), xmerl_xml)) of
{'EXIT', _} -> {error, 'xml serialization failed'};
Data -> {ok, Data}
end.
+-spec encode_list(Struct :: [{atom(), any()}]) -> list().
encode_list(List) ->
encode_list(List, []).
+-spec encode_list(Struct :: [{atom(), any()}], Acc :: list()) -> list().
encode_list([], Acc) ->
lists:reverse(Acc);
Please sign in to comment.
Something went wrong with that request. Please try again.