round out writeAddressBook
This commit is contained in:
parent
ddbab77252
commit
b006a01730
2 changed files with 32 additions and 2 deletions
|
@ -796,7 +796,18 @@ private:
|
||||||
kj::strTree(" return _builder.get",toTitleCase(type),"Field(", offset, ");\n"))),
|
kj::strTree(" return _builder.get",toTitleCase(type),"Field(", offset, ");\n"))),
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
//spaces(indent), " public final void set", titleCase, "(", type, " value", setterDefault, ");\n",
|
(typeBody.which() == schema::Type::VOID ?
|
||||||
|
kj::strTree(spaces(indent), " public final void set", titleCase, "() {}\n") :
|
||||||
|
(typeBody.which() == schema::Type::ENUM ?
|
||||||
|
kj::strTree(
|
||||||
|
spaces(indent), " public final void set", titleCase, "(", type, " value) {\n",
|
||||||
|
spaces(indent), " _builder.setShortField(", offset, ", (short)value.ordinal());\n",
|
||||||
|
spaces(indent), " }\n") :
|
||||||
|
kj::strTree(
|
||||||
|
spaces(indent), " public final void set", titleCase, "(", type, " value) {\n",
|
||||||
|
spaces(indent), " _builder.set", toTitleCase(type),
|
||||||
|
"Field(", offset, ", value);\n",
|
||||||
|
spaces(indent), " }\n"))),
|
||||||
"\n"),
|
"\n"),
|
||||||
|
|
||||||
kj::strTree(),
|
kj::strTree(),
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.capnproto.MessageBuilder;
|
||||||
import org.capnproto.MessageReader;
|
import org.capnproto.MessageReader;
|
||||||
import org.capnproto.StructList;
|
import org.capnproto.StructList;
|
||||||
import org.capnproto.InputStreamMessageReader;
|
import org.capnproto.InputStreamMessageReader;
|
||||||
|
import org.capnproto.Text;
|
||||||
|
|
||||||
import org.capnproto.examples.Addressbook.*;
|
import org.capnproto.examples.Addressbook.*;
|
||||||
|
|
||||||
|
@ -16,7 +17,25 @@ public class AddressbookMain {
|
||||||
StructList.Builder<Person.Builder> people = addressbook.initPeople(2);
|
StructList.Builder<Person.Builder> people = addressbook.initPeople(2);
|
||||||
|
|
||||||
Person.Builder alice = people.get(0);
|
Person.Builder alice = people.get(0);
|
||||||
//alice.setId(123);
|
alice.setId(123);
|
||||||
|
alice.setName(new Text.Reader("Alice"));
|
||||||
|
alice.setEmail(new Text.Reader("alice@example.com"));
|
||||||
|
|
||||||
|
StructList.Builder<Person.PhoneNumber.Builder> alicePhones = alice.initPhones(1);
|
||||||
|
alicePhones.get(0).setNumber(new Text.Reader("555-1212"));
|
||||||
|
alicePhones.get(0).setType(Person.PhoneNumber.Type.MOBILE);
|
||||||
|
alice.getEmployment().setSchool(new Text.Reader("MIT"));
|
||||||
|
|
||||||
|
Person.Builder bob = people.get(0);
|
||||||
|
bob.setId(456);
|
||||||
|
bob.setName(new Text.Reader("Bob"));
|
||||||
|
bob.setEmail(new Text.Reader("bob@example.com"));
|
||||||
|
StructList.Builder<Person.PhoneNumber.Builder> bobPhones = bob.initPhones(2);
|
||||||
|
bobPhones.get(0).setNumber(new Text.Reader("555-4567"));
|
||||||
|
bobPhones.get(0).setType(Person.PhoneNumber.Type.HOME);
|
||||||
|
bobPhones.get(1).setNumber(new Text.Reader("555-7654"));
|
||||||
|
bobPhones.get(1).setType(Person.PhoneNumber.Type.WORK);
|
||||||
|
bob.getEmployment().setUnemployed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printAddressBook() throws java.io.IOException {
|
public static void printAddressBook() throws java.io.IOException {
|
||||||
|
|
Loading…
Reference in a new issue