Commit b2496f3a authored by Kenton Varda's avatar Kenton Varda

Fix AnyStruct::getPointerSection(), which was totally broken and not tested.

parent db268884
......@@ -162,6 +162,20 @@ TEST(Any, AnyStruct) {
// TODO: is there a higher-level API for this?
memcpy(sb.getDataSection().begin(), r.getDataSection().begin(), r.getDataSection().size());
}
{
auto ptrs = r.getPointerSection();
EXPECT_EQ("foo", ptrs[0].getAs<Text>());
EXPECT_EQ("bar", kj::heapString(ptrs[1].getAs<Data>().asChars()));
EXPECT_EQ("xyzzy", ptrs[15].getAs<List<Text>>()[1]);
}
{
auto ptrs = b.getPointerSection();
EXPECT_EQ("foo", ptrs[0].getAs<Text>());
EXPECT_EQ("bar", kj::heapString(ptrs[1].getAs<Data>().asChars()));
EXPECT_EQ("xyzzy", ptrs[15].getAs<List<Text>>()[1]);
}
}
TEST(Any, AnyList) {
......
......@@ -574,7 +574,7 @@ public:
inline uint size() { return _reader.size() / ELEMENTS; }
template <typename T> ReaderFor<T> as() {
// T must be List<U>.
// T must be List<U>.
return ReaderFor<T>(_reader);
}
private:
......@@ -599,7 +599,7 @@ public:
inline uint size() { return _builder.size() / ELEMENTS; }
template <typename T> BuilderFor<T> as() {
// T must be List<U>.
// T must be List<U>.
return BuilderFor<T>(_builder);
}
......
......@@ -826,7 +826,7 @@ inline Data::Builder StructBuilder::getDataSectionAsBlob() {
}
inline _::ListBuilder StructBuilder::getPointerSectionAsList() {
return _::ListBuilder(segment, pointers, pointerCount * BITS_PER_POINTER / ELEMENTS,
return _::ListBuilder(segment, pointers, 1 * POINTERS * BITS_PER_POINTER / ELEMENTS,
pointerCount * (1 * ELEMENTS / POINTERS),
0 * BITS, 1 * POINTERS, ElementSize::POINTER);
}
......@@ -911,8 +911,8 @@ inline Data::Reader StructReader::getDataSectionAsBlob() {
inline _::ListReader StructReader::getPointerSectionAsList() {
return _::ListReader(segment, pointers, pointerCount * (1 * ELEMENTS / POINTERS),
pointerCount * BITS_PER_POINTER / ELEMENTS,
0 * BITS, 1 * POINTERS, ElementSize::POINTER, nestingLimit);
1 * POINTERS * BITS_PER_POINTER / ELEMENTS, 0 * BITS, 1 * POINTERS,
ElementSize::POINTER, nestingLimit);
}
template <typename T>
......
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