toD

Generates D code from Protobuf IDL ParseTree (Proto result).

string
toD
(
ParseTree p
,
int numIndent = 0
,
string indent = " "
)

Examples

1   import std.stdio;
2   import pbd.parse : Proto;
3 
4   enum exampleProto = `
5 syntax = "proto3";
6 
7 package tensorflow;
8 
9 message Foo {
10   int32 aa = 1;
11   sint32 bb = 2;
12 }
13 `;
14 
15   // example of generated code
16   import pbd.codegen;
17   struct ExpectedFoo {
18     @ProtoTag(1) int aa;
19     @ZigZag @ProtoTag(2) int bb;
20   }
21 
22   enum tree = Proto(exampleProto);
23   enum code = tree.toD(0, "  ");
24   mixin(code);
25 
26   static assert(is(typeof(Foo.aa) == int));
27   static assert(protoTagOf!(Foo, "aa") == 1);
28   static assert(!isZigZag!(Foo, "aa"));
29 
30   static assert(is(typeof(Foo.bb) == int));
31   static assert(protoTagOf!(Foo, "bb") == 2);
32   static assert(isZigZag!(Foo, "bb"));
33   // writeln("generated:\n", code);

Meta