Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Specs and types for marshalling

  • Loading branch information...
commit 829980ba540885a59e30e092f11d6896e771faeb 1 parent d59bd18
authored

Showing 1 changed file with 5 additions and 2 deletions. Show diff stats Hide diff stats

  1. +5 2 src/tavern_marshal_xml.erl
7 src/tavern_marshal_xml.erl
@@ -2,10 +2,10 @@
2 2
3 3 -export([decode/1, encode/1]).
4 4
5   --compile([export_all]).
6   -
  5 +-include("types.hrl").
7 6 -include_lib("eunit/include/eunit.hrl").
8 7
  8 +-spec decode(binary()) -> {ok, Data :: tree()} | {error, Error :: atom()}.
9 9 decode(Payload) ->
10 10 case erlsom:simple_form(Payload) of
11 11 {ok, {_, _, NodeList}, _} ->
@@ -19,15 +19,18 @@ decode(Payload) ->
19 19 _ -> {error, 'xml unserialization failed'}
20 20 end.
21 21
  22 +-spec encode(tree()) -> {ok, Data :: binary()} | {error, Error :: atom()}.
22 23 encode(Payload) ->
23 24 case (catch xmerl:export_simple(encode_list(Payload), xmerl_xml)) of
24 25 {'EXIT', _} -> {error, 'xml serialization failed'};
25 26 Data -> {ok, Data}
26 27 end.
27 28
  29 +-spec encode_list(Struct :: [{atom(), any()}]) -> list().
28 30 encode_list(List) ->
29 31 encode_list(List, []).
30 32
  33 +-spec encode_list(Struct :: [{atom(), any()}], Acc :: list()) -> list().
31 34 encode_list([], Acc) ->
32 35 lists:reverse(Acc);
33 36

0 comments on commit 829980b

Please sign in to comment.
Something went wrong with that request. Please try again.