Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,26 @@ void MapBufferBuilder::putMapBuffer(MapBuffer::Key key, const MapBuffer& map) {
void MapBufferBuilder::putMapBufferList(
MapBuffer::Key key,
const std::vector<MapBuffer>& mapBufferList) {
auto offset = static_cast<int32_t>(dynamicData_.size());
const auto offset = dynamicData_.size();
size_t payloadSize = 0;
for (const auto& mapBuffer : mapBufferList) {
payloadSize += INT_SIZE + mapBuffer.size();
}
dynamicData_.resize(offset + payloadSize);

// The bucket stores [offset][byteLength] for the whole list region; within it
// each child stays framed as [int32 childSize][child bytes] so the children
// remain individually delimited.
for (const MapBuffer& mapBuffer : mapBufferList) {
auto mapBufferSize = static_cast<int32_t>(mapBuffer.size());
auto pos = static_cast<int32_t>(dynamicData_.size());
dynamicData_.resize(pos + INT_SIZE + mapBufferSize, 0);
memcpy(dynamicData_.data() + pos, &mapBufferSize, INT_SIZE);
// Each child stays framed as [int32 childSize][child bytes].
auto position = offset;
for (const auto& mapBuffer : mapBufferList) {
const auto mapBufferSize = static_cast<int32_t>(mapBuffer.size());
memcpy(dynamicData_.data() + position, &mapBufferSize, INT_SIZE);
memcpy(
dynamicData_.data() + pos + INT_SIZE, mapBuffer.data(), mapBufferSize);
dynamicData_.data() + position + INT_SIZE,
mapBuffer.data(),
mapBufferSize);
position += INT_SIZE + mapBufferSize;
}

auto totalSize = static_cast<int32_t>(dynamicData_.size()) - offset;
const auto totalSize = static_cast<int32_t>(payloadSize);
uint64_t data = packOffsetAndLength(offset, totalSize);
// Uses the dedicated MapBufferList type so the entry is self-describing and
// distinguishable from a single Map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,28 @@ TEST(MapBufferTest, testMapListEntriesAtNonZeroOffset) {
EXPECT_EQ(readList[0].getInt(1), 42);
}

TEST(MapBufferTest, testMapListEntriesWithDifferentPayloadSizes) {
auto child = MapBufferBuilder();
child.putString(3, "a child with dynamic data");

std::vector<MapBuffer> children;
children.push_back(MapBufferBuilder::EMPTY());
children.push_back(child.build());

auto builder = MapBufferBuilder();
builder.putString(0, "before");
builder.putMapBufferList(1, children);
builder.putString(2, "after");
auto map = builder.build();

EXPECT_EQ(map.getString(0), "before");
auto decoded = map.getMapBufferList(1);
ASSERT_EQ(decoded.size(), 2);
EXPECT_EQ(decoded[0].count(), 0);
EXPECT_EQ(decoded[1].getString(3), "a child with dynamic data");
EXPECT_EQ(map.getString(2), "after");
}

TEST(MapBufferTest, testIntBufferEntries) {
auto builder = MapBufferBuilder();

Expand Down
Loading