variant introspection possible?

13 views
Skip to first unread message

bart van deenen

unread,
Jan 14, 2013, 11:19:12 AM1/14/13
to pi...@googlegroups.com
Hi Anton, all

I have a variant definition:

.variant [
    .name resource
    .option [ .type port-nr ]
    .option [ .type database ]
    .option [ .type  db-server ]
    .option [ .type  host ]
]

where the various types are records.

Is there a way to ask for the option list, so that I would have something like [ port_nr, database, db_server, host ] ?

Thanks

Bart

Anton Lavrik

unread,
Jan 15, 2013, 1:43:08 AM1/15/13
to pi...@googlegroups.com
Hi Bart,

Not sure what you mean. Are you talking about doing this with Erlang
values or with a static type specification? Can you share some extra
context about what you are trying to achieve and in what environment.

Anton

bart van deenen

unread,
Jan 15, 2013, 3:08:00 AM1/15/13
to pi...@googlegroups.com
Hi Anton

I have an application with a piqi_rpc http user interface, that deals with various kinds of resources, and I'd like to be able to ask the application: "what kind of resources do you handle?". So either I keep track of the types of resource in another way, or I somehow look inside the variant definition, and return the list of variant option names [ 'port_nr', 'database', 'db_server', 'host'].

That's what I meant.

Greetings

Bart

Anton Lavrik

unread,
Jan 15, 2013, 10:11:51 AM1/15/13
to pi...@googlegroups.com
Hi Bart,

Do you need this on client or server side?

On client side, it is possible to get interface definitions from the
server in .piqi, JSON, XML and Protocol Buffers format by making an
HTTP GET call against the service URL and specifying the desired
return type in the "Accept" header. It is documented here:
http://piqi.org/doc/piqi-rpc/#gettingpiqispecificationfromarunningpiqirpcservice

It is also possible for the server applications to access their type
definitions. This functionality is not exposed directly, but it is
available. Basically, this is the same mechanism used to return the
list of Piqi modules to the clients. You can follow the code to see
how it works starting from this point:
https://github.com/alavrik/piqi/blob/dev/piqi-rpc/src/piqi_rpc_webmachine_resource.erl#L270

There's one caveat. The way Piqi definitions are represented in
external formats (JSON, XML, Protobuf) will change in the new 0.6.0
version (I'm going to release in a couple of weeks). The good thing is
that it is unlikely to change in a backward-incompatible way in future
versions following 0.6.0

Anton

On Tue, Jan 15, 2013 at 2:08 AM, bart van deenen

bart van deenen

unread,
Jan 18, 2013, 6:19:39 AM1/18/13
to pi...@googlegroups.com
Hi Anton

I just had a look at it, and I'll use the internal method, using 'xml' and xmerl_xpath to return my list of variant names

Thanks!

Bart
Reply all
Reply to author
Forward
0 new messages