Converting PB to XML rev II

178 views
Skip to first unread message

Carl Slater

unread,
Aug 27, 2014, 10:49:25 AM8/27/14
to pi...@googlegroups.com
Greetings:

    I am a new Piqi user and I am wondering if this is possible? I have a proto file that contains a large number of messages types and these messages include other messages that maybe in other proto files ...  yes it is a big model.  Think of building up a car in a traditional OO manner... only using PB as containers. So the CAR message contains a message called Wheel. Wheel contains a message called Tire ....

    Now I have read Anton Lavrik's post:

The Protocol Buffers format is based on external type definitions and encoded data generally can't be interpreted or converted without knowing its type.

Usually, Protocol Buffers type definitions are distributed as text files with .proto extension. Assuming you have the matching .proto file (e.g. x.proto), the rest should be fairly straightforward:

First, you need to convert x.proto to x.piqi (the type definition format piqi can work with directly):

    piqi of-proto x.proto

After that, inside the generated x.piqi, find the type corresponding to the data structure encoded in Protocol Buffers format you want to convert. It should have the same or very similar name to the original type name in x.proto. Lets say the name of the type is "t".

Then, the full name you need to pass to piqi convert --type is x/t, where x is the name of the .piqi module and t is the name of the type.

Finally, to convert your encoded Protocol Buffers data into xml, run:

    piqi convert --type x/t -f pb -t xml <your-pb-file>

So does this mean when I build my x.piqi file I need to

      piqi of-proto car.proto

And it pulls in protos as required or do I

      piqi of-proto car.proto
      piqi of-proto whell.proto
      piqi of-proto tire.proto

After I cross that hurdle will "piqi convert --type car.piqi/car car.pb" give me car.xml with cars, wheels and tires contained in it?

Regards
Carl





Anton Lavrik

unread,
Aug 28, 2014, 3:06:33 AM8/28/14
to pi...@googlegroups.com, Carl Slater
On Wed, Aug 27, 2014 at 7:49 AM, Carl Slater <ce.sla...@gmail.com> wrote:

So does this mean when I build my x.piqi file I need to

      piqi of-proto car.proto

And it pulls in protos as required or do I

      piqi of-proto car.proto
      piqi of-proto whell.proto
      piqi of-proto tire.proto

The latter. You will need to convert each .proto files to .piqi individually beforehand.
 
After I cross that hurdle will "piqi convert --type car.piqi/car car.pb" give me car.xml with cars, wheels and tires contained in it?

Correct.

Anton 
Reply all
Reply to author
Forward
0 new messages