google-protobuf 4.29.0.rc.1-x86_64-linux → 4.29.0.rc.3-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
@@ -1133,16 +1133,47 @@ UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast(
1133
1133
  #ifndef UPB_JSON_DECODE_H_
1134
1134
  #define UPB_JSON_DECODE_H_
1135
1135
 
1136
+ #include <stddef.h>
1136
1137
 
1137
- #ifndef UPB_REFLECTION_DEF_H_
1138
- #define UPB_REFLECTION_DEF_H_
1139
1138
 
1140
- // IWYU pragma: begin_exports
1139
+ // Public APIs for message operations that do not depend on the schema.
1140
+ //
1141
+ // MiniTable-based accessors live in accessors.h.
1141
1142
 
1142
- // IWYU pragma: private, include "upb/reflection/def.h"
1143
+ #ifndef UPB_MESSAGE_MESSAGE_H_
1144
+ #define UPB_MESSAGE_MESSAGE_H_
1143
1145
 
1144
- #ifndef UPB_REFLECTION_DEF_POOL_H_
1145
- #define UPB_REFLECTION_DEF_POOL_H_
1146
+ #include <stddef.h>
1147
+
1148
+
1149
+ /*
1150
+ ** Our memory representation for parsing tables and messages themselves.
1151
+ ** Functions in this file are used by generated code and possibly reflection.
1152
+ **
1153
+ ** The definitions in this file are internal to upb.
1154
+ **/
1155
+
1156
+ #ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_
1157
+ #define UPB_MESSAGE_INTERNAL_MESSAGE_H_
1158
+
1159
+ #include <stdlib.h>
1160
+ #include <string.h>
1161
+
1162
+
1163
+ #ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_
1164
+ #define UPB_MESSAGE_INTERNAL_EXTENSION_H_
1165
+
1166
+ #include <stddef.h>
1167
+
1168
+
1169
+ // Users should include array.h or map.h instead.
1170
+ // IWYU pragma: private, include "upb/message/array.h"
1171
+
1172
+ #ifndef UPB_MESSAGE_VALUE_H_
1173
+ #define UPB_MESSAGE_VALUE_H_
1174
+
1175
+ #include <stdint.h>
1176
+ #include <string.h>
1146
1177
 
1147
1178
  #ifndef UPB_BASE_STRING_VIEW_H_
1148
1179
  #define UPB_BASE_STRING_VIEW_H_
@@ -1196,74 +1227,63 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) {
1196
1227
 
1197
1228
  #endif /* UPB_BASE_STRING_VIEW_H_ */
1198
1229
 
1199
- // IWYU pragma: private, include "upb/reflection/def.h"
1200
-
1201
- // Declarations common to all public def types.
1202
-
1203
- #ifndef UPB_REFLECTION_COMMON_H_
1204
- #define UPB_REFLECTION_COMMON_H_
1205
-
1206
- #ifndef THIRD_PARTY_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H_
1207
- #define THIRD_PARTY_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H_
1208
-
1209
- // IWYU pragma: begin_exports
1210
-
1211
- #if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0
1212
- // This header is checked in.
1213
- #elif UPB_BOOTSTRAP_STAGE == 1
1214
- // This header is generated at build time by the bootstrapping process.
1215
- #else
1216
- // This is the normal header, generated by upb_c_proto_library().
1217
- /* This file was generated by upb_generator from the input file:
1218
- *
1219
- * google/protobuf/descriptor.proto
1220
- *
1221
- * Do not edit -- your changes will be discarded when the file is
1222
- * regenerated.
1223
- * NO CHECKED-IN PROTOBUF GENCODE */
1224
-
1225
- #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
1226
- #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
1230
+ // Must be last.
1227
1231
 
1232
+ #ifdef __cplusplus
1233
+ extern "C" {
1234
+ #endif
1228
1235
 
1229
- #ifndef UPB_GENERATED_CODE_SUPPORT_H_
1230
- #define UPB_GENERATED_CODE_SUPPORT_H_
1236
+ typedef union {
1237
+ bool bool_val;
1238
+ float float_val;
1239
+ double double_val;
1240
+ int32_t int32_val;
1241
+ int64_t int64_val;
1242
+ uint32_t uint32_val;
1243
+ uint64_t uint64_val;
1244
+ const struct upb_Array* array_val;
1245
+ const struct upb_Map* map_val;
1246
+ const struct upb_Message* msg_val;
1247
+ upb_StringView str_val;
1231
1248
 
1232
- // IWYU pragma: begin_exports
1249
+ // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of
1250
+ // msg_val if unlinked sub-messages may possibly be in use. See the
1251
+ // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more
1252
+ // information.
1253
+ uintptr_t tagged_msg_val; // upb_TaggedMessagePtr
1254
+ } upb_MessageValue;
1233
1255
 
1234
- #ifndef UPB_BASE_UPCAST_H_
1235
- #define UPB_BASE_UPCAST_H_
1256
+ UPB_API_INLINE upb_MessageValue upb_MessageValue_Zero(void) {
1257
+ upb_MessageValue zero;
1258
+ memset(&zero, 0, sizeof(zero));
1259
+ return zero;
1260
+ }
1236
1261
 
1237
- // Must be last.
1262
+ typedef union {
1263
+ struct upb_Array* array;
1264
+ struct upb_Map* map;
1265
+ struct upb_Message* msg;
1266
+ } upb_MutableMessageValue;
1238
1267
 
1239
- // This macro provides a way to upcast message pointers in a way that is
1240
- // somewhat more bulletproof than blindly casting a pointer. Example:
1241
- //
1242
- // typedef struct {
1243
- // upb_Message UPB_PRIVATE(base);
1244
- // } pkg_FooMessage;
1245
- //
1246
- // void f(pkg_FooMessage* msg) {
1247
- // upb_Decode(UPB_UPCAST(msg), ...);
1248
- // }
1268
+ UPB_API_INLINE upb_MutableMessageValue upb_MutableMessageValue_Zero(void) {
1269
+ upb_MutableMessageValue zero;
1270
+ memset(&zero, 0, sizeof(zero));
1271
+ return zero;
1272
+ }
1249
1273
 
1250
- #define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only)
1274
+ #ifdef __cplusplus
1275
+ } /* extern "C" */
1276
+ #endif
1251
1277
 
1252
1278
 
1253
- #endif /* UPB_BASE_UPCAST_H_ */
1279
+ #endif /* UPB_MESSAGE_VALUE_H_ */
1254
1280
 
1255
- #ifndef UPB_MESSAGE_ACCESSORS_H_
1256
- #define UPB_MESSAGE_ACCESSORS_H_
1281
+ #ifndef UPB_MINI_TABLE_EXTENSION_H_
1282
+ #define UPB_MINI_TABLE_EXTENSION_H_
1257
1283
 
1258
1284
  #include <stdint.h>
1259
1285
 
1260
1286
 
1261
- #ifndef UPB_MESSAGE_ARRAY_H_
1262
- #define UPB_MESSAGE_ARRAY_H_
1263
-
1264
- #include <stddef.h>
1265
-
1266
-
1267
1287
  #ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
1268
1288
  #define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
1269
1289
 
@@ -1367,290 +1387,94 @@ UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
1367
1387
 
1368
1388
  #endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
1369
1389
 
1370
- #ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_
1371
- #define UPB_MESSAGE_INTERNAL_ARRAY_H_
1390
+ #ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_
1391
+ #define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_
1372
1392
 
1393
+ #include <stddef.h>
1373
1394
  #include <stdint.h>
1374
- #include <string.h>
1375
1395
 
1376
1396
 
1377
- // Must be last.
1397
+ #ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_
1398
+ #define UPB_MINI_TABLE_INTERNAL_FIELD_H_
1378
1399
 
1379
- #define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit.
1380
- #define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size.
1381
- #define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2)
1400
+ #include <stddef.h>
1401
+ #include <stdint.h>
1402
+
1403
+
1404
+ #ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
1405
+ #define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
1406
+
1407
+ #include <stddef.h>
1408
+ #include <stdint.h>
1409
+
1410
+
1411
+ // Must be last.
1382
1412
 
1383
1413
  #ifdef __cplusplus
1384
1414
  extern "C" {
1385
1415
  #endif
1386
1416
 
1387
- // LINT.IfChange(upb_Array)
1417
+ // Return the log2 of the storage size in bytes for a upb_CType
1418
+ UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) {
1419
+ static const int8_t size[] = {
1420
+ 0, // kUpb_CType_Bool
1421
+ 2, // kUpb_CType_Float
1422
+ 2, // kUpb_CType_Int32
1423
+ 2, // kUpb_CType_UInt32
1424
+ 2, // kUpb_CType_Enum
1425
+ UPB_SIZE(2, 3), // kUpb_CType_Message
1426
+ 3, // kUpb_CType_Double
1427
+ 3, // kUpb_CType_Int64
1428
+ 3, // kUpb_CType_UInt64
1429
+ UPB_SIZE(3, 4), // kUpb_CType_String
1430
+ UPB_SIZE(3, 4), // kUpb_CType_Bytes
1431
+ };
1388
1432
 
1389
- // Our internal representation for repeated fields.
1390
- struct upb_Array {
1391
- // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows:
1392
- // 0 maps to elem size 1
1393
- // 1 maps to elem size 4
1394
- // 2 maps to elem size 8
1395
- // 3 maps to elem size 16
1396
- //
1397
- // Bit #2 contains the frozen/immutable flag.
1398
- uintptr_t UPB_ONLYBITS(data);
1433
+ // -1 here because the enum is one-based but the table is zero-based.
1434
+ return size[c_type - 1];
1435
+ }
1399
1436
 
1400
- size_t UPB_ONLYBITS(size); // The number of elements in the array.
1401
- size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements.
1402
- };
1437
+ // Return the log2 of the storage size in bytes for a upb_FieldType
1438
+ UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) {
1439
+ static const int8_t size[] = {
1440
+ 3, // kUpb_FieldType_Double
1441
+ 2, // kUpb_FieldType_Float
1442
+ 3, // kUpb_FieldType_Int64
1443
+ 3, // kUpb_FieldType_UInt64
1444
+ 2, // kUpb_FieldType_Int32
1445
+ 3, // kUpb_FieldType_Fixed64
1446
+ 2, // kUpb_FieldType_Fixed32
1447
+ 0, // kUpb_FieldType_Bool
1448
+ UPB_SIZE(3, 4), // kUpb_FieldType_String
1449
+ UPB_SIZE(2, 3), // kUpb_FieldType_Group
1450
+ UPB_SIZE(2, 3), // kUpb_FieldType_Message
1451
+ UPB_SIZE(3, 4), // kUpb_FieldType_Bytes
1452
+ 2, // kUpb_FieldType_UInt32
1453
+ 2, // kUpb_FieldType_Enum
1454
+ 2, // kUpb_FieldType_SFixed32
1455
+ 3, // kUpb_FieldType_SFixed64
1456
+ 2, // kUpb_FieldType_SInt32
1457
+ 3, // kUpb_FieldType_SInt64
1458
+ };
1403
1459
 
1404
- UPB_INLINE void UPB_PRIVATE(_upb_Array_ShallowFreeze)(struct upb_Array* arr) {
1405
- arr->UPB_ONLYBITS(data) |= _UPB_ARRAY_MASK_IMM;
1460
+ // -1 here because the enum is one-based but the table is zero-based.
1461
+ return size[field_type - 1];
1406
1462
  }
1407
1463
 
1408
- UPB_API_INLINE bool upb_Array_IsFrozen(const struct upb_Array* arr) {
1409
- return (arr->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_IMM) != 0;
1410
- }
1464
+ #ifdef __cplusplus
1465
+ } /* extern "C" */
1466
+ #endif
1411
1467
 
1412
- UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array,
1413
- void* data, size_t lg2) {
1414
- UPB_ASSERT(lg2 != 1);
1415
- UPB_ASSERT(lg2 <= 4);
1416
- const size_t bits = lg2 - (lg2 != 0);
1417
- array->UPB_ONLYBITS(data) = (uintptr_t)data | bits;
1418
- }
1419
1468
 
1420
- UPB_INLINE size_t
1421
- UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) {
1422
- const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2;
1423
- const size_t lg2 = bits + (bits != 0);
1424
- return lg2;
1425
- }
1469
+ #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */
1426
1470
 
1427
- UPB_API_INLINE const void* upb_Array_DataPtr(const struct upb_Array* array) {
1428
- UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions.
1429
- return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL);
1430
- }
1471
+ // Must be last.
1431
1472
 
1432
- UPB_API_INLINE void* upb_Array_MutableDataPtr(struct upb_Array* array) {
1433
- return (void*)upb_Array_DataPtr(array);
1434
- }
1435
-
1436
- UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena,
1437
- size_t init_capacity,
1438
- int elem_size_lg2) {
1439
- UPB_ASSERT(elem_size_lg2 != 1);
1440
- UPB_ASSERT(elem_size_lg2 <= 4);
1441
- const size_t array_size =
1442
- UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN);
1443
- const size_t bytes = array_size + (init_capacity << elem_size_lg2);
1444
- struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes);
1445
- if (!array) return NULL;
1446
- UPB_PRIVATE(_upb_Array_SetTaggedPtr)
1447
- (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2);
1448
- array->UPB_ONLYBITS(size) = 0;
1449
- array->UPB_PRIVATE(capacity) = init_capacity;
1450
- return array;
1451
- }
1452
-
1453
- // Resizes the capacity of the array to be at least min_size.
1454
- bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size,
1455
- upb_Arena* arena);
1456
-
1457
- UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
1458
- upb_Arena* arena) {
1459
- UPB_ASSERT(!upb_Array_IsFrozen(array));
1460
- if (array->UPB_PRIVATE(capacity) < size)
1461
- return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena);
1462
- return true;
1463
- }
1464
-
1465
- // Resize without initializing new elements.
1466
- UPB_INLINE bool UPB_PRIVATE(_upb_Array_ResizeUninitialized)(
1467
- struct upb_Array* array, size_t size, upb_Arena* arena) {
1468
- UPB_ASSERT(!upb_Array_IsFrozen(array));
1469
- UPB_ASSERT(size <= array->UPB_ONLYBITS(size) ||
1470
- arena); // Allow NULL arena when shrinking.
1471
- if (!upb_Array_Reserve(array, size, arena)) return false;
1472
- array->UPB_ONLYBITS(size) = size;
1473
- return true;
1474
- }
1475
-
1476
- // This function is intended for situations where elem_size is compile-time
1477
- // constant or a known expression of the form (1 << lg2), so that the expression
1478
- // i*elem_size does not result in an actual multiplication.
1479
- UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i,
1480
- const void* data,
1481
- size_t elem_size) {
1482
- UPB_ASSERT(!upb_Array_IsFrozen(array));
1483
- UPB_ASSERT(i < array->UPB_ONLYBITS(size));
1484
- UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array));
1485
- char* arr_data = (char*)upb_Array_MutableDataPtr(array);
1486
- memcpy(arr_data + (i * elem_size), data, elem_size);
1487
- }
1488
-
1489
- UPB_API_INLINE size_t upb_Array_Size(const struct upb_Array* arr) {
1490
- return arr->UPB_ONLYBITS(size);
1491
- }
1492
-
1493
- // LINT.ThenChange(GoogleInternalName0)
1494
-
1495
- #ifdef __cplusplus
1496
- } /* extern "C" */
1497
- #endif
1498
-
1499
- #undef _UPB_ARRAY_MASK_IMM
1500
- #undef _UPB_ARRAY_MASK_LG2
1501
- #undef _UPB_ARRAY_MASK_ALL
1502
-
1503
-
1504
- #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */
1505
-
1506
- // Users should include array.h or map.h instead.
1507
- // IWYU pragma: private, include "upb/message/array.h"
1508
-
1509
- #ifndef UPB_MESSAGE_VALUE_H_
1510
- #define UPB_MESSAGE_VALUE_H_
1511
-
1512
- #include <stdint.h>
1513
- #include <string.h>
1514
-
1515
-
1516
- // Must be last.
1517
-
1518
- #ifdef __cplusplus
1519
- extern "C" {
1520
- #endif
1521
-
1522
- typedef union {
1523
- bool bool_val;
1524
- float float_val;
1525
- double double_val;
1526
- int32_t int32_val;
1527
- int64_t int64_val;
1528
- uint32_t uint32_val;
1529
- uint64_t uint64_val;
1530
- const struct upb_Array* array_val;
1531
- const struct upb_Map* map_val;
1532
- const struct upb_Message* msg_val;
1533
- upb_StringView str_val;
1534
-
1535
- // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of
1536
- // msg_val if unlinked sub-messages may possibly be in use. See the
1537
- // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more
1538
- // information.
1539
- uintptr_t tagged_msg_val; // upb_TaggedMessagePtr
1540
- } upb_MessageValue;
1541
-
1542
- UPB_API_INLINE upb_MessageValue upb_MessageValue_Zero(void) {
1543
- upb_MessageValue zero;
1544
- memset(&zero, 0, sizeof(zero));
1545
- return zero;
1546
- }
1547
-
1548
- typedef union {
1549
- struct upb_Array* array;
1550
- struct upb_Map* map;
1551
- struct upb_Message* msg;
1552
- } upb_MutableMessageValue;
1553
-
1554
- UPB_API_INLINE upb_MutableMessageValue upb_MutableMessageValue_Zero(void) {
1555
- upb_MutableMessageValue zero;
1556
- memset(&zero, 0, sizeof(zero));
1557
- return zero;
1558
- }
1559
-
1560
- #ifdef __cplusplus
1561
- } /* extern "C" */
1562
- #endif
1563
-
1564
-
1565
- #endif /* UPB_MESSAGE_VALUE_H_ */
1566
-
1567
- #ifndef UPB_MINI_TABLE_FIELD_H_
1568
- #define UPB_MINI_TABLE_FIELD_H_
1569
-
1570
- #include <stdint.h>
1571
-
1572
-
1573
- #ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_
1574
- #define UPB_MINI_TABLE_INTERNAL_FIELD_H_
1575
-
1576
- #include <stddef.h>
1577
- #include <stdint.h>
1578
-
1579
-
1580
- #ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
1581
- #define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
1582
-
1583
- #include <stddef.h>
1584
- #include <stdint.h>
1585
-
1586
-
1587
- // Must be last.
1588
-
1589
- #ifdef __cplusplus
1590
- extern "C" {
1591
- #endif
1592
-
1593
- // Return the log2 of the storage size in bytes for a upb_CType
1594
- UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) {
1595
- static const int8_t size[] = {
1596
- 0, // kUpb_CType_Bool
1597
- 2, // kUpb_CType_Float
1598
- 2, // kUpb_CType_Int32
1599
- 2, // kUpb_CType_UInt32
1600
- 2, // kUpb_CType_Enum
1601
- UPB_SIZE(2, 3), // kUpb_CType_Message
1602
- 3, // kUpb_CType_Double
1603
- 3, // kUpb_CType_Int64
1604
- 3, // kUpb_CType_UInt64
1605
- UPB_SIZE(3, 4), // kUpb_CType_String
1606
- UPB_SIZE(3, 4), // kUpb_CType_Bytes
1607
- };
1608
-
1609
- // -1 here because the enum is one-based but the table is zero-based.
1610
- return size[c_type - 1];
1611
- }
1612
-
1613
- // Return the log2 of the storage size in bytes for a upb_FieldType
1614
- UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) {
1615
- static const int8_t size[] = {
1616
- 3, // kUpb_FieldType_Double
1617
- 2, // kUpb_FieldType_Float
1618
- 3, // kUpb_FieldType_Int64
1619
- 3, // kUpb_FieldType_UInt64
1620
- 2, // kUpb_FieldType_Int32
1621
- 3, // kUpb_FieldType_Fixed64
1622
- 2, // kUpb_FieldType_Fixed32
1623
- 0, // kUpb_FieldType_Bool
1624
- UPB_SIZE(3, 4), // kUpb_FieldType_String
1625
- UPB_SIZE(2, 3), // kUpb_FieldType_Group
1626
- UPB_SIZE(2, 3), // kUpb_FieldType_Message
1627
- UPB_SIZE(3, 4), // kUpb_FieldType_Bytes
1628
- 2, // kUpb_FieldType_UInt32
1629
- 2, // kUpb_FieldType_Enum
1630
- 2, // kUpb_FieldType_SFixed32
1631
- 3, // kUpb_FieldType_SFixed64
1632
- 2, // kUpb_FieldType_SInt32
1633
- 3, // kUpb_FieldType_SInt64
1634
- };
1635
-
1636
- // -1 here because the enum is one-based but the table is zero-based.
1637
- return size[field_type - 1];
1638
- }
1639
-
1640
- #ifdef __cplusplus
1641
- } /* extern "C" */
1642
- #endif
1643
-
1644
-
1645
- #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */
1646
-
1647
- // Must be last.
1648
-
1649
- // LINT.IfChange(struct_definition)
1650
- struct upb_MiniTableField {
1651
- uint32_t UPB_ONLYBITS(number);
1652
- uint16_t UPB_ONLYBITS(offset);
1653
- int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index
1473
+ // LINT.IfChange(struct_definition)
1474
+ struct upb_MiniTableField {
1475
+ uint32_t UPB_ONLYBITS(number);
1476
+ uint16_t UPB_ONLYBITS(offset);
1477
+ int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index
1654
1478
 
1655
1479
  // Indexes into `upb_MiniTable.subs`
1656
1480
  // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM
@@ -1850,47 +1674,104 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(
1850
1674
 
1851
1675
  #endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */
1852
1676
 
1677
+ #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_
1678
+ #define UPB_MINI_TABLE_INTERNAL_SUB_H_
1679
+
1853
1680
  // Must be last.
1854
1681
 
1855
- typedef struct upb_MiniTableField upb_MiniTableField;
1682
+ typedef union {
1683
+ const struct upb_MiniTable* const* UPB_PRIVATE(submsg);
1684
+ const struct upb_MiniTableEnum* UPB_PRIVATE(subenum);
1685
+ } upb_MiniTableSubInternal;
1686
+
1687
+ union upb_MiniTableSub {
1688
+ const struct upb_MiniTable* UPB_PRIVATE(submsg);
1689
+ const struct upb_MiniTableEnum* UPB_PRIVATE(subenum);
1690
+ };
1856
1691
 
1857
1692
  #ifdef __cplusplus
1858
1693
  extern "C" {
1859
1694
  #endif
1860
1695
 
1861
- UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f);
1696
+ UPB_API_INLINE union upb_MiniTableSub upb_MiniTableSub_FromEnum(
1697
+ const struct upb_MiniTableEnum* subenum) {
1698
+ union upb_MiniTableSub out;
1699
+ out.UPB_PRIVATE(subenum) = subenum;
1700
+ return out;
1701
+ }
1862
1702
 
1863
- UPB_API_INLINE bool upb_MiniTableField_HasPresence(const upb_MiniTableField* f);
1703
+ UPB_API_INLINE union upb_MiniTableSub upb_MiniTableSub_FromMessage(
1704
+ const struct upb_MiniTable* submsg) {
1705
+ union upb_MiniTableSub out;
1706
+ out.UPB_PRIVATE(submsg) = submsg;
1707
+ return out;
1708
+ }
1864
1709
 
1865
- UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f);
1710
+ UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum(
1711
+ const union upb_MiniTableSub sub) {
1712
+ return sub.UPB_PRIVATE(subenum);
1713
+ }
1866
1714
 
1867
- UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum(
1868
- const upb_MiniTableField* f);
1715
+ UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message(
1716
+ const union upb_MiniTableSub sub) {
1717
+ return sub.UPB_PRIVATE(submsg);
1718
+ }
1869
1719
 
1870
- UPB_API_INLINE bool upb_MiniTableField_IsExtension(const upb_MiniTableField* f);
1720
+ #ifdef __cplusplus
1721
+ } /* extern "C" */
1722
+ #endif
1871
1723
 
1872
- UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f);
1873
1724
 
1874
- UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f);
1725
+ #endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */
1875
1726
 
1876
- UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f);
1727
+ // Must be last.
1877
1728
 
1878
- UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f);
1729
+ struct upb_MiniTableExtension {
1730
+ // Do not move this field. We need to be able to alias pointers.
1731
+ struct upb_MiniTableField UPB_PRIVATE(field);
1879
1732
 
1880
- UPB_API_INLINE bool upb_MiniTableField_IsSubMessage(
1881
- const upb_MiniTableField* f);
1733
+ const struct upb_MiniTable* UPB_PRIVATE(extendee);
1734
+ union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum
1735
+ };
1882
1736
 
1883
- UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f);
1737
+ #ifdef __cplusplus
1738
+ extern "C" {
1739
+ #endif
1884
1740
 
1885
- UPB_API_INLINE upb_FieldType
1886
- upb_MiniTableField_Type(const upb_MiniTableField* f);
1741
+ UPB_API_INLINE upb_CType
1742
+ upb_MiniTableExtension_CType(const struct upb_MiniTableExtension* e) {
1743
+ return upb_MiniTableField_CType(&e->UPB_PRIVATE(field));
1744
+ }
1745
+
1746
+ UPB_API_INLINE uint32_t
1747
+ upb_MiniTableExtension_Number(const struct upb_MiniTableExtension* e) {
1748
+ return e->UPB_PRIVATE(field).UPB_ONLYBITS(number);
1749
+ }
1750
+
1751
+ UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage(
1752
+ const struct upb_MiniTableExtension* e) {
1753
+ if (upb_MiniTableExtension_CType(e) != kUpb_CType_Message) {
1754
+ return NULL;
1755
+ }
1756
+ return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub));
1757
+ }
1758
+
1759
+ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
1760
+ struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) {
1761
+ e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
1762
+ }
1763
+
1764
+ UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
1765
+ const struct upb_MiniTableExtension* e) {
1766
+ return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
1767
+ }
1887
1768
 
1888
1769
  #ifdef __cplusplus
1889
1770
  } /* extern "C" */
1890
1771
  #endif
1891
1772
 
1892
1773
 
1893
- #endif /* UPB_MINI_TABLE_FIELD_H_ */
1774
+ #endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */
1894
1775
 
1895
1776
  #ifndef UPB_MINI_TABLE_MESSAGE_H_
1896
1777
  #define UPB_MINI_TABLE_MESSAGE_H_
@@ -1970,62 +1851,60 @@ UPB_API_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e,
1970
1851
 
1971
1852
  #endif /* UPB_MINI_TABLE_ENUM_H_ */
1972
1853
 
1973
- #ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
1974
- #define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
1854
+ #ifndef UPB_MINI_TABLE_FIELD_H_
1855
+ #define UPB_MINI_TABLE_FIELD_H_
1975
1856
 
1976
- #include <stddef.h>
1977
1857
  #include <stdint.h>
1978
1858
 
1979
1859
 
1980
- #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_
1981
- #define UPB_MINI_TABLE_INTERNAL_SUB_H_
1982
-
1983
1860
  // Must be last.
1984
1861
 
1985
- typedef union {
1986
- const struct upb_MiniTable* const* UPB_PRIVATE(submsg);
1987
- const struct upb_MiniTableEnum* UPB_PRIVATE(subenum);
1988
- } upb_MiniTableSubInternal;
1989
-
1990
- union upb_MiniTableSub {
1991
- const struct upb_MiniTable* UPB_PRIVATE(submsg);
1992
- const struct upb_MiniTableEnum* UPB_PRIVATE(subenum);
1993
- };
1862
+ typedef struct upb_MiniTableField upb_MiniTableField;
1994
1863
 
1995
1864
  #ifdef __cplusplus
1996
1865
  extern "C" {
1997
1866
  #endif
1998
1867
 
1999
- UPB_API_INLINE union upb_MiniTableSub upb_MiniTableSub_FromEnum(
2000
- const struct upb_MiniTableEnum* subenum) {
2001
- union upb_MiniTableSub out;
2002
- out.UPB_PRIVATE(subenum) = subenum;
2003
- return out;
2004
- }
1868
+ UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f);
2005
1869
 
2006
- UPB_API_INLINE union upb_MiniTableSub upb_MiniTableSub_FromMessage(
2007
- const struct upb_MiniTable* submsg) {
2008
- union upb_MiniTableSub out;
2009
- out.UPB_PRIVATE(submsg) = submsg;
2010
- return out;
2011
- }
1870
+ UPB_API_INLINE bool upb_MiniTableField_HasPresence(const upb_MiniTableField* f);
2012
1871
 
2013
- UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum(
2014
- const union upb_MiniTableSub sub) {
2015
- return sub.UPB_PRIVATE(subenum);
2016
- }
1872
+ UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f);
2017
1873
 
2018
- UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message(
2019
- const union upb_MiniTableSub sub) {
2020
- return sub.UPB_PRIVATE(submsg);
2021
- }
1874
+ UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum(
1875
+ const upb_MiniTableField* f);
1876
+
1877
+ UPB_API_INLINE bool upb_MiniTableField_IsExtension(const upb_MiniTableField* f);
1878
+
1879
+ UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f);
1880
+
1881
+ UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f);
1882
+
1883
+ UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f);
1884
+
1885
+ UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f);
1886
+
1887
+ UPB_API_INLINE bool upb_MiniTableField_IsSubMessage(
1888
+ const upb_MiniTableField* f);
1889
+
1890
+ UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f);
1891
+
1892
+ UPB_API_INLINE upb_FieldType
1893
+ upb_MiniTableField_Type(const upb_MiniTableField* f);
2022
1894
 
2023
1895
  #ifdef __cplusplus
2024
1896
  } /* extern "C" */
2025
1897
  #endif
2026
1898
 
2027
1899
 
2028
- #endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */
1900
+ #endif /* UPB_MINI_TABLE_FIELD_H_ */
1901
+
1902
+ #ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
1903
+ #define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
1904
+
1905
+ #include <stddef.h>
1906
+ #include <stdint.h>
1907
+
2029
1908
 
2030
1909
  // Must be last.
2031
1910
 
@@ -2294,90 +2173,73 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m,
2294
2173
 
2295
2174
  // Must be last.
2296
2175
 
2297
- typedef struct upb_Array upb_Array;
2176
+ typedef struct upb_MiniTableExtension upb_MiniTableExtension;
2298
2177
 
2299
2178
  #ifdef __cplusplus
2300
2179
  extern "C" {
2301
2180
  #endif
2302
2181
 
2303
- // Creates a new array on the given arena that holds elements of this type.
2304
- UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type);
2305
-
2306
- // Returns the number of elements in the array.
2307
- UPB_API_INLINE size_t upb_Array_Size(const upb_Array* arr);
2308
-
2309
- // Returns the given element, which must be within the array's current size.
2310
- UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i);
2182
+ UPB_API_INLINE upb_CType
2183
+ upb_MiniTableExtension_CType(const upb_MiniTableExtension* e);
2311
2184
 
2312
- // Returns a mutating pointer to the given element, which must be within the
2313
- // array's current size.
2314
- UPB_API upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i);
2185
+ UPB_API_INLINE uint32_t
2186
+ upb_MiniTableExtension_Number(const upb_MiniTableExtension* e);
2315
2187
 
2316
- // Sets the given element, which must be within the array's current size.
2317
- UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val);
2188
+ UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage(
2189
+ const upb_MiniTableExtension* e);
2318
2190
 
2319
- // Appends an element to the array. Returns false on allocation failure.
2320
- UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val,
2321
- upb_Arena* arena);
2191
+ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
2192
+ upb_MiniTableExtension* e, const upb_MiniTable* m);
2322
2193
 
2323
- // Moves elements within the array using memmove().
2324
- // Like memmove(), the source and destination elements may be overlapping.
2325
- UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx,
2326
- size_t count);
2194
+ #ifdef __cplusplus
2195
+ } /* extern "C" */
2196
+ #endif
2327
2197
 
2328
- // Inserts one or more empty elements into the array.
2329
- // Existing elements are shifted right.
2330
- // The new elements have undefined state and must be set with `upb_Array_Set()`.
2331
- // REQUIRES: `i <= upb_Array_Size(arr)`
2332
- UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count,
2333
- upb_Arena* arena);
2334
2198
 
2335
- // Deletes one or more elements from the array.
2336
- // Existing elements are shifted left.
2337
- // REQUIRES: `i + count <= upb_Array_Size(arr)`
2338
- UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count);
2199
+ #endif /* UPB_MINI_TABLE_EXTENSION_H_ */
2339
2200
 
2340
- // Reserves |size| elements of storage for the array.
2341
- UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
2342
- upb_Arena* arena);
2201
+ // Must be last.
2343
2202
 
2344
- // Changes the size of a vector. New elements are initialized to NULL/0.
2345
- // Returns false on allocation failure.
2346
- UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena);
2203
+ // The internal representation of an extension is self-describing: it contains
2204
+ // enough information that we can serialize it to binary format without needing
2205
+ // to look it up in a upb_ExtensionRegistry.
2206
+ //
2207
+ // This representation allocates 16 bytes to data on 64-bit platforms.
2208
+ // This is rather wasteful for scalars (in the extreme case of bool,
2209
+ // it wastes 15 bytes). We accept this because we expect messages to be
2210
+ // the most common extension type.
2211
+ typedef struct {
2212
+ const upb_MiniTableExtension* ext;
2213
+ upb_MessageValue data;
2214
+ } upb_Extension;
2347
2215
 
2348
- // Returns pointer to array data.
2349
- UPB_API_INLINE const void* upb_Array_DataPtr(const upb_Array* arr);
2216
+ #ifdef __cplusplus
2217
+ extern "C" {
2218
+ #endif
2350
2219
 
2351
- // Returns mutable pointer to array data.
2352
- UPB_API_INLINE void* upb_Array_MutableDataPtr(upb_Array* arr);
2220
+ // Adds the given extension data to the given message.
2221
+ // |ext| is copied into the message instance.
2222
+ // This logically replaces any previously-added extension with this number.
2223
+ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(
2224
+ struct upb_Message* msg, const upb_MiniTableExtension* ext,
2225
+ upb_Arena* arena);
2353
2226
 
2354
- // Mark an array and all of its descendents as frozen/immutable.
2355
- // If the array elements are messages then |m| must point to the minitable for
2356
- // those messages. Otherwise |m| must be NULL.
2357
- UPB_API void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m);
2227
+ // Returns an array of extensions for this message.
2228
+ // Note: the array is ordered in reverse relative to the order of creation.
2229
+ const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
2230
+ const struct upb_Message* msg, size_t* count);
2358
2231
 
2359
- // Returns whether an array has been frozen.
2360
- UPB_API_INLINE bool upb_Array_IsFrozen(const upb_Array* arr);
2232
+ // Returns an extension for a message with a given mini table,
2233
+ // or NULL if no extension exists with this mini table.
2234
+ const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)(
2235
+ const struct upb_Message* msg, const upb_MiniTableExtension* ext);
2361
2236
 
2362
2237
  #ifdef __cplusplus
2363
2238
  } /* extern "C" */
2364
2239
  #endif
2365
2240
 
2366
2241
 
2367
- #endif /* UPB_MESSAGE_ARRAY_H_ */
2368
-
2369
- #ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
2370
- #define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
2371
-
2372
- #include <stddef.h>
2373
- #include <stdint.h>
2374
- #include <string.h>
2375
-
2376
-
2377
- #ifndef UPB_BASE_INTERNAL_ENDIAN_H_
2378
- #define UPB_BASE_INTERNAL_ENDIAN_H_
2379
-
2380
- #include <stdint.h>
2242
+ #endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */
2381
2243
 
2382
2244
  // Must be last.
2383
2245
 
@@ -2385,170 +2247,501 @@ UPB_API_INLINE bool upb_Array_IsFrozen(const upb_Array* arr);
2385
2247
  extern "C" {
2386
2248
  #endif
2387
2249
 
2388
- UPB_INLINE bool upb_IsLittleEndian(void) {
2389
- const int x = 1;
2390
- return *(char*)&x == 1;
2391
- }
2392
-
2393
- UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) {
2394
- if (upb_IsLittleEndian()) return val;
2395
-
2396
- return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
2397
- ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
2398
- }
2250
+ extern const float kUpb_FltInfinity;
2251
+ extern const double kUpb_Infinity;
2252
+ extern const double kUpb_NaN;
2399
2253
 
2400
- UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) {
2401
- if (upb_IsLittleEndian()) return val;
2254
+ // Internal members of a upb_Message that track unknown fields and/or
2255
+ // extensions. We can change this without breaking binary compatibility.
2402
2256
 
2403
- const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32;
2404
- const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32));
2405
- return hi | lo;
2406
- }
2257
+ typedef struct upb_Message_Internal {
2258
+ // Total size of this structure, including the data that follows.
2259
+ // Must be aligned to 8, which is alignof(upb_Extension)
2260
+ uint32_t size;
2407
2261
 
2408
- #ifdef __cplusplus
2409
- } /* extern "C" */
2262
+ /* Offsets relative to the beginning of this structure.
2263
+ *
2264
+ * Unknown data grows forward from the beginning to unknown_end.
2265
+ * Extension data grows backward from size to ext_begin.
2266
+ * When the two meet, we're out of data and have to realloc.
2267
+ *
2268
+ * If we imagine that the final member of this struct is:
2269
+ * char data[size - overhead]; // overhead = sizeof(upb_Message_Internal)
2270
+ *
2271
+ * Then we have:
2272
+ * unknown data: data[0 .. (unknown_end - overhead)]
2273
+ * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */
2274
+ uint32_t unknown_end;
2275
+ uint32_t ext_begin;
2276
+ // Data follows, as if there were an array:
2277
+ // char data[size - sizeof(upb_Message_Internal)];
2278
+ } upb_Message_Internal;
2279
+
2280
+ #ifdef UPB_TRACING_ENABLED
2281
+ UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
2282
+ const upb_Arena* arena);
2283
+ UPB_API void upb_Message_SetNewMessageTraceHandler(
2284
+ void (*handler)(const upb_MiniTable*, const upb_Arena*));
2285
+ #endif // UPB_TRACING_ENABLED
2286
+
2287
+ // Inline version upb_Message_New(), for internal use.
2288
+ UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* m,
2289
+ upb_Arena* a) {
2290
+ #ifdef UPB_TRACING_ENABLED
2291
+ upb_Message_LogNewMessage(m, a);
2292
+ #endif // UPB_TRACING_ENABLED
2293
+
2294
+ const int size = m->UPB_PRIVATE(size);
2295
+ struct upb_Message* msg = (struct upb_Message*)upb_Arena_Malloc(a, size);
2296
+ if (UPB_UNLIKELY(!msg)) return NULL;
2297
+ memset(msg, 0, size);
2298
+ return msg;
2299
+ }
2300
+
2301
+ // Discards the unknown fields for this message only.
2302
+ void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg);
2303
+
2304
+ // Adds unknown data (serialized protobuf data) to the given message.
2305
+ // The data is copied into the message instance.
2306
+ bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
2307
+ const char* data, size_t len,
2308
+ upb_Arena* arena);
2309
+
2310
+ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
2311
+ upb_Arena* arena);
2312
+
2313
+ #ifdef __cplusplus
2314
+ } /* extern "C" */
2410
2315
  #endif
2411
2316
 
2412
2317
 
2413
- #endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */
2318
+ #endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */
2414
2319
 
2415
- #ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_
2416
- #define UPB_MESSAGE_INTERNAL_EXTENSION_H_
2320
+ #ifndef UPB_MESSAGE_INTERNAL_TYPES_H_
2321
+ #define UPB_MESSAGE_INTERNAL_TYPES_H_
2417
2322
 
2418
- #include <stddef.h>
2323
+ #include <stdint.h>
2324
+
2325
+ // Must be last.
2419
2326
 
2327
+ #define UPB_OPAQUE(x) x##_opaque
2420
2328
 
2421
- #ifndef UPB_MINI_TABLE_EXTENSION_H_
2422
- #define UPB_MINI_TABLE_EXTENSION_H_
2329
+ struct upb_Message {
2330
+ union {
2331
+ uintptr_t UPB_OPAQUE(internal); // tagged pointer, low bit == frozen
2332
+ double d; // Forces same size for 32-bit/64-bit builds
2333
+ };
2334
+ };
2335
+
2336
+ #ifdef __cplusplus
2337
+ extern "C" {
2338
+ #endif
2339
+
2340
+ UPB_INLINE void UPB_PRIVATE(_upb_Message_ShallowFreeze)(
2341
+ struct upb_Message* msg) {
2342
+ msg->UPB_OPAQUE(internal) |= 1ULL;
2343
+ }
2344
+
2345
+ UPB_API_INLINE bool upb_Message_IsFrozen(const struct upb_Message* msg) {
2346
+ return (msg->UPB_OPAQUE(internal) & 1ULL) != 0;
2347
+ }
2348
+
2349
+ UPB_INLINE struct upb_Message_Internal* UPB_PRIVATE(_upb_Message_GetInternal)(
2350
+ const struct upb_Message* msg) {
2351
+ const uintptr_t tmp = msg->UPB_OPAQUE(internal) & ~1ULL;
2352
+ return (struct upb_Message_Internal*)tmp;
2353
+ }
2354
+
2355
+ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetInternal)(
2356
+ struct upb_Message* msg, struct upb_Message_Internal* internal) {
2357
+ UPB_ASSERT(!upb_Message_IsFrozen(msg));
2358
+ msg->UPB_OPAQUE(internal) = (uintptr_t)internal;
2359
+ }
2360
+
2361
+ #ifdef __cplusplus
2362
+ } /* extern "C" */
2363
+ #endif
2364
+
2365
+ #undef UPB_OPAQUE
2366
+
2367
+
2368
+ #endif /* UPB_MESSAGE_INTERNAL_TYPES_H_ */
2369
+
2370
+ // Must be last.
2371
+
2372
+ typedef struct upb_Message upb_Message;
2373
+
2374
+ #ifdef __cplusplus
2375
+ extern "C" {
2376
+ #endif
2377
+
2378
+ // Creates a new message with the given mini_table on the given arena.
2379
+ UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena);
2380
+
2381
+ // Returns a reference to the message's unknown data.
2382
+ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len);
2383
+
2384
+ // Removes partial unknown data from message.
2385
+ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len);
2386
+
2387
+ // Returns the number of extensions present in this message.
2388
+ size_t upb_Message_ExtensionCount(const upb_Message* msg);
2389
+
2390
+ // Mark a message and all of its descendents as frozen/immutable.
2391
+ UPB_API void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m);
2392
+
2393
+ // Returns whether a message has been frozen.
2394
+ UPB_API_INLINE bool upb_Message_IsFrozen(const upb_Message* msg);
2395
+
2396
+ #ifdef UPB_TRACING_ENABLED
2397
+ UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
2398
+ const upb_Arena* arena);
2399
+
2400
+ UPB_API void upb_Message_SetNewMessageTraceHandler(
2401
+ void (*handler)(const upb_MiniTable* m, const upb_Arena* arena));
2402
+ #endif // UPB_TRACING_ENABLED
2403
+
2404
+ #ifdef __cplusplus
2405
+ } /* extern "C" */
2406
+ #endif
2407
+
2408
+
2409
+ #endif /* UPB_MESSAGE_MESSAGE_H_ */
2410
+
2411
+ #ifndef UPB_REFLECTION_DEF_H_
2412
+ #define UPB_REFLECTION_DEF_H_
2413
+
2414
+ // IWYU pragma: begin_exports
2415
+
2416
+ // IWYU pragma: private, include "upb/reflection/def.h"
2417
+
2418
+ #ifndef UPB_REFLECTION_DEF_POOL_H_
2419
+ #define UPB_REFLECTION_DEF_POOL_H_
2420
+
2421
+
2422
+ // IWYU pragma: private, include "upb/reflection/def.h"
2423
+
2424
+ // Declarations common to all public def types.
2425
+
2426
+ #ifndef UPB_REFLECTION_COMMON_H_
2427
+ #define UPB_REFLECTION_COMMON_H_
2428
+
2429
+ #ifndef THIRD_PARTY_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H_
2430
+ #define THIRD_PARTY_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H_
2431
+
2432
+ // IWYU pragma: begin_exports
2433
+
2434
+ #if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0
2435
+ // This header is checked in.
2436
+ #elif UPB_BOOTSTRAP_STAGE == 1
2437
+ // This header is generated at build time by the bootstrapping process.
2438
+ #else
2439
+ // This is the normal header, generated by upb_c_proto_library().
2440
+ /* This file was generated by upb_generator from the input file:
2441
+ *
2442
+ * google/protobuf/descriptor.proto
2443
+ *
2444
+ * Do not edit -- your changes will be discarded when the file is
2445
+ * regenerated.
2446
+ * NO CHECKED-IN PROTOBUF GENCODE */
2447
+
2448
+ #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
2449
+ #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
2450
+
2451
+
2452
+ #ifndef UPB_GENERATED_CODE_SUPPORT_H_
2453
+ #define UPB_GENERATED_CODE_SUPPORT_H_
2454
+
2455
+ // IWYU pragma: begin_exports
2456
+
2457
+ #ifndef UPB_BASE_UPCAST_H_
2458
+ #define UPB_BASE_UPCAST_H_
2459
+
2460
+ // Must be last.
2461
+
2462
+ // This macro provides a way to upcast message pointers in a way that is
2463
+ // somewhat more bulletproof than blindly casting a pointer. Example:
2464
+ //
2465
+ // typedef struct {
2466
+ // upb_Message UPB_PRIVATE(base);
2467
+ // } pkg_FooMessage;
2468
+ //
2469
+ // void f(pkg_FooMessage* msg) {
2470
+ // upb_Decode(UPB_UPCAST(msg), ...);
2471
+ // }
2472
+
2473
+ #define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only)
2474
+
2475
+
2476
+ #endif /* UPB_BASE_UPCAST_H_ */
2477
+
2478
+ #ifndef UPB_MESSAGE_ACCESSORS_H_
2479
+ #define UPB_MESSAGE_ACCESSORS_H_
2423
2480
 
2424
2481
  #include <stdint.h>
2425
2482
 
2426
2483
 
2427
- #ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_
2428
- #define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_
2484
+ #ifndef UPB_MESSAGE_ARRAY_H_
2485
+ #define UPB_MESSAGE_ARRAY_H_
2429
2486
 
2430
2487
  #include <stddef.h>
2488
+
2489
+
2490
+ #ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_
2491
+ #define UPB_MESSAGE_INTERNAL_ARRAY_H_
2492
+
2431
2493
  #include <stdint.h>
2494
+ #include <string.h>
2432
2495
 
2433
2496
 
2434
2497
  // Must be last.
2435
2498
 
2436
- struct upb_MiniTableExtension {
2437
- // Do not move this field. We need to be able to alias pointers.
2438
- struct upb_MiniTableField UPB_PRIVATE(field);
2439
-
2440
- const struct upb_MiniTable* UPB_PRIVATE(extendee);
2441
- union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum
2442
- };
2499
+ #define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit.
2500
+ #define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size.
2501
+ #define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2)
2443
2502
 
2444
2503
  #ifdef __cplusplus
2445
2504
  extern "C" {
2446
2505
  #endif
2447
2506
 
2448
- UPB_API_INLINE upb_CType
2449
- upb_MiniTableExtension_CType(const struct upb_MiniTableExtension* e) {
2450
- return upb_MiniTableField_CType(&e->UPB_PRIVATE(field));
2507
+ // LINT.IfChange(upb_Array)
2508
+
2509
+ // Our internal representation for repeated fields.
2510
+ struct upb_Array {
2511
+ // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows:
2512
+ // 0 maps to elem size 1
2513
+ // 1 maps to elem size 4
2514
+ // 2 maps to elem size 8
2515
+ // 3 maps to elem size 16
2516
+ //
2517
+ // Bit #2 contains the frozen/immutable flag.
2518
+ uintptr_t UPB_ONLYBITS(data);
2519
+
2520
+ size_t UPB_ONLYBITS(size); // The number of elements in the array.
2521
+ size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements.
2522
+ };
2523
+
2524
+ UPB_INLINE void UPB_PRIVATE(_upb_Array_ShallowFreeze)(struct upb_Array* arr) {
2525
+ arr->UPB_ONLYBITS(data) |= _UPB_ARRAY_MASK_IMM;
2451
2526
  }
2452
2527
 
2453
- UPB_API_INLINE uint32_t
2454
- upb_MiniTableExtension_Number(const struct upb_MiniTableExtension* e) {
2455
- return e->UPB_PRIVATE(field).UPB_ONLYBITS(number);
2528
+ UPB_API_INLINE bool upb_Array_IsFrozen(const struct upb_Array* arr) {
2529
+ return (arr->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_IMM) != 0;
2456
2530
  }
2457
2531
 
2458
- UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage(
2459
- const struct upb_MiniTableExtension* e) {
2460
- if (upb_MiniTableExtension_CType(e) != kUpb_CType_Message) {
2461
- return NULL;
2462
- }
2463
- return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub));
2532
+ UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array,
2533
+ void* data, size_t lg2) {
2534
+ UPB_ASSERT(lg2 != 1);
2535
+ UPB_ASSERT(lg2 <= 4);
2536
+ const size_t bits = lg2 - (lg2 != 0);
2537
+ array->UPB_ONLYBITS(data) = (uintptr_t)data | bits;
2464
2538
  }
2465
2539
 
2466
- UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
2467
- struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) {
2468
- e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
2540
+ UPB_INLINE size_t
2541
+ UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) {
2542
+ const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2;
2543
+ const size_t lg2 = bits + (bits != 0);
2544
+ return lg2;
2469
2545
  }
2470
2546
 
2471
- UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
2472
- const struct upb_MiniTableExtension* e) {
2473
- return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
2547
+ UPB_API_INLINE const void* upb_Array_DataPtr(const struct upb_Array* array) {
2548
+ UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions.
2549
+ return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL);
2550
+ }
2551
+
2552
+ UPB_API_INLINE void* upb_Array_MutableDataPtr(struct upb_Array* array) {
2553
+ return (void*)upb_Array_DataPtr(array);
2554
+ }
2555
+
2556
+ UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena,
2557
+ size_t init_capacity,
2558
+ int elem_size_lg2) {
2559
+ UPB_ASSERT(elem_size_lg2 != 1);
2560
+ UPB_ASSERT(elem_size_lg2 <= 4);
2561
+ const size_t array_size =
2562
+ UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN);
2563
+ const size_t bytes = array_size + (init_capacity << elem_size_lg2);
2564
+ struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes);
2565
+ if (!array) return NULL;
2566
+ UPB_PRIVATE(_upb_Array_SetTaggedPtr)
2567
+ (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2);
2568
+ array->UPB_ONLYBITS(size) = 0;
2569
+ array->UPB_PRIVATE(capacity) = init_capacity;
2570
+ return array;
2571
+ }
2572
+
2573
+ // Resizes the capacity of the array to be at least min_size.
2574
+ bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size,
2575
+ upb_Arena* arena);
2576
+
2577
+ UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
2578
+ upb_Arena* arena) {
2579
+ UPB_ASSERT(!upb_Array_IsFrozen(array));
2580
+ if (array->UPB_PRIVATE(capacity) < size)
2581
+ return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena);
2582
+ return true;
2583
+ }
2584
+
2585
+ // Resize without initializing new elements.
2586
+ UPB_INLINE bool UPB_PRIVATE(_upb_Array_ResizeUninitialized)(
2587
+ struct upb_Array* array, size_t size, upb_Arena* arena) {
2588
+ UPB_ASSERT(!upb_Array_IsFrozen(array));
2589
+ UPB_ASSERT(size <= array->UPB_ONLYBITS(size) ||
2590
+ arena); // Allow NULL arena when shrinking.
2591
+ if (!upb_Array_Reserve(array, size, arena)) return false;
2592
+ array->UPB_ONLYBITS(size) = size;
2593
+ return true;
2474
2594
  }
2475
2595
 
2596
+ // This function is intended for situations where elem_size is compile-time
2597
+ // constant or a known expression of the form (1 << lg2), so that the expression
2598
+ // i*elem_size does not result in an actual multiplication.
2599
+ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i,
2600
+ const void* data,
2601
+ size_t elem_size) {
2602
+ UPB_ASSERT(!upb_Array_IsFrozen(array));
2603
+ UPB_ASSERT(i < array->UPB_ONLYBITS(size));
2604
+ UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array));
2605
+ char* arr_data = (char*)upb_Array_MutableDataPtr(array);
2606
+ memcpy(arr_data + (i * elem_size), data, elem_size);
2607
+ }
2608
+
2609
+ UPB_API_INLINE size_t upb_Array_Size(const struct upb_Array* arr) {
2610
+ return arr->UPB_ONLYBITS(size);
2611
+ }
2612
+
2613
+ // LINT.ThenChange(GoogleInternalName0)
2614
+
2476
2615
  #ifdef __cplusplus
2477
2616
  } /* extern "C" */
2478
2617
  #endif
2479
2618
 
2619
+ #undef _UPB_ARRAY_MASK_IMM
2620
+ #undef _UPB_ARRAY_MASK_LG2
2621
+ #undef _UPB_ARRAY_MASK_ALL
2480
2622
 
2481
- #endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */
2623
+
2624
+ #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */
2482
2625
 
2483
2626
  // Must be last.
2484
2627
 
2485
- typedef struct upb_MiniTableExtension upb_MiniTableExtension;
2628
+ typedef struct upb_Array upb_Array;
2486
2629
 
2487
2630
  #ifdef __cplusplus
2488
2631
  extern "C" {
2489
2632
  #endif
2490
2633
 
2491
- UPB_API_INLINE upb_CType
2492
- upb_MiniTableExtension_CType(const upb_MiniTableExtension* e);
2634
+ // Creates a new array on the given arena that holds elements of this type.
2635
+ UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type);
2493
2636
 
2494
- UPB_API_INLINE uint32_t
2495
- upb_MiniTableExtension_Number(const upb_MiniTableExtension* e);
2637
+ // Returns the number of elements in the array.
2638
+ UPB_API_INLINE size_t upb_Array_Size(const upb_Array* arr);
2496
2639
 
2497
- UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage(
2498
- const upb_MiniTableExtension* e);
2640
+ // Returns the given element, which must be within the array's current size.
2641
+ UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i);
2642
+
2643
+ // Returns a mutating pointer to the given element, which must be within the
2644
+ // array's current size.
2645
+ UPB_API upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i);
2646
+
2647
+ // Sets the given element, which must be within the array's current size.
2648
+ UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val);
2649
+
2650
+ // Appends an element to the array. Returns false on allocation failure.
2651
+ UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val,
2652
+ upb_Arena* arena);
2653
+
2654
+ // Moves elements within the array using memmove().
2655
+ // Like memmove(), the source and destination elements may be overlapping.
2656
+ UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx,
2657
+ size_t count);
2658
+
2659
+ // Inserts one or more empty elements into the array.
2660
+ // Existing elements are shifted right.
2661
+ // The new elements have undefined state and must be set with `upb_Array_Set()`.
2662
+ // REQUIRES: `i <= upb_Array_Size(arr)`
2663
+ UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count,
2664
+ upb_Arena* arena);
2665
+
2666
+ // Deletes one or more elements from the array.
2667
+ // Existing elements are shifted left.
2668
+ // REQUIRES: `i + count <= upb_Array_Size(arr)`
2669
+ UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count);
2670
+
2671
+ // Reserves |size| elements of storage for the array.
2672
+ UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
2673
+ upb_Arena* arena);
2674
+
2675
+ // Changes the size of a vector. New elements are initialized to NULL/0.
2676
+ // Returns false on allocation failure.
2677
+ UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena);
2678
+
2679
+ // Returns pointer to array data.
2680
+ UPB_API_INLINE const void* upb_Array_DataPtr(const upb_Array* arr);
2681
+
2682
+ // Returns mutable pointer to array data.
2683
+ UPB_API_INLINE void* upb_Array_MutableDataPtr(upb_Array* arr);
2684
+
2685
+ // Mark an array and all of its descendents as frozen/immutable.
2686
+ // If the array elements are messages then |m| must point to the minitable for
2687
+ // those messages. Otherwise |m| must be NULL.
2688
+ UPB_API void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m);
2689
+
2690
+ // Returns whether an array has been frozen.
2691
+ UPB_API_INLINE bool upb_Array_IsFrozen(const upb_Array* arr);
2692
+
2693
+ #ifdef __cplusplus
2694
+ } /* extern "C" */
2695
+ #endif
2696
+
2697
+
2698
+ #endif /* UPB_MESSAGE_ARRAY_H_ */
2699
+
2700
+ #ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
2701
+ #define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
2499
2702
 
2500
- UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
2501
- upb_MiniTableExtension* e, const upb_MiniTable* m);
2703
+ #include <stddef.h>
2704
+ #include <stdint.h>
2705
+ #include <string.h>
2502
2706
 
2503
- #ifdef __cplusplus
2504
- } /* extern "C" */
2505
- #endif
2506
2707
 
2708
+ #ifndef UPB_BASE_INTERNAL_ENDIAN_H_
2709
+ #define UPB_BASE_INTERNAL_ENDIAN_H_
2507
2710
 
2508
- #endif /* UPB_MINI_TABLE_EXTENSION_H_ */
2711
+ #include <stdint.h>
2509
2712
 
2510
2713
  // Must be last.
2511
2714
 
2512
- // The internal representation of an extension is self-describing: it contains
2513
- // enough information that we can serialize it to binary format without needing
2514
- // to look it up in a upb_ExtensionRegistry.
2515
- //
2516
- // This representation allocates 16 bytes to data on 64-bit platforms.
2517
- // This is rather wasteful for scalars (in the extreme case of bool,
2518
- // it wastes 15 bytes). We accept this because we expect messages to be
2519
- // the most common extension type.
2520
- typedef struct {
2521
- const upb_MiniTableExtension* ext;
2522
- upb_MessageValue data;
2523
- } upb_Extension;
2524
-
2525
2715
  #ifdef __cplusplus
2526
2716
  extern "C" {
2527
2717
  #endif
2528
2718
 
2529
- // Adds the given extension data to the given message.
2530
- // |ext| is copied into the message instance.
2531
- // This logically replaces any previously-added extension with this number.
2532
- upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(
2533
- struct upb_Message* msg, const upb_MiniTableExtension* ext,
2534
- upb_Arena* arena);
2719
+ UPB_INLINE bool upb_IsLittleEndian(void) {
2720
+ const int x = 1;
2721
+ return *(char*)&x == 1;
2722
+ }
2535
2723
 
2536
- // Returns an array of extensions for this message.
2537
- // Note: the array is ordered in reverse relative to the order of creation.
2538
- const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
2539
- const struct upb_Message* msg, size_t* count);
2724
+ UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) {
2725
+ if (upb_IsLittleEndian()) return val;
2540
2726
 
2541
- // Returns an extension for a message with a given mini table,
2542
- // or NULL if no extension exists with this mini table.
2543
- const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)(
2544
- const struct upb_Message* msg, const upb_MiniTableExtension* ext);
2727
+ return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
2728
+ ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
2729
+ }
2730
+
2731
+ UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) {
2732
+ if (upb_IsLittleEndian()) return val;
2733
+
2734
+ const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32;
2735
+ const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32));
2736
+ return hi | lo;
2737
+ }
2545
2738
 
2546
2739
  #ifdef __cplusplus
2547
2740
  } /* extern "C" */
2548
2741
  #endif
2549
2742
 
2550
2743
 
2551
- #endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */
2744
+ #endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */
2552
2745
 
2553
2746
  #ifndef UPB_MESSAGE_INTERNAL_MAP_H_
2554
2747
  #define UPB_MESSAGE_INTERNAL_MAP_H_
@@ -3010,96 +3203,6 @@ struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size);
3010
3203
 
3011
3204
  #endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */
3012
3205
 
3013
- /*
3014
- ** Our memory representation for parsing tables and messages themselves.
3015
- ** Functions in this file are used by generated code and possibly reflection.
3016
- **
3017
- ** The definitions in this file are internal to upb.
3018
- **/
3019
-
3020
- #ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_
3021
- #define UPB_MESSAGE_INTERNAL_MESSAGE_H_
3022
-
3023
- #include <stdlib.h>
3024
- #include <string.h>
3025
-
3026
-
3027
- // Must be last.
3028
-
3029
- #ifdef __cplusplus
3030
- extern "C" {
3031
- #endif
3032
-
3033
- extern const float kUpb_FltInfinity;
3034
- extern const double kUpb_Infinity;
3035
- extern const double kUpb_NaN;
3036
-
3037
- // Internal members of a upb_Message that track unknown fields and/or
3038
- // extensions. We can change this without breaking binary compatibility.
3039
-
3040
- typedef struct upb_Message_Internal {
3041
- // Total size of this structure, including the data that follows.
3042
- // Must be aligned to 8, which is alignof(upb_Extension)
3043
- uint32_t size;
3044
-
3045
- /* Offsets relative to the beginning of this structure.
3046
- *
3047
- * Unknown data grows forward from the beginning to unknown_end.
3048
- * Extension data grows backward from size to ext_begin.
3049
- * When the two meet, we're out of data and have to realloc.
3050
- *
3051
- * If we imagine that the final member of this struct is:
3052
- * char data[size - overhead]; // overhead = sizeof(upb_Message_Internal)
3053
- *
3054
- * Then we have:
3055
- * unknown data: data[0 .. (unknown_end - overhead)]
3056
- * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */
3057
- uint32_t unknown_end;
3058
- uint32_t ext_begin;
3059
- // Data follows, as if there were an array:
3060
- // char data[size - sizeof(upb_Message_Internal)];
3061
- } upb_Message_Internal;
3062
-
3063
- #ifdef UPB_TRACING_ENABLED
3064
- UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
3065
- const upb_Arena* arena);
3066
- UPB_API void upb_Message_SetNewMessageTraceHandler(
3067
- void (*handler)(const upb_MiniTable*, const upb_Arena*));
3068
- #endif // UPB_TRACING_ENABLED
3069
-
3070
- // Inline version upb_Message_New(), for internal use.
3071
- UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* m,
3072
- upb_Arena* a) {
3073
- #ifdef UPB_TRACING_ENABLED
3074
- upb_Message_LogNewMessage(m, a);
3075
- #endif // UPB_TRACING_ENABLED
3076
-
3077
- const int size = m->UPB_PRIVATE(size);
3078
- struct upb_Message* msg = (struct upb_Message*)upb_Arena_Malloc(a, size);
3079
- if (UPB_UNLIKELY(!msg)) return NULL;
3080
- memset(msg, 0, size);
3081
- return msg;
3082
- }
3083
-
3084
- // Discards the unknown fields for this message only.
3085
- void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg);
3086
-
3087
- // Adds unknown data (serialized protobuf data) to the given message.
3088
- // The data is copied into the message instance.
3089
- bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
3090
- const char* data, size_t len,
3091
- upb_Arena* arena);
3092
-
3093
- bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
3094
- upb_Arena* arena);
3095
-
3096
- #ifdef __cplusplus
3097
- } /* extern "C" */
3098
- #endif
3099
-
3100
-
3101
- #endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */
3102
-
3103
3206
  #ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
3104
3207
  #define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
3105
3208
 
@@ -3147,56 +3250,6 @@ UPB_INLINE struct upb_Message* UPB_PRIVATE(
3147
3250
 
3148
3251
  #endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */
3149
3252
 
3150
- #ifndef UPB_MESSAGE_INTERNAL_TYPES_H_
3151
- #define UPB_MESSAGE_INTERNAL_TYPES_H_
3152
-
3153
- #include <stdint.h>
3154
-
3155
- // Must be last.
3156
-
3157
- #define UPB_OPAQUE(x) x##_opaque
3158
-
3159
- struct upb_Message {
3160
- union {
3161
- uintptr_t UPB_OPAQUE(internal); // tagged pointer, low bit == frozen
3162
- double d; // Forces same size for 32-bit/64-bit builds
3163
- };
3164
- };
3165
-
3166
- #ifdef __cplusplus
3167
- extern "C" {
3168
- #endif
3169
-
3170
- UPB_INLINE void UPB_PRIVATE(_upb_Message_ShallowFreeze)(
3171
- struct upb_Message* msg) {
3172
- msg->UPB_OPAQUE(internal) |= 1ULL;
3173
- }
3174
-
3175
- UPB_API_INLINE bool upb_Message_IsFrozen(const struct upb_Message* msg) {
3176
- return (msg->UPB_OPAQUE(internal) & 1ULL) != 0;
3177
- }
3178
-
3179
- UPB_INLINE struct upb_Message_Internal* UPB_PRIVATE(_upb_Message_GetInternal)(
3180
- const struct upb_Message* msg) {
3181
- const uintptr_t tmp = msg->UPB_OPAQUE(internal) & ~1ULL;
3182
- return (struct upb_Message_Internal*)tmp;
3183
- }
3184
-
3185
- UPB_INLINE void UPB_PRIVATE(_upb_Message_SetInternal)(
3186
- struct upb_Message* msg, struct upb_Message_Internal* internal) {
3187
- UPB_ASSERT(!upb_Message_IsFrozen(msg));
3188
- msg->UPB_OPAQUE(internal) = (uintptr_t)internal;
3189
- }
3190
-
3191
- #ifdef __cplusplus
3192
- } /* extern "C" */
3193
- #endif
3194
-
3195
- #undef UPB_OPAQUE
3196
-
3197
-
3198
- #endif /* UPB_MESSAGE_INTERNAL_TYPES_H_ */
3199
-
3200
3253
  // Must be last.
3201
3254
 
3202
3255
  #if defined(__GNUC__) && !defined(__clang__)
@@ -4203,57 +4256,6 @@ UPB_API_INLINE bool upb_Map_IsFrozen(const upb_Map* map);
4203
4256
 
4204
4257
  #endif /* UPB_MESSAGE_MAP_H_ */
4205
4258
 
4206
- // Public APIs for message operations that do not depend on the schema.
4207
- //
4208
- // MiniTable-based accessors live in accessors.h.
4209
-
4210
- #ifndef UPB_MESSAGE_MESSAGE_H_
4211
- #define UPB_MESSAGE_MESSAGE_H_
4212
-
4213
- #include <stddef.h>
4214
-
4215
-
4216
- // Must be last.
4217
-
4218
- typedef struct upb_Message upb_Message;
4219
-
4220
- #ifdef __cplusplus
4221
- extern "C" {
4222
- #endif
4223
-
4224
- // Creates a new message with the given mini_table on the given arena.
4225
- UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena);
4226
-
4227
- // Returns a reference to the message's unknown data.
4228
- const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len);
4229
-
4230
- // Removes partial unknown data from message.
4231
- void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len);
4232
-
4233
- // Returns the number of extensions present in this message.
4234
- size_t upb_Message_ExtensionCount(const upb_Message* msg);
4235
-
4236
- // Mark a message and all of its descendents as frozen/immutable.
4237
- UPB_API void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m);
4238
-
4239
- // Returns whether a message has been frozen.
4240
- UPB_API_INLINE bool upb_Message_IsFrozen(const upb_Message* msg);
4241
-
4242
- #ifdef UPB_TRACING_ENABLED
4243
- UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
4244
- const upb_Arena* arena);
4245
-
4246
- UPB_API void upb_Message_SetNewMessageTraceHandler(
4247
- void (*handler)(const upb_MiniTable* m, const upb_Arena* arena));
4248
- #endif // UPB_TRACING_ENABLED
4249
-
4250
- #ifdef __cplusplus
4251
- } /* extern "C" */
4252
- #endif
4253
-
4254
-
4255
- #endif /* UPB_MESSAGE_MESSAGE_H_ */
4256
-
4257
4259
  #ifndef UPB_MINI_TABLE_TAGGED_PTR_H_
4258
4260
  #define UPB_MINI_TABLE_TAGGED_PTR_H_
4259
4261
 
@@ -13019,9 +13021,27 @@ extern "C" {
13019
13021
 
13020
13022
  enum { upb_JsonDecode_IgnoreUnknown = 1 };
13021
13023
 
13022
- UPB_API bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg,
13023
- const upb_MessageDef* m, const upb_DefPool* symtab,
13024
- int options, upb_Arena* arena, upb_Status* status);
13024
+ enum {
13025
+ kUpb_JsonDecodeResult_Ok = 0,
13026
+ kUpb_JsonDecodeResult_OkWithEmptyStringNumerics = 1,
13027
+ kUpb_JsonDecodeResult_Error = 2,
13028
+ };
13029
+
13030
+ UPB_API int upb_JsonDecodeDetectingNonconformance(const char* buf, size_t size,
13031
+ upb_Message* msg,
13032
+ const upb_MessageDef* m,
13033
+ const upb_DefPool* symtab,
13034
+ int options, upb_Arena* arena,
13035
+ upb_Status* status);
13036
+
13037
+ UPB_API_INLINE bool upb_JsonDecode(const char* buf, size_t size,
13038
+ upb_Message* msg, const upb_MessageDef* m,
13039
+ const upb_DefPool* symtab, int options,
13040
+ upb_Arena* arena, upb_Status* status) {
13041
+ return upb_JsonDecodeDetectingNonconformance(buf, size, msg, m, symtab,
13042
+ options, arena, status) ==
13043
+ kUpb_JsonDecodeResult_Ok;
13044
+ }
13025
13045
 
13026
13046
  #ifdef __cplusplus
13027
13047
  } /* extern "C" */