msoucy / dproto

D Protocol Buffer mixins to create structures at compile time
Boost Software License 1.0
37 stars 16 forks source link

errors 1.2.0 #2 #42

Closed bigbendrugs closed 9 years ago

bigbendrugs commented 9 years ago
import std.stdio;
import dproto.dproto;

mixin ProtocolBufferFromString!"
    message Person {
      required string name = 1;
      required int32 id = 2;
      optional string email = 3;

      enum PhoneType {
        MOBILE = 0;
        HOME = 1;
        WORK = 2;
      }

      message PhoneNumber {
        required string number = 1;
        optional PhoneType type = 2 [default = HOME];
      }

      repeated PhoneNumber phone = 4;
    }
";

int main()
{
    Person person;
    person.name = "John Doe";
    person.id = 1234;
    person.email = "jdoe@example.com";

    Person.PhoneNumber pn1;
    pn1.number = "0123456789";
    pn1.type = PhoneType.WORK;

    Person.PhoneNumber pn2;
    pn2.number = "0123456789";

    t.phone = [pn1, pn2];

    ubyte[] serializedObject = person.serialize();

    Person person2 = Person(serializedObject);
    writeln("Name: ", person2.name);
    writeln("E-mail: ", person2.email);
    return 0;
}

dub

Target dproto 1.2.1 is up to date. Use --force to rebuild.
Building dproto_simple ~master configuration "application", build type debug.
Compiling using dmd...
source/app.d(43): Error: undefined identifier PhoneType
source/app.d(48): Error: undefined identifier t
FAIL .dub/build/application-debug-linux.posix-x86_64-dmd_2066-D58341A42DC7432308F148A8247E9EF7/ dproto_simple executable
Error executing command run:
dmd failed with exit code 1.
msoucy commented 9 years ago

source/app.d(43): Error: undefined identifier PhoneType

That's because it's actually Person.PhoneType.

source/app.d(48): Error: undefined identifier t

t does, indeed, not exist. I assume that you meant the person variable.

msoucy commented 9 years ago

Any more concerns, or can this be closed?