-
- All Implemented Interfaces:
-
kotlin.collections.Iterable
public interface MapBuffer implements Iterable<MapBuffer.Entry>
MapBuffer is an optimized sparse array format for transferring props-like data between C++ and JNI. It is designed to:
be compact to optimize space when sparse (sparse is the common case).
be accessible through JNI with zero/minimal copying.
work recursively for nested maps/arrays.
support dynamic types that map to JSON.
have minimal APK size and build time impact.
See <react/renderer/mapbuffer/MapBuffer.h> for more information and native implementation.
Limitations:
Keys are usually sized as 2 bytes, with each buffer supporting up to 65536 entries as a result.
O(log(N)) random key access for native buffers due to selected structure. Faster access can be achieved by retrieving MapBuffer.Entry with entryAt on known offsets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
MapBuffer.Companion
public enum
MapBuffer.DataType
Data types supported by MapBuffer. Keep in sync with definition in
<react/renderer/mapbuffer/MapBuffer.h>
, as enum serialization relies on correct order.public interface
MapBuffer.Entry
Iterable entry representing parsed MapBuffer values
-
Method Summary
Modifier and Type Method Description abstract Boolean
contains(Integer key)
Checks whether entry for given key exists in MapBuffer. abstract Integer
getKeyOffset(Integer key)
Provides offset of the key to use for entryAt, for cases when offset is not statically known but can be cached. abstract MapBuffer.Entry
entryAt(Integer offset)
Provides parsed access to a MapBuffer without additional lookups for provided offset. abstract MapBuffer.DataType
getType(Integer key)
Provides parsed DataType annotation associated with the given key. abstract Boolean
getBoolean(Integer key)
Provides parsed Boolean value if the entry for given key exists with DataType.BOOL type abstract Integer
getInt(Integer key)
Provides parsed Int value if the entry for given key exists with DataType.INT type abstract Double
getDouble(Integer key)
Provides parsed Double value if the entry for given key exists with DataType.DOUBLE type abstract String
getString(Integer key)
Provides parsed String value if the entry for given key exists with DataType.STRING type abstract MapBuffer
getMapBuffer(Integer key)
Provides parsed MapBuffer value if the entry for given key exists with DataType.MAP type abstract Integer
getCount()
Number of elements inserted into current MapBuffer. -
-
Method Detail
-
contains
abstract Boolean contains(Integer key)
Checks whether entry for given key exists in MapBuffer.
- Parameters:
key
- key to lookup the entry
-
getKeyOffset
abstract Integer getKeyOffset(Integer key)
Provides offset of the key to use for entryAt, for cases when offset is not statically known but can be cached.
- Parameters:
key
- key to lookup offset for
-
entryAt
abstract MapBuffer.Entry entryAt(Integer offset)
Provides parsed access to a MapBuffer without additional lookups for provided offset.
- Parameters:
offset
- offset of entry in the MapBuffer structure.
-
getType
abstract MapBuffer.DataType getType(Integer key)
Provides parsed DataType annotation associated with the given key.
- Parameters:
key
- key to lookup type for
-
getBoolean
abstract Boolean getBoolean(Integer key)
Provides parsed Boolean value if the entry for given key exists with DataType.BOOL type
- Parameters:
key
- key to lookup Boolean value for
-
getInt
abstract Integer getInt(Integer key)
Provides parsed Int value if the entry for given key exists with DataType.INT type
- Parameters:
key
- key to lookup Int value for
-
getDouble
abstract Double getDouble(Integer key)
Provides parsed Double value if the entry for given key exists with DataType.DOUBLE type
- Parameters:
key
- key to lookup Double value for
-
getString
abstract String getString(Integer key)
Provides parsed String value if the entry for given key exists with DataType.STRING type
- Parameters:
key
- key to lookup String value for
-
getMapBuffer
abstract MapBuffer getMapBuffer(Integer key)
Provides parsed MapBuffer value if the entry for given key exists with DataType.MAP type
- Parameters:
key
- key to lookup MapBuffer value for
-
-
-
-