Closed grizzly-monkey closed 7 years ago
Conditional decoding is unsupported. I was thinking about it, but it's not that simple and may introduce infinite loops.
Also, 'default = 0' is incorrect, you need to add dec/enc functions in this case.
It seems like you need something like this:
-xml(sync,
#elem{name = <<"sync">>,
xmlns = <<"mycustom:xmlsns:sync">>,
result = {sync, '$c','$json', '$_els'},
cdata = #cdata{label = '$json'},
attrs = [#attr{name = <<"c">>,
enc = {enc_int, []},
dec = {dec_int, [0, unlimited]},
default = 0}]}).
Then in ejabberd's code you should add json decoding/encoding of #sync.json
based on #sync.c
value.
yes zinid you are correct i need enc = {enc_int, []}, dec = {dec_int, [0, unlimited]},
however my json decoding should happen based on my attribute <<"c">> is there any other way you could point me to and i can try it
No, you should make decoding manually in the code, as I said above. E.g.
foo(#sync{c = C, json = Data}) when C == 0 ->
try jiffy:decode(Data) of
JSON -> do_something(JSON)
catch _:_ ->
process_invalid_json()
end;
...
I actually need this conditional decoding myself in some places (like privacy lists decoding), but implementing this is tough.
Cool thanks hope we can get this conditional decoding ... :) thanks for your help 👍
Hello i want to write a custom spec in xmpp_codec.spec which will decode json cdata
_-xml(sync,
elem{name = <<"sync">>,
in dec = dec_json , [] i want to pass the label '$c' so that my decode will be based on '$c'
how can i achieve this right now it just accepts the atom or constants is it possible to pass a attribute var ? any other method i can achieve this?
Merci