Commit 7197456b authored by Kenton Varda's avatar Kenton Varda

Delete Code Friday: Inline structs/lists/data are too complicated for not…

Delete Code Friday:  Inline structs/lists/data are too complicated for not enough benefit.  There goes a week of my life that I'll never get back.
parent de742607
......@@ -395,225 +395,18 @@ TEST(Encoding, UnionDefault) {
// =======================================================================================
TEST(Encoding, InlineStructUnionLayout) {
uint ptrOffset = TestInlineUnions::STRUCT_SIZE.data * BITS_PER_WORD / BITS - 64;
auto ptr = [=](uint i) { return ptrOffset + i * 64; };
#define INIT_UNION(setter) \
initUnion<TestInlineUnions>([](TestInlineUnions::Builder b) {b.setter;})
EXPECT_EQ(UnionState({ 0,0,0,0}, -1), INIT_UNION(getUnion0().initF0()));
EXPECT_EQ(UnionState({ 2,0,0,0}, 0), INIT_UNION(getUnion0().initF8().setF0(true)));
EXPECT_EQ(UnionState({ 3,0,0,0}, 0), INIT_UNION(getUnion0().initF16().setF0(1)));
EXPECT_EQ(UnionState({ 4,0,0,0}, 0), INIT_UNION(getUnion0().initF32().setF0(1)));
EXPECT_EQ(UnionState({ 5,0,0,0}, 0), INIT_UNION(getUnion0().initF64().setF0(1)));
EXPECT_EQ(UnionState({ 6,0,0,0}, 0), INIT_UNION(getUnion0().initF128().setF0(1)));
EXPECT_EQ(UnionState({ 7,0,0,0}, 0), INIT_UNION(getUnion0().initF192().setF0(1)));
EXPECT_EQ(UnionState({ 8,0,0,0}, -1), INIT_UNION(getUnion0().initF0p().initF()));
EXPECT_EQ(UnionState({10,0,0,0}, 0), INIT_UNION(getUnion0().initF8p().initF().setF0(true)));
EXPECT_EQ(UnionState({11,0,0,0}, 0), INIT_UNION(getUnion0().initF16p().initF().setF0(1)));
EXPECT_EQ(UnionState({12,0,0,0}, 0), INIT_UNION(getUnion0().initF32p().initF().setF0(1)));
EXPECT_EQ(UnionState({13,0,0,0}, 0), INIT_UNION(getUnion0().initF64p().initF().setF0(1)));
EXPECT_EQ(UnionState({14,0,0,0}, 0), INIT_UNION(getUnion0().initF128p().initF().setF0(1)));
EXPECT_EQ(UnionState({15,0,0,0}, 0), INIT_UNION(getUnion0().initF192p().initF().setF0(1)));
EXPECT_EQ(UnionState({ 8,0,0,0}, ptr(0)), INIT_UNION(getUnion0().initF0p().setP0("1")));
EXPECT_EQ(UnionState({10,0,0,0}, ptr(0)), INIT_UNION(getUnion0().initF8p().setP0("1")));
EXPECT_EQ(UnionState({11,0,0,0}, ptr(0)), INIT_UNION(getUnion0().initF16p().setP0("1")));
EXPECT_EQ(UnionState({12,0,0,0}, ptr(0)), INIT_UNION(getUnion0().initF32p().setP0("1")));
EXPECT_EQ(UnionState({13,0,0,0}, ptr(0)), INIT_UNION(getUnion0().initF64p().setP0("1")));
EXPECT_EQ(UnionState({14,0,0,0}, ptr(0)), INIT_UNION(getUnion0().initF128p().setP0("1")));
EXPECT_EQ(UnionState({15,0,0,0}, ptr(0)), INIT_UNION(getUnion0().initF192p().setP0("1")));
EXPECT_EQ(UnionState({0, 0,0,0}, -1), INIT_UNION(getUnion1().initF0()));
EXPECT_EQ(UnionState({0, 2,0,0}, 200), INIT_UNION(getUnion1().initF8().setF0(true)));
EXPECT_EQ(UnionState({0, 3,0,0}, 208), INIT_UNION(getUnion1().initF16().setF0(1)));
EXPECT_EQ(UnionState({0, 4,0,0}, 224), INIT_UNION(getUnion1().initF32().setF0(1)));
EXPECT_EQ(UnionState({0, 5,0,0}, 256), INIT_UNION(getUnion1().initF64().setF0(1)));
EXPECT_EQ(UnionState({0, 6,0,0}, 256), INIT_UNION(getUnion1().initF128().setF0(1)));
EXPECT_EQ(UnionState({0, 7,0,0}, 256), INIT_UNION(getUnion1().initF192().setF0(1)));
EXPECT_EQ(UnionState({0,0, 1,0}, 456), INIT_UNION(getUnion2().initF8p().initF().setF0(true)));
EXPECT_EQ(UnionState({0,0,0, 1}, 464), INIT_UNION(getUnion3().initF8p().initF().setF0(true)));
EXPECT_EQ(UnionState({0,0, 2,0}, 480), INIT_UNION(getUnion2().initF16p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0,0, 2}, 496), INIT_UNION(getUnion3().initF16p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0, 3,0}, 512), INIT_UNION(getUnion2().initF32p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0,0, 3}, 544), INIT_UNION(getUnion3().initF32p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0, 4,0}, 576), INIT_UNION(getUnion2().initF64p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0,0, 4}, 640), INIT_UNION(getUnion3().initF64p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0, 5,0}, 704), INIT_UNION(getUnion2().initF128p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0,0, 5}, 832), INIT_UNION(getUnion3().initF128p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0, 6,0}, 960), INIT_UNION(getUnion2().initF192p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0,0, 6},1152), INIT_UNION(getUnion3().initF192p().initF().setF0(1)));
EXPECT_EQ(UnionState({0,0, 1,0}, ptr( 3)), INIT_UNION(getUnion2().initF8p().setP0("1")));
EXPECT_EQ(UnionState({0,0,0, 1}, ptr( 4)), INIT_UNION(getUnion3().initF8p().setP0("1")));
EXPECT_EQ(UnionState({0,0, 2,0}, ptr( 5)), INIT_UNION(getUnion2().initF16p().setP0("1")));
EXPECT_EQ(UnionState({0,0,0, 2}, ptr( 7)), INIT_UNION(getUnion3().initF16p().setP0("1")));
EXPECT_EQ(UnionState({0,0, 3,0}, ptr( 5)), INIT_UNION(getUnion2().initF32p().setP0("1")));
EXPECT_EQ(UnionState({0,0,0, 3}, ptr( 7)), INIT_UNION(getUnion3().initF32p().setP0("1")));
EXPECT_EQ(UnionState({0,0, 4,0}, ptr( 5)), INIT_UNION(getUnion2().initF64p().setP0("1")));
EXPECT_EQ(UnionState({0,0,0, 4}, ptr( 7)), INIT_UNION(getUnion3().initF64p().setP0("1")));
EXPECT_EQ(UnionState({0,0, 5,0}, ptr( 9)), INIT_UNION(getUnion2().initF128p().setP0("1")));
EXPECT_EQ(UnionState({0,0,0, 5}, ptr(12)), INIT_UNION(getUnion3().initF128p().setP0("1")));
EXPECT_EQ(UnionState({0,0, 6,0}, ptr( 9)), INIT_UNION(getUnion2().initF192p().setP0("1")));
EXPECT_EQ(UnionState({0,0,0, 6}, ptr(12)), INIT_UNION(getUnion3().initF192p().setP0("1")));
#undef INIT_UNION
}
TEST(Encoding, InitInlineStruct) {
MallocMessageBuilder builder;
auto root = builder.getRoot<TestInlineLayout>();
// Set as many bits as we can.
root.setPad1(0xffu);
root.initF8().setF0(true);
root.getF8().setF1(true);
root.getF8().setF2(true);
root.initF16().setF0(0xffu);
root.getF16().setF1(0xffu);
root.initF32().setF0(0xffu);
root.getF32().setF1(0xffffu);
root.initF64().setF0(0xffu);
root.getF64().setF1(0xffffffffu);
root.initF128().setF0(0xffffffffffffffffull);
root.getF128().setF1(0xffffffffffffffffull);
root.initF192().setF0(0xffffffffffffffffull);
root.getF192().setF1(0xffffffffffffffffull);
root.getF192().setF2(0xffffffffffffffffull);
root.initF0p().setP0("foo");
root.setPad2(0xffu);
root.setPadP("foo");
root.initF8p().setP0("foo");
root.initF16p().setP0("foo");
root.getF16p().setP1("foo");
root.initF32p().setP0("foo");
root.getF32p().setP1("foo");
root.initF64p().setP0("foo");
root.getF64p().setP1("foo");
root.initF128p().setP0("foo");
root.getF128p().setP1("foo");
root.getF128p().setP2("foo");
root.initF192p().setP0("foo");
root.getF192p().setP1("foo");
root.getF192p().setP2("foo");
// Now try re-initializing each thing and making sure the surrounding things aren't modified.
EXPECT_FALSE(root.initF8().getF0());
EXPECT_FALSE(root.getF8().getF1());
EXPECT_FALSE(root.getF8().getF2());
EXPECT_EQ(0xffu, root.getPad1());
EXPECT_EQ(0xffu, root.getF16().getF0());
root.initF8().setF0(true);
root.getF8().setF1(true);
root.getF8().setF2(true);
EXPECT_EQ(0u, root.initF16().getF0());
EXPECT_EQ(0u, root.getF16().getF1());
EXPECT_TRUE(root.getF8().getF0());
EXPECT_TRUE(root.getF8().getF1());
EXPECT_TRUE(root.getF8().getF2());
EXPECT_EQ(0xffu, root.getF32().getF0());
root.getF16().setF0(0xffu);
root.getF16().setF1(0xffu);
EXPECT_EQ(0u, root.initF32().getF0());
EXPECT_EQ(0u, root.getF32().getF1());
EXPECT_EQ(0xffu, root.getF16().getF0());
EXPECT_EQ(0xffu, root.getF16().getF1());
EXPECT_EQ(0xffu, root.getF64().getF0());
root.getF32().setF0(0xffu);
root.getF32().setF1(0xffffu);
EXPECT_EQ(0u, root.initF64().getF0());
EXPECT_EQ(0u, root.getF64().getF1());
EXPECT_EQ(0xffu, root.getF32().getF0());
EXPECT_EQ(0xffffu, root.getF32().getF1());
EXPECT_EQ(0xffffffffffffffffull, root.getF128().getF0());
root.getF64().setF0(0xffu);
root.getF64().setF1(0xffffffffu);
EXPECT_EQ(0u, root.initF128().getF0());
EXPECT_EQ(0u, root.getF128().getF1());
EXPECT_EQ(0xffu, root.getF64().getF0());
EXPECT_EQ(0xffffffffu, root.getF64().getF1());
EXPECT_EQ(0xffffffffffffffffull, root.getF192().getF0());
root.getF128().setF0(0xffffffffffffffffull);
root.getF128().setF1(0xffffffffffffffffull);
EXPECT_EQ(0u, root.initF192().getF0());
EXPECT_EQ(0u, root.getF192().getF1());
EXPECT_EQ(0u, root.getF192().getF2());
EXPECT_EQ(0xffffffffffffffffull, root.getF128().getF0());
EXPECT_EQ(0xffffffffffffffffull, root.getF128().getF1());
EXPECT_EQ(0xffu, root.getPad2());
root.getF192().setF0(0xffffffffffffffffull);
root.getF192().setF1(0xffffffffffffffffull);
root.getF192().setF2(0xffffffffffffffffull);
EXPECT_EQ("", root.initF0p().getP0());
EXPECT_EQ("foo", root.getPadP());
root.getF0p().setP0("foo");
EXPECT_EQ("", root.initF8p().getP0());
EXPECT_EQ("foo", root.getPadP());
EXPECT_EQ("foo", root.getF16p().getP0());
root.initF8p().setP0("foo");
EXPECT_EQ("", root.initF16p().getP0());
EXPECT_EQ("", root.getF16p().getP1());
EXPECT_EQ("foo", root.getF8p().getP0());
EXPECT_EQ("foo", root.getF32p().getP0());
root.initF16p().setP0("foo");
root.getF16p().setP1("foo");
EXPECT_EQ("", root.initF32p().getP0());
EXPECT_EQ("", root.getF32p().getP1());
EXPECT_EQ("foo", root.getF16p().getP1());
EXPECT_EQ("foo", root.getF64p().getP0());
root.initF32p().setP0("foo");
root.getF32p().setP1("foo");
EXPECT_EQ("", root.initF64p().getP0());
EXPECT_EQ("", root.getF64p().getP1());
EXPECT_EQ("foo", root.getF32p().getP1());
EXPECT_EQ("foo", root.getF128p().getP0());
root.initF64p().setP0("foo");
root.getF64p().setP1("foo");
EXPECT_EQ("", root.initF128p().getP0());
EXPECT_EQ("", root.getF128p().getP1());
EXPECT_EQ("", root.getF128p().getP2());
EXPECT_EQ("foo", root.getF64p().getP1());
EXPECT_EQ("foo", root.getF192p().getP0());
root.initF128p().setP0("foo");
root.getF128p().setP1("foo");
root.getF128p().setP2("foo");
EXPECT_EQ("", root.initF192p().getP0());
EXPECT_EQ("", root.getF192p().getP1());
EXPECT_EQ("", root.getF192p().getP2());
EXPECT_EQ("foo", root.getF128p().getP2());
root.initF192p().setP0("foo");
root.getF192p().setP1("foo");
root.getF192p().setP2("foo");
}
TEST(Encoding, InlineDefaults) {
TEST(Encoding, ListDefaults) {
MallocMessageBuilder builder;
TestInlineDefaults::Builder root = builder.getRoot<TestInlineDefaults>();
TestListDefaults::Builder root = builder.getRoot<TestListDefaults>();
checkTestMessage(root.asReader());
checkTestMessage(root);
checkTestMessage(root.asReader());
}
TEST(Encoding, BuildInlineDefaults) {
TEST(Encoding, BuildListDefaults) {
MallocMessageBuilder builder;
TestInlineDefaults::Builder root = builder.getRoot<TestInlineDefaults>();
TestListDefaults::Builder root = builder.getRoot<TestListDefaults>();
initTestMessage(root);
checkTestMessage(root.asReader());
......@@ -621,244 +414,13 @@ TEST(Encoding, BuildInlineDefaults) {
checkTestMessage(root.asReader());
}
TEST(Encoding, InlineNotPresent) {
// Test that getting an inline field of a zero-sized struct works. This simulates what happens
// when a new inline field is added to a struct, then old data lacking that field is received.
AlignedData<1> emptyMessage = {{0, 0, 0, 0, 0, 0, 0, 0}};
ArrayPtr<const word> segments[1] = {arrayPtr(emptyMessage.words, 1)};
SegmentArrayMessageReader reader(arrayPtr(segments, 1));
{
auto normal = reader.getRoot<test::TestInlineLayout>();
EXPECT_FALSE(normal.getF8().getF0());
EXPECT_FALSE(normal.getF8().getF1());
EXPECT_FALSE(normal.getF8().getF2());
EXPECT_EQ(0u, normal.getF16().getF0());
EXPECT_EQ(0u, normal.getF16().getF1());
EXPECT_EQ(0u, normal.getF32().getF0());
EXPECT_EQ(0u, normal.getF32().getF1());
EXPECT_EQ(0u, normal.getF64().getF0());
EXPECT_EQ(0u, normal.getF64().getF1());
EXPECT_EQ(0u, normal.getF128().getF0());
EXPECT_EQ(0u, normal.getF128().getF1());
EXPECT_EQ(0u, normal.getF192().getF0());
EXPECT_EQ(0u, normal.getF192().getF1());
EXPECT_EQ(0u, normal.getF192().getF2());
EXPECT_FALSE(normal.getF8p().getF().getF0());
EXPECT_FALSE(normal.getF8p().getF().getF1());
EXPECT_FALSE(normal.getF8p().getF().getF2());
EXPECT_EQ(0u, normal.getF16p().getF().getF0());
EXPECT_EQ(0u, normal.getF16p().getF().getF1());
EXPECT_EQ(0u, normal.getF32p().getF().getF0());
EXPECT_EQ(0u, normal.getF32p().getF().getF1());
EXPECT_EQ(0u, normal.getF64p().getF().getF0());
EXPECT_EQ(0u, normal.getF64p().getF().getF1());
EXPECT_EQ(0u, normal.getF128p().getF().getF0());
EXPECT_EQ(0u, normal.getF128p().getF().getF1());
EXPECT_EQ(0u, normal.getF192p().getF().getF0());
EXPECT_EQ(0u, normal.getF192p().getF().getF1());
EXPECT_EQ(0u, normal.getF192p().getF().getF2());
EXPECT_EQ("", normal.getF0p().getP0());
EXPECT_EQ("", normal.getF8p().getP0());
EXPECT_EQ("", normal.getF16p().getP0());
EXPECT_EQ("", normal.getF16p().getP1());
EXPECT_EQ("", normal.getF32p().getP0());
EXPECT_EQ("", normal.getF32p().getP1());
EXPECT_EQ("", normal.getF64p().getP0());
EXPECT_EQ("", normal.getF64p().getP1());
EXPECT_EQ("", normal.getF128p().getP0());
EXPECT_EQ("", normal.getF128p().getP1());
EXPECT_EQ("", normal.getF128p().getP2());
EXPECT_EQ("", normal.getF192p().getP0());
EXPECT_EQ("", normal.getF192p().getP1());
EXPECT_EQ("", normal.getF192p().getP2());
}
{
auto lists = reader.getRoot<test::TestInlineLists>();
// Inline lists have fixed size even when "empty".
ASSERT_EQ(2u, lists.getVoidList().size());
ASSERT_EQ(3u, lists.getBoolList().size());
ASSERT_EQ(4u, lists.getUInt8List().size());
ASSERT_EQ(5u, lists.getUInt16List().size());
ASSERT_EQ(6u, lists.getUInt32List().size());
ASSERT_EQ(7u, lists.getUInt64List().size());
ASSERT_EQ(8u, lists.getTextList().size());
ASSERT_EQ(2u, lists.getStructList0().size());
ASSERT_EQ(3u, lists.getStructList1().size());
ASSERT_EQ(4u, lists.getStructList8().size());
ASSERT_EQ(2u, lists.getStructList16().size());
ASSERT_EQ(3u, lists.getStructList32().size());
ASSERT_EQ(4u, lists.getStructList64().size());
ASSERT_EQ(2u, lists.getStructList128().size());
ASSERT_EQ(3u, lists.getStructList192().size());
ASSERT_EQ(4u, lists.getStructList0p().size());
ASSERT_EQ(2u, lists.getStructList1p().size());
ASSERT_EQ(3u, lists.getStructList8p().size());
ASSERT_EQ(4u, lists.getStructList16p().size());
ASSERT_EQ(2u, lists.getStructList32p().size());
ASSERT_EQ(3u, lists.getStructList64p().size());
ASSERT_EQ(4u, lists.getStructList128p().size());
ASSERT_EQ(2u, lists.getStructList192p().size());
EXPECT_EQ(Void::VOID, lists.getVoidList()[0]);
EXPECT_EQ(Void::VOID, lists.getVoidList()[1]);
EXPECT_FALSE(lists.getBoolList()[0]);
EXPECT_FALSE(lists.getBoolList()[1]);
EXPECT_FALSE(lists.getBoolList()[2]);
EXPECT_EQ(0u, lists.getUInt8List()[0]);
EXPECT_EQ(0u, lists.getUInt8List()[1]);
EXPECT_EQ(0u, lists.getUInt8List()[2]);
EXPECT_EQ(0u, lists.getUInt8List()[3]);
EXPECT_EQ(0u, lists.getUInt16List()[0]);
EXPECT_EQ(0u, lists.getUInt16List()[1]);
EXPECT_EQ(0u, lists.getUInt16List()[2]);
EXPECT_EQ(0u, lists.getUInt16List()[3]);
EXPECT_EQ(0u, lists.getUInt16List()[4]);
EXPECT_EQ(0u, lists.getUInt32List()[0]);
EXPECT_EQ(0u, lists.getUInt32List()[1]);
EXPECT_EQ(0u, lists.getUInt32List()[2]);
EXPECT_EQ(0u, lists.getUInt32List()[3]);
EXPECT_EQ(0u, lists.getUInt32List()[4]);
EXPECT_EQ(0u, lists.getUInt32List()[5]);
for (uint i = 0; i < 7; i++) {
EXPECT_EQ(0u, lists.getUInt64List()[i]);
}
EXPECT_EQ("", lists.getTextList()[0]);
EXPECT_EQ("", lists.getTextList()[1]);
EXPECT_EQ("", lists.getTextList()[2]);
EXPECT_EQ("", lists.getTextList()[3]);
EXPECT_EQ("", lists.getTextList()[4]);
EXPECT_EQ("", lists.getTextList()[5]);
EXPECT_EQ("", lists.getTextList()[6]);
EXPECT_EQ("", lists.getTextList()[7]);
EXPECT_EQ(Void::VOID, lists.getStructList0()[0].getF());
EXPECT_EQ(Void::VOID, lists.getStructList0()[1].getF());
EXPECT_FALSE(lists.getStructList8()[0].getF0());
EXPECT_FALSE(lists.getStructList8()[0].getF1());
EXPECT_FALSE(lists.getStructList8()[0].getF2());
EXPECT_FALSE(lists.getStructList8()[1].getF0());
EXPECT_FALSE(lists.getStructList8()[1].getF1());
EXPECT_FALSE(lists.getStructList8()[1].getF2());
EXPECT_FALSE(lists.getStructList8()[2].getF0());
EXPECT_FALSE(lists.getStructList8()[2].getF1());
EXPECT_FALSE(lists.getStructList8()[2].getF2());
EXPECT_FALSE(lists.getStructList8()[3].getF0());
EXPECT_FALSE(lists.getStructList8()[3].getF1());
EXPECT_FALSE(lists.getStructList8()[3].getF2());
EXPECT_EQ(0u, lists.getStructList16()[0].getF0());
EXPECT_EQ(0u, lists.getStructList16()[0].getF1());
EXPECT_EQ(0u, lists.getStructList16()[1].getF0());
EXPECT_EQ(0u, lists.getStructList16()[1].getF1());
EXPECT_EQ(0u, lists.getStructList32()[0].getF0());
EXPECT_EQ(0u, lists.getStructList32()[0].getF1());
EXPECT_EQ(0u, lists.getStructList32()[1].getF0());
EXPECT_EQ(0u, lists.getStructList32()[1].getF1());
EXPECT_EQ(0u, lists.getStructList32()[2].getF0());
EXPECT_EQ(0u, lists.getStructList32()[2].getF1());
EXPECT_EQ(0u, lists.getStructList64()[0].getF0());
EXPECT_EQ(0u, lists.getStructList64()[0].getF1());
EXPECT_EQ(0u, lists.getStructList64()[1].getF0());
EXPECT_EQ(0u, lists.getStructList64()[1].getF1());
EXPECT_EQ(0u, lists.getStructList64()[2].getF0());
EXPECT_EQ(0u, lists.getStructList64()[2].getF1());
EXPECT_EQ(0u, lists.getStructList64()[3].getF0());
EXPECT_EQ(0u, lists.getStructList64()[3].getF1());
EXPECT_EQ(0ull, lists.getStructList128()[0].getF0());
EXPECT_EQ(0ull, lists.getStructList128()[0].getF1());
EXPECT_EQ(0ull, lists.getStructList128()[1].getF0());
EXPECT_EQ(0ull, lists.getStructList128()[1].getF1());
EXPECT_EQ(0ull, lists.getStructList192()[0].getF0());
EXPECT_EQ(0ull, lists.getStructList192()[0].getF1());
EXPECT_EQ(0ull, lists.getStructList192()[0].getF2());
EXPECT_EQ(0ull, lists.getStructList192()[1].getF0());
EXPECT_EQ(0ull, lists.getStructList192()[1].getF1());
EXPECT_EQ(0ull, lists.getStructList192()[1].getF2());
EXPECT_EQ(0ull, lists.getStructList192()[2].getF0());
EXPECT_EQ(0ull, lists.getStructList192()[2].getF1());
EXPECT_EQ(0ull, lists.getStructList192()[2].getF2());
EXPECT_EQ("", lists.getStructList0p()[0].getP0());
EXPECT_EQ("", lists.getStructList0p()[1].getP0());
EXPECT_EQ("", lists.getStructList0p()[2].getP0());
EXPECT_EQ("", lists.getStructList0p()[3].getP0());
EXPECT_FALSE(lists.getStructList8p()[0].getF().getF0());
EXPECT_EQ("", lists.getStructList8p()[0].getP0());
EXPECT_EQ("", lists.getStructList8p()[1].getP0());
EXPECT_EQ("", lists.getStructList8p()[2].getP0());
EXPECT_EQ(0u, lists.getStructList16p()[0].getF().getF0());
EXPECT_EQ("", lists.getStructList16p()[0].getP0());
EXPECT_EQ("", lists.getStructList16p()[0].getP1());
EXPECT_EQ("", lists.getStructList16p()[1].getP0());
EXPECT_EQ("", lists.getStructList16p()[1].getP1());
EXPECT_EQ("", lists.getStructList16p()[2].getP0());
EXPECT_EQ("", lists.getStructList16p()[2].getP1());
EXPECT_EQ("", lists.getStructList16p()[3].getP0());
EXPECT_EQ("", lists.getStructList16p()[3].getP1());
EXPECT_EQ(0u, lists.getStructList32p()[0].getF().getF1());
EXPECT_EQ("", lists.getStructList32p()[0].getP0());
EXPECT_EQ("", lists.getStructList32p()[0].getP1());
EXPECT_EQ("", lists.getStructList32p()[1].getP0());
EXPECT_EQ("", lists.getStructList32p()[1].getP1());
EXPECT_EQ(0u, lists.getStructList64p()[0].getF().getF1());
EXPECT_EQ("", lists.getStructList64p()[0].getP0());
EXPECT_EQ("", lists.getStructList64p()[0].getP1());
EXPECT_EQ("", lists.getStructList64p()[1].getP0());
EXPECT_EQ("", lists.getStructList64p()[1].getP1());
EXPECT_EQ("", lists.getStructList64p()[2].getP0());
EXPECT_EQ("", lists.getStructList64p()[2].getP1());
EXPECT_EQ(0ull, lists.getStructList128p()[0].getF().getF1());
EXPECT_EQ("", lists.getStructList128p()[0].getP0());
EXPECT_EQ("", lists.getStructList128p()[0].getP1());
EXPECT_EQ("", lists.getStructList128p()[0].getP2());
EXPECT_EQ("", lists.getStructList128p()[1].getP0());
EXPECT_EQ("", lists.getStructList128p()[1].getP1());
EXPECT_EQ("", lists.getStructList128p()[1].getP2());
EXPECT_EQ("", lists.getStructList128p()[2].getP0());
EXPECT_EQ("", lists.getStructList128p()[2].getP1());
EXPECT_EQ("", lists.getStructList128p()[2].getP2());
EXPECT_EQ("", lists.getStructList128p()[3].getP0());
EXPECT_EQ("", lists.getStructList128p()[3].getP1());
EXPECT_EQ("", lists.getStructList128p()[3].getP2());
EXPECT_EQ(0ull, lists.getStructList192p()[0].getF().getF2());
EXPECT_EQ("", lists.getStructList192p()[0].getP0());
EXPECT_EQ("", lists.getStructList192p()[0].getP1());
EXPECT_EQ("", lists.getStructList192p()[0].getP2());
EXPECT_EQ("", lists.getStructList192p()[1].getP0());
EXPECT_EQ("", lists.getStructList192p()[1].getP1());
EXPECT_EQ("", lists.getStructList192p()[1].getP2());
EXPECT_EQ(Data::Reader(std::string(5, '\0')), lists.getData());
}
}
TEST(Encoding, SmallStructLists) {
// In this test, we will manually initialize TestInlineDefaults.structLists to match the default
// In this test, we will manually initialize TestListDefaults.lists to match the default
// value and verify that we end up with the same encoding that the compiler produces.
MallocMessageBuilder builder;
auto root = builder.getRoot<TestInlineDefaults>();
auto sl = root.initStructLists();
auto root = builder.getRoot<TestListDefaults>();
auto sl = root.initLists();
// Verify that all the lists are actually empty.
EXPECT_EQ(0u, sl.getList0 ().size());
......@@ -868,6 +430,9 @@ TEST(Encoding, SmallStructLists) {
EXPECT_EQ(0u, sl.getList32().size());
EXPECT_EQ(0u, sl.getList64().size());
EXPECT_EQ(0u, sl.getListP ().size());
EXPECT_EQ(0u, sl.getInt32ListList().size());
EXPECT_EQ(0u, sl.getTextListList().size());
EXPECT_EQ(0u, sl.getStructListList().size());
{ auto l = sl.initList0 (2); l[0].setF(Void::VOID); l[1].setF(Void::VOID); }
{ auto l = sl.initList1 (2); l[0].setF(true); l[1].setF(false); }
......@@ -877,11 +442,35 @@ TEST(Encoding, SmallStructLists) {
{ auto l = sl.initList64(2); l[0].setF(1234567890123456u); l[1].setF(2345678901234567u); }
{ auto l = sl.initListP (2); l[0].setF("foo"); l[1].setF("bar"); }
{
auto l = sl.initInt32ListList(3);
l.init(0, 3).copyFrom({1, 2, 3});
l.init(1, 2).copyFrom({4, 5});
l.init(2, 1).copyFrom({12341234});
}
{
auto l = sl.initTextListList(3);
l.init(0, 2).copyFrom({"foo", "bar"});
l.init(1, 1).copyFrom({"baz"});
l.init(2, 2).copyFrom({"qux", "corge"});
}
{
auto l = sl.initStructListList(2);
l.init(0, 2);
l.init(1, 1);
l[0][0].setInt32Field(123);
l[0][1].setInt32Field(456);
l[1][0].setInt32Field(789);
}
ArrayPtr<const word> segment = builder.getSegmentsForOutput()[0];
// Initialize another message such that it copies the default value for that field.
MallocMessageBuilder defaultBuilder;
defaultBuilder.getRoot<TestInlineDefaults>().getStructLists();
defaultBuilder.getRoot<TestListDefaults>().getLists();
ArrayPtr<const word> defaultSegment = defaultBuilder.getSegmentsForOutput()[0];
// Should match...
......
......@@ -32,14 +32,6 @@
namespace capnproto {
namespace internal {
namespace {
// This zero array is used only as a default value for inlined fields, which are limited
// to no more than 64 words.
static const AlignedData<64> ZERO = {{0}};
} // namespace
// =======================================================================================
struct WireReference {
......@@ -1064,24 +1056,6 @@ StructReader StructReader::getStructField(
return WireHelpers::readStructReference(segment, ref, defaultValue, nestingLimit);
}
StructReader StructReader::getInlineStructField(
ByteCount dataOffset, ByteCount inlineDataSize,
WireReferenceCount refIndex, WireReferenceCount inlineRefCount) const {
if (dataOffset + inlineDataSize <= dataSize &&
refIndex + inlineRefCount <= referenceCount) {
return StructReader(
segment, reinterpret_cast<const byte*>(data) + dataOffset,
// WireReference is incomplete here so we have to cast around... Bah.
reinterpret_cast<const WireReference*>(
reinterpret_cast<const word*>(references) + refIndex * WORDS_PER_REFERENCE),
inlineDataSize, inlineRefCount,
nestingLimit);
} else {
// Return empty struct.
return StructReader();
}
}
ListReader StructReader::getListField(
WireReferenceCount refIndex, FieldSize expectedElementSize, const word* defaultValue) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex;
......@@ -1089,52 +1063,6 @@ ListReader StructReader::getListField(
segment, ref, defaultValue, expectedElementSize, nestingLimit);
}
ListReader StructReader::getInlineDataListField(
ByteCount offset, ElementCount elementCount, FieldSize elementSize) const {
if (offset + WireHelpers::roundUpToBytes(
elementCount * bitsPerElement(elementSize)) <= dataSize) {
return ListReader(
segment, reinterpret_cast<const byte*>(data) + offset, nullptr,
elementCount, bytesPerElement(elementSize), 0 * REFERENCES / ELEMENTS,
nestingLimit);
} else {
// Return zeros.
return ListReader(elementCount);
}
}
ListReader StructReader::getInlinePointerListField(
WireReferenceCount offset, ElementCount elementCount) const {
if (offset + elementCount * (1 * REFERENCES / ELEMENTS) <= referenceCount) {
return ListReader(
segment, nullptr,
reinterpret_cast<const WireReference*>(
reinterpret_cast<const word*>(references) + offset * WORDS_PER_REFERENCE),
elementCount, 0 * BYTES / ELEMENTS, 1 * REFERENCES / ELEMENTS,
nestingLimit);
} else {
// Return nulls.
return ListReader(elementCount);
}
}
ListReader StructReader::getInlineStructListField(
ByteCount dataOffset, WireReferenceCount ptrOffset, ElementCount elementCount,
StructSize elementSize) const {
if (dataOffset + elementSize.dataBytes <= dataSize &&
ptrOffset + elementSize.pointers <= referenceCount) {
return ListReader(
segment, reinterpret_cast<const byte*>(data) + dataOffset,
reinterpret_cast<const WireReference*>(
reinterpret_cast<const word*>(references) + ptrOffset * WORDS_PER_REFERENCE),
elementCount, elementSize.dataBytes / ELEMENTS, elementSize.pointers / ELEMENTS,
elementSize.dataBytes, elementSize.pointers, nestingLimit);
} else {
// Return empty structs.
return ListReader(elementCount);
}
}
Text::Reader StructReader::getTextField(
WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex;
......@@ -1147,17 +1075,6 @@ Data::Reader StructReader::getDataField(
return WireHelpers::readDataReference(segment, ref, defaultValue, defaultSize);
}
Data::Reader StructReader::getInlineDataField(ByteCount offset, ByteCount size) const {
// TODO(soon): Bounds check! Needs to fall back to some common zero'd region.
if (offset + size <= dataSize) {
return Data::Reader(reinterpret_cast<const char*>(reinterpret_cast<const byte*>(data) + offset),
size / BYTES);
} else {
CHECK(size < sizeof(ZERO) * BYTES);
return Data::Reader(reinterpret_cast<const char*>(ZERO.bytes), size / BYTES);
}
}
// =======================================================================================
// ListBuilder
......@@ -1230,12 +1147,6 @@ ListReader ListBuilder::asReader(StructSize elementSize) const {
// =======================================================================================
// ListReader
ListReader::ListReader(ElementCount elementCount)
: segment(nullptr), data(ZERO.bytes),
pointers(reinterpret_cast<const WireReference*>(data)), elementCount(elementCount),
stepBytes(0 * BYTES / ELEMENTS), stepPointers(0 * REFERENCES / ELEMENTS),
structDataSize(0), structReferenceCount(0), nestingLimit(0) {}
StructReader ListReader::getStructElement(ElementCount index) const {
// TODO: Inline this method?
VALIDATE_INPUT((segment == nullptr) | (nestingLimit > 0),
......
......@@ -93,11 +93,8 @@ enum class FieldSize: uint8_t {
// when you realize that you need to attach some extra information to each element of some
// primitive list.
//
// 2) For struct fields of composite types where the field's total size is known at compile time,
// we can embed the field directly into the parent struct to avoid indirection through a
// reference. However, this means that the field size can never change -- e.g. if it is a
// struct, new fields cannot be added to it. The field's struct type is therefore required to
// be declared "inline" with a fixed width.
// 2) At one point there was a notion of "inline" struct fields, but it was deemed too much of
// an implementation burden for too little gain, and so was deleted.
};
typedef decltype(BITS / ELEMENTS) BitsPerElement;
......@@ -293,17 +290,6 @@ public:
// initialized, it is initialized as a deep copy of the given default value (a trusted message),
// or to the empty state if defaultValue is nullptr.
CAPNPROTO_ALWAYS_INLINE(StructBuilder initInlineStructField(
ByteCount dataOffset, ByteCount inlineDataSize,
WireReferenceCount refIndex, WireReferenceCount inlineRefCount) const);
// Initialize an inlined struct field, given the position and size of the data and pointer
// sections.
CAPNPROTO_ALWAYS_INLINE(StructBuilder getInlineStructField(
ByteCount dataOffset, ByteCount inlineDataSize,
WireReferenceCount refIndex, WireReferenceCount inlineRefCount) const);
// Gets an inlined struct field, given the position and size of the data and pointer sections.
ListBuilder initListField(WireReferenceCount refIndex, FieldSize elementSize,
ElementCount elementCount) const;
// Allocates a new list of the given size for the field at the given index in the reference
......@@ -319,34 +305,6 @@ public:
// already allocated, it is allocated as a deep copy of the given default value (a trusted
// message). If the default value is null, an empty list is used.
CAPNPROTO_ALWAYS_INLINE(ListBuilder initInlineDataListField(
ByteCount offset, ByteCount inlineSize,
ElementCount elementCount, FieldSize elementSize) const);
// Initialize an inline list field.
CAPNPROTO_ALWAYS_INLINE(ListBuilder initInlinePointerListField(
WireReferenceCount offset, WireReferenceCount inlineSize,
ElementCount elementCount) const);
// Initialize an inline list field.
CAPNPROTO_ALWAYS_INLINE(ListBuilder initInlineStructListField(
ByteCount dataOffset, WireReferenceCount ptrOffset, ElementCount elementCount,
StructSize elementSize) const);
// Initialize an inline struct list field.
CAPNPROTO_ALWAYS_INLINE(ListBuilder getInlineDataListField(
ByteCount offset, ElementCount elementCount, FieldSize elementSize) const);
// Get an already-initialized inline list field.
CAPNPROTO_ALWAYS_INLINE(ListBuilder getInlinePointerListField(
WireReferenceCount offset, ElementCount elementCount) const);
// Get an already-initialized inline list field.
CAPNPROTO_ALWAYS_INLINE(ListBuilder getInlineStructListField(
ByteCount dataOffset, WireReferenceCount ptrOffset, ElementCount elementCount,
StructSize elementSize) const);
// Get an already-initialized inline struct list field.
Text::Builder initTextField(WireReferenceCount refIndex, ByteCount size) const;
// Initialize the text field to the given size in bytes (not including NUL terminator) and return
// a Text::Builder which can be used to fill in the content.
......@@ -364,14 +322,6 @@ public:
const void* defaultValue, ByteCount defaultSize) const;
// Same as *Text*, but for data blobs.
CAPNPROTO_ALWAYS_INLINE(Data::Builder getInlineDataField(
ByteCount offset, ByteCount size) const);
CAPNPROTO_ALWAYS_INLINE(void setInlineDataField(
ByteCount offset, ByteCount size, Data::Reader value) const);
CAPNPROTO_ALWAYS_INLINE(Data::Builder initInlineDataField(
ByteCount offset, ByteCount size) const);
// For InlineData.
StructReader asReader() const;
// Gets a StructReader pointing at the same memory.
......@@ -422,29 +372,11 @@ public:
// struct reference, which in turn points at the struct value. The default value is allowed to
// be null, in which case an empty struct is used.
StructReader getInlineStructField(
ByteCount dataOffset, ByteCount inlineDataSize,
WireReferenceCount refIndex, WireReferenceCount inlineRefCount) const;
// Gets an inlined struct field, given the position and size of the data and pointer sections.
ListReader getListField(WireReferenceCount refIndex, FieldSize expectedElementSize,
const word* defaultValue) const;
// Get the list field at the given index in the reference segment, or the default value if not
// initialized. The default value is allowed to be null, in which case an empty list is used.
ListReader getInlineDataListField(
ByteCount offset, ElementCount elementCount, FieldSize elementSize) const;
// Get an inline list field.
ListReader getInlinePointerListField(
WireReferenceCount offset, ElementCount elementCount) const;
// Get an inline list field.
ListReader getInlineStructListField(
ByteCount dataOffset, WireReferenceCount ptrOffset, ElementCount elementCount,
StructSize elementSize) const;
// Get an inline struct list field.
Text::Reader getTextField(WireReferenceCount refIndex,
const void* defaultValue, ByteCount defaultSize) const;
// Gets the text field, or the given default value if not initialized.
......@@ -453,9 +385,6 @@ public:
const void* defaultValue, ByteCount defaultSize) const;
// Gets the data field, or the given default value if not initialized.
Data::Reader getInlineDataField(ByteCount offset, ByteCount size) const;
// Gets the inline data field.
WireReferenceCount getReferenceCount() { return referenceCount; }
private:
......@@ -576,10 +505,6 @@ public:
stepBytes(0 * BYTES / ELEMENTS), stepPointers(0 * REFERENCES / ELEMENTS),
structDataSize(0), structReferenceCount(0), nestingLimit(0) {}
ListReader(ElementCount elementCount);
// Constructs a ListReader representing a list where all elements are zero. Intended to be used
// only for inlined lists that are out-of-bounds in the parent struct.
inline ElementCount size();
// The number of elements in the list.
......@@ -693,94 +618,6 @@ inline void StructBuilder::setDataField(
setDataField<typename MaskType<T>::Type>(offset, mask<T>(value, m));
}
inline StructBuilder StructBuilder::initInlineStructField(
ByteCount dataOffset, ByteCount inlineDataSize,
WireReferenceCount refIndex, WireReferenceCount inlineRefCount) const {
memset(reinterpret_cast<byte*>(data) + dataOffset, 0, inlineDataSize / BYTES);
memset(reinterpret_cast<word*>(references) + refIndex * WORDS_PER_REFERENCE,
0, inlineRefCount * WORDS_PER_REFERENCE * BYTES_PER_WORD / BYTES);
return getInlineStructField(dataOffset, inlineDataSize, refIndex, inlineRefCount);
}
inline StructBuilder StructBuilder::getInlineStructField(
ByteCount dataOffset, ByteCount inlineDataSize,
WireReferenceCount refIndex, WireReferenceCount inlineRefCount) const {
return StructBuilder(
segment, reinterpret_cast<byte*>(data) + dataOffset,
// WireReference is incomplete here so we have to cast around... Bah.
reinterpret_cast<WireReference*>(
reinterpret_cast<word*>(references) + refIndex * WORDS_PER_REFERENCE),
inlineRefCount);
}
inline ListBuilder StructBuilder::initInlineDataListField(
ByteCount offset, ByteCount inlineSize,
ElementCount elementCount, FieldSize elementSize) const {
memset(reinterpret_cast<byte*>(data) + offset, 0, inlineSize / BYTES);
return getInlineDataListField(offset, elementCount, elementSize);
}
inline ListBuilder StructBuilder::initInlinePointerListField(
WireReferenceCount offset, WireReferenceCount inlineSize,
ElementCount elementCount) const {
memset(reinterpret_cast<word*>(references) + offset * WORDS_PER_REFERENCE, 0,
inlineSize * BYTES_PER_REFERENCE / BYTES);
return getInlinePointerListField(offset, elementCount);
}
inline ListBuilder StructBuilder::initInlineStructListField(
ByteCount dataOffset, WireReferenceCount ptrOffset, ElementCount elementCount,
StructSize elementSize) const {
memset(reinterpret_cast<byte*>(data) + dataOffset, 0,
elementSize.dataBytes / BYTES);
memset(reinterpret_cast<word*>(references) + ptrOffset * WORDS_PER_REFERENCE, 0,
elementSize.pointers * BYTES_PER_REFERENCE / BYTES);
return getInlineStructListField(dataOffset, ptrOffset, elementCount, elementSize);
}
inline ListBuilder StructBuilder::getInlineDataListField(
ByteCount offset, ElementCount elementCount, FieldSize elementSize) const {
return ListBuilder(
segment, reinterpret_cast<byte*>(data) + offset, nullptr,
bytesPerElement(elementSize), 0 * REFERENCES / ELEMENTS, elementCount);
}
inline ListBuilder StructBuilder::getInlinePointerListField(
WireReferenceCount offset, ElementCount elementCount) const {
return ListBuilder(
segment, nullptr,
reinterpret_cast<WireReference*>(
reinterpret_cast<word*>(references) + offset * WORDS_PER_REFERENCE),
0 * BYTES / ELEMENTS, 1 * REFERENCES / ELEMENTS, elementCount);
}
inline ListBuilder StructBuilder::getInlineStructListField(
ByteCount dataOffset, WireReferenceCount ptrOffset, ElementCount elementCount,
StructSize elementSize) const {
return ListBuilder(
segment, reinterpret_cast<byte*>(data) + dataOffset,
reinterpret_cast<WireReference*>(
reinterpret_cast<word*>(references) + ptrOffset * WORDS_PER_REFERENCE),
elementSize.dataBytes / ELEMENTS, elementSize.pointers / ELEMENTS,
elementCount);
}
inline Data::Builder StructBuilder::getInlineDataField(
ByteCount offset, ByteCount size) const {
return Data::Builder(
reinterpret_cast<char*>(reinterpret_cast<byte*>(data) + offset), size / BYTES);
}
inline void StructBuilder::setInlineDataField(
ByteCount offset, ByteCount size, Data::Reader value) const {
getInlineDataField(offset, size).copyFrom(value);
}
inline Data::Builder StructBuilder::initInlineDataField(
ByteCount offset, ByteCount size) const {
byte* ptr = reinterpret_cast<byte*>(data) + offset;
memset(ptr, 0, size / BYTES);
return Data::Builder(reinterpret_cast<char*>(ptr), size / BYTES);
}
// -------------------------------------------------------------------
template <typename T>
......
......@@ -51,10 +51,6 @@ struct PointerHelpers;
template <typename T, bool isPrimitive = internal::IsPrimitive<T>::value>
struct List;
template <typename T, size_t size>
struct InlineList: public List<T> {};
// Alias for List. Primarily exists so that we can specialize List<InlineList<...>>.
namespace internal {
template <size_t size> struct FieldSizeForByteSize;
......@@ -412,86 +408,6 @@ private:
friend struct internal::PointerHelpers;
};
template <typename T, size_t subSize>
struct List<InlineList<T, subSize>, false> {
// List of inline lists.
class Reader {
public:
Reader() = default;
inline explicit Reader(internal::ListReader reader): reader(reader) {}
inline uint size() { return reader.size() / ELEMENTS / subSize; }
inline typename List<T>::Reader operator[](uint index) {
return typename List<T>::Reader(reader.slice(
index * subSize * ELEMENTS, subSize * ELEMENTS));
}
typedef internal::IndexingIterator<Reader, typename List<T>::Reader> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
private:
internal::ListReader reader;
};
class Builder {
public:
Builder() = default;
inline explicit Builder(internal::ListBuilder builder): builder(builder) {}
inline uint size() { return builder.size() / ELEMENTS / subSize; }
inline typename List<T>::Builder operator[](uint index) {
return typename List<T>::Builder(builder.slice(
index * subSize * ELEMENTS, subSize * ELEMENTS));
}
typedef internal::IndexingIterator<Builder, typename List<T>::Builder> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
template <typename Other>
void copyFrom(const Other& other);
void copyFrom(std::initializer_list<typename List<T>::Reader> other);
// TODO
private:
internal::ListBuilder builder;
};
private:
inline static internal::ListBuilder initAsElementOf(
internal::ListBuilder& builder, uint index, uint size) {
return List<T>::initAsElementOf(builder, index, size * subSize);
}
inline static internal::ListBuilder getAsElementOf(
internal::ListBuilder& builder, uint index) {
return List<T>::getAsElementOf(builder, index);
}
inline static internal::ListReader getAsElementOf(
internal::ListReader& reader, uint index) {
return List<T>::getAsElementOf(reader, index);
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return List<T>::initAsFieldOf(builder, index, size * subSize);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return List<T>::getAsFieldOf(builder, index);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return List<T>::getAsFieldOf(reader, index);
}
template <typename U, bool b>
friend class List;
template <typename U>
friend struct internal::PointerHelpers;
};
template <>
struct List<Data, false> {
class Reader {
......@@ -589,103 +505,6 @@ private:
friend struct internal::PointerHelpers;
};
template <size_t subSize>
struct List<InlineData<subSize>, false> {
// List of inline data.
class Reader {
public:
Reader() = default;
inline explicit Reader(Data::Reader reader): reader(reader) {}
inline uint size() { return reader.size() / subSize; }
inline typename Data::Reader operator[](uint index) {
return typename Data::Reader(reader.slice(
index * subSize, index * subSize + subSize));
}
typedef internal::IndexingIterator<Reader, typename Data::Reader> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
private:
Data::Reader reader;
};
class Builder {
public:
Builder() = default;
inline explicit Builder(Data::Builder builder): builder(builder) {}
inline uint size() { return builder.size() / subSize; }
inline typename Data::Builder operator[](uint index) {
return typename Data::Builder(builder.slice(
index * subSize, index * subSize + subSize));
}
inline void set(uint index, Data::Reader value) {
(*this)[index].copyFrom(value);
}
typedef internal::IndexingIterator<Builder, typename Data::Builder> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
template <typename Other>
void copyFrom(const Other& other) {
auto i = other.begin();
auto end = other.end();
uint pos = 0;
for (; i != end && pos < size(); ++i) {
set(pos, *i);
}
CAPNPROTO_INLINE_DPRECOND(pos == size() && i == end,
"List::copyFrom() argument had different size.");
}
void copyFrom(std::initializer_list<Data::Reader> other) {
CAPNPROTO_INLINE_DPRECOND(other.size() == size(),
"List::copyFrom() argument had different size.");
for (uint i = 0; i < other.size(); i++) {
set(i, other.begin()[i]);
}
}
private:
Data::Builder builder;
};
private:
inline static Data::Builder initAsElementOf(
internal::ListBuilder& builder, uint index, uint size) {
return builder.initDataElement(index * ELEMENTS, size * subSize * BYTES);
}
inline static Data::Builder getAsElementOf(
internal::ListBuilder& builder, uint index) {
return builder.getDataElement(index * ELEMENTS);
}
inline static Data::Reader getAsElementOf(
internal::ListReader& reader, uint index) {
return reader.getDataElement(index * ELEMENTS);
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initDataField(index, size * subSize * BYTES);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getDataField(index, nullptr, 0 * BYTES);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getDataField(index, nullptr, 0 * BYTES);
}
template <typename U, bool b>
friend class List;
template <typename U>
friend struct internal::PointerHelpers;
};
template <>
struct List<Text, false> {
class Reader {
......
......@@ -325,963 +325,109 @@ void genericCheckTestMessageAllZero(Reader reader) {
}
template <typename Builder>
void genericInitInlineDefaults(Builder builder) {
{
auto normal = builder.initNormal();
normal.getF8().setF0(true);
normal.getF8().setF1(false);
normal.getF8().setF2(true);
normal.getF16().setF0(123u);
normal.getF16().setF1(45u);
normal.getF32().setF0(67u);
normal.getF32().setF1(8901u);
normal.getF64().setF0(234u);
normal.getF64().setF1(567890123u);
normal.getF128().setF0(1234567890123ull);
normal.getF128().setF1(4567890123456ull);
normal.getF192().setF0(7890123456789ull);
normal.getF192().setF1(2345678901234ull);
normal.getF192().setF2(5678901234567ull);
normal.getF8p().getF().setF0(true);
normal.getF8p().getF().setF1(true);
normal.getF8p().getF().setF2(false);
normal.getF16p().getF().setF0(98u);
normal.getF16p().getF().setF1(76u);
normal.getF32p().getF().setF0(54u);
normal.getF32p().getF().setF1(32109u);
normal.getF64p().getF().setF0(87u);
normal.getF64p().getF().setF1(654321098u);
normal.getF128p().getF().setF0(7654321098765ull);
normal.getF128p().getF().setF1(4321098765432ull);
normal.getF192p().getF().setF0(1098765432109ull);
normal.getF192p().getF().setF1(8765432109876ull);
normal.getF192p().getF().setF2(5432109876543ull);
normal.getF0p().setP0("foo");
normal.getF8p().setP0("baz");
normal.getF16p().setP0("qux");
normal.getF16p().setP1("quux");
normal.getF32p().setP0("corge");
normal.getF32p().setP1("grault");
normal.getF64p().setP0("garply");
normal.getF64p().setP1("waldo");
normal.getF128p().setP0("fred");
normal.getF128p().setP1("plugh");
normal.getF128p().setP2("xyzzy");
normal.getF192p().setP0("thud");
normal.getF192p().setP1("foobar");
normal.getF192p().setP2("barbaz");
}
void genericInitListDefaults(Builder builder) {
auto lists = builder.initLists();
lists.initList0(2);
lists.initList1(2);
lists.initList8(2);
lists.initList16(2);
lists.initList32(2);
lists.initList64(2);
lists.initListP(2);
lists.getList0()[0].setF(Void::VOID);
lists.getList0()[1].setF(Void::VOID);
lists.getList1()[0].setF(true);
lists.getList1()[1].setF(false);
lists.getList8()[0].setF(123u);
lists.getList8()[1].setF(45u);
lists.getList16()[0].setF(12345u);
lists.getList16()[1].setF(6789u);
lists.getList32()[0].setF(123456789u);
lists.getList32()[1].setF(234567890u);
lists.getList64()[0].setF(1234567890123456u);
lists.getList64()[1].setF(2345678901234567u);
lists.getListP()[0].setF("foo");
lists.getListP()[1].setF("bar");
{
auto unions = builder.initUnions();
unions.getUnion0().initF32().setF0(67u);
unions.getUnion0().getF32().setF1(8901u);
unions.getUnion1().initF128().setF0(1234567890123ull);
unions.getUnion1().getF128().setF1(4567890123456ull);
unions.getUnion3().initF16p().getF().setF0(98u);
unions.getUnion3().getF16p().getF().setF1(76u);
unions.getUnion3().getF16p().setP0("qux");
unions.getUnion3().getF16p().setP1("quux");
auto l = lists.initInt32ListList(3);
l.init(0, 3).copyFrom({1, 2, 3});
l.init(1, 2).copyFrom({4, 5});
l.init(2, 1).copyFrom({12341234});
}
{
auto lists = builder.initLists();
ASSERT_EQ(2u, lists.getVoidList().size());
ASSERT_EQ(3u, lists.getBoolList().size());
ASSERT_EQ(4u, lists.getUInt8List().size());
ASSERT_EQ(5u, lists.getUInt16List().size());
ASSERT_EQ(6u, lists.getUInt32List().size());
ASSERT_EQ(7u, lists.getUInt64List().size());
ASSERT_EQ(8u, lists.getTextList().size());
ASSERT_EQ(2u, lists.getStructList0().size());
ASSERT_EQ(3u, lists.getStructList1().size());
ASSERT_EQ(4u, lists.getStructList8().size());
ASSERT_EQ(2u, lists.getStructList16().size());
ASSERT_EQ(3u, lists.getStructList32().size());
ASSERT_EQ(4u, lists.getStructList64().size());
ASSERT_EQ(2u, lists.getStructList128().size());
ASSERT_EQ(3u, lists.getStructList192().size());
ASSERT_EQ(4u, lists.getStructList0p().size());
ASSERT_EQ(2u, lists.getStructList1p().size());
ASSERT_EQ(3u, lists.getStructList8p().size());
ASSERT_EQ(4u, lists.getStructList16p().size());
ASSERT_EQ(2u, lists.getStructList32p().size());
ASSERT_EQ(3u, lists.getStructList64p().size());
ASSERT_EQ(4u, lists.getStructList128p().size());
ASSERT_EQ(2u, lists.getStructList192p().size());
lists.getVoidList().set(0, Void::VOID);
lists.getVoidList().set(1, Void::VOID);
lists.getBoolList().set(0, false);
lists.getBoolList().set(1, true);
lists.getBoolList().set(2, false);
lists.getUInt8List().set(0, 12u);
lists.getUInt8List().set(1, 34u);
lists.getUInt8List().set(2, 56u);
lists.getUInt8List().set(3, 78u);
lists.getUInt16List().set(0, 1234u);
lists.getUInt16List().set(1, 5678u);
lists.getUInt16List().set(2, 9012u);
lists.getUInt16List().set(3, 3456u);
lists.getUInt16List().set(4, 7890u);
lists.getUInt32List().set(0, 123456789u);
lists.getUInt32List().set(1, 234567890u);
lists.getUInt32List().set(2, 345678901u);
lists.getUInt32List().set(3, 456789012u);
lists.getUInt32List().set(4, 567890123u);
lists.getUInt32List().set(5, 678901234u);
for (uint i = 0; i < 7; i++) {
lists.getUInt64List().set(i, i + 1);
}
lists.getTextList().set(0, "foo");
lists.getTextList().set(1, "bar");
lists.getTextList().set(2, "baz");
lists.getTextList().set(3, "qux");
lists.getTextList().set(4, "quux");
lists.getTextList().set(5, "corge");
lists.getTextList().set(6, "grault");
lists.getTextList().set(7, "garply");
lists.getStructList0()[0].setF(Void::VOID);
lists.getStructList0()[1].setF(Void::VOID);
lists.getStructList8()[0].setF0(true);
lists.getStructList8()[0].setF1(false);
lists.getStructList8()[0].setF2(false);
lists.getStructList8()[1].setF0(false);
lists.getStructList8()[1].setF1(true);
lists.getStructList8()[1].setF2(false);
lists.getStructList8()[2].setF0(true);
lists.getStructList8()[2].setF1(true);
lists.getStructList8()[2].setF2(false);
lists.getStructList8()[3].setF0(false);
lists.getStructList8()[3].setF1(false);
lists.getStructList8()[3].setF2(true);
lists.getStructList16()[0].setF0(12u);
lists.getStructList16()[0].setF1(34u);
lists.getStructList16()[1].setF0(56u);
lists.getStructList16()[1].setF1(78u);
lists.getStructList32()[0].setF0(90u);
lists.getStructList32()[0].setF1(12345u);
lists.getStructList32()[1].setF0(67u);
lists.getStructList32()[1].setF1(8901u);
lists.getStructList32()[2].setF0(23u);
lists.getStructList32()[2].setF1(45678u);
lists.getStructList64()[0].setF0(90u);
lists.getStructList64()[0].setF1(123456789u);
lists.getStructList64()[1].setF0(12u);
lists.getStructList64()[1].setF1(345678901u);
lists.getStructList64()[2].setF0(234u);
lists.getStructList64()[2].setF1(567890123u);
lists.getStructList64()[3].setF0(45u);
lists.getStructList64()[3].setF1(678901234u);
lists.getStructList128()[0].setF0(56789012345678ull);
lists.getStructList128()[0].setF1(90123456789012ull);
lists.getStructList128()[1].setF0(34567890123456ull);
lists.getStructList128()[1].setF1(78901234567890ull);
lists.getStructList192()[0].setF0(1234567890123ull);
lists.getStructList192()[0].setF1(4567890123456ull);
lists.getStructList192()[0].setF2(7890123456789ull);
lists.getStructList192()[1].setF0( 123456789012ull);
lists.getStructList192()[1].setF1(3456789012345ull);
lists.getStructList192()[1].setF2(6789012345678ull);
lists.getStructList192()[2].setF0(9012345678901ull);
lists.getStructList192()[2].setF1(2345678901234ull);
lists.getStructList192()[2].setF2(5678901234567ull);
lists.getStructList0p()[0].setP0("foo");
lists.getStructList0p()[1].setP0("bar");
lists.getStructList0p()[2].setP0("baz");
lists.getStructList0p()[3].setP0("qux");
lists.getStructList8p()[0].getF().setF0(true);
lists.getStructList8p()[0].setP0("grault");
lists.getStructList8p()[1].setP0("garply");
lists.getStructList8p()[2].setP0("waldo");
lists.getStructList16p()[0].getF().setF0(123u);
lists.getStructList16p()[0].setP0("fred");
lists.getStructList16p()[0].setP1("plugh");
lists.getStructList16p()[1].setP0("xyzzy");
lists.getStructList16p()[1].setP1("thud");
lists.getStructList16p()[2].setP0("foobar");
lists.getStructList16p()[2].setP1("barbaz");
lists.getStructList16p()[3].setP0("bazqux");
lists.getStructList16p()[3].setP1("quxquux");
lists.getStructList32p()[0].getF().setF1(12345u);
lists.getStructList32p()[0].setP0("quuxcorge");
lists.getStructList32p()[0].setP1("corgegrault");
lists.getStructList32p()[1].setP0("graultgarply");
lists.getStructList32p()[1].setP1("garplywaldo");
lists.getStructList64p()[0].getF().setF1(123456789u);
lists.getStructList64p()[0].setP0("waldofred");
lists.getStructList64p()[0].setP1("fredplugh");
lists.getStructList64p()[1].setP0("plughxyzzy");
lists.getStructList64p()[1].setP1("xyzzythud");
lists.getStructList64p()[2].setP0("thudfoo");
lists.getStructList64p()[2].setP1("foofoo");
lists.getStructList128p()[0].getF().setF1(123456789012345ull);
lists.getStructList128p()[0].setP0("foobaz");
lists.getStructList128p()[0].setP1("fooqux");
lists.getStructList128p()[0].setP2("foocorge");
lists.getStructList128p()[1].setP0("barbaz");
lists.getStructList128p()[1].setP1("barqux");
lists.getStructList128p()[1].setP2("barcorge");
lists.getStructList128p()[2].setP0("bazbaz");
lists.getStructList128p()[2].setP1("bazqux");
lists.getStructList128p()[2].setP2("bazcorge");
lists.getStructList128p()[3].setP0("quxbaz");
lists.getStructList128p()[3].setP1("quxqux");
lists.getStructList128p()[3].setP2("quxcorge");
lists.getStructList192p()[0].getF().setF2(123456789012345ull);
lists.getStructList192p()[0].setP0("corgebaz");
lists.getStructList192p()[0].setP1("corgequx");
lists.getStructList192p()[0].setP2("corgecorge");
lists.getStructList192p()[1].setP0("graultbaz");
lists.getStructList192p()[1].setP1("graultqux");
lists.getStructList192p()[1].setP2("graultcorge");
lists.setData("12345");
auto l = lists.initTextListList(3);
l.init(0, 2).copyFrom({"foo", "bar"});
l.init(1, 1).copyFrom({"baz"});
l.init(2, 2).copyFrom({"qux", "corge"});
}
{
auto sl = builder.initStructLists();
sl.initList0(2);
sl.initList1(2);
sl.initList8(2);
sl.initList16(2);
sl.initList32(2);
sl.initList64(2);
sl.initListP(2);
sl.getList0()[0].setF(Void::VOID);
sl.getList0()[1].setF(Void::VOID);
sl.getList1()[0].setF(true);
sl.getList1()[1].setF(false);
sl.getList8()[0].setF(123u);
sl.getList8()[1].setF(45u);
sl.getList16()[0].setF(12345u);
sl.getList16()[1].setF(6789u);
sl.getList32()[0].setF(123456789u);
sl.getList32()[1].setF(234567890u);
sl.getList64()[0].setF(1234567890123456u);
sl.getList64()[1].setF(2345678901234567u);
sl.getListP()[0].setF("foo");
sl.getListP()[1].setF("bar");
}
{
auto ll = builder.initListLists();
{
auto l = ll.initInt32ListList(3);
l.init(0, 3).copyFrom({1, 2, 3});
l.init(1, 2).copyFrom({4, 5});
l.init(2, 1).copyFrom({12341234});
}
{
auto l = ll.initTextListList(3);
l.init(0, 2).copyFrom({"foo", "bar"});
l.init(1, 1).copyFrom({"baz"});
l.init(2, 2).copyFrom({"qux", "corge"});
}
{
auto l = ll.initStructListList(2);
auto e = l.init(0, 2);
e[0].setInt32Field(123);
e[1].setInt32Field(456);
e = l.init(1, 1);
e[0].setInt32Field(789);
}
{
auto l = ll.initInt32InlineListList(2);
l[0].copyFrom({1, 2, 3, 4, 5, 6, 123456789});
l[1].copyFrom({987654321, 6, 5, 4, 3, 2, 1});
}
{
auto l = ll.initTextInlineListList(3);
l[0].copyFrom({"grault1", "grault2", "grault3", "grault4", "grault5"});
l[1].copyFrom({"garply1", "garply2", "garply3", "garply4", "garply5"});
l[2].copyFrom({"waldo1", "waldo2", "waldo3", "waldo4", "waldo5"});
}
{
auto l = ll.initStructInlineListList(3);
ASSERT_EQ(3u, l[0].size());
ASSERT_EQ(3u, l[1].size());
ASSERT_EQ(3u, l[2].size());
l[0][0].getF().setF1(123);
l[0][1].getF().setF1(456);
l[0][2].getF().setF1(789);
l[1][0].getF().setF1(321);
l[1][1].getF().setF1(654);
l[1][2].getF().setF1(987);
l[2][0].getF().setF1(111);
l[2][1].getF().setF1(222);
l[2][2].getF().setF1(333);
l[0][0].setP0("fred1");
l[0][1].setP0("fred2");
l[0][2].setP0("fred3");
l[1][0].setP0("plugh1");
l[1][1].setP0("plugh2");
l[1][2].setP0("plugh3");
l[2][0].setP0("thud1");
l[2][1].setP0("thud2");
l[2][2].setP0("thud3");
}
ll.setInlineDataList({"123456789", "234567890", "345678901", "456789012", "567890123"});
{
auto l = ll.initInt32InlineListListList(3);
l.init(0, 3);
l.init(1, 2);
l.init(2, 1);
ASSERT_EQ(2u, l[0][0].size());
ASSERT_EQ(2u, l[0][1].size());
ASSERT_EQ(2u, l[0][2].size());
ASSERT_EQ(2u, l[1][0].size());
ASSERT_EQ(2u, l[1][1].size());
ASSERT_EQ(2u, l[2][0].size());
l[0][0].copyFrom({1, 2});
l[0][1].copyFrom({3, 4});
l[0][2].copyFrom({5, 6});
l[1][0].copyFrom({7, 8});
l[1][1].copyFrom({9, 10});
l[2][0].copyFrom({1234567, 7654321});
}
{
auto l = ll.initTextInlineListListList(2);
l.init(0, 2);
l.init(1, 1);
ASSERT_EQ(5u, l[0][0].size());
ASSERT_EQ(5u, l[0][1].size());
ASSERT_EQ(5u, l[1][0].size());
l[0][0].copyFrom({"1", "2", "3", "4", "5"});
l[0][1].copyFrom({"foo", "bar", "baz", "qux", "corge"});
l[1][0].copyFrom({"z", "y", "x", "w", "v"});
}
{
auto l = ll.initStructInlineListListList(2);
l.init(0, 2);
l.init(1, 1);
ASSERT_EQ(3u, l[0][0].size());
ASSERT_EQ(3u, l[0][1].size());
ASSERT_EQ(3u, l[1][0].size());
l[0][0][0].getF().setF1(123);
l[0][0][1].getF().setF1(456);
l[0][0][2].getF().setF1(789);
l[0][1][0].getF().setF1(321);
l[0][1][1].getF().setF1(654);
l[0][1][2].getF().setF1(987);
l[1][0][0].getF().setF1(111);
l[1][0][1].getF().setF1(222);
l[1][0][2].getF().setF1(333);
l[0][0][0].setP0("fred1");
l[0][0][1].setP0("fred2");
l[0][0][2].setP0("fred3");
l[0][1][0].setP0("plugh1");
l[0][1][1].setP0("plugh2");
l[0][1][2].setP0("plugh3");
l[1][0][0].setP0("thud1");
l[1][0][1].setP0("thud2");
l[1][0][2].setP0("thud3");
}
{
auto l = ll.initInlineDataListList(2);
l.init(0, 3).copyFrom({"foo", "bar", "baz"});
l.init(1, 2).copyFrom({"123", "234"});
}
auto l = lists.initStructListList(2);
auto e = l.init(0, 2);
e[0].setInt32Field(123);
e[1].setInt32Field(456);
e = l.init(1, 1);
e[0].setInt32Field(789);
}
}
template <typename Reader>
void genericCheckInlineDefaults(Reader reader) {
{
auto normal = reader.getNormal();
EXPECT_TRUE(normal.getF8().getF0());
EXPECT_FALSE(normal.getF8().getF1());
EXPECT_TRUE(normal.getF8().getF2());
EXPECT_EQ(123u, normal.getF16().getF0());
EXPECT_EQ(45u, normal.getF16().getF1());
EXPECT_EQ(67u, normal.getF32().getF0());
EXPECT_EQ(8901u, normal.getF32().getF1());
EXPECT_EQ(234u, normal.getF64().getF0());
EXPECT_EQ(567890123u, normal.getF64().getF1());
EXPECT_EQ(1234567890123ull, normal.getF128().getF0());
EXPECT_EQ(4567890123456ull, normal.getF128().getF1());
EXPECT_EQ(7890123456789ull, normal.getF192().getF0());
EXPECT_EQ(2345678901234ull, normal.getF192().getF1());
EXPECT_EQ(5678901234567ull, normal.getF192().getF2());
EXPECT_TRUE(normal.getF8p().getF().getF0());
EXPECT_TRUE(normal.getF8p().getF().getF1());
EXPECT_FALSE(normal.getF8p().getF().getF2());
EXPECT_EQ(98u, normal.getF16p().getF().getF0());
EXPECT_EQ(76u, normal.getF16p().getF().getF1());
EXPECT_EQ(54u, normal.getF32p().getF().getF0());
EXPECT_EQ(32109u, normal.getF32p().getF().getF1());
EXPECT_EQ(87u, normal.getF64p().getF().getF0());
EXPECT_EQ(654321098u, normal.getF64p().getF().getF1());
EXPECT_EQ(7654321098765ull, normal.getF128p().getF().getF0());
EXPECT_EQ(4321098765432ull, normal.getF128p().getF().getF1());
EXPECT_EQ(1098765432109ull, normal.getF192p().getF().getF0());
EXPECT_EQ(8765432109876ull, normal.getF192p().getF().getF1());
EXPECT_EQ(5432109876543ull, normal.getF192p().getF().getF2());
EXPECT_EQ("foo", normal.getF0p().getP0());
EXPECT_EQ("baz", normal.getF8p().getP0());
EXPECT_EQ("qux", normal.getF16p().getP0());
EXPECT_EQ("quux", normal.getF16p().getP1());
EXPECT_EQ("corge", normal.getF32p().getP0());
EXPECT_EQ("grault", normal.getF32p().getP1());
EXPECT_EQ("garply", normal.getF64p().getP0());
EXPECT_EQ("waldo", normal.getF64p().getP1());
EXPECT_EQ("fred", normal.getF128p().getP0());
EXPECT_EQ("plugh", normal.getF128p().getP1());
EXPECT_EQ("xyzzy", normal.getF128p().getP2());
EXPECT_EQ("thud", normal.getF192p().getP0());
EXPECT_EQ("foobar", normal.getF192p().getP1());
EXPECT_EQ("barbaz", normal.getF192p().getP2());
}
{
auto unions = reader.getUnions();
ASSERT_EQ(TestInlineUnions::Union0::F32, unions.getUnion0().which());
EXPECT_EQ(67u, unions.getUnion0().getF32().getF0());
EXPECT_EQ(8901u, unions.getUnion0().getF32().getF1());
ASSERT_EQ(TestInlineUnions::Union1::F128, unions.getUnion1().which());
EXPECT_EQ(1234567890123ull, unions.getUnion1().getF128().getF0());
EXPECT_EQ(4567890123456ull, unions.getUnion1().getF128().getF1());
ASSERT_EQ(TestInlineUnions::Union3::F16P, unions.getUnion3().which());
EXPECT_EQ(98u, unions.getUnion3().getF16p().getF().getF0());
EXPECT_EQ(76u, unions.getUnion3().getF16p().getF().getF1());
EXPECT_EQ("qux", unions.getUnion3().getF16p().getP0());
EXPECT_EQ("quux", unions.getUnion3().getF16p().getP1());
}
{
auto lists = reader.getLists();
ASSERT_EQ(2u, lists.getVoidList().size());
ASSERT_EQ(3u, lists.getBoolList().size());
ASSERT_EQ(4u, lists.getUInt8List().size());
ASSERT_EQ(5u, lists.getUInt16List().size());
ASSERT_EQ(6u, lists.getUInt32List().size());
ASSERT_EQ(7u, lists.getUInt64List().size());
ASSERT_EQ(8u, lists.getTextList().size());
ASSERT_EQ(2u, lists.getStructList0().size());
ASSERT_EQ(3u, lists.getStructList1().size());
ASSERT_EQ(4u, lists.getStructList8().size());
ASSERT_EQ(2u, lists.getStructList16().size());
ASSERT_EQ(3u, lists.getStructList32().size());
ASSERT_EQ(4u, lists.getStructList64().size());
ASSERT_EQ(2u, lists.getStructList128().size());
ASSERT_EQ(3u, lists.getStructList192().size());
ASSERT_EQ(4u, lists.getStructList0p().size());
ASSERT_EQ(2u, lists.getStructList1p().size());
ASSERT_EQ(3u, lists.getStructList8p().size());
ASSERT_EQ(4u, lists.getStructList16p().size());
ASSERT_EQ(2u, lists.getStructList32p().size());
ASSERT_EQ(3u, lists.getStructList64p().size());
ASSERT_EQ(4u, lists.getStructList128p().size());
ASSERT_EQ(2u, lists.getStructList192p().size());
EXPECT_EQ(Void::VOID, lists.getVoidList()[0]);
EXPECT_EQ(Void::VOID, lists.getVoidList()[1]);
EXPECT_FALSE(lists.getBoolList()[0]);
EXPECT_TRUE(lists.getBoolList()[1]);
EXPECT_FALSE(lists.getBoolList()[2]);
EXPECT_EQ(12u, lists.getUInt8List()[0]);
EXPECT_EQ(34u, lists.getUInt8List()[1]);
EXPECT_EQ(56u, lists.getUInt8List()[2]);
EXPECT_EQ(78u, lists.getUInt8List()[3]);
EXPECT_EQ(1234u, lists.getUInt16List()[0]);
EXPECT_EQ(5678u, lists.getUInt16List()[1]);
EXPECT_EQ(9012u, lists.getUInt16List()[2]);
EXPECT_EQ(3456u, lists.getUInt16List()[3]);
EXPECT_EQ(7890u, lists.getUInt16List()[4]);
EXPECT_EQ(123456789u, lists.getUInt32List()[0]);
EXPECT_EQ(234567890u, lists.getUInt32List()[1]);
EXPECT_EQ(345678901u, lists.getUInt32List()[2]);
EXPECT_EQ(456789012u, lists.getUInt32List()[3]);
EXPECT_EQ(567890123u, lists.getUInt32List()[4]);
EXPECT_EQ(678901234u, lists.getUInt32List()[5]);
for (uint i = 0; i < 7; i++) {
EXPECT_EQ(i + 1, lists.getUInt64List()[i]);
}
EXPECT_EQ("foo", lists.getTextList()[0]);
EXPECT_EQ("bar", lists.getTextList()[1]);
EXPECT_EQ("baz", lists.getTextList()[2]);
EXPECT_EQ("qux", lists.getTextList()[3]);
EXPECT_EQ("quux", lists.getTextList()[4]);
EXPECT_EQ("corge", lists.getTextList()[5]);
EXPECT_EQ("grault", lists.getTextList()[6]);
EXPECT_EQ("garply", lists.getTextList()[7]);
EXPECT_EQ(Void::VOID, lists.getStructList0()[0].getF());
EXPECT_EQ(Void::VOID, lists.getStructList0()[1].getF());
EXPECT_TRUE (lists.getStructList8()[0].getF0());
EXPECT_FALSE(lists.getStructList8()[0].getF1());
EXPECT_FALSE(lists.getStructList8()[0].getF2());
EXPECT_FALSE(lists.getStructList8()[1].getF0());
EXPECT_TRUE (lists.getStructList8()[1].getF1());
EXPECT_FALSE(lists.getStructList8()[1].getF2());
EXPECT_TRUE (lists.getStructList8()[2].getF0());
EXPECT_TRUE (lists.getStructList8()[2].getF1());
EXPECT_FALSE(lists.getStructList8()[2].getF2());
EXPECT_FALSE(lists.getStructList8()[3].getF0());
EXPECT_FALSE(lists.getStructList8()[3].getF1());
EXPECT_TRUE (lists.getStructList8()[3].getF2());
EXPECT_EQ(12u, lists.getStructList16()[0].getF0());
EXPECT_EQ(34u, lists.getStructList16()[0].getF1());
EXPECT_EQ(56u, lists.getStructList16()[1].getF0());
EXPECT_EQ(78u, lists.getStructList16()[1].getF1());
EXPECT_EQ(90u, lists.getStructList32()[0].getF0());
EXPECT_EQ(12345u, lists.getStructList32()[0].getF1());
EXPECT_EQ(67u, lists.getStructList32()[1].getF0());
EXPECT_EQ(8901u, lists.getStructList32()[1].getF1());
EXPECT_EQ(23u, lists.getStructList32()[2].getF0());
EXPECT_EQ(45678u, lists.getStructList32()[2].getF1());
EXPECT_EQ(90u, lists.getStructList64()[0].getF0());
EXPECT_EQ(123456789u, lists.getStructList64()[0].getF1());
EXPECT_EQ(12u, lists.getStructList64()[1].getF0());
EXPECT_EQ(345678901u, lists.getStructList64()[1].getF1());
EXPECT_EQ(234u, lists.getStructList64()[2].getF0());
EXPECT_EQ(567890123u, lists.getStructList64()[2].getF1());
EXPECT_EQ(45u, lists.getStructList64()[3].getF0());
EXPECT_EQ(678901234u, lists.getStructList64()[3].getF1());
EXPECT_EQ(56789012345678ull, lists.getStructList128()[0].getF0());
EXPECT_EQ(90123456789012ull, lists.getStructList128()[0].getF1());
EXPECT_EQ(34567890123456ull, lists.getStructList128()[1].getF0());
EXPECT_EQ(78901234567890ull, lists.getStructList128()[1].getF1());
EXPECT_EQ(1234567890123ull, lists.getStructList192()[0].getF0());
EXPECT_EQ(4567890123456ull, lists.getStructList192()[0].getF1());
EXPECT_EQ(7890123456789ull, lists.getStructList192()[0].getF2());
EXPECT_EQ( 123456789012ull, lists.getStructList192()[1].getF0());
EXPECT_EQ(3456789012345ull, lists.getStructList192()[1].getF1());
EXPECT_EQ(6789012345678ull, lists.getStructList192()[1].getF2());
EXPECT_EQ(9012345678901ull, lists.getStructList192()[2].getF0());
EXPECT_EQ(2345678901234ull, lists.getStructList192()[2].getF1());
EXPECT_EQ(5678901234567ull, lists.getStructList192()[2].getF2());
EXPECT_EQ("foo", lists.getStructList0p()[0].getP0());
EXPECT_EQ("bar", lists.getStructList0p()[1].getP0());
EXPECT_EQ("baz", lists.getStructList0p()[2].getP0());
EXPECT_EQ("qux", lists.getStructList0p()[3].getP0());
EXPECT_TRUE(lists.getStructList8p()[0].getF().getF0());
EXPECT_EQ("grault", lists.getStructList8p()[0].getP0());
EXPECT_EQ("garply", lists.getStructList8p()[1].getP0());
EXPECT_EQ("waldo", lists.getStructList8p()[2].getP0());
EXPECT_EQ(123u, lists.getStructList16p()[0].getF().getF0());
EXPECT_EQ("fred", lists.getStructList16p()[0].getP0());
EXPECT_EQ("plugh", lists.getStructList16p()[0].getP1());
EXPECT_EQ("xyzzy", lists.getStructList16p()[1].getP0());
EXPECT_EQ("thud", lists.getStructList16p()[1].getP1());
EXPECT_EQ("foobar", lists.getStructList16p()[2].getP0());
EXPECT_EQ("barbaz", lists.getStructList16p()[2].getP1());
EXPECT_EQ("bazqux", lists.getStructList16p()[3].getP0());
EXPECT_EQ("quxquux", lists.getStructList16p()[3].getP1());
EXPECT_EQ(12345u, lists.getStructList32p()[0].getF().getF1());
EXPECT_EQ("quuxcorge", lists.getStructList32p()[0].getP0());
EXPECT_EQ("corgegrault", lists.getStructList32p()[0].getP1());
EXPECT_EQ("graultgarply", lists.getStructList32p()[1].getP0());
EXPECT_EQ("garplywaldo", lists.getStructList32p()[1].getP1());
EXPECT_EQ(123456789u, lists.getStructList64p()[0].getF().getF1());
EXPECT_EQ("waldofred", lists.getStructList64p()[0].getP0());
EXPECT_EQ("fredplugh", lists.getStructList64p()[0].getP1());
EXPECT_EQ("plughxyzzy", lists.getStructList64p()[1].getP0());
EXPECT_EQ("xyzzythud", lists.getStructList64p()[1].getP1());
EXPECT_EQ("thudfoo", lists.getStructList64p()[2].getP0());
EXPECT_EQ("foofoo", lists.getStructList64p()[2].getP1());
EXPECT_EQ(123456789012345ull, lists.getStructList128p()[0].getF().getF1());
EXPECT_EQ("foobaz", lists.getStructList128p()[0].getP0());
EXPECT_EQ("fooqux", lists.getStructList128p()[0].getP1());
EXPECT_EQ("foocorge", lists.getStructList128p()[0].getP2());
EXPECT_EQ("barbaz", lists.getStructList128p()[1].getP0());
EXPECT_EQ("barqux", lists.getStructList128p()[1].getP1());
EXPECT_EQ("barcorge", lists.getStructList128p()[1].getP2());
EXPECT_EQ("bazbaz", lists.getStructList128p()[2].getP0());
EXPECT_EQ("bazqux", lists.getStructList128p()[2].getP1());
EXPECT_EQ("bazcorge", lists.getStructList128p()[2].getP2());
EXPECT_EQ("quxbaz", lists.getStructList128p()[3].getP0());
EXPECT_EQ("quxqux", lists.getStructList128p()[3].getP1());
EXPECT_EQ("quxcorge", lists.getStructList128p()[3].getP2());
EXPECT_EQ(123456789012345ull, lists.getStructList192p()[0].getF().getF2());
EXPECT_EQ("corgebaz", lists.getStructList192p()[0].getP0());
EXPECT_EQ("corgequx", lists.getStructList192p()[0].getP1());
EXPECT_EQ("corgecorge", lists.getStructList192p()[0].getP2());
EXPECT_EQ("graultbaz", lists.getStructList192p()[1].getP0());
EXPECT_EQ("graultqux", lists.getStructList192p()[1].getP1());
EXPECT_EQ("graultcorge", lists.getStructList192p()[1].getP2());
EXPECT_EQ("12345", lists.getData());
}
void genericCheckListDefaults(Reader reader) {
auto lists = reader.getLists();
ASSERT_EQ(2u, lists.getList0().size());
ASSERT_EQ(2u, lists.getList1().size());
ASSERT_EQ(2u, lists.getList8().size());
ASSERT_EQ(2u, lists.getList16().size());
ASSERT_EQ(2u, lists.getList32().size());
ASSERT_EQ(2u, lists.getList64().size());
ASSERT_EQ(2u, lists.getListP().size());
EXPECT_EQ(Void::VOID, lists.getList0()[0].getF());
EXPECT_EQ(Void::VOID, lists.getList0()[1].getF());
EXPECT_TRUE(lists.getList1()[0].getF());
EXPECT_FALSE(lists.getList1()[1].getF());
EXPECT_EQ(123u, lists.getList8()[0].getF());
EXPECT_EQ(45u, lists.getList8()[1].getF());
EXPECT_EQ(12345u, lists.getList16()[0].getF());
EXPECT_EQ(6789u, lists.getList16()[1].getF());
EXPECT_EQ(123456789u, lists.getList32()[0].getF());
EXPECT_EQ(234567890u, lists.getList32()[1].getF());
EXPECT_EQ(1234567890123456u, lists.getList64()[0].getF());
EXPECT_EQ(2345678901234567u, lists.getList64()[1].getF());
EXPECT_EQ("foo", lists.getListP()[0].getF());
EXPECT_EQ("bar", lists.getListP()[1].getF());
{
auto sl = reader.getStructLists();
ASSERT_EQ(2u, sl.getList0().size());
ASSERT_EQ(2u, sl.getList1().size());
ASSERT_EQ(2u, sl.getList8().size());
ASSERT_EQ(2u, sl.getList16().size());
ASSERT_EQ(2u, sl.getList32().size());
ASSERT_EQ(2u, sl.getList64().size());
ASSERT_EQ(2u, sl.getListP().size());
EXPECT_EQ(Void::VOID, sl.getList0()[0].getF());
EXPECT_EQ(Void::VOID, sl.getList0()[1].getF());
EXPECT_TRUE(sl.getList1()[0].getF());
EXPECT_FALSE(sl.getList1()[1].getF());
EXPECT_EQ(123u, sl.getList8()[0].getF());
EXPECT_EQ(45u, sl.getList8()[1].getF());
EXPECT_EQ(12345u, sl.getList16()[0].getF());
EXPECT_EQ(6789u, sl.getList16()[1].getF());
EXPECT_EQ(123456789u, sl.getList32()[0].getF());
EXPECT_EQ(234567890u, sl.getList32()[1].getF());
EXPECT_EQ(1234567890123456u, sl.getList64()[0].getF());
EXPECT_EQ(2345678901234567u, sl.getList64()[1].getF());
EXPECT_EQ("foo", sl.getListP()[0].getF());
EXPECT_EQ("bar", sl.getListP()[1].getF());
auto l = lists.getInt32ListList();
ASSERT_EQ(3u, l.size());
checkList(l[0], {1, 2, 3});
checkList(l[1], {4, 5});
checkList(l[2], {12341234});
}
{
auto ll = reader.getListLists();
{
auto l = ll.getInt32ListList();
ASSERT_EQ(3u, l.size());
checkList(l[0], {1, 2, 3});
checkList(l[1], {4, 5});
checkList(l[2], {12341234});
}
{
auto l = ll.getTextListList();
ASSERT_EQ(3u, l.size());
checkList(l[0], {"foo", "bar"});
checkList(l[1], {"baz"});
checkList(l[2], {"qux", "corge"});
}
{
auto l = ll.getStructListList();
ASSERT_EQ(2u, l.size());
auto e = l[0];
ASSERT_EQ(2u, e.size());
EXPECT_EQ(123, e[0].getInt32Field());
EXPECT_EQ(456, e[1].getInt32Field());
e = l[1];
ASSERT_EQ(1u, e.size());
EXPECT_EQ(789, e[0].getInt32Field());
}
{
auto l = ll.getInt32InlineListList();
ASSERT_EQ(2u, l.size());
checkList(l[0], {1, 2, 3, 4, 5, 6, 123456789});
checkList(l[1], {987654321, 6, 5, 4, 3, 2, 1});
}
{
auto l = ll.getTextInlineListList();
ASSERT_EQ(3u, l.size());
checkList(l[0], {"grault1", "grault2", "grault3", "grault4", "grault5"});
checkList(l[1], {"garply1", "garply2", "garply3", "garply4", "garply5"});
checkList(l[2], {"waldo1", "waldo2", "waldo3", "waldo4", "waldo5"});
}
{
auto l = ll.getStructInlineListList();
ASSERT_EQ(3u, l.size());
ASSERT_EQ(3u, l[0].size());
ASSERT_EQ(3u, l[1].size());
ASSERT_EQ(3u, l[2].size());
EXPECT_EQ(123, l[0][0].getF().getF1());
EXPECT_EQ(456, l[0][1].getF().getF1());
EXPECT_EQ(789, l[0][2].getF().getF1());
EXPECT_EQ(321, l[1][0].getF().getF1());
EXPECT_EQ(654, l[1][1].getF().getF1());
EXPECT_EQ(987, l[1][2].getF().getF1());
EXPECT_EQ(111, l[2][0].getF().getF1());
EXPECT_EQ(222, l[2][1].getF().getF1());
EXPECT_EQ(333, l[2][2].getF().getF1());
EXPECT_EQ("fred1", l[0][0].getP0());
EXPECT_EQ("fred2", l[0][1].getP0());
EXPECT_EQ("fred3", l[0][2].getP0());
EXPECT_EQ("plugh1", l[1][0].getP0());
EXPECT_EQ("plugh2", l[1][1].getP0());
EXPECT_EQ("plugh3", l[1][2].getP0());
EXPECT_EQ("thud1", l[2][0].getP0());
EXPECT_EQ("thud2", l[2][1].getP0());
EXPECT_EQ("thud3", l[2][2].getP0());
}
checkList(ll.getInlineDataList(),
{"123456789", "234567890", "345678901", "456789012", "567890123"});
{
auto l = ll.getInt32InlineListListList();
ASSERT_EQ(3u, l.size());
ASSERT_EQ(3u, l[0].size());
ASSERT_EQ(2u, l[1].size());
ASSERT_EQ(1u, l[2].size());
ASSERT_EQ(2u, l[0][0].size());
ASSERT_EQ(2u, l[0][1].size());
ASSERT_EQ(2u, l[0][2].size());
ASSERT_EQ(2u, l[1][0].size());
ASSERT_EQ(2u, l[1][1].size());
ASSERT_EQ(2u, l[2][0].size());
checkList(l[0][0], {1, 2});
checkList(l[0][1], {3, 4});
checkList(l[0][2], {5, 6});
checkList(l[1][0], {7, 8});
checkList(l[1][1], {9, 10});
checkList(l[2][0], {1234567, 7654321});
}
{
auto l = ll.getTextInlineListListList();
ASSERT_EQ(2u, l.size());
ASSERT_EQ(2u, l[0].size());
ASSERT_EQ(1u, l[1].size());
ASSERT_EQ(5u, l[0][0].size());
ASSERT_EQ(5u, l[0][1].size());
ASSERT_EQ(5u, l[1][0].size());
checkList(l[0][0], {"1", "2", "3", "4", "5"});
checkList(l[0][1], {"foo", "bar", "baz", "qux", "corge"});
checkList(l[1][0], {"z", "y", "x", "w", "v"});
}
{
auto l = ll.getStructInlineListListList();
ASSERT_EQ(2u, l.size());
ASSERT_EQ(2u, l[0].size());
ASSERT_EQ(1u, l[1].size());
ASSERT_EQ(3u, l[0][0].size());
ASSERT_EQ(3u, l[0][1].size());
ASSERT_EQ(3u, l[1][0].size());
EXPECT_EQ(123, l[0][0][0].getF().getF1());
EXPECT_EQ(456, l[0][0][1].getF().getF1());
EXPECT_EQ(789, l[0][0][2].getF().getF1());
EXPECT_EQ(321, l[0][1][0].getF().getF1());
EXPECT_EQ(654, l[0][1][1].getF().getF1());
EXPECT_EQ(987, l[0][1][2].getF().getF1());
EXPECT_EQ(111, l[1][0][0].getF().getF1());
EXPECT_EQ(222, l[1][0][1].getF().getF1());
EXPECT_EQ(333, l[1][0][2].getF().getF1());
EXPECT_EQ("fred1", l[0][0][0].getP0());
EXPECT_EQ("fred2", l[0][0][1].getP0());
EXPECT_EQ("fred3", l[0][0][2].getP0());
EXPECT_EQ("plugh1", l[0][1][0].getP0());
EXPECT_EQ("plugh2", l[0][1][1].getP0());
EXPECT_EQ("plugh3", l[0][1][2].getP0());
EXPECT_EQ("thud1", l[1][0][0].getP0());
EXPECT_EQ("thud2", l[1][0][1].getP0());
EXPECT_EQ("thud3", l[1][0][2].getP0());
}
{
auto l = ll.getInlineDataListList();
ASSERT_EQ(2u, l.size());
checkList(l[0], {"foo", "bar", "baz"});
checkList(l[1], {"123", "234"});
}
}
}
template <typename Builder>
void genericInitEmptyInlineLists(Builder builder) {
// Initialize all inline lists in TestInlineDefaults to "empty" values, of the same sizes that
// genericInitInlineDefaults() would create.
builder.initNormal();
{
auto lists = builder.initLists();
ASSERT_EQ(2u, lists.getVoidList().size());
ASSERT_EQ(3u, lists.getBoolList().size());
ASSERT_EQ(4u, lists.getUInt8List().size());
ASSERT_EQ(5u, lists.getUInt16List().size());
ASSERT_EQ(6u, lists.getUInt32List().size());
ASSERT_EQ(7u, lists.getUInt64List().size());
ASSERT_EQ(8u, lists.getTextList().size());
ASSERT_EQ(2u, lists.getStructList0().size());
ASSERT_EQ(3u, lists.getStructList1().size());
ASSERT_EQ(4u, lists.getStructList8().size());
ASSERT_EQ(2u, lists.getStructList16().size());
ASSERT_EQ(3u, lists.getStructList32().size());
ASSERT_EQ(4u, lists.getStructList64().size());
ASSERT_EQ(2u, lists.getStructList128().size());
ASSERT_EQ(3u, lists.getStructList192().size());
ASSERT_EQ(4u, lists.getStructList0p().size());
ASSERT_EQ(2u, lists.getStructList1p().size());
ASSERT_EQ(3u, lists.getStructList8p().size());
ASSERT_EQ(4u, lists.getStructList16p().size());
ASSERT_EQ(2u, lists.getStructList32p().size());
ASSERT_EQ(3u, lists.getStructList64p().size());
ASSERT_EQ(4u, lists.getStructList128p().size());
ASSERT_EQ(2u, lists.getStructList192p().size());
}
{
auto sl = builder.initStructLists();
sl.initList0(2);
sl.initList1(2);
sl.initList8(2);
sl.initList16(2);
sl.initList32(2);
sl.initList64(2);
sl.initListP(2);
auto l = lists.getTextListList();
ASSERT_EQ(3u, l.size());
checkList(l[0], {"foo", "bar"});
checkList(l[1], {"baz"});
checkList(l[2], {"qux", "corge"});
}
{
auto ll = builder.initListLists();
{
auto l = ll.initInt32ListList(3);
l.init(0, 3);
l.init(1, 2);
l.init(2, 1);
}
{
auto l = ll.initTextListList(3);
l.init(0, 2);
l.init(1, 1);
l.init(2, 2);
}
{
auto l = ll.initStructListList(2);
l.init(0, 2);
l.init(1, 1);
}
{
auto l = ll.initInt32InlineListList(2);
EXPECT_EQ(7u, l[0].size());
EXPECT_EQ(7u, l[1].size());
}
{
auto l = ll.initTextInlineListList(3);
EXPECT_EQ(5u, l[0].size());
EXPECT_EQ(5u, l[1].size());
EXPECT_EQ(5u, l[2].size());
}
{
auto l = ll.initStructInlineListList(3);
EXPECT_EQ(3u, l[0].size());
EXPECT_EQ(3u, l[1].size());
EXPECT_EQ(3u, l[2].size());
}
ll.initInlineDataList(5);
{
auto l = ll.initInt32InlineListListList(3);
l.init(0, 3);
l.init(1, 2);
l.init(2, 1);
EXPECT_EQ(2u, l[0][0].size());
EXPECT_EQ(2u, l[0][1].size());
EXPECT_EQ(2u, l[0][2].size());
EXPECT_EQ(2u, l[1][0].size());
EXPECT_EQ(2u, l[1][1].size());
EXPECT_EQ(2u, l[2][0].size());
}
{
auto l = ll.initTextInlineListListList(2);
l.init(0, 2);
l.init(1, 1);
EXPECT_EQ(5u, l[0][0].size());
EXPECT_EQ(5u, l[0][1].size());
EXPECT_EQ(5u, l[1][0].size());
}
{
auto l = ll.initStructInlineListListList(2);
l.init(0, 2);
l.init(1, 1);
EXPECT_EQ(3u, l[0][0].size());
EXPECT_EQ(3u, l[0][1].size());
EXPECT_EQ(3u, l[1][0].size());
}
{
auto l = ll.initInlineDataListList(2);
l.init(0, 3);
l.init(1, 2);
}
auto l = lists.getStructListList();
ASSERT_EQ(2u, l.size());
auto e = l[0];
ASSERT_EQ(2u, e.size());
EXPECT_EQ(123, e[0].getInt32Field());
EXPECT_EQ(456, e[1].getInt32Field());
e = l[1];
ASSERT_EQ(1u, e.size());
EXPECT_EQ(789, e[0].getInt32Field());
}
}
......@@ -1289,15 +435,15 @@ void genericInitEmptyInlineLists(Builder builder) {
void initTestMessage(TestAllTypes::Builder builder) { genericInitTestMessage(builder); }
void initTestMessage(TestDefaults::Builder builder) { genericInitTestMessage(builder); }
void initTestMessage(TestInlineDefaults::Builder builder) { genericInitInlineDefaults(builder); }
void initTestMessage(TestListDefaults::Builder builder) { genericInitListDefaults(builder); }
void checkTestMessage(TestAllTypes::Builder builder) { genericCheckTestMessage(builder); }
void checkTestMessage(TestDefaults::Builder builder) { genericCheckTestMessage(builder); }
void checkTestMessage(TestInlineDefaults::Builder builder) { genericCheckInlineDefaults(builder); }
void checkTestMessage(TestListDefaults::Builder builder) { genericCheckListDefaults(builder); }
void checkTestMessage(TestAllTypes::Reader reader) { genericCheckTestMessage(reader); }
void checkTestMessage(TestDefaults::Reader reader) { genericCheckTestMessage(reader); }
void checkTestMessage(TestInlineDefaults::Reader reader) { genericCheckInlineDefaults(reader); }
void checkTestMessage(TestListDefaults::Reader reader) { genericCheckListDefaults(reader); }
void checkTestMessageAllZero(TestAllTypes::Builder builder) {
genericCheckTestMessageAllZero(builder);
......
......@@ -59,21 +59,19 @@ using ::capnproto_test::capnproto::test::TestUnion;
using ::capnproto_test::capnproto::test::TestUnionDefaults;
using ::capnproto_test::capnproto::test::TestNestedTypes;
using ::capnproto_test::capnproto::test::TestUsing;
using ::capnproto_test::capnproto::test::TestInlineLayout;
using ::capnproto_test::capnproto::test::TestInlineUnions;
using ::capnproto_test::capnproto::test::TestInlineDefaults;
using ::capnproto_test::capnproto::test::TestListDefaults;
void initTestMessage(TestAllTypes::Builder builder);
void initTestMessage(TestDefaults::Builder builder);
void initTestMessage(TestInlineDefaults::Builder builder);
void initTestMessage(TestListDefaults::Builder builder);
void checkTestMessage(TestAllTypes::Builder builder);
void checkTestMessage(TestDefaults::Builder builder);
void checkTestMessage(TestInlineDefaults::Builder builder);
void checkTestMessage(TestListDefaults::Builder builder);
void checkTestMessage(TestAllTypes::Reader reader);
void checkTestMessage(TestDefaults::Reader reader);
void checkTestMessage(TestInlineDefaults::Reader reader);
void checkTestMessage(TestListDefaults::Reader reader);
void checkTestMessageAllZero(TestAllTypes::Builder builder);
void checkTestMessageAllZero(TestAllTypes::Reader reader);
......
......@@ -284,141 +284,7 @@ struct TestUsing {
innerNestedEnum @0 :NestedEnum = quux;
}
struct TestInline0 fixed() { f @0: Void; }
struct TestInline8 fixed(1 bytes) { f0 @0: Bool; f1 @1: Bool; f2 @2: Bool; }
struct TestInline16 fixed(2 bytes) { f0 @0: UInt8; f1 @1: UInt8; }
struct TestInline32 fixed(4 bytes) { f0 @0: UInt8; f1 @1: UInt16; }
struct TestInline64 fixed(8 bytes) { f0 @0: UInt8; f1 @1: UInt32; }
struct TestInline128 fixed(16 bytes) { f0 @0: UInt64; f1 @1: UInt64; }
struct TestInline192 fixed(24 bytes) { f0 @0: UInt64; f1 @1: UInt64; f2 @2: UInt64; }
struct TestInline0p fixed(1 pointers) { f @0 :Inline(TestInline0); p0 @1 :Text; }
struct TestInline8p fixed(1 bytes, 1 pointers) { f @0 :Inline(TestInline8); p0 @1 :Text; }
struct TestInline16p fixed(2 bytes, 2 pointers) { f @0 :Inline(TestInline16); p0 @1 :Text; p1 @2 :Text; }
struct TestInline32p fixed(4 bytes, 2 pointers) { f @0 :Inline(TestInline32); p0 @1 :Text; p1 @2 :Text; }
struct TestInline64p fixed(8 bytes, 2 pointers) { f @0 :Inline(TestInline64); p0 @1 :Text; p1 @2 :Text; }
struct TestInline128p fixed(16 bytes, 3 pointers) { f @0 :Inline(TestInline128); p0 @1 :Text; p1 @2 :Text; p2 @3 :Text; }
struct TestInline192p fixed(24 bytes, 3 pointers) { f @0 :Inline(TestInline192); p0 @1 :Text; p1 @2 :Text; p2 @3 :Text; }
struct TestInlineLayout {
f0 @0 :Inline(TestInline0);
pad1 @1 :UInt8;
f8 @2 :Inline(TestInline8);
f16 @3 :Inline(TestInline16);
f32 @4 :Inline(TestInline32);
f64 @5 :Inline(TestInline64);
f128 @6 :Inline(TestInline128);
f192 @7 :Inline(TestInline192);
f0p @8 :Inline(TestInline0p);
pad2 @9 :UInt8;
padP @10 :Text;
f8p @11 :Inline(TestInline8p);
f16p @12 :Inline(TestInline16p);
f32p @13 :Inline(TestInline32p);
f64p @14 :Inline(TestInline64p);
f128p @15 :Inline(TestInline128p);
f192p @16 :Inline(TestInline192p);
}
struct TestInlineUnions {
union0 @0 union {
f0 @4 :Inline(TestInline0);
f1 @5 :Bool; # There used to be a TestInline1 but it was decided to be a bad idea.
f8 @6 :Inline(TestInline8);
f16 @7 :Inline(TestInline16);
f32 @8 :Inline(TestInline32);
f64 @9 :Inline(TestInline64);
f128 @10 :Inline(TestInline128);
f192 @11 :Inline(TestInline192);
f0p @12 :Inline(TestInline0p);
f1p @13 :Bool;
f8p @14 :Inline(TestInline8p);
f16p @15 :Inline(TestInline16p);
f32p @16 :Inline(TestInline32p);
f64p @17 :Inline(TestInline64p);
f128p @18 :Inline(TestInline128p);
f192p @19 :Inline(TestInline192p);
}
# Pack one bit in order to make pathological situation for union1.
bit0 @20: Bool;
union1 @1 union {
f0 @21 :Inline(TestInline0);
f1 @22 :Bool;
f8 @23 :Inline(TestInline8);
f16 @24 :Inline(TestInline16);
f32 @25 :Inline(TestInline32);
f64 @26 :Inline(TestInline64);
f128 @27 :Inline(TestInline128);
f192 @28 :Inline(TestInline192);
}
# Fill in the rest of that bitfield from earlier.
bit2 @29: Bool;
bit3 @30: Bool;
bit4 @31: Bool;
bit5 @32: Bool;
bit6 @33: Bool;
bit7 @34: Bool;
# Interleave two unions to be really annoying.
union2 @2 union {
f1p @35 :Bool;
f8p @37 :Inline(TestInline8p);
f16p @40 :Inline(TestInline16p);
f32p @42 :Inline(TestInline32p);
f64p @44 :Inline(TestInline64p);
f128p @46 :Inline(TestInline128p);
f192p @48 :Inline(TestInline192p);
}
union3 @3 union {
f1p @36 :Bool;
f8p @38 :Inline(TestInline8p);
f16p @41 :Inline(TestInline16p);
f32p @43 :Inline(TestInline32p);
f64p @45 :Inline(TestInline64p);
f128p @47 :Inline(TestInline128p);
f192p @49 :Inline(TestInline192p);
}
byte0 @39: UInt8;
}
struct TestInlineLists {
voidList @ 0 : InlineList(Void, 2);
boolList @ 1 : InlineList(Bool, 3);
uInt8List @ 2 : InlineList(UInt8, 4);
uInt16List @ 3 : InlineList(UInt16, 5);
uInt32List @ 4 : InlineList(UInt32, 6);
uInt64List @ 5 : InlineList(UInt64, 7);
textList @ 6 : InlineList(Text, 8);
structList0 @ 7 : InlineList(TestInline0, 2);
structList1 @ 8 : InlineList(Bool, 3);
structList8 @ 9 : InlineList(TestInline8, 4);
structList16 @10 : InlineList(TestInline16, 2);
structList32 @11 : InlineList(TestInline32, 3);
structList64 @12 : InlineList(TestInline64, 4);
structList128 @13 : InlineList(TestInline128, 2);
structList192 @14 : InlineList(TestInline192, 3);
structList0p @15 : InlineList(TestInline0p, 4);
structList1p @16 : InlineList(Bool, 2);
structList8p @17 : InlineList(TestInline8p, 3);
structList16p @18 : InlineList(TestInline16p, 4);
structList32p @19 : InlineList(TestInline32p, 2);
structList64p @20 : InlineList(TestInline64p, 3);
structList128p @21 : InlineList(TestInline128p, 4);
structList192p @22 : InlineList(TestInline192p, 2);
data @23 :InlineData(5);
}
struct TestStructLists {
struct TestLists {
# Small structs, when encoded as list, will be encoded as primitive lists rather than struct
# lists, to save space.
struct Struct0 { f @0 :Void; }
......@@ -436,129 +302,22 @@ struct TestStructLists {
list32 @4 :List(Struct32);
list64 @5 :List(Struct64);
listP @6 :List(StructP);
}
struct TestListLists {
int32ListList @0 :List(List(Int32));
textListList @1 :List(List(Text));
structListList @2 :List(List(TestAllTypes));
int32InlineListList @3 :List(InlineList(Int32, 7));
textInlineListList @4 :List(InlineList(Text, 5));
structInlineListList @5 :List(InlineList(TestInline32p, 3));
inlineDataList @6 :List(InlineData(9));
int32InlineListListList @7 :List(List(InlineList(Int32, 2)));
textInlineListListList @8 :List(List(InlineList(Text, 5)));
structInlineListListList @9 :List(List(InlineList(TestInline32p, 3)));
inlineDataListList @10 :List(List(InlineData(3)));
int32ListList @7 :List(List(Int32));
textListList @8 :List(List(Text));
structListList @9 :List(List(TestAllTypes));
}
struct TestInlineDefaults {
normal @0 :TestInlineLayout = (
f0 = (f = void),
f8 = (f0 = true, f1 = false, f2 = true),
f16 = (f0 = 123, f1 = 45),
f32 = (f0 = 67, f1 = 8901),
f64 = (f0 = 234, f1 = 567890123),
f128 = (f0 = 1234567890123, f1 = 4567890123456),
f192 = (f0 = 7890123456789, f1 = 2345678901234, f2 = 5678901234567),
f0p = (p0 = "foo"),
f8p = (f = (f0 = true, f1 = true, f2 = false), p0 = "baz"),
f16p = (f = (f0 = 98, f1 = 76), p0 = "qux", p1 = "quux"),
f32p = (f = (f0 = 54, f1 = 32109), p0 = "corge", p1 = "grault"),
f64p = (f = (f0 = 87, f1 = 654321098), p0 = "garply", p1 = "waldo"),
f128p = (f = (f0 = 7654321098765, f1 = 4321098765432),
p0 = "fred", p1 = "plugh", p2 = "xyzzy"),
f192p = (f = (f0 = 1098765432109, f1 = 8765432109876, f2 = 5432109876543),
p0 = "thud", p1 = "foobar", p2 = "barbaz"));
unions @1 :TestInlineUnions = (
union0 = f32(f0 = 67, f1 = 8901),
union1 = f128(f0 = 1234567890123, f1 = 4567890123456),
union2 = f8p(p0 = "foo"),
union3 = f16p(f = (f0 = 98, f1 = 76), p0 = "qux", p1 = "quux"));
lists @2 :TestInlineLists = (
voidList = [void, void],
boolList = [false, true, false],
uInt8List = [12, 34, 56, 78],
uInt16List = [1234, 5678, 9012, 3456, 7890],
uInt32List = [123456789, 234567890, 345678901, 456789012, 567890123, 678901234],
uInt64List = [1, 2, 3, 4, 5, 6, 7],
textList = ["foo", "bar", "baz", "qux", "quux", "corge", "grault", "garply"],
structList0 = [(f = void), ()],
structList8 = [(f0 = true, f1 = false, f2 = false),
(f0 = false, f1 = true, f2 = false),
(f0 = true, f1 = true, f2 = false),
(f0 = false, f1 = false, f2 = true)],
structList16 = [(f0 = 12, f1 = 34), (f0 = 56, f1 = 78)],
structList32 = [(f0 = 90, f1 = 12345), (f0 = 67, f1 = 8901), (f0 = 23, f1 = 45678)],
structList64 = [(f0 = 90, f1 = 123456789), (f0 = 12, f1 = 345678901),
(f0 = 234, f1 = 567890123), (f0 = 45, f1 = 678901234)],
structList128 = [(f0 = 56789012345678, f1 = 90123456789012),
(f0 = 34567890123456, f1 = 78901234567890)],
structList192 = [(f0 = 1234567890123, f1 = 4567890123456, f2 = 7890123456789),
(f0 = 123456789012, f1 = 3456789012345, f2 = 6789012345678),
(f0 = 9012345678901, f1 = 2345678901234, f2 = 5678901234567)],
structList0p = [(f = (f = void), p0 = "foo"), (p0 = "bar"),
(f = (), p0 = "baz"), (p0 = "qux")],
structList8p = [(f = (f0 = true), p0 = "grault"), (p0 = "garply"), (p0 = "waldo")],
structList16p = [(f = (f0 = 123), p0 = "fred", p1 = "plugh"),
(p0 = "xyzzy", p1 = "thud"),
(p0 = "foobar", p1 = "barbaz"),
(p0 = "bazqux", p1 = "quxquux")],
structList32p = [(f = (f1 = 12345), p0 = "quuxcorge", p1 = "corgegrault"),
(p0 = "graultgarply", p1 = "garplywaldo")],
structList64p = [(f = (f1 = 123456789), p0 = "waldofred", p1 = "fredplugh"),
(p0 = "plughxyzzy", p1 = "xyzzythud"),
(p0 = "thudfoo", p1 = "foofoo")],
structList128p = [(f = (f1 = 123456789012345),
p0 = "foobaz", p1 = "fooqux", p2 = "foocorge"),
(p0 = "barbaz", p1 = "barqux", p2 = "barcorge"),
(p0 = "bazbaz", p1 = "bazqux", p2 = "bazcorge"),
(p0 = "quxbaz", p1 = "quxqux", p2 = "quxcorge")],
structList192p = [(f = (f2 = 123456789012345),
p0 = "corgebaz", p1 = "corgequx", p2 = "corgecorge"),
(p0 = "graultbaz", p1 = "graultqux", p2 = "graultcorge")],
data = "12345");
structLists @3 :TestStructLists = (
struct TestListDefaults {
lists @0 :TestLists = (
list0 = [(f = void), (f = void)],
list1 = [(f = true), (f = false)],
list8 = [(f = 123), (f = 45)],
list16 = [(f = 12345), (f = 6789)],
list32 = [(f = 123456789), (f = 234567890)],
list64 = [(f = 1234567890123456), (f = 2345678901234567)],
listP = [(f = "foo"), (f = "bar")]);
listLists @4 :TestListLists = (
listP = [(f = "foo"), (f = "bar")],
int32ListList = [[1, 2, 3], [4, 5], [12341234]],
textListList = [["foo", "bar"], ["baz"], ["qux", "corge"]],
structListList = [[(int32Field = 123), (int32Field = 456)], [(int32Field = 789)]],
int32InlineListList = [[1, 2, 3, 4, 5, 6, 123456789], [987654321, 6, 5, 4, 3, 2, 1]],
textInlineListList = [["grault1", "grault2", "grault3", "grault4", "grault5"],
["garply1", "garply2", "garply3", "garply4", "garply5"],
["waldo1", "waldo2", "waldo3", "waldo4", "waldo5"]],
structInlineListList =
[[(f=(f1=123), p0="fred1"), (f=(f1=456), p0="fred2"), (f=(f1=789), p0="fred3")],
[(f=(f1=321), p0="plugh1"), (f=(f1=654), p0="plugh2"), (f=(f1=987), p0="plugh3")],
[(f=(f1=111), p0="thud1"), (f=(f1=222), p0="thud2"), (f=(f1=333), p0="thud3")]],
inlineDataList = ["123456789", "234567890", "345678901", "456789012", "567890123"],
int32InlineListListList = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]], [[1234567,7654321]]],
textInlineListListList = [[["1", "2", "3", "4", "5"],
["foo", "bar", "baz", "qux", "corge"]],
[["z", "y", "x", "w", "v"]]],
structInlineListListList =
[[[(f=(f1=123), p0="fred1"), (f=(f1=456), p0="fred2"), (f=(f1=789), p0="fred3")],
[(f=(f1=321), p0="plugh1"), (f=(f1=654), p0="plugh2"), (f=(f1=987), p0="plugh3")]],
[[(f=(f1=111), p0="thud1"), (f=(f1=222), p0="thud2"), (f=(f1=333), p0="thud3")]]],
inlineDataListList = [["foo", "bar", "baz"], ["123", "234"]]);
structListList = [[(int32Field = 123), (int32Field = 456)], [(int32Field = 789)]]);
}
......@@ -164,10 +164,13 @@ lookupDesc scope name = lookupDesc (descParent scope) name
builtinTypeMap :: Map.Map String Desc
builtinTypeMap = Map.fromList
([(builtinTypeName t, DescBuiltinType t) | t <- builtinTypes] ++
[("List", DescBuiltinList),
("Inline", DescBuiltinInline),
("InlineList", DescBuiltinInlineList),
("InlineData", DescBuiltinInlineData)])
[ ("List", DescBuiltinList)
{- Inlines have been disabled for now because they added too much complication.
, ("Inline", DescBuiltinInline)
, ("InlineList", DescBuiltinInlineList)
, ("InlineData", DescBuiltinInlineData)
-}
])
------------------------------------------------------------------------------------------
......
......@@ -49,7 +49,7 @@ keywords =
, (UnionKeyword, "union")
, (InterfaceKeyword, "interface")
, (AnnotationKeyword, "annotation")
, (FixedKeyword, "fixed")
-- , (FixedKeyword, "fixed") -- Inlines have been disabled because they were too complicated.
]
languageDef :: T.LanguageDef st
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment