I am sligtly changed example with file (added multiple phones):
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
repeated PhoneNumber phone = 4;
}
enum PhoneType {
MOBILE = 0;
HOME = 0;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = MOBILE];
}
import std.stdio;
import dproto.dproto;
mixin ProtocolBuffer!"person.proto";
int main()
{
PhoneNumber phone;
phone.number = "45345";
Person person;
person.name = "John Doe";
person.id = 1234;
person.email = "jdoe@example.com";
person.phone ~= phone; // look here!
person.phone ~= phone; // look here!
ubyte[] serializedObject = person.serialize();
Person person2 = Person(serializedObject);
writeln("Name: ", person2.name);
writeln("E-mail: ", person2.email);
writeln("Phones: ", phone); // but now it contains two different values
return 0;
}
$ dub
Target dproto 1.2.3 is up to date. Use --force to rebuild.
Building dproto_simple_file ~master configuration "application", build type debug.
Compiling using dmd...
Linking...
Running ./dproto_simple_file
Name: John Doe
E-mail: jdoe@example.com
Phones: PhoneNumber("45345", 0) # <====== here
I am sligtly changed example with file (added multiple phones):