[erlang-questions] Erlang de/serializer and data type validator

Tim Watson watson.timothy@REDACTED
Tue Aug 2 22:10:49 CEST 2011


http://piqi.org/ might also be worth a look.

2011/8/2 Ulf Wiger <ulf.wiger@REDACTED>:
>
> Hi Motiejus,
> Perhaps you should look into Joe Norton's work with UBF?
> UBF is a type system for describing contracts between services.
> http://www.sics.se/~joe/ubf/site/home.html (for original documentation)
> https://github.com/norton/ubf (for the current stuff)
> There is a UBF-to-JSON converter. There is also one for Thrift, and Joe
> Norton has combined UBF, UBF-JSON and QuickCheck to do validation of web
> services.
> I don't think UBF to XML would be particularly difficult.
> There may be some more work that needs to be done before it fits your
> problem. OTOH, you might get a lot of other benefits going this route.
> BR,
> Ulf W
> On 2 Aug 2011, at 10:27, Motiejus Jakštys wrote:
>
> Hello,
>
> I have a data structure validator. It should check if variable has
> a pre-defined data structure.
>
> The validator takes Erlang data type (in this example, #'bp.message'{})
> and checks if:
> 1) to is either {participant | bpid, binary() | undefined}
> 2) module either se_port_v2 or se_transfer_v2
>
> Part of validator schema:
>
> schema('bp.message') ->
>    {record, 'bp.message', [
>        {to, schema('bp.message.destination')}
>        {module, schema('bp.message.module')},
>    ]};
>
> schema('bp.message.destination') ->
>    {tuple, {choice, ['participant', 'bpid']}, {choice, ['binary',
> undefined]}};
>
> schema('bp.message.module') ->
>    {choice, [
>        se_assign_v2,
>        se_release_v2,
>    ]};
>
> Two questions:
> 1) I feel I could do the same with erlang -type. How do I check the data
> structure complies?
> 2) I need serializer and deserializer to JSON, XML or any other common
> data format. Maybe there is such a thing in the wild?
>
> Serialized structure must not hold Erlang data type information as I
> have to share it with third parties. It should distinguish between atom
> and binary from schema (as well as list from tuple..). Serialized message
> to JSON would look like this:
>
> { "bp.message" : {
>    "to" : [participant, "yadda"],
>    "module" : "se_assign_v2"
>     }
> }
>
> If I will have to write one, how do I recursively crawl type definition
> information?
>
> Motiejus
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
> Ulf Wiger, CTO, Erlang Solutions, Ltd.
> http://erlang-solutions.com
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>



More information about the erlang-questions mailing list