toD

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

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

Examples

  import std.stdio;
  import pbd.parse : Proto;

  enum exampleProto = `
syntax = "proto3";

package tensorflow;

message Foo {
  int32 aa = 1;
  sint32 bb = 2;
}
`;

  // example of generated code
  import pbd.codegen;
  struct ExpectedFoo {
    @ProtoTag(1) int aa;
    @ZigZag @ProtoTag(2) int bb;
  }

  enum tree = Proto(exampleProto);
  enum code = tree.toD(0, "  ");
  mixin(code);

  static assert(is(typeof(Foo.aa) == int));
  static assert(protoTagOf!(Foo, "aa") == 1);
  static assert(!isZigZag!(Foo, "aa"));

  static assert(is(typeof(Foo.bb) == int));
  static assert(protoTagOf!(Foo, "bb") == 2);
  static assert(isZigZag!(Foo, "bb"));
  // writeln("generated:\n", code);

Meta