generate Text setters that take a String
This commit is contained in:
parent
8f027fcaa1
commit
3e66f44266
3 changed files with 56 additions and 15 deletions
|
@ -48,7 +48,7 @@ public class CatRank
|
||||||
url.append('a' + rng.nextLessThan(26));
|
url.append('a' + rng.nextLessThan(26));
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setUrl(new Text.Reader(url.toString()));
|
result.setUrl(url.toString());
|
||||||
|
|
||||||
boolean isCat = rng.nextLessThan(8) == 0;
|
boolean isCat = rng.nextLessThan(8) == 0;
|
||||||
boolean isDog = rng.nextLessThan(8) == 0;
|
boolean isDog = rng.nextLessThan(8) == 0;
|
||||||
|
@ -70,7 +70,7 @@ public class CatRank
|
||||||
snippet.append(Common.WORDS[rng.nextLessThan(Common.WORDS.length)]);
|
snippet.append(Common.WORDS[rng.nextLessThan(Common.WORDS.length)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setSnippet(new Text.Reader(snippet.toString()));
|
result.setSnippet(snippet.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return goodCount;
|
return goodCount;
|
||||||
|
|
|
@ -958,9 +958,52 @@ private:
|
||||||
kj::strTree()
|
kj::strTree()
|
||||||
};
|
};
|
||||||
|
|
||||||
} else if (kind == FieldKind::BLOB) {
|
} else if (kind == FieldKind::BLOB && typeBody.which() == schema::Type::TEXT ) {
|
||||||
|
|
||||||
kj::String blobKind = typeBody.which() == schema::Type::TEXT ? kj::str("Text") : kj::str("Data");
|
kj::String blobKind = kj::str("Text");
|
||||||
|
|
||||||
|
return FieldText {
|
||||||
|
kj::strTree(
|
||||||
|
kj::mv(unionDiscrim.readerIsDecl),
|
||||||
|
spaces(indent), " public boolean has", titleCase, "() {\n",
|
||||||
|
spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n",
|
||||||
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
|
spaces(indent), " public ", type, ".Reader",
|
||||||
|
" get", titleCase, "() {\n",
|
||||||
|
spaces(indent), " return _reader.getPointerField(",
|
||||||
|
offset, ").get", blobKind, " ();\n", // XXX
|
||||||
|
spaces(indent), " }\n", "\n"),
|
||||||
|
|
||||||
|
kj::strTree(
|
||||||
|
kj::mv(unionDiscrim.builderIsDecl),
|
||||||
|
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
||||||
|
spaces(indent), " return !_builder.getPointerField(", offset, ").isNull();\n",
|
||||||
|
spaces(indent), " }\n",
|
||||||
|
spaces(indent), " public final ", type, ".Builder get", titleCase, "() {\n",
|
||||||
|
spaces(indent), " return _builder.getPointerField(",
|
||||||
|
offset, ").get", blobKind, " ();\n", // XXX
|
||||||
|
spaces(indent), " }\n",
|
||||||
|
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
||||||
|
unionDiscrim.set,
|
||||||
|
spaces(indent), " _builder.getPointerField(", offset, ").set", blobKind, "(value);\n",
|
||||||
|
spaces(indent), " }\n",
|
||||||
|
spaces(indent), " public final void set", titleCase, "(String value) {\n",
|
||||||
|
unionDiscrim.set,
|
||||||
|
spaces(indent), " _builder.getPointerField(", offset, ").set", blobKind, "( new",
|
||||||
|
type, ".Reader(value));\n",
|
||||||
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
|
spaces(indent), " public final ", type, ".Builder init", titleCase, "(int size) {\n",
|
||||||
|
spaces(indent), " throw new Error();\n",
|
||||||
|
spaces(indent), " }\n"),
|
||||||
|
|
||||||
|
kj::strTree(),
|
||||||
|
kj::strTree()
|
||||||
|
};
|
||||||
|
} else if (kind == FieldKind::BLOB && typeBody.which() == schema::Type::DATA ) {
|
||||||
|
|
||||||
|
kj::String blobKind = kj::str("Data");
|
||||||
|
|
||||||
return FieldText {
|
return FieldText {
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
|
@ -995,6 +1038,7 @@ private:
|
||||||
kj::strTree(),
|
kj::strTree(),
|
||||||
kj::strTree()
|
kj::strTree()
|
||||||
};
|
};
|
||||||
|
|
||||||
} else if (kind == FieldKind::LIST) {
|
} else if (kind == FieldKind::LIST) {
|
||||||
|
|
||||||
uint64_t typeId = field.getContainingStruct().getProto().getId();
|
uint64_t typeId = field.getContainingStruct().getProto().getId();
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.capnproto.MessageBuilder;
|
||||||
import org.capnproto.MessageReader;
|
import org.capnproto.MessageReader;
|
||||||
import org.capnproto.SerializePacked;
|
import org.capnproto.SerializePacked;
|
||||||
import org.capnproto.StructList;
|
import org.capnproto.StructList;
|
||||||
import org.capnproto.Text;
|
|
||||||
|
|
||||||
import org.capnproto.examples.Addressbook.*;
|
import org.capnproto.examples.Addressbook.*;
|
||||||
|
|
||||||
|
@ -21,24 +20,22 @@ public class AddressbookMain {
|
||||||
|
|
||||||
Person.Builder alice = people.get(0);
|
Person.Builder alice = people.get(0);
|
||||||
alice.setId(123);
|
alice.setId(123);
|
||||||
|
alice.setName("Alice");
|
||||||
alice.setName(new Text.Reader("Alice"));
|
alice.setEmail("alice@example.com");
|
||||||
|
|
||||||
alice.setEmail(new Text.Reader("alice@example.com"));
|
|
||||||
|
|
||||||
StructList.Builder<Person.PhoneNumber.Builder> alicePhones = alice.initPhones(1);
|
StructList.Builder<Person.PhoneNumber.Builder> alicePhones = alice.initPhones(1);
|
||||||
alicePhones.get(0).setNumber(new Text.Reader("555-1212"));
|
alicePhones.get(0).setNumber("555-1212");
|
||||||
alicePhones.get(0).setType(Person.PhoneNumber.Type.MOBILE);
|
alicePhones.get(0).setType(Person.PhoneNumber.Type.MOBILE);
|
||||||
alice.getEmployment().setSchool(new Text.Reader("MIT"));
|
alice.getEmployment().setSchool("MIT");
|
||||||
|
|
||||||
Person.Builder bob = people.get(1);
|
Person.Builder bob = people.get(1);
|
||||||
bob.setId(456);
|
bob.setId(456);
|
||||||
bob.setName(new Text.Reader("Bob"));
|
bob.setName("Bob");
|
||||||
bob.setEmail(new Text.Reader("bob@example.com"));
|
bob.setEmail("bob@example.com");
|
||||||
StructList.Builder<Person.PhoneNumber.Builder> bobPhones = bob.initPhones(2);
|
StructList.Builder<Person.PhoneNumber.Builder> bobPhones = bob.initPhones(2);
|
||||||
bobPhones.get(0).setNumber(new Text.Reader("555-4567"));
|
bobPhones.get(0).setNumber("555-4567");
|
||||||
bobPhones.get(0).setType(Person.PhoneNumber.Type.HOME);
|
bobPhones.get(0).setType(Person.PhoneNumber.Type.HOME);
|
||||||
bobPhones.get(1).setNumber(new Text.Reader("555-7654"));
|
bobPhones.get(1).setNumber("555-7654");
|
||||||
bobPhones.get(1).setType(Person.PhoneNumber.Type.WORK);
|
bobPhones.get(1).setType(Person.PhoneNumber.Type.WORK);
|
||||||
bob.getEmployment().setUnemployed(org.capnproto.Void.VOID);
|
bob.getEmployment().setUnemployed(org.capnproto.Void.VOID);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue