mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add ability to store and retrieve a list of MapBuffer
Summary:
Add ability to store and retrieve a list of MapBuffer as an entry of MapBuffer.
```
Example:
MapBuffer1
{
key1: "test string",
key2: MapBuffer2,
key3: [MapBuffer3, MapBuffer4]
}
```
Changelog:
[General][Added] Add ability to store and retrieve a list of MapBuffer
Reviewed By: JoshuaGross
Differential Revision: D38460204
fbshipit-source-id: 3e721418be2dca6d5f15f665753844d6f531e31c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7e580b97bf
commit
fc065151ce
@@ -112,6 +112,31 @@ MapBuffer MapBuffer::getMapBuffer(Key key) const {
|
||||
return MapBuffer(std::move(value));
|
||||
}
|
||||
|
||||
std::vector<MapBuffer> MapBuffer::getMapBufferList(MapBuffer::Key key) const {
|
||||
std::vector<MapBuffer> mapBufferList;
|
||||
|
||||
int32_t dynamicDataOffset = getDynamicDataOffset();
|
||||
int32_t offset = getInt(key);
|
||||
int32_t mapBufferListLength = *reinterpret_cast<int32_t const *>(
|
||||
bytes_.data() + dynamicDataOffset + offset);
|
||||
offset = offset + sizeof(uint32_t);
|
||||
|
||||
int32_t curLen = 0;
|
||||
while (curLen < mapBufferListLength) {
|
||||
int32_t mapBufferLength = *reinterpret_cast<int32_t const *>(
|
||||
bytes_.data() + dynamicDataOffset + offset + curLen);
|
||||
curLen = curLen + sizeof(uint32_t);
|
||||
std::vector<uint8_t> value(mapBufferLength);
|
||||
memcpy(
|
||||
value.data(),
|
||||
bytes_.data() + dynamicDataOffset + offset + curLen,
|
||||
mapBufferLength);
|
||||
mapBufferList.emplace_back(std::move(value));
|
||||
curLen = curLen + mapBufferLength;
|
||||
}
|
||||
return mapBufferList;
|
||||
}
|
||||
|
||||
size_t MapBuffer::size() const {
|
||||
return bytes_.size();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user