Skip to content

Commit a7e7faa

Browse files
javachemeta-codesync[bot]
authored andcommitted
Add MapBufferList entry type to MapBuffer
Summary: Introduces a dedicated `MapBufferList` `DataType` for an ordered array of nested MapBuffers, instead of overloading the `Map` type for lists. This makes a list of MapBuffers self-describing and distinguishable from a single nested `Map` (they were byte-distinct in payload but previously shared the `Map` type tag). Updates the C++ builder (`putMapBufferList`), the Kotlin `MapBuffer` interface, `ReadableMapBuffer`, and `WritableMapBuffer`, and adds cross-language JNI round-trip coverage in the serialization instrumentation test. Changelog: [Android][Added] - Add a dedicated `MapBufferList` type to `MapBuffer` for ordered lists of nested `MapBuffer`s Differential Revision: D109848477
1 parent fcd0afe commit a7e7faa

15 files changed

Lines changed: 39 additions & 5 deletions

File tree

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,7 @@ public final class com/facebook/react/common/mapbuffer/MapBuffer$DataType : java
16871687
public static final field INT_BUFFER Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType;
16881688
public static final field LONG Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType;
16891689
public static final field MAP Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType;
1690+
public static final field MAP_BUFFER_LIST Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType;
16901691
public static final field STRING Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType;
16911692
public static fun getEntries ()Lkotlin/enums/EnumEntries;
16921693
public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType;
@@ -1701,6 +1702,7 @@ public abstract interface class com/facebook/react/common/mapbuffer/MapBuffer$En
17011702
public abstract fun getIntValue ()I
17021703
public abstract fun getKey ()I
17031704
public abstract fun getLongValue ()J
1705+
public abstract fun getMapBufferListValue ()Ljava/util/List;
17041706
public abstract fun getMapBufferValue ()Lcom/facebook/react/common/mapbuffer/MapBuffer;
17051707
public abstract fun getStringValue ()Ljava/lang/String;
17061708
public abstract fun getType ()Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/mapbuffer/MapBuffer.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public interface MapBuffer : Iterable<MapBuffer.Entry> {
4848
LONG,
4949
INT_BUFFER,
5050
DOUBLE_BUFFER,
51+
MAP_BUFFER_LIST,
5152
}
5253

5354
/**
@@ -153,8 +154,8 @@ public interface MapBuffer : Iterable<MapBuffer.Entry> {
153154
public fun getMapBuffer(key: Int): MapBuffer
154155

155156
/**
156-
* Provides parsed [List<MapBuffer>] value if the entry for given key exists with [DataType.MAP]
157-
* type
157+
* Provides parsed [List<MapBuffer>] value if the entry for given key exists with
158+
* [DataType.MAP_BUFFER_LIST] type
158159
*
159160
* @param key key to lookup [List<MapBuffer>] value for
160161
* @return value associated with the requested key
@@ -253,5 +254,12 @@ public interface MapBuffer : Iterable<MapBuffer.Entry> {
253254
* @throws IllegalStateException if the data type doesn't match [DataType.DOUBLE_BUFFER]
254255
*/
255256
public val doubleBufferValue: DoubleArray
257+
258+
/**
259+
* Entry value represented as [List<MapBuffer>]
260+
*
261+
* @throws IllegalStateException if the data type doesn't match [DataType.MAP_BUFFER_LIST]
262+
*/
263+
public val mapBufferListValue: List<MapBuffer>
256264
}
257265
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/mapbuffer/ReadableMapBuffer.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private constructor(
205205
readMapBufferValue(getTypedValueOffsetForKey(key, MapBuffer.DataType.MAP))
206206

207207
override fun getMapBufferList(key: Int): List<ReadableMapBuffer> =
208-
readMapBufferListValue(getTypedValueOffsetForKey(key, MapBuffer.DataType.MAP))
208+
readMapBufferListValue(getTypedValueOffsetForKey(key, MapBuffer.DataType.MAP_BUFFER_LIST))
209209

210210
override fun getIntBuffer(key: Int): IntArray =
211211
readIntBufferValue(getTypedValueOffsetForKey(key, MapBuffer.DataType.INT_BUFFER))
@@ -251,6 +251,7 @@ private constructor(
251251
MapBuffer.DataType.MAP -> append(entry.mapBufferValue.toString())
252252
MapBuffer.DataType.INT_BUFFER -> append(entry.intBufferValue.contentToString())
253253
MapBuffer.DataType.DOUBLE_BUFFER -> append(entry.doubleBufferValue.contentToString())
254+
MapBuffer.DataType.MAP_BUFFER_LIST -> append(entry.mapBufferListValue.toString())
254255
}
255256
}
256257
}
@@ -345,6 +346,12 @@ private constructor(
345346
assertType(MapBuffer.DataType.DOUBLE_BUFFER)
346347
return readDoubleBufferValue(bucketOffset + VALUE_OFFSET)
347348
}
349+
350+
override val mapBufferListValue: List<MapBuffer>
351+
get() {
352+
assertType(MapBuffer.DataType.MAP_BUFFER_LIST)
353+
return readMapBufferListValue(bucketOffset + VALUE_OFFSET)
354+
}
348355
}
349356

350357
public companion object {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/mapbuffer/WritableMapBuffer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ internal class WritableMapBuffer : MapBuffer {
186186

187187
override val doubleBufferValue: DoubleArray
188188
get() = verifyValue(key, values.valueAt(index))
189+
190+
override val mapBufferListValue: List<MapBuffer>
191+
get() = verifyValue(key, values.valueAt(index))
189192
}
190193

191194
/*

packages/react-native/ReactCommon/react/renderer/mapbuffer/MapBuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ class MapBuffer {
112112
// array within the dynamic data section.
113113
IntBuffer = 6,
114114
DoubleBuffer = 7,
115+
// A homogeneous, ordered array of nested MapBuffers. Distinct from `Map` so
116+
// that a list of MapBuffers is self-describing (a single Map and a list are
117+
// byte-distinct in payload but previously shared the `Map` type tag).
118+
MapBufferList = 8,
115119
};
116120

117121
explicit MapBuffer(std::vector<uint8_t> data);

packages/react-native/ReactCommon/react/renderer/mapbuffer/MapBufferBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ void MapBufferBuilder::putMapBufferList(
153153
mapBufferSize);
154154
}
155155

156-
// Store Key and pointer to the string
156+
// Store Key and pointer to the list. Uses the dedicated MapBufferList type so
157+
// the entry is self-describing and distinguishable from a single Map.
157158
storeKeyValue(
158159
key,
159-
MapBuffer::DataType::Map,
160+
MapBuffer::DataType::MapBufferList,
160161
reinterpret_cast<const uint8_t*>(&offset),
161162
INT_SIZE);
162163
}

scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,6 +3268,7 @@ enum facebook::react::MapBuffer::DataType : uint16_t {
32683268
IntBuffer,
32693269
Long,
32703270
Map,
3271+
MapBufferList,
32713272
String,
32723273
}
32733274

scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,6 +3177,7 @@ enum facebook::react::MapBuffer::DataType : uint16_t {
31773177
IntBuffer,
31783178
Long,
31793179
Map,
3180+
MapBufferList,
31803181
String,
31813182
}
31823183

scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,6 +3265,7 @@ enum facebook::react::MapBuffer::DataType : uint16_t {
32653265
IntBuffer,
32663266
Long,
32673267
Map,
3268+
MapBufferList,
32683269
String,
32693270
}
32703271

scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5498,6 +5498,7 @@ enum facebook::react::MapBuffer::DataType : uint16_t {
54985498
IntBuffer,
54995499
Long,
55005500
Map,
5501+
MapBufferList,
55015502
String,
55025503
}
55035504

0 commit comments

Comments
 (0)