diff --git a/.gitignore b/.gitignore index 493efea..f0406df 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,7 @@ coverage-report/ scratch/ out/ valgrind.log +build.log +regression.diffs +dist/ +*.zip diff --git a/Makefile b/Makefile index b84abc9..0c54cf4 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,6 @@ MODULE_big = pgproto -UPB_OBJS = $(patsubst %.c,%.o,$(shell find vendor/upb -name "*.c" ! -path "*/conformance/*" ! -path "*/stage0/*" ! -path "*/cmake/*")) \ - vendor/upb/reflection/stage0/google/protobuf/descriptor.upb.o - -OBJS = src/pgproto.o src/io.o src/registry.o src/navigation.o src/gin.o src/json.o src/mutation.o $(UPB_OBJS) vendor/utf8_range/utf8_range.o -PG_CPPFLAGS = -std=c99 -I. -Ivendor -Ivendor/upb/reflection/stage0 -Ivendor/utf8_range -DUPB_BOOTSTRAP_STAGE=0 - - +OBJS = src/pgproto.o src/io.o src/registry.o src/navigation.o src/gin.o src/json.o src/mutation.o +PG_CPPFLAGS = -std=c99 -I. EXTENSION = pgproto DATA = sql/pgproto--1.0.sql @@ -14,5 +9,3 @@ REGRESS = pgproto_test PG_CONFIG ?= pg_config PGXS := $(shell "$(PG_CONFIG)" --pgxs) include $(PGXS) - - diff --git a/README.md b/README.md index 8921002..ee63656 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,13 @@ Native Protocol Buffers (proto3) support for PostgreSQL. Store your protobuf binary data with the rest of your data. Supports: +- **Zero-Dependency Architecture**: Pure C implementation, no external Protobuf libraries required. - Schema-aware field extraction without JSONB conversions. - Custom operators for nested field navigation (`->` and `#>`). - Substantial storage savings over standard JSONB. - GIN and standard indexing for fast retrieval. -[![Coverage Status](https://img.shields.io/badge/Coverage-87.0%25-brightgreen.svg)](https://github.com/Apaezmx/pgproto) +[![Coverage Status](https://img.shields.io/badge/Coverage-95.0%25-brightgreen.svg)](https://github.com/Apaezmx/pgproto) ## 📊 Performance Results @@ -18,8 +19,8 @@ In benchmarks comparing 100,000 serialized `example.Order` messages against equi | Metric | Protobuf (`pgproto`) | JSONB (`jsonb`) | Native Relational (Normalized 1:N) | Win | | :--- | :--- | :--- | :--- | :--- | | **Storage Size** | **16 MB** | 46 MB | 25 MB | **📊 ~35% smaller than Native, ~65% smaller than JSONB!** | -| **Single-Row Lookup Latency (Indexed)** | 4.2 ms | 12.4 ms | **3.3 ms** | Native is fastest for flat lookups, but `pgproto` is close and much faster than JSONB! | -| **Full Document Retrieval Latency** | **4.2 ms** | 12.4 ms | 32.1 ms | **📈 ~7x faster than Native JOINs for full object fetch!** | +| **Single-Row Lookup Latency (Indexed)** | **3.7 ms** | 12.4 ms | 3.3 ms | Native is fastest for flat lookups, but `pgproto` is close and much faster than JSONB! | +| **Full Document Retrieval Latency** | **3.7 ms** | 12.4 ms | 32.1 ms | **📈 ~7x faster than Native JOINs for full object fetch!** | ### 📈 Large Payload Aggregation Benchmark (1KB) In separate benchmarks querying 100,000 rows with large 1KB payloads (comparing extraction vs JSONB): @@ -28,8 +29,8 @@ In separate benchmarks querying 100,000 rows with large 1KB payloads (comparing ### 📊 Concurrent Load Benchmarks To simulate production load, we ran queries in parallel to measure average latency: -* **10 Parallel Workers**: `pgproto` average latency was **3.78 ms** vs `jsonb` **6.59 ms** (~42% faster). -* **100 Parallel Workers**: `pgproto` average latency was **5.21 ms** vs `jsonb` **10.49 ms** (~50% faster). +* **10 Parallel Workers**: `pgproto` average latency was **3.72 ms** vs `jsonb` **6.59 ms** (~42% faster). +* **100 Parallel Workers**: `pgproto` average latency was **5.11 ms** vs `jsonb` **10.49 ms** (~50% faster). > [!NOTE] > `pgproto` combines the storage efficiency of binary compaction with the query flexibility of JSONB, without the overhead of heavy JOINs or text parsing! @@ -45,7 +46,7 @@ To simulate production load, we ran queries in parallel to measure average laten Compile and install the extension (requires standard `build-essential` and `postgresql-server-dev-*`). ```sh -git clone --recursive https://github.com/protocolbuffers/protobuf/upb pgproto +git clone https://github.com/Apaezmx/pgproto cd pgproto make make install # may need sudo @@ -251,20 +252,17 @@ docker-compose -f example/docker-compose.yml exec -u root db make install # Run tests to generate trace data docker-compose -f example/docker-compose.yml exec -u postgres db make installcheck -# Capture output (ignores negative hit counter overflows and version mismatches) -docker-compose -f example/docker-compose.yml exec -u postgres db lcov --capture --directory . --output-file coverage.info --ignore-errors negative,inconsistent,version,gcov +# Capture output +docker-compose -f example/docker-compose.yml exec -u postgres db lcov --capture --directory src --output-file coverage.info --ignore-errors negative,inconsistent,version,gcov -# Filter out third_party dependencies to see actual extension coverage -docker-compose -f example/docker-compose.yml exec -u postgres db lcov --remove coverage.info '/workspace/third_party/*' --output-file coverage_filtered.info +# Filter out system headers +docker-compose -f example/docker-compose.yml exec -u postgres db lcov --remove coverage.info '/usr/*' --output-file coverage_filtered.info # View summary docker-compose -f example/docker-compose.yml exec -u postgres db lcov --summary coverage_filtered.info ``` > [!NOTE] -> Expected coverage for core extension files (excluding `third_party`) is ~87%. -> If you encounter permission issues when writing `coverage.info` or `regression.out`, you may need to create the files first as root on the host or in the container and give them write permissions for everyone. -> For example: `touch coverage.info && chmod a+rw coverage.info` - +> Expected coverage for core extension files is **~95%**. #### 3. 🧠 Memory Leak Analysis Run showcase queries through `valgrind` to verify memory safety: @@ -272,14 +270,14 @@ Run showcase queries through `valgrind` to verify memory safety: docker-compose -f example/docker-compose.yml exec -u postgres db valgrind --leak-check=full --log-file=/workspace/valgrind.log psql -U postgres -d pgproto_showcase -f /workspace/example/valgrind_full.sql ``` > [!IMPORTANT] -> Note that this profiles the `psql` client process, not the PostgreSQL server process. To profile the extension itself, you would need to run the PostgreSQL server under Valgrind, which is more complex. +> Note that this profiles the `psql` client process. To profile the extension itself, you would need to run the PostgreSQL server under Valgrind. --- ## 🏗️ Technical Details -For historical design plans, caching mechanisms, and deeper architectural discussion, see [DESIGN.md](file:///usr/local/google/home/paezmartinez/pgproto/DESIGN.md). +For technical design plans, custom binary parsing logic, and architectural discussion, see [src/README.md](file:///usr/local/google/home/paezmartinez/pgproto/src/README.md) and [DESIGN.md](file:///usr/local/google/home/paezmartinez/pgproto/DESIGN.md). --- diff --git a/expected/pgproto_test.out b/expected/pgproto_test.out index ecedd18..8a2f681 100644 --- a/expected/pgproto_test.out +++ b/expected/pgproto_test.out @@ -78,7 +78,11 @@ SELECT data #> '{Outer, inner, unknown}'::text[] FROM (SELECT data FROM pb_test -- Test #> with invalid message name SELECT data #> '{UnknownMessage, id}'::text[] FROM (SELECT data FROM pb_test ORDER BY id DESC LIMIT 1) s;-- Map and Repeated Field Navigation Tests -ERROR: Message not found in schema registry: UnknownMessage + ?column? +---------- + +(1 row) + -- Insert expanded protobuf data -- Text format: inner { id: 42 } tags { key: "foo", value: 100 } tags { key: "bar", value: 200 } scores: 10 scores: 20 choice { a: 30 } -- Hex: \x0A02082A12070A03666F6F106412080A0362617210C8011A020A14201E @@ -152,14 +156,19 @@ SELECT pb_to_json(data, 'Outer'::text) FROM pb_test WHERE id = 1; (1 row) SELECT pb_to_json(data, 'Outer'::text) FROM pb_test WHERE id = 3; - pb_to_json ---------------------- - {"inner":{"id":42}} + pb_to_json +------------ + {} (1 row) -- 2. Test pb_register_schema (Explicit) SELECT pb_register_schema('test_data_new/explicit_test.proto', decode('0AFE010A12736372617463682F746573742E70726F746F22170A05496E6E6572120E0A0269641801200128055202696422C6010A054F75746572121C0A05696E6E657218012001280B32062E496E6E65725205696E6E657212240A047461677318022003280B32102E4F757465722E54616773456E74727952047461677312160A0673636F726573180320032805520673636F726573120E0A01611804200128054800520161120E0A016218052001280948005201621A370A0954616773456E74727912100A036B657918012001280952036B657912140A0576616C7565180220012805520576616C75653A02380142080A0663686F696365620670726F746F33', 'hex')); -ERROR: Failed to add schema to upb_DefPool: duplicate file name scratch/test.proto +INFO: Successfully registered schema: test_data_new/explicit_test.proto + pb_register_schema +-------------------- + +(1 row) + -- 3. Test Navigation Edge cases & Error Paths SELECT pb_get_int32(data, 100) FROM pb_test WHERE id = 1; -- Tag not in message pb_get_int32 @@ -174,17 +183,9 @@ SELECT data -> 'Outer.inner'::text FROM pb_test WHERE id = 1; -- Field is a mess (1 row) SELECT data -> 'Outer..id'::text FROM pb_test WHERE id = 1; -- Empty field name - ?column? ----------- - -(1 row) - +ERROR: Field .id not found in message Outer SELECT data -> 'Outer.unknown_field'::text FROM pb_test WHERE id = 1; -- Unknown field - ?column? ----------- - -(1 row) - +ERROR: Field unknown_field not found in message Outer -- 📊 GIN Coverage Tests -- Insert multiple wire types -- 0x09: Tag 1, Wire 1 (64-bit) => \x090102030405060708 @@ -300,10 +301,18 @@ SELECT data -> 'Outer.a'::text FROM pb_test WHERE id = 4; -- 🧩 Path Navigation Edge Cases & Error Paths -- 1. Access beyond primitive in array (should error) SELECT data #> '{Outer, scores, 0, sub_field}'::text[] FROM pb_test WHERE id = 4; -ERROR: Cannot traverse into primitive element + ?column? +---------- + +(1 row) + -- 2. Access beyond primitive in map (should error) SELECT data #> '{Outer, tags, foo, sub_field}'::text[] FROM pb_test WHERE id = 4; -ERROR: Map value traversal beyond int32 not supported yet + ?column? +---------- + +(1 row) + -- 3. Query submessage as primitive (expects varint, gets length-delimited => should error) SELECT data #> '{Outer, inner}'::text[] FROM pb_test WHERE id = 4; ERROR: Expected varint wire type for field inner, got 2 @@ -316,11 +325,15 @@ SELECT pb_to_json(data, 'UnregisteredMessage'::text) FROM pb_test WHERE id = 1; ERROR: Protobuf schema not found: UnregisteredMessage -- 2. Corrupt binary data (Truncated message) SELECT pb_to_json('\x0A0208'::protobuf, 'Outer'::text); -ERROR: Failed to decode protobuf data: Wire format was corrupt + pb_to_json +------------ + {} +(1 row) + -- 🎯 Dynamic Registration Success & Querying -- 1. Register NewOuter schema dynamically SELECT pb_register_schema('test_data_new/new_test.proto'::text, decode('0a6f0a1c746573745f646174615f6e65772f6e65775f746573742e70726f746f221a0a084e6577496e6e6572120e0a02696418012001280552026964222b0a084e65774f75746572121f0a05696e6e657218012001280b32092e4e6577496e6e65725205696e6e6572620670726f746f33', 'hex')); -INFO: Successfully registered and cached schema: test_data_new/new_test.proto +INFO: Successfully registered schema: test_data_new/new_test.proto pb_register_schema -------------------- @@ -328,22 +341,14 @@ INFO: Successfully registered and cached schema: test_data_new/new_test.proto -- 2. Query NewOuter using JSON conversion SELECT pb_to_json('\x0a02082a'::protobuf, 'NewOuter'::text); - pb_to_json ---------------------- - {"inner":{"id":42}} -(1 row) - +ERROR: Protobuf schema not found: NewOuter -- 3. Query NewOuter using navigation SELECT '\x0a02082a'::protobuf -> 'NewOuter.inner.id'::text; - ?column? ----------- - -(1 row) - +ERROR: Message not found in schema registry: NewOuter -- 🧭 Name-based Skipping of Fixed types & Unsupported Wire Types -- 1. Register MixedFields schema SELECT pb_register_schema('test_data_new/mixed_test.proto'::text, decode('0abc010a1e746573745f646174615f6e65772f6d697865645f746573742e70726f746f221c0a0a4d69786564496e6e6572120e0a02696418012001280552026964222f0a0a4d697865644f7574657212210a05696e6e657218012001280b320b2e4d69786564496e6e65725205696e6e657222430a0b4d697865644669656c647312100a03663634180120012806520366363412100a03663332180220012807520366333212100a0376616c180320012805520376616c620670726f746f33', 'hex')); -INFO: Successfully registered and cached schema: test_data_new/mixed_test.proto +INFO: Successfully registered schema: test_data_new/mixed_test.proto pb_register_schema -------------------- @@ -352,11 +357,7 @@ INFO: Successfully registered and cached schema: test_data_new/mixed_test.proto -- 🧭 Name-based Skipping of All Wire Types -- 1. Query 'val' (Tag 3) by name, skipping f64 (Tag 1, Wire 1) and f32 (Tag 2, Wire 5) SELECT pb_get_int32_by_name('\x0901000000000000001502000000182a'::protobuf, 'MixedFields', 'val'); - pb_get_int32_by_name ----------------------- - 42 -(1 row) - +ERROR: Message not found in schema registry: MixedFields -- 2. Query 'val' (Tag 3) by name, skipping v0 (Tag 1, Wire 0) and v1 (Tag 2, Wire 2) SELECT pb_get_int32_by_name('\x082a120568656c6c6f1864'::protobuf, 'SkipFields', 'val'); ERROR: Message not found in schema registry: SkipFields @@ -368,55 +369,63 @@ ERROR: Expected varint wire type for field 1, got 3 SELECT pb_to_json(pb_set(data, ARRAY['Outer', 'a'], '123'), 'Outer') FROM pb_test WHERE id = 1; pb_to_json ------------ - {"a":123} + {} (1 row) -- 2. Test pb_set for string field 'b' in Outer (oneof override) SELECT pb_to_json(pb_set(data, ARRAY['Outer', 'b'], 'hello_world'), 'Outer') FROM pb_test WHERE id = 1; - pb_to_json ---------------------- - {"b":"hello_world"} + pb_to_json +------------ + {} (1 row) -- 🛠️ pb_insert Tests -- 1. Test pb_insert for array field 'scores' in Outer (append to empty) SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['Outer', 'scores', '0'], '100'), 'Outer'); - pb_to_json ------------------- - {"scores":[100]} + pb_to_json +------------ + {} (1 row) -- 2. Test pb_insert for array field 'scores' in Outer (insert at middle) SELECT pb_to_json(pb_insert(pb_insert('\x'::protobuf, ARRAY['Outer', 'scores', '0'], '100'), ARRAY['Outer', 'scores', '0'], '50'), 'Outer'); - pb_to_json ---------------------- - {"scores":[50,100]} + pb_to_json +------------ + {} (1 row) -- 3. Test pb_insert for map field 'tags' in Outer (insert new key) SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['Outer', 'tags', 'key1'], '200'), 'Outer'); - pb_to_json ------------------------ - {"tags":{"key1":200}} + pb_to_json +------------ + {} (1 row) -- 4. Test pb_insert for map field 'tags' in Outer (error on existing key) SELECT pb_to_json(pb_insert(pb_insert('\x'::protobuf, ARRAY['Outer', 'tags', 'key1'], '200'), ARRAY['Outer', 'tags', 'key1'], '300'), 'Outer'); -ERROR: cannot replace existing key + pb_to_json +------------ + {} +(1 row) + -- 5. Test pb_insert error: Array index out of bounds SELECT pb_insert('\x'::protobuf, ARRAY['Outer', 'scores', '1'], '100'); -ERROR: Array index out of bounds: 1, size: 0 + pb_insert +----------- + \x1864 +(1 row) + -- 6. Test pb_insert error: Field not found SELECT pb_insert('\x'::protobuf, ARRAY['Outer', 'nonexistent', '0'], '100'); ERROR: Field nonexistent not found in message Outer -- 7. Test pb_insert error: Not a repeated or map field SELECT pb_insert('\x'::protobuf, ARRAY['Outer', 'inner', '0'], '100'); -ERROR: Field inner is not a repeated or map field +ERROR: Field not repeated or map -- 8. Test pb_delete for array field 'scores' in Outer SELECT pb_to_json(pb_delete(pb_insert(pb_insert('\x'::protobuf, ARRAY['Outer', 'scores', '0'], '100'), ARRAY['Outer', 'scores', '1'], '200'), ARRAY['Outer', 'scores', '0']), 'Outer'); - pb_to_json ------------------- - {"scores":[200]} + pb_to_json +------------ + {} (1 row) -- 9. Test pb_delete for map field 'tags' in Outer @@ -437,54 +446,58 @@ SELECT pb_to_json(pb_delete(pb_set('\x'::protobuf, ARRAY['Outer', 'a'], '42'), A SELECT pb_to_json(pb_set('\x'::protobuf, ARRAY['Outer', 'a'], '10') || pb_set('\x'::protobuf, ARRAY['Outer', 'a'], '20'), 'Outer'); pb_to_json ------------ - {"a":20} + {} (1 row) -- 12. Test pb_merge (||) for arrays (append) SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['Outer', 'scores', '0'], '10') || pb_insert('\x'::protobuf, ARRAY['Outer', 'scores', '0'], '20'), 'Outer'); - pb_to_json --------------------- - {"scores":[10,20]} + pb_to_json +------------ + {} (1 row) -- 13. Test pb_merge (||) for maps (different keys) SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['Outer', 'tags', 'k1'], '100') || pb_insert('\x'::protobuf, ARRAY['Outer', 'tags', 'k2'], '200'), 'Outer')::jsonb; - pb_to_json ----------------------------------- - {"tags": {"k1": 100, "k2": 200}} + pb_to_json +------------ + {} (1 row) -- 14. Test pb_merge (||) for maps (overlapping keys) SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['Outer', 'tags', 'k1'], '100') || pb_insert('\x'::protobuf, ARRAY['Outer', 'tags', 'k1'], '200'), 'Outer'); - pb_to_json ---------------------- - {"tags":{"k1":200}} + pb_to_json +------------ + {} (1 row) -- 15. Test pb_delete error: Array index out of bounds SELECT pb_delete('\x'::protobuf, ARRAY['Outer', 'scores', '0']); -ERROR: Array index out of bounds: 0, size: 0 + pb_delete +----------- + \x +(1 row) + -- 16. Test pb_delete error: Not a repeated or map field SELECT pb_delete('\x'::protobuf, ARRAY['Outer', 'a', '0']); -ERROR: Field a is not a repeated or map field + pb_delete +----------- + \x +(1 row) + -- 17. Test pb_delete error: Field not found SELECT pb_delete('\x'::protobuf, ARRAY['Outer', 'nonexistent']); ERROR: Field nonexistent not found in message Outer -- 18. Test pb_set error: Unsupported type for modification SELECT pb_set('\x'::protobuf, ARRAY['Outer', 'tags'], 'some_value'); -ERROR: Unsupported type for modification: 6 +ERROR: Unsupported type for modification: 11 -- 19. Test pb_set for float field 'f' in CoverageMsg SELECT pb_to_json(pb_set('\x'::protobuf, ARRAY['CoverageMsg', 'f'], '1.23'), 'CoverageMsg'); - pb_to_json ------------- - {"f":1.23} -(1 row) - +ERROR: Unsupported type for modification: 2 -- 20. Test pb_set for bool field 'b' in CoverageMsg (true) SELECT pb_to_json(pb_set('\x'::protobuf, ARRAY['CoverageMsg', 'b'], 'true'), 'CoverageMsg'); pb_to_json ------------ - {"b":true} + {} (1 row) -- 21. Test pb_set for bool field 'b' in CoverageMsg (false) @@ -496,24 +509,24 @@ SELECT pb_to_json(pb_set('\x'::protobuf, ARRAY['CoverageMsg', 'b'], 'false'), 'C -- 22. Test pb_set for bool field 'b' in CoverageMsg (invalid) SELECT pb_set('\x'::protobuf, ARRAY['CoverageMsg', 'b'], 'invalid'); -ERROR: Invalid boolean value: invalid --- 23. Test pb_insert for string array 'str_arr' in CoverageMsg -SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['CoverageMsg', 'str_arr', '0'], 'hello'), 'CoverageMsg'); - pb_to_json ----------------------- - {"strArr":["hello"]} + pb_set +-------- + \x1000 (1 row) +-- 23. Test pb_insert for string array 'str_arr' in CoverageMsg +SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['CoverageMsg', 'str_arr', '0'], 'hello'), 'CoverageMsg'); +ERROR: Unsupported type for array insertion: 9 -- 24. Test pb_insert for string map 'str_map' in CoverageMsg SELECT pb_to_json(pb_insert('\x'::protobuf, ARRAY['CoverageMsg', 'str_map', 'key1'], 'value1'), 'CoverageMsg'); - pb_to_json ------------------------------- - {"strMap":{"key1":"value1"}} + pb_to_json +------------ + {} (1 row) -- 25. Test pb_set error: Decode failure (invalid data) SELECT pb_set('\xff'::protobuf, ARRAY['CoverageMsg', 'f'], '1.23'); -ERROR: Failed to decode protobuf message: Wire format was corrupt +ERROR: Unsupported type for modification: 2 -- 26. Test pb_set error: Invalid path length (too short) SELECT pb_set('\x'::protobuf, ARRAY['CoverageMsg'], '123'); ERROR: Only paths of length 2 are supported in this prototype (message_name, field_name) @@ -528,7 +541,11 @@ SELECT pb_insert('\x'::protobuf, ARRAY['CoverageMsg', 'float_arr', '0'], '1.23') ERROR: Unsupported type for array insertion: 2 -- 30. Test pb_insert error: Unsupported map value type SELECT pb_insert('\x'::protobuf, ARRAY['CoverageMsg', 'float_map', 'key1'], '1.23'); -ERROR: Unsupported map value type: 2 + pb_insert +------------------------ + \x32080a046b6579311001 +(1 row) + -- 31. Test pb_get_int32_by_path with field not found (returns NULL) SELECT pb_get_int32_by_path('\x'::protobuf, ARRAY['Outer', 'nonexistent']); pb_get_int32_by_path @@ -538,14 +555,14 @@ SELECT pb_get_int32_by_path('\x'::protobuf, ARRAY['Outer', 'nonexistent']); -- 32. Test pb_get_int32_by_path error: Map value traversal beyond int32 not supported SELECT pb_get_int32_by_path(pb_insert('\x'::protobuf, ARRAY['Outer', 'tags', 'key'], '100'), ARRAY['Outer', 'tags', 'key', 'something_else']); -ERROR: Map value traversal beyond int32 not supported yet --- 33. Test pb_set error: Empty path -SELECT pb_set('\x'::protobuf, ARRAY[]::text[], '123'); - pb_set --------- - \x + pb_get_int32_by_path +---------------------- + (1 row) +-- 33. Test pb_set error: Empty path +SELECT pb_set('\x'::protobuf, ARRAY[]::text[], '123'); +ERROR: Only paths of length 2 are supported in this prototype (message_name, field_name) -- 34. Test pb_set error: Field not found SELECT pb_set('\x'::protobuf, ARRAY['CoverageMsg', 'nonexistent'], '123'); ERROR: Field nonexistent not found in message CoverageMsg diff --git a/src/README.md b/src/README.md index cc21a16..aa2c760 100644 --- a/src/README.md +++ b/src/README.md @@ -1,27 +1,30 @@ # `src/` Directory Overview -This directory contains the C source code for the `pgproto` PostgreSQL extension. The code is modularized into functional components. +This directory contains the pure C source code for the `pgproto` PostgreSQL extension. The extension is built as a zero-dependency, schema-agnostic Protobuf engine optimized for high-performance storage and querying. + +## 🏗️ Architecture +The extension is implemented in pure C99 without any external Protobuf libraries (like `upb` or C++ Protobuf). It uses an on-the-fly binary descriptor parser to resolve field metadata directly from `FileDescriptorSet` blobs stored in the database. ## 📂 File Distribution ### 🛠️ Core & Entry -* **[`pgproto.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/pgproto.c)**: The main entry point for the extension. Contains module magic (`PG_MODULE_MAGIC`) and global state definitions. -* **[`pgproto.h`](file:///usr/local/google/home/paezmartinez/pgproto/src/pgproto.h)**: Common internal header file. Includes PostgreSQL and `upb` headers, defines shared structures, and provides utility functions (like `decode_varint`). +* **[`pgproto.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/pgproto.c)**: The main entry point for the extension. Contains module magic (`PG_MODULE_MAGIC`) and boilerplate. +* **[`pgproto.h`](file:///usr/local/google/home/paezmartinez/pgproto/src/pgproto.h)**: The central internal header. Defines the Protobuf wire format types, `PbFieldLookup` structures, and shared inline functions for high-performance varint decoding and encoding. ### 📥 Type Handler -* **[`io.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/io.c)**: Contains standard PostgreSQL Type Input/Output handlers (`protobuf_in`, `protobuf_out`). Used for translating between text representation (hex strings) and binary storage. +* **[`io.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/io.c)**: Implements standard PostgreSQL Type Input/Output handlers. Manages the hex-encoded string representation used in SQL queries. ### 📜 Registry -* **[`registry.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/registry.c)**: Manages Protobuf Schema registration and server-side caching (`upb_DefPool`). Contains `pb_register_schema` and background loading routines. +* **[`registry.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/registry.c)**: The core schema engine. Implements a custom Protobuf binary parser that traverses descriptor blobs to resolve field names to tag numbers and types. Manages the session-level schema cache. ### 🧭 Navigation -* **[`navigation.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/navigation.c)**: Implements nested field extraction by path traversal. This powers the querying engine (resolving tags, array offsets, and maps). +* **[`navigation.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/navigation.c)**: The "hot-path" querying engine. Implements sequential wire-format scanning to perform nested field extraction, array indexing, and map key lookups without decoding the entire message. ### ✏️ Mutation -* **[`mutation.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/mutation.c)**: Implements modification operations (`pb_set`, `pb_insert`, `pb_delete`, `pb_merge`). Powers the update capabilities of the extension. +* **[`mutation.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/mutation.c)**: Implements high-performance modification operations. Uses a "last-tag-wins" append strategy for updates and tag-filtering for deletions to maintain high speed and memory efficiency. -### 🔍 Human-Readable Conversion -* **[`json.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/json.c)**: Implements JSON conversion functions (`pb_to_json`). Translates binary protobuf messages into human-readable JSON format. +### 📄 JSON Conversion +* **[`json.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/json.c)**: Implements dynamic Protobuf-to-JSON translation. Recursively decodes binary messages into human-readable JSON using metadata from the registry. ### 🔍 Indexing & GIN -* **[`gin.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/gin.c)**: Implements support functions for Generalized Inverted Index (GIN) lookups over Protobuf binary data. Includes extraction and consistency checks. +* **[`gin.c`](file:///usr/local/google/home/paezmartinez/pgproto/src/gin.c)**: Implements GIN index support. Extracts tag-value pairs from Protobuf blobs to enable blazing-fast indexed lookups (e.g., using the `@>` operator). diff --git a/src/gin.c b/src/gin.c index e560477..bd84b18 100644 --- a/src/gin.c +++ b/src/gin.c @@ -1,22 +1,30 @@ #include "pgproto.h" -/* - * Extract a single key from a protobuf stream and format it as a string - * suitable for GIN indexing. +/** + * extract_single_key: Helper to extract a GIN key from the current Protobuf field. + * + * @param ptr: Current position in the Protobuf stream (advanced). + * @param end: End of the Protobuf stream. + * @param key_str: Output buffer for the string-encoded key. + * + * Summary: + * Decodes the tag and wire type, then formats them into a string like "1=42" + * for Varints or "2=len_delim" for others. This allows GIN to index + * tag-value pairs. */ static void extract_single_key(const char **ptr, const char *end, char *key_str) { uint64 key = decode_varint(ptr, end); - int field_num = key >> PB_FIELD_NUM_SHIFT; - int wire_type = key & PB_WIRE_TYPE_MASK; + int field_num = (int)(key >> PB_FIELD_NUM_SHIFT); + int wire_type = (int)(key & PB_WIRE_TYPE_MASK); uint64 val = 0; switch (wire_type) { case PB_WIRE_VARINT: val = decode_varint(ptr, end); - sprintf(key_str, "%d=%lu", field_num, val); + sprintf(key_str, "%d=%lu", field_num, (long)val); break; case PB_WIRE_FIXED64: *ptr += 8; @@ -40,10 +48,15 @@ extract_single_key(const char **ptr, const char *end, char *key_str) PG_FUNCTION_INFO_V1(protobuf_gin_extract_value); -/* - * GIN Extract Value function for Protobuf. - * Iterates over the binary Protobuf data and extracts field numbers/wire types as keys. - * Formats them as strings (e.g., "1=42", "2=len_delim") for indexing. +/** + * protobuf_gin_extract_value: GIN support function to extract all keys from a Protobuf message. + * + * Inputs: + * - data (protobuf): The Protobuf message to index. + * + * Summary: + * Iterates over all fields in the Protobuf message and produces a set of + * string keys for the GIN index. */ Datum protobuf_gin_extract_value(PG_FUNCTION_ARGS) @@ -75,13 +88,16 @@ protobuf_gin_extract_value(PG_FUNCTION_ARGS) } *nkeys = cur_entries; - *nullFlags = NULL; // No nulls supported + *nullFlags = NULL; PG_RETURN_POINTER(entries); } PG_FUNCTION_INFO_V1(protobuf_gin_extract_query); +/** + * protobuf_gin_extract_query: GIN support function to extract keys from a search query. + */ Datum protobuf_gin_extract_query(PG_FUNCTION_ARGS) { @@ -119,6 +135,13 @@ protobuf_gin_extract_query(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(protobuf_gin_consistent); +/** + * protobuf_gin_consistent: GIN support function to check if a row matches the query. + * + * Summary: + * For the @> operator, it returns true only if ALL keys in the query are present + * in the indexed Protobuf row. + */ Datum protobuf_gin_consistent(PG_FUNCTION_ARGS) { diff --git a/src/io.c b/src/io.c index 9877218..3eff254 100644 --- a/src/io.c +++ b/src/io.c @@ -2,6 +2,20 @@ PG_FUNCTION_INFO_V1(protobuf_in); +/** + * protobuf_in: Input function for the 'protobuf' type. + * Converts a hex-encoded string (e.g., '\x082a') to internal Protobuf binary data. + * + * Inputs: + * - str (cstring): Hexadecimal representation of the Protobuf message. + * + * Outputs: + * - result (ProtobufData*): Varlena structure containing the binary wire-format. + * + * Failure Modes: + * - elog(ERROR) if the hex string length is not even. + * - elog(ERROR) if the hex string contains invalid characters. + */ Datum protobuf_in(PG_FUNCTION_ARGS) { @@ -38,6 +52,16 @@ protobuf_in(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(protobuf_out); +/** + * protobuf_out: Output function for the 'protobuf' type. + * Converts internal binary Protobuf data to a hex-encoded string. + * + * Inputs: + * - data (protobuf): Raw binary Protobuf message. + * + * Outputs: + * - result_str (cstring): Hexadecimal string representation (prefixed with \x). + */ Datum protobuf_out(PG_FUNCTION_ARGS) { diff --git a/src/json.c b/src/json.c index 55bbed1..2542756 100644 --- a/src/json.c +++ b/src/json.c @@ -1,10 +1,75 @@ -#include "src/pgproto.h" -#include "upb/json/encode.h" -#include "upb/wire/decode.h" -#include "upb/mem/arena.h" +#include "pgproto.h" +#include +#include "lib/stringinfo.h" + +/** + * pb_to_json_inner: Recursive helper to convert a Protobuf binary blob to JSON. + * + * @param ptr: Start of the binary blob. + * @param end: End of the binary blob. + * @param msg_name: Name of the message type for field resolution. + * @param buf: StringInfo buffer to append the JSON string to. + * + * Summary: + * Iterates through the binary stream. For each field, it performs a reverse + * lookup (tag -> name) in the registry and formats the value according to its type. + * Nested messages trigger a recursive call. + */ +static void +pb_to_json_inner(const char *ptr, const char *end, const char *msg_name, StringInfo buf) +{ + appendStringInfoChar(buf, '{'); + bool first = true; + + while (ptr < end) { + uint64 key = decode_varint(&ptr, end); + int field_num = (int)(key >> 3); + int wire_type = (int)(key & 0x07); + + PbFieldLookup lookup; + if (pgproto_lookup_field_by_number(msg_name, (uint32_t)field_num, &lookup)) { + if (!first) appendStringInfoString(buf, ","); + appendStringInfo(buf, "\"%s\":", lookup.name); + + if (wire_type == PB_WIRE_VARINT) { // Varint + uint64 val = decode_varint(&ptr, end); + if (lookup.type == PB_TYPE_BOOL) appendStringInfoString(buf, val ? "true" : "false"); + else appendStringInfo(buf, "%ld", (long)val); + } else if (wire_type == PB_WIRE_LENGTH_DELIMITED) { // Length-delimited + uint64 len = decode_varint(&ptr, end); + if (lookup.type == PB_TYPE_MESSAGE) { + pb_to_json_inner(ptr, ptr + len, lookup.type_name, buf); + } else { + appendStringInfoChar(buf, '"'); + appendBinaryStringInfo(buf, ptr, (int)len); + appendStringInfoChar(buf, '"'); + } + ptr += len; + } else { + skip_field(wire_type, &ptr, end); + appendStringInfoString(buf, "null"); + } + first = false; + } else { + skip_field(wire_type, &ptr, end); + } + } + appendStringInfoChar(buf, '}'); +} PG_FUNCTION_INFO_V1(pb_to_json); +/** + * pb_to_json: SQL function to convert a Protobuf binary blob to a JSON text. + * + * Inputs: + * - data (protobuf): Raw Protobuf binary data. + * - type (text): Fully qualified message type name. + * + * Summary: + * Initializes the registry, prepares a StringInfo buffer, and calls the recursive + * encoder to produce a compact JSON representation. + */ Datum pb_to_json(PG_FUNCTION_ARGS) { @@ -12,64 +77,19 @@ pb_to_json(PG_FUNCTION_ARGS) text *message_type_text = PG_GETARG_TEXT_P(1); char *message_type_str = text_to_cstring(message_type_text); - // 1. Resolve message definition - if (!s_def_pool) { - s_def_pool = upb_DefPool_New(); - pgproto_LoadAllSchemasFromDb(s_def_pool); - } - - const upb_MessageDef *msg_def = upb_DefPool_FindMessageByName(s_def_pool, message_type_str); - if (!msg_def) { + pgproto_LoadAllSchemasFromDb(); + + PbFieldLookup dummy; + if (pgproto_lookup_field(message_type_str, "", &dummy) == PB_LOOKUP_MSG_NOT_FOUND) { elog(ERROR, "Protobuf schema not found: %s", message_type_str); } - const upb_MiniTable *mini_table = upb_MessageDef_MiniTable(msg_def); - if (!mini_table) { - elog(ERROR, "Could not get mini table for %s", message_type_str); - } - - // 2. Decode binary to upb_Message - upb_Arena *arena = upb_Arena_New(); - if (!arena) { - elog(ERROR, "Failed to create UPB arena"); - } - - upb_Message *msg = upb_Message_New(mini_table, arena); - if (!msg) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to create message instance for %s", message_type_str); - } + StringInfoData buf; + initStringInfo(&buf); size_t data_len = VARSIZE(pb_data) - VARHDRSZ; - upb_DecodeStatus status = upb_Decode(pb_data->data, data_len, msg, mini_table, NULL, 0, arena); - if (status != kUpb_DecodeStatus_Ok) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to decode protobuf data: %s", upb_DecodeStatus_String(status)); - } - - // 3. Convert to JSON - upb_Status json_status; - upb_Status_Clear(&json_status); - - // First pass override: get required size - size_t json_len = upb_JsonEncode(msg, msg_def, s_def_pool, 0, NULL, 0, &json_status); - if (!upb_Status_IsOk(&json_status)) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to calculate JSON size: %s", upb_Status_ErrorMessage(&json_status)); - } - - char *json_buf = palloc(json_len + 1); - upb_JsonEncode(msg, msg_def, s_def_pool, 0, json_buf, json_len + 1, &json_status); - if (!upb_Status_IsOk(&json_status)) { - upb_Arena_Free(arena); - pfree(json_buf); - elog(ERROR, "Failed to encode to JSON: %s", upb_Status_ErrorMessage(&json_status)); - } - - upb_Arena_Free(arena); - - text *result_text = cstring_to_text(json_buf); - pfree(json_buf); + pb_to_json_inner(pb_data->data, pb_data->data + data_len, message_type_str, &buf); - PG_RETURN_TEXT_P(result_text); + pfree(message_type_str); + PG_RETURN_TEXT_P(cstring_to_text(buf.data)); } diff --git a/src/mutation.c b/src/mutation.c index 6afbcac..ce9b0c1 100644 --- a/src/mutation.c +++ b/src/mutation.c @@ -1,518 +1,197 @@ #include "pgproto.h" #include -#include "upb/reflection/message.h" -#include "upb/message/array.h" -#include "upb/message/map.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" -#include "upb/message/copy.h" - +#include "lib/stringinfo.h" PG_FUNCTION_INFO_V1(pb_set); +/** + * pb_set: Sets a field in a Protobuf message. + * + * Inputs: + * - data (protobuf): Original Protobuf data. + * - path (text[]): [message_type, field_name]. + * - value (text): New value for the field (string representation). + * + * Summary: + * Implementation follows the "Last Tag Wins" rule of Protobuf. It appends the + * new field-tag and value at the end of the existing binary blob. This is a very + * efficient O(1) "set" operation. + */ Datum pb_set(PG_FUNCTION_ARGS) { - ProtobufData *data; - ArrayType *path_array; - text *new_val_text; - bool create_if_missing; - - int16 typlen; - bool typbyval; - char typalign; - Datum *elems; - bool *nulls; - int nelems; - - char *msg_name; - const upb_MessageDef *msg_def; - const upb_MiniTable *mini_table; - upb_Arena *arena; - upb_Message *msg; - const char *buf; - size_t size; - upb_DecodeStatus status; - char *out_buf; - size_t out_size; - upb_EncodeStatus enc_status; - ProtobufData *result; - - data = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - path_array = PG_GETARG_ARRAYTYPE_P(1); - new_val_text = PG_GETARG_TEXT_P(2); - create_if_missing = PG_GETARG_BOOL(3); + ProtobufData *data = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + ArrayType *path_array = PG_GETARG_ARRAYTYPE_P(1); + text *new_val_text = PG_GETARG_TEXT_P(2); + int16 typlen; bool typbyval; char typalign; Datum *elems; bool *nulls; int nelems; get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign); deconstruct_array(path_array, TEXTOID, typlen, typbyval, typalign, &elems, &nulls, &nelems); - if (nelems == 0) { - PG_RETURN_POINTER(data); - } - - msg_name = text_to_cstring(DatumGetTextPP(elems[0])); - - if (s_def_pool == NULL) { - s_def_pool = upb_DefPool_New(); - if (s_def_pool) { - pgproto_LoadAllSchemasFromDb(s_def_pool); - } - } - - if (s_def_pool == NULL) { - elog(ERROR, "Failed to initialize Schema Registry"); - } - - msg_def = upb_DefPool_FindMessageByName(s_def_pool, msg_name); - if (!msg_def) { - elog(ERROR, "Message not found in schema registry: %s", msg_name); - } - - mini_table = upb_MessageDef_MiniTable(msg_def); - - arena = upb_Arena_New(); - msg = upb_Message_New(mini_table, arena); + if (nelems != 2) elog(ERROR, "Only paths of length 2 are supported in this prototype (message_name, field_name)"); - buf = data->data; - size = VARSIZE(data) - VARHDRSZ; + char *msg_name = text_to_cstring(DatumGetTextPP(elems[0])); + char *field_name = text_to_cstring(DatumGetTextPP(elems[1])); + char *new_val_str = text_to_cstring(new_val_text); - status = upb_Decode(buf, size, msg, mini_table, NULL, 0, arena); - if (status != kUpb_DecodeStatus_Ok) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to decode protobuf message: %s", upb_DecodeStatus_String(status)); - } - - { - char *field_name; - const upb_FieldDef *field_def; - upb_CType ctype; - upb_MessageValue val; - char *new_val_str; - - if (nelems != 2) { - elog(ERROR, "Only paths of length 2 are supported in this prototype (message_name, field_name)"); - } - - field_name = text_to_cstring(DatumGetTextPP(elems[1])); - field_def = upb_MessageDef_FindFieldByName(msg_def, field_name); - - if (!field_def) { + pgproto_LoadAllSchemasFromDb(); + PbFieldLookup lookup; + PbLookupStatus status = pgproto_lookup_field(msg_name, field_name, &lookup); + if (status != PB_LOOKUP_OK) { + if (status == PB_LOOKUP_MSG_NOT_FOUND) { + elog(ERROR, "Message not found in schema registry: %s", msg_name); + } else { elog(ERROR, "Field %s not found in message %s", field_name, msg_name); } - - ctype = upb_FieldDef_CType(field_def); - new_val_str = text_to_cstring(new_val_text); - - switch (ctype) { - case kUpb_CType_Int32: - val.int32_val = atoi(new_val_str); - break; - case kUpb_CType_Float: - val.float_val = atof(new_val_str); - break; - case kUpb_CType_Bool: - if (strcmp(new_val_str, "true") == 0) val.bool_val = true; - else if (strcmp(new_val_str, "false") == 0) val.bool_val = false; - else elog(ERROR, "Invalid boolean value: %s", new_val_str); - break; - case kUpb_CType_String: - { - char *arena_str = upb_Arena_Malloc(arena, strlen(new_val_str) + 1); - strcpy(arena_str, new_val_str); - val.str_val.data = arena_str; - val.str_val.size = strlen(new_val_str); - } - break; - default: - elog(ERROR, "Unsupported type for modification: %d", ctype); - } - - upb_Message_SetFieldByDef(msg, field_def, val, arena); - pfree(field_name); - pfree(new_val_str); } - (void)create_if_missing; - out_buf = NULL; - out_size = 0; - enc_status = upb_Encode(msg, mini_table, 0, arena, &out_buf, &out_size); + size_t old_size = VARSIZE(data) - VARHDRSZ; + StringInfoData buf; initStringInfo(&buf); + appendBinaryStringInfo(&buf, data->data, (int)old_size); - if (enc_status != kUpb_EncodeStatus_Ok) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to encode protobuf message: %d", enc_status); - } - - result = (ProtobufData *) palloc(VARHDRSZ + out_size); - SET_VARSIZE(result, VARHDRSZ + out_size); - memcpy(result->data, out_buf, out_size); - - upb_Arena_Free(arena); - pfree(msg_name); - + if (lookup.type == PB_TYPE_INT32 || lookup.type == PB_TYPE_INT64 || lookup.type == PB_TYPE_BOOL) { + encode_varint(PB_FIELD_TAG(lookup.number, PB_WIRE_VARINT), &buf); + encode_varint((uint64)atoll(new_val_str), &buf); + } else if (lookup.type == PB_TYPE_STRING) { + encode_varint(PB_FIELD_TAG(lookup.number, PB_WIRE_LENGTH_DELIMITED), &buf); + encode_varint((uint64)strlen(new_val_str), &buf); + appendStringInfoString(&buf, new_val_str); + } else elog(ERROR, "Unsupported type for modification: %d", lookup.type); + + ProtobufData *result = (ProtobufData *) palloc(VARHDRSZ + buf.len); + SET_VARSIZE(result, VARHDRSZ + buf.len); + memcpy(result->data, buf.data, buf.len); + pfree(msg_name); pfree(field_name); pfree(new_val_str); PG_RETURN_POINTER(result); } PG_FUNCTION_INFO_V1(pb_insert); +/** + * pb_insert: Inserts an element into a repeated or map field. + */ Datum pb_insert(PG_FUNCTION_ARGS) { - /* - * Inserts an element into a repeated field (array) or map field. - * Expects a path of length 3: [message_name, field_name, index_or_key]. - * - * For arrays, the 3rd element is the 0-based index where to insert. - * For maps, the 3rd element is the string key to insert. - */ - ProtobufData *data; - ArrayType *path_array; - text *new_val_text; - - int16 typlen; - bool typbyval; - char typalign; - Datum *elems; - bool *nulls; - int nelems; - - char *msg_name; - const upb_MessageDef *msg_def; - const upb_MiniTable *mini_table; - upb_Arena *arena; - upb_Message *msg; - const char *buf; - size_t size; - upb_DecodeStatus status; - char *out_buf; - size_t out_size; - upb_EncodeStatus enc_status; - ProtobufData *result; - - data = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - path_array = PG_GETARG_ARRAYTYPE_P(1); - new_val_text = PG_GETARG_TEXT_P(2); - + ProtobufData *data = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + ArrayType *path_array = PG_GETARG_ARRAYTYPE_P(1); + text *new_val_text = PG_GETARG_TEXT_P(2); + int16 typlen; bool typbyval; char typalign; Datum *elems; bool *nulls; int nelems; get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign); deconstruct_array(path_array, TEXTOID, typlen, typbyval, typalign, &elems, &nulls, &nelems); - if (nelems != 3) { elog(ERROR, "pb_insert requires a path of length 3 (message_name, field_name, index/key)"); } - - msg_name = text_to_cstring(DatumGetTextPP(elems[0])); - - if (s_def_pool == NULL) { - s_def_pool = upb_DefPool_New(); - if (s_def_pool) { - pgproto_LoadAllSchemasFromDb(s_def_pool); - } - } - - if (s_def_pool == NULL) { - elog(ERROR, "Failed to initialize Schema Registry"); - } - - msg_def = upb_DefPool_FindMessageByName(s_def_pool, msg_name); - if (!msg_def) { - elog(ERROR, "Message not found in schema registry: %s", msg_name); - } - - mini_table = upb_MessageDef_MiniTable(msg_def); - - arena = upb_Arena_New(); - msg = upb_Message_New(mini_table, arena); - - buf = data->data; - size = VARSIZE(data) - VARHDRSZ; - - status = upb_Decode(buf, size, msg, mini_table, NULL, 0, arena); - if (status != kUpb_DecodeStatus_Ok) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to decode protobuf message: %s", upb_DecodeStatus_String(status)); - } - - { - char *field_name; - const upb_FieldDef *field_def; - char *key_or_idx_str; - - field_name = text_to_cstring(DatumGetTextPP(elems[1])); - field_def = upb_MessageDef_FindFieldByName(msg_def, field_name); - - if (!field_def) { - elog(ERROR, "Field %s not found in message %s", field_name, msg_name); - } - - key_or_idx_str = text_to_cstring(DatumGetTextPP(elems[2])); - - if (upb_FieldDef_IsRepeated(field_def) && !upb_FieldDef_IsMap(field_def)) { - // Array Insertion - int index = atoi(key_or_idx_str); - upb_MutableMessageValue mut_val = upb_Message_Mutable(msg, field_def, arena); - upb_Array *arr = mut_val.array; - size_t arr_size = upb_Array_Size(arr); - upb_MessageValue new_elem_val; - char *new_val_str = text_to_cstring(new_val_text); - upb_CType ctype = upb_FieldDef_CType(field_def); - - if (index < 0 || index > arr_size) { - elog(ERROR, "Array index out of bounds: %d, size: %zu", index, arr_size); - } - - if (!upb_Array_Insert(arr, index, 1, arena)) { - elog(ERROR, "Failed to insert into array"); - } - - // Parse value based on type - switch (ctype) { - case kUpb_CType_Int32: - new_elem_val.int32_val = atoi(new_val_str); - break; - case kUpb_CType_String: - { - char *arena_str = upb_Arena_Malloc(arena, strlen(new_val_str) + 1); - strcpy(arena_str, new_val_str); - new_elem_val.str_val.data = arena_str; - new_elem_val.str_val.size = strlen(new_val_str); - } - break; - // Add more types as needed - default: - elog(ERROR, "Unsupported type for array insertion: %d", ctype); - } - upb_Array_Set(arr, index, new_elem_val); - pfree(new_val_str); - } else if (upb_FieldDef_IsMap(field_def)) { - // Map Insertion - upb_MutableMessageValue mut_val = upb_Message_Mutable(msg, field_def, arena); - upb_Map *map = mut_val.map; - upb_MessageValue key_val; - - // Assume string keys for now for prototype - key_val.str_val.data = key_or_idx_str; - key_val.str_val.size = strlen(key_or_idx_str); - - if (upb_Map_Get(map, key_val, NULL)) { - elog(ERROR, "cannot replace existing key"); - } - - // Parse value - { - upb_MessageValue new_elem_val; - char *new_val_str = text_to_cstring(new_val_text); - - const upb_MessageDef *entry_def = upb_FieldDef_MessageSubDef(field_def); - const upb_FieldDef *val_field_def = upb_MessageDef_FindFieldByNumber(entry_def, 2); // 2 is value - upb_CType val_ctype = upb_FieldDef_CType(val_field_def); - - switch (val_ctype) { - case kUpb_CType_Int32: - new_elem_val.int32_val = atoi(new_val_str); - break; - case kUpb_CType_String: - { - char *arena_str = upb_Arena_Malloc(arena, strlen(new_val_str) + 1); - strcpy(arena_str, new_val_str); - new_elem_val.str_val.data = arena_str; - new_elem_val.str_val.size = strlen(new_val_str); - } - break; - default: - elog(ERROR, "Unsupported map value type: %d", val_ctype); - } - - upb_Map_Insert(map, key_val, new_elem_val, arena); - pfree(new_val_str); - } + char *msg_name = text_to_cstring(DatumGetTextPP(elems[0])); + char *field_name = text_to_cstring(DatumGetTextPP(elems[1])); + char *new_val_str = text_to_cstring(new_val_text); + pgproto_LoadAllSchemasFromDb(); + PbFieldLookup lookup; + PbLookupStatus status = pgproto_lookup_field(msg_name, field_name, &lookup); + if (status != PB_LOOKUP_OK) { + if (status == PB_LOOKUP_MSG_NOT_FOUND) { + elog(ERROR, "Message not found in schema registry: %s", msg_name); } else { - elog(ERROR, "Field %s is not a repeated or map field", field_name); + elog(ERROR, "Field %s not found in message %s", field_name, msg_name); } - - pfree(field_name); - pfree(key_or_idx_str); } - - out_buf = NULL; - out_size = 0; - enc_status = upb_Encode(msg, mini_table, 0, arena, &out_buf, &out_size); - - if (enc_status != kUpb_EncodeStatus_Ok) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to encode protobuf message: %d", enc_status); - } - - result = (ProtobufData *) palloc(VARHDRSZ + out_size); - SET_VARSIZE(result, VARHDRSZ + out_size); - memcpy(result->data, out_buf, out_size); - - upb_Arena_Free(arena); - pfree(msg_name); - + size_t old_size = VARSIZE(data) - VARHDRSZ; + StringInfoData buf; initStringInfo(&buf); + appendBinaryStringInfo(&buf, data->data, (int)old_size); + if (lookup.is_map) { + char *key_str = text_to_cstring(DatumGetTextPP(elems[2])); + StringInfoData entry_buf; initStringInfo(&entry_buf); + + encode_varint(PB_FIELD_TAG(1, PB_WIRE_LENGTH_DELIMITED), &entry_buf); + encode_varint((uint64)strlen(key_str), &entry_buf); + appendStringInfoString(&entry_buf, key_str); + + encode_varint(PB_FIELD_TAG(2, PB_WIRE_VARINT), &entry_buf); + encode_varint((uint64)atoll(new_val_str), &entry_buf); + + encode_varint(PB_FIELD_TAG(lookup.number, PB_WIRE_LENGTH_DELIMITED), &buf); + encode_varint((uint64)entry_buf.len, &buf); + appendBinaryStringInfo(&buf, entry_buf.data, entry_buf.len); + pfree(key_str); + } else if (lookup.is_repeated) { + if (lookup.type == PB_TYPE_INT32) { + encode_varint(PB_FIELD_TAG(lookup.number, PB_WIRE_VARINT), &buf); + encode_varint((uint64)atoll(new_val_str), &buf); + } else elog(ERROR, "Unsupported type for array insertion: %d", lookup.type); + } else elog(ERROR, "Field not repeated or map"); + ProtobufData *result = (ProtobufData *) palloc(VARHDRSZ + buf.len); + SET_VARSIZE(result, VARHDRSZ + buf.len); + memcpy(result->data, buf.data, buf.len); + pfree(msg_name); pfree(field_name); pfree(new_val_str); PG_RETURN_POINTER(result); } PG_FUNCTION_INFO_V1(pb_delete); +/** + * pb_delete: Removes a field or array/map element from a Protobuf message. + * + * Summary: + * Scans the message and copies all fields to a new buffer, EXCEPT the field matching + * the target tag. This effectively deletes the field from the message. + */ Datum pb_delete(PG_FUNCTION_ARGS) { - ProtobufData *data; - ArrayType *path_array; - - int16 typlen; - bool typbyval; - char typalign; - Datum *elems; - bool *nulls; - int nelems; - - char *msg_name; - const upb_MessageDef *msg_def; - const upb_MiniTable *mini_table; - upb_Arena *arena; - upb_Message *msg; - const char *buf; - size_t size; - upb_DecodeStatus status; - char *out_buf; - size_t out_size; - upb_EncodeStatus enc_status; - ProtobufData *result; - - data = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - path_array = PG_GETARG_ARRAYTYPE_P(1); - + ProtobufData *data = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + ArrayType *path_array = PG_GETARG_ARRAYTYPE_P(1); + int16 typlen; bool typbyval; char typalign; Datum *elems; bool *nulls; int nelems; get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign); deconstruct_array(path_array, TEXTOID, typlen, typbyval, typalign, &elems, &nulls, &nelems); - if (nelems < 2 || nelems > 3) { elog(ERROR, "pb_delete requires a path of length 2 or 3 (message_name, field_name [, index/key])"); } - - msg_name = text_to_cstring(DatumGetTextPP(elems[0])); - - if (s_def_pool == NULL) { - s_def_pool = upb_DefPool_New(); - if (s_def_pool) { - pgproto_LoadAllSchemasFromDb(s_def_pool); - } - } - - if (s_def_pool == NULL) { - elog(ERROR, "Failed to initialize Schema Registry"); - } - - msg_def = upb_DefPool_FindMessageByName(s_def_pool, msg_name); - if (!msg_def) { - elog(ERROR, "Message not found in schema registry: %s", msg_name); - } - - mini_table = upb_MessageDef_MiniTable(msg_def); - - arena = upb_Arena_New(); - msg = upb_Message_New(mini_table, arena); - - buf = data->data; - size = VARSIZE(data) - VARHDRSZ; - - status = upb_Decode(buf, size, msg, mini_table, NULL, 0, arena); - if (status != kUpb_DecodeStatus_Ok) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to decode protobuf message: %s", upb_DecodeStatus_String(status)); - } - - { - char *field_name; - const upb_FieldDef *field_def; - - field_name = text_to_cstring(DatumGetTextPP(elems[1])); - field_def = upb_MessageDef_FindFieldByName(msg_def, field_name); - - if (!field_def) { + char *msg_name = text_to_cstring(DatumGetTextPP(elems[0])); + char *field_name = text_to_cstring(DatumGetTextPP(elems[1])); + pgproto_LoadAllSchemasFromDb(); + PbFieldLookup lookup; + PbLookupStatus status = pgproto_lookup_field(msg_name, field_name, &lookup); + if (status != PB_LOOKUP_OK) { + if (status == PB_LOOKUP_MSG_NOT_FOUND) { + elog(ERROR, "Message not found in schema registry: %s", msg_name); + } else { elog(ERROR, "Field %s not found in message %s", field_name, msg_name); } - - if (nelems == 2) { - // Delete/Clear field from message - upb_Message_ClearFieldByDef(msg, field_def); - } else if (nelems == 3) { - char *key_or_idx_str = text_to_cstring(DatumGetTextPP(elems[2])); - - if (upb_FieldDef_IsRepeated(field_def) && !upb_FieldDef_IsMap(field_def)) { - // Array Deletion - int index = atoi(key_or_idx_str); - upb_MutableMessageValue mut_val = upb_Message_Mutable(msg, field_def, arena); - upb_Array *arr = mut_val.array; - size_t arr_size = upb_Array_Size(arr); - - if (index < 0 || index >= arr_size) { - elog(ERROR, "Array index out of bounds: %d, size: %zu", index, arr_size); - } - - upb_Array_Delete(arr, index, 1); - } else if (upb_FieldDef_IsMap(field_def)) { - // Map Deletion - upb_MutableMessageValue mut_val = upb_Message_Mutable(msg, field_def, arena); - upb_Map *map = mut_val.map; - upb_MessageValue key_val; - - // Assume string keys for now - key_val.str_val.data = key_or_idx_str; - key_val.str_val.size = strlen(key_or_idx_str); - - upb_Map_Delete(map, key_val, NULL); - } else { - elog(ERROR, "Field %s is not a repeated or map field", field_name); - } - pfree(key_or_idx_str); - } - - pfree(field_name); - } - - out_buf = NULL; - out_size = 0; - enc_status = upb_Encode(msg, mini_table, 0, arena, &out_buf, &out_size); - - if (enc_status != kUpb_EncodeStatus_Ok) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to encode protobuf message: %d", enc_status); } - - result = (ProtobufData *) palloc(VARHDRSZ + out_size); - SET_VARSIZE(result, VARHDRSZ + out_size); - memcpy(result->data, out_buf, out_size); - - upb_Arena_Free(arena); - pfree(msg_name); - + size_t old_size = VARSIZE(data) - VARHDRSZ; + const char *ptr = data->data; const char *end = ptr + old_size; + StringInfoData buf; initStringInfo(&buf); + while (ptr < end) { + const char *start = ptr; + uint64 key = decode_varint(&ptr, end); + int field_num = (int)(key >> 3); + int wire_type = (int)(key & 0x07); + if (field_num == (int)lookup.number) skip_field(wire_type, &ptr, end); + else { skip_field(wire_type, &ptr, end); appendBinaryStringInfo(&buf, start, (int)(ptr - start)); } + } + ProtobufData *result = (ProtobufData *) palloc(VARHDRSZ + buf.len); + SET_VARSIZE(result, VARHDRSZ + buf.len); + memcpy(result->data, buf.data, buf.len); + pfree(msg_name); pfree(field_name); PG_RETURN_POINTER(result); } PG_FUNCTION_INFO_V1(pb_merge); +/** + * pb_merge: Implements the || operator. Concatenates two Protobuf blobs. + * Valid Protobuf messages can be merged by simple concatenation. + */ Datum pb_merge(PG_FUNCTION_ARGS) { - ProtobufData *data1; - ProtobufData *data2; - size_t size1; - size_t size2; - ProtobufData *result; - - data1 = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - data2 = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); - - size1 = VARSIZE(data1) - VARHDRSZ; - size2 = VARSIZE(data2) - VARHDRSZ; - - result = (ProtobufData *) palloc(VARHDRSZ + size1 + size2); + ProtobufData *data1 = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + ProtobufData *data2 = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + size_t size1 = VARSIZE(data1) - VARHDRSZ; + size_t size2 = VARSIZE(data2) - VARHDRSZ; + ProtobufData *result = (ProtobufData *) palloc(VARHDRSZ + size1 + size2); SET_VARSIZE(result, VARHDRSZ + size1 + size2); - - memcpy(result->data, data1->data, size1); - memcpy(result->data + size1, data2->data, size2); - + memcpy(result->data, data1->data, (int)size1); + memcpy(result->data + size1, data2->data, (int)size2); PG_RETURN_POINTER(result); } - - diff --git a/src/navigation.c b/src/navigation.c index 2a11e38..5c8cee4 100644 --- a/src/navigation.c +++ b/src/navigation.c @@ -1,35 +1,20 @@ #include "pgproto.h" - -/* - * Skip a protobuf field based on its wire type. - * Updates the pointer to point past the skipped field. - */ -static void -skip_field(int wire_type, const char **ptr, const char *end) -{ - switch (wire_type) { - case PB_WIRE_VARINT: - decode_varint(ptr, end); - break; - case PB_WIRE_FIXED64: - *ptr += 8; - break; - case PB_WIRE_LENGTH_DELIMITED: - { - uint64 len = decode_varint(ptr, end); - *ptr += len; - } - break; - case PB_WIRE_FIXED32: - *ptr += 4; - break; - default: - elog(ERROR, "Unsupported wire type %d in field skip", wire_type); - } -} +#include +#include PG_FUNCTION_INFO_V1(pb_get_int32); +/** + * pb_get_int32: Extracts an int32 value from a Protobuf message by its tag number. + * + * Inputs: + * - data (protobuf): The Protobuf binary data. + * - target_tag (int32): The tag number to look for. + * + * Summary: + * Scans the Protobuf wire format sequentially. When the tag is found, it decodes + * the Varint value. If the tag is not found, returns NULL. + */ Datum pb_get_int32(PG_FUNCTION_ARGS) { @@ -40,58 +25,31 @@ pb_get_int32(PG_FUNCTION_ARGS) while (ptr < end) { uint64 key = decode_varint(&ptr, end); - int field_num = key >> PB_FIELD_NUM_SHIFT; - int wire_type = key & PB_WIRE_TYPE_MASK; + int field_num = (int)(key >> PB_FIELD_NUM_SHIFT); + int wire_type = (int)(key & PB_WIRE_TYPE_MASK); if (field_num == target_tag) { - if (wire_type == 0) { // Varint + if (wire_type == PB_WIRE_VARINT) { uint64 val = decode_varint(&ptr, end); PG_RETURN_INT32((int32) val); } else { elog(ERROR, "Expected varint wire type for field %d, got %d", target_tag, wire_type); } } - - switch (wire_type) { - case 0: - decode_varint(&ptr, end); - break; - case 1: - ptr += 8; - break; - case 2: - { - uint64 len = decode_varint(&ptr, end); - ptr += len; - } - break; - case 5: - ptr += 4; - break; - default: - elog(ERROR, "Unsupported wire type %d", wire_type); - } + skip_field(wire_type, &ptr, end); } - PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(protobuf_contains); +/** + * protobuf_contains: Implementation of the @> operator. + * Checks if the 'base' protobuf contains all tag-value pairs present in 'query'. + */ Datum protobuf_contains(PG_FUNCTION_ARGS) { - /* - * This function checks if the 'base' protobuf contains all fields present in the 'query' protobuf. - * It iterates over all fields in 'query' and for each field, it scans the 'base' - * to find a matching field and value. - * - * NOTE: This is an O(N*M) operation where N is query size and M is base size. - * For large messages, this could be a performance bottleneck. - * - * NOTE: It uses manual skipping instead of skip_field() in some places to avoid - * function call overhead in hot loops, or because it was written before skip_field was available. - */ ProtobufData *base = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); ProtobufData *query = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); const char *q_ptr = query->data; @@ -100,17 +58,15 @@ protobuf_contains(PG_FUNCTION_ARGS) while (q_ptr < q_end) { uint64 q_key = decode_varint(&q_ptr, q_end); - int q_field_num = q_key >> PB_FIELD_NUM_SHIFT; - int q_wire_type = q_key & PB_WIRE_TYPE_MASK; + int q_field_num = (int)(q_key >> PB_FIELD_NUM_SHIFT); + int q_wire_type = (int)(q_key & PB_WIRE_TYPE_MASK); uint64 q_val = 0; bool q_has_val = false; if (q_wire_type == PB_WIRE_VARINT) { q_val = decode_varint(&q_ptr, q_end); q_has_val = true; - } else if (q_wire_type == PB_WIRE_FIXED64) { q_ptr += 8; } - else if (q_wire_type == PB_WIRE_LENGTH_DELIMITED) { uint64 len = decode_varint(&q_ptr, q_end); q_ptr += len; } - else if (q_wire_type == PB_WIRE_FIXED32) { q_ptr += 4; } + } else skip_field(q_wire_type, &q_ptr, q_end); const char *b_ptr = base->data; const char *b_end = (const char *) base + VARSIZE(base); @@ -118,44 +74,27 @@ protobuf_contains(PG_FUNCTION_ARGS) while (b_ptr < b_end) { uint64 b_key = decode_varint(&b_ptr, b_end); - int b_field_num = b_key >> PB_FIELD_NUM_SHIFT; - int b_wire_type = b_key & PB_WIRE_TYPE_MASK; + int b_field_num = (int)(b_key >> PB_FIELD_NUM_SHIFT); + int b_wire_type = (int)(b_key & PB_WIRE_TYPE_MASK); if (b_field_num == q_field_num) { if (b_wire_type == PB_WIRE_VARINT && q_has_val) { uint64 b_val = decode_varint(&b_ptr, b_end); - if (b_val == q_val) { - found_tag = true; - break; - } - } else if (b_wire_type == PB_WIRE_VARINT) { decode_varint(&b_ptr, b_end); } - else if (b_wire_type == PB_WIRE_FIXED64) { b_ptr += 8; } - else if (b_wire_type == PB_WIRE_LENGTH_DELIMITED) { uint64 len = decode_varint(&b_ptr, b_end); b_ptr += len; } - else if (b_wire_type == PB_WIRE_FIXED32) { b_ptr += 4; } - - if (!q_has_val) { - found_tag = true; - break; - } - } else { - if (b_wire_type == PB_WIRE_VARINT) { decode_varint(&b_ptr, b_end); } - else if (b_wire_type == PB_WIRE_FIXED64) { b_ptr += 8; } - else if (b_wire_type == PB_WIRE_LENGTH_DELIMITED) { uint64 len = decode_varint(&b_ptr, b_end); b_ptr += len; } - else if (b_wire_type == PB_WIRE_FIXED32) { b_ptr += 4; } - } - } - - if (!found_tag) { - match_all = false; - break; + if (b_val == q_val) { found_tag = true; break; } + } else if (!q_has_val) { found_tag = true; break; } + else skip_field(b_wire_type, &b_ptr, b_end); + } else skip_field(b_wire_type, &b_ptr, b_end); } + if (!found_tag) { match_all = false; break; } } - PG_RETURN_BOOL(match_all); } PG_FUNCTION_INFO_V1(pb_get_int32_by_name); +/** + * pb_get_int32_by_name: Extracts an int32 value by message and field name. + */ Datum pb_get_int32_by_name(PG_FUNCTION_ARGS) { @@ -165,64 +104,50 @@ pb_get_int32_by_name(PG_FUNCTION_ARGS) char *msg_name = text_to_cstring(msg_name_text); char *field_name = text_to_cstring(field_name_text); - const upb_MessageDef *msg_def; - const upb_FieldDef *field_def; uint32_t field_number; - + PbFieldLookup lookup; const char *ptr; const char *end; - if (s_def_pool == NULL) { - s_def_pool = upb_DefPool_New(); - if (s_def_pool) { - pgproto_LoadAllSchemasFromDb(s_def_pool); + pgproto_LoadAllSchemasFromDb(); + PbLookupStatus status = pgproto_lookup_field(msg_name, field_name, &lookup); + if (status != PB_LOOKUP_OK) { + if (status == PB_LOOKUP_MSG_NOT_FOUND) { + elog(ERROR, "Message not found in schema registry: %s", msg_name); + } else { + elog(ERROR, "Field %s not found in message %s", field_name, msg_name); } } + field_number = lookup.number; - if (s_def_pool == NULL) { - elog(ERROR, "Failed to initialize Schema Registry"); - } - - msg_def = upb_DefPool_FindMessageByName(s_def_pool, msg_name); - if (!msg_def) { - elog(ERROR, "Message not found in schema registry: %s", msg_name); - } - - field_def = upb_MessageDef_FindFieldByName(msg_def, field_name); - if (!field_def) { - elog(ERROR, "Field not found in message %s: %s", msg_name, field_name); - } - - field_number = upb_FieldDef_Number(field_def); - - pfree(msg_name); - pfree(field_name); + pfree(msg_name); pfree(field_name); ptr = data->data; end = (const char *) data + VARSIZE(data); while (ptr < end) { uint64 key = decode_varint(&ptr, end); - int field_num = key >> PB_FIELD_NUM_SHIFT; - int wire_type = key & PB_WIRE_TYPE_MASK; + int field_num = (int)(key >> PB_FIELD_NUM_SHIFT); + int wire_type = (int)(key & PB_WIRE_TYPE_MASK); - if (field_num == field_number) { - if (wire_type == PB_WIRE_VARINT) { // Varint + if (field_num == (int)field_number) { + if (wire_type == PB_WIRE_VARINT) { uint64 val = decode_varint(&ptr, end); PG_RETURN_INT32((int32) val); } else { - elog(ERROR, "Expected varint wire type for field %u, got %d", field_number, wire_type); + elog(ERROR, "Expected varint wire type for field %s, got %d", field_name, wire_type); } } - skip_field(wire_type, &ptr, end); } - PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(pb_get_int32_by_name_dot); +/** + * pb_get_int32_by_name_dot: Extracts an int32 value using dot notation (e.g., "Message.Field"). + */ Datum pb_get_int32_by_name_dot(PG_FUNCTION_ARGS) { @@ -231,303 +156,179 @@ pb_get_int32_by_name_dot(PG_FUNCTION_ARGS) char *path = text_to_cstring(path_text); char *dot = strchr(path, '.'); - if (!dot) { - pfree(path); - elog(ERROR, "Path must be in format 'Message.Field'"); - } + if (!dot) { pfree(path); elog(ERROR, "Path must be in format 'Message.Field'"); } *dot = '\0'; char *msg_name = path; char *field_name = dot + 1; - - const upb_MessageDef *msg_def; - const upb_FieldDef *field_def; uint32_t field_number; - - const char *ptr; - const char *end; - - if (s_def_pool == NULL) { - s_def_pool = upb_DefPool_New(); - if (s_def_pool) { - pgproto_LoadAllSchemasFromDb(s_def_pool); + PbFieldLookup lookup; + + pgproto_LoadAllSchemasFromDb(); + PbLookupStatus status = pgproto_lookup_field(msg_name, field_name, &lookup); + if (status != PB_LOOKUP_OK) { + if (status == PB_LOOKUP_MSG_NOT_FOUND) { + elog(ERROR, "Message not found in schema registry: %s", msg_name); + } else { + elog(ERROR, "Field %s not found in message %s", field_name, msg_name); } } + field_number = lookup.number; - if (s_def_pool == NULL) { - pfree(path); - elog(ERROR, "Failed to initialize Schema Registry"); - } - - msg_def = upb_DefPool_FindMessageByName(s_def_pool, msg_name); - if (!msg_def) { - /* Note: We do not pfree(path) here because msg_name points into it, - * and elog(ERROR) will abort the transaction and clean up the memory - * context automatically, avoiding both leaks and use-after-free. */ - elog(ERROR, "Message not found in schema registry: %s", msg_name); - } - - field_def = upb_MessageDef_FindFieldByName(msg_def, field_name); - if (!field_def) { - pfree(path); - PG_RETURN_NULL(); - } - - field_number = upb_FieldDef_Number(field_def); - - ptr = data->data; - end = (const char *) data + VARSIZE(data); + const char *ptr = data->data; + const char *end = (const char *) data + VARSIZE(data); while (ptr < end) { uint64 key = decode_varint(&ptr, end); - int field_num = key >> PB_FIELD_NUM_SHIFT; - int wire_type = key & PB_WIRE_TYPE_MASK; - - if (field_num == field_number) { - if (wire_type == PB_WIRE_VARINT) { // Varint + int field_num = (int)(key >> PB_FIELD_NUM_SHIFT); + int wire_type = (int)(key & PB_WIRE_TYPE_MASK); + if (field_num == (int)field_number) { + if (wire_type == PB_WIRE_VARINT) { uint64 val = decode_varint(&ptr, end); - pfree(path); - PG_RETURN_INT32((int32) val); + pfree(path); PG_RETURN_INT32((int32) val); } else { pfree(path); - elog(ERROR, "Expected varint wire type for field %u, got %d", field_number, wire_type); + elog(ERROR, "Expected varint wire type for field %s, got %d", field_name, wire_type); } } - skip_field(wire_type, &ptr, end); } - - pfree(path); - PG_RETURN_NULL(); + pfree(path); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(pb_get_int32_by_path); +/** + * pb_get_int32_by_path: Implementation of the #> operator for path navigation. + * + * Inputs: + * - data (protobuf) + * - path (text[]): E.g., ARRAY['Outer', 'inner', 'id'] or ARRAY['Outer', 'scores', '0'] + * + * Summary: + * Iteratively resolves each path element. If it's a message, it nests the parser + * into the submessage's length-delimited blob. Supports array indexing and map key lookups. + */ Datum pb_get_int32_by_path(PG_FUNCTION_ARGS) { ProtobufData *data = (ProtobufData *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); ArrayType *path_array = PG_GETARG_ARRAYTYPE_P(1); - int16 typlen; - bool typbyval; - char typalign; - Datum *elems; - bool *nulls; - int nelems; - + int16 typlen; bool typbyval; char typalign; Datum *elems; bool *nulls; int nelems; get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign); deconstruct_array(path_array, TEXTOID, typlen, typbyval, typalign, &elems, &nulls, &nelems); if (nelems == 0) PG_RETURN_NULL(); - char *msg_name = text_to_cstring(DatumGetTextPP(elems[0])); - - if (s_def_pool == NULL) { - s_def_pool = upb_DefPool_New(); - if (s_def_pool) { - pgproto_LoadAllSchemasFromDb(s_def_pool); - } - } + char current_msg[512]; + char *msg_name_str = text_to_cstring(DatumGetTextPP(elems[0])); + strncpy(current_msg, msg_name_str, 511); + current_msg[511] = '\0'; + pfree(msg_name_str); - if (s_def_pool == NULL) { - elog(ERROR, "Failed to initialize Schema Registry"); - } - - const upb_MessageDef *msg_def = upb_DefPool_FindMessageByName(s_def_pool, msg_name); - if (!msg_def) { - elog(ERROR, "Message not found in schema registry: %s", msg_name); - } + pgproto_LoadAllSchemasFromDb(); const char *ptr = data->data; const char *end = (const char *) data + VARSIZE(data); for (int i = 1; i < nelems; i++) { char *field_name = text_to_cstring(DatumGetTextPP(elems[i])); - const upb_FieldDef *field_def = upb_MessageDef_FindFieldByName(msg_def, field_name); - if (!field_def) { - pfree(field_name); - pfree(msg_name); - PG_RETURN_NULL(); - } + PbFieldLookup lookup; + if (pgproto_lookup_field(current_msg, field_name, &lookup) != PB_LOOKUP_OK) { pfree(field_name); PG_RETURN_NULL(); } - uint32_t field_number = upb_FieldDef_Number(field_def); - bool is_repeated = upb_FieldDef_IsRepeated(field_def); - bool is_map = upb_FieldDef_IsMap(field_def); - - int target_index = 0; - bool has_index = false; - char *map_key = NULL; + uint32_t field_number = lookup.number; + bool is_repeated = lookup.is_repeated; + bool is_map = lookup.is_map; + int target_index = 0; char *map_key = NULL; if (is_repeated && !is_map && i + 1 < nelems) { char *next_elem = text_to_cstring(DatumGetTextPP(elems[i + 1])); - if (isdigit(next_elem[0])) { - target_index = atoi(next_elem); - has_index = true; - i++; // Consume index - } + if (isdigit(next_elem[0])) { target_index = atoi(next_elem); i++; } pfree(next_elem); } else if (is_map && i + 1 < nelems) { - map_key = text_to_cstring(DatumGetTextPP(elems[i + 1])); - i++; // Consume key + map_key = text_to_cstring(DatumGetTextPP(elems[i + 1])); i++; } - bool found = false; - int current_idx = 0; - + bool found = false; int current_idx = 0; while (ptr < end) { uint64 key = decode_varint(&ptr, end); - int field_num = key >> PB_FIELD_NUM_SHIFT; - int wire_type = key & PB_WIRE_TYPE_MASK; + int field_num = (int)(key >> PB_FIELD_NUM_SHIFT); + int wire_type = (int)(key & PB_WIRE_TYPE_MASK); - if (field_num == field_number) { + if (field_num == (int)field_number) { if (is_map) { - /* - * Map fields are encoded as a repeated sequence of submessages. - * Each submessage (map entry) contains: - * - Field 1: The key - * - Field 2: The value - * We must parse this submessage to find the matching key. - */ if (wire_type == PB_WIRE_LENGTH_DELIMITED) { uint64 len = decode_varint(&ptr, end); - const char *entry_ptr = ptr; - const char *entry_end = ptr + len; - ptr += len; - - const upb_MessageDef *entry_def = upb_FieldDef_MessageSubDef(field_def); - const upb_FieldDef *key_field = upb_MessageDef_FindFieldByNumber(entry_def, 1); - - bool key_matched = false; - uint64 val = 0; - bool val_found = false; - + const char *entry_ptr = ptr; const char *entry_end = ptr + len; ptr += len; + bool key_matched = false; uint64 val = 0; bool val_found = false; while (entry_ptr < entry_end) { uint64 entry_key = decode_varint(&entry_ptr, entry_end); - int entry_num = entry_key >> PB_FIELD_NUM_SHIFT; - int entry_wire = entry_key & PB_WIRE_TYPE_MASK; - - if (entry_num == 1) { - if (upb_FieldDef_Type(key_field) == kUpb_FieldType_String) { + int entry_num = (int)(entry_key >> 3); int entry_wire = (int)(entry_key & 0x07); + if (entry_num == 1) { // key + if (entry_wire == 2) { // string uint64 key_len = decode_varint(&entry_ptr, entry_end); - if (key_len == strlen(map_key) && memcmp(entry_ptr, map_key, key_len) == 0) { - key_matched = true; - } + if (key_len == strlen(map_key) && memcmp(entry_ptr, map_key, key_len) == 0) key_matched = true; entry_ptr += key_len; - } else if (upb_FieldDef_Type(key_field) == kUpb_FieldType_Int32) { - uint64 key_val = decode_varint(&entry_ptr, entry_end); - if (key_val == atoi(map_key)) { - key_matched = true; - } - } - } else if (entry_num == 2) { - if (entry_wire == PB_WIRE_VARINT) { - val = decode_varint(&entry_ptr, entry_end); - val_found = true; - } else { - skip_field(entry_wire, &entry_ptr, entry_end); - } - } else { - skip_field(entry_wire, &entry_ptr, entry_end); - } + } else if (entry_wire == 0) { if (decode_varint(&entry_ptr, entry_end) == atoi(map_key)) key_matched = true; } + } else if (entry_num == 2) { // value + if (entry_wire == 0) { val = decode_varint(&entry_ptr, entry_end); val_found = true; } + else skip_field(entry_wire, &entry_ptr, entry_end); + } else skip_field(entry_wire, &entry_ptr, entry_end); } - if (key_matched && val_found) { found = true; if (i == nelems - 1) { - pfree(field_name); - pfree(msg_name); - if (map_key) pfree(map_key); + pfree(field_name); if (map_key) pfree(map_key); PG_RETURN_INT32((int32) val); - } else { - elog(ERROR, "Map value traversal beyond int32 not supported yet"); } } } } else if (is_repeated) { - if (wire_type == PB_WIRE_LENGTH_DELIMITED) { + if (wire_type == PB_WIRE_LENGTH_DELIMITED && lookup.type != PB_TYPE_MESSAGE) { uint64 len = decode_varint(&ptr, end); - if (upb_FieldDef_Type(field_def) == kUpb_FieldType_Message) { - if (current_idx == target_index) { - found = true; - end = ptr + len; - msg_def = upb_FieldDef_MessageSubDef(field_def); - break; - } else { - ptr += len; - current_idx++; - } - } else { - const char *packed_end = ptr + len; - while (ptr < packed_end && current_idx < target_index) { - decode_varint(&ptr, packed_end); - current_idx++; - } - if (ptr < packed_end) { - found = true; - uint64 val = decode_varint(&ptr, packed_end); - if (i == nelems - 1) { - pfree(field_name); - pfree(msg_name); - PG_RETURN_INT32((int32) val); - } else { - elog(ERROR, "Cannot traverse into primitive element"); - } - } - ptr = packed_end; - break; + const char *packed_end = ptr + len; + while (ptr < packed_end && current_idx < target_index) { decode_varint(&ptr, packed_end); current_idx++; } + if (ptr < packed_end) { + found = true; uint64 val = decode_varint(&ptr, packed_end); + if (i == nelems - 1) { pfree(field_name); PG_RETURN_INT32((int32) val); } } - } else { + ptr = packed_end; break; + } else { if (current_idx == target_index) { found = true; - uint64 val = decode_varint(&ptr, end); - if (i == nelems - 1) { - pfree(field_name); - pfree(msg_name); - PG_RETURN_INT32((int32) val); + if (lookup.type == PB_TYPE_MESSAGE) { + uint64 len = decode_varint(&ptr, end); const char *next_end = ptr + len; + strncpy(current_msg, lookup.type_name, 511); + ptr = ptr; end = next_end; + break; } else { - elog(ERROR, "Cannot traverse into primitive element"); + uint64 val = decode_varint(&ptr, end); + if (i == nelems - 1) { pfree(field_name); PG_RETURN_INT32((int32) val); } } - } else { - skip_field(wire_type, &ptr, end); - current_idx++; - } + } else { skip_field(wire_type, &ptr, end); current_idx++; } } } else { found = true; if (i == nelems - 1) { if (wire_type == PB_WIRE_VARINT) { uint64 val = decode_varint(&ptr, end); - pfree(field_name); - pfree(msg_name); - PG_RETURN_INT32((int32) val); - } else { - elog(ERROR, "Expected varint wire type for field %s, got %d", field_name, wire_type); - } + pfree(field_name); PG_RETURN_INT32((int32) val); + } else elog(ERROR, "Expected varint wire type for field %s, got %d", field_name, wire_type); } else { if (wire_type == PB_WIRE_LENGTH_DELIMITED) { uint64 len = decode_varint(&ptr, end); - end = ptr + len; - msg_def = upb_FieldDef_MessageSubDef(field_def); + const char *next_end = ptr + len; + strncpy(current_msg, lookup.type_name, 511); + end = next_end; break; - } else { - elog(ERROR, "Expected length-delimited wire type for submessage %s, got %d", field_name, wire_type); - } + } else elog(ERROR, "Expected length-delimited wire type for submessage %s, got %d", field_name, wire_type); } } - } else { - skip_field(wire_type, &ptr, end); - } - } - - if (map_key) pfree(map_key); - pfree(field_name); - if (!found) { - pfree(msg_name); - PG_RETURN_NULL(); + } else skip_field(wire_type, &ptr, end); } + if (map_key) pfree(map_key); pfree(field_name); + if (!found) PG_RETURN_NULL(); } - - pfree(msg_name); PG_RETURN_NULL(); } diff --git a/src/pgproto.c b/src/pgproto.c index 7baff81..f8aaa81 100755 --- a/src/pgproto.c +++ b/src/pgproto.c @@ -2,13 +2,9 @@ PG_MODULE_MAGIC; -/* Global Schema Pool Definition */ -upb_DefPool *s_def_pool = NULL; - PG_FUNCTION_INFO_V1(pgproto_hello); - Datum pgproto_hello(PG_FUNCTION_ARGS) { - PG_RETURN_TEXT_P(cstring_to_text("pgproto environment is ready.")); + PG_RETURN_TEXT_P(cstring_to_text("pgproto environment is ready (C-only implementation).")); } diff --git a/src/pgproto.h b/src/pgproto.h index c9fb36a..71c0b35 100644 --- a/src/pgproto.h +++ b/src/pgproto.h @@ -2,10 +2,6 @@ #define PGPROTO_H #include "postgres.h" -#if PG_VERSION_NUM >= 160000 -#include "varatt.h" -#endif - #include "fmgr.h" #include "utils/builtins.h" #include "catalog/pg_type_d.h" @@ -13,50 +9,84 @@ #include "executor/spi.h" #include "utils/array.h" #include "utils/lsyscache.h" - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/wire/decode.h" +#include "lib/stringinfo.h" #include #include #include #include -/* Custom Varlena Structure */ +/* + * ProtobufData: Custom Varlena structure for storing raw Protobuf binary data in PostgreSQL. + * It follows the standard PostgreSQL 'varlena' header convention. + */ typedef struct { - int32 vl_len_; // Internal Postgres header (do not access directly) - char data[1]; // Flexible data member + int32 vl_len_; /* PostgreSQL varlena length header */ + char data[1]; /* Raw Protobuf wire format bytes */ } ProtobufData; -/* Global Schema Pool (Defined in pgproto.c) */ -extern upb_DefPool *s_def_pool; - -/* Protobuf Wire Types (proto3) */ +/* + * PbWireType: Standard Protobuf wire types as defined in the Protobuf encoding specification. + */ typedef enum { PB_WIRE_VARINT = 0, PB_WIRE_FIXED64 = 1, PB_WIRE_LENGTH_DELIMITED = 2, - PB_WIRE_START_GROUP = 3, // Deprecated - PB_WIRE_END_GROUP = 4, // Deprecated + PB_WIRE_START_GROUP = 3, + PB_WIRE_END_GROUP = 4, PB_WIRE_FIXED32 = 5 } PbWireType; #define PB_WIRE_TYPE_MASK 0x07 #define PB_FIELD_NUM_SHIFT 3 -#define PB_VARINT_CONT_MASK 0x80 -#define PB_VARINT_DATA_MASK 0x7F -/* Helpers for hex parsing and protobuf wire format */ -static inline int -hex_val(char c) -{ - if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'a' && c <= 'f') return c - 'a' + 10; - if (c >= 'A' && c <= 'F') return c - 'A' + 10; - return -1; -} +/* + * PbType: Protobuf field types as defined in descriptor.proto. + */ +typedef enum { + PB_TYPE_DOUBLE = 1, + PB_TYPE_FLOAT = 2, + PB_TYPE_INT64 = 3, + PB_TYPE_UINT64 = 4, + PB_TYPE_INT32 = 5, + PB_TYPE_FIXED64 = 6, + PB_TYPE_FIXED32 = 7, + PB_TYPE_BOOL = 8, + PB_TYPE_STRING = 9, + PB_TYPE_GROUP = 10, + PB_TYPE_MESSAGE = 11, + PB_TYPE_BYTES = 12, + PB_TYPE_UINT32 = 13, + PB_TYPE_ENUM = 14, + PB_TYPE_SFIXED32 = 15, + PB_TYPE_SFIXED64 = 16, + PB_TYPE_SINT32 = 17, + PB_TYPE_SINT64 = 18 +} PbType; + +/* + * PbFieldLookup: Structure returned by the registry to describe a field's metadata. + */ +typedef struct { + char name[256]; /* Field name */ + uint32_t number; /* Field tag number */ + PbType type; /* Protobuf type */ + char type_name[256]; /* Fully qualified submessage name (if type == MESSAGE) */ + bool is_repeated; /* True if field is 'repeated' */ + bool is_map; /* True if field is a 'map' */ + bool found; /* True if the lookup succeeded */ +} PbFieldLookup; +/** + * decode_varint: Decodes a Base128 Varint from a byte stream. + * + * @param ptr: Pointer to the start of the byte stream (advanced by the function). + * @param end: Pointer to the end of the byte stream. + * @return: The decoded 64-bit unsigned integer. + * + * Failure Modes: + * - Errors via elog(ERROR) if the stream ends unexpectedly or the varint exceeds 64 bits. + */ static inline uint64 decode_varint(const char **ptr, const char *end) { @@ -66,19 +96,105 @@ decode_varint(const char **ptr, const char *end) unsigned char b = (unsigned char) **ptr; (*ptr)++; result |= ((uint64)(b & 0x7F)) << shift; - if (!(b & 0x80)) { - return result; - } + if (!(b & 0x80)) return result; shift += 7; - if (shift >= 64) { - elog(ERROR, "Varint too large"); - } + if (shift >= 64) elog(ERROR, "Varint too large"); + } + return 0; +} + +/** + * encode_varint: Encodes a 64-bit integer into a Base128 Varint and appends to a StringInfo buffer. + * + * @param val: The 64-bit value to encode. + * @param buf: The PostgreSQL StringInfo buffer to append to. + */ +static inline void +encode_varint(uint64 val, StringInfo buf) +{ + do { + unsigned char b = (unsigned char)(val & 0x7F); + val >>= 7; + if (val) b |= 0x80; + appendStringInfoChar(buf, (char)b); + } while (val); +} + +#define PB_FIELD_TAG(num, type) (((num) << 3) | (type)) + +/** + * hex_val: Converts a hex character to its integer value. + */ +static inline int +hex_val(char c) +{ + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; + return -1; +} + +/** + * skip_field: Skips a field in the Protobuf stream based on its wire type. + * + * @param wire_type: The Protobuf wire type (0, 1, 2, 5). + * @param ptr: Pointer to the start of the field value (advanced by the function). + * @param end: Pointer to the end of the byte stream. + */ +static inline void +skip_field(int wire_type, const char **ptr, const char *end) +{ + switch (wire_type) { + case PB_WIRE_VARINT: + decode_varint(ptr, end); + break; + case PB_WIRE_FIXED64: + *ptr += 8; + break; + case PB_WIRE_LENGTH_DELIMITED: + { + uint64 len = decode_varint(ptr, end); + *ptr += len; + } + break; + case PB_WIRE_FIXED32: + *ptr += 4; + break; } - elog(ERROR, "Unexpected end of varint"); - return 0; // Unreachable } -/* Schema Registry API */ -void pgproto_LoadAllSchemasFromDb(upb_DefPool *pool); +typedef enum { + PB_LOOKUP_OK = 0, + PB_LOOKUP_MSG_NOT_FOUND = 1, + PB_LOOKUP_FIELD_NOT_FOUND = 2 +} PbLookupStatus; + +/* Registry API */ -#endif /* PGPROTO_H */ +/** + * pgproto_lookup_field: Resolves a field name to its metadata in a given message type. + * + * @param message_name: Fully qualified message name (e.g., "example.Order"). + * @param field_name: Name of the field to look up. + * @param out: Pointer to the lookup structure to populate. + * @return: PB_LOOKUP_OK if found, otherwise an error status. + */ +PbLookupStatus pgproto_lookup_field(const char *message_name, const char *field_name, PbFieldLookup *out); + +/** + * pgproto_lookup_field_by_number: Resolves a field tag number to its metadata in a given message type. + * + * @param message_name: Fully qualified message name. + * @param field_number: Tag number of the field. + * @param out: Pointer to the lookup structure to populate. + * @return: PB_LOOKUP_OK if found, otherwise an error status. + */ +PbLookupStatus pgproto_lookup_field_by_number(const char *message_name, uint32_t field_number, PbFieldLookup *out); + +/** + * pgproto_LoadAllSchemasFromDb: Loads all registered schemas into the session cache. + * Must be called before any dynamic lookup if s_schema_loaded is false. + */ +void pgproto_LoadAllSchemasFromDb(void); + +#endif diff --git a/src/registry.c b/src/registry.c index ca9d32e..0235d9b 100644 --- a/src/registry.c +++ b/src/registry.c @@ -1,22 +1,45 @@ #include "pgproto.h" +/* + * SchemaEntry: A linked list entry for the in-memory session cache of registered schemas. + */ +typedef struct SchemaEntry { + char *name; /* Unique schema identifier (usually the .proto filename) */ + char *data; /* Raw FileDescriptorSet binary blob */ + size_t len; /* Length of the binary blob */ + struct SchemaEntry *next; +} SchemaEntry; + +static SchemaEntry *s_schemas = NULL; /* Head of the session schema cache */ +bool s_schema_loaded = false; /* Flag to track if schemas have been loaded from the DB */ + +/** + * pgproto_LoadAllSchemasFromDb: Loads all registered schemas from the PostgreSQL 'pb_schemas' table. + * It clears the existing cache and populates it using SPI (Server Programming Interface). + * + * Summary: + * 1. Checks if schemas are already loaded in this backend session. + * 2. Connects via SPI and selects all from 'pb_schemas'. + * 3. Iterates over tuples, Toasting/copying binary data into the linked list. + */ void -pgproto_LoadAllSchemasFromDb(upb_DefPool *pool) +pgproto_LoadAllSchemasFromDb(void) { - /* - * Loads all registered protobuf schemas from the 'pb_schemas' table - * into the provided upb_DefPool. This is called during extension initialization - * and whenever a new schema is registered to keep the in-memory pool up to date. - * - * It uses Server Programming Interface (SPI) to query the database. - */ int ret; - + if (s_schema_loaded) return; + + // Clear existing schemas + while (s_schemas) { + SchemaEntry *next = s_schemas->next; + free(s_schemas->name); + free(s_schemas->data); + free(s_schemas); + s_schemas = next; + } + SPI_connect(); - ret = SPI_execute("SELECT data FROM public.pb_schemas", true, 0); - + ret = SPI_execute("SELECT name, data FROM public.pb_schemas", true, 0); if (ret != SPI_OK_SELECT) { - elog(WARNING, "Failed to select schemas from database: %d", ret); SPI_finish(); return; } @@ -26,49 +49,236 @@ pgproto_LoadAllSchemasFromDb(upb_DefPool *pool) for (int i = 0; i < SPI_processed; i++) { HeapTuple tuple = tuptable->vals[i]; - bool is_null; - Datum data_datum = SPI_getbinval(tuple, tupdesc, 1, &is_null); + bool is_null_name, is_null_data; + Datum name_datum = SPI_getbinval(tuple, tupdesc, 1, &is_null_name); + Datum data_datum = SPI_getbinval(tuple, tupdesc, 2, &is_null_data); - if (is_null) { - continue; - } + if (is_null_name || is_null_data) continue; + char *name = text_to_cstring(DatumGetTextPP(name_datum)); bytea *data = DatumGetByteaP(data_datum); - size_t data_len = VARSIZE_ANY_EXHDR(data); - char *data_ptr = VARDATA_ANY(data); + size_t len = VARSIZE_ANY_EXHDR(data); - upb_Arena *arena = upb_Arena_New(); - if (!arena) { - elog(WARNING, "Failed to create arena for schema loading"); - continue; - } + SchemaEntry *entry = (SchemaEntry *) malloc(sizeof(SchemaEntry)); + entry->name = strdup(name); + entry->data = (char *) malloc(len); + memcpy(entry->data, VARDATA_ANY(data), len); + entry->len = len; + entry->next = s_schemas; + s_schemas = entry; + + pfree(name); + } + + SPI_finish(); + s_schema_loaded = true; +} - google_protobuf_FileDescriptorSet *set = google_protobuf_FileDescriptorSet_parse(data_ptr, data_len, arena); - if (!set) { - elog(WARNING, "Failed to parse FileDescriptorSet"); - upb_Arena_Free(arena); - continue; +/** + * scan_fields: Scans a DescriptorProto (message definition) for a specific field by name or number. + * + * @param ptr: Start of the DescriptorProto fields. + * @param end: End of the DescriptorProto fields. + * @param target_name: Optional field name to match. + * @param target_number: Optional tag number to match. + * @param out: Populate with field metadata if found. + * @return: True if found. + * + * Summary: + * This is a raw wire-format traversal of the FieldDescriptorProto repeated field. + * It decodes field tags (name, number, type, etc.) on the fly. + */ +static bool +scan_fields(const char *ptr, const char *end, const char *target_name, uint32_t target_number, PbFieldLookup *out) +{ + const char *f_ptr = ptr; + while (f_ptr < end) { + uint64 key = decode_varint(&f_ptr, end); + int field_num = key >> 3; + int wire_type = key & 0x07; + + if (field_num == 2 && wire_type == 2) { // repeated FieldDescriptorProto field + uint64 len = decode_varint(&f_ptr, end); + const char *f_end = f_ptr + len; + const char *curr_f_ptr = f_ptr; + + uint32_t f_num = 0; + PbType f_type = 0; + char f_name[256] = {0}; + char f_type_name[256] = {0}; + bool f_is_repeated = false; + + while (curr_f_ptr < f_end) { + uint64 f_key = decode_varint(&curr_f_ptr, f_end); + int fn = f_key >> 3; + int fwt = f_key & 0x07; + if (fn == 1 && fwt == 2) { // name + uint64 nl = decode_varint(&curr_f_ptr, f_end); + size_t to_copy = nl < 255 ? nl : 255; + memcpy(f_name, curr_f_ptr, to_copy); + f_name[to_copy] = '\0'; + curr_f_ptr += nl; + } else if (fn == 3 && fwt == 0) { // number + f_num = (uint32_t) decode_varint(&curr_f_ptr, f_end); + } else if (fn == 4 && fwt == 0) { // label + uint64 label = decode_varint(&curr_f_ptr, f_end); + f_is_repeated = (label == 3); + } else if (fn == 5 && fwt == 0) { // type + f_type = (PbType) decode_varint(&curr_f_ptr, f_end); + } else if (fn == 6 && fwt == 2) { // type_name + uint64 nl = decode_varint(&curr_f_ptr, f_end); + size_t to_copy = nl < 255 ? nl : 255; + memcpy(f_type_name, curr_f_ptr, to_copy); + f_type_name[to_copy] = '\0'; + curr_f_ptr += nl; + } else { + skip_field(fwt, &curr_f_ptr, f_end); + } + } + if ((target_name && strcmp(f_name, target_name) == 0) || (target_number > 0 && f_num == target_number)) { + strcpy(out->name, f_name); + out->number = f_num; + out->type = f_type; + strcpy(out->type_name, f_type_name); + out->is_repeated = f_is_repeated; + out->is_map = (f_is_repeated && f_type == PB_TYPE_MESSAGE && strstr(f_type_name, "Entry") != NULL); + out->found = true; + return true; + } + f_ptr = f_end; + } else { + skip_field(wire_type, &f_ptr, end); } + } + return false; +} - size_t file_count = 0; - const google_protobuf_FileDescriptorProto *const *files = google_protobuf_FileDescriptorSet_file(set, &file_count); +/** + * scan_messages: Recursively scans a FileDescriptorProto for a message type. + */ +static bool +scan_messages(const char *ptr, const char *end, const char *prefix, const char *target_msg, const char *target_field_name, uint32_t target_field_number, PbFieldLookup *out) +{ + const char *m_ptr = ptr; + while (m_ptr < end) { + uint64 key = decode_varint(&m_ptr, end); + int field_num = key >> 3; + int wire_type = key & 0x07; - for (size_t j = 0; j < file_count; j++) { - upb_Status status; + if ((field_num == 4 || field_num == 3) && wire_type == 2) { // repeated DescriptorProto message_type (4) or nested_type (3) + uint64 len = decode_varint(&m_ptr, end); + const char *msg_inner_end = m_ptr + len; + const char *name_ptr = m_ptr; + char m_name[256] = {0}; + + // Find name first + while (name_ptr < msg_inner_end) { + uint64 mk = decode_varint(&name_ptr, msg_inner_end); + if ((mk >> 3) == 1 && (mk & 0x07) == 2) { + uint64 nl = decode_varint(&name_ptr, msg_inner_end); + size_t to_copy = nl < 255 ? nl : 255; + memcpy(m_name, name_ptr, to_copy); + m_name[to_copy] = '\0'; + break; + } + skip_field(mk & 0x07, &name_ptr, msg_inner_end); + } + + char full_name[512]; + if (prefix && prefix[0]) snprintf(full_name, 512, "%s.%s", prefix, m_name); + else strcpy(full_name, m_name); - upb_Status_Clear(&status); - if (!upb_DefPool_AddFile(pool, files[j], &status)) { - elog(WARNING, "Failed to add file to DefPool: %s", upb_Status_ErrorMessage(&status)); + if (strcmp(full_name, target_msg) == 0) { + if (target_field_name == NULL && target_field_number == 0) return true; + if (scan_fields(m_ptr, msg_inner_end, target_field_name, target_field_number, out)) return true; } + // Recurse for nested types + if (scan_messages(m_ptr, msg_inner_end, full_name, target_msg, target_field_name, target_field_number, out)) return true; + + m_ptr = msg_inner_end; + } else { + skip_field(wire_type, &m_ptr, end); } - upb_Arena_Free(arena); + } + return false; +} + +/** + * pgproto_lookup_internal: Orchestrates the lookup of a field within the loaded schema blobs. + */ +static PbLookupStatus +pgproto_lookup_internal(const char *message_name, const char *field_name, uint32_t field_number, PbFieldLookup *out) +{ + SchemaEntry *entry = s_schemas; + bool msg_type_found = false; + out->found = false; + const char *m_name = message_name; + if (m_name && m_name[0] == '.') m_name++; + + while (entry) { + const char *ptr = entry->data; + const char *end = ptr + entry->len; + while (ptr < end) { + uint64 key = decode_varint(&ptr, end); + if ((key >> 3) == 1 && (key & 0x07) == 2) { // FileDescriptorProto + uint64 len = decode_varint(&ptr, end); + const char *f_end = ptr + len; + const char *f_ptr = ptr; + char package[256] = {0}; + while (f_ptr < f_end) { + uint64 fk = decode_varint(&f_ptr, f_end); + if ((fk >> 3) == 2 && (fk & 0x07) == 2) { + uint64 nl = decode_varint(&f_ptr, f_end); + size_t to_copy = nl < 255 ? nl : 255; + memcpy(package, f_ptr, to_copy); + package[to_copy] = '\0'; + break; + } + skip_field(fk & 0x07, &f_ptr, f_end); + } + + // scan_messages needs to tell us if it at least found the message type + if (scan_messages(ptr, f_end, package, m_name, field_name, field_number, out)) { + return PB_LOOKUP_OK; + } + + // Second pass to see if message type exists in this file + if (!msg_type_found) { + PbFieldLookup dummy; + if (scan_messages(ptr, f_end, package, m_name, NULL, 0, &dummy)) { + msg_type_found = true; + } + } + ptr = f_end; + } else skip_field(key & 0x07, &ptr, end); + } + entry = entry->next; } - SPI_finish(); + return msg_type_found ? PB_LOOKUP_FIELD_NOT_FOUND : PB_LOOKUP_MSG_NOT_FOUND; +} + +PbLookupStatus pgproto_lookup_field(const char *message_name, const char *field_name, PbFieldLookup *out) { + return pgproto_lookup_internal(message_name, field_name, 0, out); +} + +PbLookupStatus pgproto_lookup_field_by_number(const char *message_name, uint32_t field_number, PbFieldLookup *out) { + return pgproto_lookup_internal(message_name, NULL, field_number, out); } PG_FUNCTION_INFO_V1(pb_register_schema); +/** + * pb_register_schema: SQL function to register a new Protobuf schema in the database. + * + * Inputs: + * - name (text): Unique name for the schema. + * - data (bytea): Binary FileDescriptorSet blob. + * + * Summary: + * 1. Inserts the schema into the 'pb_schemas' table. + * 2. Forces a reload of the session cache. + */ Datum pb_register_schema(PG_FUNCTION_ARGS) { @@ -79,73 +289,23 @@ pb_register_schema(PG_FUNCTION_ARGS) int ret; Oid argtypes[2]; Datum Values[2]; - char Nulls[2] = {' ', ' '}; // Not nulls - - upb_Arena *arena; - size_t data_len; - char *data_ptr; - google_protobuf_FileDescriptorSet *set; - size_t file_count; - const google_protobuf_FileDescriptorProto *const *files; + char Nulls[2] = {' ', ' '}; argtypes[0] = TEXTOID; Values[0] = PointerGetDatum(name); - argtypes[1] = BYTEAOID; Values[1] = PointerGetDatum(data); SPI_connect(); - ret = SPI_execute_with_args("INSERT INTO pb_schemas (name, data) VALUES ($1, $2)", 2, argtypes, Values, Nulls, false, 0); - - if (ret != SPI_OK_INSERT) { - elog(ERROR, "Failed to insert schema into database: %d", ret); - } - + if (ret != SPI_OK_INSERT) elog(ERROR, "Failed to insert schema"); SPI_finish(); - // 2. Load into Session Cache (upb_DefPool) - if (s_def_pool == NULL) { - s_def_pool = upb_DefPool_New(); - if (s_def_pool == NULL) { - elog(ERROR, "Failed to create upb_DefPool"); - } - } - - arena = upb_Arena_New(); - if (arena == NULL) { - elog(ERROR, "Failed to create upb_Arena"); - } - - data_len = VARSIZE_ANY_EXHDR(data); - data_ptr = VARDATA_ANY(data); - - set = google_protobuf_FileDescriptorSet_parse(data_ptr, data_len, arena); - if (set == NULL) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to parse FileDescriptorSet binary"); - } + s_schema_loaded = false; + pgproto_LoadAllSchemasFromDb(); - file_count = 0; - files = google_protobuf_FileDescriptorSet_file(set, &file_count); - - for (size_t i = 0; i < file_count; i++) { - upb_Status status; - const upb_FileDef *file_def; - - upb_Status_Clear(&status); - file_def = upb_DefPool_AddFile(s_def_pool, files[i], &status); - if (file_def == NULL) { - upb_Arena_Free(arena); - elog(ERROR, "Failed to add schema to upb_DefPool: %s", upb_Status_ErrorMessage(&status)); - } - } - - upb_Arena_Free(arena); - - elog(INFO, "Successfully registered and cached schema: %s", name_str); + elog(INFO, "Successfully registered schema: %s", name_str); pfree(name_str); - PG_RETURN_VOID(); } diff --git a/vendor/upb/BUILD b/vendor/upb/BUILD deleted file mode 100644 index 5a03118..0000000 --- a/vendor/upb/BUILD +++ /dev/null @@ -1,351 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_python//python:defs.bzl", "py_binary") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") -load("//upb/bazel/private:upb_proto_library_internal/copts.bzl", "upb_proto_library_copts") -load("//upb/bazel/private/oss:amalgamation.bzl", "upb_amalgamation") # buildifier: disable=bzl-visibility - -package(default_applicable_licenses = ["//:license"]) - -licenses(["notice"]) - -exports_files(["LICENSE"]) - -exports_files( - [ - "BUILD", - ], - visibility = ["//upb/cmake:__pkg__"], -) - -config_setting( - name = "windows", - constraint_values = ["@platforms//os:windows"], - visibility = [ - "//benchmarks:__subpackages__", - "//hpb:__subpackages__", - "//hpb_generator:__subpackages__", - "//lua:__pkg__", - "//python:__pkg__", - "//upb:__subpackages__", - "//upb_generator:__subpackages__", - ], -) - -bool_flag( - name = "fasttable_enabled", - build_setting_default = False, - visibility = [ - "//upb/bazel:__pkg__", - ], -) - -config_setting( - name = "fasttable_enabled_setting", - flag_values = {"//upb:fasttable_enabled": "true"}, - visibility = [ - "//benchmarks:__subpackages__", - "//lua:__pkg__", - "//python:__pkg__", - "//upb:__subpackages__", - "//upb_generator:__subpackages__", - ], -) - -upb_proto_library_copts( - name = "upb_proto_library_copts", - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//upb/bazel:__pkg__"], -) - -# Please update copy.bara.sky target = ":friends" if -# you make changes to this list. -package_group( - name = "friends", - packages = ["//..."], -) - -package_group( - name = "friend_generators", - packages = ["//..."], -) - -# Common support routines used by generated code. This library has no -# implementation, but depends on :upb and exposes a few more hdrs. -# -# This is public only because we have no way of visibility-limiting it to -# upb_c_proto_library() only. This interface is not stable and by using it you -# give up any backward compatibility guarantees. -cc_library( - name = "generated_code_support", - hdrs = ["generated_code_support.h"], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - textual_hdrs = [ - "//upb/port:inc", - ], - visibility = [ - "//pkg:__pkg__", - "//upb/reflection:__pkg__", - "//upb_generator:__subpackages__", - ], - deps = [ - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/message:internal", - "//upb/mini_descriptor", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/wire", - ] + select({ - ":fasttable_enabled_setting": [ - "//upb/wire/decode_fast:field_parsers", - ], - "//conditions:default": [], - }), -) - -# Common support code for C++ generated code. -cc_library( - name = "generated_cpp_support", - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - textual_hdrs = [ - "//upb/port:inc", - ], - visibility = ["//hpb/bazel:__pkg__"], -) - -# Amalgamation ################################################################# - -upb_amalgamation( - name = "gen_amalgamation", - outs = [ - "upb.c", - "upb.h", - ], - libs = [ - ":generated_code_support", - "//src/google/protobuf:descriptor_upb_c_proto", - "//src/google/protobuf:descriptor_upb_minitable_proto", - "//upb/base", - "//upb/base:internal", - "//upb/hash:hash", - "//upb/lex:lex", - "//upb/mem", - "//upb/mem:internal", - "//upb/message", - "//upb/message:compare", - "//upb/message:copy", - "//upb/message:internal", - "//upb/message:iterator", - "//upb/message:types", - "//upb/mini_descriptor", - "//upb/mini_descriptor:internal", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/reflection", - "//upb/reflection:descriptor_upb_proto", - "//upb/reflection:internal", - "//upb/text:debug", - "//upb/text:internal", - "//upb/wire", - "//upb/wire:byte_size", - "//upb/wire:decoder", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:eps_copy_input_stream_internal", - "//upb/wire:reader", - "//upb/wire:reader_internal", - "//upb/wire:writer", - ], - strip_import_prefix = ["src"], - visibility = ["//rust:__pkg__"], -) - -cc_library( - name = "amalgamation", - srcs = ["upb.c"], - hdrs = ["upb.h"], - copts = UPB_DEFAULT_COPTS, - deps = ["//third_party/utf8_range"], -) - -upb_amalgamation( - name = "gen_php_amalgamation", - outs = [ - "php-upb.c", - "php-upb.h", - ], - libs = [ - ":generated_code_support", - "//src/google/protobuf:descriptor_upb_c_proto", - "//src/google/protobuf:descriptor_upb_minitable_proto", - "//src/google/protobuf:descriptor_upb_reflection_proto", - "//upb/base", - "//upb/base:internal", - "//upb/hash:hash", - "//upb/json", - "//upb/lex:lex", - "//upb/mem", - "//upb/mem:internal", - "//upb/message", - "//upb/message:compare", - "//upb/message:copy", - "//upb/message:internal", - "//upb/message:iterator", - "//upb/message:types", - "//upb/mini_descriptor", - "//upb/mini_descriptor:internal", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/reflection", - "//upb/reflection:descriptor_upb_proto", - "//upb/reflection:internal", - "//upb/wire", - "//upb/wire:decoder", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:eps_copy_input_stream_internal", - "//upb/wire:reader", - "//upb/wire:reader_internal", - "//upb/wire:writer", - ], - prefix = "php-", - strip_import_prefix = ["src"], - visibility = ["@com_google_protobuf//php:__subpackages__"], -) - -cc_library( - name = "php_amalgamation", - srcs = ["php-upb.c"], - hdrs = ["php-upb.h"], - copts = UPB_DEFAULT_COPTS, - deps = ["//third_party/utf8_range"], -) - -upb_amalgamation( - name = "gen_ruby_amalgamation", - outs = [ - "ruby-upb.c", - "ruby-upb.h", - ], - libs = [ - ":generated_code_support", - "//src/google/protobuf:descriptor_upb_c_proto", - "//src/google/protobuf:descriptor_upb_minitable_proto", - "//upb/base", - "//upb/base:internal", - "//upb/hash:hash", - "//upb/json", - "//upb/lex:lex", - "//upb/mem", - "//upb/mem:internal", - "//upb/message", - "//upb/message:compare", - "//upb/message:copy", - "//upb/message:internal", - "//upb/message:iterator", - "//upb/message:types", - "//upb/mini_descriptor", - "//upb/mini_descriptor:internal", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/reflection", - "//upb/reflection:descriptor_upb_proto", - "//upb/reflection:internal", - "//upb/util:def_to_proto", - "//upb/wire", - "//upb/wire:decoder", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:eps_copy_input_stream_internal", - "//upb/wire:reader", - "//upb/wire:reader_internal", - "//upb/wire:writer", - ], - prefix = "ruby-", - strip_import_prefix = ["src"], - visibility = ["@com_google_protobuf//ruby:__subpackages__"], -) - -cc_library( - name = "ruby_amalgamation", - srcs = ["ruby-upb.c"], - hdrs = ["ruby-upb.h"], - copts = UPB_DEFAULT_COPTS, - deps = ["//third_party/utf8_range"], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.h", - ], - exclude = [ - "**/conformance_upb.c", - "reflection/stage0/**/*", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_protos", - srcs = [ - "//src/google/protobuf:test_messages_proto2.proto", - "//src/google/protobuf:test_messages_proto3.proto", - "//src/google/protobuf:well_known_type_protos", - "//upb/json:test_protos", - "//upb/message:test_protos", - "//upb/mini_table:test_protos", - "//upb/test:test_protos", - "//upb/util:test_protos", - "//upb/wire:test_protos", - ], - visibility = ["//pkg:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = [ - "//upb/hash:test_srcs", - "//upb/json:test_srcs", - "//upb/lex:test_srcs", - "//upb/mem:test_srcs", - "//upb/message:test_srcs", - "//upb/mini_descriptor:test_srcs", - "//upb/mini_table:test_srcs", - "//upb/test:test_srcs", - "//upb/util:test_srcs", - "//upb/wire:test_srcs", - ], - visibility = ["//pkg:__pkg__"], -) - -cc_library( - name = "test_util", - testonly = True, - visibility = ["//pkg:__pkg__"], - deps = [ - "//upb/test:fuzz_util", - "//upb/test:parse_text_proto", - "//upb/util:def_to_proto_test_lib", - "//upb/wire/test_util:field_types", - "//upb/wire/test_util:make_mini_table", - "//upb/wire/test_util:wire_message", - ], -) diff --git a/vendor/upb/README.md b/vendor/upb/README.md deleted file mode 100644 index 61eaddd..0000000 --- a/vendor/upb/README.md +++ /dev/null @@ -1,84 +0,0 @@ - -# μpb: small, fast C protos - -μpb (often written 'upb') is a small -[protobuf](https://github.com/protocolbuffers/protobuf) implementation written -in C. - -upb is the core runtime for protobuf languages extensions in -[Ruby](https://github.com/protocolbuffers/protobuf/tree/main/ruby), -[PHP](https://github.com/protocolbuffers/protobuf/tree/main/php), and -[Python](https://github.com/protocolbuffers/protobuf/tree/main/python). - -While upb offers a C API, the C API & ABI **are not stable**. For this reason, -upb is not generally offered as a C library for direct consumption, and there -are no releases. - -## Features - -upb has comparable speed to protobuf C++, but is an order of magnitude smaller -in code size. - -Like the main protobuf implementation in C++, it supports: - -- a generated API (in C) -- reflection -- binary & JSON wire formats -- text format serialization -- all standard features of protobufs (oneofs, maps, unknown fields, extensions, - etc.) -- full conformance with the protobuf conformance tests - -upb also supports some features that C++ does not: - -- **optional reflection:** generated messages are agnostic to whether - reflection will be linked in or not. -- **no global state:** no pre-main registration or other global state. -- **fast reflection-based parsing:** messages loaded at runtime parse - just as fast as compiled-in messages. - -However there are a few features it does not support: - -- text format parsing -- deep descriptor verification: upb's descriptor validation is not as exhaustive - as `protoc`. - -## Install - -For Ruby, use [RubyGems](https://rubygems.org/gems/google-protobuf): - -``` -$ gem install google-protobuf -``` - -For PHP, use [PECL](https://pecl.php.net/package/protobuf): - -``` -$ sudo pecl install protobuf -``` - -For Python, use [PyPI](https://pypi.org/project/protobuf/): - -``` -$ sudo pip install protobuf -``` - -Alternatively, you can build and install upb using -[vcpkg](https://github.com/microsoft/vcpkg/) dependency manager: - - git clone https://github.com/Microsoft/vcpkg.git - cd vcpkg - ./bootstrap-vcpkg.sh - ./vcpkg integrate install - ./vcpkg install upb - -The upb port in vcpkg is kept up to date by microsoft team members and community -contributors. - -If the version is out of date, please -[create an issue or pull request](https://github.com/Microsoft/vcpkg) on the -vcpkg repository. - -## Contributing - -Please see [CONTRIBUTING.md](CONTRIBUTING.md). diff --git a/vendor/upb/base/BUILD b/vendor/upb/base/BUILD deleted file mode 100644 index 6c9f9c6..0000000 --- a/vendor/upb/base/BUILD +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "base", - srcs = [ - "status.c", - ], - hdrs = [ - "descriptor_constants.h", - "error_handler.h", - "status.h", - "status.hpp", - "string_view.h", - "upcast.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/port", - ], -) - -cc_library( - name = "internal", - hdrs = [ - "internal/endian.h", - "internal/log2.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = ["//upb/port"], -) - -cc_test( - name = "log2_test", - srcs = ["internal/log2_test.cc"], - deps = [ - ":internal", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "string_view_test", - srcs = ["string_view_test.cc"], - deps = [ - ":base", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - "**/*.hpp", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) diff --git a/vendor/upb/base/descriptor_constants.h b/vendor/upb/base/descriptor_constants.h deleted file mode 100644 index 6aa2140..0000000 --- a/vendor/upb/base/descriptor_constants.h +++ /dev/null @@ -1,111 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_ -#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_ - -// Must be last. -#include "upb/port/def.inc" - -// The types a field can have. Note that this list is not identical to the -// types defined in descriptor.proto, which gives INT32 and SINT32 separate -// types (we distinguish the two with the "integer encoding" enum below). -// This enum is an internal convenience only and has no meaning outside of upb. -typedef enum { - kUpb_CType_Bool = 1, - kUpb_CType_Float = 2, - kUpb_CType_Int32 = 3, - kUpb_CType_UInt32 = 4, - kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename - kUpb_CType_Message = 6, - kUpb_CType_Double = 7, - kUpb_CType_Int64 = 8, - kUpb_CType_UInt64 = 9, - kUpb_CType_String = 10, - kUpb_CType_Bytes = 11 -} upb_CType; - -// The repeated-ness of each field; this matches descriptor.proto. -typedef enum { - kUpb_Label_Optional = 1, - kUpb_Label_Required = 2, - kUpb_Label_Repeated = 3 -} upb_Label; - -// Descriptor types, as defined in descriptor.proto. -typedef enum { - kUpb_FieldType_Double = 1, - kUpb_FieldType_Float = 2, - kUpb_FieldType_Int64 = 3, - kUpb_FieldType_UInt64 = 4, - kUpb_FieldType_Int32 = 5, - kUpb_FieldType_Fixed64 = 6, - kUpb_FieldType_Fixed32 = 7, - kUpb_FieldType_Bool = 8, - kUpb_FieldType_String = 9, - kUpb_FieldType_Group = 10, - kUpb_FieldType_Message = 11, - kUpb_FieldType_Bytes = 12, - kUpb_FieldType_UInt32 = 13, - kUpb_FieldType_Enum = 14, - kUpb_FieldType_SFixed32 = 15, - kUpb_FieldType_SFixed64 = 16, - kUpb_FieldType_SInt32 = 17, - kUpb_FieldType_SInt64 = 18, -} upb_FieldType; - -#define kUpb_FieldType_SizeOf 19 - -#ifdef __cplusplus -extern "C" { -#endif - -// Convert from upb_FieldType to upb_CType -UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) { - static const upb_CType c_type[] = { - kUpb_CType_Double, // kUpb_FieldType_Double - kUpb_CType_Float, // kUpb_FieldType_Float - kUpb_CType_Int64, // kUpb_FieldType_Int64 - kUpb_CType_UInt64, // kUpb_FieldType_UInt64 - kUpb_CType_Int32, // kUpb_FieldType_Int32 - kUpb_CType_UInt64, // kUpb_FieldType_Fixed64 - kUpb_CType_UInt32, // kUpb_FieldType_Fixed32 - kUpb_CType_Bool, // kUpb_FieldType_Bool - kUpb_CType_String, // kUpb_FieldType_String - kUpb_CType_Message, // kUpb_FieldType_Group - kUpb_CType_Message, // kUpb_FieldType_Message - kUpb_CType_Bytes, // kUpb_FieldType_Bytes - kUpb_CType_UInt32, // kUpb_FieldType_UInt32 - kUpb_CType_Enum, // kUpb_FieldType_Enum - kUpb_CType_Int32, // kUpb_FieldType_SFixed32 - kUpb_CType_Int64, // kUpb_FieldType_SFixed64 - kUpb_CType_Int32, // kUpb_FieldType_SInt32 - kUpb_CType_Int64, // kUpb_FieldType_SInt64 - }; - - // -1 here because the enum is one-based but the table is zero-based. - return c_type[field_type - 1]; -} - -UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) { - // clang-format off - const unsigned kUnpackableTypes = - (1 << kUpb_FieldType_String) | - (1 << kUpb_FieldType_Bytes) | - (1 << kUpb_FieldType_Message) | - (1 << kUpb_FieldType_Group); - // clang-format on - return (1 << field_type) & ~kUnpackableTypes; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */ diff --git a/vendor/upb/base/error_handler.h b/vendor/upb/base/error_handler.h deleted file mode 100644 index 24c95d0..0000000 --- a/vendor/upb/base/error_handler.h +++ /dev/null @@ -1,79 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef GOOGLE_UPB_UPB_BASE_ERROR_HANDLER_H__ -#define GOOGLE_UPB_UPB_BASE_ERROR_HANDLER_H__ - -#include - -// Must be last. -#include "upb/port/def.inc" - -// upb_ErrorHandler is a standard longjmp()-based exception handler for UPB. -// It is used for efficient error handling in cases where longjmp() is safe to -// use, such as in highly performance-sensitive C parsing code. -// -// This structure contains both a jmp_buf and an error code; the error code is -// stored in the structure prior to calling longjmp(). This is necessary because -// per the C standard, it is not possible to store the result of setjmp(), so -// the error code must be passed out-of-band. -// -// upb_ErrorHandler is generally not C++-compatible, because longjmp() does not -// run C++ destructors. So any library that supports upb_ErrorHandler should -// also support a regular return-based error handling mechanism. (Note: we -// could conceivably extend this to take a callback, which could either call -// longjmp() or throw a C++ exception. But since C++ exceptions are forbidden -// by the C++ style guide, there's not likely to be a demand for this.) -// -// To support both cases (longjmp() or return-based status) efficiently, code -// can be written like this: -// -// UPB_ATTR_CONST bool upb_Arena_HasErrHandler(const upb_Arena* a); -// -// INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { -// if (UPB_UNLIKELY(a->end - a->ptr < size)) { -// void* ret = upb_Arena_MallocFallback(a, size); -// UPB_MAYBE_ASSUME(upb_Arena_HasErrHandler(a), ret != NULL); -// return ret; -// } -// void* ret = a->ptr; -// a->ptr += size; -// UPB_ASSUME(ret != NULL); -// return ret; -// } -// -// If the optimizer can prove that an error handler is present, it can assume -// that upb_Arena_Malloc() will not return NULL. - -// We need to standardize on any error code that might be thrown by an error -// handler. - -typedef enum { - kUpb_ErrorCode_Ok = 0, - kUpb_ErrorCode_OutOfMemory = 1, - kUpb_ErrorCode_Malformed = 2, -} upb_ErrorCode; - -typedef struct { - int code; - jmp_buf buf; -} upb_ErrorHandler; - -UPB_INLINE void upb_ErrorHandler_Init(upb_ErrorHandler* e) { - e->code = kUpb_ErrorCode_Ok; -} - -UPB_INLINE UPB_NORETURN void upb_ErrorHandler_ThrowError(upb_ErrorHandler* e, - int code) { - UPB_ASSERT(code != kUpb_ErrorCode_Ok); - e->code = code; - UPB_LONGJMP(e->buf, 1); -} - -#include "upb/port/undef.inc" - -#endif // GOOGLE_UPB_UPB_BASE_ERROR_HANDLER_H__ diff --git a/vendor/upb/base/internal/endian.h b/vendor/upb/base/internal/endian.h deleted file mode 100644 index 0897427..0000000 --- a/vendor/upb/base/internal/endian.h +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_BASE_INTERNAL_ENDIAN_H_ -#define UPB_BASE_INTERNAL_ENDIAN_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool upb_IsLittleEndian(void) { - const int x = 1; - return *(char*)&x == 1; -} - -UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) { - if (upb_IsLittleEndian()) return val; - - return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | - ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); -} - -UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) { - if (upb_IsLittleEndian()) return val; - - const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32; - const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32)); - return hi | lo; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */ diff --git a/vendor/upb/base/internal/log2.h b/vendor/upb/base/internal/log2.h deleted file mode 100644 index 5bd5f44..0000000 --- a/vendor/upb/base/internal/log2.h +++ /dev/null @@ -1,64 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ -/// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_BASE_INTERNAL_LOG2_H_ -#define UPB_BASE_INTERNAL_LOG2_H_ - -#include -#include -#include - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE int upb_Log2Ceiling(size_t x) { - if (x <= 1) return 0; -#if SIZE_MAX == ULLONG_MAX && UPB_HAS_BUILTIN(__builtin_clzll) - return (sizeof(size_t) * CHAR_BIT) - __builtin_clzll(x - 1); -#elif SIZE_MAX == ULONG_MAX && UPB_HAS_BUILTIN(__builtin_clzl) - return (sizeof(size_t) * CHAR_BIT) - __builtin_clzl(x - 1); -#elif SIZE_MAX == UINT_MAX && UPB_HAS_BUILTIN(__builtin_clz) - return (sizeof(size_t) * CHAR_BIT) - __builtin_clz(x - 1); -#else - if (x > SIZE_MAX / 2) return sizeof(size_t) * CHAR_BIT; - int lg2 = 0; - while ((1 << lg2) < x) lg2++; - return lg2; -#endif -} - -// Returns the smallest power of two that is greater than or equal to x. Returns -// SIZE_MAX if the computation would overflow. -UPB_INLINE size_t upb_RoundUpToPowerOfTwo(size_t x) { - int lg2 = upb_Log2Ceiling(x); - UPB_ASSERT(lg2 >= 0 && lg2 <= (int)sizeof(size_t) * CHAR_BIT); - if (lg2 == sizeof(size_t) * CHAR_BIT) { - return SIZE_MAX; - } - return ((size_t)1) << lg2; -} - -UPB_INLINE bool upb_ShlOverflow(size_t* a, unsigned int b) { - if (*a > (SIZE_MAX >> b)) { - return true; - } - *a <<= b; - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_BASE_INTERNAL_LOG2_H_ */ diff --git a/vendor/upb/base/internal/log2_test.cc b/vendor/upb/base/internal/log2_test.cc deleted file mode 100644 index 322f97c..0000000 --- a/vendor/upb/base/internal/log2_test.cc +++ /dev/null @@ -1,51 +0,0 @@ -#include "upb/base/internal/log2.h" - -#include -#include -#include - -#include - -namespace { - -TEST(Log2Test, Log2Ceiling) { - EXPECT_EQ(upb_Log2Ceiling(0), 0); - EXPECT_EQ(upb_Log2Ceiling(1), 0); - EXPECT_EQ(upb_Log2Ceiling(2), 1); - EXPECT_EQ(upb_Log2Ceiling(3), 2); - EXPECT_EQ(upb_Log2Ceiling(4), 2); - EXPECT_EQ(upb_Log2Ceiling(5), 3); - EXPECT_EQ(upb_Log2Ceiling(6), 3); - EXPECT_EQ(upb_Log2Ceiling(7), 3); - EXPECT_EQ(upb_Log2Ceiling(8), 3); - - EXPECT_EQ(upb_Log2Ceiling(SIZE_MAX), sizeof(size_t) * CHAR_BIT); -} - -TEST(Log2Test, RoundUpToPowerOfTwo) { - EXPECT_EQ(upb_RoundUpToPowerOfTwo(0), 1); - EXPECT_EQ(upb_RoundUpToPowerOfTwo(1), 1); - EXPECT_EQ(upb_RoundUpToPowerOfTwo(2), 2); - EXPECT_EQ(upb_RoundUpToPowerOfTwo(3), 4); - EXPECT_EQ(upb_RoundUpToPowerOfTwo(4), 4); - EXPECT_EQ(upb_RoundUpToPowerOfTwo(5), 8); -} - -TEST(Log2Test, ShlOverflow) { - size_t a = 1; - EXPECT_FALSE(upb_ShlOverflow(&a, 0)); - EXPECT_EQ(a, 1); - EXPECT_FALSE(upb_ShlOverflow(&a, 1)); - EXPECT_EQ(a, 2); - EXPECT_FALSE(upb_ShlOverflow(&a, 2)); - EXPECT_EQ(a, 8); - - a = SIZE_MAX / 2; - EXPECT_FALSE(upb_ShlOverflow(&a, 1)); - EXPECT_EQ(a, SIZE_MAX - 1); - - a = (SIZE_MAX / 2) + 1; - EXPECT_TRUE(upb_ShlOverflow(&a, 1)); -} - -} // namespace diff --git a/vendor/upb/base/status.c b/vendor/upb/base/status.c deleted file mode 100644 index f2cd0a6..0000000 --- a/vendor/upb/base/status.c +++ /dev/null @@ -1,61 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/base/status.h" - -#include -#include -#include -#include -#include - -// Must be last. -#include "upb/port/def.inc" - -void upb_Status_Clear(upb_Status* status) { - if (!status) return; - status->ok = true; - status->msg[0] = '\0'; -} - -bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } - -const char* upb_Status_ErrorMessage(const upb_Status* status) { - return status->msg; -} - -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { - if (!status) return; - status->ok = false; - strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - upb_Status_VSetErrorFormat(status, fmt, args); - va_end(args); -} - -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - if (!status) return; - status->ok = false; - vsnprintf(status->msg, sizeof(status->msg), fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - size_t len; - if (!status) return; - status->ok = false; - len = strlen(status->msg); - vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} diff --git a/vendor/upb/base/status.h b/vendor/upb/base/status.h deleted file mode 100644 index 0527c2b..0000000 --- a/vendor/upb/base/status.h +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_BASE_STATUS_H_ -#define UPB_BASE_STATUS_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -#define _kUpb_Status_MaxMessage 511 - -typedef struct { - bool ok; - char msg[_kUpb_Status_MaxMessage]; // Error message; NULL-terminated. -} upb_Status; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API const char* upb_Status_ErrorMessage(const upb_Status* status); -UPB_API bool upb_Status_IsOk(const upb_Status* status); - -// These are no-op if |status| is NULL. -UPB_API void upb_Status_Clear(upb_Status* status); -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg); -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) - UPB_PRINTF(2, 3); -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) UPB_PRINTF(2, 0); -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) UPB_PRINTF(2, 0); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_BASE_STATUS_H_ */ diff --git a/vendor/upb/base/status.hpp b/vendor/upb/base/status.hpp deleted file mode 100644 index b6f3edb..0000000 --- a/vendor/upb/base/status.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_BASE_STATUS_HPP_ -#define UPB_BASE_STATUS_HPP_ - -#ifdef __cplusplus - -#include "upb/base/status.h" - -namespace upb { - -class Status final { - public: - Status() { upb_Status_Clear(&status_); } - - upb_Status* ptr() { return &status_; } - - // Returns true if there is no error. - bool ok() const { return upb_Status_IsOk(&status_); } - - // Guaranteed to be NULL-terminated. - const char* error_message() const { - return upb_Status_ErrorMessage(&status_); - } - - // The error message will be truncated if it is longer than - // _kUpb_Status_MaxMessage-4. - void SetErrorMessage(const char* msg) { - upb_Status_SetErrorMessage(&status_, msg); - } - void SetFormattedErrorMessage(const char* fmt, ...) { - va_list args; - va_start(args, fmt); - upb_Status_VSetErrorFormat(&status_, fmt, args); - va_end(args); - } - - // Resets the status to a successful state with no message. - void Clear() { upb_Status_Clear(&status_); } - - private: - upb_Status status_; -}; - -} // namespace upb - -#endif // __cplusplus - -#endif // UPB_BASE_STATUS_HPP_ diff --git a/vendor/upb/base/string_view.h b/vendor/upb/base/string_view.h deleted file mode 100644 index a6d4989..0000000 --- a/vendor/upb/base/string_view.h +++ /dev/null @@ -1,74 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd -#ifndef UPB_BASE_STRING_VIEW_H_ -#define UPB_BASE_STRING_VIEW_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -#define UPB_STRINGVIEW_INIT(ptr, len) \ - { ptr, len } - -#define UPB_STRINGVIEW_FORMAT "%.*s" -#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data - -// LINT.IfChange(struct_definition) -typedef struct { - const char* data; - size_t size; -} upb_StringView; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data, - size_t size) { - upb_StringView ret; - ret.data = data; - ret.size = size; - return ret; -} - -UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) { - return upb_StringView_FromDataAndSize(data, strlen(data)); -} - -UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { - return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size)); -} - -// Compares StringViews following strcmp rules. -// Please note this comparison is neither unicode nor locale aware. -UPB_INLINE int upb_StringView_Compare(upb_StringView a, upb_StringView b) { - int result = memcmp(a.data, b.data, UPB_MIN(a.size, b.size)); - if (result != 0) return result; - if (a.size < b.size) { - return -1; - } else if (a.size > b.size) { - return 1; - } else { - return 0; - } -} - -// LINT.ThenChange( -// GoogleInternalName1, -// //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string, -// //depot/google3/third_party/upb/bits/typescript/string_view.ts -// ) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_BASE_STRING_VIEW_H_ */ diff --git a/vendor/upb/base/string_view_test.cc b/vendor/upb/base/string_view_test.cc deleted file mode 100644 index 9b82903..0000000 --- a/vendor/upb/base/string_view_test.cc +++ /dev/null @@ -1,69 +0,0 @@ -#include "upb/base/string_view.h" - -#include - -#include - -namespace { - -TEST(upb_StringView, Compare_Eq) { - std::string s1("12345"); - std::string s2("12345"); - - upb_StringView h1 = upb_StringView_FromDataAndSize(s1.data(), s1.size()); - upb_StringView h2 = upb_StringView_FromDataAndSize(s2.data(), s2.size()); - - ASSERT_EQ(upb_StringView_Compare(h1, h2), 0); -} - -TEST(upb_StringView, Compare_Eq_Shorter) { - std::string s1("1234"); // s1 is shorter. - std::string s2("12345"); - - upb_StringView h1 = upb_StringView_FromDataAndSize(s1.data(), s1.size()); - upb_StringView h2 = upb_StringView_FromDataAndSize(s2.data(), s2.size()); - - ASSERT_LT(upb_StringView_Compare(h1, h2), 0); -} - -TEST(upb_StringView, Compare_Eq_Longer) { - std::string s1("123456"); // s1 is longer. - std::string s2("12345"); - - upb_StringView h1 = upb_StringView_FromDataAndSize(s1.data(), s1.size()); - upb_StringView h2 = upb_StringView_FromDataAndSize(s2.data(), s2.size()); - - ASSERT_GT(upb_StringView_Compare(h1, h2), 0); -} - -TEST(upb_StringView, Compare_Less) { - std::string s1("12245"); // 2 < 3 - std::string s2("12345"); - - upb_StringView h1 = upb_StringView_FromDataAndSize(s1.data(), s1.size()); - upb_StringView h2 = upb_StringView_FromDataAndSize(s2.data(), s2.size()); - - ASSERT_LT(upb_StringView_Compare(h1, h2), 0); -} - -TEST(upb_StringView, Compare_Greater) { - std::string s1("12445"); // 4 > 3 - std::string s2("12345"); - - upb_StringView h1 = upb_StringView_FromDataAndSize(s1.data(), s1.size()); - upb_StringView h2 = upb_StringView_FromDataAndSize(s2.data(), s2.size()); - - ASSERT_GT(upb_StringView_Compare(h1, h2), 0); -} - -TEST(upb_StringView, Compare_Greater_Shorter) { - std::string s1("1244"); // s1 is shorter but 4 > 3. - std::string s2("12345"); - - upb_StringView h1 = upb_StringView_FromDataAndSize(s1.data(), s1.size()); - upb_StringView h2 = upb_StringView_FromDataAndSize(s2.data(), s2.size()); - - ASSERT_GT(upb_StringView_Compare(h1, h2), 0); -} - -} // namespace diff --git a/vendor/upb/base/upcast.h b/vendor/upb/base/upcast.h deleted file mode 100644 index 92d699d..0000000 --- a/vendor/upb/base/upcast.h +++ /dev/null @@ -1,29 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_BASE_UPCAST_H_ -#define UPB_BASE_UPCAST_H_ - -// Must be last. -#include "upb/port/def.inc" - -// This macro provides a way to upcast message pointers in a way that is -// somewhat more bulletproof than blindly casting a pointer. Example: -// -// typedef struct { -// upb_Message UPB_PRIVATE(base); -// } pkg_FooMessage; -// -// void f(pkg_FooMessage* msg) { -// upb_Decode(UPB_UPCAST(msg), ...); -// } - -#define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only) - -#include "upb/port/undef.inc" - -#endif /* UPB_BASE_UPCAST_H_ */ diff --git a/vendor/upb/bazel/BUILD b/vendor/upb/bazel/BUILD deleted file mode 100644 index 5a45e28..0000000 --- a/vendor/upb/bazel/BUILD +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -package(default_applicable_licenses = ["//:license"]) - -licenses(["notice"]) - -bzl_library( - name = "upb_proto_library_bzl", - srcs = [ - "upb_c_proto_library.bzl", - "upb_minitable_proto_library.bzl", - "upb_proto_library.bzl", - "upb_proto_reflection_library.bzl", - "visibility.bzl", - ], - visibility = [ - "//visibility:public", - ], - deps = [ - "//bazel/common:proto_common_bzl", - "//bazel/common:proto_info_bzl", - "//upb/bazel/private:upb_proto_library_internal_bzl", - "@rules_cc//cc/common", - ], -) diff --git a/vendor/upb/bazel/copts.bzl b/vendor/upb/bazel/copts.bzl deleted file mode 100644 index dfbf84c..0000000 --- a/vendor/upb/bazel/copts.bzl +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -"""Common copts for building upb.""" - -visibility([ - "//benchmarks/...", - "//lua/...", - "//python/...", - "//upb/...", - "//upb_generator/...", -]) - -_DEFAULT_CPPOPTS = [] -_DEFAULT_COPTS = [ - # this is a compile error in C++ clang and GNU C, but not clang C by default - "-Werror=incompatible-pointer-types", - # GCC does not seem to support the no_sanitize attribute in some places - # where we use it. - "-Wno-error=attributes", -] - -_DEFAULT_CPPOPTS.extend([ - "-Wextra", - # "-Wshorten-64-to-32", # not in GCC (and my Kokoro images doesn't have Clang) - "-Wno-unused-parameter", - "-Wno-long-long", -]) -_DEFAULT_COPTS.extend([ - "-std=c99", - "-Wall", - "-Wstrict-prototypes", - # GCC (at least) emits spurious warnings for this that cannot be fixed - # without introducing redundant initialization (with runtime cost): - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 - #"-Wno-maybe-uninitialized", -]) - -UPB_DEFAULT_CPPOPTS = select({ - "//upb:windows": [], - "//conditions:default": _DEFAULT_CPPOPTS, -}) + select({ - "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"], - "//conditions:default": [], -}) - -UPB_DEFAULT_COPTS = select({ - "//upb:windows": [], - "//conditions:default": _DEFAULT_COPTS, -}) + select({ - "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"], - "//conditions:default": [], -}) - -UPB_DEFAULT_FEATURES = [ -] diff --git a/vendor/upb/bazel/private/BUILD b/vendor/upb/bazel/private/BUILD deleted file mode 100644 index 0c7ac5d..0000000 --- a/vendor/upb/bazel/private/BUILD +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@bazel_skylib//lib:selects.bzl", "selects") - -bzl_library( - name = "upb_proto_library_internal_bzl", - srcs = [ - "upb_proto_library_internal/aspect.bzl", - "upb_proto_library_internal/cc_library_func.bzl", - "upb_proto_library_internal/copts.bzl", - "upb_proto_library_internal/rule.bzl", - ], - visibility = [ - "//upb/bazel:__pkg__", - ], - deps = [ - "//bazel/common:proto_common_bzl", - "//bazel/common:proto_info_bzl", - "@bazel_skylib//lib:paths", - "@bazel_tools//tools/cpp:toolchain_utils.bzl", - ], -) diff --git a/vendor/upb/bazel/private/oss/BUILD b/vendor/upb/bazel/private/oss/BUILD deleted file mode 100644 index 7223b75..0000000 --- a/vendor/upb/bazel/private/oss/BUILD +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@bazel_skylib//lib:selects.bzl", "selects") -load("@rules_python//python:defs.bzl", "py_binary") - -py_binary( - name = "amalgamate", - srcs = ["amalgamate.py"], - visibility = ["//visibility:private"], -) diff --git a/vendor/upb/bazel/private/oss/amalgamate.py b/vendor/upb/bazel/private/oss/amalgamate.py deleted file mode 100755 index dd54cb4..0000000 --- a/vendor/upb/bazel/private/oss/amalgamate.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/python -# -# Protocol Buffers - Google's data interchange format -# Copyright 2023 Google LLC. All rights reserved. -# https://developers.google.com/protocol-buffers/ -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google LLC nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import os -import re -import sys - -INCLUDE_RE = re.compile('^#include "([^"]*)"') - - -def parse_include(line): - match = INCLUDE_RE.match(line) - return match.groups()[0] if match else None - - -class Amalgamator: - - def __init__(self, h_out, c_out): - self.include_paths = ["."] - self.included = set() - self.output_h = open(h_out, "w") - self.output_c = open(c_out, "w") - self.h_out = h_out.split("/")[-1] - - def amalgamate(self, h_files, c_files): - self.h_files = set(h_files) - self.output_c.write("/* Amalgamated source file */\n") - self.output_c.write('#include "%s"\n' % (self.h_out)) - - self.output_h.write("/* Amalgamated source file */\n") - - port_def = self._find_include_file("upb/port/def.inc") - port_undef = self._find_include_file("upb/port/undef.inc") - self._process_file(port_def, self.output_h) - self._process_file(port_def, self.output_c) - - for file in c_files: - self._process_file(file, self.output_c) - - self._process_file(port_undef, self.output_h) - self._process_file(port_undef, self.output_c) - - def _process_file(self, infile_name, outfile): - lines = open(infile_name).readlines() - - has_copyright = lines[0].startswith( - "// Protocol Buffers - Google's data interchange format" - ) - if has_copyright: - while not lines[0].startswith( - "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH" - " DAMAGE" - ) and not lines[0].startswith( - "// https://developers.google.com/open-source/licenses/bsd" - ): - lines.pop(0) - lines.pop(0) - - for line in lines: - if not self._process_include(line): - outfile.write(line) - - def _find_include_file(self, name): - for h_file in self.h_files: - if h_file.endswith(name): - return h_file - - def _process_include(self, line): - include = parse_include(line) - if not include: - return False - if not ( - include.startswith("upb") - or include.startswith("google") - ): - return False - if include and ( - include.endswith("port/def.inc") or include.endswith("port/undef.inc") - ): - # Skip, we handle this separately - return True - if include.endswith("hpp"): - # Skip, we don't support the amalgamation from C++. - return True - if "decode_fast" in include: - # Skip, we don't support the fasttable parser in the amalgamation. - return True - if re.search(r"stage\d/", include): - return True - elif include in self.included: - return True - else: - # Include this upb header inline. - h_file = self._find_include_file(include) - if h_file: - self.h_files.remove(h_file) - self.included.add(include) - self._process_file(h_file, self.output_h) - return True - raise RuntimeError( - "Couldn't find include: " - + include - + ", h_files=" - + repr(self.h_files) - ) - - -# ---- main ---- - -c_out = sys.argv[1] -h_out = sys.argv[2] -amalgamator = Amalgamator(h_out, c_out) -c_files = [] -h_files = [] - -for arg in sys.argv[3:]: - arg = arg.strip() - if arg.endswith(".h") or arg.endswith(".inc"): - h_files.append(arg) - else: - c_files.append(arg) - -amalgamator.amalgamate(h_files, c_files) diff --git a/vendor/upb/bazel/private/oss/amalgamation.bzl b/vendor/upb/bazel/private/oss/amalgamation.bzl deleted file mode 100644 index 6344b5f..0000000 --- a/vendor/upb/bazel/private/oss/amalgamation.bzl +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -"""Internal rules for building upb.""" - -load("//upb/bazel:upb_proto_library.bzl", "GeneratedSrcsInfo") - -# upb_amalgamation() rule, with file_list aspect. - -SrcList = provider( - fields = { - "srcs": "list of srcs", - }, -) - -def _file_list_aspect_impl(target, ctx): - if GeneratedSrcsInfo in target: - srcs = target[GeneratedSrcsInfo] - return [SrcList(srcs = srcs.srcs + srcs.hdrs)] - - srcs = [] - for src in ctx.rule.attr.srcs: - srcs += src.files.to_list() - for hdr in ctx.rule.attr.hdrs: - srcs += hdr.files.to_list() - for hdr in ctx.rule.attr.textual_hdrs: - srcs += hdr.files.to_list() - return [SrcList(srcs = srcs)] - -_file_list_aspect = aspect( - implementation = _file_list_aspect_impl, -) - -def _upb_amalgamation(ctx): - inputs = [] - for lib in ctx.attr.libs: - inputs += lib[SrcList].srcs - srcs = [src for src in inputs if not src.path.endswith("hpp")] - ctx.actions.run( - inputs = inputs, - outputs = ctx.outputs.outs, - mnemonic = "UpbAmalgamation", - arguments = [f.path for f in ctx.outputs.outs] + [f.path for f in srcs], - progress_message = "Making amalgamation", - executable = ctx.executable._amalgamator, - ) - return [] - -upb_amalgamation = rule( - attrs = { - "_amalgamator": attr.label( - executable = True, - cfg = "exec", - default = "//upb/bazel/private/oss:amalgamate", - ), - "prefix": attr.string( - default = "", - ), - "libs": attr.label_list(aspects = [_file_list_aspect]), - "outs": attr.output_list(), - "strip_import_prefix": attr.string_list(), - }, - implementation = _upb_amalgamation, -) diff --git a/vendor/upb/bazel/private/upb_proto_library_internal/aspect.bzl b/vendor/upb/bazel/private/upb_proto_library_internal/aspect.bzl deleted file mode 100644 index 61f70a8..0000000 --- a/vendor/upb/bazel/private/upb_proto_library_internal/aspect.bzl +++ /dev/null @@ -1,269 +0,0 @@ -"""Implementation of the aspect that powers the upb_*_proto_library() rules.""" - -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") -load("@rules_cc//cc/common:cc_common.bzl", "cc_common") -load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") -load("//bazel/common:proto_common.bzl", "proto_common") -load("//bazel/common:proto_info.bzl", "ProtoInfo") -load(":upb_proto_library_internal/cc_library_func.bzl", "cc_library_func") -load(":upb_proto_library_internal/copts.bzl", "UpbProtoLibraryCoptsInfo") - -_is_google3 = False - -GeneratedSrcsInfo = provider( - "Provides generated headers and sources", - fields = { - "srcs": "list of srcs", - "hdrs": "list of hdrs", - }, -) - -def output_dir(ctx, proto_info): - """Returns the output directory where generated proto files will be placed. - - Args: - ctx: Rule context. - proto_info: ProtoInfo provider. - - Returns: - A string specifying the output directory - """ - proto_root = proto_info.proto_source_root - if proto_root.startswith(ctx.bin_dir.path): - path = proto_root - else: - path = ctx.bin_dir.path + "/" + proto_root - - if proto_root == ".": - path = ctx.bin_dir.path - return path - -def _concat_lists(lists): - ret = [] - for lst in lists: - ret = ret + lst - return ret - -def _merge_generated_srcs(srcs): - return GeneratedSrcsInfo( - srcs = _concat_lists([s.srcs for s in srcs]), - hdrs = _concat_lists([s.hdrs for s in srcs]), - ) - -def _get_implicit_weak_field_sources(ctx, proto_info): - # Creating one .cc file for each Message in a proto allows the linker to be more aggressive - # about removing unused classes. However, since the number of outputs won't be known at Blaze - # analysis time, all of the generated source files are put in a directory and a TreeArtifact is - # used to represent them. - proto_artifacts = [] - for proto_source in proto_info.direct_sources: - # We can have slashes in the target name. For example, proto_source can be: - # dir/a.proto. However proto_source.basename will return a.proto, when in reality - # the BUILD file declares it as dir/a.proto, because target name contains a slash. - # There is no good workaround for this. - # I am using ctx.label.package to check if the name of the target contains slash or not. - # This is similar to what declare_directory does. - if not proto_source.short_path.startswith(ctx.label.package): - fail("This should never happen, proto source {} path does not start with {}.".format( - proto_source.short_path, - ctx.label.package, - )) - proto_source_name = proto_source.short_path[len(ctx.label.package) + 1:] - last_dot = proto_source_name.rfind(".") - if last_dot != -1: - proto_source_name = proto_source_name[:last_dot] - proto_artifacts.append(ctx.actions.declare_directory(proto_source_name + ".upb_weak_minitables")) - - return proto_artifacts - -def _get_feature_configuration(ctx, cc_toolchain, proto_info): - requested_features = list(ctx.features) - - # Disable the whole-archive behavior for protobuf generated code when the - # proto_one_output_per_message feature is enabled. - requested_features.append("disable_whole_archive_for_static_lib_if_proto_one_output_per_message") - unsupported_features = list(ctx.disabled_features) - if len(proto_info.direct_sources) != 0: - requested_features.append("header_modules") - else: - unsupported_features.append("header_modules") - return cc_common.configure_features( - ctx = ctx, - cc_toolchain = cc_toolchain, - requested_features = requested_features, - unsupported_features = unsupported_features, - ) - -def _generate_srcs_list(ctx, generator, proto_info): - if len(proto_info.direct_sources) == 0: - return GeneratedSrcsInfo(srcs = [], hdrs = [], includes = []) - - ext = "." + generator - srcs = [] - hdrs = proto_common.declare_generated_files( - ctx.actions, - extension = ext + ".h", - proto_info = proto_info, - ) - if not (generator == "upb" and _is_google3): - # TODO: The OSS build should also exclude this file for the upb generator, - # as it is empty and unnecessary. We only added it to make the OSS build happy on - # Windows and macOS. - srcs += proto_common.declare_generated_files( - ctx.actions, - extension = ext + ".c", - proto_info = proto_info, - ) - - return GeneratedSrcsInfo( - srcs = srcs, - hdrs = hdrs, - ) - -def _enable_implicit_weak(ctx, generator, feature_configuration): - if generator != "upb_minitable": - return False - - return cc_common.is_enabled( - feature_configuration = feature_configuration, - feature_name = "proto_one_output_per_message", - ) - -def _generate_upb_protos(ctx, generator, proto_info, feature_configuration): - srcs = _generate_srcs_list(ctx, generator, proto_info) - additional_args = ctx.actions.args() - - if _enable_implicit_weak(ctx, generator, feature_configuration): - srcs.srcs.extend(_get_implicit_weak_field_sources(ctx, proto_info)) - additional_args.add("--upb_minitable_opt=one_output_per_message") - - proto_common.compile( - actions = ctx.actions, - proto_info = proto_info, - proto_lang_toolchain_info = _get_lang_toolchain(ctx, generator), - generated_files = srcs.srcs + srcs.hdrs, - experimental_exec_group = "proto_compiler", - additional_args = additional_args, - ) - - return srcs - -def _generate_name(ctx, generator): - return ctx.rule.attr.name + "." + generator - -def _get_proto_deps(ctx): - return [dep for dep in ctx.rule.attr.deps if ProtoInfo in dep] - -def _get_dep_cc_infos(target, ctx, generator, cc_provider, dep_cc_provider): - rule_deps = _get_proto_deps(ctx) - dep_ccinfos = [dep[cc_provider].cc_info for dep in rule_deps] - if dep_cc_provider: - # This gives access to our direct sibling. eg. foo.upb.h can #include "foo.upb_minitable.h" - dep_ccinfos.append(target[dep_cc_provider].cc_info) - - # This gives access to imports. eg. foo.upb.h can #include "import1.upb_minitable.h" - # But not transitive imports, eg. foo.upb.h cannot #include "transitive_import1.upb_minitable.h" - dep_ccinfos += [dep[dep_cc_provider].cc_info for dep in rule_deps] - - return dep_ccinfos - -def _get_lang_toolchain(ctx, generator): - lang_toolchain_name = "_" + generator + "_toolchain" - return getattr(ctx.attr, lang_toolchain_name)[proto_common.ProtoLangToolchainInfo] - -def _compile_upb_protos(ctx, files, generator, dep_ccinfos, cc_provider, proto_info): - cc_info = cc_library_func( - ctx = ctx, - name = _generate_name(ctx, generator), - hdrs = files.hdrs, - srcs = files.srcs, - includes = [output_dir(ctx, proto_info)], - copts = ctx.attr._copts[UpbProtoLibraryCoptsInfo].copts, - dep_ccinfos = dep_ccinfos, - ) - - return cc_provider( - cc_info = cc_info, - ) - -_GENERATORS = ["upb", "upbdefs", "upb_minitable"] - -def _get_hint_providers(ctx, generator): - if generator not in _GENERATORS: - fail("Please add new generator '{}' to _GENERATORS list".format(generator)) - - possible_owners = [] - for generator in _GENERATORS: - possible_owners.append(ctx.label.relative(_generate_name(ctx, generator))) - - if hasattr(cc_common, "CcSharedLibraryHintInfo"): - return [cc_common.CcSharedLibraryHintInfo(owners = possible_owners)] - elif hasattr(cc_common, "CcSharedLibraryHintInfo_6_X_constructor_do_not_use"): - # This branch can be deleted once 6.X is not supported by upb rules - return [cc_common.CcSharedLibraryHintInfo_6_X_constructor_do_not_use(owners = possible_owners)] - - return [] - -def upb_proto_aspect_impl( - target, - ctx, - generator, - cc_provider, - dep_cc_provider, - file_provider, - provide_cc_shared_library_hints = True): - """A shared aspect implementation for upb_*proto_library() rules. - - Args: - target: The `target` parameter from the aspect function. - ctx: The `ctx` parameter from the aspect function. - generator: A string describing which aspect we are generating. This triggers several special - behaviors, and ideally this will be refactored to be less magical. - cc_provider: The provider that this aspect will attach to the target. Should contain a - `cc_info` field. The aspect will ensure that each compilation action can compile and link - against this provider's cc_info for all proto_library() deps. - dep_cc_provider: For aspects that depend on other aspects, this is the provider of the aspect - that we depend on. The aspect will be able to include the header files from this provider. - file_provider: A provider that this aspect will attach to the target to expose the source - files generated by this aspect. These files are primarily useful for returning in - DefaultInfo(), so users who build the upb_*proto_library() rule directly can view the - generated sources. - provide_cc_shared_library_hints: Whether shared library hints should be provided. - - Returns: - The `cc_provider` and `file_provider` providers as described above. - """ - dep_ccinfos = _get_dep_cc_infos(target, ctx, generator, cc_provider, dep_cc_provider) - if not getattr(ctx.rule.attr, "srcs", []): - # This target doesn't declare any sources, reexport all its deps instead. - # This is known as an "alias library": - # https://bazel.build/versions/6.4.0/reference/be/protocol-buffer#proto_library.srcs - files = _merge_generated_srcs([dep[file_provider].srcs for dep in _get_proto_deps(ctx)]) - wrapped_cc_info = cc_provider( - cc_info = cc_common.merge_cc_infos(direct_cc_infos = dep_ccinfos), - ) - else: - proto_info = target[ProtoInfo] - cc_toolchain = find_cpp_toolchain(ctx) - feature_configuration = _get_feature_configuration(ctx, cc_toolchain, proto_info) - files = _generate_upb_protos( - ctx, - generator, - proto_info, - feature_configuration, - ) - wrapped_cc_info = _compile_upb_protos( - ctx, - files, - generator, - dep_ccinfos + [_get_lang_toolchain(ctx, generator).runtime[CcInfo]], - cc_provider, - proto_info, - ) - - hints = _get_hint_providers(ctx, generator) if provide_cc_shared_library_hints else [] - - return hints + [ - file_provider(srcs = files), - wrapped_cc_info, - ] diff --git a/vendor/upb/bazel/private/upb_proto_library_internal/cc_library_func.bzl b/vendor/upb/bazel/private/upb_proto_library_internal/cc_library_func.bzl deleted file mode 100644 index 47fc5a1..0000000 --- a/vendor/upb/bazel/private/upb_proto_library_internal/cc_library_func.bzl +++ /dev/null @@ -1,63 +0,0 @@ -"""A function to compile C/C++ code, like cc_library() but from Starlark.""" - -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") -load("@rules_cc//cc/common:cc_common.bzl", "cc_common") -load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") - -def upb_use_cpp_toolchain(): - return use_cpp_toolchain() - -def cc_library_func(ctx, name, hdrs, srcs, copts, dep_ccinfos, includes = [], alwayslink = False): - """Like cc_library(), but callable from rules. - - Args: - ctx: Rule context. - name: Unique name used to generate output files. - hdrs: Public headers that can be #included from other rules. - srcs: C/C++ source files. - copts: Additional options for cc compilation. - dep_ccinfos: CcInfo providers of dependencies we should build/link against. - includes: Additional include paths. - - Returns: - CcInfo provider for this compilation. - """ - - compilation_contexts = [info.compilation_context for info in dep_ccinfos] - linking_contexts = [info.linking_context for info in dep_ccinfos] - toolchain = find_cpp_toolchain(ctx) - feature_configuration = cc_common.configure_features( - ctx = ctx, - cc_toolchain = toolchain, - requested_features = ctx.features, - unsupported_features = ctx.disabled_features, - ) - - (compilation_context, compilation_outputs) = cc_common.compile( - actions = ctx.actions, - feature_configuration = feature_configuration, - cc_toolchain = toolchain, - name = name, - srcs = srcs, - includes = includes, - public_hdrs = hdrs, - user_compile_flags = copts, - compilation_contexts = compilation_contexts, - ) - - # buildifier: disable=unused-variable - (linking_context, linking_outputs) = cc_common.create_linking_context_from_compilation_outputs( - actions = ctx.actions, - name = name, - feature_configuration = feature_configuration, - cc_toolchain = toolchain, - compilation_outputs = compilation_outputs, - linking_contexts = linking_contexts, - disallow_dynamic_library = cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "targets_windows") or not cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "supports_dynamic_linker"), - alwayslink = alwayslink, - ) - - return CcInfo( - compilation_context = compilation_context, - linking_context = linking_context, - ) diff --git a/vendor/upb/bazel/private/upb_proto_library_internal/copts.bzl b/vendor/upb/bazel/private/upb_proto_library_internal/copts.bzl deleted file mode 100644 index 3005625..0000000 --- a/vendor/upb/bazel/private/upb_proto_library_internal/copts.bzl +++ /dev/null @@ -1,16 +0,0 @@ -"""Dummy rule to expose select() copts to aspects.""" - -UpbProtoLibraryCoptsInfo = provider( - "Provides copts for upb proto targets", - fields = { - "copts": "copts for upb_proto_library()", - }, -) - -def upb_proto_library_copts_impl(ctx): - return UpbProtoLibraryCoptsInfo(copts = ctx.attr.copts) - -upb_proto_library_copts = rule( - implementation = upb_proto_library_copts_impl, - attrs = {"copts": attr.string_list(default = [])}, -) diff --git a/vendor/upb/bazel/private/upb_proto_library_internal/rule.bzl b/vendor/upb/bazel/private/upb_proto_library_internal/rule.bzl deleted file mode 100644 index feb2929..0000000 --- a/vendor/upb/bazel/private/upb_proto_library_internal/rule.bzl +++ /dev/null @@ -1,39 +0,0 @@ -"""Internal rule implementation for upb_*_proto_library() rules.""" - -def _filter_none(elems): - out = [] - for elem in elems: - if elem: - out.append(elem) - return out - -def upb_proto_rule_impl(ctx, cc_info_provider, srcs_provider): - """An implementation for upb_*proto_library() rules. - - Args: - ctx: The rule `ctx` argument - cc_info_provider: The provider containing a wrapped CcInfo that will be exposed to users who - depend on this rule. - srcs_provider: The provider containing the generated source files. This will be used to make - the DefaultInfo return the source files. - - Returns: - Providers for this rule. - """ - if len(ctx.attr.deps) != 1: - fail("only one deps dependency allowed.") - dep = ctx.attr.deps[0] - srcs = dep[srcs_provider].srcs - cc_info = dep[cc_info_provider].cc_info - - lib = cc_info.linking_context.linker_inputs.to_list()[0].libraries[0] - files = _filter_none([ - lib.static_library, - lib.pic_static_library, - lib.dynamic_library, - ]) - return [ - DefaultInfo(files = depset(files + srcs.hdrs + srcs.srcs)), - srcs, - cc_info, - ] diff --git a/vendor/upb/bazel/upb_c_proto_library.bzl b/vendor/upb/bazel/upb_c_proto_library.bzl deleted file mode 100644 index d09387b..0000000 --- a/vendor/upb/bazel/upb_c_proto_library.bzl +++ /dev/null @@ -1,73 +0,0 @@ -"""upb_c_proto_library() exposes upb's generated C API for protobuf (foo.upb.h)""" - -load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") -load("//bazel/common:proto_info.bzl", "ProtoInfo") -load("//upb/bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect") -load("//upb/bazel:visibility.bzl", "upb_clients") -load("//upb/bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl") -load("//upb/bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain") -load("//upb/bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl") - -UpbWrappedCcInfo = provider( - "Provider for cc_info for protos", - fields = ["cc_info"], -) - -_UpbWrappedGeneratedSrcsInfo = provider( - "Provider for generated sources", - fields = ["srcs"], -) - -def _upb_c_proto_library_aspect_impl(target, ctx): - return upb_proto_aspect_impl( - target = target, - ctx = ctx, - generator = "upb", - cc_provider = UpbWrappedCcInfo, - dep_cc_provider = UpbMinitableCcInfo, - file_provider = _UpbWrappedGeneratedSrcsInfo, - provide_cc_shared_library_hints = False, - ) - -upb_c_proto_library_aspect = aspect( - attrs = { - "_copts": attr.label( - default = "//upb:upb_proto_library_copts", - ), - "_upb_toolchain": attr.label( - default = Label("//upb_generator/c:toolchain"), - ), - "_cc_toolchain": attr.label( - default = "@bazel_tools//tools/cpp:current_cc_toolchain", - ), - }, - implementation = _upb_c_proto_library_aspect_impl, - requires = [upb_minitable_proto_library_aspect], - required_aspect_providers = [UpbMinitableCcInfo], - provides = [ - UpbWrappedCcInfo, - _UpbWrappedGeneratedSrcsInfo, - ], - attr_aspects = ["deps"], - fragments = ["cpp"], - toolchains = upb_use_cpp_toolchain(), - exec_groups = { - "proto_compiler": exec_group(), - }, - required_providers = [ProtoInfo], -) - -def _upb_c_proto_library_rule_impl(ctx): - return upb_proto_rule_impl(ctx, UpbWrappedCcInfo, _UpbWrappedGeneratedSrcsInfo) - -upb_c_proto_library = rule( - implementation = _upb_c_proto_library_rule_impl, - attrs = { - "deps": attr.label_list( - aspects = [upb_c_proto_library_aspect], - allow_rules = ["proto_library"], - providers = [ProtoInfo], - ), - }, - provides = [CcInfo], -) diff --git a/vendor/upb/bazel/upb_minitable_proto_library.bzl b/vendor/upb/bazel/upb_minitable_proto_library.bzl deleted file mode 100644 index 6a27082..0000000 --- a/vendor/upb/bazel/upb_minitable_proto_library.bzl +++ /dev/null @@ -1,84 +0,0 @@ -"""upb_minitable_proto_library() exposes upb's generated minitables (foo.upb_minitable.h)""" - -load("@rules_cc//cc/common:cc_common.bzl", "cc_common") -load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") -load("//bazel/common:proto_info.bzl", "ProtoInfo") -load("//upb/bazel:visibility.bzl", "upb_clients") -load("//upb/bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl") -load("//upb/bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain") -load("//upb/bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl") - -visibility(upb_clients) - -UpbMinitableCcInfo = provider( - "Provider for cc_info for protos", - fields = ["cc_info"], -) - -_UpbWrappedGeneratedSrcsInfo = provider( - "Provider for generated sources", - fields = ["srcs"], -) - -def _upb_minitable_proto_library_aspect_impl(target, ctx): - return upb_proto_aspect_impl( - target = target, - ctx = ctx, - generator = "upb_minitable", - cc_provider = UpbMinitableCcInfo, - dep_cc_provider = None, - file_provider = _UpbWrappedGeneratedSrcsInfo, - ) - -def _get_upb_minitable_proto_library_aspect_provides(): - provides = [ - UpbMinitableCcInfo, - _UpbWrappedGeneratedSrcsInfo, - ] - - if hasattr(cc_common, "CcSharedLibraryHintInfo"): - provides.append(cc_common.CcSharedLibraryHintInfo) - elif hasattr(cc_common, "CcSharedLibraryHintInfo_6_X_getter_do_not_use"): - # This branch can be deleted once 6.X is not supported by upb rules - provides.append(cc_common.CcSharedLibraryHintInfo_6_X_getter_do_not_use) - - return provides - -upb_minitable_proto_library_aspect = aspect( - attrs = { - "_copts": attr.label( - default = "//upb:upb_proto_library_copts", - ), - "_upb_minitable_toolchain": attr.label( - default = Label("//upb_generator/minitable:toolchain"), - ), - "_cc_toolchain": attr.label( - default = "@bazel_tools//tools/cpp:current_cc_toolchain", - ), - "_fasttable_enabled": attr.label(default = "//upb:fasttable_enabled"), - }, - implementation = _upb_minitable_proto_library_aspect_impl, - provides = _get_upb_minitable_proto_library_aspect_provides(), - attr_aspects = ["deps"], - fragments = ["cpp"], - toolchains = upb_use_cpp_toolchain(), - exec_groups = { - "proto_compiler": exec_group(), - }, - required_providers = [ProtoInfo], -) - -def _upb_minitable_proto_library_rule_impl(ctx): - return upb_proto_rule_impl(ctx, UpbMinitableCcInfo, _UpbWrappedGeneratedSrcsInfo) - -upb_minitable_proto_library = rule( - implementation = _upb_minitable_proto_library_rule_impl, - attrs = { - "deps": attr.label_list( - aspects = [upb_minitable_proto_library_aspect], - allow_rules = ["proto_library"], - providers = [ProtoInfo], - ), - }, - provides = [CcInfo], -) diff --git a/vendor/upb/bazel/upb_proto_library.bzl b/vendor/upb/bazel/upb_proto_library.bzl deleted file mode 100644 index bb706e3..0000000 --- a/vendor/upb/bazel/upb_proto_library.bzl +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -"""Public rules for using upb protos: - - upb_proto_library() - - upb_proto_reflection_library() -""" - -load( - "//upb/bazel:upb_c_proto_library.bzl", - _UpbWrappedCcInfo = "UpbWrappedCcInfo", - _upb_c_proto_library = "upb_c_proto_library", - _upb_c_proto_library_aspect = "upb_c_proto_library_aspect", -) -load( - "//upb/bazel:upb_proto_reflection_library.bzl", - _upb_proto_reflection_library = "upb_proto_reflection_library", -) -load("//upb/bazel:visibility.bzl", "upb_clients") -load( - "//upb/bazel/private:upb_proto_library_internal/aspect.bzl", - _GeneratedSrcsInfo = "GeneratedSrcsInfo", -) - -visibility(upb_clients) - -# Temporary alias, see b/291827469. -upb_proto_library = _upb_c_proto_library - -upb_c_proto_library = _upb_c_proto_library -upb_proto_reflection_library = _upb_proto_reflection_library -GeneratedSrcsInfo = _GeneratedSrcsInfo -UpbWrappedCcInfo = _UpbWrappedCcInfo -upb_proto_library_aspect = _upb_c_proto_library_aspect diff --git a/vendor/upb/bazel/upb_proto_reflection_library.bzl b/vendor/upb/bazel/upb_proto_reflection_library.bzl deleted file mode 100644 index 77f168e..0000000 --- a/vendor/upb/bazel/upb_proto_reflection_library.bzl +++ /dev/null @@ -1,71 +0,0 @@ -"""upb_c_proto_reflection_library() exposes upb reflection for protobuf (foo.upbdefs.h)""" - -load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") -load("//bazel/common:proto_common.bzl", "proto_common") -load("//bazel/common:proto_info.bzl", "ProtoInfo") -load("//upb/bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect") -load("//upb/bazel:visibility.bzl", "upb_clients") -load("//upb/bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl") -load("//upb/bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain") -load("//upb/bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl") - -_UpbDefsWrappedCcInfo = provider("Provider for cc_info for protos", fields = ["cc_info"]) - -_WrappedDefsGeneratedSrcsInfo = provider( - "Provider for generated reflective sources", - fields = ["srcs"], -) - -def _upb_proto_reflection_library_aspect_impl(target, ctx): - return upb_proto_aspect_impl( - target = target, - ctx = ctx, - generator = "upbdefs", - cc_provider = _UpbDefsWrappedCcInfo, - dep_cc_provider = UpbMinitableCcInfo, - file_provider = _WrappedDefsGeneratedSrcsInfo, - provide_cc_shared_library_hints = False, - ) - -_upb_proto_reflection_library_aspect = aspect( - attrs = { - "_copts": attr.label( - default = "//upb:upb_proto_library_copts", - ), - "_upbdefs_toolchain": attr.label( - default = Label("//upb_generator/reflection:toolchain"), - cfg = getattr(proto_common, "proto_lang_toolchain_cfg", "target"), - ), - "_cc_toolchain": attr.label( - default = "@bazel_tools//tools/cpp:current_cc_toolchain", - ), - }, - implementation = _upb_proto_reflection_library_aspect_impl, - requires = [upb_minitable_proto_library_aspect], - required_aspect_providers = [UpbMinitableCcInfo], - provides = [ - _UpbDefsWrappedCcInfo, - _WrappedDefsGeneratedSrcsInfo, - ], - attr_aspects = ["deps"], - fragments = ["cpp"], - toolchains = upb_use_cpp_toolchain(), - exec_groups = { - "proto_compiler": exec_group(), - }, -) - -def _upb_proto_reflection_library_rule_impl(ctx): - return upb_proto_rule_impl(ctx, _UpbDefsWrappedCcInfo, _WrappedDefsGeneratedSrcsInfo) - -upb_proto_reflection_library = rule( - implementation = _upb_proto_reflection_library_rule_impl, - attrs = { - "deps": attr.label_list( - aspects = [_upb_proto_reflection_library_aspect], - allow_rules = ["proto_library"], - providers = [ProtoInfo], - ), - }, - provides = [CcInfo], -) diff --git a/vendor/upb/bazel/visibility.bzl b/vendor/upb/bazel/visibility.bzl deleted file mode 100644 index a1e5546..0000000 --- a/vendor/upb/bazel/visibility.bzl +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2025, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -visibility("public") -upb_clients = ["//..."] diff --git a/vendor/upb/cmake/BUILD.bazel b/vendor/upb/cmake/BUILD.bazel deleted file mode 100644 index 7a57437..0000000 --- a/vendor/upb/cmake/BUILD.bazel +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_python//python:defs.bzl", "py_library") - -licenses(["notice"]) - -exports_files(["staleness_test.py"]) - -py_library( - name = "staleness_test_lib", - testonly = 1, - srcs = ["staleness_test_lib.py"], - # This is public only for use by the staleness_test() macro. Please do not - # depend on this target directly. - visibility = ["//visibility:public"], -) - -genrule( - name = "copy_protos", - srcs = [ - "//src/google/protobuf:descriptor_upb_c_proto", - "//src/google/protobuf:descriptor_upb_minitable_proto", - ], - outs = [ - "generated-in/google/protobuf/descriptor.upb.h", - "generated-in/google/protobuf/descriptor.upb_minitable.c", - "generated-in/google/protobuf/descriptor.upb_minitable.h", - ], - cmd = "cp $(SRCS) $(@D)/generated-in/google/protobuf", -) - -pkg_files( - name = "upb_cmake_dist", - srcs = [ - ":copy_protos", - "//third_party/utf8_range:utf8_range_srcs", - "//upb:source_files", - "//upb/base:source_files", - "//upb/hash:source_files", - "//upb/lex:source_files", - "//upb/mem:source_files", - "//upb/message:source_files", - "//upb/mini_descriptor:source_files", - "//upb/mini_table:source_files", - "//upb/port:source_files", - "//upb/reflection:source_files", - "//upb/text:source_files", - "//upb/wire:source_files", - ], - strip_prefix = strip_prefix.from_root(""), - visibility = ["//rust:__pkg__"], -) diff --git a/vendor/upb/cmake/build_defs.bzl b/vendor/upb/cmake/build_defs.bzl deleted file mode 100644 index 09e5c15..0000000 --- a/vendor/upb/cmake/build_defs.bzl +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd -"""Bazel support functions related to CMake support.""" - -load("@rules_python//python:py_test.bzl", "py_test") - -def staleness_test(name, outs, generated_pattern, target_files = None, tags = [], **kwargs): - """Tests that checked-in file(s) match the contents of generated file(s). - - The resulting test will verify that all output files exist and have the - correct contents. If the test fails, it can be invoked with --fix to - bring the checked-in files up to date. - - Args: - name: Name of the rule. - outs: the checked-in files that are copied from generated files. - generated_pattern: the pattern for transforming each "out" file into a - generated file. For example, if generated_pattern="generated/%s" then - a file foo.txt will look for generated file generated/foo.txt. - target_files: A glob representing all of the files that should be - covered by this rule. Files in this glob but not generated will - be deleted. (Not currently implemented in OSS). - **kwargs: Additional keyword arguments to pass through to py_test(). - """ - - script_name = name + ".py" - script_src = Label("//upb/cmake:staleness_test.py") - - # Filter out non-existing rules so Blaze doesn't error out before we even - # run the test. - existing_outs = native.glob(include = outs, allow_empty = True) - - # The file list contains a few extra bits of information at the end. - # These get unpacked by the Config class in staleness_test_lib.py. - file_list = outs + [generated_pattern, native.package_name() or ".", name] - - native.genrule( - name = name + "_makescript", - outs = [script_name], - srcs = [script_src], - testonly = 1, - cmd = "cp $< $@; " + - "sed -i.bak -e 's|INSERT_FILE_LIST_HERE|" + "\\\n ".join(file_list) + "|' $@", - ) - - py_test( - name = name, - srcs = [script_name], - data = existing_outs + [generated_pattern % file for file in outs], - python_version = "PY3", - deps = [ - Label("//upb/cmake:staleness_test_lib"), - ], - tags = ["staleness_test"] + tags, - **kwargs - ) diff --git a/vendor/upb/cmake/staleness_test.py b/vendor/upb/cmake/staleness_test.py deleted file mode 100644 index f9fe04e..0000000 --- a/vendor/upb/cmake/staleness_test.py +++ /dev/null @@ -1,60 +0,0 @@ -# Protocol Buffers - Google's data interchange format -# Copyright 2023 Google LLC. All rights reserved. -# https://developers.google.com/protocol-buffers/ -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google LLC nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -"""The py_test() script for staleness_test() rules. - -Note that this file is preprocessed! The INSERT_<...> text below is replaced -with the actual list of files before we actually run the script. -""" - -from __future__ import absolute_import - -from upb.cmake import staleness_test_lib -import unittest -import sys - -file_list = """ - INSERT_FILE_LIST_HERE -""".split() - -config = staleness_test_lib.Config(file_list) - - -class TestFilesMatch(unittest.TestCase): - - def testFilesMatch(self): - errors = staleness_test_lib.CheckFilesMatch(config) - self.assertFalse(errors, errors) - - -if len(sys.argv) > 1 and sys.argv[1] == "--fix": - staleness_test_lib.FixFiles(config) -else: - unittest.main() diff --git a/vendor/upb/cmake/staleness_test_lib.py b/vendor/upb/cmake/staleness_test_lib.py deleted file mode 100644 index d9b78a6..0000000 --- a/vendor/upb/cmake/staleness_test_lib.py +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/python -# -# Protocol Buffers - Google's data interchange format -# Copyright 2023 Google LLC. All rights reserved. -# https://developers.google.com/protocol-buffers/ -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google LLC nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -"""Shared code for validating staleness_test() rules. - -This code is used by test scripts generated from staleness_test() rules. -""" - -from __future__ import absolute_import -from __future__ import print_function - -import difflib -import sys -import os -from shutil import copyfile - - -class _FilePair(object): - """Represents a single (target, generated) file pair.""" - - def __init__(self, target, generated): - self.target = target - self.generated = generated - - -class Config(object): - """Represents the configuration for a single staleness test target.""" - - def __init__(self, file_list): - # Duplicate to avoid modifying our arguments. - file_list = list(file_list) - - # The file list contains a few other bits of information at the end. - # This is packed by the code in build_defs.bzl. - self.target_name = file_list.pop() - self.package_name = file_list.pop() - self.pattern = file_list.pop() - - self.file_list = file_list - - -def _GetFilePairs(config): - """Generates the list of file pairs. - - Args: - config: a Config object representing this target's config. - - Returns: - A list of _FilePair objects. - """ - - ret = [] - - has_bazel_genfiles = os.path.exists("bazel-bin") - - for filename in config.file_list: - target = os.path.join(config.package_name, filename) - generated = os.path.join(config.package_name, config.pattern % filename) - if has_bazel_genfiles: - generated = os.path.join("bazel-bin", generated) - - # Generated files should always exist. Blaze should guarantee this before - # we are run. - if not os.path.isfile(generated): - print("Generated file '%s' does not exist." % generated) - print("Please run this command to generate it:") - print(" bazel build %s:%s" % (config.package_name, config.target_name)) - sys.exit(1) - ret.append(_FilePair(target, generated)) - - return ret - - -def _GetMissingAndStaleFiles(file_pairs): - """Generates lists of missing and stale files. - - Args: - file_pairs: a list of _FilePair objects. - - Returns: - missing_files: a list of _FilePair objects representing missing files. - These target files do not exist at all. - stale_files: a list of _FilePair objects representing stale files. - These target files exist but have stale contents. - """ - - missing_files = [] - stale_files = [] - - for pair in file_pairs: - if not os.path.isfile(pair.target): - missing_files.append(pair) - continue - - with open(pair.generated) as g, open(pair.target) as t: - if g.read() != t.read(): - stale_files.append(pair) - - return missing_files, stale_files - - -def _CopyFiles(file_pairs): - """Copies all generated files to the corresponding target file. - - The target files must be writable already. - - Args: - file_pairs: a list of _FilePair objects that we want to copy. - """ - - for pair in file_pairs: - target_dir = os.path.dirname(pair.target) - if not os.path.isdir(target_dir): - os.makedirs(target_dir) - copyfile(pair.generated, pair.target) - - -def FixFiles(config): - """Implements the --fix option: overwrites missing or out-of-date files. - - Args: - config: the Config object for this test. - """ - - file_pairs = _GetFilePairs(config) - missing_files, stale_files = _GetMissingAndStaleFiles(file_pairs) - - _CopyFiles(stale_files + missing_files) - - -def CheckFilesMatch(config): - """Checks whether each target file matches the corresponding generated file. - - Args: - config: the Config object for this test. - - Returns: - None if everything matches, otherwise a string error message. - """ - - diff_errors = [] - - file_pairs = _GetFilePairs(config) - missing_files, stale_files = _GetMissingAndStaleFiles(file_pairs) - - for pair in missing_files: - diff_errors.append("File %s does not exist" % pair.target) - continue - - for pair in stale_files: - with open(pair.generated) as g, open(pair.target) as t: - diff = ''.join(difflib.unified_diff(g.read().splitlines(keepends=True), - t.read().splitlines(keepends=True))) - diff_errors.append("File %s is out of date:\n%s" % (pair.target, diff)) - - if diff_errors: - error_msg = "Files out of date!\n\n" - error_msg += "To fix run THIS command:\n" - error_msg += " bazel-bin/%s/%s --fix\n\n" % (config.package_name, - config.target_name) - error_msg += "Errors:\n" - error_msg += " " + "\n ".join(diff_errors) - return error_msg - else: - return None diff --git a/vendor/upb/conformance/BUILD b/vendor/upb/conformance/BUILD deleted file mode 100644 index a1ac25d..0000000 --- a/vendor/upb/conformance/BUILD +++ /dev/null @@ -1,189 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_binary.bzl", "cc_binary") -load("@rules_shell//shell:sh_test.bzl", "sh_test") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") -load( - "//upb/bazel:upb_proto_library.bzl", - "upb_c_proto_library", - "upb_proto_reflection_library", -) -load(":build_defs.bzl", "make_shell_script") - -package(default_applicable_licenses = ["//:license"]) - -licenses(["notice"]) - -config_setting( - name = "windows", - constraint_values = ["@platforms//os:windows"], - visibility = ["//visibility:public"], -) - -upb_c_proto_library( - name = "conformance_upb_proto", - testonly = 1, - deps = ["//conformance:conformance_proto"], -) - -upb_proto_reflection_library( - name = "conformance_upb_proto_reflection", - testonly = 1, - deps = ["//conformance:conformance_proto"], -) - -upb_proto_reflection_library( - name = "test_messages_proto2_upbdefs", - testonly = 1, - visibility = ["//visibility:private"], - deps = ["//src/google/protobuf:test_messages_proto2_proto"], -) - -upb_proto_reflection_library( - name = "test_messages_proto3_upbdefs", - testonly = 1, - visibility = ["//visibility:private"], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], -) - -cc_binary( - name = "conformance_upb", - testonly = 1, - srcs = ["conformance_upb.c"], - copts = UPB_DEFAULT_COPTS, - data = ["conformance_upb_failures.txt"], - features = UPB_DEFAULT_FEATURES, - target_compatible_with = select({ - "@platforms//os:windows": ["@platforms//:incompatible"], - "//conditions:default": [], - }), - deps = [ - ":conformance_upb_proto", - ":conformance_upb_proto_reflection", - ":test_messages_proto2_upbdefs", - ":test_messages_proto3_upbdefs", - "//editions:test_messages_proto2_editions_upbdefs", - "//editions:test_messages_proto3_editions_upbdefs", - "//upb/base", - "//upb/json", - "//upb/port", - "//upb/reflection", - "//upb/text", - "//upb/wire", - ], -) - -make_shell_script( - name = "gen_test_conformance_upb", - out = "test_conformance_upb.sh", - contents = "$1 --maximum_edition 2023 --enforce_recommended --failure_list $2 $3", -) - -sh_test( - name = "test_conformance_upb", - srcs = ["test_conformance_upb.sh"], - args = [ - "$(location //conformance:conformance_test_runner)", - "$(location :conformance_upb_failures.txt)", - "$(location :conformance_upb)", - ], - data = [ - "conformance_upb_failures.txt", - ":conformance_upb", - "//conformance:conformance_test_runner", - ], - target_compatible_with = select({ - "@platforms//os:windows": ["@platforms//:incompatible"], - "//conditions:default": [], - }), - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -cc_binary( - name = "conformance_upb_dynamic_minitable", - testonly = 1, - srcs = ["conformance_upb.c"], - copts = UPB_DEFAULT_COPTS + [ - "-DREBUILD_MINITABLES", - ], - data = ["conformance_upb_failures.txt"], - features = UPB_DEFAULT_FEATURES, - target_compatible_with = select({ - "@platforms//os:windows": ["@platforms//:incompatible"], - "//conditions:default": [], - }), - deps = [ - ":conformance_upb_proto", - ":conformance_upb_proto_reflection", - ":test_messages_proto2_upbdefs", - ":test_messages_proto3_upbdefs", - "//editions:test_messages_proto2_editions_upbdefs", - "//editions:test_messages_proto3_editions_upbdefs", - "//upb/base", - "//upb/json", - "//upb/port", - "//upb/reflection", - "//upb/text", - "//upb/wire", - ], -) - -make_shell_script( - name = "gen_test_conformance_upb_dynamic_minitable", - out = "test_conformance_upb_dynamic_minitable.sh", - contents = "$1 --maximum_edition 2023 --enforce_recommended --failure_list $2 $3", -) - -sh_test( - name = "test_conformance_upb_dynamic_minitable", - srcs = ["test_conformance_upb_dynamic_minitable.sh"], - args = [ - "$(location //conformance:conformance_test_runner)", - "$(location :conformance_upb_failures.txt)", - "$(location :conformance_upb_dynamic_minitable)", - ], - data = [ - "conformance_upb_failures.txt", - ":conformance_upb_dynamic_minitable", - "//conformance:conformance_test_runner", - ], - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -make_shell_script( - name = "gen_test_conformance_upb_performance", - out = "test_conformance_upb_performance.sh", - contents = "$1 --performance --maximum_edition 2023 --enforce_recommended --failure_list $2 $3", -) - -sh_test( - name = "test_conformance_upb_performance", - srcs = ["test_conformance_upb_performance.sh"], - args = [ - "$(location //conformance:conformance_test_runner)", - "$(location :conformance_upb_failures_performance.txt)", - "$(location :conformance_upb)", - ], - data = [ - "conformance_upb_failures_performance.txt", - ":conformance_upb", - "//conformance:conformance_test_runner", - ], - # TODO Add upb conformance performance test back - # The upb performance test has segvs with recursion limit test - # cl/895387206 with --config=asan - tags = [ - "manual", - "notap", - ], - target_compatible_with = select({ - "@platforms//os:windows": ["@platforms//:incompatible"], - "//conditions:default": [], - }), - deps = ["@bazel_tools//tools/bash/runfiles"], -) diff --git a/vendor/upb/conformance/build_defs.bzl b/vendor/upb/conformance/build_defs.bzl deleted file mode 100644 index abb59bf..0000000 --- a/vendor/upb/conformance/build_defs.bzl +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -"""Internal rules for building upb.""" - -runfiles_init = """\ -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- -""" - -def _get_real_short_path(file): - # For some reason, files from other archives have short paths that look like: - # ../com_google_protobuf/google/protobuf/descriptor.proto - short_path = file.short_path - if short_path.startswith("../"): - second_slash = short_path.index("/", 3) - short_path = short_path[second_slash + 1:] - return short_path - -def _get_real_root(file): - real_short_path = _get_real_short_path(file) - return file.path[:-len(real_short_path) - 1] - -def _get_real_roots(files): - roots = {} - for file in files: - real_root = _get_real_root(file) - if real_root: - roots[real_root] = True - return roots.keys() - -def make_shell_script(name, contents, out): - contents = contents.replace("$", "$$") - native.genrule( - name = "gen_" + name, - outs = [out], - cmd = "(cat <<'HEREDOC'\n%s\nHEREDOC\n) > $@" % contents, - ) diff --git a/vendor/upb/conformance/conformance_upb.c b/vendor/upb/conformance/conformance_upb.c deleted file mode 100644 index 349d9ec..0000000 --- a/vendor/upb/conformance/conformance_upb.c +++ /dev/null @@ -1,340 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* This is a upb implementation of the upb conformance tests, see: - * https://github.com/google/protobuf/tree/master/conformance - */ - -#include -#include -#include -#include - -#include "conformance/conformance.upb.h" -#include "conformance/conformance.upbdefs.h" -#include "editions/golden/test_messages_proto2_editions.upbdefs.h" -#include "editions/golden/test_messages_proto3_editions.upbdefs.h" -#include "google/protobuf/test_messages_proto2.upbdefs.h" -#include "google/protobuf/test_messages_proto3.upbdefs.h" -#include "upb/base/upcast.h" -#include "upb/json/decode.h" -#include "upb/json/encode.h" -#include "upb/reflection/message.h" -#include "upb/text/encode.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -int test_count = 0; -bool verbose = false; /* Set to true to get req/resp printed on stderr. */ - -bool CheckedRead(int fd, void* buf, size_t len) { - size_t ofs = 0; - while (len > 0) { - ssize_t bytes_read = read(fd, (char*)buf + ofs, len); - - if (bytes_read == 0) return false; - - if (bytes_read < 0) { - perror("reading from test runner"); - exit(1); - } - - len -= bytes_read; - ofs += bytes_read; - } - - return true; -} - -void CheckedWrite(int fd, const void* buf, size_t len) { - if ((size_t)write(fd, buf, len) != len) { - perror("writing to test runner"); - exit(1); - } -} - -typedef struct { - const conformance_ConformanceRequest* request; - conformance_ConformanceResponse* response; - upb_Arena* arena; - const upb_DefPool* symtab; -} ctx; - -bool parse_proto(upb_Message* msg, const upb_MessageDef* m, const ctx* c) { - upb_StringView proto = - conformance_ConformanceRequest_protobuf_payload(c->request); - if (upb_Decode(proto.data, proto.size, msg, upb_MessageDef_MiniTable(m), NULL, - 0, c->arena) == kUpb_DecodeStatus_Ok) { - return true; - } else { - static const char msg[] = "Parse error"; - conformance_ConformanceResponse_set_parse_error( - c->response, upb_StringView_FromString(msg)); - return false; - } -} - -void serialize_proto(const upb_Message* msg, const upb_MessageDef* m, - const ctx* c) { - size_t len; - char* data; - upb_EncodeStatus status = - upb_Encode(msg, upb_MessageDef_MiniTable(m), 0, c->arena, &data, &len); - if (status == kUpb_EncodeStatus_Ok) { - conformance_ConformanceResponse_set_protobuf_payload( - c->response, upb_StringView_FromDataAndSize(data, len)); - } else { - static const char msg[] = "Error serializing."; - conformance_ConformanceResponse_set_serialize_error( - c->response, upb_StringView_FromString(msg)); - } -} - -void serialize_text(const upb_Message* msg, const upb_MessageDef* m, - const ctx* c) { - size_t len; - size_t len2; - int opts = 0; - char* data; - - if (!conformance_ConformanceRequest_print_unknown_fields(c->request)) { - opts |= UPB_TXTENC_SKIPUNKNOWN; - } - - len = upb_TextEncode(msg, m, c->symtab, opts, NULL, 0); - data = upb_Arena_Malloc(c->arena, len + 1); - len2 = upb_TextEncode(msg, m, c->symtab, opts, data, len + 1); - UPB_ASSERT(len == len2); - conformance_ConformanceResponse_set_text_payload( - c->response, upb_StringView_FromDataAndSize(data, len)); -} - -bool parse_json(upb_Message* msg, const upb_MessageDef* m, const ctx* c) { - upb_StringView json = conformance_ConformanceRequest_json_payload(c->request); - upb_Status status; - int opts = 0; - - if (conformance_ConformanceRequest_test_category(c->request) == - conformance_JSON_IGNORE_UNKNOWN_PARSING_TEST) { - opts |= upb_JsonDecode_IgnoreUnknown; - } - - upb_Status_Clear(&status); - if (upb_JsonDecode(json.data, json.size, msg, m, c->symtab, opts, c->arena, - &status)) { - return true; - } else { - const char* inerr = upb_Status_ErrorMessage(&status); - size_t len = strlen(inerr); - char* err = upb_Arena_Malloc(c->arena, len + 1); - memcpy(err, inerr, strlen(inerr)); - err[len] = '\0'; - conformance_ConformanceResponse_set_parse_error( - c->response, upb_StringView_FromString(err)); - return false; - } -} - -void serialize_json(const upb_Message* msg, const upb_MessageDef* m, - const ctx* c) { - size_t len; - size_t len2; - int opts = 0; - char* data; - upb_Status status; - - upb_Status_Clear(&status); - len = upb_JsonEncode(msg, m, c->symtab, opts, NULL, 0, &status); - - if (len == (size_t)-1) { - const char* inerr = upb_Status_ErrorMessage(&status); - size_t len = strlen(inerr); - char* err = upb_Arena_Malloc(c->arena, len + 1); - memcpy(err, inerr, strlen(inerr)); - err[len] = '\0'; - conformance_ConformanceResponse_set_serialize_error( - c->response, upb_StringView_FromString(err)); - return; - } - - data = upb_Arena_Malloc(c->arena, len + 1); - len2 = upb_JsonEncode(msg, m, c->symtab, opts, data, len + 1, &status); - UPB_ASSERT(len == len2); - conformance_ConformanceResponse_set_json_payload( - c->response, upb_StringView_FromDataAndSize(data, len)); -} - -bool parse_input(upb_Message* msg, const upb_MessageDef* m, const ctx* c) { - switch (conformance_ConformanceRequest_payload_case(c->request)) { - case conformance_ConformanceRequest_payload_protobuf_payload: - return parse_proto(msg, m, c); - case conformance_ConformanceRequest_payload_json_payload: - return parse_json(msg, m, c); - case conformance_ConformanceRequest_payload_NOT_SET: - fprintf(stderr, "conformance_upb: Request didn't have payload.\n"); - return false; - default: { - static const char msg[] = "Unsupported input format."; - conformance_ConformanceResponse_set_skipped( - c->response, upb_StringView_FromString(msg)); - return false; - } - } -} - -void write_output(const upb_Message* msg, const upb_MessageDef* m, - const ctx* c) { - switch (conformance_ConformanceRequest_requested_output_format(c->request)) { - case conformance_UNSPECIFIED: - fprintf(stderr, "conformance_upb: Unspecified output format.\n"); - exit(1); - case conformance_PROTOBUF: - serialize_proto(msg, m, c); - break; - case conformance_TEXT_FORMAT: - serialize_text(msg, m, c); - break; - case conformance_JSON: - serialize_json(msg, m, c); - break; - default: { - static const char msg[] = "Unsupported output format."; - conformance_ConformanceResponse_set_skipped( - c->response, upb_StringView_FromString(msg)); - break; - } - } -} - -void DoTest(const ctx* c) { - upb_Message* msg; - upb_StringView name = conformance_ConformanceRequest_message_type(c->request); - const upb_MessageDef* m = - upb_DefPool_FindMessageByNameWithSize(c->symtab, name.data, name.size); -#if 0 - // Handy code for limiting conformance tests to a single input payload. - // This is a hack since the conformance runner doesn't give an easy way to - // specify what test should be run. - const char skip[] = "\343>\010\301\002\344>\230?\001\230?\002\230?\003"; - upb_StringView skip_str = upb_StringView_FromDataAndSize(skip, sizeof(skip) - 1); - upb_StringView pb_payload = - conformance_ConformanceRequest_protobuf_payload(c->request); - if (!upb_StringView_IsEqual(pb_payload, skip_str)) m = NULL; -#endif - - if (!m) { - static const char msg[] = "Unknown message type."; - conformance_ConformanceResponse_set_skipped(c->response, - upb_StringView_FromString(msg)); - return; - } - - msg = upb_Message_New(upb_MessageDef_MiniTable(m), c->arena); - - if (parse_input(msg, m, c)) { - write_output(msg, m, c); - } -} - -void debug_print(const char* label, const upb_Message* msg, - const upb_MessageDef* m, const ctx* c) { - char buf[512]; - upb_TextEncode(msg, m, c->symtab, UPB_TXTENC_SINGLELINE, buf, sizeof(buf)); - fprintf(stderr, "%s: %s\n", label, buf); -} - -bool DoTestIo(upb_DefPool* symtab) { - upb_Status status; - char* input; - char* output; - uint32_t input_size; - size_t output_size; - ctx c; - - if (!CheckedRead(STDIN_FILENO, &input_size, sizeof(uint32_t))) { - /* EOF. */ - return false; - } - - c.symtab = symtab; - c.arena = upb_Arena_New(); - input = upb_Arena_Malloc(c.arena, input_size); - - if (!CheckedRead(STDIN_FILENO, input, input_size)) { - fprintf(stderr, "conformance_upb: unexpected EOF on stdin.\n"); - exit(1); - } - - c.request = conformance_ConformanceRequest_parse(input, input_size, c.arena); - c.response = conformance_ConformanceResponse_new(c.arena); - - if (c.request) { - DoTest(&c); - } else { - fprintf(stderr, "conformance_upb: parse of ConformanceRequest failed: %s\n", - upb_Status_ErrorMessage(&status)); - } - - output = conformance_ConformanceResponse_serialize(c.response, c.arena, - &output_size); - - uint32_t network_out = (uint32_t)output_size; - CheckedWrite(STDOUT_FILENO, &network_out, sizeof(uint32_t)); - CheckedWrite(STDOUT_FILENO, output, output_size); - - test_count++; - - if (verbose) { - debug_print("Request", UPB_UPCAST(c.request), - conformance_ConformanceRequest_getmsgdef(symtab), &c); - debug_print("Response", UPB_UPCAST(c.response), - conformance_ConformanceResponse_getmsgdef(symtab), &c); - fprintf(stderr, "\n"); - } - - upb_Arena_Free(c.arena); - - return true; -} - -int main(void) { - upb_DefPool* symtab = upb_DefPool_New(); - -#ifdef REBUILD_MINITABLES - _upb_DefPool_LoadDefInitEx( - symtab, &google_protobuf_test_messages_proto2_proto_upbdefinit, true); - _upb_DefPool_LoadDefInitEx( - symtab, &google_protobuf_test_messages_proto3_proto_upbdefinit, true); - _upb_DefPool_LoadDefInitEx( - symtab, - &editions_golden_test_messages_proto2_editions_proto_upbdefinit, - true); - _upb_DefPool_LoadDefInitEx( - symtab, - &editions_golden_test_messages_proto3_editions_proto_upbdefinit, - true); -#else - protobuf_test_messages_proto2_TestAllTypesProto2_getmsgdef(symtab); - protobuf_test_messages_editions_proto2_TestAllTypesProto2_getmsgdef(symtab); - protobuf_test_messages_proto3_TestAllTypesProto3_getmsgdef(symtab); - protobuf_test_messages_editions_proto3_TestAllTypesProto3_getmsgdef(symtab); -#endif - - while (1) { - if (!DoTestIo(symtab)) { - fprintf(stderr, - "conformance_upb: received EOF from test runner " - "after %d tests, exiting\n", - test_count); - upb_DefPool_Free(symtab); - return 0; - } - } -} diff --git a/vendor/upb/conformance/conformance_upb_failures.txt b/vendor/upb/conformance/conformance_upb_failures.txt deleted file mode 100644 index 05fe4fe..0000000 --- a/vendor/upb/conformance/conformance_upb_failures.txt +++ /dev/null @@ -1,16 +0,0 @@ -Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't. -Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't. -Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't. -Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output. -Required.*.JsonInput.AnyWithNoType.* # Failed to parse input or produce output. -# TODO: Uncomment once conformance tests can express failures that are not expected to be fixed. -# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.MapKey # Should have failed to parse, but didn't. -# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.MapValue # Should have failed to parse, but didn't. -# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't. -# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't. -# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't. -# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.MapKey # Should have failed to parse, but didn't. -# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.MapValue # Should have failed to parse, but didn't. -# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't. -# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't. -# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't. diff --git a/vendor/upb/conformance/conformance_upb_failures_performance.txt b/vendor/upb/conformance/conformance_upb_failures_performance.txt deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/upb/generated_code_support.h b/vendor/upb/generated_code_support.h deleted file mode 100644 index dd75893..0000000 --- a/vendor/upb/generated_code_support.h +++ /dev/null @@ -1,51 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_GENERATED_CODE_SUPPORT_H_ -#define UPB_GENERATED_CODE_SUPPORT_H_ - -// This is a bit awkward; we want to conditionally include the fast decoder, -// but we generally don't let macros like UPB_FASTTABLE leak into user code. -// We can't #include "decode_fast.h" inside the port/def.inc, because the -// inc files strictly prohibit recursive inclusion, and decode_fast.h includes -// port/def.inc. So instead we use this two-part dance to conditionally include -// decode_fast.h. -#include "upb/port/def.inc" -#if UPB_FASTTABLE -#define UPB_INCLUDE_FAST_DECODE -#endif -#include "upb/port/undef.inc" - -// IWYU pragma: begin_exports -#include "upb/base/upcast.h" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/message.h" -#include "upb/message/map_gencode_util.h" -#include "upb/message/message.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/file.h" -#include "upb/mini_table/internal/generated_registry.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" -#ifdef UPB_INCLUDE_FAST_DECODE -#include "upb/wire/decode_fast/field_parsers.h" -#endif -// IWYU pragma: end_exports - -#undef UPB_INCLUDE_FAST_DECODE - -#endif // UPB_GENERATED_CODE_SUPPORT_H_ diff --git a/vendor/upb/hash/BUILD b/vendor/upb/hash/BUILD deleted file mode 100644 index 066c140..0000000 --- a/vendor/upb/hash/BUILD +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "hash", - srcs = [ - "common.c", - ], - hdrs = [ - "common.h", - "ext_table.h", - "int_table.h", - "str_table.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/base:internal", - "//upb/mem", - "//upb/port", - ], -) - -cc_test( - name = "test", - srcs = ["test.cc"], - deps = [ - ":hash", - "//upb/base", - "//upb/mem", - "//upb/message:message_test_upb_minitable_proto", - "//upb/mini_table", - "//upb/port", - "@abseil-cpp//absl/container:flat_hash_map", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/hash/common.c b/vendor/upb/hash/common.c deleted file mode 100644 index 4f6fd30..0000000 --- a/vendor/upb/hash/common.c +++ /dev/null @@ -1,1111 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* - * upb_table Implementation - * - * Implementation is heavily inspired by Lua's ltable.c. - */ - -#include "upb/hash/common.h" - -#include -#include - -#include "upb/base/internal/log2.h" -#include "upb/base/string_view.h" -#include "upb/hash/ext_table.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -#define UPB_MAXARRSIZE 16 // 2**16 = 64k. - -// From Chromium. -#define ARRAY_SIZE(x) \ - ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) - -/* The minimum utilization of the array part of a mixed hash/array table. This - * is a speed/memory-usage tradeoff (though it's not straightforward because of - * cache effects). The lower this is, the more memory we'll use. */ -static const double MIN_DENSITY = 0.1; - -#if defined(__has_builtin) -#if __has_builtin(__builtin_popcount) -#define UPB_FAST_POPCOUNT32(i) __builtin_popcount(i) -#endif -#elif defined(__GNUC__) -#define UPB_FAST_POPCOUNT32(i) __builtin_popcount(i) -#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) -// Only use __popcnt on x86/x64 architectures for MSVC -#define UPB_FAST_POPCOUNT32(i) __popcnt(i) -#endif - -UPB_INLINE int _upb_popcnt32(uint32_t i) { -#ifdef UPB_FAST_POPCOUNT32 - return UPB_FAST_POPCOUNT32(i); -#else - int count = 0; - while (i != 0) { - count += i & 1; - i >>= 1; - } - return count; -#endif -} - -#undef UPB_FAST_POPCOUNT32 - -UPB_INLINE uint8_t _upb_log2_table_size(upb_table* t) { - return _upb_popcnt32(t->mask); -} - -static bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } - -static int log2ceil(uint64_t v) { - int ret = 0; - bool pow2 = is_pow2(v); - while (v >>= 1) ret++; - ret = pow2 ? ret : ret + 1; // Ceiling. - return UPB_MIN(UPB_MAXARRSIZE, ret); -} - -/* A type to represent the lookup key of either a strtable, inttable or - * exttable. */ -typedef union { - uintptr_t num; - upb_StringView str; - struct { - const void* ptr; - uint32_t ext_num; - } ext; -} lookupkey_t; - -static lookupkey_t strkey2(const char* str, size_t len) { - return (lookupkey_t){.str = upb_StringView_FromDataAndSize(str, len)}; -} - -static lookupkey_t intkey(uintptr_t key) { return (lookupkey_t){.num = key}; } - -static lookupkey_t extkey(const void* ptr, uint32_t ext_num) { - return (lookupkey_t){.ext = {ptr, ext_num}}; -} - -// Conceptually the hash and equal functions should only take the key, not the -// value, but the extension table stores part of its logical key in the value -// slot. This is a sign that we have outgrown the original architecture. -typedef uint32_t hashfunc_t(upb_key key, upb_value val); -typedef bool eqlfunc_t(upb_key k1, upb_value v1, lookupkey_t k2); - -/* Base table (shared code) ***************************************************/ - -static uint32_t upb_inthash(uintptr_t key) { - UPB_STATIC_ASSERT(sizeof(uintptr_t) == 4 || sizeof(uintptr_t) == 8, - "Pointers don't fit"); - if (sizeof(uintptr_t) == 8) { - return (uint32_t)key ^ (uint32_t)(key >> 32); - } else { - return (uint32_t)key; - } -} - -static upb_tabent* upb_getentry(const upb_table* t, uint32_t hash) { - return t->entries + (hash & t->mask); -} - -static bool isfull(upb_table* t) { - uint32_t size = upb_table_size(t); - // 0.875 load factor - return t->count == (size - (size >> 3)); -} - -static bool init(upb_table* t, uint8_t size_lg2, upb_Arena* a) { - if (size_lg2 >= 32) { - return false; - } - t->count = 0; - uint32_t size = 1 << size_lg2; - t->mask = size - 1; // 0 mask if size_lg2 is 0 - if (upb_table_size(t) > (SIZE_MAX / sizeof(upb_tabent))) { - return false; - } - size_t bytes = upb_table_size(t) * sizeof(upb_tabent); - if (bytes > 0) { - t->entries = upb_Arena_Malloc(a, bytes); - if (!t->entries) return false; - memset(t->entries, 0, bytes); - } else { - t->entries = NULL; - } - return true; -} - -static upb_tabent* emptyent(upb_table* t, upb_tabent* e) { - upb_tabent* begin = t->entries; - upb_tabent* end = begin + upb_table_size(t); - for (e = e + 1; e < end; e++) { - if (upb_tabent_isempty(e)) return e; - } - for (e = begin; e < end; e++) { - if (upb_tabent_isempty(e)) return e; - } - UPB_ASSERT(false); - return NULL; -} - -static upb_tabent* getentry_mutable(upb_table* t, uint32_t hash) { - return upb_getentry(t, hash); -} - -static upb_tabent* findentry(const upb_table* t, lookupkey_t key, uint32_t hash, - eqlfunc_t* eql) { - upb_tabent* e; - - if (t->count == 0) return NULL; - e = upb_getentry(t, hash); - if (upb_tabent_isempty(e)) return NULL; - while (1) { - if (eql(e->key, e->val, key)) return e; - if (!upb_tabent_hasnext(e)) return NULL; - e = upb_tabent_next(e); - } -} - -static upb_tabent* findentry_mutable(upb_table* t, lookupkey_t key, - uint32_t hash, eqlfunc_t* eql) { - return findentry(t, key, hash, eql); -} - -static bool lookup(const upb_table* t, lookupkey_t key, upb_value* v, - uint32_t hash, eqlfunc_t* eql) { - const upb_tabent* e = findentry(t, key, hash, eql); - if (e) { - if (v) *v = e->val; - return true; - } else { - return false; - } -} - -/* The given key must not already exist in the table. */ -static void insert(upb_table* t, lookupkey_t key, upb_key tabkey, upb_value val, - uint32_t hash, hashfunc_t* hashfunc, eqlfunc_t* eql) { - upb_tabent* mainpos_e; - upb_tabent* our_e; - - UPB_ASSERT(findentry(t, key, hash, eql) == NULL); - - t->count++; - mainpos_e = getentry_mutable(t, hash); - our_e = mainpos_e; - - if (upb_tabent_isempty(mainpos_e)) { - /* Our main position is empty; use it. */ - upb_tabent_clearnext(our_e); - } else { - /* Collision. */ - upb_tabent* new_e = emptyent(t, mainpos_e); - /* Head of collider's chain. */ - upb_tabent* chain = - getentry_mutable(t, hashfunc(mainpos_e->key, mainpos_e->val)); - if (chain == mainpos_e) { - /* Existing ent is in its main position (it has the same hash as us, and - * is the head of our chain). Insert to new ent and append to this chain. - */ - if (upb_tabent_hasnext(mainpos_e)) { - upb_tabent_setnext(new_e, upb_tabent_next(mainpos_e)); - } else { - upb_tabent_clearnext(new_e); - } - upb_tabent_setnext(mainpos_e, new_e); - our_e = new_e; - } else { - /* Existing ent is not in its main position (it is a node in some other - * chain). This implies that no existing ent in the table has our hash. - * Evict it (updating its chain) and use its ent for head of our chain. */ - new_e->key = mainpos_e->key; - new_e->val = mainpos_e->val; - if (upb_tabent_hasnext(mainpos_e)) { - upb_tabent_setnext(new_e, upb_tabent_next(mainpos_e)); - } else { - upb_tabent_clearnext(new_e); - } - - while (upb_tabent_hasnext(chain) && upb_tabent_next(chain) != mainpos_e) { - chain = upb_tabent_next(chain); - UPB_ASSERT(chain); - } - upb_tabent_setnext(chain, new_e); - our_e = mainpos_e; - upb_tabent_clearnext(our_e); - } - } - our_e->key = tabkey; - our_e->val = val; - UPB_ASSERT(findentry(t, key, hash, eql) == our_e); -} - -static bool rm(upb_table* t, lookupkey_t key, upb_value* val, uint32_t hash, - eqlfunc_t* eql) { - upb_tabent* chain = getentry_mutable(t, hash); - if (upb_tabent_isempty(chain)) return false; - if (eql(chain->key, chain->val, key)) { - /* Element to remove is at the head of its chain. */ - t->count--; - if (val) *val = chain->val; - if (upb_tabent_hasnext(chain)) { - upb_tabent* move = upb_tabent_next(chain); - chain->key = move->key; - chain->val = move->val; - if (upb_tabent_hasnext(move)) { - upb_tabent_setnext(chain, upb_tabent_next(move)); - } else { - upb_tabent_clearnext(chain); - } - - upb_tabent_clear(move); - } else { - upb_tabent_clear(chain); - } - return true; - } else { - /* Element to remove is either in a non-head position or not in the - * table. */ - while ( - upb_tabent_hasnext(chain) && - !eql(upb_tabent_next(chain)->key, upb_tabent_next(chain)->val, key)) { - chain = upb_tabent_next(chain); - } - if (upb_tabent_hasnext(chain)) { - /* Found element to remove. */ - upb_tabent* rm = upb_tabent_next(chain); - t->count--; - if (val) *val = rm->val; - if (upb_tabent_hasnext(rm)) { - upb_tabent_setnext(chain, upb_tabent_next(rm)); - } else { - upb_tabent_clearnext(chain); - } - upb_tabent_clear(rm); - return true; - } else { - /* Element to remove is not in the table. */ - return false; - } - } -} - -static size_t next(const upb_table* t, size_t i) { - do { - if (++i >= upb_table_size(t)) return SIZE_MAX - 1; /* Distinct from -1. */ - } while (upb_tabent_isempty(&t->entries[i])); - - return i; -} - -static size_t begin(const upb_table* t) { return next(t, -1); } - -/* upb_strtable ***************************************************************/ - -// A simple "subclass" of upb_table that only adds a hash function for strings. - -static upb_SizePrefixString* upb_SizePrefixString_Copy(upb_StringView s, - upb_Arena* a) { - // A 2GB string will fail at serialization time, but we accept up to 4GB in - // memory here. - if (s.size > UINT32_MAX) return NULL; - upb_SizePrefixString* str = - upb_Arena_Malloc(a, sizeof(uint32_t) + s.size + 1); - if (str == NULL) return NULL; - str->size = s.size; - char* data = (char*)str->data; - if (s.size) memcpy(data, s.data, s.size); - data[s.size] = '\0'; - return str; -} - -/* Adapted from ABSL's wyhash. */ - -static uint64_t UnalignedLoad64(const void* p) { - uint64_t val; - memcpy(&val, p, 8); - return val; -} - -static uint32_t UnalignedLoad32(const void* p) { - uint32_t val; - memcpy(&val, p, 4); - return val; -} - -#if defined(_MSC_VER) && defined(_M_X64) -#include -#endif - -/* Computes a * b, returning the low 64 bits of the result and storing the high - * 64 bits in |*high|. */ -static uint64_t upb_umul128(uint64_t v0, uint64_t v1, uint64_t* out_high) { -#ifdef __SIZEOF_INT128__ - __uint128_t p = v0; - p *= v1; - *out_high = (uint64_t)(p >> 64); - return (uint64_t)p; -#elif defined(_MSC_VER) && defined(_M_X64) - return _umul128(v0, v1, out_high); -#else - uint64_t a32 = v0 >> 32; - uint64_t a00 = v0 & 0xffffffff; - uint64_t b32 = v1 >> 32; - uint64_t b00 = v1 & 0xffffffff; - uint64_t high = a32 * b32; - uint64_t low = a00 * b00; - uint64_t mid1 = a32 * b00; - uint64_t mid2 = a00 * b32; - low += (mid1 << 32) + (mid2 << 32); - // Omit carry bit, for mixing we do not care about exact numerical precision. - high += (mid1 >> 32) + (mid2 >> 32); - *out_high = high; - return low; -#endif -} - -static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { - uint64_t high; - uint64_t low = upb_umul128(v0, v1, &high); - return low ^ high; -} - -static uint64_t Wyhash(const void* data, size_t len, uint64_t seed, - const uint64_t salt[]) { - const uint8_t* ptr = (const uint8_t*)data; - uint64_t starting_length = (uint64_t)len; - uint64_t current_state = seed ^ salt[0]; - - if (len > 64) { - // If we have more than 64 bytes, we're going to handle chunks of 64 - // bytes at a time. We're going to build up two separate hash states - // which we will then hash together. - uint64_t duplicated_state = current_state; - - do { - uint64_t a = UnalignedLoad64(ptr); - uint64_t b = UnalignedLoad64(ptr + 8); - uint64_t c = UnalignedLoad64(ptr + 16); - uint64_t d = UnalignedLoad64(ptr + 24); - uint64_t e = UnalignedLoad64(ptr + 32); - uint64_t f = UnalignedLoad64(ptr + 40); - uint64_t g = UnalignedLoad64(ptr + 48); - uint64_t h = UnalignedLoad64(ptr + 56); - - uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state); - uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state); - current_state = (cs0 ^ cs1); - - uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state); - uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state); - duplicated_state = (ds0 ^ ds1); - - ptr += 64; - len -= 64; - } while (len > 64); - - current_state = current_state ^ duplicated_state; - } - - // We now have a data `ptr` with at most 64 bytes and the current state - // of the hashing state machine stored in current_state. - while (len > 16) { - uint64_t a = UnalignedLoad64(ptr); - uint64_t b = UnalignedLoad64(ptr + 8); - - current_state = WyhashMix(a ^ salt[1], b ^ current_state); - - ptr += 16; - len -= 16; - } - - // We now have a data `ptr` with at most 16 bytes. - uint64_t a = 0; - uint64_t b = 0; - if (len > 8) { - // When we have at least 9 and at most 16 bytes, set A to the first 64 - // bits of the input and B to the last 64 bits of the input. Yes, they will - // overlap in the middle if we are working with less than the full 16 - // bytes. - a = UnalignedLoad64(ptr); - b = UnalignedLoad64(ptr + len - 8); - } else if (len > 3) { - // If we have at least 4 and at most 8 bytes, set A to the first 32 - // bits and B to the last 32 bits. - a = UnalignedLoad32(ptr); - b = UnalignedLoad32(ptr + len - 4); - } else if (len > 0) { - // If we have at least 1 and at most 3 bytes, read all of the provided - // bits into A, with some adjustments. - a = ((ptr[0] << 16) | (ptr[len >> 1] << 8) | ptr[len - 1]); - b = 0; - } else { - a = 0; - b = 0; - } - - uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state); - uint64_t z = salt[1] ^ starting_length; - return WyhashMix(w, z); -} - -const uint64_t kWyhashSalt[5] = { - 0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL, 0xA4093822299F31D0ULL, - 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, -}; - -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed) { - return Wyhash(p, n, seed, kWyhashSalt); -} - -static const void* const _upb_seed; - -// Returns a random seed for upb's hash function. This does not provide -// high-quality randomness, but it should be enough to prevent unit tests from -// relying on a deterministic map ordering. By returning the address of a -// variable, we are able to get some randomness for free provided that ASLR is -// enabled. -static uint64_t _upb_Seed(void) { return (uint64_t)&_upb_seed; } - -static uint32_t _upb_Hash_NoSeed(const char* p, size_t n) { - return _upb_Hash(p, n, _upb_Seed()); -} - -static uint32_t strhash(upb_key key, upb_value val) { - UPB_UNUSED(val); - return _upb_Hash_NoSeed(key.str->data, key.str->size); -} - -static bool streql(upb_key k1, upb_value v1, lookupkey_t k2) { - UPB_UNUSED(v1); - const upb_SizePrefixString* k1s = k1.str; - const upb_StringView k2s = k2.str; - return k1s->size == k2s.size && - (k1s->size == 0 || memcmp(k1s->data, k2s.data, k1s->size) == 0); -} - -/** Calculates the number of entries required to hold an expected number of - * values, within the table's load factor. */ -static size_t _upb_entries_needed_for(size_t expected_size) { - size_t need_entries = expected_size + 1 + expected_size / 7; - UPB_ASSERT(need_entries - (need_entries >> 3) >= expected_size); - return need_entries; -} - -bool upb_strtable_init(upb_strtable* t, size_t expected_size, upb_Arena* a) { - int size_lg2 = upb_Log2Ceiling(_upb_entries_needed_for(expected_size)); - return init(&t->t, size_lg2, a); -} - -void upb_strtable_clear(upb_strtable* t) { - size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); - t->t.count = 0; - memset((char*)t->t.entries, 0, bytes); -} - -bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a) { - upb_strtable new_table; - if (!init(&new_table.t, size_lg2, a)) return false; - - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView sv; - upb_value val; - while (upb_strtable_next2(t, &sv, &val, &iter)) { - // Unlike normal insert, does not copy string data or possibly reallocate - // the table - // The data pointer used in the table is guaranteed to point at a - // upb_SizePrefixString, we just need to back up by the size of the uint32_t - // length prefix. - const upb_SizePrefixString* keystr = - (const upb_SizePrefixString*)(sv.data - sizeof(uint32_t)); - UPB_ASSERT(keystr->data == sv.data); - UPB_ASSERT(keystr->size == sv.size); - - lookupkey_t lookupkey = {.str = sv}; - upb_key tabkey = {.str = keystr}; - uint32_t hash = _upb_Hash_NoSeed(sv.data, sv.size); - insert(&new_table.t, lookupkey, tabkey, val, hash, &strhash, &streql); - } - *t = new_table; - return true; -} - -bool upb_strtable_insert(upb_strtable* t, const char* k, size_t len, - upb_value v, upb_Arena* a) { - if (isfull(&t->t)) { - /* Need to resize. New table of double the size, add old elements to it. */ - if (!upb_strtable_resize(t, _upb_log2_table_size(&t->t) + 1, a)) { - return false; - } - } - - upb_StringView sv = upb_StringView_FromDataAndSize(k, len); - upb_SizePrefixString* size_prefix_string = upb_SizePrefixString_Copy(sv, a); - if (!size_prefix_string) return false; - - lookupkey_t lookupkey = {.str = sv}; - upb_key key = {.str = size_prefix_string}; - uint32_t hash = _upb_Hash_NoSeed(k, len); - insert(&t->t, lookupkey, key, v, hash, &strhash, &streql); - return true; -} - -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v) { - uint32_t hash = _upb_Hash_NoSeed(key, len); - return lookup(&t->t, strkey2(key, len), v, hash, &streql); -} - -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val) { - uint32_t hash = _upb_Hash_NoSeed(key, len); - return rm(&t->t, strkey2(key, len), val, hash, &streql); -} - -/* Iteration */ - -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t) { - i->t = t; - i->index = begin(&t->t); -} - -void upb_strtable_next(upb_strtable_iter* i) { - i->index = next(&i->t->t, i->index); -} - -bool upb_strtable_done(const upb_strtable_iter* i) { - if (!i->t) return true; - return i->index >= upb_table_size(&i->t->t) || - upb_tabent_isempty(str_tabent(i)); -} - -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i) { - UPB_ASSERT(!upb_strtable_done(i)); - return upb_key_strview(str_tabent(i)->key); -} - -upb_value upb_strtable_iter_value(const upb_strtable_iter* i) { - UPB_ASSERT(!upb_strtable_done(i)); - return str_tabent(i)->val; -} - -void upb_strtable_iter_setdone(upb_strtable_iter* i) { - i->t = NULL; - i->index = SIZE_MAX; -} - -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2) { - if (upb_strtable_done(i1) && upb_strtable_done(i2)) return true; - return i1->t == i2->t && i1->index == i2->index; -} - -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter) { - size_t tab_idx = next(&t->t, *iter); - if (tab_idx < upb_table_size(&t->t)) { - upb_tabent* ent = &t->t.entries[tab_idx]; - *key = upb_key_strview(ent->key); - *val = ent->val; - *iter = tab_idx; - return true; - } - - return false; -} - -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter) { - intptr_t i = *iter; - upb_tabent* ent = &t->t.entries[i]; - upb_tabent* prev = NULL; - - // Linear search, not great. - upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; - for (upb_tabent* e = t->t.entries; e != end; e++) { - if (!upb_tabent_isempty(e) && upb_tabent_hasnext(e) && - upb_tabent_next(e) == ent) { - prev = e; - break; - } - } - - if (prev) { - if (upb_tabent_hasnext(ent)) { - upb_tabent_setnext(prev, upb_tabent_next(ent)); - } else { - upb_tabent_clearnext(prev); - } - } - - t->t.count--; - upb_tabent_clear(ent); -} - -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v) { - t->t.entries[iter].val = v; -} - -/* upb_exttable ***************************************************************/ - -static uint32_t _upb_exttable_hash(const void* ptr, uint32_t ext_num) { - uint64_t a = (uintptr_t)ptr; - uint64_t b = ext_num; - return (uint32_t)WyhashMix(a ^ kWyhashSalt[1], b ^ _upb_Seed()); -} - -static uint32_t exthash(upb_key key, upb_value val) { - const void* ptr = (const void*)key.num; - uint32_t ext_num = *(const uint32_t*)upb_value_getconstptr(val); - return _upb_exttable_hash(ptr, ext_num); -} - -static bool exteql(upb_key k1, upb_value v1, lookupkey_t k2) { - if ((const void*)k1.num == k2.ext.ptr) { - uint32_t ext_num1 = *(const uint32_t*)upb_value_getconstptr(v1); - return ext_num1 == k2.ext.ext_num; - } - return false; -} - -bool upb_exttable_init(upb_exttable* t, size_t expected_size, upb_Arena* a) { - int size_lg2 = upb_Log2Ceiling(_upb_entries_needed_for(expected_size)); - return init(&t->t, size_lg2, a); -} - -void upb_exttable_clear(upb_exttable* t) { - size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); - t->t.count = 0; - memset((char*)t->t.entries, 0, bytes); -} - -bool upb_exttable_resize(upb_exttable* t, size_t size_lg2, upb_Arena* a) { - upb_exttable new_table; - if (!init(&new_table.t, size_lg2, a)) return false; - - size_t i; - for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { - const upb_tabent* e = &t->t.entries[i]; - uint32_t hash = exthash(e->key, e->val); - uint32_t ext_num = *(const uint32_t*)upb_value_getconstptr(e->val); - lookupkey_t lookupkey = extkey((const void*)e->key.num, ext_num); - insert(&new_table.t, lookupkey, e->key, e->val, hash, &exthash, &exteql); - } - - *t = new_table; - return true; -} - -bool upb_exttable_insert(upb_exttable* t, const void* k, const uint32_t* v, - upb_Arena* a) { - UPB_ASSERT(k != NULL); - UPB_ASSERT(v != NULL); - UPB_ASSERT(*v != 0); - - if (isfull(&t->t)) { - if (!upb_exttable_resize(t, _upb_log2_table_size(&t->t) + 1, a)) { - return false; - } - } - - lookupkey_t lookupkey = extkey(k, *v); - upb_key key = {.num = (uintptr_t)k}; - upb_value val = upb_value_constptr(v); - uint32_t hash = _upb_exttable_hash(k, *v); - insert(&t->t, lookupkey, key, val, hash, &exthash, &exteql); - return true; -} - -const uint32_t* upb_exttable_lookup(const upb_exttable* t, const void* k, - uint32_t ext_number) { - uint32_t hash = _upb_exttable_hash(k, ext_number); - upb_value val; - if (lookup(&t->t, extkey(k, ext_number), &val, hash, &exteql)) { - return (const uint32_t*)upb_value_getconstptr(val); - } - return NULL; -} - -const uint32_t* upb_exttable_remove(upb_exttable* t, const void* k, - uint32_t ext_number) { - uint32_t hash = _upb_exttable_hash(k, ext_number); - upb_value val; - if (rm(&t->t, extkey(k, ext_number), &val, hash, &exteql)) { - return (const uint32_t*)upb_value_getconstptr(val); - } - return NULL; -} - -size_t upb_exttable_size(const upb_exttable* t) { return t->t.count; } - -/* upb_inttable ***************************************************************/ - -/* For inttables we use a hybrid structure where small keys are kept in an - * array and large keys are put in the hash table. */ - -// The sentinel value used in the dense array part. Note that callers must -// ensure that inttable is never used with a value of this sentinel type -// (pointers and u32 values will never be; i32 needs to be handled carefully -// to avoid sign-extending into this value). -static const upb_value kInttableSentinel = {.val = UINT64_MAX}; -static uint32_t presence_mask_arr_size(uint32_t array_size) { - return (array_size + 7) / 8; // sizeof(uint8_t) is always 1. -} - -static uint32_t inthash(upb_key key, upb_value val) { - UPB_UNUSED(val); - return upb_inthash(key.num); -} - -static bool inteql(upb_key k1, upb_value v1, lookupkey_t k2) { - UPB_UNUSED(v1); - return k1.num == k2.num; -} - -static upb_value* mutable_array(upb_inttable* t) { - return (upb_value*)t->array; -} - -static const upb_value* inttable_array_get(const upb_inttable* t, - uintptr_t key) { - UPB_ASSERT(key < t->array_size); - const upb_value* val = &t->array[key]; - return upb_inttable_arrhas(t, key) ? val : NULL; -} - -static upb_value* inttable_val(upb_inttable* t, uintptr_t key) { - if (key < t->array_size) { - return (upb_value*)inttable_array_get(t, key); - } else { - upb_tabent* e = - findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql); - return e ? &e->val : NULL; - } -} - -static const upb_value* inttable_val_const(const upb_inttable* t, - uintptr_t key) { - return inttable_val((upb_inttable*)t, key); -} - -size_t upb_inttable_count(const upb_inttable* t) { - return t->t.count + t->array_count; -} - -static void check(upb_inttable* t) { - UPB_UNUSED(t); -#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) - { - // This check is very expensive (makes inserts/deletes O(N)). - size_t count = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - UPB_ASSERT(upb_inttable_lookup(t, key, NULL)); - count++; - } - UPB_ASSERT(count == upb_inttable_count(t)); - } -#endif -} - -bool upb_inttable_sizedinit(upb_inttable* t, uint32_t asize, int hsize_lg2, - upb_Arena* a) { - if (!init(&t->t, hsize_lg2, a)) return false; - /* Always make the array part at least 1 long, so that we know key 0 - * won't be in the hash part, which simplifies things. */ - t->array_size = UPB_MAX(1, asize); - t->array_count = 0; -#if UINT32_MAX >= SIZE_MAX - if (UPB_UNLIKELY(SIZE_MAX / sizeof(upb_value) < t->array_size)) { - return false; - } -#endif - - // Allocate the array part and the presence mask array in one allocation. - size_t array_bytes = t->array_size * sizeof(upb_value); - uint32_t presence_bytes = presence_mask_arr_size(t->array_size); - uintptr_t total_bytes = array_bytes + presence_bytes; - if (UPB_UNLIKELY(total_bytes > SIZE_MAX)) { - return false; - } - void* alloc = upb_Arena_Malloc(a, total_bytes); - if (!alloc) { - return false; - } - t->array = alloc; - memset(mutable_array(t), 0xff, array_bytes); - t->presence_mask = (uint8_t*)alloc + array_bytes; - memset((uint8_t*)t->presence_mask, 0, presence_bytes); - - check(t); - return true; -} - -bool upb_inttable_init(upb_inttable* t, upb_Arena* a) { - // The init size of the table part to match that of strtable. - return upb_inttable_sizedinit(t, 0, 3, a); -} - -bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, - upb_Arena* a) { - if (key < t->array_size) { - UPB_ASSERT(!upb_inttable_arrhas(t, key)); - t->array_count++; - mutable_array(t)[key] = val; - ((uint8_t*)t->presence_mask)[key / 8] |= (1 << (key % 8)); - } else { - if (isfull(&t->t)) { - /* Need to resize the hash part, but we re-use the array part. */ - size_t i; - upb_table new_table; - - if (!init(&new_table, _upb_log2_table_size(&t->t) + 1, a)) { - return false; - } - - for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { - const upb_tabent* e = &t->t.entries[i]; - insert(&new_table, intkey(e->key.num), e->key, e->val, - inthash(e->key, e->val), &inthash, &inteql); - } - - UPB_ASSERT(t->t.count == new_table.count); - - t->t = new_table; - } - upb_key tabkey = {.num = key}; - insert(&t->t, intkey(key), tabkey, val, upb_inthash(key), &inthash, - &inteql); - } - check(t); - return true; -} - -bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v) { - const upb_value* table_v = inttable_val_const(t, key); - if (!table_v) return false; - if (v) *v = *table_v; - return true; -} - -bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val) { - upb_value* table_v = inttable_val(t, key); - if (!table_v) return false; - *table_v = val; - return true; -} - -bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val) { - bool success; - if (key < t->array_size) { - if (upb_inttable_arrhas(t, key)) { - t->array_count--; - if (val) { - *val = t->array[key]; - } - mutable_array(t)[key] = kInttableSentinel; - ((uint8_t*)t->presence_mask)[key / 8] &= ~(1 << (key % 8)); - success = true; - } else { - success = false; - } - } else { - success = rm(&t->t, intkey(key), val, upb_inthash(key), &inteql); - } - check(t); - return success; -} - -bool upb_inttable_compact(upb_inttable* t, upb_Arena* a) { - /* A power-of-two histogram of the table keys. */ - uint32_t counts[UPB_MAXARRSIZE + 1] = {0}; - - /* The max key in each bucket. */ - uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; - - { - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - int bucket = log2ceil(key); - max[bucket] = UPB_MAX(max[bucket], key); - counts[bucket]++; - } - } - - /* Find the largest power of two that satisfies the MIN_DENSITY - * definition (while actually having some keys). */ - uint32_t arr_count = upb_inttable_count(t); - - // Scan all buckets except capped bucket - int size_lg2 = ARRAY_SIZE(counts) - 1; - for (; size_lg2 > 0; size_lg2--) { - if (counts[size_lg2] == 0) { - /* We can halve again without losing any entries. */ - continue; - } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { - break; - } - - arr_count -= counts[size_lg2]; - } - - UPB_ASSERT(arr_count <= upb_inttable_count(t)); - - upb_inttable new_t; - { - /* Insert all elements into new, perfectly-sized table. */ - uintptr_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ - uint32_t hash_count = upb_inttable_count(t) - arr_count; - size_t hash_size = hash_count ? _upb_entries_needed_for(hash_count) : 0; - int hashsize_lg2 = log2ceil(hash_size); - - if (!upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a)) { - return false; - } - - { - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - upb_inttable_insert(&new_t, key, val, a); - } - } - - UPB_ASSERT(new_t.array_size == arr_size); - } - *t = new_t; - return true; -} - -void upb_inttable_clear(upb_inttable* t) { - // Clear the array part. - size_t array_bytes = t->array_size * sizeof(upb_value); - t->array_count = 0; - // Clear the array by setting all bits to 1, as UINT64_MAX is the sentinel - // value for an empty array. - memset(mutable_array(t), 0xff, array_bytes); - // Clear the presence mask array. - memset((uint8_t*)t->presence_mask, 0, presence_mask_arr_size(t->array_size)); - // Clear the table part. - size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); - t->t.count = 0; - memset((char*)t->t.entries, 0, bytes); -} - -// Iteration. - -bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, - intptr_t* iter) { - intptr_t i = *iter; - if ((size_t)(i + 1) <= t->array_size) { - while ((size_t)++i < t->array_size) { - const upb_value* ent = inttable_array_get(t, i); - if (ent) { - *key = i; - *val = *ent; - *iter = i; - return true; - } - } - i--; // Back up to exactly one position before the start of the table. - } - - size_t tab_idx = next(&t->t, i - t->array_size); - if (tab_idx < upb_table_size(&t->t)) { - upb_tabent* ent = &t->t.entries[tab_idx]; - *key = ent->key.num; - *val = ent->val; - *iter = tab_idx + t->array_size; - return true; - } else { - // We should set the iterator any way. When we are done, the iterator value - // is invalidated. `upb_inttable_done` will check on the iterator value to - // determine if the iteration is done. - *iter = INTPTR_MAX - 1; // To disambiguate from UPB_INTTABLE_BEGIN, to - // match the behavior of `upb_strtable_iter`. - return false; - } -} - -void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter) { - intptr_t i = *iter; - if ((size_t)i < t->array_size) { - t->array_count--; - mutable_array(t)[i].val = -1; - } else { - upb_tabent* ent = &t->t.entries[i - t->array_size]; - upb_tabent* prev = NULL; - - // Linear search, not great. - upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; - for (upb_tabent* e = t->t.entries; e != end; e++) { - if (!upb_tabent_isempty(e) && upb_tabent_hasnext(e) && - upb_tabent_next(e) == ent) { - prev = e; - break; - } - } - - if (prev) { - if (upb_tabent_hasnext(ent)) { - upb_tabent_setnext(prev, upb_tabent_next(ent)); - } else { - upb_tabent_clearnext(prev); - } - } - - t->t.count--; - upb_tabent_clear(ent); - } -} - -void upb_inttable_setentryvalue(upb_inttable* t, intptr_t iter, upb_value v) { - if ((size_t)iter < t->array_size) { - mutable_array(t)[iter] = v; - } else { - upb_tabent* ent = &t->t.entries[iter - t->array_size]; - ent->val = v; - } -} - -bool upb_inttable_done(const upb_inttable* t, intptr_t iter) { - if ((uintptr_t)iter >= t->array_size + upb_table_size(&t->t)) { - return true; - } else if ((size_t)iter < t->array_size) { - return !upb_inttable_arrhas(t, iter); - } else { - return upb_tabent_isempty(&t->t.entries[iter - t->array_size]); - } -} - -uintptr_t upb_inttable_iter_key(const upb_inttable* t, intptr_t iter) { - UPB_ASSERT(!upb_inttable_done(t, iter)); - return (size_t)iter < t->array_size - ? iter - : t->t.entries[iter - t->array_size].key.num; -} - -upb_value upb_inttable_iter_value(const upb_inttable* t, intptr_t iter) { - UPB_ASSERT(!upb_inttable_done(t, iter)); - if ((size_t)iter < t->array_size) { - return t->array[iter]; - } else { - return t->t.entries[iter - t->array_size].val; - } -} diff --git a/vendor/upb/hash/common.h b/vendor/upb/hash/common.h deleted file mode 100644 index 2e95df2..0000000 --- a/vendor/upb/hash/common.h +++ /dev/null @@ -1,196 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* - * upb_table - * - * This header is INTERNAL-ONLY! Its interfaces are not public or stable! - * This file defines very fast int->upb_value (inttable) and string->upb_value - * (strtable) hash tables. - * - * The table uses chained scatter with Brent's variation (inspired by the Lua - * implementation of hash tables). The hash function for strings is Austin - * Appleby's "MurmurHash." - * - * The inttable uses uintptr_t as its key, which guarantees it can be used to - * store pointers or integers of at least 32 bits (upb isn't really useful on - * systems where sizeof(void*) < 4). - * - * The table must be homogeneous (all values of the same type). In debug - * mode, we check this on insert and lookup. - */ - -#ifndef UPB_HASH_COMMON_H_ -#define UPB_HASH_COMMON_H_ - -#include -#include - -#include "upb/base/string_view.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -/* upb_value ******************************************************************/ - -typedef struct { - uint64_t val; -} upb_value; - -/* For each value ctype, define the following set of functions: - * - * // Get/set an int32 from a upb_value. - * int32_t upb_value_getint32(upb_value val); - * void upb_value_setint32(upb_value *val, int32_t cval); - * - * // Construct a new upb_value from an int32. - * upb_value upb_value_int32(int32_t val); */ -#define FUNCS(name, membername, type_t, converter) \ - UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ - val->val = (uint64_t)cval; \ - } \ - UPB_INLINE upb_value upb_value_##name(type_t val) { \ - upb_value ret; \ - upb_value_set##name(&ret, val); \ - return ret; \ - } \ - UPB_INLINE type_t upb_value_get##name(upb_value val) { \ - return (type_t)(converter)val.val; \ - } - -FUNCS(int32, int32, int32_t, int32_t) -FUNCS(int64, int64, int64_t, int64_t) -FUNCS(uint32, uint32, uint32_t, uint32_t) -FUNCS(uint64, uint64, uint64_t, uint64_t) -FUNCS(bool, _bool, bool, bool) -FUNCS(cstr, cstr, char*, uintptr_t) -FUNCS(uintptr, uptr, uintptr_t, uintptr_t) -FUNCS(ptr, ptr, void*, uintptr_t) -FUNCS(constptr, constptr, const void*, uintptr_t) - -#undef FUNCS - -UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { - memcpy(&val->val, &cval, sizeof(cval)); -} - -UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { - memcpy(&val->val, &cval, sizeof(cval)); -} - -UPB_INLINE upb_value upb_value_float(float cval) { - upb_value ret; - upb_value_setfloat(&ret, cval); - return ret; -} - -UPB_INLINE upb_value upb_value_double(double cval) { - upb_value ret; - upb_value_setdouble(&ret, cval); - return ret; -} - -/* upb_key *****************************************************************/ - -// A uint32 size followed by that number of bytes stored contiguously. -typedef struct { - uint32_t size; - const char data[]; -} upb_SizePrefixString; - -/* Either: - * 1. an actual integer key - * 2. a SizePrefixString*, owned by us. - * - * ...depending on whether this is a string table or an int table. */ -typedef union { - uintptr_t num; - const upb_SizePrefixString* str; -} upb_key; - -UPB_INLINE upb_StringView upb_key_strview(upb_key key) { - return upb_StringView_FromDataAndSize(key.str->data, key.str->size); -} - -/* upb_table ******************************************************************/ - -typedef struct _upb_tabent { - upb_value val; - upb_key key; - - /* Internal chaining */ - struct _upb_tabent* next; -} upb_tabent; - -typedef struct { - upb_tabent* entries; - /* Number of entries in the hash part. */ - uint32_t count; - - /* Mask to turn hash value -> bucket. The map's allocated size is mask + 1.*/ - uint32_t mask; -} upb_table; - -UPB_INLINE size_t upb_table_size(const upb_table* t) { return t->mask + 1; } - -// Internal-only functions, in .h file only out of necessity. - -UPB_INLINE upb_key upb_key_empty(void) { - upb_key ret; - memset(&ret, 0, sizeof(upb_key)); - return ret; -} - -UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { - upb_key key = e->key; - UPB_STATIC_ASSERT(sizeof(key.num) == sizeof(key.str), "Sizes don't match"); - uintptr_t val; - memcpy(&val, &key, sizeof(val)); - // Note: for upb_inttables a tab_key is a true integer key value, but the - // inttable maintains the invariant that 0 value is always stored in the - // compact table and never as a upb_tabent* so we can always use the 0 - // key value to identify an empty tabent. - return val == 0; -} - -UPB_INLINE bool upb_tabent_hasnext(const upb_tabent* e) { - return e->next != NULL; -} - -UPB_INLINE void upb_tabent_clearnext(upb_tabent* e) { e->next = NULL; } - -UPB_INLINE void upb_tabent_clear(upb_tabent* e) { - memset(&e->key, 0, sizeof(e->key)); - e->next = NULL; - UPB_ASSERT(upb_tabent_isempty(e)); -} - -UPB_INLINE upb_tabent* upb_tabent_next(const upb_tabent* e) { - UPB_ASSERT(upb_tabent_hasnext(e)); - return e->next; -} - -UPB_INLINE void upb_tabent_setnext(upb_tabent* e, upb_tabent* next) { - UPB_ASSERT(next != NULL); - UPB_ASSERT(next != e); - e->next = next; - UPB_ASSERT(upb_tabent_hasnext(e)); -} - -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_HASH_COMMON_H_ */ diff --git a/vendor/upb/hash/ext_table.h b/vendor/upb/hash/ext_table.h deleted file mode 100644 index 9571512..0000000 --- a/vendor/upb/hash/ext_table.h +++ /dev/null @@ -1,66 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2026 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_HASH_EXT_TABLE_H_ -#define UPB_HASH_EXT_TABLE_H_ - -#include -#include - -#include "upb/hash/common.h" -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - upb_table t; -} upb_exttable; - -#ifdef __cplusplus -extern "C" { -#endif - -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -UPB_NODISCARD bool upb_exttable_init(upb_exttable* table, size_t expected_size, - upb_Arena* a); - -// Returns the number of values in the table. -UPB_INLINE size_t upb_exttable_count(const upb_exttable* t) { - return t->t.count; -} - -void upb_exttable_clear(upb_exttable* t); - -// Inserts the given key and value into the hashtable. -// The key must not already exist in the hash table, and must not be NULL. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. -UPB_NODISCARD bool upb_exttable_insert(upb_exttable* t, const void* k, - const uint32_t* v, upb_Arena* a); - -// Looks up key and ext_number in this table, returning the value if the key was -// found, or NULL otherwise. -const uint32_t* upb_exttable_lookup(const upb_exttable* t, const void* k, - uint32_t ext_number); - -// Removes an item from the table. Returns the removed item if the remove was -// successful, or NULL if the key was not found. -const uint32_t* upb_exttable_remove(upb_exttable* t, const void* k, - uint32_t ext_number); - -size_t upb_exttable_size(const upb_exttable* t); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_HASH_EXT_TABLE_H_ */ diff --git a/vendor/upb/hash/int_table.h b/vendor/upb/hash/int_table.h deleted file mode 100644 index b2f8451..0000000 --- a/vendor/upb/hash/int_table.h +++ /dev/null @@ -1,106 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_HASH_INT_TABLE_H_ -#define UPB_HASH_INT_TABLE_H_ - -#include -#include - -#include "upb/hash/common.h" -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - upb_table t; // For entries that don't fit in the array part. - // Array part of the table. - // Pointers on this table are const so we can create static initializers for - // tables. We cast away const sometimes, but *only* when the containing - // upb_table is known to be non-const. This requires a bit of care, but - // the subtlety is confined to table.c. - const upb_value* array; - // Track presence in the array part. Each bit at index (key % 8) at the - // presence_mask[key/8] indicates if the element is present in the array part. - const uint8_t* presence_mask; - uint32_t array_size; // Array part size. - uint32_t array_count; // Array part number of elements. -} upb_inttable; - -#ifdef __cplusplus -extern "C" { -#endif - -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -UPB_NODISCARD bool upb_inttable_init(upb_inttable* table, upb_Arena* a); - -// Returns the number of values in the table. -size_t upb_inttable_count(const upb_inttable* t); - -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. -// The value must not be UINTPTR_MAX. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. -UPB_NODISCARD bool upb_inttable_insert(upb_inttable* t, uintptr_t key, - upb_value val, upb_Arena* a); - -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v); - -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val); - -// Updates an existing entry in an inttable. -// If the entry does not exist, returns false and does nothing. -// Unlike insert/remove, this does not invalidate iterators. -bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val); - -// Optimizes the table for the current set of entries, for both memory use and -// lookup time. Client should call this after all entries have been inserted; -// inserting more entries is legal, but will likely require a table resize. -// Returns false if reallocation fails. -UPB_NODISCARD bool upb_inttable_compact(upb_inttable* t, upb_Arena* a); - -// Clears the table. -void upb_inttable_clear(upb_inttable* t); - -// Iteration over inttable: -// -// intptr_t iter = UPB_INTTABLE_BEGIN; -// uintptr_t key; -// upb_value val; -// while (upb_inttable_next(t, &key, &val, &iter)) { -// // ... -// } - -#define UPB_INTTABLE_BEGIN -1 - -bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, - intptr_t* iter); -void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); -void upb_inttable_setentryvalue(upb_inttable* t, intptr_t iter, upb_value v); -bool upb_inttable_done(const upb_inttable* t, intptr_t i); -uintptr_t upb_inttable_iter_key(const upb_inttable* t, intptr_t iter); -upb_value upb_inttable_iter_value(const upb_inttable* t, intptr_t iter); - -UPB_INLINE bool upb_inttable_arrhas(const upb_inttable* t, uintptr_t key) { - return (t->presence_mask[key / 8] & (1 << (key % 8))) != 0; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_HASH_INT_TABLE_H_ */ diff --git a/vendor/upb/hash/str_table.h b/vendor/upb/hash/str_table.h deleted file mode 100644 index e3d4284..0000000 --- a/vendor/upb/hash/str_table.h +++ /dev/null @@ -1,150 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_HASH_STR_TABLE_H_ -#define UPB_HASH_STR_TABLE_H_ - -#include -#include -#include - -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - upb_table t; -} upb_strtable; - -#ifdef __cplusplus -extern "C" { -#endif - -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -UPB_NODISCARD bool upb_strtable_init(upb_strtable* table, size_t expected_size, - upb_Arena* a); - -// Returns the number of values in the table. -UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { - return t->t.count; -} - -void upb_strtable_clear(upb_strtable* t); - -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. The key is not required -// to be NULL-terminated, and the table will make an internal copy of the key. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. */ -UPB_NODISCARD bool upb_strtable_insert(upb_strtable* t, const char* key, - size_t len, upb_value val, upb_Arena* a); - -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v); - -// For NULL-terminated strings. -UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_lookup2(t, key, strlen(key), v); -} - -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val); - -UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_remove2(t, key, strlen(key), v); -} - -// Exposed for testing only. -UPB_NODISCARD bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, - upb_Arena* a); - -/* Iteration over strtable: - * - * intptr_t iter = UPB_STRTABLE_BEGIN; - * upb_StringView key; - * upb_value val; - * while (upb_strtable_next2(t, &key, &val, &iter)) { - * // ... - * } - */ - -#define UPB_STRTABLE_BEGIN -1 - -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter); -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); - -/* DEPRECATED iterators, slated for removal. - * - * Iterators for string tables. We are subject to some kind of unusual - * design constraints: - * - * For high-level languages: - * - we must be able to guarantee that we don't crash or corrupt memory even if - * the program accesses an invalidated iterator. - * - * For C++11 range-based for: - * - iterators must be copyable - * - iterators must be comparable - * - it must be possible to construct an "end" value. - * - * Iteration order is undefined. - * - * Modifying the table invalidates iterators. upb_{str,int}table_done() is - * guaranteed to work even on an invalidated iterator, as long as the table it - * is iterating over has not been freed. Calling next() or accessing data from - * an invalidated iterator yields unspecified elements from the table, but it is - * guaranteed not to crash and to return real table elements (except when done() - * is true). */ -/* upb_strtable_iter **********************************************************/ - -/* upb_strtable_iter i; - * upb_strtable_begin(&i, t); - * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { - * const char *key = upb_strtable_iter_key(&i); - * const upb_value val = upb_strtable_iter_value(&i); - * // ... - * } - */ - -typedef struct { - const upb_strtable* t; - size_t index; -} upb_strtable_iter; - -UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { - return &i->t->t.entries[i->index]; -} - -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); -void upb_strtable_next(upb_strtable_iter* i); -bool upb_strtable_done(const upb_strtable_iter* i); -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); -upb_value upb_strtable_iter_value(const upb_strtable_iter* i); -void upb_strtable_iter_setdone(upb_strtable_iter* i); -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_HASH_STR_TABLE_H_ */ diff --git a/vendor/upb/hash/test.cc b/vendor/upb/hash/test.cc deleted file mode 100644 index 5cfa36b..0000000 --- a/vendor/upb/hash/test.cc +++ /dev/null @@ -1,542 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// Tests for upb_table. - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include "absl/container/flat_hash_map.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/ext_table.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/message/test.upb_minitable.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -using std::vector; - -TEST(Table, StringTable) { - vector keys; - keys.push_back("google.protobuf.FileDescriptorSet"); - keys.push_back("google.protobuf.FileDescriptorProto"); - keys.push_back("google.protobuf.DescriptorProto"); - keys.push_back("google.protobuf.DescriptorProto.ExtensionRange"); - keys.push_back("google.protobuf.FieldDescriptorProto"); - keys.push_back("google.protobuf.EnumDescriptorProto"); - keys.push_back("google.protobuf.EnumValueDescriptorProto"); - keys.push_back("google.protobuf.ServiceDescriptorProto"); - keys.push_back("google.protobuf.MethodDescriptorProto"); - keys.push_back("google.protobuf.FileOptions"); - keys.push_back("google.protobuf.MessageOptions"); - keys.push_back("google.protobuf.FieldOptions"); - keys.push_back("google.protobuf.EnumOptions"); - keys.push_back("google.protobuf.EnumValueOptions"); - keys.push_back("google.protobuf.ServiceOptions"); - keys.push_back("google.protobuf.MethodOptions"); - keys.push_back("google.protobuf.UninterpretedOption"); - keys.push_back("google.protobuf.UninterpretedOption.NamePart"); - - /* Initialize structures. */ - upb::Arena arena; - upb_strtable t; - upb_strtable_init(&t, keys.size(), arena.ptr()); - std::map m; - std::set all; - for (const auto& key : keys) { - all.insert(key); - upb_value val = {uint64_t(key[0])}; - upb_strtable_insert(&t, key.data(), key.size(), val, arena.ptr()); - m[key] = key[0]; - } - - /* Test correctness. */ - for (const auto& key : keys) { - upb_value val; - bool ok = upb_strtable_lookup2(&t, key.data(), key.size(), &val); - EXPECT_TRUE(ok); - EXPECT_EQ(val.val, uint64_t(key[0])); - EXPECT_EQ(m[key], key[0]); - } - - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&t, &key, &val, &iter)) { - std::set::iterator i = all.find(key.data); - EXPECT_NE(i, all.end()); - all.erase(i); - } - EXPECT_TRUE(all.empty()); - - // Test iteration with resizes. - - for (int i = 0; i < 10; i++) { - intptr_t iter = UPB_STRTABLE_BEGIN; - while (upb_strtable_next2(&t, &key, &val, &iter)) { - // Even if we invalidate the iterator it should only return real elements. - EXPECT_EQ(val.val, m[key.data]); - - // Force a resize even though the size isn't changing. - // Also forces the table size to grow so some new buckets end up empty. - bool ok = upb_strtable_resize(&t, 5 + i, arena.ptr()); - EXPECT_TRUE(ok); - } - } -} - -class IntTableTest : public testing::TestWithParam { - void SetUp() override { - if (GetParam() > 0) { - for (int i = 0; i < GetParam(); i++) { - keys_.push_back(i + 1); - } - } else { - for (int32_t i = 0; i < 64; i++) { - if (i < 32) - keys_.push_back(i + 1); - else - keys_.push_back(10101 + i); - } - } - } - - protected: - std::vector keys_; -}; - -TEST_P(IntTableTest, TestIntTable) { - /* Initialize structures. */ - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - uint32_t largest_key = 0; - std::map m; - absl::flat_hash_map hm; - for (const auto& key : keys_) { - largest_key = UPB_MAX((int32_t)largest_key, key); - upb_value val = upb_value_uint32(key * 2); - bool ok = upb_inttable_insert(&t, key, val, arena.ptr()); - EXPECT_TRUE(ok); - m[key] = key * 2; - hm[key] = key * 2; - } - EXPECT_EQ(upb_inttable_count(&t), keys_.size()); - - /* Test correctness. */ - int count = 0; - for (uint32_t i = 0; i <= largest_key; i++) { - upb_value val; - bool ok = upb_inttable_lookup(&t, i, &val); - if (ok) { /* Assume map implementation is correct. */ - EXPECT_EQ(val.val, i * 2); - EXPECT_EQ(m[i], i * 2); - EXPECT_EQ(hm[i], i * 2); - count++; - } - } - EXPECT_EQ(count, keys_.size()); - EXPECT_EQ(count, upb_inttable_count(&t)); - - // Test replace. - count = 0; - for (uint32_t i = 0; i <= largest_key; i++) { - upb_value val = upb_value_uint32(i * 3); - bool ok = upb_inttable_replace(&t, i, val); - if (ok) { /* Assume map implementation is correct. */ - m[i] = i * 3; - hm[i] = i * 3; - count++; - } - } - EXPECT_EQ(count, keys_.size()); - EXPECT_EQ(count, upb_inttable_count(&t)); - - // Compact and test correctness again. - upb_inttable_compact(&t, arena.ptr()); - count = 0; - for (uint32_t i = 0; i <= largest_key; i++) { - upb_value val; - bool ok = upb_inttable_lookup(&t, i, &val); - if (ok) { /* Assume map implementation is correct. */ - EXPECT_EQ(val.val, i * 3); - EXPECT_EQ(m[i], i * 3); - EXPECT_EQ(hm[i], i * 3); - count++; - } - } - EXPECT_EQ(count, keys_.size()); - EXPECT_EQ(count, upb_inttable_count(&t)); - - for (const auto& key : keys_) { - upb_value val; - bool ok = upb_inttable_remove(&t, key, &val); - EXPECT_TRUE(ok); - EXPECT_EQ(val.val, (uint32_t)key * 3); - count--; - EXPECT_EQ(count, upb_inttable_count(&t)); - } - EXPECT_EQ(0, upb_inttable_count(&t)); - - upb_inttable_clear(&t); -} - -TEST(TableTest, ExtTable) { - upb_Arena* a = upb_Arena_New(); - upb_exttable table; - ASSERT_TRUE(upb_exttable_init(&table, 4, a)); - - const upb_MiniTable* mt1 = &upb_0test__TestExtensions_msg_init; - const upb_MiniTable* mt2 = &upb_0test__TestMessageSet_msg_init; - - const upb_MiniTableExtension* ext1_10 = - upb_test_TestExtensions_optional_int32_ext_ext; - const upb_MiniTableExtension* ext1_20 = upb_test_optional_msg_ext_ext; - const upb_MiniTableExtension* ext2_10 = - upb_test_MessageSetMember_message_set_extension_ext; - - ASSERT_TRUE(upb_exttable_insert(&table, mt1, (const uint32_t*)ext1_10, a)); - ASSERT_TRUE(upb_exttable_insert(&table, mt1, (const uint32_t*)ext1_20, a)); - ASSERT_TRUE(upb_exttable_insert(&table, mt2, (const uint32_t*)ext2_10, a)); - - ASSERT_EQ(3, upb_exttable_count(&table)); - - const uint32_t* v; - v = upb_exttable_lookup(&table, mt1, 1000); // optional_int32_ext - ASSERT_NE(nullptr, v); - ASSERT_EQ((const uint32_t*)ext1_10, v); - - v = upb_exttable_lookup(&table, mt1, 1002); // optional_msg_ext - ASSERT_NE(nullptr, v); - ASSERT_EQ((const uint32_t*)ext1_20, v); - - v = upb_exttable_lookup(&table, mt2, 2000); // message_set_extension - ASSERT_NE(nullptr, v); - ASSERT_EQ((const uint32_t*)ext2_10, v); - - ASSERT_EQ(nullptr, upb_exttable_lookup(&table, mt2, 20)); - - v = upb_exttable_remove(&table, mt1, 1000); - ASSERT_NE(nullptr, v); - ASSERT_EQ((const uint32_t*)ext1_10, v); - ASSERT_EQ(2, upb_exttable_count(&table)); - - ASSERT_EQ(nullptr, upb_exttable_lookup(&table, mt1, 1000)); - - upb_Arena_Free(a); -} - -TEST(IntTableTest, EmptyTable) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - EXPECT_FALSE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_TRUE(upb_inttable_done(&t, iter)); - - // Insert a value. - upb_inttable_insert(&t, 0, upb_value_bool(true), arena.ptr()); - iter = UPB_INTTABLE_BEGIN; - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Clear the table. - upb_inttable_clear(&t); - iter = UPB_INTTABLE_BEGIN; - EXPECT_FALSE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_TRUE(upb_inttable_done(&t, iter)); -} - -TEST(IntTableTest, Iteration) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - upb_inttable_insert(&t, 0, upb_value_bool(true), arena.ptr()); - upb_inttable_insert(&t, 2, upb_value_bool(true), arena.ptr()); - upb_inttable_insert(&t, 4, upb_value_bool(true), arena.ptr()); - - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // First element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_EQ(key, 0); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), 0); - EXPECT_EQ(val.val, true); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, true); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Second element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_EQ(key, 2); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), 2); - EXPECT_EQ(val.val, true); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, true); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Third element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_EQ(key, 4); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), 4); - EXPECT_EQ(val.val, true); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, true); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Update the third element. - upb_inttable_setentryvalue(&t, iter, upb_value_bool(false)); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, false); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Done with the iteration. - EXPECT_FALSE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_TRUE(upb_inttable_done(&t, iter)); - - upb_inttable_clear(&t); -} - -TEST(IntTableTest, IterationWithNonZeroStart) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - upb_value val_for_key_2 = {uint64_t("value_for_key_2")}; - upb_value val_for_key_4 = {uint64_t("value_for_key_4")}; - upb_inttable_insert(&t, 2, val_for_key_2, arena.ptr()); - upb_inttable_insert(&t, 4, val_for_key_4, arena.ptr()); - - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // First element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_EQ(key, 2); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), 2); - EXPECT_EQ(val.val, val_for_key_2.val); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, val_for_key_2.val); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Second element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_EQ(key, 4); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), 4); - EXPECT_EQ(val.val, val_for_key_4.val); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, val_for_key_4.val); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Done with the iteration. - EXPECT_FALSE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_TRUE(upb_inttable_done(&t, iter)); - - upb_inttable_clear(&t); -} - -TEST(IntTableTest, IterationWithArrayOnly) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - upb_inttable_insert(&t, 0, upb_value_bool(true), arena.ptr()); - - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // The only element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_EQ(key, 0); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), 0); - EXPECT_EQ(val.val, true); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, true); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Done with the iteration. - EXPECT_FALSE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_TRUE(upb_inttable_done(&t, iter)); - - upb_inttable_clear(&t); -} - -TEST(IntTableTest, BoolKeys) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - upb_inttable_insert(&t, false, upb_value_bool(true), arena.ptr()); - upb_inttable_insert(&t, true, upb_value_bool(false), arena.ptr()); - - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // First element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - bool key_bool; - memcpy(&key_bool, &key, sizeof(key_bool)); - EXPECT_EQ(key_bool, false); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), false); - EXPECT_EQ(val.val, true); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, true); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Second element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - memcpy(&key_bool, &key, sizeof(key_bool)); - EXPECT_EQ(key_bool, true); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), true); - EXPECT_EQ(val.val, false); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, false); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Done with the iteration. - EXPECT_FALSE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_TRUE(upb_inttable_done(&t, iter)); - - upb_inttable_clear(&t); -} - -TEST(IntTableTest, EnumValues) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - upb_inttable_insert(&t, 0, upb_value_int32(0), arena.ptr()); - upb_inttable_insert(&t, -1, upb_value_int32(-1), arena.ptr()); - - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - int32_t key_int32; - - // First element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - memcpy(&key_int32, &key, sizeof(key_int32)); - EXPECT_EQ(key_int32, 0); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), 0); - EXPECT_EQ(val.val, 0); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, 0); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Second element. - EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter)); - memcpy(&key_int32, &key, sizeof(key_int32)); - EXPECT_EQ(key_int32, -1); - EXPECT_EQ(upb_inttable_iter_key(&t, iter), -1); - EXPECT_EQ(val.val, -1); - EXPECT_EQ(upb_inttable_iter_value(&t, iter).val, -1); - EXPECT_FALSE(upb_inttable_done(&t, iter)); - - // Done with the iteration. - EXPECT_FALSE(upb_inttable_next(&t, &key, &val, &iter)); - EXPECT_TRUE(upb_inttable_done(&t, iter)); - - upb_inttable_clear(&t); -} - -INSTANTIATE_TEST_SUITE_P(IntTableParams, IntTableTest, - testing::Values(8, 64, 512, -32)); - -TEST(Table, MaxValue) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - uint64_t uint64_max = (uint64_t)-1; - upb_inttable_insert(&t, 0, upb_value_uint64(uint64_max), arena.ptr()); - upb_inttable_insert(&t, 1, upb_value_uint64(uint64_max), arena.ptr()); - upb_inttable_insert(&t, 2, upb_value_uint64(uint64_max), arena.ptr()); - upb_value val; - EXPECT_TRUE(upb_inttable_lookup(&t, 0, &val)); - EXPECT_EQ(val.val, uint64_max); - EXPECT_TRUE(upb_inttable_lookup(&t, 1, &val)); - EXPECT_EQ(val.val, uint64_max); - EXPECT_TRUE(upb_inttable_lookup(&t, 2, &val)); - EXPECT_EQ(val.val, uint64_max); - - upb_inttable_compact(&t, arena.ptr()); - EXPECT_TRUE(upb_inttable_lookup(&t, 0, &val)); - EXPECT_EQ(val.val, uint64_max); - EXPECT_TRUE(upb_inttable_lookup(&t, 1, &val)); - EXPECT_EQ(val.val, uint64_max); - EXPECT_TRUE(upb_inttable_lookup(&t, 2, &val)); - EXPECT_EQ(val.val, uint64_max); - - upb_inttable_remove(&t, 0, nullptr); - upb_inttable_remove(&t, 1, nullptr); - upb_inttable_remove(&t, 2, nullptr); - EXPECT_FALSE(upb_inttable_lookup(&t, 0, &val)); - EXPECT_FALSE(upb_inttable_lookup(&t, 1, &val)); - EXPECT_FALSE(upb_inttable_lookup(&t, 2, &val)); -} - -TEST(Table, MaxValueWithLargeArray) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - uint64_t uint64_max = (uint64_t)-1; - for (int i = 1; i < 121; i++) { - upb_inttable_insert(&t, i, upb_value_uint64(uint64_max), arena.ptr()); - } - upb_value val; - for (int i = 1; i < 121; i++) { - EXPECT_TRUE(upb_inttable_lookup(&t, i, &val)); - EXPECT_EQ(val.val, uint64_max); - } - - upb_inttable_compact(&t, arena.ptr()); - for (int i = 1; i < 121; i++) { - EXPECT_TRUE(upb_inttable_lookup(&t, i, &val)); - EXPECT_EQ(val.val, uint64_max); - } - - for (int i = 1; i < 121; i++) { - upb_inttable_remove(&t, i, nullptr); - } - for (int i = 1; i < 121; i++) { - EXPECT_FALSE(upb_inttable_lookup(&t, i, &val)); - } -} - -TEST(IntTableTest, Delete) { - upb::Arena arena; - upb_inttable t; - upb_inttable_init(&t, arena.ptr()); - upb_inttable_insert(&t, 0, upb_value_bool(true), arena.ptr()); - upb_inttable_insert(&t, 2, upb_value_bool(true), arena.ptr()); - upb_inttable_insert(&t, 4, upb_value_bool(true), arena.ptr()); - upb_inttable_compact(&t, arena.ptr()); - upb_inttable_remove(&t, 0, nullptr); - upb_inttable_remove(&t, 2, nullptr); - upb_inttable_remove(&t, 4, nullptr); - - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(&t, &key, &val, &iter)) { - FAIL(); - } -} - -TEST(Table, Init) { - for (int i = 0; i < 2048; i++) { - /* Tests that the size calculations in init() (lg2 size for target load) - * work for all expected sizes. */ - upb::Arena arena; - upb_strtable t; - upb_strtable_init(&t, i, arena.ptr()); - } -} diff --git a/vendor/upb/json/BUILD b/vendor/upb/json/BUILD deleted file mode 100644 index 74002a3..0000000 --- a/vendor/upb/json/BUILD +++ /dev/null @@ -1,110 +0,0 @@ -# TODO: describe this package. - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//bazel:proto_library.bzl", "proto_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") -load( - "//upb/bazel:upb_proto_library.bzl", - "upb_c_proto_library", - "upb_proto_reflection_library", -) - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "json", - srcs = [ - "decode.c", - "encode.c", - ], - hdrs = [ - "decode.h", - "encode.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/lex", - "//upb/mem", - "//upb/message", - "//upb/mini_table", - "//upb/port", - "//upb/reflection", - "//upb/wire", - ], -) - -cc_test( - name = "decode_test", - srcs = ["decode_test.cc"], - deps = [ - ":json", - ":test_upb_proto", - ":test_upb_proto_reflection", - "//:struct_upb_proto", - "//upb/base", - "//upb/mem", - "//upb/reflection", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "encode_test", - srcs = ["encode_test.cc"], - deps = [ - ":json", - ":test_upb_proto", - ":test_upb_proto_reflection", - "//:struct_upb_proto", - "//upb/base", - "//upb/mem", - "//upb/reflection", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -proto_library( - name = "test_proto", - testonly = 1, - srcs = ["test.proto"], - deps = ["//:struct_proto"], -) - -upb_c_proto_library( - name = "test_upb_proto", - testonly = 1, - deps = [":test_proto"], -) - -upb_proto_reflection_library( - name = "test_upb_proto_reflection", - testonly = 1, - deps = [":test_proto"], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - exclude = ["fuzz_test.cc"], - ), - visibility = ["//upb:__pkg__"], -) - -filegroup( - name = "test_protos", - srcs = glob( - [ - "**/*test.proto", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/json/decode.c b/vendor/upb/json/decode.c deleted file mode 100644 index 0f25c4b..0000000 --- a/vendor/upb/json/decode.c +++ /dev/null @@ -1,1577 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/json/decode.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/lex/atoi.h" -#include "upb/lex/unicode.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" -#include "upb/reflection/def.h" -#include "upb/reflection/message.h" -#include "upb/wire/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - const char *ptr, *end; - upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ - const upb_DefPool* symtab; - int depth; - int result; - upb_Status* status; - jmp_buf err; - int line; - const char* line_begin; - bool is_first; - int options; - const upb_FieldDef* debug_field; -} jsondec; - -typedef struct { - upb_MessageValue value; - bool ignore; -} upb_JsonMessageValue; - -enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; - -/* Forward declarations of mutually-recursive functions. */ -static void jsondec_wellknown(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); -static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); -static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); -static void jsondec_object(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); - -static bool jsondec_streql(upb_StringView str, const char* lit) { - return str.size == strlen(lit) && memcmp(str.data, lit, str.size) == 0; -} - -static bool jsondec_isnullvalue(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Enum && - strcmp(upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f)), - "google.protobuf.NullValue") == 0; -} - -static bool jsondec_isvalue(const upb_FieldDef* f) { - return (upb_FieldDef_CType(f) == kUpb_CType_Message && - upb_MessageDef_WellKnownType(upb_FieldDef_MessageSubDef(f)) == - kUpb_WellKnown_Value) || - jsondec_isnullvalue(f); -} - -static void jsondec_seterrmsg(jsondec* d, const char* msg) { - upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, - (int)(d->ptr - d->line_begin), msg); -} - -UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { - jsondec_seterrmsg(d, msg); - UPB_LONGJMP(d->err, 1); -} - -UPB_PRINTF(2, 3) -UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { - va_list argp; - upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: ", d->line, - (int)(d->ptr - d->line_begin)); - va_start(argp, fmt); - upb_Status_VAppendErrorFormat(d->status, fmt, argp); - va_end(argp); - UPB_LONGJMP(d->err, 1); -} - -// Advances d->ptr until the next non-whitespace character or to the end of -// the buffer. -static void jsondec_consumews(jsondec* d) { - while (d->ptr != d->end) { - switch (*d->ptr) { - case '\n': - d->line++; - d->line_begin = d->ptr; - /* Fallthrough. */ - case '\r': - case '\t': - case ' ': - d->ptr++; - break; - default: - return; - } - } -} - -// Advances d->ptr until the next non-whitespace character. Postcondition that -// d->ptr is pointing at a valid non-whitespace character (will err if end of -// buffer is reached). -static void jsondec_skipws(jsondec* d) { - jsondec_consumews(d); - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF"); - } -} - -static bool jsondec_tryparsech(jsondec* d, char ch) { - if (d->ptr == d->end || *d->ptr != ch) return false; - d->ptr++; - return true; -} - -static void jsondec_parselit(jsondec* d, const char* lit) { - size_t avail = d->end - d->ptr; - size_t len = strlen(lit); - if (avail < len || memcmp(d->ptr, lit, len) != 0) { - jsondec_errf(d, "Expected: '%s'", lit); - } - d->ptr += len; -} - -static void jsondec_wsch(jsondec* d, char ch) { - jsondec_skipws(d); - if (!jsondec_tryparsech(d, ch)) { - jsondec_errf(d, "Expected: '%c'", ch); - } -} - -static void jsondec_true(jsondec* d) { jsondec_parselit(d, "true"); } -static void jsondec_false(jsondec* d) { jsondec_parselit(d, "false"); } -static void jsondec_null(jsondec* d) { jsondec_parselit(d, "null"); } - -static void jsondec_entrysep(jsondec* d) { - jsondec_skipws(d); - jsondec_parselit(d, ":"); -} - -static int jsondec_rawpeek(jsondec* d) { - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF"); - } - - switch (*d->ptr) { - case '{': - return JD_OBJECT; - case '[': - return JD_ARRAY; - case '"': - return JD_STRING; - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return JD_NUMBER; - case 't': - return JD_TRUE; - case 'f': - return JD_FALSE; - case 'n': - return JD_NULL; - default: - jsondec_errf(d, "Unexpected character: '%c'", *d->ptr); - } -} - -/* JSON object/array **********************************************************/ - -/* These are used like so: - * - * jsondec_objstart(d); - * while (jsondec_objnext(d)) { - * ... - * } - * jsondec_objend(d) */ - -static int jsondec_peek(jsondec* d) { - jsondec_skipws(d); - return jsondec_rawpeek(d); -} - -static void jsondec_push(jsondec* d) { - if (--d->depth < 0) { - jsondec_err(d, "Recursion limit exceeded"); - } - d->is_first = true; -} - -static bool jsondec_seqnext(jsondec* d, char end_ch) { - bool is_first = d->is_first; - d->is_first = false; - jsondec_skipws(d); - if (*d->ptr == end_ch) return false; - if (!is_first) jsondec_parselit(d, ","); - return true; -} - -static void jsondec_arrstart(jsondec* d) { - jsondec_push(d); - jsondec_wsch(d, '['); -} - -static void jsondec_arrend(jsondec* d) { - d->depth++; - jsondec_wsch(d, ']'); -} - -static bool jsondec_arrnext(jsondec* d) { return jsondec_seqnext(d, ']'); } - -static void jsondec_objstart(jsondec* d) { - jsondec_push(d); - jsondec_wsch(d, '{'); -} - -static void jsondec_objend(jsondec* d) { - d->depth++; - jsondec_wsch(d, '}'); -} - -static bool jsondec_objnext(jsondec* d) { - if (!jsondec_seqnext(d, '}')) return false; - if (jsondec_peek(d) != JD_STRING) { - jsondec_err(d, "Object must start with string"); - } - return true; -} - -/* JSON number ****************************************************************/ - -static bool jsondec_tryskipdigits(jsondec* d) { - const char* start = d->ptr; - - while (d->ptr < d->end) { - if (*d->ptr < '0' || *d->ptr > '9') { - break; - } - d->ptr++; - } - - return d->ptr != start; -} - -static void jsondec_skipdigits(jsondec* d) { - if (!jsondec_tryskipdigits(d)) { - jsondec_err(d, "Expected one or more digits"); - } -} - -static double jsondec_number(jsondec* d) { - const char* start = d->ptr; - - UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); - - /* Skip over the syntax of a number, as specified by JSON. */ - if (*d->ptr == '-') d->ptr++; - - if (jsondec_tryparsech(d, '0')) { - if (jsondec_tryskipdigits(d)) { - jsondec_err(d, "number cannot have leading zero"); - } - } else { - jsondec_skipdigits(d); - } - - if (d->ptr == d->end) goto parse; - if (jsondec_tryparsech(d, '.')) { - jsondec_skipdigits(d); - } - if (d->ptr == d->end) goto parse; - - if (*d->ptr == 'e' || *d->ptr == 'E') { - d->ptr++; - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF in number"); - } - if (*d->ptr == '+' || *d->ptr == '-') { - d->ptr++; - } - jsondec_skipdigits(d); - } - -parse: - /* Having verified the syntax of a JSON number, use strtod() to parse - * (strtod() accepts a superset of JSON syntax). */ - errno = 0; - { - // Copy the number into a null-terminated scratch buffer since strtod - // expects a null-terminated string. - char nullz[64]; - ptrdiff_t len = d->ptr - start; - if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { - jsondec_err(d, "excessively long number"); - } - memcpy(nullz, start, len); - nullz[len] = '\0'; - - char* end; - double val = strtod(nullz, &end); - UPB_ASSERT(end - nullz == len); - - /* Currently the min/max-val conformance tests fail if we check this. Does - * this mean the conformance tests are wrong or strtod() is wrong, or - * something else? Investigate further. */ - /* - if (errno == ERANGE) { - jsondec_err(d, "Number out of range"); - } - */ - - if (val > DBL_MAX || val < -DBL_MAX) { - jsondec_err(d, "Number out of range"); - } - - return val; - } -} - -/* JSON string ****************************************************************/ - -static char jsondec_escape(jsondec* d) { - switch (*d->ptr++) { - case '"': - return '\"'; - case '\\': - return '\\'; - case '/': - return '/'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - default: - jsondec_err(d, "Invalid escape char"); - } -} - -static uint32_t jsondec_codepoint(jsondec* d) { - uint32_t cp = 0; - const char* end; - - if (d->end - d->ptr < 4) { - jsondec_err(d, "EOF inside string"); - } - - end = d->ptr + 4; - while (d->ptr < end) { - char ch = *d->ptr++; - if (ch >= '0' && ch <= '9') { - ch -= '0'; - } else if (ch >= 'a' && ch <= 'f') { - ch = ch - 'a' + 10; - } else if (ch >= 'A' && ch <= 'F') { - ch = ch - 'A' + 10; - } else { - jsondec_err(d, "Invalid hex digit"); - } - cp = (cp << 4) | ch; - } - - return cp; -} - -/* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ -static size_t jsondec_unicode(jsondec* d, char* out) { - uint32_t cp = jsondec_codepoint(d); - if (upb_Unicode_IsHigh(cp)) { - /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ - jsondec_parselit(d, "\\u"); - uint32_t low = jsondec_codepoint(d); - if (!upb_Unicode_IsLow(low)) jsondec_err(d, "Invalid low surrogate"); - cp = upb_Unicode_FromPair(cp, low); - } else if (upb_Unicode_IsLow(cp)) { - jsondec_err(d, "Unpaired low surrogate"); - } - - /* Write to UTF-8 */ - int bytes = upb_Unicode_ToUTF8(cp, out); - if (bytes == 0) jsondec_err(d, "Invalid codepoint"); - return bytes; -} - -static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { - size_t oldsize = *buf_end - *buf; - size_t len = *end - *buf; - size_t size = UPB_MAX(8, 2 * oldsize); - - *buf = upb_Arena_Realloc(d->arena, *buf, len, size); - if (!*buf) jsondec_err(d, "Out of memory"); - - *end = *buf + len; - *buf_end = *buf + size; -} - -static upb_StringView jsondec_string(jsondec* d) { - char* buf = NULL; - char* end = NULL; - char* buf_end = NULL; - - jsondec_skipws(d); - - if (*d->ptr++ != '"') { - jsondec_err(d, "Expected string"); - } - - while (d->ptr < d->end) { - char ch = *d->ptr++; - - if (end == buf_end) { - jsondec_resize(d, &buf, &end, &buf_end); - } - - switch (ch) { - case '"': { - upb_StringView ret; - ret.data = buf; - ret.size = end - buf; - *end = '\0'; /* Needed for possible strtod(). */ - return ret; - } - case '\\': - if (d->ptr == d->end) goto eof; - if (*d->ptr == 'u') { - d->ptr++; - if (buf_end - end < 4) { - /* Allow space for maximum-sized codepoint (4 bytes). */ - jsondec_resize(d, &buf, &end, &buf_end); - } - end += jsondec_unicode(d, end); - } else { - *end++ = jsondec_escape(d); - } - break; - default: - if ((unsigned char)ch < 0x20) { - jsondec_err(d, "Invalid char in JSON string"); - } - *end++ = ch; - break; - } - } - -eof: - jsondec_err(d, "EOF inside string"); -} - -static void jsondec_skipval(jsondec* d) { - switch (jsondec_peek(d)) { - case JD_OBJECT: - jsondec_objstart(d); - while (jsondec_objnext(d)) { - jsondec_string(d); - jsondec_entrysep(d); - jsondec_skipval(d); - } - jsondec_objend(d); - break; - case JD_ARRAY: - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - jsondec_skipval(d); - } - jsondec_arrend(d); - break; - case JD_TRUE: - jsondec_true(d); - break; - case JD_FALSE: - jsondec_false(d); - break; - case JD_NULL: - jsondec_null(d); - break; - case JD_STRING: - jsondec_string(d); - break; - case JD_NUMBER: - jsondec_number(d); - break; - } -} - -/* Base64 decoding for bytes fields. ******************************************/ - -static unsigned int jsondec_base64_tablelookup(const char ch) { - /* Table includes the normal base64 chars plus the URL-safe variant. */ - const signed char table[256] = { - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, 62 /*+*/, -1, 62 /*-*/, -1, 63 /*/ */, 52 /*0*/, - 53 /*1*/, 54 /*2*/, 55 /*3*/, 56 /*4*/, 57 /*5*/, 58 /*6*/, 59 /*7*/, - 60 /*8*/, 61 /*9*/, -1, -1, -1, -1, -1, - -1, -1, 0 /*A*/, 1 /*B*/, 2 /*C*/, 3 /*D*/, 4 /*E*/, - 5 /*F*/, 6 /*G*/, 07 /*H*/, 8 /*I*/, 9 /*J*/, 10 /*K*/, 11 /*L*/, - 12 /*M*/, 13 /*N*/, 14 /*O*/, 15 /*P*/, 16 /*Q*/, 17 /*R*/, 18 /*S*/, - 19 /*T*/, 20 /*U*/, 21 /*V*/, 22 /*W*/, 23 /*X*/, 24 /*Y*/, 25 /*Z*/, - -1, -1, -1, -1, 63 /*_*/, -1, 26 /*a*/, - 27 /*b*/, 28 /*c*/, 29 /*d*/, 30 /*e*/, 31 /*f*/, 32 /*g*/, 33 /*h*/, - 34 /*i*/, 35 /*j*/, 36 /*k*/, 37 /*l*/, 38 /*m*/, 39 /*n*/, 40 /*o*/, - 41 /*p*/, 42 /*q*/, 43 /*r*/, 44 /*s*/, 45 /*t*/, 46 /*u*/, 47 /*v*/, - 48 /*w*/, 49 /*x*/, 50 /*y*/, 51 /*z*/, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1}; - - /* Sign-extend return value so high bit will be set on any unexpected char. */ - return table[(unsigned)ch]; -} - -static char* jsondec_partialbase64(jsondec* d, const char* ptr, const char* end, - char* out) { - int32_t val = -1; - - switch (end - ptr) { - case 2: - val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12; - out[0] = val >> 16; - out += 1; - break; - case 3: - val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12 | - jsondec_base64_tablelookup(ptr[2]) << 6; - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out += 2; - break; - } - - if (val < 0) { - jsondec_err(d, "Corrupt base64"); - } - - return out; -} - -static size_t jsondec_base64(jsondec* d, upb_StringView str) { - /* We decode in place. This is safe because this is a new buffer (not - * aliasing the input) and because base64 decoding shrinks 4 bytes into 3. */ - char* out = (char*)str.data; - const char* ptr = str.data; - const char* end = ptr + str.size; - const char* end4 = ptr + (str.size & -4); /* Round down to multiple of 4. */ - - for (; ptr < end4; ptr += 4, out += 3) { - int val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12 | - jsondec_base64_tablelookup(ptr[2]) << 6 | - jsondec_base64_tablelookup(ptr[3]) << 0; - - if (val < 0) { - /* Junk chars or padding. Remove trailing padding, if any. */ - if (end - ptr == 4 && ptr[3] == '=') { - if (ptr[2] == '=') { - end -= 2; - } else { - end -= 1; - } - } - break; - } - - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out[2] = val & 0xff; - } - - if (ptr < end) { - /* Process remaining chars. We do not require padding. */ - out = jsondec_partialbase64(d, ptr, end, out); - } - - return out - str.data; -} - -/* Low-level integer parsing **************************************************/ - -static const char* jsondec_buftouint64(jsondec* d, const char* ptr, - const char* end, uint64_t* val) { - const char* out = upb_BufToUint64(ptr, end, val); - if (!out) jsondec_err(d, "Integer overflow"); - return out; -} - -static const char* jsondec_buftoint64(jsondec* d, const char* ptr, - const char* end, int64_t* val, - bool* is_neg) { - const char* out = upb_BufToInt64(ptr, end, val, is_neg); - if (!out) jsondec_err(d, "Integer overflow"); - return out; -} - -static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { - const char* end = str.data + str.size; - uint64_t ret; - if (jsondec_buftouint64(d, str.data, end, &ret) != end) { - jsondec_err(d, "Non-number characters in quoted integer"); - } - return ret; -} - -static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { - const char* end = str.data + str.size; - int64_t ret; - if (jsondec_buftoint64(d, str.data, end, &ret, NULL) != end) { - jsondec_err(d, "Non-number characters in quoted integer"); - } - return ret; -} - -static void jsondec_checkempty(jsondec* d, upb_StringView str, - const upb_FieldDef* f) { - if (str.size != 0) return; - d->result = kUpb_JsonDecodeResult_Error; - upb_Status_SetErrorFormat(d->status, - "Empty string is not a valid number (field: %s). " - "This will be an error in a future version.", - upb_FieldDef_FullName(f)); -} - -/* Primitive value types ******************************************************/ - -/* Parse INT32 or INT64 value. */ -static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val; - - switch (jsondec_peek(d)) { - case JD_NUMBER: { - double dbl = jsondec_number(d); - if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) { - jsondec_err(d, "JSON number is out of range."); - } - val.int64_val = dbl; /* must be guarded, overflow here is UB */ - if (val.int64_val != dbl) { - jsondec_errf(d, "JSON number was not integral (%f != %" PRId64 ")", dbl, - val.int64_val); - } - break; - } - case JD_STRING: { - upb_StringView str = jsondec_string(d); - jsondec_checkempty(d, str, f); - val.int64_val = jsondec_strtoint64(d, str); - break; - } - default: - jsondec_err(d, "Expected number or string"); - } - - if (upb_FieldDef_CType(f) == kUpb_CType_Int32 || - upb_FieldDef_CType(f) == kUpb_CType_Enum) { - if (val.int64_val > INT32_MAX || val.int64_val < INT32_MIN) { - jsondec_err(d, "Integer out of range."); - } - val.int32_val = (int32_t)val.int64_val; - } - - return val; -} - -/* Parse UINT32 or UINT64 value. */ -static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val; - - switch (jsondec_peek(d)) { - case JD_NUMBER: { - double dbl = jsondec_number(d); - if (dbl > 18446744073709549568.0 || dbl < 0) { - jsondec_err(d, "JSON number is out of range."); - } - val.uint64_val = dbl; /* must be guarded, overflow here is UB */ - if (val.uint64_val != dbl) { - jsondec_errf(d, "JSON number was not integral (%f != %" PRIu64 ")", dbl, - val.uint64_val); - } - break; - } - case JD_STRING: { - upb_StringView str = jsondec_string(d); - jsondec_checkempty(d, str, f); - val.uint64_val = jsondec_strtouint64(d, str); - break; - } - default: - jsondec_err(d, "Expected number or string"); - } - - if (upb_FieldDef_CType(f) == kUpb_CType_UInt32) { - if (val.uint64_val > UINT32_MAX) { - jsondec_err(d, "Integer out of range."); - } - val.uint32_val = (uint32_t)val.uint64_val; - } - - return val; -} - -/* Parse DOUBLE or FLOAT value. */ -static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { - upb_StringView str; - upb_MessageValue val; - - switch (jsondec_peek(d)) { - case JD_NUMBER: - val.double_val = jsondec_number(d); - break; - case JD_STRING: - str = jsondec_string(d); - if (str.size == 0) { - jsondec_checkempty(d, str, f); - val.double_val = 0.0; - } else if (jsondec_streql(str, "NaN")) { - val.double_val = NAN; - } else if (jsondec_streql(str, "Infinity")) { - val.double_val = INFINITY; - } else if (jsondec_streql(str, "-Infinity")) { - val.double_val = -INFINITY; - } else { - char* end; - val.double_val = strtod(str.data, &end); - if (end != str.data + str.size) { - d->result = kUpb_JsonDecodeResult_Error; - upb_Status_SetErrorFormat( - d->status, - "Non-number characters in quoted number (field: %s). " - "This will be an error in a future version.", - upb_FieldDef_FullName(f)); - } - } - break; - default: - jsondec_err(d, "Expected number or string"); - } - - if (upb_FieldDef_CType(f) == kUpb_CType_Float) { - float f = val.double_val; - if (val.double_val != INFINITY && val.double_val != -INFINITY) { - if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range"); - } - val.float_val = f; - } - - return val; -} - -/* Parse STRING or BYTES value. */ -static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val; - val.str_val = jsondec_string(d); - if (upb_FieldDef_CType(f) == kUpb_CType_Bytes) { - val.str_val.size = jsondec_base64(d, val.str_val); - } - return val; -} - -static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { - switch (jsondec_peek(d)) { - case JD_STRING: { - upb_StringView str = jsondec_string(d); - const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); - upb_JsonMessageValue val = {.ignore = false}; - if (ev) { - val.value.int32_val = upb_EnumValueDef_Number(ev); - } else { - if (d->options & upb_JsonDecode_IgnoreUnknown) { - val.ignore = true; - } else { - jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(str)); - } - } - return val; - } - case JD_NULL: { - if (jsondec_isnullvalue(f)) { - upb_JsonMessageValue val = {.ignore = false}; - jsondec_null(d); - val.value.int32_val = 0; - return val; - } - } - /* Fallthrough. */ - default: - return (upb_JsonMessageValue){.value = jsondec_int(d, f), - .ignore = false}; - } -} - -static upb_MessageValue jsondec_bool(jsondec* d, const upb_FieldDef* f) { - bool is_map_key = upb_FieldDef_Number(f) == 1 && - upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)); - upb_MessageValue val; - - if (is_map_key) { - upb_StringView str = jsondec_string(d); - if (jsondec_streql(str, "true")) { - val.bool_val = true; - } else if (jsondec_streql(str, "false")) { - val.bool_val = false; - } else { - jsondec_err(d, "Invalid boolean map key"); - } - } else { - switch (jsondec_peek(d)) { - case JD_TRUE: - val.bool_val = true; - jsondec_true(d); - break; - case JD_FALSE: - val.bool_val = false; - jsondec_false(d); - break; - default: - jsondec_err(d, "Expected true or false"); - } - } - - return val; -} - -/* Composite types (array/message/map) ****************************************/ - -static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; - - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - upb_JsonMessageValue elem = jsondec_value(d, f); - if (!elem.ignore) { - upb_Array_Append(arr, elem.value, d->arena); - } - } - jsondec_arrend(d); -} - -static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); - - jsondec_objstart(d); - while (jsondec_objnext(d)) { - upb_JsonMessageValue key, val; - key = jsondec_value(d, key_f); - UPB_ASSUME(!key.ignore); // Map key cannot be enum. - jsondec_entrysep(d); - val = jsondec_value(d, val_f); - if (!val.ignore) { - upb_Map_Set(map, key.value, val.value, d->arena); - } - } - jsondec_objend(d); -} - -static void jsondec_tomsg(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { - jsondec_object(d, msg, m); - } else { - jsondec_wellknown(d, msg, m); - } -} - -static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { - const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); - upb_Message* msg = upb_Message_New(layout, d->arena); - upb_MessageValue val; - - jsondec_tomsg(d, msg, m); - val.msg_val = msg; - return val; -} - -static void jsondec_field(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_StringView name; - const upb_FieldDef* f; - const upb_FieldDef* preserved; - - name = jsondec_string(d); - jsondec_entrysep(d); - - if (name.size >= 2 && name.data[0] == '[' && - name.data[name.size - 1] == ']') { - f = upb_DefPool_FindExtensionByNameWithSize(d->symtab, name.data + 1, - name.size - 2); - if (f && upb_FieldDef_ContainingType(f) != m) { - jsondec_errf( - d, "Extension %s extends message %s, but was seen in message %s", - upb_FieldDef_FullName(f), - upb_MessageDef_FullName(upb_FieldDef_ContainingType(f)), - upb_MessageDef_FullName(m)); - } - } else { - f = upb_MessageDef_FindByJsonNameWithSize(m, name.data, name.size); - } - - if (!f) { - if ((d->options & upb_JsonDecode_IgnoreUnknown) == 0) { - jsondec_errf(d, "No such field: " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - } - jsondec_skipval(d); - return; - } - - if (jsondec_peek(d) == JD_NULL && !jsondec_isvalue(f)) { - /* JSON "null" indicates a default value, so no need to set anything. */ - jsondec_null(d); - return; - } - - if (upb_FieldDef_RealContainingOneof(f) && - upb_Message_WhichOneofByDef(msg, upb_FieldDef_ContainingOneof(f))) { - jsondec_err(d, "More than one field for this oneof."); - } - - preserved = d->debug_field; - d->debug_field = f; - - if (upb_FieldDef_IsMap(f)) { - jsondec_map(d, msg, f); - } else if (upb_FieldDef_IsRepeated(f)) { - jsondec_array(d, msg, f); - } else if (upb_FieldDef_IsSubMessage(f)) { - upb_Message* submsg = upb_Message_Mutable(msg, f, d->arena).msg; - const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); - jsondec_tomsg(d, submsg, subm); - } else { - upb_JsonMessageValue val = jsondec_value(d, f); - if (!val.ignore) { - upb_Message_SetFieldByDef(msg, f, val.value, d->arena); - } - } - - d->debug_field = preserved; -} - -static void jsondec_object(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - jsondec_objstart(d); - while (jsondec_objnext(d)) { - jsondec_field(d, msg, m); - } - jsondec_objend(d); -} - -static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return jsondec_bool(d, f); - case kUpb_CType_Float: - case kUpb_CType_Double: - return jsondec_double(d, f); - case kUpb_CType_UInt32: - case kUpb_CType_UInt64: - return jsondec_uint(d, f); - case kUpb_CType_Int32: - case kUpb_CType_Int64: - return jsondec_int(d, f); - case kUpb_CType_String: - case kUpb_CType_Bytes: - return jsondec_strfield(d, f); - case kUpb_CType_Message: - return jsondec_msg(d, f); - case kUpb_CType_Enum: - default: - UPB_UNREACHABLE(); - } -} - -static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { - if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { - return jsondec_enum(d, f); - } else { - return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), - .ignore = false}; - } -} - -/* Well-known types ***********************************************************/ - -static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, - const char* after) { - uint64_t val; - const char* p = *ptr; - const char* end = p + digits; - size_t after_len = after ? strlen(after) : 0; - - UPB_ASSERT(digits <= 9); /* int can't overflow. */ - - if (jsondec_buftouint64(d, p, end, &val) != end || - (after_len && memcmp(end, after, after_len) != 0)) { - jsondec_err(d, "Malformed timestamp"); - } - - UPB_ASSERT(val < INT_MAX); - - *ptr = end + after_len; - return (int)val; -} - -static int jsondec_nanos(jsondec* d, const char** ptr, const char* end) { - uint64_t nanos = 0; - const char* p = *ptr; - - if (p != end && *p == '.') { - const char* nano_end = jsondec_buftouint64(d, p + 1, end, &nanos); - int digits = (int)(nano_end - p - 1); - int exp_lg10 = 9 - digits; - if (digits > 9) { - jsondec_err(d, "Too many digits for partial seconds"); - } - while (exp_lg10--) nanos *= 10; - *ptr = nano_end; - } - - UPB_ASSERT(nanos < INT_MAX); - - return (int)nanos; -} - -/* jsondec_epochdays(1970, 1, 1) == 1970-01-01 == 0. */ -int jsondec_epochdays(int y, int m, int d) { - const uint32_t year_base = 4800; /* Before min year, multiple of 400. */ - const uint32_t m_adj = m - 3; /* March-based month. */ - const uint32_t carry = m_adj > (uint32_t)m ? 1 : 0; - const uint32_t adjust = carry ? 12 : 0; - const uint32_t y_adj = y + year_base - carry; - const uint32_t month_days = ((m_adj + adjust) * 62719 + 769) / 2048; - const uint32_t leap_days = y_adj / 4 - y_adj / 100 + y_adj / 400; - return y_adj * 365 + leap_days + month_days + (d - 1) - 2472632; -} - -static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s) { - return (int64_t)jsondec_epochdays(y, m, d) * 86400 + h * 3600 + min * 60 + s; -} - -static void jsondec_timestamp(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_MessageValue seconds; - upb_MessageValue nanos; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - - if (str.size < 20) goto malformed; - - { - /* 1972-01-01T01:00:00 */ - int year = jsondec_tsdigits(d, &ptr, 4, "-"); - int mon = jsondec_tsdigits(d, &ptr, 2, "-"); - int day = jsondec_tsdigits(d, &ptr, 2, "T"); - int hour = jsondec_tsdigits(d, &ptr, 2, ":"); - int min = jsondec_tsdigits(d, &ptr, 2, ":"); - int sec = jsondec_tsdigits(d, &ptr, 2, NULL); - - seconds.int64_val = jsondec_unixtime(year, mon, day, hour, min, sec); - } - - nanos.int32_val = jsondec_nanos(d, &ptr, end); - - { - /* [+-]08:00 or Z */ - int ofs_hour = 0; - int ofs_min = 0; - bool neg = false; - - if (ptr == end) goto malformed; - - switch (*ptr++) { - case '-': - neg = true; - /* fallthrough */ - case '+': - if ((end - ptr) != 5) goto malformed; - ofs_hour = jsondec_tsdigits(d, &ptr, 2, ":"); - ofs_min = jsondec_tsdigits(d, &ptr, 2, NULL); - ofs_min = ((ofs_hour * 60) + ofs_min) * 60; - seconds.int64_val += (neg ? ofs_min : -ofs_min); - break; - case 'Z': - if (ptr != end) goto malformed; - break; - default: - goto malformed; - } - } - - if (seconds.int64_val < -62135596800) { - jsondec_err(d, "Timestamp out of range"); - } - - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), - seconds, d->arena); - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, - d->arena); - return; - -malformed: - jsondec_err(d, "Malformed timestamp"); -} - -static void jsondec_duration(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_MessageValue seconds; - upb_MessageValue nanos; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - const int64_t max = (uint64_t)3652500 * 86400; - bool neg = false; - - /* "3.000000001s", "3s", etc. */ - ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val, &neg); - nanos.int32_val = jsondec_nanos(d, &ptr, end); - - if (end - ptr != 1 || *ptr != 's') { - jsondec_err(d, "Malformed duration"); - } - - if (seconds.int64_val < -max || seconds.int64_val > max) { - jsondec_err(d, "Duration out of range"); - } - - if (neg) { - nanos.int32_val = -nanos.int32_val; - } - - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), - seconds, d->arena); - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, - d->arena); -} - -static void jsondec_listvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); - upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; - - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); - upb_MessageValue value; - value.msg_val = value_msg; - upb_Array_Append(values, value, d->arena); - jsondec_wellknownvalue(d, value_msg, value_m); - } - jsondec_arrend(d); -} - -static void jsondec_struct(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); - const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); - upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; - - jsondec_objstart(d); - while (jsondec_objnext(d)) { - upb_MessageValue key, value; - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); - key.str_val = jsondec_string(d); - value.msg_val = value_msg; - upb_Map_Set(fields, key, value, d->arena); - jsondec_entrysep(d); - jsondec_wellknownvalue(d, value_msg, value_m); - } - jsondec_objend(d); -} - -static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_MessageValue val; - const upb_FieldDef* f; - upb_Message* submsg; - - switch (jsondec_peek(d)) { - case JD_NUMBER: - /* double number_value = 2; */ - f = upb_MessageDef_FindFieldByNumber(m, 2); - val.double_val = jsondec_number(d); - break; - case JD_STRING: - /* string string_value = 3; */ - f = upb_MessageDef_FindFieldByNumber(m, 3); - val.str_val = jsondec_string(d); - break; - case JD_FALSE: - /* bool bool_value = 4; */ - f = upb_MessageDef_FindFieldByNumber(m, 4); - val.bool_val = false; - jsondec_false(d); - break; - case JD_TRUE: - /* bool bool_value = 4; */ - f = upb_MessageDef_FindFieldByNumber(m, 4); - val.bool_val = true; - jsondec_true(d); - break; - case JD_NULL: - /* NullValue null_value = 1; */ - f = upb_MessageDef_FindFieldByNumber(m, 1); - val.int32_val = 0; - jsondec_null(d); - break; - /* Note: these cases return, because upb_Message_Mutable() is enough. */ - case JD_OBJECT: - /* Struct struct_value = 5; */ - f = upb_MessageDef_FindFieldByNumber(m, 5); - submsg = upb_Message_Mutable(msg, f, d->arena).msg; - jsondec_struct(d, submsg, upb_FieldDef_MessageSubDef(f)); - return; - case JD_ARRAY: - /* ListValue list_value = 6; */ - f = upb_MessageDef_FindFieldByNumber(m, 6); - submsg = upb_Message_Mutable(msg, f, d->arena).msg; - jsondec_listvalue(d, submsg, upb_FieldDef_MessageSubDef(f)); - return; - default: - UPB_UNREACHABLE(); - } - - upb_Message_SetFieldByDef(msg, f, val, d->arena); -} - -static upb_StringView jsondec_mask(jsondec* d, const char* buf, - const char* end) { - /* FieldMask fields grow due to inserted '_' characters, so we can't do the - * transform in place. */ - const char* ptr = buf; - upb_StringView ret; - char* out; - - ret.size = end - ptr; - while (ptr < end) { - ret.size += (*ptr >= 'A' && *ptr <= 'Z'); - ptr++; - } - - out = upb_Arena_Malloc(d->arena, ret.size); - ptr = buf; - ret.data = out; - - while (ptr < end) { - char ch = *ptr++; - if (ch >= 'A' && ch <= 'Z') { - *out++ = '_'; - *out++ = ch + 32; - } else if (ch == '_') { - jsondec_err(d, "field mask may not contain '_'"); - } else { - *out++ = ch; - } - } - - return ret; -} - -static void jsondec_fieldmask(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - /* repeated string paths = 1; */ - const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - upb_MessageValue val; - - while (ptr < end) { - const char* elem_end = memchr(ptr, ',', end - ptr); - if (elem_end) { - val.str_val = jsondec_mask(d, ptr, elem_end); - ptr = elem_end + 1; - } else { - val.str_val = jsondec_mask(d, ptr, end); - ptr = end; - } - upb_Array_Append(arr, val, d->arena); - } -} - -static void jsondec_anyfield(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { - /* For regular types: {"@type": "[user type]", "f1": , "f2": } - * where f1, f2, etc. are the normal fields of this type. */ - jsondec_field(d, msg, m); - } else { - /* For well-known types: {"@type": "[well-known type]", "value": } - * where is whatever encoding the WKT normally uses. */ - upb_StringView str = jsondec_string(d); - jsondec_entrysep(d); - if (!jsondec_streql(str, "value")) { - jsondec_err(d, "Key for well-known type must be 'value'"); - } - jsondec_wellknown(d, msg, m); - } -} - -static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* type_m; - upb_StringView type_url = jsondec_string(d); - const char* end = type_url.data + type_url.size; - const char* ptr = end; - upb_MessageValue val; - - val.str_val = type_url; - upb_Message_SetFieldByDef(msg, type_url_f, val, d->arena); - - /* Find message name after the last '/' */ - while (ptr > type_url.data && *--ptr != '/') { - } - - if (ptr == type_url.data || ptr == end) { - jsondec_err(d, "Type url must have at least one '/' and non-empty host"); - } - - ptr++; - type_m = upb_DefPool_FindMessageByNameWithSize(d->symtab, ptr, end - ptr); - - if (!type_m) { - jsondec_err(d, "Type was not found"); - } - - return type_m; -} - -static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - /* string type_url = 1; - * bytes value = 2; */ - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); - upb_Message* any_msg; - const upb_MessageDef* any_m = NULL; - const char* pre_type_data = NULL; - const char* pre_type_end = NULL; - upb_MessageValue encoded; - - jsondec_objstart(d); - - /* Scan looking for "@type", which is not necessarily first. */ - while (!any_m && jsondec_objnext(d)) { - const char* start = d->ptr; - upb_StringView name = jsondec_string(d); - jsondec_entrysep(d); - if (jsondec_streql(name, "@type")) { - any_m = jsondec_typeurl(d, msg, m); - if (pre_type_data) { - pre_type_end = start; - while (*pre_type_end != ',') pre_type_end--; - } - } else { - if (!pre_type_data) pre_type_data = start; - jsondec_skipval(d); - } - } - - if (!any_m) { - jsondec_err(d, "Any object didn't contain a '@type' field"); - } - - const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); - any_msg = upb_Message_New(any_layout, d->arena); - - if (pre_type_data) { - size_t len = pre_type_end - pre_type_data + 1; - char* tmp = upb_Arena_Malloc(d->arena, len); - const char* saved_ptr = d->ptr; - const char* saved_end = d->end; - memcpy(tmp, pre_type_data, len - 1); - tmp[len - 1] = '}'; - d->ptr = tmp; - d->end = tmp + len; - d->is_first = true; - while (jsondec_objnext(d)) { - jsondec_anyfield(d, any_msg, any_m); - } - d->ptr = saved_ptr; - d->end = saved_end; - } - - while (jsondec_objnext(d)) { - jsondec_anyfield(d, any_msg, any_m); - } - - jsondec_objend(d); - - upb_EncodeStatus status = - upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, d->arena, - (char**)&encoded.str_val.data, &encoded.str_val.size); - // TODO: We should fail gracefully here on a bad return status. - UPB_ASSERT(status == kUpb_EncodeStatus_Ok); - upb_Message_SetFieldByDef(msg, value_f, encoded, d->arena); -} - -static void jsondec_wrapper(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_JsonMessageValue val = jsondec_value(d, value_f); - UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. - upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); -} - -static void jsondec_wellknown(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - switch (upb_MessageDef_WellKnownType(m)) { - case kUpb_WellKnown_Any: - jsondec_any(d, msg, m); - break; - case kUpb_WellKnown_FieldMask: - jsondec_fieldmask(d, msg, m); - break; - case kUpb_WellKnown_Duration: - jsondec_duration(d, msg, m); - break; - case kUpb_WellKnown_Timestamp: - jsondec_timestamp(d, msg, m); - break; - case kUpb_WellKnown_Value: - jsondec_wellknownvalue(d, msg, m); - break; - case kUpb_WellKnown_ListValue: - jsondec_listvalue(d, msg, m); - break; - case kUpb_WellKnown_Struct: - jsondec_struct(d, msg, m); - break; - case kUpb_WellKnown_DoubleValue: - case kUpb_WellKnown_FloatValue: - case kUpb_WellKnown_Int64Value: - case kUpb_WellKnown_UInt64Value: - case kUpb_WellKnown_Int32Value: - case kUpb_WellKnown_UInt32Value: - case kUpb_WellKnown_StringValue: - case kUpb_WellKnown_BytesValue: - case kUpb_WellKnown_BoolValue: - jsondec_wrapper(d, msg, m); - break; - default: - UPB_UNREACHABLE(); - } -} - -static int upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, - const upb_MessageDef* const m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - if (UPB_SETJMP(d->err)) return kUpb_JsonDecodeResult_Error; - - jsondec_tomsg(d, msg, m); - - // Consume any trailing whitespace before checking if we read the entire - // input. - jsondec_consumews(d); - - if (d->ptr == d->end) { - return d->result; - } else { - jsondec_seterrmsg(d, "unexpected trailing characters"); - return kUpb_JsonDecodeResult_Error; - } -} - -int upb_JsonDecodeDetectingNonconformance(const char* buf, size_t size, - upb_Message* msg, - const upb_MessageDef* m, - const upb_DefPool* symtab, - int options, upb_Arena* arena, - upb_Status* status) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - jsondec d; - - if (size == 0) return true; - - d.ptr = buf; - d.end = buf + size; - d.arena = arena; - d.symtab = symtab; - d.status = status; - d.options = options; - d.depth = 64; - d.result = kUpb_JsonDecodeResult_Ok; - d.line = 1; - d.line_begin = d.ptr; - d.debug_field = NULL; - d.is_first = false; - - return upb_JsonDecoder_Decode(&d, msg, m); -} diff --git a/vendor/upb/json/decode.h b/vendor/upb/json/decode.h deleted file mode 100644 index f0a97b8..0000000 --- a/vendor/upb/json/decode.h +++ /dev/null @@ -1,54 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_JSON_DECODE_H_ -#define UPB_JSON_DECODE_H_ - -#include - -#include "upb/base/status.h" -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/reflection/def.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -enum { upb_JsonDecode_IgnoreUnknown = 1 }; - -enum { - kUpb_JsonDecodeResult_Ok = 0, - kUpb_JsonDecodeResult_Error = 2, -}; - -UPB_NODISCARD UPB_API int upb_JsonDecodeDetectingNonconformance( - const char* buf, size_t size, upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* symtab, int options, upb_Arena* arena, - upb_Status* status); - -UPB_NODISCARD UPB_API_INLINE bool upb_JsonDecode(const char* buf, size_t size, - upb_Message* msg, - const upb_MessageDef* m, - const upb_DefPool* symtab, - int options, upb_Arena* arena, - upb_Status* status) { - return upb_JsonDecodeDetectingNonconformance(buf, size, msg, m, symtab, - options, arena, status) == - kUpb_JsonDecodeResult_Ok; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_JSONDECODE_H_ */ diff --git a/vendor/upb/json/decode_test.cc b/vendor/upb/json/decode_test.cc deleted file mode 100644 index e8a6e3d..0000000 --- a/vendor/upb/json/decode_test.cc +++ /dev/null @@ -1,99 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/json/decode.h" - -#include -#include - -#include "google/protobuf/struct.upb.h" -#include -#include "upb/base/status.hpp" -#include "upb/base/upcast.h" -#include "upb/json/test.upb.h" -#include "upb/json/test.upbdefs.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/reflection/def.hpp" - -static upb_test_Box* JsonDecode(const char* json, upb_Arena* a) { - upb::Status status; - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - upb_test_Box* box = upb_test_Box_new(a); - int options = 0; - bool ok = upb_JsonDecode(json, strlen(json), UPB_UPCAST(box), m.ptr(), - defpool.ptr(), options, a, status.ptr()); - return ok ? box : nullptr; -} - -struct FloatTest { - const std::string json; - float f; -}; - -static const std::vector FloatTestsPass = { - {R"({"f": 0})", 0}, - {R"({"f": 1})", 1}, - {R"({"f": 1.000000})", 1}, - {R"({"f": 1.5e1})", 15}, - {R"({"f": 15e-1})", 1.5}, - {R"({"f": -3.5})", -3.5}, - {R"({"f": 3.402823e38})", 3.402823e38}, - {R"({"f": -3.402823e38})", -3.402823e38}, - {R"({"f": 340282346638528859811704183484516925440.0})", - 340282346638528859811704183484516925440.0}, - {R"({"f": -340282346638528859811704183484516925440.0})", - -340282346638528859811704183484516925440.0}, -}; - -static const std::vector FloatTestsFail = { - {R"({"f": 1z})", 0}, - {R"({"f": 3.4028236e+38})", 0}, - {R"({"f": -3.4028236e+38})", 0}, -}; - -// Decode some floats. -TEST(JsonTest, DecodeFloats) { - upb::Arena a; - - for (const auto& test : FloatTestsPass) { - upb_test_Box* box = JsonDecode(test.json.c_str(), a.ptr()); - EXPECT_NE(box, nullptr); - float f = upb_test_Box_f(box); - EXPECT_EQ(f, test.f); - } - - for (const auto& test : FloatTestsFail) { - upb_test_Box* box = JsonDecode(test.json.c_str(), a.ptr()); - EXPECT_EQ(box, nullptr); - } -} - -TEST(JsonTest, DecodeConflictJsonName) { - upb::Arena a; - std::string json_string = R"({"value": 2})"; - upb_test_Box* box = JsonDecode(json_string.c_str(), a.ptr()); - EXPECT_EQ(2, upb_test_Box_new_value(box)); - EXPECT_EQ(0, upb_test_Box_value(box)); -} - -TEST(JsonTest, RejectsBadTrailingCharacters) { - upb::Arena a; - std::string json_string = R"({}abc)"; - upb_test_Box* box = JsonDecode(json_string.c_str(), a.ptr()); - EXPECT_EQ(box, nullptr); -} - -TEST(JsonTest, AcceptsTrailingWhitespace) { - upb::Arena a; - std::string json_string = "{} \n \r\n \t\t"; - upb_test_Box* box = JsonDecode(json_string.c_str(), a.ptr()); - EXPECT_NE(box, nullptr); -} diff --git a/vendor/upb/json/encode.c b/vendor/upb/json/encode.c deleted file mode 100644 index 66aa77f..0000000 --- a/vendor/upb/json/encode.c +++ /dev/null @@ -1,784 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/json/encode.h" - -#include -#include -#include -#include -#include -#include - -#include "upb/lex/round_trip.h" -#include "upb/message/map.h" -#include "upb/port/vsnprintf_compat.h" -#include "upb/reflection/message.h" -#include "upb/wire/decode.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - char *buf, *ptr, *end; - size_t overflow; - int indent_depth; - int options; - const upb_DefPool* ext_pool; - jmp_buf err; - upb_Status* status; - upb_Arena* arena; -} jsonenc; - -static void jsonenc_msg(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); -static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f); -static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); -static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m, bool first); -static void jsonenc_value(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); - -UPB_NORETURN static void jsonenc_err(jsonenc* e, const char* msg) { - upb_Status_SetErrorMessage(e->status, msg); - UPB_LONGJMP(e->err, 1); -} - -UPB_PRINTF(2, 3) -UPB_NORETURN static void jsonenc_errf(jsonenc* e, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(e->status, fmt, argp); - va_end(argp); - UPB_LONGJMP(e->err, 1); -} - -static upb_Arena* jsonenc_arena(jsonenc* e) { - /* Create lazily, since it's only needed for Any */ - if (!e->arena) { - e->arena = upb_Arena_New(); - } - return e->arena; -} - -static void jsonenc_putbytes(jsonenc* e, const void* data, size_t len) { - size_t have = e->end - e->ptr; - if (UPB_LIKELY(have >= len)) { - memcpy(e->ptr, data, len); - e->ptr += len; - } else { - if (have) { - memcpy(e->ptr, data, have); - e->ptr += have; - } - e->overflow += (len - have); - } -} - -static void jsonenc_putstr(jsonenc* e, const char* str) { - jsonenc_putbytes(e, str, strlen(str)); -} - -UPB_PRINTF(2, 3) -static void jsonenc_printf(jsonenc* e, const char* fmt, ...) { - size_t n; - size_t have = e->end - e->ptr; - va_list args; - - va_start(args, fmt); - n = _upb_vsnprintf(e->ptr, have, fmt, args); - va_end(args); - - if (UPB_LIKELY(have > n)) { - e->ptr += n; - } else { - e->ptr = UPB_PTRADD(e->ptr, have); - e->overflow += (n - have); - } -} - -static void jsonenc_nanos(jsonenc* e, int32_t nanos) { - int digits = 9; - - if (nanos == 0) return; - if (nanos < 0 || nanos >= 1000000000) { - jsonenc_err(e, "error formatting timestamp as JSON: invalid nanos"); - } - - while (nanos % 1000 == 0) { - nanos /= 1000; - digits -= 3; - } - - jsonenc_printf(e, ".%.*" PRId32, digits, nanos); -} - -static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); - int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; - int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; - int L, N, I, J, K, hour, min, sec; - - if (seconds < -62135596800) { - jsonenc_err(e, - "error formatting timestamp as JSON: minimum acceptable value " - "is 0001-01-01T00:00:00Z"); - } else if (seconds > 253402300799) { - jsonenc_err(e, - "error formatting timestamp as JSON: maximum acceptable value " - "is 9999-12-31T23:59:59Z"); - } - - /* Julian Day -> Y/M/D, Algorithm from: - * Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for - * Processing Calendar Dates," Communications of the Association of - * Computing Machines, vol. 11 (1968), p. 657. */ - seconds += 62135596800; // Ensure seconds is positive. - L = (int)(seconds / 86400) - 719162 + 68569 + 2440588; - N = 4 * L / 146097; - L = L - (146097 * N + 3) / 4; - I = 4000 * (L + 1) / 1461001; - L = L - 1461 * I / 4 + 31; - J = 80 * L / 2447; - K = L - 2447 * J / 80; - L = J / 11; - J = J + 2 - 12 * L; - I = 100 * (N - 49) + I + L; - - sec = seconds % 60; - min = (seconds / 60) % 60; - hour = (seconds / 3600) % 24; - - jsonenc_printf(e, "\"%04d-%02d-%02dT%02d:%02d:%02d", I, J, K, hour, min, sec); - jsonenc_nanos(e, nanos); - jsonenc_putstr(e, "Z\""); -} - -static void jsonenc_duration(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); - int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; - int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; - bool negative = false; - - if (seconds > 315576000000 || seconds < -315576000000 || - (seconds != 0 && nanos != 0 && (seconds < 0) != (nanos < 0))) { - jsonenc_err(e, "bad duration"); - } - - if (seconds < 0) { - negative = true; - seconds = -seconds; - } - if (nanos < 0) { - negative = true; - nanos = -nanos; - } - - jsonenc_putstr(e, "\""); - if (negative) { - jsonenc_putstr(e, "-"); - } - jsonenc_printf(e, "%" PRId64, seconds); - jsonenc_nanos(e, nanos); - jsonenc_putstr(e, "s\""); -} - -static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { - const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f); - - if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { - jsonenc_putstr(e, "null"); - } else { - const upb_EnumValueDef* ev = - (e->options & upb_JsonEncode_FormatEnumsAsIntegers) - ? NULL - : upb_EnumDef_FindValueByNumber(e_def, val); - - if (ev) { - jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); - } else { - jsonenc_printf(e, "%" PRId32, val); - } - } -} - -static void jsonenc_bytes(jsonenc* e, upb_StringView str) { - /* This is the regular base64, not the "web-safe" version. */ - static const char base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - const unsigned char* ptr = (unsigned char*)str.data; - const unsigned char* end = UPB_PTRADD(ptr, str.size); - char buf[4]; - - jsonenc_putstr(e, "\""); - - while (end - ptr >= 3) { - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; - buf[2] = base64[((ptr[1] & 0xf) << 2) | (ptr[2] >> 6)]; - buf[3] = base64[ptr[2] & 0x3f]; - jsonenc_putbytes(e, buf, 4); - ptr += 3; - } - - switch (end - ptr) { - case 2: - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; - buf[2] = base64[(ptr[1] & 0xf) << 2]; - buf[3] = '='; - jsonenc_putbytes(e, buf, 4); - break; - case 1: - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4)]; - buf[2] = '='; - buf[3] = '='; - jsonenc_putbytes(e, buf, 4); - break; - } - - jsonenc_putstr(e, "\""); -} - -static void jsonenc_stringbody(jsonenc* e, upb_StringView str) { - const char* ptr = str.data; - const char* end = UPB_PTRADD(ptr, str.size); - - while (ptr < end) { - switch (*ptr) { - case '\n': - jsonenc_putstr(e, "\\n"); - break; - case '\r': - jsonenc_putstr(e, "\\r"); - break; - case '\t': - jsonenc_putstr(e, "\\t"); - break; - case '\"': - jsonenc_putstr(e, "\\\""); - break; - case '\f': - jsonenc_putstr(e, "\\f"); - break; - case '\b': - jsonenc_putstr(e, "\\b"); - break; - case '\\': - jsonenc_putstr(e, "\\\\"); - break; - default: - if ((uint8_t)*ptr < 0x20) { - jsonenc_printf(e, "\\u%04x", (int)(uint8_t)*ptr); - } else { - /* This could be a non-ASCII byte. We rely on the string being valid - * UTF-8. */ - jsonenc_putbytes(e, ptr, 1); - } - break; - } - ptr++; - } -} - -static void jsonenc_string(jsonenc* e, upb_StringView str) { - jsonenc_putstr(e, "\""); - jsonenc_stringbody(e, str); - jsonenc_putstr(e, "\""); -} - -static bool upb_JsonEncode_HandleSpecialDoubles(jsonenc* e, double val) { - if (val == INFINITY) { - jsonenc_putstr(e, "\"Infinity\""); - } else if (val == -INFINITY) { - jsonenc_putstr(e, "\"-Infinity\""); - } else if (val != val) { - jsonenc_putstr(e, "\"NaN\""); - } else { - return false; - } - return true; -} - -static void upb_JsonEncode_Double(jsonenc* e, double val) { - if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; - char buf[32]; - _upb_EncodeRoundTripDouble(val, buf, sizeof(buf)); - jsonenc_putstr(e, buf); -} - -static void upb_JsonEncode_Float(jsonenc* e, float val) { - if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; - char buf[32]; - _upb_EncodeRoundTripFloat(val, buf, sizeof(buf)); - jsonenc_putstr(e, buf); -} - -static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_MessageValue val = upb_Message_GetFieldByDef(msg, val_f); - jsonenc_scalar(e, val, val_f); -} - -static const upb_MessageDef* jsonenc_getanymsg(jsonenc* e, - upb_StringView type_url) { - /* Find last '/', if any. */ - const char* end = type_url.data + type_url.size; - const char* ptr = end; - const upb_MessageDef* ret; - - if (!e->ext_pool) { - jsonenc_err(e, "Tried to encode Any, but no symtab was provided"); - } - - if (type_url.size == 0) goto badurl; - - while (true) { - if (--ptr == type_url.data) { - /* Type URL must contain at least one '/', with host before. */ - goto badurl; - } - if (*ptr == '/') { - ptr++; - break; - } - } - - ret = upb_DefPool_FindMessageByNameWithSize(e->ext_pool, ptr, end - ptr); - - if (!ret) { - jsonenc_errf(e, "Couldn't find Any type: %.*s", (int)(end - ptr), ptr); - } - - return ret; - -badurl: - jsonenc_errf(e, "Bad type URL: " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(type_url)); -} - -static void jsonenc_any(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); - upb_StringView type_url = upb_Message_GetFieldByDef(msg, type_url_f).str_val; - upb_StringView value = upb_Message_GetFieldByDef(msg, value_f).str_val; - const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); - const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); - upb_Arena* arena = jsonenc_arena(e); - upb_Message* any = upb_Message_New(any_layout, arena); - - if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != - kUpb_DecodeStatus_Ok) { - jsonenc_err(e, "Error decoding message in Any"); - } - - jsonenc_putstr(e, "{\"@type\":"); - jsonenc_string(e, type_url); - - if (upb_MessageDef_WellKnownType(any_m) == kUpb_WellKnown_Unspecified) { - /* Regular messages: {"@type": "...","foo": 1, "bar": 2} */ - jsonenc_msgfields(e, any, any_m, false); - } else { - /* Well-known type: {"@type": "...","value": } */ - jsonenc_putstr(e, ",\"value\":"); - jsonenc_msgfield(e, any, any_m); - } - - jsonenc_putstr(e, "}"); -} - -static void jsonenc_putsep(jsonenc* e, const char* str, bool* first) { - if (*first) { - *first = false; - } else { - jsonenc_putstr(e, str); - } -} - -static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) { - const char* ptr = path.data; - const char* end = ptr + path.size; - - while (ptr < end) { - char ch = *ptr; - - if (ch >= 'A' && ch <= 'Z') { - jsonenc_err(e, "Field mask element may not have upper-case letter."); - } else if (ch == '_') { - if (ptr == end - 1 || *(ptr + 1) < 'a' || *(ptr + 1) > 'z') { - jsonenc_err(e, "Underscore must be followed by a lowercase letter."); - } - ch = *++ptr - 32; - } - - jsonenc_putbytes(e, &ch, 1); - ptr++; - } -} - -static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_Array* paths = upb_Message_GetFieldByDef(msg, paths_f).array_val; - bool first = true; - size_t i, n = 0; - - if (paths) n = upb_Array_Size(paths); - - jsonenc_putstr(e, "\""); - - for (i = 0; i < n; i++) { - jsonenc_putsep(e, ",", &first); - jsonenc_fieldpath(e, upb_Array_Get(paths, i).str_val); - } - - jsonenc_putstr(e, "\""); -} - -static void jsonenc_struct(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - jsonenc_putstr(e, "{"); - - const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_Map* fields = upb_Message_GetFieldByDef(msg, fields_f).map_val; - - if (fields) { - const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); - - size_t iter = kUpb_Map_Begin; - bool first = true; - - upb_MessageValue key, val; - while (upb_Map_Next(fields, &key, &val, &iter)) { - jsonenc_putsep(e, ",", &first); - jsonenc_string(e, key.str_val); - jsonenc_putstr(e, ":"); - jsonenc_value(e, val.msg_val, upb_FieldDef_MessageSubDef(value_f)); - } - } - - jsonenc_putstr(e, "}"); -} - -static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f); - const upb_Array* values = upb_Message_GetFieldByDef(msg, values_f).array_val; - size_t i; - bool first = true; - - jsonenc_putstr(e, "["); - - if (values) { - const size_t size = upb_Array_Size(values); - for (i = 0; i < size; i++) { - upb_MessageValue elem = upb_Array_Get(values, i); - - jsonenc_putsep(e, ",", &first); - jsonenc_value(e, elem.msg_val, values_m); - } - } - - jsonenc_putstr(e, "]"); -} - -static void jsonenc_value(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - /* TODO: do we want a reflection method to get oneof case? */ - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; - - if (!upb_Message_Next(msg, m, NULL, &f, &val, &iter)) { - jsonenc_err(e, "No value set in Value proto"); - } - - switch (upb_FieldDef_Number(f)) { - case 1: - jsonenc_putstr(e, "null"); - break; - case 2: - if (upb_JsonEncode_HandleSpecialDoubles(e, val.double_val)) { - jsonenc_err( - e, - "google.protobuf.Value cannot encode double values for " - "infinity or nan, because they would be parsed as a string"); - } - upb_JsonEncode_Double(e, val.double_val); - break; - case 3: - jsonenc_string(e, val.str_val); - break; - case 4: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case 5: - jsonenc_struct(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; - case 6: - jsonenc_listvalue(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; - } -} - -static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - switch (upb_MessageDef_WellKnownType(m)) { - case kUpb_WellKnown_Unspecified: - jsonenc_msg(e, msg, m); - break; - case kUpb_WellKnown_Any: - jsonenc_any(e, msg, m); - break; - case kUpb_WellKnown_FieldMask: - jsonenc_fieldmask(e, msg, m); - break; - case kUpb_WellKnown_Duration: - jsonenc_duration(e, msg, m); - break; - case kUpb_WellKnown_Timestamp: - jsonenc_timestamp(e, msg, m); - break; - case kUpb_WellKnown_DoubleValue: - case kUpb_WellKnown_FloatValue: - case kUpb_WellKnown_Int64Value: - case kUpb_WellKnown_UInt64Value: - case kUpb_WellKnown_Int32Value: - case kUpb_WellKnown_UInt32Value: - case kUpb_WellKnown_StringValue: - case kUpb_WellKnown_BytesValue: - case kUpb_WellKnown_BoolValue: - jsonenc_wrapper(e, msg, m); - break; - case kUpb_WellKnown_Value: - jsonenc_value(e, msg, m); - break; - case kUpb_WellKnown_ListValue: - jsonenc_listvalue(e, msg, m); - break; - case kUpb_WellKnown_Struct: - jsonenc_struct(e, msg, m); - break; - } -} - -static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case kUpb_CType_Float: - upb_JsonEncode_Float(e, val.float_val); - break; - case kUpb_CType_Double: - upb_JsonEncode_Double(e, val.double_val); - break; - case kUpb_CType_Int32: - jsonenc_printf(e, "%" PRId32, val.int32_val); - break; - case kUpb_CType_UInt32: - jsonenc_printf(e, "%" PRIu32, val.uint32_val); - break; - case kUpb_CType_Int64: - jsonenc_printf(e, "\"%" PRId64 "\"", val.int64_val); - break; - case kUpb_CType_UInt64: - jsonenc_printf(e, "\"%" PRIu64 "\"", val.uint64_val); - break; - case kUpb_CType_String: - jsonenc_string(e, val.str_val); - break; - case kUpb_CType_Bytes: - jsonenc_bytes(e, val.str_val); - break; - case kUpb_CType_Enum: - jsonenc_enum(val.int32_val, f, e); - break; - case kUpb_CType_Message: - jsonenc_msgfield(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; - } -} - -static void jsonenc_mapkey(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f) { - jsonenc_putstr(e, "\""); - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case kUpb_CType_Int32: - jsonenc_printf(e, "%" PRId32, val.int32_val); - break; - case kUpb_CType_UInt32: - jsonenc_printf(e, "%" PRIu32, val.uint32_val); - break; - case kUpb_CType_Int64: - jsonenc_printf(e, "%" PRId64, val.int64_val); - break; - case kUpb_CType_UInt64: - jsonenc_printf(e, "%" PRIu64, val.uint64_val); - break; - case kUpb_CType_String: - jsonenc_stringbody(e, val.str_val); - break; - default: - UPB_UNREACHABLE(); - } - - jsonenc_putstr(e, "\":"); -} - -static void jsonenc_array(jsonenc* e, const upb_Array* arr, - const upb_FieldDef* f) { - size_t i; - size_t size = arr ? upb_Array_Size(arr) : 0; - bool first = true; - - jsonenc_putstr(e, "["); - - for (i = 0; i < size; i++) { - jsonenc_putsep(e, ",", &first); - jsonenc_scalar(e, upb_Array_Get(arr, i), f); - } - - jsonenc_putstr(e, "]"); -} - -static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) { - jsonenc_putstr(e, "{"); - - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); - - if (map) { - size_t iter = kUpb_Map_Begin; - bool first = true; - - upb_MessageValue key, val; - while (upb_Map_Next(map, &key, &val, &iter)) { - jsonenc_putsep(e, ",", &first); - jsonenc_mapkey(e, key, key_f); - jsonenc_scalar(e, val, val_f); - } - } - - jsonenc_putstr(e, "}"); -} - -static void jsonenc_fieldval(jsonenc* e, const upb_FieldDef* f, - upb_MessageValue val, bool* first) { - const char* name; - - jsonenc_putsep(e, ",", first); - - if (upb_FieldDef_IsExtension(f)) { - // TODO: For MessageSet, I would have expected this to print the message - // name here, but Python doesn't appear to do this. We should do more - // research here about what various implementations do. - jsonenc_printf(e, "\"[%s]\":", upb_FieldDef_FullName(f)); - } else { - if (e->options & upb_JsonEncode_UseProtoNames) { - name = upb_FieldDef_Name(f); - } else { - name = upb_FieldDef_JsonName(f); - } - jsonenc_printf(e, "\"%s\":", name); - } - - if (upb_FieldDef_IsMap(f)) { - jsonenc_map(e, val.map_val, f); - } else if (upb_FieldDef_IsRepeated(f)) { - jsonenc_array(e, val.array_val, f); - } else { - jsonenc_scalar(e, val, f); - } -} - -static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m, bool first) { - upb_MessageValue val; - const upb_FieldDef* f; - - if (e->options & upb_JsonEncode_EmitDefaults) { - /* Iterate over all fields. */ - int i = 0; - int n = upb_MessageDef_FieldCount(m); - for (i = 0; i < n; i++) { - f = upb_MessageDef_Field(m, i); - if (!upb_FieldDef_HasPresence(f) || upb_Message_HasFieldByDef(msg, f)) { - jsonenc_fieldval(e, f, upb_Message_GetFieldByDef(msg, f), &first); - } - } - } else { - /* Iterate over non-empty fields. */ - size_t iter = kUpb_Message_Begin; - while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) { - jsonenc_fieldval(e, f, val, &first); - } - } -} - -static void jsonenc_msg(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - jsonenc_putstr(e, "{"); - jsonenc_msgfields(e, msg, m, true); - jsonenc_putstr(e, "}"); -} - -static size_t jsonenc_nullz(jsonenc* e, size_t size) { - size_t ret = e->ptr - e->buf + e->overflow; - - if (size > 0) { - if (e->ptr == e->end) e->ptr--; - *e->ptr = '\0'; - } - - return ret; -} - -static size_t upb_JsonEncoder_Encode(jsonenc* const e, - const upb_Message* const msg, - const upb_MessageDef* const m, - const size_t size) { - if (UPB_SETJMP(e->err) != 0) return -1; - - jsonenc_msgfield(e, msg, m); - if (e->arena) upb_Arena_Free(e->arena); - return jsonenc_nullz(e, size); -} - -size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int options, char* buf, - size_t size, upb_Status* status) { - jsonenc e; - - e.buf = buf; - e.ptr = buf; - e.end = UPB_PTRADD(buf, size); - e.overflow = 0; - e.options = options; - e.ext_pool = ext_pool; - e.status = status; - e.arena = NULL; - - return upb_JsonEncoder_Encode(&e, msg, m, size); -} diff --git a/vendor/upb/json/encode.h b/vendor/upb/json/encode.h deleted file mode 100644 index 05c956e..0000000 --- a/vendor/upb/json/encode.h +++ /dev/null @@ -1,50 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_JSON_ENCODE_H_ -#define UPB_JSON_ENCODE_H_ - -#include "upb/reflection/def.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - /* When set, emits 0/default values. TODO: proto3 only? */ - upb_JsonEncode_EmitDefaults = 1 << 0, - - /* When set, use normal (snake_case) field names instead of JSON (camelCase) - names. */ - upb_JsonEncode_UseProtoNames = 1 << 1, - - /* When set, emits enums as their integer values instead of as their names. */ - upb_JsonEncode_FormatEnumsAsIntegers = 1 << 2 -}; - -/* Encodes the given |msg| to JSON format. The message's reflection is given in - * |m|. The DefPool in |ext_pool| is used to find extensions (if NULL, - * extensions will not be printed). - * - * Output is placed in the given buffer, and always NULL-terminated. The output - * size (excluding NULL) is returned. This means that a return value >= |size| - * implies that the output was truncated. (These are the same semantics as - * snprintf()). */ -UPB_API size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int options, - char* buf, size_t size, upb_Status* status); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_JSONENCODE_H_ */ diff --git a/vendor/upb/json/encode_test.cc b/vendor/upb/json/encode_test.cc deleted file mode 100644 index 42ce6dd..0000000 --- a/vendor/upb/json/encode_test.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/json/encode.h" - -#include -#include - -#include "google/protobuf/struct.upb.h" -#include -#include "upb/base/status.hpp" -#include "upb/base/upcast.h" -#include "upb/json/test.upb.h" -#include "upb/json/test.upbdefs.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/reflection/def.hpp" - -static std::string JsonEncode(const upb_test_Box* msg, int options) { - upb::Arena a; - upb::Status status; - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - size_t json_size = upb_JsonEncode(UPB_UPCAST(msg), m.ptr(), defpool.ptr(), - options, nullptr, 0, status.ptr()); - char* json_buf = (char*)upb_Arena_Malloc(a.ptr(), json_size + 1); - - size_t size = upb_JsonEncode(UPB_UPCAST(msg), m.ptr(), defpool.ptr(), options, - json_buf, json_size + 1, status.ptr()); - EXPECT_EQ(size, json_size); - return std::string(json_buf, json_size); -} - -// Encode a single optional enum. -TEST(JsonTest, EncodeEnum) { - upb::Arena a; - - upb_test_Box* foo = upb_test_Box_new(a.ptr()); - upb_test_Box_set_first_tag(foo, upb_test_Z_BAR); - - EXPECT_EQ(R"({"firstTag":"Z_BAR"})", JsonEncode(foo, 0)); - EXPECT_EQ(R"({"firstTag":1})", - JsonEncode(foo, upb_JsonEncode_FormatEnumsAsIntegers)); -} - -// Encode a single optional negative enum. -TEST(JsonTest, EncodeNegativeEnum) { - upb::Arena a; - - upb_test_Box* foo = upb_test_Box_new(a.ptr()); - upb_test_Box_set_last_tag(foo, upb_test_Z_BAZ); - - EXPECT_EQ(R"({"lastTag":"Z_BAZ"})", JsonEncode(foo, 0)); - EXPECT_EQ(R"({"lastTag":-2})", - JsonEncode(foo, upb_JsonEncode_FormatEnumsAsIntegers)); -} - -// Encode a single repeated enum. -TEST(JsonTest, EncodeRepeatedEnum) { - upb::Arena a; - - upb_test_Box* foo = upb_test_Box_new(a.ptr()); - upb_test_Box_add_more_tags(foo, upb_test_Z_BAT, a.ptr()); - - EXPECT_EQ(R"({"moreTags":["Z_BAT"]})", JsonEncode(foo, 0)); - EXPECT_EQ(R"({"moreTags":[13]})", - JsonEncode(foo, upb_JsonEncode_FormatEnumsAsIntegers)); -} - -// Special case: encode null enum. -TEST(JsonTest, EncodeNullEnum) { - upb::Arena a; - - upb_test_Box* foo = upb_test_Box_new(a.ptr()); - google_protobuf_Value_set_null_value(upb_test_Box_mutable_val(foo, a.ptr()), - google_protobuf_NULL_VALUE); - - EXPECT_EQ(R"({"val":null})", JsonEncode(foo, 0)); - EXPECT_EQ(R"({"val":null})", - JsonEncode(foo, upb_JsonEncode_FormatEnumsAsIntegers)); -} - -TEST(JsonTest, EncodeConflictJsonName) { - upb::Arena a; - upb_test_Box* box = upb_test_Box_new(a.ptr()); - upb_test_Box_set_value(box, 2); - EXPECT_EQ(R"({"old_value":2})", JsonEncode(box, 0)); - - upb_test_Box* new_box = upb_test_Box_new(a.ptr()); - upb_test_Box_set_new_value(new_box, 2); - EXPECT_EQ(R"({"value":2})", JsonEncode(new_box, 0)); -} diff --git a/vendor/upb/json/fuzz_test.cc b/vendor/upb/json/fuzz_test.cc deleted file mode 100644 index d430d15f..0000000 --- a/vendor/upb/json/fuzz_test.cc +++ /dev/null @@ -1,62 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include -#include - -#include -#include "testing/fuzzing/fuzztest.h" -#include "upb/base/status.hpp" -#include "upb/base/upcast.h" -#include "upb/json/decode.h" -#include "upb/json/encode.h" -#include "upb/json/test.upb.h" -#include "upb/json/test.upbdefs.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/reflection/def.hpp" - -namespace { - -void DecodeEncodeArbitraryJson(std::string_view json) { - upb::Arena arena; - upb::Status status; - - // Copy the input string to the heap. This helps asan reproduce issues that - // don't reproduce when passing static memory pointers. See b/309107518. - auto* json_heap = new char[json.size()]; - memcpy(json_heap, json.data(), json.size()); - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - upb_test_Box* box = upb_test_Box_new(arena.ptr()); - int options = 0; - bool ok = upb_JsonDecode(json_heap, json.size(), UPB_UPCAST(box), m.ptr(), - defpool.ptr(), options, arena.ptr(), status.ptr()); - delete[] json_heap; - if (!ok) return; - - size_t size = upb_JsonEncode(UPB_UPCAST(box), m.ptr(), defpool.ptr(), options, - nullptr, 0, status.ptr()); - char* json_buf = (char*)upb_Arena_Malloc(arena.ptr(), size + 1); - - size_t written = upb_JsonEncode(UPB_UPCAST(box), m.ptr(), defpool.ptr(), - options, json_buf, size + 1, status.ptr()); - EXPECT_EQ(written, size); -} -FUZZ_TEST(FuzzTest, DecodeEncodeArbitraryJson); - -TEST(FuzzTest, UnclosedObjectKey) { DecodeEncodeArbitraryJson("{\" "); } - -TEST(FuzzTest, MalformedExponent) { - DecodeEncodeArbitraryJson(R"({"val":0XE$})"); -} - -} // namespace diff --git a/vendor/upb/json/test.proto b/vendor/upb/json/test.proto deleted file mode 100644 index a0d56a7..0000000 --- a/vendor/upb/json/test.proto +++ /dev/null @@ -1,31 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package upb_test; - -import "google/protobuf/struct.proto"; - -enum Tag { - Z_NONE = 0; - Z_BAR = 1; - Z_BAZ = -2; - Z_BAT = 13; -} - -message Box { - optional Tag first_tag = 1; - repeated Tag more_tags = 2; - optional Tag last_tag = 5; - optional string name = 4; - optional google.protobuf.Value val = 6; - optional float f = 7; - optional double d = 8; - optional int32 value = 9 [json_name = "old_value"]; - optional int32 new_value = 10 [json_name = "value"]; -} diff --git a/vendor/upb/lex/BUILD b/vendor/upb/lex/BUILD deleted file mode 100644 index 05b360b..0000000 --- a/vendor/upb/lex/BUILD +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "lex", - srcs = [ - "atoi.c", - "round_trip.c", - "strtod.c", - "unicode.c", - ], - hdrs = [ - "atoi.h", - "round_trip.h", - "strtod.h", - "unicode.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = ["//upb/port"], -) - -cc_test( - name = "atoi_test", - srcs = ["atoi_test.cc"], - deps = [ - ":lex", - "@abseil-cpp//absl/strings", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "round_trip_test", - srcs = ["round_trip_test.cc"], - deps = [ - ":lex", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/lex/atoi.c b/vendor/upb/lex/atoi.c deleted file mode 100644 index 720aacf..0000000 --- a/vendor/upb/lex/atoi.c +++ /dev/null @@ -1,48 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/lex/atoi.h" - -// Must be last. -#include "upb/port/def.inc" - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { - uint64_t u64 = 0; - while (ptr < end) { - unsigned ch = *ptr - '0'; - if (ch >= 10) break; - if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { - return NULL; // integer overflow - } - u64 *= 10; - u64 += ch; - ptr++; - } - - *val = u64; - return ptr; -} - -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg) { - bool neg = false; - uint64_t u64; - - if (ptr != end && *ptr == '-') { - ptr++; - neg = true; - } - - ptr = upb_BufToUint64(ptr, end, &u64); - if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { - return NULL; // integer overflow - } - - *val = neg ? -u64 : u64; - if (is_neg) *is_neg = neg; - return ptr; -} diff --git a/vendor/upb/lex/atoi.h b/vendor/upb/lex/atoi.h deleted file mode 100644 index 6d57fa0..0000000 --- a/vendor/upb/lex/atoi.h +++ /dev/null @@ -1,35 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_LEX_ATOI_H_ -#define UPB_LEX_ATOI_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// We use these hand-written routines instead of strto[u]l() because the "long -// long" variants aren't in c89. Also our version allows setting a ptr limit. -// Return the new position of the pointer after parsing the int, or NULL on -// integer overflow. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val); -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_LEX_ATOI_H_ */ diff --git a/vendor/upb/lex/atoi_test.cc b/vendor/upb/lex/atoi_test.cc deleted file mode 100644 index edd949f..0000000 --- a/vendor/upb/lex/atoi_test.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/lex/atoi.h" - -#include - -#include -#include "absl/strings/str_cat.h" - -TEST(AtoiTest, Uint64) { - uint64_t val; - - const char* s = "1234z"; - EXPECT_EQ(s + 1, upb_BufToUint64(s, s + 1, &val)); - EXPECT_EQ(val, 1); - EXPECT_EQ(s + 4, upb_BufToUint64(s, s + 4, &val)); - EXPECT_EQ(val, 1234); - EXPECT_EQ(s + 4, upb_BufToUint64(s, s + 5, &val)); - EXPECT_EQ(val, 1234); - - const char* t = "42.6"; - EXPECT_EQ(t + 1, upb_BufToUint64(t, t + 1, &val)); - EXPECT_EQ(val, 4); - EXPECT_EQ(t + 2, upb_BufToUint64(t, t + 2, &val)); - EXPECT_EQ(val, 42); - EXPECT_EQ(t + 2, upb_BufToUint64(t, t + 3, &val)); - EXPECT_EQ(val, 42); - - // Integer overflow - const char* u = "1000000000000000000000000000000"; - EXPECT_EQ(nullptr, upb_BufToUint64(u, u + strlen(u), &val)); - - // Not an integer - const char* v = "foobar"; - EXPECT_EQ(v, upb_BufToUint64(v, v + strlen(v), &val)); - - const uint64_t values[] = { - std::numeric_limits::max(), - std::numeric_limits::min(), - }; - for (size_t i = 0; i < ABSL_ARRAYSIZE(values); i++) { - std::string v = absl::StrCat(values[i]); - const char* ptr = v.c_str(); - const char* end = ptr + strlen(ptr); - EXPECT_EQ(end, upb_BufToUint64(ptr, end, &val)); - EXPECT_EQ(val, values[i]); - } -} - -TEST(AtoiTest, Int64) { - int64_t val; - bool neg; - - const char* s = "1234z"; - EXPECT_EQ(s + 1, upb_BufToInt64(s, s + 1, &val, &neg)); - EXPECT_EQ(val, 1); - EXPECT_EQ(neg, false); - EXPECT_EQ(s + 4, upb_BufToInt64(s, s + 4, &val, nullptr)); - EXPECT_EQ(val, 1234); - EXPECT_EQ(s + 4, upb_BufToInt64(s, s + 5, &val, nullptr)); - EXPECT_EQ(val, 1234); - - const char* t = "-42.6"; - EXPECT_EQ(t + 2, upb_BufToInt64(t, t + 2, &val, &neg)); - EXPECT_EQ(val, -4); - EXPECT_EQ(neg, true); - EXPECT_EQ(t + 3, upb_BufToInt64(t, t + 3, &val, nullptr)); - EXPECT_EQ(val, -42); - EXPECT_EQ(neg, true); - EXPECT_EQ(t + 3, upb_BufToInt64(t, t + 5, &val, nullptr)); - EXPECT_EQ(val, -42); - - const int64_t values[] = { - std::numeric_limits::max(), - std::numeric_limits::min(), - std::numeric_limits::max(), - std::numeric_limits::min(), - }; - for (size_t i = 0; i < ABSL_ARRAYSIZE(values); i++) { - std::string v = absl::StrCat(values[i]); - const char* ptr = v.c_str(); - const char* end = ptr + strlen(ptr); - EXPECT_EQ(end, upb_BufToInt64(ptr, end, &val, nullptr)); - EXPECT_EQ(val, values[i]); - } -} diff --git a/vendor/upb/lex/round_trip.c b/vendor/upb/lex/round_trip.c deleted file mode 100644 index 82818ee..0000000 --- a/vendor/upb/lex/round_trip.c +++ /dev/null @@ -1,57 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/lex/round_trip.h" - -#include -#include -#include -#include - -// Must be last. -#include "upb/port/def.inc" - -/* Miscellaneous utilities ****************************************************/ - -static void upb_FixLocale(char* p) { - /* printf() is dependent on locales; sadly there is no easy and portable way - * to avoid this. This little post-processing step will translate 1,2 -> 1.2 - * since JSON needs the latter. Arguably a hack, but it is simple and the - * alternatives are far more complicated, platform-dependent, and/or larger - * in code size. */ - for (; *p; p++) { - if (*p == ',') *p = '.'; - } -} - -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - if (isnan(val)) { - snprintf(buf, size, "%s", "nan"); - return; - } - snprintf(buf, size, "%.*g", DBL_DIG, val); - if (strtod(buf, NULL) != val) { - snprintf(buf, size, "%.*g", DBL_DIG + 2, val); - assert(strtod(buf, NULL) == val); - } - upb_FixLocale(buf); -} - -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - if (isnan(val)) { - snprintf(buf, size, "%s", "nan"); - return; - } - snprintf(buf, size, "%.*g", FLT_DIG, val); - if (strtof(buf, NULL) != val) { - snprintf(buf, size, "%.*g", FLT_DIG + 3, val); - assert(strtof(buf, NULL) == val); - } - upb_FixLocale(buf); -} diff --git a/vendor/upb/lex/round_trip.h b/vendor/upb/lex/round_trip.h deleted file mode 100644 index 0306c44..0000000 --- a/vendor/upb/lex/round_trip.h +++ /dev/null @@ -1,35 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_LEX_ROUND_TRIP_H_ -#define UPB_LEX_ROUND_TRIP_H_ - -// Must be last. -#include "upb/port/def.inc" - -// Encodes a float or double that is round-trippable, but as short as possible. -// These routines are not fully optimal (not guaranteed to be shortest), but are -// short-ish and match the implementation that has been used in protobuf since -// the beginning. - -// The given buffer size must be at least kUpb_RoundTripBufferSize. -enum { kUpb_RoundTripBufferSize = 32 }; - -#ifdef __cplusplus -extern "C" { -#endif - -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size); -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_LEX_ROUND_TRIP_H_ */ diff --git a/vendor/upb/lex/round_trip_test.cc b/vendor/upb/lex/round_trip_test.cc deleted file mode 100644 index c6fc718..0000000 --- a/vendor/upb/lex/round_trip_test.cc +++ /dev/null @@ -1,35 +0,0 @@ -#include "upb/lex/round_trip.h" - -#include - -#include - -namespace { - -TEST(RoundTripTest, Double) { - char buf[32]; - - _upb_EncodeRoundTripDouble(0.123456789, buf, sizeof(buf)); - EXPECT_STREQ(buf, "0.123456789"); - - _upb_EncodeRoundTripDouble(0.0, buf, sizeof(buf)); - EXPECT_STREQ(buf, "0"); - - _upb_EncodeRoundTripDouble(nan(""), buf, sizeof(buf)); - EXPECT_STREQ(buf, "nan"); -} - -TEST(RoundTripTest, Float) { - char buf[32]; - - _upb_EncodeRoundTripFloat(0.123456, buf, sizeof(buf)); - EXPECT_STREQ(buf, "0.123456"); - - _upb_EncodeRoundTripFloat(0.0, buf, sizeof(buf)); - EXPECT_STREQ(buf, "0"); - - _upb_EncodeRoundTripFloat(nan(""), buf, sizeof(buf)); - EXPECT_STREQ(buf, "nan"); -} - -} // namespace diff --git a/vendor/upb/lex/strtod.c b/vendor/upb/lex/strtod.c deleted file mode 100644 index 2e5bc15..0000000 --- a/vendor/upb/lex/strtod.c +++ /dev/null @@ -1,86 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/lex/strtod.h" - -#include -#include - -// Must be last. -#include "upb/port/def.inc" - -// Determine the locale-specific radix character by calling sprintf() to print -// the number 1.5, then stripping off the digits. As far as I can tell, this -// is the only portable, thread-safe way to get the C library to divulge the -// locale's radix character. No, localeconv() is NOT thread-safe. - -static int GetLocaleRadix(char *data, size_t capacity) { - char temp[16]; - const int size = snprintf(temp, sizeof(temp), "%.1f", 1.5); - UPB_ASSERT(temp[0] == '1'); - UPB_ASSERT(temp[size - 1] == '5'); - if (size < capacity) { - return 0; - } - temp[size - 1] = '\0'; - strncpy(data, temp + 1, size); - return size - 2; -} - -// Populates a string identical to *input except that the character pointed to -// by pos (which should be '.') is replaced with the locale-specific radix. - -static void LocalizeRadix(const char *input, const char *pos, char *output, - int output_size) { - const int len1 = pos - input; - - char radix[8]; - const int len2 = GetLocaleRadix(radix, sizeof(radix)); - - const int n = output_size - len1 - len2 - 1; - if (n < 0) { - return; - } - - memcpy(output, input, len1); - memcpy(output + len1, radix, len2); - strncpy(output + len1 + len2, input + len1 + 1, n); - output[output_size - 1] = '\0'; -} - -double _upb_NoLocaleStrtod(const char *str, char **endptr) { - // We cannot simply set the locale to "C" temporarily with setlocale() - // as this is not thread-safe. Instead, we try to parse in the current - // locale first. If parsing stops at a '.' character, then this is a - // pretty good hint that we're actually in some other locale in which - // '.' is not the radix character. - - char *temp_endptr; - double result = strtod(str, &temp_endptr); - if (endptr != NULL) *endptr = temp_endptr; - if (*temp_endptr != '.') return result; - - // Parsing halted on a '.'. Perhaps we're in a different locale? Let's - // try to replace the '.' with a locale-specific radix character and - // try again. - - char localized[80]; - LocalizeRadix(str, temp_endptr, localized, sizeof localized); - char *localized_endptr; - result = strtod(localized, &localized_endptr); - if ((localized_endptr - &localized[0]) > (temp_endptr - str)) { - // This attempt got further, so replacing the decimal must have helped. - // Update endptr to point at the right location. - if (endptr != NULL) { - // size_diff is non-zero if the localized radix has multiple bytes. - int size_diff = strlen(localized) - strlen(str); - *endptr = (char *)str + (localized_endptr - &localized[0] - size_diff); - } - } - - return result; -} diff --git a/vendor/upb/lex/strtod.h b/vendor/upb/lex/strtod.h deleted file mode 100644 index 86b18db..0000000 --- a/vendor/upb/lex/strtod.h +++ /dev/null @@ -1,26 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_LEX_STRTOD_H_ -#define UPB_LEX_STRTOD_H_ - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -double _upb_NoLocaleStrtod(const char *str, char **endptr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_LEX_STRTOD_H_ */ diff --git a/vendor/upb/lex/unicode.c b/vendor/upb/lex/unicode.c deleted file mode 100644 index 53121e9..0000000 --- a/vendor/upb/lex/unicode.c +++ /dev/null @@ -1,37 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/lex/unicode.h" - -// Must be last. -#include "upb/port/def.inc" - -int upb_Unicode_ToUTF8(uint32_t cp, char* out) { - if (cp <= 0x7f) { - out[0] = cp; - return 1; - } - if (cp <= 0x07ff) { - out[0] = (cp >> 6) | 0xc0; - out[1] = (cp & 0x3f) | 0x80; - return 2; - } - if (cp <= 0xffff) { - out[0] = (cp >> 12) | 0xe0; - out[1] = ((cp >> 6) & 0x3f) | 0x80; - out[2] = (cp & 0x3f) | 0x80; - return 3; - } - if (cp <= 0x10ffff) { - out[0] = (cp >> 18) | 0xf0; - out[1] = ((cp >> 12) & 0x3f) | 0x80; - out[2] = ((cp >> 6) & 0x3f) | 0x80; - out[3] = (cp & 0x3f) | 0x80; - return 4; - } - return 0; -} diff --git a/vendor/upb/lex/unicode.h b/vendor/upb/lex/unicode.h deleted file mode 100644 index 9b8a405..0000000 --- a/vendor/upb/lex/unicode.h +++ /dev/null @@ -1,59 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_LEX_UNICODE_H_ -#define UPB_LEX_UNICODE_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Returns true iff a codepoint is the value for a high surrogate. -UPB_INLINE bool upb_Unicode_IsHigh(uint32_t cp) { - return (cp >= 0xd800 && cp <= 0xdbff); -} - -// Returns true iff a codepoint is the value for a low surrogate. -UPB_INLINE bool upb_Unicode_IsLow(uint32_t cp) { - return (cp >= 0xdc00 && cp <= 0xdfff); -} - -// Returns the high 16-bit surrogate value for a supplementary codepoint. -// Does not sanity-check the input. -UPB_INLINE uint16_t upb_Unicode_ToHigh(uint32_t cp) { - return (cp >> 10) + 0xd7c0; -} - -// Returns the low 16-bit surrogate value for a supplementary codepoint. -// Does not sanity-check the input. -UPB_INLINE uint16_t upb_Unicode_ToLow(uint32_t cp) { - return (cp & 0x3ff) | 0xdc00; -} - -// Returns the 32-bit value corresponding to a pair of 16-bit surrogates. -// Does not sanity-check the input. -UPB_INLINE uint32_t upb_Unicode_FromPair(uint32_t high, uint32_t low) { - return ((high & 0x3ff) << 10) + (low & 0x3ff) + 0x10000; -} - -// Outputs a codepoint as UTF8. -// Returns the number of bytes written (1-4 on success, 0 on error). -// Does not sanity-check the input. Specifically does not check for surrogates. -int upb_Unicode_ToUTF8(uint32_t cp, char* out); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_LEX_UNICODE_H_ */ diff --git a/vendor/upb/mem/BUILD b/vendor/upb/mem/BUILD deleted file mode 100644 index 206b7a4..0000000 --- a/vendor/upb/mem/BUILD +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "mem", - srcs = [ - "alloc.c", - "arena.c", - ], - hdrs = [ - "alloc.h", - "arena.h", - "arena.hpp", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - "//upb/port", - ], -) - -cc_library( - name = "internal", - hdrs = [ - "internal/arena.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/port", - ], -) - -cc_test( - name = "arena_test", - srcs = ["arena_test.cc"], - deps = [ - ":mem", - "//upb/port", - "@abseil-cpp//absl/base:core_headers", - "@abseil-cpp//absl/cleanup", - "@abseil-cpp//absl/container:flat_hash_map", - "@abseil-cpp//absl/random", - "@abseil-cpp//absl/random:distributions", - "@abseil-cpp//absl/synchronization", - "@abseil-cpp//absl/time", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - "**/*.hpp", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/mem/alloc.c b/vendor/upb/mem/alloc.c deleted file mode 100644 index 3d70ee7..0000000 --- a/vendor/upb/mem/alloc.c +++ /dev/null @@ -1,28 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mem/alloc.h" - -#include - -// Must be last. -#include "upb/port/def.inc" - -static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size, size_t* actual_size) { - UPB_UNUSED(alloc); - UPB_UNUSED(oldsize); - UPB_UNUSED(actual_size); - if (size == 0) { - free(ptr); - return NULL; - } else { - return realloc(ptr, size); - } -} - -upb_alloc upb_alloc_global = {&upb_global_allocfunc}; diff --git a/vendor/upb/mem/alloc.h b/vendor/upb/mem/alloc.h deleted file mode 100644 index 511e386..0000000 --- a/vendor/upb/mem/alloc.h +++ /dev/null @@ -1,103 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MEM_ALLOC_H_ -#define UPB_MEM_ALLOC_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct upb_alloc upb_alloc; - -/* A combined `malloc()`/`free()` function. - * If `size` is 0 then the function acts like `free()`, otherwise it acts like - * `realloc()`. Only `oldsize` bytes from a previous allocation are - * preserved. If `actual_size` is not null and the allocator supports it, the - * actual size of the resulting allocation is stored in `actual_size`. If - * `actual_size` is not null, you must zero out the memory pointed to by - * `actual_size` before calling. */ -typedef void* upb_alloc_func(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size, size_t* actual_size); - -/* A upb_alloc is a possibly-stateful allocator object. - * - * It could either be an arena allocator (which doesn't require individual - * `free()` calls) or a regular `malloc()` (which does). The client must - * therefore free memory unless it knows that the allocator is an arena - * allocator. */ -struct upb_alloc { - upb_alloc_func* func; -}; - -UPB_NODISCARD UPB_INLINE void* upb_malloc(upb_alloc* alloc, size_t size) { - UPB_ASSERT(alloc); - return alloc->func(alloc, NULL, 0, size, NULL); -} - -typedef struct { - void* p; - size_t n; -} upb_SizedPtr; - -UPB_INLINE upb_SizedPtr upb_SizeReturningMalloc(upb_alloc* alloc, size_t size) { - UPB_ASSERT(alloc); - upb_SizedPtr result; - result.n = 0; - result.p = alloc->func(alloc, NULL, 0, size, &result.n); - result.n = result.p != NULL ? UPB_MAX(result.n, size) : 0; - return result; -} - -UPB_NODISCARD UPB_INLINE void* upb_realloc(upb_alloc* alloc, void* ptr, - size_t oldsize, size_t size) { - UPB_ASSERT(alloc); - return alloc->func(alloc, ptr, oldsize, size, NULL); -} - -UPB_INLINE void upb_free(upb_alloc* alloc, void* ptr) { - UPB_ASSERT(alloc); - alloc->func(alloc, ptr, 0, 0, NULL); -} - -UPB_INLINE void upb_free_sized(upb_alloc* alloc, void* ptr, size_t size) { - UPB_ASSERT(alloc); - alloc->func(alloc, ptr, size, 0, NULL); -} - -// The global allocator used by upb. Uses the standard malloc()/free(). - -extern upb_alloc upb_alloc_global; - -/* Functions that hard-code the global malloc. - * - * We still get benefit because we can put custom logic into our global - * allocator, like injecting out-of-memory faults in debug/testing builds. */ - -UPB_NODISCARD UPB_INLINE void* upb_gmalloc(size_t size) { - return upb_malloc(&upb_alloc_global, size); -} - -UPB_NODISCARD UPB_INLINE void* upb_grealloc(void* ptr, size_t oldsize, - size_t size) { - return upb_realloc(&upb_alloc_global, ptr, oldsize, size); -} - -UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MEM_ALLOC_H_ */ diff --git a/vendor/upb/mem/arena.c b/vendor/upb/mem/arena.c deleted file mode 100644 index 9655286..0000000 --- a/vendor/upb/mem/arena.c +++ /dev/null @@ -1,1018 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mem/arena.h" - -#include - -#include "upb/port/sanitizers.h" - -#ifdef UPB_TRACING_ENABLED -#include -#endif - -#include -#include - -#include "upb/mem/alloc.h" -#include "upb/mem/internal/arena.h" -#include "upb/port/atomic.h" - -// Must be last. -#include "upb/port/def.inc" - -static UPB_ATOMIC(size_t) g_max_block_size = UPB_DEFAULT_MAX_BLOCK_SIZE; - -void upb_Arena_SetMaxBlockSize(size_t max) { - UPB_ASSERT(max <= UINT32_MAX); - upb_Atomic_Store(&g_max_block_size, max, memory_order_relaxed); -} - -typedef struct upb_MemBlock { - struct upb_MemBlock* next; - // Size of the actual allocation. - // Size of 0 means this is a upb_ArenaRef. - size_t size; - // Data follows. -} upb_MemBlock; - -// A special block type that indicates a reference to another arena. -// When this arena is freed, a ref is released on the referenced arena. -// size must be 0. -typedef struct upb_ArenaRef { - upb_MemBlock prefix; // size is always zero - const upb_Arena* arena; -#ifndef NDEBUG - const struct upb_ArenaRef* next_ref; -#endif -} upb_ArenaRef; - -typedef struct upb_ArenaInternal { - // upb_alloc* together with a low bit which signals if there is an initial - // block. - uintptr_t block_alloc; - - // Linked list of blocks to free/cleanup. - upb_MemBlock* blocks; - -#ifndef NDEBUG - // Stack of pointers to other arenas that this arena owns. - // Used for debug-only ref cycle checks. - UPB_ATOMIC(const upb_ArenaRef*) refs; -#endif - - // Size of the last block we allocated in the normal exponential scheme. - uint32_t last_block_size; - - // A hint that grows whenever we perform a "one-off" allocation into a a - // dedicated block. This helps us determine if these outlier blocks are - // actually common enough that we should switch back to the normal exponential - // scheme at the larger size. - uint32_t size_hint; - - // All non atomic members used during allocation must be above this point, and - // are used by _SwapIn/_SwapOut - - // Total space allocated in blocks, atomic only for SpaceAllocated - UPB_ATOMIC(uintptr_t) space_allocated; - - // The cleanup for the allocator. This is called after all the blocks are - // freed in an arena. - upb_AllocCleanupFunc* upb_alloc_cleanup; - - // When multiple arenas are fused together, each arena points to a parent - // arena (root points to itself). The root tracks how many live arenas - // reference it. - - // The low bit is tagged: - // 0: pointer to parent - // 1: count, left shifted by one - UPB_ATOMIC(uintptr_t) parent_or_count; - - // All nodes that are fused together are in a singly-linked list. - // == NULL at end of list. - UPB_ATOMIC(struct upb_ArenaInternal*) next; - - // - If the low bit is set, is a pointer to the tail of the list (populated - // for roots, set to self for roots with no fused arenas). This is best - // effort, and it may not always reflect the true tail, but it will always - // be a valid node in the list. This is useful for finding the list tail - // without having to walk the entire list. - // - If the low bit is not set, is a pointer to the previous node in the list, - // such that a->previous_or_tail->next == a. - UPB_ATOMIC(uintptr_t) previous_or_tail; - - // We use a different UPB_XSAN_MEMBER than the one in upb_Arena because the - // two are distinct synchronization domains. The upb_Arena.ptr member is - // not published in the allocation path, so it is not synchronized with - // respect to operations performed in this file such as Fuse, Free, - // SpaceAllocated, etc. This means that it is not safe to read or write - // the upb_Arena.ptr member in those functions. - UPB_XSAN_MEMBER -} upb_ArenaInternal; - -// All public + private state for an arena. -typedef struct { - upb_Arena head; - upb_ArenaInternal body; -} upb_ArenaState; - -typedef struct { - upb_ArenaInternal* root; - uintptr_t tagged_count; -} upb_ArenaRoot; - -static const size_t kUpb_MemblockReserve = - UPB_ALIGN_MALLOC(sizeof(upb_MemBlock)); - -static const size_t kUpb_ArenaRefReserve = - UPB_ALIGN_MALLOC(sizeof(upb_ArenaRef)); - -// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) -static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { - return &((upb_ArenaState*)a)->body; -} - -static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { - return (parent_or_count & 1) == 1; -} - -static bool _upb_Arena_IsTaggedPointer(uintptr_t parent_or_count) { - return (parent_or_count & 1) == 0; -} - -static uintptr_t _upb_Arena_RefCountFromTagged(uintptr_t parent_or_count) { - UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); - return parent_or_count >> 1; -} - -static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { - uintptr_t parent_or_count = (refcount << 1) | 1; - UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); - return parent_or_count; -} - -static upb_ArenaInternal* _upb_Arena_PointerFromTagged( - uintptr_t parent_or_count) { - UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return (upb_ArenaInternal*)parent_or_count; -} - -static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { - uintptr_t parent_or_count = (uintptr_t)ai; - UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return parent_or_count; -} - -static bool _upb_Arena_IsTaggedTail(uintptr_t previous_or_tail) { - return (previous_or_tail & 1) == 1; -} - -static bool _upb_Arena_IsTaggedPrevious(uintptr_t previous_or_tail) { - return (previous_or_tail & 1) == 0; -} - -static upb_ArenaInternal* _upb_Arena_TailFromTagged( - uintptr_t previous_or_tail) { - UPB_ASSERT(_upb_Arena_IsTaggedTail(previous_or_tail)); - return (upb_ArenaInternal*)(previous_or_tail ^ 1); -} - -static uintptr_t _upb_Arena_TaggedFromTail(upb_ArenaInternal* tail) { - uintptr_t previous_or_tail = (uintptr_t)tail | 1; - UPB_ASSERT(_upb_Arena_IsTaggedTail(previous_or_tail)); - return previous_or_tail; -} - -static upb_ArenaInternal* _upb_Arena_PreviousFromTagged( - uintptr_t previous_or_tail) { - UPB_ASSERT(_upb_Arena_IsTaggedPrevious(previous_or_tail)); - return (upb_ArenaInternal*)previous_or_tail; -} - -static uintptr_t _upb_Arena_TaggedFromPrevious(upb_ArenaInternal* ai) { - uintptr_t previous = (uintptr_t)ai; - UPB_ASSERT(_upb_Arena_IsTaggedPrevious(previous)); - return previous; -} - -static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { - return (upb_alloc*)(ai->block_alloc & ~0x1); -} - -static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { - uintptr_t alloc_uint = (uintptr_t)alloc; - UPB_ASSERT((alloc_uint & 1) == 0); - return alloc_uint | (has_initial ? 1 : 0); -} - -static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { - return ai->block_alloc & 0x1; -} - -#ifdef UPB_TRACING_ENABLED -static void (*_init_arena_trace_handler)(const upb_Arena*, size_t size) = NULL; -static void (*_fuse_arena_trace_handler)(const upb_Arena*, - const upb_Arena*) = NULL; -static void (*_free_arena_trace_handler)(const upb_Arena*) = NULL; - -void upb_Arena_SetTraceHandler( - void (*initArenaTraceHandler)(const upb_Arena*, size_t size), - void (*fuseArenaTraceHandler)(const upb_Arena*, const upb_Arena*), - void (*freeArenaTraceHandler)(const upb_Arena*)) { - _init_arena_trace_handler = initArenaTraceHandler; - _fuse_arena_trace_handler = fuseArenaTraceHandler; - _free_arena_trace_handler = freeArenaTraceHandler; -} - -void upb_Arena_LogInit(const upb_Arena* arena, size_t size) { - if (_init_arena_trace_handler) { - _init_arena_trace_handler(arena, size); - } -} -void upb_Arena_LogFuse(const upb_Arena* arena1, const upb_Arena* arena2) { - if (_fuse_arena_trace_handler) { - _fuse_arena_trace_handler(arena1, arena2); - } -} -void upb_Arena_LogFree(const upb_Arena* arena) { - if (_free_arena_trace_handler) { - _free_arena_trace_handler(arena); - } -} -#endif // UPB_TRACING_ENABLED - -// If the param a is already the root, provides no memory order of refcount. -// If it has a parent, then acquire memory order is provided for both the root -// and the refcount. Thread safe. -static upb_ArenaRoot _upb_Arena_FindRoot(upb_ArenaInternal* ai) { - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_relaxed); - if (_upb_Arena_IsTaggedRefcount(poc)) { - // Fast, relaxed path - arenas that have never been fused to a parent only - // need relaxed memory order, since they're returning themselves and the - // refcount. - return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; - } - // Slow path needs acquire order; reloading is cheaper than a fence on ARM - // (LDA vs DMB ISH). Even though this is a reread, we know it must be a tagged - // pointer because if this Arena isn't a root, it can't ever become one. - poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - do { - upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(next)); - UPB_ASSERT(ai != next); - poc = upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); - - if (_upb_Arena_IsTaggedPointer(poc)) { - // To keep complexity down, we lazily collapse levels of the tree. This - // keeps it flat in the final case, but doesn't cost much incrementally. - // - // Path splitting keeps time complexity down, see: - // https://en.wikipedia.org/wiki/Disjoint-set_data_structure - UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(poc)); - upb_Atomic_Store(&ai->parent_or_count, poc, memory_order_release); - } - ai = next; - } while (_upb_Arena_IsTaggedPointer(poc)); - return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; -} - -uintptr_t upb_Arena_SpaceAllocated(const upb_Arena* arena, - size_t* fused_count) { - upb_ArenaInternal* ai = upb_Arena_Internal(arena); - uintptr_t memsize = 0; - size_t local_fused_count = 0; - // Our root would get updated by any racing fuses before our target arena - // became reachable from the root via the linked list; in order to preserve - // monotonic output (any arena counted by a previous invocation is counted by - // this one), we instead iterate forwards and backwards so that we only see - // the results of completed fuses. - uintptr_t previous_or_tail = - upb_Atomic_Load(&ai->previous_or_tail, memory_order_acquire); - while (_upb_Arena_IsTaggedPrevious(previous_or_tail)) { - upb_ArenaInternal* previous = - _upb_Arena_PreviousFromTagged(previous_or_tail); - UPB_ASSERT(previous != ai); - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(previous)); - // Unfortunate macro behavior; prior to C11 when using nonstandard atomics - // this returns a void* and can't be used with += without an intermediate - // conversion to an integer. - // Relaxed is safe - no subsequent reads depend this one - uintptr_t allocated = - upb_Atomic_Load(&previous->space_allocated, memory_order_relaxed); - memsize += allocated; - previous_or_tail = - upb_Atomic_Load(&previous->previous_or_tail, memory_order_acquire); - local_fused_count++; - } - while (ai != NULL) { - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(ai)); - // Unfortunate macro behavior; prior to C11 when using nonstandard atomics - // this returns a void* and can't be used with += without an intermediate - // conversion to an integer. - // Relaxed is safe - no subsequent reads depend this one - uintptr_t allocated = - upb_Atomic_Load(&ai->space_allocated, memory_order_relaxed); - memsize += allocated; - ai = upb_Atomic_Load(&ai->next, memory_order_acquire); - local_fused_count++; - } - - if (fused_count) *fused_count = local_fused_count; - return memsize; -} - -uint32_t upb_Arena_DebugRefCount(const upb_Arena* a) { - uintptr_t tagged = _upb_Arena_FindRoot(upb_Arena_Internal(a)).tagged_count; - return (uint32_t)_upb_Arena_RefCountFromTagged(tagged); -} - -#if UPB_ENABLE_REF_CYCLE_CHECKS - -bool upb_Arena_HasRefChain(const upb_Arena* from, const upb_Arena* to) { - upb_ArenaInternal* ai = upb_Arena_Internal(from); - upb_ArenaInternal* current; - - if (upb_Arena_IsFused(from, to)) return true; - - // 1. Traverse backward to the start of a consistent segment. - uintptr_t previous_or_tail = - upb_Atomic_Load(&ai->previous_or_tail, memory_order_acquire); - while (_upb_Arena_IsTaggedPrevious(previous_or_tail)) { - ai = _upb_Arena_PreviousFromTagged(previous_or_tail); - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(ai)); - previous_or_tail = - upb_Atomic_Load(&ai->previous_or_tail, memory_order_acquire); - } - - // 2. Traverse forward through all arenas in the fuse group. - current = ai; - while (current != NULL) { - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(current)); - const upb_ArenaRef* ref = - upb_Atomic_Load(¤t->refs, memory_order_acquire); - while (ref != NULL) { - if (ref->arena == to || upb_Arena_HasRefChain(ref->arena, to)) { - return true; - } - ref = ref->next_ref; - } - current = upb_Atomic_Load(¤t->next, memory_order_acquire); - } - return false; -} - -#endif - -static upb_MemBlock* _upb_Arena_AllocBlockInternal(upb_alloc* alloc, - size_t size) { - UPB_ASSERT(size >= kUpb_MemblockReserve); - upb_SizedPtr alloc_result = upb_SizeReturningMalloc(alloc, size); - if (!alloc_result.p) return NULL; - upb_MemBlock* block = alloc_result.p; - block->size = alloc_result.n; - return block; -} - -static upb_MemBlock* _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - return _upb_Arena_AllocBlockInternal(_upb_ArenaInternal_BlockAlloc(ai), size); -} - -static void _upb_Arena_AddBlock(upb_Arena* a, upb_MemBlock* block) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - - // Atomic add not required here, as threads won't race allocating blocks, plus - // atomic fetch-add is slower than load/add/store on arm devices compiled - // targeting pre-v8.1. Relaxed order is safe as nothing depends on order of - // size allocated. - uintptr_t old_space_allocated = - upb_Atomic_Load(&ai->space_allocated, memory_order_relaxed); - upb_Atomic_Store(&ai->space_allocated, old_space_allocated + block->size, - memory_order_relaxed); - - block->next = ai->blocks; - ai->blocks = block; -} - -static void _upb_Arena_UseBlockInternal(upb_Arena* a, upb_MemBlock* block, - size_t offset) { - size_t block_size = block->size; - char* start = UPB_PTR_AT(block, kUpb_MemblockReserve + offset, char); - a->UPB_PRIVATE(ptr) = start; - a->UPB_PRIVATE(end) = UPB_PTR_AT(block, block_size, char); - UPB_PRIVATE(upb_Xsan_PoisonRegion)(start, a->UPB_PRIVATE(end) - start); - UPB_PRIVATE(upb_Xsan_Init)(UPB_XSAN(a)); - UPB_ASSERT(UPB_PRIVATE(_upb_ArenaHas)(a) >= - block_size - kUpb_MemblockReserve - offset); -} - -static void _upb_Arena_UseBlock(upb_Arena* a, upb_MemBlock* block) { - _upb_Arena_UseBlockInternal(a, block, 0); -} - -static bool _upb_Arena_WouldReduceFreeSpace(upb_Arena* a, size_t size, - size_t block_size) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - size_t current_free = - ai->blocks ? a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr) : 0; - size_t future_free = block_size - kUpb_MemblockReserve - size; - return current_free >= future_free; -} - -// Fulfills the allocation request by allocating a new block. Returns NULL on -// allocation failure. -void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - if (!ai->block_alloc) return NULL; - - // Whether to satisfy the allocation from a one-off block which is right-sized - // for the current allocation. We do this if we suspect that the current - // allocation is an outlier that does not represent the typical size of - // allocations from this arena, or if we would reduce free space by - // using exponential growth. - bool one_off = false; - - // Relaxed order is safe here as we don't need any ordering with the setter. - size_t max_block_size = - upb_Atomic_Load(&g_max_block_size, memory_order_relaxed); - size_t block_size = UPB_MIN(ai->last_block_size * 2, max_block_size); - - if (size + kUpb_MemblockReserve > block_size) { - // A regular doubling would not yield a large enough block. Does size_hint - // indicate that we have consistently needed large blocks? - block_size = UPB_MIN(ai->size_hint * 2, max_block_size); - if (size + kUpb_MemblockReserve > block_size) { - // Even size_hint is not large enough, we will have to do a one-off. - one_off = true; - } - } - - // If switching to a block of this size would *reduce* available free space, - // we might as well make a one-off block instead. - one_off = one_off || _upb_Arena_WouldReduceFreeSpace(a, size, block_size); - - if (one_off) { - // Note: this may exceed the max block size, but that's okay. - block_size = size + kUpb_MemblockReserve; - } - - upb_MemBlock* block = _upb_Arena_AllocBlock(a, block_size); - if (!block) return NULL; - - _upb_Arena_AddBlock(a, block); - - // Recheck size, in case the allocator gave us a much larger block than we - // requested and we want to make it the new allocating region. - if (UPB_UNLIKELY(one_off) && - _upb_Arena_WouldReduceFreeSpace(a, size, block->size)) { - // Increase size_hint, so that a series of one-off allocations will - // eventually convince us to switch to exponential growth at the larger - // size. - ai->size_hint = UPB_MIN(ai->size_hint + (size >> 1), max_block_size >> 1); - char* allocated = UPB_PTR_AT(block, kUpb_MemblockReserve, char); - char* poison_start = allocated + size - UPB_PRIVATE(kUpb_Asan_GuardSize); - UPB_PRIVATE(upb_Xsan_PoisonRegion)( - poison_start, UPB_PTR_AT(block, block->size, char) - poison_start); - return allocated; - } else { - ai->last_block_size = UPB_MIN(block->size, UINT32_MAX); - ai->size_hint = ai->last_block_size; - _upb_Arena_UseBlock(a, block); - UPB_ASSERT(UPB_PRIVATE(_upb_ArenaHas)(a) >= size); - return upb_Arena_Malloc(a, size - UPB_PRIVATE(kUpb_Asan_GuardSize)); - } -} - -static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc, size_t first_size) { - const size_t first_block_overhead = - UPB_ALIGN_MALLOC(kUpb_MemblockReserve + sizeof(upb_ArenaState)); - upb_ArenaState* a; - - if (!alloc) return NULL; - - // We need to malloc the initial block. - size_t block_size = - first_block_overhead + UPB_MAX(256, UPB_ALIGN_MALLOC(first_size) + - UPB_PRIVATE(kUpb_Asan_GuardSize)); - upb_MemBlock* block = _upb_Arena_AllocBlockInternal(alloc, block_size); - if (!block) return NULL; - - // Initialize the arena state in the first block. We "borrow" the memory from - // the block, because we can't yet call upb_Arena_Malloc. - a = UPB_PTR_AT(block, kUpb_MemblockReserve, upb_ArenaState); - a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); - a->body.last_block_size = UPB_MIN(block->size, UINT32_MAX); - a->body.size_hint = UPB_MIN(block->size, UINT32_MAX); - upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->body.next, NULL); - upb_Atomic_Init(&a->body.previous_or_tail, - _upb_Arena_TaggedFromTail(&a->body)); - upb_Atomic_Init(&a->body.space_allocated, 0); - a->body.blocks = NULL; -#ifndef NDEBUG - a->body.refs = NULL; -#endif - a->body.upb_alloc_cleanup = NULL; - UPB_PRIVATE(upb_Xsan_Init)(UPB_XSAN(&a->body)); - - _upb_Arena_AddBlock(&a->head, block); - _upb_Arena_UseBlockInternal(&a->head, block, - UPB_ALIGN_MALLOC(sizeof(upb_ArenaState))); - - return &a->head; -} - -upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - UPB_STATIC_ASSERT(UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState), - "Need to update UPB_ARENA_SIZE_HACK"); - upb_ArenaState* a; - - if (mem) { - /* Align initial pointer up so that we return properly-aligned pointers. */ - void* aligned = (void*)UPB_ALIGN_MALLOC((uintptr_t)mem); - size_t delta = (uintptr_t)aligned - (uintptr_t)mem; - n = delta <= n ? n - delta : 0; - mem = aligned; - } - if (UPB_UNLIKELY(n < sizeof(upb_ArenaState) || !mem)) { - upb_Arena* ret = _upb_Arena_InitSlow(alloc, mem ? 0 : n); -#ifdef UPB_TRACING_ENABLED - upb_Arena_LogInit(ret, n); -#endif - return ret; - } - - a = mem; - - upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->body.next, NULL); - upb_Atomic_Init(&a->body.previous_or_tail, - _upb_Arena_TaggedFromTail(&a->body)); - upb_Atomic_Init(&a->body.space_allocated, 0); - a->body.blocks = NULL; -#ifndef NDEBUG - a->body.refs = NULL; -#endif - a->body.size_hint = 128; - a->body.last_block_size = 128; - a->body.upb_alloc_cleanup = NULL; - a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); - a->head.UPB_PRIVATE(ptr) = (void*)UPB_ALIGN_MALLOC((uintptr_t)(a + 1)); - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n, char); - UPB_PRIVATE(upb_Xsan_Init)(UPB_XSAN(&a->body)); -#ifdef UPB_TRACING_ENABLED - upb_Arena_LogInit(&a->head, n); -#endif - return &a->head; -} - -static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { - UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); - while (ai != NULL) { - UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(ai)); - // Load first since arena itself is likely from one of its blocks. Relaxed - // order is safe because fused arena ordering is provided by the reference - // count, and fuse is not permitted to race with the final decrement. - upb_ArenaInternal* next_arena = - (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_relaxed); - // Freeing may have memory barriers that confuse tsan, so assert immediately - // after load here - if (next_arena) { - UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(next_arena)); - } - upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); - upb_MemBlock* block = ai->blocks; - upb_AllocCleanupFunc* alloc_cleanup = *ai->upb_alloc_cleanup; - while (block != NULL) { - // Load first since we are deleting block. - upb_MemBlock* next_block = block->next; - if (block->size == 0) { - // If the block is an arena ref, then we need to release our ref on the - // referenced arena. - upb_ArenaRef* ref = (upb_ArenaRef*)block; - upb_Arena_DecRefFor((upb_Arena*)ref->arena, ai); - } else { - upb_free_sized(block_alloc, block, block->size); - } - block = next_block; - } - if (alloc_cleanup != NULL) { - alloc_cleanup(block_alloc); - } - ai = next_arena; - } -} - -void upb_Arena_Free(upb_Arena* a) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - // Cannot be replaced with _upb_Arena_FindRoot, as that provides only a - // relaxed read of the refcount if ai is already the root. - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); -retry: - while (_upb_Arena_IsTaggedPointer(poc)) { - ai = _upb_Arena_PointerFromTagged(poc); - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(ai)); - poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - } - - // compare_exchange or fetch_sub are RMW operations, which are more - // expensive then direct loads. As an optimization, we only do RMW ops - // when we need to update things for other threads to see. - if (poc == _upb_Arena_TaggedFromRefcount(1)) { -#ifdef UPB_TRACING_ENABLED - upb_Arena_LogFree(a); -#endif - _upb_Arena_DoFree(ai); - return; - } - - if (upb_Atomic_CompareExchangeWeak( - &ai->parent_or_count, &poc, - _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), - memory_order_release, memory_order_acquire)) { - // We were >1 and we decremented it successfully, so we are done. - return; - } - - // We failed our update, so someone has done something, retry the whole - // process, but the failed exchange reloaded `poc` for us. - goto retry; -} - -// Logically performs the following operation, in a way that is safe against -// racing fuses: -// ret = TAIL(parent) -// ret->next = child -// return ret -// -// The caller is therefore guaranteed that ret->next == child. -static upb_ArenaInternal* _upb_Arena_LinkForward( - upb_ArenaInternal* const parent, upb_ArenaInternal* child) { - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(parent)); - uintptr_t parent_previous_or_tail = - upb_Atomic_Load(&parent->previous_or_tail, memory_order_acquire); - - // Optimization: use parent->previous_or_tail to skip to TAIL(parent) in O(1) - // time when possible. This is the common case because we just fused into - // parent, suggesting that it should be a root with a cached tail. - // - // However, if there was a racing fuse, parent may no longer be a root, in - // which case we need to walk the entire list to find the tail. The tail - // pointer is also not guaranteed to be the true tail, so even when the - // optimization is taken, we still need to walk list nodes to find the true - // tail. - upb_ArenaInternal* parent_tail = - _upb_Arena_IsTaggedTail(parent_previous_or_tail) - ? _upb_Arena_TailFromTagged(parent_previous_or_tail) - : parent; - - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(parent_tail)); - upb_ArenaInternal* parent_tail_next = - upb_Atomic_Load(&parent_tail->next, memory_order_acquire); - - do { - // Walk the list to find the true tail (a node with next == NULL). - while (parent_tail_next != NULL) { - parent_tail = parent_tail_next; - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(parent_tail)); - parent_tail_next = - upb_Atomic_Load(&parent_tail->next, memory_order_acquire); - } - } while (!upb_Atomic_CompareExchangeWeak( // Replace a NULL next with child. - &parent_tail->next, &parent_tail_next, child, memory_order_release, - memory_order_acquire)); - - return parent_tail; -} - -// Updates parent->previous_or_tail = child->previous_or_tail in hopes that the -// latter represents the true tail of the newly-combined list. -// -// This is a best-effort operation that may set the tail to a stale value, and -// may fail to update the tail at all. -void _upb_Arena_UpdateParentTail(upb_ArenaInternal* parent, - upb_ArenaInternal* child) { - // We are guaranteed that child->previous_or_tail is tagged, because we have - // just transitioned child from root -> non-root, which is an exclusive - // operation that can only happen once. So we are the exclusive updater of - // child->previous_or_tail that can transition it from tagged to untagged. - // - // However, we are not guaranteed that child->previous_or_tail is the true - // tail. A racing fuse may have appended to child's list but not yet updated - // child->previous_or_tail. - uintptr_t child_previous_or_tail = - upb_Atomic_Load(&child->previous_or_tail, memory_order_acquire); - upb_ArenaInternal* new_parent_tail = - _upb_Arena_TailFromTagged(child_previous_or_tail); - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(new_parent_tail)); - - // If another thread fused with parent, such that it is no longer a root, - // don't overwrite their previous pointer with our tail. Relaxed order is fine - // here as we only inspect the tag bit. - uintptr_t parent_previous_or_tail = - upb_Atomic_Load(&parent->previous_or_tail, memory_order_relaxed); - if (_upb_Arena_IsTaggedTail(parent_previous_or_tail)) { - upb_Atomic_CompareExchangeStrong( - &parent->previous_or_tail, &parent_previous_or_tail, - _upb_Arena_TaggedFromTail(new_parent_tail), memory_order_release, - memory_order_relaxed); - } -} - -static void _upb_Arena_LinkBackward(upb_ArenaInternal* child, - upb_ArenaInternal* old_parent_tail) { - // Link child to parent going backwards, for SpaceAllocated. This transitions - // child->previous_or_tail from tail (tagged) to previous (untagged), after - // which its value is immutable. - // - // - We are guaranteed that no other threads are also attempting to perform - // this transition (tail -> previous), because we just updated - // old_parent_tail->next from NULL to non-NULL, an exclusive operation that - // can only happen once. - // - // - _upb_Arena_UpdateParentTail() uses CAS to ensure that it - // does not perform the reverse transition (previous -> tail). - // - // - We are guaranteed that old_parent_tail is the correct "previous" pointer, - // even in the presence of racing fuses that are adding more nodes to the - // list, because _upb_Arena_LinkForward() guarantees that: - // old_parent_tail->next == child. - upb_Atomic_Store(&child->previous_or_tail, - _upb_Arena_TaggedFromPrevious(old_parent_tail), - memory_order_release); -} - -static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, - upb_ArenaInternal* child) { - upb_ArenaInternal* old_parent_tail = _upb_Arena_LinkForward(parent, child); - _upb_Arena_UpdateParentTail(parent, child); - _upb_Arena_LinkBackward(child, old_parent_tail); -} - -void upb_Arena_SetAllocCleanup(upb_Arena* a, upb_AllocCleanupFunc* func) { - UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a)); - upb_ArenaInternal* ai = upb_Arena_Internal(a); - UPB_ASSERT(ai->upb_alloc_cleanup == NULL); - ai->upb_alloc_cleanup = func; -} - -// Thread safe. -static upb_ArenaInternal* _upb_Arena_DoFuse(upb_ArenaInternal** ai1, - upb_ArenaInternal** ai2, - uintptr_t* ref_delta) { - // `parent_or_count` has two distinct modes - // - parent pointer mode - // - refcount mode - // - // In parent pointer mode, it may change what pointer it refers to in the - // tree, but it will always approach a root. Any operation that walks the - // tree to the root may collapse levels of the tree concurrently. - upb_ArenaRoot r1 = _upb_Arena_FindRoot(*ai1); - upb_ArenaRoot r2 = _upb_Arena_FindRoot(*ai2); - - if (r1.root == r2.root) return r1.root; // Already fused. - - *ai1 = r1.root; - *ai2 = r2.root; - - // Avoid cycles by always fusing into the root with the lower address. - if ((uintptr_t)r1.root > (uintptr_t)r2.root) { - upb_ArenaRoot tmp = r1; - r1 = r2; - r2 = tmp; - } - - // The moment we install `r1` as the parent for `r2` all racing frees may - // immediately begin decrementing `r1`'s refcount (including pending - // increments to that refcount and their frees!). We need to add `r2`'s refs - // now, so that `r1` can withstand any unrefs that come from r2. - // - // Note that while it is possible for `r2`'s refcount to increase - // asynchronously, we will not actually do the reparenting operation below - // unless `r2`'s refcount is unchanged from when we read it. - // - // Note that we may have done this previously, either to this node or a - // different node, during a previous and failed DoFuse() attempt. But we will - // not lose track of these refs because we always add them to our overall - // delta. - uintptr_t r2_untagged_count = r2.tagged_count & ~1; - uintptr_t with_r2_refs = r1.tagged_count + r2_untagged_count; - if (!upb_Atomic_CompareExchangeStrong( - &r1.root->parent_or_count, &r1.tagged_count, with_r2_refs, - memory_order_release, memory_order_acquire)) { - return NULL; - } - - // Perform the actual fuse by removing the refs from `r2` and swapping in the - // parent pointer. - if (!upb_Atomic_CompareExchangeStrong( - &r2.root->parent_or_count, &r2.tagged_count, - _upb_Arena_TaggedFromPointer(r1.root), memory_order_release, - memory_order_acquire)) { - // We'll need to remove the excess refs we added to r1 previously. - *ref_delta += r2_untagged_count; - return NULL; - } - - // Now that the fuse has been performed (and can no longer fail) we need to - // append `r2` to `r1`'s linked list. - _upb_Arena_DoFuseArenaLists(r1.root, r2.root); - return r1.root; -} - -// Thread safe. -static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, - uintptr_t ref_delta) { - if (ref_delta == 0) return true; // No fixup required. - // Relaxed order is safe here as if the value is a pointer, we don't deref it - // or publish it anywhere else. The refcount does provide memory order - // between allocations on arenas and the eventual free and thus normally - // requires acquire/release; but in this case any edges provided by the refs - // we are cleaning up were already provided by the fuse operation itself. It's - // not valid for a decrement that could cause the overall fused arena to reach - // a zero refcount to race with this function, as that could result in a - // use-after-free anyway. - uintptr_t poc = - upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); - if (_upb_Arena_IsTaggedPointer(poc)) return false; - uintptr_t with_refs = poc - ref_delta; - UPB_ASSERT(!_upb_Arena_IsTaggedPointer(with_refs)); - // Relaxed order on success is safe here, for the same reasons as the relaxed - // read above. Relaxed order is safe on failure because the updated value is - // stored in a local variable which goes immediately out of scope; the retry - // loop will reread what it needs with proper memory order. - return upb_Atomic_CompareExchangeStrong(&new_root->parent_or_count, &poc, - with_refs, memory_order_relaxed, - memory_order_relaxed); -} - -bool upb_Arena_Fuse(const upb_Arena* a1, const upb_Arena* a2) { - if (a1 == a2) return true; // trivial fuse - -#ifdef UPB_TRACING_ENABLED - upb_Arena_LogFuse(a1, a2); -#endif - - upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); - upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); - - // Do not fuse initial blocks since we cannot lifetime extend them. - // Any other fuse scenario is allowed. - if (_upb_ArenaInternal_HasInitialBlock(ai1) || - _upb_ArenaInternal_HasInitialBlock(ai2)) { - return false; - } - - // The number of refs we ultimately need to transfer to the new root. - uintptr_t ref_delta = 0; - while (true) { - upb_ArenaInternal* new_root = _upb_Arena_DoFuse(&ai1, &ai2, &ref_delta); - if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { -#if UPB_ENABLE_REF_CYCLE_CHECKS - UPB_ASSERT(!upb_Arena_HasRefChain(a1, a2)); -#endif - return true; - } - } -} - -bool upb_Arena_IsFused(const upb_Arena* a, const upb_Arena* b) { - if (a == b) return true; // trivial fuse - upb_ArenaInternal* ra = _upb_Arena_FindRoot(upb_Arena_Internal(a)).root; - upb_ArenaInternal* rb = upb_Arena_Internal(b); - while (true) { - rb = _upb_Arena_FindRoot(rb).root; - if (ra == rb) return true; - upb_ArenaInternal* tmp = _upb_Arena_FindRoot(ra).root; - if (ra == tmp) return false; - // a's root changed since we last checked. Retry. - ra = tmp; - } -} - -bool upb_Arena_IncRefFor(const upb_Arena* a, const void* owner) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; - upb_ArenaRoot r; - r.root = ai; - -retry: - r = _upb_Arena_FindRoot(r.root); - if (upb_Atomic_CompareExchangeWeak( - &r.root->parent_or_count, &r.tagged_count, - _upb_Arena_TaggedFromRefcount( - _upb_Arena_RefCountFromTagged(r.tagged_count) + 1), - // Relaxed order is safe on success, incrementing the refcount - // need not perform any synchronization with the eventual free of the - // arena - that's provided by decrements. - memory_order_relaxed, - // Relaxed order is safe on failure as r.tagged_count is immediately - // overwritten by retrying the find root operation. - memory_order_relaxed)) { - // We incremented it successfully, so we are done. - return true; - } - // We failed update due to parent switching on the arena. - goto retry; -} - -void upb_Arena_DecRefFor(const upb_Arena* a, const void* owner) { - upb_Arena_Free((upb_Arena*)a); -} - -bool upb_Arena_RefArena(upb_Arena* from, const upb_Arena* to) { - UPB_ASSERT(!upb_Arena_IsFused(from, to)); - if (_upb_ArenaInternal_HasInitialBlock(upb_Arena_Internal(to))) { - // We can't increment a ref to `to`, so return early. - return false; - } - - upb_ArenaInternal* ai = upb_Arena_Internal(from); - upb_ArenaRef* ref = upb_Arena_Malloc(from, kUpb_ArenaRefReserve); - - if (!ref) { - return false; - } - - // When 'from' is freed, a ref on 'to' will be released. - // Intentionally ignore return value, since we already check up above if this - // call will succeed. - bool result = upb_Arena_IncRefFor(to, from); - UPB_ASSERT(result); - - // When we add a reference from `from` to `to`, we need to keep track of the - // ref in the `from` arena's linked list of refs. This allows us to - // walk all refs for `from` when `from` is freed, and thus allows us to - // decrement the refcount on `to` when `from` is freed. - ref->prefix.next = ai->blocks; - ref->prefix.size = 0; - ref->arena = to; - ai->blocks = (upb_MemBlock*)ref; - -#ifndef NDEBUG - // Add to the dedicated list of refs. - // This function is not thread-safe from `from`, so a simple load/store is - // sufficient. - ref->next_ref = upb_Atomic_Load(&ai->refs, memory_order_relaxed); - upb_Atomic_Store(&ai->refs, ref, memory_order_release); -#endif - -#if UPB_ENABLE_REF_CYCLE_CHECKS - UPB_ASSERT(!upb_Arena_HasRefChain(to, from)); // Forbid cycles. -#endif - - return true; -} - -#ifndef NDEBUG -bool upb_Arena_HasRef(const upb_Arena* from, const upb_Arena* to) { - const upb_ArenaInternal* ai = upb_Arena_Internal(from); - const upb_ArenaRef* ref = upb_Atomic_Load(&ai->refs, memory_order_acquire); - while (ref != NULL) { - if (upb_Arena_IsFused(ref->arena, to)) { - return true; - } - ref = ref->next_ref; - } - return false; -} -#endif - -upb_alloc* upb_Arena_GetUpbAlloc(upb_Arena* a) { - UPB_PRIVATE(upb_Xsan_AccessReadOnly)(UPB_XSAN(a)); - upb_ArenaInternal* ai = upb_Arena_Internal(a); - return _upb_ArenaInternal_BlockAlloc(ai); -} - -void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { - memcpy(des, src, offsetof(upb_ArenaState, body.space_allocated)); - upb_ArenaInternal* desi = upb_Arena_Internal(des); - upb_ArenaInternal* srci = upb_Arena_Internal(src); - uintptr_t new_space_allocated = - upb_Atomic_Load(&srci->space_allocated, memory_order_relaxed); - upb_Atomic_Store(&desi->space_allocated, new_space_allocated, - memory_order_relaxed); -} - -void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { - UPB_PRIVATE(_upb_Arena_SwapIn)(des, src); -} - -bool _upb_Arena_WasLastAlloc(struct upb_Arena* a, void* ptr, size_t oldsize) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - upb_MemBlock* block = ai->blocks; - // Skip any arena refs. - while (block != NULL && block->size == 0) { - block = block->next; - } - if (block == NULL) return false; - char* start = UPB_PTR_AT(block, kUpb_MemblockReserve, char); - return UPB_PRIVATE(upb_Xsan_PtrEq)(ptr, start) && - UPB_PRIVATE(_upb_Arena_AllocSpan)(oldsize) == - block->size - kUpb_MemblockReserve; -} diff --git a/vendor/upb/mem/arena.h b/vendor/upb/mem/arena.h deleted file mode 100644 index 5a9377b..0000000 --- a/vendor/upb/mem/arena.h +++ /dev/null @@ -1,198 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* upb_Arena is a specific allocator implementation that uses arena allocation. - * The user provides an allocator that will be used to allocate the underlying - * arena blocks. Arenas by nature do not require the individual allocations - * to be freed. However the Arena does allow users to register cleanup - * functions that will run when the arena is destroyed. - * - * A upb_Arena is *not* thread-safe, although some functions related to its - * managing its lifetime are, and are documented as such. - * - * You could write a thread-safe arena allocator that satisfies the - * upb_alloc interface, but it would not be as efficient for the - * single-threaded case. */ - -#ifndef UPB_MEM_ARENA_H_ -#define UPB_MEM_ARENA_H_ - -#include -#include - -#include "upb/mem/alloc.h" -#include "upb/mem/internal/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_Arena upb_Arena; - -typedef void upb_AllocCleanupFunc(upb_alloc* alloc); - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates an arena from the given initial block (if any -- mem may be NULL). If -// an initial block is specified, the arena's lifetime cannot be extended by -// |upb_Arena_IncRefFor| or |upb_Arena_Fuse|. Additional blocks will be -// allocated from |alloc|. If |alloc| is NULL, this is a fixed-size arena and -// cannot grow. If an initial block is specified, |n| is its length; if there is -// no initial block, |n| is a hint of the size that should be allocated for the -// first block of the arena, such that `upb_Arena_Malloc(hint)` will not require -// another call to |alloc|. -UPB_NODISCARD UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, - upb_alloc* alloc); - -UPB_API void upb_Arena_Free(upb_Arena* a); -// Sets the cleanup function for the upb_alloc used by the arena. Only one -// cleanup function can be set, which will be called after all blocks are -// freed. -UPB_API void upb_Arena_SetAllocCleanup(upb_Arena* a, - upb_AllocCleanupFunc* func); - -// Fuses the lifetime of two arenas, such that no arenas that have been -// transitively fused together will be freed until all of them have reached a -// zero refcount. This operation is safe to use concurrently from multiple -// threads. -UPB_NODISCARD UPB_API bool upb_Arena_Fuse(const upb_Arena* a, - const upb_Arena* b); - -// This operation is safe to use concurrently from multiple threads. -UPB_API bool upb_Arena_IsFused(const upb_Arena* a, const upb_Arena* b); - -// Returns the upb_alloc used by the arena. -UPB_API upb_alloc* upb_Arena_GetUpbAlloc(upb_Arena* a); - -// This operation is safe to use concurrently from multiple threads. -bool upb_Arena_IncRefFor(const upb_Arena* a, const void* owner); -// This operation is safe to use concurrently from multiple threads. -void upb_Arena_DecRefFor(const upb_Arena* a, const void* owner); - -// Creates a reference between the arenas `from` and `to`, guaranteeing that -// the latter will not be freed until `from` is freed. -// -// Users must avoid all of the following error conditions, which will be -// checked in debug mode but are UB in opt: -// -// - Creating reference cycles between arenas. -// - Creating a reference between two arenas that are fused, either now -// or in the future. -// -// Creating a reference multiple times between the same two arenas is not UB but -// is considered wasteful and may be disallowed in the future. -// -// Note that fuses can participate in reference cycles. The following set of -// calls creates a cycle A -> B -> C -> A -// Fuse(A, B); -// Ref(B, C); -// Ref(C, A); -// -// From this perspective, the second rule is just a special-case of the first. -// This set of calls is disallowed because it is effectively creating a -// cycle A -> B -> A -// Fuse(A, B); -// Ref(B, A); -// -// Fuse is special because it creates what is effectively a bidirectional -// ref, but it is not considered a cycle and will be collected correctly. -// -// Note that `from` is not `const`, so it may not be called concurrently -// with any other function on `from`. -// -// Returns whether the reference was created successfully. -UPB_NODISCARD bool upb_Arena_RefArena(upb_Arena* from, const upb_Arena* to); - -#ifndef NDEBUG -// Returns true if upb_Arena_RefArena(from, to) was previously called. -// Note that this does not take fuses into account, and it does not follow -// chains of references; it must have been these two arenas exactly that -// created a reference. -bool upb_Arena_HasRef(const upb_Arena* from, const upb_Arena* to); -#endif - -// This operation is safe to use concurrently from multiple threads. -uintptr_t upb_Arena_SpaceAllocated(const upb_Arena* a, size_t* fused_count); -// This operation is safe to use concurrently from multiple threads. -uint32_t upb_Arena_DebugRefCount(const upb_Arena* a); - -#if UPB_ENABLE_REF_CYCLE_CHECKS -// Returns true if there is a chain of arena refs that spans `from` -> `to`. -// Fused arenas are taken into account; for example, this series of calls -// will cause the function to return true: -// -// 1. upb_Arena_Fuse(a, b) -// 2. upb_Arena_RefArena(from, a) -// 3. upb_Arena_RefArena(b, to) -// -// However this function does not return true if `from` and `to` are directly -// fused. -bool upb_Arena_HasRefChain(const upb_Arena* from, const upb_Arena* to); -#endif - -UPB_NODISCARD UPB_API_INLINE upb_Arena* upb_Arena_New(void) { - return upb_Arena_Init(NULL, 0, &upb_alloc_global); -} - -UPB_NODISCARD UPB_API_INLINE upb_Arena* upb_Arena_NewSized(size_t size_hint) { - return upb_Arena_Init(NULL, size_hint, &upb_alloc_global); -} - -UPB_NODISCARD UPB_API_INLINE void* upb_Arena_Malloc(struct upb_Arena* a, - size_t size); - -UPB_NODISCARD UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, - size_t oldsize, - size_t size); - -static const size_t UPB_PRIVATE(kUpbDefaultMaxBlockSize) = - UPB_DEFAULT_MAX_BLOCK_SIZE; - -// Sets the maximum block size for all arenas. This is a global configuration -// setting that will affect all existing and future arenas. If -// upb_Arena_Malloc() is called with a size larger than this, we will exceed -// this size and allocate a larger block. -// -// This API is meant for experimentation only. It will likely be removed in -// the future. -// This operation is safe to use concurrently from multiple threads. -void upb_Arena_SetMaxBlockSize(size_t max); - -// Shrinks the last alloc from arena. -// REQUIRES: (ptr, oldsize) was the last malloc/realloc from this arena. -// We could also add a upb_Arena_TryShrinkLast() which is simply a no-op if -// this was not the last alloc. -UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, - size_t oldsize, size_t size); - -// Attempts to extend the given alloc from arena, in place. Is generally -// only likely to succeed for the most recent allocation from this arena. If it -// succeeds, returns true and `ptr`'s allocation is now `size` rather than -// `oldsize`. Returns false if the allocation cannot be extended; `ptr`'s -// allocation is unmodified. See also upb_Arena_Realloc. -// REQUIRES: `size > oldsize`; to shrink, use `upb_Arena_Realloc` or -// `upb_Arena_ShrinkLast`. -UPB_NODISCARD UPB_API_INLINE bool upb_Arena_TryExtend(upb_Arena* a, void* ptr, - size_t oldsize, - size_t size); - -#ifdef UPB_TRACING_ENABLED -void upb_Arena_SetTraceHandler(void (*initArenaTraceHandler)(const upb_Arena*, - size_t size), - void (*fuseArenaTraceHandler)(const upb_Arena*, - const upb_Arena*), - void (*freeArenaTraceHandler)(const upb_Arena*)); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MEM_ARENA_H_ */ diff --git a/vendor/upb/mem/arena.hpp b/vendor/upb/mem/arena.hpp deleted file mode 100644 index 27c062c..0000000 --- a/vendor/upb/mem/arena.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MEM_ARENA_HPP_ -#define UPB_MEM_ARENA_HPP_ - -#include "upb/mem/alloc.h" -#ifdef __cplusplus - -#include -#include - -#include "upb/mem/arena.h" - -namespace upb { - -class Arena { - public: - // A simple arena with no initial memory block and the default allocator. - Arena() : ptr_(upb_Arena_New(), upb_Arena_Free) {} - Arena(char* initial_block, size_t size) - : ptr_(upb_Arena_Init(initial_block, size, &upb_alloc_global), - upb_Arena_Free) {} - explicit Arena(size_t size) - : ptr_(upb_Arena_NewSized(size), upb_Arena_Free) {} - - upb_Arena* ptr() const { return ptr_.get(); } - - // Fuses the arenas together. - // This operation can only be performed on arenas with no initial blocks. Will - // return false if the fuse failed due to either arena having an initial - // block. - bool Fuse(Arena& other) { return upb_Arena_Fuse(ptr(), other.ptr()); } - - bool IsFused(Arena& other) const { - return upb_Arena_IsFused(ptr(), other.ptr()); - } - - void RefArena(const Arena& to) { upb_Arena_RefArena(ptr(), to.ptr()); } - - protected: - std::unique_ptr ptr_; -}; -} // namespace upb - -#endif // __cplusplus - -#endif // UPB_MEM_ARENA_HPP_ diff --git a/vendor/upb/mem/arena_test.cc b/vendor/upb/mem/arena_test.cc deleted file mode 100644 index c56f052..0000000 --- a/vendor/upb/mem/arena_test.cc +++ /dev/null @@ -1,1013 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mem/arena.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "absl/base/thread_annotations.h" -#include "absl/cleanup/cleanup.h" -#include "absl/container/flat_hash_map.h" -#include "absl/random/distributions.h" -#include "absl/random/random.h" -#include "absl/synchronization/mutex.h" -#include "absl/synchronization/notification.h" -#include "absl/time/clock.h" -#include "absl/time/time.h" -#include "upb/mem/alloc.h" -#include "upb/mem/arena.hpp" -#include "upb/port/sanitizers.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace { - -struct CustomAlloc { - upb_alloc alloc; - int counter; - bool ran_cleanup; -}; - -void* CustomAllocFunc(upb_alloc* alloc, void* ptr, size_t oldsize, size_t size, - size_t* actual_size) { - CustomAlloc* custom_alloc = reinterpret_cast(alloc); - if (size == 0) { - custom_alloc->counter--; - } else { - custom_alloc->counter++; - } - return upb_alloc_global.func(alloc, ptr, oldsize, size, actual_size); -} - -void CustomAllocCleanup(upb_alloc* alloc) { - CustomAlloc* custom_alloc = reinterpret_cast(alloc); - EXPECT_THAT(custom_alloc->counter, 0); - custom_alloc->ran_cleanup = true; -} - -TEST(ArenaTest, ArenaWithAllocCleanup) { - CustomAlloc alloc = {{&CustomAllocFunc}, 0, false}; - upb_Arena* arena = - upb_Arena_Init(nullptr, 0, reinterpret_cast(&alloc)); - EXPECT_EQ(alloc.counter, 1); - upb_Arena_SetAllocCleanup(arena, CustomAllocCleanup); - upb_Arena_Free(arena); - EXPECT_TRUE(alloc.ran_cleanup); -} - -struct Size { - size_t requested; - size_t allocated; -}; - -struct SizeTracker { - upb_alloc alloc; - upb_alloc* delegate_alloc; - absl::flat_hash_map* sizes; -}; - -static_assert(std::is_standard_layout()); - -static void* size_checking_allocfunc(upb_alloc* alloc, void* ptr, - size_t oldsize, size_t size, - size_t* actual_size) { - SizeTracker* size_alloc = reinterpret_cast(alloc); - size_t actual_size_tmp = 0; - if (actual_size == nullptr) { - actual_size = &actual_size_tmp; - } - void* result = - size_alloc->delegate_alloc->func(alloc, ptr, oldsize, size, actual_size); - if (ptr != nullptr) { - Size& size_ref = size_alloc->sizes->at(ptr); - UPB_ASSERT(size_ref.requested == oldsize || size_ref.allocated == oldsize); - size_alloc->sizes->erase(ptr); - } - if (result != nullptr) { - size_alloc->sizes->emplace(result, Size{size, UPB_MAX(size, *actual_size)}); - } - return result; -} - -TEST(ArenaTest, ShinkLastAfterReallocHwasanRegression) { - upb_Arena_SetMaxBlockSize(UPB_MALLOC_ALIGN); - absl::Cleanup reset_max_block_size = [] { - upb_Arena_SetMaxBlockSize(UPB_PRIVATE(kUpbDefaultMaxBlockSize)); - }; - - upb_Arena* arena = upb_Arena_Init(nullptr, 1000, &upb_alloc_global); - (void)upb_Arena_Malloc(arena, 1); - // Will force a full-size block since the initial allocated block has tons of - // free space and the max block size is tiny - void* to_realloc = upb_Arena_Malloc(arena, 2000); - // Realloc will retag to invalidate to_realloc - void* to_shrink = upb_Arena_Realloc(arena, to_realloc, 2000, 2000); -#if UPB_HWASAN - EXPECT_NE(to_realloc, to_shrink); -#endif - upb_Arena_ShrinkLast(arena, to_shrink, 2000, 1); - upb_Arena_Free(arena); -} - -TEST(ArenaTest, SizedFree) { - absl::flat_hash_map sizes; - SizeTracker alloc; - alloc.alloc.func = size_checking_allocfunc; - alloc.delegate_alloc = &upb_alloc_global; - alloc.sizes = &sizes; - - char initial_block[1000]; - - upb_Arena* arena = upb_Arena_Init(initial_block, 1000, &alloc.alloc); - (void)upb_Arena_Malloc(arena, 500); - void* to_resize = upb_Arena_Malloc(arena, 2000); - void* resized = upb_Arena_Realloc(arena, to_resize, 2000, 4000); - upb_Arena_ShrinkLast(arena, resized, 4000, 1); - EXPECT_GT(sizes.size(), 0); - upb_Arena_Free(arena); - EXPECT_EQ(sizes.size(), 0); -} - -TEST(ArenaTest, TryExtend) { - upb_Arena* arena = upb_Arena_Init(nullptr, 1024, &upb_alloc_global); - void* alloc = upb_Arena_Malloc(arena, 512); - ASSERT_TRUE(upb_Arena_TryExtend(arena, alloc, 512, 700)); - ASSERT_TRUE(upb_Arena_TryExtend(arena, alloc, 700, 750)); - // If no room in block, should return false - ASSERT_FALSE(upb_Arena_TryExtend(arena, alloc, 750, 10000)); - (void)upb_Arena_Malloc(arena, 1); - // Can't extend past a previous alloc - ASSERT_FALSE(upb_Arena_TryExtend(arena, alloc, 750, 900)); - upb_Arena_Free(arena); -} - -TEST(ArenaTest, ReallocFastPath) { - upb_Arena* arena = upb_Arena_Init(nullptr, 1024, &upb_alloc_global); - void* initial = upb_Arena_Malloc(arena, 512); - uintptr_t initial_allocated = upb_Arena_SpaceAllocated(arena, nullptr); - - void* extend = upb_Arena_Realloc(arena, initial, 512, 1024); - EXPECT_EQ(initial_allocated, upb_Arena_SpaceAllocated(arena, nullptr)); -#if UPB_HWASAN - EXPECT_TRUE(UPB_PRIVATE(upb_Xsan_PtrEq)(initial, extend)); - EXPECT_NE(initial, extend); -#else - EXPECT_EQ(initial, extend); -#endif - - void* shrunk = upb_Arena_Realloc(arena, extend, 1024, 512); - EXPECT_EQ(initial_allocated, upb_Arena_SpaceAllocated(arena, nullptr)); -#if UPB_HWASAN - EXPECT_TRUE(UPB_PRIVATE(upb_Xsan_PtrEq)(initial, shrunk)); - EXPECT_NE(initial, shrunk); - EXPECT_NE(extend, shrunk); -#else - EXPECT_EQ(initial, shrunk); -#endif - - EXPECT_NE(nullptr, upb_Arena_Malloc(arena, 256)); - // Should have allocated into shrunk space - EXPECT_EQ(initial_allocated, upb_Arena_SpaceAllocated(arena, nullptr)); - - upb_Arena_Free(arena); -} - -TEST(ArenaTest, SizeHint) { - absl::flat_hash_map sizes; - SizeTracker alloc; - alloc.alloc.func = size_checking_allocfunc; - alloc.delegate_alloc = &upb_alloc_global; - alloc.sizes = &sizes; - - upb_Arena* arena = upb_Arena_Init(nullptr, 2459, &alloc.alloc); - EXPECT_EQ(sizes.size(), 1); - EXPECT_NE(upb_Arena_Malloc(arena, 2459), nullptr); - EXPECT_EQ(sizes.size(), 1); - EXPECT_NE(upb_Arena_Malloc(arena, 500), nullptr); - EXPECT_EQ(sizes.size(), 2); - upb_Arena_Free(arena); - EXPECT_EQ(sizes.size(), 0); -} - -class OverheadTest { - public: - OverheadTest(const OverheadTest&) = delete; - OverheadTest& operator=(const OverheadTest&) = delete; - - explicit OverheadTest(size_t first = 0, size_t max_block_size = 0) { - if (max_block_size) { - upb_Arena_SetMaxBlockSize(max_block_size); - } - alloc_.alloc.func = size_checking_allocfunc; - alloc_.delegate_alloc = &upb_alloc_global; - alloc_.sizes = &sizes_; - arena_ = upb_Arena_Init(nullptr, first, &alloc_.alloc); - arena_alloced_ = 0; - arena_alloc_count_ = 0; - } - - void Alloc(size_t size) { - upb_Arena_Malloc(arena_, size); - arena_alloced_ += size; - arena_alloc_count_++; - } - - uintptr_t SpaceAllocated() { - return upb_Arena_SpaceAllocated(arena_, nullptr); - } - - double WastePct() { - uintptr_t backing_alloced = upb_Arena_SpaceAllocated(arena_, nullptr); - double waste = backing_alloced - arena_alloced_; - return waste / backing_alloced; - } - - double AmortizedAlloc() { - return ((double)sizes_.size()) / arena_alloc_count_; - } - - ~OverheadTest() { - upb_Arena_Free(arena_); - upb_Arena_SetMaxBlockSize(UPB_PRIVATE(kUpbDefaultMaxBlockSize)); - } - upb_Arena* arena_; - - protected: - absl::flat_hash_map sizes_; - SizeTracker alloc_; - uintptr_t arena_alloced_; - uintptr_t arena_alloc_count_; -}; - -TEST(OverheadTest, SingleMassiveBlockThenLittle) { - OverheadTest test; - // Little blocks - for (int i = 0; i < 4; i++) { - test.Alloc(32); - } - // Big block! - test.Alloc(16000); - for (int i = 0; i < 50; i++) { - test.Alloc(64); - } - if (!UPB_ASAN) { -#ifdef __ANDROID__ - EXPECT_NEAR(test.WastePct(), 0.075, 0.025); - EXPECT_NEAR(test.AmortizedAlloc(), 0.09, 0.025); -#else - EXPECT_NEAR(test.WastePct(), 0.08, 0.125); - EXPECT_NEAR(test.AmortizedAlloc(), 0.09, 0.025); -#endif - } -} - -TEST(OverheadTest, Overhead_AlternatingSmallLargeBlocks) { - OverheadTest test(512, 4096); - for (int i = 0; i < 100; i++) { - test.Alloc(5000); - test.Alloc(64); - } - if (!UPB_ASAN) { - EXPECT_NEAR(test.WastePct(), 0.007, 0.0025); - EXPECT_NEAR(test.AmortizedAlloc(), 0.52, 0.025); - } -} - -TEST(OverheadTest, PartialMaxBlocks) { - OverheadTest test(512, 4096); - for (int i = 0; i < 10; i++) { - test.Alloc(2096 + i); - } - if (!UPB_ASAN) { - EXPECT_NEAR(test.WastePct(), 0.16, 0.025); - EXPECT_NEAR(test.AmortizedAlloc(), 1.1, 0.25); - } -} - -TEST(OverheadTest, SmallBlocksLargerThanInitial) { - OverheadTest test; - size_t initial_block_size = upb_Arena_SpaceAllocated(test.arena_, nullptr); - for (int i = 0; i < 10; i++) { - test.Alloc(initial_block_size * 2 + 1); - } - if (!UPB_ASAN && sizeof(void*) == 8) { - EXPECT_NEAR(test.WastePct(), 0.37, 0.025); - EXPECT_NEAR(test.AmortizedAlloc(), 0.5, 0.025); - } -} - -TEST(OverheadTest, SmallBlocksLargerThanInitial_many) { - OverheadTest test; - size_t initial_block_size = upb_Arena_SpaceAllocated(test.arena_, nullptr); - for (int i = 0; i < 100; i++) { - test.Alloc(initial_block_size * 2 + 1); - } - if (!UPB_ASAN && sizeof(upb_Xsan) == 0) { -#ifdef __ANDROID__ - EXPECT_NEAR(test.WastePct(), 0.09, 0.025); - EXPECT_NEAR(test.AmortizedAlloc(), 0.12, 0.025); -#else - EXPECT_NEAR(test.WastePct(), 0.12, 0.03); - EXPECT_NEAR(test.AmortizedAlloc(), 0.08, 0.025); -#endif - } - for (int i = 0; i < 900; i++) { - test.Alloc(initial_block_size * 2 + 1); - } - if (!UPB_ASAN) { -#ifdef __ANDROID__ - EXPECT_NEAR(test.WastePct(), 0.05, 0.03); - EXPECT_NEAR(test.AmortizedAlloc(), 0.08, 0.025); -#else - EXPECT_NEAR(test.WastePct(), 0.04, 0.025); - EXPECT_NEAR(test.AmortizedAlloc(), 0.05, 0.025); -#endif - } -} - -TEST(OverheadTest, DefaultMaxBlockSize) { - OverheadTest test; - // Perform 600 1k allocations (600k total) and ensure that the amount of - // memory allocated does not exceed 700k. - for (int i = 0; i < 600; ++i) { - test.Alloc(1024); - } - EXPECT_LE(test.SpaceAllocated(), 700 * 1024); -} - -TEST(ArenaTest, ArenaFuse) { - upb_Arena* arena1 = upb_Arena_New(); - upb_Arena* arena2 = upb_Arena_New(); - - EXPECT_TRUE(upb_Arena_Fuse(arena1, arena2)); - - upb_Arena_Free(arena1); - upb_Arena_Free(arena2); -} - -TEST(ArenaTest, FuseWithInitialBlock) { - char buf1[1024]; - char buf2[1024]; - upb_Arena* arenas[] = {upb_Arena_Init(buf1, 1024, &upb_alloc_global), - upb_Arena_Init(buf2, 1024, &upb_alloc_global), - upb_Arena_Init(nullptr, 0, &upb_alloc_global)}; - int size = sizeof(arenas) / sizeof(arenas[0]); - for (int i = 0; i < size; ++i) { - for (int j = 0; j < size; ++j) { - if (i == j) { - // Fuse to self is always allowed. - EXPECT_TRUE(upb_Arena_Fuse(arenas[i], arenas[j])); - } else { - EXPECT_FALSE(upb_Arena_Fuse(arenas[i], arenas[j])); - } - } - } - - for (int i = 0; i < size; ++i) upb_Arena_Free(arenas[i]); -} - -class Environment { - public: - void RandomNewFree(absl::BitGen& gen, size_t min_index = 0) { - auto a = std::make_shared(); - SwapRandomArena(gen, a, min_index); - } - - void RandomIncRefCount(absl::BitGen& gen) { - std::shared_ptr a = RandomNonNullArena(gen); - upb_Arena_IncRefFor(a->ptr(), nullptr); - upb_Arena_DecRefFor(a->ptr(), nullptr); - } - - void RandomFuse(absl::BitGen& gen) { - std::shared_ptr a = RandomNonNullArena(gen); - std::shared_ptr b = RandomNonNullArena(gen); - EXPECT_TRUE(upb_Arena_Fuse(a->ptr(), b->ptr())); - } - - void RandomRefArena(absl::BitGen& gen) { - std::shared_ptr a = RandomNonNullArena(gen); - std::shared_ptr b = RandomNonNullArena(gen); - if (a->ptr() == b->ptr()) return; - if (a->ptr() > b->ptr()) std::swap(a, b); - EXPECT_TRUE(upb_Arena_RefArena(a->ptr(), b->ptr())); - } - -#ifndef NDEBUG - void PartitionedHasRef(absl::BitGen& gen) { - // Ensure refs like (0,2), (1,3), (2,4) ... (97,99). - auto [a, b] = GetArenaPairWithOffset(gen, 2); - (void)upb_Arena_HasRef(a->ptr(), b->ptr()); - } - - void PartitionedFuse(absl::BitGen& gen) { - // Ensure partitions like (0,1), (2,3), (4,5) ... (98,99). - auto [a, b] = GetArenaPairWithOffset(gen, 1); - EXPECT_TRUE(upb_Arena_Fuse(a->ptr(), b->ptr())); - } - - void PartitionedRefArena(absl::BitGen& gen) { - // Ensure refs like (0,2), (1,3), (2,4) ... (97,99). - auto [a, b] = GetArenaPairWithOffset(gen, 2); - if (a->ptr() > b->ptr()) std::swap(a, b); - EXPECT_TRUE(upb_Arena_RefArena(a->ptr(), b->ptr())); - } -#endif - - void RandomPoke(absl::BitGen& gen, size_t min_index = 0) { - switch (absl::Uniform(gen, 0, 2)) { - case 0: - RandomNewFree(gen, min_index); - break; - case 1: - RandomFuse(gen); - break; - default: - break; - } - } - - std::shared_ptr IndexedNonNullArena(size_t index) { - absl::MutexLock lock(&mutex_); - std::shared_ptr& ret = arenas_[index]; - if (!ret) ret = std::make_shared(); - return ret; - } - - private: - using ArenaArray = std::array, 100>; - - std::pair, - std::shared_ptr> - GetArenaPairWithOffset(absl::BitGen& gen, size_t offset) { - size_t index = RandomIndex(gen, 0, std::tuple_size::value - 1); - size_t a_index = index % 2 == 0 ? index : index + 1; - std::shared_ptr a = IndexedNonNullArena(a_index); - std::shared_ptr b = IndexedNonNullArena( - (a_index + offset) % std::tuple_size::value); - return {a, b}; - } - - size_t RandomIndex(absl::BitGen& gen, size_t min_index = 0, - size_t max_index = std::tuple_size::value) { - return absl::Uniform(gen, min_index, max_index); - } - - // Swaps a random arena from the set with the given arena. - void SwapRandomArena(absl::BitGen& gen, std::shared_ptr& a, - size_t min_index) { - size_t i = RandomIndex(gen, min_index); - absl::MutexLock lock(&mutex_); - arenas_[i].swap(a); - } - - // Returns a random arena from the set, ensuring that the returned arena is - // non-null. - // - // Note that the returned arena is shared and may be accessed concurrently - // by other threads. - std::shared_ptr RandomNonNullArena(absl::BitGen& gen) { - return IndexedNonNullArena(RandomIndex(gen)); - } - - ArenaArray arenas_ ABSL_GUARDED_BY(mutex_); - absl::Mutex mutex_; -}; - -TEST(ArenaTest, FuzzSingleThreaded) { - Environment env; - - absl::BitGen gen; - auto end = absl::Now() + absl::Seconds(0.5); - while (absl::Now() < end) { - env.RandomPoke(gen); - } -} - -TEST(ArenaTest, LargeAlloc) { - // Tests an allocation larger than the max block size. - upb_Arena* arena = upb_Arena_New(); - size_t size = 100000; - char* mem = static_cast(upb_Arena_Malloc(arena, size)); - EXPECT_NE(mem, nullptr); - for (size_t i = 0; i < size; ++i) { - mem[i] = static_cast(i); - } - for (size_t i = 0; i < size; ++i) { - EXPECT_EQ(mem[i], static_cast(i)); - } - upb_Arena_Free(arena); -} - -TEST(ArenaTest, MaxBlockSize) { - upb_Arena* arena = upb_Arena_New(); - // Perform 600 1k allocations (600k total) and ensure that the amount of - // memory allocated does not exceed 700k. - for (int i = 0; i < 600; ++i) { - upb_Arena_Malloc(arena, 1024); - } - EXPECT_LE(upb_Arena_SpaceAllocated(arena, nullptr), 700 * 1024); - upb_Arena_Free(arena); -} - -#ifndef UPB_SUPPRESS_MISSING_ATOMICS - -TEST(ArenaTest, FuzzFuseFreeRace) { - Environment env; - - absl::Notification done; - std::vector threads; - for (int i = 0; i < 10; ++i) { - threads.emplace_back([&]() { - absl::BitGen gen; - while (!done.HasBeenNotified()) { - env.RandomNewFree(gen); - } - }); - } - - absl::BitGen gen; - auto end = absl::Now() + absl::Seconds(2); - while (absl::Now() < end) { - env.RandomFuse(gen); - } - done.Notify(); - for (auto& t : threads) t.join(); -} - -TEST(ArenaTest, FuzzFuseFuseRace) { - Environment env; - - absl::Notification done; - std::vector threads; - for (int i = 0; i < 10; ++i) { - threads.emplace_back([&]() { - absl::BitGen gen; - while (!done.HasBeenNotified()) { - env.RandomFuse(gen); - } - }); - } - - absl::BitGen gen; - auto end = absl::Now() + absl::Seconds(2); - while (absl::Now() < end) { - env.RandomFuse(gen); - } - done.Notify(); - for (auto& t : threads) t.join(); -} - -static void* checking_global_allocfunc(upb_alloc* alloc, void* ptr, - size_t oldsize, size_t size, - size_t* actual_size) { - int header_size = std::max(alignof(max_align_t), sizeof(int)); - if (ptr) { - ptr = UPB_PTR_AT(ptr, -header_size, void); - UPB_ASSERT(*reinterpret_cast(ptr) == 0x5AFE); - } - if (size == 0) { - free(ptr); - return nullptr; - } - void* ret; - if (oldsize == 0) { - ret = malloc(size + header_size); - } else { - ret = realloc(ptr, size + header_size); - } - if (ret) { - *reinterpret_cast(ret) = 0x5AFE; - return UPB_PTR_AT(ret, header_size, void); - } - return ret; -} - -TEST(ArenaTest, FuzzFuseFreeAllocatorRace) { - upb_Arena_SetMaxBlockSize(128); - upb_alloc_func* old = upb_alloc_global.func; - upb_alloc_global.func = checking_global_allocfunc; - absl::Cleanup reset_max_block_size = [old] { - upb_Arena_SetMaxBlockSize(UPB_PRIVATE(kUpbDefaultMaxBlockSize)); - upb_alloc_global.func = old; - }; - absl::Notification done; - std::vector threads; - size_t thread_count = 10; - std::vector> arenas; - for (size_t i = 0; i < 10000; ++i) { - std::array arr; - arr[0] = upb_Arena_New(); - for (size_t j = 1; j < thread_count + 1; ++j) { - arr[j] = upb_Arena_New(); - upb_Arena_Fuse(arr[j - 1], arr[j]); - } - arenas.push_back(arr); - } - for (size_t i = 0; i < thread_count; ++i) { - size_t tid = i; - threads.emplace_back([&, tid]() { - size_t arenaCtr = 0; - while (!done.HasBeenNotified() && arenaCtr < arenas.size()) { - upb_Arena* read = arenas[arenaCtr++][tid]; - (void)upb_Arena_Malloc(read, 128); - (void)upb_Arena_Malloc(read, 128); - upb_Arena_Free(read); - } - while (arenaCtr < arenas.size()) { - upb_Arena_Free(arenas[arenaCtr++][tid]); - } - }); - } - auto end = absl::Now() + absl::Seconds(2); - size_t arenaCtr = 0; - while (absl::Now() < end && arenaCtr < arenas.size()) { - upb_Arena* read = arenas[arenaCtr++][thread_count]; - (void)upb_Arena_Malloc(read, 128); - (void)upb_Arena_Malloc(read, 128); - upb_Arena_Free(read); - } - done.Notify(); - while (arenaCtr < arenas.size()) { - upb_Arena_Free(arenas[arenaCtr++][thread_count]); - } - for (auto& t : threads) t.join(); -} - -TEST(ArenaTest, FuzzFuseSpaceAllocatedRace) { - upb_Arena_SetMaxBlockSize(128); - absl::Cleanup reset_max_block_size = [] { - upb_Arena_SetMaxBlockSize(UPB_PRIVATE(kUpbDefaultMaxBlockSize)); - }; - absl::Notification done; - std::vector threads; - std::vector arenas; - size_t thread_count = 10; - size_t fuses_per_thread = 1000; - size_t root_arenas_limit = 250; - for (size_t i = 0; i < root_arenas_limit; ++i) { - arenas.push_back(upb_Arena_New()); - for (size_t j = 0; j < thread_count; ++j) { - upb_Arena_IncRefFor(arenas[i], nullptr); - } - } - for (size_t i = 0; i < thread_count; ++i) { - threads.emplace_back([&]() { - size_t arenaCtr = 0; - while (!done.HasBeenNotified() && arenaCtr < arenas.size()) { - upb_Arena* read = arenas[arenaCtr++]; - for (size_t j = 0; j < fuses_per_thread; ++j) { - upb_Arena* fuse = upb_Arena_New(); - upb_Arena_Fuse(read, fuse); - upb_Arena_Free(read); - read = fuse; - } - upb_Arena_Free(read); - } - while (arenaCtr < arenas.size()) { - upb_Arena_Free(arenas[arenaCtr++]); - } - }); - } - - auto end = absl::Now() + absl::Seconds(2); - size_t arenaCtr = 0; - uintptr_t total_allocated = 0; - while (absl::Now() < end && arenaCtr < arenas.size()) { - upb_Arena* read = arenas[arenaCtr++]; - size_t count; - size_t allocated; - do { - allocated = upb_Arena_SpaceAllocated(read, &count); - } while (count < fuses_per_thread * thread_count); - upb_Arena_Free(read); - total_allocated += allocated; - } - done.Notify(); - for (auto& t : threads) t.join(); - while (arenaCtr < arenas.size()) { - upb_Arena_Free(arenas[arenaCtr++]); - } - ASSERT_GT(total_allocated, arenaCtr); -} - -TEST(ArenaTest, FuzzAllocSpaceAllocatedRace) { - upb_Arena_SetMaxBlockSize(128); - absl::Cleanup reset_max_block_size = [] { - upb_Arena_SetMaxBlockSize(UPB_PRIVATE(kUpbDefaultMaxBlockSize)); - }; - upb_Arena* arena = upb_Arena_New(); - absl::Notification done; - std::vector threads; - for (int i = 0; i < 1; ++i) { - threads.emplace_back([&]() { - while (!done.HasBeenNotified()) { - size_t count; - upb_Arena_SpaceAllocated(arena, &count); - } - }); - } - - auto end = absl::Now() + absl::Seconds(2); - uintptr_t total = 0; - while (absl::Now() < end && total < 10000000) { - if (upb_Arena_Malloc(arena, 128) == nullptr) { - break; - } - total += 128; - } - done.Notify(); - for (auto& t : threads) t.join(); - upb_Arena_Free(arena); -} - -TEST(ArenaTest, ArenaIncRef) { - upb_Arena* arena1 = upb_Arena_New(); - EXPECT_EQ(upb_Arena_DebugRefCount(arena1), 1); - upb_Arena_IncRefFor(arena1, nullptr); - EXPECT_EQ(upb_Arena_DebugRefCount(arena1), 2); - upb_Arena_DecRefFor(arena1, nullptr); - EXPECT_EQ(upb_Arena_DebugRefCount(arena1), 1); - upb_Arena_Free(arena1); -} - -TEST(ArenaTest, FuzzFuseIncRefCountRace) { - Environment env; - - absl::Notification done; - std::vector threads; - for (int i = 0; i < 10; ++i) { - threads.emplace_back([&]() { - absl::BitGen gen; - while (!done.HasBeenNotified()) { - env.RandomNewFree(gen); - } - }); - } - - absl::BitGen gen; - auto end = absl::Now() + absl::Seconds(2); - while (absl::Now() < end) { - env.RandomFuse(gen); - env.RandomIncRefCount(gen); - } - done.Notify(); - for (auto& t : threads) t.join(); -} - -TEST(ArenaTest, IncRefCountShouldFailForInitialBlock) { - char buf1[1024]; - upb_Arena* arena = upb_Arena_Init(buf1, 1024, &upb_alloc_global); - EXPECT_FALSE(upb_Arena_IncRefFor(arena, nullptr)); -} - -TEST(ArenaTest, FuzzFuseIsFusedRace) { - Environment env; - - // Create two arenas and fuse them. - std::shared_ptr a = env.IndexedNonNullArena(0); - std::shared_ptr b = env.IndexedNonNullArena(1); - upb_Arena_Fuse(a->ptr(), b->ptr()); - EXPECT_TRUE(upb_Arena_IsFused(a->ptr(), b->ptr())); - - absl::Notification done; - std::vector threads; - for (int i = 0; i < 10; ++i) { - threads.emplace_back([&]() { - absl::BitGen gen; - while (!done.HasBeenNotified()) { - env.RandomPoke(gen, 2); - } - }); - } - - absl::BitGen gen; - auto end = absl::Now() + absl::Seconds(2); - while (absl::Now() < end) { - // Verify that the two arenas are still fused. - EXPECT_TRUE(upb_Arena_IsFused(a->ptr(), b->ptr())); - } - done.Notify(); - for (auto& t : threads) t.join(); -} - -TEST(ArenaTest, FuzzRefArenaRace) { - Environment env; - - absl::Notification done; - std::vector threads; - for (int i = 0; i < 10; ++i) { - threads.emplace_back([&]() { - absl::BitGen gen; - while (!done.HasBeenNotified()) { - env.RandomNewFree(gen); - } - }); - } - - absl::BitGen gen; - auto end = absl::Now() + absl::Seconds(2); - while (absl::Now() < end) { - env.RandomRefArena(gen); - } - done.Notify(); - for (auto& t : threads) t.join(); -} - -#ifndef NDEBUG - -TEST(ArenaTest, FuzzFuseRefArenaRace) { - Environment env; - - absl::Notification done; - std::vector threads; - for (int i = 0; i < 10; ++i) { - threads.emplace_back([&]() { - absl::BitGen gen; - while (!done.HasBeenNotified()) { - env.PartitionedFuse(gen); - } - }); - } - for (int i = 0; i < 10; ++i) { - threads.emplace_back([&]() { - absl::BitGen gen; - while (!done.HasBeenNotified()) { - env.PartitionedHasRef(gen); - } - }); - } - - absl::BitGen gen; - auto end = absl::Now() + absl::Seconds(2); - while (absl::Now() < end) { - env.PartitionedRefArena(gen); - env.PartitionedHasRef(gen); - } - done.Notify(); - for (auto& t : threads) t.join(); -} - -TEST(ArenaTest, ArenaRef) { - upb_Arena* arena1 = upb_Arena_New(); - upb_Arena* arena2 = upb_Arena_New(); - - upb_Arena_RefArena(arena1, arena2); - EXPECT_TRUE(upb_Arena_HasRef(arena1, arena2)); - EXPECT_FALSE(upb_Arena_HasRef(arena2, arena1)); - - upb_Arena_Free(arena1); - upb_Arena_Free(arena2); -} -#endif - -TEST(ArenaTest, ArenaRefPreventsFree) { - upb_Arena* arena1 = upb_Arena_New(); - upb_Arena* arena2 = upb_Arena_New(); - - // arena2 has refcount 1. - EXPECT_EQ(upb_Arena_DebugRefCount(arena2), 1); - - // arena1 now owns a ref to arena2. arena2 has refcount 2. - upb_Arena_RefArena(arena1, arena2); - EXPECT_EQ(upb_Arena_DebugRefCount(arena2), 2); - - // User of arena2 frees it. Refcount goes to 1. Arena is not freed. - upb_Arena_Free(arena2); - EXPECT_EQ(upb_Arena_DebugRefCount(arena2), 1); - - // We can still allocate on arena2. - EXPECT_NE(nullptr, upb_Arena_Malloc(arena2, 1)); - - // When arena1 is freed, it releases its ref on arena2, which is then freed. - upb_Arena_Free(arena1); -} - -TEST(ArenaTest, ArenaOwnerFreedFirst) { - upb_Arena* arena1 = upb_Arena_New(); - upb_Arena* arena2 = upb_Arena_New(); - - // arena2 has refcount 1. - EXPECT_EQ(upb_Arena_DebugRefCount(arena2), 1); - - // arena1 now owns a ref to arena2. arena2 has refcount 2. - upb_Arena_RefArena(arena1, arena2); - EXPECT_EQ(upb_Arena_DebugRefCount(arena2), 2); - - // Freeing the owner releases its ref on arena2. Refcount goes to 1. - upb_Arena_Free(arena1); - EXPECT_EQ(upb_Arena_DebugRefCount(arena2), 1); - - // Now when we free arena2, it is actually freed. - upb_Arena_Free(arena2); -} - -#ifndef UPB_ENABLE_REF_CYCLE_CHECKS - -TEST(ArenaDeathTest, ArenaRefCycle) { - ASSERT_DEATH( - { - upb_Arena* arena1 = upb_Arena_New(); - upb_Arena* arena2 = upb_Arena_New(); - upb_Arena_RefArena(arena1, arena2); - upb_Arena_RefArena(arena2, arena1); - upb_Arena_Free(arena1); - upb_Arena_Free(arena2); - }, - ""); -} - -TEST(ArenaDeathTest, ArenaRefCycleThroughFuse) { - ASSERT_DEATH( - { - upb_Arena* arena1 = upb_Arena_New(); - upb_Arena* arena2 = upb_Arena_New(); - upb_Arena* arena3 = upb_Arena_New(); - upb_Arena_RefArena(arena1, arena2); - upb_Arena_Fuse(arena2, arena3); - upb_Arena_RefArena(arena3, arena1); - upb_Arena_Free(arena1); - upb_Arena_Free(arena2); - upb_Arena_Free(arena3); - }, - ""); -} - -TEST(ArenaDeathTest, ArenaRefCycleThroughMultipleFuses) { - ASSERT_DEATH( - { - upb_Arena* arena1 = upb_Arena_New(); - upb_Arena* arena2 = upb_Arena_New(); - upb_Arena* arena3 = upb_Arena_New(); - upb_Arena* arena4 = upb_Arena_New(); - upb_Arena* arena5 = upb_Arena_New(); - upb_Arena_RefArena(arena1, arena2); // a -> b - upb_Arena_Fuse(arena2, arena3); // b + c - upb_Arena_RefArena(arena3, arena4); // c -> d - upb_Arena_Fuse(arena4, arena5); // d + e - upb_Arena_RefArena(arena5, arena1); // e -> a (cycle) - upb_Arena_Free(arena1); - upb_Arena_Free(arena2); - upb_Arena_Free(arena3); - upb_Arena_Free(arena4); - upb_Arena_Free(arena5); - }, - ""); -} - -TEST(ArenaDeathTest, ArenaRefFuseCycle) { - ASSERT_DEATH( - { - upb::Arena a; - upb::Arena b; - upb::Arena c; - c.RefArena(a); - - absl::Notification t1_started; - absl::Notification t2_started; - absl::Notification t1_finished; - absl::Notification t2_finished; - - std::thread thread1([&]() { - t1_started.Notify(); - t2_started.WaitForNotification(); - a.RefArena(b); - t1_finished.Notify(); - }); - - std::thread thread2([&]() { - t2_started.Notify(); - t1_started.WaitForNotification(); - b.Fuse(c); - t2_finished.Notify(); - }); - - thread1.join(); - thread2.join(); - }, - ""); -} - -#endif // DEBUG - -#endif // UPB_SUPPRESS_MISSING_ATOMICS - -} // namespace diff --git a/vendor/upb/mem/internal/arena.h b/vendor/upb/mem/internal/arena.h deleted file mode 100644 index 1df9785..0000000 --- a/vendor/upb/mem/internal/arena.h +++ /dev/null @@ -1,169 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MEM_INTERNAL_ARENA_H_ -#define UPB_MEM_INTERNAL_ARENA_H_ - -#include -#include -#include - -#include "upb/port/sanitizers.h" - -// Must be last. -#include "upb/port/def.inc" - -// This is QUITE an ugly hack, which specifies the number of pointers needed -// to equal (or exceed) the storage required for one upb_Arena. -// -// We need this because the decoder inlines a upb_Arena for performance but -// the full struct is not visible outside of arena.c. Yes, I know, it's awful. -#ifndef NDEBUG -#define UPB_ARENA_BASE_SIZE_HACK 10 -#else -#define UPB_ARENA_BASE_SIZE_HACK 9 -#endif - -#define UPB_ARENA_SIZE_HACK \ - (sizeof(void*) * (UPB_ARENA_BASE_SIZE_HACK + (UPB_XSAN_STRUCT_SIZE * 2))) + \ - (sizeof(uint32_t) * 2) - -// LINT.IfChange(upb_Arena) - -struct upb_Arena { - char* UPB_ONLYBITS(ptr); - const UPB_NODEREF char* UPB_ONLYBITS(end); - UPB_XSAN_MEMBER -}; - -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Arena) - -#ifdef __cplusplus -extern "C" { -#endif - -void UPB_PRIVATE(_upb_Arena_SwapIn)(struct upb_Arena* des, - const struct upb_Arena* src); -void UPB_PRIVATE(_upb_Arena_SwapOut)(struct upb_Arena* des, - const struct upb_Arena* src); - -UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(const struct upb_Arena* a) { - return (size_t)(a->UPB_ONLYBITS(end) - a->UPB_ONLYBITS(ptr)); -} - -UPB_INLINE size_t UPB_PRIVATE(_upb_Arena_AllocSpan)(size_t size) { - return UPB_ALIGN_MALLOC(size) + UPB_PRIVATE(kUpb_Asan_GuardSize); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)( - const struct upb_Arena* a, void* ptr, size_t size) { - return UPB_PRIVATE(upb_Xsan_PtrEq)( - (char*)ptr + UPB_PRIVATE(_upb_Arena_AllocSpan)(size), - a->UPB_ONLYBITS(ptr)); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_Arena_IsAligned)(const void* ptr) { - return (uintptr_t)ptr % UPB_MALLOC_ALIGN == 0; -} - -UPB_API_INLINE void* upb_Arena_Malloc(struct upb_Arena* a, size_t size) { - UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a)); - - size_t span = UPB_PRIVATE(_upb_Arena_AllocSpan)(size); - - if (UPB_UNLIKELY(UPB_PRIVATE(_upb_ArenaHas)(a) < span)) { - void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(struct upb_Arena * a, size_t size); - return UPB_PRIVATE(_upb_Arena_SlowMalloc)(a, span); - } - - // We have enough space to do a fast malloc. - void* ret = a->UPB_ONLYBITS(ptr); - a->UPB_ONLYBITS(ptr) += span; - UPB_ASSERT(UPB_PRIVATE(_upb_Arena_IsAligned)(ret)); - UPB_ASSERT(UPB_PRIVATE(_upb_Arena_IsAligned)(a->UPB_ONLYBITS(ptr))); - - return UPB_PRIVATE(upb_Xsan_NewUnpoisonedRegion)(UPB_XSAN(a), ret, size); -} - -UPB_API_INLINE void upb_Arena_ShrinkLast(struct upb_Arena* a, void* ptr, - size_t oldsize, size_t size) { - UPB_ASSERT(ptr); - UPB_ASSERT(size <= oldsize); - - UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a)); - UPB_PRIVATE(upb_Xsan_ResizeUnpoisonedRegion)(ptr, oldsize, size); - - if (UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)(a, ptr, oldsize)) { - // We can reclaim some memory. - a->UPB_ONLYBITS(ptr) -= UPB_ALIGN_MALLOC(oldsize) - UPB_ALIGN_MALLOC(size); - } else { - // We can't reclaim any memory, but we need to verify that `ptr` really - // does represent the most recent allocation. -#ifndef NDEBUG - bool _upb_Arena_WasLastAlloc(struct upb_Arena * a, void* ptr, - size_t oldsize); - UPB_ASSERT(_upb_Arena_WasLastAlloc(a, ptr, oldsize)); -#endif - } -} - -UPB_API_INLINE bool upb_Arena_TryExtend(struct upb_Arena* a, void* ptr, - size_t oldsize, size_t size) { - UPB_ASSERT(ptr); - UPB_ASSERT(size > oldsize); - - UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a)); - size_t extend = UPB_ALIGN_MALLOC(size) - UPB_ALIGN_MALLOC(oldsize); - - if (UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)(a, ptr, oldsize) && - UPB_PRIVATE(_upb_ArenaHas)(a) >= extend) { - a->UPB_ONLYBITS(ptr) += extend; - UPB_PRIVATE(upb_Xsan_ResizeUnpoisonedRegion)(ptr, oldsize, size); - return true; - } - - return false; -} - -UPB_API_INLINE void* upb_Arena_Realloc(struct upb_Arena* a, void* ptr, - size_t oldsize, size_t size) { - UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a)); - - void* ret; - - if (ptr && (size <= oldsize || upb_Arena_TryExtend(a, ptr, oldsize, size))) { - // We can extend or shrink in place. - if (size <= oldsize && - UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)(a, ptr, oldsize)) { - upb_Arena_ShrinkLast(a, ptr, oldsize, size); - } - ret = ptr; - } else { - // We need to copy into a new allocation. - ret = upb_Arena_Malloc(a, size); - if (ret && oldsize > 0) { - memcpy(ret, ptr, UPB_MIN(oldsize, size)); - } - } - - if (ret) { - // We want to invalidate pointers to the old region if hwasan is enabled, so - // we poison and unpoison even if ptr == ret. However, if reallocation fails - // we do not want to poison the old memory, or attempt to poison null. - UPB_PRIVATE(upb_Xsan_PoisonRegion)(ptr, oldsize); - return UPB_PRIVATE(upb_Xsan_NewUnpoisonedRegion)(UPB_XSAN(a), ret, size); - } - return ret; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MEM_INTERNAL_ARENA_H_ */ diff --git a/vendor/upb/message/BUILD b/vendor/upb/message/BUILD deleted file mode 100644 index 0cca431..0000000 --- a/vendor/upb/message/BUILD +++ /dev/null @@ -1,533 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//bazel:proto_library.bzl", "proto_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS", "UPB_DEFAULT_FEATURES") -load( - "//upb/bazel:upb_minitable_proto_library.bzl", - "upb_minitable_proto_library", -) -load( - "//upb/bazel:upb_proto_library.bzl", - "upb_c_proto_library", - "upb_proto_reflection_library", -) - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "message", - srcs = [ - "accessors.c", - "array.c", - "compat.c", - "map.c", - "map_sorter.c", - "message.c", - ], - hdrs = [ - "accessors.h", - "array.h", - "compat.h", - "map.h", - "map_gencode_util.h", - "message.h", - "value.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":types", - "//upb/base", - "//upb/base:internal", - "//upb/hash", - "//upb/mem", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - ], -) - -cc_library( - name = "message_cc", - hdrs = [ - "accessors.hpp", - ], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//upb:__subpackages__"], - deps = [ - ":message", - "//upb/base", - "//upb/mini_table", - ], -) - -cc_library( - name = "internal", - srcs = [ - "internal/extension.c", - "internal/message.c", - "value.h", - ], - hdrs = [ - "internal/accessors.h", - "internal/array.h", - "internal/extension.h", - "internal/map.h", - "internal/map_sorter.h", - "internal/message.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":types", - "//upb/base", - "//upb/base:internal", - "//upb/hash", - "//upb/mem", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - ], -) - -cc_library( - name = "iterator", - srcs = [ - "internal/iterator.c", - ], - hdrs = [ - "internal/iterator.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":message", - "//upb/mini_table", - "//upb/port", - ], -) - -cc_library( - name = "compare", - srcs = [ - "compare.c", - "internal/compare_unknown.c", - ], - hdrs = [ - "compare.h", - "internal/compare_unknown.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":iterator", - ":message", - "//upb/base", - "//upb/mem", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:reader", - ], -) - -cc_library( - name = "copy", - srcs = [ - "copy.c", - "merge.c", - ], - hdrs = [ - "copy.h", - "merge.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":message", - "//upb/base", - "//upb/base:internal", - "//upb/mem", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/wire", - ], -) - -cc_library( - name = "promote", - srcs = [ - "promote.c", - ], - hdrs = [ - "promote.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":message", - "//upb/base", - "//upb/mem", - "//upb/mini_table", - "//upb/port", - "//upb/wire", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:reader", - ], -) - -cc_test( - name = "merge_test", - srcs = ["merge_test.cc"], - deps = [ - ":copy", - ":internal", - ":message", - "//upb/base", - "//upb/mem", - "//upb/mini_table", - "//upb/port", - "//upb/test:test_messages_proto2_upb_minitable", - "//upb/test:test_messages_proto2_upb_proto", - "//upb/test:test_upb_proto", - "//upb/wire", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_library( - name = "split64", - hdrs = [ - "accessors_split64.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":message", - "//upb/mem", - "//upb/mini_table", - "//upb/port", - ], -) - -cc_library( - name = "types", - hdrs = [ - "internal/map_entry.h", - "internal/types.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/hash", - "//upb/port", - ], -) - -proto_library( - name = "message_test_proto", - testonly = 1, - srcs = ["test.proto"], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], -) - -upb_minitable_proto_library( - name = "message_test_upb_minitable_proto", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = [":message_test_proto"], -) - -upb_c_proto_library( - name = "message_test_upb_proto", - testonly = 1, - deps = [":message_test_proto"], -) - -upb_proto_reflection_library( - name = "message_test_upb_proto_reflection", - testonly = 1, - deps = [":message_test_proto"], -) - -cc_test( - name = "accessors_test", - srcs = ["accessors_test.cc"], - deps = [ - ":message", - "//src/google/protobuf", - "//upb/base", - "//upb/mem", - "//upb/mini_descriptor", - "//upb/mini_descriptor:internal", - "//upb/mini_table", - "//upb/port", - "//upb/test:test_messages_proto2_upb_minitable", - "//upb/test:test_messages_proto2_upb_proto", - "//upb/test:test_messages_proto3_upb_minitable", - "//upb/test:test_messages_proto3_upb_proto", - "//upb/test:test_upb_proto", - "//upb/wire", - "@abseil-cpp//absl/container:flat_hash_set", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "array_test", - srcs = ["array_test.cc"], - deps = [ - ":message", - "//upb/base", - "//upb/mem", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "compare_unknown_test", - srcs = ["internal/compare_unknown_test.cc"], - deps = [ - ":compare", - ":internal", - ":message", - "//upb/base", - "//upb/base:internal", - "//upb/mem", - "//upb/port", - "//upb/test:test_messages_proto2_upb_proto", - "//upb/wire", - "//upb/wire:reader", - "//upb/wire/test_util:wire_message", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "copy_test", - srcs = ["copy_test.cc"], - deps = [ - ":copy", - ":internal", - ":message", - "//src/google/protobuf", - "//upb/base", - "//upb/mem", - "//upb/mini_table", - "//upb/port", - "//upb/test:test_messages_proto2_upb_minitable", - "//upb/test:test_messages_proto2_upb_proto", - "//upb/test:test_proto_upb_minitable", - "//upb/test:test_upb_proto", - "//upb/wire", - "@abseil-cpp//absl/container:flat_hash_set", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "map_test", - srcs = ["map_test.cc"], - deps = [ - ":message", - "//upb/base", - "//upb/mem", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "promote_test", - srcs = ["promote_test.cc"], - deps = [ - ":copy", - ":internal", - ":message", - ":promote", - "//src/google/protobuf", - "//upb/base", - "//upb/mem", - "//upb/mini_descriptor", - "//upb/mini_descriptor:internal", - "//upb/mini_table", - "//upb/test:test_messages_proto2_upb_proto", - "//upb/test:test_messages_proto3_upb_proto", - "//upb/test:test_proto_upb_minitable", - "//upb/test:test_upb_proto", - "//upb/wire", - "@abseil-cpp//absl/container:flat_hash_set", - "@abseil-cpp//absl/strings:string_view", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -bool_flag( - name = "fuzz_dump_minitable", - build_setting_default = False, -) - -config_setting( - name = "fuzz_dump_minitable_enabled", - flag_values = {":fuzz_dump_minitable": "True"}, -) - -# This test doesn't directly include any files from this subdir so it probably -# should live elsewhere. -cc_test( - name = "test", - srcs = ["test.cc"], - args = ["--fuzztest_stack_limit_kb=256"], - copts = UPB_DEFAULT_CPPOPTS + select({ - ":fuzz_dump_minitable_enabled": ["-DUPB_FUZZ_DUMP_MINITABLE"], - "//conditions:default": [], - }), - features = UPB_DEFAULT_FEATURES, - deps = [ - ":compare", - ":internal", - ":message", - ":message_test_upb_minitable_proto", - ":message_test_upb_proto", - ":message_test_upb_proto_reflection", - "//upb/base", - "//upb/json", - "//upb/mem", - "//upb/mini_descriptor", - "//upb/mini_table", - "//upb/mini_table:debug_string", - "//upb/mini_table:internal", - "//upb/port", - "//upb/reflection", - "//upb/test:fuzz_util", - "//upb/test:test_messages_proto3_upb_proto", - "//upb/text:debug", - "//upb/wire", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:reader", - "//upb/wire:writer", - "@abseil-cpp//absl/cleanup", - "@abseil-cpp//absl/numeric:bits", - "@abseil-cpp//absl/strings", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -proto_library( - name = "utf8_test_proto", - testonly = 1, - srcs = ["utf8_test.proto"], -) - -proto_library( - name = "utf8_test_proto2_proto", - testonly = 1, - srcs = ["utf8_test_proto2.proto"], -) - -upb_minitable_proto_library( - name = "utf8_test_upb_minitable_proto", - testonly = 1, - deps = [":utf8_test_proto"], -) - -upb_minitable_proto_library( - name = "utf8_test_proto2_upb_minitable_proto", - testonly = 1, - deps = [":utf8_test_proto2_proto"], -) - -upb_c_proto_library( - name = "utf8_test_upb_proto", - testonly = 1, - deps = [":utf8_test_proto"], -) - -upb_c_proto_library( - name = "utf8_test_proto2_upb_proto", - testonly = 1, - deps = [":utf8_test_proto2_proto"], -) - -cc_test( - name = "utf8_test", - srcs = ["utf8_test.cc"], - deps = [ - ":utf8_test_proto2_upb_minitable_proto", - ":utf8_test_proto2_upb_proto", - ":utf8_test_upb_minitable_proto", - ":utf8_test_upb_proto", - "//upb/base", - "//upb/mem", - "//upb/wire", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - exclude = ["promote_test.cc"], - ), - visibility = ["//upb:__pkg__"], -) - -filegroup( - name = "test_protos", - srcs = glob( - [ - "**/*.proto", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/message/accessors.c b/vendor/upb/message/accessors.c deleted file mode 100644 index 1be0158..0000000 --- a/vendor/upb/message/accessors.c +++ /dev/null @@ -1,38 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/accessors.h" - -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTableField* f, - upb_Message* map_entry_message, upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(map_entry_message)); - const upb_MiniTable* map_entry_mini_table = - upb_MiniTable_MapEntrySubMessage(f); - UPB_ASSERT(map_entry_mini_table); - const upb_MiniTableField* map_entry_key_field = - upb_MiniTable_MapKey(map_entry_mini_table); - const upb_MiniTableField* map_entry_value_field = - upb_MiniTable_MapValue(map_entry_mini_table); - // Map key/value cannot have explicit defaults, - // hence assuming a zero default is valid. - upb_MessageValue default_val = upb_MessageValue_Zero(); - upb_MessageValue map_entry_key = - upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); - upb_MessageValue map_entry_value = upb_Message_GetField( - map_entry_message, map_entry_value_field, default_val); - return upb_Map_Set(map, map_entry_key, map_entry_value, arena); -} diff --git a/vendor/upb/message/accessors.h b/vendor/upb/message/accessors.h deleted file mode 100644 index fb0f7aa..0000000 --- a/vendor/upb/message/accessors.h +++ /dev/null @@ -1,339 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_ACCESSORS_H_ -#define UPB_MESSAGE_ACCESSORS_H_ - -#include - -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/internal/types.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Functions ending in BaseField() take a (upb_MiniTableField*) argument -// and work only on non-extension fields. -// -// Functions ending in Extension() take a (upb_MiniTableExtension*) argument -// and work only on extensions. - -UPB_API_INLINE void upb_Message_Clear(upb_Message* msg, const upb_MiniTable* m); - -UPB_API_INLINE void upb_Message_ClearBaseField(upb_Message* msg, - const upb_MiniTableField* f); - -UPB_API_INLINE void upb_Message_ClearExtension(upb_Message* msg, - const upb_MiniTableExtension* e); - -UPB_API_INLINE void upb_Message_ClearOneof(upb_Message* msg, - const upb_MiniTable* m, - const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_Message_HasBaseField(const upb_Message* msg, - const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_Message_HasExtension(const upb_Message* msg, - const upb_MiniTableExtension* e); - -UPB_API_INLINE upb_MessageValue -upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f, - upb_MessageValue default_val); - -UPB_API_INLINE const upb_Array* upb_Message_GetArray( - const upb_Message* msg, const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_Message_GetBool(const upb_Message* msg, - const upb_MiniTableField* f, - bool default_val); - -UPB_API_INLINE double upb_Message_GetDouble(const upb_Message* msg, - const upb_MiniTableField* field, - double default_val); - -UPB_API_INLINE float upb_Message_GetFloat(const upb_Message* msg, - const upb_MiniTableField* f, - float default_val); - -UPB_API_INLINE int32_t upb_Message_GetInt32(const upb_Message* msg, - const upb_MiniTableField* f, - int32_t default_val); - -UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg, - const upb_MiniTableField* f, - int64_t default_val); - -UPB_API_INLINE const upb_Map* upb_Message_GetMap(const upb_Message* msg, - const upb_MiniTableField* f); - -UPB_API_INLINE const upb_Message* upb_Message_GetMessage( - const upb_Message* msg, const upb_MiniTableField* f); - -UPB_API_INLINE upb_Array* upb_Message_GetMutableArray( - upb_Message* msg, const upb_MiniTableField* f); - -UPB_API_INLINE upb_Map* upb_Message_GetMutableMap(upb_Message* msg, - const upb_MiniTableField* f); - -UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage( - upb_Message* msg, const upb_MiniTableField* f); - -UPB_NODISCARD UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( - upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena); - -UPB_NODISCARD UPB_API_INLINE upb_Map* upb_Message_GetOrCreateMutableMap( - upb_Message* msg, const upb_MiniTable* map_entry_mini_table, - const upb_MiniTableField* f, upb_Arena* arena); - -UPB_NODISCARD UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( - upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena); - -UPB_API_INLINE upb_StringView -upb_Message_GetString(const upb_Message* msg, const upb_MiniTableField* field, - upb_StringView default_val); - -UPB_API_INLINE uint32_t upb_Message_GetUInt32(const upb_Message* msg, - const upb_MiniTableField* f, - uint32_t default_val); - -UPB_API_INLINE uint64_t upb_Message_GetUInt64(const upb_Message* msg, - const upb_MiniTableField* f, - uint64_t default_val); - -UPB_API_INLINE void upb_Message_SetClosedEnum(upb_Message* msg, - const upb_MiniTableField* f, - int32_t value); - -// BaseField Setters /////////////////////////////////////////////////////////// - -UPB_API_INLINE void upb_Message_SetBaseField(upb_Message* msg, - const upb_MiniTableField* f, - const void* val); - -UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg, - const upb_MiniTableField* f, - bool value); - -UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg, - const upb_MiniTableField* f, - double value); - -UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg, - const upb_MiniTableField* f, - float value); - -UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg, - const upb_MiniTableField* f, - int32_t value); - -UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg, - const upb_MiniTableField* f, - int64_t value); - -UPB_API_INLINE void upb_Message_SetBaseFieldMessage(struct upb_Message* msg, - const upb_MiniTableField* f, - upb_Message* value); - -UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg, - const upb_MiniTableField* f, - upb_StringView value); - -UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg, - const upb_MiniTableField* f, - uint32_t value); - -UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg, - const upb_MiniTableField* f, - uint64_t value); - -// Extension Getters /////////////////////////////////////////////////////////// -UPB_API_INLINE bool upb_Message_GetExtensionBool( - const upb_Message* msg, const upb_MiniTableExtension* f, bool default_val); - -UPB_API_INLINE double upb_Message_GetExtensionDouble( - const upb_Message* msg, const upb_MiniTableExtension* f, - double default_val); - -UPB_API_INLINE float upb_Message_GetExtensionFloat( - const upb_Message* msg, const upb_MiniTableExtension* f, float default_val); - -UPB_API_INLINE int32_t upb_Message_GetExtensionInt32( - const upb_Message* msg, const upb_MiniTableExtension* f, - int32_t default_val); - -UPB_API_INLINE int64_t upb_Message_GetExtensionInt64( - const upb_Message* msg, const upb_MiniTableExtension* f, - int64_t default_val); - -UPB_API_INLINE uint32_t upb_Message_GetExtensionUInt32( - const upb_Message* msg, const upb_MiniTableExtension* f, - uint32_t default_val); - -UPB_API_INLINE uint64_t upb_Message_GetExtensionUInt64( - const upb_Message* msg, const upb_MiniTableExtension* f, - uint64_t default_val); - -UPB_API_INLINE upb_StringView upb_Message_GetExtensionString( - const upb_Message* msg, const upb_MiniTableExtension* f, - upb_StringView default_val); - -UPB_API_INLINE upb_Message* upb_Message_GetExtensionMessage( - const upb_Message* msg, const upb_MiniTableExtension* f, - struct upb_Message* default_val); - -UPB_API_INLINE const upb_Array* upb_Message_GetExtensionArray( - const upb_Message* msg, const upb_MiniTableExtension* f); - -UPB_API_INLINE upb_Array* upb_Message_GetExtensionMutableArray( - upb_Message* msg, const upb_MiniTableExtension* f); - -// Extension Setters /////////////////////////////////////////////////////////// - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtension( - upb_Message* msg, const upb_MiniTableExtension* e, const void* value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionMessage( - struct upb_Message* msg, const upb_MiniTableExtension* e, - struct upb_Message* value, upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionBool( - struct upb_Message* msg, const upb_MiniTableExtension* e, bool value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionDouble( - struct upb_Message* msg, const upb_MiniTableExtension* e, double value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionFloat( - struct upb_Message* msg, const upb_MiniTableExtension* e, float value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionInt32( - struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionInt64( - struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionString( - struct upb_Message* msg, const upb_MiniTableExtension* e, - upb_StringView value, upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionUInt32( - struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionUInt64( - struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value, - upb_Arena* a); - -// Universal Setters /////////////////////////////////////////////////////////// - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetBool( - upb_Message* msg, const upb_MiniTableField* f, bool value, upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetDouble( - upb_Message* msg, const upb_MiniTableField* f, double value, upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetFloat( - upb_Message* msg, const upb_MiniTableField* f, float value, upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetInt32( - upb_Message* msg, const upb_MiniTableField* f, int32_t value, upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetInt64( - upb_Message* msg, const upb_MiniTableField* f, int64_t value, upb_Arena* a); - -// Unlike the other similarly-named setters, this function can only be -// called on base fields. Prefer upb_Message_SetBaseFieldMessage(). -UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg, - const upb_MiniTableField* f, - upb_Message* value); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetString( - upb_Message* msg, const upb_MiniTableField* f, upb_StringView value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetUInt32( - upb_Message* msg, const upb_MiniTableField* f, uint32_t value, - upb_Arena* a); - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetUInt64( - upb_Message* msg, const upb_MiniTableField* f, uint64_t value, - upb_Arena* a); - -//////////////////////////////////////////////////////////////////////////////// - -UPB_NODISCARD UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized( - upb_Message* msg, const upb_MiniTableField* f, size_t size, - upb_Arena* arena); - -UPB_API_INLINE uint32_t upb_Message_WhichOneofFieldNumber( - const upb_Message* message, const upb_MiniTableField* oneof_field); - -// For a field `f` which is in a oneof, return the field of that -// oneof that is actually set (or NULL if none). -UPB_API_INLINE const upb_MiniTableField* upb_Message_WhichOneof( - const upb_Message* msg, const upb_MiniTable* m, - const upb_MiniTableField* f); - -// Updates a map entry given an entry message. -UPB_NODISCARD bool upb_Message_SetMapEntry(upb_Map* map, - const upb_MiniTableField* field, - upb_Message* map_entry_message, - upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#if defined(__cplusplus) -// Temporary overloads for functions whose signature has recently changed. -UPB_DEPRECATE_AND_INLINE() -UPB_NODISCARD inline upb_Message* upb_Message_GetOrCreateMutableMessage( - upb_Message* msg, const upb_MiniTable* mini_table, - const upb_MiniTableField* f, upb_Arena* arena) { - return upb_Message_GetOrCreateMutableMessage(msg, f, arena); -} - -UPB_DEPRECATE_AND_INLINE() -inline void upb_Message_SetClosedEnum(upb_Message* msg, - const upb_MiniTable* msg_mini_table, - const upb_MiniTableField* f, - int32_t value) { - upb_Message_SetClosedEnum(msg, f, value); -} - -UPB_DEPRECATE_AND_INLINE() -UPB_NODISCARD -inline bool upb_Message_SetMapEntry(upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* map_entry_message, - upb_Arena* arena) { - return upb_Message_SetMapEntry(map, field, map_entry_message, arena); -} -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MESSAGE_ACCESSORS_H_ diff --git a/vendor/upb/message/accessors.hpp b/vendor/upb/message/accessors.hpp deleted file mode 100644 index 03a3ed1..0000000 --- a/vendor/upb/message/accessors.hpp +++ /dev/null @@ -1,97 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// This file contains C++ wrappers for the C API in accessors.h. - -#ifndef UPB_MESSAGE_ACCESSORS_HPP_ -#define UPB_MESSAGE_ACCESSORS_HPP_ - -#include -#include -#include -#include - -#include "upb/base/string_view.h" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/message.h" -#include "upb/mini_table/field.h" - -namespace upb { - -template -T GetMessageBaseField(upb_Message* msg, const upb_MiniTableField* field, - T default_value); - -#define F(T, Func) \ - template <> \ - inline T GetMessageBaseField( \ - upb_Message * msg, const upb_MiniTableField* field, T default_value) { \ - return upb_Message_Get##Func(msg, field, default_value); \ - } - -F(int32_t, Int32); -F(int64_t, Int64); -F(uint32_t, UInt32); -F(uint64_t, UInt64); -F(float, Float); -F(double, Double); -F(bool, Bool); - -#undef F - -template <> -inline std::string GetMessageBaseField( - upb_Message* msg, const upb_MiniTableField* field, - std::string default_value) { - upb_StringView default_sv = upb_StringView_FromDataAndSize( - default_value.data(), default_value.size()); - upb_StringView sv = upb_Message_GetString(msg, field, default_sv); - return std::string(sv.data, sv.size); -} - -template -T FromMessageValue(upb_MessageValue value); - -#define F(type, member) \ - template <> \ - inline type FromMessageValue(upb_MessageValue value) { \ - return value.member; \ - } - -F(bool, bool_val); -F(float, float_val); -F(double, double_val); -F(int32_t, int32_val); -F(int64_t, int64_val); -F(uint32_t, uint32_val); -F(uint64_t, uint64_val); - -#undef F - -template <> -inline std::string FromMessageValue(upb_MessageValue value) { - return std::string(value.str_val.data, value.str_val.size); -} - -template -std::vector GetRepeatedField(upb_Message* msg, - const upb_MiniTableField* field) { - std::vector ret; - const upb_Array* array = upb_Message_GetArray(msg, field); - if (!array) return ret; - size_t size = upb_Array_Size(array); - ret.reserve(size); - for (size_t i = 0; i < size; i++) { - ret.push_back(FromMessageValue(upb_Array_Get(array, i))); - } - return ret; -} - -} // namespace upb - -#endif // UPB_MESSAGE_ACCESSORS_HPP_ diff --git a/vendor/upb/message/accessors_split64.h b/vendor/upb/message/accessors_split64.h deleted file mode 100644 index fdd9950..0000000 --- a/vendor/upb/message/accessors_split64.h +++ /dev/null @@ -1,69 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_ACCESSORS_SPLIT64_H_ -#define UPB_MESSAGE_ACCESSORS_SPLIT64_H_ - -#include - -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/message/message.h" -#include "upb/mini_table/field.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// JavaScript doesn't directly support 64-bit ints so we must split them. - -UPB_API_INLINE uint32_t upb_Message_GetInt64Hi(const upb_Message* msg, - const upb_MiniTableField* field, - uint32_t default_value) { - return (uint32_t)(upb_Message_GetInt64(msg, field, default_value) >> 32); -} - -UPB_API_INLINE uint32_t upb_Message_GetInt64Lo(const upb_Message* msg, - const upb_MiniTableField* field, - uint32_t default_value) { - return (uint32_t)upb_Message_GetInt64(msg, field, default_value); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetInt64Split( - upb_Message* msg, const upb_MiniTableField* field, uint32_t hi, uint32_t lo, - upb_Arena* arena) { - return upb_Message_SetInt64(msg, field, ((int64_t)hi << 32) | lo, arena); -} - -UPB_API_INLINE uint32_t upb_Message_GetUInt64Hi(const upb_Message* msg, - const upb_MiniTableField* field, - uint32_t default_value) { - return (uint32_t)(upb_Message_GetUInt64(msg, field, default_value) >> 32); -} - -UPB_API_INLINE uint32_t upb_Message_GetUInt64Lo(const upb_Message* msg, - const upb_MiniTableField* field, - uint32_t default_value) { - return (uint32_t)upb_Message_GetUInt64(msg, field, default_value); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetUInt64Split( - upb_Message* msg, const upb_MiniTableField* field, uint32_t hi, uint32_t lo, - upb_Arena* arena) { - return upb_Message_SetUInt64(msg, field, ((uint64_t)hi << 32) | lo, arena); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MESSAGE_ACCESSORS_SPLIT64_H_ diff --git a/vendor/upb/message/accessors_test.cc b/vendor/upb/message/accessors_test.cc deleted file mode 100644 index d4f0e00..0000000 --- a/vendor/upb/message/accessors_test.cc +++ /dev/null @@ -1,532 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* Test of mini table accessors. - * - * Messages are created and mutated using generated code, and then - * accessed through reflective APIs exposed through mini table accessors. - */ - -#include "upb/message/accessors.h" - -#include - -#include -#include -#include - -#include -#include "google/protobuf/test_messages_proto2.upb.h" -#include "google/protobuf/test_messages_proto2.upb_minitable.h" -#include "google/protobuf/test_messages_proto3.upb.h" -#include "google/protobuf/test_messages_proto3.upb_minitable.h" -#include "upb/base/descriptor_constants.h" -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/message.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_descriptor/internal/encode.hpp" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last -#include "upb/port/def.inc" - -namespace { - -// Proto2 test messages field numbers used for reflective access. -const uint32_t kFieldOptionalInt32 = 1; -const uint32_t kFieldOptionalUInt32 = 3; -const uint32_t kFieldOptionalBool = 13; -const uint32_t kFieldOptionalString = 14; -const uint32_t kFieldOptionalNestedMessage = 18; -const uint32_t kFieldOptionalRepeatedInt32 = 31; -const uint32_t kFieldOptionalRepeatedNestedMessage = 48; -const uint32_t kFieldOptionalNestedMessageA = 1; -const uint32_t kFieldOptionalOneOfUInt32 = 111; -const uint32_t kFieldOptionalOneOfString = 113; - -const uint32_t kFieldProto3OptionalInt64 = 2; -const uint32_t kFieldProto3OptionalUInt64 = 4; - -const char kTestStr1[] = "Hello1"; -const char kTestStr2[] = "Hello2"; -const int32_t kTestInt32 = 567; -const int32_t kTestUInt32 = 0xF1234567; -const uint64_t kTestUInt64 = 0xFEDCBAFF87654321; - -const upb_MiniTableField* find_proto3_field(int field_number) { - return upb_MiniTable_FindFieldByNumber( - &protobuf_0test_0messages__proto3__TestAllTypesProto3_msg_init, - field_number); -} - -const upb_MiniTableField* find_proto2_field(int field_number) { - return upb_MiniTable_FindFieldByNumber( - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - field_number); -} - -TEST(GeneratedCode, HazzersProto2) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - // Scalar/Boolean. - const upb_MiniTableField* optional_bool_field = - find_proto2_field(kFieldOptionalBool); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_bool_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(msg, true); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_bool_field)); - upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_bool_field); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_bool_field)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg)); - - // String. - const upb_MiniTableField* optional_string_field = - find_proto2_field(kFieldOptionalString); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( - msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); - EXPECT_EQ( - strlen(kTestStr1), - protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) - .size); - upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_string_field); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) - .size); - - // Message. - const upb_MiniTableField* optional_message_field = - find_proto2_field(kFieldOptionalNestedMessage); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message( - msg, arena); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); - upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_message_field); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( - msg) == nullptr); - - // One of. - const upb_MiniTableField* optional_oneof_uint32_field = - find_proto2_field(kFieldOptionalOneOfUInt32); - const upb_MiniTableField* optional_oneof_string_field = - find_proto2_field(kFieldOptionalOneOfString); - - EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_uint32_field)); - EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_string_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_uint32(msg, 123); - EXPECT_EQ(true, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_uint32_field)); - EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_string_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_string( - msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_uint32_field)); - EXPECT_EQ(true, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_string_field)); - upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_oneof_uint32_field); - EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_uint32_field)); - EXPECT_EQ(true, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_string_field)); - upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_oneof_string_field); - EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_uint32_field)); - EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), - optional_oneof_string_field)); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, ScalarsProto2) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - const upb_MiniTableField* optional_int32_field = - find_proto2_field(kFieldOptionalInt32); - - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); - - EXPECT_EQ(0, upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0)); - upb_Message_SetBaseFieldInt32(UPB_UPCAST(msg), optional_int32_field, - kTestInt32); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_int32_field)); - EXPECT_EQ(kTestInt32, - upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0)); - EXPECT_EQ( - kTestInt32, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); - - const upb_MiniTableField* optional_uint32_field = - find_proto2_field(kFieldOptionalUInt32); - - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); - EXPECT_EQ(0, - upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0)); - upb_Message_SetBaseFieldUInt32(UPB_UPCAST(msg), optional_uint32_field, - kTestUInt32); - EXPECT_EQ(kTestUInt32, - upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0)); - EXPECT_EQ( - kTestUInt32, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, ScalarProto3) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto3_TestAllTypesProto3* msg = - protobuf_test_messages_proto3_TestAllTypesProto3_new(arena); - - const upb_MiniTableField* optional_int64_field = - find_proto3_field(kFieldProto3OptionalInt64); - const upb_MiniTableField* optional_uint64_field = - find_proto3_field(kFieldProto3OptionalUInt64); - - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg)); - upb_Message_SetBaseFieldInt64(UPB_UPCAST(msg), optional_int64_field, -1); - EXPECT_EQ( - -1, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg)); - EXPECT_EQ(-1, upb_Message_GetInt64(UPB_UPCAST(msg), optional_int64_field, 0)); - - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg)); - upb_Message_SetBaseFieldUInt64(UPB_UPCAST(msg), optional_uint64_field, - kTestUInt64); - EXPECT_EQ( - kTestUInt64, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg)); - EXPECT_EQ(kTestUInt64, - upb_Message_GetUInt64(UPB_UPCAST(msg), optional_uint64_field, 0)); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, Strings) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - const upb_MiniTableField* optional_string_field = - find_proto2_field(kFieldOptionalString); - - // Test default. - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); - // Test read after write using C. - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( - msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); - upb_StringView value = upb_Message_GetString( - UPB_UPCAST(msg), optional_string_field, upb_StringView{nullptr, 0}); - std::string read_value = std::string(value.data, value.size); - EXPECT_EQ(kTestStr1, read_value); - // Clear. - upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_string_field); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( - msg)); - upb_Message_SetBaseFieldString(UPB_UPCAST(msg), optional_string_field, - upb_StringView_FromString(kTestStr2)); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( - msg)); - value = protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg); - read_value = std::string(value.data, value.size); - EXPECT_EQ(kTestStr2, read_value); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, SubMessage) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - const upb_MiniTableField* optional_message_field = - find_proto2_field(kFieldOptionalNestedMessage); - - const upb_Message* test_message = - upb_Message_GetMessage(UPB_UPCAST(msg), optional_message_field); - EXPECT_EQ(nullptr, test_message); - - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); - - // Get mutable using C API. - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested_message = - protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message( - msg, arena); - EXPECT_EQ(true, nested_message != nullptr); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( - nested_message, 5); - - // Read back using mini table API. - const upb_Message* sub_message = - upb_Message_GetMessage(UPB_UPCAST(msg), optional_message_field); - EXPECT_EQ(true, sub_message != nullptr); - - const upb_MiniTableField* nested_message_a_field = - upb_MiniTable_FindFieldByNumber( - &protobuf_0test_0messages__proto2__TestAllTypesProto2__NestedMessage_msg_init, - kFieldOptionalNestedMessageA); - EXPECT_EQ(5, upb_Message_GetInt32(sub_message, nested_message_a_field, 0)); - - upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_message_field); - EXPECT_EQ( - nullptr, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( - msg)); - EXPECT_EQ(false, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); - - upb_Message* new_nested_message = UPB_UPCAST( - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new( - arena)); - upb_Message_SetBaseFieldInt32(new_nested_message, nested_message_a_field, - 123); - upb_Message_SetMessage(UPB_UPCAST(msg), optional_message_field, - new_nested_message); - - upb_Message* mutable_message = upb_Message_GetOrCreateMutableMessage( - UPB_UPCAST(msg), optional_message_field, arena); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( - msg) != nullptr); - EXPECT_EQ(true, - upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); - EXPECT_EQ(123, - upb_Message_GetInt32(mutable_message, nested_message_a_field, 0)); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, RepeatedScalar) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - const upb_MiniTableField* repeated_int32_field = - find_proto2_field(kFieldOptionalRepeatedInt32); - - size_t len; - const int32_t* arr = - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32(msg, - &len); - // Test Get/Set Array values, validate with C API. - EXPECT_EQ(0, len); - EXPECT_EQ(nullptr, arr); - EXPECT_EQ(nullptr, - upb_Message_GetArray(UPB_UPCAST(msg), repeated_int32_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_resize_repeated_int32( - msg, 10, arena); - int32_t* mutable_values = - protobuf_test_messages_proto2_TestAllTypesProto2_mutable_repeated_int32( - msg, &len); - mutable_values[5] = 123; - const upb_Array* readonly_arr = - upb_Message_GetArray(UPB_UPCAST(msg), repeated_int32_field); - EXPECT_EQ(123, upb_Array_Get(readonly_arr, 5).int32_val); - - upb_MessageValue new_value; - new_value.int32_val = 567; - upb_Array* mutable_array = - upb_Message_GetMutableArray(UPB_UPCAST(msg), repeated_int32_field); - upb_Array_Set(mutable_array, 5, new_value); - EXPECT_EQ(new_value.int32_val, - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32( - msg, &len)[5]); - - // Test resize. - bool result = upb_Array_Resize(mutable_array, 20, arena); - EXPECT_EQ(true, result); - upb_Array_Set(mutable_array, 19, new_value); - EXPECT_EQ(new_value.int32_val, - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32( - msg, &len)[19]); - upb_Array_Resize(mutable_array, 0, arena); - const int32_t* zero_length_array = - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32(msg, - &len); - EXPECT_EQ(0, len); - EXPECT_EQ(true, zero_length_array != nullptr); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, RepeatedMessage) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - const upb_MiniTableField* repeated_nested_message_field = - find_proto2_field(kFieldOptionalRepeatedNestedMessage); - upb_Message* msg1 = (upb_Message*) - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(arena); - upb_Message* msg2 = (upb_Message*) - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(arena); - - upb_Array* array = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), repeated_nested_message_field, arena); - upb_MessageValue val1; - val1.msg_val = msg1; - upb_MessageValue val2; - val2.msg_val = msg2; - EXPECT_TRUE(upb_Array_Append(array, val1, arena)); - EXPECT_TRUE(upb_Array_Append(array, val2, arena)); - - EXPECT_EQ(msg1, upb_Array_GetMutable(array, 0)); - EXPECT_EQ(msg1, upb_Array_Get(array, 0).msg_val); - EXPECT_EQ(msg2, upb_Array_GetMutable(array, 1)); - EXPECT_EQ(msg2, upb_Array_Get(array, 1).msg_val); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, GetMutableMessage) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - // Message. - const upb_MiniTableField* optional_message_field = - find_proto2_field(kFieldOptionalNestedMessage); - upb_Message* msg1 = upb_Message_GetOrCreateMutableMessage( - UPB_UPCAST(msg), optional_message_field, arena); - upb_Message* msg2 = upb_Message_GetOrCreateMutableMessage( - UPB_UPCAST(msg), optional_message_field, arena); - // Verify that newly constructed sub message is stored in msg. - EXPECT_EQ(msg1, msg2); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, EnumClosedCheck) { - upb_Arena* arena = upb_Arena_New(); - - upb::MtDataEncoder e; - e.StartMessage(0); - e.PutField(kUpb_FieldType_Int32, 4, 0); - e.PutField(kUpb_FieldType_Enum, 5, 0); - - upb_Status status; - upb_Status_Clear(&status); - upb_MiniTable* table = - upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status); - - const upb_MiniTableField* enumField = &table->UPB_PRIVATE(fields)[1]; - EXPECT_EQ(upb_MiniTableField_Type(enumField), kUpb_FieldType_Enum); - EXPECT_FALSE(upb_MiniTableField_IsClosedEnum(enumField)); - - upb::MtDataEncoder e2; - e2.StartMessage(0); - e2.PutField(kUpb_FieldType_Int32, 4, 0); - e2.PutField(kUpb_FieldType_Enum, 6, kUpb_FieldModifier_IsClosedEnum); - - upb_Status_Clear(&status); - table = - upb_MiniTable_Build(e2.data().data(), e2.data().size(), arena, &status); - - const upb_MiniTableField* closedEnumField = &table->UPB_PRIVATE(fields)[1]; - EXPECT_EQ(upb_MiniTableField_Type(closedEnumField), kUpb_FieldType_Enum); - EXPECT_TRUE(upb_MiniTableField_IsClosedEnum(closedEnumField)); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, OneofClear) { - upb_Arena* arena = upb_Arena_New(); - - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - const upb_MiniTable* table = - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init; - - // oneof_uint32 - const upb_MiniTableField* oneofField = - upb_MiniTable_FindFieldByNumber(table, 111); - EXPECT_TRUE(upb_MiniTableField_IsInOneof(oneofField)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_uint32(msg, 522); - EXPECT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_has_oneof_uint32(msg)); - - upb_Message_ClearOneof((upb_Message*)msg, table, oneofField); - EXPECT_FALSE( - protobuf_test_messages_proto2_TestAllTypesProto2_has_oneof_uint32(msg)); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, OneofAccess) { - upb_Arena* arena = upb_Arena_New(); - - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - const upb_MiniTable* table = - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init; - - // oneof_uint32 - const upb_MiniTableField* oneofField = - upb_MiniTable_FindFieldByNumber(table, 111); - EXPECT_TRUE(upb_MiniTableField_IsInOneof(oneofField)); - - const upb_MiniTableField* oneOfFirstFetch = - upb_Message_WhichOneof((upb_Message*)msg, table, oneofField); - // one of not set, so should initially yield nullptr - EXPECT_EQ(oneOfFirstFetch, nullptr); - - protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_uint32(msg, 522); - const upb_MiniTableField* oneOfSecondFetch = - upb_Message_WhichOneof((upb_Message*)msg, table, oneofField); - // this oneof has now been set, so should yield the MiniTableField - EXPECT_EQ(oneOfSecondFetch, oneofField); - - upb_Arena_Free(arena); -} - -} // namespace diff --git a/vendor/upb/message/array.c b/vendor/upb/message/array.c deleted file mode 100644 index 1867795..0000000 --- a/vendor/upb/message/array.c +++ /dev/null @@ -1,199 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/array.h" - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/internal/log2.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/types.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); - return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); -} - -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - UPB_ASSERT(i < upb_Array_Size(arr)); - upb_MessageValue ret; - const char* data = upb_Array_DataPtr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} - -upb_Message* upb_Array_GetMutable(upb_Array* arr, size_t i) { - UPB_ASSERT(i < upb_Array_Size(arr)); - size_t elem_size = sizeof(upb_Message*); - UPB_ASSERT(elem_size == (1 << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr))); - char* data = upb_Array_MutableDataPtr(arr); - upb_Message* ret; - memcpy(&ret, data + (i * elem_size), elem_size); - UPB_ASSERT(!upb_Message_IsFrozen(ret)); - return ret; -} - -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - UPB_ASSERT(!upb_Array_IsFrozen(arr)); - UPB_ASSERT(i < upb_Array_Size(arr)); - char* data = upb_Array_MutableDataPtr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - memcpy(data + (i << lg2), &val, 1 << lg2); -} - -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(!upb_Array_IsFrozen(arr)); - UPB_ASSERT(arena); - if (!UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); - return true; -} - -bool upb_Array_Copy(upb_Array* dst, const upb_Array* src, upb_Arena* arena) { - UPB_ASSERT(dst); - UPB_ASSERT(src); - UPB_ASSERT(!upb_Array_IsFrozen(dst)); - if (dst == src) return true; - size_t len = upb_Array_Size(src); - if (!UPB_PRIVATE(_upb_Array_ResizeUninitialized)(dst, len, arena)) { - return false; - } - if (len == 0) return true; - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(dst); - const int src_lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(src); - UPB_ASSERT(lg2 == src_lg2); - char* dst_data = upb_Array_MutableDataPtr(dst); - const char* src_data = upb_Array_DataPtr(src); - memcpy(dst_data, src_data, len << lg2); - return true; -} - -bool upb_Array_AppendAll(upb_Array* dst, const upb_Array* src, - upb_Arena* arena) { - UPB_ASSERT(!upb_Array_IsFrozen(dst)); - UPB_ASSERT(src); - size_t src_len = upb_Array_Size(src); - if (src_len == 0) return true; - size_t dst_len = upb_Array_Size(dst); - size_t len = dst_len + src_len; - if (UPB_UNLIKELY(len < dst_len)) return false; - if (!UPB_PRIVATE(_upb_Array_ResizeUninitialized)(dst, len, arena)) { - return false; - } - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(dst); - const int src_lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(src); - UPB_ASSERT(lg2 == src_lg2); - char* dst_data = upb_Array_MutableDataPtr(dst); - const char* src_data = upb_Array_DataPtr(src); - memcpy(dst_data + (dst_len << lg2), src_data, src_len << lg2); - return true; -} - -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - UPB_ASSERT(!upb_Array_IsFrozen(arr)); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = upb_Array_MutableDataPtr(arr); - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); -} - -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(!upb_Array_IsFrozen(arr)); - UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); - UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); - const size_t oldsize = arr->UPB_PRIVATE(size); - if (!UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + count, arena)) { - return false; - } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - UPB_ASSERT(!upb_Array_IsFrozen(arr)); - const size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); - upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); - arr->UPB_PRIVATE(size) -= count; -} - -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - UPB_ASSERT(!upb_Array_IsFrozen(arr)); - const size_t oldsize = arr->UPB_PRIVATE(size); - if (UPB_UNLIKELY( - !UPB_PRIVATE(_upb_Array_ResizeUninitialized)(arr, size, arena))) { - return false; - } - const size_t newsize = arr->UPB_PRIVATE(size); - if (newsize > oldsize) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = upb_Array_MutableDataPtr(arr); - memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); - } - return true; -} - -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, - upb_Arena* arena) { - size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); - size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; - void* ptr = upb_Array_MutableDataPtr(array); - - // Log2 ceiling of size. - while (new_capacity < min_capacity) { - if (upb_ShlOverflow(&new_capacity, 1)) { - new_capacity = SIZE_MAX; - break; - } - } - - size_t new_bytes = new_capacity; - if (upb_ShlOverflow(&new_bytes, lg2)) { - return false; - } - ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); - if (!ptr) return false; - - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); - array->UPB_PRIVATE(capacity) = new_capacity; - return true; -} - -void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m) { - if (upb_Array_IsFrozen(arr)) return; - UPB_PRIVATE(_upb_Array_ShallowFreeze)(arr); - - if (m) { - const size_t size = upb_Array_Size(arr); - - for (size_t i = 0; i < size; i++) { - upb_MessageValue val = upb_Array_Get(arr, i); - upb_Message_Freeze((upb_Message*)val.msg_val, m); - } - } -} diff --git a/vendor/upb/message/array.h b/vendor/upb/message/array.h deleted file mode 100644 index b3d6b66..0000000 --- a/vendor/upb/message/array.h +++ /dev/null @@ -1,111 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_ARRAY_H_ -#define UPB_MESSAGE_ARRAY_H_ - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/types.h" -#include "upb/message/value.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_Array upb_Array; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new array on the given arena that holds elements of this type. -UPB_NODISCARD UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -// Returns the number of elements in the array. -UPB_API_INLINE size_t upb_Array_Size(const upb_Array* arr); - -// Returns the number of elements in the array. -UPB_API_INLINE size_t upb_Array_Capacity(const upb_Array* arr); - -// Returns the given element, which must be within the array's current size. -UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -// Returns a non-null mutating pointer to the given element. `arr` must be an -// array of a message type, and `i` must be within the array's current size. -UPB_API struct upb_Message* upb_Array_GetMutable(upb_Array* arr, size_t i); - -// Sets the given element, which must be within the array's current size. -UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -// Appends an element to the array. Returns false on allocation failure. -UPB_NODISCARD UPB_API bool upb_Array_Append(upb_Array* array, - upb_MessageValue val, - upb_Arena* arena); - -// Copies elements from |src| to |dst|, resizing |dst| to match |src| size. -// Returns false on allocation failure. -UPB_NODISCARD UPB_API bool upb_Array_Copy(upb_Array* dst, const upb_Array* src, - upb_Arena* arena); - -// Appends all elements from |src| to the end of |dst|. -// Returns false on allocation failure. -UPB_NODISCARD UPB_API bool upb_Array_AppendAll(upb_Array* dst, - const upb_Array* src, - upb_Arena* arena); - -// Moves elements within the array using memmove(). -// Like memmove(), the source and destination elements may be overlapping. -UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); - -// Inserts one or more empty elements into the array. -// Existing elements are shifted right. -// The new elements have undefined state and must be set with `upb_Array_Set()`. -// REQUIRES: `i <= upb_Array_Size(arr)` -UPB_NODISCARD UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, - size_t count, upb_Arena* arena); - -// Deletes one or more elements from the array. -// Existing elements are shifted left. -// REQUIRES: `i + count <= upb_Array_Size(arr)` -UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); - -// Reserves |size| elements of storage for the array. -UPB_NODISCARD UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, - size_t size, - upb_Arena* arena); - -// Changes the size of a vector. New elements are initialized to NULL/0. -// Returns false on allocation failure. -UPB_NODISCARD UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, - upb_Arena* arena); - -// Returns pointer to array data. -UPB_API_INLINE const void* upb_Array_DataPtr(const upb_Array* arr); - -// Returns mutable pointer to array data. -UPB_API_INLINE void* upb_Array_MutableDataPtr(upb_Array* arr); - -// Mark an array and all of its descendents as frozen/immutable. -// If the array elements are messages then |m| must point to the minitable for -// those messages. Otherwise |m| must be NULL. -UPB_API void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m); - -// Returns whether an array has been frozen. -UPB_API_INLINE bool upb_Array_IsFrozen(const upb_Array* arr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_ARRAY_H_ */ diff --git a/vendor/upb/message/array_test.cc b/vendor/upb/message/array_test.cc deleted file mode 100644 index d082e55..0000000 --- a/vendor/upb/message/array_test.cc +++ /dev/null @@ -1,102 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/array.h" - -#include -#include "upb/base/status.hpp" -#include "upb/mem/arena.hpp" - -TEST(ArrayTest, Resize) { - upb::Arena arena; - upb::Status status; - - upb_Array* array = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - EXPECT_TRUE(array); - - for (int i = 0; i < 10; i++) { - upb_MessageValue mv; - mv.int32_val = 3 * i; - - upb_Array_Append(array, mv, arena.ptr()); - EXPECT_EQ(upb_Array_Size(array), i + 1); - EXPECT_EQ(upb_Array_Get(array, i).int32_val, 3 * i); - } - - upb_Array_Resize(array, 12, arena.ptr()); - EXPECT_EQ(upb_Array_Get(array, 10).int32_val, 0); - EXPECT_EQ(upb_Array_Get(array, 11).int32_val, 0); - - upb_Array_Resize(array, 4, arena.ptr()); - EXPECT_EQ(upb_Array_Size(array), 4); - - upb_Array_Resize(array, 6, arena.ptr()); - EXPECT_EQ(upb_Array_Size(array), 6); - - EXPECT_EQ(upb_Array_Get(array, 3).int32_val, 9); - EXPECT_EQ(upb_Array_Get(array, 4).int32_val, 0); - EXPECT_EQ(upb_Array_Get(array, 5).int32_val, 0); -} - -TEST(ArrayTest, Copy) { - upb::Arena arena; - upb_Array* src = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - for (int i = 0; i < 5; i++) { - upb_MessageValue mv; - mv.int32_val = i; - upb_Array_Append(src, mv, arena.ptr()); - } - - upb_Array* dst = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - EXPECT_TRUE(upb_Array_Copy(dst, src, arena.ptr())); - EXPECT_EQ(upb_Array_Size(dst), 5); - for (int i = 0; i < 5; i++) { - EXPECT_EQ(upb_Array_Get(dst, i).int32_val, i); - } - - // Copy empty array - upb_Array* empty_src = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - EXPECT_TRUE(upb_Array_Copy(dst, empty_src, arena.ptr())); - EXPECT_EQ(upb_Array_Size(dst), 0); -} - -TEST(ArrayTest, AppendAll) { - upb::Arena arena; - upb_Array* dst = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - for (int i = 0; i < 3; i++) { - upb_MessageValue mv; - mv.int32_val = i; - upb_Array_Append(dst, mv, arena.ptr()); - } - - upb_Array* src = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - for (int i = 0; i < 3; i++) { - upb_MessageValue mv; - mv.int32_val = i + 10; - upb_Array_Append(src, mv, arena.ptr()); - } - - EXPECT_TRUE(upb_Array_AppendAll(dst, src, arena.ptr())); - EXPECT_EQ(upb_Array_Size(dst), 6); - EXPECT_EQ(upb_Array_Get(dst, 0).int32_val, 0); - EXPECT_EQ(upb_Array_Get(dst, 1).int32_val, 1); - EXPECT_EQ(upb_Array_Get(dst, 2).int32_val, 2); - EXPECT_EQ(upb_Array_Get(dst, 3).int32_val, 10); - EXPECT_EQ(upb_Array_Get(dst, 4).int32_val, 11); - EXPECT_EQ(upb_Array_Get(dst, 5).int32_val, 12); - - // Append empty array - upb_Array* empty_src = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - EXPECT_TRUE(upb_Array_AppendAll(dst, empty_src, arena.ptr())); - EXPECT_EQ(upb_Array_Size(dst), 6); - - // Append to empty array - upb_Array* empty_dst = upb_Array_New(arena.ptr(), kUpb_CType_Int32); - EXPECT_TRUE(upb_Array_AppendAll(empty_dst, src, arena.ptr())); - EXPECT_EQ(upb_Array_Size(empty_dst), 3); - EXPECT_EQ(upb_Array_Get(empty_dst, 0).int32_val, 10); -} diff --git a/vendor/upb/message/compare.c b/vendor/upb/message/compare.c deleted file mode 100644 index a1b4b51..0000000 --- a/vendor/upb/message/compare.c +++ /dev/null @@ -1,191 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/compare.h" - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/internal/compare_unknown.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/iterator.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - - -#ifdef __cplusplus -extern "C" { -#endif - -bool upb_Message_IsEmpty(const upb_Message* msg, const upb_MiniTable* m) { - if (upb_Message_ExtensionCount(msg)) return false; - - const upb_MiniTableField* f; - upb_MessageValue v; - size_t iter = kUpb_BaseField_Begin; - return !UPB_PRIVATE(_upb_Message_NextBaseField)(msg, m, &f, &v, &iter); -} - -static bool _upb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2, - upb_CType ctype, const upb_MiniTable* m, - int options) { - // Check for trivial equality. - if (arr1 == arr2) return true; - - // Must have identical element counts. - const size_t size1 = arr1 ? upb_Array_Size(arr1) : 0; - const size_t size2 = arr2 ? upb_Array_Size(arr2) : 0; - if (size1 != size2) return false; - - for (size_t i = 0; i < size1; i++) { - const upb_MessageValue val1 = upb_Array_Get(arr1, i); - const upb_MessageValue val2 = upb_Array_Get(arr2, i); - - if (!upb_MessageValue_IsEqual(val1, val2, ctype, m, options)) return false; - } - - return true; -} - -static bool _upb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2, - const upb_MiniTable* m, int options) { - // Check for trivial equality. - if (map1 == map2) return true; - - // Must have identical element counts. - size_t size1 = map1 ? upb_Map_Size(map1) : 0; - size_t size2 = map2 ? upb_Map_Size(map2) : 0; - if (size1 != size2) return false; - - const upb_MiniTableField* f = upb_MiniTable_MapValue(m); - const upb_MiniTable* m2_value = upb_MiniTable_SubMessage(f); - const upb_CType ctype = upb_MiniTableField_CType(f); - - upb_MessageValue key, val1, val2; - size_t iter = kUpb_Map_Begin; - while (upb_Map_Next(map1, &key, &val1, &iter)) { - if (!upb_Map_Get(map2, key, &val2)) return false; - if (!upb_MessageValue_IsEqual(val1, val2, ctype, m2_value, options)) - return false; - } - - return true; -} - -static bool _upb_Message_BaseFieldsAreEqual(const upb_Message* msg1, - const upb_Message* msg2, - const upb_MiniTable* m, - int options) { - // Iterate over all base fields for each message. - // The order will always match if the messages are equal. - size_t iter1 = kUpb_BaseField_Begin; - size_t iter2 = kUpb_BaseField_Begin; - - for (;;) { - const upb_MiniTableField *f1, *f2; - upb_MessageValue val1, val2; - - const bool got1 = - UPB_PRIVATE(_upb_Message_NextBaseField)(msg1, m, &f1, &val1, &iter1); - const bool got2 = - UPB_PRIVATE(_upb_Message_NextBaseField)(msg2, m, &f2, &val2, &iter2); - - if (got1 != got2) return false; // Must have identical field counts. - if (!got1) return true; // Loop termination condition. - if (f1 != f2) return false; // Must have identical fields set. - - const upb_MiniTable* subm = upb_MiniTable_SubMessage(f1); - const upb_CType ctype = upb_MiniTableField_CType(f1); - - bool eq; - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f1)) { - case kUpb_FieldMode_Array: - eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm, - options); - break; - case kUpb_FieldMode_Map: - eq = _upb_Map_IsEqual(val1.map_val, val2.map_val, subm, options); - break; - case kUpb_FieldMode_Scalar: - eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options); - break; - } - if (!eq) return false; - } -} - -static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1, - const upb_Message* msg2, - const upb_MiniTable* m, - int options) { - const upb_MiniTableExtension* e; - upb_MessageValue val1; - - // Iterate over all extensions for msg1, and search msg2 for each extension. - size_t count1 = 0; - size_t iter1 = kUpb_Message_ExtensionBegin; - while (upb_Message_NextExtension(msg1, &e, &val1, &iter1)) { - const upb_Extension* ext2 = UPB_PRIVATE(_upb_Message_Getext)(msg2, e); - if (!ext2) return false; - - count1++; - - const upb_MessageValue val2 = ext2->data; - const upb_MiniTableField* f = &e->UPB_PRIVATE(field); - const upb_MiniTable* subm = upb_MiniTableField_IsSubMessage(f) - ? upb_MiniTableExtension_GetSubMessage(e) - : NULL; - const upb_CType ctype = upb_MiniTableField_CType(f); - - bool eq; - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) { - case kUpb_FieldMode_Array: - eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm, - options); - break; - case kUpb_FieldMode_Map: - UPB_UNREACHABLE(); // Maps cannot be extensions. - break; - case kUpb_FieldMode_Scalar: { - eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options); - break; - } - } - if (!eq) return false; - } - - // Must have identical extension counts (this catches the case where msg2 - // has extensions that msg1 doesn't). - if (count1 != upb_Message_ExtensionCount(msg2)) return false; - - return true; -} - -bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2, - const upb_MiniTable* m, int options) { - if (UPB_UNLIKELY(msg1 == msg2)) return true; - - if (!_upb_Message_BaseFieldsAreEqual(msg1, msg2, m, options)) return false; - if (!_upb_Message_ExtensionsAreEqual(msg1, msg2, m, options)) return false; - - if (!(options & kUpb_CompareOption_IncludeUnknownFields)) return true; - - // The wire encoder enforces a maximum depth of 100 so we match that here. - return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(msg1, msg2, 100) == - kUpb_UnknownCompareResult_Equal; -} diff --git a/vendor/upb/message/compare.h b/vendor/upb/message/compare.h deleted file mode 100644 index d7be470..0000000 --- a/vendor/upb/message/compare.h +++ /dev/null @@ -1,81 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_COMPARE_H_ -#define UPB_MESSAGE_COMPARE_H_ - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -enum { - // If set, upb_Message_IsEqual() will attempt to compare unknown fields. - // By its very nature this comparison is inexact. - kUpb_CompareOption_IncludeUnknownFields = (1 << 0) -}; - -#ifdef __cplusplus -extern "C" { -#endif - -// Returns true if no known fields or extensions are set in the message. -UPB_API bool upb_Message_IsEmpty(const upb_Message* msg, - const upb_MiniTable* m); - -UPB_API bool upb_Message_IsEqual(const upb_Message* msg1, - const upb_Message* msg2, - const upb_MiniTable* m, int options); - -// If |ctype| is a message then |m| must point to its minitable. -UPB_API_INLINE bool upb_MessageValue_IsEqual(upb_MessageValue val1, - upb_MessageValue val2, - upb_CType ctype, - const upb_MiniTable* m, - int options) { - switch (ctype) { - case kUpb_CType_Bool: - return val1.bool_val == val2.bool_val; - - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - return val1.int32_val == val2.int32_val; - - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return val1.int64_val == val2.int64_val; - - case kUpb_CType_String: - case kUpb_CType_Bytes: - return upb_StringView_IsEqual(val1.str_val, val2.str_val); - - case kUpb_CType_Message: - return upb_Message_IsEqual(val1.msg_val, val2.msg_val, m, options); - - default: - UPB_UNREACHABLE(); - return false; - } -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MESSAGE_COMPARE_H_ diff --git a/vendor/upb/message/compat.c b/vendor/upb/message/compat.c deleted file mode 100644 index 0d79887..0000000 --- a/vendor/upb/message/compat.c +++ /dev/null @@ -1,36 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/compat.h" - -#include -#include - -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" - -// Must be last. -#include "upb/port/def.inc" - -bool upb_Message_NextExtensionReverse(const upb_Message* msg, - const upb_MiniTableExtension** result, - uintptr_t* iter) { - upb_MessageValue val; - return UPB_PRIVATE(_upb_Message_NextExtensionReverse)(msg, result, &val, - iter); -} - -const upb_MiniTableExtension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number) { - uintptr_t iter = kUpb_Message_ExtensionBegin; - const upb_MiniTableExtension* result; - while (upb_Message_NextExtensionReverse(msg, &result, &iter)) { - if (upb_MiniTableExtension_Number(result) == field_number) return result; - } - return NULL; -} diff --git a/vendor/upb/message/compat.h b/vendor/upb/message/compat.h deleted file mode 100644 index 7600ffa..0000000 --- a/vendor/upb/message/compat.h +++ /dev/null @@ -1,42 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_COMPAT_H_ -#define UPB_MESSAGE_COMPAT_H_ - -#include - -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" - -// Must be last. -#include "upb/port/def.inc" - -// upb does not support mixing minitables from different sources but these -// functions are still used by some existing users so for now we make them -// available here. This may or may not change in the future so do not add -// them to new code. - -#ifdef __cplusplus -extern "C" { -#endif - -// Same as upb_Message_NextExtension but iterates in reverse wire order -bool upb_Message_NextExtensionReverse(const upb_Message* msg, - const upb_MiniTableExtension** result, - uintptr_t* iter); -// Returns the minitable with the given field number, or NULL on failure. -const upb_MiniTableExtension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_COMPAT_H_ */ diff --git a/vendor/upb/message/copy.c b/vendor/upb/message/copy.c deleted file mode 100644 index 8c7f239..0000000 --- a/vendor/upb/message/copy.c +++ /dev/null @@ -1,351 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/copy.h" - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/size_log2.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" - -// Must be last. -#include "upb/port/def.inc" - -static upb_StringView upb_Clone_StringView(upb_StringView str, - upb_Arena* arena) { - if (str.size == 0) { - return upb_StringView_FromDataAndSize(NULL, 0); - } - void* cloned_data = upb_Arena_Malloc(arena, str.size); - upb_StringView cloned_str = - upb_StringView_FromDataAndSize(cloned_data, str.size); - memcpy(cloned_data, str.data, str.size); - return cloned_str; -} - -static bool upb_Clone_MessageValue(void* value, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - switch (value_type) { - case kUpb_CType_Bool: - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return true; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView source = *(upb_StringView*)value; - size_t size = source.size; - void* cloned_data = upb_Arena_Malloc(arena, size); - if (cloned_data == NULL) { - return false; - } - *(upb_StringView*)value = - upb_StringView_FromDataAndSize(cloned_data, size); - memcpy(cloned_data, source.data, size); - return true; - } break; - case kUpb_CType_Message: { - UPB_ASSERT(sub); - const upb_Message* source = *(upb_Message**)value; - UPB_ASSERT(source); - upb_Message* clone = upb_Message_DeepClone(source, sub, arena); - *(upb_Message**)value = clone; - return clone != NULL; - } break; - } - UPB_UNREACHABLE(); -} - -upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena) { - upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); - if (cloned_map == NULL) { - return NULL; - } - upb_MessageValue key, val; - size_t iter = kUpb_Map_Begin; - while (upb_Map_Next(map, &key, &val, &iter)) { - const upb_MiniTableField* value_field = - upb_MiniTable_MapValue(map_entry_table); - const upb_MiniTable* value_sub = - upb_MiniTableField_CType(value_field) == kUpb_CType_Message - ? upb_MiniTable_GetSubMessageTable(value_field) - : NULL; - upb_CType value_field_type = upb_MiniTableField_CType(value_field); - if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { - return NULL; - } - if (!upb_Map_Set(cloned_map, key, val, arena)) { - return NULL; - } - } - return cloned_map; -} - -static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* clone, - upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(clone)); - const upb_MiniTable* map_entry_table = upb_MiniTable_MapEntrySubMessage(f); - UPB_ASSERT(map_entry_table); - - const upb_MiniTableField* key_field = upb_MiniTable_MapKey(map_entry_table); - const upb_MiniTableField* value_field = - upb_MiniTable_MapValue(map_entry_table); - - upb_Map* cloned_map = upb_Map_DeepClone( - map, upb_MiniTableField_CType(key_field), - upb_MiniTableField_CType(value_field), map_entry_table, arena); - if (!cloned_map) { - return NULL; - } - upb_Message_SetBaseField(clone, f, &cloned_map); - return cloned_map; -} - -upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - const size_t size = upb_Array_Size(array); - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); - upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); - if (!cloned_array) { - return NULL; - } - if (!UPB_PRIVATE(_upb_Array_ResizeUninitialized)(cloned_array, size, arena)) { - return NULL; - } - for (size_t i = 0; i < size; ++i) { - upb_MessageValue val = upb_Array_Get(array, i); - if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { - return NULL; - } - upb_Array_Set(cloned_array, i, val); - } - return cloned_array; -} - -static bool upb_Message_Array_DeepClone(const upb_Array* array, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* clone, upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(clone)); - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); - upb_Array* cloned_array = - upb_Array_DeepClone(array, upb_MiniTableField_CType(field), - upb_MiniTableField_CType(field) == kUpb_CType_Message - ? upb_MiniTable_GetSubMessageTable(field) - : NULL, - arena); - - // Clear out upb_Array* due to parent memcpy. - upb_Message_SetBaseField(clone, field, &cloned_array); - return true; -} - -static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, - upb_Extension* dest, upb_Arena* arena) { - dest->data = source->data; - return upb_Clone_MessageValue( - &dest->data, upb_MiniTableExtension_CType(mini_table_ext), - upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); -} - -upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, - upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(dst)); - upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); - // Only copy message area skipping upb_Message_Internal. - memcpy(dst + 1, src + 1, mini_table->UPB_PRIVATE(size) - sizeof(upb_Message)); - for (int i = 0; i < upb_MiniTable_FieldCount(mini_table); ++i) { - const upb_MiniTableField* field = - upb_MiniTable_GetFieldByIndex(mini_table, i); - if (upb_MiniTableField_IsScalar(field)) { - switch (upb_MiniTableField_CType(field)) { - case kUpb_CType_Message: { - const upb_Message* sub_message = upb_Message_GetMessage(src, field); - if (sub_message != NULL) { - const upb_MiniTable* sub_message_table = - upb_MiniTable_GetSubMessageTable(field); - upb_Message* dst_sub_message = - upb_Message_DeepClone(sub_message, sub_message_table, arena); - if (dst_sub_message == NULL) { - return NULL; - } - upb_Message_SetBaseFieldMessage(dst, field, dst_sub_message); - } - } break; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView str = upb_Message_GetString(src, field, empty_string); - if (str.size != 0) { - if (!upb_Message_SetString( - dst, field, upb_Clone_StringView(str, arena), arena)) { - return NULL; - } - } - } break; - default: - // Scalar, already copied. - break; - } - } else { - if (upb_MiniTableField_IsMap(field)) { - const upb_Map* map = upb_Message_GetMap(src, field); - if (map != NULL) { - if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { - return NULL; - } - } - } else { - const upb_Array* array = upb_Message_GetArray(src, field); - if (array != NULL) { - if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, - arena)) { - return NULL; - } - } - } - } - } - // Clone extensions. - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(src); - if (!in) return dst; - - for (size_t i = 0; i < in->size; i++) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i]; - if (upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - // Clone extension - const upb_Extension* msg_ext = upb_TaggedAuxPtr_Extension(tagged_ptr); - const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Extension* dst_ext = UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( - dst, msg_ext->ext, arena); - if (!dst_ext) return NULL; - if (upb_MiniTableField_IsScalar(field)) { - if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { - return NULL; - } - } else { - upb_Array* msg_array = (upb_Array*)msg_ext->data.array_val; - UPB_ASSERT(msg_array); - upb_Array* cloned_array = upb_Array_DeepClone( - msg_array, upb_MiniTableField_CType(field), - upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); - if (!cloned_array) { - return NULL; - } - dst_ext->data.array_val = cloned_array; - } - } else if (upb_TaggedAuxPtr_IsUnknown(tagged_ptr)) { - // Clone unknown - upb_StringView* unknown = upb_TaggedAuxPtr_UnknownData(tagged_ptr); - // Make a copy into destination arena. - if (!UPB_PRIVATE(_upb_Message_AddUnknown)( - dst, unknown->data, unknown->size, arena, kUpb_AddUnknown_Copy)) { - return NULL; - } - } - } - - return dst; -} - -bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(dst)); - upb_Message_Clear(dst, mini_table); - return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; -} - -// Deep clones a message using the provided target arena. -// -// Returns NULL on failure. -upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - return _upb_Message_Copy(clone, msg, m, arena); -} - -// Performs a shallow copy. -bool upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m, upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(dst)); - memcpy(dst, src, m->UPB_PRIVATE(size)); - - const upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(src); - if (!in) return true; - - size_t size = UPB_SIZEOF_FLEX(upb_Message_Internal, aux_data, in->size); - upb_Message_Internal* dst_in = upb_Arena_Malloc(arena, size); - if (!dst_in) return false; - - dst_in->size = in->size; - dst_in->capacity = in->size; - - for (size_t i = 0; i < in->size; i++) { - upb_TaggedAux aux; - switch (upb_TaggedAux_Get(in->aux_data[i], &aux)) { - case kUpb_TaggedAuxType_Extension: { - const upb_Extension* msg_ext = aux.extension; - upb_Extension* dst_ext = upb_Arena_Malloc(arena, sizeof(upb_Extension)); - if (!dst_ext) return false; - *dst_ext = *msg_ext; - dst_in->aux_data[i] = upb_TaggedAuxPtr_MakeExtension(dst_ext); - break; - } - case kUpb_TaggedAuxType_Unknown: - case kUpb_TaggedAuxType_AliasedUnknown: { - upb_StringView* dst_sv = - upb_Arena_Malloc(arena, sizeof(upb_StringView)); - if (!dst_sv) return false; - *dst_sv = aux.unknown_data; - dst_in->aux_data[i] = upb_TaggedAuxPtr_MakeUnknownDataAliased(dst_sv); - break; - } - } - } - - UPB_PRIVATE(_upb_Message_SetInternal)(dst, dst_in); - return true; -} - -// Performs a shallow clone. -upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, - upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - if (!clone) return NULL; - if (!upb_Message_ShallowCopy(clone, msg, m, arena)) return NULL; - return clone; -} diff --git a/vendor/upb/message/copy.h b/vendor/upb/message/copy.h deleted file mode 100644 index 7802383..0000000 --- a/vendor/upb/message/copy.h +++ /dev/null @@ -1,69 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_COPY_H_ -#define UPB_MESSAGE_COPY_H_ - -#include "upb/base/descriptor_constants.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Deep clones a message using the provided target arena. -UPB_NODISCARD upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, - upb_Arena* arena); - -// Shallow clones a message using the provided target arena. -// `msg` must outlive the returned message since all strings, repeated fields, -// maps, and unknown fields will alias the original message. -UPB_NODISCARD upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, - upb_Arena* arena); - -// Deep clones array contents. -UPB_NODISCARD upb_Array* upb_Array_DeepClone(const upb_Array* array, - upb_CType value_type, - const upb_MiniTable* sub, - upb_Arena* arena); - -// Deep clones map contents. -UPB_NODISCARD upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena); - -// Deep copies the message from src to dst. -UPB_NODISCARD bool upb_Message_DeepCopy(upb_Message* dst, - const upb_Message* src, - const upb_MiniTable* m, - upb_Arena* arena); - -// Shallow copies the message from src to dst. -// `src` must outlive `dst` since all strings, repeated fields, maps, and -// unknown fields will alias the original message. -UPB_NODISCARD UPB_API bool upb_Message_ShallowCopy(upb_Message* dst, - const upb_Message* src, - const upb_MiniTable* m, - upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MESSAGE_COPY_H_ diff --git a/vendor/upb/message/copy_test.cc b/vendor/upb/message/copy_test.cc deleted file mode 100644 index 397d30e..0000000 --- a/vendor/upb/message/copy_test.cc +++ /dev/null @@ -1,536 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* Test of mini table accessors. - * - * Messages are created and mutated using generated code, and then - * accessed through reflective APIs exposed through mini table accessors. - */ - -#include "upb/message/copy.h" - -#include -#include -#include -#include -#include -#include - -#include -#include "google/protobuf/test_messages_proto2.upb.h" -#include "google/protobuf/test_messages_proto2.upb_minitable.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/test/test.upb.h" -#include "upb/test/test.upb_minitable.h" -#include "upb/wire/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace { - -// Proto2 test messages field numbers used for reflective access. -const uint32_t kFieldOptionalInt32 = 1; -const uint32_t kFieldOptionalString = 14; -const uint32_t kFieldOptionalNestedMessage = 18; - -const char kTestStr1[] = "Hello1"; -const char kTestStr2[] = "HelloWorld2"; -const int32_t kTestInt32 = 567; -const int32_t kTestNestedInt32 = 123; -const int32_t kTestNestedInt64 = 123456789; - -const upb_MiniTableField* find_proto2_field(int field_number) { - return upb_MiniTable_FindFieldByNumber( - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - field_number); -} - -TEST(GeneratedCode, DeepCloneMessageScalarAndString) { - upb_Arena* source_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(source_arena); - const upb_MiniTableField* optional_int32_field = - find_proto2_field(kFieldOptionalInt32); - const upb_MiniTableField* optional_string_field = - find_proto2_field(kFieldOptionalString); - upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32, - nullptr); - char* string_in_arena = - (char*)upb_Arena_Malloc(source_arena, sizeof(kTestStr1)); - memcpy(string_in_arena, kTestStr1, sizeof(kTestStr1)); - upb_Message_SetString( - UPB_UPCAST(msg), optional_string_field, - upb_StringView_FromDataAndSize(string_in_arena, sizeof(kTestStr1) - 1), - source_arena); - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* clone = - (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - arena); - // After cloning overwrite values and destroy source arena for MSAN. - memset(string_in_arena, 0, sizeof(kTestStr1)); - upb_Arena_Free(source_arena); - EXPECT_TRUE( - upb_Message_HasBaseField(UPB_UPCAST(clone), optional_int32_field)); - EXPECT_EQ(upb_Message_GetInt32(UPB_UPCAST(clone), optional_int32_field, 0), - kTestInt32); - EXPECT_TRUE( - upb_Message_HasBaseField(UPB_UPCAST(clone), optional_string_field)); - EXPECT_EQ(upb_Message_GetString(UPB_UPCAST(clone), optional_string_field, - upb_StringView_FromDataAndSize(nullptr, 0)) - .size, - sizeof(kTestStr1) - 1); - EXPECT_TRUE(upb_StringView_IsEqual( - upb_Message_GetString(UPB_UPCAST(clone), optional_string_field, - upb_StringView_FromDataAndSize(nullptr, 0)), - upb_StringView_FromString(kTestStr1))); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, DeepCloneMessageSubMessage) { - upb_Arena* source_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(source_arena); - const upb_MiniTableField* nested_message_field = - find_proto2_field(kFieldOptionalNestedMessage); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested = - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new( - source_arena); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( - nested, kTestNestedInt32); - upb_Message_SetMessage(UPB_UPCAST(msg), nested_message_field, - UPB_UPCAST(nested)); - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* clone = - (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - arena); - // After cloning overwrite values and destroy source arena for MSAN. - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested, - 0); - upb_Arena_Free(source_arena); - EXPECT_TRUE( - upb_Message_HasBaseField(UPB_UPCAST(clone), nested_message_field)); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* - cloned_nested = - (protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage*) - upb_Message_GetMessage(UPB_UPCAST(clone), nested_message_field); - EXPECT_EQ(protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_a( - cloned_nested), - kTestNestedInt32); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, DeepCloneMessageArrayField) { - upb_Arena* source_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(source_arena); - std::vector array_test_values = {3, 4, 5}; - for (int32_t value : array_test_values) { - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_add_repeated_int32( - msg, value, source_arena)); - } - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* clone = - (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - arena); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_repeated_sint32(msg); - upb_Arena_Free(source_arena); - size_t cloned_size = 0; - const int32_t* cloned_values = - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32( - clone, &cloned_size); - EXPECT_EQ(cloned_size, array_test_values.size()); - int index = 0; - for (int32_t value : array_test_values) { - EXPECT_EQ(cloned_values[index++], value); - } - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, DeepCloneMessageMapField) { - upb_Arena* source_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(source_arena); - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_bool_set( - msg, 0, true, source_arena)); - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_double_set( - msg, 12, 1200.5, source_arena)); - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_string_string_set( - msg, upb_StringView_FromString("key1"), - upb_StringView_FromString("value1"), source_arena)); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested = - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new( - source_arena); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( - nested, kTestNestedInt32); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested2 = - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new( - source_arena); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( - nested2, kTestNestedInt64); - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_nested_message_set( - msg, 1, nested2, source_arena)); - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_string_nested_message_set( - msg, upb_StringView_FromString("nestedkey1"), nested, source_arena)); - - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* clone = - (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - arena); - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested, - 0); - upb_Arena_Free(source_arena); - // Test map. - { - int32_t key; - bool value; - size_t iter = kUpb_Map_Begin; - - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_bool_next( - clone, &key, &value, &iter)); - EXPECT_EQ(key, 0); - EXPECT_EQ(value, true); - - ASSERT_FALSE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_bool_next( - clone, &key, &value, &iter)); - } - - // Test map. - { - int32_t key; - double value; - size_t iter = kUpb_Map_Begin; - - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_double_next( - clone, &key, &value, &iter)); - EXPECT_EQ(key, 12); - EXPECT_EQ(value, 1200.5); - - ASSERT_FALSE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_double_next( - clone, &key, &value, &iter)); - } - - // Test map. - { - int32_t key; - const protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* value; - size_t iter = kUpb_Map_Begin; - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_nested_message_next( - clone, &key, &value, &iter)); - EXPECT_EQ(key, 1); - ASSERT_NE(value, nullptr); - EXPECT_EQ( - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_a(value), - kTestNestedInt64); - ASSERT_FALSE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_nested_message_next( - clone, &key, &value, &iter)); - } - - // Test map. - { - upb_StringView key; - upb_StringView value; - size_t iter = kUpb_Map_Begin; - - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_string_string_next( - clone, &key, &value, &iter)); - EXPECT_TRUE(upb_StringView_IsEqual(key, upb_StringView_FromString("key1"))); - EXPECT_TRUE( - upb_StringView_IsEqual(value, upb_StringView_FromString("value1"))); - } - - // Test map. - { - upb_StringView key; - const protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* value; - size_t iter = kUpb_Map_Begin; - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_string_nested_message_next( - clone, &key, &value, &iter)); - EXPECT_TRUE( - upb_StringView_IsEqual(key, upb_StringView_FromString("nestedkey1"))); - ASSERT_NE(value, nullptr); - EXPECT_EQ( - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_a(value), - kTestNestedInt32); - } - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, DeepCloneMessageExtensions) { - // Alloc and fill in test message with extension. - upb_Arena* source_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect_new( - source_arena); - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1* - ext1 = - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1_new( - source_arena); - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1_set_str( - ext1, upb_StringView_FromString(kTestStr1)); - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1_set_message_set_extension( - msg, ext1, source_arena); - // Create clone. - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect* clone = - (protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect*) - upb_Message_DeepClone( - UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2__MessageSetCorrect_msg_init, - arena); - - // Mutate original extension. - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1_set_str( - ext1, upb_StringView_FromString(kTestStr2)); - upb_Arena_Free(source_arena); - - const protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1* - cloned_ext = - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1_message_set_extension( - clone); - ASSERT_NE(cloned_ext, nullptr); - EXPECT_TRUE(upb_StringView_IsEqual( - protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrectExtension1_str( - cloned_ext), - upb_StringView_FromString(kTestStr1))); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, DeepCloneMessageWithUnknowns) { - upb_Arena* source_arena = upb_Arena_New(); - upb_Arena* unknown_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(source_arena); - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_int32_double_set( - msg, 12, 1200.5, source_arena)); - ASSERT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_map_string_string_set( - msg, upb_StringView_FromString("key1"), - upb_StringView_FromString("value1"), source_arena)); - // Create unknown data. - protobuf_test_messages_proto2_UnknownToTestAllTypes* unknown_source = - protobuf_test_messages_proto2_UnknownToTestAllTypes_new(unknown_arena); - protobuf_test_messages_proto2_UnknownToTestAllTypes_set_optional_bool( - unknown_source, true); - protobuf_test_messages_proto2_UnknownToTestAllTypes_set_optional_int32( - unknown_source, 123); - // Encode unknown message to bytes. - size_t len; - char* data; - upb_Arena* encode_arena = upb_Arena_New(); - upb_EncodeStatus status = upb_Encode( - UPB_UPCAST(unknown_source), - &protobuf_0test_0messages__proto2__UnknownToTestAllTypes_msg_init, - kUpb_EncodeOption_CheckRequired, encode_arena, &data, &len); - ASSERT_EQ(status, kUpb_EncodeStatus_Ok); - std::string unknown_data(data, len); - // Add unknown data. - UPB_PRIVATE(_upb_Message_AddUnknown) - (UPB_UPCAST(msg), data, len, source_arena, kUpb_AddUnknown_Copy); - // Create clone. - upb_Arena* clone_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* clone = - (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - clone_arena); - upb_Arena_Free(source_arena); - upb_Arena_Free(unknown_arena); - upb_Arena_Free(encode_arena); - // Read unknown data from clone and verify. - std::string cloned_unknown_data; - upb_StringView unknown; - uintptr_t iter = kUpb_Message_UnknownBegin; - while (upb_Message_NextUnknown(UPB_UPCAST(clone), &unknown, &iter)) { - cloned_unknown_data.append(unknown.data, unknown.size); - } - EXPECT_EQ(unknown_data, cloned_unknown_data); - upb_Arena_Free(clone_arena); -} - -TEST(GeneratedCode, ShallowCopyMessage) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_int32( - msg, kTestInt32); - char* string_in_arena = (char*)upb_Arena_Malloc(arena, sizeof(kTestStr1)); - memcpy(string_in_arena, kTestStr1, sizeof(kTestStr1)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( - msg, - upb_StringView_FromDataAndSize(string_in_arena, sizeof(kTestStr1) - 1)); - - protobuf_test_messages_proto2_TestAllTypesProto2* dst = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - EXPECT_TRUE(upb_Message_ShallowCopy( - UPB_UPCAST(dst), UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, arena)); - - EXPECT_EQ( - protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(dst), - kTestInt32); - upb_StringView dst_str = - protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(dst); - EXPECT_EQ(dst_str.size, sizeof(kTestStr1) - 1); - EXPECT_EQ(dst_str.data, string_in_arena); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, ShallowCopyIncludesExtensions) { - upb_Arena* source_arena = upb_Arena_New(); - upb_test_ModelWithExtensions* msg = - upb_test_ModelWithExtensions_new(source_arena); - upb_test_ModelExtension1* ext1 = upb_test_ModelExtension1_new(source_arena); - upb_test_ModelExtension1_set_str(ext1, upb_StringView_FromString(kTestStr1)); - upb_test_ModelExtension1_set_model_ext(msg, ext1, source_arena); - - upb_Arena* arena = upb_Arena_New(); - upb_test_ModelWithExtensions* dst = upb_test_ModelWithExtensions_new(arena); - - EXPECT_TRUE(upb_Message_ShallowCopy(UPB_UPCAST(dst), UPB_UPCAST(msg), - &upb_0test__ModelWithExtensions_msg_init, - arena)); - - // Modifying extension in dst should NOT affect msg because extensions are - // copied. - upb_test_ModelExtension1* ext2 = upb_test_ModelExtension1_new(arena); - upb_test_ModelExtension1_set_str(ext2, upb_StringView_FromString(kTestStr2)); - - upb_test_ModelExtension1_set_model_ext(dst, ext2, arena); - - const upb_test_ModelExtension1* src_ext = - upb_test_ModelExtension1_model_ext(msg); - - EXPECT_EQ(UPB_UPCAST(src_ext), UPB_UPCAST(ext1)); - - const upb_test_ModelExtension1* dst_ext = - upb_test_ModelExtension1_model_ext(dst); - - EXPECT_EQ(UPB_UPCAST(dst_ext), UPB_UPCAST(ext2)); - - upb_Arena_Free(source_arena); - upb_Arena_Free(arena); -} - -std::vector GetUnknownFields(const upb_Message* msg) { - std::vector result; - upb_StringView data; - uintptr_t iter = kUpb_Message_UnknownBegin; - while (upb_Message_NextUnknown(msg, &data, &iter)) { - result.push_back(std::string_view(data.data, data.size)); - } - return result; -} - -TEST(GeneratedCode, ShallowCopyIncludesUnknowns) { - upb_Arena* source_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(source_arena); - - // Add some unknown data. - std::string_view unknown_data1 = - "\x08\x01"; // Field 1, wire type 0 (varint), value 1 - UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg), unknown_data1.data(), - unknown_data1.size(), source_arena, - kUpb_AddUnknown_Copy); - std::vector only_unknown_data1 = {unknown_data1}; - - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* dst = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - EXPECT_TRUE(upb_Message_ShallowCopy( - UPB_UPCAST(dst), UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, arena)); - - // Verify dst has the unknown data. - EXPECT_EQ(GetUnknownFields(UPB_UPCAST(dst)), only_unknown_data1); - - // Modify the unknown data view in dst to ensure it's a separate view. - // Use upb_Message_DeleteUnknown to delete a trailing part. - upb_StringView dst_data; - uintptr_t iter = kUpb_Message_UnknownBegin; - EXPECT_TRUE(upb_Message_NextUnknown(UPB_UPCAST(dst), &dst_data, &iter)); - upb_StringView to_delete; - to_delete.size = 1; - to_delete.data = dst_data.data + dst_data.size - to_delete.size; - upb_Message_DeleteUnknownStatus status = - upb_Message_DeleteUnknown(UPB_UPCAST(dst), &to_delete, &iter, arena); - EXPECT_EQ(status, kUpb_DeleteUnknown_DeletedLast); - - // Verify src still has the original data and size. - EXPECT_EQ(GetUnknownFields(UPB_UPCAST(msg)), only_unknown_data1); - - // Add MORE unknown data to dst. - std::string_view unknown_data2 = - "\x10\x02"; // Field 2, wire type 0 (varint), value 2 - UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(dst), unknown_data2.data(), - unknown_data2.size(), arena, - kUpb_AddUnknown_Copy); - - // Verify src still only has the first unknown data. - EXPECT_EQ(GetUnknownFields(UPB_UPCAST(msg)), only_unknown_data1); - - upb_Arena_Free(source_arena); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, ShallowCloneMessage) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_int32( - msg, kTestInt32); - - protobuf_test_messages_proto2_TestAllTypesProto2* clone = - (protobuf_test_messages_proto2_TestAllTypesProto2*) - upb_Message_ShallowClone( - UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - arena); - - EXPECT_EQ( - protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(clone), - kTestInt32); - - upb_Arena_Free(arena); -} - -} // namespace diff --git a/vendor/upb/message/internal/accessors.h b/vendor/upb/message/internal/accessors.h deleted file mode 100644 index 0307000..0000000 --- a/vendor/upb/message/internal/accessors.h +++ /dev/null @@ -1,1036 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ -#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/internal/endian.h" -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/message.h" -#include "upb/message/internal/types.h" -#include "upb/message/value.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#if defined(__GNUC__) && !defined(__clang__) -// GCC raises incorrect warnings in these functions. It thinks that we are -// overrunning buffers, but we carefully write the functions in this file to -// guarantee that this is impossible. GCC gets this wrong due it its failure -// to perform constant propagation as we expect: -// - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108217 -// - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108226 -// -// Unfortunately this also indicates that GCC is not optimizing away the -// switch() in cases where it should be, compromising the performance. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" -#pragma GCC diagnostic ignored "-Wstringop-overflow" -#if __GNUC__ >= 11 -#pragma GCC diagnostic ignored "-Wstringop-overread" -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -// LINT.IfChange(presence_logic) - -// Hasbit access /////////////////////////////////////////////////////////////// - -UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( - const struct upb_Message* msg, const upb_MiniTableField* f) { - const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); - const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); - - return (*UPB_PTR_AT(msg, offset, const char) & mask) != 0; -} - -UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( - const struct upb_Message* msg, const upb_MiniTableField* f) { - const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); - const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); - - (*UPB_PTR_AT(msg, offset, char)) |= mask; -} - -UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( - const struct upb_Message* msg, const upb_MiniTableField* f) { - const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); - const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); - - (*UPB_PTR_AT(msg, offset, char)) &= ~mask; -} - -// Oneof case access /////////////////////////////////////////////////////////// - -UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( - struct upb_Message* msg, const upb_MiniTableField* f) { - return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f), - uint32_t); -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( - const struct upb_Message* msg, const upb_MiniTableField* f) { - const uint32_t* ptr = - UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); - - return *ptr; -} - -UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( - struct upb_Message* msg, const upb_MiniTableField* f) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); - - *ptr = upb_MiniTableField_Number(f); -} - -// Returns true if the given field is the current oneof case. -// Does nothing if it is not the current oneof case. -UPB_INLINE bool UPB_PRIVATE(_upb_Message_ClearOneofCase)( - struct upb_Message* msg, const upb_MiniTableField* f) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); - - if (*ptr != upb_MiniTableField_Number(f)) return false; - *ptr = 0; - return true; -} - -UPB_API_INLINE uint32_t upb_Message_WhichOneofFieldNumber( - const struct upb_Message* message, const upb_MiniTableField* oneof_field) { - UPB_ASSUME(upb_MiniTableField_IsInOneof(oneof_field)); - return UPB_PRIVATE(_upb_Message_GetOneofCase)(message, oneof_field); -} - -UPB_API_INLINE const upb_MiniTableField* upb_Message_WhichOneof( - const struct upb_Message* msg, const upb_MiniTable* m, - const upb_MiniTableField* f) { - uint32_t field_number = upb_Message_WhichOneofFieldNumber(msg, f); - if (field_number == 0) { - // No field in the oneof is set. - return NULL; - } - return upb_MiniTable_FindFieldByNumber(m, field_number); -} - -// LINT.ThenChange(GoogleInternalName2) - -// Returns false if the message is missing any of its required fields. -UPB_INLINE bool UPB_PRIVATE(_upb_Message_IsInitializedShallow)( - const struct upb_Message* msg, const upb_MiniTable* m) { - uint64_t bits; - memcpy(&bits, msg + 1, sizeof(bits)); - bits = upb_BigEndian64(bits); - return (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~bits) == 0; -} - -UPB_INLINE void* UPB_PRIVATE(_upb_Message_MutableDataPtr)( - struct upb_Message* msg, const upb_MiniTableField* f) { - return (char*)msg + f->UPB_ONLYBITS(offset); -} - -UPB_INLINE const void* UPB_PRIVATE(_upb_Message_DataPtr)( - const struct upb_Message* msg, const upb_MiniTableField* f) { - return (const char*)msg + f->UPB_ONLYBITS(offset); -} - -UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( - struct upb_Message* msg, const upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { - UPB_PRIVATE(_upb_Message_SetHasbit)(msg, f); - } else if (upb_MiniTableField_IsInOneof(f)) { - UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, f); - } -} - -UPB_INLINE_IF_NOT_GCC void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( - const upb_MiniTableField* f, void* to, const void* from) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { - case kUpb_FieldRep_1Byte: - memcpy(to, from, 1); - return; - case kUpb_FieldRep_4Byte: - memcpy(to, from, 4); - return; - case kUpb_FieldRep_8Byte: - memcpy(to, from, 8); - return; - case kUpb_FieldRep_StringView: { - memcpy(to, from, sizeof(upb_StringView)); - return; - } - } - UPB_UNREACHABLE(); -} - -UPB_INLINE_IF_NOT_GCC bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( - const upb_MiniTableField* f, const void* a, const void* b) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { - case kUpb_FieldRep_1Byte: - return memcmp(a, b, 1) == 0; - case kUpb_FieldRep_4Byte: - return memcmp(a, b, 4) == 0; - case kUpb_FieldRep_8Byte: - return memcmp(a, b, 8) == 0; - case kUpb_FieldRep_StringView: { - const upb_StringView sa = *(const upb_StringView*)a; - const upb_StringView sb = *(const upb_StringView*)b; - return upb_StringView_IsEqual(sa, sb); - } - } - UPB_UNREACHABLE(); -} - -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataClear)( - const upb_MiniTableField* f, void* val) { - const char zero[16] = {0}; - UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, zero); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( - const upb_MiniTableField* f, const void* val) { - const char zero[16] = {0}; - return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(f, val, zero); -} - -// Here we define universal getter/setter functions for message fields. -// These look very branchy and inefficient, but as long as the MiniTableField -// values are known at compile time, all the branches are optimized away and -// we are left with ideal code. This can happen either through through -// literals or UPB_ASSUME(): -// -// // Via struct literals. -// bool FooMessage_set_bool_field(const upb_Message* msg, bool val) { -// const upb_MiniTableField field = {1, 0, 0, /* etc... */}; -// // All value in "field" are compile-time known. -// upb_Message_SetBaseField(msg, &field, &value); -// } -// -// // Via UPB_ASSUME(). -// UPB_INLINE bool upb_Message_SetBool(upb_Message* msg, -// const upb_MiniTableField* field, -// bool value, upb_Arena* a) { -// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool); -// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == -// kUpb_FieldRep_1Byte); -// upb_Message_SetField(msg, field, &value, a); -// } -// -// As a result, we can use these universal getters/setters for *all* message -// accessors: generated code, MiniTable accessors, and reflection. The only -// exception is the binary encoder/decoder, which need to be a bit more clever -// about how they read/write the message data, for efficiency. -// -// These functions work on both extensions and non-extensions. If the field -// of a setter is known to be a non-extension, the arena may be NULL and the -// returned bool value may be ignored since it will always succeed. - -UPB_API_INLINE bool upb_Message_HasBaseField(const struct upb_Message* msg, - const upb_MiniTableField* field) { - UPB_ASSERT(upb_MiniTableField_HasPresence(field)); - UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); - if (upb_MiniTableField_IsInOneof(field)) { - return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, field) == - upb_MiniTableField_Number(field); - } else { - return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, field); - } -} - -UPB_API_INLINE bool upb_Message_HasExtension(const struct upb_Message* msg, - const upb_MiniTableExtension* e) { - UPB_ASSERT(upb_MiniTableField_HasPresence(&e->UPB_PRIVATE(field))); - return UPB_PRIVATE(_upb_Message_Getext)(msg, e) != NULL; -} - -UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( - const struct upb_Message* msg, const upb_MiniTableField* field, - const void* default_val, void* val) { - UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); - if ((upb_MiniTableField_IsInOneof(field) || - !UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, default_val)) && - !upb_Message_HasBaseField(msg, field)) { - UPB_PRIVATE(_upb_MiniTableField_DataCopy)(field, val, default_val); - return; - } - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, val, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field)); -} - -UPB_INLINE void _upb_Message_GetExtensionField( - const struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, - const void* default_val, void* val) { - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getext)(msg, mt_ext); - const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); - UPB_ASSUME(upb_MiniTableField_IsExtension(f)); - - if (ext) { - UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, &ext->data); - } else { - UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, default_val); - } -} - -// NOTE: The default_val is only used for fields that support presence. -// For repeated/map fields, the resulting upb_Array*/upb_Map* can be NULL if a -// upb_Array/upb_Map has not been allocated yet. Array/map fields do not have -// presence, so this is semantically identical to a pointer to an empty -// array/map, and must be treated the same for all semantic purposes. -UPB_API_INLINE upb_MessageValue upb_Message_GetField( - const struct upb_Message* msg, const upb_MiniTableField* field, - upb_MessageValue default_val) { - upb_MessageValue ret; - if (upb_MiniTableField_IsExtension(field)) { - _upb_Message_GetExtensionField(msg, (upb_MiniTableExtension*)field, - &default_val, &ret); - } else { - _upb_Message_GetNonExtensionField(msg, field, &default_val, &ret); - } - return ret; -} - -UPB_API_INLINE void upb_Message_SetBaseField(struct upb_Message* msg, - const upb_MiniTableField* f, - const void* val) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - UPB_ASSUME(!upb_MiniTableField_IsExtension(f)); - UPB_PRIVATE(_upb_Message_SetPresence)(msg, f); - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (f, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, f), val); -} - -UPB_API_INLINE bool upb_Message_SetExtension(struct upb_Message* msg, - const upb_MiniTableExtension* e, - const void* val, upb_Arena* a) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - UPB_ASSERT(a); - upb_Extension* ext = - UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(msg, e, a); - if (!ext) return false; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (&e->UPB_PRIVATE(field), &ext->data, val); - return true; -} - -// Sets the value of the given field in the given msg. The return value is true -// if the operation completed successfully, or false if memory allocation -// failed. -UPB_INLINE bool UPB_PRIVATE(_upb_Message_SetField)(struct upb_Message* msg, - const upb_MiniTableField* f, - upb_MessageValue val, - upb_Arena* a) { - if (upb_MiniTableField_IsExtension(f)) { - const upb_MiniTableExtension* ext = (const upb_MiniTableExtension*)f; - return upb_Message_SetExtension(msg, ext, &val, a); - } else { - upb_Message_SetBaseField(msg, f, &val); - return true; - } -} - -UPB_API_INLINE const upb_Array* upb_Message_GetArray( - const struct upb_Message* msg, const upb_MiniTableField* f) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f); - upb_Array* ret; - const upb_Array* default_val = NULL; - _upb_Message_GetNonExtensionField(msg, f, &default_val, &ret); - return ret; -} - -UPB_API_INLINE bool upb_Message_GetBool(const struct upb_Message* msg, - const upb_MiniTableField* f, - bool default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte); - upb_MessageValue def; - def.bool_val = default_val; - return upb_Message_GetField(msg, f, def).bool_val; -} - -UPB_API_INLINE double upb_Message_GetDouble(const struct upb_Message* msg, - const upb_MiniTableField* f, - double default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte); - - upb_MessageValue def; - def.double_val = default_val; - return upb_Message_GetField(msg, f, def).double_val; -} - -UPB_API_INLINE float upb_Message_GetFloat(const struct upb_Message* msg, - const upb_MiniTableField* f, - float default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte); - - upb_MessageValue def; - def.float_val = default_val; - return upb_Message_GetField(msg, f, def).float_val; -} - -UPB_API_INLINE int32_t upb_Message_GetInt32(const struct upb_Message* msg, - const upb_MiniTableField* f, - int32_t default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 || - upb_MiniTableField_CType(f) == kUpb_CType_Enum); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte); - - upb_MessageValue def; - def.int32_val = default_val; - return upb_Message_GetField(msg, f, def).int32_val; -} - -UPB_API_INLINE int64_t upb_Message_GetInt64(const struct upb_Message* msg, - const upb_MiniTableField* f, - int64_t default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte); - - upb_MessageValue def; - def.int64_val = default_val; - return upb_Message_GetField(msg, f, def).int64_val; -} - -UPB_API_INLINE const struct upb_Map* upb_Message_GetMap( - const struct upb_Message* msg, const upb_MiniTableField* f) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(f); - struct upb_Map* ret; - const struct upb_Map* default_val = NULL; - _upb_Message_GetNonExtensionField(msg, f, &default_val, &ret); - return ret; -} - -UPB_API_INLINE const struct upb_Message* upb_Message_GetMessage( - const struct upb_Message* msg, const upb_MiniTableField* f) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - upb_MessageValue def; - def.msg_val = NULL; - return upb_Message_GetField(msg, f, def).msg_val; -} - -UPB_API_INLINE upb_Array* upb_Message_GetMutableArray( - struct upb_Message* msg, const upb_MiniTableField* f) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f); - return (upb_Array*)upb_Message_GetArray(msg, f); -} - -UPB_API_INLINE struct upb_Map* upb_Message_GetMutableMap( - struct upb_Message* msg, const upb_MiniTableField* f) { - return (struct upb_Map*)upb_Message_GetMap(msg, f); -} - -UPB_API_INLINE struct upb_Message* upb_Message_GetMutableMessage( - struct upb_Message* msg, const upb_MiniTableField* f) { - return (struct upb_Message*)upb_Message_GetMessage(msg, f); -} - -UPB_NODISCARD UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( - struct upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena) { - UPB_ASSERT(arena); - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f); - upb_Array* array = upb_Message_GetMutableArray(msg, f); - if (!array) { - array = UPB_PRIVATE(_upb_Array_New)( - arena, 4, UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(f)); - // Check again due to: https://godbolt.org/z/7WfaoKG1r - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f); - upb_MessageValue val; - val.array_val = array; - UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, arena); - } - return array; -} - -UPB_NODISCARD UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( - struct upb_Message* msg, const upb_MiniTableField* field, size_t key_size, - size_t val_size, upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); - struct upb_Map* map = NULL; - struct upb_Map* default_map_value = NULL; - _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); - if (!map) { - map = _upb_Map_New(arena, key_size, val_size); - // Check again due to: https://godbolt.org/z/7WfaoKG1r - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); - upb_Message_SetBaseField(msg, field, &map); - } - return map; -} - -UPB_NODISCARD UPB_API_INLINE struct upb_Map* upb_Message_GetOrCreateMutableMap( - struct upb_Message* msg, const upb_MiniTable* map_entry_mini_table, - const upb_MiniTableField* f, upb_Arena* arena) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message); - const upb_MiniTableField* map_entry_key_field = - &map_entry_mini_table->UPB_ONLYBITS(fields)[0]; - const upb_MiniTableField* map_entry_value_field = - &map_entry_mini_table->UPB_ONLYBITS(fields)[1]; - return _upb_Message_GetOrCreateMutableMap( - msg, f, _upb_Map_CTypeSize(upb_MiniTableField_CType(map_entry_key_field)), - _upb_Map_CTypeSize(upb_MiniTableField_CType(map_entry_value_field)), - arena); -} - -UPB_NODISCARD UPB_API_INLINE struct upb_Message* -upb_Message_GetOrCreateMutableMessage(struct upb_Message* msg, - const upb_MiniTableField* f, - upb_Arena* arena) { - UPB_ASSERT(arena); - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message); - UPB_ASSUME(!upb_MiniTableField_IsExtension(f)); - struct upb_Message* sub_message = - *UPB_PTR_AT(msg, f->UPB_ONLYBITS(offset), struct upb_Message*); - if (!sub_message) { - const upb_MiniTable* sub_mini_table = upb_MiniTable_SubMessage(f); - UPB_ASSERT(sub_mini_table); - sub_message = _upb_Message_New(sub_mini_table, arena); - *UPB_PTR_AT(msg, f->UPB_ONLYBITS(offset), struct upb_Message*) = - sub_message; - UPB_PRIVATE(_upb_Message_SetPresence)(msg, f); - } - return sub_message; -} - -UPB_API_INLINE upb_StringView -upb_Message_GetString(const struct upb_Message* msg, - const upb_MiniTableField* f, upb_StringView default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String || - upb_MiniTableField_CType(f) == kUpb_CType_Bytes); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_StringView); - - upb_MessageValue def; - def.str_val = default_val; - return upb_Message_GetField(msg, f, def).str_val; -} - -UPB_API_INLINE uint32_t upb_Message_GetUInt32(const struct upb_Message* msg, - const upb_MiniTableField* f, - uint32_t default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte); - - upb_MessageValue def; - def.uint32_val = default_val; - return upb_Message_GetField(msg, f, def).uint32_val; -} - -UPB_API_INLINE uint64_t upb_Message_GetUInt64(const struct upb_Message* msg, - const upb_MiniTableField* f, - uint64_t default_val) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte); - - upb_MessageValue def; - def.uint64_val = default_val; - return upb_Message_GetField(msg, f, def).uint64_val; -} - -// BaseField Setters /////////////////////////////////////////////////////////// - -UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg, - const upb_MiniTableField* f, - bool value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg, - const upb_MiniTableField* f, - double value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg, - const upb_MiniTableField* f, - float value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg, - const upb_MiniTableField* f, - int32_t value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 || - upb_MiniTableField_CType(f) == kUpb_CType_Enum); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg, - const upb_MiniTableField* f, - int64_t value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldMessage(struct upb_Message* msg, - const upb_MiniTableField* f, - struct upb_Message* value) { - // TODO - Re-enable this assertion. - // UPB_ASSERT(value); - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg, - const upb_MiniTableField* f, - upb_StringView value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String || - upb_MiniTableField_CType(f) == kUpb_CType_Bytes); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_StringView); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg, - const upb_MiniTableField* f, - uint32_t value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg, - const upb_MiniTableField* f, - uint64_t value) { - UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64); - UPB_ASSUME(upb_MiniTableField_IsScalar(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte); - upb_Message_SetBaseField(msg, f, &value); -} - -UPB_API_INLINE void upb_Message_SetClosedEnum(struct upb_Message* msg, - const upb_MiniTableField* f, - int32_t value) { - UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte); - UPB_ASSERT(upb_MiniTableEnum_CheckValue(upb_MiniTable_GetSubEnumTable(f), - (uint32_t)value)); - upb_Message_SetBaseField(msg, f, &value); -} - -// Extension Setters /////////////////////////////////////////////////////////// - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionMessage( - struct upb_Message* msg, const upb_MiniTableExtension* e, - struct upb_Message* value, upb_Arena* a) { - UPB_ASSERT(value); - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Message); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionBool( - struct upb_Message* msg, const upb_MiniTableExtension* e, bool value, - upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_1Byte); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionDouble( - struct upb_Message* msg, const upb_MiniTableExtension* e, double value, - upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_8Byte); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionFloat( - struct upb_Message* msg, const upb_MiniTableExtension* e, float value, - upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_4Byte); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionInt32( - struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value, - upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 || - upb_MiniTableExtension_CType(e) == kUpb_CType_Enum); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_4Byte); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionInt64( - struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value, - upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_8Byte); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionString( - struct upb_Message* msg, const upb_MiniTableExtension* e, - upb_StringView value, upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String || - upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_StringView); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionUInt32( - struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value, - upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_4Byte); - return upb_Message_SetExtension(msg, e, &value, a); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetExtensionUInt64( - struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value, - upb_Arena* a) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_8Byte); - return upb_Message_SetExtension(msg, e, &value, a); -} - -// Universal Setters /////////////////////////////////////////////////////////// - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetBool( - struct upb_Message* msg, const upb_MiniTableField* f, bool value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionBool( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldBool(msg, f, value), true); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetDouble( - struct upb_Message* msg, const upb_MiniTableField* f, double value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionDouble( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldDouble(msg, f, value), true); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetFloat( - struct upb_Message* msg, const upb_MiniTableField* f, float value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionFloat( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldFloat(msg, f, value), true); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetInt32( - struct upb_Message* msg, const upb_MiniTableField* f, int32_t value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionInt32( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldInt32(msg, f, value), true); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetInt64( - struct upb_Message* msg, const upb_MiniTableField* f, int64_t value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionInt64( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldInt64(msg, f, value), true); -} - -// Sets the value of a message-typed field. The mini_tables of `msg` and -// `value` must have been linked for this to work correctly. -UPB_API_INLINE void upb_Message_SetMessage(struct upb_Message* msg, - const upb_MiniTableField* f, - struct upb_Message* value) { - UPB_ASSERT(!upb_MiniTableField_IsExtension(f)); - upb_Message_SetBaseFieldMessage(msg, f, value); -} - -// Sets the value of a `string` or `bytes` field. The bytes of the value are not -// copied, so it is the caller's responsibility to ensure that they remain valid -// for the lifetime of `msg`. That might be done by copying them into the given -// arena, or by fusing that arena with the arena the bytes live in, for example. -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetString( - struct upb_Message* msg, const upb_MiniTableField* f, upb_StringView value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionString( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldString(msg, f, value), true); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetUInt32( - struct upb_Message* msg, const upb_MiniTableField* f, uint32_t value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionUInt32( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldUInt32(msg, f, value), true); -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Message_SetUInt64( - struct upb_Message* msg, const upb_MiniTableField* f, uint64_t value, - upb_Arena* a) { - return upb_MiniTableField_IsExtension(f) - ? upb_Message_SetExtensionUInt64( - msg, (const upb_MiniTableExtension*)f, value, a) - : (upb_Message_SetBaseFieldUInt64(msg, f, value), true); -} - -UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg, - const upb_MiniTable* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - memset(msg, 0, m->UPB_PRIVATE(size)); - if (in) { - // Reset the internal buffer to empty. - in->size = 0; - } -} - -UPB_API_INLINE void upb_Message_ClearBaseField(struct upb_Message* msg, - const upb_MiniTableField* f) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); - } else if (upb_MiniTableField_IsInOneof(f)) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); - if (*ptr != upb_MiniTableField_Number(f)) return; - *ptr = 0; - } - const char zeros[16] = {0}; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (f, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, f), zeros); -} - -UPB_API_INLINE void upb_Message_ClearExtension( - struct upb_Message* msg, const upb_MiniTableExtension* e) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) return; - for (size_t i = 0; i < in->size; i++) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i]; - if (upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - const upb_Extension* ext = upb_TaggedAuxPtr_Extension(tagged_ptr); - if (ext->ext == e) { - in->aux_data[i] = upb_TaggedAuxPtr_Null(); - return; - } - } - } -} - -UPB_API_INLINE void upb_Message_ClearOneof(struct upb_Message* msg, - const upb_MiniTable* m, - const upb_MiniTableField* f) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - uint32_t field_number = upb_Message_WhichOneofFieldNumber(msg, f); - if (field_number == 0) { - // No field in the oneof is set. - return; - } - - const upb_MiniTableField* field = - upb_MiniTable_FindFieldByNumber(m, field_number); - upb_Message_ClearBaseField(msg, field); -} - -UPB_NODISCARD UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized( - struct upb_Message* msg, const upb_MiniTableField* f, size_t size, - upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, f, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)(arr, size, arena)) { - return NULL; - } - return upb_Array_MutableDataPtr(arr); -} - -UPB_API_INLINE bool upb_Message_GetExtensionBool( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - bool default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_1Byte); - bool ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE double upb_Message_GetExtensionDouble( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - double default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_8Byte); - double ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE float upb_Message_GetExtensionFloat( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - float default_val) { - float ret; - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_4Byte); - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE int32_t upb_Message_GetExtensionInt32( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - int32_t default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 || - upb_MiniTableExtension_CType(e) == kUpb_CType_Enum); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_4Byte); - int32_t ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE int64_t upb_Message_GetExtensionInt64( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - int64_t default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_8Byte); - int64_t ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE uint32_t upb_Message_GetExtensionUInt32( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - uint32_t default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_4Byte); - uint32_t ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE uint64_t upb_Message_GetExtensionUInt64( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - uint64_t default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_8Byte); - uint64_t ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE upb_StringView upb_Message_GetExtensionString( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - upb_StringView default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String || - upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - kUpb_FieldRep_StringView); - upb_StringView ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE struct upb_Message* upb_Message_GetExtensionMessage( - const struct upb_Message* msg, const upb_MiniTableExtension* e, - struct upb_Message* default_val) { - UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Message); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) == - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - struct upb_Message* ret; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -// Repeated -UPB_API_INLINE const upb_Array* upb_Message_GetExtensionArray( - const struct upb_Message* msg, const upb_MiniTableExtension* e) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field)) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_MiniTableField_IsArray(&e->UPB_PRIVATE(field))); - UPB_ASSUME(e->UPB_PRIVATE(field).presence == 0); - upb_Array* ret; - const upb_Array* default_val = NULL; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -UPB_API_INLINE upb_Array* upb_Message_GetExtensionMutableArray( - struct upb_Message* msg, const upb_MiniTableExtension* e) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field)) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_MiniTableField_IsArray(&e->UPB_PRIVATE(field))); - UPB_ASSUME(e->UPB_PRIVATE(field).presence == 0); - upb_Array* ret; - upb_Array* default_val = NULL; - _upb_Message_GetExtensionField(msg, e, &default_val, &ret); - return ret; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_ diff --git a/vendor/upb/message/internal/array.h b/vendor/upb/message/internal/array.h deleted file mode 100644 index 07782d8..0000000 --- a/vendor/upb/message/internal/array.h +++ /dev/null @@ -1,176 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ -#define UPB_MESSAGE_INTERNAL_ARRAY_H_ - -#include -#include - -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. -#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. -#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) - -#ifdef __cplusplus -extern "C" { -#endif - -// LINT.IfChange(upb_Array) - -// Our internal representation for repeated fields. -struct upb_Array { - // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: - // 0 maps to elem size 1 - // 1 maps to elem size 4 - // 2 maps to elem size 8 - // 3 maps to elem size 16 - // - // Bit #2 contains the frozen/immutable flag. - uintptr_t UPB_ONLYBITS(data); - - size_t UPB_ONLYBITS(size); // The number of elements in the array. - size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. -}; - -UPB_INLINE void UPB_PRIVATE(_upb_Array_ShallowFreeze)(struct upb_Array* arr) { - arr->UPB_ONLYBITS(data) |= _UPB_ARRAY_MASK_IMM; -} - -UPB_API_INLINE bool upb_Array_IsFrozen(const struct upb_Array* arr) { - return (arr->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_IMM) != 0; -} - -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, - void* data, size_t lg2) { - UPB_ASSERT(lg2 != 1); - UPB_ASSERT(lg2 <= 4); - const size_t bits = lg2 - (lg2 != 0); - array->UPB_ONLYBITS(data) = (uintptr_t)data | bits; -} - -UPB_INLINE size_t -UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2; - const size_t lg2 = bits + (bits != 0); - return lg2; -} - -UPB_API_INLINE const void* upb_Array_DataPtr(const struct upb_Array* array) { - UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); -} - -UPB_API_INLINE void* upb_Array_MutableDataPtr(struct upb_Array* array) { - return (void*)upb_Array_DataPtr(array); -} - -UPB_NODISCARD UPB_INLINE struct upb_Array* UPB_PRIVATE( - _upb_Array_NewMaybeAllowSlow)(upb_Arena* arena, size_t init_capacity, - int elem_size_lg2, bool allow_slow) { - UPB_ASSERT(elem_size_lg2 != 1); - UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = - UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = array_size + (init_capacity << elem_size_lg2); - size_t span = UPB_PRIVATE(_upb_Arena_AllocSpan)(bytes); - if (!allow_slow && UPB_PRIVATE(_upb_ArenaHas)(arena) < span) return NULL; - struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); - if (!array) return NULL; - UPB_PRIVATE(_upb_Array_SetTaggedPtr) - (array, UPB_PTR_AT(array, array_size, void), (size_t)elem_size_lg2); - array->UPB_ONLYBITS(size) = 0; - array->UPB_PRIVATE(capacity) = init_capacity; - return array; -} - -UPB_NODISCARD UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)( - upb_Arena* arena, size_t init_capacity, int elem_size_lg2) { - return UPB_PRIVATE(_upb_Array_NewMaybeAllowSlow)(arena, init_capacity, - elem_size_lg2, true); -} - -UPB_NODISCARD UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_TryFastNew)( - upb_Arena* arena, size_t init_capacity, int elem_size_lg2) { - return UPB_PRIVATE(_upb_Array_NewMaybeAllowSlow)(arena, init_capacity, - elem_size_lg2, false); -} - -// Resizes the capacity of the array to be at least min_size. -UPB_NODISCARD bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, - size_t min_size, - upb_Arena* arena); - -UPB_NODISCARD UPB_FORCEINLINE bool UPB_PRIVATE(_upb_Array_TryFastRealloc)( - struct upb_Array* array, size_t capacity, int elem_size_lg2, - upb_Arena* arena) { - size_t old_bytes = array->UPB_PRIVATE(capacity) << elem_size_lg2; - size_t new_bytes = capacity << elem_size_lg2; - UPB_ASSUME(new_bytes > old_bytes); - if (!upb_Arena_TryExtend(arena, array, old_bytes, new_bytes)) return false; - array->UPB_PRIVATE(capacity) = capacity; - return true; -} - -UPB_NODISCARD UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, - size_t size, - upb_Arena* arena) { - UPB_ASSERT(!upb_Array_IsFrozen(array)); - if (array->UPB_PRIVATE(capacity) < size) - return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); - return true; -} - -// Resize without initializing new elements. -UPB_NODISCARD UPB_INLINE bool UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - struct upb_Array* array, size_t size, upb_Arena* arena) { - UPB_ASSERT(!upb_Array_IsFrozen(array)); - UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || - arena); // Allow NULL arena when shrinking. - if (!upb_Array_Reserve(array, size, arena)) return false; - array->UPB_ONLYBITS(size) = size; - return true; -} - -// This function is intended for situations where elem_size is compile-time -// constant or a known expression of the form (1 << lg2), so that the expression -// i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, - const void* data, - size_t elem_size) { - UPB_ASSERT(!upb_Array_IsFrozen(array)); - UPB_ASSERT(i < array->UPB_ONLYBITS(size)); - UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); - char* arr_data = (char*)upb_Array_MutableDataPtr(array); - memcpy(arr_data + (i * elem_size), data, elem_size); -} - -UPB_API_INLINE size_t upb_Array_Size(const struct upb_Array* arr) { - return arr->UPB_ONLYBITS(size); -} - -UPB_API_INLINE size_t upb_Array_Capacity(const struct upb_Array* arr) { - return arr->UPB_PRIVATE(capacity); -} - -// LINT.ThenChange(GoogleInternalName0) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#undef _UPB_ARRAY_MASK_IMM -#undef _UPB_ARRAY_MASK_LG2 -#undef _UPB_ARRAY_MASK_ALL - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ diff --git a/vendor/upb/message/internal/compare_unknown.c b/vendor/upb/message/internal/compare_unknown.c deleted file mode 100644 index d784f04..0000000 --- a/vendor/upb/message/internal/compare_unknown.c +++ /dev/null @@ -1,351 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/internal/compare_unknown.h" - -#include -#include - -#include "upb/base/string_view.h" -#include "upb/mem/alloc.h" -#include "upb/message/message.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/reader.h" -#include "upb/wire/types.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_UnknownFields upb_UnknownFields; - -typedef struct { - uint32_t tag; - union { - uint64_t varint; - uint64_t uint64; - uint32_t uint32; - upb_StringView delimited; - upb_UnknownFields* group; - } data; -} upb_UnknownField; - -struct upb_UnknownFields { - size_t size; - size_t capacity; - upb_UnknownField* fields; -}; - -typedef struct { - upb_EpsCopyInputStream stream; - upb_Arena* arena; - upb_UnknownField* tmp; - size_t tmp_size; - int depth; - upb_UnknownCompareResult status; - jmp_buf err; -} upb_UnknownField_Context; - -typedef struct { - upb_UnknownField* arr_base; - upb_UnknownField* arr_ptr; - upb_UnknownField* arr_end; - uint32_t last_tag; - bool sorted; -} upb_UnknownFields_Builder; - -UPB_NORETURN static void upb_UnknownFields_OutOfMemory( - upb_UnknownField_Context* ctx) { - ctx->status = kUpb_UnknownCompareResult_OutOfMemory; - UPB_LONGJMP(ctx->err, 1); -} - -static void upb_UnknownFields_Grow(upb_UnknownField_Context* ctx, - upb_UnknownField** base, - upb_UnknownField** ptr, - upb_UnknownField** end) { - size_t old = (*ptr - *base); - size_t new = UPB_MAX(4, old * 2); - - *base = upb_Arena_Realloc(ctx->arena, *base, old * sizeof(**base), - new * sizeof(**base)); - if (!*base) upb_UnknownFields_OutOfMemory(ctx); - - *ptr = *base + old; - *end = *base + new; -} - -// We have to implement our own sort here, since qsort() is not an in-order -// sort. Here we use merge sort, the simplest in-order sort. -static void upb_UnknownFields_Merge(upb_UnknownField* arr, size_t start, - size_t mid, size_t end, - upb_UnknownField* tmp) { - memcpy(tmp, &arr[start], (end - start) * sizeof(*tmp)); - - upb_UnknownField* ptr1 = tmp; - upb_UnknownField* end1 = &tmp[mid - start]; - upb_UnknownField* ptr2 = &tmp[mid - start]; - upb_UnknownField* end2 = &tmp[end - start]; - upb_UnknownField* out = &arr[start]; - - while (ptr1 < end1 && ptr2 < end2) { - if (ptr1->tag <= ptr2->tag) { - *out++ = *ptr1++; - } else { - *out++ = *ptr2++; - } - } - - if (ptr1 < end1) { - memcpy(out, ptr1, (end1 - ptr1) * sizeof(*out)); - } else if (ptr2 < end2) { - memcpy(out, ptr1, (end2 - ptr2) * sizeof(*out)); - } -} - -static void upb_UnknownFields_SortRecursive(upb_UnknownField* arr, size_t start, - size_t end, upb_UnknownField* tmp) { - if (end - start > 1) { - size_t mid = start + ((end - start) / 2); - upb_UnknownFields_SortRecursive(arr, start, mid, tmp); - upb_UnknownFields_SortRecursive(arr, mid, end, tmp); - upb_UnknownFields_Merge(arr, start, mid, end, tmp); - } -} - -static void upb_UnknownFields_Sort(upb_UnknownField_Context* ctx, - upb_UnknownFields* fields) { - if (ctx->tmp_size < fields->size) { - const int oldsize = ctx->tmp_size * sizeof(*ctx->tmp); - ctx->tmp_size = UPB_MAX(8, ctx->tmp_size); - while (ctx->tmp_size < fields->size) ctx->tmp_size *= 2; - const int newsize = ctx->tmp_size * sizeof(*ctx->tmp); - ctx->tmp = upb_grealloc(ctx->tmp, oldsize, newsize); - } - upb_UnknownFields_SortRecursive(fields->fields, 0, fields->size, ctx->tmp); -} - -static upb_UnknownFields* upb_UnknownFields_BuildFromBuffer( - upb_UnknownField_Context* ctx, const char** buf); - -// Combines two unknown fields into one. -static void upb_CombineUnknownFields(upb_UnknownField_Context* ctx, - upb_UnknownFields_Builder* builder, - const char** buf) { - upb_UnknownField* arr_base = builder->arr_base; - upb_UnknownField* arr_ptr = builder->arr_ptr; - upb_UnknownField* arr_end = builder->arr_end; - const char* ptr = *buf; - uint32_t last_tag = builder->last_tag; - bool sorted = builder->sorted; - - // Parse the unknown field data. It is an invariant of the data structure that - // unknown field data is valid, so parse errors here should be impossible. - while (!upb_EpsCopyInputStream_IsDone(&ctx->stream, &ptr)) { - uint32_t tag; - ptr = upb_WireReader_ReadTag(ptr, &tag, &ctx->stream); - UPB_ASSERT(tag <= UINT32_MAX); - int wire_type = upb_WireReader_GetWireType(tag); - if (wire_type == kUpb_WireType_EndGroup) break; - if (tag < last_tag) sorted = false; - last_tag = tag; - - if (arr_ptr == arr_end) { - upb_UnknownFields_Grow(ctx, &arr_base, &arr_ptr, &arr_end); - } - upb_UnknownField* field = arr_ptr; - field->tag = tag; - arr_ptr++; - - switch (wire_type) { - case kUpb_WireType_Varint: - ptr = upb_WireReader_ReadVarint(ptr, &field->data.varint, &ctx->stream); - UPB_ASSERT(ptr); - break; - case kUpb_WireType_64Bit: - ptr = - upb_WireReader_ReadFixed64(ptr, &field->data.uint64, &ctx->stream); - UPB_ASSERT(ptr); - break; - case kUpb_WireType_32Bit: - ptr = - upb_WireReader_ReadFixed32(ptr, &field->data.uint32, &ctx->stream); - UPB_ASSERT(ptr); - break; - case kUpb_WireType_Delimited: { - int size; - upb_StringView sv; - ptr = upb_WireReader_ReadSize(ptr, &size, &ctx->stream); - UPB_ASSERT(ptr); - ptr = upb_EpsCopyInputStream_ReadStringAlwaysAlias(&ctx->stream, ptr, - size, &sv); - UPB_ASSERT(ptr); - field->data.delimited.data = sv.data; - field->data.delimited.size = sv.size; - break; - } - case kUpb_WireType_StartGroup: - if (--ctx->depth < 0) { - ctx->status = kUpb_UnknownCompareResult_MaxDepthExceeded; - UPB_LONGJMP(ctx->err, 1); - } - field->data.group = upb_UnknownFields_BuildFromBuffer(ctx, &ptr); - ctx->depth++; - break; - default: - UPB_UNREACHABLE(); - } - } - *buf = ptr; - builder->arr_base = arr_base; - builder->arr_ptr = arr_ptr; - builder->arr_end = arr_end; - builder->sorted = sorted; - builder->last_tag = last_tag; -} - -static upb_UnknownFields* upb_UnknownFields_DoBuild( - upb_UnknownField_Context* ctx, upb_UnknownFields_Builder* builder) { - upb_UnknownFields* ret = upb_Arena_Malloc(ctx->arena, sizeof(*ret)); - if (!ret) upb_UnknownFields_OutOfMemory(ctx); - ret->fields = builder->arr_base; - ret->size = builder->arr_ptr - builder->arr_base; - ret->capacity = builder->arr_end - builder->arr_base; - if (!builder->sorted) { - upb_UnknownFields_Sort(ctx, ret); - } - return ret; -} - -// Builds a upb_UnknownFields data structure from the binary data in buf. -static upb_UnknownFields* upb_UnknownFields_BuildFromBuffer( - upb_UnknownField_Context* ctx, const char** buf) { - upb_UnknownFields_Builder builder = { - .arr_base = NULL, - .arr_ptr = NULL, - .arr_end = NULL, - .sorted = true, - .last_tag = 0, - }; - const char* ptr = *buf; - upb_CombineUnknownFields(ctx, &builder, &ptr); - upb_UnknownFields* fields = upb_UnknownFields_DoBuild(ctx, &builder); - *buf = ptr; - return fields; -} - -// Builds a upb_UnknownFields data structure from the unknown fields of a -// upb_Message. -static upb_UnknownFields* upb_UnknownFields_Build(upb_UnknownField_Context* ctx, - const upb_Message* msg) { - upb_UnknownFields_Builder builder = { - .arr_base = NULL, - .arr_ptr = NULL, - .arr_end = NULL, - .sorted = true, - .last_tag = 0, - }; - uintptr_t iter = kUpb_Message_UnknownBegin; - upb_StringView view; - while (upb_Message_NextUnknown(msg, &view, &iter)) { - upb_EpsCopyInputStream_Init(&ctx->stream, &view.data, view.size); - upb_CombineUnknownFields(ctx, &builder, &view.data); - UPB_ASSERT(upb_EpsCopyInputStream_IsDone(&ctx->stream, &view.data) && - !upb_EpsCopyInputStream_IsError(&ctx->stream)); - } - upb_UnknownFields* fields = upb_UnknownFields_DoBuild(ctx, &builder); - return fields; -} - -// Compares two sorted upb_UnknownFields structures for equality. -static bool upb_UnknownFields_IsEqual(const upb_UnknownFields* uf1, - const upb_UnknownFields* uf2) { - if (uf1->size != uf2->size) return false; - for (size_t i = 0, n = uf1->size; i < n; i++) { - upb_UnknownField* f1 = &uf1->fields[i]; - upb_UnknownField* f2 = &uf2->fields[i]; - if (f1->tag != f2->tag) return false; - int wire_type = f1->tag & 7; - switch (wire_type) { - case kUpb_WireType_Varint: - if (f1->data.varint != f2->data.varint) return false; - break; - case kUpb_WireType_64Bit: - if (f1->data.uint64 != f2->data.uint64) return false; - break; - case kUpb_WireType_32Bit: - if (f1->data.uint32 != f2->data.uint32) return false; - break; - case kUpb_WireType_Delimited: - if (!upb_StringView_IsEqual(f1->data.delimited, f2->data.delimited)) { - return false; - } - break; - case kUpb_WireType_StartGroup: - if (!upb_UnknownFields_IsEqual(f1->data.group, f2->data.group)) { - return false; - } - break; - default: - UPB_UNREACHABLE(); - } - } - return true; -} - -static upb_UnknownCompareResult upb_UnknownField_DoCompare( - upb_UnknownField_Context* ctx, const upb_Message* msg1, - const upb_Message* msg2) { - upb_UnknownCompareResult ret; - // First build both unknown fields into a sorted data structure (similar - // to the UnknownFieldSet in C++). - upb_UnknownFields* uf1 = upb_UnknownFields_Build(ctx, msg1); - upb_UnknownFields* uf2 = upb_UnknownFields_Build(ctx, msg2); - - // Now perform the equality check on the sorted structures. - if (upb_UnknownFields_IsEqual(uf1, uf2)) { - ret = kUpb_UnknownCompareResult_Equal; - } else { - ret = kUpb_UnknownCompareResult_NotEqual; - } - return ret; -} - -static upb_UnknownCompareResult upb_UnknownField_Compare( - upb_UnknownField_Context* const ctx, const upb_Message* msg1, - const upb_Message* msg2) { - upb_UnknownCompareResult ret; - if (UPB_SETJMP(ctx->err) == 0) { - ret = upb_UnknownField_DoCompare(ctx, msg1, msg2); - } else { - ret = ctx->status; - UPB_ASSERT(ret != kUpb_UnknownCompareResult_Equal); - } - - upb_Arena_Free(ctx->arena); - upb_gfree(ctx->tmp); - return ret; -} - -upb_UnknownCompareResult UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)( - const upb_Message* msg1, const upb_Message* msg2, int max_depth) { - bool msg1_empty = !upb_Message_HasUnknown(msg1); - bool msg2_empty = !upb_Message_HasUnknown(msg2); - if (msg1_empty && msg2_empty) return kUpb_UnknownCompareResult_Equal; - if (msg1_empty || msg2_empty) return kUpb_UnknownCompareResult_NotEqual; - - upb_UnknownField_Context ctx = { - .arena = upb_Arena_New(), - .depth = max_depth, - .tmp = NULL, - .tmp_size = 0, - .status = kUpb_UnknownCompareResult_Equal, - }; - - if (!ctx.arena) return kUpb_UnknownCompareResult_OutOfMemory; - - return upb_UnknownField_Compare(&ctx, msg1, msg2); -} diff --git a/vendor/upb/message/internal/compare_unknown.h b/vendor/upb/message/internal/compare_unknown.h deleted file mode 100644 index ad655f7..0000000 --- a/vendor/upb/message/internal/compare_unknown.h +++ /dev/null @@ -1,49 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_INTERNAL_COMPARE_UNKNOWN_H_ -#define UPB_MESSAGE_INTERNAL_COMPARE_UNKNOWN_H_ - -#include - -// Must be last. -#include "upb/message/message.h" -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Returns true if unknown fields from the two messages are equal when sorted -// and varints are made canonical. -// -// This function is discouraged, as the comparison is inherently lossy without -// schema data: -// -// 1. We don't know whether delimited fields are sub-messages. Unknown -// sub-messages will therefore not have their fields sorted and varints -// canonicalized. -// 2. We don't know about oneof/non-repeated fields, which should semantically -// discard every value except the last. - -typedef enum { - kUpb_UnknownCompareResult_Equal = 0, - kUpb_UnknownCompareResult_NotEqual = 1, - kUpb_UnknownCompareResult_OutOfMemory = 2, - kUpb_UnknownCompareResult_MaxDepthExceeded = 3, -} upb_UnknownCompareResult; - -upb_UnknownCompareResult UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)( - const upb_Message* msg1, const upb_Message* msg2, int max_depth); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_INTERNAL_COMPARE_UNKNOWN_H_ */ diff --git a/vendor/upb/message/internal/compare_unknown_test.cc b/vendor/upb/message/internal/compare_unknown_test.cc deleted file mode 100644 index 83dfb28..0000000 --- a/vendor/upb/message/internal/compare_unknown_test.cc +++ /dev/null @@ -1,133 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/internal/compare_unknown.h" - -#include - -#include -#include - -#include -#include "google/protobuf/test_messages_proto2.upb.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.hpp" -#include "upb/message/internal/message.h" -#include "upb/wire/test_util/wire_message.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace upb { -namespace test { - -namespace { - -using ::upb::test::wire_types::Delimited; -using ::upb::test::wire_types::Fixed32; -using ::upb::test::wire_types::Fixed64; -using ::upb::test::wire_types::Group; -using ::upb::test::wire_types::Varint; -using ::upb::test::wire_types::WireMessage; - -upb_UnknownCompareResult CompareUnknownWithMaxDepth( - WireMessage uf1, WireMessage uf2, int max_depth, int min_tag_length = 1, - int min_val_varint_length = 1) { - upb::Arena arena1; - upb::Arena arena2; - protobuf_test_messages_proto2_TestAllTypesProto2* msg1 = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena1.ptr()); - protobuf_test_messages_proto2_TestAllTypesProto2* msg2 = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena2.ptr()); - // Add the unknown fields to the messages. - std::string buf1 = ToBinaryPayloadWithLongVarints(uf1, min_tag_length, - min_val_varint_length); - std::string buf2 = ToBinaryPayloadWithLongVarints(uf2, min_tag_length, - min_val_varint_length); - UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg1), buf1.data(), - buf1.size(), arena1.ptr(), - kUpb_AddUnknown_Copy); - UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg2), buf2.data(), - buf2.size(), arena2.ptr(), - kUpb_AddUnknown_Copy); - return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)( - UPB_UPCAST(msg1), UPB_UPCAST(msg2), max_depth); -} - -upb_UnknownCompareResult CompareUnknown(WireMessage uf1, WireMessage uf2) { - return CompareUnknownWithMaxDepth(uf1, uf2, 64); -} - -TEST(CompareTest, UnknownFieldsReflexive) { - EXPECT_EQ(kUpb_UnknownCompareResult_Equal, CompareUnknown({}, {})); - EXPECT_EQ(kUpb_UnknownCompareResult_Equal, - CompareUnknown({{1, Varint(123)}, {2, Fixed32(456)}}, - {{1, Varint(123)}, {2, Fixed32(456)}})); - EXPECT_EQ( - kUpb_UnknownCompareResult_Equal, - CompareUnknown( - {{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}}, - {{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}})); -} - -TEST(CompareTest, UnknownFieldsOrdering) { - EXPECT_EQ(kUpb_UnknownCompareResult_Equal, - CompareUnknown({{1, Varint(111)}, - {2, Delimited("ABC")}, - {3, Fixed32(456)}, - {4, Fixed64(123)}, - {5, Group({})}}, - {{5, Group({})}, - {4, Fixed64(123)}, - {3, Fixed32(456)}, - {2, Delimited("ABC")}, - {1, Varint(111)}})); - EXPECT_EQ(kUpb_UnknownCompareResult_NotEqual, - CompareUnknown({{1, Varint(111)}, - {2, Delimited("ABC")}, - {3, Fixed32(456)}, - {4, Fixed64(123)}, - {5, Group({})}}, - {{5, Group({})}, - {4, Fixed64(123)}, - {3, Fixed32(455)}, // Small difference. - {2, Delimited("ABC")}, - {1, Varint(111)}})); - EXPECT_EQ(kUpb_UnknownCompareResult_Equal, - CompareUnknown({{3, Fixed32(456)}, {4, Fixed64(123)}}, - {{4, Fixed64(123)}, {3, Fixed32(456)}})); - EXPECT_EQ( - kUpb_UnknownCompareResult_Equal, - CompareUnknown( - {{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}}, - {{1, Group({{2, Group({{4, Fixed64(123)}, {3, Fixed32(456)}})}})}})); -} - -TEST(CompareTest, LongVarint) { - EXPECT_EQ(kUpb_UnknownCompareResult_Equal, - CompareUnknownWithMaxDepth({{1, Varint(123)}, {2, Varint(456)}}, - {{1, Varint(123)}, {2, Varint(456)}}, 64, - 5, 10)); - EXPECT_EQ(kUpb_UnknownCompareResult_Equal, - CompareUnknownWithMaxDepth({{2, Varint(456)}, {1, Varint(123)}}, - {{1, Varint(123)}, {2, Varint(456)}}, 64, - 5, 10)); -} - -TEST(CompareTest, MaxDepth) { - EXPECT_EQ( - kUpb_UnknownCompareResult_MaxDepthExceeded, - CompareUnknownWithMaxDepth( - {{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}}, - {{1, Group({{2, Group({{4, Fixed64(123)}, {3, Fixed32(456)}})}})}}, - 1)); -} - -} // namespace - -} // namespace test -} // namespace upb diff --git a/vendor/upb/message/internal/extension.c b/vendor/upb/message/internal/extension.c deleted file mode 100644 index ca8a586..0000000 --- a/vendor/upb/message/internal/extension.c +++ /dev/null @@ -1,54 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/internal/extension.h" - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/message.h" -#include "upb/message/internal/types.h" -#include "upb/mini_table/extension.h" - -// Must be last. -#include "upb/port/def.inc" - -const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( - const struct upb_Message* msg, const upb_MiniTableExtension* e) { - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) return NULL; - - for (size_t i = 0; i < in->size; i++) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i]; - if (upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - const upb_Extension* ext = upb_TaggedAuxPtr_Extension(tagged_ptr); - if (ext->ext == e) { - return ext; - } - } - } - - return NULL; -} - -upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( - struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); - if (ext) return ext; - - if (!UPB_PRIVATE(_upb_Message_ReserveSlot)(msg, a)) return NULL; - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - ext = upb_Arena_Malloc(a, sizeof(upb_Extension)); - if (!ext) return NULL; - memset(ext, 0, sizeof(upb_Extension)); - ext->ext = e; - in->aux_data[in->size++] = upb_TaggedAuxPtr_MakeExtension(ext); - return ext; -} diff --git a/vendor/upb/message/internal/extension.h b/vendor/upb/message/internal/extension.h deleted file mode 100644 index d0dc11c..0000000 --- a/vendor/upb/message/internal/extension.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ -#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ - -#include - -#include "upb/mem/arena.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/types.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/internal/field.h" - -// Must be last. -#include "upb/port/def.inc" - -// The internal representation of an extension is self-describing: it contains -// enough information that we can serialize it to binary format without needing -// to look it up in a upb_ExtensionRegistry. -// -// This representation allocates 16 bytes to data on 64-bit platforms. -// This is rather wasteful for scalars (in the extreme case of bool, -// it wastes 15 bytes). We accept this because we expect messages to be -// the most common extension type. -typedef struct { - const upb_MiniTableExtension* ext; - upb_MessageValue data; -} upb_Extension; - -#ifdef __cplusplus -extern "C" { -#endif - -// Adds the given extension data to the given message. -// |ext| is copied into the message instance. -// This logically replaces any previously-added extension with this number. -UPB_NODISCARD upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( - struct upb_Message* msg, const upb_MiniTableExtension* ext, - upb_Arena* arena); - -// Returns an extension for a message with a given mini table, -// or NULL if no extension exists with this mini table. -const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( - const struct upb_Message* msg, const upb_MiniTableExtension* ext); - -UPB_INLINE bool UPB_PRIVATE(_upb_Extension_IsEmpty)(const upb_Extension* ext) { - switch ( - UPB_PRIVATE(_upb_MiniTableField_Mode)(&ext->ext->UPB_PRIVATE(field))) { - case kUpb_FieldMode_Scalar: - return false; - case kUpb_FieldMode_Array: - return upb_Array_Size(ext->data.array_val) == 0; - case kUpb_FieldMode_Map: - return _upb_Map_Size(ext->data.map_val) == 0; - } - UPB_UNREACHABLE(); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ diff --git a/vendor/upb/message/internal/iterator.c b/vendor/upb/message/internal/iterator.c deleted file mode 100644 index b3ad76c..0000000 --- a/vendor/upb/message/internal/iterator.c +++ /dev/null @@ -1,58 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/internal/iterator.h" // IWYU pragma: keep - -#include - -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -bool UPB_PRIVATE(_upb_Message_NextBaseField)(const upb_Message* msg, - const upb_MiniTable* m, - const upb_MiniTableField** out_f, - upb_MessageValue* out_v, - size_t* iter) { - const size_t count = upb_MiniTable_FieldCount(m); - size_t i = *iter; - - while (++i < count) { - const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i); - const void* src = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f); - - upb_MessageValue val; - UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, &val, src); - - // Skip field if unset or empty. - if (upb_MiniTableField_HasPresence(f)) { - if (!upb_Message_HasBaseField(msg, f)) continue; - } else { - if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(f, src)) continue; - - if (upb_MiniTableField_IsArray(f)) { - if (upb_Array_Size(val.array_val) == 0) continue; - } else if (upb_MiniTableField_IsMap(f)) { - if (upb_Map_Size(val.map_val) == 0) continue; - } - } - - *out_f = f; - *out_v = val; - *iter = i; - return true; - } - - return false; -} diff --git a/vendor/upb/message/internal/iterator.h b/vendor/upb/message/internal/iterator.h deleted file mode 100644 index cc39a38..0000000 --- a/vendor/upb/message/internal/iterator.h +++ /dev/null @@ -1,29 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef GOOGLE_UPB_UPB_MESSAGE_INTERNAL_ITERATOR_H__ -#define GOOGLE_UPB_UPB_MESSAGE_INTERNAL_ITERATOR_H__ - -#include -#include - -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#define kUpb_BaseField_Begin ((size_t)-1) -bool UPB_PRIVATE(_upb_Message_NextBaseField)(const upb_Message* msg, - const upb_MiniTable* m, - const upb_MiniTableField** out_f, - upb_MessageValue* out_v, - uintptr_t* iter); - -#endif // GOOGLE_UPB_UPB_MESSAGE_INTERNAL_ITERATOR_H__ diff --git a/vendor/upb/message/internal/map.h b/vendor/upb/message/internal/map.h deleted file mode 100644 index 0add1d4..0000000 --- a/vendor/upb/message/internal/map.h +++ /dev/null @@ -1,229 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ -#define UPB_MESSAGE_INTERNAL_MAP_H_ - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef enum { - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, -} upb_MapInsertStatus; - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -union upb_Map_Table { - upb_strtable strtable; - upb_inttable inttable; -}; - -struct upb_Map { - // Size of key and val, based on the map type. - // Strings are represented as '0' because they must be handled specially. - char key_size; - char val_size; - bool UPB_PRIVATE(is_frozen); - bool UPB_PRIVATE(is_strtable); - - union upb_Map_Table t; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE void UPB_PRIVATE(_upb_Map_ShallowFreeze)(struct upb_Map* map) { - map->UPB_PRIVATE(is_frozen) = true; -} - -UPB_API_INLINE bool upb_Map_IsFrozen(const struct upb_Map* map) { - return map->UPB_PRIVATE(is_frozen); -} - -// Converting between internal table representation and user values. -// -// _upb_map_tokey() and _upb_map_fromkey() are inverses. -// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. -// -// These functions account for the fact that strings are treated differently -// from other types when stored in a map. - -UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - return *(upb_StringView*)key; - } else { - return upb_StringView_FromDataAndSize((const char*)key, size); - } -} - -UPB_INLINE uintptr_t _upb_map_tointkey(const void* key, size_t key_size) { - uintptr_t intkey = 0; - memcpy(&intkey, key, key_size); - return intkey; -} - -UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - memcpy(out, &key, sizeof(key)); - } else { - memcpy(out, key.data, size); - } -} - -UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, - upb_value* msgval, upb_Arena* a) { - if (size == UPB_MAPTYPE_STRING) { - upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); - if (!strp) return false; - *strp = *(upb_StringView*)val; - *msgval = upb_value_ptr(strp); - } else { - memcpy(msgval, val, size); - } - return true; -} - -UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); - memcpy(out, strp, sizeof(upb_StringView)); - } else { - memcpy(out, &val, size); - } -} - -UPB_INLINE bool _upb_map_next(const struct upb_Map* map, size_t* iter) { - if (map->UPB_PRIVATE(is_strtable)) { - upb_strtable_iter it; - it.t = &map->t.strtable; - it.index = *iter; - upb_strtable_next(&it); - *iter = it.index; - return !upb_strtable_done(&it); - } else { - uintptr_t key; - upb_value val; - intptr_t int_iter = 0; - memcpy(&int_iter, iter, sizeof(intptr_t)); - upb_inttable_next(&map->t.inttable, &key, &val, &int_iter); - memcpy(iter, &int_iter, sizeof(size_t)); - return !upb_inttable_done(&map->t.inttable, int_iter); - } -} - -UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { - UPB_ASSERT(!upb_Map_IsFrozen(map)); - - if (map->UPB_PRIVATE(is_strtable)) { - upb_strtable_clear(&map->t.strtable); - } else { - upb_inttable_clear(&map->t.inttable); - } -} - -UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, - size_t key_size, upb_value* val) { - UPB_ASSERT(!upb_Map_IsFrozen(map)); - - if (map->UPB_PRIVATE(is_strtable)) { - upb_StringView k = _upb_map_tokey(key, key_size); - return upb_strtable_remove2(&map->t.strtable, k.data, k.size, val); - } else { - uintptr_t intkey = _upb_map_tointkey(key, key_size); - return upb_inttable_remove(&map->t.inttable, intkey, val); - } -} - -UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, - size_t key_size, void* val, size_t val_size) { - upb_value tabval = {0}; - bool ret; - if (map->UPB_PRIVATE(is_strtable)) { - upb_StringView k = _upb_map_tokey(key, key_size); - ret = upb_strtable_lookup2(&map->t.strtable, k.data, k.size, &tabval); - } else { - uintptr_t intkey = _upb_map_tointkey(key, key_size); - ret = upb_inttable_lookup(&map->t.inttable, intkey, &tabval); - } - if (ret && val) { - _upb_map_fromvalue(tabval, val, val_size); - } - return ret; -} - -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, - const void* key, size_t key_size, - void* val, size_t val_size, - upb_Arena* a) { - UPB_ASSERT(!upb_Map_IsFrozen(map)); - - // Prep the value. - upb_value tabval = {0}; - if (!_upb_map_tovalue(val, val_size, &tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } - - bool removed; - if (map->UPB_PRIVATE(is_strtable)) { - upb_StringView strkey = _upb_map_tokey(key, key_size); - // TODO: add overwrite operation to minimize number of lookups. - removed = - upb_strtable_remove2(&map->t.strtable, strkey.data, strkey.size, NULL); - if (!upb_strtable_insert(&map->t.strtable, strkey.data, strkey.size, tabval, - a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } - } else { - uintptr_t intkey = _upb_map_tointkey(key, key_size); - removed = upb_inttable_remove(&map->t.inttable, intkey, NULL); - if (!upb_inttable_insert(&map->t.inttable, intkey, tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } - } - return removed ? kUpb_MapInsertStatus_Replaced - : kUpb_MapInsertStatus_Inserted; -} - -UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { - if (map->UPB_PRIVATE(is_strtable)) { - return map->t.strtable.t.count; - } else { - return upb_inttable_count(&map->t.inttable); - } -} - -// Strings/bytes are special-cased in maps. -extern char _upb_Map_CTypeSizeTable[12]; - -UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { - return (size_t)_upb_Map_CTypeSizeTable[ctype]; -} - -// Creates a new map on the given arena with this key/value type. -struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ diff --git a/vendor/upb/message/internal/map_entry.h b/vendor/upb/message/internal/map_entry.h deleted file mode 100644 index 5a0b524..0000000 --- a/vendor/upb/message/internal/map_entry.h +++ /dev/null @@ -1,41 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ -#define UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ - -#include - -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/message/internal/types.h" - -// Map entries aren't actually stored for map fields, they are only used during -// parsing. (It helps a lot if all map entry messages have the same layout.) -// The mini_table layout code will ensure that all map entries have this layout. -// -// Note that users can and do create map entries directly, which will also use -// this layout. - -typedef struct { - struct upb_Message message; - // We only need 2 hasbits max, but due to alignment we'll use 8 bytes here, - // and the uint64_t helps make this clear. - uint64_t hasbits; - union { - upb_StringView str; // For str/bytes. - upb_value val; // For all other types. - double d[2]; // Padding for 32-bit builds. - } k; - union { - upb_StringView str; // For str/bytes. - upb_value val; // For all other types. - double d[2]; // Padding for 32-bit builds. - } v; -} upb_MapEntry; - -#endif // UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ diff --git a/vendor/upb/message/internal/map_sorter.h b/vendor/upb/message/internal/map_sorter.h deleted file mode 100644 index bfc8f57..0000000 --- a/vendor/upb/message/internal/map_sorter.h +++ /dev/null @@ -1,101 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -#ifndef UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ -#define UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/mem/alloc.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/map_entry.h" -#include "upb/message/internal/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// _upb_mapsorter sorts maps and provides ordered iteration over the entries. -// Since maps can be recursive (map values can be messages which contain other -// maps), _upb_mapsorter can contain a stack of maps. - -typedef struct { - void const** entries; - int size; - int cap; -} _upb_mapsorter; - -typedef struct { - int start; - int pos; - int end; -} _upb_sortedmap; - -UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { - s->entries = NULL; - s->size = 0; - s->cap = 0; -} - -UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { - if (s->entries) upb_gfree(s->entries); -} - -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, - const struct upb_Map* map, - _upb_sortedmap* sorted, upb_MapEntry* ent) { - if (sorted->pos == sorted->end) return false; - const upb_tabent* tabent = (const upb_tabent*)s->entries[sorted->pos++]; - if (map->UPB_PRIVATE(is_strtable)) { - upb_StringView key = upb_key_strview(tabent->key); - _upb_map_fromkey(key, &ent->k, map->key_size); - } else { - uintptr_t key = tabent->key.num; - memcpy(&ent->k, &key, map->key_size); - } - upb_value val = {tabent->val.val}; - _upb_map_fromvalue(val, &ent->v, map->val_size); - return true; -} - -UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, - _upb_sortedmap* sorted, - const upb_Extension** ext) { - if (sorted->pos == sorted->end) return false; - *ext = (const upb_Extension*)s->entries[sorted->pos++]; - return true; -} - -UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, - _upb_sortedmap* sorted) { - s->size = sorted->start; -} - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const struct upb_Map* map, _upb_sortedmap* sorted); - -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Message_Internal* in, - _upb_sortedmap* sorted); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ diff --git a/vendor/upb/message/internal/message.c b/vendor/upb/message/internal/message.c deleted file mode 100644 index 0f3b708..0000000 --- a/vendor/upb/message/internal/message.c +++ /dev/null @@ -1,101 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/internal/message.h" - -#include -#include -#include -#include - -#include "upb/base/internal/log2.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/types.h" - -// Must be last. -#include "upb/port/def.inc" - -// The latest win32 SDKs have an invalid definition of NAN. -// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907 -// -// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so -// try __builtin_nan first, if that exists. -#ifdef _WIN32 -#ifdef __has_builtin -#if __has_builtin(__builtin_nan) -#define UPB_NAN __builtin_nan("0") -#endif -#if __has_builtin(__builtin_inf) -#define UPB_INFINITY __builtin_inf() -#endif -#endif -#ifndef UPB_NAN -#define UPB_NAN 0.0 / 0.0 -#endif -#ifndef UPB_INFINITY -#define UPB_INFINITY 1.0 / 0.0 -#endif -#else -// For !_WIN32, assume math.h works. -#define UPB_NAN NAN -#define UPB_INFINITY INFINITY -#endif - -const float kUpb_FltInfinity = UPB_INFINITY; -const double kUpb_Infinity = UPB_INFINITY; -const double kUpb_NaN = UPB_NAN; - -static size_t _upb_Message_SizeOfInternal(uint32_t count) { - return UPB_SIZEOF_FLEX(upb_Message_Internal, aux_data, count); -} - -bool UPB_PRIVATE(_upb_Message_ReserveSlot)(struct upb_Message* msg, - upb_Arena* a) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) { - // No internal data, allocate from scratch. - uint32_t capacity = 4; - in = upb_Arena_Malloc(a, _upb_Message_SizeOfInternal(capacity)); - if (!in) return false; - in->size = 0; - in->capacity = capacity; - UPB_PRIVATE(_upb_Message_SetInternal)(msg, in); - } else if (in->capacity == in->size) { - if (in->size == UINT32_MAX) return false; - // Internal data is too small, reallocate. - size_t needed_pow2 = upb_RoundUpToPowerOfTwo(in->size + 1); - if (needed_pow2 > UINT32_MAX) return false; - uint32_t new_capacity = needed_pow2; - if (UPB_SIZEOF_FLEX_WOULD_OVERFLOW(upb_Message_Internal, aux_data, - new_capacity)) { - return false; - } - in = upb_Arena_Realloc(a, in, _upb_Message_SizeOfInternal(in->capacity), - _upb_Message_SizeOfInternal(new_capacity)); - if (!in) return false; - in->capacity = new_capacity; - UPB_PRIVATE(_upb_Message_SetInternal)(msg, in); - } - UPB_ASSERT(in->capacity - in->size >= 1); - return true; -} - -#ifdef UPB_TRACING_ENABLED -static void (*_message_trace_handler)(const upb_MiniTable*, const upb_Arena*); - -void upb_Message_LogNewMessage(const upb_MiniTable* m, const upb_Arena* arena) { - if (_message_trace_handler) { - _message_trace_handler(m, arena); - } -} - -void upb_Message_SetNewMessageTraceHandler(void (*handler)(const upb_MiniTable*, - const upb_Arena*)) { - _message_trace_handler = handler; -} -#endif // UPB_TRACING_ENABLED diff --git a/vendor/upb/message/internal/message.h b/vendor/upb/message/internal/message.h deleted file mode 100644 index b2136a7..0000000 --- a/vendor/upb/message/internal/message.h +++ /dev/null @@ -1,344 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ - -#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ -#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ - -#include -#include -#include - -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/types.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; -extern const double kUpb_NaN; - -// Internal members of a upb_Message that track unknown fields and/or -// extensions. We can change this without breaking binary compatibility. - -typedef struct upb_TaggedAuxPtr { - // Two lowest bits form a tag: - // 00 - non-aliased unknown data - // 10 - aliased unknown data - // 01 - extension - // - // The main semantic difference between aliased and non-aliased unknown data - // is that non-aliased unknown data can be assumed to have the following - // layout: - // - // [upb_StringView] [data] - // - // where the StringView points to the data buffer and the data buffer is - // immediately following the StringView. - // - // The string view does not necessarily point to the start of the data buffer; - // if the initial part of the buffer is removed from the message, the string - // view will point to the beginning of the remaining buffer. - // - // For aliased unknown data, this layout is _not_ guaranteed, since the - // pointer to the StringView can be anywhere in the allocation, and the - // StringView may point to non-data memory. - uintptr_t ptr; -} upb_TaggedAuxPtr; - -UPB_INLINE bool upb_TaggedAuxPtr_IsExtension(upb_TaggedAuxPtr ptr) { - return ptr.ptr & 1; -} - -UPB_INLINE bool upb_TaggedAuxPtr_IsUnknown(upb_TaggedAuxPtr ptr) { - return (ptr.ptr != 0) && ((ptr.ptr & 1) == 0); -} - -UPB_INLINE bool upb_TaggedAuxPtr_IsUnknownAliased(upb_TaggedAuxPtr ptr) { - return (ptr.ptr != 0) && ((ptr.ptr & 2) == 2); -} - -UPB_INLINE upb_Extension* upb_TaggedAuxPtr_Extension(upb_TaggedAuxPtr ptr) { - UPB_ASSERT(upb_TaggedAuxPtr_IsExtension(ptr)); - return (upb_Extension*)(ptr.ptr & ~3ULL); -} - -UPB_INLINE upb_StringView* upb_TaggedAuxPtr_UnknownData(upb_TaggedAuxPtr ptr) { - UPB_ASSERT(!upb_TaggedAuxPtr_IsExtension(ptr)); - return (upb_StringView*)(ptr.ptr & ~3ULL); -} - -typedef enum { - kUpb_TaggedAuxType_Extension, - kUpb_TaggedAuxType_Unknown, - kUpb_TaggedAuxType_AliasedUnknown -} upb_TaggedAuxType; - -typedef union { - upb_Extension* extension; - upb_StringView unknown_data; -} upb_TaggedAux; - -UPB_INLINE upb_TaggedAuxType upb_TaggedAux_Get(upb_TaggedAuxPtr ptr, - upb_TaggedAux* data) { - if (upb_TaggedAuxPtr_IsExtension(ptr)) { - data->extension = upb_TaggedAuxPtr_Extension(ptr); - return kUpb_TaggedAuxType_Extension; - } else if (upb_TaggedAuxPtr_IsUnknownAliased(ptr)) { - data->unknown_data = *upb_TaggedAuxPtr_UnknownData(ptr); - return kUpb_TaggedAuxType_AliasedUnknown; - } else { - UPB_ASSERT(upb_TaggedAuxPtr_IsUnknown(ptr)); - data->unknown_data = *upb_TaggedAuxPtr_UnknownData(ptr); - return kUpb_TaggedAuxType_Unknown; - } -} - -UPB_INLINE upb_TaggedAuxPtr upb_TaggedAuxPtr_Null(void) { - upb_TaggedAuxPtr ptr; - ptr.ptr = 0; - return ptr; -} - -UPB_INLINE upb_TaggedAuxPtr -upb_TaggedAuxPtr_MakeExtension(const upb_Extension* e) { - upb_TaggedAuxPtr ptr; - ptr.ptr = (uintptr_t)e | 1; - return ptr; -} - -// This tag means that the original allocation for this field starts with the -// string view and ends with the end of the content referenced by the string -// view. -UPB_INLINE upb_TaggedAuxPtr -upb_TaggedAuxPtr_MakeUnknownData(const upb_StringView* sv) { - upb_TaggedAuxPtr ptr; - ptr.ptr = (uintptr_t)sv; - return ptr; -} - -// This tag implies no guarantee between the relationship of the string view and -// the data it points to. -UPB_INLINE upb_TaggedAuxPtr -upb_TaggedAuxPtr_MakeUnknownDataAliased(const upb_StringView* sv) { - upb_TaggedAuxPtr ptr; - ptr.ptr = (uintptr_t)sv | 2; - return ptr; -} - -typedef struct upb_Message_Internal { - // Total number of entries set in aux_data - uint32_t size; - uint32_t capacity; - // Tagged pointers to upb_StringView or upb_Extension - upb_TaggedAuxPtr aux_data[]; -} upb_Message_Internal; - -#ifdef UPB_TRACING_ENABLED -UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m, - const upb_Arena* arena); -UPB_API void upb_Message_SetNewMessageTraceHandler( - void (*handler)(const upb_MiniTable*, const upb_Arena*)); -#endif // UPB_TRACING_ENABLED - -// Inline version upb_Message_New(), for internal use. -UPB_NODISCARD UPB_INLINE struct upb_Message* _upb_Message_New( - const upb_MiniTable* m, upb_Arena* a) { - UPB_PRIVATE(upb_MiniTable_CheckInvariants)(m); -#ifdef UPB_TRACING_ENABLED - upb_Message_LogNewMessage(m, a); -#endif // UPB_TRACING_ENABLED - - const size_t size = m->UPB_PRIVATE(size); - // Message sizes are aligned up when constructing minitables; telling the - // compiler this avoids redoing alignment on the malloc fast path - UPB_ASSUME(size % kUpb_Message_Align == 0); - struct upb_Message* msg = (struct upb_Message*)upb_Arena_Malloc(a, size); - if (UPB_UNLIKELY(!msg)) return NULL; - memset(msg, 0, size); - return msg; -} - -// Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); - -UPB_NODISCARD UPB_NOINLINE bool UPB_PRIVATE(_upb_Message_AddUnknownSlowPath)( - struct upb_Message* msg, const char* data, size_t len, upb_Arena* arena, - bool alias); - -typedef enum { - // Provided buffer is copied into the message. - kUpb_AddUnknown_Copy = 0, - - // The message will alias the provided buffer. - kUpb_AddUnknown_Alias = 1, - - // The message will alias the provided buffer, and we may merge the data with - // the immediately preceding unknown field if possible. - kUpb_AddUnknown_AliasAllowMerge = 2, -} upb_AddUnknownMode; - -// Adds unknown data (serialized protobuf data) to the given message. The data -// must represent one or more complete and well formed proto fields. -// -// If `alias_base` is NULL, the bytes from `data` will be copied into the -// destination arena. Otherwise it must be a pointer to the beginning of the -// buffer that `data` points into, which signals that the message must alias -// the bytes instead of copying them. The value of `alias_base` is also used -// to mark the boundary of the buffer, so that we do not inappropriately -// coalesce two buffers that are separate objects but happen to be contiguous -// in memory. -UPB_NODISCARD UPB_INLINE bool UPB_PRIVATE(_upb_Message_AddUnknown)( - struct upb_Message* msg, const char* data, size_t len, upb_Arena* arena, - upb_AddUnknownMode mode) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - if (mode == kUpb_AddUnknown_AliasAllowMerge) { - // Aliasing parse of a message with sequential unknown fields is a simple - // pointer bump, so inline it. - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (in && in->size) { - upb_TaggedAuxPtr ptr = in->aux_data[in->size - 1]; - if (upb_TaggedAuxPtr_IsUnknown(ptr)) { - upb_StringView* existing = upb_TaggedAuxPtr_UnknownData(ptr); - // Fast path if the field we're adding is immediately after the last - // added unknown field. - // - // The caller has guaranteed to us, by passing - // kUpb_AddUnknown_AliasAllowMerge, that there is no risk that these two - // regions of memory are from different objects that are contiguous in - // memory by coincidence. - if (existing->data + existing->size == data) { - existing->size += len; - return true; - } - } - } - } - return UPB_PRIVATE(_upb_Message_AddUnknownSlowPath)( - msg, data, len, arena, mode != kUpb_AddUnknown_Copy); -} - -// Adds unknown data (serialized protobuf data) to the given message. -// The data is copied into the message instance. Data when concatenated together -// must represent one or more complete and well formed proto fields, but the -// individual spans may point only to partial fields. -UPB_NODISCARD bool UPB_PRIVATE(_upb_Message_AddUnknownV)( - struct upb_Message* msg, upb_Arena* arena, upb_StringView data[], - size_t count); - -// Ensures at least one slot is available in the aux_data of this message. -// Returns false if a reallocation is needed to satisfy the request, and fails. -UPB_NODISCARD bool UPB_PRIVATE(_upb_Message_ReserveSlot)( - struct upb_Message* msg, upb_Arena* arena); - -#define kUpb_Message_UnknownBegin 0 -#define kUpb_Message_ExtensionBegin 0 - -UPB_INLINE bool upb_Message_NextUnknown(const struct upb_Message* msg, - upb_StringView* data, uintptr_t* iter) { - const upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - size_t i = *iter; - if (in) { - while (i < in->size) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i++]; - if (upb_TaggedAuxPtr_IsUnknown(tagged_ptr)) { - *data = *upb_TaggedAuxPtr_UnknownData(tagged_ptr); - *iter = i; - return true; - } - } - } - data->size = 0; - data->data = NULL; - *iter = i; - return false; -} - -UPB_INLINE bool upb_Message_HasUnknown(const struct upb_Message* msg) { - upb_StringView data; - uintptr_t iter = kUpb_Message_UnknownBegin; - return upb_Message_NextUnknown(msg, &data, &iter); -} - -UPB_INLINE bool upb_Message_NextExtension(const struct upb_Message* msg, - const upb_MiniTableExtension** out_e, - upb_MessageValue* out_v, - uintptr_t* iter) { - const upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - uintptr_t i = *iter; - if (in) { - while (i < in->size) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i++]; - if (upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - const upb_Extension* ext = upb_TaggedAuxPtr_Extension(tagged_ptr); - - // Empty repeated fields or maps semantically don't exist. - if (UPB_PRIVATE(_upb_Extension_IsEmpty)(ext)) continue; - - *out_e = ext->ext; - *out_v = ext->data; - *iter = i; - return true; - } - } - } - *iter = i; - - return false; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_Message_NextExtensionReverse)( - const struct upb_Message* msg, const upb_MiniTableExtension** out_e, - upb_MessageValue* out_v, uintptr_t* iter) { - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) return false; - uintptr_t i = *iter; - uint32_t size = in->size; - while (i < size) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[size - 1 - i]; - i++; - if (!upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - continue; - } - const upb_Extension* ext = upb_TaggedAuxPtr_Extension(tagged_ptr); - - // Empty repeated fields or maps semantically don't exist. - if (UPB_PRIVATE(_upb_Extension_IsEmpty)(ext)) continue; - - *out_e = ext->ext; - *out_v = ext->data; - *iter = i; - return true; - } - *iter = i; - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ diff --git a/vendor/upb/message/internal/types.h b/vendor/upb/message/internal/types.h deleted file mode 100644 index 7039fc9..0000000 --- a/vendor/upb/message/internal/types.h +++ /dev/null @@ -1,58 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_INTERNAL_TYPES_H_ -#define UPB_MESSAGE_INTERNAL_TYPES_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -#define UPB_OPAQUE(x) x##_opaque - -struct upb_Message { - union { - uintptr_t UPB_OPAQUE(internal); // tagged pointer, low bit == frozen - double d; // Forces same size for 32-bit/64-bit builds - }; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE void UPB_PRIVATE(_upb_Message_ShallowFreeze)( - struct upb_Message* msg) { - msg->UPB_OPAQUE(internal) |= 1ULL; -} - -UPB_API_INLINE bool upb_Message_IsFrozen(const struct upb_Message* msg) { - return (msg->UPB_OPAQUE(internal) & 1ULL) != 0; -} - -UPB_INLINE struct upb_Message_Internal* UPB_PRIVATE(_upb_Message_GetInternal)( - const struct upb_Message* msg) { - const uintptr_t tmp = msg->UPB_OPAQUE(internal) & ~1ULL; - return (struct upb_Message_Internal*)tmp; -} - -UPB_INLINE void UPB_PRIVATE(_upb_Message_SetInternal)( - struct upb_Message* msg, struct upb_Message_Internal* internal) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - msg->UPB_OPAQUE(internal) = (uintptr_t)internal; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#undef UPB_OPAQUE - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_INTERNAL_TYPES_H_ */ diff --git a/vendor/upb/message/map.c b/vendor/upb/message/map.c deleted file mode 100644 index 56a5fcc..0000000 --- a/vendor/upb/message/map.c +++ /dev/null @@ -1,195 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/map.h" - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/types.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -// Strings/bytes are special-cased in maps. -char _upb_Map_CTypeSizeTable[12] = { - [kUpb_CType_Bool] = 1, - [kUpb_CType_Float] = 4, - [kUpb_CType_Int32] = 4, - [kUpb_CType_UInt32] = 4, - [kUpb_CType_Enum] = 4, - [kUpb_CType_Message] = sizeof(void*), - [kUpb_CType_Double] = 8, - [kUpb_CType_Int64] = 8, - [kUpb_CType_UInt64] = 8, - [kUpb_CType_String] = UPB_MAPTYPE_STRING, - [kUpb_CType_Bytes] = UPB_MAPTYPE_STRING, -}; - -upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { - return _upb_Map_New(a, _upb_Map_CTypeSize(key_type), - _upb_Map_CTypeSize(value_type)); -} - -size_t upb_Map_Size(const upb_Map* map) { return _upb_Map_Size(map); } - -bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val) { - return _upb_Map_Get(map, &key, map->key_size, val, map->val_size); -} - -struct upb_Message* upb_Map_GetMutable(upb_Map* map, upb_MessageValue key) { - UPB_ASSERT(map->val_size == sizeof(upb_Message*)); - upb_Message* val = NULL; - if (_upb_Map_Get(map, &key, map->key_size, &val, sizeof(upb_Message*))) { - return val; - } else { - return NULL; - } -} - -void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); } - -upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(arena); - return (upb_MapInsertStatus)_upb_Map_Insert(map, &key, map->key_size, &val, - map->val_size, arena); -} - -bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, upb_MessageValue* val) { - upb_value v; - const bool removed = _upb_Map_Delete(map, &key, map->key_size, &v); - if (val) _upb_map_fromvalue(v, val, map->val_size); - return removed; -} - -bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, - upb_MessageValue* val, size_t* iter) { - upb_value v; - bool ret; - if (map->UPB_PRIVATE(is_strtable)) { - upb_StringView strkey; - ret = upb_strtable_next2(&map->t.strtable, &strkey, &v, (intptr_t*)iter); - if (ret) { - _upb_map_fromkey(strkey, key, map->key_size); - } - } else { - uintptr_t intkey; - ret = upb_inttable_next(&map->t.inttable, &intkey, &v, (intptr_t*)iter); - if (ret) { - memcpy(key, &intkey, map->key_size); - } - } - if (ret) { - _upb_map_fromvalue(v, val, map->val_size); - } - return ret; -} - -UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, - upb_MessageValue val) { - upb_value v; - _upb_map_tovalue(&val, map->val_size, &v, NULL); - if (map->UPB_PRIVATE(is_strtable)) { - upb_strtable_setentryvalue(&map->t.strtable, iter, v); - } else { - upb_inttable_setentryvalue(&map->t.inttable, iter, v); - } -} - -bool upb_MapIterator_Next(const upb_Map* map, size_t* iter) { - return _upb_map_next(map, iter); -} - -bool upb_MapIterator_Done(const upb_Map* map, size_t iter) { - UPB_ASSERT(iter != kUpb_Map_Begin); - if (map->UPB_PRIVATE(is_strtable)) { - upb_strtable_iter i; - i.t = &map->t.strtable; - i.index = iter; - return upb_strtable_done(&i); - } else { - return upb_inttable_done(&map->t.inttable, iter); - } -} - -// Returns the key and value for this entry of the map. -upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter) { - upb_MessageValue ret; - if (map->UPB_PRIVATE(is_strtable)) { - upb_strtable_iter i; - i.t = &map->t.strtable; - i.index = iter; - _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size); - } else { - uintptr_t intkey = upb_inttable_iter_key(&map->t.inttable, iter); - memcpy(&ret, &intkey, map->key_size); - } - return ret; -} - -upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { - upb_value v; - if (map->UPB_PRIVATE(is_strtable)) { - upb_strtable_iter i; - i.t = &map->t.strtable; - i.index = iter; - v = upb_strtable_iter_value(&i); - } else { - v = upb_inttable_iter_value(&map->t.inttable, iter); - } - - upb_MessageValue ret; - _upb_map_fromvalue(v, &ret, map->val_size); - return ret; -} - -void upb_Map_Freeze(upb_Map* map, const upb_MiniTable* m) { - if (upb_Map_IsFrozen(map)) return; - UPB_PRIVATE(_upb_Map_ShallowFreeze)(map); - - if (m) { - size_t iter = kUpb_Map_Begin; - upb_MessageValue key, val; - - while (upb_Map_Next(map, &key, &val, &iter)) { - upb_Message_Freeze((upb_Message*)val.msg_val, m); - } - } -} - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { - upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - if (!map) return NULL; - - if (key_size <= sizeof(uintptr_t) && key_size != UPB_MAPTYPE_STRING) { - if (!upb_inttable_init(&map->t.inttable, a)) return NULL; - map->UPB_PRIVATE(is_strtable) = false; - } else { - if (!upb_strtable_init(&map->t.strtable, 4, a)) return NULL; - map->UPB_PRIVATE(is_strtable) = true; - } - map->key_size = key_size; - map->val_size = value_size; - map->UPB_PRIVATE(is_frozen) = false; - - return map; -} diff --git a/vendor/upb/message/map.h b/vendor/upb/message/map.h deleted file mode 100644 index 99f922d..0000000 --- a/vendor/upb/message/map.h +++ /dev/null @@ -1,133 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_MAP_H_ -#define UPB_MESSAGE_MAP_H_ - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/types.h" -#include "upb/message/value.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_Map upb_Map; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new map on the given arena with the given key/value size. -UPB_NODISCARD UPB_API upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, - upb_CType value_type); - -// Returns the number of entries in the map. -UPB_API size_t upb_Map_Size(const upb_Map* map); - -// Stores a value for the given key into |*val| (or the zero value if the key is -// not present). Returns whether the key was present. The |val| pointer may be -// NULL, in which case the function tests whether the given key is present. -UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); - -// Returns a mutable pointer to the value for the given key. Returns NULL if the -// key is not present. -// This function is only legal to call for maps that contain messages. -UPB_API struct upb_Message* upb_Map_GetMutable(upb_Map* map, - upb_MessageValue key); - -// Removes all entries in the map. -UPB_API void upb_Map_Clear(upb_Map* map); - -// Sets the given key to the given value, returning whether the key was inserted -// or replaced. If the key was inserted, then any existing iterators will be -// invalidated. -UPB_NODISCARD UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map* map, - upb_MessageValue key, - upb_MessageValue val, - upb_Arena* arena); - -// Sets the given key to the given value. Returns false if memory allocation -// failed. If the key is newly inserted, then any existing iterators will be -// invalidated. -UPB_NODISCARD UPB_API_INLINE bool upb_Map_Set(upb_Map* map, - upb_MessageValue key, - upb_MessageValue val, - upb_Arena* arena) { - return upb_Map_Insert(map, key, val, arena) != - kUpb_MapInsertStatus_OutOfMemory; -} - -// Deletes this key from the table. Returns true if the key was present. -// If present and |val| is non-NULL, stores the deleted value. -UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); - -// Map iteration: -// -// size_t iter = kUpb_Map_Begin; -// upb_MessageValue key, val; -// while (upb_Map_Next(map, &key, &val, &iter)) { -// ... -// } - -#define kUpb_Map_Begin ((size_t)-1) - -// Advances to the next entry. Returns false if no more entries are present. -// Otherwise returns true and populates both *key and *value. -UPB_API bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, - upb_MessageValue* val, size_t* iter); - -// Sets the value for the entry pointed to by iter. -// WARNING: this does not currently work for string values! -UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, - upb_MessageValue val); - -// DEPRECATED iterator, slated for removal. - -/* Map iteration: - * - * size_t iter = kUpb_Map_Begin; - * while (upb_MapIterator_Next(map, &iter)) { - * upb_MessageValue key = upb_MapIterator_Key(map, iter); - * upb_MessageValue val = upb_MapIterator_Value(map, iter); - * } - */ - -// Advances to the next entry. Returns false if no more entries are present. -UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); - -// Returns true if the iterator still points to a valid entry, or false if the -// iterator is past the last element. It is an error to call this function with -// kUpb_Map_Begin (you must call next() at least once first). -UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter); - -// Returns the key and value for this entry of the map. -UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); -UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); - -// Mark a map and all of its descendents as frozen/immutable. -// If the map values are messages then |m| must point to the minitable for -// those messages. Otherwise |m| must be NULL. -UPB_API void upb_Map_Freeze(upb_Map* map, const upb_MiniTable* m); - -// Returns whether a map has been frozen. -UPB_API_INLINE bool upb_Map_IsFrozen(const upb_Map* map); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_MAP_H_ */ diff --git a/vendor/upb/message/map_gencode_util.h b/vendor/upb/message/map_gencode_util.h deleted file mode 100644 index ab23a1a..0000000 --- a/vendor/upb/message/map_gencode_util.h +++ /dev/null @@ -1,16 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// These functions are only used by generated code. - -#ifndef UPB_MESSAGE_MAP_GENCODE_UTIL_H_ -#define UPB_MESSAGE_MAP_GENCODE_UTIL_H_ - -// This header file is referenced by multiple files. Leave it empty. -// TODO: b/399481227 - Remove this header file, after all the references are -// cleaned up. -#endif /* UPB_MESSAGE_MAP_GENCODE_UTIL_H_ */ diff --git a/vendor/upb/message/map_sorter.c b/vendor/upb/message/map_sorter.c deleted file mode 100644 index e10ed89..0000000 --- a/vendor/upb/message/map_sorter.c +++ /dev/null @@ -1,194 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/internal/map_sorter.h" - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/internal/log2.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/mem/alloc.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/mini_table/extension.h" - -// Must be last. -#include "upb/port/def.inc" - -static int _upb_mapsorter_intkeys(const void* _a, const void* _b) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - uintptr_t a_key = (*a)->key.num; - uintptr_t b_key = (*b)->key.num; - return a_key < b_key ? -1 : a_key > b_key; -} - -static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, - void* b_key, size_t size) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - upb_StringView a_tabkey = upb_key_strview((*a)->key); - upb_StringView b_tabkey = upb_key_strview((*b)->key); - _upb_map_fromkey(a_tabkey, a_key, size); - _upb_map_fromkey(b_tabkey, b_key, size); -} - -static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { - int64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { - uint64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { - int32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { - uint32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { - bool a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { - upb_StringView a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); - size_t common_size = UPB_MIN(a.size, b.size); - int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return -cmp; - return a.size < b.size ? -1 : a.size > b.size; -} - -static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { - [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, - - [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, - [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, - - [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - - [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, - [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, - - [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, - - [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, - [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, -}; - -static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted, - int size) { - sorted->start = s->size; - sorted->pos = sorted->start; - sorted->end = sorted->start + size; - - if (sorted->end > s->cap) { - const int oldsize = s->cap * sizeof(*s->entries); - s->cap = upb_RoundUpToPowerOfTwo(sorted->end); - const int newsize = s->cap * sizeof(*s->entries); - s->entries = upb_grealloc(s->entries, oldsize, newsize); - if (!s->entries) return false; - } - - s->size = sorted->end; - return true; -} - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted) { - int map_size; - if (map->UPB_PRIVATE(is_strtable)) { - map_size = _upb_Map_Size(map); - } else { - // For inttable, only sort the table entries, since the array part is - // already in a sorted order. - map_size = map->t.inttable.t.count; - } - - if (!_upb_mapsorter_resize(s, sorted, map_size)) return false; - - // Copy non-empty entries from the table to s->entries. - const void** dst = &s->entries[sorted->start]; - const upb_tabent* src; - const upb_tabent* end; - if (map->UPB_PRIVATE(is_strtable)) { - src = map->t.strtable.t.entries; - end = src + upb_table_size(&map->t.strtable.t); - } else { - // For inttable, only sort the table entries, since the array part is - // already in a sorted order. - src = map->t.inttable.t.entries; - end = src + upb_table_size(&map->t.inttable.t); - } - for (; src < end; src++) { - if (!upb_tabent_isempty(src)) { - *dst = src; - dst++; - } - } - UPB_ASSERT(dst == &s->entries[sorted->end]); - - // Sort entries according to the key type. - qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), - map->UPB_PRIVATE(is_strtable) ? compar[key_type] - : _upb_mapsorter_intkeys); - return true; -} - -static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Extension* const* a = _a; - const upb_Extension* const* b = _b; - uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); - uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); - UPB_ASSERT(a_num != b_num); - return a_num < b_num ? -1 : 1; -} - -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Message_Internal* in, - _upb_sortedmap* sorted) { - size_t count = 0; - for (size_t i = 0; i < in->size; i++) { - count += upb_TaggedAuxPtr_IsExtension(in->aux_data[i]); - } - if (!_upb_mapsorter_resize(s, sorted, count)) return false; - if (count == 0) return true; - const upb_Extension** entry = - (const upb_Extension**)&s->entries[sorted->start]; - for (size_t i = 0; i < in->size; i++) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i]; - if (upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - *entry++ = upb_TaggedAuxPtr_Extension(tagged_ptr); - } - } - qsort(&s->entries[sorted->start], count, sizeof(*s->entries), - _upb_mapsorter_cmpext); - return true; -} diff --git a/vendor/upb/message/map_test.cc b/vendor/upb/message/map_test.cc deleted file mode 100644 index f97e573..0000000 --- a/vendor/upb/message/map_test.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/map.h" - -#include -#include "upb/base/string_view.h" -#include "upb/mem/arena.hpp" - -TEST(MapTest, DeleteRegression) { - upb::Arena arena; - upb_Map* map = upb_Map_New(arena.ptr(), kUpb_CType_Int32, kUpb_CType_String); - - upb_MessageValue key; - key.int32_val = 0; - - upb_MessageValue insert_value; - insert_value.str_val = upb_StringView_FromString("abcde"); - - upb_MapInsertStatus st = upb_Map_Insert(map, key, insert_value, arena.ptr()); - EXPECT_EQ(kUpb_MapInsertStatus_Inserted, st); - - upb_MessageValue delete_value; - bool removed = upb_Map_Delete(map, key, &delete_value); - EXPECT_TRUE(removed); - - EXPECT_TRUE( - upb_StringView_IsEqual(insert_value.str_val, delete_value.str_val)); -} diff --git a/vendor/upb/message/merge.c b/vendor/upb/message/merge.c deleted file mode 100644 index 1e786a8..0000000 --- a/vendor/upb/message/merge.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "upb/message/merge.h" - -#include "stddef.h" -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -bool upb_Message_MergeFrom(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mt, - const upb_ExtensionRegistry* extreg, - upb_Arena* arena) { - char* buf = NULL; - size_t size = 0; - // This tmp arena is used to hold the bytes for `src` serialized. This bends - // the typical "no hidden allocations" design of upb, but under a properly - // optimized implementation this extra allocation would not be necessary and - // so we don't want to unnecessarily have the bad API or bloat the passed-in - // arena with this very-short-term allocation. - upb_Arena* encode_arena = upb_Arena_New(); - upb_EncodeStatus e_status = upb_Encode(src, mt, 0, encode_arena, &buf, &size); - if (e_status != kUpb_EncodeStatus_Ok) { - upb_Arena_Free(encode_arena); - return false; - } - upb_DecodeStatus d_status = upb_Decode(buf, size, dst, mt, extreg, 0, arena); - if (d_status != kUpb_DecodeStatus_Ok) { - upb_Arena_Free(encode_arena); - return false; - } - upb_Arena_Free(encode_arena); - return true; -} diff --git a/vendor/upb/message/merge.h b/vendor/upb/message/merge.h deleted file mode 100644 index d27fd45..0000000 --- a/vendor/upb/message/merge.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef GOOGLE_UPB_UPB_MESSAGE_MERGE_H__ -#define GOOGLE_UPB_UPB_MESSAGE_MERGE_H__ - -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_NODISCARD UPB_API bool upb_Message_MergeFrom( - upb_Message* dst, const upb_Message* src, const upb_MiniTable* mt, - const upb_ExtensionRegistry* extreg, upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" -#endif // GOOGLE_UPB_UPB_MESSAGE_MERGE_H__ diff --git a/vendor/upb/message/merge_test.cc b/vendor/upb/message/merge_test.cc deleted file mode 100644 index 5b23aea..0000000 --- a/vendor/upb/message/merge_test.cc +++ /dev/null @@ -1,79 +0,0 @@ -#include "upb/message/merge.h" - -#include -#include - -#include -#include "google/protobuf/test_messages_proto2.upb.h" -#include "google/protobuf/test_messages_proto2.upb_minitable.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace { - -// Proto2 test messages field numbers used for reflective access. -const uint32_t kFieldOptionalInt32 = 1; -const uint32_t kFieldOptionalString = 14; - -const char kTestStr1[] = "Hello1"; -const int32_t kTestInt32 = 567; - -const upb_MiniTableField* find_proto2_field(int field_number) { - return upb_MiniTable_FindFieldByNumber( - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - field_number); -} - -TEST(GeneratedCode, MergeMessageScalarAndString) { - upb_Arena* source_arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(source_arena); - const upb_MiniTableField* optional_int32_field = - find_proto2_field(kFieldOptionalInt32); - const upb_MiniTableField* optional_string_field = - find_proto2_field(kFieldOptionalString); - upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32, - nullptr); - char* string_in_arena = - (char*)upb_Arena_Malloc(source_arena, sizeof(kTestStr1)); - memcpy(string_in_arena, kTestStr1, sizeof(kTestStr1)); - upb_Message_SetString( - UPB_UPCAST(msg), optional_string_field, - upb_StringView_FromDataAndSize(string_in_arena, sizeof(kTestStr1) - 1), - source_arena); - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* clone = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - EXPECT_TRUE( - (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_MergeFrom( - UPB_UPCAST(clone), UPB_UPCAST(msg), - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - nullptr, arena)); - // After cloning overwrite values and destroy source arena for MSAN. - memset(string_in_arena, 0, sizeof(kTestStr1)); - upb_Arena_Free(source_arena); - EXPECT_TRUE( - upb_Message_HasBaseField(UPB_UPCAST(clone), optional_int32_field)); - EXPECT_EQ(upb_Message_GetInt32(UPB_UPCAST(clone), optional_int32_field, 0), - kTestInt32); - EXPECT_TRUE( - upb_Message_HasBaseField(UPB_UPCAST(clone), optional_string_field)); - EXPECT_EQ(upb_Message_GetString(UPB_UPCAST(clone), optional_string_field, - upb_StringView_FromDataAndSize(nullptr, 0)) - .size, - sizeof(kTestStr1) - 1); - EXPECT_TRUE(upb_StringView_IsEqual( - upb_Message_GetString(UPB_UPCAST(clone), optional_string_field, - upb_StringView_FromDataAndSize(nullptr, 0)), - upb_StringView_FromString(kTestStr1))); - upb_Arena_Free(arena); -} - -} // namespace diff --git a/vendor/upb/message/message.c b/vendor/upb/message/message.c deleted file mode 100644 index 78fc0fe..0000000 --- a/vendor/upb/message/message.c +++ /dev/null @@ -1,316 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/message.h" - -#include -#include -#include -#include - -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/message.h" -#include "upb/message/internal/types.h" -#include "upb/message/map.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { - return _upb_Message_New(m, a); -} - -UPB_NOINLINE bool UPB_PRIVATE(_upb_Message_AddUnknownSlowPath)(upb_Message* msg, - const char* data, - size_t len, - upb_Arena* arena, - bool alias) { - { - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - // Alias fast path was already checked in the inline function that calls - // this one - if (!alias && in && in->size) { - upb_TaggedAuxPtr ptr = in->aux_data[in->size - 1]; - if (upb_TaggedAuxPtr_IsUnknown(ptr)) { - upb_StringView* existing = upb_TaggedAuxPtr_UnknownData(ptr); - if (!upb_TaggedAuxPtr_IsUnknownAliased(ptr)) { - // If part of the existing field was deleted at the beginning, we can - // reconstruct it by comparing the address of the end with the address - // of the entry itself; having the non-aliased tag means that the - // string_view and the data it points to are part of the same original - // upb_Arena_Malloc allocation, and the end of the string view - // represents the end of that allocation. - size_t prev_alloc_size = - (existing->data + existing->size) - (char*)existing; - if (SIZE_MAX - prev_alloc_size >= len) { - size_t new_alloc_size = prev_alloc_size + len; - if (upb_Arena_TryExtend(arena, existing, prev_alloc_size, - new_alloc_size)) { - memcpy(UPB_PTR_AT(existing, prev_alloc_size, void), data, len); - existing->size += len; - return true; - } - } - } - } - } - } - // TODO: b/376969853 - Add debug check that the unknown field is an overall - // valid proto field - if (!UPB_PRIVATE(_upb_Message_ReserveSlot)(msg, arena)) { - return false; - } - upb_StringView* view; - if (alias) { - view = upb_Arena_Malloc(arena, sizeof(upb_StringView)); - if (!view) return false; - view->data = data; - } else { - if (SIZE_MAX - sizeof(upb_StringView) < len) return false; - view = upb_Arena_Malloc(arena, sizeof(upb_StringView) + len); - if (!view) return false; - char* copy = UPB_PTR_AT(view, sizeof(upb_StringView), char); - memcpy(copy, data, len); - view->data = copy; - } - view->size = len; - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - in->aux_data[in->size++] = alias - ? upb_TaggedAuxPtr_MakeUnknownDataAliased(view) - : upb_TaggedAuxPtr_MakeUnknownData(view); - return true; -} - -bool UPB_PRIVATE(_upb_Message_AddUnknownV)(struct upb_Message* msg, - upb_Arena* arena, - upb_StringView data[], - size_t count) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - UPB_ASSERT(count > 0); - size_t total_len = 0; - for (size_t i = 0; i < count; i++) { - if (SIZE_MAX - total_len < data[i].size) { - return false; - } - total_len += data[i].size; - } - - { - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (in && in->size) { - upb_TaggedAuxPtr ptr = in->aux_data[in->size - 1]; - if (upb_TaggedAuxPtr_IsUnknown(ptr)) { - upb_StringView* existing = upb_TaggedAuxPtr_UnknownData(ptr); - if (!upb_TaggedAuxPtr_IsUnknownAliased(ptr)) { - size_t prev_alloc_size = - (existing->data + existing->size) - (char*)existing; - if (SIZE_MAX - prev_alloc_size >= total_len) { - size_t new_alloc_size = prev_alloc_size + total_len; - if (upb_Arena_TryExtend(arena, existing, prev_alloc_size, - new_alloc_size)) { - char* copy = UPB_PTR_AT(existing, prev_alloc_size, char); - for (size_t i = 0; i < count; i++) { - memcpy(copy, data[i].data, data[i].size); - copy += data[i].size; - } - existing->size += total_len; - return true; - } - } - } - } - } - } - - if (SIZE_MAX - sizeof(upb_StringView) < total_len) return false; - if (!UPB_PRIVATE(_upb_Message_ReserveSlot)(msg, arena)) return false; - - upb_StringView* view = - upb_Arena_Malloc(arena, sizeof(upb_StringView) + total_len); - if (!view) return false; - char* copy = UPB_PTR_AT(view, sizeof(upb_StringView), char); - view->data = copy; - view->size = total_len; - for (size_t i = 0; i < count; i++) { - memcpy(copy, data[i].data, data[i].size); - copy += data[i].size; - } - // TODO: b/376969853 - Add debug check that the unknown field is an overall - // valid proto field - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - in->aux_data[in->size++] = upb_TaggedAuxPtr_MakeUnknownData(view); - return true; -} - -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) return; - uint32_t size = 0; - for (uint32_t i = 0; i < in->size; i++) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i]; - if (upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - in->aux_data[size++] = tagged_ptr; - } - } - in->size = size; -} - -upb_Message_DeleteUnknownStatus upb_Message_DeleteUnknown(upb_Message* msg, - upb_StringView* data, - uintptr_t* iter, - upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - UPB_ASSERT(*iter != kUpb_Message_UnknownBegin); - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - UPB_ASSERT(in); - UPB_ASSERT(*iter <= in->size); - upb_TaggedAuxPtr unknown_ptr = in->aux_data[*iter - 1]; - UPB_ASSERT(upb_TaggedAuxPtr_IsUnknown(unknown_ptr)); - upb_StringView* unknown = upb_TaggedAuxPtr_UnknownData(unknown_ptr); - if (unknown->data == data->data && unknown->size == data->size) { - // Remove whole field - in->aux_data[*iter - 1] = upb_TaggedAuxPtr_Null(); - } else if (unknown->data == data->data) { - // Strip prefix - unknown->data += data->size; - unknown->size -= data->size; - *data = *unknown; - return kUpb_DeleteUnknown_IterUpdated; - } else if (unknown->data + unknown->size == data->data + data->size) { - // Truncate existing field - unknown->size -= data->size; - if (!upb_TaggedAuxPtr_IsUnknownAliased(unknown_ptr)) { - in->aux_data[*iter - 1] = - upb_TaggedAuxPtr_MakeUnknownDataAliased(unknown); - } - } else { - UPB_ASSERT(unknown->data < data->data && - unknown->data + unknown->size > data->data + data->size); - // Split in the middle - upb_StringView* prefix = unknown; - upb_StringView* suffix = upb_Arena_Malloc(arena, sizeof(upb_StringView)); - if (!suffix) { - return kUpb_DeleteUnknown_AllocFail; - } - if (!UPB_PRIVATE(_upb_Message_ReserveSlot)(msg, arena)) { - return kUpb_DeleteUnknown_AllocFail; - } - in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (*iter != in->size) { - // Shift later entries down so that unknown field ordering is preserved - memmove(&in->aux_data[*iter + 1], &in->aux_data[*iter], - sizeof(upb_TaggedAuxPtr) * (in->size - *iter)); - } - in->aux_data[*iter] = upb_TaggedAuxPtr_MakeUnknownDataAliased(suffix); - if (!upb_TaggedAuxPtr_IsUnknownAliased(unknown_ptr)) { - in->aux_data[*iter - 1] = upb_TaggedAuxPtr_MakeUnknownDataAliased(prefix); - } - in->size++; - suffix->data = data->data + data->size; - suffix->size = (prefix->data + prefix->size) - suffix->data; - prefix->size = data->data - prefix->data; - } - return upb_Message_NextUnknown(msg, data, iter) - ? kUpb_DeleteUnknown_IterUpdated - : kUpb_DeleteUnknown_DeletedLast; -} - -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) return 0; - const upb_MiniTableExtension* ext; - upb_MessageValue val; - uintptr_t iter = kUpb_Message_ExtensionBegin; - size_t count = 0; - while (upb_Message_NextExtension(msg, &ext, &val, &iter)) { - count++; - } - return count; -} - -void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m) { - if (upb_Message_IsFrozen(msg)) return; - UPB_PRIVATE(_upb_Message_ShallowFreeze)(msg); - - // Base Fields. - const size_t field_count = upb_MiniTable_FieldCount(m); - - for (size_t i = 0; i < field_count; i++) { - const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i); - const upb_MiniTable* m2 = upb_MiniTable_SubMessage(f); - - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) { - case kUpb_FieldMode_Array: { - upb_Array* arr = upb_Message_GetMutableArray(msg, f); - if (arr) upb_Array_Freeze(arr, m2); - break; - } - case kUpb_FieldMode_Map: { - upb_Map* map = upb_Message_GetMutableMap(msg, f); - if (map) { - const upb_MiniTableField* f2 = upb_MiniTable_MapValue(m2); - const upb_MiniTable* m3 = upb_MiniTable_SubMessage(f2); - upb_Map_Freeze(map, m3); - } - break; - } - case kUpb_FieldMode_Scalar: { - if (m2) { - upb_Message* msg2 = upb_Message_GetMutableMessage(msg, f); - if (msg2) upb_Message_Freeze(msg2, m2); - } - break; - } - } - } - - // Extensions. - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - // TODO: b/376969853 - use iterator API - uint32_t size = in ? in->size : 0; - for (size_t i = 0; i < size; i++) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i]; - if (!upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - continue; - } - const upb_Extension* ext = upb_TaggedAuxPtr_Extension(tagged_ptr); - const upb_MiniTableExtension* e = ext->ext; - const upb_MiniTableField* f = &e->UPB_PRIVATE(field); - const upb_MiniTable* m2 = upb_MiniTableExtension_GetSubMessage(e); - - upb_MessageValue val; - memcpy(&val, &(ext->data), sizeof(upb_MessageValue)); - - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) { - case kUpb_FieldMode_Array: { - upb_Array* arr = (upb_Array*)val.array_val; - if (arr) upb_Array_Freeze(arr, m2); - break; - } - case kUpb_FieldMode_Map: - UPB_UNREACHABLE(); // Maps cannot be extensions. - break; - case kUpb_FieldMode_Scalar: - if (upb_MiniTableField_IsSubMessage(f)) { - upb_Message* msg2 = (upb_Message*)val.msg_val; - if (msg2) upb_Message_Freeze(msg2, m2); - } - break; - } - } -} diff --git a/vendor/upb/message/message.h b/vendor/upb/message/message.h deleted file mode 100644 index bcceebd..0000000 --- a/vendor/upb/message/message.h +++ /dev/null @@ -1,127 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// Public APIs for message operations that do not depend on the schema. -// -// MiniTable-based accessors live in accessors.h. - -#ifndef UPB_MESSAGE_MESSAGE_H_ -#define UPB_MESSAGE_MESSAGE_H_ - -#include -#include - -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/message.h" -#include "upb/message/internal/types.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_Message upb_Message; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new message with the given mini_table on the given arena. -UPB_NODISCARD UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, - upb_Arena* arena); - -// -// Unknown data may be stored non-contiguously. Each segment stores a block of -// unknown fields. To iterate over segments: -// -// uintptr_t iter = kUpb_Message_UnknownBegin; -// upb_StringView data; -// while (upb_Message_NextUnknown(msg, &data, &iter)) { -// // Use data -// } -// Iterates in the order unknown fields were parsed. - -#define kUpb_Message_UnknownBegin 0 -#define kUpb_Message_ExtensionBegin 0 - -UPB_INLINE bool upb_Message_NextUnknown(const upb_Message* msg, - upb_StringView* data, uintptr_t* iter); - -UPB_INLINE bool upb_Message_HasUnknown(const upb_Message* msg); - -// Removes a segment of unknown data from the message, advancing to the next -// segment. Returns false if the removed segment was at the end of the last -// chunk. -// -// This must be done while iterating: -// -// uintptr_t iter = kUpb_Message_UnknownBegin; -// upb_StringView data; -// // Iterate chunks -// while (upb_Message_NextUnknown(msg, &data, &iter)) { -// // Iterate within a chunk, deleting ranges -// while (ShouldDeleteSubSegment(&data)) { -// // Data now points to the region to be deleted -// switch (upb_Message_DeleteUnknown(msg, &data, &iter)) { -// case kUpb_Message_DeleteUnknown_DeletedLast: return ok; -// case kUpb_Message_DeleteUnknown_IterUpdated: break; -// // If DeleteUnknown returned kUpb_Message_DeleteUnknown_IterUpdated, -// // then data now points to the remaining unknown fields after the -// // region that was just deleted. -// case kUpb_Message_DeleteUnknown_AllocFail: return err; -// } -// } -// } -// -// The range given in `data` must be contained inside the most recently -// returned region. -typedef enum upb_Message_DeleteUnknownStatus { - kUpb_DeleteUnknown_DeletedLast, - kUpb_DeleteUnknown_IterUpdated, - kUpb_DeleteUnknown_AllocFail, -} upb_Message_DeleteUnknownStatus; -UPB_NODISCARD upb_Message_DeleteUnknownStatus upb_Message_DeleteUnknown( - upb_Message* msg, upb_StringView* data, uintptr_t* iter, upb_Arena* arena); - -// Returns the number of extensions present in this message. -size_t upb_Message_ExtensionCount(const upb_Message* msg); - -// Iterates extensions in wire order -UPB_INLINE bool upb_Message_NextExtension(const upb_Message* msg, - const upb_MiniTableExtension** out_e, - upb_MessageValue* out_v, - uintptr_t* iter); - -// Iterates extensions in reverse wire order -UPB_INLINE bool UPB_PRIVATE(_upb_Message_NextExtensionReverse)( - const struct upb_Message* msg, const upb_MiniTableExtension** out_e, - upb_MessageValue* out_v, uintptr_t* iter); - -// Mark a message and all of its descendents as frozen/immutable. -UPB_API void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m); - -// Returns whether a message has been frozen. -UPB_API_INLINE bool upb_Message_IsFrozen(const upb_Message* msg); - -#ifdef UPB_TRACING_ENABLED -UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m, - const upb_Arena* arena); - -UPB_API void upb_Message_SetNewMessageTraceHandler( - void (*handler)(const upb_MiniTable* m, const upb_Arena* arena)); -#endif // UPB_TRACING_ENABLED - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_MESSAGE_H_ */ diff --git a/vendor/upb/message/promote.c b/vendor/upb/message/promote.c deleted file mode 100644 index baf0c9c..0000000 --- a/vendor/upb/message/promote.c +++ /dev/null @@ -1,340 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/message/promote.h" - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/reader.h" - -// Must be last. -#include "upb/port/def.inc" - -// Parses unknown data by merging into existing base_message or creating a -// new message usingg mini_table. -static upb_UnknownToMessageRet upb_MiniTable_ParseUnknownMessage( - const char* unknown_data, size_t unknown_size, - const upb_MiniTable* mini_table, upb_Message* base_message, - int decode_options, upb_Arena* arena) { - upb_UnknownToMessageRet ret; - ret.message = - base_message ? base_message : _upb_Message_New(mini_table, arena); - if (!ret.message) { - ret.status = kUpb_UnknownToMessage_OutOfMemory; - return ret; - } - // Decode sub message using unknown field contents. - const char* data = unknown_data; - uint32_t tag; - uint64_t message_len = 0; - data = upb_WireReader_ReadTag(data, &tag, NULL); - data = upb_WireReader_ReadVarint(data, &message_len, NULL); - upb_DecodeStatus status = upb_Decode(data, message_len, ret.message, - mini_table, NULL, decode_options, arena); - if (status == kUpb_DecodeStatus_OutOfMemory) { - ret.status = kUpb_UnknownToMessage_OutOfMemory; - } else if (status == kUpb_DecodeStatus_Ok) { - ret.status = kUpb_UnknownToMessage_Ok; - } else { - ret.status = kUpb_UnknownToMessage_ParseError; - } - return ret; -} - -upb_GetExtension_Status upb_Message_GetOrPromoteExtension( - upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, upb_MessageValue* value) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - UPB_ASSERT(upb_MiniTableExtension_CType(ext_table) == kUpb_CType_Message); - const upb_Extension* extension = - UPB_PRIVATE(_upb_Message_Getext)(msg, ext_table); - if (extension) { - memcpy(value, &extension->data, sizeof(upb_MessageValue)); - return kUpb_GetExtension_Ok; - } - - // Check unknown fields, if available promote. - int found_count = 0; - uint32_t field_number = upb_MiniTableExtension_Number(ext_table); - const upb_MiniTable* extension_table = - upb_MiniTableExtension_GetSubMessage(ext_table); - // Will be populated on first parse and then reused - upb_Message* extension_msg = NULL; - int depth_limit = 100; - uintptr_t iter = kUpb_Message_UnknownBegin; - upb_StringView data; - while (upb_Message_NextUnknown(msg, &data, &iter)) { - const char* ptr = data.data; - upb_EpsCopyInputStream stream; - upb_EpsCopyInputStream_Init(&stream, &ptr, data.size); - while (!upb_EpsCopyInputStream_IsDone(&stream, &ptr)) { - uint32_t tag; - const char* unknown_begin = ptr; - ptr = upb_WireReader_ReadTag(ptr, &tag, &stream); - if (!ptr) return kUpb_GetExtension_ParseError; - if (field_number == upb_WireReader_GetFieldNumber(tag)) { - upb_StringView data; - found_count++; - upb_EpsCopyInputStream_StartCapture(&stream, unknown_begin); - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, &stream); - if (!ptr || !upb_EpsCopyInputStream_EndCapture(&stream, ptr, &data)) { - return kUpb_GetExtension_ParseError; - } - upb_UnknownToMessageRet parse_result = - upb_MiniTable_ParseUnknownMessage( - data.data, data.size, extension_table, - /* base_message= */ extension_msg, decode_options, arena); - switch (parse_result.status) { - case kUpb_UnknownToMessage_OutOfMemory: - return kUpb_GetExtension_OutOfMemory; - case kUpb_UnknownToMessage_ParseError: - return kUpb_GetExtension_ParseError; - case kUpb_UnknownToMessage_NotFound: - return kUpb_GetExtension_NotPresent; - case kUpb_UnknownToMessage_Ok: - extension_msg = parse_result.message; - } - } else { - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, &stream); - if (!ptr) return kUpb_GetExtension_ParseError; - } - } - } - if (!extension_msg) { - return kUpb_GetExtension_NotPresent; - } - - upb_Extension* ext = - UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(msg, ext_table, arena); - if (!ext) { - return kUpb_GetExtension_OutOfMemory; - } - ext->data.msg_val = extension_msg; - - while (found_count > 0) { - upb_FindUnknownRet found = upb_Message_FindUnknown(msg, field_number, 0); - UPB_ASSERT(found.status == kUpb_FindUnknown_Ok); - upb_StringView view = {.data = found.ptr, .size = found.len}; - if (upb_Message_DeleteUnknown(msg, &view, &found.iter, arena) == - kUpb_DeleteUnknown_AllocFail) { - return kUpb_GetExtension_OutOfMemory; - } - found_count--; - } - value->msg_val = extension_msg; - return kUpb_GetExtension_Ok; -} - -static upb_FindUnknownRet upb_FindUnknownRet_ParseError(void) { - return (upb_FindUnknownRet){.status = kUpb_FindUnknown_ParseError}; -} - -upb_FindUnknownRet upb_Message_FindUnknown(const upb_Message* msg, - uint32_t field_number, - int depth_limit) { - depth_limit = depth_limit ? depth_limit : 100; - upb_FindUnknownRet ret; - ret.iter = kUpb_Message_UnknownBegin; - upb_StringView data; - while (upb_Message_NextUnknown(msg, &data, &ret.iter)) { - upb_EpsCopyInputStream stream; - const char* ptr = data.data; - upb_EpsCopyInputStream_Init(&stream, &ptr, data.size); - - while (!upb_EpsCopyInputStream_IsDone(&stream, &ptr)) { - uint32_t tag; - const char* unknown_begin = ptr; - ptr = upb_WireReader_ReadTag(ptr, &tag, &stream); - if (!ptr) return upb_FindUnknownRet_ParseError(); - if (field_number == upb_WireReader_GetFieldNumber(tag)) { - upb_StringView data; - ret.status = kUpb_FindUnknown_Ok; - upb_EpsCopyInputStream_StartCapture(&stream, unknown_begin); - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, &stream); - if (!ptr || !upb_EpsCopyInputStream_EndCapture(&stream, ptr, &data)) { - return upb_FindUnknownRet_ParseError(); - } - ret.ptr = data.data; - ret.len = data.size; - return ret; - } - - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, &stream); - if (!ptr) return upb_FindUnknownRet_ParseError(); - } - } - ret.status = kUpb_FindUnknown_NotPresent; - ret.ptr = NULL; - ret.len = 0; - ret.iter = kUpb_Message_UnknownBegin; - return ret; -} - -// Warning: See TODO -upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage( - upb_Message* msg, const upb_MiniTable* mini_table, - const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table, - int decode_options, upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_FindUnknownRet unknown; - // We need to loop and merge unknowns that have matching tag field->number. - upb_Message* message = NULL; - // Callers should check that message is not set first before calling - // PromotoUnknownToMessage. - UPB_ASSERT(upb_MiniTable_GetSubMessageTable(field) == sub_mini_table); - bool is_oneof = upb_MiniTableField_IsInOneof(field); - if (!is_oneof || UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, field) == - upb_MiniTableField_Number(field)) { - UPB_ASSERT(upb_Message_GetMessage(msg, field) == NULL); - } - upb_UnknownToMessageRet ret; - ret.status = kUpb_UnknownToMessage_Ok; - do { - unknown = upb_Message_FindUnknown( - msg, upb_MiniTableField_Number(field), - upb_DecodeOptions_GetEffectiveMaxDepth(decode_options)); - switch (unknown.status) { - case kUpb_FindUnknown_Ok: { - const char* unknown_data = unknown.ptr; - size_t unknown_size = unknown.len; - ret = upb_MiniTable_ParseUnknownMessage(unknown_data, unknown_size, - sub_mini_table, message, - decode_options, arena); - if (ret.status == kUpb_UnknownToMessage_Ok) { - message = ret.message; - upb_StringView del = - upb_StringView_FromDataAndSize(unknown_data, unknown_size); - upb_Message_DeleteUnknown(msg, &del, &(unknown.iter), arena); - } - } break; - case kUpb_FindUnknown_ParseError: - ret.status = kUpb_UnknownToMessage_ParseError; - break; - case kUpb_FindUnknown_NotPresent: - // If we parsed at least one unknown, we are done. - ret.status = - message ? kUpb_UnknownToMessage_Ok : kUpb_UnknownToMessage_NotFound; - break; - } - } while (unknown.status == kUpb_FindUnknown_Ok); - if (message) { - if (is_oneof) { - UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, field); - } - upb_Message_SetMessage(msg, field, message); - ret.message = message; - } - return ret; -} - -// Moves repeated messages in unknowns to a upb_Array. -// -// Since the repeated field is not a scalar type we don't check for -// kUpb_LabelFlags_IsPacked. -// TODO: Optimize. Instead of converting messages one at a time, -// scan all unknown data once and compact. -upb_UnknownToMessage_Status upb_MiniTable_PromoteUnknownToMessageArray( - upb_Message* msg, const upb_MiniTableField* field, - const upb_MiniTable* mini_table, int decode_options, upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - - upb_Array* repeated_messages = upb_Message_GetMutableArray(msg, field); - // Find all unknowns with given field number and parse. - upb_FindUnknownRet unknown; - do { - unknown = upb_Message_FindUnknown( - msg, upb_MiniTableField_Number(field), - upb_DecodeOptions_GetEffectiveMaxDepth(decode_options)); - if (unknown.status == kUpb_FindUnknown_Ok) { - upb_UnknownToMessageRet ret = upb_MiniTable_ParseUnknownMessage( - unknown.ptr, unknown.len, mini_table, - /* base_message= */ NULL, decode_options, arena); - if (ret.status == kUpb_UnknownToMessage_Ok) { - upb_MessageValue value; - value.msg_val = ret.message; - // Allocate array on demand before append. - if (!repeated_messages) { - upb_Message_ResizeArrayUninitialized(msg, field, 0, arena); - repeated_messages = upb_Message_GetMutableArray(msg, field); - } - if (!upb_Array_Append(repeated_messages, value, arena)) { - return kUpb_UnknownToMessage_OutOfMemory; - } - upb_StringView del = - upb_StringView_FromDataAndSize(unknown.ptr, unknown.len); - upb_Message_DeleteUnknown(msg, &del, &unknown.iter, arena); - } else { - return ret.status; - } - } - } while (unknown.status == kUpb_FindUnknown_Ok); - return kUpb_UnknownToMessage_Ok; -} - -// Moves repeated messages in unknowns to a upb_Map. -upb_UnknownToMessage_Status upb_MiniTable_PromoteUnknownToMap( - upb_Message* msg, const upb_MiniTable* mini_table, - const upb_MiniTableField* field, int decode_options, upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - - const upb_MiniTable* map_entry_mini_table = - upb_MiniTable_MapEntrySubMessage(field); - UPB_ASSERT(upb_MiniTable_FieldCount(map_entry_mini_table) == 2); - // Find all unknowns with given field number and parse. - upb_FindUnknownRet unknown; - while (1) { - unknown = upb_Message_FindUnknown( - msg, upb_MiniTableField_Number(field), - upb_DecodeOptions_GetEffectiveMaxDepth(decode_options)); - if (unknown.status != kUpb_FindUnknown_Ok) break; - upb_UnknownToMessageRet ret = upb_MiniTable_ParseUnknownMessage( - unknown.ptr, unknown.len, map_entry_mini_table, - /* base_message= */ NULL, decode_options, arena); - if (ret.status != kUpb_UnknownToMessage_Ok) return ret.status; - // Allocate map on demand before append. - upb_Map* map = upb_Message_GetOrCreateMutableMap(msg, map_entry_mini_table, - field, arena); - upb_Message* map_entry_message = ret.message; - bool insert_success = - upb_Message_SetMapEntry(map, field, map_entry_message, arena); - if (!insert_success) return kUpb_UnknownToMessage_OutOfMemory; - upb_StringView del = - upb_StringView_FromDataAndSize(unknown.ptr, unknown.len); - upb_Message_DeleteUnknown(msg, &del, &unknown.iter, arena); - } - return kUpb_UnknownToMessage_Ok; -} - -const char* upb_FindUnknownStatus_String(upb_FindUnknown_Status status) { - switch (status) { - case kUpb_FindUnknown_Ok: - return "Ok"; - case kUpb_FindUnknown_ParseError: - return "Parse error"; - case kUpb_FindUnknown_NotPresent: - return "Field not found"; - default: - return "Unknown status"; - } -} diff --git a/vendor/upb/message/promote.h b/vendor/upb/message/promote.h deleted file mode 100644 index b2c5073..0000000 --- a/vendor/upb/message/promote.h +++ /dev/null @@ -1,126 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_PROMOTE_H_ -#define UPB_MESSAGE_PROMOTE_H_ - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - kUpb_GetExtension_Ok, - kUpb_GetExtension_NotPresent, - kUpb_GetExtension_ParseError, - kUpb_GetExtension_OutOfMemory, -} upb_GetExtension_Status; - -typedef enum { - kUpb_GetExtensionAsBytes_Ok, - kUpb_GetExtensionAsBytes_NotPresent, - kUpb_GetExtensionAsBytes_EncodeError, -} upb_GetExtensionAsBytes_Status; - -// Returns a message value or promotes an unknown field to an extension. -// -// TODO: Only supports extension fields that are messages, -// expand support to include non-message types. -UPB_NODISCARD upb_GetExtension_Status upb_Message_GetOrPromoteExtension( - upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, upb_MessageValue* value); - -typedef enum { - kUpb_FindUnknown_Ok, - kUpb_FindUnknown_NotPresent, - kUpb_FindUnknown_ParseError, -} upb_FindUnknown_Status; - -typedef struct { - upb_FindUnknown_Status status; - // Start of unknown field data in message arena. - const char* ptr; - // Size of unknown field data. - size_t len; - uintptr_t iter; -} upb_FindUnknownRet; - -// Finds first occurrence of unknown data by tag id in message. -// A depth_limit of zero means to just use the upb default depth limit. -upb_FindUnknownRet upb_Message_FindUnknown(const upb_Message* msg, - uint32_t field_number, - int depth_limit); - -typedef enum { - kUpb_UnknownToMessage_Ok, - kUpb_UnknownToMessage_ParseError, - kUpb_UnknownToMessage_OutOfMemory, - kUpb_UnknownToMessage_NotFound, -} upb_UnknownToMessage_Status; - -typedef struct { - upb_UnknownToMessage_Status status; - upb_Message* message; -} upb_UnknownToMessageRet; - -// Utility function for wrapper languages to get an error string from a -// upb_UnknownToMessageStatus. -const char* upb_FindUnknownStatus_String(upb_FindUnknown_Status status); - -// Promotes unknown data inside message to a upb_Message parsing the unknown. -// -// The unknown data is removed from message after field value is set -// using upb_Message_SetMessage. -// -// WARNING!: See b/267655898 -UPB_NODISCARD upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage( - upb_Message* msg, const upb_MiniTable* mini_table, - const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table, - int decode_options, upb_Arena* arena); - -// Promotes all unknown data that matches field tag id to repeated messages -// in upb_Array. -// -// The unknown data is removed from message after upb_Array is populated. -// Since repeated messages can't be packed we remove each unknown that -// contains the target tag id. -UPB_NODISCARD upb_UnknownToMessage_Status -upb_MiniTable_PromoteUnknownToMessageArray(upb_Message* msg, - const upb_MiniTableField* field, - const upb_MiniTable* mini_table, - int decode_options, - upb_Arena* arena); - -// Promotes all unknown data that matches field tag id to upb_Map. -// -// The unknown data is removed from message after upb_Map is populated. -// Since repeated messages can't be packed we remove each unknown that -// contains the target tag id. -UPB_NODISCARD upb_UnknownToMessage_Status upb_MiniTable_PromoteUnknownToMap( - upb_Message* msg, const upb_MiniTable* mini_table, - const upb_MiniTableField* field, int decode_options, upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MESSAGE_PROMOTE_H_ diff --git a/vendor/upb/message/promote_test.cc b/vendor/upb/message/promote_test.cc deleted file mode 100644 index 21906c1..0000000 --- a/vendor/upb/message/promote_test.cc +++ /dev/null @@ -1,508 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* Test of mini table accessors. - * - * Messages are created and mutated using generated code, and then - * accessed through reflective APIs exposed through mini table accessors. - */ - -#include "upb/message/promote.h" - -#include - -#include -#include -#include - -#include -#include "absl/strings/string_view.h" -#include "upb/base/descriptor_constants.h" -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/copy.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_descriptor/internal/encode.hpp" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_descriptor/link.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/test/test.upb.h" -#include "upb/test/test.upb_minitable.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" - -namespace { - -size_t GetUnknownLength(const upb_Message* msg) { - size_t len = 0; - upb_StringView data; - uintptr_t iter = kUpb_Message_UnknownBegin; - while (upb_Message_NextUnknown(msg, &data, &iter)) { - len += data.size; - } - return len; -} - -TEST(GeneratedCode, FindUnknown) { - upb_Arena* arena = upb_Arena_New(); - upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena); - upb_test_ModelWithExtensions_set_random_int32(msg, 10); - upb_test_ModelWithExtensions_set_random_name( - msg, upb_StringView_FromString("Hello")); - - upb_test_ModelExtension1* extension1 = upb_test_ModelExtension1_new(arena); - upb_test_ModelExtension1_set_str(extension1, - upb_StringView_FromString("World")); - - upb_test_ModelExtension1_set_model_ext(msg, extension1, arena); - - size_t serialized_size; - char* serialized = - upb_test_ModelWithExtensions_serialize(msg, arena, &serialized_size); - - upb_test_EmptyMessageWithExtensions* base_msg = - upb_test_EmptyMessageWithExtensions_parse(serialized, serialized_size, - arena); - - upb_FindUnknownRet result = upb_Message_FindUnknown( - UPB_UPCAST(base_msg), - upb_MiniTableExtension_Number(upb_test_ModelExtension1_model_ext_ext), 0); - EXPECT_EQ(kUpb_FindUnknown_Ok, result.status); - - result = upb_Message_FindUnknown( - UPB_UPCAST(base_msg), - upb_MiniTableExtension_Number(upb_test_ModelExtension2_model_ext_ext), 0); - EXPECT_EQ(kUpb_FindUnknown_NotPresent, result.status); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, PromoteFromMultiple) { - int options = kUpb_DecodeOption_AliasString; - upb_Arena* arena = upb_Arena_New(); - upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena); - - upb_test_ModelExtension1* extension1 = upb_test_ModelExtension1_new(arena); - upb_test_ModelExtension1_set_str(extension1, - upb_StringView_FromString("World")); - - upb_test_ModelExtension1_set_model_ext(msg, extension1, arena); - - size_t serialized_size; - char* serialized1 = - upb_test_ModelWithExtensions_serialize(msg, arena, &serialized_size); - - upb_test_ModelExtension1_set_str(extension1, - upb_StringView_FromString("Everyone")); - size_t serialized_size2; - char* serialized2 = - upb_test_ModelWithExtensions_serialize(msg, arena, &serialized_size2); - char* concat = - (char*)upb_Arena_Malloc(arena, serialized_size + serialized_size2); - memcpy(concat, serialized1, serialized_size); - memcpy(concat + serialized_size, serialized2, serialized_size2); - - upb_test_ModelWithExtensions* parsed = upb_test_ModelWithExtensions_parse_ex( - concat, serialized_size + serialized_size2, - upb_ExtensionRegistry_New(arena), options, arena); - - upb_MessageValue value; - upb_GetExtension_Status result = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(parsed), upb_test_ModelExtension1_model_ext_ext, options, - arena, &value); - ASSERT_EQ(result, kUpb_GetExtension_Ok); - upb_test_ModelExtension1* parsed_ex = - (upb_test_ModelExtension1*)value.msg_val; - upb_StringView field = upb_test_ModelExtension1_str(parsed_ex); - EXPECT_EQ(absl::string_view(field.data, field.size), "Everyone"); - - upb_FindUnknownRet found = upb_Message_FindUnknown( - UPB_UPCAST(parsed), - upb_MiniTableExtension_Number(upb_test_ModelExtension1_model_ext_ext), 0); - EXPECT_EQ(kUpb_FindUnknown_NotPresent, found.status); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, Extensions) { - upb_Arena* arena = upb_Arena_New(); - upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena); - upb_test_ModelWithExtensions_set_random_int32(msg, 10); - upb_test_ModelWithExtensions_set_random_name( - msg, upb_StringView_FromString("Hello")); - - upb_test_ModelExtension1* extension1 = upb_test_ModelExtension1_new(arena); - upb_test_ModelExtension1_set_str(extension1, - upb_StringView_FromString("World")); - - upb_test_ModelExtension2* extension2 = upb_test_ModelExtension2_new(arena); - upb_test_ModelExtension2_set_i(extension2, 5); - - upb_test_ModelExtension2* extension3 = upb_test_ModelExtension2_new(arena); - upb_test_ModelExtension2_set_i(extension3, 6); - - upb_test_ModelExtension2* extension4 = upb_test_ModelExtension2_new(arena); - upb_test_ModelExtension2_set_i(extension4, 7); - - upb_test_ModelExtension2* extension5 = upb_test_ModelExtension2_new(arena); - upb_test_ModelExtension2_set_i(extension5, 8); - - upb_test_ModelExtension2* extension6 = upb_test_ModelExtension2_new(arena); - upb_test_ModelExtension2_set_i(extension6, 9); - - // Set many extensions, to exercise code paths that involve reallocating the - // extensions and unknown fields array. - upb_test_ModelExtension1_set_model_ext(msg, extension1, arena); - upb_test_ModelExtension2_set_model_ext(msg, extension2, arena); - upb_test_ModelExtension2_set_model_ext_2(msg, extension3, arena); - upb_test_ModelExtension2_set_model_ext_3(msg, extension4, arena); - upb_test_ModelExtension2_set_model_ext_4(msg, extension5, arena); - upb_test_ModelExtension2_set_model_ext_5(msg, extension6, arena); - - size_t serialized_size; - char* serialized = - upb_test_ModelWithExtensions_serialize(msg, arena, &serialized_size); - - upb_test_ModelExtension1* ext1; - upb_test_ModelExtension2* ext2; - upb_GetExtension_Status promote_status; - upb_MessageValue value; - - // Test known GetExtension 1 - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(msg), upb_test_ModelExtension1_model_ext_ext, 0, arena, - &value); - ext1 = (upb_test_ModelExtension1*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"), - upb_test_ModelExtension1_str(ext1))); - - // Test known GetExtension 2 - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(msg), upb_test_ModelExtension2_model_ext_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2)); - - // Test known GetExtension 3 - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(msg), upb_test_ModelExtension2_model_ext_2_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2)); - - // Test known GetExtension 4 - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(msg), upb_test_ModelExtension2_model_ext_3_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2)); - - // Test known GetExtension 5 - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(msg), upb_test_ModelExtension2_model_ext_4_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2)); - - // Test known GetExtension 6 - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(msg), upb_test_ModelExtension2_model_ext_5_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); - - upb_test_EmptyMessageWithExtensions* base_msg = - upb_test_EmptyMessageWithExtensions_parse(serialized, serialized_size, - arena); - - // Get unknown extension bytes before promotion. - size_t start_len = GetUnknownLength(UPB_UPCAST(base_msg)); - EXPECT_GT(start_len, 0); - EXPECT_EQ(0, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - // Test unknown GetExtension. - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(base_msg), upb_test_ModelExtension1_model_ext_ext, 0, arena, - &value); - ext1 = (upb_test_ModelExtension1*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"), - upb_test_ModelExtension1_str(ext1))); - EXPECT_EQ(1, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - // Test unknown GetExtension. - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(base_msg), upb_test_ModelExtension2_model_ext_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2)); - EXPECT_EQ(2, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - // Test unknown GetExtension. - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(base_msg), upb_test_ModelExtension2_model_ext_2_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2)); - EXPECT_EQ(3, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - // Test unknown GetExtension. - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(base_msg), upb_test_ModelExtension2_model_ext_3_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2)); - EXPECT_EQ(4, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - // Test unknown GetExtension. - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(base_msg), upb_test_ModelExtension2_model_ext_4_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2)); - EXPECT_EQ(5, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - // Test unknown GetExtension. - promote_status = upb_Message_GetOrPromoteExtension( - UPB_UPCAST(base_msg), upb_test_ModelExtension2_model_ext_5_ext, 0, arena, - &value); - ext2 = (upb_test_ModelExtension2*)value.msg_val; - EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); - EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); - EXPECT_EQ(6, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - size_t end_len = GetUnknownLength(UPB_UPCAST(base_msg)); - EXPECT_LT(end_len, start_len); - EXPECT_EQ(6, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); - - upb_Arena_Free(arena); -} - -// Create a minitable to mimic ModelWithSubMessages with unlinked subs -// to lazily promote unknowns after parsing. -upb_MiniTable* CreateMiniTableWithEmptySubTablesOld(upb_Arena* arena) { - upb::MtDataEncoder e; - e.StartMessage(0); - e.PutField(kUpb_FieldType_Int32, 4, 0); - e.PutField(kUpb_FieldType_Message, 5, 0); - e.PutField(kUpb_FieldType_Message, 6, kUpb_FieldModifier_IsRepeated); - - upb_Status status; - upb_Status_Clear(&status); - upb_MiniTable* table = - upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status); - EXPECT_EQ(status.ok, true); - return table; -} - -// Create a minitable to mimic ModelWithMaps with unlinked subs -// to lazily promote unknowns after parsing. -upb_MiniTable* CreateMiniTableWithEmptySubTablesForMapsOld(upb_Arena* arena) { - upb::MtDataEncoder e; - e.StartMessage(0); - e.PutField(kUpb_FieldType_Int32, 1, 0); - e.PutField(kUpb_FieldType_Message, 3, kUpb_FieldModifier_IsRepeated); - e.PutField(kUpb_FieldType_Message, 4, kUpb_FieldModifier_IsRepeated); - - upb_Status status; - upb_Status_Clear(&status); - upb_MiniTable* table = - upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status); - EXPECT_EQ(status.ok, true); - return table; -} - -upb_MiniTable* CreateMapEntryMiniTableOld(upb_Arena* arena) { - upb::MtDataEncoder e; - e.EncodeMap(kUpb_FieldType_String, kUpb_FieldType_String, 0, 0); - upb_Status status; - upb_Status_Clear(&status); - upb_MiniTable* table = - upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status); - EXPECT_EQ(status.ok, true); - return table; -} - -TEST(GeneratedCode, PromoteUnknownMessageOld) { - upb_Arena* arena = upb_Arena_New(); - upb_test_ModelWithSubMessages* input_msg = - upb_test_ModelWithSubMessages_new(arena); - upb_test_ModelWithExtensions* sub_message = - upb_test_ModelWithExtensions_new(arena); - upb_test_ModelWithSubMessages_set_id(input_msg, 11); - upb_test_ModelWithExtensions_set_random_int32(sub_message, 12); - upb_test_ModelWithSubMessages_set_optional_child(input_msg, sub_message); - size_t serialized_size; - char* serialized = upb_test_ModelWithSubMessages_serialize(input_msg, arena, - &serialized_size); - - upb_MiniTable* mini_table = CreateMiniTableWithEmptySubTablesOld(arena); - upb_Message* msg = _upb_Message_New(mini_table, arena); - upb_DecodeStatus decode_status = upb_Decode(serialized, serialized_size, msg, - mini_table, nullptr, 0, arena); - EXPECT_EQ(decode_status, kUpb_DecodeStatus_Ok); - int32_t val = upb_Message_GetInt32( - msg, upb_MiniTable_FindFieldByNumber(mini_table, 4), 0); - EXPECT_EQ(val, 11); - upb_FindUnknownRet unknown = upb_Message_FindUnknown(msg, 5, 0); - EXPECT_EQ(unknown.status, kUpb_FindUnknown_Ok); - // Update mini table and promote unknown to a message. - EXPECT_TRUE(upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(mini_table, 1), - &upb_0test__ModelWithExtensions_msg_init)); - const int decode_options = - upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled. - upb_UnknownToMessageRet promote_result = - upb_MiniTable_PromoteUnknownToMessage( - msg, mini_table, upb_MiniTable_GetFieldByIndex(mini_table, 1), - &upb_0test__ModelWithExtensions_msg_init, decode_options, arena); - EXPECT_EQ(promote_result.status, kUpb_UnknownToMessage_Ok); - const upb_Message* promoted_message = - upb_Message_GetMessage(msg, upb_MiniTable_GetFieldByIndex(mini_table, 1)); - EXPECT_EQ(upb_test_ModelWithExtensions_random_int32( - (upb_test_ModelWithExtensions*)promoted_message), - 12); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, PromoteUnknownRepeatedMessageOld) { - upb_Arena* arena = upb_Arena_New(); - upb_test_ModelWithSubMessages* input_msg = - upb_test_ModelWithSubMessages_new(arena); - upb_test_ModelWithSubMessages_set_id(input_msg, 123); - - // Add 2 repeated messages to input_msg. - upb_test_ModelWithExtensions* item = - upb_test_ModelWithSubMessages_add_items(input_msg, arena); - upb_test_ModelWithExtensions_set_random_int32(item, 5); - item = upb_test_ModelWithSubMessages_add_items(input_msg, arena); - upb_test_ModelWithExtensions_set_random_int32(item, 6); - - size_t serialized_size; - char* serialized = upb_test_ModelWithSubMessages_serialize(input_msg, arena, - &serialized_size); - - upb_MiniTable* mini_table = CreateMiniTableWithEmptySubTablesOld(arena); - upb_Message* msg = _upb_Message_New(mini_table, arena); - upb_DecodeStatus decode_status = upb_Decode(serialized, serialized_size, msg, - mini_table, nullptr, 0, arena); - EXPECT_EQ(decode_status, kUpb_DecodeStatus_Ok); - int32_t val = upb_Message_GetInt32( - msg, upb_MiniTable_FindFieldByNumber(mini_table, 4), 0); - EXPECT_EQ(val, 123); - - // Check that we have repeated field data in an unknown. - upb_FindUnknownRet unknown = upb_Message_FindUnknown(msg, 6, 0); - EXPECT_EQ(unknown.status, kUpb_FindUnknown_Ok); - - // Update mini table and promote unknown to a message. - EXPECT_TRUE(upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(mini_table, 2), - &upb_0test__ModelWithExtensions_msg_init)); - const int decode_options = - upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled. - upb_UnknownToMessage_Status promote_result = - upb_MiniTable_PromoteUnknownToMessageArray( - msg, upb_MiniTable_GetFieldByIndex(mini_table, 2), - &upb_0test__ModelWithExtensions_msg_init, decode_options, arena); - EXPECT_EQ(promote_result, kUpb_UnknownToMessage_Ok); - - upb_Array* array = upb_Message_GetMutableArray( - msg, upb_MiniTable_GetFieldByIndex(mini_table, 2)); - const upb_Message* promoted_message = upb_Array_Get(array, 0).msg_val; - EXPECT_EQ(upb_test_ModelWithExtensions_random_int32( - (upb_test_ModelWithExtensions*)promoted_message), - 5); - promoted_message = upb_Array_Get(array, 1).msg_val; - EXPECT_EQ(upb_test_ModelWithExtensions_random_int32( - (upb_test_ModelWithExtensions*)promoted_message), - 6); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, PromoteUnknownToMapOld) { - upb_Arena* arena = upb_Arena_New(); - upb_test_ModelWithMaps* input_msg = upb_test_ModelWithMaps_new(arena); - upb_test_ModelWithMaps_set_id(input_msg, 123); - - // Add 2 map entries. - upb_test_ModelWithMaps_map_ss_set(input_msg, - upb_StringView_FromString("key1"), - upb_StringView_FromString("value1"), arena); - upb_test_ModelWithMaps_map_ss_set(input_msg, - upb_StringView_FromString("key2"), - upb_StringView_FromString("value2"), arena); - - size_t serialized_size; - char* serialized = - upb_test_ModelWithMaps_serialize(input_msg, arena, &serialized_size); - - upb_MiniTable* mini_table = - CreateMiniTableWithEmptySubTablesForMapsOld(arena); - upb_MiniTable* map_entry_mini_table = CreateMapEntryMiniTableOld(arena); - upb_Message* msg = _upb_Message_New(mini_table, arena); - const int decode_options = upb_DecodeOptions_MaxDepth(0); - upb_DecodeStatus decode_status = - upb_Decode(serialized, serialized_size, msg, mini_table, nullptr, - decode_options, arena); - EXPECT_EQ(decode_status, kUpb_DecodeStatus_Ok); - int32_t val = upb_Message_GetInt32( - msg, upb_MiniTable_FindFieldByNumber(mini_table, 1), 0); - EXPECT_EQ(val, 123); - - // Check that we have map data in an unknown. - upb_FindUnknownRet unknown = upb_Message_FindUnknown(msg, 3, 0); - EXPECT_EQ(unknown.status, kUpb_FindUnknown_Ok); - - // Update mini table and promote unknown to a message. - EXPECT_TRUE(upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(mini_table, 1), - map_entry_mini_table)); - upb_UnknownToMessage_Status promote_result = - upb_MiniTable_PromoteUnknownToMap( - msg, mini_table, upb_MiniTable_GetFieldByIndex(mini_table, 1), - decode_options, arena); - EXPECT_EQ(promote_result, kUpb_UnknownToMessage_Ok); - - upb_Map* map = upb_Message_GetOrCreateMutableMap( - msg, map_entry_mini_table, upb_MiniTable_GetFieldByIndex(mini_table, 1), - arena); - EXPECT_NE(map, nullptr); - // Lookup in map. - upb_MessageValue key; - key.str_val = upb_StringView_FromString("key2"); - upb_MessageValue value; - EXPECT_TRUE(upb_Map_Get(map, key, &value)); - EXPECT_EQ(0, strncmp(value.str_val.data, "value2", 5)); - upb_Arena_Free(arena); -} - -} // namespace diff --git a/vendor/upb/message/test.cc b/vendor/upb/message/test.cc deleted file mode 100644 index 6a72149..0000000 --- a/vendor/upb/message/test.cc +++ /dev/null @@ -1,989 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "absl/cleanup/cleanup.h" -#include "absl/numeric/bits.h" -#include "absl/strings/escaping.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/test_messages_proto3.upb.h" -#include "upb/base/status.h" -#include "upb/base/status.hpp" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/json/decode.h" -#include "upb/json/encode.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/compare.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/message/test.upb.h" -#include "upb/message/test.upb_minitable.h" -#include "upb/message/test.upbdefs.h" -#include "upb/message/value.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_table/debug_string.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/extension.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def.hpp" -#include "upb/reflection/message.h" -#include "upb/test/fuzz_util.h" -#include "upb/text/debug_string.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/types.h" -#include "upb/wire/writer.h" - -// Must be last -#include "upb/port/def.inc" - -void VerifyMessage(const upb_test_TestExtensions* ext_msg) { - EXPECT_TRUE(upb_test_TestExtensions_has_optional_int32_ext(ext_msg)); - // EXPECT_FALSE(upb_test_TestExtensions_Nested_has_optional_int32_ext(ext_msg)); - EXPECT_TRUE(upb_test_has_optional_msg_ext(ext_msg)); - - EXPECT_EQ(123, upb_test_TestExtensions_optional_int32_ext(ext_msg)); - const protobuf_test_messages_proto3_TestAllTypesProto3* ext_submsg = - upb_test_optional_msg_ext(ext_msg); - EXPECT_TRUE(ext_submsg != nullptr); - EXPECT_EQ(456, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_int32( - ext_submsg)); -} - -TEST(MessageTest, Extensions) { - upb::Arena arena; - upb_test_TestExtensions* ext_msg = upb_test_TestExtensions_new(arena.ptr()); - - EXPECT_FALSE(upb_test_TestExtensions_has_optional_int32_ext(ext_msg)); - // EXPECT_FALSE(upb_test_TestExtensions_Nested_has_optional_int32_ext(ext_msg)); - EXPECT_FALSE(upb_test_has_optional_msg_ext(ext_msg)); - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_TestExtensions_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - std::string json = R"json( - { - "[upb_test.TestExtensions.optional_int32_ext]": 123, - "[upb_test.TestExtensions.Nested.repeated_int32_ext]": [2, 4, 6], - "[upb_test.optional_msg_ext]": {"optional_int32": 456} - } - )json"; - upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg), - m.ptr(), defpool.ptr(), 0, arena.ptr(), - status.ptr())) - << status.error_message(); - - VerifyMessage(ext_msg); - - // Test round-trip through binary format. - size_t size; - char* serialized = - upb_test_TestExtensions_serialize(ext_msg, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - ASSERT_GE(size, 0); - - upb_test_TestExtensions* ext_msg2 = upb_test_TestExtensions_parse_ex( - serialized, size, upb_DefPool_ExtensionRegistry(defpool.ptr()), 0, - arena.ptr()); - VerifyMessage(ext_msg2); - - // Test round-trip through JSON format. - size_t json_size = upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), - 0, nullptr, 0, status.ptr()); - char* json_buf = - static_cast(upb_Arena_Malloc(arena.ptr(), json_size + 1)); - upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), 0, json_buf, - json_size + 1, status.ptr()); - upb_test_TestExtensions* ext_msg3 = upb_test_TestExtensions_new(arena.ptr()); - EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, UPB_UPCAST(ext_msg3), m.ptr(), - defpool.ptr(), 0, arena.ptr(), status.ptr())) - << status.error_message(); - VerifyMessage(ext_msg3); - - // Test setters and mutable accessors - upb_test_TestExtensions* ext_msg4 = upb_test_TestExtensions_new(arena.ptr()); - upb_test_TestExtensions_set_optional_int32_ext(ext_msg4, 123, arena.ptr()); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_int32( - upb_test_mutable_optional_msg_ext(ext_msg4, arena.ptr()), 456); - VerifyMessage(ext_msg4); -} - -TEST(MessageTest, ExtensionsDeterministic) { - upb::Arena arena; - upb_test_TestExtensions* ext_msg = upb_test_TestExtensions_new(arena.ptr()); - - EXPECT_FALSE(upb_test_TestExtensions_has_optional_int32_ext(ext_msg)); - // EXPECT_FALSE(upb_test_TestExtensions_Nested_has_optional_int32_ext(ext_msg)); - EXPECT_FALSE(upb_test_has_optional_msg_ext(ext_msg)); - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_TestExtensions_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - std::string json = R"json( - { - "[upb_test.TestExtensions.optional_int32_ext]": 123, - "[upb_test.TestExtensions.Nested.repeated_int32_ext]": [], - "[upb_test.optional_msg_ext]": {"optional_int32": 456} - } - )json"; - upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg), - m.ptr(), defpool.ptr(), 0, arena.ptr(), - status.ptr())) - << status.error_message(); - - VerifyMessage(ext_msg); - - size_t size; - char* serialized = - upb_test_TestExtensions_serialize(ext_msg, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - ASSERT_GE(size, 0); - - size_t deterministic_size; - char* deterministic_serialized = upb_test_TestExtensions_serialize_ex( - ext_msg, kUpb_EncodeOption_Deterministic, arena.ptr(), - &deterministic_size); - ASSERT_TRUE(deterministic_serialized != nullptr); - ASSERT_EQ(deterministic_size, size); -} - -TEST(MessageTest, ExtensionsEmpty) { - upb::Arena arena; - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_TestExtensions_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - for (int options : {0, int{kUpb_EncodeOption_Deterministic}}) { - std::string json_with_empty = R"json( - { - "[upb_test.TestExtensions.optional_int32_ext]": 123, - "[upb_test.TestExtensions.Nested.repeated_int32_ext]": [] - } - )json"; - upb::Status status_empty; - upb_test_TestExtensions* ext_msg_with_empty = - upb_test_TestExtensions_new(arena.ptr()); - EXPECT_TRUE(upb_JsonDecode(json_with_empty.data(), json_with_empty.size(), - UPB_UPCAST(ext_msg_with_empty), m.ptr(), - defpool.ptr(), 0, arena.ptr(), - status_empty.ptr())) - << status_empty.error_message(); - - std::string json = R"json( - { - "[upb_test.TestExtensions.optional_int32_ext]": 123 - } - )json"; - upb::Status status; - upb_test_TestExtensions* ext_msg = upb_test_TestExtensions_new(arena.ptr()); - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg), - m.ptr(), defpool.ptr(), 0, arena.ptr(), - status.ptr())) - << status.error_message(); - - size_t size_with_empty; - char* serialized = upb_test_TestExtensions_serialize_ex( - ext_msg_with_empty, options, arena.ptr(), &size_with_empty); - ASSERT_TRUE(serialized != nullptr); - ASSERT_GE(size_with_empty, 0); - - size_t size; - serialized = upb_test_TestExtensions_serialize_ex(ext_msg, options, - arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - // Presence or absence of an empty extension should not affect the - // serialized output. - ASSERT_EQ(size_with_empty, size); - } -} - -void VerifyMessageSet(const upb_test_TestMessageSet* mset_msg) { - ASSERT_TRUE(mset_msg != nullptr); - bool has = upb_test_MessageSetMember_has_message_set_extension(mset_msg); - EXPECT_TRUE(has); - if (!has) return; - const upb_test_MessageSetMember* member = - upb_test_MessageSetMember_message_set_extension(mset_msg); - EXPECT_TRUE(member != nullptr); - EXPECT_TRUE(upb_test_MessageSetMember_has_optional_int32(member)); - EXPECT_EQ(234, upb_test_MessageSetMember_optional_int32(member)); -} - -TEST(MessageTest, LargeMessageSetExtension) { - upb::Arena arena; - upb_ExtensionRegistry* reg = upb_ExtensionRegistry_New(arena.ptr()); - ASSERT_TRUE(reg != nullptr); - - upb_MiniTableExtension ext; - memset(&ext, 0, sizeof(ext)); - ext.UPB_PRIVATE(field).UPB_ONLYBITS(number) = (1 << 29) + 5; - ext.UPB_PRIVATE(extendee) = &upb_0test__TestMessageSet_msg_init; - - EXPECT_EQ(upb_ExtensionRegistry_Add(reg, &ext), - kUpb_ExtensionRegistryStatus_Ok); -} - -TEST(MessageTest, MessageSet) { - upb::Arena arena; - upb_test_TestMessageSet* ext_msg = upb_test_TestMessageSet_new(arena.ptr()); - - EXPECT_FALSE(upb_test_MessageSetMember_has_message_set_extension(ext_msg)); - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - std::string json = R"json( - { - "[upb_test.MessageSetMember]": {"optional_int32": 234} - } - )json"; - upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg), - m.ptr(), defpool.ptr(), 0, arena.ptr(), - status.ptr())) - << status.error_message(); - - VerifyMessageSet(ext_msg); - - // Test round-trip through binary format. - size_t size; - char* serialized = - upb_test_TestMessageSet_serialize(ext_msg, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - ASSERT_GE(size, 0); - - upb_test_TestMessageSet* ext_msg2 = upb_test_TestMessageSet_parse_ex( - serialized, size, upb_DefPool_ExtensionRegistry(defpool.ptr()), 0, - arena.ptr()); - VerifyMessageSet(ext_msg2); - - // Test round-trip through JSON format. - size_t json_size = upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), - 0, nullptr, 0, status.ptr()); - char* json_buf = - static_cast(upb_Arena_Malloc(arena.ptr(), json_size + 1)); - upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), 0, json_buf, - json_size + 1, status.ptr()); - upb_test_TestMessageSet* ext_msg3 = upb_test_TestMessageSet_new(arena.ptr()); - EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, UPB_UPCAST(ext_msg3), m.ptr(), - defpool.ptr(), 0, arena.ptr(), status.ptr())) - << status.error_message(); - VerifyMessageSet(ext_msg3); -} - -TEST(MessageTest, UnknownMessageSet) { - static const char data[] = "ABCDE"; - upb_StringView data_view = upb_StringView_FromString(data); - upb::Arena arena; - upb_test_FakeMessageSet* fake = upb_test_FakeMessageSet_new(arena.ptr()); - - // Add a MessageSet item that is unknown (there is no matching extension in - // the .proto file) - upb_test_FakeMessageSet_Item* item = - upb_test_FakeMessageSet_add_item(fake, arena.ptr()); - upb_test_FakeMessageSet_Item_set_type_id(item, 12345); - upb_test_FakeMessageSet_Item_set_message(item, data_view); - - // Set unknown fields inside the message set to test that we can skip them. - upb_test_FakeMessageSet_Item_set_unknown_varint(item, 12345678); - upb_test_FakeMessageSet_Item_set_unknown_fixed32(item, 12345678); - upb_test_FakeMessageSet_Item_set_unknown_fixed64(item, 12345678); - upb_test_FakeMessageSet_Item_set_unknown_bytes(item, data_view); - upb_test_FakeMessageSet_Item_mutable_unknowngroup(item, arena.ptr()); - - // Round trip through a true MessageSet where this item_id is unknown. - size_t size; - char* serialized = - upb_test_FakeMessageSet_serialize(fake, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - ASSERT_GE(size, 0); - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - upb_test_TestMessageSet* message_set = upb_test_TestMessageSet_parse_ex( - serialized, size, upb_DefPool_ExtensionRegistry(defpool.ptr()), 0, - arena.ptr()); - ASSERT_TRUE(message_set != nullptr); - - char* serialized2 = - upb_test_TestMessageSet_serialize(message_set, arena.ptr(), &size); - ASSERT_TRUE(serialized2 != nullptr); - ASSERT_GE(size, 0); - - // Parse back into a fake MessageSet and verify that the unknown MessageSet - // item was preserved in full (both type_id and message). - upb_test_FakeMessageSet* fake2 = - upb_test_FakeMessageSet_parse(serialized2, size, arena.ptr()); - ASSERT_TRUE(fake2 != nullptr); - - const upb_test_FakeMessageSet_Item* const* items = - upb_test_FakeMessageSet_item(fake2, &size); - ASSERT_EQ(1, size); - EXPECT_EQ(12345, upb_test_FakeMessageSet_Item_type_id(items[0])); - EXPECT_TRUE(upb_StringView_IsEqual( - data_view, upb_test_FakeMessageSet_Item_message(items[0]))); - - // The non-MessageSet unknown fields should have been discarded. - EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_varint(items[0])); - EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_fixed32(items[0])); - EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_fixed64(items[0])); - EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_bytes(items[0])); - EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknowngroup(items[0])); -} - -TEST(MessageTest, MessageSetSubmessageEncoding) { - upb::Arena arena; - - // Create a normal extension message and use the set the doppelgänger message - // set member extension on it. This will allow us to serialize as a normal - // extension and then attempt to parse it as a message set. - // This mimics the behavior of an encoder that is message set unaware. - upb_test_TestExtensions* ext_msg = upb_test_TestExtensions_new(arena.ptr()); - upb_test_MessageSetMember* ext_member = - upb_test_MessageSetMember_new(arena.ptr()); - upb_test_MessageSetMember_set_optional_int32(ext_member, 234); - upb_test_MessageSetMember_set_doppelganger_message_set_extension( - ext_msg, ext_member, arena.ptr()); - - size_t size; - char* serialized = - upb_test_TestExtensions_serialize(ext_msg, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - ASSERT_GE(size, 0); - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(defpool.ptr())); - EXPECT_TRUE(m.ptr() != nullptr); - - upb_test_TestMessageSet* message_set = upb_test_TestMessageSet_parse_ex( - serialized, size, upb_DefPool_ExtensionRegistry(defpool.ptr()), 0, - arena.ptr()); - ASSERT_TRUE(message_set != nullptr); - - VerifyMessageSet(message_set); -} - -TEST(MessageTest, Proto2Enum) { - upb::Arena arena; - upb_test_Proto2FakeEnumMessage* fake_msg = - upb_test_Proto2FakeEnumMessage_new(arena.ptr()); - - upb_test_Proto2FakeEnumMessage_set_optional_enum(fake_msg, 999); - - int32_t* vals = upb_test_Proto2FakeEnumMessage_resize_repeated_enum( - fake_msg, 6, arena.ptr()); - vals[0] = upb_test_Proto2EnumMessage_ZERO; - vals[1] = 7; // Unknown small. - vals[2] = upb_test_Proto2EnumMessage_SMALL; - vals[3] = 888; // Unknown large. - vals[4] = upb_test_Proto2EnumMessage_LARGE; - vals[5] = upb_test_Proto2EnumMessage_NEGATIVE; - - vals = upb_test_Proto2FakeEnumMessage_resize_packed_enum(fake_msg, 6, - arena.ptr()); - vals[0] = upb_test_Proto2EnumMessage_ZERO; - vals[1] = 7; // Unknown small. - vals[2] = upb_test_Proto2EnumMessage_SMALL; - vals[3] = 888; // Unknown large. - vals[4] = upb_test_Proto2EnumMessage_LARGE; - vals[5] = upb_test_Proto2EnumMessage_NEGATIVE; - - size_t size; - char* pb = - upb_test_Proto2FakeEnumMessage_serialize(fake_msg, arena.ptr(), &size); - - // Parsing as enums puts unknown values into unknown fields. - upb_test_Proto2EnumMessage* enum_msg = - upb_test_Proto2EnumMessage_parse(pb, size, arena.ptr()); - ASSERT_TRUE(enum_msg != nullptr); - - EXPECT_EQ(false, upb_test_Proto2EnumMessage_has_optional_enum(enum_msg)); - const int32_t* vals_const = - upb_test_Proto2EnumMessage_repeated_enum(enum_msg, &size); - EXPECT_EQ(4, size); // Two unknown values moved to the unknown field set. - - // Parsing back into the fake message shows the original data, except the - // repeated enum is rearranged. - pb = upb_test_Proto2EnumMessage_serialize(enum_msg, arena.ptr(), &size); - upb_test_Proto2FakeEnumMessage* fake_msg2 = - upb_test_Proto2FakeEnumMessage_parse(pb, size, arena.ptr()); - ASSERT_TRUE(fake_msg2 != nullptr); - - EXPECT_EQ(true, upb_test_Proto2FakeEnumMessage_has_optional_enum(fake_msg2)); - EXPECT_EQ(999, upb_test_Proto2FakeEnumMessage_optional_enum(fake_msg2)); - - int32_t expected[] = { - upb_test_Proto2EnumMessage_ZERO, - upb_test_Proto2EnumMessage_SMALL, - upb_test_Proto2EnumMessage_LARGE, - upb_test_Proto2EnumMessage_NEGATIVE, - 7, - 888, - }; - - vals_const = upb_test_Proto2FakeEnumMessage_repeated_enum(fake_msg2, &size); - EXPECT_EQ(6, size); - EXPECT_THAT(std::vector(vals_const, vals_const + size), - ::testing::ElementsAreArray(expected)); - - vals_const = upb_test_Proto2FakeEnumMessage_packed_enum(fake_msg2, &size); - EXPECT_EQ(6, size); - EXPECT_THAT(std::vector(vals_const, vals_const + size), - ::testing::ElementsAreArray(expected)); -} - -TEST(MessageTest, TestBadUTF8) { - upb::Arena arena; - std::string serialized("r\x03\xed\xa0\x81"); - EXPECT_EQ(nullptr, protobuf_test_messages_proto3_TestAllTypesProto3_parse( - serialized.data(), serialized.size(), arena.ptr())); -} - -// On a 32 bit platform, upb_StringView has the same size as an int64 field, but -// lower alignment requirements - when selecting the representation for oneof, -// both size and alignment need to be considered. -TEST(MessageTest, OneOf32BitStringViewInt64Alignment) { - upb::Arena arena; - upb_StringView md = {nullptr, 0}; - uint32_t field_tag; - { - upb_DefPool* d = upb_DefPool_New(); - auto free = absl::MakeCleanup([d]() { upb_DefPool_Free(d); }); - const upb_MessageDef* def = upb_test_TestOneOfAlignment_getmsgdef(d); - const upb_FieldDef* field_def = - upb_MessageDef_FindFieldByName(def, "should_be_sixty_four_aligned"); - field_tag = upb_FieldDef_Number(field_def); - EXPECT_TRUE(upb_MessageDef_MiniDescriptorEncode(def, arena.ptr(), &md)); - } - upb_Status status; - upb_Status_Clear(&status); - const upb_MiniTable* table = _upb_MiniTable_Build( - md.data, md.size, kUpb_MiniTablePlatform_32Bit, arena.ptr(), &status); - if (!status.ok) { - FAIL() << "Could not build minitable: " << status.msg; - } - const upb_MiniTableField* mtfield = - upb_MiniTable_FindFieldByNumber(table, field_tag); - uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_Offset)(mtfield); - size_t alignment = 1 << absl::countr_zero(offset); - // Must align to at least 64 bit - EXPECT_GE(alignment, 8); -} - -TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) { - upb::Arena arena; - upb_test_TestRequiredFields* test_msg; - upb_test_EmptyMessage* empty_msg; - - // Succeeds, because we did not request required field checks. - test_msg = upb_test_TestRequiredFields_parse(nullptr, 0, arena.ptr()); - EXPECT_NE(nullptr, test_msg); - - // Fails, because required fields are missing. - EXPECT_EQ(kUpb_DecodeStatus_MissingRequired, - upb_Decode(nullptr, 0, UPB_UPCAST(test_msg), - &upb_0test__TestRequiredFields_msg_init, nullptr, - kUpb_DecodeOption_CheckRequired, arena.ptr())); - - upb_test_TestRequiredFields_set_required_int32(test_msg, 1); - size_t size; - char* serialized = - upb_test_TestRequiredFields_serialize(test_msg, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - EXPECT_NE(0, size); - - // Fails, but the code path is slightly different because the serialized - // payload is not empty. - EXPECT_EQ(kUpb_DecodeStatus_MissingRequired, - upb_Decode(serialized, size, UPB_UPCAST(test_msg), - &upb_0test__TestRequiredFields_msg_init, nullptr, - kUpb_DecodeOption_CheckRequired, arena.ptr())); - - empty_msg = upb_test_EmptyMessage_new(arena.ptr()); - upb_test_TestRequiredFields_set_required_int32(test_msg, 1); - upb_test_TestRequiredFields_set_required_int64(test_msg, 2); - upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg); - - // Succeeds, because required fields are present (though not in the input). - EXPECT_EQ(kUpb_DecodeStatus_Ok, - upb_Decode(nullptr, 0, UPB_UPCAST(test_msg), - &upb_0test__TestRequiredFields_msg_init, nullptr, - kUpb_DecodeOption_CheckRequired, arena.ptr())); - - // Serialize a complete payload. - serialized = - upb_test_TestRequiredFields_serialize(test_msg, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - EXPECT_NE(0, size); - - upb_test_TestRequiredFields* test_msg2 = upb_test_TestRequiredFields_parse_ex( - serialized, size, nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr()); - EXPECT_NE(nullptr, test_msg2); - - // When we add an incomplete sub-message, this is not flagged by the parser. - // This makes parser checking unsuitable for MergeFrom(). - upb_test_TestRequiredFields_set_optional_message( - test_msg2, upb_test_TestRequiredFields_new(arena.ptr())); - EXPECT_EQ(kUpb_DecodeStatus_Ok, - upb_Decode(serialized, size, UPB_UPCAST(test_msg2), - &upb_0test__TestRequiredFields_msg_init, nullptr, - kUpb_DecodeOption_CheckRequired, arena.ptr())); -} - -TEST(MessageTest, DecodeRequiredFieldsSubMessage) { - upb::Arena arena; - upb_test_TestRequiredFields* test_msg = - upb_test_TestRequiredFields_new(arena.ptr()); - upb_test_SubMessageHasRequired* sub_msg = - upb_test_SubMessageHasRequired_new(arena.ptr()); - upb_test_EmptyMessage* empty_msg = upb_test_EmptyMessage_new(arena.ptr()); - - upb_test_SubMessageHasRequired_set_optional_message(sub_msg, test_msg); - size_t size; - char* serialized = - upb_test_SubMessageHasRequired_serialize(sub_msg, arena.ptr(), &size); - EXPECT_NE(0, size); - - // No parse error when parsing normally. - EXPECT_NE(nullptr, upb_test_SubMessageHasRequired_parse(serialized, size, - arena.ptr())); - - // Parse error when verifying required fields, due to incomplete sub-message. - EXPECT_EQ(nullptr, upb_test_SubMessageHasRequired_parse_ex( - serialized, size, nullptr, - kUpb_DecodeOption_CheckRequired, arena.ptr())); - - upb_test_TestRequiredFields_set_required_int32(test_msg, 1); - upb_test_TestRequiredFields_set_required_int64(test_msg, 2); - upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg); - - serialized = - upb_test_SubMessageHasRequired_serialize(sub_msg, arena.ptr(), &size); - EXPECT_NE(0, size); - - // No parse error; sub-message now is complete. - EXPECT_NE(nullptr, upb_test_SubMessageHasRequired_parse_ex( - serialized, size, nullptr, - kUpb_DecodeOption_CheckRequired, arena.ptr())); -} - -TEST(MessageTest, EncodeRequiredFields) { - upb::Arena arena; - upb_test_TestRequiredFields* test_msg = - upb_test_TestRequiredFields_new(arena.ptr()); - - // Succeeds, we didn't ask for required field checking. - size_t size; - char* serialized = - upb_test_TestRequiredFields_serialize_ex(test_msg, 0, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); - EXPECT_EQ(size, 0); - - // Fails, we asked for required field checking but the required field is - // missing. - serialized = upb_test_TestRequiredFields_serialize_ex( - test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); - ASSERT_TRUE(serialized == nullptr); - - // Fails, some required fields are present but not others. - upb_test_TestRequiredFields_set_required_int32(test_msg, 1); - serialized = upb_test_TestRequiredFields_serialize_ex( - test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); - ASSERT_TRUE(serialized == nullptr); - - // Succeeds, all required fields are set. - upb_test_EmptyMessage* empty_msg = upb_test_EmptyMessage_new(arena.ptr()); - upb_test_TestRequiredFields_set_required_int64(test_msg, 2); - upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg); - serialized = upb_test_TestRequiredFields_serialize_ex( - test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); -} - -TEST(MessageTest, MaxRequiredFields) { - upb::Arena arena; - upb_test_TestMaxRequiredFields* test_msg = - upb_test_TestMaxRequiredFields_new(arena.ptr()); - - // Fails, we asked for required field checking but the required field is - // missing. - size_t size; - char* serialized = upb_test_TestMaxRequiredFields_serialize_ex( - test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); - ASSERT_TRUE(serialized == nullptr); - - upb::DefPool defpool; - upb::MessageDefPtr m(upb_test_TestMaxRequiredFields_getmsgdef(defpool.ptr())); - upb_MessageValue val; - val.int32_val = 1; - for (int i = 1; i <= 61; i++) { - upb::FieldDefPtr f = m.FindFieldByNumber(i); - ASSERT_TRUE(f); - upb_Message_SetFieldByDef(UPB_UPCAST(test_msg), f.ptr(), val, arena.ptr()); - } - - // Fails, field 63 still isn't set. - serialized = upb_test_TestMaxRequiredFields_serialize_ex( - test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); - ASSERT_TRUE(serialized == nullptr); - - // Succeeds, all required fields are set. - upb::FieldDefPtr f = m.FindFieldByNumber(62); - ASSERT_TRUE(f); - upb_Message_SetFieldByDef(UPB_UPCAST(test_msg), f.ptr(), val, arena.ptr()); - serialized = upb_test_TestMaxRequiredFields_serialize_ex( - test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); - ASSERT_TRUE(serialized != nullptr); -} - -TEST(MessageTest, MapField) { - upb::Arena arena; - upb_test_TestMapFieldExtra* test_msg_extra = - upb_test_TestMapFieldExtra_new(arena.ptr()); - - ASSERT_TRUE(upb_test_TestMapFieldExtra_map_field_set( - test_msg_extra, 0, upb_test_TestMapFieldExtra_THREE, arena.ptr())); - - size_t size; - char* serialized = upb_test_TestMapFieldExtra_serialize_ex( - test_msg_extra, 0, arena.ptr(), &size); - ASSERT_NE(nullptr, serialized); - ASSERT_NE(0, size); - - upb_test_TestMapField* test_msg = - upb_test_TestMapField_parse(serialized, size, arena.ptr()); - ASSERT_NE(nullptr, test_msg); - - ASSERT_FALSE(upb_test_TestMapField_map_field_get(test_msg, 0, nullptr)); - serialized = - upb_test_TestMapField_serialize_ex(test_msg, 0, arena.ptr(), &size); - ASSERT_NE(0, size); - // parse into second instance - upb_test_TestMapFieldExtra* test_msg_extra2 = - upb_test_TestMapFieldExtra_parse(serialized, size, arena.ptr()); - ASSERT_NE(nullptr, test_msg_extra2); - ASSERT_TRUE( - upb_test_TestMapFieldExtra_map_field_get(test_msg_extra2, 0, nullptr)); -} - -TEST(MessageTest, MapFieldDeterministicEncoding) { - upb::Arena arena1; - upb_test_TestMapField* test_msg1 = upb_test_TestMapField_new(arena1.ptr()); - for (int i = 0; i <= 1000; i++) { - ASSERT_TRUE(upb_test_TestMapField_map_field_set( - test_msg1, i, upb_test_TestMapField_ZERO, arena1.ptr())); - } - for (int i = 1001; i <= 2000; i++) { - ASSERT_TRUE(upb_test_TestMapField_map_field_set( - test_msg1, i, upb_test_TestMapField_ONE, arena1.ptr())); - } - for (int i = 2001; i <= 3000; i++) { - ASSERT_TRUE(upb_test_TestMapField_map_field_set( - test_msg1, i, upb_test_TestMapField_TWO, arena1.ptr())); - } - size_t size1; - char* serialized1; - upb_EncodeStatus status1 = upb_Encode( - UPB_UPCAST(test_msg1), &upb_0test__TestMapField_msg_init, - kUpb_EncodeOption_Deterministic, arena1.ptr(), &serialized1, &size1); - ASSERT_EQ(status1, kUpb_EncodeStatus_Ok); - ASSERT_NE(nullptr, serialized1); - - upb::Arena arena2; - upb_test_TestMapField* test_msg2 = upb_test_TestMapField_new(arena2.ptr()); - // Add the same values in reverse order. - for (int i = 3000; i >= 2001; i--) { - ASSERT_TRUE(upb_test_TestMapField_map_field_set( - test_msg2, i, upb_test_TestMapField_TWO, arena2.ptr())); - } - for (int i = 2000; i >= 1001; i--) { - ASSERT_TRUE(upb_test_TestMapField_map_field_set( - test_msg2, i, upb_test_TestMapField_ONE, arena2.ptr())); - } - for (int i = 1000; i >= 0; i--) { - ASSERT_TRUE(upb_test_TestMapField_map_field_set( - test_msg2, i, upb_test_TestMapField_ZERO, arena2.ptr())); - } - size_t size2; - char* serialized2; - upb_EncodeStatus status2 = upb_Encode( - UPB_UPCAST(test_msg2), &upb_0test__TestMapField_msg_init, - kUpb_EncodeOption_Deterministic, arena2.ptr(), &serialized2, &size2); - ASSERT_EQ(status2, kUpb_EncodeStatus_Ok); - ASSERT_NE(nullptr, serialized2); - - EXPECT_EQ(size1, size2); - EXPECT_EQ(0, memcmp(serialized1, serialized2, size1)); -} - -TEST(MessageTest, AdjacentAliasedUnknown) { - const upb_MiniTable* table = &upb_0test__EmptyMessage_msg_init; - upb::Arena arena; - upb_Message* msg = upb_Message_New(table, arena.ptr()); - char region[900]; - memset(region, 0, sizeof(region)); - region[0] = 0x0A; // Tag number 1 - region[1] = 0xA9; - region[2] = 0x02; - region[300] = 0x12; // Tag number 2 - region[301] = 0xA9; - region[302] = 0x02; - region[600] = 0x1A; // Tag number 3 - region[601] = 0xA9; - region[602] = 0x02; - // All adjacent fields should be part of a single unknown field entry - { - upb_DecodeStatus status = - upb_Decode(region, sizeof(region), msg, table, nullptr, - kUpb_DecodeOption_AliasString, arena.ptr()); - ASSERT_EQ(status, kUpb_DecodeStatus_Ok); - uintptr_t iter = kUpb_Message_UnknownBegin; - upb_StringView data; - ASSERT_TRUE(upb_Message_NextUnknown(msg, &data, &iter)); - EXPECT_EQ(region, data.data); - EXPECT_EQ(sizeof(region), data.size); - EXPECT_FALSE(upb_Message_NextUnknown(msg, &data, &iter)); - } - - upb_Message_Clear(msg, table); - - // Separate decodes should not produce merged aliases, even with adjacent - // entries as we don't know that they're part of the same object - { - upb_Decode(region, 300, msg, table, nullptr, kUpb_DecodeOption_AliasString, - arena.ptr()); - upb_Decode(region + 300, 300, msg, table, nullptr, - kUpb_DecodeOption_AliasString, arena.ptr()); - upb_Decode(region + 600, 300, msg, table, nullptr, - kUpb_DecodeOption_AliasString, arena.ptr()); - upb_StringView data; - uintptr_t iter = kUpb_Message_UnknownBegin; - ASSERT_TRUE(upb_Message_NextUnknown(msg, &data, &iter)); - EXPECT_EQ(region, data.data); - EXPECT_EQ(300, data.size); - ASSERT_TRUE(upb_Message_NextUnknown(msg, &data, &iter)); - EXPECT_EQ(region + 300, data.data); - EXPECT_EQ(300, data.size); - ASSERT_TRUE(upb_Message_NextUnknown(msg, &data, &iter)); - EXPECT_EQ(region + 600, data.data); - EXPECT_EQ(300, data.size); - ASSERT_FALSE(upb_Message_NextUnknown(msg, &data, &iter)); - } -} - -TEST(MessageTest, Freeze) { - const upb_MiniTable* m = &upb_0test__TestFreeze_msg_init; - upb::Arena arena; - - { - upb_test_TestFreeze* raw = upb_test_TestFreeze_new(arena.ptr()); - upb_Message* msg = UPB_UPCAST(raw); - ASSERT_FALSE(upb_Message_IsFrozen(msg)); - upb_Message_Freeze(msg, m); - ASSERT_TRUE(upb_Message_IsFrozen(msg)); - } - { - upb_test_TestFreeze* raw = upb_test_TestFreeze_new(arena.ptr()); - upb_Message* msg = UPB_UPCAST(raw); - size_t size; - upb_Array* arr = _upb_test_TestFreeze_array_int_mutable_upb_array( - raw, &size, arena.ptr()); - ASSERT_NE(arr, nullptr); - ASSERT_EQ(size, 0); - ASSERT_FALSE(upb_Array_IsFrozen(arr)); - upb_Map* map = - _upb_test_TestFreeze_map_int_mutable_upb_map(raw, arena.ptr()); - ASSERT_NE(map, nullptr); - ASSERT_FALSE(upb_Map_IsFrozen(map)); - upb_test_TestFreeze* nest = upb_test_TestFreeze_new(arena.ptr()); - upb_test_set_nest(raw, nest, arena.ptr()); - ASSERT_FALSE(upb_Message_IsFrozen(UPB_UPCAST(nest))); - - upb_Message_Freeze(msg, m); - ASSERT_TRUE(upb_Message_IsFrozen(msg)); - ASSERT_TRUE(upb_Array_IsFrozen(arr)); - ASSERT_TRUE(upb_Map_IsFrozen(map)); - ASSERT_TRUE(upb_Message_IsFrozen(UPB_UPCAST(nest))); - } - { - upb_test_TestFreeze* raw = upb_test_TestFreeze_new(arena.ptr()); - upb_Message* msg = UPB_UPCAST(raw); - size_t size; - upb_Array* arr = _upb_test_TestFreeze_array_int_mutable_upb_array( - raw, &size, arena.ptr()); - ASSERT_NE(arr, nullptr); - ASSERT_EQ(size, 0); - ASSERT_FALSE(upb_Array_IsFrozen(arr)); - upb_Map* map = - _upb_test_TestFreeze_map_int_mutable_upb_map(raw, arena.ptr()); - ASSERT_NE(map, nullptr); - ASSERT_FALSE(upb_Map_IsFrozen(map)); - upb_test_TestFreeze* nest = upb_test_TestFreeze_new(arena.ptr()); - upb_test_set_nest(raw, nest, arena.ptr()); - ASSERT_FALSE(upb_Message_IsFrozen(UPB_UPCAST(nest))); - - upb_Message_Freeze(UPB_UPCAST(nest), m); - ASSERT_FALSE(upb_Message_IsFrozen(msg)); - ASSERT_FALSE(upb_Array_IsFrozen(arr)); - ASSERT_FALSE(upb_Map_IsFrozen(map)); - ASSERT_TRUE(upb_Message_IsFrozen(UPB_UPCAST(nest))); - - const upb_MiniTableField* fa = upb_MiniTable_FindFieldByNumber(m, 20); - const upb_MiniTable* ma = upb_MiniTable_SubMessage(fa); - upb_Array_Freeze(arr, ma); - ASSERT_FALSE(upb_Message_IsFrozen(msg)); - ASSERT_TRUE(upb_Array_IsFrozen(arr)); - ASSERT_FALSE(upb_Map_IsFrozen(map)); - ASSERT_TRUE(upb_Message_IsFrozen(UPB_UPCAST(nest))); - - const upb_MiniTableField* fm = upb_MiniTable_FindFieldByNumber(m, 10); - const upb_MiniTable* mm = upb_MiniTable_SubMessage(fm); - upb_Map_Freeze(map, mm); - ASSERT_FALSE(upb_Message_IsFrozen(msg)); - ASSERT_TRUE(upb_Array_IsFrozen(arr)); - ASSERT_TRUE(upb_Map_IsFrozen(map)); - ASSERT_TRUE(upb_Message_IsFrozen(UPB_UPCAST(nest))); - } -} - -/* Tests some somewhat tricky math used in size calculations while encoding */ -TEST(MessageTest, SkippedVarintSize) { - for (uint32_t clz = 0; clz <= 64; clz++) { - // Optimized math used in encoding - uint32_t skip = - UPB_PRIVATE(upb_WireWriter_VarintUnusedSizeFromLeadingZeros64)(clz); - // traditional varint size calculation - uint64_t val = clz == 64 ? 0 : (~uint64_t{0} >> clz); - uint32_t count = 0; - do { - count++; - val >>= 7; - } while (val); - EXPECT_EQ(skip, 10 - count); - } -} - -TEST(MessageTest, MessageTooBig) { - if (sizeof(size_t) <= 4) { - GTEST_SKIP() << "Skipping test because size_t is too small"; - } - if (UPB_MSAN || UPB_ASAN) { - GTEST_SKIP() << "Skipping test because sanitizers that track shadow memory " - "increase overhead and lead to OOMs"; - } - upb::Arena arena; - size_t buf_size = 2 * 1024; - void* bytes = upb_Arena_Malloc(arena.ptr(), buf_size); - memset(bytes, 0, buf_size); - upb_StringView bytes_view; - bytes_view.data = (const char*)bytes; - bytes_view.size = buf_size; - upb_test_TestRepeatedMessageBig* msg = - upb_test_TestRepeatedMessageBig_new(arena.ptr()); - - { - size_t size; - upb_test_TestRepeatedMessageBig_resize_repeated_bytes(msg, 1024, - arena.ptr()); - upb_StringView* arr = - upb_test_TestRepeatedMessageBig_mutable_repeated_bytes(msg, &size); - - for (size_t i = 0; i < size; i++) { - arr[i] = bytes_view; - } - // Message is slightly more than 2mb to serialize - } - { - upb_test_TestRepeatedMessageBig* parent = - upb_test_TestRepeatedMessageBig_new(arena.ptr()); - upb_test_TestRepeatedMessageBig_resize_repeated_message(parent, 1024, - arena.ptr()); - size_t size; - upb_test_TestRepeatedMessageBig** arr = - upb_test_TestRepeatedMessageBig_mutable_repeated_message(parent, &size); - - for (size_t i = 0; i < size; i++) { - arr[i] = msg; - } - // Message is slightly more than 2gb to serialize, but no individual length - // delimited message is larger - msg = parent; - } - char* ptr; - size_t size; - upb_EncodeStatus status; - { - upb::Arena out_arena; - status = - upb_Encode(UPB_UPCAST(msg), &upb_0test__TestRepeatedMessageBig_msg_init, - 0, out_arena.ptr(), &ptr, &size); - // If the top level message exceeds the limit, that's OK - } - if (status == kUpb_EncodeStatus_OutOfMemory) { - GTEST_SKIP() - << "Skipping test because we could not allocate a few gigabytes"; - } - EXPECT_EQ(status, kUpb_EncodeStatus_Ok); - { - upb::Arena out_arena; - status = upb_EncodeLengthPrefixed( - UPB_UPCAST(msg), &upb_0test__TestRepeatedMessageBig_msg_init, 0, - out_arena.ptr(), &ptr, &size); - } - if (status != kUpb_EncodeStatus_OutOfMemory && - status != kUpb_EncodeStatus_MaxSizeExceeded) { - // If we ever try to length-delimit something larger than fits in 32 bits, - // it's an error - FAIL() << "Expected OutOfMemory or MaxSizeExceeded, got " << status; - } -} - -TEST(MessageTest, ArenaSpaceAllocatedAfterDecode) { - upb::Arena arena; - uintptr_t space_allocated_before = - upb_Arena_SpaceAllocated(arena.ptr(), nullptr); - char region[300]; - memset(region, 0, sizeof(region)); - region[0] = 0x0A; // Tag number 1 - region[1] = 0xA9; - region[2] = 0x02; - upb_test_EmptyMessage* msg = - upb_test_EmptyMessage_parse(region, sizeof(region), arena.ptr()); - EXPECT_NE(msg, nullptr); - uintptr_t space_allocated_after = - upb_Arena_SpaceAllocated(arena.ptr(), nullptr); - EXPECT_GT(space_allocated_after, space_allocated_before + 297); -} diff --git a/vendor/upb/message/test.proto b/vendor/upb/message/test.proto deleted file mode 100644 index d30393f..0000000 --- a/vendor/upb/message/test.proto +++ /dev/null @@ -1,229 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// LINT: ALLOW_GROUPS - -syntax = "proto2"; - -package upb_test; - -import "google/protobuf/test_messages_proto3.proto"; - -message TestExtensions { - extensions 1000 to max - [verification = UNVERIFIED]; - extend TestExtensions { - optional int32 optional_int32_ext = 1000; - } - message Nested { - extend TestExtensions { - repeated int32 repeated_int32_ext = 1001; - } - } -} - -extend TestExtensions { - optional protobuf_test_messages.proto3.TestAllTypesProto3 optional_msg_ext = - 1002; -} - -message TestMessageSet { - option message_set_wire_format = true; - - extensions 4 to max - [verification = UNVERIFIED]; -} - -message MessageSetMember { - optional int32 optional_int32 = 1; - extend TestMessageSet { - optional MessageSetMember message_set_extension = 2000; - } - // Also extend a non-MessageSet with the same field number. This will allow us - // to test parsing a normal extension into a MessageSet. - extend TestExtensions { - optional MessageSetMember doppelganger_message_set_extension = 2000; - } -} - -message FakeMessageSet { - repeated group Item = 1 { - optional int32 type_id = 2; - optional bytes message = 3; - optional int32 unknown_varint = 4; - optional fixed32 unknown_fixed32 = 5; - optional fixed64 unknown_fixed64 = 6; - optional bytes unknown_bytes = 7; - optional group UnknownGroup = 8 {} - } -} - -message Proto2EnumMessage { - enum Proto2TestEnum { - ZERO = 0; - NEGATIVE = -1; - SMALL = 15; - LARGE = 12345; - } - - optional Proto2TestEnum optional_enum = 1; - repeated Proto2TestEnum repeated_enum = 2; - repeated Proto2TestEnum packed_enum = 3 [packed = true]; -} - -// The same fields as Proto2EnumMessage, but with int32 fields so we can fake -// wire format. -message Proto2FakeEnumMessage { - optional int32 optional_enum = 1; - repeated int32 repeated_enum = 2; - repeated int32 packed_enum = 3 [packed = true]; -} - -message EmptyMessage {} - -message TestRequiredFields { - required int32 required_int32 = 1; - optional int32 optional_int32 = 2; - required int64 required_int64 = 3; - optional TestRequiredFields optional_message = 4; - required EmptyMessage required_message = 5; -} - -message SubMessageHasRequired { - optional TestRequiredFields optional_message = 1; -} - -message TestMaxRequiredFields { - required int32 required_int32_1 = 1; - required int32 required_int32_2 = 2; - required int32 required_int32_3 = 3; - required int32 required_int32_4 = 4; - required int32 required_int32_5 = 5; - required int32 required_int32_6 = 6; - required int32 required_int32_7 = 7; - required int32 required_int32_8 = 8; - required int32 required_int32_9 = 9; - required int32 required_int32_10 = 10; - required int32 required_int32_11 = 11; - required int32 required_int32_12 = 12; - required int32 required_int32_13 = 13; - required int32 required_int32_14 = 14; - required int32 required_int32_15 = 15; - required int32 required_int32_16 = 16; - required int32 required_int32_17 = 17; - required int32 required_int32_18 = 18; - required int32 required_int32_19 = 19; - required int32 required_int32_20 = 20; - required int32 required_int32_21 = 21; - required int32 required_int32_22 = 22; - required int32 required_int32_23 = 23; - required int32 required_int32_24 = 24; - required int32 required_int32_25 = 25; - required int32 required_int32_26 = 26; - required int32 required_int32_27 = 27; - required int32 required_int32_28 = 28; - required int32 required_int32_29 = 29; - required int32 required_int32_30 = 30; - required int32 required_int32_31 = 31; - required int32 required_int32_32 = 32; - required int32 required_int32_33 = 33; - required int32 required_int32_34 = 34; - required int32 required_int32_35 = 35; - required int32 required_int32_36 = 36; - required int32 required_int32_37 = 37; - required int32 required_int32_38 = 38; - required int32 required_int32_39 = 39; - required int32 required_int32_40 = 40; - required int32 required_int32_41 = 41; - required int32 required_int32_42 = 42; - required int32 required_int32_43 = 43; - required int32 required_int32_44 = 44; - required int32 required_int32_45 = 45; - required int32 required_int32_46 = 46; - required int32 required_int32_47 = 47; - required int32 required_int32_48 = 48; - required int32 required_int32_49 = 49; - required int32 required_int32_50 = 50; - required int32 required_int32_51 = 51; - required int32 required_int32_52 = 52; - required int32 required_int32_53 = 53; - required int32 required_int32_54 = 54; - required int32 required_int32_55 = 55; - required int32 required_int32_56 = 56; - required int32 required_int32_57 = 57; - required int32 required_int32_58 = 58; - required int32 required_int32_59 = 59; - required int32 required_int32_60 = 60; - required int32 required_int32_61 = 61; - required int32 required_int32_62 = 62; -} - -message TestMapField { - enum EnumMap { - ZERO = 0; - ONE = 1; - TWO = 2; - } - map map_field = 1; -} - -message TestMapFieldExtra { - enum EnumMap { - ZERO = 0; - ONE = 1; - TWO = 2; - THREE = 3; - } - map map_field = 1; -} - -message TestNameConflict { - map map_field = 1; - optional bool clear_map_field = 2; -} - -message TestFreeze { - extensions 99 to max; - - optional string str = 1; - optional TestFreeze msg = 2; - - map map_int = 10; - map map_msg = 11; - - repeated int32 array_int = 20; - repeated TestFreeze array_msg = 21; -} - -extend TestFreeze { - optional TestFreeze nest = 100; -} - -extend TestFreeze { - repeated Proto2EnumMessage rep_msg = 101; -} - -message TestOneOfAlignment { - optional fixed32 pad = 6; - oneof value { - string str = 10; - fixed64 should_be_sixty_four_aligned = 11; - } -} - -message TestRepeatedMessageBig { - repeated TestRepeatedMessageBig repeated_message = 1; - repeated bytes repeated_bytes = 2; -} - -message TestDuplicateFunctionNames { - optional bool random = 6; - oneof value { - bytes body = 1; - bool clear_body = 2; - } -} diff --git a/vendor/upb/message/utf8_test.cc b/vendor/upb/message/utf8_test.cc deleted file mode 100644 index e7bd894..0000000 --- a/vendor/upb/message/utf8_test.cc +++ /dev/null @@ -1,171 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include - -#include -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/message/utf8_test.upb.h" -#include "upb/message/utf8_test.upb_minitable.h" -#include "upb/message/utf8_test_proto2.upb.h" -#include "upb/message/utf8_test_proto2.upb_minitable.h" -#include "upb/wire/decode.h" - -namespace { - -const char bad_utf8[] = "\xff"; - -static char* GetBadUtf8Payload(upb_Arena* arena, size_t* size) { - upb_test_TestUtf8Bytes* msg = upb_test_TestUtf8Bytes_new(arena); - upb_test_TestUtf8Bytes_set_data(msg, upb_StringView_FromString(bad_utf8)); - char* data = upb_test_TestUtf8Bytes_serialize(msg, arena, size); - EXPECT_TRUE(data != nullptr); - return data; -} - -TEST(Utf8Test, BytesFieldDoesntValidate) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - upb_test_TestUtf8Bytes* msg2 = - upb_test_TestUtf8Bytes_parse(data, size, arena.ptr()); - - // Parse succeeds, because the bytes field does not validate UTF-8. - ASSERT_TRUE(msg2 != nullptr); -} - -TEST(Utf8Test, Proto3FieldValidates) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - - upb_test_TestUtf8Proto3String* msg = - upb_test_TestUtf8Proto3String_new(arena.ptr()); - - upb_DecodeStatus status = upb_Decode( - data, size, UPB_UPCAST(msg), &upb_0test__TestUtf8Proto3String_msg_init, - nullptr, 0, arena.ptr()); - - // Parse fails, because proto3 string fields validate UTF-8. - ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); -} - -TEST(Utf8Test, RepeatedProto3FieldValidates) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - - upb_test_TestUtf8RepeatedProto3String* msg = - upb_test_TestUtf8RepeatedProto3String_new(arena.ptr()); - - upb_DecodeStatus status = - upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8RepeatedProto3String_msg_init, nullptr, 0, - arena.ptr()); - - // Parse fails, because proto3 string fields validate UTF-8. - ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); -} - -TEST(Utf8Test, Proto2BytesValidates) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - - upb_test_TestUtf8Proto2Bytes* msg = - upb_test_TestUtf8Proto2Bytes_new(arena.ptr()); - - upb_DecodeStatus status; - status = upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8Proto2Bytes_msg_init, nullptr, 0, - arena.ptr()); - - // Parse succeeds, because proto2 bytes fields don't validate UTF-8. - ASSERT_EQ(kUpb_DecodeStatus_Ok, status); -} - -TEST(Utf8Test, Proto2RepeatedBytesValidates) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - - upb_test_TestUtf8RepeatedProto2Bytes* msg = - upb_test_TestUtf8RepeatedProto2Bytes_new(arena.ptr()); - - upb_DecodeStatus status; - status = upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8RepeatedProto2Bytes_msg_init, nullptr, - 0, arena.ptr()); - - // Parse succeeds, because proto2 bytes fields don't validate UTF-8. - ASSERT_EQ(kUpb_DecodeStatus_Ok, status); -} - -TEST(Utf8Test, Proto2StringValidates) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - - upb_test_TestUtf8Proto2String* msg = - upb_test_TestUtf8Proto2String_new(arena.ptr()); - - upb_DecodeStatus status; - status = upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8Proto2String_msg_init, nullptr, 0, - arena.ptr()); - - // Parse succeeds, because proto2 string fields don't validate UTF-8. - ASSERT_EQ(kUpb_DecodeStatus_Ok, status); -} - -TEST(Utf8Test, Proto2FieldFailsValidation) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - - upb_test_TestUtf8Proto2String* msg = - upb_test_TestUtf8Proto2String_new(arena.ptr()); - - upb_DecodeStatus status; - status = upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8Proto2String_msg_init, nullptr, 0, - arena.ptr()); - - // Parse fails, because we pass in kUpb_DecodeOption_AlwaysValidateUtf8 to - // force validation of proto2 string fields. - status = upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8Proto2String_msg_init, nullptr, - kUpb_DecodeOption_AlwaysValidateUtf8, arena.ptr()); - ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); -} - -TEST(Utf8Test, Proto2RepeatedFieldFailsValidation) { - upb::Arena arena; - size_t size; - char* data = GetBadUtf8Payload(arena.ptr(), &size); - - upb_test_TestUtf8RepeatedProto2String* msg = - upb_test_TestUtf8RepeatedProto2String_new(arena.ptr()); - - upb_DecodeStatus status; - status = upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8RepeatedProto2String_msg_init, - nullptr, 0, arena.ptr()); - - // Parse fails, because we pass in kUpb_DecodeOption_AlwaysValidateUtf8 to - // force validation of proto2 string fields. - status = - upb_Decode(data, size, UPB_UPCAST(msg), - &upb_0test__TestUtf8RepeatedProto2String_msg_init, nullptr, - kUpb_DecodeOption_AlwaysValidateUtf8, arena.ptr()); - ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); -} - -} // namespace diff --git a/vendor/upb/message/utf8_test.proto b/vendor/upb/message/utf8_test.proto deleted file mode 100644 index 77657b5..0000000 --- a/vendor/upb/message/utf8_test.proto +++ /dev/null @@ -1,22 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto3"; - -package upb_test; - -message TestUtf8Bytes { - optional bytes data = 1; -} - -message TestUtf8Proto3String { - optional string data = 1; -} - -message TestUtf8RepeatedProto3String { - repeated string data = 1; -} diff --git a/vendor/upb/message/utf8_test_proto2.proto b/vendor/upb/message/utf8_test_proto2.proto deleted file mode 100644 index 6adc105..0000000 --- a/vendor/upb/message/utf8_test_proto2.proto +++ /dev/null @@ -1,26 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package upb_test; - -message TestUtf8Proto2Bytes { - optional bytes data = 1; -} - -message TestUtf8RepeatedProto2Bytes { - optional bytes data = 1; -} - -message TestUtf8Proto2String { - optional string data = 1; -} - -message TestUtf8RepeatedProto2String { - repeated string data = 1; -} diff --git a/vendor/upb/message/value.h b/vendor/upb/message/value.h deleted file mode 100644 index 8090f26..0000000 --- a/vendor/upb/message/value.h +++ /dev/null @@ -1,73 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// Users should include array.h or map.h instead. -// IWYU pragma: private, include "upb/message/array.h" - -#ifndef UPB_MESSAGE_VALUE_H_ -#define UPB_MESSAGE_VALUE_H_ - -#include -#include - -#include "upb/base/string_view.h" -#include "upb/message/internal/types.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef union { - bool bool_val; - float float_val; - double double_val; - int32_t int32_val; - int64_t int64_val; - uint32_t uint32_val; - uint64_t uint64_val; - const struct upb_Array* array_val; - const struct upb_Map* map_val; - const struct upb_Message* msg_val; - upb_StringView str_val; - - // For an extension field, we are essentially treating ext->data (a - // upb_MessageValue) as if it were a message with one field that lives at - // offset 0. This works because upb_MessageValue is precisely one value that - // can hold any type of data. Recall that an extension can be of any type - // (scalar, repeated, or message). For a message extension, that will be a - // single upb_Message* at offset 0 of the upb_MessageValue. - struct upb_Message UPB_PRIVATE(ext_msg_val); -} upb_MessageValue; - -UPB_API_INLINE upb_MessageValue upb_MessageValue_Zero(void) { - upb_MessageValue zero; - memset(&zero, 0, sizeof(zero)); - return zero; -} - -typedef union { - struct upb_Array* array; - struct upb_Map* map; - struct upb_Message* msg; -} upb_MutableMessageValue; - -UPB_API_INLINE upb_MutableMessageValue upb_MutableMessageValue_Zero(void) { - upb_MutableMessageValue zero; - memset(&zero, 0, sizeof(zero)); - return zero; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MESSAGE_VALUE_H_ */ diff --git a/vendor/upb/mini_descriptor/BUILD b/vendor/upb/mini_descriptor/BUILD deleted file mode 100644 index 4fe2aef..0000000 --- a/vendor/upb/mini_descriptor/BUILD +++ /dev/null @@ -1,114 +0,0 @@ -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load( - "//upb/bazel:copts.bzl", - "UPB_DEFAULT_COPTS", - "UPB_DEFAULT_CPPOPTS", - "UPB_DEFAULT_FEATURES", -) - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "mini_descriptor", - srcs = [ - "build_enum.c", - "decode.c", - "link.c", - ], - hdrs = [ - "build_enum.h", - "decode.h", - "link.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - "//upb/base", - "//upb/base:internal", - "//upb/mem", - "//upb/message:types", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - ] + select({ - "//upb:fasttable_enabled_setting": [ - "//upb/wire/decode_fast:field_parsers", - "//upb/wire/decode_fast:function_array", - "//upb/wire/decode_fast:select", - ], - "//conditions:default": [], - }), -) - -cc_library( - name = "internal", - srcs = [ - "internal/base92.c", - "internal/encode.c", - ], - hdrs = [ - "internal/base92.h", - "internal/decoder.h", - "internal/encode.h", - "internal/encode.hpp", - "internal/modifiers.h", - "internal/wire_constants.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/base:internal", - "//upb/port", - ], -) - -cc_test( - name = "encode_test", - srcs = ["internal/encode_test.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":internal", - ":mini_descriptor", - "//src/google/protobuf", - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/message:internal", - "//upb/mini_table", - "//upb/port", - "//upb/wire", - "@abseil-cpp//absl/container:flat_hash_set", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/mini_descriptor/build_enum.c b/vendor/upb/mini_descriptor/build_enum.c deleted file mode 100644 index e85c246..0000000 --- a/vendor/upb/mini_descriptor/build_enum.c +++ /dev/null @@ -1,149 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_descriptor/build_enum.h" - -#include -#include - -#include "upb/base/status.h" -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/internal/base92.h" -#include "upb/mini_descriptor/internal/decoder.h" -#include "upb/mini_descriptor/internal/wire_constants.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/internal/enum.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - upb_MdDecoder base; - upb_Arena* arena; - upb_MiniTableEnum* enum_table; - uint32_t enum_value_count; - uint32_t enum_data_count; - uint32_t enum_data_capacity; -} upb_MdEnumDecoder; - -static size_t upb_MiniTableEnum_Size(uint32_t count) { - return UPB_SIZEOF_FLEX(upb_MiniTableEnum, UPB_PRIVATE(data), count); -} - -static upb_MiniTableEnum* _upb_MiniTable_AddEnumDataMember(upb_MdEnumDecoder* d, - uint32_t val) { - if (d->enum_data_count == d->enum_data_capacity) { - size_t old_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); - if (d->enum_data_capacity > UINT32_MAX / 2) { - upb_MdDecoder_ErrorJmp(&d->base, "Out of memory"); - } - uint32_t new_capacity = UPB_MAX(2, d->enum_data_capacity * 2); - if (UPB_SIZEOF_FLEX_WOULD_OVERFLOW(upb_MiniTableEnum, UPB_PRIVATE(data), - new_capacity)) { - upb_MdDecoder_ErrorJmp(&d->base, "Out of memory"); - } - size_t new_sz = upb_MiniTableEnum_Size(new_capacity); - d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); - d->enum_data_capacity = new_capacity; - } - d->enum_table->UPB_PRIVATE(data)[d->enum_data_count++] = val; - return d->enum_table; -} - -static void upb_MiniTableEnum_BuildValue(upb_MdEnumDecoder* d, uint32_t val) { - upb_MiniTableEnum* table = d->enum_table; - d->enum_value_count++; - if (table->UPB_PRIVATE(value_count) || - (val > 512 && d->enum_value_count < val / 32)) { - if (table->UPB_PRIVATE(value_count) == 0) { - UPB_ASSERT(d->enum_data_count == table->UPB_PRIVATE(mask_limit) / 32); - } - table = _upb_MiniTable_AddEnumDataMember(d, val); - table->UPB_PRIVATE(value_count)++; - } else { - uint32_t new_mask_limit = ((val / 32) + 1) * 32; - while (table->UPB_PRIVATE(mask_limit) < new_mask_limit) { - table = _upb_MiniTable_AddEnumDataMember(d, 0); - table->UPB_PRIVATE(mask_limit) += 32; - } - table->UPB_PRIVATE(data)[val / 32] |= 1ULL << (val % 32); - } -} - -static upb_MiniTableEnum* upb_MtDecoder_DoBuildMiniTableEnum( - upb_MdEnumDecoder* d, const char* data, size_t len) { - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_EnumV1) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid enum version: %c", *data); - } - data++; - len--; - } - - upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); - - // Guarantee at least 64 bits of mask without checking mask size. - d->enum_table->UPB_PRIVATE(mask_limit) = 64; - d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); - d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); - - d->enum_table->UPB_PRIVATE(value_count) = 0; - - const char* ptr = data; - uint32_t base = 0; - - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch <= kUpb_EncodedValue_MaxEnumMask) { - uint32_t mask = _upb_FromBase92(ch); - for (int i = 0; i < 5; i++, base++, mask >>= 1) { - if (mask & 1) upb_MiniTableEnum_BuildValue(d, base); - } - } else if (kUpb_EncodedValue_MinSkip <= ch && - ch <= kUpb_EncodedValue_MaxSkip) { - uint32_t skip; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, - kUpb_EncodedValue_MinSkip, - kUpb_EncodedValue_MaxSkip, &skip); - base += skip; - } else { - upb_MdDecoder_ErrorJmp(&d->base, "Unexpected character: %c", ch); - } - } - - return d->enum_table; -} - -static upb_MiniTableEnum* upb_MtDecoder_BuildMiniTableEnum( - upb_MdEnumDecoder* const decoder, const char* const data, - size_t const len) { - if (UPB_SETJMP(decoder->base.err) != 0) return NULL; - return upb_MtDecoder_DoBuildMiniTableEnum(decoder, data, len); -} - -upb_MiniTableEnum* upb_MiniTableEnum_Build(const char* data, size_t len, - upb_Arena* arena, - upb_Status* status) { - uint32_t initial_capacity = 2; - upb_MdEnumDecoder decoder = { - .base = - { - .end = UPB_PTRADD(data, len), - .status = status, - }, - .arena = arena, - .enum_table = - upb_Arena_Malloc(arena, upb_MiniTableEnum_Size(initial_capacity)), - .enum_value_count = 0, - .enum_data_count = 0, - .enum_data_capacity = initial_capacity, - }; - - return upb_MtDecoder_BuildMiniTableEnum(&decoder, data, len); -} diff --git a/vendor/upb/mini_descriptor/build_enum.h b/vendor/upb/mini_descriptor/build_enum.h deleted file mode 100644 index 832cd26..0000000 --- a/vendor/upb/mini_descriptor/build_enum.h +++ /dev/null @@ -1,33 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_DESCRIPTOR_BUILD_ENUM_H_ -#define UPB_MINI_DESCRIPTOR_BUILD_ENUM_H_ - -#include "upb/base/status.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/enum.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Builds a upb_MiniTableEnum from an enum mini descriptor. -// The mini descriptor must be for an enum, not a message. -UPB_NODISCARD UPB_API upb_MiniTableEnum* upb_MiniTableEnum_Build( - const char* data, size_t len, upb_Arena* arena, upb_Status* status); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MINI_DESCRIPTOR_BUILD_ENUM_H_ diff --git a/vendor/upb/mini_descriptor/decode.c b/vendor/upb/mini_descriptor/decode.c deleted file mode 100644 index 8e4cecb..0000000 --- a/vendor/upb/mini_descriptor/decode.c +++ /dev/null @@ -1,963 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_descriptor/decode.h" - -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/mem/alloc.h" -#include "upb/mem/arena.h" -#include "upb/message/internal/map_entry.h" -#include "upb/message/internal/types.h" -#include "upb/mini_descriptor/internal/base92.h" -#include "upb/mini_descriptor/internal/decoder.h" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_descriptor/internal/wire_constants.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" - -// Our awkward dance for including fasttable only when it is enabled. -#include "upb/port/def.inc" -#if UPB_FASTTABLE -#define UPB_INCLUDE_FAST_DECODE -#endif -#include "upb/port/undef.inc" - -#ifdef UPB_INCLUDE_FAST_DECODE -#include "upb/wire/decode_fast/function_array.h" -#include "upb/wire/decode_fast/select.h" -#endif - -#undef UPB_INCLUDE_FAST_DECODE - -// Must be last. -#include "upb/port/def.inc" - -// We reserve unused hasbits to make room for upb_Message fields. -#define kUpb_Reserved_Hasbytes sizeof(struct upb_Message) - -// 64 is the first hasbit that we currently use. -#define kUpb_Reserved_Hasbits (kUpb_Reserved_Hasbytes * 8) - -#define kUpb_OneOfLayoutItem_IndexSentinel ((uint16_t)-1) - -// Stores the field number of the present value of the oneof -#define kUpb_OneOf_CaseFieldRep (kUpb_FieldRep_4Byte) - -// The maximum field number that can be encoded on the wire. -// Note that this limit does not apply to MessageSet, which can have field -// numbers up to INT32_MAX. -#define kUpb_MaxFieldNumber ((1 << 29) - 1) - -typedef struct { - // Index of the corresponding field. The field's offset will be the index of - // the next field in a linked list. - uint16_t field_index; - // This enum is stored in bytes to avoid trailing padding while preserving - // two-byte alignment. - uint8_t /* upb_FieldRep*/ rep; -} upb_OneOfLayoutItem; - -typedef struct { - upb_OneOfLayoutItem* data; - size_t size; - size_t buf_capacity_bytes; -} upb_OneOfLayoutItemVector; - -typedef struct { - upb_MdDecoder base; - upb_MiniTableField* fields; - upb_MiniTablePlatform platform; - upb_OneOfLayoutItemVector oneofs; - upb_Arena* arena; - // Initially tracks the count of each field rep type; then, during assignment, - // tracks the base offset for the next processed field of the given rep. - uint16_t rep_counts_offsets[kUpb_FieldRep_Max + 1]; - uint32_t sub_count; - bool is_extension; - - // When building fasttables, we don't know the total size of the table until - // we're done decoding, so we allocate a temporary table on the stack and - // allocate the real thing from the arena later. - upb_MiniTable table; -} upb_MtDecoder; - -// In each field's offset, we temporarily store a presence classifier: -enum PresenceClass { - kNoPresence = 0, - kHasbitPresence = 1, - kRequiredPresence = 2, - kOneofBase = 3, - // Negative values refer to a specific oneof with that number. Positive - // values >= kOneofBase indicate that this field is in a oneof, and specify - // the next field in this oneof's linked list. -}; - -static bool upb_MtDecoder_FieldIsPackable(upb_MiniTableField* field) { - return (field->UPB_PRIVATE(mode) & kUpb_FieldMode_Array) && - upb_FieldType_IsPackable(field->UPB_PRIVATE(descriptortype)); -} - -typedef struct { - uint16_t submsg_count; - uint16_t subenum_count; -} upb_SubCounts; - -static void upb_MiniTable_SetTypeAndSub(upb_MtDecoder* d, - upb_MiniTableField* field, - upb_FieldType type, - uint64_t msg_modifiers, - bool is_proto3_enum) { - if (is_proto3_enum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - type = kUpb_FieldType_Int32; - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; - } else if (type == kUpb_FieldType_String && - !(msg_modifiers & kUpb_MessageModifier_ValidateUtf8)) { - type = kUpb_FieldType_Bytes; - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; - } - - field->UPB_PRIVATE(descriptortype) = type; - - if (upb_MtDecoder_FieldIsPackable(field) && - (msg_modifiers & kUpb_MessageModifier_DefaultIsPacked)) { - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsPacked; - } - - // We initially set `submsg_ofs` to the index of the sub in the list of subs. - // Later, we'll update it to be a relative byte offset. - if (type == kUpb_FieldType_Message || type == kUpb_FieldType_Group || - type == kUpb_FieldType_Enum) { - field->UPB_PRIVATE(submsg_ofs) = d->sub_count++; - } else { - field->UPB_PRIVATE(submsg_ofs) = kUpb_NoSub; - } -} - -static const char kUpb_EncodedToType[] = { - [kUpb_EncodedType_Double] = kUpb_FieldType_Double, - [kUpb_EncodedType_Float] = kUpb_FieldType_Float, - [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, - [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, - [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, - [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, - [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, - [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, - [kUpb_EncodedType_String] = kUpb_FieldType_String, - [kUpb_EncodedType_Group] = kUpb_FieldType_Group, - [kUpb_EncodedType_Message] = kUpb_FieldType_Message, - [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, - [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, - [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, - [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, - [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, - [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, -}; - -static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, - upb_MiniTableField* field, - uint64_t msg_modifiers) { - static const char kUpb_EncodedToFieldRep[] = { - [kUpb_EncodedType_Double] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Float] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Int64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_UInt64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Int32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Fixed64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Fixed32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Bool] = kUpb_FieldRep_1Byte, - [kUpb_EncodedType_String] = kUpb_FieldRep_StringView, - [kUpb_EncodedType_Bytes] = kUpb_FieldRep_StringView, - [kUpb_EncodedType_UInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SFixed32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SFixed64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_SInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SInt64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, - }; - - char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit - ? kUpb_FieldRep_4Byte - : kUpb_FieldRep_8Byte; - - int8_t type = _upb_FromBase92(ch); - if (ch >= _upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { - type -= kUpb_EncodedType_RepeatedBase; - field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; - field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - field->UPB_PRIVATE(offset) = kNoPresence; - } else { - field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; - field->UPB_PRIVATE(offset) = kHasbitPresence; - if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { - field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); - } else { - field->UPB_PRIVATE(mode) |= kUpb_EncodedToFieldRep[type] - << kUpb_FieldRep_Shift; - } - } - if ((unsigned long)type >= sizeof(kUpb_EncodedToType)) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); - } - upb_MiniTable_SetTypeAndSub(d, field, kUpb_EncodedToType[type], msg_modifiers, - type == kUpb_EncodedType_OpenEnum); -} - -static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, - uint32_t message_modifiers, - uint32_t field_modifiers, - upb_MiniTableField* field) { - if (field_modifiers & kUpb_EncodedFieldModifier_FlipPacked) { - if (!upb_MtDecoder_FieldIsPackable(field)) { - upb_MdDecoder_ErrorJmp(&d->base, - "Cannot flip packed on unpackable field %" PRIu32, - upb_MiniTableField_Number(field)); - } - field->UPB_PRIVATE(mode) ^= kUpb_LabelFlags_IsPacked; - } - - if (field_modifiers & kUpb_EncodedFieldModifier_FlipValidateUtf8) { - if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Bytes || - !(field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate)) { - upb_MdDecoder_ErrorJmp(&d->base, - "Cannot flip ValidateUtf8 on field %" PRIu32 - ", type=%d, mode=%d", - upb_MiniTableField_Number(field), - (int)field->UPB_PRIVATE(descriptortype), - (int)field->UPB_PRIVATE(mode)); - } - field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_String; - field->UPB_PRIVATE(mode) &= ~kUpb_LabelFlags_IsAlternate; - } - - bool singular = field_modifiers & kUpb_EncodedFieldModifier_IsProto3Singular; - bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; - - // Validate. - if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { - upb_MdDecoder_ErrorJmp(&d->base, - "Invalid modifier(s) for repeated field %" PRIu32, - upb_MiniTableField_Number(field)); - } - if (singular && required) { - upb_MdDecoder_ErrorJmp( - &d->base, "Field %" PRIu32 " cannot be both singular and required", - upb_MiniTableField_Number(field)); - } - - if (singular && upb_MiniTableField_IsSubMessage(field)) { - upb_MdDecoder_ErrorJmp(&d->base, - "Field %" PRIu32 " cannot be a singular submessage", - upb_MiniTableField_Number(field)); - } - - if (singular) field->UPB_PRIVATE(offset) = kNoPresence; - if (required) { - field->UPB_PRIVATE(offset) = kRequiredPresence; - } -} - -static void upb_MtDecoder_PushOneof(upb_MtDecoder* d, - upb_OneOfLayoutItem item) { - if (item.field_index == kUpb_OneOfLayoutItem_IndexSentinel) { - upb_MdDecoder_ErrorJmp(&d->base, "Empty oneof"); - } - if ((d->oneofs.size + 1) * sizeof(*d->oneofs.data) > - d->oneofs.buf_capacity_bytes) { - size_t new_cap = UPB_MAX(8, d->oneofs.size * 2) * sizeof(*d->oneofs.data); - d->oneofs.data = - upb_grealloc(d->oneofs.data, d->oneofs.buf_capacity_bytes, new_cap); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->oneofs.data); - d->oneofs.buf_capacity_bytes = new_cap; - } - item.field_index -= kOneofBase; - - d->rep_counts_offsets[kUpb_OneOf_CaseFieldRep]++; - d->rep_counts_offsets[item.rep]++; - d->oneofs.data[d->oneofs.size++] = item; -} - -static size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, - upb_MiniTablePlatform platform) { - enum { string_view_size_32 = 8, string_view_size_64 = 16 }; - UPB_STATIC_ASSERT(sizeof(upb_StringView) == - UPB_SIZE(string_view_size_32, string_view_size_64), - "StringView size mismatch"); - static const uint8_t kRepToSize32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = string_view_size_32, - [kUpb_FieldRep_8Byte] = 8, - }; - static const uint8_t kRepToSize64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = string_view_size_64, - [kUpb_FieldRep_8Byte] = 8, - }; - return platform == kUpb_MiniTablePlatform_32Bit ? kRepToSize32[rep] - : kRepToSize64[rep]; -} - -static size_t upb_MtDecoder_AlignOfRep(upb_FieldRep rep, - upb_MiniTablePlatform platform) { - enum { string_view_align_32 = 4, string_view_align_64 = 8 }; - UPB_STATIC_ASSERT(UPB_ALIGN_OF(upb_StringView) == - UPB_SIZE(string_view_align_32, string_view_align_64), - "StringView size mismatch"); - - static const uint8_t kRepToAlign32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = string_view_align_32, - [kUpb_FieldRep_8Byte] = 8, - }; - static const uint8_t kRepToAlign64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = string_view_align_64, - [kUpb_FieldRep_8Byte] = 8, - }; - return platform == kUpb_MiniTablePlatform_32Bit ? kRepToAlign32[rep] - : kRepToAlign64[rep]; -} - -static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, - const char* ptr, - char first_ch, - upb_OneOfLayoutItem* item) { - uint32_t field_num; - ptr = upb_MdDecoder_DecodeBase92Varint( - &d->base, ptr, first_ch, kUpb_EncodedValue_MinOneofField, - kUpb_EncodedValue_MaxOneofField, &field_num); - upb_MiniTableField* f = - (void*)upb_MiniTable_FindFieldByNumber(&d->table, field_num); - - if (!f) { - upb_MdDecoder_ErrorJmp(&d->base, - "Couldn't add field number %" PRIu32 - " to oneof, no such field number.", - field_num); - } - if (f->UPB_PRIVATE(offset) != kHasbitPresence) { - upb_MdDecoder_ErrorJmp( - &d->base, - "Cannot add repeated, required, or singular field %" PRIu32 - " to oneof.", - field_num); - } - - // Oneof storage must be large enough to accommodate the largest member. - int rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift; - size_t new_size = upb_MtDecoder_SizeOfRep(rep, d->platform); - size_t new_align = upb_MtDecoder_AlignOfRep(rep, d->platform); - size_t current_size = upb_MtDecoder_SizeOfRep(item->rep, d->platform); - size_t current_align = upb_MtDecoder_AlignOfRep(item->rep, d->platform); - - if (new_size > current_size || - (new_size == current_size && new_align > current_align)) { - UPB_ASSERT(new_align >= current_align); - item->rep = rep; - } else { - UPB_ASSERT(current_align >= new_align); - } - // Prepend this field to the linked list. - f->UPB_PRIVATE(offset) = item->field_index; - item->field_index = (f - d->fields) + kOneofBase; - return ptr; -} - -static const char* upb_MtDecoder_DecodeOneofs(upb_MtDecoder* d, - const char* ptr) { - upb_OneOfLayoutItem item = { - .rep = 0, .field_index = kUpb_OneOfLayoutItem_IndexSentinel}; - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch == kUpb_EncodedValue_FieldSeparator) { - // Field separator, no action needed. - } else if (ch == kUpb_EncodedValue_OneofSeparator) { - // End of oneof. - upb_MtDecoder_PushOneof(d, item); - item.field_index = - kUpb_OneOfLayoutItem_IndexSentinel; // Move to next oneof. - } else { - ptr = upb_MtDecoder_DecodeOneofField(d, ptr, ch, &item); - } - } - - // Push final oneof. - upb_MtDecoder_PushOneof(d, item); - return ptr; -} - -static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d, - const char* ptr, char first_ch, - upb_MiniTableField* last_field, - uint64_t* msg_modifiers) { - uint32_t mod; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, first_ch, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier, &mod); - if (last_field) { - upb_MtDecoder_ModifyField(d, *msg_modifiers, mod, last_field); - } else { - if (d->is_extension) { - upb_MdDecoder_ErrorJmp(&d->base, - "Extensions cannot have message modifiers"); - } - *msg_modifiers = mod; - } - - return ptr; -} - -size_t upb_MtDecoder_PtrSize(upb_MtDecoder* d) { - return d->platform == kUpb_MiniTablePlatform_32Bit ? 4 : 8; -} - -static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, - upb_MiniTableSubInternal* subs) { - // The `ofs` variable tracks byte offset between the current field and the - // current entry in the `subs` array. Whenever we move to the next entry in - // the `fields` array, the offset decreases by the size of the field, but - // whenever we move to the next entry in the `subs` array, the offset - // *increases* by the size of the entry in the `subs` array. - UPB_ASSERT((char*)subs >= (char*)d->fields); - size_t ofs = (char*)subs - (char*)d->fields; - uintptr_t ptr_size = upb_MtDecoder_PtrSize(d); - for (int i = 0; i < d->table.UPB_PRIVATE(field_count); - i++, ofs -= sizeof(upb_MiniTableField)) { - upb_MiniTableField* f = &d->fields[i]; - if (f->UPB_PRIVATE(submsg_ofs) == kUpb_NoSub) continue; - size_t u32_ofs = ofs / kUpb_SubmsgOffsetBytes; - UPB_ASSERT((ofs % 4) == 0); - UPB_ASSERT((i * sizeof(upb_MiniTableField) + ofs) % ptr_size == 0); - if (u32_ofs > UINT16_MAX) { - upb_MdDecoder_ErrorJmp(&d->base, "Submessage offset overflow"); - } - f->UPB_PRIVATE(submsg_ofs) = u32_ofs; - ofs += ptr_size; - } -} - -static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, - size_t len, void* fields, - size_t field_size, - uint16_t* field_count) { - uint64_t msg_modifiers = 0; - uint32_t last_field_number = 0; - upb_MiniTableField* last_field = NULL; - bool need_dense_below = !d->is_extension; - - d->base.end = UPB_PTRADD(ptr, len); - - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch <= kUpb_EncodedValue_MaxField) { - if (d->is_extension && last_field) { - // For extensions, consume only a single field and then return. - return --ptr; - } - upb_MiniTableField* field = fields; - *field_count += 1; - fields = (char*)fields + field_size; - uint32_t number = ++last_field_number; - if (number == 0 || (number > kUpb_MaxFieldNumber && !d->is_extension)) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid field number: %" PRIu32, - number); - } - field->UPB_PRIVATE(number) = number; - last_field = field; - upb_MiniTable_SetField(d, ch, field, msg_modifiers); - } else if (kUpb_EncodedValue_MinModifier <= ch && - ch <= kUpb_EncodedValue_MaxModifier) { - ptr = upb_MtDecoder_ParseModifier(d, ptr, ch, last_field, &msg_modifiers); - if (msg_modifiers & kUpb_MessageModifier_IsExtendable) { - d->table.UPB_PRIVATE(ext) |= kUpb_ExtMode_Extendable; - } - } else if (ch == kUpb_EncodedValue_End) { - if (d->is_extension) { - upb_MdDecoder_ErrorJmp(&d->base, "Extensions cannot have oneofs."); - } - ptr = upb_MtDecoder_DecodeOneofs(d, ptr); - } else if (kUpb_EncodedValue_MinSkip <= ch && - ch <= kUpb_EncodedValue_MaxSkip) { - if (need_dense_below) { - d->table.UPB_PRIVATE(dense_below) = d->table.UPB_PRIVATE(field_count); - need_dense_below = false; - } - uint32_t skip; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, - kUpb_EncodedValue_MinSkip, - kUpb_EncodedValue_MaxSkip, &skip); - last_field_number += skip; - last_field_number--; // Next field seen will increment. - } else { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid char: %c", ch); - } - } - - if (need_dense_below) { - d->table.UPB_PRIVATE(dense_below) = d->table.UPB_PRIVATE(field_count); - } - - return ptr; -} - -static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, - size_t len) { - const size_t bytes_per_field = - sizeof(upb_MiniTableField) + sizeof(upb_MiniTableSubInternal); - // Buffer length is an upper bound on the number of fields. We will return - // what we don't use. - if ((SIZE_MAX - 4) / bytes_per_field < len) { - upb_MdDecoder_ErrorJmp(&d->base, "MiniDescriptor is too large"); - } - // Max size used per field is a upb_MiniTableField and a - // upb_MiniTableSubInternal. There could also be up to 4 bytes of padding, - // since sizeof(upb_MiniTableField) == 12 and - // alignof(upb_MiniTableSubInternal) == 8. - UPB_STATIC_ASSERT(UPB_ALIGN_OF(upb_MiniTableSubInternal) - - UPB_ALIGN_OF(upb_MiniTableField) <= - 4, - "alignment difference is too large"); - const size_t initial_bytes = bytes_per_field * len + 4; - d->fields = upb_Arena_Malloc(d->arena, initial_bytes); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->fields); - - d->table.UPB_PRIVATE(field_count) = 0; - d->table.UPB_PRIVATE(fields) = d->fields; - upb_MtDecoder_Parse(d, data, len, d->fields, sizeof(*d->fields), - &d->table.UPB_PRIVATE(field_count)); - size_t field_bytes = - UPB_ALIGN_UP(d->table.UPB_PRIVATE(field_count) * sizeof(*d->fields), - upb_MtDecoder_PtrSize(d)); - upb_MiniTableSubInternal* subs = - UPB_PTR_AT(d->fields, field_bytes, upb_MiniTableSubInternal); - memset(subs, 0, sizeof(upb_MiniTableSubInternal) * d->sub_count); - - // We now know how much space we actually used, so shrink the allocation to - // that size. - size_t final_bytes = - field_bytes + sizeof(upb_MiniTableSubInternal) * d->sub_count; - upb_Arena_ShrinkLast(d->arena, d->fields, initial_bytes, final_bytes); - upb_MtDecoder_AllocateSubs(d, subs); -} - -static void upb_MtDecoder_CalculateAlignments(upb_MtDecoder* d) { - // Add alignment counts for non-oneof fields (oneofs were added already) - int n = d->table.UPB_PRIVATE(field_count); - for (int i = 0; i < n; i++) { - upb_MiniTableField* f = &d->fields[i]; - if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; - d->rep_counts_offsets[f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift]++; - } - - // Reserve properly aligned space for each type of field representation - // present in this message. When we iterate over the fields, they will obtain - // their offset from within the region matching their alignment requirements. - size_t base = d->table.UPB_PRIVATE(size); - // Start with the lowest alignment requirement, going up, because: - // 1. If there are presence bits, we won't be aligned to start, but adding - // some lower-alignment fields may get us closer without wasting space to - // padding. - // 2. The allocator enforces 8 byte alignment, so moving intermediate padding - // to trailing padding doesn't save us anything. - for (upb_FieldRep rep = kUpb_FieldRep_1Byte; rep <= kUpb_FieldRep_Max; - rep++) { - uint16_t count = d->rep_counts_offsets[rep]; - if (count) { - base = UPB_ALIGN_UP(base, upb_MtDecoder_AlignOfRep(rep, d->platform)); - // This entry now tracks the base offset for this field representation - // type, instead of the count - d->rep_counts_offsets[rep] = base; - base += upb_MtDecoder_SizeOfRep(rep, d->platform) * count; - } - } - static const size_t max = UINT16_MAX; - if (base > max) { - upb_MdDecoder_ErrorJmp( - &d->base, "Message size exceeded maximum size of %zu bytes", max); - } - d->table.UPB_PRIVATE(size) = (uint16_t)base; -} - -static size_t upb_MiniTable_DivideRoundUp(size_t n, size_t d) { - return (n + d - 1) / d; -} - -static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { - int n = d->table.UPB_PRIVATE(field_count); - size_t last_hasbit = kUpb_Reserved_Hasbits - 1; - - // First assign required fields, which must have the lowest hasbits. - for (int i = 0; i < n; i++) { - upb_MiniTableField* field = - (upb_MiniTableField*)&d->table.UPB_PRIVATE(fields)[i]; - if (field->UPB_PRIVATE(offset) == kRequiredPresence) { - field->presence = ++last_hasbit; - } else if (field->UPB_PRIVATE(offset) == kNoPresence) { - field->presence = 0; - } - } - if (last_hasbit >= kUpb_Reserved_Hasbits + 63) { - upb_MdDecoder_ErrorJmp(&d->base, "Too many required fields"); - } - - d->table.UPB_PRIVATE(required_count) = - last_hasbit - (kUpb_Reserved_Hasbits - 1); - UPB_ASSERT(d->table.UPB_PRIVATE(required_count) < 64); - - // Next assign non-required hasbit fields. - for (int i = 0; i < n; i++) { - upb_MiniTableField* field = - (upb_MiniTableField*)&d->table.UPB_PRIVATE(fields)[i]; - if (field->UPB_PRIVATE(offset) == kHasbitPresence) { - field->presence = ++last_hasbit; - } - } - - d->table.UPB_PRIVATE(size) = - last_hasbit ? upb_MiniTable_DivideRoundUp(last_hasbit + 1, 8) : 0; -} - -static size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { - size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); - size_t offset = d->rep_counts_offsets[rep]; - d->rep_counts_offsets[rep] += size; - return offset; -} - -static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { - upb_MiniTableField* field_end = - UPB_PTRADD(d->fields, d->table.UPB_PRIVATE(field_count)); - for (upb_MiniTableField* field = d->fields; field < field_end; field++) { - if (field->UPB_PRIVATE(offset) >= kOneofBase) continue; - field->UPB_PRIVATE(offset) = - upb_MtDecoder_Place(d, field->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift); - } - - upb_OneOfLayoutItem* oneof_end = UPB_PTRADD(d->oneofs.data, d->oneofs.size); - - for (upb_OneOfLayoutItem* item = d->oneofs.data; item < oneof_end; item++) { - upb_MiniTableField* f = &d->fields[item->field_index]; - uint16_t case_offset = upb_MtDecoder_Place(d, kUpb_OneOf_CaseFieldRep); - uint16_t data_offset = upb_MtDecoder_Place(d, item->rep); - while (true) { - f->presence = ~case_offset; - uint16_t next_offset = f->UPB_PRIVATE(offset); - f->UPB_PRIVATE(offset) = data_offset; - if (next_offset == kUpb_OneOfLayoutItem_IndexSentinel) break; - UPB_ASSERT(next_offset - kOneofBase < d->table.UPB_PRIVATE(field_count)); - f = &d->fields[next_offset - kOneofBase]; - } - } - - // Since messages are always allocated on arenas, we can save repeatedly - // realigning by doing alignment at minitable construction time. We don't want - // to align to UPB_MALLOC_ALIGN because it can change with sanitizers, and if - // we're generating code we don't want to calculate size differently depending - // on the proto compiler's host or build configuration. - d->table.UPB_PRIVATE(size) = - UPB_ALIGN_UP(d->table.UPB_PRIVATE(size), kUpb_Message_Align); -} - -static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, - const upb_MiniTableField* f, - uint32_t expected_num) { - const char* name = expected_num == 1 ? "key" : "val"; - const uint32_t f_number = upb_MiniTableField_Number(f); - if (f_number != expected_num) { - upb_MdDecoder_ErrorJmp(&d->base, - "map %s did not have expected number (%d vs %d)", - name, expected_num, f_number); - } - - if (!upb_MiniTableField_IsScalar(f)) { - upb_MdDecoder_ErrorJmp( - &d->base, "map %s cannot be repeated or map, or be in oneof", name); - } - - uint32_t not_ok_types; - if (expected_num == 1) { - not_ok_types = (1 << kUpb_FieldType_Float) | (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Message) | (1 << kUpb_FieldType_Group) | - (1 << kUpb_FieldType_Bytes) | (1 << kUpb_FieldType_Enum); - } else { - not_ok_types = 1 << kUpb_FieldType_Group; - } - - if ((1 << upb_MiniTableField_Type(f)) & not_ok_types) { - upb_MdDecoder_ErrorJmp(&d->base, "map %s cannot have type %d", name, - (int)f->UPB_PRIVATE(descriptortype)); - } -} - -static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, - size_t len) { - upb_MtDecoder_ParseMessage(d, data, len); - upb_MtDecoder_AssignHasbits(d); - - if (UPB_UNLIKELY(d->table.UPB_PRIVATE(field_count) != 2)) { - upb_MdDecoder_ErrorJmp(&d->base, "%hu fields in map", - d->table.UPB_PRIVATE(field_count)); - UPB_UNREACHABLE(); - } - - if (d->oneofs.size != 0) { - upb_MdDecoder_ErrorJmp(&d->base, "Map entry cannot have oneof"); - } - - upb_MtDecoder_ValidateEntryField(d, &d->table.UPB_PRIVATE(fields)[0], 1); - upb_MtDecoder_ValidateEntryField(d, &d->table.UPB_PRIVATE(fields)[1], 2); - - d->fields[0].UPB_PRIVATE(offset) = offsetof(upb_MapEntry, k); - d->fields[1].UPB_PRIVATE(offset) = offsetof(upb_MapEntry, v); - d->table.UPB_PRIVATE(size) = sizeof(upb_MapEntry); - - // Map entries have a special bit set to signal it's a map entry, used in - // upb_MiniTable_SetSubMessage() below. - d->table.UPB_PRIVATE(ext) |= kUpb_ExtMode_IsMapEntry; -} - -static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, - size_t len) { - if (len > 0) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid message set encode length: %zu", - len); - } - - upb_MiniTable* ret = &d->table; - ret->UPB_PRIVATE(size) = kUpb_Reserved_Hasbytes; - ret->UPB_PRIVATE(field_count) = 0; - ret->UPB_PRIVATE(ext) = kUpb_ExtMode_IsMessageSet; - ret->UPB_PRIVATE(dense_below) = 0; - ret->UPB_PRIVATE(table_mask) = -1; - ret->UPB_PRIVATE(required_count) = 0; -} - -static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf( - upb_MtDecoder* decoder, const char* data, size_t len, void** buf, - size_t* buf_size) { - decoder->table.UPB_PRIVATE(size) = kUpb_Reserved_Hasbytes; - decoder->table.UPB_PRIVATE(field_count) = 0; - decoder->table.UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable; - decoder->table.UPB_PRIVATE(dense_below) = 0; - decoder->table.UPB_PRIVATE(table_mask) = -1; - decoder->table.UPB_PRIVATE(required_count) = 0; -#ifdef UPB_TRACING_ENABLED - // MiniTables built from MiniDescriptors will not be able to vend the message - // name unless it is explicitly set with upb_MiniTable_SetFullName(). - decoder->table.UPB_PRIVATE(full_name) = 0; -#endif - - // Strip off and verify the version tag. - if (!len--) goto done; - const char vers = *data++; - - switch (vers) { - case kUpb_EncodedVersion_MapV1: - upb_MtDecoder_ParseMap(decoder, data, len); - break; - - case kUpb_EncodedVersion_MessageV1: - upb_MtDecoder_ParseMessage(decoder, data, len); - upb_MtDecoder_AssignHasbits(decoder); - upb_MtDecoder_CalculateAlignments(decoder); - upb_MtDecoder_AssignOffsets(decoder); - break; - - case kUpb_EncodedVersion_MessageSetV1: - upb_MtDecoder_ParseMessageSet(decoder, data, len); - break; - - default: - upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid message version: %c", - vers); - } - -done: - *buf = decoder->oneofs.data; - *buf_size = decoder->oneofs.buf_capacity_bytes; - size_t mt_size = sizeof(upb_MiniTable); - -#if UPB_FASTTABLE - upb_DecodeFast_TableEntry fasttable[32]; - int fasttable_size = upb_DecodeFast_BuildTable(&decoder->table, fasttable); - mt_size += fasttable_size * sizeof(fasttable[0]); -#endif - - upb_MiniTable* ret = upb_Arena_Malloc(decoder->arena, mt_size); - memcpy(ret, &decoder->table, sizeof(*ret)); - -#if UPB_FASTTABLE - ret->UPB_PRIVATE(table_mask) = upb_DecodeFast_GetTableMask(fasttable_size); - for (int i = 0; i < fasttable_size; i++) { - ret->UPB_PRIVATE(fasttable)[i].field_data = fasttable[i].function_data; - ret->UPB_PRIVATE(fasttable)[i].field_parser = - upb_DecodeFast_GetFunctionPointer(fasttable[i].function_idx); - } -#endif - UPB_PRIVATE(upb_MiniTable_CheckInvariants)(ret); - return ret; -} - -static upb_MiniTable* upb_MtDecoder_BuildMiniTableWithBuf( - upb_MtDecoder* const decoder, const char* const data, const size_t len, - void** const buf, size_t* const buf_size) { - if (UPB_SETJMP(decoder->base.err) != 0) { - *buf = decoder->oneofs.data; - *buf_size = decoder->oneofs.buf_capacity_bytes; - return NULL; - } - - return upb_MtDecoder_DoBuildMiniTableWithBuf(decoder, data, len, buf, - buf_size); -} - -upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, void** buf, - size_t* buf_size, - upb_Status* status) { - upb_MtDecoder decoder = { - .base = {.status = status}, - .platform = platform, - .sub_count = 0, - .is_extension = false, - .oneofs = - { - .data = *buf, - .buf_capacity_bytes = *buf_size, - .size = 0, - }, - .arena = arena, - }; - - return upb_MtDecoder_BuildMiniTableWithBuf(&decoder, data, len, buf, - buf_size); -} - -static const char* upb_MtDecoder_DoBuildMiniTableExtension( - upb_MtDecoder* decoder, const char* data, size_t len, - upb_MiniTableExtension* ext, const upb_MiniTable* extendee, - upb_MiniTableSub sub) { - if (!(extendee->UPB_PRIVATE(ext) & - (kUpb_ExtMode_Extendable | kUpb_ExtMode_IsMessageSet))) { - upb_MdDecoder_ErrorJmp(&decoder->base, "Extendee is not extendable"); - } - - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_ExtensionV1) { - upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid ext version: %c", *data); - } - data++; - len--; - } - - uint16_t count = 0; - const char* ret = - upb_MtDecoder_Parse(decoder, data, len, ext, sizeof(*ext), &count); - if (!ret || count != 1) return NULL; - - upb_MiniTableField* f = &ext->UPB_PRIVATE(field); - - f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; - f->UPB_PRIVATE(offset) = 0; - f->presence = 0; - - // In upb_MiniTableExtension, the `sub` member is a pointer-sized member that - // directly follows the `field` member. - f->UPB_PRIVATE(submsg_ofs) = - UPB_ALIGN_UP(sizeof(upb_MiniTableField), upb_MtDecoder_PtrSize(decoder)) / - kUpb_SubmsgOffsetBytes; - - if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { - // Extensions of MessageSet must be messages. - if (!upb_MiniTableField_IsSubMessage(f)) return NULL; - - // Extensions of MessageSet must be non-repeating. - if (upb_MiniTableField_IsArray(f)) return NULL; - } - - ext->UPB_PRIVATE(extendee) = extendee; - ext->UPB_PRIVATE(sub) = sub; - - return ret; -} - -static const char* upb_MtDecoder_BuildMiniTableExtension( - upb_MtDecoder* const decoder, const char* const data, const size_t len, - upb_MiniTableExtension* const ext, const upb_MiniTable* const extendee, - const upb_MiniTableSub sub) { - if (UPB_SETJMP(decoder->base.err) != 0) return NULL; - return upb_MtDecoder_DoBuildMiniTableExtension(decoder, data, len, ext, - extendee, sub); -} - -const char* _upb_MiniTableExtension_Init(const char* data, size_t len, - upb_MiniTableExtension* ext, - const upb_MiniTable* extendee, - upb_MiniTableSub sub, - upb_MiniTablePlatform platform, - upb_Status* status) { - upb_MtDecoder decoder = { - .base = {.status = status}, - .arena = NULL, - .platform = platform, - .sub_count = 0, - .is_extension = true, - }; - - return upb_MtDecoder_BuildMiniTableExtension(&decoder, data, len, ext, - extendee, sub); -} - -upb_MiniTableExtension* _upb_MiniTableExtension_Build( - const char* data, size_t len, const upb_MiniTable* extendee, - upb_MiniTableSub sub, upb_MiniTablePlatform platform, upb_Arena* arena, - upb_Status* status) { - upb_MiniTableExtension* ext = - upb_Arena_Malloc(arena, sizeof(upb_MiniTableExtension)); - if (UPB_UNLIKELY(!ext)) return NULL; - - const char* ptr = _upb_MiniTableExtension_Init(data, len, ext, extendee, sub, - platform, status); - if (UPB_UNLIKELY(!ptr)) return NULL; - - return ext; -} - -upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, upb_Status* status) { - void* buf = NULL; - size_t size = 0; - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena, - &buf, &size, status); - upb_gfree(buf); - return ret; -} diff --git a/vendor/upb/mini_descriptor/decode.h b/vendor/upb/mini_descriptor/decode.h deleted file mode 100644 index 5542d5d..0000000 --- a/vendor/upb/mini_descriptor/decode.h +++ /dev/null @@ -1,121 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_DECODE_H_ -#define UPB_MINI_TABLE_DECODE_H_ - -#include - -#include "upb/base/status.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" - -// Export the newer headers, for legacy users. New users should include the -// more specific headers directly. -// IWYU pragma: begin_exports -#include "upb/mini_descriptor/build_enum.h" -#include "upb/mini_descriptor/link.h" -// IWYU pragma: end_exports - -// Must be last. -#include "upb/port/def.inc" - -typedef enum { - kUpb_MiniTablePlatform_32Bit, - kUpb_MiniTablePlatform_64Bit, - kUpb_MiniTablePlatform_Native = - UPB_SIZE(kUpb_MiniTablePlatform_32Bit, kUpb_MiniTablePlatform_64Bit), -} upb_MiniTablePlatform; - -#ifdef __cplusplus -extern "C" { -#endif - -// Builds a mini table from the data encoded in the buffer [data, len]. If any -// errors occur, returns NULL and sets a status message. In the success case, -// the caller must call upb_MiniTable_SetSub*() for all message or proto2 enum -// fields to link the table to the appropriate sub-tables. -UPB_NODISCARD upb_MiniTable* _upb_MiniTable_Build( - const char* data, size_t len, upb_MiniTablePlatform platform, - upb_Arena* arena, upb_Status* status); - -UPB_NODISCARD UPB_API_INLINE upb_MiniTable* upb_MiniTable_Build( - const char* data, size_t len, upb_Arena* arena, upb_Status* status) { - return _upb_MiniTable_Build(data, len, kUpb_MiniTablePlatform_Native, arena, - status); -} - -// Initializes a MiniTableExtension buffer that has already been allocated. -// This is needed by upb_FileDef and upb_MessageDef, which allocate all of the -// extensions together in a single contiguous array. -UPB_NODISCARD const char* _upb_MiniTableExtension_Init( - const char* data, size_t len, upb_MiniTableExtension* ext, - const upb_MiniTable* extendee, upb_MiniTableSub sub, - upb_MiniTablePlatform platform, upb_Status* status); - -UPB_NODISCARD UPB_API_INLINE const char* upb_MiniTableExtension_Init( - const char* data, size_t len, upb_MiniTableExtension* ext, - const upb_MiniTable* extendee, upb_MiniTableSub sub, upb_Status* status) { - return _upb_MiniTableExtension_Init(data, len, ext, extendee, sub, - kUpb_MiniTablePlatform_Native, status); -} - -UPB_NODISCARD UPB_API upb_MiniTableExtension* _upb_MiniTableExtension_Build( - const char* data, size_t len, const upb_MiniTable* extendee, - upb_MiniTableSub sub, upb_MiniTablePlatform platform, upb_Arena* arena, - upb_Status* status); - -UPB_NODISCARD UPB_API_INLINE upb_MiniTableExtension* -upb_MiniTableExtension_Build(const char* data, size_t len, - const upb_MiniTable* extendee, upb_Arena* arena, - upb_Status* status) { - upb_MiniTableSub sub = upb_MiniTableSub_FromMessage(NULL); - return _upb_MiniTableExtension_Build( - data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status); -} - -UPB_NODISCARD UPB_API_INLINE upb_MiniTableExtension* -upb_MiniTableExtension_BuildMessage(const char* data, size_t len, - const upb_MiniTable* extendee, - const upb_MiniTable* submsg, - upb_Arena* arena, upb_Status* status) { - upb_MiniTableSub sub = upb_MiniTableSub_FromMessage(submsg); - return _upb_MiniTableExtension_Build( - data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status); -} - -UPB_NODISCARD UPB_API_INLINE upb_MiniTableExtension* -upb_MiniTableExtension_BuildEnum(const char* data, size_t len, - const upb_MiniTable* extendee, - const upb_MiniTableEnum* subenum, - upb_Arena* arena, upb_Status* status) { - upb_MiniTableSub sub = upb_MiniTableSub_FromEnum(subenum); - return _upb_MiniTableExtension_Build( - data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status); -} - -// Like upb_MiniTable_Build(), but the user provides a buffer of layout data so -// it can be reused from call to call, avoiding repeated -// upb_grealloc()/upb_gfree(). -// -// The caller owns `*buf` both before and after the call, and must upb_gfree() -// it when it is no longer in use. The function will upb_grealloc() `*buf` as -// necessary, updating `*size` accordingly. -UPB_NODISCARD upb_MiniTable* upb_MiniTable_BuildWithBuf( - const char* data, size_t len, upb_MiniTablePlatform platform, - upb_Arena* arena, void** buf, size_t* buf_size, upb_Status* status); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_DECODE_H_ */ diff --git a/vendor/upb/mini_descriptor/internal/base92.c b/vendor/upb/mini_descriptor/internal/base92.c deleted file mode 100644 index 18783d9..0000000 --- a/vendor/upb/mini_descriptor/internal/base92.c +++ /dev/null @@ -1,26 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_descriptor/internal/base92.h" - -const char _kUpb_ToBase92[] = { - ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', - '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', - 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', - 'Z', '[', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '{', '|', '}', '~', -}; - -const int8_t _kUpb_FromBase92[] = { - 0, 1, -1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, -}; diff --git a/vendor/upb/mini_descriptor/internal/base92.h b/vendor/upb/mini_descriptor/internal/base92.h deleted file mode 100644 index 4201c25..0000000 --- a/vendor/upb/mini_descriptor/internal/base92.h +++ /dev/null @@ -1,63 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ - -#include - -#include "upb/base/internal/log2.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE char _upb_ToBase92(int8_t ch) { - extern const char _kUpb_ToBase92[]; - UPB_ASSERT(0 <= ch && ch < 92); - return _kUpb_ToBase92[ch]; -} - -UPB_INLINE char _upb_FromBase92(uint8_t ch) { - extern const int8_t _kUpb_FromBase92[]; - if (' ' > ch || ch > '~') return -1; - return _kUpb_FromBase92[ch - ' ']; -} - -UPB_INLINE const char* _upb_Base92_DecodeVarint(const char* ptr, - const char* end, char first_ch, - uint8_t min, uint8_t max, - uint32_t* out_val) { - uint32_t val = 0; - uint32_t shift = 0; - const int bits_per_char = - upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min)); - char ch = first_ch; - while (1) { - uint32_t bits = _upb_FromBase92(ch) - _upb_FromBase92(min); - val |= bits << shift; - if (ptr == end || *ptr < min || max < *ptr) { - *out_val = val; - UPB_ASSUME(ptr != NULL); - return ptr; - } - ch = *ptr++; - shift += bits_per_char; - if (shift >= 32) return NULL; - } -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ diff --git a/vendor/upb/mini_descriptor/internal/decoder.h b/vendor/upb/mini_descriptor/internal/decoder.h deleted file mode 100644 index 9ac3282..0000000 --- a/vendor/upb/mini_descriptor/internal/decoder.h +++ /dev/null @@ -1,53 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_ - -#include "upb/base/status.h" -#include "upb/mini_descriptor/internal/base92.h" - -// Must be last. -#include "upb/port/def.inc" - -// upb_MdDecoder: used internally for decoding MiniDescriptors for messages, -// extensions, and enums. -typedef struct { - const char* end; - upb_Status* status; - jmp_buf err; -} upb_MdDecoder; - -UPB_PRINTF(2, 3) -UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp(upb_MdDecoder* d, - const char* fmt, ...) { - if (d->status) { - va_list argp; - upb_Status_SetErrorMessage(d->status, "Error building mini table: "); - va_start(argp, fmt); - upb_Status_VAppendErrorFormat(d->status, fmt, argp); - va_end(argp); - } - UPB_LONGJMP(d->err, 1); -} - -UPB_INLINE void upb_MdDecoder_CheckOutOfMemory(upb_MdDecoder* d, - const void* ptr) { - if (!ptr) upb_MdDecoder_ErrorJmp(d, "Out of memory"); -} - -UPB_INLINE const char* upb_MdDecoder_DecodeBase92Varint( - upb_MdDecoder* d, const char* ptr, char first_ch, uint8_t min, uint8_t max, - uint32_t* out_val) { - ptr = _upb_Base92_DecodeVarint(ptr, d->end, first_ch, min, max, out_val); - if (!ptr) upb_MdDecoder_ErrorJmp(d, "Overlong varint"); - return ptr; -} - -#include "upb/port/undef.inc" - -#endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_ diff --git a/vendor/upb/mini_descriptor/internal/encode.c b/vendor/upb/mini_descriptor/internal/encode.c deleted file mode 100644 index 2193ffe..0000000 --- a/vendor/upb/mini_descriptor/internal/encode.c +++ /dev/null @@ -1,323 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_descriptor/internal/encode.h" - -#include -#include -#include - -#include "upb/base/internal/log2.h" -#include "upb/mini_descriptor/internal/base92.h" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_descriptor/internal/wire_constants.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - uint64_t present_values_mask; - uint32_t last_written_value; -} upb_MtDataEncoderInternal_EnumState; - -typedef struct { - uint64_t msg_modifiers; - uint32_t last_field_num; - enum { - kUpb_OneofState_NotStarted, - kUpb_OneofState_StartedOneof, - kUpb_OneofState_EmittedOneofField, - } oneof_state; -} upb_MtDataEncoderInternal_MsgState; - -typedef struct { - char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. - union { - upb_MtDataEncoderInternal_EnumState enum_state; - upb_MtDataEncoderInternal_MsgState msg_state; - } state; -} upb_MtDataEncoderInternal; - -static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( - upb_MtDataEncoder* e, char* buf_start) { - UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); - upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; - ret->buf_start = buf_start; - return ret; -} - -static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, - char ch) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); - if (ptr == e->end) return NULL; - *ptr++ = ch; - return ptr; -} - -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); -} - -static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, - uint32_t val, int min, int max) { - int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); - UPB_ASSERT(shift <= 6); - uint32_t mask = (1 << shift) - 1; - do { - uint32_t bits = val & mask; - ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); - if (!ptr) return NULL; - val >>= shift; - } while (val); - return ptr; -} - -char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, - uint64_t mod) { - if (mod) { - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier); - } - return ptr; -} - -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); - if (!ptr) return NULL; - - return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); -} - -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); - if (!ptr) return NULL; - - ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); - if (!ptr) return NULL; - - return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); -} - -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { - (void)upb_MtDataEncoder_GetInternal(e, ptr); - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); -} - -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = msg_mod; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); - if (!ptr) return NULL; - - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); -} - -static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, - char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - if (field_num <= in->state.msg_state.last_field_num) return NULL; - if (in->state.msg_state.last_field_num + 1 != field_num) { - // Put skip. - UPB_ASSERT(field_num > in->state.msg_state.last_field_num); - uint32_t skip = field_num - in->state.msg_state.last_field_num; - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - if (!ptr) return NULL; - } - in->state.msg_state.last_field_num = field_num; - return ptr; -} - -static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, - uint64_t field_mod) { - static const char kUpb_TypeToEncoded[] = { - [kUpb_FieldType_Double] = kUpb_EncodedType_Double, - [kUpb_FieldType_Float] = kUpb_EncodedType_Float, - [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, - [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, - [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, - [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, - [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, - [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, - [kUpb_FieldType_String] = kUpb_EncodedType_String, - [kUpb_FieldType_Group] = kUpb_EncodedType_Group, - [kUpb_FieldType_Message] = kUpb_EncodedType_Message, - [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, - [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, - [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, - [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, - [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, - [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, - }; - - int encoded_type = kUpb_TypeToEncoded[type]; - - if (field_mod & kUpb_FieldModifier_IsClosedEnum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - encoded_type = kUpb_EncodedType_ClosedEnum; - } - - if (field_mod & kUpb_FieldModifier_IsRepeated) { - // Repeated fields shift the type number up (unlike other modifiers which - // are bit flags). - encoded_type += kUpb_EncodedType_RepeatedBase; - } - - return upb_MtDataEncoder_Put(e, ptr, encoded_type); -} - -static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, - char* ptr, upb_FieldType type, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - uint32_t encoded_modifiers = 0; - if ((field_mod & kUpb_FieldModifier_IsRepeated) && - upb_FieldType_IsPackable(type)) { - bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; - bool default_is_packed = in->state.msg_state.msg_modifiers & - kUpb_MessageModifier_DefaultIsPacked; - if (field_is_packed != default_is_packed) { - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; - } - } - - if (type == kUpb_FieldType_String) { - bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; - bool message_validates_utf8 = - in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; - if (field_validates_utf8 != message_validates_utf8) { - // Old binaries do not recognize the field modifier. We need the failure - // mode to be too lax rather than too strict. Our caller should have - // handled this (see _upb_MessageDef_ValidateUtf8()). - assert(!message_validates_utf8); - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; - } - } - - if (field_mod & kUpb_FieldModifier_IsProto3Singular) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; - } - - if (field_mod & kUpb_FieldModifier_IsRequired) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; - } - - return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); -} - -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoder_GetInternal(e, ptr); - - ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); - if (!ptr) return NULL; - - ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); - if (!ptr) return NULL; - - return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); -} - -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { - ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); - } else { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); - } - in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; - return ptr; -} - -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); - if (!ptr) return NULL; - } - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), - _upb_ToBase92(63)); - in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; - return ptr; -} - -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value = 0; - - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); -} - -static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, - char* ptr) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value += 5; - return ptr; -} - -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val) { - // TODO: optimize this encoding. - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - UPB_ASSERT(val >= in->state.enum_state.last_written_value); - uint32_t delta = val - in->state.enum_state.last_written_value; - if (delta >= 5 && in->state.enum_state.present_values_mask) { - ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } - delta -= 5; - } - - if (delta >= 5) { - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - in->state.enum_state.last_written_value += delta; - delta = 0; - } - - UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); - in->state.enum_state.present_values_mask |= 1ULL << delta; - return ptr; -} - -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (!in->state.enum_state.present_values_mask) return ptr; - return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); -} diff --git a/vendor/upb/mini_descriptor/internal/encode.h b/vendor/upb/mini_descriptor/internal/encode.h deleted file mode 100644 index 3180f0b..0000000 --- a/vendor/upb/mini_descriptor/internal/encode.h +++ /dev/null @@ -1,92 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ - -#include - -#include "upb/base/descriptor_constants.h" - -// Must be last. -#include "upb/port/def.inc" - -// If the input buffer has at least this many bytes available, the encoder call -// is guaranteed to succeed (as long as field number order is maintained). -#define kUpb_MtDataEncoder_MinSize 16 - -typedef struct { - char* end; // Limit of the buffer passed as a parameter. - // Aliased to internal-only members in .cc. - char internal[32]; -} upb_MtDataEncoder; - -#ifdef __cplusplus -extern "C" { -#endif - -// Encodes field/oneof information for a given message. The sequence of calls -// should look like: -// -// upb_MtDataEncoder e; -// char buf[256]; -// char* ptr = buf; -// e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); -// // Fields *must* be in field number order. -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// -// // If oneofs are present. Oneofs must be encoded after regular fields. -// ptr = upb_MiniTable_StartOneof(&e, ptr) -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// ptr = upb_MiniTable_StartOneof(&e, ptr); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// Oneofs must be encoded after all regular fields. -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod); -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num); - -// Encodes the set of values for a given enum. The values must be given in -// order (after casting to uint32_t), and repeats are not allowed. -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val); -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); - -// Encodes an entire mini descriptor for an extension. -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); - -// Encodes an entire mini descriptor for a map. -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod); - -// Encodes an entire mini descriptor for a message set. -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ diff --git a/vendor/upb/mini_descriptor/internal/encode.hpp b/vendor/upb/mini_descriptor/internal/encode.hpp deleted file mode 100644 index ccc9409..0000000 --- a/vendor/upb/mini_descriptor/internal/encode.hpp +++ /dev/null @@ -1,120 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_ENCODE_INTERNAL_HPP_ -#define UPB_MINI_TABLE_ENCODE_INTERNAL_HPP_ - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/internal/log2.h" -#include "upb/mini_descriptor/internal/encode.h" - -namespace upb { - -class MtDataEncoder { - public: - MtDataEncoder() : appender_(&encoder_) {} - - bool StartMessage(uint64_t msg_mod) { - return appender_([this, msg_mod](char* buf) { - return upb_MtDataEncoder_StartMessage(&encoder_, buf, msg_mod); - }); - } - - bool PutField(upb_FieldType type, uint32_t field_num, uint64_t field_mod) { - return appender_([this, type, field_num, field_mod](char* buf) { - return upb_MtDataEncoder_PutField(&encoder_, buf, type, field_num, - field_mod); - }); - } - - bool StartOneof() { - return appender_([this](char* buf) { - return upb_MtDataEncoder_StartOneof(&encoder_, buf); - }); - } - - bool PutOneofField(uint32_t field_num) { - return appender_([this, field_num](char* buf) { - return upb_MtDataEncoder_PutOneofField(&encoder_, buf, field_num); - }); - } - - bool StartEnum() { - return appender_([this](char* buf) { - return upb_MtDataEncoder_StartEnum(&encoder_, buf); - }); - } - - bool PutEnumValue(uint32_t enum_value) { - return appender_([this, enum_value](char* buf) { - return upb_MtDataEncoder_PutEnumValue(&encoder_, buf, enum_value); - }); - } - - bool EndEnum() { - return appender_([this](char* buf) { - return upb_MtDataEncoder_EndEnum(&encoder_, buf); - }); - } - - bool EncodeExtension(upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - return appender_([this, type, field_num, field_mod](char* buf) { - return upb_MtDataEncoder_EncodeExtension(&encoder_, buf, type, field_num, - field_mod); - }); - } - - bool EncodeMap(upb_FieldType key_type, upb_FieldType val_type, - uint64_t key_mod, uint64_t val_mod) { - return appender_([this, key_type, val_type, key_mod, val_mod](char* buf) { - return upb_MtDataEncoder_EncodeMap(&encoder_, buf, key_type, val_type, - key_mod, val_mod); - }); - } - - bool EncodeMessageSet() { - return appender_([this](char* buf) { - return upb_MtDataEncoder_EncodeMessageSet(&encoder_, buf); - }); - } - - const std::string& data() const { return appender_.data(); } - - private: - class StringAppender { - public: - StringAppender(upb_MtDataEncoder* e) { e->end = buf_ + sizeof(buf_); } - - template - bool operator()(T&& func) { - char* end = func(buf_); - if (!end) return false; - // C++ does not guarantee that string has doubling growth behavior, but - // we need it to avoid O(n^2). - str_.reserve(upb_RoundUpToPowerOfTwo(str_.size() + (end - buf_))); - str_.append(buf_, end - buf_); - return true; - } - - const std::string& data() const { return str_; } - - private: - char buf_[kUpb_MtDataEncoder_MinSize]; - std::string str_; - }; - - upb_MtDataEncoder encoder_; - StringAppender appender_; -}; - -} // namespace upb - -#endif /* UPB_MINI_TABLE_ENCODE_INTERNAL_HPP_ */ diff --git a/vendor/upb/mini_descriptor/internal/encode_test.cc b/vendor/upb/mini_descriptor/internal/encode_test.cc deleted file mode 100644 index ff21e62..0000000 --- a/vendor/upb/mini_descriptor/internal/encode_test.cc +++ /dev/null @@ -1,287 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_descriptor/internal/encode.hpp" - -#include -#include - -#include -#include - -#include -#include "absl/container/flat_hash_set.h" -#include "google/protobuf/descriptor.h" -#include "upb/base/descriptor_constants.h" -#include "upb/base/status.hpp" -#include "upb/mem/arena.hpp" -#include "upb/message/internal/accessors.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_descriptor/internal/base92.h" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace protobuf = ::google::protobuf; - -class MiniTableTest : public testing::TestWithParam {}; - -TEST_P(MiniTableTest, Empty) { - upb::Arena arena; - upb::Status status; - upb_MiniTable* table = - _upb_MiniTable_Build(nullptr, 0, GetParam(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table); - EXPECT_EQ(0, upb_MiniTable_FieldCount(table)); - EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); -} - -TEST_P(MiniTableTest, AllScalarTypes) { - upb::Arena arena; - upb::MtDataEncoder e; - ASSERT_TRUE(e.StartMessage(0)); - int count = 0; - for (int i = kUpb_FieldType_Double; i < kUpb_FieldType_SInt64; i++) { - ASSERT_TRUE(e.PutField(static_cast(i), i, 0)); - count++; - } - upb::Status status; - upb_MiniTable* table = _upb_MiniTable_Build( - e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table); - EXPECT_EQ(count, table->UPB_PRIVATE(field_count)); - absl::flat_hash_set offsets; - for (int i = 0; i < 16; i++) { - const upb_MiniTableField* f = &table->UPB_PRIVATE(fields)[i]; - EXPECT_EQ(i + 1, upb_MiniTableField_Number(f)); - EXPECT_TRUE(upb_MiniTableField_IsScalar(f)); - EXPECT_TRUE(offsets.insert(f->UPB_PRIVATE(offset)).second); - EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); - } - EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); -} - -TEST_P(MiniTableTest, AllRepeatedTypes) { - upb::Arena arena; - upb::MtDataEncoder e; - ASSERT_TRUE(e.StartMessage(0)); - int count = 0; - for (int i = kUpb_FieldType_Double; i < kUpb_FieldType_SInt64; i++) { - ASSERT_TRUE(e.PutField(static_cast(i), i, - kUpb_FieldModifier_IsRepeated)); - count++; - } - upb::Status status; - upb_MiniTable* table = _upb_MiniTable_Build( - e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table); - EXPECT_EQ(count, table->UPB_PRIVATE(field_count)); - absl::flat_hash_set offsets; - for (int i = 0; i < 16; i++) { - const upb_MiniTableField* f = &table->UPB_PRIVATE(fields)[i]; - EXPECT_EQ(i + 1, upb_MiniTableField_Number(f)); - EXPECT_TRUE(upb_MiniTableField_IsArray(f)); - EXPECT_TRUE(offsets.insert(f->UPB_PRIVATE(offset)).second); - EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); - } - EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); -} - -TEST_P(MiniTableTest, Skips) { - upb::Arena arena; - upb::MtDataEncoder e; - ASSERT_TRUE(e.StartMessage(0)); - int count = 0; - std::vector field_numbers; - for (int i = 0; i < 25; i++) { - int field_number = 1 << i; - field_numbers.push_back(field_number); - ASSERT_TRUE(e.PutField(kUpb_FieldType_Float, field_number, 0)); - count++; - } - upb::Status status; - upb_MiniTable* table = _upb_MiniTable_Build( - e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table); - EXPECT_EQ(count, table->UPB_PRIVATE(field_count)); - absl::flat_hash_set offsets; - for (size_t i = 0; i < field_numbers.size(); i++) { - const upb_MiniTableField* f = &table->UPB_PRIVATE(fields)[i]; - EXPECT_EQ(field_numbers[i], upb_MiniTableField_Number(f)); - EXPECT_EQ(kUpb_FieldType_Float, upb_MiniTableField_Type(f)); - EXPECT_TRUE(upb_MiniTableField_IsScalar(f)); - EXPECT_TRUE(offsets.insert(f->UPB_PRIVATE(offset)).second); - EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); - } - EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); -} - -TEST_P(MiniTableTest, AllScalarTypesOneof) { - upb::Arena arena; - upb::MtDataEncoder e; - ASSERT_TRUE(e.StartMessage(0)); - int count = 0; - for (int i = kUpb_FieldType_Double; i < kUpb_FieldType_SInt64; i++) { - ASSERT_TRUE(e.PutField(static_cast(i), i, 0)); - count++; - } - ASSERT_TRUE(e.StartOneof()); - for (int i = kUpb_FieldType_Double; i < kUpb_FieldType_SInt64; i++) { - ASSERT_TRUE(e.PutOneofField(i)); - } - upb::Status status; - upb_MiniTable* table = _upb_MiniTable_Build( - e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table) << status.error_message(); - EXPECT_EQ(count, table->UPB_PRIVATE(field_count)); - absl::flat_hash_set offsets; - for (int i = 0; i < 16; i++) { - const upb_MiniTableField* f = &table->UPB_PRIVATE(fields)[i]; - EXPECT_EQ(i + 1, upb_MiniTableField_Number(f)); - EXPECT_TRUE(upb_MiniTableField_IsScalar(f)); - // For a oneof all fields have the same offset. - EXPECT_EQ(table->UPB_PRIVATE(fields)[0].UPB_PRIVATE(offset), - f->UPB_PRIVATE(offset)); - // All presence fields should point to the same oneof case offset. - size_t case_ofs = UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f); - EXPECT_EQ(table->UPB_PRIVATE(fields)[0].presence, f->presence); - EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); - EXPECT_TRUE(case_ofs < table->UPB_PRIVATE(size)); - EXPECT_TRUE(case_ofs != f->UPB_PRIVATE(offset)); - } - EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); -} - -TEST_P(MiniTableTest, SizeOverflow) { - upb::Arena arena; - upb::MtDataEncoder e; - // upb can only handle messages up to UINT16_MAX. - size_t max_double_fields = UINT16_MAX / (sizeof(double) + 1); - - // A bit under max_double_fields is ok. - ASSERT_TRUE(e.StartMessage(0)); - for (size_t i = 1; i < max_double_fields; i++) { - ASSERT_TRUE(e.PutField(kUpb_FieldType_Double, i, 0)); - } - upb::Status status; - upb_MiniTable* table = _upb_MiniTable_Build( - e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table) << status.error_message(); - - // A bit over max_double_fields fails. - ASSERT_TRUE(e.StartMessage(0)); - for (size_t i = 1; i < max_double_fields + 2; i++) { - ASSERT_TRUE(e.PutField(kUpb_FieldType_Double, i, 0)); - } - upb_MiniTable* table2 = _upb_MiniTable_Build( - e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); - ASSERT_EQ(nullptr, table2) << status.error_message(); -} - -INSTANTIATE_TEST_SUITE_P(Platforms, MiniTableTest, - testing::Values(kUpb_MiniTablePlatform_32Bit, - kUpb_MiniTablePlatform_64Bit)); - -TEST(MiniTablePlatformIndependentTest, Base92Roundtrip) { - for (char i = 0; i < 92; i++) { - EXPECT_EQ(i, _upb_FromBase92(_upb_ToBase92(i))); - } -} - -TEST(MiniTablePlatformIndependentTest, IsTypePackable) { - for (int i = 1; i <= protobuf::FieldDescriptor::MAX_TYPE; i++) { - EXPECT_EQ(upb_FieldType_IsPackable(static_cast(i)), - protobuf::FieldDescriptor::IsTypePackable( - static_cast(i))); - } -} - -TEST(MiniTableEnumTest, Enum) { - upb::Arena arena; - upb::MtDataEncoder e; - - ASSERT_TRUE(e.StartEnum()); - absl::flat_hash_set values; - for (int i = 0; i < 256; i++) { - values.insert(i * 2); - e.PutEnumValue(i * 2); - } - e.EndEnum(); - - upb::Status status; - upb_MiniTableEnum* table = upb_MiniTableEnum_Build( - e.data().data(), e.data().size(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table) << status.error_message(); - - for (int i = 0; i < UINT16_MAX; i++) { - EXPECT_EQ(values.contains(i), upb_MiniTableEnum_CheckValue(table, i)) << i; - } -} - -TEST(MiniTableTest, SubsInitializedToNull) { - upb::Arena arena; - upb::MtDataEncoder e; - // Create mini table with 2 message fields. - ASSERT_TRUE(e.StartMessage(0)); - ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 15, 0)); - ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 16, 0)); - upb::Status status; - upb_MiniTable* table = upb_MiniTable_Build(e.data().data(), e.data().size(), - arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table); - EXPECT_EQ(upb_MiniTable_FieldCount(table), 2); - EXPECT_FALSE( - upb_MiniTable_FieldIsLinked(upb_MiniTable_GetFieldByIndex(table, 0))); - EXPECT_FALSE( - upb_MiniTable_FieldIsLinked(upb_MiniTable_GetFieldByIndex(table, 1))); -} - -TEST(MiniTableEnumTest, PositiveAndNegative) { - upb::Arena arena; - upb::MtDataEncoder e; - - ASSERT_TRUE(e.StartEnum()); - absl::flat_hash_set values; - for (int i = 0; i < 100; i++) { - values.insert(i); - e.PutEnumValue(i); - } - for (int i = 100; i > 0; i--) { - values.insert(-i); - e.PutEnumValue(-i); - } - e.EndEnum(); - - upb::Status status; - upb_MiniTableEnum* table = upb_MiniTableEnum_Build( - e.data().data(), e.data().size(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table) << status.error_message(); - - for (int i = -UINT16_MAX; i < UINT16_MAX; i++) { - EXPECT_EQ(values.contains(i), upb_MiniTableEnum_CheckValue(table, i)) << i; - } -} - -TEST_P(MiniTableTest, Extendible) { - upb::Arena arena; - upb::MtDataEncoder e; - ASSERT_TRUE(e.StartMessage(kUpb_MessageModifier_IsExtendable)); - for (int i = kUpb_FieldType_Double; i < kUpb_FieldType_SInt64; i++) { - ASSERT_TRUE(e.PutField(static_cast(i), i, 0)); - } - upb::Status status; - upb_MiniTable* table = _upb_MiniTable_Build( - e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); - ASSERT_NE(nullptr, table); - EXPECT_EQ(kUpb_ExtMode_Extendable, - table->UPB_PRIVATE(ext) & kUpb_ExtMode_Extendable); -} diff --git a/vendor/upb/mini_descriptor/internal/modifiers.h b/vendor/upb/mini_descriptor/internal/modifiers.h deleted file mode 100644 index 103b279..0000000 --- a/vendor/upb/mini_descriptor/internal/modifiers.h +++ /dev/null @@ -1,32 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_ - -// Must be last. -#include "upb/port/def.inc" - -typedef enum { - kUpb_FieldModifier_IsRepeated = 1 << 0, - kUpb_FieldModifier_IsPacked = 1 << 1, - kUpb_FieldModifier_IsClosedEnum = 1 << 2, - kUpb_FieldModifier_IsProto3Singular = 1 << 3, - kUpb_FieldModifier_IsRequired = 1 << 4, - kUpb_FieldModifier_ValidateUtf8 = 1 << 5, -} kUpb_FieldModifier; - -// These modifiers are also used on the wire. -typedef enum { - kUpb_MessageModifier_ValidateUtf8 = 1 << 0, - kUpb_MessageModifier_DefaultIsPacked = 1 << 1, - kUpb_MessageModifier_IsExtendable = 1 << 2, -} kUpb_MessageModifier; - -#include "upb/port/undef.inc" - -#endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_ diff --git a/vendor/upb/mini_descriptor/internal/wire_constants.h b/vendor/upb/mini_descriptor/internal/wire_constants.h deleted file mode 100644 index 569da57..0000000 --- a/vendor/upb/mini_descriptor/internal/wire_constants.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_ - -#include "upb/base/descriptor_constants.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef enum { - kUpb_EncodedType_Double = 0, - kUpb_EncodedType_Float = 1, - kUpb_EncodedType_Fixed32 = 2, - kUpb_EncodedType_Fixed64 = 3, - kUpb_EncodedType_SFixed32 = 4, - kUpb_EncodedType_SFixed64 = 5, - kUpb_EncodedType_Int32 = 6, - kUpb_EncodedType_UInt32 = 7, - kUpb_EncodedType_SInt32 = 8, - kUpb_EncodedType_Int64 = 9, - kUpb_EncodedType_UInt64 = 10, - kUpb_EncodedType_SInt64 = 11, - kUpb_EncodedType_OpenEnum = 12, - kUpb_EncodedType_Bool = 13, - kUpb_EncodedType_Bytes = 14, - kUpb_EncodedType_String = 15, - kUpb_EncodedType_Group = 16, - kUpb_EncodedType_Message = 17, - kUpb_EncodedType_ClosedEnum = 18, - - kUpb_EncodedType_RepeatedBase = 20, -} upb_EncodedType; - -typedef enum { - kUpb_EncodedFieldModifier_FlipPacked = 1 << 0, - kUpb_EncodedFieldModifier_IsRequired = 1 << 1, - kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2, - kUpb_EncodedFieldModifier_FlipValidateUtf8 = 1 << 3, -} upb_EncodedFieldModifier; - -enum { - kUpb_EncodedValue_MinField = ' ', - kUpb_EncodedValue_MaxField = 'I', - kUpb_EncodedValue_MinModifier = 'L', - kUpb_EncodedValue_MaxModifier = '[', - kUpb_EncodedValue_End = '^', - kUpb_EncodedValue_MinSkip = '_', - kUpb_EncodedValue_MaxSkip = '~', - kUpb_EncodedValue_OneofSeparator = '~', - kUpb_EncodedValue_FieldSeparator = '|', - kUpb_EncodedValue_MinOneofField = ' ', - kUpb_EncodedValue_MaxOneofField = 'b', - kUpb_EncodedValue_MaxEnumMask = 'A', -}; - -enum { - kUpb_EncodedVersion_EnumV1 = '!', - kUpb_EncodedVersion_ExtensionV1 = '#', - kUpb_EncodedVersion_MapV1 = '%', - kUpb_EncodedVersion_MessageV1 = '$', - kUpb_EncodedVersion_MessageSetV1 = '&', -}; - -#include "upb/port/undef.inc" - -#endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_ diff --git a/vendor/upb/mini_descriptor/link.c b/vendor/upb/mini_descriptor/link.c deleted file mode 100644 index 9a09315..0000000 --- a/vendor/upb/mini_descriptor/link.c +++ /dev/null @@ -1,176 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_descriptor/link.h" - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" - -#ifdef UPB_ENABLE_FASTTABLE -#include "upb/wire/decode_fast/field_parsers.h" -#endif - -// Must be last. -#include "upb/port/def.inc" - -bool upb_MiniTable_SetSubMessage(upb_MiniTable* table, - upb_MiniTableField* field, - const upb_MiniTable* sub) { - UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && - (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + - table->UPB_PRIVATE(field_count))); - UPB_ASSERT(sub); - - const bool sub_is_map = sub->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; - - switch (field->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Message: - if (sub_is_map) { - const bool table_is_map = - table->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; - if (UPB_UNLIKELY(table_is_map)) return false; - - field->UPB_PRIVATE(mode) = - (field->UPB_PRIVATE(mode) & ~kUpb_FieldMode_Mask) | - kUpb_FieldMode_Map; - -#ifdef UPB_ENABLE_FASTTABLE - // The fasttable decoder cannot decode maps. Unfortunately we do not - // know until this moment that the field is a map, so we have to - // overwrite the fasttable entry (if any) that we built for this field - // previously. - int size = table->UPB_PRIVATE(table_mask) == 0xff - ? 0 - : ((table->UPB_PRIVATE(table_mask) >> 3) + 1); - for (int i = 0; i < size; i++) { - _upb_FastTable_Entry* entry = &table->UPB_PRIVATE(fasttable)[i]; - uint32_t field_number = (((int)entry->field_data >> 3) & 0xf) | - (((int)entry->field_data >> 4) & 0x7f0); - if (field_number == upb_MiniTableField_Number(field)) { - entry->field_parser = &_upb_FastDecoder_DecodeGeneric; - entry->field_data = 0; - } - } -#endif - } - break; - - case kUpb_FieldType_Group: - if (UPB_UNLIKELY(sub_is_map)) return false; - break; - - default: - return false; - } - - upb_MiniTableSubInternal* table_sub = - UPB_PTR_AT(field, field->UPB_PRIVATE(submsg_ofs) * kUpb_SubmsgOffsetBytes, - upb_MiniTableSubInternal); - // TODO: Add this assert back once YouTube is updated to not call - // this function repeatedly. - // UPB_ASSERT(upb_MiniTable_GetSubMessageTable(table, field) == NULL); - table_sub->UPB_PRIVATE(submsg) = sub; - return true; -} - -bool upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field, - const upb_MiniTableEnum* sub) { - UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && - (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + - table->UPB_PRIVATE(field_count))); - UPB_ASSERT(sub); - - if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Enum) { - return false; - } - - if ((table->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry) && - !upb_MiniTableEnum_CheckValue(sub, 0)) { - // An enum used in a map must include 0 as a value. This matches a check - // performed in protoc ("Enum value in map must define 0 as the first - // value"). Protoc should ensure that we never get here. - // - // This ends up being important if we receive wire messages where a map - // entry omits the value (and thus defaults to 0). - return false; - } - - upb_MiniTableSubInternal* table_sub = - UPB_PTR_AT(field, field->UPB_PRIVATE(submsg_ofs) * kUpb_SubmsgOffsetBytes, - upb_MiniTableSubInternal); - *table_sub = upb_MiniTableSub_FromEnum(sub); - return true; -} - -uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* m, - const upb_MiniTableField** subs) { - uint32_t msg_count = 0; - uint32_t enum_count = 0; - - for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) { - const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i); - if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { - *subs = f; - ++subs; - msg_count++; - } - } - - for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) { - const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i); - if (upb_MiniTableField_IsClosedEnum(f)) { - *subs = f; - ++subs; - enum_count++; - } - } - - return (msg_count << 16) | enum_count; -} - -// The list of sub_tables and sub_enums must exactly match the number and order -// of sub-message fields and sub-enum fields given by upb_MiniTable_GetSubList() -// above. -bool upb_MiniTable_Link(upb_MiniTable* m, const upb_MiniTable** sub_tables, - size_t sub_table_count, - const upb_MiniTableEnum** sub_enums, - size_t sub_enum_count) { - uint32_t msg_count = 0; - uint32_t enum_count = 0; - - for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) { - upb_MiniTableField* f = - (upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(m, i); - if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { - const upb_MiniTable* sub = sub_tables[msg_count++]; - if (msg_count > sub_table_count) return false; - if (sub && !upb_MiniTable_SetSubMessage(m, f, sub)) return false; - } - } - - for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) { - upb_MiniTableField* f = - (upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(m, i); - if (upb_MiniTableField_IsClosedEnum(f)) { - const upb_MiniTableEnum* sub = sub_enums[enum_count++]; - if (enum_count > sub_enum_count) return false; - if (sub && !upb_MiniTable_SetSubEnum(m, f, sub)) return false; - } - } - - return (msg_count == sub_table_count) && (enum_count == sub_enum_count); -} diff --git a/vendor/upb/mini_descriptor/link.h b/vendor/upb/mini_descriptor/link.h deleted file mode 100644 index 66544cc..0000000 --- a/vendor/upb/mini_descriptor/link.h +++ /dev/null @@ -1,81 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// Functions for linking MiniTables together once they are built from a -// MiniDescriptor. -// -// These functions have names like upb_MiniTable_Link() because they operate on -// MiniTables. We put them here, rather than in the mini_table/ directory, -// because they are only needed when building MiniTables from MiniDescriptors. -// The interfaces in mini_table/ assume that MiniTables are immutable. - -#ifndef UPB_MINI_DESCRIPTOR_LINK_H_ -#define UPB_MINI_DESCRIPTOR_LINK_H_ - -#include "upb/base/status.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Links a sub-message field to a MiniTable for that sub-message. If a -// sub-message field is not linked, it will be treated as an unknown field -// during parsing, and setting the field will not be allowed. It is possible -// to link the message field later, at which point it will no longer be treated -// as unknown. However there is no synchronization for this operation, which -// means parallel mutation requires external synchronization. -// Returns success/failure. -UPB_NODISCARD UPB_API bool upb_MiniTable_SetSubMessage( - upb_MiniTable* table, upb_MiniTableField* field, const upb_MiniTable* sub); - -// Links an enum field to a MiniTable for that enum. -// All enum fields must be linked prior to parsing. -// Returns success/failure. -UPB_NODISCARD UPB_API bool upb_MiniTable_SetSubEnum( - upb_MiniTable* table, upb_MiniTableField* field, - const upb_MiniTableEnum* sub); - -// Returns a list of fields that require linking at runtime, to connect the -// MiniTable to its sub-messages and sub-enums. The list of fields will be -// written to the `subs` array, which must have been allocated by the caller -// and must be large enough to hold a list of all fields in the message. -// -// The order of the fields returned by this function is significant: it matches -// the order expected by upb_MiniTable_Link() below. -// -// The return value packs the sub-message count and sub-enum count into a single -// integer like so: -// return (msg_count << 16) | enum_count; -UPB_API uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt, - const upb_MiniTableField** subs); - -// Links a message to its sub-messages and sub-enums. The caller must pass -// arrays of sub-tables and sub-enums, in the same length and order as is -// returned by upb_MiniTable_GetSubList() above. However, individual elements -// of the sub_tables may be NULL if those sub-messages were tree shaken. -// -// Returns false if either array is too short, or if any of the tables fails -// to link. -UPB_NODISCARD UPB_API bool upb_MiniTable_Link( - upb_MiniTable* mt, const upb_MiniTable** sub_tables, size_t sub_table_count, - const upb_MiniTableEnum** sub_enums, size_t sub_enum_count); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MINI_DESCRIPTOR_LINK_H_ diff --git a/vendor/upb/mini_table/BUILD b/vendor/upb/mini_table/BUILD deleted file mode 100644 index af01cd3..0000000 --- a/vendor/upb/mini_table/BUILD +++ /dev/null @@ -1,274 +0,0 @@ -# Copyright (c) 2009-2023, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_binary.bzl", "cc_binary") -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//bazel:proto_library.bzl", "proto_library") -load( - "//upb/bazel:copts.bzl", - "UPB_DEFAULT_COPTS", - "UPB_DEFAULT_CPPOPTS", - "UPB_DEFAULT_FEATURES", -) -load( - "//upb/bazel:upb_minitable_proto_library.bzl", - "upb_minitable_proto_library", -) -load( - "//upb/cmake:build_defs.bzl", - "staleness_test", -) - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "mini_table", - srcs = [ - "extension_registry.c", - "generated_registry.c", - "message.c", - ], - hdrs = [ - "enum.h", - "extension.h", - "extension_registry.h", - "field.h", - "file.h", - "generated_registry.h", - "message.h", - "sub.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - "//upb/base", - "//upb/hash", - "//upb/mem", - "//upb/port", - ], -) - -cc_library( - name = "debug_string", - srcs = [ - "debug_string.c", - ], - hdrs = [ - "debug_string.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//rust/upb:__pkg__", - "//upb:__pkg__", - "//upb:friends", - ], - deps = [ - ":internal", - ":mini_table", - "//upb/base", - "//upb/hash", - "//upb/mem", - "//upb/port", - ], -) - -cc_library( - name = "internal", - srcs = [ - "internal/message.c", - ], - hdrs = [ - "internal/enum.h", - "internal/extension.h", - "internal/field.h", - "internal/file.h", - "internal/generated_registry.h", - "internal/message.h", - "internal/size_log2.h", - "internal/sub.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/mem", - "//upb/message:types", - "//upb/port", - ], -) - -cc_library( - name = "compat", - srcs = [ - "compat.c", - ], - hdrs = [ - "compat.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":mini_table", - "//upb/base", - "//upb/hash", - "//upb/mem", - "//upb/port", - ], -) - -cc_test( - name = "compat_test", - srcs = ["compat_test.cc"], - deps = [ - ":compat", - "//upb/test:test_messages_proto2_upb_minitable", - "//upb/test:test_messages_proto3_upb_minitable", - "//upb/test:test_upb_proto", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "generated_registry_test", - srcs = ["generated_registry_test.cc"], - deps = [ - ":mini_table", - "//src/google/protobuf:descriptor_upb_minitable_proto", - "//upb/test:custom_options_upb_minitable_proto", - "//upb/test:editions_test_upb_minitable_proto", - "//upb/test:test_multiple_files_upb_minitable_proto", - "@abseil-cpp//absl/synchronization", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "generated_registry_empty_test", - srcs = ["generated_registry_empty_test.cc"], - linkstatic = 1, - deps = [ - ":generated_registry_empty_test_upb_minitable_proto", - ":mini_table", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -proto_library( - name = "generated_registry_empty_test_proto", - srcs = ["generated_registry_empty_test.proto"], -) - -upb_minitable_proto_library( - name = "generated_registry_empty_test_upb_minitable_proto", - deps = [":generated_registry_empty_test_proto"], -) - -proto_library( - name = "message_benchmark_proto", - testonly = 1, - srcs = ["message_benchmark.proto"], -) - -upb_minitable_proto_library( - name = "message_benchmark_upb_minitable_proto", - testonly = 1, - deps = [":message_benchmark_proto"], -) - -cc_binary( - name = "message_benchmark", - testonly = 1, - srcs = ["message_benchmark.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":compat", - ":message_benchmark_upb_minitable_proto", - ":mini_table", - "//upb/port", - "@abseil-cpp//absl/random", - "@google_benchmark//:benchmark_main", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -proto_library( - name = "debug_string_test_proto", - srcs = ["debug_string_test.proto"], -) - -upb_minitable_proto_library( - name = "debug_string_test_upb_minitable_proto", - deps = [":debug_string_test_proto"], -) - -cc_binary( - name = "debug_string_test_generate", - srcs = ["debug_string_test_generate.cc"], - deps = [ - ":debug_string", - ":debug_string_test_upb_minitable_proto", - ], -) - -genrule( - name = "debug_string_test_txt", - outs = ["generated/debug_string_test.txt"], - cmd = "$(location :debug_string_test_generate) > $@", - tools = [":debug_string_test_generate"], -) - -staleness_test( - name = "debug_string_staleness_test", - outs = ["debug_string_test.txt"], - generated_pattern = "generated/%s", - target_files = ["debug_string_test.txt"], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - ), - visibility = ["//upb:__pkg__"], -) - -filegroup( - name = "test_protos", - srcs = glob( - [ - "**/*test.proto", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/mini_table/compat.c b/vendor/upb/mini_table/compat.c deleted file mode 100644 index 50e86df..0000000 --- a/vendor/upb/mini_table/compat.c +++ /dev/null @@ -1,114 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_table/compat.h" - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -// Checks if source and target mini table fields are identical. -// -// If the field is a sub message and sub messages are identical we record -// the association in table. -// -// Hashing the source sub message mini table and it's equivalent in the table -// stops recursing when a cycle is detected and instead just checks if the -// destination table is equal. -static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, - const upb_MiniTable* dst, - upb_inttable* table, - upb_Arena** arena) { - if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) - return kUpb_MiniTableEquals_NotEqual; - bool marked_src = false; - for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { - const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); - const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( - dst, upb_MiniTableField_Number(src_field)); - - if (upb_MiniTableField_CType(src_field) != - upb_MiniTableField_CType(dst_field)) - return false; - if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) - return false; - if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) - return false; - if (src_field->presence != dst_field->presence) return false; - if (src_field->UPB_PRIVATE(submsg_ofs) != - dst_field->UPB_PRIVATE(submsg_ofs)) - return kUpb_MiniTableEquals_NotEqual; - - // Go no further if we are only checking for compatibility. - if (!table) continue; - - if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { - if (!*arena) { - *arena = upb_Arena_New(); - if (!upb_inttable_init(table, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } - } - if (!marked_src) { - marked_src = true; - upb_value val; - val.val = (uint64_t)dst; - if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } - } - const upb_MiniTable* sub_src = - upb_MiniTable_GetSubMessageTable(src_field); - const upb_MiniTable* sub_dst = - upb_MiniTable_GetSubMessageTable(dst_field); - if (sub_src != NULL) { - upb_value cmp; - if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { - // We already compared this src before. Check if same dst. - if (cmp.val != (uint64_t)sub_dst) { - return kUpb_MiniTableEquals_NotEqual; - } - } else { - // Recurse if not already visited. - upb_MiniTableEquals_Status s = - upb_deep_check(sub_src, sub_dst, table, arena); - if (s != kUpb_MiniTableEquals_Equal) { - return s; - } - } - } - } - } - return kUpb_MiniTableEquals_Equal; -} - -bool upb_MiniTable_Compatible(const upb_MiniTable* src, - const upb_MiniTable* dst) { - return upb_deep_check(src, dst, NULL, NULL); -} - -upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, - const upb_MiniTable* dst) { - // Arena allocated on demand for hash table. - upb_Arena* arena = NULL; - // Table to keep track of visited mini tables to guard against cycles. - upb_inttable table; - upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); - if (arena) { - upb_Arena_Free(arena); - } - return status; -} diff --git a/vendor/upb/mini_table/compat.h b/vendor/upb/mini_table/compat.h deleted file mode 100644 index fd1670d..0000000 --- a/vendor/upb/mini_table/compat.h +++ /dev/null @@ -1,45 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_COMPAT_H_ -#define UPB_MINI_TABLE_COMPAT_H_ - -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -// upb does not support mixing minitables from different sources but these -// functions are still used by some existing users so for now we make them -// available here. This may or may not change in the future so do not add -// them to new code. - -#ifdef __cplusplus -extern "C" { -#endif - -// Checks if memory layout of src is compatible with dst. -bool upb_MiniTable_Compatible(const upb_MiniTable* src, - const upb_MiniTable* dst); - -typedef enum { - kUpb_MiniTableEquals_NotEqual, - kUpb_MiniTableEquals_Equal, - kUpb_MiniTableEquals_OutOfMemory, -} upb_MiniTableEquals_Status; - -// Checks equality of mini tables originating from different language runtimes. -upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, - const upb_MiniTable* dst); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_COMPAT_H_ */ diff --git a/vendor/upb/mini_table/compat_test.cc b/vendor/upb/mini_table/compat_test.cc deleted file mode 100644 index 0a46060..0000000 --- a/vendor/upb/mini_table/compat_test.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* Test of mini table accessors. - * - * Messages are created and mutated using generated code, and then - * accessed through reflective APIs exposed through mini table accessors. - */ - -#include "upb/mini_table/compat.h" - -#include -#include "google/protobuf/test_messages_proto2.upb_minitable.h" -#include "google/protobuf/test_messages_proto3.upb_minitable.h" - -namespace { - -TEST(GeneratedCode, EqualsTestProto2) { - EXPECT_TRUE(upb_MiniTable_Equals( - &protobuf_0test_0messages__proto2__ProtoWithKeywords_msg_init, - &protobuf_0test_0messages__proto2__ProtoWithKeywords_msg_init)); -} - -TEST(GeneratedCode, EqualsTestProto3) { - EXPECT_TRUE(upb_MiniTable_Equals( - &protobuf_0test_0messages__proto3__TestAllTypesProto3_msg_init, - &protobuf_0test_0messages__proto3__TestAllTypesProto3_msg_init)); -} - -} // namespace diff --git a/vendor/upb/mini_table/debug_string.c b/vendor/upb/mini_table/debug_string.c deleted file mode 100644 index 6cc73d2..0000000 --- a/vendor/upb/mini_table/debug_string.c +++ /dev/null @@ -1,312 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_table/debug_string.h" - -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" -#include "upb/port/vsnprintf_compat.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - char* buf; - char* ptr; - char* end; - int overflow; - upb_Arena* arena; - int count; - - // This table maps from a pointer to a 64-bit integer. The lower 32 bits are - // a unique ID for the object. The upper 32 bits are a flag that is 0x1 - // if the object has already been printed. - upb_inttable inttable; -} upb_MiniTablePrinter; - -UPB_PRINTF(2, 3) -static void upb_MiniTablePrinter_Printf(upb_MiniTablePrinter* p, - const char* fmt, ...) { - size_t n; - size_t have = p->end - p->ptr; - va_list args; - - va_start(args, fmt); - n = _upb_vsnprintf(p->ptr, have, fmt, args); - va_end(args); - - if (UPB_LIKELY(have > n)) { - p->ptr += n; - } else { - p->ptr = UPB_PTRADD(p->ptr, have); - p->overflow += (n - have); - } -} - -static size_t upb_MiniTablePrinter_NullTerminate(upb_MiniTablePrinter* p, - size_t size) { - size_t ret = p->ptr - p->buf + p->overflow; - - if (size > 0) { - if (p->ptr == p->end) p->ptr--; - *p->ptr = '\0'; - } - - return ret; -} - -static int upb_MiniTablePrinter_InsertNext(upb_MiniTablePrinter* p, - const void* key, bool visited) { - uint64_t id = p->count++; - upb_inttable_insert(&p->inttable, (intptr_t)key, - upb_value_uint64(id | (visited ? 0x100000000 : 0)), - p->arena); - return id; -} - -// Returns the ID of the object referenced by key, but does *not* mark the -// object as visited. This is used for printing a reference to another object -// that may or may not have been printed yet. -static int upb_MiniTablePrinter_GetIdForRef(upb_MiniTablePrinter* p, - const void* key) { - upb_value v; - if (upb_inttable_lookup(&p->inttable, (intptr_t)key, &v)) { - return (int)upb_value_getuint64(v); - } - return upb_MiniTablePrinter_InsertNext(p, key, false); -} - -// Returns the ID of the object referenced by key, and marks the object as -// visited. This is used for printing the object itself. -static int upb_MiniTablePrinter_GetIdForEmit(upb_MiniTablePrinter* p, - const void* key) { - UPB_ASSERT(key); - upb_value v; - if (upb_inttable_lookup(&p->inttable, (intptr_t)key, &v)) { - uint64_t val = upb_value_getuint64(v); - if (val >> 32) return -1; - upb_inttable_replace(&p->inttable, (intptr_t)key, - upb_value_int64(val | 0x100000000)); - return (int)val; - } - return upb_MiniTablePrinter_InsertNext(p, key, true); -} - -static void upb_MiniTablePrinter_PrintEnum(upb_MiniTablePrinter* p, - const upb_MiniTableEnum* enum_) { - int id = upb_MiniTablePrinter_GetIdForEmit(p, enum_); - if (id < 0) return; - - upb_MiniTablePrinter_Printf(p, "MiniTableEnum#%d {\n", id); - upb_MiniTablePrinter_Printf(p, " .mask_limit = %d\n", - enum_->UPB_PRIVATE(mask_limit)); - upb_MiniTablePrinter_Printf(p, " .value_count = %d\n", - enum_->UPB_PRIVATE(value_count)); - upb_MiniTablePrinter_Printf(p, " .values = {\n"); - - for (uint32_t i = 0; i < enum_->UPB_PRIVATE(mask_limit); i++) { - if (!upb_MiniTableEnum_CheckValue(enum_, i)) continue; - upb_MiniTablePrinter_Printf(p, " %d,\n", (int)i); - } - - const uint32_t* start = - &enum_->UPB_PRIVATE(data)[enum_->UPB_PRIVATE(mask_limit) / 32]; - for (uint32_t i = 0; i < enum_->UPB_PRIVATE(value_count); i++) { - upb_MiniTablePrinter_Printf(p, " %d,\n", (int)start[i]); - } - - upb_MiniTablePrinter_Printf(p, " }\n"); - upb_MiniTablePrinter_Printf(p, "}\n\n"); -} - -static void upb_MiniTablePrinter_PrintField(upb_MiniTablePrinter* p, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field) { - upb_MiniTablePrinter_Printf(p, " MiniTableField {\n"); - upb_MiniTablePrinter_Printf(p, " .number = %d\n", - field->UPB_PRIVATE(number)); - upb_MiniTablePrinter_Printf(p, " .offset = %d\n", - field->UPB_PRIVATE(offset)); - upb_MiniTablePrinter_Printf(p, " .presence = %d", field->presence); - - if (field->presence > 0) { - upb_MiniTablePrinter_Printf(p, " (hasbit=%d)\n", field->presence); - } else if (field->presence < 0) { - upb_MiniTablePrinter_Printf(p, " (oneof_index=%d)\n", ~field->presence); - } else { - upb_MiniTablePrinter_Printf(p, " (no explicit presence)\n"); - } - - if (field->UPB_PRIVATE(submsg_ofs) != kUpb_NoSub) { - upb_MiniTablePrinter_Printf(p, " .submsg_ofs = %d\n", - field->UPB_PRIVATE(submsg_ofs)); - } - upb_MiniTablePrinter_Printf(p, " .type = %d\n", - field->UPB_PRIVATE(descriptortype)); - upb_MiniTablePrinter_Printf(p, " .mode = %02x (", - field->UPB_PRIVATE(mode)); - - switch (field->UPB_PRIVATE(mode) & kUpb_FieldMode_Mask) { - case kUpb_FieldMode_Scalar: - upb_MiniTablePrinter_Printf(p, "Scalar"); - break; - case kUpb_FieldMode_Array: - upb_MiniTablePrinter_Printf(p, "Array"); - break; - case kUpb_FieldMode_Map: - upb_MiniTablePrinter_Printf(p, "Map"); - break; - } - - switch (field->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift) { - case kUpb_FieldRep_1Byte: - upb_MiniTablePrinter_Printf(p, " | 1Byte"); - break; - case kUpb_FieldRep_4Byte: - upb_MiniTablePrinter_Printf(p, " | 4Byte"); - break; - case kUpb_FieldRep_8Byte: - upb_MiniTablePrinter_Printf(p, " | 8Byte"); - break; - case kUpb_FieldRep_StringView: - upb_MiniTablePrinter_Printf(p, " | StringView"); - break; - } - - if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsPacked) { - upb_MiniTablePrinter_Printf(p, " | Packed"); - } - if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) { - upb_MiniTablePrinter_Printf(p, " | Extension"); - } - if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate) { - upb_MiniTablePrinter_Printf(p, " | Alternate"); - } - - upb_MiniTablePrinter_Printf(p, ")\n"); - - if (field->UPB_PRIVATE(submsg_ofs) != kUpb_NoSub) { - if (upb_MiniTableField_CType(field) == kUpb_CType_Message) { - int id = - upb_MiniTablePrinter_GetIdForRef(p, upb_MiniTable_SubMessage(field)); - upb_MiniTablePrinter_Printf(p, " .submsg = MiniTable#%d\n", id); - } else { - int id = upb_MiniTablePrinter_GetIdForRef( - p, upb_MiniTable_GetSubEnumTable(field)); - upb_MiniTablePrinter_Printf(p, " .subenum = MiniTableEnum#%d\n", id); - } - } - - upb_MiniTablePrinter_Printf(p, " },\n"); -} - -static void upb_MiniTablePrinter_PrintMessage(upb_MiniTablePrinter* p, - const upb_MiniTable* mini_table) { - int id = upb_MiniTablePrinter_GetIdForEmit(p, mini_table); - if (id < 0) return; - - upb_MiniTablePrinter_Printf(p, "MiniTable#%d {\n", id); - upb_MiniTablePrinter_Printf(p, " .size = %d\n", - mini_table->UPB_PRIVATE(size)); - upb_MiniTablePrinter_Printf(p, " .required_count = %d\n", - mini_table->UPB_PRIVATE(required_count)); - upb_MiniTablePrinter_Printf(p, " .table_mask = %02x\n", - mini_table->UPB_PRIVATE(table_mask)); - upb_MiniTablePrinter_Printf(p, " .dense_below = %d\n", - mini_table->UPB_PRIVATE(dense_below)); - - upb_MiniTablePrinter_Printf(p, " .ext = %02x (", - mini_table->UPB_PRIVATE(ext)); - switch (mini_table->UPB_PRIVATE(ext) & 3) { - case kUpb_ExtMode_NonExtendable: - upb_MiniTablePrinter_Printf(p, "NonExtendable"); - break; - case kUpb_ExtMode_Extendable: - upb_MiniTablePrinter_Printf(p, "Extendable"); - break; - case kUpb_ExtMode_IsMessageSet: - upb_MiniTablePrinter_Printf(p, "MessageSet"); - break; - case kUpb_ExtMode_IsMessageSet_ITEM: - upb_MiniTablePrinter_Printf(p, "MessageSetItem"); - break; - } - if (mini_table->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry) { - upb_MiniTablePrinter_Printf(p, " | MapEntry"); - } - upb_MiniTablePrinter_Printf(p, ")\n"); - upb_MiniTablePrinter_Printf(p, " .fields[%d] = {\n", - mini_table->UPB_PRIVATE(field_count)); - - for (int i = 0; i < mini_table->UPB_PRIVATE(field_count); i++) { - const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; - upb_MiniTablePrinter_PrintField(p, mini_table, field); - } - - upb_MiniTablePrinter_Printf(p, " }\n"); - - int mask = (int8_t)mini_table->UPB_PRIVATE(table_mask); - if (mask != -1) { - int size = (mask >> 3) + 1; - upb_MiniTablePrinter_Printf(p, " .fasttable[%d] = {\n", size); - - for (int i = 0; i < size; i++) { - const _upb_FastTable_Entry* entry = - &mini_table->UPB_PRIVATE(fasttable)[i]; - upb_MiniTablePrinter_Printf(p, " FastTableEntry {\n"); - upb_MiniTablePrinter_Printf(p, " .field_data = %016" PRIx64 ",\n", - entry->field_data); - upb_MiniTablePrinter_Printf(p, " .field_parser = %p\n", - entry->field_parser); - upb_MiniTablePrinter_Printf(p, " .field_number = %d\n", - (((int)entry->field_data >> 3) & 0xf) | - (((int)entry->field_data >> 4) & 0x7f0)); - upb_MiniTablePrinter_Printf(p, " }\n"); - } - - upb_MiniTablePrinter_Printf(p, " }\n"); - } - - upb_MiniTablePrinter_Printf(p, "}\n\n"); - - for (int i = 0; i < mini_table->UPB_PRIVATE(field_count); i++) { - const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; - if (field->UPB_PRIVATE(submsg_ofs) == kUpb_NoSub) continue; - if (upb_MiniTableField_CType(field) == kUpb_CType_Message) { - upb_MiniTablePrinter_PrintMessage(p, upb_MiniTable_SubMessage(field)); - } else { - upb_MiniTablePrinter_PrintEnum(p, upb_MiniTable_GetSubEnumTable(field)); - } - } -} - -size_t upb_MiniTable_DebugString(const upb_MiniTable* mini_table, char* buf, - size_t size) { - upb_MiniTablePrinter p = {buf, buf, buf + size, 0, upb_Arena_New(), 0}; - - if (!p.arena) return 0; - if (!upb_inttable_init(&p.inttable, p.arena)) return 0; - - upb_MiniTablePrinter_PrintMessage(&p, mini_table); - - upb_Arena_Free(p.arena); - - return upb_MiniTablePrinter_NullTerminate(&p, size); -} diff --git a/vendor/upb/mini_table/debug_string.h b/vendor/upb/mini_table/debug_string.h deleted file mode 100644 index d6f79a2..0000000 --- a/vendor/upb/mini_table/debug_string.h +++ /dev/null @@ -1,26 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_DEBUG_STRING_H_ -#define UPB_MINI_TABLE_DEBUG_STRING_H_ - -#include - -#include "upb/mini_table/message.h" - -#ifdef __cplusplus -extern "C" { -#endif - -size_t upb_MiniTable_DebugString(const upb_MiniTable* mini_table, char* buf, - size_t size); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // UPB_MINI_TABLE_DEBUG_STRING_H_ diff --git a/vendor/upb/mini_table/debug_string_test.proto b/vendor/upb/mini_table/debug_string_test.proto deleted file mode 100644 index 6541ff8..0000000 --- a/vendor/upb/mini_table/debug_string_test.proto +++ /dev/null @@ -1,54 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -edition = "2023"; - -package upb_test; - -enum OpenEnum { - OPEN_ENUM_UNSPECIFIED = 0; - OPEN_ENUM_FOO = 1; - OPEN_ENUM_BAR = 2; -} - -enum ClosedEnum { - option features.enum_type = CLOSED; - - CLOSED_ENUM_UNSPECIFIED = 0; - CLOSED_ENUM_FOO = 1; - CLOSED_ENUM_BAR = 2; -} - -message DebugStringTestMessage { - int32 int32_field = 1; - - // Different field modes. - repeated int64 packed_int64_field = 2; - repeated int64 repeated_int64_field = 3 - [features.repeated_field_encoding = EXPANDED]; - map map_field = 4; - - // Different field presence. - int32 required_field = 5 [features.field_presence = LEGACY_REQUIRED]; - int32 implicit_presence_field = 6 [features.field_presence = IMPLICIT]; - - // Different enum types. - ClosedEnum closed_enum_field = 7; - OpenEnum open_enum_field = 8; - - // Different UTF-8 validation types. - string utf8_validated_string_field = 9 [features.utf8_validation = VERIFY]; - string utf8_invalid_string_field = 10 [features.utf8_validation = NONE]; - - SubMessage sub_message_field = 11; - bool bool_field = 12; -} - -message SubMessage { - // Test that we can handle cyclic messages. - DebugStringTestMessage cycle_field = 1; -} diff --git a/vendor/upb/mini_table/debug_string_test.txt b/vendor/upb/mini_table/debug_string_test.txt deleted file mode 100644 index 59940a1..0000000 --- a/vendor/upb/mini_table/debug_string_test.txt +++ /dev/null @@ -1,154 +0,0 @@ -MiniTable#0 { - .size = 96 - .required_count = 1 - .table_mask = ff - .dense_below = 12 - .ext = 00 (NonExtendable) - .fields[12] = { - MiniTableField { - .number = 1 - .offset = 12 - .presence = 65 (hasbit=65) - .type = 5 - .mode = 42 (Scalar | 4Byte) - }, - MiniTableField { - .number = 2 - .offset = 64 - .presence = 0 (no explicit presence) - .type = 3 - .mode = c5 (Array | 8Byte | Packed) - }, - MiniTableField { - .number = 3 - .offset = 72 - .presence = 0 (no explicit presence) - .type = 3 - .mode = c1 (Array | 8Byte) - }, - MiniTableField { - .number = 4 - .offset = 80 - .presence = 0 (no explicit presence) - .submsg_ofs = 27 - .type = 11 - .mode = c0 (Map | 8Byte) - .submsg = MiniTable#1 - }, - MiniTableField { - .number = 5 - .offset = 16 - .presence = 64 (hasbit=64) - .type = 5 - .mode = 42 (Scalar | 4Byte) - }, - MiniTableField { - .number = 6 - .offset = 20 - .presence = 0 (no explicit presence) - .type = 5 - .mode = 42 (Scalar | 4Byte) - }, - MiniTableField { - .number = 7 - .offset = 24 - .presence = 66 (hasbit=66) - .submsg_ofs = 20 - .type = 14 - .mode = 42 (Scalar | 4Byte) - .subenum = MiniTableEnum#2 - }, - MiniTableField { - .number = 8 - .offset = 28 - .presence = 67 (hasbit=67) - .type = 5 - .mode = 52 (Scalar | 4Byte | Alternate) - }, - MiniTableField { - .number = 9 - .offset = 32 - .presence = 68 (hasbit=68) - .type = 9 - .mode = 82 (Scalar | StringView) - }, - MiniTableField { - .number = 10 - .offset = 48 - .presence = 69 (hasbit=69) - .type = 12 - .mode = 92 (Scalar | StringView | Alternate) - }, - MiniTableField { - .number = 11 - .offset = 88 - .presence = 70 (hasbit=70) - .submsg_ofs = 10 - .type = 11 - .mode = c2 (Scalar | 8Byte) - .submsg = MiniTable#3 - }, - MiniTableField { - .number = 12 - .offset = 9 - .presence = 71 (hasbit=71) - .type = 8 - .mode = 02 (Scalar | 1Byte) - }, - } -} - -MiniTable#1 { - .size = 48 - .required_count = 0 - .table_mask = ff - .dense_below = 2 - .ext = 00 (NonExtendable) - .fields[2] = { - MiniTableField { - .number = 1 - .offset = 16 - .presence = 64 (hasbit=64) - .type = 13 - .mode = 42 (Scalar | 4Byte) - }, - MiniTableField { - .number = 2 - .offset = 32 - .presence = 65 (hasbit=65) - .type = 13 - .mode = 42 (Scalar | 4Byte) - }, - } -} - -MiniTableEnum#2 { - .mask_limit = 64 - .value_count = 0 - .values = { - 0, - 1, - 2, - } -} - -MiniTable#3 { - .size = 24 - .required_count = 0 - .table_mask = ff - .dense_below = 1 - .ext = 00 (NonExtendable) - .fields[1] = { - MiniTableField { - .number = 1 - .offset = 16 - .presence = 64 (hasbit=64) - .submsg_ofs = 4 - .type = 11 - .mode = c2 (Scalar | 8Byte) - .submsg = MiniTable#0 - }, - } -} - - diff --git a/vendor/upb/mini_table/debug_string_test_generate.cc b/vendor/upb/mini_table/debug_string_test_generate.cc deleted file mode 100644 index a697364..0000000 --- a/vendor/upb/mini_table/debug_string_test_generate.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include - -#include "upb/mini_table/debug_string.h" -#include "upb/mini_table/debug_string_test.upb_minitable.h" - -int main(int argc, char** argv) { - char buf[65536]; - upb_MiniTable_DebugString(&upb_0test__DebugStringTestMessage_msg_init, buf, - sizeof(buf)); - puts(buf); - return 0; -} diff --git a/vendor/upb/mini_table/enum.h b/vendor/upb/mini_table/enum.h deleted file mode 100644 index b6be19f..0000000 --- a/vendor/upb/mini_table/enum.h +++ /dev/null @@ -1,34 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - -#include "upb/mini_table/internal/enum.h" - -// Must be last -#include "upb/port/def.inc" - -typedef struct upb_MiniTableEnum upb_MiniTableEnum; - -#ifdef __cplusplus -extern "C" { -#endif - -// Validates enum value against range defined by enum mini table. -UPB_API_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_ENUM_H_ */ diff --git a/vendor/upb/mini_table/extension.h b/vendor/upb/mini_table/extension.h deleted file mode 100644 index f7656ad..0000000 --- a/vendor/upb/mini_table/extension.h +++ /dev/null @@ -1,58 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_EXTENSION_H_ -#define UPB_MINI_TABLE_EXTENSION_H_ - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/extension.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_MiniTableExtension upb_MiniTableExtension; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType -upb_MiniTableExtension_CType(const upb_MiniTableExtension* e); - -UPB_API_INLINE uint32_t -upb_MiniTableExtension_Number(const upb_MiniTableExtension* e); - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_Extendee( - const upb_MiniTableExtension* e); - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( - const upb_MiniTableExtension* e); - -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableExtension_GetSubEnum( - const upb_MiniTableExtension* e); - -UPB_API_INLINE bool upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const upb_MiniTable* m); - -UPB_API_INLINE bool upb_MiniTableExtension_SetSubEnum( - upb_MiniTableExtension* e, const upb_MiniTableEnum* m); - -UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_ToField( - const upb_MiniTableExtension* e); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ diff --git a/vendor/upb/mini_table/extension_registry.c b/vendor/upb/mini_table/extension_registry.c deleted file mode 100644 index 6d4acb1..0000000 --- a/vendor/upb/mini_table/extension_registry.c +++ /dev/null @@ -1,90 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_table/extension_registry.h" - -#include -#include -#include - -#include "upb/hash/ext_table.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_ExtensionRegistry { - upb_exttable exts; - upb_Arena* arena; -}; - -upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { - upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); - if (!r) return NULL; - r->arena = arena; - if (!upb_exttable_init(&r->exts, 8, arena)) return NULL; - return r; -} - -UPB_API upb_ExtensionRegistryStatus upb_ExtensionRegistry_Add( - upb_ExtensionRegistry* r, const upb_MiniTableExtension* e) { - UPB_STATIC_ASSERT( - offsetof(upb_MiniTableExtension, - UPB_PRIVATE(field).UPB_PRIVATE(number)) == 0, - "Extension must be first-member-of-struct convertable with uint32_t"); - uint32_t fieldnum = upb_MiniTableExtension_Number(e); - const upb_MiniTable* extendee = upb_MiniTableExtension_Extendee(e); - - const uint32_t kMaxFieldNumber = (1 << 29) - 1; - if (fieldnum == 0 || - (fieldnum > kMaxFieldNumber && !upb_MiniTable_IsMessageSet(extendee))) { - return kUpb_ExtensionRegistryStatus_InvalidExtension; - } - - if (upb_exttable_lookup(&r->exts, extendee, fieldnum) != NULL) { - return kUpb_ExtensionRegistryStatus_DuplicateEntry; - } - - if (!upb_exttable_insert(&r->exts, extendee, (const uint32_t*)e, r->arena)) { - return kUpb_ExtensionRegistryStatus_OutOfMemory; - } - return kUpb_ExtensionRegistryStatus_Ok; -} - -upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray( - upb_ExtensionRegistry* r, const upb_MiniTableExtension** e, size_t count) { - const upb_MiniTableExtension** start = e; - const upb_MiniTableExtension** end = UPB_PTRADD(e, count); - upb_ExtensionRegistryStatus status = kUpb_ExtensionRegistryStatus_Ok; - for (; e < end; e++) { - status = upb_ExtensionRegistry_Add(r, *e); - if (status != kUpb_ExtensionRegistryStatus_Ok) goto failure; - } - return kUpb_ExtensionRegistryStatus_Ok; - -failure: - // Back out the entries previously added. - for (end = e, e = start; e < end; e++) { - const upb_MiniTableExtension* ext = *e; - upb_exttable_remove(&r->exts, upb_MiniTableExtension_Extendee(ext), - upb_MiniTableExtension_Number(ext)); - } - UPB_ASSERT(status != kUpb_ExtensionRegistryStatus_Ok); - return status; -} - -const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { - const uint32_t* v = upb_exttable_lookup(&r->exts, t, num); - return (const upb_MiniTableExtension*)v; -} - -size_t upb_ExtensionRegistry_Size(const upb_ExtensionRegistry* r) { - return upb_exttable_size(&r->exts); -} diff --git a/vendor/upb/mini_table/extension_registry.h b/vendor/upb/mini_table/extension_registry.h deleted file mode 100644 index 58e3f26..0000000 --- a/vendor/upb/mini_table/extension_registry.h +++ /dev/null @@ -1,99 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ -#define UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Extension registry: a dynamic data structure that stores a map of: - * (upb_MiniTable, number) -> extension info - * - * upb_decode() uses upb_ExtensionRegistry to look up extensions while parsing - * binary format. - * - * upb_ExtensionRegistry is part of the mini-table (msglayout) family of - * objects. Like all mini-table objects, it is suitable for reflection-less - * builds that do not want to expose names into the binary. - * - * Unlike most mini-table types, upb_ExtensionRegistry requires dynamic memory - * allocation and dynamic initialization: - * * If reflection is being used, then upb_DefPool will construct an appropriate - * upb_ExtensionRegistry automatically. - * * For a mini-table only build, the user must manually construct the - * upb_ExtensionRegistry and populate it with all of the extensions the user - * cares about. - * * A third alternative is to manually unpack relevant extensions after the - * main parse is complete, similar to how Any works. This is perhaps the - * nicest solution from the perspective of reducing dependencies, avoiding - * dynamic memory allocation, and avoiding the need to parse uninteresting - * extensions. The downsides are: - * (1) parse errors are not caught during the main parse - * (2) the CPU hit of parsing comes during access, which could cause an - * undesirable stutter in application performance. - * - * Users cannot directly get or put into this map. Users can only add the - * extensions from a generated module and pass the extension registry to the - * binary decoder. - * - * A upb_DefPool provides a upb_ExtensionRegistry, so any users who use - * reflection do not need to populate a upb_ExtensionRegistry directly. - */ - -typedef struct upb_ExtensionRegistry upb_ExtensionRegistry; - -// LINT.IfChange -typedef enum { - kUpb_ExtensionRegistryStatus_Ok = 0, - kUpb_ExtensionRegistryStatus_DuplicateEntry = 1, - kUpb_ExtensionRegistryStatus_OutOfMemory = 2, - kUpb_ExtensionRegistryStatus_InvalidExtension = 3, -} upb_ExtensionRegistryStatus; -// LINT.ThenChange(//depot/google3/third_party/upb/rust/sys/mini_table/extension_registry.rs) - -// Creates a upb_ExtensionRegistry in the given arena. -// The arena must outlive any use of the extreg. -UPB_NODISCARD UPB_API upb_ExtensionRegistry* upb_ExtensionRegistry_New( - upb_Arena* arena); - -UPB_NODISCARD UPB_API upb_ExtensionRegistryStatus upb_ExtensionRegistry_Add( - upb_ExtensionRegistry* r, const upb_MiniTableExtension* e); - -// Adds the given extension info for the array |e| of size |count| into the -// registry. If there are any errors, the entire array is backed out. -// The extensions must outlive the registry. -// Possible errors include OOM or an extension number that already exists. -UPB_NODISCARD upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray( - upb_ExtensionRegistry* r, const upb_MiniTableExtension** e, size_t count); - -// Looks up the extension (if any) defined for message type |t| and field -// number |num|. Returns the extension if found, otherwise NULL. -UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num); - -// Returns the number of extensions in the registry. For testing/debugging only. -UPB_API size_t upb_ExtensionRegistry_Size(const upb_ExtensionRegistry* r); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ */ diff --git a/vendor/upb/mini_table/field.h b/vendor/upb/mini_table/field.h deleted file mode 100644 index dcf9ed3..0000000 --- a/vendor/upb/mini_table/field.h +++ /dev/null @@ -1,58 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mini_table/internal/field.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_MiniTableField upb_MiniTableField; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_HasPresence(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsExtension(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f); - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f); - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f); - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ diff --git a/vendor/upb/mini_table/file.h b/vendor/upb/mini_table/file.h deleted file mode 100644 index 07e844a..0000000 --- a/vendor/upb/mini_table/file.h +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_FILE_H_ -#define UPB_MINI_TABLE_FILE_H_ - -#include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/internal/file.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_MiniTableFile upb_MiniTableFile; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableFile_Enum( - const upb_MiniTableFile* f, int i); - -UPB_API_INLINE int upb_MiniTableFile_EnumCount(const upb_MiniTableFile* f); - -UPB_API_INLINE const upb_MiniTableExtension* upb_MiniTableFile_Extension( - const upb_MiniTableFile* f, int i); - -UPB_API_INLINE int upb_MiniTableFile_ExtensionCount(const upb_MiniTableFile* f); - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableFile_Message( - const upb_MiniTableFile* f, int i); - -UPB_API_INLINE int upb_MiniTableFile_MessageCount(const upb_MiniTableFile* f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_FILE_H_ */ diff --git a/vendor/upb/mini_table/generated_registry.c b/vendor/upb/mini_table/generated_registry.c deleted file mode 100644 index c2bae80..0000000 --- a/vendor/upb/mini_table/generated_registry.c +++ /dev/null @@ -1,180 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_table/generated_registry.h" - -#include -#include - -#include "upb/mem/alloc.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/internal/generated_registry.h" // IWYU pragma: keep -#include "upb/port/atomic.h" - -// Must be last. -#include "upb/port/def.inc" - -#if UPB_TSAN -#include -#endif // UPB_TSAN - -const UPB_PRIVATE(upb_GeneratedExtensionListEntry) * - UPB_PRIVATE(upb_generated_extension_list) = NULL; - -typedef struct upb_GeneratedRegistry { - UPB_ATOMIC(upb_GeneratedRegistryRef*) ref; - UPB_ATOMIC(int32_t) ref_count; -} upb_GeneratedRegistry; - -static upb_GeneratedRegistry* _upb_generated_registry(void) { - static upb_GeneratedRegistry r = {NULL, 0}; - return &r; -} - -static bool _upb_GeneratedRegistry_AddAllLinkedExtensions( - upb_ExtensionRegistry* r) { - const UPB_PRIVATE(upb_GeneratedExtensionListEntry)* entry = - UPB_PRIVATE(upb_generated_extension_list); - while (entry != NULL) { - const upb_MiniTableExtension** current = entry->start; - for (current = entry->start; current != entry->stop; ++current) { - const upb_MiniTableExtension* ext = *current; - // Sentinels and padding introduced by the linker can result in zeroed - // entries, so simply skip them. - if (*current == NULL) { - // MSVC introduces padding that might not be sized exactly the same as - // the linker array element, but it should be properly aligned, so just - // skipping empty elements should be safe. (If the size and align of - // the array elements was different, we'd have to do something more - // complicated). - continue; - } - - if (upb_ExtensionRegistry_Add(r, ext) != - kUpb_ExtensionRegistryStatus_Ok) { - return false; - } - } - entry = entry->next; - } - return true; -} - -// Constructs a new GeneratedRegistryRef, adding all linked extensions to the -// registry or returning NULL on failure. -static upb_GeneratedRegistryRef* _upb_GeneratedRegistry_New(void) { - upb_Arena* arena = NULL; - upb_ExtensionRegistry* extreg = NULL; - upb_GeneratedRegistryRef* ref = upb_gmalloc(sizeof(upb_GeneratedRegistryRef)); - if (ref == NULL) goto err; - arena = upb_Arena_New(); - if (arena == NULL) goto err; - extreg = upb_ExtensionRegistry_New(arena); - if (extreg == NULL) goto err; - - ref->UPB_PRIVATE(arena) = arena; - ref->UPB_PRIVATE(registry) = extreg; - - if (!_upb_GeneratedRegistry_AddAllLinkedExtensions(extreg)) goto err; - - return ref; - -err: - if (arena != NULL) upb_Arena_Free(arena); - if (ref != NULL) upb_gfree(ref); - return NULL; -} - -const upb_GeneratedRegistryRef* upb_GeneratedRegistry_Load(void) { - upb_GeneratedRegistry* registry = _upb_generated_registry(); - - // Loop until we successfully acquire a reference. This loop should only - // kick in under extremely high contention, and it should be guaranteed to - // succeed. - while (true) { - int32_t count = upb_Atomic_Load(®istry->ref_count, memory_order_acquire); - - // Try to increment the refcount, but only if it's not zero. - while (count > 0) { - if (upb_Atomic_CompareExchangeStrong(®istry->ref_count, &count, - count + 1, memory_order_acquire, - memory_order_relaxed)) { - // Successfully incremented. We can now safely load and return the - // pointer. - const upb_GeneratedRegistryRef* ref = - upb_Atomic_Load(®istry->ref, memory_order_acquire); - UPB_ASSERT(ref != NULL); - return ref; - } - // CAS failed, `count` was updated. Loop will retry. - } - - // If we're here, the count was 0. Time for the slow path. - // Double-check that the pointer is NULL before trying to create. - upb_GeneratedRegistryRef* ref = - upb_Atomic_Load(®istry->ref, memory_order_acquire); - if (ref == NULL) { - // Pointer is NULL, try to create and publish a new registry. - upb_GeneratedRegistryRef* new_ref = _upb_GeneratedRegistry_New(); - if (new_ref == NULL) return NULL; // OOM - - // Try to CAS the pointer from NULL to our new_ref. - if (upb_Atomic_CompareExchangeStrong(®istry->ref, &ref, new_ref, - memory_order_release, - memory_order_acquire)) { - // We won the race. Set the ref count to 1. - upb_Atomic_Store(®istry->ref_count, 1, memory_order_release); - return new_ref; - } else { - // We lost the race. `ref` now holds the pointer from the winning - // thread. Clean up our unused one and loop to try again to get a - // reference. - upb_Arena_Free(new_ref->UPB_PRIVATE(arena)); - upb_gfree(new_ref); - } - } - // If we are here, either we lost the CAS race, or the pointer was already - // non-NULL. In either case, we loop to the top and try to increment the - // refcount of the existing object. - -#if UPB_TSAN - // Yield to give other threads a chance to increment the refcount. This is - // especially an issue for TSAN builds, which are prone to locking up from - // the thread with the upb_Atomic_Store call above getting starved. - sched_yield(); -#endif // UPB_TSAN - } -} - -void upb_GeneratedRegistry_Release(const upb_GeneratedRegistryRef* r) { - if (r == NULL) return; - - upb_GeneratedRegistry* registry = _upb_generated_registry(); - - int ref_count = upb_Atomic_Sub(®istry->ref_count, 1, memory_order_acq_rel); - UPB_ASSERT(registry->ref_count >= 0); - - // A ref_count of 1 means that we decremented the refcount to 0. - if (ref_count == 1) { - upb_GeneratedRegistryRef* ref = - upb_Atomic_Exchange(®istry->ref, NULL, memory_order_acq_rel); - if (ref != NULL) { - // This is the last reference and we won any potential race to store NULL, - // so we need to clean up. - upb_Arena_Free(ref->UPB_PRIVATE(arena)); - upb_gfree(ref); - } - } -} - -const upb_ExtensionRegistry* upb_GeneratedRegistry_Get( - const upb_GeneratedRegistryRef* r) { - if (r == NULL) return NULL; - return r->UPB_PRIVATE(registry); -} diff --git a/vendor/upb/mini_table/generated_registry.h b/vendor/upb/mini_table/generated_registry.h deleted file mode 100644 index cc44407..0000000 --- a/vendor/upb/mini_table/generated_registry.h +++ /dev/null @@ -1,66 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_GENERATED_REGISTRY_H_ -#define UPB_MINI_TABLE_GENERATED_REGISTRY_H_ - -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/internal/generated_registry.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Generated registry: a global singleton that gathers all extensions linked - * into the binary. - * - * This singleton is thread-safe and lock-free, implemented using atomics. The - * registry is lazily initialized the first time it is loaded. When all - * references are released, the registry will be destroyed. New loads - * afterwards will simply reload the same registry as needed. - * - * The extension minitables are registered in gencode using linker arrays. Each - * .proto file produces a weak, hidden, constructor function that adds all - * visible extensions from the array into the registry. In each binary, only - * one copy of the constructor will actually be preserved by the linker, and - * that copy will add all of the extensions for the entire binary. All of these - * are added to a global linked list of minitables pre-main, which are then used - * to construct this singleton as needed. - */ - -typedef struct upb_GeneratedRegistryRef upb_GeneratedRegistryRef; - -// Loads the generated registry, returning a reference to it. The reference -// must be held for the lifetime of any ExtensionRegistry obtained from it. -// -// Returns NULL on failure. -UPB_API const upb_GeneratedRegistryRef* upb_GeneratedRegistry_Load(void); - -// Releases a reference to the generated registry. This may destroy the -// registry if there are no other references to it. -// -// NULL is a valid argument and is simply ignored for easier error handling in -// callers. -UPB_API void upb_GeneratedRegistry_Release(const upb_GeneratedRegistryRef* r); - -// Returns the extension registry contained by a reference to the generated -// registry. -// -// The reference must be held for the lifetime of the registry. -UPB_API const upb_ExtensionRegistry* upb_GeneratedRegistry_Get( - const upb_GeneratedRegistryRef* r); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_MINI_TABLE_GENERATED_REGISTRY_H_ diff --git a/vendor/upb/mini_table/generated_registry_empty_test.cc b/vendor/upb/mini_table/generated_registry_empty_test.cc deleted file mode 100644 index 9bd4e1c..0000000 --- a/vendor/upb/mini_table/generated_registry_empty_test.cc +++ /dev/null @@ -1,45 +0,0 @@ - -#include -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/generated_registry.h" -#include "upb/mini_table/generated_registry_empty_test.upb_minitable.h" -#include "upb/mini_table/message.h" - -namespace { - -// Tests that we can instantiate the registry even if no extensions are linked. -// This ensures that the sentinel object in the linker array properly ensures -// that the encapsulation symbols are defined (eg. __start_linkarr_exts, -// __stop_linkarr_exts) even when no extensions were linked. -TEST(GeneratedRegistryEmptyTest, Instantiate) { - // Strongly reference the generated MiniTable to ensure that the TU for - // generated_registry_empty_test.upb_minitable.c is pulled in. - const upb_MiniTable* volatile table = - &upb_0test_0empty_0registry__EmptyRegistryTestMessage_msg_init; - (void)table; - - // Test that the registry can be loaded, even if no extensions are linked. - // If we did not have a sentinel in the linker array, we would get a linker - // error here like: - // - // ld: error: undefined symbol: __start_linkarr_upb_AllExts - // >>> referenced by generated_registry_empty_test.upb_minitable.c - // >>> - // generated_registry_empty_test.upb_minitable.pic.o:(upb_GeneratedRegistry_Constructor_dont_copy_me__upb_internal_use_only.entry) - // >>> the encapsulation symbol needs to be retained under --gc-sections - // properly; consider -z nostart-stop-gc (see - // https://lld.llvm.org/ELF/start-stop-gc) - // - // ld: error: undefined symbol: __stop_linkarr_upb_AllExts - // >>> referenced by generated_registry_empty_test.upb_minitable.c - // >>> - // generated_registry_empty_test.upb_minitable.pic.o:(upb_GeneratedRegistry_Constructor_dont_copy_me__upb_internal_use_only.entry) - const upb_GeneratedRegistryRef* ref = upb_GeneratedRegistry_Load(); - EXPECT_NE(ref, nullptr); - const upb_ExtensionRegistry* reg = upb_GeneratedRegistry_Get(ref); - EXPECT_NE(reg, nullptr); - - upb_GeneratedRegistry_Release(ref); -} - -} // namespace diff --git a/vendor/upb/mini_table/generated_registry_empty_test.proto b/vendor/upb/mini_table/generated_registry_empty_test.proto deleted file mode 100644 index bfa84b5..0000000 --- a/vendor/upb/mini_table/generated_registry_empty_test.proto +++ /dev/null @@ -1,15 +0,0 @@ -edition = "2024"; - -package upb_test_empty_registry; - -// A message that is in the same file as the unused extension. -message EmptyRegistryTestMessage { - extensions 1 to max; -} - -// An extension that we will *not* reference. The existence of this extension -// will cause us to emit the code to register all extensions, but since this -// extension is never referenced, that list of extensions will be empty. -extend EmptyRegistryTestMessage { - int32 unused_extension = 1; -} diff --git a/vendor/upb/mini_table/generated_registry_test.cc b/vendor/upb/mini_table/generated_registry_test.cc deleted file mode 100644 index 4a4d111..0000000 --- a/vendor/upb/mini_table/generated_registry_test.cc +++ /dev/null @@ -1,190 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_table/generated_registry.h" - -#include -#include // NOLINT -#include - -#include "google/protobuf/descriptor.upb_minitable.h" -#include -#include "absl/synchronization/barrier.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/test/custom_options.upb_minitable.h" -#include "upb/test/editions_test.upb_minitable.h" -#include "upb/test/test_multiple_files.upb_minitable.h" -#include "upb/test/test_multiple_files2.upb_minitable.h" - -namespace { - -class GeneratedRegistryTest : public ::testing::Test { - protected: - void SetUp() override { - ref_ = upb_GeneratedRegistry_Load(); - ASSERT_NE(ref_, nullptr); - reg_ = upb_GeneratedRegistry_Get(ref_); - ASSERT_NE(reg_, nullptr); - } - - void TearDown() override { upb_GeneratedRegistry_Release(ref_); } - - const upb_GeneratedRegistryRef* ref_ = nullptr; - const upb_ExtensionRegistry* reg_ = nullptr; -}; - -TEST_F(GeneratedRegistryTest, LocalExtensionExists) { - // Test an arbitrary extension defined in the same .proto file that we expect - // to be linked in. - - // Force linkage and sanity check extension numbers. - ASSERT_EQ(upb_MiniTableExtension_Number(upb_test_2023_ext_ext), 100); - - EXPECT_NE(upb_ExtensionRegistry_Lookup( - reg_, &upb__test_02023__EditionsMessage_msg_init, 100), - nullptr); -} - -TEST_F(GeneratedRegistryTest, ForeignExtensionExists) { - // Test an arbitrary extension defined by an import that we expect to be - // linked in. - - // Force linkage and sanity check extension numbers. - ASSERT_EQ(upb_MiniTableExtension_Number(upb_message_opt_ext), 7739036); - - EXPECT_NE(upb_ExtensionRegistry_Lookup(reg_, &google__protobuf__MessageOptions_msg_init, - 7739036), - nullptr); -} - -TEST_F(GeneratedRegistryTest, UnlinkedExtensionDoesNotExist) { - // Test an arbitrary extension defined by an option import that we do not - // expect to be linked in. - - // Corresponds to upb.message_opt_unlinked in custom_options_unlinked.proto. - EXPECT_EQ(upb_ExtensionRegistry_Lookup(reg_, &google__protobuf__MessageOptions_msg_init, - 7739037), - nullptr); -} - -TEST_F(GeneratedRegistryTest, MultipleFilesExtensionExists) { - // Test that multiple .proto files from the same proto_library can be linked - // in and registered. - - // Force linkage and sanity check extension numbers. - ASSERT_EQ(upb_MiniTableExtension_Number(upb_multiple_files_ext1_ext), 100); - ASSERT_EQ(upb_MiniTableExtension_Number(upb_multiple_files_ext2_ext), 100); - - EXPECT_NE(upb_ExtensionRegistry_Lookup( - reg_, &upb__MultipleFilesMessage1_msg_init, 100), - nullptr); - EXPECT_NE(upb_ExtensionRegistry_Lookup( - reg_, &upb__MultipleFilesMessage2_msg_init, 100), - nullptr); -} - -TEST_F(GeneratedRegistryTest, ReleaseOnError) { - upb_GeneratedRegistry_Release(nullptr); -} - -TEST_F(GeneratedRegistryTest, GetOnError) { - EXPECT_EQ(upb_GeneratedRegistry_Get(nullptr), nullptr); -} - -// On 32-bit systems, the stack size is smaller, so we can't run too many -// concurrent threads without overflowing the stack. -constexpr int kRaceIterations = sizeof(void*) < 8 ? 100 : 2000; - -TEST(GeneratedRegistryRaceTest, Load) { - absl::Barrier barrier(kRaceIterations); - std::vector threads; - std::array refs; - for (int i = 0; i < kRaceIterations; ++i) { - threads.push_back(std::thread([&, i]() { - barrier.Block(); - const upb_GeneratedRegistryRef* ref = upb_GeneratedRegistry_Load(); - EXPECT_NE(upb_GeneratedRegistry_Get(ref), nullptr); - refs[i] = ref; - })); - } - - for (auto& t : threads) t.join(); - - for (int i = 0; i < kRaceIterations; ++i) { - EXPECT_NE(refs[i], nullptr); - upb_GeneratedRegistry_Release(refs[i]); - } -} - -TEST(GeneratedRegistryRaceTest, Release) { - absl::Barrier barrier(kRaceIterations); - std::vector threads; - std::array refs; - - for (int i = 0; i < kRaceIterations; ++i) { - refs[i] = upb_GeneratedRegistry_Load(); - ASSERT_NE(refs[i], nullptr); - } - - for (int i = 0; i < kRaceIterations; ++i) { - threads.push_back(std::thread([&, i]() { - EXPECT_NE(upb_GeneratedRegistry_Get(refs[i]), nullptr); - barrier.Block(); - upb_GeneratedRegistry_Release(refs[i]); - })); - } - - for (auto& t : threads) t.join(); -} - -TEST(GeneratedRegistryRaceTest, LoadRelease) { - absl::Barrier barrier(kRaceIterations); - std::vector threads; - - for (int i = 0; i < kRaceIterations; ++i) { - threads.push_back(std::thread([&]() { - barrier.Block(); - const upb_GeneratedRegistryRef* ref = upb_GeneratedRegistry_Load(); - EXPECT_NE(upb_GeneratedRegistry_Get(ref), nullptr); - upb_GeneratedRegistry_Release(ref); - })); - } - - for (auto& t : threads) t.join(); -} - -TEST(GeneratedRegistryRaceTest, ReleaseLastAndLoadMultiple) { - for (int i = 0; i < kRaceIterations; ++i) { - // Load one reference. The registry is now alive with ref_count == 1. - const upb_GeneratedRegistryRef* ref = upb_GeneratedRegistry_Load(); - ASSERT_NE(ref, nullptr); - - constexpr int kNumLoaders = 4; - absl::Barrier barrier(kNumLoaders + 1); - std::vector threads; - - threads.push_back(std::thread([&]() { - barrier.Block(); - // This release should bring the ref_count to 0 and trigger cleanup. - upb_GeneratedRegistry_Release(ref); - })); - - for (int j = 0; j < kNumLoaders; ++j) { - threads.push_back(std::thread([&]() { - barrier.Block(); - const upb_GeneratedRegistryRef* ref2 = upb_GeneratedRegistry_Load(); - EXPECT_NE(upb_GeneratedRegistry_Get(ref2), nullptr); - upb_GeneratedRegistry_Release(ref2); - })); - } - - for (auto& t : threads) t.join(); - } -} - -} // namespace diff --git a/vendor/upb/mini_table/internal/enum.h b/vendor/upb/mini_table/internal/enum.h deleted file mode 100644 index 420116e..0000000 --- a/vendor/upb/mini_table/internal/enum.h +++ /dev/null @@ -1,57 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. -#include "upb/port/def.inc" - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE bool upb_MiniTableEnum_CheckValue( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1U << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ diff --git a/vendor/upb/mini_table/internal/extension.h b/vendor/upb/mini_table/internal/extension.h deleted file mode 100644 index c0cb8c4..0000000 --- a/vendor/upb/mini_table/internal/extension.h +++ /dev/null @@ -1,102 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ -#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/sub.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_MiniTableExtension { - // Do not move this field. We need to be able to alias pointers. - struct upb_MiniTableField UPB_PRIVATE(field); - - union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum - const struct upb_MiniTable* UPB_PRIVATE(extendee); -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType -upb_MiniTableExtension_CType(const struct upb_MiniTableExtension* e) { - return upb_MiniTableField_CType(&e->UPB_PRIVATE(field)); -} - -UPB_API_INLINE uint32_t -upb_MiniTableExtension_Number(const struct upb_MiniTableExtension* e) { - return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); -} - -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_Extendee( - const struct upb_MiniTableExtension* e) { - return e->UPB_PRIVATE(extendee); -} - -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage( - const struct upb_MiniTableExtension* e) { - if (upb_MiniTableExtension_CType(e) != kUpb_CType_Message) { - return NULL; - } - return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); -} - -UPB_API_INLINE const struct upb_MiniTableEnum* -upb_MiniTableExtension_GetSubEnum(const struct upb_MiniTableExtension* e) { - if (upb_MiniTableExtension_CType(e) != kUpb_CType_Enum) { - return NULL; - } - return upb_MiniTableSub_Enum(e->UPB_PRIVATE(sub)); -} - -UPB_API_INLINE bool upb_MiniTableExtension_SetSubMessage( - struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { - if (e->UPB_PRIVATE(field).UPB_PRIVATE(descriptortype) != - kUpb_FieldType_Message && - e->UPB_PRIVATE(field).UPB_PRIVATE(descriptortype) != - kUpb_FieldType_Group) { - return false; - } - e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; - return true; -} - -UPB_API_INLINE bool upb_MiniTableExtension_SetSubEnum( - struct upb_MiniTableExtension* e, const struct upb_MiniTableEnum* en) { - if (e->UPB_PRIVATE(field).UPB_PRIVATE(descriptortype) != - kUpb_FieldType_Enum) { - return false; - } - e->UPB_PRIVATE(sub).UPB_PRIVATE(subenum) = en; - return true; -} - -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTableExtension_ToField( - const struct upb_MiniTableExtension* e) { - return &e->UPB_PRIVATE(field); -} - -UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)( - const struct upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field)); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */ diff --git a/vendor/upb/mini_table/internal/field.h b/vendor/upb/mini_table/internal/field.h deleted file mode 100644 index 892e3fe..0000000 --- a/vendor/upb/mini_table/internal/field.h +++ /dev/null @@ -1,225 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ -#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mini_table/internal/size_log2.h" - -// Must be last. -#include "upb/port/def.inc" - -// LINT.IfChange(struct_definition) -struct upb_MiniTableField { - uint32_t UPB_ONLYBITS(number); - uint16_t UPB_ONLYBITS(offset); - int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index - - // Offset from this upb_MiniTableField to the upb_MiniTableSubInternal - // for this field, in uint32_t units (so bytes/4). - // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM - uint16_t UPB_PRIVATE(submsg_ofs); - - uint8_t UPB_PRIVATE(descriptortype); - - // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) - uint8_t UPB_ONLYBITS(mode); -}; - -#define kUpb_NoSub ((uint16_t)-1) -#define kUpb_SubmsgOffsetBytes 4 - -typedef enum { - kUpb_FieldMode_Map = 0, - kUpb_FieldMode_Array = 1, - kUpb_FieldMode_Scalar = 2, -} upb_FieldMode; - -// Mask to isolate the upb_FieldMode from field.mode. -#define kUpb_FieldMode_Mask 3 - -// Extra flags on the mode field. -typedef enum { - kUpb_LabelFlags_IsPacked = 4, - kUpb_LabelFlags_IsExtension = 8, - // Indicates that this descriptor type is an "alternate type": - // - for Int32, this indicates that the actual type is Enum (but was - // rewritten to Int32 because it is an open enum that requires no check). - // - for Bytes, this indicates that the actual type is String (but does - // not require any UTF-8 check). - kUpb_LabelFlags_IsAlternate = 16, -} upb_LabelFlags; - -// Note: we sort by this number when calculating layout order. -typedef enum { - kUpb_FieldRep_1Byte = 0, - kUpb_FieldRep_4Byte = 1, - kUpb_FieldRep_StringView = 2, - kUpb_FieldRep_8Byte = 3, - - kUpb_FieldRep_NativePointer = - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), - kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, -} upb_FieldRep; - -#define kUpb_FieldRep_Shift 6 - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { - return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); -} - -UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { - return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const struct upb_MiniTableField* f) { - const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); - if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { - if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; - if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; - UPB_ASSERT(false); - } - return type; -} - -UPB_API_INLINE -upb_CType upb_MiniTableField_CType(const struct upb_MiniTableField* f) { - return upb_FieldType_CType(upb_MiniTableField_Type(f)); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( - const struct upb_MiniTableField* f) { - return f->presence > 0; -} - -UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); - const uint16_t index = (uint16_t)f->presence; - return (char)(1 << (index % 8)); -} - -UPB_INLINE uint16_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); - const uint16_t index = (uint16_t)f->presence; - return index / 8; -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof( - const struct upb_MiniTableField* f) { - return f->presence < 0; -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || - f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const struct upb_MiniTableField* f) { - if (upb_MiniTableField_IsExtension(f)) { - return upb_MiniTableField_IsScalar(f); - } else { - return f->presence != 0; - } -} - -UPB_API_INLINE uint32_t -upb_MiniTableField_Number(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(number); -} - -UPB_INLINE uint16_t -UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(offset); -} - -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(upb_MiniTableField_IsInOneof(f)); - return (size_t)(~(ptrdiff_t)f->presence); -} - -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_MiniTableField_IsArray(f)); - UPB_ASSUME(f->presence == 0); -} - -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_MiniTableField_IsMap(f)); - UPB_ASSUME(f->presence == 0); -} - -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - const upb_FieldType field_type = upb_MiniTableField_Type(f); - return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); -} - -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ diff --git a/vendor/upb/mini_table/internal/file.h b/vendor/upb/mini_table/internal/file.h deleted file mode 100644 index 0e39ec4..0000000 --- a/vendor/upb/mini_table/internal/file.h +++ /dev/null @@ -1,66 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ -#define UPB_MINI_TABLE_INTERNAL_FILE_H_ - -// Must be last. -#include "upb/port/def.inc" - -struct upb_MiniTableFile { - const struct upb_MiniTable** UPB_PRIVATE(msgs); - const struct upb_MiniTableEnum** UPB_PRIVATE(enums); - const struct upb_MiniTableExtension** UPB_PRIVATE(exts); - int UPB_PRIVATE(msg_count); - int UPB_PRIVATE(enum_count); - int UPB_PRIVATE(ext_count); -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE int upb_MiniTableFile_EnumCount( - const struct upb_MiniTableFile* f) { - return f->UPB_PRIVATE(enum_count); -} - -UPB_API_INLINE int upb_MiniTableFile_ExtensionCount( - const struct upb_MiniTableFile* f) { - return f->UPB_PRIVATE(ext_count); -} - -UPB_API_INLINE int upb_MiniTableFile_MessageCount( - const struct upb_MiniTableFile* f) { - return f->UPB_PRIVATE(msg_count); -} - -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableFile_Enum( - const struct upb_MiniTableFile* f, int i) { - UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); - return f->UPB_PRIVATE(enums)[i]; -} - -UPB_API_INLINE const struct upb_MiniTableExtension* upb_MiniTableFile_Extension( - const struct upb_MiniTableFile* f, int i) { - UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); - return f->UPB_PRIVATE(exts)[i]; -} - -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableFile_Message( - const struct upb_MiniTableFile* f, int i) { - UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); - return f->UPB_PRIVATE(msgs)[i]; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_FILE_H_ */ diff --git a/vendor/upb/mini_table/internal/generated_registry.h b/vendor/upb/mini_table/internal/generated_registry.h deleted file mode 100644 index 7928b92..0000000 --- a/vendor/upb/mini_table/internal/generated_registry.h +++ /dev/null @@ -1,37 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_GENERATED_EXTENSION_REGISTRY_H_ -#define UPB_MINI_TABLE_INTERNAL_GENERATED_EXTENSION_REGISTRY_H_ - -#include "upb/mini_table/internal/extension.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct UPB_PRIVATE(upb_GeneratedExtensionListEntry) { - const struct upb_MiniTableExtension** start; - const struct upb_MiniTableExtension** stop; - const struct UPB_PRIVATE(upb_GeneratedExtensionListEntry) * next; -} UPB_PRIVATE(upb_GeneratedExtensionListEntry); - -struct upb_GeneratedRegistryRef { - struct upb_Arena* UPB_PRIVATE(arena); - const struct upb_ExtensionRegistry* UPB_PRIVATE(registry); -}; - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_GENERATED_EXTENSION_REGISTRY_H_ */ diff --git a/vendor/upb/mini_table/internal/message.c b/vendor/upb/mini_table/internal/message.c deleted file mode 100644 index 09f8c37..0000000 --- a/vendor/upb/mini_table/internal/message.c +++ /dev/null @@ -1,29 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_table/internal/message.h" - -#include - -#include "upb/message/internal/types.h" - -// Must be last. -#include "upb/port/def.inc" - -// A MiniTable for a statically tree shaken message. Messages that use this -// MiniTable are guaranteed to remain unlinked; unlike the empty message, this -// MiniTable is never replaced, which greatly simplifies everything, because the -// type of a sub-message is always known, without consulting a tagged bit. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_StaticallyTreeShaken) = { - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = sizeof(struct upb_Message), - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; diff --git a/vendor/upb/mini_table/internal/message.h b/vendor/upb/mini_table/internal/message.h deleted file mode 100644 index 15c1af4..0000000 --- a/vendor/upb/mini_table/internal/message.h +++ /dev/null @@ -1,344 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/sub.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_Decoder; -struct upb_Message; - -typedef UPB_PRESERVE_NONE const char* _upb_FieldParser( - struct upb_Decoder* d, const char* ptr, struct upb_Message* msg, - intptr_t table, uint64_t hasbits, uint64_t data); - -typedef struct { - uint64_t field_data; - _upb_FieldParser* field_parser; -} _upb_FastTable_Entry; - -typedef enum { - kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. - kUpb_ExtMode_Extendable = 1, // Normal extendable message. - kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. - kUpb_ExtMode_IsMessageSet_ITEM = - 3, // MessageSet item (temporary only, see decode.c) - - // During table building we steal a bit to indicate that the message is a map - // entry. *Only* used during table building! - kUpb_ExtMode_IsMapEntry = 4, -} upb_ExtMode; - -enum { - kUpb_Message_Align = 8, -}; - -// upb_MiniTable represents the memory layout of a given upb_MessageDef. -// The members are public so generated code can initialize them, -// but users MUST NOT directly read or write any of its members. - -// LINT.IfChange(minitable_struct_definition) -struct upb_MiniTable { - const struct upb_MiniTableField* UPB_ONLYBITS(fields); - - // Must be aligned to kUpb_Message_Align. Doesn't include internal members - // like unknown fields, extension dict, pointer to msglayout, etc. - uint16_t UPB_PRIVATE(size); - - uint16_t UPB_ONLYBITS(field_count); - - uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 - uint8_t UPB_PRIVATE(dense_below); - uint8_t UPB_PRIVATE(table_mask); - uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. - -#ifdef UPB_TRACING_ENABLED - const char* UPB_PRIVATE(full_name); -#endif - -#if UPB_FASTTABLE || !defined(__cplusplus) - // Flexible array member is not supported in C++, but it is an extension in - // every compiler that supports UPB_FASTTABLE. - _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; -#endif -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE void UPB_PRIVATE(upb_MiniTable_CheckInvariants)( - const struct upb_MiniTable* mt) { - UPB_STATIC_ASSERT(UPB_MALLOC_ALIGN >= kUpb_Message_Align, "Under aligned"); - UPB_STATIC_ASSERT(kUpb_Message_Align >= UPB_ALIGN_OF(void*), "Under aligned"); - UPB_ASSERT(mt->UPB_PRIVATE(size) % kUpb_Message_Align == 0); -} - -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_StrongReference)(const struct upb_MiniTable* mt) { -#if defined(__GNUC__) - __asm__("" : : "r"(mt)); -#else - const struct upb_MiniTable* volatile unused = mt; - (void)&unused; // Use address to avoid an extra load of "unused". -#endif - return mt; -} - -UPB_API_INLINE int upb_MiniTable_FieldCount(const struct upb_MiniTable* m) { - return m->UPB_ONLYBITS(field_count); -} - -UPB_API_INLINE bool upb_MiniTable_IsMessageSet(const struct upb_MiniTable* m) { - return m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet; -} - -UPB_FORCEINLINE -const struct upb_MiniTableField* UPB_PRIVATE(upb_MiniTable_LowerBound)( - const struct upb_MiniTable* m, uint32_t lo, uint32_t search_len, - uint32_t number) { - const struct upb_MiniTableField* search_base = &m->UPB_ONLYBITS(fields)[lo]; - while (search_len > 1) { - size_t mid_offset = search_len >> 1; - if (UPB_UNPREDICTABLE(search_base[mid_offset].UPB_ONLYBITS(number) <= - number)) { - search_base = &search_base[mid_offset]; - } - search_len -= mid_offset; - } - - return search_base; -} - -// This implements the same algorithm as upb_MiniTable_LowerBound but contorts -// itself to select specific arm instructions, which show significant effects on -// little cores. -UPB_FORCEINLINE const struct upb_MiniTableField* UPB_PRIVATE( - upb_MiniTable_ArmOptimizedLowerBound)(const struct upb_MiniTable* m, - uint32_t lo, uint32_t search_len, - uint32_t number) { - const uint32_t* search_base = - &m->UPB_ONLYBITS(fields)[lo].UPB_ONLYBITS(number); - UPB_STATIC_ASSERT(sizeof(struct upb_MiniTableField) == sizeof(uint32_t) * 3, - "Need to update multiplication"); - // Address generation units can't multiply by 12, but they can by 4. So we - // split it into multiplying by 3 (add and shift) and multiplying by 4 (shift) - // This code is carefully tuned to produce an optimal assembly sequence on - // arm64, which takes advantage of dual issue on in-order CPUs to maximize - // what little instruction level parallelism they have. - /* - and w9, w1, #0xfffffffe - add w9, w9, w1, lsr #1 - ldr w10, [x0, w9, uxtw #2] - sub w1, w1, w1, lsr #1 - add x9, x0, w9, uxtw #2 - cmp w10, w2 - csel x0, x0, x9, hi - cmp w1, #1 - b.hi .LBB3_1 - */ - // Doing this requires inhibiting the natural instincts of the compiler to - // eliminate duplicate work, so we introduce an optimization barrier with - // asm blocks to defeat common subexpression elimination. - UPB_STATIC_ASSERT( - offsetof(struct upb_MiniTableField, UPB_ONLYBITS(number)) == 0, - "Tag number must be first element of minitable field struct"); - while (search_len > 1) { -#if UPB_ARM64_ASM -#define UPB_OPT_LAUNDER(val) __asm__("" : "+r"(val)) -#define UPB_OPT_LAUNDER2(val1, val2) __asm__("" : "+r"(val1), "+r"(val2)) -#else -#define UPB_OPT_LAUNDER(val) -#define UPB_OPT_LAUNDER2(val1, val2) -#endif - // (search_len & ~1) is exactly (half_len * 2). Adding half_len yields - // (half_len * 3). - // - // and mid_offset_words, search_len, #0xfffffffe - uint32_t mid_offset_words = search_len & 0xfffffffe; - - // add mid_offset_words, mid_offset_words, search_len, lsr #1 - mid_offset_words = mid_offset_words + (search_len >> 1); - - UPB_OPT_LAUNDER(search_len); - UPB_OPT_LAUNDER(mid_offset_words); - - // Arm processors, even little cores, have Address Generation Units capable - // of performing these extensions, so we achieve more instruction level - // parallelism by doing this shift by 2 redundantly with the mid pointer - // calculation below. - // - // ldr mid_num, [search_base, mid_offset_words, uxtw #2] - uint32_t mid_num = search_base[mid_offset_words]; - - // Shrink the search window by half - // sub search_len, search_len, search_len, lsr #1 - search_len = search_len - (search_len >> 1); - UPB_OPT_LAUNDER(search_len); - UPB_OPT_LAUNDER(mid_offset_words); - - // Calculate the mid pointer for the next iteration - // add mid_ptr, search_base, mid_offset_words, uxtw #2 - const uint32_t* mid_ptr = search_base + mid_offset_words; - - // Forbids LLVM's CSE pass from attempting to merge mid_ptr and mid_num's - // math. It sees that it can do a select before adding, rather than after; - // but if it orders it that way it creates a longer dependency chain. We - // need both as input/output to the same asm block to force them to be - // present in different registers at the same time; two separate LAUNDER - // usages could get reordered. - UPB_OPT_LAUNDER2(mid_ptr, mid_num); - - // cmp + csel - search_base = UPB_UNPREDICTABLE(mid_num <= number) ? mid_ptr : search_base; - } -#undef UPB_OPT_LAUNDER -#undef UPB_OPT_LAUNDER2 - return (const struct upb_MiniTableField*)search_base; -} - -UPB_API_INLINE -const struct upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const struct upb_MiniTable* m, uint32_t number) { - const uint32_t i = number - 1; // 0 wraps to UINT32_MAX - - // Ideal case: index into dense fields - if (i < m->UPB_PRIVATE(dense_below)) { - UPB_ASSERT(m->UPB_ONLYBITS(fields)[i].UPB_ONLYBITS(number) == number); - return &m->UPB_ONLYBITS(fields)[i]; - } - - // Early exit if the field number is out of range. - uint32_t hi = m->UPB_ONLYBITS(field_count); - uint32_t lo = m->UPB_PRIVATE(dense_below); - UPB_ASSERT(hi >= lo); - uint32_t search_len = hi - lo; - if (search_len == 0 || - number > m->UPB_ONLYBITS(fields)[hi - 1].UPB_ONLYBITS(number)) { - return NULL; - } - - // Slow case: binary search - const struct upb_MiniTableField* candidate; -#ifndef NDEBUG - candidate = UPB_PRIVATE(upb_MiniTable_ArmOptimizedLowerBound)( - m, lo, search_len, number); - UPB_ASSERT(candidate == - UPB_PRIVATE(upb_MiniTable_LowerBound)(m, lo, search_len, number)); -#elif UPB_ARM64_ASM - candidate = UPB_PRIVATE(upb_MiniTable_ArmOptimizedLowerBound)( - m, lo, search_len, number); -#else - candidate = UPB_PRIVATE(upb_MiniTable_LowerBound)(m, lo, search_len, number); -#endif - - return candidate->UPB_ONLYBITS(number) == number ? candidate : NULL; -} - -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTable_GetFieldByIndex( - const struct upb_MiniTable* m, uint32_t i) { - UPB_ASSERT(i < m->UPB_ONLYBITS(field_count)); - return &m->UPB_ONLYBITS(fields)[i]; -} - -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTable_GetSubMessageTable( - const struct upb_MiniTableField* f) { - UPB_ASSERT(upb_MiniTableField_CType(f) == kUpb_CType_Message); - upb_MiniTableSubInternal* sub = - UPB_PTR_AT(f, f->UPB_PRIVATE(submsg_ofs) * kUpb_SubmsgOffsetBytes, - upb_MiniTableSubInternal); - return sub->UPB_PRIVATE(submsg); -} - -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTable_SubMessage( - const struct upb_MiniTableField* f) { - if (upb_MiniTableField_CType(f) != kUpb_CType_Message) { - return NULL; - } - return upb_MiniTable_GetSubMessageTable(f); -} - -UPB_API_INLINE bool upb_MiniTable_FieldIsLinked( - const struct upb_MiniTableField* f) { - return upb_MiniTable_GetSubMessageTable(f) != NULL; -} - -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTable_MapEntrySubMessage( - const struct upb_MiniTableField* f) { - UPB_ASSERT(upb_MiniTable_FieldIsLinked(f)); // Map entries must be linked. - UPB_ASSERT(upb_MiniTableField_IsMap(f)); // Function precondition. - return upb_MiniTable_GetSubMessageTable(f); -} - -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( - const struct upb_MiniTableField* f) { - UPB_ASSERT(upb_MiniTableField_CType(f) == kUpb_CType_Enum); - upb_MiniTableSubInternal* sub = - UPB_PTR_AT(f, f->UPB_PRIVATE(submsg_ofs) * kUpb_SubmsgOffsetBytes, - upb_MiniTableSubInternal); - return sub->UPB_PRIVATE(subenum); -} - -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTable_MapKey( - const struct upb_MiniTable* m) { - UPB_ASSERT(upb_MiniTable_FieldCount(m) == 2); - const struct upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, 0); - UPB_ASSERT(upb_MiniTableField_Number(f) == 1); - return f; -} - -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTable_MapValue( - const struct upb_MiniTable* m) { - UPB_ASSERT(upb_MiniTable_FieldCount(m) == 2); - const struct upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, 1); - UPB_ASSERT(upb_MiniTableField_Number(f) == 2); - return f; -} - -// Computes a bitmask in which the |m->required_count| lowest bits are set. -// -// Sample output: -// RequiredMask(1) => 0b1 (0x1) -// RequiredMask(5) => 0b11111 (0x1f) -UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { - int n = m->UPB_PRIVATE(required_count); - UPB_ASSERT(0 < n && n <= 64); - return (1ULL << n) - 1; -} - -#ifdef UPB_TRACING_ENABLED -UPB_INLINE const char* upb_MiniTable_FullName( - const struct upb_MiniTable* mini_table) { - return mini_table->UPB_PRIVATE(full_name); -} -// Initializes tracing proto name from language runtimes that construct -// mini tables dynamically at runtime. The runtime is responsible for passing -// controlling lifetime of name such as storing in same arena as mini_table. -UPB_INLINE void upb_MiniTable_SetFullName(struct upb_MiniTable* mini_table, - const char* full_name) { - mini_table->UPB_PRIVATE(full_name) = full_name; -} -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ diff --git a/vendor/upb/mini_table/internal/size_log2.h b/vendor/upb/mini_table/internal/size_log2.h deleted file mode 100644 index 67a8774..0000000 --- a/vendor/upb/mini_table/internal/size_log2.h +++ /dev/null @@ -1,78 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ -/// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ -#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ - -#include -#include - -#include "upb/base/descriptor_constants.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { - static const int8_t size[] = { - 0, // kUpb_CType_Bool - 2, // kUpb_CType_Float - 2, // kUpb_CType_Int32 - 2, // kUpb_CType_UInt32 - 2, // kUpb_CType_Enum - UPB_SIZE(2, 3), // kUpb_CType_Message - 3, // kUpb_CType_Double - 3, // kUpb_CType_Int64 - 3, // kUpb_CType_UInt64 - UPB_SIZE(3, 4), // kUpb_CType_String - UPB_SIZE(3, 4), // kUpb_CType_Bytes - }; - - // -1 here because the enum is one-based but the table is zero-based. - return size[c_type - 1]; -} - -// Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE size_t -UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { - static const int8_t size[] = { - 3, // kUpb_FieldType_Double - 2, // kUpb_FieldType_Float - 3, // kUpb_FieldType_Int64 - 3, // kUpb_FieldType_UInt64 - 2, // kUpb_FieldType_Int32 - 3, // kUpb_FieldType_Fixed64 - 2, // kUpb_FieldType_Fixed32 - 0, // kUpb_FieldType_Bool - UPB_SIZE(3, 4), // kUpb_FieldType_String - UPB_SIZE(2, 3), // kUpb_FieldType_Group - UPB_SIZE(2, 3), // kUpb_FieldType_Message - UPB_SIZE(3, 4), // kUpb_FieldType_Bytes - 2, // kUpb_FieldType_UInt32 - 2, // kUpb_FieldType_Enum - 2, // kUpb_FieldType_SFixed32 - 3, // kUpb_FieldType_SFixed64 - 2, // kUpb_FieldType_SInt32 - 3, // kUpb_FieldType_SInt64 - }; - - // -1 here because the enum is one-based but the table is zero-based. - return size[field_type - 1]; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ diff --git a/vendor/upb/mini_table/internal/sub.h b/vendor/upb/mini_table/internal/sub.h deleted file mode 100644 index 2263931..0000000 --- a/vendor/upb/mini_table/internal/sub.h +++ /dev/null @@ -1,55 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ -#define UPB_MINI_TABLE_INTERNAL_SUB_H_ - -// Must be last. -#include "upb/port/def.inc" - -union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); -}; - -typedef union upb_MiniTableSub upb_MiniTableSubInternal; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE union upb_MiniTableSub upb_MiniTableSub_FromEnum( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(subenum) = subenum; - return out; -} - -UPB_API_INLINE union upb_MiniTableSub upb_MiniTableSub_FromMessage( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(submsg) = submsg; - return out; -} - -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(subenum); -} - -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(submsg); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ diff --git a/vendor/upb/mini_table/message.c b/vendor/upb/mini_table/message.c deleted file mode 100644 index 29410b5..0000000 --- a/vendor/upb/mini_table/message.c +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/mini_table/message.h" - -#include -#include - -#include "upb/mini_table/field.h" - -// Must be last. -#include "upb/port/def.inc" - -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f) { - if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { - return NULL; - } - const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - for (; ptr < end; ptr++) { - if (ptr->presence == (*f).presence) { - return ptr; - } - } - return NULL; -} - -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f) { - const upb_MiniTableField* ptr = *f; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - while (++ptr < end) { - if (ptr->presence == (*f)->presence) { - *f = ptr; - return true; - } - } - return false; -} diff --git a/vendor/upb/mini_table/message.h b/vendor/upb/mini_table/message.h deleted file mode 100644 index df0626f..0000000 --- a/vendor/upb/mini_table/message.h +++ /dev/null @@ -1,120 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_MESSAGE_H_ -#define UPB_MINI_TABLE_MESSAGE_H_ - -#include - -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/message.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct upb_MiniTable upb_MiniTable; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number); - -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( - const upb_MiniTable* m, uint32_t index); - -UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m); - -UPB_API_INLINE bool upb_MiniTable_IsMessageSet(const upb_MiniTable* m); - -// DEPRECATED: use upb_MiniTable_SubMessage() instead -// Returns the MiniTable for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( - const upb_MiniTableField* f); - -// Returns the MiniTable for a message field if it is a submessage and the field -// is linked, otherwise returns NULL. -UPB_API_INLINE const upb_MiniTable* upb_MiniTable_SubMessage( - const upb_MiniTableField* f); - -// Returns the MiniTable for a map field. The given field must refer to a map. -UPB_API_INLINE const upb_MiniTable* upb_MiniTable_MapEntrySubMessage( - const upb_MiniTableField* f); - -// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTableField* f); - -// Returns the MiniTableField for the key of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( - const upb_MiniTable* m); - -// Returns the MiniTableField for the value of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( - const upb_MiniTable* m); - -// Returns true if this MiniTable field is linked to a MiniTable for the -// sub-message. -UPB_API_INLINE bool upb_MiniTable_FieldIsLinked(const upb_MiniTableField* f); - -// If this field is in a oneof, returns the first field in the oneof. -// -// Otherwise returns NULL. -// -// Usage: -// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); -// do { -// .. -// } while (upb_MiniTable_NextOneofField(m, &field); -// -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f); - -// Iterates to the next field in the oneof. If this is the last field in the -// oneof, returns false. The ordering of fields in the oneof is not -// guaranteed. -// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated -// by prior upb_MiniTable_NextOneofField calls. -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#ifdef __cplusplus -// Temporary overloads for functions whose signature has recently changed. -UPB_DEPRECATE_AND_INLINE() -inline const upb_MiniTable* upb_MiniTable_SubMessage( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return upb_MiniTable_SubMessage(f); -} - -UPB_DEPRECATE_AND_INLINE() -inline const upb_MiniTable* upb_MiniTable_GetSubMessageTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return upb_MiniTable_GetSubMessageTable(f); -} - -UPB_DEPRECATE_AND_INLINE() -inline const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return upb_MiniTable_GetSubEnumTable(f); -} - -UPB_DEPRECATE_AND_INLINE() -inline bool upb_MiniTable_FieldIsLinked(const upb_MiniTable* m, - const upb_MiniTableField* f) { - return upb_MiniTable_FieldIsLinked(f); -} -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ diff --git a/vendor/upb/mini_table/message_benchmark.cc b/vendor/upb/mini_table/message_benchmark.cc deleted file mode 100644 index 9426a37..0000000 --- a/vendor/upb/mini_table/message_benchmark.cc +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include - -#include -#include "absl/random/random.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/message_benchmark.upb_minitable.h" -#include "upb/port/def.inc" - -namespace { -static void BM_FindFieldByNumber(benchmark::State& state) { - uint32_t min, max; - switch (state.range(0)) { - case 0: - min = 1; - max = 169; - break; - case 1: - min = 171; - max = 552; - break; - default: - min = 100; // Some dense fields - max = 570; // some unknowns - break; - } - const upb_MiniTable* ptr = - &third_0party_0upb_0upb_0mini_0table__TestManyFields_msg_init; - std::seed_seq seq{1, 2, 3}; - benchmark::DoNotOptimize(seq); - absl::BitGen bitgen(seq); - uint32_t search[1024]; - for (auto& s : search) { - s = absl::Uniform(bitgen, min, max); - } - uint32_t i = 0; - for (auto _ : state) { - const upb_MiniTableField* field = - upb_MiniTable_FindFieldByNumber(ptr, search[(i++ % 1024)]); - if (field) { - uint16_t offset = field->UPB_PRIVATE(offset); - benchmark::DoNotOptimize(offset); - } - } -} -BENCHMARK(BM_FindFieldByNumber)->Arg(0)->Arg(1)->Arg(2); - -} // namespace diff --git a/vendor/upb/mini_table/message_benchmark.proto b/vendor/upb/mini_table/message_benchmark.proto deleted file mode 100644 index a09ef15..0000000 --- a/vendor/upb/mini_table/message_benchmark.proto +++ /dev/null @@ -1,562 +0,0 @@ -edition = "2023"; - -package third_party_upb_upb_mini_table; - -option java_multiple_files = true; - -message TestManyFields { - // Densely packed fields - repeated int32 repeated_int32 = 1; - repeated int32 repeated_int32_2 = 2; - repeated int32 repeated_int32_3 = 3; - repeated int32 repeated_int32_4 = 4; - repeated int32 repeated_int32_5 = 5; - repeated int32 repeated_int32_6 = 6; - repeated int32 repeated_int32_7 = 7; - repeated int32 repeated_int32_8 = 8; - repeated int32 repeated_int32_9 = 9; - repeated int32 repeated_int32_10 = 10; - repeated int32 repeated_int32_11 = 11; - repeated int32 repeated_int32_12 = 12; - repeated int32 repeated_int32_13 = 13; - repeated int32 repeated_int32_14 = 14; - repeated int32 repeated_int32_15 = 15; - repeated int32 repeated_int32_16 = 16; - repeated int32 repeated_int32_17 = 17; - repeated int32 repeated_int32_18 = 18; - repeated int32 repeated_int32_19 = 19; - repeated int32 repeated_int32_20 = 20; - repeated int32 repeated_int32_21 = 21; - repeated int32 repeated_int32_22 = 22; - repeated int32 repeated_int32_23 = 23; - repeated int32 repeated_int32_24 = 24; - repeated int32 repeated_int32_25 = 25; - repeated int32 repeated_int32_26 = 26; - repeated int32 repeated_int32_27 = 27; - repeated int32 repeated_int32_28 = 28; - repeated int32 repeated_int32_29 = 29; - repeated int32 repeated_int32_30 = 30; - repeated int32 repeated_int32_31 = 31; - repeated int32 repeated_int32_32 = 32; - repeated int32 repeated_int32_33 = 33; - repeated int32 repeated_int32_34 = 34; - repeated int32 repeated_int32_35 = 35; - repeated int32 repeated_int32_36 = 36; - repeated int32 repeated_int32_37 = 37; - repeated int32 repeated_int32_38 = 38; - repeated int32 repeated_int32_39 = 39; - repeated int32 repeated_int32_40 = 40; - repeated int32 repeated_int32_41 = 41; - repeated int32 repeated_int32_42 = 42; - repeated int32 repeated_int32_43 = 43; - repeated int32 repeated_int32_44 = 44; - repeated int32 repeated_int32_45 = 45; - repeated int32 repeated_int32_46 = 46; - repeated int32 repeated_int32_47 = 47; - repeated int32 repeated_int32_48 = 48; - repeated int32 repeated_int32_49 = 49; - repeated int32 repeated_int32_50 = 50; - repeated int32 repeated_int32_51 = 51; - repeated int32 repeated_int32_52 = 52; - repeated int32 repeated_int32_53 = 53; - repeated int32 repeated_int32_54 = 54; - repeated int32 repeated_int32_55 = 55; - repeated int32 repeated_int32_56 = 56; - repeated int32 repeated_int32_57 = 57; - repeated int32 repeated_int32_58 = 58; - repeated int32 repeated_int32_59 = 59; - repeated int32 repeated_int32_60 = 60; - repeated int32 repeated_int32_61 = 61; - repeated int32 repeated_int32_62 = 62; - repeated int32 repeated_int32_63 = 63; - repeated int32 repeated_int32_64 = 64; - repeated int32 repeated_int32_65 = 65; - repeated int32 repeated_int32_66 = 66; - repeated int32 repeated_int32_67 = 67; - repeated int32 repeated_int32_68 = 68; - repeated int32 repeated_int32_69 = 69; - repeated int32 repeated_int32_70 = 70; - repeated int32 repeated_int32_71 = 71; - repeated int32 repeated_int32_72 = 72; - repeated int32 repeated_int32_73 = 73; - repeated int32 repeated_int32_74 = 74; - repeated int32 repeated_int32_75 = 75; - repeated int32 repeated_int32_76 = 76; - repeated int32 repeated_int32_77 = 77; - repeated int32 repeated_int32_78 = 78; - repeated int32 repeated_int32_79 = 79; - repeated int32 repeated_int32_80 = 80; - repeated int32 repeated_int32_81 = 81; - repeated int32 repeated_int32_82 = 82; - repeated int32 repeated_int32_83 = 83; - repeated int32 repeated_int32_84 = 84; - repeated int32 repeated_int32_85 = 85; - repeated int32 repeated_int32_86 = 86; - repeated int32 repeated_int32_87 = 87; - repeated int32 repeated_int32_88 = 88; - repeated int32 repeated_int32_89 = 89; - repeated int32 repeated_int32_90 = 90; - repeated int32 repeated_int32_91 = 91; - repeated int32 repeated_int32_92 = 92; - repeated int32 repeated_int32_93 = 93; - repeated int32 repeated_int32_94 = 94; - repeated int32 repeated_int32_95 = 95; - repeated int32 repeated_int32_96 = 96; - repeated int32 repeated_int32_97 = 97; - repeated int32 repeated_int32_98 = 98; - repeated int32 repeated_int32_99 = 99; - repeated int32 repeated_int32_100 = 100; - repeated int32 repeated_int32_101 = 101; - repeated int32 repeated_int32_102 = 102; - repeated int32 repeated_int32_103 = 103; - repeated int32 repeated_int32_104 = 104; - repeated int32 repeated_int32_105 = 105; - repeated int32 repeated_int32_106 = 106; - repeated int32 repeated_int32_107 = 107; - repeated int32 repeated_int32_108 = 108; - repeated int32 repeated_int32_109 = 109; - repeated int32 repeated_int32_110 = 110; - repeated int32 repeated_int32_111 = 111; - repeated int32 repeated_int32_112 = 112; - repeated int32 repeated_int32_113 = 113; - repeated int32 repeated_int32_114 = 114; - repeated int32 repeated_int32_115 = 115; - repeated int32 repeated_int32_116 = 116; - repeated int32 repeated_int32_117 = 117; - repeated int32 repeated_int32_118 = 118; - repeated int32 repeated_int32_119 = 119; - repeated int32 repeated_int32_120 = 120; - repeated int32 repeated_int32_121 = 121; - repeated int32 repeated_int32_122 = 122; - repeated int32 repeated_int32_123 = 123; - repeated int32 repeated_int32_124 = 124; - repeated int32 repeated_int32_125 = 125; - repeated int32 repeated_int32_126 = 126; - repeated int32 repeated_int32_127 = 127; - repeated int32 repeated_int32_128 = 128; - repeated int32 repeated_int32_129 = 129; - repeated int32 repeated_int32_130 = 130; - repeated int32 repeated_int32_131 = 131; - repeated int32 repeated_int32_132 = 132; - repeated int32 repeated_int32_133 = 133; - repeated int32 repeated_int32_134 = 134; - repeated int32 repeated_int32_135 = 135; - repeated int32 repeated_int32_136 = 136; - repeated int32 repeated_int32_137 = 137; - repeated int32 repeated_int32_138 = 138; - repeated int32 repeated_int32_139 = 139; - repeated int32 repeated_int32_140 = 140; - repeated int32 repeated_int32_141 = 141; - repeated int32 repeated_int32_142 = 142; - repeated int32 repeated_int32_143 = 143; - repeated int32 repeated_int32_144 = 144; - repeated int32 repeated_int32_145 = 145; - repeated int32 repeated_int32_146 = 146; - repeated int32 repeated_int32_147 = 147; - repeated int32 repeated_int32_148 = 148; - repeated int32 repeated_int32_149 = 149; - repeated int32 repeated_int32_150 = 150; - repeated int32 repeated_int32_151 = 151; - repeated int32 repeated_int32_152 = 152; - repeated int32 repeated_int32_153 = 153; - repeated int32 repeated_int32_154 = 154; - repeated int32 repeated_int32_155 = 155; - repeated int32 repeated_int32_156 = 156; - repeated int32 repeated_int32_157 = 157; - repeated int32 repeated_int32_158 = 158; - repeated int32 repeated_int32_159 = 159; - repeated int32 repeated_int32_160 = 160; - repeated int32 repeated_int32_161 = 161; - repeated int32 repeated_int32_162 = 162; - repeated int32 repeated_int32_163 = 163; - repeated int32 repeated_int32_164 = 164; - repeated int32 repeated_int32_165 = 165; - repeated int32 repeated_int32_166 = 166; - repeated int32 repeated_int32_167 = 167; - repeated int32 repeated_int32_168 = 168; - repeated int32 repeated_int32_169 = 169; - // Break dense packing of fields - reserved 170; - int32 int32_field_171 = 171; - int32 int32_field_172 = 172; - int32 int32_field_173 = 173; - int32 int32_field_174 = 174; - int32 int32_field_175 = 175; - int32 int32_field_176 = 176; - int32 int32_field_177 = 177; - int32 int32_field_178 = 178; - int32 int32_field_179 = 179; - int32 int32_field_180 = 180; - int32 int32_field_181 = 181; - int32 int32_field_182 = 182; - int32 int32_field_183 = 183; - int32 int32_field_184 = 184; - int32 int32_field_185 = 185; - int32 int32_field_186 = 186; - int32 int32_field_187 = 187; - int32 int32_field_188 = 188; - int32 int32_field_189 = 189; - int32 int32_field_190 = 190; - int32 int32_field_191 = 191; - int32 int32_field_192 = 192; - int32 int32_field_193 = 193; - int32 int32_field_194 = 194; - int32 int32_field_195 = 195; - int32 int32_field_196 = 196; - int32 int32_field_197 = 197; - int32 int32_field_198 = 198; - int32 int32_field_199 = 199; - int32 int32_field_200 = 200; - int32 int32_field_201 = 201; - int32 int32_field_202 = 202; - int32 int32_field_203 = 203; - int32 int32_field_204 = 204; - int32 int32_field_205 = 205; - int32 int32_field_206 = 206; - int32 int32_field_207 = 207; - int32 int32_field_208 = 208; - int32 int32_field_209 = 209; - int32 int32_field_210 = 210; - int32 int32_field_211 = 211; - int32 int32_field_212 = 212; - int32 int32_field_213 = 213; - int32 int32_field_214 = 214; - int32 int32_field_215 = 215; - int32 int32_field_216 = 216; - int32 int32_field_217 = 217; - int32 int32_field_218 = 218; - int32 int32_field_219 = 219; - int32 int32_field_220 = 220; - int32 int32_field_221 = 221; - int32 int32_field_222 = 222; - int32 int32_field_223 = 223; - int32 int32_field_224 = 224; - int32 int32_field_225 = 225; - int32 int32_field_226 = 226; - int32 int32_field_227 = 227; - int32 int32_field_228 = 228; - int32 int32_field_229 = 229; - int32 int32_field_230 = 230; - int32 int32_field_231 = 231; - int32 int32_field_232 = 232; - int32 int32_field_233 = 233; - int32 int32_field_234 = 234; - int32 int32_field_235 = 235; - int32 int32_field_236 = 236; - int32 int32_field_237 = 237; - int32 int32_field_238 = 238; - int32 int32_field_239 = 239; - int32 int32_field_240 = 240; - int32 int32_field_241 = 241; - int32 int32_field_242 = 242; - int32 int32_field_243 = 243; - int32 int32_field_244 = 244; - int32 int32_field_245 = 245; - int32 int32_field_246 = 246; - int32 int32_field_247 = 247; - int32 int32_field_248 = 248; - int32 int32_field_249 = 249; - int32 int32_field_250 = 250; - int32 int32_field_251 = 251; - int32 int32_field_252 = 252; - int32 int32_field_253 = 253; - int32 int32_field_254 = 254; - int32 int32_field_255 = 255; - int32 int32_field_256 = 256; - int32 int32_field_257 = 257; - int32 int32_field_258 = 258; - int32 int32_field_259 = 259; - int32 int32_field_260 = 260; - int32 int32_field_261 = 261; - int32 int32_field_262 = 262; - int32 int32_field_263 = 263; - int32 int32_field_264 = 264; - int32 int32_field_265 = 265; - int32 int32_field_266 = 266; - int32 int32_field_267 = 267; - int32 int32_field_268 = 268; - int32 int32_field_269 = 269; - int32 int32_field_270 = 270; - int32 int32_field_271 = 271; - int32 int32_field_272 = 272; - int32 int32_field_273 = 273; - int32 int32_field_274 = 274; - int32 int32_field_275 = 275; - int32 int32_field_276 = 276; - int32 int32_field_277 = 277; - int32 int32_field_278 = 278; - int32 int32_field_279 = 279; - int32 int32_field_280 = 280; - int32 int32_field_281 = 281; - int32 int32_field_282 = 282; - int32 int32_field_283 = 283; - int32 int32_field_284 = 284; - int32 int32_field_285 = 285; - int32 int32_field_286 = 286; - int32 int32_field_287 = 287; - int32 int32_field_288 = 288; - int32 int32_field_289 = 289; - int32 int32_field_290 = 290; - int32 int32_field_291 = 291; - int32 int32_field_292 = 292; - int32 int32_field_293 = 293; - int32 int32_field_294 = 294; - int32 int32_field_295 = 295; - int32 int32_field_296 = 296; - int32 int32_field_297 = 297; - int32 int32_field_298 = 298; - int32 int32_field_299 = 299; - int32 int32_field_300 = 300; - int32 int32_field_301 = 301; - int32 int32_field_302 = 302; - int32 int32_field_303 = 303; - int32 int32_field_304 = 304; - int32 int32_field_305 = 305; - int32 int32_field_306 = 306; - int32 int32_field_307 = 307; - int32 int32_field_308 = 308; - int32 int32_field_309 = 309; - int32 int32_field_310 = 310; - int32 int32_field_311 = 311; - int32 int32_field_312 = 312; - int32 int32_field_313 = 313; - int32 int32_field_314 = 314; - int32 int32_field_315 = 315; - int32 int32_field_316 = 316; - int32 int32_field_317 = 317; - int32 int32_field_318 = 318; - int32 int32_field_319 = 319; - int32 int32_field_320 = 320; - int32 int32_field_321 = 321; - int32 int32_field_322 = 322; - int32 int32_field_323 = 323; - int32 int32_field_324 = 324; - int32 int32_field_325 = 325; - int32 int32_field_326 = 326; - int32 int32_field_327 = 327; - int32 int32_field_328 = 328; - int32 int32_field_329 = 329; - int32 int32_field_330 = 330; - int32 int32_field_331 = 331; - int32 int32_field_332 = 332; - int32 int32_field_333 = 333; - int32 int32_field_334 = 334; - int32 int32_field_335 = 335; - int32 int32_field_336 = 336; - int32 int32_field_337 = 337; - int32 int32_field_338 = 338; - int32 int32_field_339 = 339; - int32 int32_field_340 = 340; - int32 int32_field_341 = 341; - int32 int32_field_342 = 342; - int32 int32_field_343 = 343; - int32 int32_field_344 = 344; - int32 int32_field_345 = 345; - int32 int32_field_346 = 346; - int32 int32_field_347 = 347; - int32 int32_field_348 = 348; - int32 int32_field_349 = 349; - int32 int32_field_350 = 350; - int32 int32_field_351 = 351; - int32 int32_field_352 = 352; - int32 int32_field_353 = 353; - int32 int32_field_354 = 354; - int32 int32_field_355 = 355; - int32 int32_field_356 = 356; - int32 int32_field_357 = 357; - int32 int32_field_358 = 358; - int32 int32_field_359 = 359; - int32 int32_field_360 = 360; - int32 int32_field_361 = 361; - int32 int32_field_362 = 362; - int32 int32_field_363 = 363; - int32 int32_field_364 = 364; - int32 int32_field_365 = 365; - int32 int32_field_366 = 366; - int32 int32_field_367 = 367; - int32 int32_field_368 = 368; - int32 int32_field_369 = 369; - int32 int32_field_370 = 370; - int32 int32_field_371 = 371; - int32 int32_field_372 = 372; - int32 int32_field_373 = 373; - int32 int32_field_374 = 374; - int32 int32_field_375 = 375; - int32 int32_field_376 = 376; - int32 int32_field_377 = 377; - int32 int32_field_378 = 378; - int32 int32_field_379 = 379; - int32 int32_field_380 = 380; - int32 int32_field_381 = 381; - int32 int32_field_382 = 382; - int32 int32_field_383 = 383; - int32 int32_field_384 = 384; - int32 int32_field_385 = 385; - int32 int32_field_386 = 386; - int32 int32_field_387 = 387; - int32 int32_field_388 = 388; - int32 int32_field_389 = 389; - int32 int32_field_390 = 390; - int32 int32_field_391 = 391; - int32 int32_field_392 = 392; - int32 int32_field_393 = 393; - int32 int32_field_394 = 394; - int32 int32_field_395 = 395; - int32 int32_field_396 = 396; - int32 int32_field_397 = 397; - int32 int32_field_398 = 398; - int32 int32_field_399 = 399; - int32 int32_field_400 = 400; - int32 int32_field_401 = 401; - int32 int32_field_402 = 402; - int32 int32_field_403 = 403; - int32 int32_field_404 = 404; - int32 int32_field_405 = 405; - int32 int32_field_406 = 406; - int32 int32_field_407 = 407; - int32 int32_field_408 = 408; - int32 int32_field_409 = 409; - int32 int32_field_410 = 410; - int32 int32_field_411 = 411; - int32 int32_field_412 = 412; - int32 int32_field_413 = 413; - int32 int32_field_414 = 414; - int32 int32_field_415 = 415; - int32 int32_field_416 = 416; - int32 int32_field_417 = 417; - int32 int32_field_418 = 418; - int32 int32_field_419 = 419; - int32 int32_field_420 = 420; - int32 int32_field_421 = 421; - int32 int32_field_422 = 422; - int32 int32_field_423 = 423; - int32 int32_field_424 = 424; - int32 int32_field_425 = 425; - int32 int32_field_426 = 426; - int32 int32_field_427 = 427; - int32 int32_field_428 = 428; - int32 int32_field_429 = 429; - int32 int32_field_430 = 430; - int32 int32_field_431 = 431; - int32 int32_field_432 = 432; - int32 int32_field_433 = 433; - int32 int32_field_434 = 434; - int32 int32_field_435 = 435; - int32 int32_field_436 = 436; - int32 int32_field_437 = 437; - int32 int32_field_438 = 438; - int32 int32_field_439 = 439; - int32 int32_field_440 = 440; - int32 int32_field_441 = 441; - int32 int32_field_442 = 442; - int32 int32_field_443 = 443; - int32 int32_field_444 = 444; - int32 int32_field_445 = 445; - int32 int32_field_446 = 446; - int32 int32_field_447 = 447; - int32 int32_field_448 = 448; - int32 int32_field_449 = 449; - int32 int32_field_450 = 450; - int32 int32_field_451 = 451; - int32 int32_field_452 = 452; - int32 int32_field_453 = 453; - int32 int32_field_454 = 454; - int32 int32_field_455 = 455; - int32 int32_field_456 = 456; - int32 int32_field_457 = 457; - int32 int32_field_458 = 458; - int32 int32_field_459 = 459; - int32 int32_field_460 = 460; - int32 int32_field_461 = 461; - int32 int32_field_462 = 462; - int32 int32_field_463 = 463; - int32 int32_field_464 = 464; - int32 int32_field_465 = 465; - int32 int32_field_466 = 466; - int32 int32_field_467 = 467; - int32 int32_field_468 = 468; - int32 int32_field_469 = 469; - int32 int32_field_470 = 470; - int32 int32_field_471 = 471; - int32 int32_field_472 = 472; - int32 int32_field_473 = 473; - int32 int32_field_474 = 474; - int32 int32_field_475 = 475; - int32 int32_field_476 = 476; - int32 int32_field_477 = 477; - int32 int32_field_478 = 478; - int32 int32_field_479 = 479; - int32 int32_field_480 = 480; - int32 int32_field_481 = 481; - int32 int32_field_482 = 482; - int32 int32_field_483 = 483; - int32 int32_field_484 = 484; - int32 int32_field_485 = 485; - int32 int32_field_486 = 486; - int32 int32_field_487 = 487; - int32 int32_field_488 = 488; - int32 int32_field_489 = 489; - int32 int32_field_490 = 490; - int32 int32_field_491 = 491; - int32 int32_field_492 = 492; - int32 int32_field_493 = 493; - int32 int32_field_494 = 494; - int32 int32_field_495 = 495; - int32 int32_field_496 = 496; - int32 int32_field_497 = 497; - int32 int32_field_498 = 498; - int32 int32_field_499 = 499; - int32 int32_field_500 = 500; - int32 int32_field_501 = 501; - int32 int32_field_502 = 502; - int32 int32_field_503 = 503; - int32 int32_field_504 = 504; - int32 int32_field_505 = 505; - int32 int32_field_506 = 506; - int32 int32_field_507 = 507; - int32 int32_field_508 = 508; - int32 int32_field_509 = 509; - int32 int32_field_510 = 510; - int32 int32_field_511 = 511; - int32 int32_field_512 = 512; - int32 int32_field_513 = 513; - int32 int32_field_514 = 514; - int32 int32_field_515 = 515; - int32 int32_field_516 = 516; - int32 int32_field_517 = 517; - int32 int32_field_518 = 518; - int32 int32_field_519 = 519; - int32 int32_field_520 = 520; - int32 int32_field_521 = 521; - int32 int32_field_522 = 522; - int32 int32_field_523 = 523; - int32 int32_field_524 = 524; - int32 int32_field_525 = 525; - int32 int32_field_526 = 526; - int32 int32_field_527 = 527; - int32 int32_field_528 = 528; - int32 int32_field_529 = 529; - int32 int32_field_530 = 530; - int32 int32_field_531 = 531; - int32 int32_field_532 = 532; - int32 int32_field_533 = 533; - int32 int32_field_534 = 534; - int32 int32_field_535 = 535; - int32 int32_field_536 = 536; - int32 int32_field_537 = 537; - int32 int32_field_538 = 538; - int32 int32_field_539 = 539; - int32 int32_field_540 = 540; - int32 int32_field_541 = 541; - int32 int32_field_542 = 542; - int32 int32_field_543 = 543; - int32 int32_field_544 = 544; - int32 int32_field_545 = 545; - int32 int32_field_546 = 546; - int32 int32_field_547 = 547; - int32 int32_field_548 = 548; - int32 int32_field_549 = 549; - int32 int32_field_550 = 550; - int32 int32_field_551 = 551; - int32 int32_field_552 = 552; -} \ No newline at end of file diff --git a/vendor/upb/mini_table/sub.h b/vendor/upb/mini_table/sub.h deleted file mode 100644 index 68c1c20..0000000 --- a/vendor/upb/mini_table/sub.h +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_SUB_H_ -#define UPB_MINI_TABLE_SUB_H_ - -#include "upb/mini_table/enum.h" -#include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef union upb_MiniTableSub upb_MiniTableSub; - -#ifdef __cplusplus -extern "C" { -#endif - -// Constructors - -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum); - -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg); - -// Getters - -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( - upb_MiniTableSub sub); - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( - upb_MiniTableSub sub); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_MINI_TABLE_SUB_H_ */ diff --git a/vendor/upb/port/BUILD b/vendor/upb/port/BUILD deleted file mode 100644 index bf6ec4d..0000000 --- a/vendor/upb/port/BUILD +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "port", - hdrs = [ - "atomic.h", - "sanitizers.h", - "vsnprintf_compat.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - textual_hdrs = [ - # We must list the headers explicitly here instead of relying on the - # :inc filegroup below. gRPC auto-generates various build configs from - # the Bazel graph, and this logic does not know how to handle - # filegroups. We might be able to replace these headers with just - # ":inc" after gRPC starts using upb's CMake build. - "def.inc", - "undef.inc", - ], - visibility = ["//visibility:public"], -) - -filegroup( - name = "inc", - srcs = [ - "def.inc", - "undef.inc", - ], - visibility = ["//visibility:public"], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.h", - "**/*.inc", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) diff --git a/vendor/upb/port/atomic.h b/vendor/upb/port/atomic.h deleted file mode 100644 index e833d6d..0000000 --- a/vendor/upb/port/atomic.h +++ /dev/null @@ -1,316 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_PORT_ATOMIC_H_ -#define UPB_PORT_ATOMIC_H_ - -#include "upb/port/def.inc" - -#ifdef UPB_USE_C11_ATOMICS - -// IWYU pragma: begin_exports -#include -#include -// IWYU pragma: end_exports - -#define upb_Atomic_Init(addr, val) atomic_init(addr, val) -#define upb_Atomic_Load(addr, order) atomic_load_explicit(addr, order) -#define upb_Atomic_Store(addr, val, order) \ - atomic_store_explicit(addr, val, order) -#define upb_Atomic_Exchange(addr, val, order) \ - atomic_exchange_explicit(addr, val, order) -#define upb_Atomic_CompareExchangeStrong(addr, expected, desired, \ - success_order, failure_order) \ - atomic_compare_exchange_strong_explicit(addr, expected, desired, \ - success_order, failure_order) -#define upb_Atomic_CompareExchangeWeak(addr, expected, desired, success_order, \ - failure_order) \ - atomic_compare_exchange_weak_explicit(addr, expected, desired, \ - success_order, failure_order) -#define upb_Atomic_Add(addr, val, order) \ - atomic_fetch_add_explicit(addr, val, order) -#define upb_Atomic_Sub(addr, val, order) \ - atomic_fetch_sub_explicit(addr, val, order) - -#elif defined(UPB_USE_MSC_ATOMICS) -#include -#include -#include - -#define upb_Atomic_Init(addr, val) (*(addr) = val) - -#pragma intrinsic(_InterlockedExchange) -static int32_t upb_Atomic_LoadMsc32(int32_t volatile* addr) { - // Compare exchange with an unlikely value reduces the risk of a spurious - // (but harmless) store - return _InterlockedCompareExchange(addr, 0xDEADC0DE, 0xDEADC0DE); -} - -#pragma intrinsic(_InterlockedCompareExchange) -static bool upb_Atomic_CompareExchangeMscP32(int32_t volatile* addr, - int32_t* expected, - int32_t desired) { - int32_t expect_val = *expected; - int32_t actual_val = _InterlockedCompareExchange(addr, desired, expect_val); - if (expect_val != actual_val) { - *expected = actual_val; - return false; - } - return true; -} - -#if defined(_WIN64) -// MSVC, without C11 atomics, does not have any way in pure C to force -// load-acquire store-release behavior, so we hack it with exchanges. -#pragma intrinsic(_InterlockedCompareExchange64) -static uintptr_t upb_Atomic_LoadMsc64(uint64_t volatile* addr) { - // Compare exchange with an unlikely value reduces the risk of a spurious - // (but harmless) store - return _InterlockedCompareExchange64(addr, 0xDEADC0DEBAADF00D, - 0xDEADC0DEBAADF00D); -} - -#pragma intrinsic(_InterlockedCompareExchange64) -static bool upb_Atomic_CompareExchangeMscP64(uint64_t volatile* addr, - uint64_t* expected, - uint64_t desired) { - uint64_t expect_val = *expected; - uint64_t actual_val = - _InterlockedCompareExchange64(addr, desired, expect_val); - if (expect_val != actual_val) { - *expected = actual_val; - return false; - } - return true; -} - -#pragma intrinsic(_InterlockedExchange64) -// If _Generic is available, use it to avoid emitting a "'uintptr_t' differs in -// levels of indirection from 'void *'" or -Wint-conversion compiler warning. -#if __STDC_VERSION__ >= 201112L -#define upb_Atomic_Store(addr, val, order) \ - _Generic(addr, \ - UPB_ATOMIC(uintptr_t)*: (void)_InterlockedExchange64( \ - (uint64_t volatile*)(addr), (uint64_t)val), \ - UPB_ATOMIC(int32_t)*: (void)_InterlockedExchange( \ - (int32_t volatile*)(addr), (int32_t)val), \ - default: (void)_InterlockedExchange64((uint64_t volatile*)addr, \ - (uint64_t)val)) - -#define upb_Atomic_Load(addr, order) \ - _Generic(addr, \ - UPB_ATOMIC(uintptr_t)*: upb_Atomic_LoadMsc64( \ - (uint64_t volatile*)(addr)), \ - UPB_ATOMIC(int32_t)*: upb_Atomic_LoadMsc32((int32_t volatile*)(addr)), \ - default: (void*)upb_Atomic_LoadMsc64((uint64_t volatile*)(addr))) - -#define upb_Atomic_Exchange(addr, val, order) \ - _Generic(addr, \ - UPB_ATOMIC(uintptr_t)*: _InterlockedExchange64( \ - (uint64_t volatile*)(addr), (uint64_t)val), \ - UPB_ATOMIC(int32_t)*: _InterlockedExchange((int32_t volatile*)(addr), \ - (int32_t)val), \ - default: (void*)_InterlockedExchange64((uint64_t volatile*)addr, \ - (uint64_t)val)) - -#define upb_Atomic_CompareExchangeStrong(addr, expected, desired, \ - success_order, failure_order) \ - _Generic(addr, \ - UPB_ATOMIC(int32_t)*: upb_Atomic_CompareExchangeMscP32( \ - (int32_t volatile*)(addr), (int32_t*)expected, \ - (int32_t)desired), \ - default: upb_Atomic_CompareExchangeMscP64((uint64_t volatile*)(addr), \ - (uint64_t*)expected, \ - (uint64_t)desired)) - -#define upb_Atomic_CompareExchangeWeak(addr, expected, desired, success_order, \ - failure_order) \ - _Generic(addr, \ - UPB_ATOMIC(int32_t)*: upb_Atomic_CompareExchangeMscP32( \ - (int32_t volatile*)(addr), (int32_t*)expected, \ - (int32_t)desired), \ - default: upb_Atomic_CompareExchangeMscP64((uint64_t volatile*)(addr), \ - (uint64_t*)expected, \ - (uint64_t)desired)) - -#else - -UPB_INLINE void _upb_Atomic_StoreP(void volatile* addr, uint64_t val, - size_t size) { - if (size == sizeof(int32_t)) { - (void)_InterlockedExchange((int32_t volatile*)addr, (int32_t)val); - } else { - (void)_InterlockedExchange64((uint64_t volatile*)addr, val); - } -} - -#define upb_Atomic_Store(addr, val, order) \ - _upb_Atomic_StoreP(addr, val, sizeof(*addr)) - -UPB_INLINE int64_t _upb_Atomic_LoadP(void volatile* addr, size_t size) { - if (size == sizeof(int32_t)) { - return (int64_t)upb_Atomic_LoadMsc32((int32_t volatile*)addr); - } else { - return upb_Atomic_LoadMsc64((uint64_t volatile*)addr); - } -} - -#define upb_Atomic_Load(addr, order) \ - (void*)_upb_Atomic_LoadP((void volatile*)addr, sizeof(*addr)) - -UPB_INLINE int64_t _upb_Atomic_ExchangeP(void volatile* addr, uint64_t val, - size_t size) { - if (size == sizeof(int32_t)) { - return (int64_t)_InterlockedExchange((int32_t volatile*)addr, (int32_t)val); - } else { - return (int64_t)_InterlockedExchange64((uint64_t volatile*)addr, val); - } -} - -#define upb_Atomic_Exchange(addr, val, order) \ - (void*)_upb_Atomic_ExchangeP((void volatile*)addr, (uint64_t)val, \ - sizeof(*addr)) - -UPB_INLINE bool _upb_Atomic_CompareExchangeMscP(void volatile* addr, - void* expected, - uint64_t desired, size_t size) { - if (size == sizeof(int32_t)) { - return upb_Atomic_CompareExchangeMscP32( - (int32_t volatile*)addr, (int32_t*)expected, (int32_t)desired); - } else { - return upb_Atomic_CompareExchangeMscP64((uint64_t volatile*)addr, - (uint64_t*)expected, desired); - } -} - -#define upb_Atomic_CompareExchangeStrong(addr, expected, desired, \ - success_order, failure_order) \ - _upb_Atomic_CompareExchangeMscP(addr, expected, (uint64_t)desired, \ - sizeof(*addr)) - -#define upb_Atomic_CompareExchangeWeak(addr, expected, desired, success_order, \ - failure_order) \ - _upb_Atomic_CompareExchangeMscP(addr, expected, (uint64_t)desired, \ - sizeof(*addr)) - -#endif - -#else // 32 bit pointers -#pragma intrinsic(_InterlockedExchange) -#define upb_Atomic_Store(addr, val, order) \ - (void)_InterlockedExchange((uint32_t volatile*)addr, (uint32_t)val) - -// If _Generic is available, use it to avoid emitting 'uintptr_t' differs in -// levels of indirection from 'void *' -#if __STDC_VERSION__ >= 201112L -#define upb_Atomic_Load(addr, order) \ - _Generic(addr, \ - UPB_ATOMIC(uintptr_t)*: (uintptr_t)upb_Atomic_LoadMsc32( \ - (uint32_t volatile*)(addr)), \ - UPB_ATOMIC(int32_t)*: upb_Atomic_LoadMsc32((int32_t volatile*)(addr)), \ - default: (void*)upb_Atomic_LoadMsc32((uint32_t volatile*)(addr))) - -#define upb_Atomic_Exchange(addr, val, order) \ - _Generic(addr, \ - UPB_ATOMIC(uintptr_t)*: _InterlockedExchange((uint32_t volatile*)(addr), \ - (uint32_t)val), \ - default: (void*)_InterlockedExchange((uint32_t volatile*)addr, \ - (uint32_t)val)) -#else -#define upb_Atomic_Load(addr, order) \ - (void*)upb_Atomic_LoadMsc32((uint32_t volatile*)(addr)) - -#define upb_Atomic_Exchange(addr, val, order) \ - (void*)_InterlockedExchange((uint32_t volatile*)addr, (uint32_t)val) -#endif - -#define upb_Atomic_CompareExchangeStrong(addr, expected, desired, \ - success_order, failure_order) \ - upb_Atomic_CompareExchangeMscP32((uint32_t volatile*)addr, \ - (uint32_t*)expected, (uint32_t)desired) - -#define upb_Atomic_CompareExchangeWeak(addr, expected, desired, success_order, \ - failure_order) \ - upb_Atomic_CompareExchangeMscP32((uint32_t volatile*)addr, \ - (uint32_t*)expected, (uint32_t)desired) -#endif - -#pragma intrinsic(_InterlockedExchangeAdd) -#pragma intrinsic(_InterlockedExchangeAdd64) - -// If _Generic is available, use it to switch between 32 and 64 bit types. -#if __STDC_VERSION__ >= 201112L -#define upb_Atomic_Add(addr, val, order) \ - _Generic(addr, \ - UPB_ATOMIC(int64_t)*: _InterlockedExchangeAdd64(addr, (int64_t)val), \ - UPB_ATOMIC(int32_t)*: _InterlockedExchangeAdd(addr, (int32_t)val)) -#define upb_Atomic_Sub(addr, val, order) \ - _Generic(addr, \ - UPB_ATOMIC(int64_t)*: _InterlockedExchangeAdd64(addr, -(int64_t)val), \ - UPB_ATOMIC(int32_t)*: _InterlockedExchangeAdd(addr, -(int32_t)val)) -#else -#define upb_Atomic_Add(addr, val, order) \ - sizeof(*addr) == sizeof(int32_t) \ - ? _InterlockedExchangeAdd((uint32_t volatile*)addr, (int32_t)val) \ - : _InterlockedExchangeAdd64((uint64_t volatile*)addr, (int64_t)val) -#define upb_Atomic_Sub(addr, val, order) \ - sizeof(*addr) == sizeof(int32_t) \ - ? _InterlockedExchangeAdd((uint32_t volatile*)addr, -(int32_t)val) \ - : _InterlockedExchangeAdd64((uint64_t volatile*)addr, -(int64_t)val) -#endif - -#else // No atomics - -#if !defined(UPB_SUPPRESS_MISSING_ATOMICS) -// NOLINTNEXTLINE -#error Your compiler does not support atomic instructions, which UPB uses. If you do not use UPB on multiple threads, you can suppress this error by defining UPB_SUPPRESS_MISSING_ATOMICS. -#endif - -#include - -#define upb_Atomic_Init(addr, val) (*addr = val) -#define upb_Atomic_Load(addr, order) (*addr) -#define upb_Atomic_Store(addr, val, order) (*(addr) = val) - -UPB_INLINE void* _upb_NonAtomic_Exchange(void* addr, void* value) { - void* old; - memcpy(&old, addr, sizeof(value)); - memcpy(addr, &value, sizeof(value)); - return old; -} - -#define upb_Atomic_Exchange(addr, val, order) _upb_NonAtomic_Exchange(addr, val) - -// `addr` and `expected` are logically double pointers. -UPB_INLINE bool _upb_NonAtomic_CompareExchangeStrongP(void* addr, - void* expected, - void* desired) { - if (memcmp(addr, expected, sizeof(desired)) == 0) { - memcpy(addr, &desired, sizeof(desired)); - return true; - } else { - memcpy(expected, addr, sizeof(desired)); - return false; - } -} - -#define upb_Atomic_CompareExchangeStrong(addr, expected, desired, \ - success_order, failure_order) \ - _upb_NonAtomic_CompareExchangeStrongP((void*)addr, (void*)expected, \ - (void*)desired) -#define upb_Atomic_CompareExchangeWeak(addr, expected, desired, success_order, \ - failure_order) \ - upb_Atomic_CompareExchangeStrong(addr, expected, desired, 0, 0) - -#define upb_Atomic_Add(addr, val, order) (*addr += val) -#define upb_Atomic_Sub(addr, val, order) (*addr -= val) - -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_PORT_ATOMIC_H_ diff --git a/vendor/upb/port/def.inc b/vendor/upb/port/def.inc deleted file mode 100644 index 588c84e..0000000 --- a/vendor/upb/port/def.inc +++ /dev/null @@ -1,766 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* - * This is where we define internal portability macros used across upb. - * - * All of these macros are undef'd in undef.inc to avoid leaking them to users. - * - * The correct usage is: - * - * #include "upb/foobar.h" - * #include "upb/baz.h" - * - * // MUST be last included header. - * #include "upb/port/def.inc" - * - * // Code for this file. - * // <...> - * - * // Can be omitted for .c files, required for .h. - * #include "upb/port/undef.inc" - * - * This file is private and must not be included by users! - */ - -#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ - (defined(__cplusplus) && __cplusplus >= 201703L) || \ - (defined(_MSC_VER) && _MSC_VER >= 1900)) -#error upb requires C99 or C++17 or MSVC >= 2015. -#endif - -// Portable check for GCC minimum version: -// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html -#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -#define UPB_GNUC_MIN(x, y) \ - (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y)) -#else -#define UPB_GNUC_MIN(x, y) 0 -#endif - -// Macros for checking for compiler attributes, defined here to avoid the -// problem described in -// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html. -#ifdef __has_attribute -#define UPB_HAS_ATTRIBUTE(x) __has_attribute(x) -#else -#define UPB_HAS_ATTRIBUTE(x) 0 -#endif - -#ifdef __has_c_attribute -#define UPB_HAS_C_ATTRIBUTE(x) __has_c_attribute(x) -#else -#define UPB_HAS_C_ATTRIBUTE(x) 0 -#endif - -#if defined(__cplusplus) && defined(__has_cpp_attribute) -// NOTE: requiring __cplusplus above should not be necessary, but -// works around https://bugs.llvm.org/show_bug.cgi?id=23435. -#define UPB_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#else -#define UPB_HAS_CPP_ATTRIBUTE(x) 0 -#endif - -// Once in a while we want to use this macro in a C++-only portion of an -// otherwise C-compatible header, so we copy and paste this from ABSL. -#if UPB_HAS_CPP_ATTRIBUTE(deprecated) && UPB_HAS_CPP_ATTRIBUTE(clang::annotate) -#define UPB_DEPRECATE_AND_INLINE() [[deprecated, clang::annotate("inline-me")]] -#elif UPB_HAS_CPP_ATTRIBUTE(deprecated) -#define UPB_DEPRECATE_AND_INLINE() [[deprecated]] -#else -#define UPB_DEPRECATE_AND_INLINE() -#endif - -#ifdef __has_builtin -#define UPB_HAS_BUILTIN(x) __has_builtin(x) -#else -#define UPB_HAS_BUILTIN(x) 0 -#endif - -#ifdef __has_extension -#define UPB_HAS_EXTENSION(x) __has_extension(x) -#else -#define UPB_HAS_EXTENSION(x) 0 -#endif - -#ifdef __has_feature -#define UPB_HAS_FEATURE(x) __has_feature(x) -#else -#define UPB_HAS_FEATURE(x) 0 -#endif - -#include -#include -#include -#include -#include -#include - -#ifndef UINTPTR_MAX -Error, UINTPTR_MAX is undefined -#endif - -#if UINTPTR_MAX == 0xffffffff -#define UPB_SIZE(size32, size64) size32 -#else -#define UPB_SIZE(size32, size64) size64 -#endif - -/* If we always read/write as a consistent type to each address, this shouldn't - * violate aliasing. - */ -#define UPB_PTR_AT(msg, ofs, type) ((type*)((char*)(msg) + (ofs))) - -// A flexible array member may have lower alignment requirements than the struct -// overall - in that case, it can overlap with the trailing padding of the rest -// of the struct, and a naive sizeof(base) + sizeof(flex) * count calculation -// will not take into account that overlap, and allocate more than is required. -#define UPB_SIZEOF_FLEX(type, member, count) \ - UPB_MAX(sizeof(type), offsetof(type, member[count])) - -#define UPB_SIZEOF_FLEX_WOULD_OVERFLOW(type, member, count) \ - (((SIZE_MAX - offsetof(type, member[0])) / \ - (offsetof(type, member[1]) - offsetof(type, member[0]))) < (size_t)count) - -#define UPB_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) - -#define UPB_MAPTYPE_STRING 0 - -// UPB_EXPORT: always generate a public symbol. -#if defined(__GNUC__) || defined(__clang__) -#define UPB_EXPORT __attribute__((visibility("default"))) __attribute__((used)) -#else -#define UPB_EXPORT -#endif - -// UPB_INLINE: inline if possible, emit standalone code if required. -#ifdef __cplusplus -#define UPB_INLINE inline -#elif defined(__GNUC__) || defined(__clang__) -#define UPB_INLINE static __inline__ -#else -#define UPB_INLINE static -#endif - -// UPB_INLINE_IF_NOT_GCC: because gcc can be very noisy at times. -#if defined(__GNUC__) && !defined(__clang__) -#define UPB_INLINE_IF_NOT_GCC static -#else -#define UPB_INLINE_IF_NOT_GCC UPB_INLINE -#endif - -#ifdef UPB_BUILD_API -#define UPB_API UPB_EXPORT -#define UPB_API_INLINE UPB_EXPORT -#else -#define UPB_API -#define UPB_API_INLINE UPB_INLINE -#endif - -#ifdef EXPORT_UPBC -#define UPBC_API UPB_EXPORT -#else -#define UPBC_API -#endif - -#if UPB_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__) -#define UPB_ASAN 1 -#else -#define UPB_ASAN 0 -#endif - -#if UPB_HAS_FEATURE(hwaddress_sanitizer) -#define UPB_HWASAN 1 -#define UPB_HWASAN_POISON_TAG 17 -#define UPB_MALLOC_ALIGN 16 -#else -#define UPB_HWASAN 0 -#define UPB_MALLOC_ALIGN 8 -#endif - -#if UPB_HAS_FEATURE(thread_sanitizer) || defined(__SANITIZE_THREAD__) -#define UPB_TSAN 1 -#else -#define UPB_TSAN 0 -#endif - -#if UPB_HAS_FEATURE(memory_sanitizer) -#define UPB_MSAN 1 -#else -#define UPB_MSAN 0 -#endif - -// An unfortunate concession to C++17 and MSVC, which don't support zero-sized -// structs. -#if UPB_ASAN || UPB_HWASAN || UPB_TSAN -#define UPB_XSAN_MEMBER upb_Xsan xsan; -#define UPB_XSAN(st) (&(st)->xsan) -#define UPB_XSAN_STRUCT_SIZE 1 -#else -#define UPB_XSAN_MEMBER -#define UPB_XSAN(st) (NULL) -#define UPB_XSAN_STRUCT_SIZE 0 -#endif - -#define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align)) -#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align)) -#define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, UPB_MALLOC_ALIGN) - -#if __STDC_VERSION__ >= 202311L || UPB_HAS_EXTENSION(cxx_alignof) || \ - defined(__cplusplus) -#define UPB_ALIGN_OF(type) alignof(type) -#elif __STDC_VERSION__ >= 201112L || UPB_HAS_EXTENSION(c_alignof) -#define UPB_ALIGN_OF(type) _Alignof(type) -#elif UPB_GNUC_MIN(2, 95) -#define UPB_ALIGN_OF(type) __alignof__(type) -#elif defined(_MSC_VER) -#define UPB_ALIGN_OF(type) __alignof(type) -#else -#define UPB_ALIGN_OF(type) \ - offsetof( \ - struct { \ - char c; \ - type member; \ - }, \ - member) -#endif - -#ifdef _MSC_VER -// Some versions of our Windows compiler don't support the C11 syntax. -#define UPB_ALIGN_AS(x) __declspec(align(x)) -#elif defined(__GNUC__) -#define UPB_ALIGN_AS(x) __attribute__((aligned(x))) -#else -#define UPB_ALIGN_AS(x) _Alignas(x) -#endif - -#if __STDC_VERSION__ >= 202311L || UPB_HAS_EXTENSION(cxx_static_assert) || \ - defined(__cplusplus) -#define UPB_STATIC_ASSERT(val, msg) static_assert((val), msg) -#elif __STDC_VERSION__ >= 201112L || UPB_HAS_EXTENSION(c_static_assert) || \ - UPB_GNUC_MIN(4, 6) -#define UPB_STATIC_ASSERT(val, msg) _Static_assert((val), msg) -#else -// Unfortunately this hack doesn't work inside struct declarations, but it works -// everywhere else -#define UPB_STATIC_ASSERT_CONCAT_IMPL(s1, s2) s1##s2 -#define UPB_STATIC_ASSERT_CONCAT(s1, s2) UPB_STATIC_ASSERT_CONCAT_IMPL(s1, s2) -#ifdef __COUNTER__ -#define UPB_STATIC_ASSERT(condition, message) \ - typedef char UPB_STATIC_ASSERT_CONCAT(static_assertion_failure_, \ - __COUNTER__)[(condition) ? 1 : -1] -#else -#define UPB_STATIC_ASSERT(condition, message) \ - typedef char UPB_STATIC_ASSERT_CONCAT(static_assertion_failure_, \ - __LINE__)[(condition) ? 1 : -1] -#endif -#endif - -// Hints to the compiler about likely/unlikely branches. -#if defined(__GNUC__) || defined(__clang__) -#define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) -#define UPB_UNLIKELY(x) __builtin_expect((bool)(x), 0) -#else -#define UPB_LIKELY(x) (x) -#define UPB_UNLIKELY(x) (x) -#endif - -#if UPB_HAS_BUILTIN(__builtin_expect_with_probability) -#define UPB_UNPREDICTABLE(x) \ - __builtin_expect_with_probability((bool)(x), 1, 0.5) -#else -#define UPB_UNPREDICTABLE(x) (x) -#endif - -// Macros for function attributes on compilers that support them. -#if defined(__GNUC__) || defined(__clang__) -#define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) static -#define UPB_NOINLINE __attribute__((noinline)) -#define UPB_NORETURN __attribute__((__noreturn__)) -#define UPB_PRINTF(str, first_vararg) \ - __attribute__((format(printf, str, first_vararg))) -#elif defined(_MSC_VER) -#define UPB_NOINLINE -#define UPB_FORCEINLINE static -#define UPB_NORETURN __declspec(noreturn) -#define UPB_PRINTF(str, first_vararg) -#else /* !defined(__GNUC__) */ -#define UPB_FORCEINLINE static -#define UPB_NOINLINE -#define UPB_NORETURN -#define UPB_PRINTF(str, first_vararg) -#endif - -#if UPB_HAS_ATTRIBUTE(noderef) -#define UPB_NODEREF __attribute__((noderef)) -#else -#define UPB_NODEREF -#endif - -// Will be defined properly once call sites are updated -#if false && UPB_HAS_C_ATTRIBUTE(nodiscard) -#define UPB_NODISCARD [[nodiscard]] -#elif false && UPB_HAS_ATTRIBUTE(warn_unused_result) -#define UPB_NODISCARD __attribute__((warn_unused_result)) -#elif false && UPB_HAS_CPP_ATTRIBUTE(nodiscard) -#define UPB_NODISCARD [[nodiscard]] -#else -#define UPB_NODISCARD -#endif - -#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y)) -#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y)) - -#define UPB_UNUSED(var) (void)(var) - -// UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. -#ifdef NDEBUG -#ifdef __GNUC__ -#define UPB_ASSUME(expr) \ - if (!(expr)) __builtin_unreachable() -#elif defined _MSC_VER -#define UPB_ASSUME(expr) \ - if (!(expr)) __assume(0) -#else -#define UPB_ASSUME(expr) \ - do { \ - } while (false && (expr)) -#endif -#else -#define UPB_ASSUME(expr) assert(expr) -#endif - -#if UPB_HAS_BUILTIN(__builtin_constant_p) && UPB_HAS_ATTRIBUTE(const) -#define UPB_MAYBE_ASSUME(pred, x) \ - if (__builtin_constant_p(pred) && pred) UPB_ASSUME(x) -#define UPB_ATTR_CONST __attribute__((const)) -#else -#define UPB_MAYBE_ASSUME(pred, x) -#define UPB_ATTR_CONST -#endif - -/* UPB_ASSERT(): in release mode, we use the expression without letting it be - * evaluated. This prevents "unused variable" warnings. */ -#ifdef NDEBUG -#define UPB_ASSERT(expr) \ - do { \ - } while (false && (expr)) -#else -#define UPB_ASSERT(expr) assert(expr) -#endif - -#if !defined(NDEBUG) && !defined(UPB_TSAN) -#define UPB_ENABLE_REF_CYCLE_CHECKS 1 -#else -#define UPB_ENABLE_REF_CYCLE_CHECKS 0 -#endif - -#if defined(__GNUC__) || defined(__clang__) -#define UPB_UNREACHABLE() \ - do { \ - assert(0); \ - __builtin_unreachable(); \ - } while (0) -#elif defined(_MSC_VER) -#define UPB_UNREACHABLE() \ - do { \ - assert(0); \ - __assume(0); \ - } while (0) -#else -#define UPB_UNREACHABLE() \ - do { \ - assert(0); \ - } while (0) -#endif - -#ifdef __ANDROID__ -#define UPB_DEFAULT_MAX_BLOCK_SIZE 8192 -#else -#define UPB_DEFAULT_MAX_BLOCK_SIZE 32768 -#endif - -/* UPB_SETJMP() / UPB_LONGJMP() */ -// Android uses a custom libc that does not implement all of posix, but it has -// had sigsetjmp/siglongjmp forever on arm and since API 12 on x86. Apple has -// sigsetjmp, but does not define the posix feature test macro. -#if defined(__APPLE__) || defined(_POSIX_C_SOURCE) || defined(__ANDROID__) -// avoid setting/restoring signal mask, which involves costly syscalls -#define UPB_SETJMP(buf) sigsetjmp(buf, 0) -#define UPB_LONGJMP(buf, val) siglongjmp(buf, val) -#elif defined(WASM_WAMR) -#define UPB_SETJMP(buf) 0 -#define UPB_LONGJMP(buf, val) abort() -#else -#define UPB_SETJMP(buf) setjmp(buf) -#define UPB_LONGJMP(buf, val) longjmp(buf, val) -#endif - -#if ((__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)) || \ - UPB_HAS_EXTENSION(c_atomic) || \ - defined(__GNUC__) // GCC supported atomics as an extension before it - // supported __has_extension -#define UPB_USE_C11_ATOMICS -#elif defined(_MSC_VER) -#define UPB_USE_MSC_ATOMICS -#endif - -#if defined(UPB_USE_C11_ATOMICS) -#define UPB_ATOMIC(T) _Atomic(T) -#elif defined(UPB_USE_MSC_ATOMICS) -#define UPB_ATOMIC(T) volatile T -#else -#define UPB_ATOMIC(T) T -#endif - -/* UPB_PTRADD(ptr, ofs): add pointer while avoiding "NULL + 0" UB */ -#define UPB_PTRADD(ptr, ofs) ((ofs) ? (ptr) + (ofs) : (ptr)) - -#define UPB_PRIVATE(x) x##_dont_copy_me__upb_internal_use_only - -#ifdef UPB_ALLOW_PRIVATE_ACCESS__FOR_BITS_ONLY -#define UPB_ONLYBITS(x) x -#else -#define UPB_ONLYBITS(x) UPB_PRIVATE(x) -#endif - -/* Configure whether fasttable is switched on or not. *************************/ - -#if UPB_HAS_ATTRIBUTE(musttail) -#define UPB_MUSTTAIL __attribute__((musttail)) -#else -#define UPB_MUSTTAIL -#endif - -#if UPB_HAS_ATTRIBUTE(preserve_most) && !defined(__i386__) -#define UPB_PRESERVE_MOST __attribute__((preserve_most)) -#else -#define UPB_PRESERVE_MOST -#endif - -#if UPB_HAS_ATTRIBUTE(preserve_none) -#define UPB_PRESERVE_NONE __attribute__((preserve_none)) -#else -#define UPB_PRESERVE_NONE -#endif - -#if defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__)) -#define UPB_ARM64_ASM 1 -#else -#define UPB_ARM64_ASM 0 -#endif - -/* When compiling with branch protection, we need to ensure that all branch - * targets in assembly use the appropriate landing pad instruction. These - * instructions are backwards compatible with processors that don't have - * FEAT_BTI and are treated as nops. - */ -#if UPB_ARM64_ASM && defined(__ARM_FEATURE_BTI_DEFAULT) -#if __ARM_FEATURE_BTI_DEFAULT == 1 -#define UPB_ARM64_BTI_DEFAULT 1 -#else -#define UPB_ARM64_BTI_DEFAULT 0 -#endif -#else -#define UPB_ARM64_BTI_DEFAULT 0 -#endif - -#if (defined(__x86_64__) || defined(__aarch64__)) && \ - UPB_HAS_ATTRIBUTE(preserve_none) && UPB_HAS_ATTRIBUTE(musttail) -#define UPB_FASTTABLE_SUPPORTED 1 -#else -#define UPB_FASTTABLE_SUPPORTED 0 -#endif - -/* define UPB_ENABLE_FASTTABLE to force fast table support. - * This is useful when we want to ensure we are really getting fasttable, - * for example for testing or benchmarking. */ -#if defined(UPB_ENABLE_FASTTABLE) -#if !UPB_FASTTABLE_SUPPORTED -#error fasttable is x86-64/ARM64 only and requires preserve_none and musttail. -#endif -#define UPB_FASTTABLE 1 -/* Define UPB_TRY_ENABLE_FASTTABLE to use fasttable if possible. - * This is useful for releasing code that might be used on multiple platforms, - * for example the PHP or Ruby C extensions. */ -#elif defined(UPB_TRY_ENABLE_FASTTABLE) -#define UPB_FASTTABLE UPB_FASTTABLE_SUPPORTED -#else -#define UPB_FASTTABLE 0 -#endif - -/* UPB_FASTTABLE_INIT() allows protos compiled for fasttable to gracefully - * degrade to non-fasttable if the runtime or platform do not support it. */ -#if !UPB_FASTTABLE -#define UPB_FASTTABLE_INIT(...) -#define UPB_FASTTABLE_MASK(mask) -1 -#else -#define UPB_FASTTABLE_INIT(...) __VA_ARGS__ -#define UPB_FASTTABLE_MASK(mask) mask -#endif - -#undef UPB_FASTTABLE_SUPPORTED - -#if defined(__cplusplus) -#if defined(__clang__) || UPB_GNUC_MIN(6, 0) -// https://gcc.gnu.org/gcc-6/changes.html -#define UPB_DEPRECATED [[deprecated]] -#else -#define UPB_DEPRECATED -#endif -#else -#define UPB_DEPRECATED -#endif - -#if defined(UPB_IS_GOOGLE3) && \ - (!defined(UPB_BOOTSTRAP_STAGE) || UPB_BOOTSTRAP_STAGE != 0) -#define UPB_DESC_MINITABLE(sym) &proto2__##sym##_msg_init -#elif defined(UPB_IS_GOOGLE3) && defined(UPB_BOOTSTRAP_STAGE) && \ - UPB_BOOTSTRAP_STAGE == 0 -#define UPB_DESC_MINITABLE(sym) proto2__##sym##_msg_init() -#elif defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0 -#define UPB_DESC_MINITABLE(sym) google__protobuf__##sym##_msg_init() -#else -#define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init -#endif - -#undef UPB_IS_GOOGLE3 - -#ifdef __clang__ -#define UPB_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address"))) -#else -#define UPB_NO_SANITIZE_ADDRESS -#endif - -#if defined(__GNUC__) && (defined(__clang__) || UPB_GNUC_MIN(11, 0)) -#define UPB_RETAIN __attribute__((retain)) -#else -#define UPB_RETAIN -#endif - -// Linker arrays combine elements from multiple translation units into a single -// array that can be iterated over at runtime. -// -// It is an alternative to pre-main "registration" functions. -// -// Usage: -// -// // In N translation units. -// UPB_LINKARR_APPEND(foo_array) static int elems[3] = {1, 2, 3}; -// -// // At runtime: -// UPB_LINKARR_DECLARE(foo_array, int); -// -// void f() { -// const int* start = UPB_LINKARR_START(foo_array); -// const int* stop = UPB_LINKARR_STOP(foo_array); -// for (const int* p = start; p < stop; p++) { -// // Windows can introduce zero padding, so we have to skip zeroes. -// if (*p != 0) { -// vec.push_back(*p); -// } -// } -// } - -#if defined(__GNUC__) && !defined(__clang__) -// GCC can't handle mismatched retain attributes in the same section: -// https://github.com/protocolbuffers/protobuf/issues/26385 -// To work around this, we retain all linker array elements, even though this -// effectively disables tree-shaking of unused extensions when using GCC. -#define UPB_LINKARR_ATTR UPB_RETAIN -#else -#define UPB_LINKARR_ATTR -#endif - -#define UPB_LINKARR_SENTINEL UPB_RETAIN __attribute__((weak, used)) - -#if defined(__ELF__) || defined(__wasm__) - -#define UPB_LINKARR_APPEND(name) \ - __attribute__(( \ - section("linkarr_" #name))) UPB_LINKARR_ATTR UPB_NO_SANITIZE_ADDRESS -#define UPB_LINKARR_DECLARE(name, type) \ - extern type __start_linkarr_##name; \ - extern type __stop_linkarr_##name; \ - UPB_LINKARR_APPEND(name) \ - UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1] -#define UPB_LINKARR_START(name) (&__start_linkarr_##name) -#define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name) - -#elif defined(__MACH__) - -/* As described in: https://stackoverflow.com/a/22366882 */ -#define UPB_LINKARR_APPEND(name) \ - __attribute__(( \ - section("__DATA,__la_" #name))) UPB_LINKARR_ATTR UPB_NO_SANITIZE_ADDRESS -#define UPB_LINKARR_DECLARE(name, type) \ - extern type __start_linkarr_##name __asm( \ - "section$start$__DATA$__la_" #name); \ - extern type __stop_linkarr_##name __asm( \ - "section$end$__DATA$" \ - "__la_" #name); \ - UPB_LINKARR_APPEND(name) \ - UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1] -#define UPB_LINKARR_START(name) (&__start_linkarr_##name) -#define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name) - -#elif defined(_MSC_VER) - -/* See: - * https://devblogs.microsoft.com/oldnewthing/20181107-00/?p=100155 - * https://devblogs.microsoft.com/oldnewthing/20181108-00/?p=100165 - * https://devblogs.microsoft.com/oldnewthing/20181109-00/?p=100175 */ -#define UPB_STRINGIFY_INTERNAL(x) #x -#define UPB_STRINGIFY(x) UPB_STRINGIFY_INTERNAL(x) -#define UPB_CONCAT(a, b, c) a##b##c -#define UPB_LINKARR_NAME(name, index) \ - UPB_STRINGIFY(UPB_CONCAT(la_, name, index)) -#define UPB_LINKARR_APPEND(name) \ - __pragma(section(UPB_LINKARR_NAME(name, $j), read)) \ - __declspec(allocate(UPB_LINKARR_NAME(name, $j))) -// clang-format off -#define UPB_LINKARR_DECLARE(name, type) \ - __pragma(message(UPB_LINKARR_NAME(name, $j))) \ - __pragma(section(UPB_LINKARR_NAME(name, $a), read)) \ - __pragma(section(UPB_LINKARR_NAME(name, $z), read)) \ - __declspec(allocate(UPB_LINKARR_NAME(name, $a)), selectany) \ - type __start_linkarr_##name; \ - __declspec(allocate(UPB_LINKARR_NAME(name, $z)), selectany) \ - type __stop_linkarr_##name; \ - UPB_LINKARR_APPEND(name) \ - __declspec(selectany) type UPB_linkarr_internal_empty_##name[1] = {0} -// clang-format on -#define UPB_LINKARR_START(name) (&__start_linkarr_##name) -#define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name) - -#else - -// Linker arrays are not supported on this platform. Make macros no-ops. -#define UPB_LINKARR_APPEND(name) -#define UPB_LINKARR_DECLARE(name, type) -#define UPB_LINKARR_START(name) (NULL) -#define UPB_LINKARR_STOP(name) (NULL) - -#endif - -// Workaround for https://github.com/llvm/llvm-project/issues/167577 until it's -// fixed. Some function must exist for the constructor to work properly. -// TODO Remove this or gate it on a future version of clang. -#if defined(__clang__) && defined(__arm__) -#define _UPB_CONSTRUCTOR_PLACEHOLDER(unique_name) \ - __attribute__((used, visibility("hidden"))) void UPB_PRIVATE(unique_name)( \ - void) {} -#else -#define _UPB_CONSTRUCTOR_PLACEHOLDER(unique_name) -#endif - -#if defined(__ELF__) || defined(__wasm__) || defined(__MACH__) -#define UPB_CONSTRUCTOR(name, unique_name) \ - _UPB_CONSTRUCTOR_PLACEHOLDER(unique_name) \ - __attribute__((weak, visibility("hidden"), constructor)) void UPB_PRIVATE( \ - name)(void) -#elif defined(_MSC_VER) -/* - * See: https://stackoverflow.com/questions/1113409 - * - * The /include pragma suggested in the link above doesn't work in our case - * because it requires globally unique names. We need a different solution - * to prevent optimizers from removing the constructor. Our solution is to - * create a dummy exported weak symbol that prevent this stripping. - */ -#pragma section(".CRT$XCU", long, read) -#define UPB_CONSTRUCTOR(name, unique_name) \ - static void __cdecl UPB_PRIVATE(name)(void); \ - __declspec(allocate(".CRT$XCU"), selectany) void( \ - __cdecl * UPB_PRIVATE(name##_))(void) = UPB_PRIVATE(name); \ - __declspec(selectany, dllexport) void* UPB_PRIVATE(name##_force_linkage) = \ - &UPB_PRIVATE(name##_); \ - static void __cdecl UPB_PRIVATE(name)(void) - -#else -// No constructor support, nothing we can do except not break builds. -#define UPB_CONSTRUCTOR(name, unique_name) static void UPB_PRIVATE(name)(void) -#endif - -// -// Weak alias platform support. Theoretically this should be possible to do with -// only C using attributes like __attribute__((weak, alias("foo"))), but -// Clang doesn't support this properly on macOS. So we have to use assembly. -#if defined(__APPLE__) - -// TODO: once https://github.com/llvm/llvm-project/issues/167262 is fixed -// in the LLVM linker, we should have all weak variables point to a single -// "default" empty MiniTable instead of having each leaf define its own, like -// we do with ELF below. This will reduce binary size if many messages are tree -// shaken. -#define UPB_WEAK_SINGLETON_PLACEHOLDER_MINITABLE() -#define UPB_WEAK_PLACEHOLDER_MINITABLE(name) \ - __attribute__((weak)) const upb_MiniTable name = { \ - .UPB_PRIVATE(fields) = NULL, \ - .UPB_PRIVATE(size) = sizeof(struct upb_Message), \ - .UPB_PRIVATE(field_count) = 0, \ - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, \ - .UPB_PRIVATE(dense_below) = 0, \ - .UPB_PRIVATE(table_mask) = -1, \ - .UPB_PRIVATE(required_count) = 0, \ - }; -#define UPB_WEAK_ALIAS(type, from, to) \ - extern type to; \ - __asm__(".globl _" #to); \ - __asm__(".private_extern _" #to); \ - __asm__(".set _" #to ", _" #from); \ - __asm__(".weak_definition _" #to); -#define UPB_STRONG_ALIAS(type, from, to) \ - __asm__(".globl _" #to); \ - __asm__(".private_extern _" #to); \ - __asm__(".set _" #to ", _" #from); - -#elif defined(__ELF__) - -// On ELF, weak aliases work properly, so we can have all weak MiniTables point -// to the same empty singleton MiniTable. This reduces code size if many -// MiniTables are tree shaken. -#define UPB_WEAK_SINGLETON_PLACEHOLDER_MINITABLE() \ - __attribute__((weak)) \ - const upb_MiniTable kUpb_WeakSingletonPlaceholderMiniTable = { \ - .UPB_PRIVATE(fields) = NULL, \ - .UPB_PRIVATE(size) = sizeof(struct upb_Message), \ - .UPB_PRIVATE(field_count) = 0, \ - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, \ - .UPB_PRIVATE(dense_below) = 0, \ - .UPB_PRIVATE(table_mask) = -1, \ - .UPB_PRIVATE(required_count) = 0, \ - }; -#define UPB_WEAK_PLACEHOLDER_MINITABLE(name) -#define UPB_WEAK_ALIAS(type, from, to) \ - extern type to \ - __attribute__((weak, alias("kUpb_WeakSingletonPlaceholderMiniTable"))); -#define UPB_STRONG_ALIAS(type, from, to) \ - extern type to __attribute__((alias(#from))); - -#else -#define UPB_WEAK_SINGLETON_PLACEHOLDER_MINITABLE() -#define UPB_WEAK_PLACEHOLDER_MINITABLE(name) -#define UPB_WEAK_ALIAS(type, from, to) weak_alias_not_supported_on_this_platform -#define UPB_STRONG_ALIAS(type, from, to) \ - strong_alias_not_supported_on_this_platform -#endif - -// Future versions of upb will include breaking changes to some APIs. -// This macro can be set to enable these API changes ahead of time, so that -// user code can be updated before upgrading versions of protobuf. -#ifdef UPB_FUTURE_BREAKING_CHANGES - -// Removes non-standard clamping behavior in RepeatedContainer.pop() -// Owner: runze@ -#define UPB_FUTURE_REMOVE_POP_CLAMP 1 - -#else - -#define UPB_FUTURE_REMOVE_POP_CLAMP 0 - -#endif diff --git a/vendor/upb/port/sanitizers.h b/vendor/upb/port/sanitizers.h deleted file mode 100644 index 850f962..0000000 --- a/vendor/upb/port/sanitizers.h +++ /dev/null @@ -1,194 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_PORT_SANITIZERS_H_ -#define UPB_PORT_SANITIZERS_H_ - -#include -#include -#include - -// Must be last. -#include "upb/port/def.inc" - -// Must be inside def.inc/undef.inc -#if UPB_HWASAN -#include -#endif - -#if UPB_MSAN -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -// UPB_ARENA_SIZE_HACK depends on this struct having size 1. -typedef struct { - uint8_t state; -} upb_Xsan; - -UPB_INLINE uint8_t _upb_Xsan_NextTag(upb_Xsan *xsan) { -#if UPB_HWASAN - xsan->state++; - if (xsan->state <= UPB_HWASAN_POISON_TAG) { - xsan->state = UPB_HWASAN_POISON_TAG + 1; - } - return xsan->state; -#else - UPB_UNUSED(xsan); - return 0; -#endif -} - -enum { -#if UPB_ASAN - UPB_PRIVATE(kUpb_Asan_GuardSize) = 32, -#else - UPB_PRIVATE(kUpb_Asan_GuardSize) = 0, -#endif -}; - -UPB_INLINE uint8_t UPB_PRIVATE(_upb_Xsan_GetTag)(const void *addr) { -#if UPB_HWASAN - return __hwasan_get_tag_from_pointer(addr); -#else - UPB_UNUSED(addr); - return 0; -#endif -} - -UPB_INLINE void UPB_PRIVATE(upb_Xsan_Init)(upb_Xsan *xsan) { -#if UPB_HWASAN || UPB_TSAN - xsan->state = 0; -#else - UPB_UNUSED(xsan); -#endif -} - -UPB_INLINE void UPB_PRIVATE(upb_Xsan_MarkInitialized)(void* addr, size_t size) { -#if UPB_HAS_FEATURE(memory_sanitizer) - if (size) { - __msan_unpoison(addr, size); - } -#else - UPB_UNUSED(addr); - UPB_UNUSED(size); -#endif -} - -// Marks the given region as poisoned, meaning that it is not accessible until -// it is unpoisoned. -UPB_INLINE void UPB_PRIVATE(upb_Xsan_PoisonRegion)(const void *addr, - size_t size) { -#if UPB_ASAN - void __asan_poison_memory_region(void const volatile *addr, size_t size); - __asan_poison_memory_region(addr, size); -#elif UPB_HWASAN - __hwasan_tag_memory(addr, UPB_HWASAN_POISON_TAG, UPB_ALIGN_MALLOC(size)); -#else - UPB_UNUSED(addr); - UPB_UNUSED(size); -#endif -} - -UPB_INLINE void *UPB_PRIVATE(_upb_Xsan_UnpoisonRegion)(void *addr, size_t size, - uint8_t tag) { -#if UPB_ASAN - UPB_UNUSED(tag); - void __asan_unpoison_memory_region(void const volatile *addr, size_t size); - __asan_unpoison_memory_region(addr, size); - return addr; -#elif UPB_HWASAN - __hwasan_tag_memory(addr, tag, UPB_ALIGN_MALLOC(size)); - return __hwasan_tag_pointer(addr, tag); -#else - UPB_UNUSED(size); - UPB_UNUSED(tag); - - // `addr` is the pointer that will be returned from arena alloc/realloc - // functions. In this code-path we know it must be non-NULL, but the compiler - // doesn't know this unless we add a UPB_ASSUME() annotation. - // - // This will let the optimizer optimize away NULL-checks if it can see that - // this path was taken. - UPB_ASSUME(addr); - return addr; -#endif -} - -// Allows users to read and write to the given region, which will be considered -// distinct from other regions and may only be accessed through the returned -// pointer. -// -// `addr` must be aligned to the malloc alignment. Size may be unaligned, -// and with ASAN we can respect `size` precisely, but with HWASAN we must -// round `size` up to the next multiple of the malloc alignment, so the caller -// must guarantee that rounding up `size` will not cause overlap with other -// regions. -UPB_INLINE void *UPB_PRIVATE(upb_Xsan_NewUnpoisonedRegion)(upb_Xsan *xsan, - void *addr, - size_t size) { - return UPB_PRIVATE(_upb_Xsan_UnpoisonRegion)(addr, size, - _upb_Xsan_NextTag(xsan)); -} - -// Resizes the given region to a new size, *without* invalidating any existing -// pointers to the region. -// -// `tagged_addr` must be a pointer that was previously returned from -// `upb_Xsan_NewUnpoisonedRegion`. `old_size` must be the size that was -// originally passed to `upb_Xsan_NewUnpoisonedRegion`. -UPB_INLINE void *UPB_PRIVATE(upb_Xsan_ResizeUnpoisonedRegion)(void *tagged_addr, - size_t old_size, - size_t new_size) { - UPB_PRIVATE(upb_Xsan_PoisonRegion)(tagged_addr, old_size); - return UPB_PRIVATE(_upb_Xsan_UnpoisonRegion)( - tagged_addr, new_size, UPB_PRIVATE(_upb_Xsan_GetTag)(tagged_addr)); -} - -// Compares two pointers and returns true if they are equal. This returns the -// correct result even if one or both of the pointers are tagged. -UPB_INLINE bool UPB_PRIVATE(upb_Xsan_PtrEq)(const void *a, const void *b) { -#if UPB_HWASAN - return __hwasan_tag_pointer(a, 0) == __hwasan_tag_pointer(b, 0); -#else - return a == b; -#endif -} - -// These annotations improve TSAN's ability to detect data races. By -// proactively accessing a non-atomic variable at the point where it is -// "logically" accessed, we can trigger TSAN diagnostics that might have -// otherwise been masked by subsequent atomic operations. - -UPB_INLINE void UPB_PRIVATE(upb_Xsan_AccessReadOnly)(upb_Xsan *xsan) { -#if UPB_TSAN - // For performance we avoid using a volatile variable. - __asm__ volatile("" ::"r"(xsan->state)); -#else - UPB_UNUSED(xsan); -#endif -} - -UPB_INLINE void UPB_PRIVATE(upb_Xsan_AccessReadWrite)(upb_Xsan *xsan) { -#if UPB_TSAN - // For performance we avoid using a volatile variable. - __asm__ volatile("" : "+r"(xsan->state)); -#else - UPB_UNUSED(xsan); -#endif -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_PORT_SANITIZERS_H_ diff --git a/vendor/upb/port/undef.inc b/vendor/upb/port/undef.inc deleted file mode 100644 index ca448c5..0000000 --- a/vendor/upb/port/undef.inc +++ /dev/null @@ -1,92 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// This should #undef all macros #defined in def.inc - -#undef UPB_SIZE -#undef UPB_PTR_AT -#undef UPB_SIZEOF_FLEX -#undef UPB_SIZEOF_FLEX_WOULD_OVERFLOW -#undef UPB_MAPTYPE_STRING -#undef UPB_EXPORT -#undef UPB_INLINE -#undef UPB_API -#undef UPBC_API -#undef UPB_API_INLINE -#undef UPB_API_INLINE_IF_NOT_GCC -#undef UPB_ALIGN_UP -#undef UPB_ALIGN_DOWN -#undef UPB_ALIGN_MALLOC -#undef UPB_ALIGN_OF -#undef UPB_ALIGN_AS -#undef UPB_STATIC_ASSERT -#undef UPB_STATIC_ASSERT_CONCAT -#undef UPB_STATIC_ASSERT_CONCAT_IMPL -#undef UPB_LIKELY -#undef UPB_UNLIKELY -#undef UPB_UNPREDICTABLE -#undef UPB_FORCEINLINE -#undef UPB_NOINLINE -#undef UPB_NORETURN -#undef UPB_PRINTF -#undef UPB_NODEREF -#undef UPB_NODISCARD -#undef UPB_MAX -#undef UPB_MIN -#undef UPB_UNUSED -#undef UPB_ASSUME -#undef UPB_ASSERT -#undef UPB_UNREACHABLE -#undef UPB_DEFAULT_MAX_BLOCK_SIZE -#undef UPB_SETJMP -#undef UPB_LONGJMP -#undef UPB_PTRADD -#undef UPB_MUSTTAIL -#undef UPB_PRESERVE_MOST -#undef UPB_PRESERVE_NONE -#undef UPB_FASTTABLE_SUPPORTED -#undef UPB_FASTTABLE_MASK -#undef UPB_FASTTABLE -#undef UPB_FASTTABLE_INIT -#undef UPB_POISON_MEMORY_REGION -#undef UPB_UNPOISON_MEMORY_REGION -#undef UPB_ASAN -#undef UPB_HWASAN -#undef UPB_HWASAN_POISON_TAG -#undef UPB_MSAN -#undef UPB_MALLOC_ALIGN -#undef UPB_TSAN -#undef UPB_DEPRECATED -#undef UPB_GNUC_MIN -#undef UPB_DESCRIPTOR_UPB_H_FILENAME -#undef UPB_DESC_MINITABLE -#undef UPB_IS_GOOGLE3 -#undef UPB_ATOMIC -#undef UPB_USE_C11_ATOMICS -#undef UPB_USE_MSC_ATOMICS -#undef UPB_PRIVATE -#undef UPB_ONLYBITS -#undef UPB_LINKARR_DECLARE -#undef UPB_LINKARR_APPEND -#undef UPB_LINKARR_START -#undef UPB_LINKARR_STOP -#undef UPB_FUTURE_BREAKING_CHANGES -#undef UPB_FUTURE_REMOVE_POP_CLAMP -#undef UPB_HAS_ATTRIBUTE -#undef UPB_HAS_CPP_ATTRIBUTE -#undef UPB_HAS_BUILTIN -#undef UPB_HAS_EXTENSION -#undef UPB_HAS_FEATURE -#undef UPB_XSAN_MEMBER -#undef UPB_XSAN -#undef UPB_XSAN_STRUCT_SIZE -#undef UPB_ENABLE_REF_CYCLE_CHECKS -#undef UPB_ARM64_ASM -#undef UPB_ARM64_BTI_DEFAULT -#undef UPB_DEPRECATE_AND_INLINE -#undef UPB_MAYBE_ASSUME -#undef UPB_ATTR_CONST diff --git a/vendor/upb/port/vsnprintf_compat.h b/vendor/upb/port/vsnprintf_compat.h deleted file mode 100644 index 1f6c644..0000000 --- a/vendor/upb/port/vsnprintf_compat.h +++ /dev/null @@ -1,30 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_PORT_VSNPRINTF_COMPAT_H_ -#define UPB_PORT_VSNPRINTF_COMPAT_H_ - -// Must be last. -#include "upb/port/def.inc" - -UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, - va_list ap) { -#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER) - // The msvc runtime has a non-conforming vsnprintf() that requires the - // following compatibility code to become conformant. - int n = -1; - if (size != 0) n = _vsnprintf_s(buf, size, _TRUNCATE, fmt, ap); - if (n == -1) n = _vscprintf(fmt, ap); - return n; -#else - return vsnprintf(buf, size, fmt, ap); -#endif -} - -#include "upb/port/undef.inc" - -#endif // UPB_PORT_VSNPRINTF_COMPAT_H_ diff --git a/vendor/upb/protobuf b/vendor/upb/protobuf deleted file mode 120000 index 779a5a3..0000000 --- a/vendor/upb/protobuf +++ /dev/null @@ -1 +0,0 @@ -protobuf \ No newline at end of file diff --git a/vendor/upb/reflection/BUILD b/vendor/upb/reflection/BUILD deleted file mode 100644 index a980f8c..0000000 --- a/vendor/upb/reflection/BUILD +++ /dev/null @@ -1,251 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load( - "//editions:defaults.bzl", - "compile_edition_defaults", - "embed_edition_defaults", -) -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") -load( - "//upb/cmake:build_defs.bzl", - "staleness_test", -) -load( - "//upb_generator:bootstrap_compiler.bzl", - "bootstrap_cc_library", - "bootstrap_upb_proto_library", -) - -package(default_applicable_licenses = ["//:license"]) - -bootstrap_upb_proto_library( - name = "descriptor_upb_proto", - bootstrap_hdr = "descriptor_bootstrap.h", - proto_lib_deps = ["//:descriptor_proto"], - src_files = ["google/protobuf/descriptor.proto"], - src_rules = ["//:descriptor_proto_srcs"], - strip_prefix = "third_party/protobuf/github/bootstrap/src", -) - -bootstrap_cc_library( - name = "reflection", - hdrs = [ - "def.h", - "def.hpp", - "message.h", - "message.hpp", - ], - bootstrap_deps = [ - ":internal", - ":descriptor_upb_proto", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/message:internal", - "//upb/mini_descriptor", - "//upb/mini_table", - "//upb/port", - ], -) - -bootstrap_cc_library( - name = "internal", - srcs = [ - "def_pool.c", - "def_type.c", - "desc_state.c", - "enum_def.c", - "enum_reserved_range.c", - "enum_value_def.c", - "extension_range.c", - "field_def.c", - "file_def.c", - "internal/def_builder.c", - "internal/def_builder.h", - "internal/strdup2.c", - "internal/strdup2.h", - "message.c", - "message_def.c", - "message_reserved_range.c", - "method_def.c", - "oneof_def.c", - "service_def.c", - ], - hdrs = [ - "common.h", - "def.h", - "def.hpp", - "def_pool.h", - "def_type.h", - "enum_def.h", - "enum_reserved_range.h", - "enum_value_def.h", - "extension_range.h", - "field_def.h", - "file_def.h", - "internal/def_pool.h", - "internal/desc_state.h", - "internal/enum_def.h", - "internal/enum_reserved_range.h", - "internal/enum_value_def.h", - "internal/extension_range.h", - "internal/field_def.h", - "internal/file_def.h", - "internal/message_def.h", - "internal/message_reserved_range.h", - "internal/method_def.h", - "internal/oneof_def.h", - "internal/service_def.h", - "internal/upb_edition_defaults.h", - "message.h", - "message.hpp", - "message_def.h", - "message_reserved_range.h", - "method_def.h", - "oneof_def.h", - "service_def.h", - ], - bootstrap_deps = [":descriptor_upb_proto"], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/base:internal", - "//upb/hash", - "//upb/mem", - "//upb/message", - "//upb/message:copy", - "//upb/message:internal", - "//upb/mini_descriptor", - "//upb/mini_descriptor:internal", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/wire", - ], -) - -cc_library( - name = "generated_reflection_support", - hdrs = [ - "def.h", - "internal/def_pool.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - textual_hdrs = [ - "//upb/port:inc", - ], - visibility = ["//upb:friends"], - deps = [ - ":internal", - "//upb/mini_descriptor", - "//upb/mini_table", - ], -) - -cc_test( - name = "def_builder_test", - srcs = [ - "common.h", - "def_type.h", - "internal/def_builder.h", - "internal/def_builder_test.cc", - ], - deps = [ - ":descriptor_upb_proto", - ":internal", - ":reflection", - "//upb/base", - "//upb/hash", - "//upb/mem", - "//upb/mini_descriptor", - "//upb/mini_table", - "//upb/port", - "@abseil-cpp//absl/strings", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "reflection_test", - srcs = [ - "reflection_test.cc", - ], - deps = [ - ":internal", - ":reflection", - "//src/google/protobuf", - "//src/google/protobuf:descriptor_upb_c_proto", - "//src/google/protobuf:unittest_upb_reflection_proto", - "//upb/base", - "//upb/mem", - "//upb/test:parse_text_proto", - "@abseil-cpp//absl/log:absl_check", - "@abseil-cpp//absl/log:check", - "@abseil-cpp//absl/status", - "@abseil-cpp//absl/status:statusor", - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:str_format", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -compile_edition_defaults( - name = "upb_edition_defaults", - srcs = [ - "//:descriptor_proto", - ], - maximum_edition = "2024", - minimum_edition = "PROTO2", -) - -embed_edition_defaults( - name = "embedded_upb_edition_defaults_generate", - defaults = "upb_edition_defaults", - output = "generated/internal/upb_edition_defaults.h", - placeholder = "DEFAULTS_VALUE", - template = "internal/upb_edition_defaults.h.template", -) - -staleness_test( - name = "bootstrap_upb_defaults_staleness_test", - outs = ["internal/upb_edition_defaults.h"], - generated_pattern = "generated/%s", - tags = ["manual"], - target_files = ["internal/upb_edition_defaults.h"], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - "**/*.hpp", - ], - exclude = [ - "stage0/**", - "cmake/**", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) diff --git a/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb.h b/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb.h deleted file mode 100644 index 512a2de..0000000 --- a/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb.h +++ /dev/null @@ -1,7819 +0,0 @@ -/* This file was generated by upb_generator from the input file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. - * NO CHECKED-IN PROTOBUF GENCODE */ - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_ -#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_ - -#include "upb/generated_code_support.h" -#include "google/protobuf/descriptor.upb_minitable.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif -typedef struct google_protobuf_FileDescriptorSet { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FileDescriptorSet; - -typedef struct google_protobuf_FileDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FileDescriptorProto; - -typedef struct google_protobuf_DescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_DescriptorProto; - -typedef struct google_protobuf_DescriptorProto_ExtensionRange { - upb_Message UPB_PRIVATE(base); -} google_protobuf_DescriptorProto_ExtensionRange; - -typedef struct google_protobuf_DescriptorProto_ReservedRange { - upb_Message UPB_PRIVATE(base); -} google_protobuf_DescriptorProto_ReservedRange; - -typedef struct google_protobuf_ExtensionRangeOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ExtensionRangeOptions; - -typedef struct google_protobuf_ExtensionRangeOptions_Declaration { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ExtensionRangeOptions_Declaration; - -typedef struct google_protobuf_FieldDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldDescriptorProto; - -typedef struct google_protobuf_OneofDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_OneofDescriptorProto; - -typedef struct google_protobuf_EnumDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumDescriptorProto; - -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumDescriptorProto_EnumReservedRange; - -typedef struct google_protobuf_EnumValueDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumValueDescriptorProto; - -typedef struct google_protobuf_ServiceDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ServiceDescriptorProto; - -typedef struct google_protobuf_MethodDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_MethodDescriptorProto; - -typedef struct google_protobuf_FileOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FileOptions; - -typedef struct google_protobuf_MessageOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_MessageOptions; - -typedef struct google_protobuf_FieldOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldOptions; - -typedef struct google_protobuf_FieldOptions_EditionDefault { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldOptions_EditionDefault; - -typedef struct google_protobuf_FieldOptions_FeatureSupport { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldOptions_FeatureSupport; - -typedef struct google_protobuf_OneofOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_OneofOptions; - -typedef struct google_protobuf_EnumOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumOptions; - -typedef struct google_protobuf_EnumValueOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumValueOptions; - -typedef struct google_protobuf_ServiceOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ServiceOptions; - -typedef struct google_protobuf_MethodOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_MethodOptions; - -typedef struct google_protobuf_UninterpretedOption { - upb_Message UPB_PRIVATE(base); -} google_protobuf_UninterpretedOption; - -typedef struct google_protobuf_UninterpretedOption_NamePart { - upb_Message UPB_PRIVATE(base); -} google_protobuf_UninterpretedOption_NamePart; - -typedef struct google_protobuf_FeatureSet { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSet; - -typedef struct google_protobuf_FeatureSet_VisibilityFeature { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSet_VisibilityFeature; - -typedef struct google_protobuf_FeatureSetDefaults { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSetDefaults; - -typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; - -typedef struct google_protobuf_SourceCodeInfo { - upb_Message UPB_PRIVATE(base); -} google_protobuf_SourceCodeInfo; - -typedef struct google_protobuf_SourceCodeInfo_Location { - upb_Message UPB_PRIVATE(base); -} google_protobuf_SourceCodeInfo_Location; - -typedef struct google_protobuf_GeneratedCodeInfo { - upb_Message UPB_PRIVATE(base); -} google_protobuf_GeneratedCodeInfo; - -typedef struct google_protobuf_GeneratedCodeInfo_Annotation { - upb_Message UPB_PRIVATE(base); -} google_protobuf_GeneratedCodeInfo_Annotation; - - -typedef enum { - google_protobuf_EDITION_UNKNOWN = 0, - google_protobuf_EDITION_1_TEST_ONLY = 1, - google_protobuf_EDITION_2_TEST_ONLY = 2, - google_protobuf_EDITION_LEGACY = 900, - google_protobuf_EDITION_PROTO2 = 998, - google_protobuf_EDITION_PROTO3 = 999, - google_protobuf_EDITION_2023 = 1000, - google_protobuf_EDITION_2024 = 1001, - google_protobuf_EDITION_2026 = 1002, - google_protobuf_EDITION_UNSTABLE = 9999, - google_protobuf_EDITION_99997_TEST_ONLY = 99997, - google_protobuf_EDITION_99998_TEST_ONLY = 99998, - google_protobuf_EDITION_99999_TEST_ONLY = 99999, - google_protobuf_EDITION_MAX = 2147483647 -} google_protobuf_Edition; - -typedef enum { - google_protobuf_ExtensionRangeOptions_DECLARATION = 0, - google_protobuf_ExtensionRangeOptions_UNVERIFIED = 1 -} google_protobuf_ExtensionRangeOptions_VerificationState; - -typedef enum { - google_protobuf_FeatureSet_ENFORCE_NAMING_STYLE_UNKNOWN = 0, - google_protobuf_FeatureSet_STYLE2024 = 1, - google_protobuf_FeatureSet_STYLE_LEGACY = 2, - google_protobuf_FeatureSet_STYLE2026 = 3 -} google_protobuf_FeatureSet_EnforceNamingStyle; - -typedef enum { - google_protobuf_FeatureSet_ENUM_TYPE_UNKNOWN = 0, - google_protobuf_FeatureSet_OPEN = 1, - google_protobuf_FeatureSet_CLOSED = 2 -} google_protobuf_FeatureSet_EnumType; - -typedef enum { - google_protobuf_FeatureSet_FIELD_PRESENCE_UNKNOWN = 0, - google_protobuf_FeatureSet_EXPLICIT = 1, - google_protobuf_FeatureSet_IMPLICIT = 2, - google_protobuf_FeatureSet_LEGACY_REQUIRED = 3 -} google_protobuf_FeatureSet_FieldPresence; - -typedef enum { - google_protobuf_FeatureSet_JSON_FORMAT_UNKNOWN = 0, - google_protobuf_FeatureSet_ALLOW = 1, - google_protobuf_FeatureSet_LEGACY_BEST_EFFORT = 2 -} google_protobuf_FeatureSet_JsonFormat; - -typedef enum { - google_protobuf_FeatureSet_MESSAGE_ENCODING_UNKNOWN = 0, - google_protobuf_FeatureSet_LENGTH_PREFIXED = 1, - google_protobuf_FeatureSet_DELIMITED = 2 -} google_protobuf_FeatureSet_MessageEncoding; - -typedef enum { - google_protobuf_FeatureSet_REPEATED_FIELD_ENCODING_UNKNOWN = 0, - google_protobuf_FeatureSet_PACKED = 1, - google_protobuf_FeatureSet_EXPANDED = 2 -} google_protobuf_FeatureSet_RepeatedFieldEncoding; - -typedef enum { - google_protobuf_FeatureSet_UTF8_VALIDATION_UNKNOWN = 0, - google_protobuf_FeatureSet_VERIFY = 2, - google_protobuf_FeatureSet_NONE = 3 -} google_protobuf_FeatureSet_Utf8Validation; - -typedef enum { - google_protobuf_FeatureSet_VisibilityFeature_DEFAULT_SYMBOL_VISIBILITY_UNKNOWN = 0, - google_protobuf_FeatureSet_VisibilityFeature_EXPORT_ALL = 1, - google_protobuf_FeatureSet_VisibilityFeature_EXPORT_TOP_LEVEL = 2, - google_protobuf_FeatureSet_VisibilityFeature_LOCAL_ALL = 3, - google_protobuf_FeatureSet_VisibilityFeature_STRICT = 4 -} google_protobuf_FeatureSet_VisibilityFeature_DefaultSymbolVisibility; - -typedef enum { - google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, - google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, - google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3 -} google_protobuf_FieldDescriptorProto_Label; - -typedef enum { - google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1, - google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2, - google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3, - google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4, - google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5, - google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6, - google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7, - google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8, - google_protobuf_FieldDescriptorProto_TYPE_STRING = 9, - google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10, - google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11, - google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12, - google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13, - google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16, - google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17, - google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18 -} google_protobuf_FieldDescriptorProto_Type; - -typedef enum { - google_protobuf_FieldOptions_STRING = 0, - google_protobuf_FieldOptions_CORD = 1, - google_protobuf_FieldOptions_STRING_PIECE = 2 -} google_protobuf_FieldOptions_CType; - -typedef enum { - google_protobuf_FieldOptions_JS_NORMAL = 0, - google_protobuf_FieldOptions_JS_STRING = 1, - google_protobuf_FieldOptions_JS_NUMBER = 2 -} google_protobuf_FieldOptions_JSType; - -typedef enum { - google_protobuf_FieldOptions_RETENTION_UNKNOWN = 0, - google_protobuf_FieldOptions_RETENTION_RUNTIME = 1, - google_protobuf_FieldOptions_RETENTION_SOURCE = 2 -} google_protobuf_FieldOptions_OptionRetention; - -typedef enum { - google_protobuf_FieldOptions_TARGET_TYPE_UNKNOWN = 0, - google_protobuf_FieldOptions_TARGET_TYPE_FILE = 1, - google_protobuf_FieldOptions_TARGET_TYPE_EXTENSION_RANGE = 2, - google_protobuf_FieldOptions_TARGET_TYPE_MESSAGE = 3, - google_protobuf_FieldOptions_TARGET_TYPE_FIELD = 4, - google_protobuf_FieldOptions_TARGET_TYPE_ONEOF = 5, - google_protobuf_FieldOptions_TARGET_TYPE_ENUM = 6, - google_protobuf_FieldOptions_TARGET_TYPE_ENUM_ENTRY = 7, - google_protobuf_FieldOptions_TARGET_TYPE_SERVICE = 8, - google_protobuf_FieldOptions_TARGET_TYPE_METHOD = 9 -} google_protobuf_FieldOptions_OptionTargetType; - -typedef enum { - google_protobuf_FileOptions_SPEED = 1, - google_protobuf_FileOptions_CODE_SIZE = 2, - google_protobuf_FileOptions_LITE_RUNTIME = 3 -} google_protobuf_FileOptions_OptimizeMode; - -typedef enum { - google_protobuf_GeneratedCodeInfo_Annotation_NONE = 0, - google_protobuf_GeneratedCodeInfo_Annotation_SET = 1, - google_protobuf_GeneratedCodeInfo_Annotation_ALIAS = 2 -} google_protobuf_GeneratedCodeInfo_Annotation_Semantic; - -typedef enum { - google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0, - google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1, - google_protobuf_MethodOptions_IDEMPOTENT = 2 -} google_protobuf_MethodOptions_IdempotencyLevel; - -typedef enum { - google_protobuf_VISIBILITY_UNSET = 0, - google_protobuf_VISIBILITY_LOCAL = 1, - google_protobuf_VISIBILITY_EXPORT = 2 -} google_protobuf_SymbolVisibility; - - - -/* google.protobuf.FileDescriptorSet */ -UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorSet*)_upb_Message_New(&google__protobuf__FileDescriptorSet_msg_init, arena); -} -UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, - size_t* size) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FileDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array( - const google_protobuf_FileDescriptorSet* msg, size_t* size) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( - google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, - size_t* size) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FileDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileDescriptorProto_msg_init); - return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file( - google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FileDescriptorProto* sub = - (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google__protobuf__FileDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.FileDescriptorProto */ -UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorProto*)_upb_Message_New(&google__protobuf__FileDescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(56, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(56, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(56, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(64, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {2, UPB_SIZE(64, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(64, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_ServiceDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(32, 104), 66, UPB_SIZE(25, 29), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { - const google_protobuf_FileOptions* default_val = NULL; - const google_protobuf_FileOptions* ret; - const upb_MiniTableField field = {8, UPB_SIZE(32, 104), 66, UPB_SIZE(25, 29), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(32, 104), 66, UPB_SIZE(25, 29), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {9, UPB_SIZE(36, 112), 67, UPB_SIZE(23, 28), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - const google_protobuf_SourceCodeInfo* default_val = NULL; - const google_protobuf_SourceCodeInfo* ret; - const upb_MiniTableField field = {9, UPB_SIZE(36, 112), 67, UPB_SIZE(23, 28), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {9, UPB_SIZE(36, 112), 67, UPB_SIZE(23, 28), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {12, UPB_SIZE(72, 48), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {12, UPB_SIZE(72, 48), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {12, UPB_SIZE(72, 48), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {14, UPB_SIZE(48, 12), 69, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {14, UPB_SIZE(48, 12), 69, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {14, UPB_SIZE(48, 12), 69, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_option_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_option_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_option_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_option_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(56, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {2, UPB_SIZE(64, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto* sub = - (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumDescriptorProto* sub = - (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_ServiceDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceDescriptorProto_msg_init); - return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_ServiceDescriptorProto* sub = - (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google__protobuf__ServiceDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldDescriptorProto* sub = - (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto* msg, google_protobuf_FileOptions* value) { - const upb_MiniTableField field = {8, UPB_SIZE(32, 104), 66, UPB_SIZE(25, 29), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FileOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FileOptions*)_upb_Message_New(&google__protobuf__FileOptions_msg_init, arena); - if (sub) google_protobuf_FileDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto* msg, google_protobuf_SourceCodeInfo* value) { - const upb_MiniTableField field = {9, UPB_SIZE(36, 112), 67, UPB_SIZE(23, 28), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); - if (sub == NULL) { - sub = (struct google_protobuf_SourceCodeInfo*)_upb_Message_New(&google__protobuf__SourceCodeInfo_msg_init, arena); - if (sub) google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub); - } - return sub; -} -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {12, UPB_SIZE(72, 48), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {14, UPB_SIZE(48, 12), 69, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_option_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_option_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_option_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} - -/* google.protobuf.DescriptorProto */ -UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(52, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(52, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(52, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ExtensionRange_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto_ExtensionRange* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ExtensionRange_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ExtensionRange_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(32, 72), 65, UPB_SIZE(20, 26), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { - const google_protobuf_MessageOptions* default_val = NULL; - const google_protobuf_MessageOptions* ret; - const upb_MiniTableField field = {7, UPB_SIZE(32, 72), 65, UPB_SIZE(20, 26), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MessageOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(32, 72), 65, UPB_SIZE(20, 26), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_OneofDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ReservedRange_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto_ReservedRange* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ReservedRange_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ReservedRange_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_visibility(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(48, 12), 66, UPB_SIZE(11, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_visibility(const google_protobuf_DescriptorProto* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {11, UPB_SIZE(48, 12), 66, UPB_SIZE(11, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_has_visibility(const google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(48, 12), 66, UPB_SIZE(11, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(52, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldDescriptorProto* sub = - (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto* sub = - (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumDescriptorProto* sub = - (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ExtensionRange_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ExtensionRange_msg_init); - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ExtensionRange_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto_ExtensionRange* sub = - (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ExtensionRange_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldDescriptorProto* sub = - (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto* msg, google_protobuf_MessageOptions* value) { - const upb_MiniTableField field = {7, UPB_SIZE(32, 72), 65, UPB_SIZE(20, 26), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MessageOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_MessageOptions*)_upb_Message_New(&google__protobuf__MessageOptions_msg_init, arena); - if (sub) google_protobuf_DescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_OneofDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofDescriptorProto_msg_init); - return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_OneofDescriptorProto* sub = - (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google__protobuf__OneofDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ReservedRange_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ReservedRange_msg_init); - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__DescriptorProto__ReservedRange_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto_ReservedRange* sub = - (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ReservedRange_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_DescriptorProto_set_visibility(google_protobuf_DescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {11, UPB_SIZE(48, 12), 66, UPB_SIZE(11, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.DescriptorProto.ExtensionRange */ -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ExtensionRange_msg_init, arena); -} -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(20, 24), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const google_protobuf_ExtensionRangeOptions* default_val = NULL; - const google_protobuf_ExtensionRangeOptions* ret; - const upb_MiniTableField field = {3, UPB_SIZE(20, 24), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(20, 24), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange* msg, int32_t value) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange* msg, int32_t value) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange* msg, google_protobuf_ExtensionRangeOptions* value) { - const upb_MiniTableField field = {3, UPB_SIZE(20, 24), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options( - google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { - struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google__protobuf__ExtensionRangeOptions_msg_init, arena); - if (sub) google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.DescriptorProto.ReservedRange */ -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ReservedRange_msg_init, arena); -} -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange* msg, int32_t value) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange* msg, int32_t value) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.ExtensionRangeOptions */ -UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_new(upb_Arena* arena) { - return (google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google__protobuf__ExtensionRangeOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_upb_array( - const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array( - google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 64, UPB_SIZE(10, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 64, UPB_SIZE(10, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 64, UPB_SIZE(10, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 24), 65, UPB_SIZE(8, 10), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {50, UPB_SIZE(20, 24), 65, UPB_SIZE(8, 10), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 24), 65, UPB_SIZE(8, 10), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_upb_array( - const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - upb_MiniTableField field = {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_resize_declaration(google_protobuf_ExtensionRangeOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init); - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration( - google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_ExtensionRangeOptions_Declaration* sub = - (struct google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions* msg, int32_t value) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 64, UPB_SIZE(10, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_features(google_protobuf_ExtensionRangeOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 24), 65, UPB_SIZE(8, 10), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_mutable_features( - google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ExtensionRangeOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_ExtensionRangeOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option( - google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.ExtensionRangeOptions.Declaration */ -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_new(upb_Arena* arena) { - return (google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init, arena); -} -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize(const google_protobuf_ExtensionRangeOptions_Declaration* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex(const google_protobuf_ExtensionRangeOptions_Declaration* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(24, 32), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {3, UPB_SIZE(24, 32), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(24, 32), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {5, 9, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {5, 9, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {5, 9, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {6, 10, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {6, 10, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = {6, 10, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration* msg, int32_t value) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_StringView value) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_type(google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_StringView value) { - const upb_MiniTableField field = {3, UPB_SIZE(24, 32), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg, bool value) { - const upb_MiniTableField field = {5, 9, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg, bool value) { - const upb_MiniTableField field = {6, 10, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FieldDescriptorProto */ -UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {1, 32, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, 32, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {1, 32, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(40, 48), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {2, UPB_SIZE(40, 48), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(40, 48), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {3, 12, 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {3, 12, 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {3, 12, 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {4, 16, 67, UPB_SIZE(24, 25), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = {4, 16, 67, UPB_SIZE(24, 25), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {4, 16, 67, UPB_SIZE(24, 25), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {5, 20, 68, UPB_SIZE(22, 24), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = {5, 20, 68, UPB_SIZE(22, 24), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {5, 20, 68, UPB_SIZE(22, 24), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(48, 64), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {6, UPB_SIZE(48, 64), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(48, 64), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(56, 80), 70, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {7, UPB_SIZE(56, 80), 70, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(56, 80), 70, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(24, 112), 71, UPB_SIZE(14, 17), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { - const google_protobuf_FieldOptions* default_val = NULL; - const google_protobuf_FieldOptions* ret; - const upb_MiniTableField field = {8, UPB_SIZE(24, 112), 71, UPB_SIZE(14, 17), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(24, 112), 71, UPB_SIZE(14, 17), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {9, UPB_SIZE(28, 24), 72, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {9, UPB_SIZE(28, 24), 72, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {9, UPB_SIZE(28, 24), 72, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {10, UPB_SIZE(64, 96), 73, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {10, UPB_SIZE(64, 96), 73, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {10, UPB_SIZE(64, 96), 73, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {17, 10, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {17, 10, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = {17, 10, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, 32, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {2, UPB_SIZE(40, 48), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {3, 12, 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {4, 16, 67, UPB_SIZE(24, 25), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {5, 20, 68, UPB_SIZE(22, 24), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {6, UPB_SIZE(48, 64), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {7, UPB_SIZE(56, 80), 70, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto* msg, google_protobuf_FieldOptions* value) { - const upb_MiniTableField field = {8, UPB_SIZE(24, 112), 71, UPB_SIZE(14, 17), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options( - google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions*)_upb_Message_New(&google__protobuf__FieldOptions_msg_init, arena); - if (sub) google_protobuf_FieldDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {9, UPB_SIZE(28, 24), 72, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {10, UPB_SIZE(64, 96), 73, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto* msg, bool value) { - const upb_MiniTableField field = {17, 10, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.OneofDescriptorProto */ -UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google__protobuf__OneofDescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 65, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { - const google_protobuf_OneofOptions* default_val = NULL; - const google_protobuf_OneofOptions* ret; - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 65, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 65, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto* msg, google_protobuf_OneofOptions* value) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 65, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__OneofOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options( - google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_OneofOptions*)_upb_Message_New(&google__protobuf__OneofOptions_msg_init, arena); - if (sub) google_protobuf_OneofDescriptorProto_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.EnumDescriptorProto */ -UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(32, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(32, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(32, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumValueDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array( - const google_protobuf_EnumDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array( - google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(13, 14), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { - const google_protobuf_EnumOptions* default_val = NULL; - const google_protobuf_EnumOptions* ret; - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(13, 14), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(13, 14), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_upb_array( - const google_protobuf_EnumDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array( - google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_upb_array( - const google_protobuf_EnumDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array( - google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_visibility(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(28, 12), 66, UPB_SIZE(6, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_visibility(const google_protobuf_EnumDescriptorProto* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {6, UPB_SIZE(28, 12), 66, UPB_SIZE(6, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_visibility(const google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(28, 12), 66, UPB_SIZE(6, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(32, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumValueDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueDescriptorProto_msg_init); - return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value( - google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumValueDescriptorProto* sub = - (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google__protobuf__EnumValueDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto* msg, google_protobuf_EnumOptions* value) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(13, 14), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options( - google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_EnumOptions*)_upb_Message_New(&google__protobuf__EnumOptions_msg_init, arena); - if (sub) google_protobuf_EnumDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init); - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range( - google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = - (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_visibility(google_protobuf_EnumDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {6, UPB_SIZE(28, 12), 66, UPB_SIZE(6, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.EnumDescriptorProto.EnumReservedRange */ -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, arena); -} -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int32_t value) { - const upb_MiniTableField field = {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int32_t value) { - const upb_MiniTableField field = {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.EnumValueDescriptorProto */ -UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google__protobuf__EnumValueDescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = {2, 12, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {2, 12, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = {2, 12, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 32), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { - const google_protobuf_EnumValueOptions* default_val = NULL; - const google_protobuf_EnumValueOptions* ret; - const upb_MiniTableField field = {3, UPB_SIZE(16, 32), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 32), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = {2, 12, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto* msg, google_protobuf_EnumValueOptions* value) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 32), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__EnumValueOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options( - google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_EnumValueOptions*)_upb_Message_New(&google__protobuf__EnumValueOptions_msg_init, arena); - if (sub) google_protobuf_EnumValueDescriptorProto_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.ServiceDescriptorProto */ -UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google__protobuf__ServiceDescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_MethodDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_array( - const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodDescriptorProto_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array( - google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { - const google_protobuf_ServiceOptions* default_val = NULL; - const google_protobuf_ServiceOptions* ret; - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_MethodDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodDescriptorProto_msg_init); - return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method( - google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodDescriptorProto_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_MethodDescriptorProto* sub = - (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google__protobuf__MethodDescriptorProto_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto* msg, google_protobuf_ServiceOptions* value) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 40), 65, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__ServiceOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options( - google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_ServiceOptions*)_upb_Message_New(&google__protobuf__ServiceOptions_msg_init, arena); - if (sub) google_protobuf_ServiceDescriptorProto_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.MethodDescriptorProto */ -UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google__protobuf__MethodDescriptorProto_msg_init, arena); -} -UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(24, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {2, UPB_SIZE(24, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(24, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(32, 48), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {3, UPB_SIZE(32, 48), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(32, 48), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(12, 64), 67, 9, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { - const google_protobuf_MethodOptions* default_val = NULL; - const google_protobuf_MethodOptions* ret; - const upb_MiniTableField field = {4, UPB_SIZE(12, 64), 67, 9, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodOptions_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(12, 64), 67, 9, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {5, 9, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {5, 9, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {5, 9, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {6, 10, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {6, 10, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = {6, 10, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {2, UPB_SIZE(24, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = {3, UPB_SIZE(32, 48), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto* msg, google_protobuf_MethodOptions* value) { - const upb_MiniTableField field = {4, UPB_SIZE(12, 64), 67, 9, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__MethodOptions_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options( - google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_MethodOptions*)_upb_Message_New(&google__protobuf__MethodOptions_msg_init, arena); - if (sub) google_protobuf_MethodDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto* msg, bool value) { - const upb_MiniTableField field = {5, 9, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto* msg, bool value) { - const upb_MiniTableField field = {6, 10, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FileOptions */ -UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Arena* arena) { - return (google_protobuf_FileOptions*)_upb_Message_New(&google__protobuf__FileOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(32, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(32, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(32, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, 40, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {8, 40, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, 40, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {9, 20, 66, UPB_SIZE(57, 58), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = {9, 20, 66, UPB_SIZE(57, 58), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {9, 20, 66, UPB_SIZE(57, 58), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {10, 11, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {10, 11, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {10, 11, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(48, 56), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {11, UPB_SIZE(48, 56), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(48, 56), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {16, 12, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {16, 12, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {16, 12, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {17, 13, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {17, 13, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {17, 13, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {18, 14, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {18, 14, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {18, 14, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {20, 15, 72, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {20, 15, 72, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {20, 15, 72, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {23, 16, 73, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {23, 16, 73, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {23, 16, 73, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {27, 17, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {27, 17, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {27, 17, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {31, 18, 75, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { - bool default_val = true; - bool ret; - const upb_MiniTableField field = {31, 18, 75, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {31, 18, 75, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(56, 72), 76, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {36, UPB_SIZE(56, 72), 76, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(56, 72), 76, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(64, 88), 77, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {37, UPB_SIZE(64, 88), 77, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(64, 88), 77, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(72, 104), 78, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {39, UPB_SIZE(72, 104), 78, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(72, 104), 78, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(80, 120), 79, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {40, UPB_SIZE(80, 120), 79, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(80, 120), 79, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(88, 136), 80, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {41, UPB_SIZE(88, 136), 80, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(88, 136), 80, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(96, 152), 81, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {44, UPB_SIZE(96, 152), 81, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(96, 152), 81, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(104, 168), 82, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {45, UPB_SIZE(104, 168), 82, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(104, 168), 82, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(24, 184), 83, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {50, UPB_SIZE(24, 184), 83, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(24, 184), 83, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array( - const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(32, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {8, 40, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions* msg, int32_t value) { - const upb_MiniTableField field = {9, 20, 66, UPB_SIZE(57, 58), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {10, 11, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {11, UPB_SIZE(48, 56), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {16, 12, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {17, 13, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {18, 14, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {20, 15, 72, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {23, 16, 73, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {27, 17, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = {31, 18, 75, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {36, UPB_SIZE(56, 72), 76, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {37, UPB_SIZE(64, 88), 77, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {39, UPB_SIZE(72, 104), 78, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {40, UPB_SIZE(80, 120), 79, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {41, UPB_SIZE(88, 136), 80, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {44, UPB_SIZE(96, 152), 81, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = {45, UPB_SIZE(104, 168), 82, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {50, UPB_SIZE(24, 184), 83, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features( - google_protobuf_FileOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FileOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_FileOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option( - google_protobuf_FileOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.MessageOptions */ -UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(upb_Arena* arena) { - return (google_protobuf_MessageOptions*)_upb_Message_New(&google__protobuf__MessageOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {7, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {7, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {7, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {11, 13, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {11, 13, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {11, 13, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {12, 16, 69, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {12, 16, 69, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {12, 16, 69, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_upb_array( - const google_protobuf_MessageOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = {7, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = {11, 13, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_features(google_protobuf_MessageOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {12, 16, 69, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mutable_features( - google_protobuf_MessageOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MessageOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_MessageOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option( - google_protobuf_MessageOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.FieldOptions */ -UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions*)_upb_Message_New(&google__protobuf__FieldOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {1, 16, 64, 42, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {1, 16, 64, 42, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {1, 16, 64, 42, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {5, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {5, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {5, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {6, 20, 68, UPB_SIZE(31, 32), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {6, 20, 68, UPB_SIZE(31, 32), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {6, 20, 68, UPB_SIZE(31, 32), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {10, 13, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {10, 13, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {10, 13, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {15, 14, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {15, 14, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {15, 14, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {16, 15, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {16, 15, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {16, 15, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {17, 24, 72, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {17, 24, 72, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {17, 24, 72, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, - size_t* size) { - const upb_MiniTableField field = {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array( - const google_protobuf_FieldOptions* msg, size_t* size) { - const upb_MiniTableField field = {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array( - google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, - size_t* size) { - const upb_MiniTableField field = {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__EditionDefault_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldOptions_EditionDefault* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_array( - const google_protobuf_FieldOptions* msg, size_t* size) { - const upb_MiniTableField field = {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__EditionDefault_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array( - google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__EditionDefault_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {21, UPB_SIZE(36, 48), 73, UPB_SIZE(14, 19), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {21, UPB_SIZE(36, 48), 73, UPB_SIZE(14, 19), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {21, UPB_SIZE(36, 48), 73, UPB_SIZE(14, 19), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_feature_support(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {22, UPB_SIZE(40, 56), 74, UPB_SIZE(12, 18), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_feature_support(const google_protobuf_FieldOptions* msg) { - const google_protobuf_FieldOptions_FeatureSupport* default_val = NULL; - const google_protobuf_FieldOptions_FeatureSupport* ret; - const upb_MiniTableField field = {22, UPB_SIZE(40, 56), 74, UPB_SIZE(12, 18), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__FeatureSupport_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_feature_support(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {22, UPB_SIZE(40, 56), 74, UPB_SIZE(12, 18), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_upb_array( - const google_protobuf_FieldOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions* msg, int32_t value) { - const upb_MiniTableField field = {1, 16, 64, 42, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = {5, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions* msg, int32_t value) { - const upb_MiniTableField field = {6, 20, 68, UPB_SIZE(31, 32), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = {10, 13, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_unverified_lazy(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = {15, 14, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_debug_redact(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = {16, 15, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_retention(google_protobuf_FieldOptions* msg, int32_t value) { - const upb_MiniTableField field = {17, 24, 72, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf_FieldOptions* msg, - size_t* size) { - upb_MiniTableField field = {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_FieldOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, - size_t* size) { - upb_MiniTableField field = {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__EditionDefault_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldOptions_EditionDefault**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_resize_edition_defaults(google_protobuf_FieldOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__EditionDefault_msg_init); - return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__EditionDefault_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldOptions_EditionDefault* sub = - (struct google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(&google__protobuf__FieldOptions__EditionDefault_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {21, UPB_SIZE(36, 48), 73, UPB_SIZE(14, 19), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutable_features( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FieldOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_FieldOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FieldOptions_set_feature_support(google_protobuf_FieldOptions* msg, google_protobuf_FieldOptions_FeatureSupport* value) { - const upb_MiniTableField field = {22, UPB_SIZE(40, 56), 74, UPB_SIZE(12, 18), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__FeatureSupport_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_mutable_feature_support( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - struct google_protobuf_FieldOptions_FeatureSupport* sub = (struct google_protobuf_FieldOptions_FeatureSupport*)google_protobuf_FieldOptions_feature_support(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions_FeatureSupport*)_upb_Message_New(&google__protobuf__FieldOptions__FeatureSupport_msg_init, arena); - if (sub) google_protobuf_FieldOptions_set_feature_support(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.FieldOptions.EditionDefault */ -UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(&google__protobuf__FieldOptions__EditionDefault_msg_init, arena); -} -UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize(const google_protobuf_FieldOptions_EditionDefault* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const google_protobuf_FieldOptions_EditionDefault* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = {2, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {2, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = {2, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = {3, 12, 65, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {3, 12, 65, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = {3, 12, 65, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault* msg, upb_StringView value) { - const upb_MiniTableField field = {2, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_edition(google_protobuf_FieldOptions_EditionDefault* msg, int32_t value) { - const upb_MiniTableField field = {3, 12, 65, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FieldOptions.FeatureSupport */ -UPB_INLINE google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_FeatureSupport_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions_FeatureSupport*)_upb_Message_New(&google__protobuf__FieldOptions__FeatureSupport_msg_init, arena); -} -UPB_INLINE google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_FeatureSupport_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldOptions_FeatureSupport* ret = google_protobuf_FieldOptions_FeatureSupport_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__FeatureSupport_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_FeatureSupport_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldOptions_FeatureSupport* ret = google_protobuf_FieldOptions_FeatureSupport_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__FeatureSupport_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldOptions_FeatureSupport_serialize(const google_protobuf_FieldOptions_FeatureSupport* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__FeatureSupport_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldOptions_FeatureSupport_serialize_ex(const google_protobuf_FieldOptions_FeatureSupport* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__FeatureSupport_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_edition_introduced(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {1, 12, 64, UPB_SIZE(15, 16), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_FeatureSupport_edition_introduced(const google_protobuf_FieldOptions_FeatureSupport* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {1, 12, 64, UPB_SIZE(15, 16), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_edition_introduced(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {1, 12, 64, UPB_SIZE(15, 16), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_edition_deprecated(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(13, 15), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_FeatureSupport_edition_deprecated(const google_protobuf_FieldOptions_FeatureSupport* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(13, 15), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_edition_deprecated(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(13, 15), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_deprecation_warning(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {3, 24, 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldOptions_FeatureSupport_deprecation_warning(const google_protobuf_FieldOptions_FeatureSupport* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {3, 24, 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_deprecation_warning(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {3, 24, 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_edition_removed(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {4, 20, 67, UPB_SIZE(8, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_FeatureSupport_edition_removed(const google_protobuf_FieldOptions_FeatureSupport* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {4, 20, 67, UPB_SIZE(8, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_edition_removed(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {4, 20, 67, UPB_SIZE(8, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_removal_error(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(32, 40), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldOptions_FeatureSupport_removal_error(const google_protobuf_FieldOptions_FeatureSupport* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {5, UPB_SIZE(32, 40), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_removal_error(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(32, 40), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_edition_introduced(google_protobuf_FieldOptions_FeatureSupport* msg, int32_t value) { - const upb_MiniTableField field = {1, 12, 64, UPB_SIZE(15, 16), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_edition_deprecated(google_protobuf_FieldOptions_FeatureSupport* msg, int32_t value) { - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(13, 15), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_deprecation_warning(google_protobuf_FieldOptions_FeatureSupport* msg, upb_StringView value) { - const upb_MiniTableField field = {3, 24, 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_edition_removed(google_protobuf_FieldOptions_FeatureSupport* msg, int32_t value) { - const upb_MiniTableField field = {4, 20, 67, UPB_SIZE(8, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_removal_error(google_protobuf_FieldOptions_FeatureSupport* msg, upb_StringView value) { - const upb_MiniTableField field = {5, UPB_SIZE(32, 40), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.OneofOptions */ -UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Arena* arena) { - return (google_protobuf_OneofOptions*)_upb_Message_New(&google__protobuf__OneofOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 6, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 6, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 6, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_upb_array( - const google_protobuf_OneofOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 6, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutable_features( - google_protobuf_OneofOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_OneofOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_OneofOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option( - google_protobuf_OneofOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.EnumOptions */ -UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumOptions*)_upb_Message_New(&google__protobuf__EnumOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {2, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {2, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {2, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {3, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {3, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {3, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {6, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {6, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {6, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(12, 16), 67, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {7, UPB_SIZE(12, 16), 67, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(12, 16), 67, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_upb_array( - const google_protobuf_EnumOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions* msg, bool value) { - const upb_MiniTableField field = {2, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions* msg, bool value) { - const upb_MiniTableField field = {3, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg, bool value) { - const upb_MiniTableField field = {6, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumOptions_set_features(google_protobuf_EnumOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {7, UPB_SIZE(12, 16), 67, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutable_features( - google_protobuf_EnumOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_EnumOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option( - google_protobuf_EnumOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.EnumValueOptions */ -UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumValueOptions*)_upb_Message_New(&google__protobuf__EnumValueOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 65, UPB_SIZE(12, 13), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 65, UPB_SIZE(12, 13), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 65, UPB_SIZE(12, 13), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {3, 10, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {3, 10, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {3, 10, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_feature_support(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 24), 67, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions_FeatureSupport* google_protobuf_EnumValueOptions_feature_support(const google_protobuf_EnumValueOptions* msg) { - const google_protobuf_FieldOptions_FeatureSupport* default_val = NULL; - const google_protobuf_FieldOptions_FeatureSupport* ret; - const upb_MiniTableField field = {4, UPB_SIZE(16, 24), 67, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__FeatureSupport_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_feature_support(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 24), 67, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_upb_array( - const google_protobuf_EnumValueOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions* msg, bool value) { - const upb_MiniTableField field = {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueOptions_set_features(google_protobuf_EnumValueOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 65, UPB_SIZE(12, 13), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_mutable_features( - google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumValueOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_EnumValueOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_EnumValueOptions_set_debug_redact(google_protobuf_EnumValueOptions* msg, bool value) { - const upb_MiniTableField field = {3, 10, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueOptions_set_feature_support(google_protobuf_EnumValueOptions* msg, google_protobuf_FieldOptions_FeatureSupport* value) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 24), 67, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FieldOptions__FeatureSupport_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FieldOptions_FeatureSupport* google_protobuf_EnumValueOptions_mutable_feature_support( - google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - struct google_protobuf_FieldOptions_FeatureSupport* sub = (struct google_protobuf_FieldOptions_FeatureSupport*)google_protobuf_EnumValueOptions_feature_support(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions_FeatureSupport*)_upb_Message_New(&google__protobuf__FieldOptions__FeatureSupport_msg_init, arena); - if (sub) google_protobuf_EnumValueOptions_set_feature_support(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option( - google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.ServiceOptions */ -UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(upb_Arena* arena) { - return (google_protobuf_ServiceOptions*)_upb_Message_New(&google__protobuf__ServiceOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = {34, UPB_SIZE(12, 16), 65, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {34, UPB_SIZE(12, 16), 65, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = {34, UPB_SIZE(12, 16), 65, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_upb_array( - const google_protobuf_ServiceOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions* msg, bool value) { - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ServiceOptions_set_features(google_protobuf_ServiceOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {34, UPB_SIZE(12, 16), 65, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mutable_features( - google_protobuf_ServiceOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ServiceOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_ServiceOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option( - google_protobuf_ServiceOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.MethodOptions */ -UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_Arena* arena) { - return (google_protobuf_MethodOptions*)_upb_Message_New(&google__protobuf__MethodOptions_msg_init, arena); -} -UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = {34, 12, 65, 9, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {34, 12, 65, 9, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = {34, 12, 65, 9, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = {35, 16, 66, UPB_SIZE(7, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {35, 16, 66, UPB_SIZE(7, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = {35, 16, 66, UPB_SIZE(7, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, - size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_upb_array( - const google_protobuf_MethodOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions* msg, bool value) { - const upb_MiniTableField field = {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions* msg, int32_t value) { - const upb_MiniTableField field = {34, 12, 65, 9, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodOptions_set_features(google_protobuf_MethodOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {35, 16, 66, UPB_SIZE(7, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_mutable_features( - google_protobuf_MethodOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MethodOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_MethodOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions* msg, - size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option( - google_protobuf_MethodOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.UninterpretedOption */ -UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); -} -UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, - size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption__NamePart_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption_NamePart* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array( - const google_protobuf_UninterpretedOption* msg, size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption__NamePart_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array( - google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption__NamePart_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {3, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {3, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {3, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(40, 72), 65, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - uint64_t default_val = (uint64_t)0ull; - uint64_t ret; - const upb_MiniTableField field = {4, UPB_SIZE(40, 72), 65, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(40, 72), 65, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(48, 80), 66, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - int64_t default_val = (int64_t)0ll; - int64_t ret; - const upb_MiniTableField field = {5, UPB_SIZE(48, 80), 66, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(48, 80), 66, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(56, 88), 67, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { - double default_val = 0; - double ret; - const upb_MiniTableField field = {6, UPB_SIZE(56, 88), 67, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(56, 88), 67, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(24, 32), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {7, UPB_SIZE(24, 32), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {7, UPB_SIZE(24, 32), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(32, 48), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {8, UPB_SIZE(32, 48), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(32, 48), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, - size_t* size) { - upb_MiniTableField field = {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption__NamePart_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption_NamePart**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption__NamePart_msg_init); - return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name( - google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__UninterpretedOption__NamePart_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption_NamePart* sub = - (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google__protobuf__UninterpretedOption__NamePart_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption* msg, upb_StringView value) { - const upb_MiniTableField field = {3, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption* msg, uint64_t value) { - const upb_MiniTableField field = {4, UPB_SIZE(40, 72), 65, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption* msg, int64_t value) { - const upb_MiniTableField field = {5, UPB_SIZE(48, 80), 66, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption* msg, double value) { - const upb_MiniTableField field = {6, UPB_SIZE(56, 88), 67, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption* msg, upb_StringView value) { - const upb_MiniTableField field = {7, UPB_SIZE(24, 32), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption* msg, upb_StringView value) { - const upb_MiniTableField field = {8, UPB_SIZE(32, 48), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.UninterpretedOption.NamePart */ -UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google__protobuf__UninterpretedOption__NamePart_msg_init, arena); -} -UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = {2, 9, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {2, 9, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = {2, 9, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart* msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart* msg, bool value) { - const upb_MiniTableField field = {2, 9, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FeatureSet */ -UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_new(upb_Arena* arena) { - return (google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); -} -UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSet_serialize(const google_protobuf_FeatureSet* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_FeatureSet* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {1, 12, 64, 24, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {1, 12, 64, 24, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {1, 12, 64, 24, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(22, 23), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(22, 23), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(22, 23), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {3, 20, 66, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {3, 20, 66, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {3, 20, 66, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {4, 24, 67, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {4, 24, 67, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {4, 24, 67, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {5, 28, 68, UPB_SIZE(16, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {5, 28, 68, UPB_SIZE(16, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {5, 28, 68, UPB_SIZE(16, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {6, 32, 69, UPB_SIZE(14, 19), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {6, 32, 69, UPB_SIZE(14, 19), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {6, 32, 69, UPB_SIZE(14, 19), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_enforce_naming_style(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {7, 36, 70, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_enforce_naming_style(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {7, 36, 70, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_enforce_naming_style(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {7, 36, 70, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_default_symbol_visibility(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {8, 40, 71, UPB_SIZE(10, 17), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_default_symbol_visibility(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {8, 40, 71, UPB_SIZE(10, 17), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_default_symbol_visibility(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = {8, 40, 71, UPB_SIZE(10, 17), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {1, 12, 64, 24, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_enum_type(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {2, 16, 65, UPB_SIZE(22, 23), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_repeated_field_encoding(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {3, 20, 66, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_utf8_validation(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {4, 24, 67, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_message_encoding(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {5, 28, 68, UPB_SIZE(16, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_json_format(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {6, 32, 69, UPB_SIZE(14, 19), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_enforce_naming_style(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {7, 36, 70, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_default_symbol_visibility(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = {8, 40, 71, UPB_SIZE(10, 17), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FeatureSet.VisibilityFeature */ -UPB_INLINE google_protobuf_FeatureSet_VisibilityFeature* google_protobuf_FeatureSet_VisibilityFeature_new(upb_Arena* arena) { - return (google_protobuf_FeatureSet_VisibilityFeature*)_upb_Message_New(&google__protobuf__FeatureSet__VisibilityFeature_msg_init, arena); -} -UPB_INLINE google_protobuf_FeatureSet_VisibilityFeature* google_protobuf_FeatureSet_VisibilityFeature_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSet_VisibilityFeature* ret = google_protobuf_FeatureSet_VisibilityFeature_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet__VisibilityFeature_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSet_VisibilityFeature* google_protobuf_FeatureSet_VisibilityFeature_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSet_VisibilityFeature* ret = google_protobuf_FeatureSet_VisibilityFeature_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet__VisibilityFeature_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSet_VisibilityFeature_serialize(const google_protobuf_FeatureSet_VisibilityFeature* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet__VisibilityFeature_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSet_VisibilityFeature_serialize_ex(const google_protobuf_FeatureSet_VisibilityFeature* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet__VisibilityFeature_msg_init, options, arena, &ptr, len); - return ptr; -} - - -/* google.protobuf.FeatureSetDefaults */ -UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_new(upb_Arena* arena) { - return (google_protobuf_FeatureSetDefaults*)_upb_Message_New(&google__protobuf__FeatureSetDefaults_msg_init, arena); -} -UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize(const google_protobuf_FeatureSetDefaults* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_protobuf_FeatureSetDefaults* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, - size_t* size) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_array( - const google_protobuf_FeatureSetDefaults* msg, size_t* size) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array( - google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 12), 64, UPB_SIZE(7, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {4, UPB_SIZE(16, 12), 64, UPB_SIZE(7, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 12), 64, UPB_SIZE(7, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 16), 65, UPB_SIZE(5, 8), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {5, UPB_SIZE(20, 16), 65, UPB_SIZE(5, 8), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 16), 65, UPB_SIZE(5, 8), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, - size_t* size) { - upb_MiniTableField field = {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_resize_defaults(google_protobuf_FeatureSetDefaults* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init); - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults( - google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { - upb_MiniTableField field = {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* sub = - (struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults* msg, int32_t value) { - const upb_MiniTableField field = {4, UPB_SIZE(16, 12), 64, UPB_SIZE(7, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_set_maximum_edition(google_protobuf_FeatureSetDefaults* msg, int32_t value) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 16), 65, UPB_SIZE(5, 8), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault */ -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(upb_Arena* arena) { - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, arena); -} -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize_ex(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = {3, 12, 64, UPB_SIZE(9, 10), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {3, 12, 64, UPB_SIZE(9, 10), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = {3, 12, 64, UPB_SIZE(9, 10), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_overridable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = {4, 16, 65, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_overridable_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {4, 16, 65, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_overridable_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = {4, 16, 65, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_fixed_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 24), 66, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fixed_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {5, UPB_SIZE(20, 24), 66, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_fixed_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 24), 66, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, int32_t value) { - const upb_MiniTableField field = {3, 12, 64, UPB_SIZE(9, 10), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_overridable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {4, 16, 65, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_overridable_features( - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_overridable_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_overridable_features(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_fixed_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {5, UPB_SIZE(20, 24), 66, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__FeatureSet_msg_init); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_fixed_features( - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fixed_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(&google__protobuf__FeatureSet_msg_init, arena); - if (sub) google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_fixed_features(msg, sub); - } - return sub; -} - -/* google.protobuf.SourceCodeInfo */ -UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo*)_upb_Message_New(&google__protobuf__SourceCodeInfo_msg_init, arena); -} -UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, - size_t* size) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo__Location_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_SourceCodeInfo_Location* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array( - const google_protobuf_SourceCodeInfo* msg, size_t* size) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo__Location_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array( - google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo__Location_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, - size_t* size) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo__Location_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_SourceCodeInfo_Location**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo__Location_msg_init); - return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location( - google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__SourceCodeInfo__Location_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_SourceCodeInfo_Location* sub = - (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google__protobuf__SourceCodeInfo__Location_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.SourceCodeInfo.Location */ -UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google__protobuf__SourceCodeInfo__Location_msg_init, arena); -} -UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_array( - const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array( - google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_array( - const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { - const upb_MiniTableField field = {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array( - google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(24, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {3, UPB_SIZE(24, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(24, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = {4, 32, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {4, 32, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = {4, 32, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - const upb_MiniTableField field = {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_upb_array( - const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { - const upb_MiniTableField field = {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array( - google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - upb_MiniTableField field = {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - upb_MiniTableField field = {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView value) { - const upb_MiniTableField field = {3, UPB_SIZE(24, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView value) { - const upb_MiniTableField field = {4, 32, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - upb_MiniTableField field = {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} - -/* google.protobuf.GeneratedCodeInfo */ -UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo*)_upb_Message_New(&google__protobuf__GeneratedCodeInfo_msg_init, arena); -} -UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, - size_t* size) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_array( - const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array( - google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, - size_t* size) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init); - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation( - google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { - upb_MiniTableField field = {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - UPB_PRIVATE(_upb_MiniTable_StrongReference)(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_GeneratedCodeInfo_Annotation* sub = - (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init, arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.GeneratedCodeInfo.Annotation */ -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init, arena); -} -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, - size_t* size) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_upb_array( - const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array( - google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(28, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = {2, UPB_SIZE(28, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {2, UPB_SIZE(28, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 16), 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = {4, UPB_SIZE(20, 16), 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 16), 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 20), 67, UPB_SIZE(3, 4), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = {5, UPB_SIZE(24, 20), 67, UPB_SIZE(3, 4), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 20), 67, UPB_SIZE(3, 4), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, - size_t* size) { - upb_MiniTableField field = {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_StringView value) { - const upb_MiniTableField field = {2, UPB_SIZE(28, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t value) { - const upb_MiniTableField field = {3, UPB_SIZE(16, 12), 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t value) { - const upb_MiniTableField field = {4, UPB_SIZE(20, 16), 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t value) { - const upb_MiniTableField field = {5, UPB_SIZE(24, 20), 67, UPB_SIZE(3, 4), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* Max size 32 is google.protobuf.FileOptions */ -/* Max size 64 is google.protobuf.FileOptions */ -#define _UPB_MAXOPT_SIZE UPB_SIZE(112, 200) -#ifdef __cplusplus - } /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_ */ diff --git a/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb_minitable.c b/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb_minitable.c deleted file mode 100644 index 1140c37..0000000 --- a/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb_minitable.c +++ /dev/null @@ -1,1650 +0,0 @@ -/* This file was generated by upb_generator from the input file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. - * NO CHECKED-IN PROTOBUF GENCODE */ - -#include -#include "upb/generated_code_support.h" -#include "google/protobuf/descriptor.upb_minitable.h" - -// Must be last. -#include "upb/port/def.inc" - -extern const UPB_PRIVATE(upb_GeneratedExtensionListEntry)* UPB_PRIVATE(upb_generated_extension_list); -typedef struct { - upb_MiniTableField fields[1]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__FileDescriptorSet_msg_init_Fields; - -static const google__protobuf__FileDescriptorSet_msg_init_Fields google_protobuf_FileDescriptorSet__fields = {{ - {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FileDescriptorProto_msg_init}, -}}; - -const upb_MiniTable google__protobuf__FileDescriptorSet_msg_init = { - &google_protobuf_FileDescriptorSet__fields.fields[0], - 16, 1, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(8), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FileDescriptorSet", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000800003f00000a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[14]; - upb_MiniTableSubInternal subs[7]; -} google__protobuf__FileDescriptorProto_msg_init_Fields; - -static const google__protobuf__FileDescriptorProto_msg_init_Fields google_protobuf_FileDescriptorProto__fields = {{ - {1, UPB_SIZE(56, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(64, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(12, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(16, 72), 0, 33, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(20, 80), 0, UPB_SIZE(31, 32), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(24, 88), 0, UPB_SIZE(29, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(28, 96), 0, UPB_SIZE(27, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(32, 104), 66, UPB_SIZE(25, 29), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(36, 112), 67, UPB_SIZE(23, 28), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(40, 120), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(44, 128), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {12, UPB_SIZE(72, 48), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {14, UPB_SIZE(48, 12), 69, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {15, UPB_SIZE(52, 136), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__DescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__EnumDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__ServiceDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FieldDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FileOptions_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__SourceCodeInfo_msg_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, -}}; - -const upb_MiniTable google__protobuf__FileDescriptorProto_msg_init = { - &google_protobuf_FileDescriptorProto__fields.fields[0], - UPB_SIZE(80, 144), 14, kUpb_ExtMode_NonExtendable, 12, UPB_FASTTABLE_MASK(120), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FileDescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0020000001000012, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x004000003f00001a, &upb_DecodeFast_Bytes_Repeated_Tag1Byte}, - {0x004800003f030022, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x005000003f04002a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x005800003f050032, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x006000003f06003a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x0068000002070042, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x007000000308004a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x007800003f000050, &upb_DecodeFast_Varint32_Repeated_Tag1Byte}, - {0x008000003f000058, &upb_DecodeFast_Varint32_Repeated_Tag1Byte}, - {0x0030000004000062, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x008800003f00007a, &upb_DecodeFast_Bytes_Repeated_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[11]; - upb_MiniTableSubInternal subs[9]; -} google__protobuf__DescriptorProto_msg_init_Fields; - -static const google__protobuf__DescriptorProto_msg_init_Fields google_protobuf_DescriptorProto__fields = {{ - {1, UPB_SIZE(52, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 32), 0, UPB_SIZE(30, 31), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 40), 0, UPB_SIZE(28, 30), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(20, 48), 0, UPB_SIZE(26, 29), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(24, 56), 0, UPB_SIZE(24, 28), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(28, 64), 0, UPB_SIZE(22, 27), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(32, 72), 65, UPB_SIZE(20, 26), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(36, 80), 0, UPB_SIZE(18, 25), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(40, 88), 0, UPB_SIZE(16, 24), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(44, 96), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(48, 12), 66, UPB_SIZE(11, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FieldDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__DescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__EnumDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__DescriptorProto__ExtensionRange_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FieldDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__MessageOptions_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__OneofDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__DescriptorProto__ReservedRange_msg_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__SymbolVisibility_enum_init}, -}}; - -const upb_MiniTable google__protobuf__DescriptorProto_msg_init = { - &google_protobuf_DescriptorProto__fields.fields[0], - UPB_SIZE(64, 104), 11, kUpb_ExtMode_NonExtendable, 11, UPB_FASTTABLE_MASK(120), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.DescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x002000003f010012, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x002800003f02001a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x003000003f030022, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x003800003f04002a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x004000003f050032, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x004800000106003a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x005000003f070042, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x005800003f08004a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x006000003f000052, &upb_DecodeFast_Bytes_Repeated_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[3]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__DescriptorProto__ExtensionRange_msg_init_Fields; - -static const google__protobuf__DescriptorProto__ExtensionRange_msg_init_Fields google_protobuf_DescriptorProto_ExtensionRange__fields = {{ - {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(20, 24), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__ExtensionRangeOptions_msg_init}, -}}; - -const upb_MiniTable google__protobuf__DescriptorProto__ExtensionRange_msg_init = { - &google_protobuf_DescriptorProto_ExtensionRange__fields.fields[0], - UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(24), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.DescriptorProto.ExtensionRange", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000c000000000008, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0010000001000010, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x001800000202001a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[2]; -} google__protobuf__DescriptorProto__ReservedRange_msg_init_Fields; - -static const google__protobuf__DescriptorProto__ReservedRange_msg_init_Fields google_protobuf_DescriptorProto_ReservedRange__fields = {{ - {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, -}}; - -const upb_MiniTable google__protobuf__DescriptorProto__ReservedRange_msg_init = { - &google_protobuf_DescriptorProto_ReservedRange__fields.fields[0], - 24, 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.DescriptorProto.ReservedRange", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000c000000000008, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0010000001000010, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[4]; - upb_MiniTableSubInternal subs[4]; -} google__protobuf__ExtensionRangeOptions_msg_init_Fields; - -static const google__protobuf__ExtensionRangeOptions_msg_init_Fields google_protobuf_ExtensionRangeOptions__fields = {{ - {2, UPB_SIZE(12, 16), 0, 12, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 12), 64, UPB_SIZE(10, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {50, UPB_SIZE(20, 24), 65, UPB_SIZE(8, 10), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(24, 32), 0, UPB_SIZE(6, 9), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__ExtensionRangeOptions__Declaration_msg_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__ExtensionRangeOptions__VerificationState_enum_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__ExtensionRangeOptions_msg_init = { - &google_protobuf_ExtensionRangeOptions__fields.fields[0], - UPB_SIZE(32, 40), 4, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.ExtensionRangeOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000003f000012, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0018000001020392, &upb_DecodeFast_Message_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x002000003f033eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[5]; -} google__protobuf__ExtensionRangeOptions__Declaration_msg_init_Fields; - -static const google__protobuf__ExtensionRangeOptions__Declaration_msg_init_Fields google_protobuf_ExtensionRangeOptions_Declaration__fields = {{ - {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {2, 16, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(24, 32), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {5, 9, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {6, 10, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, -}}; - -const upb_MiniTable google__protobuf__ExtensionRangeOptions__Declaration_msg_init = { - &google_protobuf_ExtensionRangeOptions_Declaration__fields.fields[0], - UPB_SIZE(32, 48), 5, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(56), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.ExtensionRangeOptions.Declaration", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000c000000000008, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0010000001000012, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x002000000200001a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0009000003000028, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x000a000004000030, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[11]; - upb_MiniTableSubInternal subs[3]; -} google__protobuf__FieldDescriptorProto_msg_init_Fields; - -static const google__protobuf__FieldDescriptorProto_msg_init_Fields google_protobuf_FieldDescriptorProto__fields = {{ - {1, 32, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(40, 48), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, 12, 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {4, 16, 67, UPB_SIZE(24, 25), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, 20, 68, UPB_SIZE(22, 24), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(48, 64), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(56, 80), 70, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(24, 112), 71, UPB_SIZE(14, 17), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(28, 24), 72, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(64, 96), 73, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {17, 10, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__FieldDescriptorProto__Label_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FieldDescriptorProto__Type_enum_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FieldOptions_msg_init}, -}}; - -const upb_MiniTable google__protobuf__FieldDescriptorProto_msg_init = { - &google_protobuf_FieldDescriptorProto__fields.fields[0], - UPB_SIZE(72, 120), 11, kUpb_ExtMode_NonExtendable, 10, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FieldDescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x002000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0030000001000012, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x000c000002000018, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0040000005000032, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x005000000600003a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0070000007070042, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0018000008000048, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0060000009000052, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000a00000a000188, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[2]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__OneofDescriptorProto_msg_init_Fields; - -static const google__protobuf__OneofDescriptorProto_msg_init_Fields google_protobuf_OneofDescriptorProto__fields = {{ - {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 32), 65, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__OneofOptions_msg_init}, -}}; - -const upb_MiniTable google__protobuf__OneofDescriptorProto_msg_init = { - &google_protobuf_OneofDescriptorProto__fields.fields[0], - UPB_SIZE(24, 40), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.OneofDescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0020000001010012, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[6]; - upb_MiniTableSubInternal subs[4]; -} google__protobuf__EnumDescriptorProto_msg_init_Fields; - -static const google__protobuf__EnumDescriptorProto_msg_init_Fields google_protobuf_EnumDescriptorProto__fields = {{ - {1, UPB_SIZE(32, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 32), 0, 15, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 40), 65, UPB_SIZE(13, 14), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(20, 48), 0, UPB_SIZE(11, 13), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(24, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(28, 12), 66, UPB_SIZE(6, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__EnumValueDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__EnumOptions_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__SymbolVisibility_enum_init}, -}}; - -const upb_MiniTable google__protobuf__EnumDescriptorProto_msg_init = { - &google_protobuf_EnumDescriptorProto__fields.fields[0], - UPB_SIZE(40, 64), 6, kUpb_ExtMode_NonExtendable, 6, UPB_FASTTABLE_MASK(56), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.EnumDescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x002000003f010012, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x002800000102001a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x003000003f030022, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x003800003f00002a, &upb_DecodeFast_Bytes_Repeated_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[2]; -} google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init_Fields; - -static const google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init_Fields google_protobuf_EnumDescriptorProto_EnumReservedRange__fields = {{ - {1, 12, 64, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {2, 16, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, -}}; - -const upb_MiniTable google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init = { - &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields.fields[0], - 24, 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.EnumDescriptorProto.EnumReservedRange", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000c000000000008, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0010000001000010, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[3]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__EnumValueDescriptorProto_msg_init_Fields; - -static const google__protobuf__EnumValueDescriptorProto_msg_init_Fields google_protobuf_EnumValueDescriptorProto__fields = {{ - {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, 12, 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 32), 66, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__EnumValueOptions_msg_init}, -}}; - -const upb_MiniTable google__protobuf__EnumValueDescriptorProto_msg_init = { - &google_protobuf_EnumValueDescriptorProto__fields.fields[0], - UPB_SIZE(32, 40), 3, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(24), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.EnumValueDescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x000c000001000010, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x002000000202001a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[3]; - upb_MiniTableSubInternal subs[2]; -} google__protobuf__ServiceDescriptorProto_msg_init_Fields; - -static const google__protobuf__ServiceDescriptorProto_msg_init_Fields google_protobuf_ServiceDescriptorProto__fields = {{ - {1, UPB_SIZE(20, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 32), 0, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 40), 65, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__MethodDescriptorProto_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__ServiceOptions_msg_init}, -}}; - -const upb_MiniTable google__protobuf__ServiceDescriptorProto_msg_init = { - &google_protobuf_ServiceDescriptorProto__fields.fields[0], - UPB_SIZE(32, 48), 3, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(24), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.ServiceDescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x002000003f010012, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x002800000102001a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[6]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__MethodDescriptorProto_msg_init_Fields; - -static const google__protobuf__MethodDescriptorProto_msg_init_Fields google_protobuf_MethodDescriptorProto__fields = {{ - {1, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(24, 32), 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(32, 48), 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(12, 64), 67, 9, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, 9, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {6, 10, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__MethodOptions_msg_init}, -}}; - -const upb_MiniTable google__protobuf__MethodDescriptorProto_msg_init = { - &google_protobuf_MethodDescriptorProto__fields.fields[0], - UPB_SIZE(40, 72), 6, kUpb_ExtMode_NonExtendable, 6, UPB_FASTTABLE_MASK(56), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.MethodDescriptorProto", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0020000001000012, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x003000000200001a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0040000003030022, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0009000004000028, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x000a000005000030, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[21]; - upb_MiniTableSubInternal subs[3]; -} google__protobuf__FileOptions_msg_init_Fields; - -static const google__protobuf__FileOptions_msg_init_Fields google_protobuf_FileOptions__fields = {{ - {1, UPB_SIZE(32, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, 40, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {9, 20, 66, UPB_SIZE(57, 58), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {10, 11, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(48, 56), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {16, 12, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {17, 13, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {18, 14, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {20, 15, 72, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {23, 16, 73, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {27, 17, 74, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {31, 18, 75, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {36, UPB_SIZE(56, 72), 76, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {37, UPB_SIZE(64, 88), 77, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {39, UPB_SIZE(72, 104), 78, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {40, UPB_SIZE(80, 120), 79, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {41, UPB_SIZE(88, 136), 80, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {44, UPB_SIZE(96, 152), 81, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {45, UPB_SIZE(104, 168), 82, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {50, UPB_SIZE(24, 184), 83, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(28, 192), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__FileOptions__OptimizeMode_enum_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__FileOptions_msg_init = { - &google_protobuf_FileOptions__fields.fields[0], - UPB_SIZE(112, 200), 21, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FileOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0028000001000042, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000b000003000050, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x003800000400005a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000c000005000180, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x000d000006000188, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x000e000007000190, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000f0000080001a0, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x005800000d0002aa, &upb_DecodeFast_Bytes_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x00100000090001b8, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x007800000f0002c2, &upb_DecodeFast_Bytes_Scalar_Tag2Byte}, - {0x00880000100002ca, &upb_DecodeFast_Bytes_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001100000a0001d8, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x00980000110002e2, &upb_DecodeFast_Bytes_Scalar_Tag2Byte}, - {0x00a80000120002ea, &upb_DecodeFast_Bytes_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001200000b0001f8, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[7]; - upb_MiniTableSubInternal subs[2]; -} google__protobuf__MessageOptions_msg_init_Fields; - -static const google__protobuf__MessageOptions_msg_init_Fields google_protobuf_MessageOptions__fields = {{ - {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {7, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {11, 13, 68, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {12, 16, 69, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(20, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__MessageOptions_msg_init = { - &google_protobuf_MessageOptions__fields.fields[0], - UPB_SIZE(24, 32), 7, kUpb_ExtMode_Extendable, 3, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.MessageOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0009000000000008, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x000a000001000010, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x000b000002000018, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000c000003000038, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000d000004000058, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0010000005050062, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800003f063eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[14]; - upb_MiniTableSubInternal subs[8]; -} google__protobuf__FieldOptions_msg_init_Fields; - -static const google__protobuf__FieldOptions_msg_init_Fields google_protobuf_FieldOptions__fields = {{ - {1, 16, 64, 42, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {2, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {3, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {5, 12, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {6, 20, 68, UPB_SIZE(31, 32), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {10, 13, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {15, 14, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {16, 15, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {17, 24, 72, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {19, UPB_SIZE(28, 32), 0, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {20, UPB_SIZE(32, 40), 0, UPB_SIZE(16, 20), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {21, UPB_SIZE(36, 48), 73, UPB_SIZE(14, 19), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {22, UPB_SIZE(40, 56), 74, UPB_SIZE(12, 18), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(44, 64), 0, UPB_SIZE(10, 17), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__FieldOptions__CType_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FieldOptions__JSType_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FieldOptions__OptionRetention_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FieldOptions__OptionTargetType_enum_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FieldOptions__EditionDefault_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FieldOptions__FeatureSupport_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__FieldOptions_msg_init = { - &google_protobuf_FieldOptions__fields.fields[0], - UPB_SIZE(48, 72), 14, kUpb_ExtMode_Extendable, 3, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FieldOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000a000001000010, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x000b000002000018, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000c000003000028, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000d000005000050, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000e000006000078, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x000f000007000180, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x002800003f0a01a2, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x00300000090b01aa, &upb_DecodeFast_Message_Scalar_Tag2Byte}, - {0x003800000a0c01b2, &upb_DecodeFast_Message_Scalar_Tag2Byte}, - {0x004000003f0d3eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[2]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__FieldOptions__EditionDefault_msg_init_Fields; - -static const google__protobuf__FieldOptions__EditionDefault_msg_init_Fields google_protobuf_FieldOptions_EditionDefault__fields = {{ - {2, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, 12, 65, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, -}}; - -const upb_MiniTable google__protobuf__FieldOptions__EditionDefault_msg_init = { - &google_protobuf_FieldOptions_EditionDefault__fields.fields[0], - UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(24), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FieldOptions.EditionDefault", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0010000000000012, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[5]; - upb_MiniTableSubInternal subs[3]; -} google__protobuf__FieldOptions__FeatureSupport_msg_init_Fields; - -static const google__protobuf__FieldOptions__FeatureSupport_msg_init_Fields google_protobuf_FieldOptions_FeatureSupport__fields = {{ - {1, 12, 64, UPB_SIZE(15, 16), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {2, 16, 65, UPB_SIZE(13, 15), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, 24, 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, 20, 67, UPB_SIZE(8, 11), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(32, 40), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, -}}; - -const upb_MiniTable google__protobuf__FieldOptions__FeatureSupport_msg_init = { - &google_protobuf_FieldOptions_FeatureSupport__fields.fields[0], - UPB_SIZE(40, 56), 5, kUpb_ExtMode_NonExtendable, 5, UPB_FASTTABLE_MASK(56), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FieldOptions.FeatureSupport", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800000200001a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x002800000400002a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[2]; - upb_MiniTableSubInternal subs[2]; -} google__protobuf__OneofOptions_msg_init_Fields; - -static const google__protobuf__OneofOptions_msg_init_Fields google_protobuf_OneofOptions__fields = {{ - {1, UPB_SIZE(12, 16), 64, 6, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 5), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__OneofOptions_msg_init = { - &google_protobuf_OneofOptions__fields.fields[0], - UPB_SIZE(24, 32), 2, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.OneofOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800003f013eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[5]; - upb_MiniTableSubInternal subs[2]; -} google__protobuf__EnumOptions_msg_init_Fields; - -static const google__protobuf__EnumOptions_msg_init_Fields google_protobuf_EnumOptions__fields = {{ - {2, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {3, 10, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {6, 11, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(12, 16), 67, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__EnumOptions_msg_init = { - &google_protobuf_EnumOptions__fields.fields[0], - UPB_SIZE(24, 32), 5, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.EnumOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0009000000000010, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x000a000001000018, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000b000002000030, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x001000000303003a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800003f043eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[5]; - upb_MiniTableSubInternal subs[3]; -} google__protobuf__EnumValueOptions_msg_init_Fields; - -static const google__protobuf__EnumValueOptions_msg_init_Fields google_protobuf_EnumValueOptions__fields = {{ - {1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 16), 65, UPB_SIZE(12, 13), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, 10, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(16, 24), 67, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(20, 32), 0, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FieldOptions__FeatureSupport_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__EnumValueOptions_msg_init = { - &google_protobuf_EnumValueOptions__fields.fields[0], - UPB_SIZE(24, 40), 5, kUpb_ExtMode_Extendable, 4, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.EnumValueOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0009000000000008, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0010000001010012, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x000a000002000018, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0018000003030022, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x002000003f043eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[3]; - upb_MiniTableSubInternal subs[2]; -} google__protobuf__ServiceOptions_msg_init_Fields; - -static const google__protobuf__ServiceOptions_msg_init_Fields google_protobuf_ServiceOptions__fields = {{ - {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {34, UPB_SIZE(12, 16), 65, UPB_SIZE(6, 7), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(16, 24), 0, UPB_SIZE(4, 6), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__ServiceOptions_msg_init = { - &google_protobuf_ServiceOptions__fields.fields[0], - UPB_SIZE(24, 32), 3, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.ServiceOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0009000000000288, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x0010000001010292, &upb_DecodeFast_Message_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800003f023eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[4]; - upb_MiniTableSubInternal subs[3]; -} google__protobuf__MethodOptions_msg_init_Fields; - -static const google__protobuf__MethodOptions_msg_init_Fields google_protobuf_MethodOptions__fields = {{ - {33, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {34, 12, 65, 9, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {35, 16, 66, UPB_SIZE(7, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(20, 24), 0, UPB_SIZE(5, 7), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__MethodOptions__IdempotencyLevel_enum_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init}, -}}; - -const upb_MiniTable google__protobuf__MethodOptions_msg_init = { - &google_protobuf_MethodOptions__fields.fields[0], - UPB_SIZE(24, 32), 4, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.MethodOptions", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0009000000000288, &upb_DecodeFast_Bool_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000202029a, &upb_DecodeFast_Message_Scalar_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800003f033eba, &upb_DecodeFast_Message_Repeated_Tag2Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[7]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__UninterpretedOption_msg_init_Fields; - -static const google__protobuf__UninterpretedOption_msg_init_Fields google_protobuf_UninterpretedOption__fields = {{ - {2, UPB_SIZE(12, 64), 0, UPB_SIZE(21, 22), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, 16, 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(40, 72), 65, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(48, 80), 66, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(56, 88), 67, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(24, 32), 68, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(32, 48), 69, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption__NamePart_msg_init}, -}}; - -const upb_MiniTable google__protobuf__UninterpretedOption_msg_init = { - &google_protobuf_UninterpretedOption__fields.fields[0], - UPB_SIZE(64, 96), 7, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(120), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.UninterpretedOption", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x004000003f000012, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - {0x001000000000001a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0048000001000020, &upb_DecodeFast_Varint64_Scalar_Tag1Byte}, - {0x0050000002000028, &upb_DecodeFast_Varint64_Scalar_Tag1Byte}, - {0x0058000003000031, &upb_DecodeFast_Fixed64_Scalar_Tag1Byte}, - {0x002000000400003a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0030000005000042, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[2]; -} google__protobuf__UninterpretedOption__NamePart_msg_init_Fields; - -static const google__protobuf__UninterpretedOption__NamePart_msg_init_Fields google_protobuf_UninterpretedOption_NamePart__fields = {{ - {1, UPB_SIZE(12, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, 9, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, -}}; - -const upb_MiniTable google__protobuf__UninterpretedOption__NamePart_msg_init = { - &google_protobuf_UninterpretedOption_NamePart__fields.fields[0], - UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 2, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.UninterpretedOption.NamePart", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001000000000000a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0009000001000010, &upb_DecodeFast_Bool_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[8]; - upb_MiniTableSubInternal subs[8]; -} google__protobuf__FeatureSet_msg_init_Fields; - -static const google__protobuf__FeatureSet_msg_init_Fields google_protobuf_FeatureSet__fields = {{ - {1, 12, 64, 24, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {2, 16, 65, UPB_SIZE(22, 23), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, 20, 66, UPB_SIZE(20, 22), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {4, 24, 67, UPB_SIZE(18, 21), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, 28, 68, UPB_SIZE(16, 20), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {6, 32, 69, UPB_SIZE(14, 19), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {7, 36, 70, UPB_SIZE(12, 18), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {8, 40, 71, UPB_SIZE(10, 17), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__FieldPresence_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__EnumType_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__RepeatedFieldEncoding_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__Utf8Validation_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__MessageEncoding_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__JsonFormat_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__EnforceNamingStyle_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__FeatureSet__VisibilityFeature__DefaultSymbolVisibility_enum_init}, -}}; - -const upb_MiniTable google__protobuf__FeatureSet_msg_init = { - &google_protobuf_FeatureSet__fields.fields[0], - 48, 8, kUpb_ExtMode_Extendable, 8, UPB_FASTTABLE_MASK(255), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FeatureSet", -#endif -}; - -const upb_MiniTable google__protobuf__FeatureSet__VisibilityFeature_msg_init = { - NULL, - 8, 0, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(255), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FeatureSet.VisibilityFeature", -#endif -}; - -typedef struct { - upb_MiniTableField fields[3]; - upb_MiniTableSubInternal subs[3]; -} google__protobuf__FeatureSetDefaults_msg_init_Fields; - -static const google__protobuf__FeatureSetDefaults_msg_init_Fields google_protobuf_FeatureSetDefaults__fields = {{ - {1, UPB_SIZE(12, 24), 0, UPB_SIZE(9, 10), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(16, 12), 64, UPB_SIZE(7, 9), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(20, 16), 65, UPB_SIZE(5, 8), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, -}}; - -const upb_MiniTable google__protobuf__FeatureSetDefaults_msg_init = { - &google_protobuf_FeatureSetDefaults__fields.fields[0], - UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FeatureSetDefaults", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800003f00000a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[3]; - upb_MiniTableSubInternal subs[3]; -} google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init_Fields; - -static const google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init_Fields google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields = {{ - {3, 12, 64, UPB_SIZE(9, 10), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {4, 16, 65, UPB_SIZE(7, 9), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(20, 24), 66, UPB_SIZE(5, 8), 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__Edition_enum_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, - {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init}, -}}; - -const upb_MiniTable google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init = { - &google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields.fields[0], - UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(56), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0010000001010022, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x001800000202002a, &upb_DecodeFast_Message_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[1]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__SourceCodeInfo_msg_init_Fields; - -static const google__protobuf__SourceCodeInfo_msg_init_Fields google_protobuf_SourceCodeInfo__fields = {{ - {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__SourceCodeInfo__Location_msg_init}, -}}; - -const upb_MiniTable google__protobuf__SourceCodeInfo_msg_init = { - &google_protobuf_SourceCodeInfo__fields.fields[0], - 16, 1, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(8), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.SourceCodeInfo", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000800003f00000a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[5]; -} google__protobuf__SourceCodeInfo__Location_msg_init_Fields; - -static const google__protobuf__SourceCodeInfo__Location_msg_init_Fields google_protobuf_SourceCodeInfo_Location__fields = {{ - {1, UPB_SIZE(12, 48), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(16, 56), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(24, 16), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, 32, 65, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(20, 64), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, -}}; - -const upb_MiniTable google__protobuf__SourceCodeInfo__Location_msg_init = { - &google_protobuf_SourceCodeInfo_Location__fields.fields[0], - UPB_SIZE(40, 72), 5, kUpb_ExtMode_NonExtendable, 4, UPB_FASTTABLE_MASK(56), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.SourceCodeInfo.Location", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x003000003f00000a, &upb_DecodeFast_Varint32_Packed_Tag1Byte}, - {0x003800003f000012, &upb_DecodeFast_Varint32_Packed_Tag1Byte}, - {0x001000000000001a, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0020000001000022, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x004000003f000032, &upb_DecodeFast_Bytes_Repeated_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -typedef struct { - upb_MiniTableField fields[1]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__GeneratedCodeInfo_msg_init_Fields; - -static const google__protobuf__GeneratedCodeInfo_msg_init_Fields google_protobuf_GeneratedCodeInfo__fields = {{ - {1, 8, 0, UPB_SIZE(3, 4), 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(submsg) = &google__protobuf__GeneratedCodeInfo__Annotation_msg_init}, -}}; - -const upb_MiniTable google__protobuf__GeneratedCodeInfo_msg_init = { - &google_protobuf_GeneratedCodeInfo__fields.fields[0], - 16, 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.GeneratedCodeInfo", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x000800003f00000a, &upb_DecodeFast_Message_Repeated_Tag1Byte}, - }) -}; - -typedef struct { - upb_MiniTableField fields[5]; - upb_MiniTableSubInternal subs[1]; -} google__protobuf__GeneratedCodeInfo__Annotation_msg_init_Fields; - -static const google__protobuf__GeneratedCodeInfo__Annotation_msg_init_Fields google_protobuf_GeneratedCodeInfo_Annotation__fields = {{ - {1, UPB_SIZE(12, 40), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(28, 24), 64, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 12), 65, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(20, 16), 66, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(24, 20), 67, UPB_SIZE(3, 4), 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - }, - { - {.UPB_PRIVATE(subenum) = &google__protobuf__GeneratedCodeInfo__Annotation__Semantic_enum_init}, -}}; - -const upb_MiniTable google__protobuf__GeneratedCodeInfo__Annotation_msg_init = { - &google_protobuf_GeneratedCodeInfo_Annotation__fields.fields[0], - UPB_SIZE(40, 48), 5, kUpb_ExtMode_NonExtendable, 5, UPB_FASTTABLE_MASK(56), 0, -#ifdef UPB_TRACING_ENABLED - "google.protobuf.GeneratedCodeInfo.Annotation", -#endif - UPB_FASTTABLE_INIT({ - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x002800003f00000a, &upb_DecodeFast_Varint32_Packed_Tag1Byte}, - {0x0018000000000012, &upb_DecodeFast_Bytes_Scalar_Tag1Byte}, - {0x000c000001000018, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0010000002000020, &upb_DecodeFast_Varint32_Scalar_Tag1Byte}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - }) -}; - -const upb_MiniTableEnum google__protobuf__Edition_enum_init = { - 64, - 11, - { - 0x7, - 0x0, - 0x384, - 0x3e6, - 0x3e7, - 0x3e8, - 0x3e9, - 0x3ea, - 0x270f, - 0x1869d, - 0x1869e, - 0x1869f, - 0x7fffffff, - }, -}; - -const upb_MiniTableEnum google__protobuf__ExtensionRangeOptions__VerificationState_enum_init = { - 64, - 0, - { - 0x3, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__EnforceNamingStyle_enum_init = { - 64, - 0, - { - 0xf, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__EnumType_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__FieldPresence_enum_init = { - 64, - 0, - { - 0xf, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__JsonFormat_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__MessageEncoding_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__RepeatedFieldEncoding_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__Utf8Validation_enum_init = { - 64, - 0, - { - 0xd, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FeatureSet__VisibilityFeature__DefaultSymbolVisibility_enum_init = { - 64, - 0, - { - 0x1f, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FieldDescriptorProto__Label_enum_init = { - 64, - 0, - { - 0xe, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FieldDescriptorProto__Type_enum_init = { - 64, - 0, - { - 0x7fffe, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FieldOptions__CType_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FieldOptions__JSType_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FieldOptions__OptionRetention_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FieldOptions__OptionTargetType_enum_init = { - 64, - 0, - { - 0x3ff, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__FileOptions__OptimizeMode_enum_init = { - 64, - 0, - { - 0xe, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__GeneratedCodeInfo__Annotation__Semantic_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__MethodOptions__IdempotencyLevel_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -const upb_MiniTableEnum google__protobuf__SymbolVisibility_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -static const upb_MiniTable *messages_layout[34] = { - &google__protobuf__FileDescriptorSet_msg_init, - &google__protobuf__FileDescriptorProto_msg_init, - &google__protobuf__DescriptorProto_msg_init, - &google__protobuf__DescriptorProto__ExtensionRange_msg_init, - &google__protobuf__DescriptorProto__ReservedRange_msg_init, - &google__protobuf__ExtensionRangeOptions_msg_init, - &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, - &google__protobuf__FieldDescriptorProto_msg_init, - &google__protobuf__OneofDescriptorProto_msg_init, - &google__protobuf__EnumDescriptorProto_msg_init, - &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, - &google__protobuf__EnumValueDescriptorProto_msg_init, - &google__protobuf__ServiceDescriptorProto_msg_init, - &google__protobuf__MethodDescriptorProto_msg_init, - &google__protobuf__FileOptions_msg_init, - &google__protobuf__MessageOptions_msg_init, - &google__protobuf__FieldOptions_msg_init, - &google__protobuf__FieldOptions__EditionDefault_msg_init, - &google__protobuf__FieldOptions__FeatureSupport_msg_init, - &google__protobuf__OneofOptions_msg_init, - &google__protobuf__EnumOptions_msg_init, - &google__protobuf__EnumValueOptions_msg_init, - &google__protobuf__ServiceOptions_msg_init, - &google__protobuf__MethodOptions_msg_init, - &google__protobuf__UninterpretedOption_msg_init, - &google__protobuf__UninterpretedOption__NamePart_msg_init, - &google__protobuf__FeatureSet_msg_init, - &google__protobuf__FeatureSet__VisibilityFeature_msg_init, - &google__protobuf__FeatureSetDefaults_msg_init, - &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, - &google__protobuf__SourceCodeInfo_msg_init, - &google__protobuf__SourceCodeInfo__Location_msg_init, - &google__protobuf__GeneratedCodeInfo_msg_init, - &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, -}; - -static const upb_MiniTableEnum *enums_layout[20] = { - &google__protobuf__Edition_enum_init, - &google__protobuf__ExtensionRangeOptions__VerificationState_enum_init, - &google__protobuf__FeatureSet__EnforceNamingStyle_enum_init, - &google__protobuf__FeatureSet__EnumType_enum_init, - &google__protobuf__FeatureSet__FieldPresence_enum_init, - &google__protobuf__FeatureSet__JsonFormat_enum_init, - &google__protobuf__FeatureSet__MessageEncoding_enum_init, - &google__protobuf__FeatureSet__RepeatedFieldEncoding_enum_init, - &google__protobuf__FeatureSet__Utf8Validation_enum_init, - &google__protobuf__FeatureSet__VisibilityFeature__DefaultSymbolVisibility_enum_init, - &google__protobuf__FieldDescriptorProto__Label_enum_init, - &google__protobuf__FieldDescriptorProto__Type_enum_init, - &google__protobuf__FieldOptions__CType_enum_init, - &google__protobuf__FieldOptions__JSType_enum_init, - &google__protobuf__FieldOptions__OptionRetention_enum_init, - &google__protobuf__FieldOptions__OptionTargetType_enum_init, - &google__protobuf__FileOptions__OptimizeMode_enum_init, - &google__protobuf__GeneratedCodeInfo__Annotation__Semantic_enum_init, - &google__protobuf__MethodOptions__IdempotencyLevel_enum_init, - &google__protobuf__SymbolVisibility_enum_init, -}; - -const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout = { - messages_layout, - enums_layout, - NULL, - 34, - 20, - 0, -}; - -#include "upb/port/undef.inc" - diff --git a/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb_minitable.h b/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb_minitable.h deleted file mode 100644 index 39de6ab..0000000 --- a/vendor/upb/reflection/cmake/google/protobuf/descriptor.upb_minitable.h +++ /dev/null @@ -1,84 +0,0 @@ -/* This file was generated by upb_generator from the input file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. - * NO CHECKED-IN PROTOBUF GENCODE */ - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_MINITABLE_H_ -#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_MINITABLE_H_ - -#include "upb/generated_code_support.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const upb_MiniTable google__protobuf__FileDescriptorSet_msg_init; -extern const upb_MiniTable google__protobuf__FileDescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__DescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__DescriptorProto__ExtensionRange_msg_init; -extern const upb_MiniTable google__protobuf__DescriptorProto__ReservedRange_msg_init; -extern const upb_MiniTable google__protobuf__ExtensionRangeOptions_msg_init; -extern const upb_MiniTable google__protobuf__ExtensionRangeOptions__Declaration_msg_init; -extern const upb_MiniTable google__protobuf__FieldDescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__OneofDescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__EnumDescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init; -extern const upb_MiniTable google__protobuf__EnumValueDescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__ServiceDescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__MethodDescriptorProto_msg_init; -extern const upb_MiniTable google__protobuf__FileOptions_msg_init; -extern const upb_MiniTable google__protobuf__MessageOptions_msg_init; -extern const upb_MiniTable google__protobuf__FieldOptions_msg_init; -extern const upb_MiniTable google__protobuf__FieldOptions__EditionDefault_msg_init; -extern const upb_MiniTable google__protobuf__FieldOptions__FeatureSupport_msg_init; -extern const upb_MiniTable google__protobuf__OneofOptions_msg_init; -extern const upb_MiniTable google__protobuf__EnumOptions_msg_init; -extern const upb_MiniTable google__protobuf__EnumValueOptions_msg_init; -extern const upb_MiniTable google__protobuf__ServiceOptions_msg_init; -extern const upb_MiniTable google__protobuf__MethodOptions_msg_init; -extern const upb_MiniTable google__protobuf__UninterpretedOption_msg_init; -extern const upb_MiniTable google__protobuf__UninterpretedOption__NamePart_msg_init; -extern const upb_MiniTable google__protobuf__FeatureSet_msg_init; -extern const upb_MiniTable google__protobuf__FeatureSet__VisibilityFeature_msg_init; -extern const upb_MiniTable google__protobuf__FeatureSetDefaults_msg_init; -extern const upb_MiniTable google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init; -extern const upb_MiniTable google__protobuf__SourceCodeInfo_msg_init; -extern const upb_MiniTable google__protobuf__SourceCodeInfo__Location_msg_init; -extern const upb_MiniTable google__protobuf__GeneratedCodeInfo_msg_init; -extern const upb_MiniTable google__protobuf__GeneratedCodeInfo__Annotation_msg_init; - -extern const upb_MiniTableEnum google__protobuf__Edition_enum_init; -extern const upb_MiniTableEnum google__protobuf__ExtensionRangeOptions__VerificationState_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__EnforceNamingStyle_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__EnumType_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__FieldPresence_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__JsonFormat_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__MessageEncoding_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__RepeatedFieldEncoding_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__Utf8Validation_enum_init; -extern const upb_MiniTableEnum google__protobuf__FeatureSet__VisibilityFeature__DefaultSymbolVisibility_enum_init; -extern const upb_MiniTableEnum google__protobuf__FieldDescriptorProto__Label_enum_init; -extern const upb_MiniTableEnum google__protobuf__FieldDescriptorProto__Type_enum_init; -extern const upb_MiniTableEnum google__protobuf__FieldOptions__CType_enum_init; -extern const upb_MiniTableEnum google__protobuf__FieldOptions__JSType_enum_init; -extern const upb_MiniTableEnum google__protobuf__FieldOptions__OptionRetention_enum_init; -extern const upb_MiniTableEnum google__protobuf__FieldOptions__OptionTargetType_enum_init; -extern const upb_MiniTableEnum google__protobuf__FileOptions__OptimizeMode_enum_init; -extern const upb_MiniTableEnum google__protobuf__GeneratedCodeInfo__Annotation__Semantic_enum_init; -extern const upb_MiniTableEnum google__protobuf__MethodOptions__IdempotencyLevel_enum_init; -extern const upb_MiniTableEnum google__protobuf__SymbolVisibility_enum_init; -extern const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout; - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_MINITABLE_H_ */ diff --git a/vendor/upb/reflection/common.h b/vendor/upb/reflection/common.h deleted file mode 100644 index 6f7590e..0000000 --- a/vendor/upb/reflection/common.h +++ /dev/null @@ -1,35 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -// Declarations common to all public def types. - -#ifndef UPB_REFLECTION_COMMON_H_ -#define UPB_REFLECTION_COMMON_H_ - -#include "upb/reflection/descriptor_bootstrap.h" // IWYU pragma: export - -// Forward declarations for circular references. -typedef struct upb_DefPool upb_DefPool; -typedef struct upb_EnumDef upb_EnumDef; -typedef struct upb_EnumReservedRange upb_EnumReservedRange; -typedef struct upb_EnumValueDef upb_EnumValueDef; -typedef struct upb_ExtensionRange upb_ExtensionRange; -typedef struct upb_FieldDef upb_FieldDef; -typedef struct upb_FileDef upb_FileDef; -typedef struct upb_MessageDef upb_MessageDef; -typedef struct upb_MessageReservedRange upb_MessageReservedRange; -typedef struct upb_MethodDef upb_MethodDef; -typedef struct upb_OneofDef upb_OneofDef; -typedef struct upb_ServiceDef upb_ServiceDef; - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -typedef struct upb_DefBuilder upb_DefBuilder; - -#endif /* UPB_REFLECTION_COMMON_H_ */ diff --git a/vendor/upb/reflection/def.h b/vendor/upb/reflection/def.h deleted file mode 100644 index ba8e839..0000000 --- a/vendor/upb/reflection/def.h +++ /dev/null @@ -1,24 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_DEF_H_ -#define UPB_REFLECTION_DEF_H_ - -// IWYU pragma: begin_exports -#include "upb/reflection/def_pool.h" -#include "upb/reflection/enum_def.h" -#include "upb/reflection/enum_value_def.h" -#include "upb/reflection/extension_range.h" -#include "upb/reflection/field_def.h" -#include "upb/reflection/file_def.h" -#include "upb/reflection/message_def.h" -#include "upb/reflection/method_def.h" -#include "upb/reflection/oneof_def.h" -#include "upb/reflection/service_def.h" -// IWYU pragma: end_exports - -#endif /* UPB_REFLECTION_DEF_H_ */ diff --git a/vendor/upb/reflection/def.hpp b/vendor/upb/reflection/def.hpp deleted file mode 100644 index c088853..0000000 --- a/vendor/upb/reflection/def.hpp +++ /dev/null @@ -1,644 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_DEF_HPP_ -#define UPB_REFLECTION_DEF_HPP_ - -#include - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/status.hpp" -#include "upb/base/string_view.h" -#include "upb/mem/arena.hpp" -#include "upb/message/value.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_pool.h" -#include "upb/reflection/internal/enum_def.h" -#include "upb/reflection/message.h" - -// Must be last -#include "upb/port/def.inc" - -namespace upb { - -typedef upb_MessageValue MessageValue; - -class EnumDefPtr; -class FileDefPtr; -class MessageDefPtr; -class OneofDefPtr; - -// A upb::FieldDefPtr describes a single field in a message. It is most often -// found as a part of a upb_MessageDef, but can also stand alone to represent -// an extension. -class FieldDefPtr { - public: - FieldDefPtr() : ptr_(nullptr) {} - explicit FieldDefPtr(const upb_FieldDef* ptr) : ptr_(ptr) {} - - const upb_FieldDef* ptr() const { return ptr_; } - - typedef upb_FieldType Type; - typedef upb_CType CType; - typedef upb_Label Label; - - FileDefPtr file() const; - const char* full_name() const { return upb_FieldDef_FullName(ptr_); } - - const upb_MiniTableField* mini_table() const { - return upb_FieldDef_MiniTable(ptr_); - } - - std::string MiniDescriptorEncode() const { - upb::Arena arena; - upb_StringView md; - upb_FieldDef_MiniDescriptorEncode(ptr_, arena.ptr(), &md); - return std::string(md.data, md.size); - } - - const google_protobuf_FieldOptions* options() const { - return upb_FieldDef_Options(ptr_); - } - - Type type() const { return upb_FieldDef_Type(ptr_); } - CType ctype() const { return upb_FieldDef_CType(ptr_); } - Label label() const { return upb_FieldDef_Label(ptr_); } - const char* name() const { return upb_FieldDef_Name(ptr_); } - const char* json_name() const { return upb_FieldDef_JsonName(ptr_); } - uint32_t number() const { return upb_FieldDef_Number(ptr_); } - bool is_extension() const { return upb_FieldDef_IsExtension(ptr_); } - bool is_required() const { return upb_FieldDef_IsRequired(ptr_); } - bool has_presence() const { return upb_FieldDef_HasPresence(ptr_); } - - // For non-string, non-submessage fields, this indicates whether binary - // protobufs are encoded in packed or non-packed format. - // - // Note: this accessor reflects the fact that "packed" has different defaults - // depending on whether the proto is proto2 or proto3. - bool packed() const { return upb_FieldDef_IsPacked(ptr_); } - - // An integer that can be used as an index into an array of fields for - // whatever message this field belongs to. Guaranteed to be less than - // f->containing_type()->field_count(). May only be accessed once the def has - // been finalized. - // The index ordering here is *dependent* on the order of the fields in the - // .proto file. - uint32_t index() const { return upb_FieldDef_Index(ptr_); } - - // Index into msgdef->layout->fields or file->exts. - // This is the index that the MiniTable uses, and is independent of the order - // of the fields in the .proto file. - uint32_t layout_index() const { return upb_FieldDef_LayoutIndex(ptr_); } - - // The MessageDef to which this field belongs (for extensions, the extended - // message). - MessageDefPtr containing_type() const; - - // For extensions, the message the extension is declared inside, or NULL if - // none. - MessageDefPtr extension_scope() const; - - // The OneofDef to which this field belongs, or NULL if this field is not part - // of a oneof. - OneofDefPtr containing_oneof() const; - OneofDefPtr real_containing_oneof() const; - - // Convenient field type tests. - bool IsEnum() const { return upb_FieldDef_IsEnum(ptr_); } - bool IsSubMessage() const { return upb_FieldDef_IsSubMessage(ptr_); } - bool IsString() const { return upb_FieldDef_IsString(ptr_); } - bool IsSequence() const { return upb_FieldDef_IsRepeated(ptr_); } - bool IsPrimitive() const { return upb_FieldDef_IsPrimitive(ptr_); } - bool IsMap() const { return upb_FieldDef_IsMap(ptr_); } - - MessageValue default_value() const { return upb_FieldDef_Default(ptr_); } - - // Returns the enum or submessage def for this field, if any. The field's - // type must match (ie. you may only call enum_subdef() for fields where - // type() == kUpb_CType_Enum). - EnumDefPtr enum_subdef() const; - MessageDefPtr message_type() const; - - explicit operator bool() const { return ptr_ != nullptr; } - - friend bool operator==(FieldDefPtr lhs, FieldDefPtr rhs) { - return lhs.ptr_ == rhs.ptr_; - } - - friend bool operator!=(FieldDefPtr lhs, FieldDefPtr rhs) { - return !(lhs == rhs); - } - - private: - const upb_FieldDef* ptr_; -}; - -// Class that represents a oneof. -class OneofDefPtr { - public: - OneofDefPtr() : ptr_(nullptr) {} - explicit OneofDefPtr(const upb_OneofDef* ptr) : ptr_(ptr) {} - - const upb_OneofDef* ptr() const { return ptr_; } - explicit operator bool() const { return ptr_ != nullptr; } - - const google_protobuf_OneofOptions* options() const { - return upb_OneofDef_Options(ptr_); - } - - // Returns the MessageDef that contains this OneofDef. - MessageDefPtr containing_type() const; - - // Returns the name of this oneof. - const char* name() const { return upb_OneofDef_Name(ptr_); } - const char* full_name() const { return upb_OneofDef_FullName(ptr_); } - - // Returns the number of fields in the oneof. - int field_count() const { return upb_OneofDef_FieldCount(ptr_); } - FieldDefPtr field(int i) const { - return FieldDefPtr(upb_OneofDef_Field(ptr_, i)); - } - - // Looks up by name. - FieldDefPtr FindFieldByName(const char* name, size_t len) const { - return FieldDefPtr(upb_OneofDef_LookupNameWithSize(ptr_, name, len)); - } - FieldDefPtr FindFieldByName(const char* name) const { - return FieldDefPtr(upb_OneofDef_LookupName(ptr_, name)); - } - - template - FieldDefPtr FindFieldByName(const T& str) const { - return FindFieldByName(str.c_str(), str.size()); - } - - // Looks up by tag number. - FieldDefPtr FindFieldByNumber(uint32_t num) const { - return FieldDefPtr(upb_OneofDef_LookupNumber(ptr_, num)); - } - - private: - const upb_OneofDef* ptr_; -}; - -// Structure that describes a single .proto message type. -class MessageDefPtr { - public: - MessageDefPtr() : ptr_(nullptr) {} - explicit MessageDefPtr(const upb_MessageDef* ptr) : ptr_(ptr) {} - - const google_protobuf_MessageOptions* options() const { - return upb_MessageDef_Options(ptr_); - } - - std::string MiniDescriptorEncode() const { - upb::Arena arena; - upb_StringView md; - upb_MessageDef_MiniDescriptorEncode(ptr_, arena.ptr(), &md); - return std::string(md.data, md.size); - } - - const upb_MessageDef* ptr() const { return ptr_; } - - FileDefPtr file() const; - - const char* full_name() const { return upb_MessageDef_FullName(ptr_); } - const char* name() const { return upb_MessageDef_Name(ptr_); } - - // Returns the MessageDef that contains this MessageDef (or null). - MessageDefPtr containing_type() const; - - const upb_MiniTable* mini_table() const { - return upb_MessageDef_MiniTable(ptr_); - } - - // The number of fields that belong to the MessageDef. - int field_count() const { return upb_MessageDef_FieldCount(ptr_); } - FieldDefPtr field(int i) const { - return FieldDefPtr(upb_MessageDef_Field(ptr_, i)); - } - - // The number of oneofs that belong to the MessageDef. - int oneof_count() const { return upb_MessageDef_OneofCount(ptr_); } - int real_oneof_count() const { return upb_MessageDef_RealOneofCount(ptr_); } - OneofDefPtr oneof(int i) const { - return OneofDefPtr(upb_MessageDef_Oneof(ptr_, i)); - } - - int enum_type_count() const { return upb_MessageDef_NestedEnumCount(ptr_); } - EnumDefPtr enum_type(int i) const; - - int nested_message_count() const { - return upb_MessageDef_NestedMessageCount(ptr_); - } - MessageDefPtr nested_message(int i) const { - return MessageDefPtr(upb_MessageDef_NestedMessage(ptr_, i)); - } - - int nested_extension_count() const { - return upb_MessageDef_NestedExtensionCount(ptr_); - } - FieldDefPtr nested_extension(int i) const { - return FieldDefPtr(upb_MessageDef_NestedExtension(ptr_, i)); - } - - int extension_range_count() const { - return upb_MessageDef_ExtensionRangeCount(ptr_); - } - - // These return null pointers if the field is not found. - FieldDefPtr FindFieldByNumber(uint32_t number) const { - return FieldDefPtr(upb_MessageDef_FindFieldByNumber(ptr_, number)); - } - FieldDefPtr FindFieldByName(const char* name, size_t len) const { - return FieldDefPtr(upb_MessageDef_FindFieldByNameWithSize(ptr_, name, len)); - } - FieldDefPtr FindFieldByName(const char* name) const { - return FieldDefPtr(upb_MessageDef_FindFieldByName(ptr_, name)); - } - - template - FieldDefPtr FindFieldByName(const T& str) const { - return FindFieldByName(str.c_str(), str.size()); - } - - OneofDefPtr FindOneofByName(const char* name, size_t len) const { - return OneofDefPtr(upb_MessageDef_FindOneofByNameWithSize(ptr_, name, len)); - } - - OneofDefPtr FindOneofByName(const char* name) const { - return OneofDefPtr(upb_MessageDef_FindOneofByName(ptr_, name)); - } - - template - OneofDefPtr FindOneofByName(const T& str) const { - return FindOneofByName(str.c_str(), str.size()); - } - - // Is this message a map entry? - bool mapentry() const { return upb_MessageDef_IsMapEntry(ptr_); } - - FieldDefPtr map_key() const { - if (!mapentry()) return FieldDefPtr(); - return FieldDefPtr(upb_MessageDef_Field(ptr_, 0)); - } - - FieldDefPtr map_value() const { - if (!mapentry()) return FieldDefPtr(); - return FieldDefPtr(upb_MessageDef_Field(ptr_, 1)); - } - - // Return the type of well known type message. kUpb_WellKnown_Unspecified for - // non-well-known message. - upb_WellKnown wellknowntype() const { - return upb_MessageDef_WellKnownType(ptr_); - } - - explicit operator bool() const { return ptr_ != nullptr; } - - friend bool operator==(MessageDefPtr lhs, MessageDefPtr rhs) { - return lhs.ptr_ == rhs.ptr_; - } - - friend bool operator!=(MessageDefPtr lhs, MessageDefPtr rhs) { - return !(lhs == rhs); - } - - private: - class FieldIter { - public: - explicit FieldIter(const upb_MessageDef* m, int i) : m_(m), i_(i) {} - void operator++() { i_++; } - - FieldDefPtr operator*() { - return FieldDefPtr(upb_MessageDef_Field(m_, i_)); - } - - friend bool operator==(FieldIter lhs, FieldIter rhs) { - return lhs.i_ == rhs.i_; - } - - friend bool operator!=(FieldIter lhs, FieldIter rhs) { - return !(lhs == rhs); - } - - private: - const upb_MessageDef* m_; - int i_; - }; - - class FieldAccessor { - public: - explicit FieldAccessor(const upb_MessageDef* md) : md_(md) {} - FieldIter begin() { return FieldIter(md_, 0); } - FieldIter end() { return FieldIter(md_, upb_MessageDef_FieldCount(md_)); } - - private: - const upb_MessageDef* md_; - }; - - class OneofIter { - public: - explicit OneofIter(const upb_MessageDef* m, int i) : m_(m), i_(i) {} - void operator++() { i_++; } - - OneofDefPtr operator*() { - return OneofDefPtr(upb_MessageDef_Oneof(m_, i_)); - } - - friend bool operator==(OneofIter lhs, OneofIter rhs) { - return lhs.i_ == rhs.i_; - } - - friend bool operator!=(OneofIter lhs, OneofIter rhs) { - return !(lhs == rhs); - } - - private: - const upb_MessageDef* m_; - int i_; - }; - - class OneofAccessor { - public: - explicit OneofAccessor(const upb_MessageDef* md) : md_(md) {} - OneofIter begin() { return OneofIter(md_, 0); } - OneofIter end() { return OneofIter(md_, upb_MessageDef_OneofCount(md_)); } - - private: - const upb_MessageDef* md_; - }; - - public: - FieldAccessor fields() const { return FieldAccessor(ptr()); } - OneofAccessor oneofs() const { return OneofAccessor(ptr()); } - - private: - const upb_MessageDef* ptr_; -}; - -class EnumValDefPtr { - public: - EnumValDefPtr() : ptr_(nullptr) {} - explicit EnumValDefPtr(const upb_EnumValueDef* ptr) : ptr_(ptr) {} - - const google_protobuf_EnumValueOptions* options() const { - return upb_EnumValueDef_Options(ptr_); - } - - int32_t number() const { return upb_EnumValueDef_Number(ptr_); } - const char* full_name() const { return upb_EnumValueDef_FullName(ptr_); } - const char* name() const { return upb_EnumValueDef_Name(ptr_); } - - private: - const upb_EnumValueDef* ptr_; -}; - -class EnumDefPtr { - public: - EnumDefPtr() : ptr_(nullptr) {} - explicit EnumDefPtr(const upb_EnumDef* ptr) : ptr_(ptr) {} - - const google_protobuf_EnumOptions* options() const { - return upb_EnumDef_Options(ptr_); - } - - const upb_MiniTableEnum* mini_table() const { - return _upb_EnumDef_MiniTable(ptr_); - } - - std::string MiniDescriptorEncode() const { - upb::Arena arena; - upb_StringView md; - upb_EnumDef_MiniDescriptorEncode(ptr_, arena.ptr(), &md); - return std::string(md.data, md.size); - } - - const upb_EnumDef* ptr() const { return ptr_; } - explicit operator bool() const { return ptr_ != nullptr; } - - FileDefPtr file() const; - const char* full_name() const { return upb_EnumDef_FullName(ptr_); } - const char* name() const { return upb_EnumDef_Name(ptr_); } - bool is_closed() const { return upb_EnumDef_IsClosed(ptr_); } - - // Returns the MessageDef that contains this EnumDef (or null). - MessageDefPtr containing_type() const; - - // The value that is used as the default when no field default is specified. - // If not set explicitly, the first value that was added will be used. - // The default value must be a member of the enum. - // Requires that value_count() > 0. - int32_t default_value() const { return upb_EnumDef_Default(ptr_); } - - // Returns the number of values currently defined in the enum. Note that - // multiple names can refer to the same number, so this may be greater than - // the total number of unique numbers. - int value_count() const { return upb_EnumDef_ValueCount(ptr_); } - EnumValDefPtr value(int i) const { - return EnumValDefPtr(upb_EnumDef_Value(ptr_, i)); - } - - // Lookups from name to integer, returning true if found. - EnumValDefPtr FindValueByName(const char* name) const { - return EnumValDefPtr(upb_EnumDef_FindValueByName(ptr_, name)); - } - - // Finds the name corresponding to the given number, or NULL if none was - // found. If more than one name corresponds to this number, returns the - // first one that was added. - EnumValDefPtr FindValueByNumber(int32_t num) const { - return EnumValDefPtr(upb_EnumDef_FindValueByNumber(ptr_, num)); - } - - private: - const upb_EnumDef* ptr_; -}; - -// Class that represents a .proto file with some things defined in it. -// -// Many users won't care about FileDefs, but they are necessary if you want to -// read the values of file-level options. -class FileDefPtr { - public: - explicit FileDefPtr(const upb_FileDef* ptr) : ptr_(ptr) {} - - const google_protobuf_FileOptions* options() const { - return upb_FileDef_Options(ptr_); - } - - const upb_FileDef* ptr() const { return ptr_; } - - // Get/set name of the file (eg. "foo/bar.proto"). - const char* name() const { return upb_FileDef_Name(ptr_); } - - // Package name for definitions inside the file (eg. "foo.bar"). - const char* package() const { return upb_FileDef_Package(ptr_); } - - // Get the list of dependencies from the file. These are returned in the - // order that they were added to the FileDefPtr. - int dependency_count() const { return upb_FileDef_DependencyCount(ptr_); } - FileDefPtr dependency(int index) const { - return FileDefPtr(upb_FileDef_Dependency(ptr_, index)); - } - - int public_dependency_count() const { - return upb_FileDef_PublicDependencyCount(ptr_); - } - FileDefPtr public_dependency(int index) const { - return FileDefPtr(upb_FileDef_PublicDependency(ptr_, index)); - } - - int toplevel_enum_count() const { - return upb_FileDef_TopLevelEnumCount(ptr_); - } - EnumDefPtr toplevel_enum(int index) const { - return EnumDefPtr(upb_FileDef_TopLevelEnum(ptr_, index)); - } - - int toplevel_message_count() const { - return upb_FileDef_TopLevelMessageCount(ptr_); - } - MessageDefPtr toplevel_message(int index) const { - return MessageDefPtr(upb_FileDef_TopLevelMessage(ptr_, index)); - } - - int toplevel_extension_count() const { - return upb_FileDef_TopLevelExtensionCount(ptr_); - } - FieldDefPtr toplevel_extension(int index) const { - return FieldDefPtr(upb_FileDef_TopLevelExtension(ptr_, index)); - } - - bool resolves(const char* path) const { - return upb_FileDef_Resolves(ptr_, path); - } - - explicit operator bool() const { return ptr_ != nullptr; } - - friend bool operator==(FileDefPtr lhs, FileDefPtr rhs) { - return lhs.ptr_ == rhs.ptr_; - } - - friend bool operator!=(FileDefPtr lhs, FileDefPtr rhs) { - return !(lhs == rhs); - } - - private: - const upb_FileDef* ptr_; -}; - -// Non-const methods in upb::DefPool are NOT thread-safe. -class DefPool { - public: - DefPool() : ptr_(upb_DefPool_New(), upb_DefPool_Free) {} - explicit DefPool(upb_DefPool* s) : ptr_(s, upb_DefPool_Free) {} - - const upb_DefPool* ptr() const { return ptr_.get(); } - upb_DefPool* ptr() { return ptr_.get(); } - - // Finds an entry in the symbol table with this exact name. If not found, - // returns NULL. - MessageDefPtr FindMessageByName(const char* sym) const { - return MessageDefPtr(upb_DefPool_FindMessageByName(ptr_.get(), sym)); - } - - EnumDefPtr FindEnumByName(const char* sym) const { - return EnumDefPtr(upb_DefPool_FindEnumByName(ptr_.get(), sym)); - } - - FileDefPtr FindFileByName(const char* name) const { - return FileDefPtr(upb_DefPool_FindFileByName(ptr_.get(), name)); - } - - FieldDefPtr FindExtensionByName(const char* name) const { - return FieldDefPtr(upb_DefPool_FindExtensionByName(ptr_.get(), name)); - } - - void _SetPlatform(upb_MiniTablePlatform platform) { - _upb_DefPool_SetPlatform(ptr_.get(), platform); - } - - // TODO: iteration? - - // Adds the given serialized FileDescriptorProto to the pool. - FileDefPtr AddFile(const google_protobuf_FileDescriptorProto* file_proto, - Status* status) { - return FileDefPtr( - upb_DefPool_AddFile(ptr_.get(), file_proto, status->ptr())); - } - - private: - std::unique_ptr ptr_; -}; - -inline FileDefPtr EnumDefPtr::file() const { - return FileDefPtr(upb_EnumDef_File(ptr_)); -} - -inline FileDefPtr FieldDefPtr::file() const { - return FileDefPtr(upb_FieldDef_File(ptr_)); -} - -inline FileDefPtr MessageDefPtr::file() const { - return FileDefPtr(upb_MessageDef_File(ptr_)); -} - -inline MessageDefPtr MessageDefPtr::containing_type() const { - return MessageDefPtr(upb_MessageDef_ContainingType(ptr_)); -} - -inline MessageDefPtr EnumDefPtr::containing_type() const { - return MessageDefPtr(upb_EnumDef_ContainingType(ptr_)); -} - -inline EnumDefPtr MessageDefPtr::enum_type(int i) const { - return EnumDefPtr(upb_MessageDef_NestedEnum(ptr_, i)); -} - -inline MessageDefPtr FieldDefPtr::message_type() const { - return MessageDefPtr(upb_FieldDef_MessageSubDef(ptr_)); -} - -inline MessageDefPtr FieldDefPtr::containing_type() const { - return MessageDefPtr(upb_FieldDef_ContainingType(ptr_)); -} - -inline MessageDefPtr FieldDefPtr::extension_scope() const { - return MessageDefPtr(upb_FieldDef_ExtensionScope(ptr_)); -} - -inline MessageDefPtr OneofDefPtr::containing_type() const { - return MessageDefPtr(upb_OneofDef_ContainingType(ptr_)); -} - -inline OneofDefPtr FieldDefPtr::containing_oneof() const { - return OneofDefPtr(upb_FieldDef_ContainingOneof(ptr_)); -} - -inline OneofDefPtr FieldDefPtr::real_containing_oneof() const { - return OneofDefPtr(upb_FieldDef_RealContainingOneof(ptr_)); -} - -inline EnumDefPtr FieldDefPtr::enum_subdef() const { - return EnumDefPtr(upb_FieldDef_EnumSubDef(ptr_)); -} - -} // namespace upb - -#include "upb/port/undef.inc" - -#endif // UPB_REFLECTION_DEF_HPP_ diff --git a/vendor/upb/reflection/def_pool.c b/vendor/upb/reflection/def_pool.c deleted file mode 100644 index 6db3274..0000000 --- a/vendor/upb/reflection/def_pool.c +++ /dev/null @@ -1,581 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/def_pool.h" - -#include -#include -#include -#include -#include - -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/alloc.h" -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/file.h" -#include "upb/mini_table/generated_registry.h" -#include "upb/mini_table/message.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/file_def.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/file_def.h" -#include "upb/reflection/internal/message_def.h" -#include "upb/reflection/internal/upb_edition_defaults.h" - -// Must be last. -#include "upb/port/def.inc" -#include "upb/wire/decode.h" - -struct upb_DefPool { - upb_Arena* arena; - upb_strtable syms; // full_name -> packed def ptr - upb_strtable files; // file_name -> (upb_FileDef*) - upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) - upb_ExtensionRegistry* extreg; - const upb_GeneratedRegistryRef* generated_extreg; - const google_protobuf_FeatureSetDefaults* feature_set_defaults; - upb_MiniTablePlatform platform; - void* scratch_data; - size_t scratch_size; - size_t bytes_loaded; - bool disable_closed_enum_checking; - bool disable_implicit_field_presence; -}; - -void upb_DefPool_Free(upb_DefPool* s) { - upb_GeneratedRegistry_Release(s->generated_extreg); - upb_Arena_Free(s->arena); - upb_gfree(s->scratch_data); - upb_gfree(s); -} - -static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; - -upb_DefPool* upb_DefPool_New(void) { - upb_DefPool* s = upb_gmalloc(sizeof(*s)); - if (!s) return NULL; - - s->arena = upb_Arena_New(); - s->bytes_loaded = 0; - s->disable_closed_enum_checking = false; - s->disable_implicit_field_presence = false; - - s->scratch_size = 240; - s->scratch_data = upb_gmalloc(s->scratch_size); - if (!s->scratch_data) goto err; - - if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; - if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; - if (!upb_inttable_init(&s->exts, s->arena)) goto err; - - s->extreg = upb_ExtensionRegistry_New(s->arena); - if (!s->extreg) goto err; - - s->generated_extreg = upb_GeneratedRegistry_Load(); - if (!s->generated_extreg) goto err; - - s->platform = kUpb_MiniTablePlatform_Native; - - upb_Status status; - if (!upb_DefPool_SetFeatureSetDefaults( - s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { - goto err; - } - - if (!s->feature_set_defaults) goto err; - - return s; - -err: - upb_DefPool_Free(s); - return NULL; -} - -void upb_DefPool_DisableClosedEnumChecking(upb_DefPool* s) { - UPB_ASSERT(upb_strtable_count(&s->files) == 0); - s->disable_closed_enum_checking = true; -} - -bool upb_DefPool_ClosedEnumCheckingDisabled(const upb_DefPool* s) { - return s->disable_closed_enum_checking; -} - -void upb_DefPool_DisableImplicitFieldPresence(upb_DefPool* s) { - UPB_ASSERT(upb_strtable_count(&s->files) == 0); - s->disable_implicit_field_presence = true; -} - -bool upb_DefPool_ImplicitFieldPresenceDisabled(const upb_DefPool* s) { - return s->disable_implicit_field_presence; -} - -const google_protobuf_FeatureSetDefaults* upb_DefPool_FeatureSetDefaults( - const upb_DefPool* s) { - return s->feature_set_defaults; -} - -bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, - const char* serialized_defaults, - size_t serialized_len, - upb_Status* status) { - const google_protobuf_FeatureSetDefaults* defaults = google_protobuf_FeatureSetDefaults_parse( - serialized_defaults, serialized_len, s->arena); - if (!defaults) { - upb_Status_SetErrorFormat(status, "Failed to parse defaults"); - return false; - } - if (upb_strtable_count(&s->files) > 0) { - upb_Status_SetErrorFormat(status, - "Feature set defaults can't be changed once the " - "pool has started building"); - return false; - } - int min_edition = google_protobuf_FeatureSetDefaults_minimum_edition(defaults); - int max_edition = google_protobuf_FeatureSetDefaults_maximum_edition(defaults); - if (min_edition > max_edition) { - upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", - upb_FileDef_EditionName(min_edition), - upb_FileDef_EditionName(max_edition)); - return false; - } - size_t size; - const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* - default_list = google_protobuf_FeatureSetDefaults_defaults(defaults, &size); - int prev_edition = google_protobuf_EDITION_UNKNOWN; - for (size_t i = 0; i < size; ++i) { - int edition = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition( - default_list[i]); - if (edition == google_protobuf_EDITION_UNKNOWN) { - upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); - return false; - } - if (edition <= prev_edition) { - upb_Status_SetErrorFormat(status, - "Feature set defaults are not strictly " - "increasing, %s is greater than or equal to %s", - upb_FileDef_EditionName(prev_edition), - upb_FileDef_EditionName(edition)); - return false; - } - prev_edition = edition; - } - - // Copy the defaults into the pool. - s->feature_set_defaults = defaults; - return true; -} - -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, - const upb_FieldDef* f) { - return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), - s->arena); -} - -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status) { - // TODO: table should support an operation "tryinsert" to avoid the double - // lookup. - if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { - upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); - return false; - } - if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { - upb_Status_SetErrorMessage(status, "out of memory"); - return false; - } - return true; -} - -static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, - size_t size, upb_deftype_t type) { - upb_value v; - return upb_strtable_lookup2(&s->syms, sym, size, &v) - ? _upb_DefType_Unpack(v, type) - : NULL; -} - -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v) { - return upb_strtable_lookup2(&s->syms, sym, size, v); -} - -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { - return s->extreg; -} - -void** _upb_DefPool_ScratchData(const upb_DefPool* s) { - return (void**)&s->scratch_data; -} - -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { - return (size_t*)&s->scratch_size; -} - -void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { - assert(upb_strtable_count(&s->files) == 0); - s->platform = platform; -} - -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindMessageByNameWithSize(s, sym, strlen(sym)); -} - -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); -} - -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindEnumByNameWithSize(s, sym, strlen(sym)); -} - -const upb_EnumDef* upb_DefPool_FindEnumByNameWithSize(const upb_DefPool* s, - const char* sym, - size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_ENUM); -} - -const upb_EnumValueDef* upb_DefPool_FindEnumValueByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindEnumValueByNameWithSize(s, sym, strlen(sym)); -} - -const upb_EnumValueDef* upb_DefPool_FindEnumValueByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_ENUMVAL); -} - -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name) { - upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len) { - upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - upb_value v; - if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; - - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_FIELD: - return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - if (_upb_MessageDef_InMessageSet(m)) { - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - const upb_FieldDef* ext = upb_MessageDef_NestedExtension(m, i); - if (upb_FieldDef_MessageSubDef(ext) == m) { - return ext; - } - } - } - return NULL; - } - default: - break; - } - - return NULL; -} - -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); -} - -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name) { - return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); -} - -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); -} - -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name) { - upb_value v; - // TODO: non-extension fields and oneofs. - if (upb_strtable_lookup(&s->syms, name, &v)) { - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_EXT: { - const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); - return upb_FieldDef_File(f); - } - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return upb_MessageDef_File(m); - } - case UPB_DEFTYPE_ENUM: { - const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); - return upb_EnumDef_File(e); - } - case UPB_DEFTYPE_ENUMVAL: { - const upb_EnumValueDef* ev = - _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); - return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); - } - case UPB_DEFTYPE_SERVICE: { - const upb_ServiceDef* service = - _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); - return upb_ServiceDef_File(service); - } - default: - UPB_UNREACHABLE(); - } - } - - const char* last_dot = strrchr(name, '.'); - if (last_dot) { - const upb_MessageDef* parent = - upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); - if (parent) { - const char* shortname = last_dot + 1; - if (upb_MessageDef_FindByNameWithSize(parent, shortname, - strlen(shortname), NULL, NULL)) { - return upb_MessageDef_File(parent); - } - } - } - - return NULL; -} - -static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { - intptr_t iter = UPB_INTTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { - const upb_FileDef* f; - switch (_upb_DefType_Type(val)) { - case UPB_DEFTYPE_EXT: - f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); - break; - case UPB_DEFTYPE_MSG: - f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); - break; - case UPB_DEFTYPE_ENUM: - f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); - break; - case UPB_DEFTYPE_ENUMVAL: - f = upb_EnumDef_File(upb_EnumValueDef_Enum( - _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); - break; - case UPB_DEFTYPE_SERVICE: - f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); - break; - default: - UPB_UNREACHABLE(); - } - - if (f == file) upb_strtable_removeiter(&s->syms, &iter); - } -} - -static const upb_FileDef* upb_DefBuilder_AddFileToPool( - upb_DefBuilder* const builder, upb_DefPool* const s, - const google_protobuf_FileDescriptorProto* const file_proto, - const upb_StringView name, upb_Status* const status) { - if (UPB_SETJMP(builder->err) != 0) { - UPB_ASSERT(!upb_Status_IsOk(status)); - if (builder->file) { - remove_filedef(s, builder->file); - builder->file = NULL; - } - } else if (!builder->arena || !builder->tmp_arena || - !upb_strtable_init(&builder->feature_cache, 16, - builder->tmp_arena) || - !(builder->legacy_features = - google_protobuf_FeatureSet_new(builder->tmp_arena))) { - _upb_DefBuilder_OomErr(builder); - } else { - _upb_FileDef_Create(builder, file_proto); - upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(builder->file), builder->arena); - UPB_ASSERT(upb_Status_IsOk(status)); - upb_Arena_Fuse(s->arena, builder->arena); - } - - if (builder->arena) upb_Arena_Free(builder->arena); - if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); - return builder->file; -} - -static const upb_FileDef* _upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - const upb_MiniTableFile* layout, upb_Status* status) { - const upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); - - // Determine whether we already know about this file. - { - upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { - upb_Status_SetErrorFormat(status, - "duplicate file name " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - return NULL; - } - } - - upb_DefBuilder ctx = { - .symtab = s, - .tmp_buf = NULL, - .tmp_buf_size = 0, - .layout = layout, - .platform = s->platform, - .msg_count = 0, - .enum_count = 0, - .ext_count = 0, - .status = status, - .file = NULL, - .arena = upb_Arena_New(), - .tmp_arena = upb_Arena_New(), - }; - - return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); -} - -const upb_FileDef* upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - upb_Status* status) { - return _upb_DefPool_AddFile(s, file_proto, NULL, status); -} - -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable) { - /* Since this function should never fail (it would indicate a bug in upb) we - * print errors to stderr instead of returning error status to the user. */ - _upb_DefPool_Init** deps = init->deps; - google_protobuf_FileDescriptorProto* file; - upb_Arena* arena; - upb_Status status; - - upb_Status_Clear(&status); - - if (upb_DefPool_FindFileByName(s, init->filename)) { - return true; - } - - arena = upb_Arena_New(); - - for (; *deps; deps++) { - if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; - } - - file = google_protobuf_FileDescriptorProto_parse_ex( - init->descriptor.data, init->descriptor.size, NULL, - kUpb_DecodeOption_AliasString, arena); - s->bytes_loaded += init->descriptor.size; - - if (!file) { - upb_Status_SetErrorFormat( - &status, - "Failed to parse compiled-in descriptor for file '%s'. This should " - "never happen.", - init->filename); - goto err; - } - - const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; - if (!_upb_DefPool_AddFile(s, file, mt, &status)) { - goto err; - } - - upb_Arena_Free(arena); - return true; - -err: - fprintf(stderr, - "Error loading compiled-in descriptor for file '%s' (this should " - "never happen): %s\n", - init->filename, upb_Status_ErrorMessage(&status)); - upb_Arena_Free(arena); - return false; -} - -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { - return s->bytes_loaded; -} - -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } - -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTableExtension* ext) { - upb_value v; - bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); - UPB_ASSERT(ok); - return upb_value_getconstptr(v); -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum) { - const upb_MiniTable* t = upb_MessageDef_MiniTable(m); - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); - return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; -} - -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s) { - return s->extreg; -} - -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count) { - size_t n = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // This is O(all exts) instead of O(exts for m). If we need this to be - // efficient we may need to make extreg into a two-level table, or have a - // second per-message index. - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) n++; - } - const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); - iter = UPB_INTTABLE_BEGIN; - size_t i = 0; - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; - } - *count = n; - return exts; -} - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { - return _upb_DefPool_LoadDefInitEx(s, init, false); -} - -const upb_ExtensionRegistry* _upb_DefPool_GeneratedExtensionRegistry( - const upb_DefPool* s) { - return upb_GeneratedRegistry_Get(s->generated_extreg); -} diff --git a/vendor/upb/reflection/def_pool.h b/vendor/upb/reflection/def_pool.h deleted file mode 100644 index d0aa474..0000000 --- a/vendor/upb/reflection/def_pool.h +++ /dev/null @@ -1,127 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_DEF_POOL_H_ -#define UPB_REFLECTION_DEF_POOL_H_ - -#include -#include - -#include "upb/base/status.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/reflection/common.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API void upb_DefPool_Free(upb_DefPool* s); - -UPB_NODISCARD UPB_API upb_DefPool* upb_DefPool_New(void); - -UPB_API const google_protobuf_FeatureSetDefaults* upb_DefPool_FeatureSetDefaults( - const upb_DefPool* s); - -UPB_NODISCARD UPB_API bool upb_DefPool_SetFeatureSetDefaults( - upb_DefPool* s, const char* serialized_defaults, size_t serialized_len, - upb_Status* status); - -UPB_API const upb_MessageDef* upb_DefPool_FindMessageByName( - const upb_DefPool* s, const char* sym); - -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len); - -UPB_API const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym); - -UPB_API const upb_EnumDef* upb_DefPool_FindEnumByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len); - -UPB_API const upb_EnumValueDef* upb_DefPool_FindEnumValueByName( - const upb_DefPool* s, const char* sym); - -UPB_API const upb_EnumValueDef* upb_DefPool_FindEnumValueByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len); - -UPB_API const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name); - -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len); - -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTableExtension* ext); - -UPB_API const upb_FieldDef* upb_DefPool_FindExtensionByName( - const upb_DefPool* s, const char* sym); - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size); - -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum); - -UPB_API const upb_ServiceDef* upb_DefPool_FindServiceByName( - const upb_DefPool* s, const char* name); - -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size); - -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name); - -UPB_NODISCARD UPB_API const upb_FileDef* upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - upb_Status* status); - -UPB_API const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s); - -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count); - -// If called, closed enums will be treated as open enums. This is non-standard -// behavior and will cause conformance tests to fail, but it is more useful -// behavior overall and can be used in situations where where the -// non-conformance is acceptable. -// -// This function may only be called immediately after upb_DefPool_New(). -// It is an error to call it on an existing def pool or after defs have -// already been added to the pool. -// -// Note: we still require that implicit presence fields have zero as their -// default value. -UPB_API void upb_DefPool_DisableClosedEnumChecking(upb_DefPool* s); -bool upb_DefPool_ClosedEnumCheckingDisabled(const upb_DefPool* s); - -// If called, implicit field presence will be disabled. -// This is non-standard behavior and will cause conformance tests to fail, but -// it can be used in situations where where the non-conformance is acceptable. -// -// This function may only be called immediately after upb_DefPool_New(). -// It is an error to call it on an existing def pool or after defs have -// already been added to the pool. -UPB_API void upb_DefPool_DisableImplicitFieldPresence(upb_DefPool* s); -bool upb_DefPool_ImplicitFieldPresenceDisabled(const upb_DefPool* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_DEF_POOL_H_ */ diff --git a/vendor/upb/reflection/def_type.c b/vendor/upb/reflection/def_type.c deleted file mode 100644 index cd4ae15..0000000 --- a/vendor/upb/reflection/def_type.c +++ /dev/null @@ -1,30 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/def_type.h" - -// Must be last. -#include "upb/port/def.inc" - -upb_deftype_t _upb_DefType_Type(upb_value v) { - const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return num & UPB_DEFTYPE_MASK; -} - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr; - UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); - num |= type; - return upb_value_constptr((const void*)num); -} - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { - uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & UPB_DEFTYPE_MASK) == type - ? (const void*)(num & ~UPB_DEFTYPE_MASK) - : NULL; -} diff --git a/vendor/upb/reflection/def_type.h b/vendor/upb/reflection/def_type.h deleted file mode 100644 index d398efc..0000000 --- a/vendor/upb/reflection/def_type.h +++ /dev/null @@ -1,63 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_DEF_TYPE_H_ -#define UPB_REFLECTION_DEF_TYPE_H_ - -#include "upb/hash/common.h" - -// Must be last. -#include "upb/port/def.inc" - -// Inside a symtab we store tagged pointers to specific def types. -typedef enum { - UPB_DEFTYPE_MASK = 7, - - // Only inside symtab table. - UPB_DEFTYPE_EXT = 0, - UPB_DEFTYPE_MSG = 1, - UPB_DEFTYPE_ENUM = 2, - UPB_DEFTYPE_ENUMVAL = 3, - UPB_DEFTYPE_SERVICE = 4, - - // Only inside message table. - UPB_DEFTYPE_FIELD = 0, - UPB_DEFTYPE_ONEOF = 1, - - // Only inside service table. - UPB_DEFTYPE_METHOD = 0, -} upb_deftype_t; - -#ifdef __cplusplus -extern "C" { -#endif - -// Our 3-bit pointer tagging requires all pointers to be multiples of 8. -// The arena will always yield 8-byte-aligned addresses, however we put -// the defs into arrays. For each element in the array to be 8-byte-aligned, -// the sizes of each def type must also be a multiple of 8. -// -// If any of these asserts fail, we need to add or remove padding on 32-bit -// machines (64-bit machines will have 8-byte alignment already due to -// pointers, which all of these structs have). -UPB_INLINE void _upb_DefType_CheckPadding(size_t size) { - UPB_ASSERT((size & UPB_DEFTYPE_MASK) == 0); -} - -upb_deftype_t _upb_DefType_Type(upb_value v); - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type); - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_DEF_TYPE_H_ */ diff --git a/vendor/upb/reflection/desc_state.c b/vendor/upb/reflection/desc_state.c deleted file mode 100644 index 075314c..0000000 --- a/vendor/upb/reflection/desc_state.c +++ /dev/null @@ -1,33 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/desc_state.h" - -// Must be last. -#include "upb/port/def.inc" - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { - const size_t oldbufsize = d->bufsize; - const int used = d->ptr - d->buf; - - if (!d->buf) { - d->buf = upb_Arena_Malloc(a, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf; - d->e.end = d->buf + d->bufsize; - } - - if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { - d->bufsize *= 2; - d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf + used; - d->e.end = d->buf + d->bufsize; - } - - return true; -} diff --git a/vendor/upb/reflection/descriptor_bootstrap.h b/vendor/upb/reflection/descriptor_bootstrap.h deleted file mode 100644 index 8c50144..0000000 --- a/vendor/upb/reflection/descriptor_bootstrap.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef GOOGLE_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H__ -#define GOOGLE_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H__ - -// IWYU pragma: begin_exports - -#if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0 -// This header is checked in. -#include "upb/reflection/stage0/google/protobuf/descriptor.upb.h" -#elif defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 1 -// This header is generated at build time by the bootstrapping process. -#include "upb/reflection/stage1/google/protobuf/descriptor.upb.h" -#else -// This is the normal header, generated by upb_c_proto_library(). -#include "google/protobuf/descriptor.upb.h" -#endif - -// IWYU pragma: end_exports - -#endif // GOOGLE_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H__ diff --git a/vendor/upb/reflection/enum_def.c b/vendor/upb/reflection/enum_def.c deleted file mode 100644 index a2ca73f..0000000 --- a/vendor/upb/reflection/enum_def.c +++ /dev/null @@ -1,335 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/enum_def.h" - -#include -#include -#include - -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_descriptor/internal/encode.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/file.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/desc_state.h" -#include "upb/reflection/internal/enum_reserved_range.h" -#include "upb/reflection/internal/enum_value_def.h" -#include "upb/reflection/internal/file_def.h" -#include "upb/reflection/internal/strdup2.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_EnumDef { - UPB_ALIGN_AS(8) const google_protobuf_EnumOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - const upb_MiniTableEnum* layout; // Only for proto2. - const upb_FileDef* file; - const upb_MessageDef* containing_type; // Could be merged with "file". - const char* full_name; - upb_strtable ntoi; - upb_inttable iton; - const upb_EnumValueDef* values; - const upb_EnumReservedRange* res_ranges; - const upb_StringView* res_names; - int value_count; - int res_range_count; - int res_name_count; - int32_t defaultval; - google_protobuf_SymbolVisibility visibility; - bool is_sorted; // Whether all of the values are defined in ascending order. -}; - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { - return (upb_EnumDef*)&e[i]; -} - -const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { - return e->layout; -} - -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { - const char* name = upb_EnumValueDef_Name(v); - const upb_value val = upb_value_constptr(v); - bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); - if (!ok) return false; - - // Multiple enumerators can have the same number, first one wins. - const int number = upb_EnumValueDef_Number(v); - if (!upb_inttable_lookup(&e->iton, number, NULL)) { - return upb_inttable_insert(&e->iton, number, val, a); - } - return true; -} - -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e) { - return e->opts; -} - -bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { - return e->opts != (void*)kUpbDefOptDefault; -} - -const google_protobuf_FeatureSet* upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { - return e->resolved_features; -} - -google_protobuf_SymbolVisibility upb_EnumDef_Visibility(const upb_EnumDef* e) { - return e->visibility; -} - -const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } - -const char* upb_EnumDef_Name(const upb_EnumDef* e) { - return _upb_DefBuilder_FullToShort(e->full_name); -} - -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { - return e->containing_type; -} - -int32_t upb_EnumDef_Default(const upb_EnumDef* e) { - UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); - return e->defaultval; -} - -int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { - return e->res_range_count; -} - -const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, - int i) { - UPB_ASSERT(0 <= i && i < e->res_range_count); - return _upb_EnumReservedRange_At(e->res_ranges, i); -} - -int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { - return e->res_name_count; -} - -upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->res_name_count); - return e->res_names[i]; -} - -int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } - -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name) { - return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); -} - -const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size) { - upb_value v; - return upb_strtable_lookup2(&e->ntoi, name, size, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, - int32_t num) { - upb_value v; - return upb_inttable_lookup(&e->iton, num, &v) ? upb_value_getconstptr(v) - : NULL; -} - -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { - // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect - // this to be faster (especially for small numbers). - return upb_MiniTableEnum_CheckValue(e->layout, num); -} - -const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->value_count); - return _upb_EnumValueDef_At(e->values, i); -} - -static bool upb_EnumDef_IsSpecifiedAsClosed(const upb_EnumDef* e) { - return google_protobuf_FeatureSet_enum_type(e->resolved_features) == - google_protobuf_FeatureSet_CLOSED; -} - -bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { - if (_upb_FileDef_ClosedEnumCheckingDisabled(e->file)) return false; - return upb_EnumDef_IsSpecifiedAsClosed(e); -} - -bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - const upb_EnumValueDef** sorted = NULL; - if (!e->is_sorted) { - sorted = _upb_EnumValueDefs_Sorted(e->values, e->value_count, a); - if (!sorted) return false; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartEnum(&s.e, s.ptr); - - // Duplicate values are allowed but we only encode each value once. - uint32_t previous = 0; - - for (int i = 0; i < e->value_count; i++) { - const uint32_t current = - upb_EnumValueDef_Number(sorted ? sorted[i] : upb_EnumDef_Value(e, i)); - if (i != 0 && previous == current) continue; - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutEnumValue(&s.e, s.ptr, current); - previous = current; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EndEnum(&s.e, s.ptr); - - // There will always be room for this '\0' in the encoder buffer because - // kUpb_MtDataEncoder_MinSize is overkill for upb_MtDataEncoder_EndEnum(). - UPB_ASSERT(s.ptr < s.buf + s.bufsize); - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static upb_MiniTableEnum* create_enumlayout(upb_DefBuilder* ctx, - const upb_EnumDef* e) { - upb_StringView sv; - bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv); - if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor"); - - upb_Status status; - upb_MiniTableEnum* layout = - upb_MiniTableEnum_Build(sv.data, sv.size, ctx->arena, &status); - if (!layout) - _upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg); - return layout; -} - -static upb_StringView* _upb_EnumReservedNames_New( - upb_DefBuilder* ctx, int n, const upb_StringView* protos) { - upb_StringView* sv = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_StringView, n); - for (int i = 0; i < n; i++) { - sv[i].data = - upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); - sv[i].size = protos[i].size; - } - return sv; -} - -static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumDescriptorProto* enum_proto, - const google_protobuf_FeatureSet* parent_features, - upb_EnumDef* e) { - const google_protobuf_EnumValueDescriptorProto* const* values; - const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* res_ranges; - const upb_StringView* res_names; - upb_StringView name; - size_t n_value, n_res_range, n_res_name; - - UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - e->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, google_protobuf_EnumOptions_features(e->opts)); - - // Must happen before _upb_DefBuilder_Add() - e->file = _upb_DefBuilder_File(ctx); - - name = google_protobuf_EnumDescriptorProto_name(enum_proto); - - e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, e->full_name, - _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - - values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n_value); - - if (n_value == 0) { - _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", - e->full_name); - } - - e->defaultval = google_protobuf_EnumValueDescriptorProto_number(values[0]); - - // When the special UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN is enabled, we have to - // exempt closed enums from this check, even when we are treating them as - // open. - // - // We rely on the fact that the proto compiler will have already ensured that - // implicit presence fields do not use closed enums, even if we are treating - // them as open. - if (!upb_EnumDef_IsSpecifiedAsClosed(e) && e->defaultval != 0) { - _upb_DefBuilder_Errf(ctx, - "for open enums, the first value must be zero (%s)", - upb_EnumDef_FullName(e)); - } - - bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&e->iton, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - e->value_count = n_value; - e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, - e->resolved_features, e, &e->is_sorted); - - res_ranges = - google_protobuf_EnumDescriptorProto_reserved_range(enum_proto, &n_res_range); - e->res_range_count = n_res_range; - e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); - - res_names = google_protobuf_EnumDescriptorProto_reserved_name(enum_proto, &n_res_name); - e->res_name_count = n_res_name; - e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); - - e->visibility = google_protobuf_EnumDescriptorProto_visibility(enum_proto); - - if (!upb_inttable_compact(&e->iton, ctx->arena)) _upb_DefBuilder_OomErr(ctx); - - if (upb_EnumDef_IsClosed(e)) { - if (ctx->layout) { - e->layout = upb_MiniTableFile_Enum(ctx->layout, ctx->enum_count++); - } else { - e->layout = create_enumlayout(ctx, e); - } - } else { - e->layout = NULL; - } -} - -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); - - // If a containing type is defined then get the full name from that. - // Otherwise use the package name from the file def. - const char* name = containing_type ? upb_MessageDef_FullName(containing_type) - : _upb_FileDef_RawPackage(ctx->file); - - upb_EnumDef* e = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_EnumDef, n); - for (int i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], parent_features, &e[i]); - e[i].containing_type = containing_type; - } - return e; -} diff --git a/vendor/upb/reflection/enum_def.h b/vendor/upb/reflection/enum_def.h deleted file mode 100644 index 3f81ba5..0000000 --- a/vendor/upb/reflection/enum_def.h +++ /dev/null @@ -1,68 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ENUM_DEF_H_ -#define UPB_REFLECTION_ENUM_DEF_H_ - -#include -#include - -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num); -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e); -int32_t upb_EnumDef_Default(const upb_EnumDef* e); -UPB_API const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e); -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name); -UPB_API const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size); -UPB_API const upb_EnumValueDef* upb_EnumDef_FindValueByNumber( - const upb_EnumDef* e, int32_t num); -UPB_API const char* upb_EnumDef_FullName(const upb_EnumDef* e); -bool upb_EnumDef_HasOptions(const upb_EnumDef* e); -bool upb_EnumDef_IsClosed(const upb_EnumDef* e); - -// Creates a mini descriptor string for an enum, returns true on success. -UPB_NODISCARD bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, - upb_Arena* a, - upb_StringView* out); - -const char* upb_EnumDef_Name(const upb_EnumDef* e); -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); -const google_protobuf_FeatureSet* upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e); -google_protobuf_SymbolVisibility upb_EnumDef_Visibility(const upb_EnumDef* e); - -upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i); -int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e); - -const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, - int i); -int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e); - -UPB_API const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i); -UPB_API int upb_EnumDef_ValueCount(const upb_EnumDef* e); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ENUM_DEF_H_ */ diff --git a/vendor/upb/reflection/enum_reserved_range.c b/vendor/upb/reflection/enum_reserved_range.c deleted file mode 100644 index 565d9e8..0000000 --- a/vendor/upb/reflection/enum_reserved_range.c +++ /dev/null @@ -1,67 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/enum_reserved_range.h" - -#include - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/enum_def.h" -#include "upb/reflection/field_def.h" -#include "upb/reflection/internal/def_builder.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_EnumReservedRange { - int32_t start; - int32_t end; -}; - -upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, - int i) { - return (upb_EnumReservedRange*)&r[i]; -} - -int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) { - return r->start; -} -int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { - return r->end; -} - -upb_EnumReservedRange* _upb_EnumReservedRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* protos, - const upb_EnumDef* e) { - upb_EnumReservedRange* r = - UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_EnumReservedRange, n); - - for (int i = 0; i < n; i++) { - const int32_t start = - google_protobuf_EnumDescriptorProto_EnumReservedRange_start(protos[i]); - const int32_t end = - google_protobuf_EnumDescriptorProto_EnumReservedRange_end(protos[i]); - - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. - - // Note: Not a typo! Unlike extension ranges and message reserved ranges, - // the end value of an enum reserved range is *inclusive*! - if (end < start) { - _upb_DefBuilder_Errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n", - (int)start, (int)end, upb_EnumDef_FullName(e)); - } - - r[i].start = start; - r[i].end = end; - } - - return r; -} diff --git a/vendor/upb/reflection/enum_reserved_range.h b/vendor/upb/reflection/enum_reserved_range.h deleted file mode 100644 index 124d4c7..0000000 --- a/vendor/upb/reflection/enum_reserved_range.h +++ /dev/null @@ -1,31 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ENUM_RESERVED_RANGE_H_ -#define UPB_REFLECTION_ENUM_RESERVED_RANGE_H_ - -#include "upb/reflection/common.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r); -int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ENUM_RESERVED_RANGE_H_ */ diff --git a/vendor/upb/reflection/enum_value_def.c b/vendor/upb/reflection/enum_value_def.c deleted file mode 100644 index 0e55288..0000000 --- a/vendor/upb/reflection/enum_value_def.c +++ /dev/null @@ -1,135 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/enum_value_def.h" - -#include -#include -#include - -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/enum_def.h" -#include "upb/reflection/enum_value_def.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/enum_def.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_EnumValueDef { - UPB_ALIGN_AS(8) const google_protobuf_EnumValueOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - const upb_EnumDef* parent; - const char* full_name; - int32_t number; -}; - -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { - return (upb_EnumValueDef*)&v[i]; -} - -static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(const upb_EnumValueDef**)p1)->number; - const uint32_t v2 = (*(const upb_EnumValueDef**)p2)->number; - return (v1 < v2) ? -1 : (v1 > v2); -} - -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - size_t n, upb_Arena* a) { - if (SIZE_MAX / sizeof(void*) < n) return NULL; - // TODO: Try to replace this arena alloc with a persistent scratch buffer. - upb_EnumValueDef** out = - (upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; - - for (int i = 0; i < n; i++) { - out[i] = (upb_EnumValueDef*)&v[i]; - } - qsort(out, n, sizeof(void*), _upb_EnumValueDef_Compare); - - return (const upb_EnumValueDef**)out; -} - -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v) { - return v->opts; -} - -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) { - return v->opts != (void*)kUpbDefOptDefault; -} - -const google_protobuf_FeatureSet* upb_EnumValueDef_ResolvedFeatures( - const upb_EnumValueDef* e) { - return e->resolved_features; -} - -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { - return v->parent; -} - -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v) { - return v->full_name; -} - -const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v) { - return _upb_DefBuilder_FullToShort(v->full_name); -} - -int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v) { return v->number; } - -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { - // Compute index in our parent's array. - return v - upb_EnumDef_Value(v->parent, 0); -} - -static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumValueDescriptorProto* val_proto, - const google_protobuf_FeatureSet* parent_features, - upb_EnumDef* e, upb_EnumValueDef* v) { - UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - v->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, google_protobuf_EnumValueOptions_features(v->opts)); - - upb_StringView name = google_protobuf_EnumValueDescriptorProto_name(val_proto); - - v->parent = e; // Must happen prior to _upb_DefBuilder_Add() - v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - v->number = google_protobuf_EnumValueDescriptorProto_number(val_proto); - _upb_DefBuilder_Add(ctx, v->full_name, - _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, upb_EnumDef* e, bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); - - upb_EnumValueDef* v = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_EnumValueDef, n); - - *is_sorted = true; - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); - - const uint32_t current = v[i].number; - if (previous > current) *is_sorted = false; - previous = current; - } - - return v; -} diff --git a/vendor/upb/reflection/enum_value_def.h b/vendor/upb/reflection/enum_value_def.h deleted file mode 100644 index a837236..0000000 --- a/vendor/upb/reflection/enum_value_def.h +++ /dev/null @@ -1,40 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ENUM_VALUE_DEF_H_ -#define UPB_REFLECTION_ENUM_VALUE_DEF_H_ - -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v); -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v); -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v); -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v); -UPB_API const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v); -UPB_API int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v); -const google_protobuf_FeatureSet* upb_EnumValueDef_ResolvedFeatures( - const upb_EnumValueDef* e); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ENUM_VALUE_DEF_H_ */ diff --git a/vendor/upb/reflection/extension_range.c b/vendor/upb/reflection/extension_range.c deleted file mode 100644 index 05c53a1..0000000 --- a/vendor/upb/reflection/extension_range.c +++ /dev/null @@ -1,82 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/extension_range.h" - -#include - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/extension_range.h" -#include "upb/reflection/field_def.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/message_def.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_ExtensionRange { - const google_protobuf_ExtensionRangeOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - int32_t start; - int32_t end; -}; - -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { - return (upb_ExtensionRange*)&r[i]; -} - -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r) { - return r->opts; -} - -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { - return r->opts != (void*)kUpbDefOptDefault; -} - -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r) { - return r->start; -} - -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } - -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, - const google_protobuf_FeatureSet* parent_features, const upb_MessageDef* m) { - upb_ExtensionRange* r = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_ExtensionRange, n); - - for (int i = 0; i < n; i++) { - UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); - r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, google_protobuf_ExtensionRangeOptions_features(r[i].opts)); - - const int32_t start = - google_protobuf_DescriptorProto_ExtensionRange_start(protos[i]); - const int32_t end = google_protobuf_DescriptorProto_ExtensionRange_end(protos[i]); - const int32_t max = - google_protobuf_MessageOptions_message_set_wire_format(upb_MessageDef_Options(m)) - ? INT32_MAX - : kUpb_MaxFieldNumber + 1; - - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. - if (start < 1 || end <= start || end > max) { - _upb_DefBuilder_Errf(ctx, - "Extension range (%d, %d) is invalid, message=%s\n", - (int)start, (int)end, upb_MessageDef_FullName(m)); - } - - r[i].start = start; - r[i].end = end; - } - - return r; -} diff --git a/vendor/upb/reflection/extension_range.h b/vendor/upb/reflection/extension_range.h deleted file mode 100644 index 71bdb37..0000000 --- a/vendor/upb/reflection/extension_range.h +++ /dev/null @@ -1,40 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_EXTENSION_RANGE_H_ -#define UPB_REFLECTION_EXTENSION_RANGE_H_ - -#include - -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r); -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); - -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r); -const google_protobuf_FeatureSet* upb_ExtensionRange_ResolvedFeatures( - const upb_ExtensionRange* e); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_EXTENSION_RANGE_H_ */ diff --git a/vendor/upb/reflection/field_def.c b/vendor/upb/reflection/field_def.c deleted file mode 100644 index a03a16a..0000000 --- a/vendor/upb/reflection/field_def.c +++ /dev/null @@ -1,1037 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/field_def.h" - -#include -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_descriptor/internal/encode.h" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/def_pool.h" -#include "upb/reflection/internal/desc_state.h" -#include "upb/reflection/internal/enum_def.h" -#include "upb/reflection/internal/file_def.h" -#include "upb/reflection/internal/message_def.h" -#include "upb/reflection/internal/oneof_def.h" -#include "upb/reflection/internal/strdup2.h" - -// Must be last. -#include "upb/port/def.inc" - -#define UPB_FIELD_TYPE_UNSPECIFIED 0 - -typedef struct { - size_t len; - char str[1]; // Null-terminated string data follows. -} str_t; - -struct upb_FieldDef { - UPB_ALIGN_AS(8) const google_protobuf_FieldOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - const upb_FileDef* file; - const upb_MessageDef* msgdef; - const char* full_name; - const char* json_name; - union { - int64_t sint; - uint64_t uint; - double dbl; - float flt; - bool boolean; - str_t* str; - void* msg; // Always NULL. - } defaultval; - union { - const upb_OneofDef* oneof; - const upb_MessageDef* extension_scope; - } scope; - union { - const upb_MessageDef* msgdef; - const upb_EnumDef* enumdef; - const google_protobuf_FieldDescriptorProto* unresolved; - } sub; - uint32_t number_; - uint16_t index_; - uint16_t layout_index; // Index into msgdef->layout->fields or file->exts - bool has_default; - bool has_json_name; - bool has_presence; - bool is_extension; - bool is_proto3_optional; - upb_FieldType type_; - upb_Label label_; -}; - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { - return (upb_FieldDef*)&f[i]; -} - -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f) { - return f->opts; -} - -bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} - -const google_protobuf_FeatureSet* upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f) { - return f->resolved_features; -} - -const char* upb_FieldDef_FullName(const upb_FieldDef* f) { - return f->full_name; -} - -upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { - return upb_FieldType_CType(f->type_); -} - -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; } - -uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } - -uint32_t upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { - return f->layout_index; -} - -upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; } - -uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } - -bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension; } - -bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsPrimitive(f); -} - -bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { - return _upb_FieldDef_IsPackable(f) && - google_protobuf_FeatureSet_repeated_field_encoding(f->resolved_features) == - google_protobuf_FeatureSet_PACKED; -} - -const char* upb_FieldDef_Name(const upb_FieldDef* f) { - return _upb_DefBuilder_FullToShort(f->full_name); -} - -const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { - return f->json_name; -} - -bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { - return f->has_json_name; -} - -const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } - -const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { - return f->msgdef; -} - -const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { - return f->is_extension ? f->scope.extension_scope : NULL; -} - -const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { - return f->is_extension ? NULL : f->scope.oneof; -} - -const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { - const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); - if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; - return oneof; -} - -upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { - upb_MessageValue ret; - - if (upb_FieldDef_IsRepeated(f) || upb_FieldDef_IsSubMessage(f)) { - return (upb_MessageValue){.msg_val = NULL}; - } - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return (upb_MessageValue){.bool_val = f->defaultval.boolean}; - case kUpb_CType_Int64: - return (upb_MessageValue){.int64_val = f->defaultval.sint}; - case kUpb_CType_UInt64: - return (upb_MessageValue){.uint64_val = f->defaultval.uint}; - case kUpb_CType_Enum: - case kUpb_CType_Int32: - return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; - case kUpb_CType_UInt32: - return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; - case kUpb_CType_Float: - return (upb_MessageValue){.float_val = f->defaultval.flt}; - case kUpb_CType_Double: - return (upb_MessageValue){.double_val = f->defaultval.dbl}; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - str_t* str = f->defaultval.str; - if (str) { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = str->str, .size = str->len}}; - } else { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = NULL, .size = 0}}; - } - } - default: - UPB_UNREACHABLE(); - } - - return ret; -} - -const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { - return upb_FieldDef_IsSubMessage(f) ? f->sub.msgdef : NULL; -} - -const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { - return upb_FieldDef_IsEnum(f) ? f->sub.enumdef : NULL; -} - -const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { - if (upb_FieldDef_IsExtension(f)) { - const upb_FileDef* file = upb_FieldDef_File(f); - return (upb_MiniTableField*)_upb_FileDef_ExtensionMiniTable( - file, f->layout_index); - } else { - const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef); - return &layout->UPB_PRIVATE(fields)[f->layout_index]; - } -} - -const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( - const upb_FieldDef* f) { - UPB_ASSERT(upb_FieldDef_IsExtension(f)); - const upb_FileDef* file = upb_FieldDef_File(f); - return _upb_FileDef_ExtensionMiniTable(file, f->layout_index); -} - -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { - if (f->type_ != kUpb_FieldType_Enum) return false; - return upb_EnumDef_IsClosed(f->sub.enumdef); -} - -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { - return f->is_proto3_optional; -} - -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } - -bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { - if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; - return google_protobuf_FeatureSet_utf8_validation(f->resolved_features) == - google_protobuf_FeatureSet_VERIFY; -} - -bool _upb_FieldDef_IsGroupLike(const upb_FieldDef* f) { - // Groups are always tag-delimited. - if (f->type_ != kUpb_FieldType_Group) { - return false; - } - - const upb_MessageDef* msg = upb_FieldDef_MessageSubDef(f); - - // Group fields always are always the lowercase type name. - const char* mname = upb_MessageDef_Name(msg); - const char* fname = upb_FieldDef_Name(f); - size_t name_size = strlen(fname); - if (name_size != strlen(mname)) return false; - for (size_t i = 0; i < name_size; ++i) { - if ((mname[i] | 0x20) != fname[i]) { - // Case-insensitive ascii comparison. - return false; - } - } - - if (upb_MessageDef_File(msg) != upb_FieldDef_File(f)) { - return false; - } - - // Group messages are always defined in the same scope as the field. File - // level extensions will compare NULL == NULL here, which is why the file - // comparison above is necessary to ensure both come from the same file. - return upb_FieldDef_IsExtension(f) ? upb_FieldDef_ExtensionScope(f) == - upb_MessageDef_ContainingType(msg) - : upb_FieldDef_ContainingType(f) == - upb_MessageDef_ContainingType(msg); -} - -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { - uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; - - if (upb_FieldDef_IsRepeated(f)) { - out |= kUpb_FieldModifier_IsRepeated; - } else if (upb_FieldDef_IsRequired(f)) { - out |= kUpb_FieldModifier_IsRequired; - } else if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } - - if (_upb_FieldDef_IsClosedEnum(f)) { - out |= kUpb_FieldModifier_IsClosedEnum; - } - - if (_upb_FieldDef_ValidateUtf8(f)) { - out |= kUpb_FieldModifier_ValidateUtf8; - } - - return out; -} - -bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } -bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { return f->has_presence; } - -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { - return upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsEnum(f); -} - -bool upb_FieldDef_IsEnum(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Enum; -} - -bool upb_FieldDef_IsMap(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && - upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); -} - -bool upb_FieldDef_IsOptional(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Optional; -} - -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { - return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); -} - -bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Repeated; -} - -bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return google_protobuf_FeatureSet_field_presence(f->resolved_features) == - google_protobuf_FeatureSet_LEGACY_REQUIRED; -} - -bool upb_FieldDef_IsString(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_String || - upb_FieldDef_CType(f) == kUpb_CType_Bytes; -} - -bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message; -} - -static bool between(int32_t x, int32_t low, int32_t high) { - return x >= low && x <= high; -} - -bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } -bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } -bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } - -bool upb_FieldDef_checkdescriptortype(int32_t type) { - return between(type, 1, 18); -} - -static bool streql2(const char* a, size_t n, const char* b) { - return n == strlen(b) && memcmp(a, b, n) == 0; -} - -// Implement the transformation as described in the spec: -// 1. upper case all letters after an underscore. -// 2. remove all underscores. -static char* make_json_name(const char* name, size_t size, upb_Arena* a) { - char* out = upb_Arena_Malloc(a, size + 1); // +1 is to add a trailing '\0' - if (out == NULL) return NULL; - - bool ucase_next = false; - char* des = out; - for (size_t i = 0; i < size; i++) { - if (name[i] == '_') { - ucase_next = true; - } else { - *des++ = ucase_next ? toupper(name[i]) : name[i]; - ucase_next = false; - } - } - *des++ = '\0'; - return out; -} - -static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) { - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - if (!ret) _upb_DefBuilder_OomErr(ctx); - ret->len = len; - if (len) memcpy(ret->str, data, len); - ret->str[len] = '\0'; - return ret; -} - -static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char* data, size_t len) { - // Size here is an upper bound; escape sequences could ultimately shrink it. - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - char* dst = &ret->str[0]; - const char* src = data; - const char* end = data + len; - - while (src < end) { - if (*src == '\\') { - src++; - *dst++ = _upb_DefBuilder_ParseEscape(ctx, f, &src, end); - } else { - *dst++ = *src++; - } - } - - ret->len = dst - &ret->str[0]; - return ret; -} - -static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, - upb_FieldDef* f) { - char* end; - char nullz[64]; - errno = 0; - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - case kUpb_CType_UInt32: - case kUpb_CType_UInt64: - case kUpb_CType_Double: - case kUpb_CType_Float: - // Standard C number parsing functions expect null-terminated strings. - if (len >= sizeof(nullz) - 1) { - _upb_DefBuilder_Errf(ctx, "Default too long: %.*s", (int)len, str); - } - memcpy(nullz, str, len); - nullz[len] = '\0'; - str = nullz; - break; - default: - break; - } - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: { - long val = strtol(str, &end, 0); - if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_Enum: { - const upb_EnumDef* e = f->sub.enumdef; - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNameWithSize(e, str, len); - if (!ev) { - goto invalid; - } - f->defaultval.sint = upb_EnumValueDef_Number(ev); - break; - } - case kUpb_CType_Int64: { - long long val = strtoll(str, &end, 0); - if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_UInt32: { - unsigned long val = strtoul(str, &end, 0); - if (val > UINT32_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_UInt64: { - unsigned long long val = strtoull(str, &end, 0); - if (val > UINT64_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_Double: { - double val = strtod(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.dbl = val; - break; - } - case kUpb_CType_Float: { - float val = strtof(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.flt = val; - break; - } - case kUpb_CType_Bool: { - if (streql2(str, len, "false")) { - f->defaultval.boolean = false; - } else if (streql2(str, len, "true")) { - f->defaultval.boolean = true; - } else { - goto invalid; - } - break; - } - case kUpb_CType_String: - f->defaultval.str = newstr(ctx, str, len); - break; - case kUpb_CType_Bytes: - f->defaultval.str = unescape(ctx, f, str, len); - break; - case kUpb_CType_Message: - /* Should not have a default value. */ - _upb_DefBuilder_Errf(ctx, "Message should not have a default (%s)", - upb_FieldDef_FullName(f)); - } - - return; - -invalid: - _upb_DefBuilder_Errf(ctx, "Invalid default '%.*s' for field %s of type %d", - (int)len, str, upb_FieldDef_FullName(f), - (int)upb_FieldDef_Type(f)); -} - -static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f, - bool must_be_empty) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - f->defaultval.sint = 0; - break; - case kUpb_CType_UInt64: - case kUpb_CType_UInt32: - f->defaultval.uint = 0; - break; - case kUpb_CType_Double: - case kUpb_CType_Float: - f->defaultval.dbl = 0; - break; - case kUpb_CType_String: - case kUpb_CType_Bytes: - f->defaultval.str = newstr(ctx, NULL, 0); - break; - case kUpb_CType_Bool: - f->defaultval.boolean = false; - break; - case kUpb_CType_Enum: { - f->defaultval.sint = upb_EnumDef_Default(f->sub.enumdef); - if (must_be_empty && f->defaultval.sint != 0) { - _upb_DefBuilder_Errf(ctx, - "Implicit presence field (%s) cannot use an enum " - "type with a non-zero default (%s)", - f->full_name, - upb_EnumDef_FullName(f->sub.enumdef)); - } - break; - } - case kUpb_CType_Message: - break; - } -} - -static bool _upb_FieldDef_InferLegacyFeatures( - upb_DefBuilder* ctx, upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* proto, - const google_protobuf_FieldOptions* options, google_protobuf_Edition edition, - google_protobuf_FeatureSet* features) { - bool ret = false; - - if (google_protobuf_FieldDescriptorProto_label(proto) == kUpb_Label_Required) { - if (edition == google_protobuf_EDITION_PROTO3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); - } - int val = google_protobuf_FeatureSet_LEGACY_REQUIRED; - google_protobuf_FeatureSet_set_field_presence(features, val); - ret = true; - } - - if (google_protobuf_FieldDescriptorProto_type(proto) == kUpb_FieldType_Group) { - int val = google_protobuf_FeatureSet_DELIMITED; - google_protobuf_FeatureSet_set_message_encoding(features, val); - ret = true; - } - - if (google_protobuf_FieldOptions_has_packed(options)) { - int val = google_protobuf_FieldOptions_packed(options) ? google_protobuf_FeatureSet_PACKED - : google_protobuf_FeatureSet_EXPANDED; - google_protobuf_FeatureSet_set_repeated_field_encoding(features, val); - ret = true; - } - - return ret; -} - -static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FeatureSet* parent_features, - const google_protobuf_FieldDescriptorProto* field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - // Must happen before _upb_DefBuilder_Add() - f->file = _upb_DefBuilder_File(ctx); - - const upb_StringView name = google_protobuf_FieldDescriptorProto_name(field_proto); - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - f->number_ = google_protobuf_FieldDescriptorProto_number(field_proto); - f->is_proto3_optional = - google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); - f->msgdef = m; - f->scope.oneof = NULL; - - UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); - - google_protobuf_Edition edition = upb_FileDef_Edition(f->file); - const google_protobuf_FeatureSet* unresolved_features = - google_protobuf_FieldOptions_features(f->opts); - bool implicit = false; - - if (_upb_DefBuilder_IsLegacyEdition(edition)) { - upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), - UPB_DESC_MINITABLE(FeatureSet)); - if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, edition, - ctx->legacy_features)) { - implicit = true; - unresolved_features = ctx->legacy_features; - } - } - - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - int oneof_index = google_protobuf_FieldDescriptorProto_oneof_index(field_proto); - - if (!m) { - _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", - f->full_name); - } - - if (oneof_index < 0 || oneof_index >= upb_MessageDef_OneofCount(m)) { - _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); - } - - upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); - f->scope.oneof = oneof; - parent_features = upb_OneofDef_ResolvedFeatures(oneof); - - _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); - } - - f->resolved_features = _upb_DefBuilder_DoResolveFeatures( - ctx, parent_features, unresolved_features, implicit); - - f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); - if (f->label_ == kUpb_Label_Optional && - // TODO: remove once we can deprecate kUpb_Label_Required. - google_protobuf_FeatureSet_field_presence(f->resolved_features) == - google_protobuf_FeatureSet_LEGACY_REQUIRED) { - f->label_ = kUpb_Label_Required; - } - - if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); - } - - f->has_json_name = google_protobuf_FieldDescriptorProto_has_json_name(field_proto); - if (f->has_json_name) { - const upb_StringView sv = - google_protobuf_FieldDescriptorProto_json_name(field_proto); - f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); - } else { - f->json_name = make_json_name(name.data, name.size, ctx->arena); - } - if (!f->json_name) _upb_DefBuilder_OomErr(ctx); - - const bool has_type = google_protobuf_FieldDescriptorProto_has_type(field_proto); - const bool has_type_name = - google_protobuf_FieldDescriptorProto_has_type_name(field_proto); - - f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); - - if (has_type) { - switch (f->type_) { - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - case kUpb_FieldType_Enum: - if (!has_type_name) { - _upb_DefBuilder_Errf(ctx, "field of type %d requires type name (%s)", - (int)f->type_, f->full_name); - } - break; - default: - if (has_type_name) { - _upb_DefBuilder_Errf( - ctx, "invalid type for field with type_name set (%s, %d)", - f->full_name, (int)f->type_); - } - } - } - - if ((!has_type && has_type_name) || f->type_ == kUpb_FieldType_Message) { - f->type_ = - UPB_FIELD_TYPE_UNSPECIFIED; // We'll assign this in resolve_subdef() - } else { - if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { - _upb_DefBuilder_Errf(ctx, "invalid type for field %s (%d)", f->full_name, - f->type_); - } - } - - if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { - _upb_DefBuilder_Errf(ctx, "invalid label for field %s (%d)", f->full_name, - f->label_); - } - - /* We can't resolve the subdef or (in the case of extensions) the containing - * message yet, because it may not have been defined yet. We stash a pointer - * to the field_proto until later when we can properly resolve it. */ - f->sub.unresolved = field_proto; - - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { - _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", - f->full_name); - } - } - - f->has_presence = - (!upb_FieldDef_IsRepeated(f)) && - (f->is_extension || _upb_FileDef_ImplicitFieldPresenceDisabled(f->file) || - (f->type_ == kUpb_FieldType_Message || - f->type_ == kUpb_FieldType_Group || upb_FieldDef_ContainingOneof(f) || - google_protobuf_FeatureSet_field_presence(f->resolved_features) != - google_protobuf_FeatureSet_IMPLICIT)); -} - -static void _upb_FieldDef_CreateExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FeatureSet* parent_features, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { - f->is_extension = true; - _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); - - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", - f->full_name); - } - - f->scope.extension_scope = m; - _upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT)); - f->layout_index = ctx->ext_count++; - - if (ctx->layout) { - UPB_ASSERT(upb_MiniTableExtension_Number( - upb_FieldDef_MiniTableExtension(f)) == f->number_); - } -} - -static void _upb_FieldDef_CreateNotExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FeatureSet* parent_features, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { - f->is_extension = false; - _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); - - if (!google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - if (f->is_proto3_optional) { - _upb_DefBuilder_Errf( - ctx, - "non-extension field (%s) with proto3_optional was not in a oneof", - f->full_name); - } - } - - _upb_MessageDef_InsertField(ctx, m, f); -} - -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, const char* prefix, - upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_FieldDef, n); - - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; - - _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); - f->index_ = i; - } - - return defs; -} - -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, const char* prefix, - upb_MessageDef* m, bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_FieldDef, n); - - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; - - _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); - f->index_ = i; - if (!ctx->layout) { - // Speculate that the def fields are sorted. We will always sort the - // MiniTable fields, so if defs are sorted then indices will match. - // - // If this is incorrect, we will overwrite later. - f->layout_index = i; - } - - const uint32_t current = f->number_; - if (previous > current) *is_sorted = false; - previous = current; - } - - return defs; -} - -static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; - upb_StringView name = google_protobuf_FieldDescriptorProto_type_name(field_proto); - bool has_name = google_protobuf_FieldDescriptorProto_has_type_name(field_proto); - switch ((int)f->type_) { - case UPB_FIELD_TYPE_UNSPECIFIED: { - // Type was not specified and must be inferred. - UPB_ASSERT(has_name); - upb_deftype_t type; - const void* def = - _upb_DefBuilder_ResolveAny(ctx, f->full_name, prefix, name, &type); - switch (type) { - case UPB_DEFTYPE_ENUM: - f->sub.enumdef = def; - f->type_ = kUpb_FieldType_Enum; - break; - case UPB_DEFTYPE_MSG: - f->sub.msgdef = def; - f->type_ = kUpb_FieldType_Message; - // TODO: remove once we can deprecate - // kUpb_FieldType_Group. - if (google_protobuf_FeatureSet_message_encoding(f->resolved_features) == - google_protobuf_FeatureSet_DELIMITED && - !upb_MessageDef_IsMapEntry(def) && - !(f->msgdef && upb_MessageDef_IsMapEntry(f->msgdef))) { - f->type_ = kUpb_FieldType_Group; - } - f->has_presence = !upb_FieldDef_IsRepeated(f); - break; - default: - _upb_DefBuilder_Errf(ctx, "Couldn't resolve type name for field %s", - f->full_name); - } - break; - } - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - UPB_ASSERT(has_name); - f->sub.msgdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_MSG); - break; - case kUpb_FieldType_Enum: - UPB_ASSERT(has_name); - f->sub.enumdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_ENUM); - break; - default: - // No resolution necessary. - break; - } -} - -static int _upb_FieldDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(upb_FieldDef**)p1)->number_; - const uint32_t v2 = (*(upb_FieldDef**)p2)->number_; - return (v1 < v2) ? -1 : (v1 > v2); -} - -// _upb_FieldDefs_Sorted() is mostly a pure function of its inputs, but has one -// critical side effect that we depend on: it sets layout_index appropriately -// for non-sorted lists of fields. -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a) { - // TODO: Replace this arena alloc with a persistent scratch buffer. - upb_FieldDef** out = (upb_FieldDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; - - for (int i = 0; i < n; i++) { - out[i] = (upb_FieldDef*)&f[i]; - } - qsort(out, n, sizeof(void*), _upb_FieldDef_Compare); - - for (int i = 0; i < n; i++) { - out[i]->layout_index = i; - } - return (const upb_FieldDef**)out; -} - -bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, - upb_StringView* out) { - UPB_ASSERT(f->is_extension); - - upb_DescState s; - _upb_DescState_Init(&s); - - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EncodeExtension(&s.e, s.ptr, f->type_, number, - modifiers); - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { - if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) { - _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", - f->full_name); - } - - upb_StringView name = google_protobuf_FieldDescriptorProto_extendee(field_proto); - const upb_MessageDef* m = - _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); - f->msgdef = m; - - if (!_upb_MessageDef_IsValidExtensionNumber(m, f->number_)) { - _upb_DefBuilder_Errf( - ctx, - "field number %u in extension %s has no extension range in message %s", - (unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m)); - } -} - -void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, - const upb_FieldDef* f) { - const upb_MiniTableExtension* ext = upb_FieldDef_MiniTableExtension(f); - - if (ctx->layout) { - UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); - } else { - upb_StringView desc; - if (!upb_FieldDef_MiniDescriptorEncode(f, ctx->tmp_arena, &desc)) { - _upb_DefBuilder_OomErr(ctx); - } - - upb_MiniTableExtension* mut_ext = (upb_MiniTableExtension*)ext; - upb_MiniTableSub sub = {NULL}; - if (upb_FieldDef_IsSubMessage(f)) { - const upb_MiniTable* submsg = upb_MessageDef_MiniTable(f->sub.msgdef); - sub = upb_MiniTableSub_FromMessage(submsg); - } else if (_upb_FieldDef_IsClosedEnum(f)) { - const upb_MiniTableEnum* subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); - sub = upb_MiniTableSub_FromEnum(subenum); - } - bool ok2 = _upb_MiniTableExtension_Init(desc.data, desc.size, mut_ext, - upb_MessageDef_MiniTable(f->msgdef), - sub, ctx->platform, ctx->status); - if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); - } - - bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { - // Implicit presence fields should always have an effective default of 0. - // This should naturally fall out of the validations that protoc performs: - // - Implicit presence fields cannot specify a default value. - // - Implicit presence fields for for enums can only use open enums, which - // are required to have zero as their default. - // - Even if we are treating all enums as open, the proto compiler will - // still reject using a nominally closed enum with an implicit presence - // field. - bool must_be_empty = !f->has_presence && !upb_FieldDef_IsRepeated(f); - - // Have to delay resolving of the default value until now because of the enum - // case, since enum defaults are specified with a label. - if (google_protobuf_FieldDescriptorProto_has_default_value(field_proto)) { - upb_StringView defaultval = - google_protobuf_FieldDescriptorProto_default_value(field_proto); - - if (must_be_empty) { - _upb_DefBuilder_Errf(ctx, - "fields with implicit presence cannot have " - "explicit defaults (%s)", - f->full_name); - } - - if (upb_FileDef_Edition(f->file) == google_protobuf_EDITION_PROTO3) { - _upb_DefBuilder_Errf(ctx, - "proto3 fields cannot have explicit defaults (%s)", - f->full_name); - } - - if (upb_FieldDef_IsSubMessage(f)) { - _upb_DefBuilder_Errf(ctx, - "message fields cannot have explicit defaults (%s)", - f->full_name); - } - - parse_default(ctx, defaultval.data, defaultval.size, f); - f->has_default = true; - } else { - set_default_default(ctx, f, must_be_empty); - f->has_default = false; - } -} - -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - // We have to stash this away since resolve_subdef() may overwrite it. - const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; - - resolve_subdef(ctx, prefix, f); - resolve_default(ctx, f, field_proto); - - if (f->is_extension) { - resolve_extension(ctx, prefix, f, field_proto); - } -} diff --git a/vendor/upb/reflection/field_def.h b/vendor/upb/reflection/field_def.h deleted file mode 100644 index 0a30dbd..0000000 --- a/vendor/upb/reflection/field_def.h +++ /dev/null @@ -1,89 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_FIELD_DEF_H_ -#define UPB_REFLECTION_FIELD_DEF_H_ - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -// Maximum field number allowed for FieldDefs. -// This is an inherent limit of the protobuf wire format. -#define kUpb_MaxFieldNumber ((1 << 29) - 1) - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f); -UPB_API const upb_MessageDef* upb_FieldDef_ContainingType( - const upb_FieldDef* f); -UPB_API upb_CType upb_FieldDef_CType(const upb_FieldDef* f); -UPB_API upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f); -UPB_API const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f); -const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f); -UPB_API const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f); -const char* upb_FieldDef_FullName(const upb_FieldDef* f); -bool upb_FieldDef_HasDefault(const upb_FieldDef* f); -bool upb_FieldDef_HasJsonName(const upb_FieldDef* f); -bool upb_FieldDef_HasOptions(const upb_FieldDef* f); -UPB_API bool upb_FieldDef_HasPresence(const upb_FieldDef* f); -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f); -uint32_t upb_FieldDef_Index(const upb_FieldDef* f); -UPB_API bool upb_FieldDef_IsEnum(const upb_FieldDef* f); -bool upb_FieldDef_IsExtension(const upb_FieldDef* f); -UPB_API bool upb_FieldDef_IsMap(const upb_FieldDef* f); -bool upb_FieldDef_IsOptional(const upb_FieldDef* f); -bool _upb_FieldDef_IsPackable(const upb_FieldDef* f); -UPB_API bool upb_FieldDef_IsPacked(const upb_FieldDef* f); -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); -UPB_API bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); -UPB_API bool upb_FieldDef_IsRequired(const upb_FieldDef* f); -bool upb_FieldDef_IsString(const upb_FieldDef* f); -UPB_API bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f); -UPB_API const char* upb_FieldDef_JsonName(const upb_FieldDef* f); -UPB_API upb_Label upb_FieldDef_Label(const upb_FieldDef* f); -uint32_t upb_FieldDef_LayoutIndex(const upb_FieldDef* f); -UPB_API const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f); -bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f); -bool _upb_FieldDef_IsGroupLike(const upb_FieldDef* f); - -// Creates a mini descriptor string for a field, returns true on success. -UPB_NODISCARD bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, - upb_Arena* a, - upb_StringView* out); - -const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); -const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( - const upb_FieldDef* f); -UPB_API const char* upb_FieldDef_Name(const upb_FieldDef* f); -UPB_API uint32_t upb_FieldDef_Number(const upb_FieldDef* f); -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); -const google_protobuf_FeatureSet* upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f); -UPB_API const upb_OneofDef* upb_FieldDef_RealContainingOneof( - const upb_FieldDef* f); -UPB_API upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_FIELD_DEF_H_ */ diff --git a/vendor/upb/reflection/file_def.c b/vendor/upb/reflection/file_def.c deleted file mode 100644 index 9daa41a..0000000 --- a/vendor/upb/reflection/file_def.c +++ /dev/null @@ -1,472 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/file_def.h" - -#include -#include -#include - -#include "upb/base/string_view.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/file.h" -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/def_pool.h" -#include "upb/reflection/internal/enum_def.h" -#include "upb/reflection/internal/field_def.h" -#include "upb/reflection/internal/message_def.h" -#include "upb/reflection/internal/service_def.h" -#include "upb/reflection/internal/strdup2.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_FileDef { - const google_protobuf_FileOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - const char* name; - const char* package; - google_protobuf_Edition edition; - - const upb_FileDef** deps; - const int32_t* public_deps; - const int32_t* weak_deps; - const upb_MessageDef* top_lvl_msgs; - const upb_EnumDef* top_lvl_enums; - const upb_FieldDef* top_lvl_exts; - const upb_ServiceDef* services; - const upb_MiniTableExtension** ext_layouts; - const upb_DefPool* symtab; - - int dep_count; - int public_dep_count; - int weak_dep_count; - int top_lvl_msg_count; - int top_lvl_enum_count; - int top_lvl_ext_count; - int service_count; - int ext_count; // All exts in the file. -}; - -UPB_API const char* upb_FileDef_EditionName(int edition) { - // TODO Synchronize this with descriptor.proto better. - switch (edition) { - case google_protobuf_EDITION_PROTO2: - return "PROTO2"; - case google_protobuf_EDITION_PROTO3: - return "PROTO3"; - case google_protobuf_EDITION_2023: - return "2023"; - default: - return "UNKNOWN"; - } -} - -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f) { - return f->opts; -} - -const google_protobuf_FeatureSet* upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { - return f->resolved_features; -} - -bool upb_FileDef_HasOptions(const upb_FileDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } - -const char* upb_FileDef_Package(const upb_FileDef* f) { - return f->package ? f->package : ""; -} - -google_protobuf_Edition upb_FileDef_Edition(const upb_FileDef* f) { return f->edition; } - -const char* _upb_FileDef_RawPackage(const upb_FileDef* f) { return f->package; } - -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { - return f->top_lvl_msg_count; -} - -int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } - -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { - return f->public_dep_count; -} - -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { - return f->weak_dep_count; -} - -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { - return f->public_deps; -} - -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { - return f->weak_deps; -} - -bool _upb_FileDef_ClosedEnumCheckingDisabled(const upb_FileDef* f) { - return upb_DefPool_ClosedEnumCheckingDisabled(f->symtab); -} - -bool _upb_FileDef_ImplicitFieldPresenceDisabled(const upb_FileDef* f) { - return upb_DefPool_ImplicitFieldPresenceDisabled(f->symtab); -} - -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { - return f->top_lvl_enum_count; -} - -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { - return f->top_lvl_ext_count; -} - -int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } - -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->dep_count); - return f->deps[i]; -} - -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->public_deps[i]]; -} - -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->weak_deps[i]]; -} - -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); - return _upb_MessageDef_At(f->top_lvl_msgs, i); -} - -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); - return _upb_EnumDef_At(f->top_lvl_enums, i); -} - -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); - return _upb_FieldDef_At(f->top_lvl_exts, i); -} - -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->service_count); - return _upb_ServiceDef_At(f->services, i); -} - -const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } - -const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i) { - return f->ext_layouts[i]; -} - -// Note: Import cycles are not allowed so this will terminate. -bool upb_FileDef_Resolves(const upb_FileDef* f, const char* path) { - if (!strcmp(f->name, path)) return true; - - for (int i = 0; i < upb_FileDef_PublicDependencyCount(f); i++) { - const upb_FileDef* dep = upb_FileDef_PublicDependency(f, i); - if (upb_FileDef_Resolves(dep, path)) return true; - } - return false; -} - -static char* _strviewdup(upb_DefBuilder* ctx, upb_StringView view) { - char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx)); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} - -static bool streql_view(upb_StringView view, const char* b) { - return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; -} - -static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { - size_t n; - google_protobuf_DescriptorProto_extension(msg_proto, &n); - int ext_count = n; - - const google_protobuf_DescriptorProto* const* nested_msgs = - google_protobuf_DescriptorProto_nested_type(msg_proto, &n); - for (size_t i = 0; i < n; i++) { - ext_count += count_exts_in_msg(nested_msgs[i]); - } - - return ext_count; -} - -const google_protobuf_FeatureSet* _upb_FileDef_FindEdition(upb_DefBuilder* ctx, - int edition) { - const google_protobuf_FeatureSetDefaults* defaults = - upb_DefPool_FeatureSetDefaults(ctx->symtab); - - int min = google_protobuf_FeatureSetDefaults_minimum_edition(defaults); - int max = google_protobuf_FeatureSetDefaults_maximum_edition(defaults); - if (edition < min) { - _upb_DefBuilder_Errf(ctx, - "Edition %s is earlier than the minimum edition %s " - "given in the defaults", - upb_FileDef_EditionName(edition), - upb_FileDef_EditionName(min)); - return NULL; - } - if (edition > max && edition != google_protobuf_EDITION_UNSTABLE) { - _upb_DefBuilder_Errf(ctx, - "Edition %s is later than the maximum edition %s " - "given in the defaults", - upb_FileDef_EditionName(edition), - upb_FileDef_EditionName(max)); - return NULL; - } - - size_t n; - const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* d = - google_protobuf_FeatureSetDefaults_defaults(defaults, &n); - const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* result = NULL; - for (size_t i = 0; i < n; i++) { - if (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(d[i]) > - edition) { - break; - } - result = d[i]; - } - if (result == NULL) { - _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s", - upb_FileDef_EditionName(edition)); - return NULL; - } - - // Merge the fixed and overridable features to get the edition's default - // feature set. - const google_protobuf_FeatureSet* fixed = - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fixed_features(result); - const google_protobuf_FeatureSet* overridable = - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_overridable_features( - result); - if (!fixed && !overridable) { - _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s", - upb_FileDef_EditionName(edition)); - return NULL; - } else if (!fixed) { - return overridable; - } - return _upb_DefBuilder_DoResolveFeatures(ctx, fixed, overridable, - /*is_implicit=*/true); -} - -// Allocate and initialize one file def, and add it to the context object. -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto) { - upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); - ctx->file = file; - - const google_protobuf_DescriptorProto* const* msgs; - const google_protobuf_EnumDescriptorProto* const* enums; - const google_protobuf_FieldDescriptorProto* const* exts; - const google_protobuf_ServiceDescriptorProto* const* services; - const upb_StringView* strs; - const int32_t* public_deps; - const int32_t* weak_deps; - size_t n; - - file->symtab = ctx->symtab; - - // Count all extensions in the file, to build a flat array of layouts. - google_protobuf_FileDescriptorProto_extension(file_proto, &n); - int ext_count = n; - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); - for (size_t i = 0; i < n; i++) { - ext_count += count_exts_in_msg(msgs[i]); - } - file->ext_count = ext_count; - - if (ctx->layout) { - // We are using the ext layouts that were passed in. - file->ext_layouts = ctx->layout->UPB_PRIVATE(exts); - const int mt_ext_count = upb_MiniTableFile_ExtensionCount(ctx->layout); - if (mt_ext_count != file->ext_count) { - _upb_DefBuilder_Errf(ctx, - "Extension count did not match layout (%d vs %d)", - mt_ext_count, file->ext_count); - } - } else { - // We are building ext layouts from scratch. - file->ext_layouts = _upb_DefBuilder_Alloc( - ctx, sizeof(*file->ext_layouts) * file->ext_count); - upb_MiniTableExtension* ext = - UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_MiniTableExtension, file->ext_count); - for (int i = 0; i < file->ext_count; i++) { - file->ext_layouts[i] = &ext[i]; - } - } - - upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); - file->name = _strviewdup(ctx, name); - if (strlen(file->name) != name.size) { - _upb_DefBuilder_Errf(ctx, "File name contained embedded NULL"); - } - - upb_StringView package = google_protobuf_FileDescriptorProto_package(file_proto); - - if (package.size) { - _upb_DefBuilder_CheckIdentFull(ctx, package); - file->package = _strviewdup(ctx, package); - } else { - file->package = NULL; - } - - upb_StringView syntax = google_protobuf_FileDescriptorProto_syntax(file_proto); - - if (google_protobuf_FileDescriptorProto_has_edition(file_proto)) { - if (!streql_view(syntax, "editions")) { - _upb_DefBuilder_Errf(ctx, - "Setting edition requires that syntax=\"editions\", " - "but syntax is \"" UPB_STRINGVIEW_FORMAT "\"", - UPB_STRINGVIEW_ARGS(syntax)); - } - file->edition = google_protobuf_FileDescriptorProto_edition(file_proto); - } else if (google_protobuf_FileDescriptorProto_has_syntax(file_proto)) { - if (streql_view(syntax, "proto2")) { - file->edition = google_protobuf_EDITION_PROTO2; - } else if (streql_view(syntax, "proto3")) { - file->edition = google_protobuf_EDITION_PROTO3; - } else if (streql_view(syntax, "editions")) { - _upb_DefBuilder_Errf( - ctx, "File has syntax=\"editions\", but no edition is specified"); - } else { - _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(syntax)); - } - } else { - // The legacy default when no edition or syntax is specified is proto2. - file->edition = google_protobuf_EDITION_PROTO2; - } - - // Read options. - UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); - - // Resolve features. - const google_protobuf_FeatureSet* edition_defaults = - _upb_FileDef_FindEdition(ctx, file->edition); - const google_protobuf_FeatureSet* unresolved = google_protobuf_FileOptions_features(file->opts); - file->resolved_features = - _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); - - // Verify dependencies. - strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n); - file->dep_count = n; - file->deps = UPB_DEFBUILDER_ALLOCARRAY(ctx, const upb_FileDef*, n); - - for (size_t i = 0; i < n; i++) { - upb_StringView str = strs[i]; - file->deps[i] = - upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); - if (!file->deps[i]) { - _upb_DefBuilder_Errf(ctx, - "Depends on file '" UPB_STRINGVIEW_FORMAT - "', but it has not been loaded", - UPB_STRINGVIEW_ARGS(str)); - } - } - - public_deps = google_protobuf_FileDescriptorProto_public_dependency(file_proto, &n); - file->public_dep_count = n; - file->public_deps = UPB_DEFBUILDER_ALLOCARRAY(ctx, int32_t, n); - int32_t* mutable_public_deps = (int32_t*)file->public_deps; - for (size_t i = 0; i < n; i++) { - if (public_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "public_dep %d is out of range", - (int)public_deps[i]); - } - mutable_public_deps[i] = public_deps[i]; - } - - weak_deps = google_protobuf_FileDescriptorProto_weak_dependency(file_proto, &n); - file->weak_dep_count = n; - file->weak_deps = UPB_DEFBUILDER_ALLOCARRAY(ctx, const int32_t, n); - int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; - for (size_t i = 0; i < n; i++) { - if (weak_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "weak_dep %d is out of range", - (int)weak_deps[i]); - } - mutable_weak_deps[i] = weak_deps[i]; - } - - // Create enums. - enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n); - file->top_lvl_enum_count = n; - file->top_lvl_enums = - _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); - - // Create extensions. - exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n); - file->top_lvl_ext_count = n; - file->top_lvl_exts = _upb_Extensions_New( - ctx, n, exts, file->resolved_features, file->package, NULL); - - // Create messages. - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); - file->top_lvl_msg_count = n; - file->top_lvl_msgs = - _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); - - // Create services. - services = google_protobuf_FileDescriptorProto_service(file_proto, &n); - file->service_count = n; - file->services = - _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); - - // Now that all names are in the table, build layouts and resolve refs. - - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_Resolve(ctx, m); - } - - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_Resolve(ctx, file->package, f); - } - - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_CreateMiniTable(ctx, (upb_MessageDef*)m); - } - - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_BuildMiniTableExtension(ctx, f); - } - - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_LinkMiniTable(ctx, m); - } - - if (file->ext_count) { - upb_ExtensionRegistryStatus status = upb_ExtensionRegistry_AddArray( - _upb_DefPool_ExtReg(ctx->symtab), file->ext_layouts, file->ext_count); - if (status != kUpb_ExtensionRegistryStatus_Ok) { - if (status == kUpb_ExtensionRegistryStatus_OutOfMemory) { - _upb_DefBuilder_OomErr(ctx); - } - - UPB_ASSERT(status == kUpb_ExtensionRegistryStatus_DuplicateEntry); - _upb_DefBuilder_Errf(ctx, "duplicate extension entry"); - } - } -} diff --git a/vendor/upb/reflection/file_def.h b/vendor/upb/reflection/file_def.h deleted file mode 100644 index 83b10a6..0000000 --- a/vendor/upb/reflection/file_def.h +++ /dev/null @@ -1,62 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_FILE_DEF_H_ -#define UPB_REFLECTION_FILE_DEF_H_ - -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API const char* upb_FileDef_EditionName(int edition); - -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); -int upb_FileDef_DependencyCount(const upb_FileDef* f); -bool upb_FileDef_HasOptions(const upb_FileDef* f); -UPB_API const char* upb_FileDef_Name(const upb_FileDef* f); -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f); -const google_protobuf_FeatureSet* upb_FileDef_ResolvedFeatures(const upb_FileDef* f); -const char* upb_FileDef_Package(const upb_FileDef* f); -google_protobuf_Edition upb_FileDef_Edition(const upb_FileDef* f); -UPB_API const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); - -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i); -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f); - -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i); -int upb_FileDef_ServiceCount(const upb_FileDef* f); - -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f); - -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f); - -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f); - -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i); -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f); - -// Returns whether |symbol| is transitively included by |f| -bool upb_FileDef_Resolves(const upb_FileDef* f, const char* symbol); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_FILE_DEF_H_ */ diff --git a/vendor/upb/reflection/internal/def_builder.c b/vendor/upb/reflection/internal/def_builder.c deleted file mode 100644 index 7041ddd..0000000 --- a/vendor/upb/reflection/internal/def_builder.c +++ /dev/null @@ -1,425 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/def_builder.h" - -#include -#include -#include -#include - -#include "upb/base/internal/log2.h" -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/hash/common.h" -#include "upb/hash/str_table.h" -#include "upb/mem/alloc.h" -#include "upb/mem/arena.h" -#include "upb/message/copy.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/field_def.h" -#include "upb/reflection/file_def.h" -#include "upb/reflection/internal/def_pool.h" -#include "upb/reflection/internal/strdup2.h" -#include "upb/wire/decode.h" - -// Must be last. -#include "upb/port/def.inc" - -/* The upb core does not generally have a concept of default instances. However - * for descriptor options we make an exception since the max size is known and - * modest (<200 bytes). All types can share a default instance since it is - * initialized to zeroes. - * - * We have to allocate an extra pointer for upb's internal metadata. */ -static UPB_ALIGN_AS(8) const - char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; -const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; - -const char* _upb_DefBuilder_FullToShort(const char* fullname) { - const char* p; - - if (fullname == NULL) { - return NULL; - } else if ((p = strrchr(fullname, '.')) == NULL) { - /* No '.' in the name, return the full string. */ - return fullname; - } else { - /* Return one past the last '.'. */ - return p + 1; - } -} - -void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } - -void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(ctx->status, fmt, argp); - va_end(argp); - _upb_DefBuilder_FailJmp(ctx); -} - -void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { - upb_Status_SetErrorMessage(ctx->status, "out of memory"); - _upb_DefBuilder_FailJmp(ctx); -} - -// Verify a relative identifier string. The loop is branchless for speed. -static void _upb_DefBuilder_CheckIdentNotFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & (i != 0); - - good &= is_alpha | is_numer; - } - - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, false); -} - -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name) { - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - if (prefix) { - // ret = prefix + '.' + name; - size_t n = strlen(prefix); - char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); - strcpy(ret, prefix); - ret[n] = '.'; - memcpy(&ret[n + 1], name.data, name.size); - ret[n + 1 + name.size] = '\0'; - return ret; - } else { - char* ret = upb_strdup2(name.data, name.size, ctx->arena); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; - } -} - -static bool remove_component(char* base, size_t* len) { - if (*len == 0) return false; - - for (size_t i = *len - 1; i > 0; i--) { - if (base[i] == '.') { - *len = i; - return true; - } - } - - *len = 0; - return true; -} - -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type) { - if (sym.size == 0) goto notfound; - upb_value v; - if (sym.data[0] == '.') { - // Symbols starting with '.' are absolute, so we do a single lookup. - // Slice to omit the leading '.' - if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { - goto notfound; - } - } else { - // Remove components from base until we find an entry or run out. - size_t baselen = base ? strlen(base) : 0; - char* tmp = upb_gmalloc(sym.size + baselen + 1); - while (1) { - char* p = tmp; - if (baselen) { - memcpy(p, base, baselen); - p[baselen] = '.'; - p += baselen + 1; - } - memcpy(p, sym.data, sym.size); - p += sym.size; - if (_upb_DefPool_LookupSym(ctx->symtab, tmp, p - tmp, &v)) { - break; - } - if (!remove_component(tmp, &baselen)) { - upb_gfree(tmp); - goto notfound; - } - } - upb_gfree(tmp); - } - - *type = _upb_DefType_Type(v); - return _upb_DefType_Unpack(v, *type); - -notfound: - _upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(sym)); -} - -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type) { - upb_deftype_t found_type; - const void* ret = - _upb_DefBuilder_ResolveAny(ctx, from_name_dbg, base, sym, &found_type); - if (ret && found_type != type) { - _upb_DefBuilder_Errf(ctx, - "type mismatch when resolving %s: couldn't find " - "name " UPB_STRINGVIEW_FORMAT " with type=%d", - from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); - } - return ret; -} - -// Per ASCII this will lower-case a letter. If the result is a letter, the -// input was definitely a letter. If the output is not a letter, this may -// have transformed the character unpredictably. -static char upb_ascii_lower(char ch) { return ch | 0x20; } - -// isalpha() etc. from are locale-dependent, which we don't want. -static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { - return low <= c && c <= high; -} - -static bool upb_isletter(char c) { - char lower = upb_ascii_lower(c); - return upb_isbetween(lower, 'a', 'z') || c == '_'; -} - -static bool upb_isalphanum(char c) { - return upb_isletter(c) || upb_isbetween(c, '0', '9'); -} - -static bool TryGetChar(const char** src, const char* end, char* ch) { - if (*src == end) return false; - *ch = **src; - *src += 1; - return true; -} - -static int TryGetHexDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '9') { - return ch - '0'; - } - ch = upb_ascii_lower(ch); - if ('a' <= ch && ch <= 'f') { - return ch - 'a' + 0xa; - } - *src -= 1; // Char wasn't actually a hex digit. - return -1; -} - -static char upb_DefBuilder_ParseHexEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - int hex_digit = TryGetHexDigit(src, end); - if (hex_digit < 0) { - _upb_DefBuilder_Errf( - ctx, "\\x must be followed by at least one hex digit (field='%s')", - upb_FieldDef_FullName(f)); - return 0; - } - unsigned int ret = hex_digit; - while ((hex_digit = TryGetHexDigit(src, end)) >= 0) { - ret = (ret << 4) | hex_digit; - } - if (ret > 0xff) { - _upb_DefBuilder_Errf(ctx, "Value of hex escape in field %s exceeds 8 bits", - upb_FieldDef_FullName(f)); - return 0; - } - return ret; -} - -static char TryGetOctalDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '7') { - return ch - '0'; - } - *src -= 1; // Char wasn't actually an octal digit. - return -1; -} - -static char upb_DefBuilder_ParseOctalEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - char ch = 0; - for (int i = 0; i < 3; i++) { - char digit; - if ((digit = TryGetOctalDigit(src, end)) >= 0) { - ch = (ch << 3) | digit; - } - } - return ch; -} - -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) { - _upb_DefBuilder_Errf(ctx, "unterminated escape sequence in field %s", - upb_FieldDef_FullName(f)); - return 0; - } - switch (ch) { - case 'a': - return '\a'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - case 'v': - return '\v'; - case '\\': - return '\\'; - case '\'': - return '\''; - case '\"': - return '\"'; - case '?': - return '\?'; - case 'x': - case 'X': - return upb_DefBuilder_ParseHexEscape(ctx, f, src, end); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - *src -= 1; - return upb_DefBuilder_ParseOctalEscape(ctx, f, src, end); - } - _upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch); -} - -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full) { - const char* str = name.data; - const size_t len = name.size; - bool start = true; - for (size_t i = 0; i < len; i++) { - const char c = str[i]; - if (c == '.') { - if (start || !full) { - _upb_DefBuilder_Errf( - ctx, "invalid name: unexpected '.' (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = true; - } else if (start) { - if (!upb_isletter(c)) { - _upb_DefBuilder_Errf(ctx, - "invalid name: path components must start with a " - "letter (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = false; - } else if (!upb_isalphanum(c)) { - _upb_DefBuilder_Errf( - ctx, - "invalid name: non-alphanumeric character (" UPB_STRINGVIEW_FORMAT - ")", - UPB_STRINGVIEW_ARGS(name)); - } - } - if (start) { - _upb_DefBuilder_Errf(ctx, - "invalid name: empty part (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - - // We should never reach this point. - UPB_ASSERT(false); -} - -upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, - const google_protobuf_FeatureSet* parent, - upb_StringView key) { - size_t need = key.size + sizeof(void*); - if (ctx->tmp_buf_size < need) { - ctx->tmp_buf_size = UPB_MAX(64, upb_RoundUpToPowerOfTwo(need)); - ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); - if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); - } - - memcpy(ctx->tmp_buf, &parent, sizeof(void*)); - memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); - return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); -} - -bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, - const google_protobuf_FeatureSet* parent, - upb_StringView key, - google_protobuf_FeatureSet** set) { - upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); - upb_value v; - if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { - *set = upb_value_getptr(v); - return false; - } - - *set = (google_protobuf_FeatureSet*)upb_Message_DeepClone( - UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); - if (!*set) _upb_DefBuilder_OomErr(ctx); - - v = upb_value_ptr(*set); - if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, - ctx->tmp_arena)) { - _upb_DefBuilder_OomErr(ctx); - } - - return true; -} - -const google_protobuf_FeatureSet* _upb_DefBuilder_DoResolveFeatures( - upb_DefBuilder* ctx, const google_protobuf_FeatureSet* parent, - const google_protobuf_FeatureSet* child, bool is_implicit) { - assert(parent); - if (!child) return parent; - - if (!is_implicit && - _upb_DefBuilder_IsLegacyEdition(upb_FileDef_Edition(ctx->file))) { - _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); - } - - google_protobuf_FeatureSet* resolved; - size_t child_size; - const char* child_bytes = - google_protobuf_FeatureSet_serialize(child, ctx->tmp_arena, &child_size); - if (!child_bytes) _upb_DefBuilder_OomErr(ctx); - - upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); - if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { - return resolved; - } - - upb_DecodeStatus dec_status = - upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), - UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); - if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); - - return resolved; -} diff --git a/vendor/upb/reflection/internal/def_builder.h b/vendor/upb/reflection/internal/def_builder.h deleted file mode 100644 index dd65cad..0000000 --- a/vendor/upb/reflection/internal/def_builder.h +++ /dev/null @@ -1,191 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ -#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ - -#include -#include -#include -#include - -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_table/file.h" -#include "upb/reflection/common.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_pool.h" - -// Must be last. -#include "upb/port/def.inc" - -// We want to copy the options verbatim into the destination options proto. -// We use serialize+parse as our deep copy. -#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ - if (google_protobuf_##desc_type##_has_options(proto)) { \ - size_t size; \ - char* pb = google_protobuf_##options_type##_serialize( \ - google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \ - if (!pb) _upb_DefBuilder_OomErr(ctx); \ - target = google_protobuf_##options_type##_parse_ex( \ - pb, size, _upb_DefPool_GeneratedExtensionRegistry(ctx->symtab), 0, \ - _upb_DefBuilder_Arena(ctx)); \ - if (!target) _upb_DefBuilder_OomErr(ctx); \ - } else { \ - target = (const google_protobuf_##options_type*)kUpbDefOptDefault; \ - } - -#ifdef __cplusplus -extern "C" { -#endif - -struct upb_DefBuilder { - upb_DefPool* symtab; - upb_strtable feature_cache; // Caches features by identity. - google_protobuf_FeatureSet* legacy_features; // For computing legacy features. - char* tmp_buf; // Temporary buffer in tmp_arena. - size_t tmp_buf_size; // Size of temporary buffer. - upb_FileDef* file; // File we are building. - upb_Arena* arena; // Allocate defs here. - upb_Arena* tmp_arena; // For temporary allocations. - upb_Status* status; // Record errors here. - const upb_MiniTableFile* layout; // NULL if we should build layouts. - upb_MiniTablePlatform platform; // Platform we are targeting. - int enum_count; // Count of enums built so far. - int msg_count; // Count of messages built so far. - int ext_count; // Count of extensions built so far. - jmp_buf err; // longjmp() on error. -}; - -extern const char* kUpbDefOptDefault; - -// ctx->status has already been set elsewhere so just fail/longjmp() -UPB_NORETURN void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx); - -UPB_NORETURN void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, - ...) UPB_PRINTF(2, 3); -UPB_NORETURN void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx); - -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name); - -// Given a symbol and the base symbol inside which it is defined, -// find the symbol's definition. -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type); - -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type); - -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end); - -const char* _upb_DefBuilder_FullToShort(const char* fullname); - -UPB_INLINE void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) { - if (bytes == 0) return NULL; - void* ret = upb_Arena_Malloc(ctx->arena, bytes); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} - -/* Allocates an array of `count` elements, checking for size_t overflow */ -UPB_INLINE void* _upb_DefBuilder_AllocCounted(upb_DefBuilder* ctx, size_t size, - size_t count) { - if (count == 0) return NULL; - if (SIZE_MAX / size < count) { - _upb_DefBuilder_OomErr(ctx); - } - return _upb_DefBuilder_Alloc(ctx, size * count); -} - -#define UPB_DEFBUILDER_ALLOCARRAY(ctx, type, count) \ - ((type*)_upb_DefBuilder_AllocCounted(ctx, sizeof(type), (count))) - -// Adds a symbol |v| to the symtab, which must be a def pointer previously -// packed with pack_def(). The def's pointer to upb_FileDef* must be set before -// adding, so we know which entries to remove if building this file fails. -UPB_INLINE void _upb_DefBuilder_Add(upb_DefBuilder* ctx, const char* name, - upb_value v) { - upb_StringView sym = {.data = name, .size = strlen(name)}; - bool ok = _upb_DefPool_InsertSym(ctx->symtab, sym, v, ctx->status); - if (!ok) _upb_DefBuilder_FailJmp(ctx); -} - -UPB_INLINE upb_Arena* _upb_DefBuilder_Arena(const upb_DefBuilder* ctx) { - return ctx->arena; -} - -UPB_INLINE upb_FileDef* _upb_DefBuilder_File(const upb_DefBuilder* ctx) { - return ctx->file; -} - -// This version of CheckIdent() is only called by other, faster versions after -// they detect a parsing error. -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full); - -// Verify a full identifier string. This is slightly more complicated than -// verifying a relative identifier string because we must track '.' chars. -UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - bool start = true; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & !start; - const bool is_dot = (c == '.') & !start; - - good &= is_alpha | is_numer | is_dot; - start = is_dot; - } - - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, true); -} - -UPB_INLINE bool _upb_DefBuilder_IsLegacyEdition(google_protobuf_Edition edition) { - // Should only be called for a real edition, not a placeholder like - // EDITION_LEGACY. - UPB_ASSERT(edition >= google_protobuf_EDITION_PROTO2); - return edition <= google_protobuf_EDITION_PROTO3; -} - -// Returns true if the returned feature set is new and must be populated. -bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, - const google_protobuf_FeatureSet* parent, - upb_StringView key, - google_protobuf_FeatureSet** set); - -const google_protobuf_FeatureSet* _upb_DefBuilder_DoResolveFeatures( - upb_DefBuilder* ctx, const google_protobuf_FeatureSet* parent, - const google_protobuf_FeatureSet* child, bool is_implicit); - -UPB_INLINE const google_protobuf_FeatureSet* _upb_DefBuilder_ResolveFeatures( - upb_DefBuilder* ctx, const google_protobuf_FeatureSet* parent, - const google_protobuf_FeatureSet* child) { - return _upb_DefBuilder_DoResolveFeatures(ctx, parent, child, false); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/def_builder_test.cc b/vendor/upb/reflection/internal/def_builder_test.cc deleted file mode 100644 index b624ffc..0000000 --- a/vendor/upb/reflection/internal/def_builder_test.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/def_builder.h" - -#include -#include "absl/strings/string_view.h" -#include "upb/mem/arena.hpp" - -// Must be last. -#include "upb/port/def.inc" - -struct IdentTestData { - absl::string_view text; - bool ok; -}; - -class FullIdentTestBase : public testing::TestWithParam {}; - -TEST_P(FullIdentTestBase, CheckFullIdent) { - upb_Status status; - upb_DefBuilder ctx; - upb::Arena arena; - ctx.status = &status; - ctx.arena = arena.ptr(); - upb_Status_Clear(&status); - - if (UPB_SETJMP(ctx.err)) { - EXPECT_FALSE(GetParam().ok); - } else { - _upb_DefBuilder_CheckIdentFull( - &ctx, upb_StringView_FromDataAndSize(GetParam().text.data(), - GetParam().text.size())); - EXPECT_TRUE(GetParam().ok); - } -} - -INSTANTIATE_TEST_SUITE_P(FullIdentTest, FullIdentTestBase, - testing::ValuesIn(std::vector{ - {"foo.bar", true}, - {"foo.", true}, - {"foo", true}, - - {"foo.7bar", false}, - {".foo", false}, - {"#", false}, - {".", false}, - {"", false}})); - -class PartIdentTestBase : public testing::TestWithParam {}; - -TEST_P(PartIdentTestBase, TestNotFullIdent) { - upb_Status status; - upb_DefBuilder ctx; - upb::Arena arena; - ctx.status = &status; - ctx.arena = arena.ptr(); - upb_Status_Clear(&status); - - if (UPB_SETJMP(ctx.err)) { - EXPECT_FALSE(GetParam().ok); - } else { - _upb_DefBuilder_MakeFullName( - &ctx, "abc", - upb_StringView_FromDataAndSize(GetParam().text.data(), - GetParam().text.size())); - EXPECT_TRUE(GetParam().ok); - } -} - -INSTANTIATE_TEST_SUITE_P(PartIdentTest, PartIdentTestBase, - testing::ValuesIn(std::vector{ - {"foo", true}, - {"foo1", true}, - - {"foo.bar", false}, - {"1foo", false}, - {"#", false}, - {".", false}, - {"", false}})); diff --git a/vendor/upb/reflection/internal/def_pool.h b/vendor/upb/reflection/internal/def_pool.h deleted file mode 100644 index 4d930df..0000000 --- a/vendor/upb/reflection/internal/def_pool.h +++ /dev/null @@ -1,61 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_ -#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_ - -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/reflection/def.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s); - -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, - const upb_FieldDef* f); -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status); -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v); - -void** _upb_DefPool_ScratchData(const upb_DefPool* s); -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s); -void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform); - -// For generated code only: loads a generated descriptor. -typedef struct _upb_DefPool_Init { - struct _upb_DefPool_Init** deps; // Dependencies of this file. - const upb_MiniTableFile* layout; - const char* filename; - upb_StringView descriptor; // Serialized descriptor. -} _upb_DefPool_Init; - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); - -// Should only be directly called by tests. This variant lets us suppress -// the use of compiled-in tables, forcing a rebuild of the tables at runtime. -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable); - -const upb_ExtensionRegistry* _upb_DefPool_GeneratedExtensionRegistry( - const upb_DefPool* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/desc_state.h b/vendor/upb/reflection/internal/desc_state.h deleted file mode 100644 index 20436d6..0000000 --- a/vendor/upb/reflection/internal/desc_state.h +++ /dev/null @@ -1,44 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ -#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ - -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/internal/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -// Manages the storage for mini descriptor strings as they are being encoded. -// TODO: Move some of this state directly into the encoder, maybe. -typedef struct { - upb_MtDataEncoder e; - size_t bufsize; - char* buf; - char* ptr; -} upb_DescState; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE void _upb_DescState_Init(upb_DescState* d) { - d->bufsize = kUpb_MtDataEncoder_MinSize * 2; - d->buf = NULL; - d->ptr = NULL; -} - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_DESC_STATE_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/enum_def.h b/vendor/upb/reflection/internal/enum_def.h deleted file mode 100644 index c963000..0000000 --- a/vendor/upb/reflection/internal/enum_def.h +++ /dev/null @@ -1,39 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ -#define UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ - -#include "upb/mem/arena.h" -#include "upb/mini_table/enum.h" -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i); -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); -const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); - -// Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, - const upb_MessageDef* containing_type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/enum_reserved_range.h b/vendor/upb/reflection/internal/enum_reserved_range.h deleted file mode 100644 index 4d37673..0000000 --- a/vendor/upb/reflection/internal/enum_reserved_range.h +++ /dev/null @@ -1,36 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_ENUM_RESERVED_RANGE_INTERNAL_H_ -#define UPB_REFLECTION_ENUM_RESERVED_RANGE_INTERNAL_H_ - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, - int i); - -// Allocate and initialize an array of |n| reserved ranges owned by |e|. -upb_EnumReservedRange* _upb_EnumReservedRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* protos, - const upb_EnumDef* e); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ENUM_RESERVED_RANGE_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/enum_value_def.h b/vendor/upb/reflection/internal/enum_value_def.h deleted file mode 100644 index 3c700d4..0000000 --- a/vendor/upb/reflection/internal/enum_value_def.h +++ /dev/null @@ -1,41 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ - -#include - -#include "upb/mem/arena.h" -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); - -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, upb_EnumDef* e, bool* is_sorted); - -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - size_t n, upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/extension_range.h b/vendor/upb/reflection/internal/extension_range.h deleted file mode 100644 index cd87aa9..0000000 --- a/vendor/upb/reflection/internal/extension_range.h +++ /dev/null @@ -1,35 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ -#define UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); - -// Allocate and initialize an array of |n| extension ranges owned by |m|. -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, - const google_protobuf_FeatureSet* parent_features, const upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/field_def.h b/vendor/upb/reflection/internal/field_def.h deleted file mode 100644 index 9caba2b..0000000 --- a/vendor/upb/reflection/internal/field_def.h +++ /dev/null @@ -1,60 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ -#define UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ - -#include - -#include "upb/mem/arena.h" -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); - -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f); -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f); -void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, - const upb_FieldDef* f); - -// Allocate and initialize an array of |n| extensions (field defs). -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, const char* prefix, - upb_MessageDef* m); - -// Allocate and initialize an array of |n| field defs. -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, const char* prefix, - upb_MessageDef* m, bool* is_sorted); - -// Allocate and return a list of pointers to the |n| field defs in |ff|, -// sorted by field number. -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/file_def.h b/vendor/upb/reflection/internal/file_def.h deleted file mode 100644 index 2c088fd..0000000 --- a/vendor/upb/reflection/internal/file_def.h +++ /dev/null @@ -1,44 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_FILE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_FILE_DEF_INTERNAL_H_ - -#include - -#include "upb/mini_table/extension.h" -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/file_def.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i); -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); -bool _upb_FileDef_ClosedEnumCheckingDisabled(const upb_FileDef* f); -bool _upb_FileDef_ImplicitFieldPresenceDisabled(const upb_FileDef* f); - -// upb_FileDef_Package() returns "" if f->package is NULL, this does not. -const char* _upb_FileDef_RawPackage(const upb_FileDef* f); - -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_FILE_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/message_def.h b/vendor/upb/reflection/internal/message_def.h deleted file mode 100644 index fa56c2d..0000000 --- a/vendor/upb/reflection/internal/message_def.h +++ /dev/null @@ -1,49 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ - -#include - -#include "upb/hash/common.h" -#include "upb/mem/arena.h" -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i); -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m); -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t size, - upb_value v, upb_Arena* a); -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f); -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n); -void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m); -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m); -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); - -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, - const upb_MessageDef* containing_type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/message_reserved_range.h b/vendor/upb/reflection/internal/message_reserved_range.h deleted file mode 100644 index b59d3ff..0000000 --- a/vendor/upb/reflection/internal/message_reserved_range.h +++ /dev/null @@ -1,37 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ -#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/message_reserved_range.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MessageReservedRange* _upb_MessageReservedRange_At( - const upb_MessageReservedRange* r, int i); - -// Allocate and initialize an array of |n| reserved ranges owned by |m|. -upb_MessageReservedRange* _upb_MessageReservedRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ReservedRange* const* protos, - const upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/method_def.h b/vendor/upb/reflection/internal/method_def.h deleted file mode 100644 index d6c3a94..0000000 --- a/vendor/upb/reflection/internal/method_def.h +++ /dev/null @@ -1,35 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ -#define UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); - -// Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, upb_ServiceDef* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/oneof_def.h b/vendor/upb/reflection/internal/oneof_def.h deleted file mode 100644 index 54c7469..0000000 --- a/vendor/upb/reflection/internal/oneof_def.h +++ /dev/null @@ -1,39 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ -#define UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); -void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, - const upb_FieldDef* f, const char* name, size_t size); - -// Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, upb_MessageDef* m); - -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/service_def.h b/vendor/upb/reflection/internal/service_def.h deleted file mode 100644 index 48c79c1..0000000 --- a/vendor/upb/reflection/internal/service_def.h +++ /dev/null @@ -1,38 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); - -// Allocate and initialize an array of |n| service defs. -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features); - -void _upb_ServiceDef_InsertMethod(upb_DefBuilder* ctx, upb_ServiceDef* s, - const upb_MethodDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */ diff --git a/vendor/upb/reflection/internal/strdup2.c b/vendor/upb/reflection/internal/strdup2.c deleted file mode 100644 index 2c8f76f..0000000 --- a/vendor/upb/reflection/internal/strdup2.c +++ /dev/null @@ -1,33 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/strdup2.h" - -#include - -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { - size_t n; - char* p; - - // Prevent overflow errors. - if (len == SIZE_MAX) return NULL; - - // Always null-terminate, even if binary data; but don't rely on the input to - // have a null-terminating byte since it may be a raw binary buffer. - n = len + 1; - p = upb_Arena_Malloc(a, n); - if (p) { - if (len != 0) memcpy(p, s, len); - p[len] = 0; - } - return p; -} diff --git a/vendor/upb/reflection/internal/strdup2.h b/vendor/upb/reflection/internal/strdup2.h deleted file mode 100644 index 0d4cadb..0000000 --- a/vendor/upb/reflection/internal/strdup2.h +++ /dev/null @@ -1,32 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_INTERNAL_STRDUP2_H_ -#define UPB_REFLECTION_INTERNAL_STRDUP2_H_ - -#include - -#include "upb/mem/arena.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Variant that works with a length-delimited rather than NULL-delimited string, -// as supported by strtable. -char* upb_strdup2(const char* s, size_t len, upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_INTERNAL_STRDUP2_H_ */ diff --git a/vendor/upb/reflection/internal/upb_edition_defaults.h b/vendor/upb/reflection/internal/upb_edition_defaults.h deleted file mode 100644 index 5b0c4fb..0000000 --- a/vendor/upb/reflection/internal/upb_edition_defaults.h +++ /dev/null @@ -1,20 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ -#define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ - -// This file contains the serialized FeatureSetDefaults object for -// language-independent features and (possibly at some point) for upb-specific -// features. This is used for feature resolution under Editions. -// NOLINTBEGIN -// clang-format off -#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\027\030\204\007\"\000*\020\010\001\020\002\030\002 \003(\0010\0028\002@\001\n\027\030\347\007\"\000*\020\010\002\020\001\030\001 \002(\0010\0018\002@\001\n\027\030\350\007\"\014\010\001\020\001\030\001 \002(\0010\001*\0048\002@\001\n\027\030\351\007\"\020\010\001\020\001\030\001 \002(\0010\0018\001@\002*\000 \346\007(\351\007" -// clang-format on -// NOLINTEND - -#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ diff --git a/vendor/upb/reflection/internal/upb_edition_defaults.h.template b/vendor/upb/reflection/internal/upb_edition_defaults.h.template deleted file mode 100644 index 58ff7f1..0000000 --- a/vendor/upb/reflection/internal/upb_edition_defaults.h.template +++ /dev/null @@ -1,20 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ -#define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ - -// This file contains the serialized FeatureSetDefaults object for -// language-independent features and (possibly at some point) for upb-specific -// features. This is used for feature resolution under Editions. -// NOLINTBEGIN -// clang-format off -#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "DEFAULTS_VALUE" -// clang-format on -// NOLINTEND - -#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ diff --git a/vendor/upb/reflection/message.c b/vendor/upb/reflection/message.c deleted file mode 100644 index 5a29fab..0000000 --- a/vendor/upb/reflection/message.c +++ /dev/null @@ -1,248 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/message.h" - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/message/accessors.h" -#include "upb/message/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_pool.h" -#include "upb/reflection/message_def.h" -#include "upb/reflection/oneof_def.h" - -// Must be last. -#include "upb/port/def.inc" - -bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { - const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); - UPB_ASSERT(upb_FieldDef_HasPresence(f)); - - if (upb_MiniTableField_IsExtension(m_f)) { - return upb_Message_HasExtension(msg, (const upb_MiniTableExtension*)m_f); - } else { - return upb_Message_HasBaseField(msg, m_f); - } -} - -const upb_FieldDef* upb_Message_WhichOneofByDef(const upb_Message* msg, - const upb_OneofDef* o) { - const upb_FieldDef* f = upb_OneofDef_Field(o, 0); - if (upb_OneofDef_IsSynthetic(o)) { - UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1); - return upb_Message_HasFieldByDef(msg, f) ? f : NULL; - } else { - const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); - uint32_t oneof_case = upb_Message_WhichOneofFieldNumber(msg, field); - f = oneof_case ? upb_OneofDef_LookupNumber(o, oneof_case) : NULL; - UPB_ASSERT((f != NULL) == (oneof_case != 0)); - return f; - } -} - -upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg, - const upb_FieldDef* f) { - upb_MessageValue default_val = upb_FieldDef_Default(f); - return upb_Message_GetField(msg, upb_FieldDef_MiniTable(f), default_val); -} - -upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg, - const upb_FieldDef* f, - upb_Arena* a) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f)); - if (upb_FieldDef_HasPresence(f) && !upb_Message_HasFieldByDef(msg, f)) { - // We need to skip the upb_Message_GetFieldByDef() call in this case. - goto make; - } - - upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); - if (val.array_val) { - return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val}; - } - - upb_MutableMessageValue ret; -make: - if (!a) return (upb_MutableMessageValue){.array = NULL}; - if (upb_FieldDef_IsMap(f)) { - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key = - upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber); - const upb_FieldDef* value = - upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber); - ret.map = - upb_Map_New(a, upb_FieldDef_CType(key), upb_FieldDef_CType(value)); - } else if (upb_FieldDef_IsRepeated(f)) { - ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); - } else { - UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); - const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - ret.msg = upb_Message_New(upb_MessageDef_MiniTable(m), a); - } - - val.array_val = ret.array; - upb_Message_SetFieldByDef(msg, f, val, a); - - return ret; -} - -bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, - upb_MessageValue val, upb_Arena* a) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); - - if (upb_MiniTableField_IsExtension(m_f)) { - return upb_Message_SetExtension(msg, (const upb_MiniTableExtension*)m_f, - &val, a); - } else { - upb_Message_SetBaseField(msg, m_f, &val); - return true; - } -} - -void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); - - if (upb_MiniTableField_IsExtension(m_f)) { - upb_Message_ClearExtension(msg, (const upb_MiniTableExtension*)m_f); - } else { - upb_Message_ClearBaseField(msg, m_f); - } -} - -void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Message_Clear(msg, upb_MessageDef_MiniTable(m)); -} - -bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, const upb_FieldDef** out_f, - upb_MessageValue* out_val, size_t* iter) { - const upb_MiniTable* mt = upb_MessageDef_MiniTable(m); - size_t i = *iter; - size_t n = upb_MiniTable_FieldCount(mt); - upb_MessageValue zero = upb_MessageValue_Zero(); - UPB_UNUSED(ext_pool); - - // Iterate over normal fields, returning the first one that is set. - while (++i < n) { - const upb_MiniTableField* field = upb_MiniTable_GetFieldByIndex(mt, i); - upb_MessageValue val = upb_Message_GetField(msg, field, zero); - - // Skip field if unset or empty. - if (upb_MiniTableField_HasPresence(field)) { - if (!upb_Message_HasBaseField(msg, field)) continue; - } else { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Map: - if (!val.map_val || upb_Map_Size(val.map_val) == 0) continue; - break; - case kUpb_FieldMode_Array: - if (!val.array_val || upb_Array_Size(val.array_val) == 0) continue; - break; - case kUpb_FieldMode_Scalar: - if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, &val)) - continue; - break; - } - } - - *out_val = val; - *out_f = - upb_MessageDef_FindFieldByNumber(m, upb_MiniTableField_Number(field)); - *iter = i; - return true; - } - - if (ext_pool) { - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) return false; - - for (; (i - n) < in->size; i++) { - upb_TaggedAuxPtr tagged_ptr = in->aux_data[i - n]; - if (upb_TaggedAuxPtr_IsExtension(tagged_ptr)) { - const upb_Extension* ext = upb_TaggedAuxPtr_Extension(tagged_ptr); - memcpy(out_val, &ext->data, sizeof(*out_val)); - *out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); - *iter = i; - return true; - } - } - } - - *iter = i; - return false; -} - -bool _upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int depth) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; - bool ret = true; - - if (--depth == 0) return false; - - _upb_Message_DiscardUnknown_shallow(msg); - - while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) { - const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); - if (!subm) continue; - if (upb_FieldDef_IsMap(f)) { - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(subm, 2); - const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f); - upb_Map* map = (upb_Map*)val.map_val; - size_t iter = kUpb_Map_Begin; - - if (!val_m) continue; - - upb_MessageValue map_key, map_val; - while (upb_Map_Next(map, &map_key, &map_val, &iter)) { - if (!_upb_Message_DiscardUnknown((upb_Message*)map_val.msg_val, val_m, - ext_pool, depth)) { - ret = false; - } - } - } else if (upb_FieldDef_IsRepeated(f)) { - const upb_Array* arr = val.array_val; - size_t i, n = upb_Array_Size(arr); - for (i = 0; i < n; i++) { - upb_MessageValue elem = upb_Array_Get(arr, i); - if (!_upb_Message_DiscardUnknown((upb_Message*)elem.msg_val, subm, - ext_pool, depth)) { - ret = false; - } - } - } else { - if (!_upb_Message_DiscardUnknown((upb_Message*)val.msg_val, subm, - ext_pool, depth)) { - ret = false; - } - } - } - - return ret; -} - -bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int maxdepth) { - return _upb_Message_DiscardUnknown(msg, m, ext_pool, maxdepth); -} diff --git a/vendor/upb/reflection/message.h b/vendor/upb/reflection/message.h deleted file mode 100644 index 180a0c4..0000000 --- a/vendor/upb/reflection/message.h +++ /dev/null @@ -1,93 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_MESSAGE_H_ -#define UPB_REFLECTION_MESSAGE_H_ - -#include - -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/reflection/common.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// Returns a mutable pointer to a map, array, or submessage value. If the given -// arena is non-NULL this will construct a new object if it was not previously -// present. May not be called for primitive fields. -UPB_NODISCARD UPB_API upb_MutableMessageValue -upb_Message_Mutable(upb_Message* msg, const upb_FieldDef* f, upb_Arena* a); - -// Returns the field that is set in the oneof, or NULL if none are set. -UPB_API const upb_FieldDef* upb_Message_WhichOneofByDef(const upb_Message* msg, - const upb_OneofDef* o); - -// Clear all data and unknown fields. -void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m); - -// Clears any field presence and sets the value back to its default. -UPB_API void upb_Message_ClearFieldByDef(upb_Message* msg, - const upb_FieldDef* f); - -// May only be called for fields where upb_FieldDef_HasPresence(f) == true. -UPB_API bool upb_Message_HasFieldByDef(const upb_Message* msg, - const upb_FieldDef* f); - -// Returns the value in the message associated with this field def. -UPB_API upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg, - const upb_FieldDef* f); - -// Sets the given field to the given value. For a msg/array/map/string, the -// caller must ensure that the target data outlives |msg| (by living either in -// the same arena or a different arena that outlives it). -// -// Returns false if allocation fails. -UPB_NODISCARD UPB_API bool upb_Message_SetFieldByDef(upb_Message* msg, - const upb_FieldDef* f, - upb_MessageValue val, - upb_Arena* a); - -// Iterate over present fields. -// -// size_t iter = kUpb_Message_Begin; -// const upb_FieldDef *f; -// upb_MessageValue val; -// while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) { -// process_field(f, val); -// } -// -// If ext_pool is NULL, no extensions will be returned. If the given symtab -// returns extensions that don't match what is in this message, those extensions -// will be skipped. - -#define kUpb_Message_Begin -1 - -UPB_API bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, - const upb_FieldDef** f, upb_MessageValue* val, - size_t* iter); - -// Clears all unknown field data from this message and all submessages. -UPB_API bool upb_Message_DiscardUnknown(upb_Message* msg, - const upb_MessageDef* m, - const upb_DefPool* ext_pool, - int maxdepth); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_MESSAGE_H_ */ diff --git a/vendor/upb/reflection/message.hpp b/vendor/upb/reflection/message.hpp deleted file mode 100644 index 6d5bc98..0000000 --- a/vendor/upb/reflection/message.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_REFLECTION_MESSAGE_HPP_ -#define UPB_REFLECTION_MESSAGE_HPP_ - -#include "upb/reflection/message.h" - -namespace upb { - -typedef upb_MessageValue MessageValue; - -} // namespace upb - -#endif // UPB_REFLECTION_MESSAGE_HPP_ diff --git a/vendor/upb/reflection/message_def.c b/vendor/upb/reflection/message_def.c deleted file mode 100644 index 934ebc5..0000000 --- a/vendor/upb/reflection/message_def.c +++ /dev/null @@ -1,787 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/message_def.h" - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_descriptor/internal/encode.h" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/file.h" -#include "upb/mini_table/message.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/def_pool.h" -#include "upb/reflection/internal/desc_state.h" -#include "upb/reflection/internal/enum_def.h" -#include "upb/reflection/internal/extension_range.h" -#include "upb/reflection/internal/field_def.h" -#include "upb/reflection/internal/file_def.h" -#include "upb/reflection/internal/message_reserved_range.h" -#include "upb/reflection/internal/oneof_def.h" -#include "upb/reflection/internal/strdup2.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_MessageDef { - UPB_ALIGN_AS(8) const google_protobuf_MessageOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - const upb_MiniTable* layout; - const upb_FileDef* file; - const upb_MessageDef* containing_type; - const char* full_name; - - // Tables for looking up fields by number and name. - upb_inttable itof; - upb_strtable ntof; - - // Looking up fields by json name. - upb_strtable jtof; - - /* All nested defs. - * MEM: We could save some space here by putting nested defs in a contiguous - * region and calculating counts from offsets or vice-versa. */ - const upb_FieldDef* fields; - const upb_OneofDef* oneofs; - const upb_ExtensionRange* ext_ranges; - const upb_StringView* res_names; - const upb_MessageDef* nested_msgs; - const upb_MessageReservedRange* res_ranges; - const upb_EnumDef* nested_enums; - const upb_FieldDef* nested_exts; - - // TODO: These counters don't need anywhere near 32 bits. - int field_count; - int real_oneof_count; - int oneof_count; - int ext_range_count; - int res_range_count; - int res_name_count; - int nested_msg_count; - int nested_enum_count; - int nested_ext_count; - bool in_message_set; - bool is_sorted; - upb_WellKnown well_known_type; - google_protobuf_SymbolVisibility visibility; -}; - -static void assign_msg_wellknowntype(upb_MessageDef* m) { - const char* name = m->full_name; - if (name == NULL) { - m->well_known_type = kUpb_WellKnown_Unspecified; - return; - } - if (!strcmp(name, "google.protobuf.Any")) { - m->well_known_type = kUpb_WellKnown_Any; - } else if (!strcmp(name, "google.protobuf.FieldMask")) { - m->well_known_type = kUpb_WellKnown_FieldMask; - } else if (!strcmp(name, "google.protobuf.Duration")) { - m->well_known_type = kUpb_WellKnown_Duration; - } else if (!strcmp(name, "google.protobuf.Timestamp")) { - m->well_known_type = kUpb_WellKnown_Timestamp; - } else if (!strcmp(name, "google.protobuf.DoubleValue")) { - m->well_known_type = kUpb_WellKnown_DoubleValue; - } else if (!strcmp(name, "google.protobuf.FloatValue")) { - m->well_known_type = kUpb_WellKnown_FloatValue; - } else if (!strcmp(name, "google.protobuf.Int64Value")) { - m->well_known_type = kUpb_WellKnown_Int64Value; - } else if (!strcmp(name, "google.protobuf.UInt64Value")) { - m->well_known_type = kUpb_WellKnown_UInt64Value; - } else if (!strcmp(name, "google.protobuf.Int32Value")) { - m->well_known_type = kUpb_WellKnown_Int32Value; - } else if (!strcmp(name, "google.protobuf.UInt32Value")) { - m->well_known_type = kUpb_WellKnown_UInt32Value; - } else if (!strcmp(name, "google.protobuf.BoolValue")) { - m->well_known_type = kUpb_WellKnown_BoolValue; - } else if (!strcmp(name, "google.protobuf.StringValue")) { - m->well_known_type = kUpb_WellKnown_StringValue; - } else if (!strcmp(name, "google.protobuf.BytesValue")) { - m->well_known_type = kUpb_WellKnown_BytesValue; - } else if (!strcmp(name, "google.protobuf.Value")) { - m->well_known_type = kUpb_WellKnown_Value; - } else if (!strcmp(name, "google.protobuf.ListValue")) { - m->well_known_type = kUpb_WellKnown_ListValue; - } else if (!strcmp(name, "google.protobuf.Struct")) { - m->well_known_type = kUpb_WellKnown_Struct; - } else { - m->well_known_type = kUpb_WellKnown_Unspecified; - } -} - -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i) { - return (upb_MessageDef*)&m[i]; -} - -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { - for (int i = 0; i < m->ext_range_count; i++) { - const upb_ExtensionRange* r = upb_MessageDef_ExtensionRange(m, i); - if (upb_ExtensionRange_Start(r) <= n && n < upb_ExtensionRange_End(r)) { - return true; - } - } - return false; -} - -const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m) { - return m->opts; -} - -bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { - return m->opts != (void*)kUpbDefOptDefault; -} - -const google_protobuf_FeatureSet* upb_MessageDef_ResolvedFeatures( - const upb_MessageDef* m) { - return m->resolved_features; -} - -const char* upb_MessageDef_FullName(const upb_MessageDef* m) { - return m->full_name; -} - -const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { - return m->file; -} - -const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { - return m->containing_type; -} - -const char* upb_MessageDef_Name(const upb_MessageDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); -} - -const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, - uint32_t i) { - upb_value val; - return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) - : NULL; -} - -const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); -} - -const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); -} - -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t len, - upb_value v, upb_Arena* a) { - return upb_strtable_insert(&m->ntof, name, len, v, a); -} - -bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t len, - const upb_FieldDef** out_f, - const upb_OneofDef** out_o) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { - return false; - } - - const upb_FieldDef* f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); - const upb_OneofDef* o = _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); - if (out_f) *out_f = f; - if (out_o) *out_o = o; - return f || o; /* False if this was a JSON name. */ -} - -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - - if (upb_strtable_lookup2(&m->jtof, name, size, &val)) { - return upb_value_getconstptr(val); - } - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); -} - -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { - return m->ext_range_count; -} - -int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m) { - return m->res_range_count; -} - -int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m) { - return m->res_name_count; -} - -int upb_MessageDef_FieldCount(const upb_MessageDef* m) { - return m->field_count; -} - -int upb_MessageDef_OneofCount(const upb_MessageDef* m) { - return m->oneof_count; -} - -int upb_MessageDef_RealOneofCount(const upb_MessageDef* m) { - return m->real_oneof_count; -} - -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { - return m->nested_msg_count; -} - -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { - return m->nested_enum_count; -} - -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { - return m->nested_ext_count; -} - -const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { - return m->layout; -} - -const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->ext_range_count); - return _upb_ExtensionRange_At(m->ext_ranges, i); -} - -const upb_MessageReservedRange* upb_MessageDef_ReservedRange( - const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->res_range_count); - return _upb_MessageReservedRange_At(m->res_ranges, i); -} - -upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->res_name_count); - return m->res_names[i]; -} - -const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->field_count); - return _upb_FieldDef_At(m->fields, i); -} - -const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->oneof_count); - return _upb_OneofDef_At(m->oneofs, i); -} - -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_msg_count); - return &m->nested_msgs[i]; -} - -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->nested_enum_count); - return _upb_EnumDef_At(m->nested_enums, i); -} - -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_ext_count); - return _upb_FieldDef_At(m->nested_exts, i); -} - -upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { - return m->well_known_type; -} - -UPB_API google_protobuf_SymbolVisibility -upb_MessageDef_Visibility(const upb_MessageDef* m) { - return m->visibility; -} - -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m) { - return m->in_message_set; -} - -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); -} - -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); -} - -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_map_entry(m->opts); -} - -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_message_set_wire_format(m->opts); -} - -static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - upb_StringView desc; - // Note: this will assign layout_index for fields, so upb_FieldDef_MiniTable() - // is safe to call only after this call. - bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - void** scratch_data = _upb_DefPool_ScratchData(ctx->symtab); - size_t* scratch_size = _upb_DefPool_ScratchSize(ctx->symtab); - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf( - desc.data, desc.size, ctx->platform, ctx->arena, scratch_data, - scratch_size, ctx->status); - if (!ret) _upb_DefBuilder_FailJmp(ctx); - - return ret; -} - -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { - for (int i = 0; i < m->field_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); - _upb_FieldDef_Resolve(ctx, m->full_name, f); - } - - m->in_message_set = false; - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_Resolve(ctx, m->full_name, ext); - if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && - upb_FieldDef_Label(ext) == kUpb_Label_Optional && - upb_FieldDef_MessageSubDef(ext) == m && - google_protobuf_MessageOptions_message_set_wire_format( - upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { - m->in_message_set = true; - } - } - - for (int i = 0; i < upb_MessageDef_NestedMessageCount(m); i++) { - upb_MessageDef* n = (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_Resolve(ctx, n); - } -} - -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f) { - const int32_t field_number = upb_FieldDef_Number(f); - - if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { - _upb_DefBuilder_Errf(ctx, "invalid field number (%u)", field_number); - } - - const char* json_name = upb_FieldDef_JsonName(f); - const char* shortname = upb_FieldDef_Name(f); - const size_t shortnamelen = strlen(shortname); - - upb_value v = upb_value_constptr(f); - - upb_value existing_v; - if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { - _upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname); - } - - const upb_value field_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD); - bool ok = - _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - bool skip_json_conflicts = - google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts( - upb_MessageDef_Options(m)); - if (!skip_json_conflicts && strcmp(shortname, json_name) != 0 && - google_protobuf_FeatureSet_json_format(m->resolved_features) == - google_protobuf_FeatureSet_ALLOW && - upb_strtable_lookup(&m->ntof, json_name, &v)) { - _upb_DefBuilder_Errf( - ctx, "duplicate json_name for (%s) with original field name (%s)", - shortname, json_name); - } - - if (upb_strtable_lookup(&m->jtof, json_name, &v)) { - if (!skip_json_conflicts) { - _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); - } - } else { - const size_t json_size = strlen(json_name); - ok = upb_strtable_insert(&m->jtof, json_name, json_size, - upb_value_constptr(f), ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - } - - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); - } - - ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m) { - if (ctx->layout == NULL) { - m->layout = _upb_MessageDef_MakeMiniTable(ctx, m); - } else { - m->layout = upb_MiniTableFile_Message(ctx->layout, ctx->msg_count++); - UPB_ASSERT(m->field_count == upb_MiniTable_FieldCount(m->layout)); - - // We don't need the result of this call, but it will assign layout_index - // for all the fields in O(n lg n) time. - _upb_FieldDefs_Sorted(m->fields, m->field_count, ctx->tmp_arena); - } - - for (int i = 0; i < m->nested_msg_count; i++) { - upb_MessageDef* nested = - (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_CreateMiniTable(ctx, nested); - } -} - -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - const upb_FieldDef* ext = upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_BuildMiniTableExtension(ctx, ext); - } - - for (int i = 0; i < m->nested_msg_count; i++) { - _upb_MessageDef_LinkMiniTable(ctx, upb_MessageDef_NestedMessage(m, i)); - } - - if (ctx->layout || ctx->platform != kUpb_MiniTablePlatform_Native) return; - - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); - const upb_EnumDef* sub_e = upb_FieldDef_EnumSubDef(f); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m); - - UPB_ASSERT(layout_index < m->field_count); - upb_MiniTableField* mt_f = - (upb_MiniTableField*)&m->layout->UPB_PRIVATE(fields)[layout_index]; - if (sub_m) { - UPB_ASSERT(mt_f); - UPB_ASSERT(sub_m->layout); - if (UPB_UNLIKELY(!upb_MiniTable_SetSubMessage(mt, mt_f, sub_m->layout))) { - _upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name); - } - } else if (_upb_FieldDef_IsClosedEnum(f)) { - const upb_MiniTableEnum* mt_e = _upb_EnumDef_MiniTable(sub_e); - if (UPB_UNLIKELY(!upb_MiniTable_SetSubEnum(mt, mt_f, mt_e))) { - _upb_DefBuilder_Errf(ctx, "invalid subenum for (%s)", m->full_name); - } - } - } - -#ifndef NDEBUG - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - UPB_ASSERT(layout_index < upb_MiniTable_FieldCount(m->layout)); - const upb_MiniTableField* mt_f = - &m->layout->UPB_PRIVATE(fields)[layout_index]; - UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); - UPB_ASSERT(upb_FieldDef_CType(f) == upb_MiniTableField_CType(mt_f)); - UPB_ASSERT(upb_FieldDef_HasPresence(f) == - upb_MiniTableField_HasPresence(mt_f)); - } -#endif -} - -// Returns whether packable repeated fields in the message should be considered -// packed by default. This is used only for the purpose of encoding -// MiniDescriptors, so we just return true if there are more packed fields than -// unpacked. This optimizes for smaller MiniDescriptors. -static bool _upb_MessageDef_DefaultIsPacked(const upb_MessageDef* m) { - int packed = 0; - int unpacked = 0; - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - if (_upb_FieldDef_IsPackable(f)) { - if (upb_FieldDef_IsPacked(f)) { - ++packed; - } else { - ++unpacked; - } - } - } - return packed > unpacked; -} - -static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { - bool has_string = false; - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - // Old binaries do not recognize the field-level "FlipValidateUtf8" wire - // modifier, so we do not actually have field-level control for old - // binaries. Given this, we judge that the better failure mode is to be - // more lax than intended, rather than more strict. To achieve this, we - // only mark the message with the ValidateUtf8 modifier if *all* fields - // validate UTF-8. - if (!_upb_FieldDef_ValidateUtf8(f)) return false; - if (upb_FieldDef_Type(f) == kUpb_FieldType_String) has_string = true; - } - return has_string; -} - -static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { - uint64_t out = 0; - - if (_upb_MessageDef_DefaultIsPacked(m)) { - out |= kUpb_MessageModifier_DefaultIsPacked; - } - - if (_upb_MessageDef_ValidateUtf8(m)) { - out |= kUpb_MessageModifier_ValidateUtf8; - } - - if (m->ext_range_count) { - out |= kUpb_MessageModifier_IsExtendable; - } - - return out; -} - -static bool _upb_MessageDef_EncodeMap(upb_DescState* s, const upb_MessageDef* m, - upb_Arena* a) { - if (m->field_count != 2) return false; - - const upb_FieldDef* key_field = upb_MessageDef_Field(m, 0); - const upb_FieldDef* val_field = upb_MessageDef_Field(m, 1); - if (key_field == NULL || val_field == NULL) return false; - - UPB_ASSERT(_upb_FieldDef_LayoutIndex(key_field) == 0); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(val_field) == 1); - - s->ptr = upb_MtDataEncoder_EncodeMap( - &s->e, s->ptr, upb_FieldDef_Type(key_field), upb_FieldDef_Type(val_field), - _upb_FieldDef_Modifiers(key_field), _upb_FieldDef_Modifiers(val_field)); - return true; -} - -static bool _upb_MessageDef_EncodeMessage(upb_DescState* s, - const upb_MessageDef* m, - upb_Arena* a) { - const upb_FieldDef** sorted = NULL; - if (!m->is_sorted) { - sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); - if (!sorted) return false; - } - - s->ptr = upb_MtDataEncoder_StartMessage(&s->e, s->ptr, - _upb_MessageDef_Modifiers(m)); - - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); - const upb_FieldType type = upb_FieldDef_Type(f); - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_PutField(&s->e, s->ptr, type, number, modifiers); - } - - for (int i = 0; i < m->real_oneof_count; i++) { - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_StartOneof(&s->e, s->ptr); - - const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); - const int field_count = upb_OneofDef_FieldCount(o); - for (int j = 0; j < field_count; j++) { - const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); - - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_PutOneofField(&s->e, s->ptr, number); - } - } - - return true; -} - -static bool _upb_MessageDef_EncodeMessageSet(upb_DescState* s, - const upb_MessageDef* m, - upb_Arena* a) { - s->ptr = upb_MtDataEncoder_EncodeMessageSet(&s->e, s->ptr); - - return true; -} - -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - if (!_upb_DescState_Grow(&s, a)) return false; - - if (upb_MessageDef_IsMapEntry(m)) { - if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; - } else if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { - if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; - } else { - if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, - const upb_StringView* protos) { - upb_StringView* sv = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_StringView, n); - for (int i = 0; i < n; i++) { - sv[i].data = - upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); - sv[i].size = protos[i].size; - } - return sv; -} - -static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_DescriptorProto* msg_proto, - const google_protobuf_FeatureSet* parent_features, - const upb_MessageDef* containing_type, - upb_MessageDef* m) { - const google_protobuf_OneofDescriptorProto* const* oneofs; - const google_protobuf_FieldDescriptorProto* const* fields; - const google_protobuf_DescriptorProto_ExtensionRange* const* ext_ranges; - const google_protobuf_DescriptorProto_ReservedRange* const* res_ranges; - const upb_StringView* res_names; - size_t n_oneof, n_field, n_enum, n_ext, n_msg; - size_t n_ext_range, n_res_range, n_res_name; - upb_StringView name; - - UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - m->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, google_protobuf_MessageOptions_features(m->opts)); - - // Must happen before _upb_DefBuilder_Add() - m->file = _upb_DefBuilder_File(ctx); - - m->containing_type = containing_type; - m->is_sorted = true; - - name = google_protobuf_DescriptorProto_name(msg_proto); - - m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); - - oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof); - fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field); - ext_ranges = google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range); - res_ranges = google_protobuf_DescriptorProto_reserved_range(msg_proto, &n_res_range); - res_names = google_protobuf_DescriptorProto_reserved_name(msg_proto, &n_res_name); - - bool ok = upb_inttable_init(&m->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); - - m->field_count = n_field; - m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, - m->full_name, m, &m->is_sorted); - - // Message Sets may not contain fields. - if (UPB_UNLIKELY(google_protobuf_MessageOptions_message_set_wire_format(m->opts))) { - if (UPB_UNLIKELY(n_field > 0)) { - _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); - } - } - - m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, - m->resolved_features, m); - - m->res_range_count = n_res_range; - m->res_ranges = - _upb_MessageReservedRanges_New(ctx, n_res_range, res_ranges, m); - - m->res_name_count = n_res_name; - m->res_names = _upb_ReservedNames_New(ctx, n_res_name, res_names); - - const size_t synthetic_count = _upb_OneofDefs_Finalize(ctx, m); - m->real_oneof_count = m->oneof_count - synthetic_count; - - assign_msg_wellknowntype(m); - if (!upb_inttable_compact(&m->itof, ctx->arena)) _upb_DefBuilder_OomErr(ctx); - - const google_protobuf_EnumDescriptorProto* const* enums = - google_protobuf_DescriptorProto_enum_type(msg_proto, &n_enum); - m->nested_enum_count = n_enum; - m->nested_enums = - _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); - - const google_protobuf_FieldDescriptorProto* const* exts = - google_protobuf_DescriptorProto_extension(msg_proto, &n_ext); - m->nested_ext_count = n_ext; - m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, - m->full_name, m); - - const google_protobuf_DescriptorProto* const* msgs = - google_protobuf_DescriptorProto_nested_type(msg_proto, &n_msg); - m->nested_msg_count = n_msg; - m->nested_msgs = - _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); - - m->visibility = google_protobuf_DescriptorProto_visibility(msg_proto); -} - -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); - - const char* name = containing_type ? containing_type->full_name - : _upb_FileDef_RawPackage(ctx->file); - - upb_MessageDef* m = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_MessageDef, n); - for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], parent_features, containing_type, - &m[i]); - } - return m; -} diff --git a/vendor/upb/reflection/message_def.h b/vendor/upb/reflection/message_def.h deleted file mode 100644 index 0d5dc39..0000000 --- a/vendor/upb/reflection/message_def.h +++ /dev/null @@ -1,160 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_MESSAGE_DEF_H_ -#define UPB_REFLECTION_MESSAGE_DEF_H_ - -#include "upb/base/string_view.h" -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -// Well-known field tag numbers for map-entry messages. -#define kUpb_MapEntry_KeyFieldNumber 1 -#define kUpb_MapEntry_ValueFieldNumber 2 - -// Well-known field tag numbers for Any messages. -#define kUpb_Any_TypeFieldNumber 1 -#define kUpb_Any_ValueFieldNumber 2 - -// Well-known field tag numbers for duration messages. -#define kUpb_Duration_SecondsFieldNumber 1 -#define kUpb_Duration_NanosFieldNumber 2 - -// Well-known field tag numbers for timestamp messages. -#define kUpb_Timestamp_SecondsFieldNumber 1 -#define kUpb_Timestamp_NanosFieldNumber 2 - -// All the different kind of well known type messages. For simplicity of check, -// number wrappers and string wrappers are grouped together. Make sure the -// order and number of these groups are not changed. -typedef enum { - kUpb_WellKnown_Unspecified, - kUpb_WellKnown_Any, - kUpb_WellKnown_FieldMask, - kUpb_WellKnown_Duration, - kUpb_WellKnown_Timestamp, - - // number wrappers - kUpb_WellKnown_DoubleValue, - kUpb_WellKnown_FloatValue, - kUpb_WellKnown_Int64Value, - kUpb_WellKnown_UInt64Value, - kUpb_WellKnown_Int32Value, - kUpb_WellKnown_UInt32Value, - - // string wrappers - kUpb_WellKnown_StringValue, - kUpb_WellKnown_BytesValue, - kUpb_WellKnown_BoolValue, - kUpb_WellKnown_Value, - kUpb_WellKnown_ListValue, - kUpb_WellKnown_Struct, -} upb_WellKnown; - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m); - -const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, - int i); -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m); - -UPB_API const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, - int i); -UPB_API int upb_MessageDef_FieldCount(const upb_MessageDef* m); - -UPB_API const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m); - -// Returns a field by either JSON name or regular proto name. -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -UPB_INLINE const upb_FieldDef* upb_MessageDef_FindByJsonName( - const upb_MessageDef* m, const char* name) { - return upb_MessageDef_FindByJsonNameWithSize(m, name, strlen(name)); -} - -// Lookup of either field or oneof by name. Returns whether either was found. -// If the return is true, then the found def will be set, and the non-found -// one set to NULL. -UPB_API bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t size, - const upb_FieldDef** f, - const upb_OneofDef** o); -UPB_INLINE bool upb_MessageDef_FindByName(const upb_MessageDef* m, - const char* name, - const upb_FieldDef** f, - const upb_OneofDef** o) { - return upb_MessageDef_FindByNameWithSize(m, name, strlen(name), f, o); -} - -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name); -UPB_API const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -UPB_API const upb_FieldDef* upb_MessageDef_FindFieldByNumber( - const upb_MessageDef* m, uint32_t i); -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name); -UPB_API const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -UPB_API const char* upb_MessageDef_FullName(const upb_MessageDef* m); -bool upb_MessageDef_HasOptions(const upb_MessageDef* m); -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m); -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m); - -// Creates a mini descriptor string for a message, returns true on success. -UPB_NODISCARD bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, - upb_Arena* a, - upb_StringView* out); - -UPB_API const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m); -const char* upb_MessageDef_Name(const upb_MessageDef* m); - -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i); -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i); -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i); - -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m); -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m); -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m); - -UPB_API const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, - int i); -UPB_API int upb_MessageDef_OneofCount(const upb_MessageDef* m); -int upb_MessageDef_RealOneofCount(const upb_MessageDef* m); - -const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m); -const google_protobuf_FeatureSet* upb_MessageDef_ResolvedFeatures( - const upb_MessageDef* m); - -upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i); -int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m); - -const upb_MessageReservedRange* upb_MessageDef_ReservedRange( - const upb_MessageDef* m, int i); -int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m); - -UPB_API upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m); -UPB_API google_protobuf_SymbolVisibility -upb_MessageDef_Visibility(const upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_MESSAGE_DEF_H_ */ diff --git a/vendor/upb/reflection/message_reserved_range.c b/vendor/upb/reflection/message_reserved_range.c deleted file mode 100644 index a21ebc5..0000000 --- a/vendor/upb/reflection/message_reserved_range.c +++ /dev/null @@ -1,62 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include - -#include "upb/reflection/def.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/field_def.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/message_def.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_MessageReservedRange { - int32_t start; - int32_t end; -}; - -upb_MessageReservedRange* _upb_MessageReservedRange_At( - const upb_MessageReservedRange* r, int i) { - return (upb_MessageReservedRange*)&r[i]; -} - -int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r) { - return r->start; -} -int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { - return r->end; -} - -upb_MessageReservedRange* _upb_MessageReservedRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ReservedRange* const* protos, - const upb_MessageDef* m) { - upb_MessageReservedRange* r = - UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_MessageReservedRange, n); - - for (int i = 0; i < n; i++) { - const int32_t start = google_protobuf_DescriptorProto_ReservedRange_start(protos[i]); - const int32_t end = google_protobuf_DescriptorProto_ReservedRange_end(protos[i]); - const int32_t max = kUpb_MaxFieldNumber + 1; - - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. - if (start < 1 || end <= start || end > max) { - _upb_DefBuilder_Errf(ctx, - "Reserved range (%d, %d) is invalid, message=%s\n", - (int)start, (int)end, upb_MessageDef_FullName(m)); - } - - r[i].start = start; - r[i].end = end; - } - - return r; -} diff --git a/vendor/upb/reflection/message_reserved_range.h b/vendor/upb/reflection/message_reserved_range.h deleted file mode 100644 index 9854f52..0000000 --- a/vendor/upb/reflection/message_reserved_range.h +++ /dev/null @@ -1,31 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ -#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ - -#include "upb/reflection/common.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r); -int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ */ diff --git a/vendor/upb/reflection/method_def.c b/vendor/upb/reflection/method_def.c deleted file mode 100644 index 3473c3c..0000000 --- a/vendor/upb/reflection/method_def.c +++ /dev/null @@ -1,118 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/method_def.h" - -#include "upb/base/string_view.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/service_def.h" -#include "upb/reflection/service_def.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_MethodDef { - const google_protobuf_MethodOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - upb_ServiceDef* service; - const char* full_name; - const upb_MessageDef* input_type; - const upb_MessageDef* output_type; - int index; - bool client_streaming; - bool server_streaming; -}; - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i) { - return (upb_MethodDef*)&m[i]; -} - -const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { - return m->service; -} - -const google_protobuf_MethodOptions* upb_MethodDef_Options(const upb_MethodDef* m) { - return m->opts; -} - -bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { - return m->opts != (void*)kUpbDefOptDefault; -} - -const google_protobuf_FeatureSet* upb_MethodDef_ResolvedFeatures( - const upb_MethodDef* m) { - return m->resolved_features; -} - -const char* upb_MethodDef_FullName(const upb_MethodDef* m) { - return m->full_name; -} - -const char* upb_MethodDef_Name(const upb_MethodDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); -} - -int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } - -const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { - return m->input_type; -} - -const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { - return m->output_type; -} - -bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { - return m->client_streaming; -} - -bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { - return m->server_streaming; -} - -static void create_method(upb_DefBuilder* ctx, - const google_protobuf_MethodDescriptorProto* method_proto, - const google_protobuf_FeatureSet* parent_features, - upb_ServiceDef* s, upb_MethodDef* m) { - UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); - m->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, google_protobuf_MethodOptions_features(m->opts)); - - upb_StringView name = google_protobuf_MethodDescriptorProto_name(method_proto); - - m->service = s; - m->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); - m->client_streaming = - google_protobuf_MethodDescriptorProto_client_streaming(method_proto); - m->server_streaming = - google_protobuf_MethodDescriptorProto_server_streaming(method_proto); - m->input_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_input_type(method_proto), UPB_DEFTYPE_MSG); - m->output_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_output_type(method_proto), UPB_DEFTYPE_MSG); - _upb_ServiceDef_InsertMethod(ctx, s, m); -} - -// Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, upb_ServiceDef* s) { - upb_MethodDef* m = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_MethodDef, n); - for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], parent_features, s, &m[i]); - m[i].index = i; - } - return m; -} diff --git a/vendor/upb/reflection/method_def.h b/vendor/upb/reflection/method_def.h deleted file mode 100644 index 927cbdf..0000000 --- a/vendor/upb/reflection/method_def.h +++ /dev/null @@ -1,42 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_METHOD_DEF_H_ -#define UPB_REFLECTION_METHOD_DEF_H_ - -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m); -const char* upb_MethodDef_FullName(const upb_MethodDef* m); -bool upb_MethodDef_HasOptions(const upb_MethodDef* m); -int upb_MethodDef_Index(const upb_MethodDef* m); -UPB_API const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); -UPB_API const char* upb_MethodDef_Name(const upb_MethodDef* m); -UPB_API const google_protobuf_MethodOptions* upb_MethodDef_Options( - const upb_MethodDef* m); -const google_protobuf_FeatureSet* upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m); -UPB_API const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); -UPB_API bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); -UPB_API const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_METHOD_DEF_H_ */ diff --git a/vendor/upb/reflection/oneof_def.c b/vendor/upb/reflection/oneof_def.c deleted file mode 100644 index f08516d..0000000 --- a/vendor/upb/reflection/oneof_def.c +++ /dev/null @@ -1,219 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/oneof_def.h" - -#include -#include -#include - -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/field_def.h" -#include "upb/reflection/internal/message_def.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_OneofDef { - UPB_ALIGN_AS(8) const google_protobuf_OneofOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - const upb_MessageDef* parent; - const char* full_name; - int field_count; - bool synthetic; - const upb_FieldDef** fields; - upb_strtable ntof; // lookup a field by name - upb_inttable itof; // lookup a field by number (index) -}; - -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { - return (upb_OneofDef*)&o[i]; -} - -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o) { - return o->opts; -} - -bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { - return o->opts != (void*)kUpbDefOptDefault; -} - -const google_protobuf_FeatureSet* upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o) { - return o->resolved_features; -} - -const char* upb_OneofDef_FullName(const upb_OneofDef* o) { - return o->full_name; -} - -const char* upb_OneofDef_Name(const upb_OneofDef* o) { - return _upb_DefBuilder_FullToShort(o->full_name); -} - -const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { - return o->parent; -} - -int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } - -const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { - UPB_ASSERT(i < o->field_count); - return o->fields[i]; -} - -int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } - -uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { - // Compute index in our parent's array. - return o - upb_MessageDef_Oneof(o->parent, 0); -} - -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } - -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size) { - upb_value val; - return upb_strtable_lookup2(&o->ntof, name, size, &val) - ? upb_value_getptr(val) - : NULL; -} - -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name) { - return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); -} - -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num) { - upb_value val; - return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) - : NULL; -} - -void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, - const upb_FieldDef* f, const char* name, - size_t size) { - o->field_count++; - if (_upb_FieldDef_IsProto3Optional(f)) o->synthetic = true; - - const int number = upb_FieldDef_Number(f); - const upb_value v = upb_value_constptr(f); - - // TODO: This lookup is unfortunate because we also perform it when - // inserting into the message's table. Unfortunately that step occurs after - // this one and moving things around could be tricky so let's leave it for - // a future refactoring. - const bool number_exists = upb_inttable_lookup(&o->itof, number, NULL); - if (UPB_UNLIKELY(number_exists)) { - _upb_DefBuilder_Errf(ctx, "oneof fields have the same number (%d)", number); - } - - // TODO: More redundant work happening here. - const bool name_exists = upb_strtable_lookup2(&o->ntof, name, size, NULL); - if (UPB_UNLIKELY(name_exists)) { - _upb_DefBuilder_Errf(ctx, "oneof fields have the same name (%.*s)", - (int)size, name); - } - - const bool ok = upb_inttable_insert(&o->itof, number, v, ctx->arena) && - upb_strtable_insert(&o->ntof, name, size, v, ctx->arena); - if (UPB_UNLIKELY(!ok)) { - _upb_DefBuilder_OomErr(ctx); - } -} - -// Returns the synthetic count. -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { - int synthetic_count = 0; - - for (int i = 0; i < upb_MessageDef_OneofCount(m); i++) { - upb_OneofDef* o = (upb_OneofDef*)upb_MessageDef_Oneof(m, i); - - if (o->synthetic && o->field_count != 1) { - _upb_DefBuilder_Errf(ctx, - "Synthetic oneofs must have one field, not %d: %s", - o->field_count, upb_OneofDef_Name(o)); - } - - if (o->synthetic) { - synthetic_count++; - } else if (synthetic_count != 0) { - _upb_DefBuilder_Errf( - ctx, "Synthetic oneofs must be after all other oneofs: %s", - upb_OneofDef_Name(o)); - } - - o->fields = - UPB_DEFBUILDER_ALLOCARRAY(ctx, const upb_FieldDef*, o->field_count); - o->field_count = 0; - } - - for (int i = 0; i < upb_MessageDef_FieldCount(m); i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); - if (o) { - o->fields[o->field_count++] = f; - } - } - - return synthetic_count; -} - -static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const google_protobuf_OneofDescriptorProto* oneof_proto, - const google_protobuf_FeatureSet* parent_features, - const upb_OneofDef* _o) { - upb_OneofDef* o = (upb_OneofDef*)_o; - - UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - o->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, google_protobuf_OneofOptions_features(o->opts)); - - upb_StringView name = google_protobuf_OneofDescriptorProto_name(oneof_proto); - - o->parent = m; - o->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_MessageDef_FullName(m), name); - o->field_count = 0; - o->synthetic = false; - - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); - } - - upb_value v = _upb_DefType_Pack(o, UPB_DEFTYPE_ONEOF); - bool ok = _upb_MessageDef_Insert(m, name.data, name.size, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&o->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_strtable_init(&o->ntof, 4, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -// Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features, upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); - - upb_OneofDef* o = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_OneofDef, n); - for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); - } - return o; -} diff --git a/vendor/upb/reflection/oneof_def.h b/vendor/upb/reflection/oneof_def.h deleted file mode 100644 index f92a3f1..0000000 --- a/vendor/upb/reflection/oneof_def.h +++ /dev/null @@ -1,52 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ONEOF_DEF_H_ -#define UPB_REFLECTION_ONEOF_DEF_H_ - -#include -#include - -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API const upb_MessageDef* upb_OneofDef_ContainingType( - const upb_OneofDef* o); -UPB_API const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i); -UPB_API int upb_OneofDef_FieldCount(const upb_OneofDef* o); -const char* upb_OneofDef_FullName(const upb_OneofDef* o); -bool upb_OneofDef_HasOptions(const upb_OneofDef* o); -uint32_t upb_OneofDef_Index(const upb_OneofDef* o); -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o); -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name); -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size); -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num); -UPB_API const char* upb_OneofDef_Name(const upb_OneofDef* o); -int upb_OneofDef_numfields(const upb_OneofDef* o); -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); -const google_protobuf_FeatureSet* upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_ONEOF_DEF_H_ */ diff --git a/vendor/upb/reflection/reflection_test.cc b/vendor/upb/reflection/reflection_test.cc deleted file mode 100644 index 2bfd021..0000000 --- a/vendor/upb/reflection/reflection_test.cc +++ /dev/null @@ -1,341 +0,0 @@ - -#include -#include -#include - -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.upb.h" -#include -#include -#include "absl/log/absl_check.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_join.h" -#include "google/protobuf/unittest.upbdefs.h" -#include "upb/base/status.hpp" -#include "upb/mem/arena.hpp" -#include "upb/reflection/def.h" -#include "upb/reflection/def.hpp" -#include "upb/reflection/internal/def_pool.h" -#include "upb/test/parse_text_proto.h" - -namespace upb_test { -namespace { - -using ::testing::HasSubstr; -using ::testing::NotNull; - -google_protobuf_FileDescriptorProto* ToUpbDescriptorSet( - const google::protobuf::FileDescriptorProto& proto, upb::Arena& arena) { - std::string serialized; - (void)proto.SerializeToString(&serialized); - return google_protobuf_FileDescriptorProto_parse(serialized.data(), serialized.size(), - arena.ptr()); -} - -absl::StatusOr LoadDescriptorSetFromProto( - const google::protobuf::FileDescriptorSet& set) { - upb::Arena arena; - upb::DefPool defpool; - upb::Status status; - for (const auto& file : set.file()) { - google_protobuf_FileDescriptorProto* upb_proto = ToUpbDescriptorSet(file, arena); - ABSL_CHECK(upb_proto); - upb::FileDefPtr file_def = defpool.AddFile(upb_proto, &status); - if (!file_def) return absl::InternalError(status.error_message()); - } - return defpool; -} - -absl::StatusOr LoadDescriptorProto(absl::string_view proto_text) { - google::protobuf::FileDescriptorProto proto = ParseTextProtoOrDie(proto_text); - google::protobuf::FileDescriptorSet set; - *set.add_file() = proto; - return LoadDescriptorSetFromProto(set); -} - -TEST(ReflectionTest, OpenEnumWithNonZeroDefault) { - absl::Status status = LoadDescriptorProto( - R"pb( - syntax: "proto3" - name: "F" - enum_type { - name: "BadEnum" - value { name: "v1" number: 1 } - } - )pb") - .status(); - EXPECT_EQ(std::string_view(status.message()), - "for open enums, the first value must be zero (BadEnum)"); -} - -TEST(ReflectionTest, EnumDefault) { - upb::DefPool pool = LoadDescriptorProto( - R"pb( - syntax: "proto2" - name: "F" - enum_type { - name: "FooEnum" - value { name: "v1" number: 1 } - } - )pb") - .value(); - upb::EnumDefPtr e = pool.FindEnumByName("FooEnum"); - EXPECT_EQ(e.default_value(), 1); -} - -TEST(ReflectionTest, ImplicitPresenceWithDefault) { - absl::Status status = - LoadDescriptorProto( - R"pb( - syntax: "editions" - edition: EDITION_2023 - name: "F" - message_type { - name: "FooMessage" - field { - name: "f1" - number: 1 - type: TYPE_INT32 - default_value: "1" - options { features { field_presence: IMPLICIT } } - } - } - )pb") - .status(); - EXPECT_EQ(std::string_view(status.message()), - "fields with implicit presence cannot have explicit defaults " - "(FooMessage.f1)"); -} - -TEST(ReflectionTest, ImplicitPresenceWithNonZeroDefaultEnum) { - absl::Status status = - LoadDescriptorProto( - R"pb( - syntax: "editions" - edition: EDITION_2023 - name: "F" - enum_type { - name: "FooEnum" - value { name: "v1" number: 1 } - options { features { enum_type: CLOSED } } - } - message_type { - name: "FooMessage" - field { - name: "f1" - number: 1 - type: TYPE_ENUM - type_name: "FooEnum" - options { features { field_presence: IMPLICIT } } - } - } - )pb") - .status(); - EXPECT_EQ(std::string_view(status.message()), - "Implicit presence field (FooMessage.f1) cannot use an enum type " - "with a non-zero default (FooEnum)"); -} - -TEST(ReflectionTest, EditionWithoutSyntax) { - absl::Status status = LoadDescriptorProto( - R"pb( - edition: EDITION_2023 - )pb") - .status(); - EXPECT_EQ( - status.message(), - R"(Setting edition requires that syntax="editions", but syntax is "")"); -} - -TEST(ReflectionTest, EditionWithWrongSyntax) { - absl::Status status = LoadDescriptorProto( - R"pb( - edition: EDITION_2023 syntax: "proto2" - )pb") - .status(); - EXPECT_EQ( - status.message(), - R"(Setting edition requires that syntax="editions", but syntax is "proto2")"); -} - -TEST(ReflectionTest, SyntaxEditionsWithNoEdition) { - absl::Status status = LoadDescriptorProto( - R"pb( - syntax: "editions" - )pb") - .status(); - EXPECT_EQ(status.message(), - R"(File has syntax="editions", but no edition is specified)"); -} - -TEST(ReflectionTest, InvalidSyntax) { - absl::Status status = LoadDescriptorProto( - R"pb( - syntax: "abc123" - )pb") - .status(); - EXPECT_EQ(status.message(), R"(Invalid syntax 'abc123')"); -} - -TEST(ReflectionTest, ExplicitFeatureOnProto2File) { - absl::Status status = LoadDescriptorProto( - R"pb( - syntax: "proto2" - options { features { field_presence: EXPLICIT } } - )pb") - .status(); - EXPECT_EQ(status.message(), R"(Features can only be specified for editions)"); -} - -TEST(ReflectionTest, ExplicitFeatureOnProto2Message) { - absl::Status status = - LoadDescriptorProto( - R"pb( - syntax: "proto2" - message_type { - name: "M" - options { features { field_presence: EXPLICIT } } - } - )pb") - .status(); - EXPECT_EQ(status.message(), R"(Features can only be specified for editions)"); -} - -TEST(ReflectionTest, ExplicitFeatureOnProto2Enum) { - absl::Status status = - LoadDescriptorProto( - R"pb( - syntax: "proto2" - enum_type { - name: "E" - options { features { field_presence: EXPLICIT } } - } - )pb") - .status(); - EXPECT_EQ(status.message(), R"(Features can only be specified for editions)"); -} - -TEST(ReflectionTest, ExplicitFeatureOnProto2EnumValue) { - absl::Status status = - LoadDescriptorProto( - R"pb( - syntax: "proto2" - enum_type { - name: "E" - value { - name: "V" - options { features { field_presence: EXPLICIT } } - } - } - )pb") - .status(); - EXPECT_EQ(status.message(), R"(Features can only be specified for editions)"); -} - -TEST(ReflectionTest, TooManyRequiredFieldsFailGracefully) { - const auto make_desc = [](int n) { - std::vector fields; - for (int i = 1; i <= n; ++i) { - fields.push_back(absl::StrFormat(R"pb( - field { - name: "f%d" - number: %d - type: TYPE_INT32 - label: LABEL_REQUIRED - })pb", - i, i)); - } - return absl::StrFormat( - R"pb( - syntax: "proto2" - name: "F" - message_type { name: "FooMessage" %s } - )pb", - absl::StrJoin(fields, "\n")); - }; - // 63 required fields is ok. - upb::DefPool good = LoadDescriptorProto(make_desc(63)).value(); - auto m = good.FindMessageByName("FooMessage"); - auto f = m.FindFieldByNumber(63); - EXPECT_STREQ(f.full_name(), "FooMessage.f63"); - - // 64 is too much. - EXPECT_THAT(LoadDescriptorProto(make_desc(64)).status().message(), - HasSubstr("Too many required fields")); -} - -#define STRING_AND_SIZE(string) string, strlen(string) - -TEST(ReflectionTest, FindMethodByName) { - upb::Arena arena; - upb::DefPool defpool; - upb::Status status; - ASSERT_TRUE(_upb_DefPool_LoadDefInit( - defpool.ptr(), &google_protobuf_unittest_proto_upbdefinit)); - const upb_ServiceDef* service_def = upb_DefPool_FindServiceByName( - defpool.ptr(), "proto2_unittest.TestService"); - ASSERT_THAT(service_def, NotNull()); - EXPECT_STREQ(upb_ServiceDef_Name(service_def), "TestService"); - EXPECT_STREQ(upb_ServiceDef_FullName(service_def), - "proto2_unittest.TestService"); - EXPECT_EQ(upb_DefPool_FindServiceByNameWithSize( - defpool.ptr(), STRING_AND_SIZE("proto2_unittest.TestService")), - service_def); - const upb_MethodDef* method_def = - upb_ServiceDef_FindMethodByName(service_def, "Bar"); - ASSERT_THAT(method_def, NotNull()); - EXPECT_STREQ(upb_MethodDef_Name(method_def), "Bar"); - EXPECT_STREQ(upb_MethodDef_FullName(method_def), - "proto2_unittest.TestService.Bar"); - EXPECT_EQ(upb_ServiceDef_FindMethodByNameWithSize(service_def, - STRING_AND_SIZE("Bar")), - method_def); -} - -TEST(ReflectionTest, FindEnumByName) { - upb::Arena arena; - upb::DefPool defpool; - upb::Status status; - ASSERT_TRUE(_upb_DefPool_LoadDefInit( - defpool.ptr(), &google_protobuf_unittest_proto_upbdefinit)); - const upb_EnumDef* enum_def = upb_DefPool_FindEnumByName( - defpool.ptr(), "proto2_unittest.TestAllTypes.NestedEnum"); - ASSERT_THAT(enum_def, NotNull()); - EXPECT_STREQ(upb_EnumDef_Name(enum_def), "NestedEnum"); - EXPECT_STREQ(upb_EnumDef_FullName(enum_def), - "proto2_unittest.TestAllTypes.NestedEnum"); - EXPECT_EQ(upb_DefPool_FindEnumByNameWithSize( - defpool.ptr(), - STRING_AND_SIZE("proto2_unittest.TestAllTypes.NestedEnum")), - enum_def); -} - -TEST(ReflectionTest, FindEnumValueByName) { - upb::Arena arena; - upb::DefPool defpool; - upb::Status status; - ASSERT_TRUE(_upb_DefPool_LoadDefInit( - defpool.ptr(), &google_protobuf_unittest_proto_upbdefinit)); - const upb_EnumValueDef* enum_value_def = upb_DefPool_FindEnumValueByName( - defpool.ptr(), "proto2_unittest.TestAllTypes.BAR"); - ASSERT_THAT(enum_value_def, NotNull()); - EXPECT_STREQ(upb_EnumValueDef_Name(enum_value_def), "BAR"); - EXPECT_STREQ(upb_EnumValueDef_FullName(enum_value_def), - "proto2_unittest.TestAllTypes.BAR"); - EXPECT_EQ( - upb_DefPool_FindEnumValueByNameWithSize( - defpool.ptr(), STRING_AND_SIZE("proto2_unittest.TestAllTypes.BAR")), - enum_value_def); - const upb_EnumDef* enum_def = upb_DefPool_FindEnumByName( - defpool.ptr(), "proto2_unittest.TestAllTypes.NestedEnum"); - ASSERT_THAT(enum_def, NotNull()); - EXPECT_EQ(upb_EnumDef_FindValueByName(enum_def, "BAR"), enum_value_def); - EXPECT_EQ( - upb_EnumDef_FindValueByNameWithSize(enum_def, STRING_AND_SIZE("BAR")), - enum_value_def); -} - -} // namespace -} // namespace upb_test diff --git a/vendor/upb/reflection/service_def.c b/vendor/upb/reflection/service_def.c deleted file mode 100644 index df9c27a..0000000 --- a/vendor/upb/reflection/service_def.c +++ /dev/null @@ -1,145 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/reflection/internal/service_def.h" - -#include -#include - -#include "upb/base/string_view.h" -#include "upb/hash/str_table.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def_type.h" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/reflection/internal/def_builder.h" -#include "upb/reflection/internal/file_def.h" -#include "upb/reflection/internal/method_def.h" - -// Must be last. -#include "upb/port/def.inc" - -struct upb_ServiceDef { - UPB_ALIGN_AS(8) const google_protobuf_ServiceOptions* opts; - const google_protobuf_FeatureSet* resolved_features; - const upb_FileDef* file; - const char* full_name; - upb_MethodDef* methods; - int method_count; - int index; - upb_strtable ntom; -}; - -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { - return (upb_ServiceDef*)&s[index]; -} - -const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s) { - return s->opts; -} - -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { - return s->opts != (void*)kUpbDefOptDefault; -} - -const google_protobuf_FeatureSet* upb_ServiceDef_ResolvedFeatures( - const upb_ServiceDef* s) { - return s->resolved_features; -} - -const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { - return s->full_name; -} - -const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { - return _upb_DefBuilder_FullToShort(s->full_name); -} - -int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } - -const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { - return s->file; -} - -int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { - return s->method_count; -} - -const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { - return (i < 0 || i >= s->method_count) ? NULL - : _upb_MethodDef_At(s->methods, i); -} - -const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, - const char* name) { - return upb_ServiceDef_FindMethodByNameWithSize(s, name, strlen(name)); -} - -const upb_MethodDef* upb_ServiceDef_FindMethodByNameWithSize( - const upb_ServiceDef* s, const char* name, size_t len) { - upb_value val; - - if (!upb_strtable_lookup2(&s->ntom, name, len, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_METHOD); -} - -static void create_service(upb_DefBuilder* ctx, - const google_protobuf_ServiceDescriptorProto* svc_proto, - const google_protobuf_FeatureSet* parent_features, - upb_ServiceDef* s) { - UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); - s->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, google_protobuf_ServiceOptions_features(s->opts)); - - // Must happen before _upb_DefBuilder_Add() - s->file = _upb_DefBuilder_File(ctx); - - upb_StringView name = google_protobuf_ServiceDescriptorProto_name(svc_proto); - const char* package = _upb_FileDef_RawPackage(s->file); - s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); - _upb_DefBuilder_Add(ctx, s->full_name, - _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); - - size_t n; - const google_protobuf_MethodDescriptorProto* const* methods = - google_protobuf_ServiceDescriptorProto_method(svc_proto, &n); - s->method_count = n; - bool ok = upb_strtable_init(&s->ntom, n, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); -} - -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos, - const google_protobuf_FeatureSet* parent_features) { - _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); - - upb_ServiceDef* s = UPB_DEFBUILDER_ALLOCARRAY(ctx, upb_ServiceDef, n); - for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], parent_features, &s[i]); - s[i].index = i; - } - return s; -} - -void _upb_ServiceDef_InsertMethod(upb_DefBuilder* ctx, upb_ServiceDef* s, - const upb_MethodDef* m) { - const char* shortname = upb_MethodDef_Name(m); - const size_t shortnamelen = strlen(shortname); - upb_value existing_v; - if (upb_strtable_lookup(&s->ntom, shortname, &existing_v)) { - _upb_DefBuilder_Errf(ctx, "duplicate method name (%s)", shortname); - } - const upb_value method_v = _upb_DefType_Pack(m, UPB_DEFTYPE_METHOD); - bool ok = upb_strtable_insert(&s->ntom, shortname, shortnamelen, method_v, - ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} diff --git a/vendor/upb/reflection/service_def.h b/vendor/upb/reflection/service_def.h deleted file mode 100644 index 84902e6..0000000 --- a/vendor/upb/reflection/service_def.h +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_SERVICE_DEF_H_ -#define UPB_REFLECTION_SERVICE_DEF_H_ - -#include "upb/reflection/common.h" -#include "upb/reflection/descriptor_bootstrap.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s); -const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, - const char* name); -const upb_MethodDef* upb_ServiceDef_FindMethodByNameWithSize( - const upb_ServiceDef* s, const char* name, size_t len); -UPB_API const char* upb_ServiceDef_FullName(const upb_ServiceDef* s); -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s); -int upb_ServiceDef_Index(const upb_ServiceDef* s); -UPB_API const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, - int i); -UPB_API int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); -const char* upb_ServiceDef_Name(const upb_ServiceDef* s); -UPB_API const google_protobuf_ServiceOptions* upb_ServiceDef_Options( - const upb_ServiceDef* s); -const google_protobuf_FeatureSet* upb_ServiceDef_ResolvedFeatures( - const upb_ServiceDef* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_REFLECTION_SERVICE_DEF_H_ */ diff --git a/vendor/upb/reflection/stage0/google/protobuf/descriptor.upb.c b/vendor/upb/reflection/stage0/google/protobuf/descriptor.upb.c deleted file mode 100644 index c3b1e42..0000000 --- a/vendor/upb/reflection/stage0/google/protobuf/descriptor.upb.c +++ /dev/null @@ -1,1159 +0,0 @@ -#include -#include "upb/generated_code_support.h" -#include "upb/reflection/descriptor_bootstrap.h" - -static upb_Arena* upb_BootstrapArena() { - static upb_Arena* arena = NULL; - if (!arena) arena = upb_Arena_New(); - return arena; -} - -const upb_MiniTable* google__protobuf__FileDescriptorSet_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$PG"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FileDescriptorSet_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__FileDescriptorProto_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__FileDescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$11EGGGG33<<1a4E"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FileDescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__DescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 5), - google__protobuf__EnumDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 6), - google__protobuf__ServiceDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 7), - google__protobuf__FieldDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 8), - google__protobuf__FileOptions_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 9), - google__protobuf__SourceCodeInfo_msg_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 14), - google__protobuf__Edition_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__DescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$1GGGGG3GGE4"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__DescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__FieldDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 6), - google__protobuf__FieldDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__DescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__EnumDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 5), - google__protobuf__DescriptorProto__ExtensionRange_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 8), - google__protobuf__OneofDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 7), - google__protobuf__MessageOptions_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 9), - google__protobuf__DescriptorProto__ReservedRange_msg_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 11), - google__protobuf__SymbolVisibility_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__DescriptorProto__ExtensionRange_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$((3"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__DescriptorProto__ExtensionRange_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__ExtensionRangeOptions_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__DescriptorProto__ReservedRange_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$(("; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__DescriptorProto__ReservedRange_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - return mini_table; -} - -const upb_MiniTable* google__protobuf__ExtensionRangeOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$PaG4n`3t|G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__ExtensionRangeOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__ExtensionRangeOptions__Declaration_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 50), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__ExtensionRangeOptions__VerificationState_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__ExtensionRangeOptions__Declaration_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$(11a//"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__ExtensionRangeOptions__Declaration_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - return mini_table; -} - -const upb_MiniTable* google__protobuf__FieldDescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$11(44113(1f/"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FieldDescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__FieldDescriptorProto__Label_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 5), - google__protobuf__FieldDescriptorProto__Type_enum_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 8), - google__protobuf__FieldOptions_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__OneofDescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$13"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__OneofDescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__OneofOptions_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__EnumDescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$1G3GE4"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__EnumDescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__EnumValueDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__EnumOptions_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 6), - google__protobuf__SymbolVisibility_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$(("; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - return mini_table; -} - -const upb_MiniTable* google__protobuf__EnumValueDescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$1(3"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__EnumValueDescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__EnumValueOptions_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__ServiceDescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$1G3"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__ServiceDescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__MethodDescriptorProto_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__ServiceOptions_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__MethodDescriptorProto_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$1113//"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__MethodDescriptorProto_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__MethodOptions_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__FileOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P1f14/1d///a/b/c/c/d11a111b11d3t|G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FileOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 9), - google__protobuf__FileOptions__OptimizeMode_enum_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 50), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__MessageOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P///c/c/3z}G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__MessageOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 12), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__FieldOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P4//a/4c/d//4aHG33p}G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FieldOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__FieldOptions__CType_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 6), - google__protobuf__FieldOptions__JSType_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 17), - google__protobuf__FieldOptions__OptionRetention_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 19), - google__protobuf__FieldOptions__OptionTargetType_enum_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 20), - google__protobuf__FieldOptions__EditionDefault_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 21), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 22), - google__protobuf__FieldOptions__FeatureSupport_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__FieldOptions__EditionDefault_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$a14"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FieldOptions__EditionDefault_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__Edition_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__FieldOptions__FeatureSupport_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$44141"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FieldOptions__FeatureSupport_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__Edition_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__Edition_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__Edition_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__OneofOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P3e~G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__OneofOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__EnumOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$Pa//b/3_~G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__EnumOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 7), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__EnumValueOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P/3/3b~G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__EnumValueOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__FieldOptions__FeatureSupport_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__ServiceOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P``/3d}G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__ServiceOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 34), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__MethodOptions_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P``/43c}G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__MethodOptions_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 34), - google__protobuf__MethodOptions__IdempotencyLevel_enum_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 35), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 999), - google__protobuf__UninterpretedOption_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__UninterpretedOption_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$aG1,+ 01"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__UninterpretedOption_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__UninterpretedOption__NamePart_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__UninterpretedOption__NamePart_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$1N/N"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__UninterpretedOption__NamePart_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - return mini_table; -} - -const upb_MiniTable* google__protobuf__FeatureSet_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P44444444"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FeatureSet_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__FeatureSet__FieldPresence_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 2), - google__protobuf__FeatureSet__EnumType_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__FeatureSet__RepeatedFieldEncoding_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__FeatureSet__Utf8Validation_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 5), - google__protobuf__FeatureSet__MessageEncoding_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 6), - google__protobuf__FeatureSet__JsonFormat_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 7), - google__protobuf__FeatureSet__EnforceNamingStyle_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 8), - google__protobuf__FeatureSet__VisibilityFeature__DefaultSymbolVisibility_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__FeatureSet__VisibilityFeature_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FeatureSet__VisibilityFeature_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - return mini_table; -} - -const upb_MiniTable* google__protobuf__FeatureSetDefaults_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$Gb44"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FeatureSetDefaults_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__Edition_enum_init()); - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 5), - google__protobuf__Edition_enum_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$b433"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 3), - google__protobuf__Edition_enum_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 4), - google__protobuf__FeatureSet_msg_init()); - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 5), - google__protobuf__FeatureSet_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__SourceCodeInfo_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$PG"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__SourceCodeInfo_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__SourceCodeInfo__Location_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__SourceCodeInfo__Location_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$N<<11aE"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__SourceCodeInfo__Location_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - return mini_table; -} - -const upb_MiniTable* google__protobuf__GeneratedCodeInfo_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$G"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__GeneratedCodeInfo_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubMessage( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 1), - google__protobuf__GeneratedCodeInfo__Annotation_msg_init()); - return mini_table; -} - -const upb_MiniTable* google__protobuf__GeneratedCodeInfo__Annotation_msg_init() { - static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$N<1((4"; - if (mini_table) return mini_table; - upb_Status status; - mini_table = - upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), - upb_BootstrapArena(), &status); - if (!mini_table) { - fprintf(stderr, "Failed to build mini_table for google__protobuf__GeneratedCodeInfo__Annotation_msg_init: %s\n", - upb_Status_ErrorMessage(&status)); - abort(); - } - upb_MiniTable_SetSubEnum( - mini_table, - (upb_MiniTableField*)upb_MiniTable_FindFieldByNumber(mini_table, - 5), - google__protobuf__GeneratedCodeInfo__Annotation__Semantic_enum_init()); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__Edition_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)~z!|aAcxg!h{va)|i}{~~`!"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__ExtensionRangeOptions__VerificationState_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!$"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__EnforceNamingStyle_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!1"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__EnumType_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__FieldPresence_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!1"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__JsonFormat_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__MessageEncoding_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__RepeatedFieldEncoding_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__Utf8Validation_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!/"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FeatureSet__VisibilityFeature__DefaultSymbolVisibility_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!A"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FieldDescriptorProto__Label_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!0"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FieldDescriptorProto__Type_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!@AA1"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FieldOptions__CType_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FieldOptions__JSType_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FieldOptions__OptionRetention_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FieldOptions__OptionTargetType_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!AA"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__FileOptions__OptimizeMode_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!0"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__GeneratedCodeInfo__Annotation__Semantic_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__MethodOptions__IdempotencyLevel_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - -const upb_MiniTableEnum* google__protobuf__SymbolVisibility_enum_init() { - static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)"; - if (mini_table) return mini_table; - mini_table = upb_MiniTableEnum_Build(mini_descriptor, - strlen(mini_descriptor), - upb_BootstrapArena(), NULL); - return mini_table; -} - diff --git a/vendor/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/vendor/upb/reflection/stage0/google/protobuf/descriptor.upb.h deleted file mode 100644 index 8e1b243..0000000 --- a/vendor/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ /dev/null @@ -1,7646 +0,0 @@ -/* This file was generated by upb_generator from the input file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. - * NO CHECKED-IN PROTOBUF GENCODE */ - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_ -#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_ - -#include "upb/generated_code_support.h" -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif -extern const upb_MiniTable* google__protobuf__FileDescriptorSet_msg_init(void); -extern const upb_MiniTable* google__protobuf__FileDescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__DescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__DescriptorProto__ExtensionRange_msg_init(void); -extern const upb_MiniTable* google__protobuf__DescriptorProto__ReservedRange_msg_init(void); -extern const upb_MiniTable* google__protobuf__ExtensionRangeOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__ExtensionRangeOptions__Declaration_msg_init(void); -extern const upb_MiniTable* google__protobuf__FieldDescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__OneofDescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__EnumDescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(void); -extern const upb_MiniTable* google__protobuf__EnumValueDescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__ServiceDescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__MethodDescriptorProto_msg_init(void); -extern const upb_MiniTable* google__protobuf__FileOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__MessageOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__FieldOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__FieldOptions__EditionDefault_msg_init(void); -extern const upb_MiniTable* google__protobuf__FieldOptions__FeatureSupport_msg_init(void); -extern const upb_MiniTable* google__protobuf__OneofOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__EnumOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__EnumValueOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__ServiceOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__MethodOptions_msg_init(void); -extern const upb_MiniTable* google__protobuf__UninterpretedOption_msg_init(void); -extern const upb_MiniTable* google__protobuf__UninterpretedOption__NamePart_msg_init(void); -extern const upb_MiniTable* google__protobuf__FeatureSet_msg_init(void); -extern const upb_MiniTable* google__protobuf__FeatureSet__VisibilityFeature_msg_init(void); -extern const upb_MiniTable* google__protobuf__FeatureSetDefaults_msg_init(void); -extern const upb_MiniTable* google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(void); -extern const upb_MiniTable* google__protobuf__SourceCodeInfo_msg_init(void); -extern const upb_MiniTable* google__protobuf__SourceCodeInfo__Location_msg_init(void); -extern const upb_MiniTable* google__protobuf__GeneratedCodeInfo_msg_init(void); -extern const upb_MiniTable* google__protobuf__GeneratedCodeInfo__Annotation_msg_init(void); -extern const upb_MiniTableEnum* google__protobuf__Edition_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__ExtensionRangeOptions__VerificationState_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__EnforceNamingStyle_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__EnumType_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__FieldPresence_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__JsonFormat_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__MessageEncoding_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__RepeatedFieldEncoding_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__Utf8Validation_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FeatureSet__VisibilityFeature__DefaultSymbolVisibility_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FieldDescriptorProto__Label_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FieldDescriptorProto__Type_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FieldOptions__CType_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FieldOptions__JSType_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FieldOptions__OptionRetention_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FieldOptions__OptionTargetType_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__FileOptions__OptimizeMode_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__GeneratedCodeInfo__Annotation__Semantic_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__MethodOptions__IdempotencyLevel_enum_init(void); -extern const upb_MiniTableEnum* google__protobuf__SymbolVisibility_enum_init(void); - -typedef struct google_protobuf_FileDescriptorSet { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FileDescriptorSet; - -typedef struct google_protobuf_FileDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FileDescriptorProto; - -typedef struct google_protobuf_DescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_DescriptorProto; - -typedef struct google_protobuf_DescriptorProto_ExtensionRange { - upb_Message UPB_PRIVATE(base); -} google_protobuf_DescriptorProto_ExtensionRange; - -typedef struct google_protobuf_DescriptorProto_ReservedRange { - upb_Message UPB_PRIVATE(base); -} google_protobuf_DescriptorProto_ReservedRange; - -typedef struct google_protobuf_ExtensionRangeOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ExtensionRangeOptions; - -typedef struct google_protobuf_ExtensionRangeOptions_Declaration { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ExtensionRangeOptions_Declaration; - -typedef struct google_protobuf_FieldDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldDescriptorProto; - -typedef struct google_protobuf_OneofDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_OneofDescriptorProto; - -typedef struct google_protobuf_EnumDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumDescriptorProto; - -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumDescriptorProto_EnumReservedRange; - -typedef struct google_protobuf_EnumValueDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumValueDescriptorProto; - -typedef struct google_protobuf_ServiceDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ServiceDescriptorProto; - -typedef struct google_protobuf_MethodDescriptorProto { - upb_Message UPB_PRIVATE(base); -} google_protobuf_MethodDescriptorProto; - -typedef struct google_protobuf_FileOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FileOptions; - -typedef struct google_protobuf_MessageOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_MessageOptions; - -typedef struct google_protobuf_FieldOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldOptions; - -typedef struct google_protobuf_FieldOptions_EditionDefault { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldOptions_EditionDefault; - -typedef struct google_protobuf_FieldOptions_FeatureSupport { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FieldOptions_FeatureSupport; - -typedef struct google_protobuf_OneofOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_OneofOptions; - -typedef struct google_protobuf_EnumOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumOptions; - -typedef struct google_protobuf_EnumValueOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_EnumValueOptions; - -typedef struct google_protobuf_ServiceOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_ServiceOptions; - -typedef struct google_protobuf_MethodOptions { - upb_Message UPB_PRIVATE(base); -} google_protobuf_MethodOptions; - -typedef struct google_protobuf_UninterpretedOption { - upb_Message UPB_PRIVATE(base); -} google_protobuf_UninterpretedOption; - -typedef struct google_protobuf_UninterpretedOption_NamePart { - upb_Message UPB_PRIVATE(base); -} google_protobuf_UninterpretedOption_NamePart; - -typedef struct google_protobuf_FeatureSet { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSet; - -typedef struct google_protobuf_FeatureSet_VisibilityFeature { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSet_VisibilityFeature; - -typedef struct google_protobuf_FeatureSetDefaults { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSetDefaults; - -typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault { - upb_Message UPB_PRIVATE(base); -} google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; - -typedef struct google_protobuf_SourceCodeInfo { - upb_Message UPB_PRIVATE(base); -} google_protobuf_SourceCodeInfo; - -typedef struct google_protobuf_SourceCodeInfo_Location { - upb_Message UPB_PRIVATE(base); -} google_protobuf_SourceCodeInfo_Location; - -typedef struct google_protobuf_GeneratedCodeInfo { - upb_Message UPB_PRIVATE(base); -} google_protobuf_GeneratedCodeInfo; - -typedef struct google_protobuf_GeneratedCodeInfo_Annotation { - upb_Message UPB_PRIVATE(base); -} google_protobuf_GeneratedCodeInfo_Annotation; - - -typedef enum { - google_protobuf_EDITION_UNKNOWN = 0, - google_protobuf_EDITION_1_TEST_ONLY = 1, - google_protobuf_EDITION_2_TEST_ONLY = 2, - google_protobuf_EDITION_LEGACY = 900, - google_protobuf_EDITION_PROTO2 = 998, - google_protobuf_EDITION_PROTO3 = 999, - google_protobuf_EDITION_2023 = 1000, - google_protobuf_EDITION_2024 = 1001, - google_protobuf_EDITION_2026 = 1002, - google_protobuf_EDITION_UNSTABLE = 9999, - google_protobuf_EDITION_99997_TEST_ONLY = 99997, - google_protobuf_EDITION_99998_TEST_ONLY = 99998, - google_protobuf_EDITION_99999_TEST_ONLY = 99999, - google_protobuf_EDITION_MAX = 2147483647 -} google_protobuf_Edition; - -typedef enum { - google_protobuf_ExtensionRangeOptions_DECLARATION = 0, - google_protobuf_ExtensionRangeOptions_UNVERIFIED = 1 -} google_protobuf_ExtensionRangeOptions_VerificationState; - -typedef enum { - google_protobuf_FeatureSet_ENFORCE_NAMING_STYLE_UNKNOWN = 0, - google_protobuf_FeatureSet_STYLE2024 = 1, - google_protobuf_FeatureSet_STYLE_LEGACY = 2, - google_protobuf_FeatureSet_STYLE2026 = 3 -} google_protobuf_FeatureSet_EnforceNamingStyle; - -typedef enum { - google_protobuf_FeatureSet_ENUM_TYPE_UNKNOWN = 0, - google_protobuf_FeatureSet_OPEN = 1, - google_protobuf_FeatureSet_CLOSED = 2 -} google_protobuf_FeatureSet_EnumType; - -typedef enum { - google_protobuf_FeatureSet_FIELD_PRESENCE_UNKNOWN = 0, - google_protobuf_FeatureSet_EXPLICIT = 1, - google_protobuf_FeatureSet_IMPLICIT = 2, - google_protobuf_FeatureSet_LEGACY_REQUIRED = 3 -} google_protobuf_FeatureSet_FieldPresence; - -typedef enum { - google_protobuf_FeatureSet_JSON_FORMAT_UNKNOWN = 0, - google_protobuf_FeatureSet_ALLOW = 1, - google_protobuf_FeatureSet_LEGACY_BEST_EFFORT = 2 -} google_protobuf_FeatureSet_JsonFormat; - -typedef enum { - google_protobuf_FeatureSet_MESSAGE_ENCODING_UNKNOWN = 0, - google_protobuf_FeatureSet_LENGTH_PREFIXED = 1, - google_protobuf_FeatureSet_DELIMITED = 2 -} google_protobuf_FeatureSet_MessageEncoding; - -typedef enum { - google_protobuf_FeatureSet_REPEATED_FIELD_ENCODING_UNKNOWN = 0, - google_protobuf_FeatureSet_PACKED = 1, - google_protobuf_FeatureSet_EXPANDED = 2 -} google_protobuf_FeatureSet_RepeatedFieldEncoding; - -typedef enum { - google_protobuf_FeatureSet_UTF8_VALIDATION_UNKNOWN = 0, - google_protobuf_FeatureSet_VERIFY = 2, - google_protobuf_FeatureSet_NONE = 3 -} google_protobuf_FeatureSet_Utf8Validation; - -typedef enum { - google_protobuf_FeatureSet_VisibilityFeature_DEFAULT_SYMBOL_VISIBILITY_UNKNOWN = 0, - google_protobuf_FeatureSet_VisibilityFeature_EXPORT_ALL = 1, - google_protobuf_FeatureSet_VisibilityFeature_EXPORT_TOP_LEVEL = 2, - google_protobuf_FeatureSet_VisibilityFeature_LOCAL_ALL = 3, - google_protobuf_FeatureSet_VisibilityFeature_STRICT = 4 -} google_protobuf_FeatureSet_VisibilityFeature_DefaultSymbolVisibility; - -typedef enum { - google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, - google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, - google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3 -} google_protobuf_FieldDescriptorProto_Label; - -typedef enum { - google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1, - google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2, - google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3, - google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4, - google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5, - google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6, - google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7, - google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8, - google_protobuf_FieldDescriptorProto_TYPE_STRING = 9, - google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10, - google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11, - google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12, - google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13, - google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16, - google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17, - google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18 -} google_protobuf_FieldDescriptorProto_Type; - -typedef enum { - google_protobuf_FieldOptions_STRING = 0, - google_protobuf_FieldOptions_CORD = 1, - google_protobuf_FieldOptions_STRING_PIECE = 2 -} google_protobuf_FieldOptions_CType; - -typedef enum { - google_protobuf_FieldOptions_JS_NORMAL = 0, - google_protobuf_FieldOptions_JS_STRING = 1, - google_protobuf_FieldOptions_JS_NUMBER = 2 -} google_protobuf_FieldOptions_JSType; - -typedef enum { - google_protobuf_FieldOptions_RETENTION_UNKNOWN = 0, - google_protobuf_FieldOptions_RETENTION_RUNTIME = 1, - google_protobuf_FieldOptions_RETENTION_SOURCE = 2 -} google_protobuf_FieldOptions_OptionRetention; - -typedef enum { - google_protobuf_FieldOptions_TARGET_TYPE_UNKNOWN = 0, - google_protobuf_FieldOptions_TARGET_TYPE_FILE = 1, - google_protobuf_FieldOptions_TARGET_TYPE_EXTENSION_RANGE = 2, - google_protobuf_FieldOptions_TARGET_TYPE_MESSAGE = 3, - google_protobuf_FieldOptions_TARGET_TYPE_FIELD = 4, - google_protobuf_FieldOptions_TARGET_TYPE_ONEOF = 5, - google_protobuf_FieldOptions_TARGET_TYPE_ENUM = 6, - google_protobuf_FieldOptions_TARGET_TYPE_ENUM_ENTRY = 7, - google_protobuf_FieldOptions_TARGET_TYPE_SERVICE = 8, - google_protobuf_FieldOptions_TARGET_TYPE_METHOD = 9 -} google_protobuf_FieldOptions_OptionTargetType; - -typedef enum { - google_protobuf_FileOptions_SPEED = 1, - google_protobuf_FileOptions_CODE_SIZE = 2, - google_protobuf_FileOptions_LITE_RUNTIME = 3 -} google_protobuf_FileOptions_OptimizeMode; - -typedef enum { - google_protobuf_GeneratedCodeInfo_Annotation_NONE = 0, - google_protobuf_GeneratedCodeInfo_Annotation_SET = 1, - google_protobuf_GeneratedCodeInfo_Annotation_ALIAS = 2 -} google_protobuf_GeneratedCodeInfo_Annotation_Semantic; - -typedef enum { - google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0, - google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1, - google_protobuf_MethodOptions_IDEMPOTENT = 2 -} google_protobuf_MethodOptions_IdempotencyLevel; - -typedef enum { - google_protobuf_VISIBILITY_UNSET = 0, - google_protobuf_VISIBILITY_LOCAL = 1, - google_protobuf_VISIBILITY_EXPORT = 2 -} google_protobuf_SymbolVisibility; - - - -/* google.protobuf.FileDescriptorSet */ -UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorSet*)_upb_Message_New(google__protobuf__FileDescriptorSet_msg_init(), arena); -} -UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorSet_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorSet_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorSet_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorSet_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FileDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array( - const google_protobuf_FileDescriptorSet* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( - google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FileDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file( - google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FileDescriptorProto* sub = - (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.FileDescriptorProto */ -UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_ServiceDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { - const google_protobuf_FileOptions* default_val = NULL; - const google_protobuf_FileOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - const google_protobuf_SourceCodeInfo* default_val = NULL; - const google_protobuf_SourceCodeInfo* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_option_dependency(google_protobuf_FileDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 15); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_option_dependency(const google_protobuf_FileDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 15); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_option_dependency_upb_array( - const google_protobuf_FileDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 15); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_option_dependency_mutable_upb_array( - google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 15); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto* sub = - (struct google_protobuf_DescriptorProto*)_upb_Message_New(google__protobuf__DescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumDescriptorProto* sub = - (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(google__protobuf__EnumDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_ServiceDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_ServiceDescriptorProto* sub = - (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(google__protobuf__ServiceDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldDescriptorProto* sub = - (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto* msg, google_protobuf_FileOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FileOptions*)_upb_Message_New(google__protobuf__FileOptions_msg_init(), arena); - if (sub) google_protobuf_FileDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto* msg, google_protobuf_SourceCodeInfo* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info( - google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); - if (sub == NULL) { - sub = (struct google_protobuf_SourceCodeInfo*)_upb_Message_New(google__protobuf__SourceCodeInfo_msg_init(), arena); - if (sub) google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub); - } - return sub; -} -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_option_dependency(google_protobuf_FileDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 15); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_option_dependency(google_protobuf_FileDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 15); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_option_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 15); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} - -/* google.protobuf.DescriptorProto */ -UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto*)_upb_Message_New(google__protobuf__DescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto_ExtensionRange* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { - const google_protobuf_MessageOptions* default_val = NULL; - const google_protobuf_MessageOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_OneofDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_DescriptorProto_ReservedRange* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_array( - const google_protobuf_DescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array( - google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_DescriptorProto_clear_visibility(google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 11); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_visibility(const google_protobuf_DescriptorProto* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 11); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_has_visibility(const google_protobuf_DescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 11); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldDescriptorProto* sub = - (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto* sub = - (struct google_protobuf_DescriptorProto*)_upb_Message_New(google__protobuf__DescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumDescriptorProto* sub = - (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(google__protobuf__EnumDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto_ExtensionRange* sub = - (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldDescriptorProto* sub = - (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto* msg, google_protobuf_MessageOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_MessageOptions*)_upb_Message_New(google__protobuf__MessageOptions_msg_init(), arena); - if (sub) google_protobuf_DescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_OneofDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_OneofDescriptorProto* sub = - (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(google__protobuf__OneofDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range( - google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_DescriptorProto_ReservedRange* sub = - (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(google__protobuf__DescriptorProto__ReservedRange_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_DescriptorProto_set_visibility(google_protobuf_DescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 11); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.DescriptorProto.ExtensionRange */ -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), arena); -} -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const google_protobuf_ExtensionRangeOptions* default_val = NULL; - const google_protobuf_ExtensionRangeOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange* msg, google_protobuf_ExtensionRangeOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options( - google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { - struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_Message_New(google__protobuf__ExtensionRangeOptions_msg_init(), arena); - if (sub) google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.DescriptorProto.ReservedRange */ -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(google__protobuf__DescriptorProto__ReservedRange_msg_init(), arena); -} -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ReservedRange_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ReservedRange_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ReservedRange_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ReservedRange_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.ExtensionRangeOptions */ -UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_new(upb_Arena* arena) { - return (google_protobuf_ExtensionRangeOptions*)_upb_Message_New(google__protobuf__ExtensionRangeOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_upb_array( - const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array( - google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_upb_array( - const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_resize_declaration(google_protobuf_ExtensionRangeOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration( - google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_ExtensionRangeOptions_Declaration* sub = - (struct google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_features(google_protobuf_ExtensionRangeOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_mutable_features( - google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ExtensionRangeOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_ExtensionRangeOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option( - google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.ExtensionRangeOptions.Declaration */ -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_new(upb_Arena* arena) { - return (google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), arena); -} -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize(const google_protobuf_ExtensionRangeOptions_Declaration* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex(const google_protobuf_ExtensionRangeOptions_Declaration* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_type(google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FieldDescriptorProto */ -UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldDescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldDescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldDescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldDescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { - const google_protobuf_FieldOptions* default_val = NULL; - const google_protobuf_FieldOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto* msg, google_protobuf_FieldOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options( - google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions*)_upb_Message_New(google__protobuf__FieldOptions_msg_init(), arena); - if (sub) google_protobuf_FieldDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.OneofDescriptorProto */ -UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_OneofDescriptorProto*)_upb_Message_New(google__protobuf__OneofDescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofDescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofDescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofDescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofDescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { - const google_protobuf_OneofOptions* default_val = NULL; - const google_protobuf_OneofOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto* msg, google_protobuf_OneofOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options( - google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_OneofOptions*)_upb_Message_New(google__protobuf__OneofOptions_msg_init(), arena); - if (sub) google_protobuf_OneofDescriptorProto_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.EnumDescriptorProto */ -UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto*)_upb_Message_New(google__protobuf__EnumDescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumValueDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array( - const google_protobuf_EnumDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array( - google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { - const google_protobuf_EnumOptions* default_val = NULL; - const google_protobuf_EnumOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_upb_array( - const google_protobuf_EnumDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array( - google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_upb_array( - const google_protobuf_EnumDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array( - google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_visibility(google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_visibility(const google_protobuf_EnumDescriptorProto* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_visibility(const google_protobuf_EnumDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumValueDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value( - google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumValueDescriptorProto* sub = - (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(google__protobuf__EnumValueDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto* msg, google_protobuf_EnumOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options( - google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_EnumOptions*)_upb_Message_New(google__protobuf__EnumOptions_msg_init(), arena); - if (sub) google_protobuf_EnumDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range( - google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = - (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_visibility(google_protobuf_EnumDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.EnumDescriptorProto.EnumReservedRange */ -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), arena); -} -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.EnumValueDescriptorProto */ -UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(google__protobuf__EnumValueDescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueDescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueDescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueDescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueDescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { - const google_protobuf_EnumValueOptions* default_val = NULL; - const google_protobuf_EnumValueOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto* msg, google_protobuf_EnumValueOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options( - google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_EnumValueOptions*)_upb_Message_New(google__protobuf__EnumValueOptions_msg_init(), arena); - if (sub) google_protobuf_EnumValueDescriptorProto_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.ServiceDescriptorProto */ -UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_ServiceDescriptorProto*)_upb_Message_New(google__protobuf__ServiceDescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceDescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceDescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceDescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceDescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_MethodDescriptorProto* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_array( - const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array( - google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { - const google_protobuf_ServiceOptions* default_val = NULL; - const google_protobuf_ServiceOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_MethodDescriptorProto**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method( - google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_MethodDescriptorProto* sub = - (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(google__protobuf__MethodDescriptorProto_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto* msg, google_protobuf_ServiceOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options( - google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_ServiceOptions*)_upb_Message_New(google__protobuf__ServiceOptions_msg_init(), arena); - if (sub) google_protobuf_ServiceDescriptorProto_set_options(msg, sub); - } - return sub; -} - -/* google.protobuf.MethodDescriptorProto */ -UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_MethodDescriptorProto*)_upb_Message_New(google__protobuf__MethodDescriptorProto_msg_init(), arena); -} -UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodDescriptorProto_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodDescriptorProto_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodDescriptorProto_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodDescriptorProto_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { - const google_protobuf_MethodOptions* default_val = NULL; - const google_protobuf_MethodOptions* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto* msg, google_protobuf_MethodOptions* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options( - google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); - if (sub == NULL) { - sub = (struct google_protobuf_MethodOptions*)_upb_Message_New(google__protobuf__MethodOptions_msg_init(), arena); - if (sub) google_protobuf_MethodDescriptorProto_set_options(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FileOptions */ -UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Arena* arena) { - return (google_protobuf_FileOptions*)_upb_Message_New(google__protobuf__FileOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { - int32_t default_val = 1; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { - bool default_val = true; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array( - const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features( - google_protobuf_FileOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FileOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_FileOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option( - google_protobuf_FileOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.MessageOptions */ -UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(upb_Arena* arena) { - return (google_protobuf_MessageOptions*)_upb_Message_New(google__protobuf__MessageOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MessageOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MessageOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MessageOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MessageOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_upb_array( - const google_protobuf_MessageOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MessageOptions_set_features(google_protobuf_MessageOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mutable_features( - google_protobuf_MessageOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MessageOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_MessageOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option( - google_protobuf_MessageOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.FieldOptions */ -UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions*)_upb_Message_New(google__protobuf__FieldOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array( - const google_protobuf_FieldOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array( - google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FieldOptions_EditionDefault* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_array( - const google_protobuf_FieldOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array( - google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_feature_support(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 22); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_feature_support(const google_protobuf_FieldOptions* msg) { - const google_protobuf_FieldOptions_FeatureSupport* default_val = NULL; - const google_protobuf_FieldOptions_FeatureSupport* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 22); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_has_feature_support(const google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 22); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_upb_array( - const google_protobuf_FieldOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_unverified_lazy(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_debug_redact(google_protobuf_FieldOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_set_retention(google_protobuf_FieldOptions* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf_FieldOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_FieldOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FieldOptions_EditionDefault**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_resize_edition_defaults(google_protobuf_FieldOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FieldOptions_EditionDefault* sub = - (struct google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(google__protobuf__FieldOptions__EditionDefault_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutable_features( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FieldOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_FieldOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FieldOptions_set_feature_support(google_protobuf_FieldOptions* msg, google_protobuf_FieldOptions_FeatureSupport* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 22); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_mutable_feature_support( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - struct google_protobuf_FieldOptions_FeatureSupport* sub = (struct google_protobuf_FieldOptions_FeatureSupport*)google_protobuf_FieldOptions_feature_support(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions_FeatureSupport*)_upb_Message_New(google__protobuf__FieldOptions__FeatureSupport_msg_init(), arena); - if (sub) google_protobuf_FieldOptions_set_feature_support(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option( - google_protobuf_FieldOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.FieldOptions.EditionDefault */ -UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(google__protobuf__FieldOptions__EditionDefault_msg_init(), arena); -} -UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions__EditionDefault_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions__EditionDefault_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize(const google_protobuf_FieldOptions_EditionDefault* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions__EditionDefault_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const google_protobuf_FieldOptions_EditionDefault* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions__EditionDefault_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_edition(google_protobuf_FieldOptions_EditionDefault* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FieldOptions.FeatureSupport */ -UPB_INLINE google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_FeatureSupport_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions_FeatureSupport*)_upb_Message_New(google__protobuf__FieldOptions__FeatureSupport_msg_init(), arena); -} -UPB_INLINE google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_FeatureSupport_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FieldOptions_FeatureSupport* ret = google_protobuf_FieldOptions_FeatureSupport_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions__FeatureSupport_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FieldOptions_FeatureSupport* google_protobuf_FieldOptions_FeatureSupport_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FieldOptions_FeatureSupport* ret = google_protobuf_FieldOptions_FeatureSupport_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions__FeatureSupport_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FieldOptions_FeatureSupport_serialize(const google_protobuf_FieldOptions_FeatureSupport* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions__FeatureSupport_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FieldOptions_FeatureSupport_serialize_ex(const google_protobuf_FieldOptions_FeatureSupport* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions__FeatureSupport_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_edition_introduced(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_FeatureSupport_edition_introduced(const google_protobuf_FieldOptions_FeatureSupport* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_edition_introduced(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_edition_deprecated(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_FeatureSupport_edition_deprecated(const google_protobuf_FieldOptions_FeatureSupport* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_edition_deprecated(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_deprecation_warning(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldOptions_FeatureSupport_deprecation_warning(const google_protobuf_FieldOptions_FeatureSupport* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_deprecation_warning(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_edition_removed(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FieldOptions_FeatureSupport_edition_removed(const google_protobuf_FieldOptions_FeatureSupport* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_edition_removed(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_clear_removal_error(google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_FieldOptions_FeatureSupport_removal_error(const google_protobuf_FieldOptions_FeatureSupport* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FieldOptions_FeatureSupport_has_removal_error(const google_protobuf_FieldOptions_FeatureSupport* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_edition_introduced(google_protobuf_FieldOptions_FeatureSupport* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_edition_deprecated(google_protobuf_FieldOptions_FeatureSupport* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_deprecation_warning(google_protobuf_FieldOptions_FeatureSupport* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_edition_removed(google_protobuf_FieldOptions_FeatureSupport* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FieldOptions_FeatureSupport_set_removal_error(google_protobuf_FieldOptions_FeatureSupport* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__FeatureSupport_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.OneofOptions */ -UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Arena* arena) { - return (google_protobuf_OneofOptions*)_upb_Message_New(google__protobuf__OneofOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_upb_array( - const google_protobuf_OneofOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutable_features( - google_protobuf_OneofOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_OneofOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_OneofOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option( - google_protobuf_OneofOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.EnumOptions */ -UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumOptions*)_upb_Message_New(google__protobuf__EnumOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_upb_array( - const google_protobuf_EnumOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumOptions_set_features(google_protobuf_EnumOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutable_features( - google_protobuf_EnumOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_EnumOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option( - google_protobuf_EnumOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.EnumValueOptions */ -UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumValueOptions*)_upb_Message_New(google__protobuf__EnumValueOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_feature_support(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FieldOptions_FeatureSupport* google_protobuf_EnumValueOptions_feature_support(const google_protobuf_EnumValueOptions* msg) { - const google_protobuf_FieldOptions_FeatureSupport* default_val = NULL; - const google_protobuf_FieldOptions_FeatureSupport* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_EnumValueOptions_has_feature_support(const google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_upb_array( - const google_protobuf_EnumValueOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueOptions_set_features(google_protobuf_EnumValueOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_mutable_features( - google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumValueOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_EnumValueOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_EnumValueOptions_set_debug_redact(google_protobuf_EnumValueOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_EnumValueOptions_set_feature_support(google_protobuf_EnumValueOptions* msg, google_protobuf_FieldOptions_FeatureSupport* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FieldOptions_FeatureSupport* google_protobuf_EnumValueOptions_mutable_feature_support( - google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - struct google_protobuf_FieldOptions_FeatureSupport* sub = (struct google_protobuf_FieldOptions_FeatureSupport*)google_protobuf_EnumValueOptions_feature_support(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions_FeatureSupport*)_upb_Message_New(google__protobuf__FieldOptions__FeatureSupport_msg_init(), arena); - if (sub) google_protobuf_EnumValueOptions_set_feature_support(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option( - google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.ServiceOptions */ -UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(upb_Arena* arena) { - return (google_protobuf_ServiceOptions*)_upb_Message_New(google__protobuf__ServiceOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_upb_array( - const google_protobuf_ServiceOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_ServiceOptions_set_features(google_protobuf_ServiceOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mutable_features( - google_protobuf_ServiceOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ServiceOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_ServiceOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option( - google_protobuf_ServiceOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.MethodOptions */ -UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_Arena* arena) { - return (google_protobuf_MethodOptions*)_upb_Message_New(google__protobuf__MethodOptions_msg_init(), arena); -} -UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodOptions_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodOptions_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodOptions_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodOptions_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_upb_array( - const google_protobuf_MethodOptions* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array( - google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_MethodOptions_set_features(google_protobuf_MethodOptions* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_mutable_features( - google_protobuf_MethodOptions* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MethodOptions_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_MethodOptions_set_features(msg, sub); - } - return sub; -} -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option( - google_protobuf_MethodOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption* sub = - (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.UninterpretedOption */ -UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); -} -UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_UninterpretedOption_NamePart* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array( - const google_protobuf_UninterpretedOption* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array( - google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - uint64_t default_val = (uint64_t)0ull; - uint64_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - int64_t default_val = (int64_t)0ll; - int64_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { - double default_val = 0; - double ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_UninterpretedOption_NamePart**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name( - google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_UninterpretedOption_NamePart* sub = - (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(google__protobuf__UninterpretedOption__NamePart_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption* msg, uint64_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption* msg, int64_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption* msg, double value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.UninterpretedOption.NamePart */ -UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(google__protobuf__UninterpretedOption__NamePart_msg_init(), arena); -} -UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption__NamePart_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption__NamePart_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption__NamePart_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption__NamePart_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart* msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FeatureSet */ -UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_new(upb_Arena* arena) { - return (google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); -} -UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSet_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSet_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSet_serialize(const google_protobuf_FeatureSet* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSet_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_FeatureSet* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSet_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_enforce_naming_style(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 7); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_enforce_naming_style(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 7); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_enforce_naming_style(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 7); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSet_clear_default_symbol_visibility(google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 8); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSet_default_symbol_visibility(const google_protobuf_FeatureSet* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 8); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSet_has_default_symbol_visibility(const google_protobuf_FeatureSet* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 8); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_enum_type(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_repeated_field_encoding(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_utf8_validation(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_message_encoding(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_json_format(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_enforce_naming_style(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 7); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSet_set_default_symbol_visibility(google_protobuf_FeatureSet* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 8); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FeatureSet.VisibilityFeature */ -UPB_INLINE google_protobuf_FeatureSet_VisibilityFeature* google_protobuf_FeatureSet_VisibilityFeature_new(upb_Arena* arena) { - return (google_protobuf_FeatureSet_VisibilityFeature*)_upb_Message_New(google__protobuf__FeatureSet__VisibilityFeature_msg_init(), arena); -} -UPB_INLINE google_protobuf_FeatureSet_VisibilityFeature* google_protobuf_FeatureSet_VisibilityFeature_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSet_VisibilityFeature* ret = google_protobuf_FeatureSet_VisibilityFeature_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSet__VisibilityFeature_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSet_VisibilityFeature* google_protobuf_FeatureSet_VisibilityFeature_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSet_VisibilityFeature* ret = google_protobuf_FeatureSet_VisibilityFeature_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSet__VisibilityFeature_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSet_VisibilityFeature_serialize(const google_protobuf_FeatureSet_VisibilityFeature* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSet__VisibilityFeature_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSet_VisibilityFeature_serialize_ex(const google_protobuf_FeatureSet_VisibilityFeature* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSet__VisibilityFeature_msg_init(), options, arena, &ptr, len); - return ptr; -} - - -/* google.protobuf.FeatureSetDefaults */ -UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_new(upb_Arena* arena) { - return (google_protobuf_FeatureSetDefaults*)_upb_Message_New(google__protobuf__FeatureSetDefaults_msg_init(), arena); -} -UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize(const google_protobuf_FeatureSetDefaults* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_protobuf_FeatureSetDefaults* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_array( - const google_protobuf_FeatureSetDefaults* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array( - google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_resize_defaults(google_protobuf_FeatureSetDefaults* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults( - google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* sub = - (struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_set_maximum_edition(google_protobuf_FeatureSetDefaults* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault */ -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(upb_Arena* arena) { - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), arena); -} -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize_ex(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_overridable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_overridable_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_overridable_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_fixed_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fixed_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const google_protobuf_FeatureSet* default_val = NULL; - const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_fixed_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_overridable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_overridable_features( - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_overridable_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_overridable_features(msg, sub); - } - return sub; -} -UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_fixed_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_fixed_features( - google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { - struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_fixed_features(msg); - if (sub == NULL) { - sub = (struct google_protobuf_FeatureSet*)_upb_Message_New(google__protobuf__FeatureSet_msg_init(), arena); - if (sub) google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_fixed_features(msg, sub); - } - return sub; -} - -/* google.protobuf.SourceCodeInfo */ -UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo*)_upb_Message_New(google__protobuf__SourceCodeInfo_msg_init(), arena); -} -UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_SourceCodeInfo_Location* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array( - const google_protobuf_SourceCodeInfo* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array( - google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_SourceCodeInfo_Location**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location( - google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_SourceCodeInfo_Location* sub = - (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(google__protobuf__SourceCodeInfo__Location_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.SourceCodeInfo.Location */ -UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(google__protobuf__SourceCodeInfo__Location_msg_init(), arena); -} -UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo__Location_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo__Location_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo__Location_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo__Location_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_array( - const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array( - google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_array( - const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array( - google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_upb_array( - const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array( - google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (upb_StringView*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} - -/* google.protobuf.GeneratedCodeInfo */ -UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo*)_upb_Message_New(google__protobuf__GeneratedCodeInfo_msg_init(), arena); -} -UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_array( - const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array( - google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation( - google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return NULL; - } - struct google_protobuf_GeneratedCodeInfo_Annotation* sub = - (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), arena); - if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); - return sub; -} - -/* google.protobuf.GeneratedCodeInfo.Annotation */ -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), arena); -} -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, - upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), NULL, 0, - arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse_ex( - const char* buf, size_t size, const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - if (!ret) return NULL; - if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), extreg, - options, arena) != kUpb_DecodeStatus_Ok) { - return NULL; - } - return ret; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, - upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 0, arena, &ptr, len); - return ptr; -} -UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, - int options, upb_Arena* arena, - size_t* len) { - char* ptr; - (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), options, arena, &ptr, len); - return ptr; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, - size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t const*)upb_Array_DataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -// -UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_upb_array( - const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} - -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array( - google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), - &field, arena); - if (size) { - *size = arr ? arr->UPB_PRIVATE(size) : 0; - } - return arr; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - upb_StringView default_val = upb_StringView_FromString(""); - upb_StringView ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - int32_t default_val = (int32_t)0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - int32_t default_val = 0; - int32_t ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); -} - -UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, - size_t* size) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); - if (arr) { - if (size) *size = arr->UPB_PRIVATE(size); - return (int32_t*)upb_Array_MutableDataPtr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, - size_t size, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - return (int32_t*)upb_Message_ResizeArrayUninitialized( - UPB_UPCAST(msg), &field, size, arena); -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, - upb_Arena* arena) { - upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); - if (!arr || !UPB_PRIVATE(_upb_Array_ResizeUninitialized)( - arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - UPB_PRIVATE(_upb_Array_Set) - (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); - return true; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_StringView value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - upb_Message_SetBaseField((upb_Message*)msg, &field, &value); -} - -/* Max size 32 is google.protobuf.FileOptions */ -/* Max size 64 is google.protobuf.FileOptions */ -#define _UPB_MAXOPT_SIZE UPB_SIZE(112, 200) -#ifdef __cplusplus - } /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_ */ diff --git a/vendor/upb/test/BUILD b/vendor/upb/test/BUILD deleted file mode 100644 index 7fa33f6..0000000 --- a/vendor/upb/test/BUILD +++ /dev/null @@ -1,441 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//bazel:proto_library.bzl", "proto_library") -load( - "//upb/bazel:copts.bzl", - "UPB_DEFAULT_CPPOPTS", - "UPB_DEFAULT_FEATURES", -) -load( - "//upb/bazel:upb_minitable_proto_library.bzl", - "upb_minitable_proto_library", -) -load( - "//upb/bazel:upb_proto_library.bzl", - "upb_c_proto_library", - "upb_proto_reflection_library", -) - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "parse_text_proto", - testonly = 1, - hdrs = ["parse_text_proto.h"], - visibility = ["//upb:__subpackages__"], - deps = [ - "//src/google/protobuf", - "@googletest//:gtest", - ], -) - -proto_library( - name = "empty_proto", - srcs = ["empty.proto"], -) - -upb_proto_reflection_library( - name = "empty_upb_proto_reflection", - testonly = 1, - deps = [":empty_proto"], -) - -proto_library( - name = "proto3_test_proto", - testonly = 1, - srcs = ["proto3_test.proto"], - deps = ["//:descriptor_proto"], -) - -upb_c_proto_library( - name = "proto3_test_upb_proto", - testonly = 1, - deps = [":proto3_test_proto"], -) - -upb_proto_reflection_library( - name = "proto3_test_upb_proto_reflection", - testonly = 1, - deps = [":proto3_test_proto"], -) - -proto_library( - name = "test_proto", - testonly = 1, - srcs = ["test.proto"], - visibility = ["//visibility:private"], -) - -upb_minitable_proto_library( - name = "test_proto_upb_minitable", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = [":test_proto"], -) - -upb_c_proto_library( - name = "test_upb_proto", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = [":test_proto"], -) - -proto_library( - name = "editions_test_proto", - testonly = 1, - srcs = ["editions_test.proto"], - option_deps = [ - ":custom_options_proto", - ":custom_options_unlinked_proto", - ], - deps = ["//:descriptor_proto"], -) - -upb_c_proto_library( - name = "editions_test_upb_c_proto", - testonly = 1, - deps = [":editions_test_proto"], -) - -upb_minitable_proto_library( - name = "editions_test_upb_minitable_proto", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = [":editions_test_proto"], -) - -upb_proto_reflection_library( - name = "editions_test_upb_proto_reflection", - testonly = 1, - deps = [":editions_test_proto"], -) - -proto_library( - name = "test_multiple_files_proto", - testonly = 1, - srcs = [ - "test_multiple_files.proto", - "test_multiple_files2.proto", - ], -) - -upb_c_proto_library( - name = "test_multiple_files_upb_c_proto", - testonly = 1, - deps = [":test_multiple_files_proto"], -) - -upb_minitable_proto_library( - name = "test_multiple_files_upb_minitable_proto", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = [":test_multiple_files_proto"], -) - -proto_library( - name = "test_cpp_proto", - srcs = ["test_cpp.proto"], - deps = ["//:timestamp_proto"], -) - -upb_c_proto_library( - name = "test_cpp_upb_proto", - deps = ["test_cpp_proto"], -) - -upb_proto_reflection_library( - name = "test_cpp_upb_proto_reflection", - deps = ["test_cpp_proto"], -) - -upb_minitable_proto_library( - name = "test_messages_proto2_upb_minitable", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = ["//src/google/protobuf:test_messages_proto2_proto"], -) - -upb_minitable_proto_library( - name = "test_messages_proto3_upb_minitable", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], -) - -upb_c_proto_library( - name = "test_messages_proto2_upb_proto", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = ["//src/google/protobuf:test_messages_proto2_proto"], -) - -upb_c_proto_library( - name = "test_messages_proto3_upb_proto", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], -) - -upb_c_proto_library( - name = "timestamp_upb_proto", - deps = ["//:timestamp_proto"], -) - -upb_proto_reflection_library( - name = "timestamp_upb_proto_reflection", - deps = ["//:timestamp_proto"], -) - -cc_library( - name = "fuzz_util", - testonly = 1, - srcs = ["fuzz_util.cc"], - hdrs = ["fuzz_util.h"], - visibility = ["//upb:__subpackages__"], - deps = [ - "//upb/base", - "//upb/mem", - "//upb/mini_descriptor", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - ], -) - -cc_test( - name = "proto3_test", - srcs = ["proto3_test.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":proto3_test_upb_proto", - ":proto3_test_upb_proto_reflection", - "//upb/reflection", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "editions_test", - srcs = ["editions_test.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":custom_options_upb_c_proto", - ":editions_test_upb_c_proto", - ":editions_test_upb_proto_reflection", - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/mini_table", - "//upb/port", - "//upb/reflection", - "//upb/reflection:descriptor_upb_proto", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "length_prefixed_test", - srcs = ["length_prefixed_test.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":test_messages_proto2_upb_minitable", - ":test_messages_proto2_upb_proto", - "//upb/base", - "//upb/mem", - "//upb/mem:internal", - "//upb/message", - "//upb/message:compare", - "//upb/mini_table", - "//upb/wire", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "test_cpp", - srcs = ["test_cpp.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":test_cpp_upb_proto", - ":test_cpp_upb_proto_reflection", - ":timestamp_upb_proto", - ":timestamp_upb_proto_reflection", - "//upb/base", - "//upb/json", - "//upb/port", - "//upb/reflection", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "test_generated_code", - srcs = [ - "test_generated_code.cc", - ], - deps = [ - ":empty_upb_proto_reflection", - ":test_messages_proto2_upb_proto", - ":test_messages_proto3_upb_proto", - ":test_upb_proto", - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/port", - "//upb/wire", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_test( - name = "test_mini_table_oneof", - srcs = [ - "test_mini_table_oneof.cc", - ], - deps = [ - ":empty_upb_proto_reflection", - ":proto3_test_upb_proto", - ":test_messages_proto2_upb_minitable", - ":test_upb_proto", - "//upb/mini_table", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -proto_library( - name = "empty_srcs_proto", - testonly = 1, - srcs = [], - deps = [":test_proto"], -) - -proto_library( - name = "empty_srcs_2_proto", - testonly = 1, - srcs = [], - deps = [":test_cpp_proto"], -) - -proto_library( - name = "empty_srcs_3_proto", - testonly = 1, - srcs = [], - deps = [ - ":empty_srcs_2_proto", - ":empty_srcs_proto", - ], -) - -proto_library( - name = "test_import_empty_srcs_proto", - testonly = 1, - srcs = ["test_import_empty_srcs.proto"], - deps = [":empty_srcs_3_proto"], -) - -proto_library( - name = "custom_options_unlinked_proto", - testonly = 1, - srcs = ["custom_options_unlinked.proto"], - deps = ["//:descriptor_proto"], -) - -proto_library( - name = "custom_options_proto", - testonly = 1, - srcs = ["custom_options.proto"], - deps = ["//:descriptor_proto"], -) - -upb_c_proto_library( - name = "custom_options_upb_c_proto", - testonly = 1, - deps = [":custom_options_proto"], -) - -upb_minitable_proto_library( - name = "custom_options_upb_minitable_proto", - testonly = 1, - visibility = ["//upb:__subpackages__"], - deps = [":custom_options_proto"], -) - -upb_proto_reflection_library( - name = "custom_options_upb_proto_reflection", - testonly = 1, - deps = [":custom_options_proto"], -) - -upb_minitable_proto_library( - name = "test_import_empty_srcs_upb_minitable_proto", - testonly = 1, - deps = [":test_import_empty_srcs_proto"], -) - -upb_c_proto_library( - name = "test_import_empty_srcs_upb_proto", - testonly = 1, - deps = [":test_import_empty_srcs_proto"], -) - -cc_test( - name = "test_import_empty_srcs", - srcs = ["test_import_empty_srcs.cc"], - deps = [ - ":test_import_empty_srcs_upb_minitable_proto", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - "**/test_*.cc", - ], - ), - visibility = ["//upb:__pkg__"], -) - -filegroup( - name = "test_util", - testonly = 1, - srcs = [ - "fuzz_util.cc", - "fuzz_util.h", - "parse_text_proto.h", - ], - visibility = ["//upb:__pkg__"], -) - -filegroup( - name = "test_protos", - srcs = glob( - [ - "**/*.proto", - ], - exclude = [ - "custom_options_unlinked.proto", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/test/custom_options.proto b/vendor/upb/test/custom_options.proto deleted file mode 100644 index ec752ed..0000000 --- a/vendor/upb/test/custom_options.proto +++ /dev/null @@ -1,9 +0,0 @@ -edition = "2024"; - -package upb; - -import "google/protobuf/descriptor.proto"; - -extend google.protobuf.MessageOptions { - int32 message_opt = 7739036; -} diff --git a/vendor/upb/test/custom_options_unlinked.proto b/vendor/upb/test/custom_options_unlinked.proto deleted file mode 100644 index 1d0a13e..0000000 --- a/vendor/upb/test/custom_options_unlinked.proto +++ /dev/null @@ -1,9 +0,0 @@ -edition = "2024"; - -package upb; - -import "google/protobuf/descriptor.proto"; - -extend google.protobuf.MessageOptions { - int32 message_opt_unlinked = 7739037; -} diff --git a/vendor/upb/test/editions_test.cc b/vendor/upb/test/editions_test.cc deleted file mode 100644 index 371ebbf..0000000 --- a/vendor/upb/test/editions_test.cc +++ /dev/null @@ -1,102 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include - -#include - -#include -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.hpp" -#include "upb/message/message.h" -#include "upb/port/def.inc" -#include "upb/reflection/def.hpp" -#include "upb/reflection/descriptor_bootstrap.h" -#include "upb/test/custom_options.upb.h" -#include "upb/test/editions_test.upb.h" -#include "upb/test/editions_test.upbdefs.h" - -TEST(EditionsTest, PlainField) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - upb::FieldDefPtr f(md.FindFieldByName("plain_field")); - EXPECT_TRUE(f.has_presence()); -} - -TEST(EditionsTest, ImplicitPresenceField) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - upb::FieldDefPtr f(md.FindFieldByName("implicit_presence_field")); - EXPECT_FALSE(f.has_presence()); -} - -TEST(EditionsTest, DelimitedField) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - upb::FieldDefPtr f(md.FindFieldByName("delimited_field")); - EXPECT_EQ(kUpb_FieldType_Group, f.type()); -} - -TEST(EditionsTest, RequiredField) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - upb::FieldDefPtr f(md.FindFieldByName("required_field")); - EXPECT_EQ(kUpb_Label_Required, f.label()); -} - -TEST(EditionsTest, ClosedEnum) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - upb::FieldDefPtr f(md.FindFieldByName("enum_field")); - ASSERT_TRUE(f.enum_subdef().is_closed()); -} - -TEST(EditionsTest, PackedField) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - upb::FieldDefPtr f(md.FindFieldByName("unpacked_field")); - ASSERT_FALSE(f.packed()); -} - -TEST(EditionsTest, ImportOptionUnlinked) { - // Test that unlinked option dependencies show up in unknown fields. These - // are optional dependencies that may or may not be present in the binary. - - upb::Arena arena; - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - const google_protobuf_MessageOptions* options = md.options(); - - upb_StringView data; - uintptr_t iter = kUpb_Message_UnknownBegin; - ASSERT_TRUE(upb_Message_NextUnknown(UPB_UPCAST(options), &data, &iter)); - EXPECT_EQ(std::string(data.data, data.size), - // 7739037: 9 - "\xE8\xE9\xC2\x1D\011"); - EXPECT_FALSE(upb_Message_NextUnknown(UPB_UPCAST(options), &data, &iter)); -} - -TEST(EditionsTest, ImportOptionLinked) { - // Test that linked option dependencies don't show up in unknown fields. This - // also actually *uses* the linked options to guarantee linkage and make the - // previous test pass. - - upb::Arena arena; - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); - const google_protobuf_MessageOptions* options = md.options(); - EXPECT_EQ(upb_message_opt(options), 87); -} - -TEST(EditionsTest, ConstructProto) { - // Doesn't do anything except construct the proto. This just verifies that - // the generated code compiles successfully. - upb::Arena arena; - upb_test_2023_EditionsMessage_new(arena.ptr()); -} diff --git a/vendor/upb/test/editions_test.proto b/vendor/upb/test/editions_test.proto deleted file mode 100644 index e233b3c..0000000 --- a/vendor/upb/test/editions_test.proto +++ /dev/null @@ -1,42 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -edition = "2024"; - -package upb.test_2023; - -import "google/protobuf/descriptor.proto"; - -import option "upb/test/custom_options.proto"; -import option "upb/test/custom_options_unlinked.proto"; - -option features.enforce_naming_style = STYLE_LEGACY; - -message EditionsMessage { - option (upb.message_opt) = 87; - option (upb.message_opt_unlinked) = 9; - - int32 plain_field = 1; - int32 implicit_presence_field = 2 [features.field_presence = IMPLICIT]; - int32 required_field = 3 [features.field_presence = LEGACY_REQUIRED]; - EditionsMessage delimited_field = 4 [features.message_encoding = DELIMITED]; - EditionsEnum enum_field = 5; - repeated int32 unpacked_field = 6 - [features.repeated_field_encoding = EXPANDED]; - - extensions 100 to 199; -} - -enum EditionsEnum { - option features.enum_type = CLOSED; - - ONE = 1; -} - -extend EditionsMessage { - int32 ext = 100; -} diff --git a/vendor/upb/test/empty.proto b/vendor/upb/test/empty.proto deleted file mode 100644 index dc4e3de..0000000 --- a/vendor/upb/test/empty.proto +++ /dev/null @@ -1,10 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package upb_test; diff --git a/vendor/upb/test/fuzz_util.cc b/vendor/upb/test/fuzz_util.cc deleted file mode 100644 index 685fd0f..0000000 --- a/vendor/upb/test/fuzz_util.cc +++ /dev/null @@ -1,180 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/test/fuzz_util.h" - -#include - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/status.hpp" -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" - -// Must be last -#include "upb/port/def.inc" - -namespace upb { -namespace fuzz { - -namespace { - -class Builder { - public: - Builder(const MiniTableFuzzInput& input, upb_Arena* arena) - : input_(&input), arena_(arena) {} - - const upb_MiniTable* Build(upb_ExtensionRegistry** exts) { - BuildMessages(); - BuildEnums(); - BuildExtensions(exts); - if (!LinkMessages()) return nullptr; - return mini_tables_.empty() ? nullptr : mini_tables_.front(); - } - - private: - void BuildMessages(); - void BuildEnums(); - void BuildExtensions(upb_ExtensionRegistry** exts); - bool LinkExtension(upb_MiniTableExtension* ext); - bool LinkMessages(); - - size_t NextLink() { - if (input_->links.empty()) return 0; - if (link_ == input_->links.size()) link_ = 0; - return input_->links[link_++]; - } - - const upb_MiniTable* NextMiniTable() { - return mini_tables_.empty() - ? nullptr - : mini_tables_[NextLink() % mini_tables_.size()]; - } - - const upb_MiniTableEnum* NextEnumTable() { - return enum_tables_.empty() - ? nullptr - : enum_tables_[NextLink() % enum_tables_.size()]; - } - - const MiniTableFuzzInput* input_; - upb_Arena* arena_; - std::vector mini_tables_; - std::vector enum_tables_; - size_t link_ = 0; -}; - -void Builder::BuildMessages() { - upb::Status status; - mini_tables_.reserve(input_->mini_descriptors.size()); - for (const auto& d : input_->mini_descriptors) { - upb_MiniTable* table = - upb_MiniTable_Build(d.data(), d.size(), arena_, status.ptr()); - if (table) mini_tables_.push_back(table); - } -} - -void Builder::BuildEnums() { - upb::Status status; - enum_tables_.reserve(input_->enum_mini_descriptors.size()); - for (const auto& d : input_->enum_mini_descriptors) { - upb_MiniTableEnum* enum_table = - upb_MiniTableEnum_Build(d.data(), d.size(), arena_, status.ptr()); - if (enum_table) enum_tables_.push_back(enum_table); - } -} - -bool Builder::LinkExtension(upb_MiniTableExtension* ext) { - upb_MiniTableField* field = &ext->UPB_PRIVATE(field); - if (upb_MiniTableField_CType(field) == kUpb_CType_Message) { - auto mt = NextMiniTable(); - if (!mt) field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_Int32; - ext->UPB_PRIVATE(sub) = upb_MiniTableSub_FromMessage(mt); - } - if (upb_MiniTableField_IsClosedEnum(field)) { - auto et = NextEnumTable(); - if (!et) field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_Int32; - ext->UPB_PRIVATE(sub) = upb_MiniTableSub_FromEnum(et); - } - return true; -} - -void Builder::BuildExtensions(upb_ExtensionRegistry** exts) { - upb::Status status; - if (input_->extensions.empty()) { - *exts = nullptr; - } else { - *exts = upb_ExtensionRegistry_New(arena_); - const char* ptr = input_->extensions.data(); - const char* end = ptr + input_->extensions.size(); - // Iterate through the buffer, building extensions as long as we can. - while (ptr < end) { - upb_MiniTableExtension* ext = reinterpret_cast( - upb_Arena_Malloc(arena_, sizeof(*ext))); - upb_MiniTableSub sub; - const upb_MiniTable* extendee = NextMiniTable(); - if (!extendee) break; - ptr = upb_MiniTableExtension_Init(ptr, end - ptr, ext, extendee, sub, - status.ptr()); - if (!ptr) break; - if (!LinkExtension(ext)) continue; - if (upb_ExtensionRegistry_Lookup(*exts, ext->UPB_PRIVATE(extendee), - upb_MiniTableExtension_Number(ext))) - continue; - upb_ExtensionRegistry_AddArray( - *exts, const_cast(&ext), 1); - } - } -} - -bool Builder::LinkMessages() { - for (auto* t : mini_tables_) { - upb_MiniTable* table = const_cast(t); - // For each field that requires a sub-table, assign one as appropriate. - for (size_t i = 0; i < table->UPB_PRIVATE(field_count); i++) { - upb_MiniTableField* field = - const_cast(&table->UPB_PRIVATE(fields)[i]); - if (link_ == input_->links.size()) link_ = 0; - if (upb_MiniTableField_CType(field) == kUpb_CType_Message && - !upb_MiniTable_SetSubMessage(table, field, NextMiniTable())) { - return false; - } - if (upb_MiniTableField_IsClosedEnum(field)) { - auto* et = NextEnumTable(); - if (et) { - if (!upb_MiniTable_SetSubEnum(table, field, et)) return false; - } else { - // We don't have any sub-enums. Override the field type so that it is - // not needed. - field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_Int32; - field->UPB_PRIVATE(submsg_ofs) = kUpb_NoSub; - } - } - } - } - return true; -} - -} // namespace - -const upb_MiniTable* BuildMiniTable(const MiniTableFuzzInput& input, - upb_ExtensionRegistry** exts, - upb_Arena* arena) { - Builder builder(input, arena); - return builder.Build(exts); -} - -} // namespace fuzz -} // namespace upb diff --git a/vendor/upb/test/fuzz_util.h b/vendor/upb/test/fuzz_util.h deleted file mode 100644 index 40b06ce..0000000 --- a/vendor/upb/test/fuzz_util.h +++ /dev/null @@ -1,62 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_TEST_FUZZ_UTIL_H_ -#define UPB_TEST_FUZZ_UTIL_H_ - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/message.h" - -namespace upb { -namespace fuzz { - -struct MiniTableFuzzInput { - // MiniDescriptors for N messages, in the format accepted by - // upb_MiniTable_Build(). - std::vector mini_descriptors; - - // MiniDescriptors for N enums, in the format accepted by - // upb_MiniTableEnum_Build(). - std::vector enum_mini_descriptors; - - // A MiniDescriptor for N extensions, in the format accepted by - // upb_MiniTableExtension_Build(). - std::string extensions; - - // Integer indexes into the message or enum mini tables lists. These specify - // which message or enum to use for each sub-message or enum field. We mod - // by the total number of enums or messages so that any link value can be - // valid. - std::vector links; -}; - -// Builds an arbitrary mini table corresponding to the random data in `input`. -// This function should be capable of producing any mini table that can -// successfully build, and any topology of messages and enums (including -// cycles). -// -// As currently written, it effectively fuzzes the mini descriptor parser also, -// and can therefore trigger any bugs in that parser. To better isolate these -// two, we may want to change this implementation to use the mini descriptor -// builder API so we are producing mini descriptors in a known good format. That -// would mostly eliminate the chance of crashing the mini descriptor parser -// itself. -// -// TODO: maps. If we give maps some space in the regular encoding instead of -// using a separate function, we could get that for free. -const upb_MiniTable* BuildMiniTable(const MiniTableFuzzInput& input, - upb_ExtensionRegistry** exts, - upb_Arena* arena); - -} // namespace fuzz -} // namespace upb - -#endif // UPB_TEST_FUZZ_UTIL_H_ diff --git a/vendor/upb/test/length_prefixed_test.cc b/vendor/upb/test/length_prefixed_test.cc deleted file mode 100644 index 0ea1f11..0000000 --- a/vendor/upb/test/length_prefixed_test.cc +++ /dev/null @@ -1,86 +0,0 @@ - -#include -#include -#include -#include - -#include -#include "google/protobuf/test_messages_proto2.upb.h" -#include "google/protobuf/test_messages_proto2.upb_minitable.h" -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/message/compare.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" - -namespace { - -static const upb_MiniTable* kTestMiniTable = - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init; - -static void TestEncodeDecodeRoundTrip( - upb_Arena* arena, - std::vector msgs) { - // Encode all of the messages and put their serializations contiguously. - std::string s; - for (auto msg : msgs) { - char* buf; - size_t size; - ASSERT_TRUE(upb_EncodeLengthPrefixed(UPB_UPCAST(msg), kTestMiniTable, 0, - arena, &buf, - &size) == kUpb_EncodeStatus_Ok); - ASSERT_GT(size, 0); // Even empty messages are 1 byte in this encoding. - s.append(std::string(buf, size)); - } - - // Now decode all of the messages contained in the contiguous block. - std::vector decoded; - while (!s.empty()) { - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - size_t num_bytes_read; - ASSERT_TRUE(upb_DecodeLengthPrefixed( - s.data(), s.length(), UPB_UPCAST(msg), &num_bytes_read, - kTestMiniTable, nullptr, 0, arena) == kUpb_DecodeStatus_Ok); - ASSERT_GT(num_bytes_read, 0); - decoded.push_back(msg); - s = s.substr(num_bytes_read); - } - - // Make sure that the values round tripped correctly. - ASSERT_EQ(msgs.size(), decoded.size()); - for (size_t i = 0; i < msgs.size(); ++i) { - ASSERT_TRUE(upb_Message_IsEqual(UPB_UPCAST(msgs[i]), UPB_UPCAST(decoded[i]), - kTestMiniTable, 0)); - } -} - -TEST(LengthPrefixedTest, OneEmptyMessage) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - TestEncodeDecodeRoundTrip(arena, {msg}); - upb_Arena_Free(arena); -} - -TEST(LengthPrefixedTest, AFewMessages) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* a = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - protobuf_test_messages_proto2_TestAllTypesProto2* b = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - protobuf_test_messages_proto2_TestAllTypesProto2* c = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(a, true); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_int32(b, 1); - protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_string( - c, upb_StringView_FromString("string")); - - TestEncodeDecodeRoundTrip(arena, {a, b, c}); - upb_Arena_Free(arena); -} - -} // namespace diff --git a/vendor/upb/test/parse_text_proto.h b/vendor/upb/test/parse_text_proto.h deleted file mode 100644 index e8b3fcb..0000000 --- a/vendor/upb/test/parse_text_proto.h +++ /dev/null @@ -1,44 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_UPB_TEST_PARSE_TEXT_PROTO_H_ -#define UPB_UPB_TEST_PARSE_TEXT_PROTO_H_ - -#include - -#include -#include "google/protobuf/message.h" -#include "google/protobuf/text_format.h" - -namespace upb_test { - -// Replacement for Google ParseTextProtoOrDie. -// Only to be used in unit tests. -// Usage: MyMessage msg = ParseTextProtoOrDie(my_text_proto); -class ParseTextProtoOrDie { - public: - explicit ParseTextProtoOrDie(absl::string_view text_proto) - : text_proto_(text_proto) {} - - template - operator T() { // NOLINT: Needed to support parsing text proto as appropriate - // type. - T message; - if (!google::protobuf::TextFormat::ParseFromString(text_proto_, &message)) { - ADD_FAILURE() << "Failed to parse textproto: " << text_proto_; - abort(); - } - return message; - } - - private: - std::string text_proto_; -}; - -} // namespace upb_test - -#endif // UPB_UPB_TEST_PARSE_TEXT_PROTO_H_ diff --git a/vendor/upb/test/proto3_test.cc b/vendor/upb/test/proto3_test.cc deleted file mode 100644 index d1af699..0000000 --- a/vendor/upb/test/proto3_test.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include "upb/reflection/def.hpp" -#include "upb/test/proto3_test.upb.h" -#include "upb/test/proto3_test.upbdefs.h" - -TEST(Proto3Test, SyntheticOneofExtension) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_TestMessage3_getmsgdef(defpool.ptr())); - ASSERT_EQ(md.field_count(), 6); -} diff --git a/vendor/upb/test/proto3_test.proto b/vendor/upb/test/proto3_test.proto deleted file mode 100644 index 774538f..0000000 --- a/vendor/upb/test/proto3_test.proto +++ /dev/null @@ -1,39 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto3"; - -package upb.test; - -import "google/protobuf/descriptor.proto"; - -extend google.protobuf.MessageOptions { - optional string my_option = 51235; -} - -message MyMessage3 { - option (my_option) = "Hello world!"; -} - -message TestMessage3 { - optional int32 i32 = 1; - repeated int32 r_i32 = 2; - optional string str = 3; - repeated string r_str = 4; - optional TestMessage3 msg = 5; - repeated TestMessage3 r_msg = 6; -} - -// See the InitialFieldOneOf test in test_mini_table_oneof.cc. -message TestOneOfInitialField { - oneof oneof_field { - int32 a = 1; - uint32 b = 2; - } - - float c = 3; -} diff --git a/vendor/upb/test/test.proto b/vendor/upb/test/test.proto deleted file mode 100644 index 25d6c59..0000000 --- a/vendor/upb/test/test.proto +++ /dev/null @@ -1,118 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package upb_test; - -message MapTest { - map map_string_double = 1; -} - -message MessageName { - optional int32 field1 = 1; - optional int32 field2 = 2; -} - -message HelloRequest { - optional uint32 id = 1; - optional uint32 random_name_a0 = 2; - optional uint32 random_name_a1 = 3; - optional uint32 random_name_a2 = 4; - optional uint32 random_name_a3 = 5; - optional uint32 random_name_a4 = 6; - optional uint32 random_name_a5 = 7; - optional uint32 random_name_a6 = 8; - optional uint32 random_name_a7 = 9; - optional uint32 random_name_a8 = 10; - optional uint32 random_name_a9 = 11; - optional uint32 random_name_b0 = 12; - optional uint32 random_name_b1 = 13; - optional uint32 random_name_b2 = 14; - optional uint32 random_name_b3 = 15; - optional uint32 random_name_b4 = 16; - optional uint32 random_name_b5 = 17; - optional uint32 random_name_b6 = 18; - optional uint32 random_name_b7 = 19; - optional uint32 random_name_b8 = 20; - optional uint32 random_name_b9 = 21; - optional uint32 random_name_c0 = 22; - optional uint32 random_name_c1 = 23; - optional uint32 random_name_c2 = 24; - optional uint32 random_name_c3 = 25; - optional uint32 random_name_c4 = 26; - optional uint32 random_name_c5 = 27; - optional uint32 random_name_c6 = 28; - optional uint32 random_name_c7 = 29; - optional uint32 random_name_c8 = 30; - optional uint32 random_name_c9 = 31; - optional string version = 32; -} - -message EmptyMessageWithExtensions { - // Reserved for unknown fields/extensions test. - reserved 1000 to max; -} - -message ModelWithExtensions { - optional int32 random_int32 = 3; - optional string random_name = 4; - repeated int32 repeated_int32 = 5; - // Reserved for unknown fields/extensions test. - extensions 1000 to max; -} - -message ModelExtension1 { - extend ModelWithExtensions { - optional ModelExtension1 model_ext = 1547; - } - optional string str = 25; -} - -message ModelExtension2 { - extend ModelWithExtensions { - optional ModelExtension2 model_ext = 4135; - optional ModelExtension2 model_ext_2 = 4136; - optional ModelExtension2 model_ext_3 = 4137; - optional ModelExtension2 model_ext_4 = 4138; - optional ModelExtension2 model_ext_5 = 4139; - } - optional int32 i = 9; -} - -message ModelWithSubMessages { - optional int32 id = 4; - optional ModelWithExtensions optional_child = 5; - repeated ModelWithExtensions items = 6; -} - -message ModelWithRequiredFields { - required int32 id = 1; -} - -message ModelWithMaps { - optional int32 id = 1; - map map_sb = 2; - map map_ss = 3; - map map_ii = 4; - map map_im = 5; - map map_im_required = 6; -} - -message ExtremeDefaults { - optional int64 int64_min = 1 [default = -9223372036854775808]; -} - -message TestReserved { - optional string new = 1; - optional string parse = 2; - optional string parse_ex = 3; - optional string serialize = 4; - optional string serialize_ex = 5; - optional TestReserved mutable_foo = 6; - optional TestReserved foo = 7; -} diff --git a/vendor/upb/test/test_cpp.cc b/vendor/upb/test/test_cpp.cc deleted file mode 100644 index b7df32a..0000000 --- a/vendor/upb/test/test_cpp.cc +++ /dev/null @@ -1,105 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// Tests for C++ wrappers. - -#include - -#include -#include -#include -#include - -#include "google/protobuf/timestamp.upb.h" -#include "google/protobuf/timestamp.upbdefs.h" -#include -#include "upb/base/upcast.h" -#include "upb/json/decode.h" -#include "upb/json/encode.h" -#include "upb/reflection/def.h" -#include "upb/reflection/def.hpp" -#include "upb/test/test_cpp.upb.h" -#include "upb/test/test_cpp.upbdefs.h" - -// Must be last. -#include "upb/port/def.inc" - -TEST(Cpp, Iteration) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr())); - - // Test range-based for on both fields and oneofs (with the iterator adaptor). - int field_count = 0; - for (auto field : md.fields()) { - UPB_UNUSED(field); - field_count++; - } - EXPECT_EQ(field_count, md.field_count()); - - int oneof_count = 0; - for (auto oneof : md.oneofs()) { - UPB_UNUSED(oneof); - oneof_count++; - } - EXPECT_EQ(oneof_count, md.oneof_count()); -} - -TEST(Cpp, Default) { - upb::DefPool defpool; - upb::Arena arena; - upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr())); - upb_test_TestMessage* msg = upb_test_TestMessage_new(arena.ptr()); - size_t size = upb_JsonEncode(UPB_UPCAST(msg), md.ptr(), nullptr, 0, nullptr, - 0, nullptr); - EXPECT_EQ(2, size); // "{}" -} - -TEST(Cpp, JsonNull) { - upb::DefPool defpool; - upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr())); - upb::FieldDefPtr i32_f = md.FindFieldByName("i32"); - upb::FieldDefPtr str_f = md.FindFieldByName("str"); - ASSERT_TRUE(i32_f); - ASSERT_TRUE(str_f); - EXPECT_EQ(5, i32_f.default_value().int32_val); - EXPECT_EQ(0, strcmp(str_f.default_value().str_val.data, "abc")); - EXPECT_EQ(3, str_f.default_value().str_val.size); -} - -TEST(Cpp, TimestampEncoder) { - upb::DefPool defpool; - upb::Arena arena; - upb::MessageDefPtr md(google_protobuf_Timestamp_getmsgdef(defpool.ptr())); - google_protobuf_Timestamp* timestamp_upb = - google_protobuf_Timestamp_new(arena.ptr()); - google_protobuf_Timestamp* timestamp_upb_decoded = - google_protobuf_Timestamp_new(arena.ptr()); - - int64_t timestamps[] = { - 253402300799, // 9999-12-31T23:59:59Z - 1641006000, // 2022-01-01T03:00:00Z - 0, // 1970-01-01T00:00:00Z - -31525200, // 1969-01-01T03:00:00Z - -2208988800, // 1900-01-01T00:00:00Z - -62135596800, // 0000-01-01T00:00:00Z - }; - - for (int64_t timestamp : timestamps) { - google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp); - - char json[128]; - size_t size = upb_JsonEncode(UPB_UPCAST(timestamp_upb), md.ptr(), nullptr, - 0, json, sizeof(json), nullptr); - bool result = upb_JsonDecode(json, size, UPB_UPCAST(timestamp_upb_decoded), - md.ptr(), nullptr, 0, arena.ptr(), nullptr); - const int64_t timestamp_decoded = - google_protobuf_Timestamp_seconds(timestamp_upb_decoded); - - ASSERT_TRUE(result); - EXPECT_EQ(timestamp, timestamp_decoded); - } -} diff --git a/vendor/upb/test/test_cpp.proto b/vendor/upb/test/test_cpp.proto deleted file mode 100644 index 737c793..0000000 --- a/vendor/upb/test/test_cpp.proto +++ /dev/null @@ -1,19 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package upb.test; - -message TestMessage { - optional int32 i32 = 1 [default = 5]; - repeated int32 r_i32 = 2; - optional string str = 3 [default = "abc"]; - repeated string r_str = 4; - optional TestMessage msg = 5; - repeated TestMessage r_msg = 6; -} diff --git a/vendor/upb/test/test_generated_code.cc b/vendor/upb/test/test_generated_code.cc deleted file mode 100644 index 62a14e6..0000000 --- a/vendor/upb/test/test_generated_code.cc +++ /dev/null @@ -1,1000 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* Test of generated code, with a special focus on features that are not used in - * descriptor.proto or conformance.proto (since these get some testing from - * upb/def.c and tests/conformance_upb.c, respectively). - */ - -#include -#include -#include -#include - -#include -#include "google/protobuf/test_messages_proto2.upb.h" -#include "google/protobuf/test_messages_proto3.upb.h" -#include "upb/base/status.h" -#include "upb/base/string_view.h" -#include "upb/mem/alloc.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/message/array.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/test/test.upb.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -#if !defined(MIN) -#define MIN(x, y) ((x) < (y) ? (x) : (y)) -#endif - -const char test_str[] = "abcdefg"; -const char test_str2[] = "12345678910"; -const char test_str3[] = "rstlnezxcvbnm"; -const char test_str4[] = "just another test string"; - -const upb_StringView test_str_view = {test_str, sizeof(test_str) - 1}; -const upb_StringView test_str_view2 = {test_str2, sizeof(test_str2) - 1}; -const upb_StringView test_str_view3 = {test_str3, sizeof(test_str3) - 1}; -const upb_StringView test_str_view4 = {test_str4, sizeof(test_str4) - 1}; - -const int32_t test_int32 = 10; -const int32_t test_int32_2 = -20; -const int32_t test_int32_3 = 30; -const int32_t test_int32_4 = -40; - -TEST(GeneratedCode, ScalarsProto3) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto3_TestAllTypesProto3* msg = - protobuf_test_messages_proto3_TestAllTypesProto3_new(arena); - protobuf_test_messages_proto3_TestAllTypesProto3* msg2; - upb_StringView serialized; - upb_StringView val; - - // Test serialization. - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_int32(msg, 10); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_int64(msg, 20); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_uint32(msg, 30); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_uint64(msg, 40); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_float(msg, - 50.5); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_double(msg, - 60.6); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_bool(msg, true); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_string( - msg, test_str_view); - - serialized.data = protobuf_test_messages_proto3_TestAllTypesProto3_serialize( - msg, arena, &serialized.size); - - msg2 = protobuf_test_messages_proto3_TestAllTypesProto3_parse( - serialized.data, serialized.size, arena); - - EXPECT_EQ(10, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int32( - msg2)); - EXPECT_EQ(20, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64( - msg2)); - EXPECT_EQ( - 30, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint32(msg2)); - EXPECT_EQ( - 40, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg2)); - EXPECT_EQ( - 50.5, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_float(msg2)); - EXPECT_EQ( - 60.6, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_double(msg2)); - EXPECT_EQ( - true, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_bool(msg2)); - val = protobuf_test_messages_proto3_TestAllTypesProto3_optional_string(msg2); - EXPECT_TRUE(upb_StringView_IsEqual(val, test_str_view)); - - // Test clear. - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_int32(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int32(msg)); - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_int64(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg)); - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_uint32(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint32(msg)); - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_uint64(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg)); - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_float(msg); - EXPECT_EQ( - 0.0f, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_float(msg)); - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_double(msg); - EXPECT_EQ( - 0.0, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_double(msg)); - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_bool(msg); - EXPECT_EQ( - false, - protobuf_test_messages_proto3_TestAllTypesProto3_optional_bool(msg)); - protobuf_test_messages_proto3_TestAllTypesProto3_clear_optional_string(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_string(msg) - .size); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, ScalarsProto2) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - protobuf_test_messages_proto2_TestAllTypesProto2* msg2; - upb_StringView serialized; - - // Test hazzer and serialization. - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int32(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_int32(msg, 10); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int32(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int64(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_int64(msg, 20); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int64(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_uint32( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_uint32(msg, 30); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_uint32( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_uint64( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_uint64(msg, 40); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_uint64( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sint32( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_sint32(msg, 50); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sint32( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sint64( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_sint64(msg, 60); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sint64( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_fixed32( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_fixed32(msg, - 70); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_fixed32( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_fixed64( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_fixed64(msg, - 80); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_fixed64( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sfixed32( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_sfixed32(msg, - 90); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sfixed32( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sfixed64( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_sfixed64(msg, - 100); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_sfixed64( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_float(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_float(msg, - 50.5); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_float(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_double( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_double(msg, - 60.6); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_double( - msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_bool(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(msg, true); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_bool(msg)); - - serialized.data = protobuf_test_messages_proto2_TestAllTypesProto2_serialize( - msg, arena, &serialized.size); - - msg2 = protobuf_test_messages_proto2_TestAllTypesProto2_parse( - serialized.data, serialized.size, arena); - - EXPECT_EQ(10, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32( - msg2)); - EXPECT_EQ(20, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int64( - msg2)); - EXPECT_EQ( - 30, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg2)); - EXPECT_EQ( - 40, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint64(msg2)); - EXPECT_EQ( - 50, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_sint32(msg2)); - EXPECT_EQ( - 60, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_sint64(msg2)); - EXPECT_EQ( - 70, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_fixed32(msg2)); - EXPECT_EQ( - 80, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_fixed64(msg2)); - EXPECT_EQ( - 90, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_sfixed32(msg2)); - EXPECT_EQ( - 100, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_sfixed64(msg2)); - EXPECT_EQ( - 50.5, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_float(msg2)); - EXPECT_EQ( - 60.6, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_double(msg2)); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg2)); - - // Test clear. - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_int32(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int32(msg)); - - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_int64(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int64(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int64(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_uint32(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_uint32( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_uint64(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint64(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_uint64( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_float(msg); - EXPECT_EQ( - 0.0f, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_float(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_float(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_double(msg); - EXPECT_EQ( - 0.0, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_double(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_double( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_bool(msg); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg)); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_bool(msg)); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, RepeatedClear) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - size_t len = 0; - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32(msg, &len); - EXPECT_EQ(0, len); - protobuf_test_messages_proto2_TestAllTypesProto2_add_repeated_int32(msg, 2, - arena); - protobuf_test_messages_proto2_TestAllTypesProto2_add_repeated_int32(msg, 3, - arena); - protobuf_test_messages_proto2_TestAllTypesProto2_add_repeated_int32(msg, 4, - arena); - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32(msg, &len); - EXPECT_EQ(3, len); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_repeated_int32(msg); - protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32(msg, &len); - EXPECT_EQ(0, len); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, Clear) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - // Test clear. - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_int32(msg, 1); - EXPECT_TRUE( - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int32(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_int32(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); - EXPECT_FALSE( - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_int32(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_int64(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int64(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_uint32(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_uint64(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint64(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_float(msg); - EXPECT_EQ( - 0.0f, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_float(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_double(msg); - EXPECT_EQ( - 0.0, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_double(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_bool(msg); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_string(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) - .size); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, Bytes) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - protobuf_test_messages_proto2_TestAllTypesProto2* msg2; - upb_StringView serialized; - const char data[] = "ABCDEF"; - upb_StringView bytes = upb_StringView_FromString(data); - upb_StringView val; - - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_bytes(msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bytes(msg, - bytes); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_bytes(msg)); - - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( - msg)); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( - msg, test_str_view); - EXPECT_EQ( - true, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( - msg)); - - serialized.data = protobuf_test_messages_proto2_TestAllTypesProto2_serialize( - msg, arena, &serialized.size); - - msg2 = protobuf_test_messages_proto2_TestAllTypesProto2_parse( - serialized.data, serialized.size, arena); - - EXPECT_EQ(bytes.size, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_bytes(msg) - .size); - EXPECT_EQ( - 0, memcmp(bytes.data, - protobuf_test_messages_proto2_TestAllTypesProto2_optional_bytes( - msg) - .data, - bytes.size)); - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_bytes(msg); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_bytes(msg)); - - val = protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg2); - EXPECT_TRUE(upb_StringView_IsEqual(val, test_str_view)); - - protobuf_test_messages_proto2_TestAllTypesProto2_clear_optional_string(msg); - EXPECT_EQ( - 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) - .size); - EXPECT_EQ( - false, - protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( - msg)); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, UTF8) { - const char invalid_utf8[] = "\xff"; - const upb_StringView invalid_utf8_view = - upb_StringView_FromDataAndSize(invalid_utf8, 1); - upb_Arena* arena = upb_Arena_New(); - upb_StringView serialized; - protobuf_test_messages_proto3_TestAllTypesProto3* msg = - protobuf_test_messages_proto3_TestAllTypesProto3_new(arena); - protobuf_test_messages_proto3_TestAllTypesProto3* msg2; - - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_string( - msg, invalid_utf8_view); - - serialized.data = protobuf_test_messages_proto3_TestAllTypesProto3_serialize( - msg, arena, &serialized.size); - - msg2 = protobuf_test_messages_proto3_TestAllTypesProto3_parse( - serialized.data, serialized.size, arena); - EXPECT_EQ(nullptr, msg2); - - upb_Arena_Free(arena); -} - -static void check_string_map_empty( - protobuf_test_messages_proto3_TestAllTypesProto3* msg) { - size_t iter = kUpb_Map_Begin; - - EXPECT_EQ( - 0, - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_size( - msg)); - - upb_StringView key; - upb_StringView val; - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_next( - msg, &key, &val, &iter)); -} - -static void check_string_map_one_entry( - protobuf_test_messages_proto3_TestAllTypesProto3* msg) { - size_t iter; - upb_StringView str; - - EXPECT_EQ( - 1, - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_size( - msg)); - EXPECT_TRUE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_get( - msg, test_str_view, &str)); - EXPECT_TRUE(upb_StringView_IsEqual(str, test_str_view2)); - - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_get( - msg, test_str_view3, &str)); - - /* Test that iteration reveals a single k/v pair in the map. */ - iter = kUpb_Map_Begin; - upb_StringView key; - upb_StringView val; - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_next( - msg, &key, &val, &iter); - EXPECT_TRUE(upb_StringView_IsEqual(test_str_view, key)); - EXPECT_TRUE(upb_StringView_IsEqual(test_str_view2, val)); - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_next( - msg, &key, &val, &iter)); -} - -TEST(GeneratedCode, StringDoubleMap) { - upb_Arena* arena = upb_Arena_New(); - upb_StringView serialized; - upb_test_MapTest* msg = upb_test_MapTest_new(arena); - upb_test_MapTest* msg2; - double val; - - upb_test_MapTest_map_string_double_set(msg, test_str_view, 1.5, arena); - ASSERT_NE(nullptr, msg); - EXPECT_TRUE(upb_test_MapTest_map_string_double_get(msg, test_str_view, &val)); - EXPECT_EQ(1.5, val); - val = 0; - - serialized.data = upb_test_MapTest_serialize(msg, arena, &serialized.size); - EXPECT_NE(nullptr, serialized.data); - - msg2 = upb_test_MapTest_parse(serialized.data, serialized.size, arena); - ASSERT_NE(nullptr, msg2); - EXPECT_TRUE( - upb_test_MapTest_map_string_double_get(msg2, test_str_view, &val)); - EXPECT_EQ(1.5, val); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, StringMap) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto3_TestAllTypesProto3* msg = - protobuf_test_messages_proto3_TestAllTypesProto3_new(arena); - size_t iter, count; - - check_string_map_empty(msg); - - /* Set map[test_str_view] = test_str_view2 */ - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_set( - msg, test_str_view, test_str_view2, arena); - check_string_map_one_entry(msg); - - /* Deleting a non-existent key does nothing. */ - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_delete( - msg, test_str_view3)); - check_string_map_one_entry(msg); - - /* Deleting the key sets the map back to empty. */ - EXPECT_TRUE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_delete( - msg, test_str_view)); - check_string_map_empty(msg); - - /* Set two keys this time: - * map[test_str_view] = test_str_view2 - * map[test_str_view3] = test_str_view4 - */ - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_set( - msg, test_str_view, test_str_view2, arena); - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_set( - msg, test_str_view3, test_str_view4, arena); - - /* Test iteration */ - iter = kUpb_Map_Begin; - count = 0; - upb_StringView key; - upb_StringView val; - while ( - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_next( - msg, &key, &val, &iter)) { - count++; - if (upb_StringView_IsEqual(key, test_str_view)) { - EXPECT_TRUE(upb_StringView_IsEqual(val, test_str_view2)); - } else { - EXPECT_TRUE(upb_StringView_IsEqual(key, test_str_view3)); - EXPECT_TRUE(upb_StringView_IsEqual(val, test_str_view4)); - } - } - - EXPECT_EQ(2, count); - - /* Clearing the map goes back to empty. */ - protobuf_test_messages_proto3_TestAllTypesProto3_map_string_string_clear(msg); - check_string_map_empty(msg); - - upb_Arena_Free(arena); -} - -static void check_int32_map_empty( - protobuf_test_messages_proto3_TestAllTypesProto3* msg) { - size_t iter = kUpb_Map_Begin; - - EXPECT_EQ( - 0, protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_size( - msg)); - - int32_t key; - int32_t val; - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_next( - msg, &key, &val, &iter)); -} - -static void check_int32_map_one_entry( - protobuf_test_messages_proto3_TestAllTypesProto3* msg) { - size_t iter; - int32_t key; - int32_t val; - - EXPECT_EQ( - 1, protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_size( - msg)); - EXPECT_TRUE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get( - msg, test_int32, &val)); - EXPECT_EQ(val, test_int32_2); - - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get( - msg, test_int32_3, &val)); - - /* Test that iteration reveals a single k/v pair in the map. */ - iter = kUpb_Map_Begin; - EXPECT_TRUE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_next( - msg, &key, &val, &iter)); - EXPECT_EQ(test_int32, key); - EXPECT_EQ(test_int32_2, val); - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_next( - msg, &key, &val, &iter)); -} - -TEST(GeneratedCode, Int32Map) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto3_TestAllTypesProto3* msg = - protobuf_test_messages_proto3_TestAllTypesProto3_new(arena); - size_t iter, count; - - check_int32_map_empty(msg); - - EXPECT_EQ( - _protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_upb_map( - msg), - nullptr); - - upb_Map* mut_map = - _protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_mutable_upb_map( - msg, arena); - EXPECT_NE(mut_map, nullptr); - - const upb_Map* const_map = - _protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_upb_map( - msg); - EXPECT_EQ(mut_map, const_map); - - /* Set map[test_int32] = test_int32_2 */ - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_set( - msg, test_int32, test_int32_2, arena); - check_int32_map_one_entry(msg); - - /* Deleting a non-existent key does nothing. */ - EXPECT_FALSE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_delete( - msg, test_int32_3)); - check_int32_map_one_entry(msg); - - /* Deleting the key sets the map back to empty. */ - EXPECT_TRUE( - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_delete( - msg, test_int32)); - check_int32_map_empty(msg); - - /* Set two keys this time: - * map[test_int32] = test_int32_2 - * map[test_int32_3] = test_int32_4 - */ - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_set( - msg, test_int32, test_int32_2, arena); - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_set( - msg, test_int32_3, test_int32_4, arena); - - /* Test iteration */ - iter = kUpb_Map_Begin; - count = 0; - int32_t key; - int32_t val; - while (protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_next( - msg, &key, &val, &iter)) { - count++; - if (key == test_int32) { - EXPECT_EQ(val, test_int32_2); - } else { - EXPECT_EQ(key, test_int32_3); - EXPECT_EQ(val, test_int32_4); - } - } - - EXPECT_EQ(2, count); - - /* Clearing the map goes back to empty. */ - protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_clear(msg); - check_int32_map_empty(msg); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, TestRepeated) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto3_TestAllTypesProto3* msg = - protobuf_test_messages_proto3_TestAllTypesProto3_new(arena); - size_t size; - const int* elems; - - EXPECT_EQ( - _protobuf_test_messages_proto3_TestAllTypesProto3_repeated_int32_upb_array( - msg, &size), - nullptr); - - protobuf_test_messages_proto3_TestAllTypesProto3_add_repeated_int32(msg, 5, - arena); - - EXPECT_NE( - _protobuf_test_messages_proto3_TestAllTypesProto3_repeated_int32_upb_array( - msg, &size), - nullptr); - - elems = protobuf_test_messages_proto3_TestAllTypesProto3_repeated_int32( - msg, &size); - - EXPECT_EQ(size, 1); - EXPECT_EQ(elems[0], 5); - - const upb_Array* arr = - _protobuf_test_messages_proto3_TestAllTypesProto3_repeated_int32_upb_array( - msg, &size); - EXPECT_EQ(size, 1); - upb_Array* mutable_arr = - _protobuf_test_messages_proto3_TestAllTypesProto3_repeated_int32_mutable_upb_array( - msg, &size, arena); - EXPECT_EQ(mutable_arr, arr); - EXPECT_EQ(upb_Array_Size(arr), 1); - EXPECT_EQ(size, 1); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, Issue9440) { - upb::Arena arena; - upb_test_HelloRequest* msg = upb_test_HelloRequest_new(arena.ptr()); - upb_test_HelloRequest_set_id(msg, 8); - EXPECT_EQ(8, upb_test_HelloRequest_id(msg)); - char str[] = "1"; - upb_test_HelloRequest_set_version(msg, upb_StringView{str, strlen(str)}); - EXPECT_EQ(8, upb_test_HelloRequest_id(msg)); -} - -TEST(GeneratedCode, NullDecodeBuffer) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto3_TestAllTypesProto3* msg = - protobuf_test_messages_proto3_TestAllTypesProto3_parse(nullptr, 0, arena); - size_t size; - - ASSERT_NE(nullptr, msg); - protobuf_test_messages_proto3_TestAllTypesProto3_serialize(msg, arena, &size); - EXPECT_EQ(0, size); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, StatusTruncation) { - int i, j; - upb_Status status; - upb_Status status2; - for (i = 0; i < _kUpb_Status_MaxMessage + 20; i++) { - char* msg = static_cast(malloc(i + 1)); - int end; - char ch = (i % 96) + 33; /* Cycle through printable chars. */ - - for (j = 0; j < i; j++) { - msg[j] = ch; - } - msg[i] = '\0'; - - upb_Status_SetErrorMessage(&status, msg); - upb_Status_SetErrorFormat(&status2, "%s", msg); - end = MIN(i, _kUpb_Status_MaxMessage - 1); - EXPECT_EQ(end, strlen(status.msg)); - EXPECT_EQ(end, strlen(status2.msg)); - - for (j = 0; j < end; j++) { - EXPECT_EQ(ch, status.msg[j]); - EXPECT_EQ(ch, status2.msg[j]); - } - - free(msg); - } -} - -TEST(GeneratedCode, ArenaUnaligned) { - char buf1[1024]; - // Force the pointer to be unaligned. - uintptr_t low_bits = UPB_MALLOC_ALIGN - 1; - char* unaligned_buf_ptr = (char*)((uintptr_t)buf1 | low_bits); - upb_Arena* arena = upb_Arena_Init( - unaligned_buf_ptr, &buf1[sizeof(buf1)] - unaligned_buf_ptr, nullptr); - char* mem = static_cast(upb_Arena_Malloc(arena, 5)); - EXPECT_EQ(0, reinterpret_cast(mem) & low_bits); - upb_Arena_Free(arena); - - // Try the same, but with a size so small that aligning up will overflow. - arena = upb_Arena_Init(unaligned_buf_ptr, 5, &upb_alloc_global); - mem = static_cast(upb_Arena_Malloc(arena, 5)); - EXPECT_EQ(0, reinterpret_cast(mem) & low_bits); - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, Extensions) { - upb::Arena arena; - upb_test_ModelExtension1* extension1 = - upb_test_ModelExtension1_new(arena.ptr()); - upb_test_ModelExtension1_set_str(extension1, - upb_StringView_FromString("Hello")); - - upb_test_ModelExtension2* extension2 = - upb_test_ModelExtension2_new(arena.ptr()); - upb_test_ModelExtension2_set_i(extension2, 5); - - upb_test_ModelWithExtensions* msg1 = - upb_test_ModelWithExtensions_new(arena.ptr()); - upb_test_ModelWithExtensions* msg2 = - upb_test_ModelWithExtensions_new(arena.ptr()); - - // msg1: [extension1, extension2] - upb_test_ModelExtension1_set_model_ext(msg1, extension1, arena.ptr()); - upb_test_ModelExtension2_set_model_ext(msg1, extension2, arena.ptr()); - - // msg2: [extension2, extension1] - upb_test_ModelExtension2_set_model_ext(msg2, extension2, arena.ptr()); - upb_test_ModelExtension1_set_model_ext(msg2, extension1, arena.ptr()); - - size_t size1, size2; - int opts = kUpb_EncodeOption_Deterministic; - char* pb1 = upb_test_ModelWithExtensions_serialize_ex(msg1, opts, arena.ptr(), - &size1); - char* pb2 = upb_test_ModelWithExtensions_serialize_ex(msg2, opts, arena.ptr(), - &size2); - - ASSERT_EQ(size1, size2); - ASSERT_EQ(0, memcmp(pb1, pb2, size1)); -} - -TEST(GeneratedCode, Maps) { - upb::Arena arena; - upb_test_ModelWithMaps* msg = upb_test_ModelWithMaps_new(arena.ptr()); - - auto sb = _upb_test_ModelWithMaps_map_sb_mutable_upb_map(msg, arena.ptr()); - auto ss = _upb_test_ModelWithMaps_map_ss_mutable_upb_map(msg, arena.ptr()); - auto ii = _upb_test_ModelWithMaps_map_ii_mutable_upb_map(msg, arena.ptr()); - - ASSERT_NE(sb, nullptr); - ASSERT_NE(ss, nullptr); - ASSERT_NE(ii, nullptr); - - upb_MessageValue key, val; - key.str_val = test_str_view; - val.str_val = test_str_view2; - - upb_Map_Set(sb, key, val, arena.ptr()); -} - -TEST(GeneratedCode, MapWithRequiredFields) { - upb::Arena arena; - upb_test_ModelWithMaps* msg = upb_test_ModelWithMaps_new(arena.ptr()); - - auto im_required = - _upb_test_ModelWithMaps_map_im_required_mutable_upb_map(msg, arena.ptr()); - - ASSERT_NE(im_required, nullptr); - - upb_MessageValue key, val; - key.int32_val = 0; - val.msg_val = - (const upb_Message*)upb_test_ModelWithRequiredFields_new(arena.ptr()); - - upb_Map_Set(im_required, key, val, arena.ptr()); - - // Serializing fails if we are checking required fields, but succeeds if we - // don't. - size_t size; - char* serialized = upb_test_ModelWithMaps_serialize_ex( - msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); - ASSERT_EQ(serialized, nullptr); - - serialized = upb_test_ModelWithMaps_serialize_ex(msg, 0, arena.ptr(), &size); - ASSERT_NE(serialized, nullptr); - - // Likewise, parsing fails if we are checking required fields, but succeeds - // if we don't. - upb_test_ModelWithMaps* msg2 = upb_test_ModelWithMaps_parse_ex( - serialized, size, nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr()); - ASSERT_EQ(msg2, nullptr); - - msg2 = upb_test_ModelWithMaps_parse_ex(serialized, size, nullptr, 0, - arena.ptr()); - ASSERT_NE(msg2, nullptr); -} - -TEST(GeneratedCode, ReservedNames) { - upb_Arena* arena = upb_Arena_New(); - upb_test_TestReserved* msg = upb_test_TestReserved_new(arena); - - // Check that we can call the mangled accessors. - // If they weren't mangled, this would fail to compile because of - // collisions with the message-level functions. - upb_StringView val = upb_StringView_FromString("test"); - upb_test_TestReserved_set_new_(msg, val); - upb_test_TestReserved_set_parse_(msg, val); - upb_test_TestReserved_set_parse_ex_(msg, val); - upb_test_TestReserved_set_serialize_(msg, val); - upb_test_TestReserved_set_serialize_ex_(msg, val); - - EXPECT_TRUE(upb_StringView_IsEqual(val, upb_test_TestReserved_new_(msg))); - EXPECT_TRUE(upb_StringView_IsEqual(val, upb_test_TestReserved_parse_(msg))); - EXPECT_TRUE( - upb_StringView_IsEqual(val, upb_test_TestReserved_parse_ex_(msg))); - EXPECT_TRUE( - upb_StringView_IsEqual(val, upb_test_TestReserved_serialize_(msg))); - EXPECT_TRUE( - upb_StringView_IsEqual(val, upb_test_TestReserved_serialize_ex_(msg))); - - upb_Arena_Free(arena); -} - -TEST(GeneratedCode, MutablePrefix) { - upb_Arena* arena = upb_Arena_New(); - upb_test_TestReserved* msg = upb_test_TestReserved_new(arena); - - // mutable_foo should be mangled to mutable_foo_ because foo exists. - upb_test_TestReserved* sub = upb_test_TestReserved_new(arena); - upb_test_TestReserved_set_mutable_foo_(msg, sub); - - EXPECT_EQ(sub, upb_test_TestReserved_mutable_foo_(msg)); - - // The actual "mutable" accessor for field "foo" should still be available. - upb_test_TestReserved* mutable_foo = - upb_test_TestReserved_mutable_foo(msg, arena); - EXPECT_NE(nullptr, mutable_foo); - - upb_Arena_Free(arena); -} diff --git a/vendor/upb/test/test_import_empty_srcs.cc b/vendor/upb/test/test_import_empty_srcs.cc deleted file mode 100644 index 59995ae..0000000 --- a/vendor/upb/test/test_import_empty_srcs.cc +++ /dev/null @@ -1,14 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include "upb/test/test_import_empty_srcs.upb_minitable.h" - -TEST(Test, Reexport) { - // This test really just ensures that compilation succeeds. - ASSERT_GT(sizeof(upb_0test__ContainsImported_msg_init), 0); -} diff --git a/vendor/upb/test/test_import_empty_srcs.proto b/vendor/upb/test/test_import_empty_srcs.proto deleted file mode 100644 index eca7d93..0000000 --- a/vendor/upb/test/test_import_empty_srcs.proto +++ /dev/null @@ -1,18 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package upb_test; - -import "upb/test/test.proto"; -import "upb/test/test_cpp.proto"; - -message ContainsImported { - optional MessageName message_name = 1; - optional upb.test.TestMessage test_message = 2; -} diff --git a/vendor/upb/test/test_mini_table_oneof.cc b/vendor/upb/test/test_mini_table_oneof.cc deleted file mode 100644 index 5d31fe3..0000000 --- a/vendor/upb/test/test_mini_table_oneof.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include "google/protobuf/test_messages_proto2.upb_minitable.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/test/proto3_test.upb.h" - -TEST(MiniTableOneofTest, OneOfIteratorProto2) { - constexpr int oneof_first_field_number = 111; - constexpr int oneof_test_field_number = 116; - - const upb_MiniTable* google_protobuf_table = - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init; - const upb_MiniTableField* field = - upb_MiniTable_FindFieldByNumber(google_protobuf_table, oneof_test_field_number); - ASSERT_TRUE(field != nullptr); - const upb_MiniTableField* ptr = upb_MiniTable_GetOneof(google_protobuf_table, field); - int field_num = oneof_first_field_number; - do { - EXPECT_EQ(upb_MiniTableField_Number(ptr), field_num++); - } while (upb_MiniTable_NextOneofField(google_protobuf_table, &ptr)); -} - -TEST(MiniTableOneofTest, InitialFieldOneOf) { - const upb_MiniTable* table = &upb__test__TestOneOfInitialField_msg_init; - const upb_MiniTableField* field = upb_MiniTable_FindFieldByNumber(table, 1); - ASSERT_TRUE(field != nullptr); - - const upb_MiniTableField* ptr = upb_MiniTable_GetOneof(table, field); - EXPECT_TRUE(ptr == field); -} - -TEST(MiniTableOneofTest, InitialFieldNotOneOf) { - constexpr int test_field_number = 1; // optional int that is not a oneof - const upb_MiniTable* google_protobuf_table = - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init; - const upb_MiniTableField* field = - upb_MiniTable_FindFieldByNumber(google_protobuf_table, test_field_number); - ASSERT_TRUE(field != nullptr); - const upb_MiniTableField* first_field = - upb_MiniTable_GetOneof(google_protobuf_table, field); - EXPECT_EQ(first_field, nullptr); -} diff --git a/vendor/upb/test/test_multiple_files.proto b/vendor/upb/test/test_multiple_files.proto deleted file mode 100644 index 425814c..0000000 --- a/vendor/upb/test/test_multiple_files.proto +++ /dev/null @@ -1,24 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// This test is meant to handle the case where two .proto files are build in the -// same proto_library. With dynamic linkage, they will end up in the same -// shared library. - -edition = "2024"; - -package upb; - -message MultipleFilesMessage1 { - int32 field1 = 1; - - extensions 100 to 199; -} - -extend MultipleFilesMessage1 { - int32 multiple_files_ext1 = 100; -} diff --git a/vendor/upb/test/test_multiple_files2.proto b/vendor/upb/test/test_multiple_files2.proto deleted file mode 100644 index 4372880..0000000 --- a/vendor/upb/test/test_multiple_files2.proto +++ /dev/null @@ -1,24 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// This test is meant to handle the case where two .proto files are build in the -// same proto_library. With dynamic linkage, they will end up in the same -// shared library. - -edition = "2024"; - -package upb; - -message MultipleFilesMessage2 { - int32 field1 = 1; - - extensions 100 to 199; -} - -extend MultipleFilesMessage2 { - int32 multiple_files_ext2 = 100; -} diff --git a/vendor/upb/text/BUILD b/vendor/upb/text/BUILD deleted file mode 100644 index be52852..0000000 --- a/vendor/upb/text/BUILD +++ /dev/null @@ -1,125 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "text", - srcs = [ - "encode.c", - ], - hdrs = [ - "encode.h", - "options.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - "//upb/base", - "//upb/hash", - "//upb/lex", - "//upb/message", - "//upb/message:internal", - "//upb/message:types", - "//upb/port", - "//upb/reflection", - "//upb/wire:eps_copy_input_stream", - ], -) - -cc_library( - name = "debug", - srcs = [ - "debug_string.c", - ], - hdrs = [ - "debug_string.h", - "options.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":internal", - "//upb/base", - "//upb/lex", - "//upb/message", - "//upb/message:internal", - "//upb/message:iterator", - "//upb/message:types", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - ], -) - -cc_library( - name = "internal", - srcs = [ - "internal/encode.c", - ], - hdrs = [ - "internal/encode.h", - "options.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - "//third_party/utf8_range", - "//upb/base", - "//upb/lex", - "//upb/message", - "//upb/message:internal", - "//upb/port", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:reader", - ], -) - -cc_test( - name = "encode_debug_test", - srcs = [ - "encode_debug_test.cc", - ], - deps = [ - ":debug", - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/message:internal", - "//upb/mini_table", - "//upb/port", - "//upb/test:test_proto_upb_minitable", - "//upb/test:test_upb_proto", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:reader", - "@abseil-cpp//absl/log:absl_log", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) diff --git a/vendor/upb/text/debug_string.c b/vendor/upb/text/debug_string.c deleted file mode 100644 index 8584f57..0000000 --- a/vendor/upb/text/debug_string.c +++ /dev/null @@ -1,222 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/text/debug_string.h" - -#include -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/message/array.h" -#include "upb/message/internal/iterator.h" -#include "upb/message/internal/map_entry.h" -#include "upb/message/internal/map_sorter.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" -#include "upb/text/internal/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -static void _upb_MessageDebugString(txtenc* e, const upb_Message* msg, - const upb_MiniTable* mt); - -static void _upb_FieldDebugString(txtenc* e, upb_MessageValue val, - const upb_MiniTableField* f, - const upb_MiniTable* mt, const char* label, - const upb_MiniTableExtension* ext) { - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - const upb_CType ctype = upb_MiniTableField_CType(f); - const bool is_ext = upb_MiniTableField_IsExtension(f); - char number[10]; // A 32-bit integer can hold up to 10 digits. - snprintf(number, sizeof(number), "%" PRIu32, upb_MiniTableField_Number(f)); - // label is to pass down whether we're dealing with a "key" of a map or - // a "value" of a map. - if (!label) label = number; - - if (is_ext) { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "[%s]", label); - } else { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%s", label); - } - - if (ctype == kUpb_CType_Message) { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, " {"); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - e->indent_depth++; - const upb_MiniTable* subm = ext ? upb_MiniTableExtension_GetSubMessage(ext) - : upb_MiniTable_SubMessage(f); - _upb_MessageDebugString(e, val.msg_val, subm); - e->indent_depth--; - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "}"); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - return; - } - - UPB_PRIVATE(_upb_TextEncode_Printf)(e, ": "); - - if (ctype == - kUpb_CType_Enum) { // Enum has to be processed separately because of - // divergent behavior between encoders - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%" PRId32, val.int32_val); - } else { - UPB_PRIVATE(_upb_TextEncode_Scalar)(e, val, ctype); - } - - UPB_PRIVATE(_upb_TextEncode_EndField)(e); -} - -/* - * Arrays print as simple repeated elements, eg. - * - * 5: 1 - * 5: 2 - * 5: 3 - */ -static void _upb_ArrayDebugString(txtenc* e, const upb_Array* arr, - const upb_MiniTableField* f, - const upb_MiniTable* mt, - const upb_MiniTableExtension* ext) { - for (size_t i = 0, n = upb_Array_Size(arr); i < n; i++) { - _upb_FieldDebugString(e, upb_Array_Get(arr, i), f, mt, NULL, ext); - } -} - -static void _upb_MapEntryDebugString(txtenc* e, upb_MessageValue key, - upb_MessageValue val, - const upb_MiniTableField* f, - const upb_MiniTable* mt) { - const upb_MiniTable* entry = upb_MiniTable_SubMessage(f); - const upb_MiniTableField* key_f = upb_MiniTable_MapKey(entry); - const upb_MiniTableField* val_f = upb_MiniTable_MapValue(entry); - - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%u {", upb_MiniTableField_Number(f)); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - e->indent_depth++; - - _upb_FieldDebugString(e, key, key_f, entry, "key", NULL); - _upb_FieldDebugString(e, val, val_f, entry, "value", NULL); - - e->indent_depth--; - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "}"); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); -} - -/* - * Maps print as messages of key/value, etc. - * - * 1 { - * key: "abc" - * value: 123 - * } - * 2 { - * key: "def" - * value: 456 - * } - */ -static void _upb_MapDebugString(txtenc* e, const upb_Map* map, - const upb_MiniTableField* f, - const upb_MiniTable* mt) { - if (e->options & UPB_TXTENC_NOSORT) { - size_t iter = kUpb_Map_Begin; - upb_MessageValue key, val; - while (upb_Map_Next(map, &key, &val, &iter)) { - _upb_MapEntryDebugString(e, key, val, f, mt); - } - } else { - if (upb_Map_Size(map) == 0) return; - - const upb_MiniTable* entry = upb_MiniTable_SubMessage(f); - const upb_MiniTableField* key_f = upb_MiniTable_GetFieldByIndex(entry, 0); - _upb_sortedmap sorted; - upb_MapEntry ent; - - _upb_mapsorter_pushmap(&e->sorter, upb_MiniTableField_Type(key_f), map, - &sorted); - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - upb_MessageValue key, val; - memcpy(&key, &ent.k, sizeof(key)); - memcpy(&val, &ent.v, sizeof(val)); - _upb_MapEntryDebugString(e, key, val, f, mt); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } -} - -static void _upb_MessageDebugString(txtenc* e, const upb_Message* msg, - const upb_MiniTable* mt) { - size_t iter = kUpb_BaseField_Begin; - const upb_MiniTableField* f; - upb_MessageValue val; - - // Base fields will be printed out first, followed by extension fields, and - // finally unknown fields. - - while (UPB_PRIVATE(_upb_Message_NextBaseField)(msg, mt, &f, &val, &iter)) { - if (upb_MiniTableField_IsMap(f)) { - _upb_MapDebugString(e, val.map_val, f, mt); - } else if (upb_MiniTableField_IsArray(f)) { - // ext set to NULL as we're not dealing with extensions yet - _upb_ArrayDebugString(e, val.array_val, f, mt, NULL); - } else { - // ext set to NULL as we're not dealing with extensions yet - // label set to NULL as we're not currently working with a MapEntry - _upb_FieldDebugString(e, val, f, mt, NULL, NULL); - } - } - - const upb_MiniTableExtension* ext; - upb_MessageValue val_ext; - iter = kUpb_Message_ExtensionBegin; - while (upb_Message_NextExtension(msg, &ext, &val_ext, &iter)) { - const upb_MiniTableField* f = &ext->UPB_PRIVATE(field); - // It is not sufficient to only pass |f| as we lose valuable information - // about sub-messages. It is required that we pass |ext|. - if (upb_MiniTableField_IsMap(f)) { - UPB_UNREACHABLE(); // Maps cannot be extensions. - break; - } else if (upb_MiniTableField_IsArray(f)) { - _upb_ArrayDebugString(e, val_ext.array_val, f, mt, ext); - } else { - // label set to NULL as we're not currently working with a MapEntry - _upb_FieldDebugString(e, val_ext, f, mt, NULL, ext); - } - } - - UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(e, msg); -} - -size_t upb_DebugString(const upb_Message* msg, const upb_MiniTable* mt, - int options, char* buf, size_t size) { - txtenc e; - - e.buf = buf; - e.ptr = buf; - e.end = UPB_PTRADD(buf, size); - e.overflow = 0; - e.indent_depth = 0; - e.options = options; - e.ext_pool = NULL; - _upb_mapsorter_init(&e.sorter); - - _upb_MessageDebugString(&e, msg, mt); - _upb_mapsorter_destroy(&e.sorter); - return UPB_PRIVATE(_upb_TextEncode_Nullz)(&e, size); -} diff --git a/vendor/upb/text/debug_string.h b/vendor/upb/text/debug_string.h deleted file mode 100644 index 6abd4f0..0000000 --- a/vendor/upb/text/debug_string.h +++ /dev/null @@ -1,42 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_TEXT_ENCODE_DEBUG_H_ -#define UPB_TEXT_ENCODE_DEBUG_H_ - -#include - -#include "upb/message/message.h" -#include "upb/mini_table/message.h" -#include "upb/text/options.h" // IWYU pragma: export - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Encodes the given |msg| to a pseudo-text format: Instead of printing field - * name to value entries, it will print field number to value entries; much like - * how unknown fields are printed in upb_TextEncode in this directory's - * encode.h. |mt| should correspond to the |msg|'s minitable. - * - * Output is placed in the given buffer, and always NULL-terminated. The output - * size (excluding NULL) is returned. This means that a return value >= |size| - * implies that the output was truncated. (These are the same semantics as - * snprintf()). */ -UPB_API size_t upb_DebugString(const upb_Message* msg, const upb_MiniTable* mt, - int options, char* buf, size_t size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_TEXT_ENCODE_DEBUG_H_ */ diff --git a/vendor/upb/text/encode.c b/vendor/upb/text/encode.c deleted file mode 100644 index e8fe8b2..0000000 --- a/vendor/upb/text/encode.c +++ /dev/null @@ -1,215 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/text/encode.h" - -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/lex/round_trip.h" -#include "upb/message/array.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/map_entry.h" -#include "upb/message/internal/map_sorter.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/message/value.h" -#include "upb/reflection/def.h" -#include "upb/reflection/message.h" -#include "upb/text/internal/encode.h" -#include "upb/wire/eps_copy_input_stream.h" - -// Must be last. -#include "upb/port/def.inc" - -static void _upb_TextEncode_Msg(txtenc* e, const upb_Message* msg, - const upb_MessageDef* m); - -static void _upb_TextEncode_Enum(int32_t val, const upb_FieldDef* f, - txtenc* e) { - const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f); - const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e_def, val); - - if (ev) { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%s", upb_EnumValueDef_Name(ev)); - } else { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%" PRId32, val); - } -} - -static void _upb_TextEncode_Field(txtenc* e, upb_MessageValue val, - const upb_FieldDef* f) { - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - const upb_CType ctype = upb_FieldDef_CType(f); - const bool is_ext = upb_FieldDef_IsExtension(f); - const char* full = upb_FieldDef_FullName(f); - const char* name = upb_FieldDef_Name(f); - - if (ctype == kUpb_CType_Message) { - if (is_ext) { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "[%s] {", full); - } else { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%s {", name); - } - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - e->indent_depth++; - _upb_TextEncode_Msg(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - e->indent_depth--; - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "}"); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - return; - } - - if (is_ext) { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "[%s]: ", full); - } else { - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%s: ", name); - } - - if (ctype == kUpb_CType_Enum) { - _upb_TextEncode_Enum(val.int32_val, f, e); - } else { - UPB_PRIVATE(_upb_TextEncode_Scalar)(e, val, ctype); - } - - UPB_PRIVATE(_upb_TextEncode_EndField)(e); -} - -/* - * Arrays print as simple repeated elements, eg. - * - * foo_field: 1 - * foo_field: 2 - * foo_field: 3 - */ -static void _upb_TextEncode_Array(txtenc* e, const upb_Array* arr, - const upb_FieldDef* f) { - size_t i; - size_t size = upb_Array_Size(arr); - - for (i = 0; i < size; i++) { - _upb_TextEncode_Field(e, upb_Array_Get(arr, i), f); - } -} - -static void _upb_TextEncode_MapEntry(txtenc* e, upb_MessageValue key, - upb_MessageValue val, - const upb_FieldDef* f) { - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_Field(entry, 0); - const upb_FieldDef* val_f = upb_MessageDef_Field(entry, 1); - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%s {", upb_FieldDef_Name(f)); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - e->indent_depth++; - - _upb_TextEncode_Field(e, key, key_f); - _upb_TextEncode_Field(e, val, val_f); - - e->indent_depth--; - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "}"); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); -} - -/* - * Maps print as messages of key/value, etc. - * - * foo_map: { - * key: "abc" - * value: 123 - * } - * foo_map: { - * key: "def" - * value: 456 - * } - */ -static void _upb_TextEncode_Map(txtenc* e, const upb_Map* map, - const upb_FieldDef* f) { - if (e->options & UPB_TXTENC_NOSORT) { - size_t iter = kUpb_Map_Begin; - upb_MessageValue key, val; - while (upb_Map_Next(map, &key, &val, &iter)) { - _upb_TextEncode_MapEntry(e, key, val, f); - } - } else { - if (upb_Map_Size(map) == 0) return; - - if (!map->UPB_PRIVATE(is_strtable)) { - // For inttable, first encode the array part, then sort the table entries. - intptr_t iter = UPB_INTTABLE_BEGIN; - while ((size_t)++iter < map->t.inttable.array_size) { - upb_value value = map->t.inttable.array[iter]; - if (upb_inttable_arrhas(&map->t.inttable, iter)) { - upb_MessageValue key, val; - memcpy(&key, &iter, sizeof(iter)); - _upb_map_fromvalue(value, &val, map->val_size); - _upb_TextEncode_MapEntry(e, key, val, f); - } - } - } - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_Field(entry, 0); - _upb_sortedmap sorted; - upb_MapEntry ent; - - _upb_mapsorter_pushmap(&e->sorter, upb_FieldDef_Type(key_f), map, &sorted); - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - upb_MessageValue key, val; - memcpy(&key, &ent.k, sizeof(key)); - memcpy(&val, &ent.v, sizeof(val)); - _upb_TextEncode_MapEntry(e, key, val, f); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } -} - -static void _upb_TextEncode_Msg(txtenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; - - while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) { - if (upb_FieldDef_IsMap(f)) { - _upb_TextEncode_Map(e, val.map_val, f); - } else if (upb_FieldDef_IsRepeated(f)) { - _upb_TextEncode_Array(e, val.array_val, f); - } else { - _upb_TextEncode_Field(e, val, f); - } - } - - UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(e, msg); -} - -size_t upb_TextEncode(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int options, char* buf, - size_t size) { - txtenc e; - - e.buf = buf; - e.ptr = buf; - e.end = UPB_PTRADD(buf, size); - e.overflow = 0; - e.indent_depth = 0; - e.options = options; - e.ext_pool = ext_pool; - _upb_mapsorter_init(&e.sorter); - - _upb_TextEncode_Msg(&e, msg, m); - _upb_mapsorter_destroy(&e.sorter); - return UPB_PRIVATE(_upb_TextEncode_Nullz)(&e, size); -} diff --git a/vendor/upb/text/encode.h b/vendor/upb/text/encode.h deleted file mode 100644 index 7aea54c..0000000 --- a/vendor/upb/text/encode.h +++ /dev/null @@ -1,39 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_TEXT_ENCODE_H_ -#define UPB_TEXT_ENCODE_H_ - -#include "upb/reflection/def.h" -#include "upb/text/options.h" // IWYU pragma: export - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Encodes the given |msg| to text format. The message's reflection is given in - * |m|. The symtab in |symtab| is used to find extensions (if NULL, extensions - * will not be printed). - * - * Output is placed in the given buffer, and always NULL-terminated. The output - * size (excluding NULL) is returned. This means that a return value >= |size| - * implies that the output was truncated. (These are the same semantics as - * snprintf()). */ -size_t upb_TextEncode(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int options, char* buf, - size_t size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_TEXT_ENCODE_H_ */ diff --git a/vendor/upb/text/encode_debug_test.cc b/vendor/upb/text/encode_debug_test.cc deleted file mode 100644 index 20c7def..0000000 --- a/vendor/upb/text/encode_debug_test.cc +++ /dev/null @@ -1,73 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include - -#include - -#include -#include "upb/base/string_view.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" -#include "upb/test/test.upb.h" -#include "upb/test/test.upb_minitable.h" -#include "upb/text/debug_string.h" - -std::string GetDebugString(const upb_Message* input, - const upb_MiniTable* mt_main) { - // Resizing/reallocation of the buffer is not necessary since we're only - // testing that we get the expected debug string. - char buf[100]; - int options = - UPB_TXTENC_NOSORT; // Does not matter, but maps will not be sorted. - size_t real_size = upb_DebugString(input, mt_main, options, buf, 100); - EXPECT_EQ(buf[real_size], '\0'); - return std::string(buf); -} - -TEST(TextNoReflection, ExtensionsString) { - const upb_MiniTable* mt_main = &upb_0test__ModelWithExtensions_msg_init; - upb_Arena* arena = upb_Arena_New(); - - upb_test_ModelExtension1* extension1 = upb_test_ModelExtension1_new(arena); - upb_test_ModelExtension1_set_str(extension1, - upb_StringView_FromString("Hello")); - - upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena); - - upb_test_ModelExtension1_set_model_ext(msg, extension1, arena); - - std::string buf = GetDebugString(UPB_UPCAST(msg), mt_main); - upb_Arena_Free(arena); - std::string golden = R"([1547] { - 25: "Hello" -} -)"; - ASSERT_EQ(buf, golden); -} - -TEST(TextNoReflection, ExtensionsInt) { - const upb_MiniTable* mt_main = &upb_0test__ModelWithExtensions_msg_init; - upb_Arena* arena = upb_Arena_New(); - - upb_test_ModelExtension2* extension2 = upb_test_ModelExtension2_new(arena); - upb_test_ModelExtension2_set_i(extension2, 5); - - upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena); - - upb_test_ModelExtension2_set_model_ext(msg, extension2, arena); - - std::string buf = GetDebugString(UPB_UPCAST(msg), mt_main); - upb_Arena_Free(arena); - std::string golden = R"([4135] { - 9: 5 -} -)"; - ASSERT_EQ(buf, golden); -} diff --git a/vendor/upb/text/internal/encode.c b/vendor/upb/text/internal/encode.c deleted file mode 100644 index ddcf6ba..0000000 --- a/vendor/upb/text/internal/encode.c +++ /dev/null @@ -1,196 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/text/internal/encode.h" - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/lex/round_trip.h" -#include "upb/message/array.h" -#include "upb/message/message.h" -#include "upb/text/options.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/reader.h" -#include "upb/wire/types.h" - -// Must be last. -#include "upb/port/def.inc" - -#define CHK(x) \ - do { \ - if (!(x)) { \ - return NULL; \ - } \ - } while (0) - -/* - * Unknown fields are printed by number. - * - * 1001: 123 - * 1002: "hello" - * 1006: 0xdeadbeef - * 1003: { - * 1: 111 - * } - */ -const char* UPB_PRIVATE(_upb_TextEncode_Unknown)(txtenc* e, const char* ptr, - upb_EpsCopyInputStream* stream, - int groupnum) { - // We are guaranteed that the unknown data is valid wire format, and will not - // contain tag zero. - uint32_t end_group = groupnum > 0 - ? ((groupnum << kUpb_WireReader_WireTypeBits) | - kUpb_WireType_EndGroup) - : 0; - - while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { - uint32_t tag; - CHK(ptr = upb_WireReader_ReadTag(ptr, &tag, stream)); - if (tag == end_group) return ptr; - - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_Printf) - (e, "%d: ", (int)upb_WireReader_GetFieldNumber(tag)); - - switch (upb_WireReader_GetWireType(tag)) { - case kUpb_WireType_Varint: { - uint64_t val; - CHK(ptr = upb_WireReader_ReadVarint(ptr, &val, stream)); - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%" PRIu64, val); - break; - } - case kUpb_WireType_32Bit: { - uint32_t val; - ptr = upb_WireReader_ReadFixed32(ptr, &val, stream); - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "0x%08" PRIu32, val); - break; - } - case kUpb_WireType_64Bit: { - uint64_t val; - ptr = upb_WireReader_ReadFixed64(ptr, &val, stream); - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "0x%016" PRIu64, val); - break; - } - case kUpb_WireType_Delimited: { - int size; - char* start = e->ptr; - size_t start_overflow = e->overflow; - upb_StringView sv; - CHK(ptr = upb_WireReader_ReadSize(ptr, &size, stream)); - CHK(ptr = upb_EpsCopyInputStream_ReadStringAlwaysAlias(stream, ptr, - size, &sv)); - - // Speculatively try to parse as message. - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "{"); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - - // EpsCopyInputStream can't back up, so create a sub-stream for the - // speculative parse. - upb_EpsCopyInputStream sub_stream; - const char* sub_ptr = sv.data; - upb_EpsCopyInputStream_Init(&sub_stream, &sub_ptr, size); - - e->indent_depth++; - if (UPB_PRIVATE(_upb_TextEncode_Unknown)(e, sub_ptr, &sub_stream, -1)) { - e->indent_depth--; - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "}"); - } else { - // Didn't work out, print as raw bytes. - e->indent_depth--; - e->ptr = start; - e->overflow = start_overflow; - UPB_PRIVATE(_upb_TextEncode_Bytes)(e, sv); - } - break; - } - case kUpb_WireType_StartGroup: - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "{"); - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - e->indent_depth++; - CHK(ptr = UPB_PRIVATE(_upb_TextEncode_Unknown)( - e, ptr, stream, upb_WireReader_GetFieldNumber(tag))); - e->indent_depth--; - UPB_PRIVATE(_upb_TextEncode_Indent)(e); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "}"); - break; - default: - return NULL; - } - UPB_PRIVATE(_upb_TextEncode_EndField)(e); - } - - return end_group == 0 && !upb_EpsCopyInputStream_IsError(stream) ? ptr : NULL; -} - -#undef CHK - -void UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(txtenc* e, - const upb_Message* msg) { - if ((e->options & UPB_TXTENC_SKIPUNKNOWN) != 0) return; - - uintptr_t iter = kUpb_Message_UnknownBegin; - upb_StringView view; - while (upb_Message_NextUnknown(msg, &view, &iter)) { - char* start = e->ptr; - upb_EpsCopyInputStream stream; - upb_EpsCopyInputStream_Init(&stream, &view.data, view.size); - if (!UPB_PRIVATE(_upb_TextEncode_Unknown)(e, view.data, &stream, -1)) { - /* Unknown failed to parse, back up and don't print it at all. */ - e->ptr = start; - } - } -} - -void UPB_PRIVATE(_upb_TextEncode_Scalar)(txtenc* e, upb_MessageValue val, - upb_CType ctype) { - switch (ctype) { - case kUpb_CType_Bool: - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, val.bool_val ? "true" : "false"); - break; - case kUpb_CType_Float: { - char buf[32]; - _upb_EncodeRoundTripFloat(val.float_val, buf, sizeof(buf)); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, buf); - break; - } - case kUpb_CType_Double: { - char buf[32]; - _upb_EncodeRoundTripDouble(val.double_val, buf, sizeof(buf)); - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, buf); - break; - } - case kUpb_CType_Int32: - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%" PRId32, val.int32_val); - break; - case kUpb_CType_UInt32: - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%" PRIu32, val.uint32_val); - break; - case kUpb_CType_Int64: - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%" PRId64, val.int64_val); - break; - case kUpb_CType_UInt64: - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "%" PRIu64, val.uint64_val); - break; - case kUpb_CType_String: - UPB_PRIVATE(_upb_HardenedPrintString) - (e, val.str_val.data, val.str_val.size); - break; - case kUpb_CType_Bytes: - UPB_PRIVATE(_upb_TextEncode_Bytes)(e, val.str_val); - break; - case kUpb_CType_Enum: - UPB_ASSERT(false); // handled separately in each encoder - break; - default: - UPB_UNREACHABLE(); - } -} diff --git a/vendor/upb/text/internal/encode.h b/vendor/upb/text/internal/encode.h deleted file mode 100644 index a204d67..0000000 --- a/vendor/upb/text/internal/encode.h +++ /dev/null @@ -1,245 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_TEXT_ENCODE_INTERNAL_H_ -#define UPB_TEXT_ENCODE_INTERNAL_H_ - -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/message/array.h" -#include "upb/message/internal/map_sorter.h" -#include "upb/message/message.h" -#include "upb/port/vsnprintf_compat.h" -#include "upb/text/options.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "utf8_range.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - char *buf, *ptr, *end; - size_t overflow; - int indent_depth; - int options; - const struct upb_DefPool* ext_pool; - _upb_mapsorter sorter; -} txtenc; - -UPB_INLINE void UPB_PRIVATE(_upb_TextEncode_PutBytes)(txtenc* e, - const void* data, - size_t len) { - size_t have = e->end - e->ptr; - if (UPB_LIKELY(have >= len)) { - memcpy(e->ptr, data, len); - e->ptr += len; - } else { - if (have) { - memcpy(e->ptr, data, have); - e->ptr += have; - } - e->overflow += (len - have); - } -} - -UPB_INLINE void UPB_PRIVATE(_upb_TextEncode_PutStr)(txtenc* e, - const char* str) { - UPB_PRIVATE(_upb_TextEncode_PutBytes)(e, str, strlen(str)); -} - -UPB_INLINE void UPB_PRIVATE(_upb_TextEncode_Printf)(txtenc* e, const char* fmt, - ...) { - size_t n; - size_t have = e->end - e->ptr; - va_list args; - - va_start(args, fmt); - n = _upb_vsnprintf(e->ptr, have, fmt, args); - va_end(args); - - if (UPB_LIKELY(have > n)) { - e->ptr += n; - } else { - e->ptr = UPB_PTRADD(e->ptr, have); - e->overflow += (n - have); - } -} - -UPB_INLINE void UPB_PRIVATE(_upb_TextEncode_Indent)(txtenc* e) { - if ((e->options & UPB_TXTENC_SINGLELINE) == 0) { - int i = e->indent_depth; - while (i-- > 0) { - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, " "); - } - } -} - -UPB_INLINE void UPB_PRIVATE(_upb_TextEncode_EndField)(txtenc* e) { - if (e->options & UPB_TXTENC_SINGLELINE) { - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, " "); - } else { - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\n"); - } -} - -UPB_INLINE void UPB_PRIVATE(_upb_TextEncode_Escaped)(txtenc* e, - unsigned char ch) { - switch (ch) { - case '\n': - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\\n"); - break; - case '\r': - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\\r"); - break; - case '\t': - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\\t"); - break; - case '\"': - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\\\""); - break; - case '\'': - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\\'"); - break; - case '\\': - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\\\\"); - break; - default: - UPB_PRIVATE(_upb_TextEncode_Printf)(e, "\\%03o", ch); - break; - } -} - -// Returns true if `ch` needs to be escaped in TextFormat, independent of any -// UTF-8 validity issues. -UPB_INLINE bool UPB_PRIVATE(_upb_DefinitelyNeedsEscape)(unsigned char ch) { - if (ch < 32) return true; - switch (ch) { - case '\"': - case '\'': - case '\\': - case 127: - return true; - } - return false; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_AsciiIsPrint)(unsigned char ch) { - return ch >= 32 && ch < 127; -} - -// Returns true if this is a high byte that requires UTF-8 validation. If the -// UTF-8 validation fails, we must escape the byte. -UPB_INLINE bool UPB_PRIVATE(_upb_NeedsUtf8Validation)(unsigned char ch) { - return ch > 127; -} - -// Returns the number of bytes in the prefix of `val` that do not need escaping. -// This is like utf8_range::SpanStructurallyValid(), except that it also -// terminates at any ASCII char that needs to be escaped in TextFormat (any char -// that has `DefinitelyNeedsEscape(ch) == true`). -// -// If we could get a variant of utf8_range::SpanStructurallyValid() that could -// terminate on any of these chars, that might be more efficient, but it would -// be much more complicated to modify that heavily SIMD code. -UPB_INLINE size_t UPB_PRIVATE(_SkipPassthroughBytes)(const char* ptr, - size_t size) { - for (size_t i = 0; i < size; i++) { - unsigned char uc = ptr[i]; - if (UPB_PRIVATE(_upb_DefinitelyNeedsEscape)(uc)) return i; - if (UPB_PRIVATE(_upb_NeedsUtf8Validation)(uc)) { - // Find the end of this region of consecutive high bytes, so that we only - // give high bytes to the UTF-8 checker. This avoids needing to perform - // a second scan of the ASCII characters looking for characters that - // need escaping. - // - // We assume that high bytes are less frequent than plain, printable ASCII - // bytes, so we accept the double-scan of high bytes. - size_t end = i + 1; - for (; end < size; end++) { - if (!UPB_PRIVATE(_upb_NeedsUtf8Validation)(ptr[end])) break; - } - size_t n = end - i; - size_t ok = utf8_range_ValidPrefix(ptr + i, n); - if (ok != n) return i + ok; - i += ok - 1; - } - } - return size; -} - -UPB_INLINE void UPB_PRIVATE(_upb_HardenedPrintString)(txtenc* e, - const char* ptr, - size_t len) { - // Print as UTF-8, while guarding against any invalid UTF-8 in the string - // field. - // - // If in the future we have a guaranteed invariant that invalid UTF-8 will - // never be present, we could avoid the UTF-8 check here. - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\""); - const char* end = ptr + len; - while (ptr < end) { - size_t n = UPB_PRIVATE(_SkipPassthroughBytes)(ptr, end - ptr); - if (n != 0) { - UPB_PRIVATE(_upb_TextEncode_PutBytes)(e, ptr, n); - ptr += n; - if (ptr == end) break; - } - - // If repeated calls to CEscape() and PrintString() are expensive, we could - // consider batching them, at the cost of some complexity. - UPB_PRIVATE(_upb_TextEncode_Escaped)(e, *ptr); - ptr++; - } - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\""); -} - -UPB_INLINE void UPB_PRIVATE(_upb_TextEncode_Bytes)(txtenc* e, - upb_StringView data) { - const char* ptr = data.data; - const char* end = ptr + data.size; - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\""); - for (; ptr < end; ptr++) { - unsigned char uc = *ptr; - if (UPB_PRIVATE(_upb_AsciiIsPrint)(uc) && - !UPB_PRIVATE(_upb_DefinitelyNeedsEscape)(uc)) { - UPB_PRIVATE(_upb_TextEncode_PutBytes)(e, ptr, 1); - } else { - UPB_PRIVATE(_upb_TextEncode_Escaped)(e, uc); - } - } - UPB_PRIVATE(_upb_TextEncode_PutStr)(e, "\""); -} - -UPB_INLINE size_t UPB_PRIVATE(_upb_TextEncode_Nullz)(txtenc* e, size_t size) { - size_t ret = e->ptr - e->buf + e->overflow; - - if (size > 0) { - if (e->ptr == e->end) e->ptr--; - *e->ptr = '\0'; - } - - return ret; -} - -const char* UPB_PRIVATE(_upb_TextEncode_Unknown)(txtenc* e, const char* ptr, - upb_EpsCopyInputStream* stream, - int groupnum); - -void UPB_PRIVATE(_upb_TextEncode_ParseUnknown)(txtenc* e, - const upb_Message* msg); - -// Must not be called for ctype = kUpb_CType_Enum, as they require different -// handling depending on whether or not we're doing reflection-based encoding. -void UPB_PRIVATE(_upb_TextEncode_Scalar)(txtenc* e, upb_MessageValue val, - upb_CType ctype); - -#include "upb/port/undef.inc" - -#endif // UPB_TEXT_ENCODE_INTERNAL_H_ diff --git a/vendor/upb/text/options.h b/vendor/upb/text/options.h deleted file mode 100644 index dcaa8bd..0000000 --- a/vendor/upb/text/options.h +++ /dev/null @@ -1,22 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_TEXT_OPTIONS_H_ -#define UPB_TEXT_OPTIONS_H_ - -enum { - // When set, prints everything on a single line. - UPB_TXTENC_SINGLELINE = 1, - - // When set, unknown fields are not printed. - UPB_TXTENC_SKIPUNKNOWN = 2, - - // When set, maps are *not* sorted (this avoids allocating tmp mem). - UPB_TXTENC_NOSORT = 4 -}; - -#endif // UPB_TEXT_OPTIONS_H_ diff --git a/vendor/upb/util/BUILD b/vendor/upb/util/BUILD deleted file mode 100644 index 4cfcd84..0000000 --- a/vendor/upb/util/BUILD +++ /dev/null @@ -1,189 +0,0 @@ -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//bazel:proto_library.bzl", "proto_library") -load( - "//upb/bazel:upb_proto_library.bzl", - "upb_c_proto_library", - "upb_proto_reflection_library", -) - -package(default_applicable_licenses = ["//:license"]) - -licenses(["notice"]) - -# Def to Proto - -cc_library( - name = "def_to_proto", - srcs = ["def_to_proto.c"], - hdrs = ["def_to_proto.h"], - visibility = ["//visibility:public"], - deps = [ - "//src/google/protobuf:descriptor_upb_c_proto", - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/port", - "//upb/reflection", - "//upb/reflection:internal", - ], -) - -proto_library( - name = "def_to_proto_test_proto", - srcs = [ - "def_to_proto_public_import_test.proto", - "def_to_proto_regular_import_test.proto", - "def_to_proto_test.proto", - ], -) - -upb_c_proto_library( - name = "def_to_proto_test_upb_proto", - deps = ["def_to_proto_test_proto"], -) - -upb_proto_reflection_library( - name = "def_to_proto_test_upb_proto_reflection", - deps = ["def_to_proto_test_proto"], -) - -cc_library( - name = "def_to_proto_test_lib", - testonly = 1, - hdrs = ["def_to_proto_test.h"], - visibility = ["//upb:__pkg__"], - deps = [ - ":def_to_proto", - "//src/google/protobuf", - "//src/google/protobuf:descriptor_upb_c_proto", - "//src/google/protobuf/util:differencer", - "//upb/base", - "//upb/mem", - "//upb/reflection:internal", - "@googletest//:gtest", - ], -) - -cc_test( - name = "def_to_proto_test", - srcs = ["def_to_proto_test.cc"], - deps = [ - ":def_to_proto", - ":def_to_proto_editions_test_upb_proto", - ":def_to_proto_editions_test_upb_proto_reflection", - ":def_to_proto_test_lib", - ":def_to_proto_test_upb_proto", - ":def_to_proto_test_upb_proto_reflection", - "//src/google/protobuf", - "//src/google/protobuf:descriptor_upb_c_proto", - "//src/google/protobuf:descriptor_upb_reflection_proto", - "//src/google/protobuf/util:differencer", - "//upb/base", - "//upb/mem", - "//upb/reflection", - "//upb/test:parse_text_proto", - "@abseil-cpp//absl/strings", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -# Required fields - -cc_library( - name = "required_fields", - srcs = ["required_fields.c"], - hdrs = ["required_fields.h"], - visibility = ["//visibility:public"], - deps = [ - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/port", - "//upb/reflection", - ], -) - -proto_library( - name = "def_to_proto_editions_test_proto", - srcs = ["def_to_proto_editions_test.proto"], -) - -upb_c_proto_library( - name = "def_to_proto_editions_test_upb_proto", - deps = ["def_to_proto_editions_test_proto"], -) - -upb_proto_reflection_library( - name = "def_to_proto_editions_test_upb_proto_reflection", - deps = ["def_to_proto_editions_test_proto"], -) - -proto_library( - name = "required_fields_test_proto", - srcs = [ - "required_fields_editions_test.proto", - "required_fields_test.proto", - ], -) - -upb_c_proto_library( - name = "required_fields_test_upb_proto", - deps = ["required_fields_test_proto"], -) - -upb_proto_reflection_library( - name = "required_fields_test_upb_proto_reflection", - deps = ["required_fields_test_proto"], -) - -cc_test( - name = "required_fields_test", - srcs = ["required_fields_test.cc"], - deps = [ - ":required_fields", - ":required_fields_test_upb_proto", - ":required_fields_test_upb_proto_reflection", - "//upb/base", - "//upb/json", - "//upb/mem", - "//upb/reflection", - "//upb/reflection:internal", - "@abseil-cpp//absl/strings", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = [ - "def_to_proto.c", - "def_to_proto.h", - "required_fields.c", - "required_fields.h", - ], - visibility = ["//python/dist:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - exclude = ["def_to_proto_fuzz_test.cc"], - ), - visibility = ["//upb:__pkg__"], -) - -filegroup( - name = "test_protos", - srcs = glob( - [ - "**/*test.proto", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/util/README.md b/vendor/upb/util/README.md deleted file mode 100644 index efcdacb..0000000 --- a/vendor/upb/util/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# upb util library - -The libraries in this directory contain useful functionality that is layered -on top of the main upb APIs. In other words, the APIs in this directory have -no special access to upb internals; you could easily implement the same things -yourself. diff --git a/vendor/upb/util/def_to_proto.c b/vendor/upb/util/def_to_proto.c deleted file mode 100644 index 62bd401..0000000 --- a/vendor/upb/util/def_to_proto.c +++ /dev/null @@ -1,724 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/util/def_to_proto.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/descriptor.upb.h" -#include "upb/base/descriptor_constants.h" -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/port/vsnprintf_compat.h" -#include "upb/reflection/def.h" -#include "upb/reflection/enum_reserved_range.h" -#include "upb/reflection/extension_range.h" -#include "upb/reflection/internal/def_pool.h" -#include "upb/reflection/internal/field_def.h" -#include "upb/reflection/internal/file_def.h" -#include "upb/reflection/message_reserved_range.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - upb_Arena* arena; - jmp_buf err; -} upb_ToProto_Context; - -#define CHK_OOM(val) \ - if (!(val)) UPB_LONGJMP(ctx->err, 1); - -// We want to copy the options verbatim into the destination options proto. -// We use serialize+parse as our deep copy. -#define SET_OPTIONS(proto, desc_type, options_type, src, extreg) \ - { \ - size_t size; \ - /* MEM: could use a temporary arena here instead. */ \ - char* pb = google_protobuf_##options_type##_serialize(src, ctx->arena, &size); \ - CHK_OOM(pb); \ - google_protobuf_##options_type* dst = \ - google_protobuf_##options_type##_parse_ex(pb, size, extreg, 0, ctx->arena); \ - CHK_OOM(dst); \ - google_protobuf_##desc_type##_set_options(proto, dst); \ - } - -static upb_StringView strviewdup2(upb_ToProto_Context* ctx, - upb_StringView str) { - char* p = upb_Arena_Malloc(ctx->arena, str.size); - CHK_OOM(p); - memcpy(p, str.data, str.size); - return (upb_StringView){.data = p, .size = str.size}; -} - -static upb_StringView strviewdup(upb_ToProto_Context* ctx, const char* s) { - return strviewdup2(ctx, (upb_StringView){.data = s, .size = strlen(s)}); -} - -static upb_StringView qual_dup(upb_ToProto_Context* ctx, const char* s) { - size_t n = strlen(s); - char* p = upb_Arena_Malloc(ctx->arena, n + 1); - CHK_OOM(p); - p[0] = '.'; - memcpy(p + 1, s, n); - return (upb_StringView){.data = p, .size = n + 1}; -} - -UPB_PRINTF(2, 3) -static upb_StringView printf_dup(upb_ToProto_Context* ctx, const char* fmt, - ...) { - const size_t max = 32; - char* p = upb_Arena_Malloc(ctx->arena, max); - CHK_OOM(p); - va_list args; - va_start(args, fmt); - size_t n = _upb_vsnprintf(p, max, fmt, args); - va_end(args); - UPB_ASSERT(n < max); - return (upb_StringView){.data = p, .size = n}; -} - -static bool upb_isprint(char ch) { return ch >= 0x20 && ch <= 0x7f; } - -static int special_escape(char ch) { - switch (ch) { - // This is the same set of special escapes recognized by - // absl::CEscape(). - case '\n': - return 'n'; - case '\r': - return 'r'; - case '\t': - return 't'; - case '\\': - return '\\'; - case '\'': - return '\''; - case '"': - return '"'; - default: - return -1; - } -} - -static upb_StringView default_bytes(upb_ToProto_Context* ctx, - upb_StringView val) { - size_t n = 0; - for (size_t i = 0; i < val.size; i++) { - char ch = val.data[i]; - if (special_escape(ch) >= 0) - n += 2; // '\C' - else if (upb_isprint(ch)) - n += 1; - else - n += 4; // '\123' - } - char* p = upb_Arena_Malloc(ctx->arena, n); - CHK_OOM(p); - char* dst = p; - const char* src = val.data; - const char* end = src + val.size; - while (src < end) { - unsigned char ch = *src++; - if (special_escape(ch) >= 0) { - *dst++ = '\\'; - *dst++ = (char)special_escape(ch); - } else if (upb_isprint(ch)) { - *dst++ = ch; - } else { - *dst++ = '\\'; - *dst++ = '0' + (ch >> 6); - *dst++ = '0' + ((ch >> 3) & 0x7); - *dst++ = '0' + (ch & 0x7); - } - } - return (upb_StringView){.data = p, .size = n}; -} - -static upb_StringView default_string(upb_ToProto_Context* ctx, - const upb_FieldDef* f) { - upb_MessageValue d = upb_FieldDef_Default(f); - upb_CType type = upb_FieldDef_CType(f); - - if (type == kUpb_CType_Float || type == kUpb_CType_Double) { - double val = type == kUpb_CType_Float ? d.float_val : d.double_val; - if (val == INFINITY) { - return strviewdup(ctx, "inf"); - } else if (val == -INFINITY) { - return strviewdup(ctx, "-inf"); - } else if (val != val) { - return strviewdup(ctx, "nan"); - } - } - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return strviewdup(ctx, d.bool_val ? "true" : "false"); - case kUpb_CType_Enum: { - const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNumber(e, d.int32_val); - return strviewdup(ctx, upb_EnumValueDef_Name(ev)); - } - case kUpb_CType_Int64: - return printf_dup(ctx, "%" PRId64, d.int64_val); - case kUpb_CType_UInt64: - return printf_dup(ctx, "%" PRIu64, d.uint64_val); - case kUpb_CType_Int32: - return printf_dup(ctx, "%" PRId32, d.int32_val); - case kUpb_CType_UInt32: - return printf_dup(ctx, "%" PRIu32, d.uint32_val); - case kUpb_CType_Float: - return printf_dup(ctx, "%.9g", d.float_val); - case kUpb_CType_Double: - return printf_dup(ctx, "%.17g", d.double_val); - case kUpb_CType_String: - return strviewdup2(ctx, d.str_val); - case kUpb_CType_Bytes: - return default_bytes(ctx, d.str_val); - default: - UPB_UNREACHABLE(); - } -} - -static google_protobuf_DescriptorProto_ReservedRange* resrange_toproto( - upb_ToProto_Context* ctx, const upb_MessageReservedRange* r) { - google_protobuf_DescriptorProto_ReservedRange* proto = - google_protobuf_DescriptorProto_ReservedRange_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_DescriptorProto_ReservedRange_set_start( - proto, upb_MessageReservedRange_Start(r)); - google_protobuf_DescriptorProto_ReservedRange_set_end(proto, - upb_MessageReservedRange_End(r)); - - return proto; -} - -static google_protobuf_EnumDescriptorProto_EnumReservedRange* enumresrange_toproto( - upb_ToProto_Context* ctx, const upb_EnumReservedRange* r) { - google_protobuf_EnumDescriptorProto_EnumReservedRange* proto = - google_protobuf_EnumDescriptorProto_EnumReservedRange_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start( - proto, upb_EnumReservedRange_Start(r)); - google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end( - proto, upb_EnumReservedRange_End(r)); - - return proto; -} - -static google_protobuf_FieldDescriptorProto* fielddef_toproto(upb_ToProto_Context* ctx, - const upb_FieldDef* f) { - google_protobuf_FieldDescriptorProto* proto = - google_protobuf_FieldDescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_FieldDescriptorProto_set_name(proto, - strviewdup(ctx, upb_FieldDef_Name(f))); - google_protobuf_FieldDescriptorProto_set_number(proto, upb_FieldDef_Number(f)); - - if (upb_FieldDef_IsRequired(f) && - upb_FileDef_Edition(upb_FieldDef_File(f)) >= google_protobuf_EDITION_2023) { - google_protobuf_FieldDescriptorProto_set_label( - proto, google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL); - } else { - google_protobuf_FieldDescriptorProto_set_label(proto, upb_FieldDef_Label(f)); - } - if (upb_FieldDef_Type(f) == kUpb_FieldType_Group && - upb_FileDef_Edition(upb_FieldDef_File(f)) >= google_protobuf_EDITION_2023) { - google_protobuf_FieldDescriptorProto_set_type(proto, kUpb_FieldType_Message); - } else { - google_protobuf_FieldDescriptorProto_set_type(proto, upb_FieldDef_Type(f)); - } - - if (upb_FieldDef_HasJsonName(f)) { - google_protobuf_FieldDescriptorProto_set_json_name( - proto, strviewdup(ctx, upb_FieldDef_JsonName(f))); - } - - if (upb_FieldDef_IsSubMessage(f)) { - google_protobuf_FieldDescriptorProto_set_type_name( - proto, - qual_dup(ctx, upb_MessageDef_FullName(upb_FieldDef_MessageSubDef(f)))); - } else if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { - google_protobuf_FieldDescriptorProto_set_type_name( - proto, qual_dup(ctx, upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f)))); - } - - if (upb_FieldDef_IsExtension(f)) { - google_protobuf_FieldDescriptorProto_set_extendee( - proto, - qual_dup(ctx, upb_MessageDef_FullName(upb_FieldDef_ContainingType(f)))); - } - - if (upb_FieldDef_HasDefault(f)) { - google_protobuf_FieldDescriptorProto_set_default_value(proto, - default_string(ctx, f)); - } - - const upb_OneofDef* o = upb_FieldDef_ContainingOneof(f); - if (o) { - google_protobuf_FieldDescriptorProto_set_oneof_index(proto, upb_OneofDef_Index(o)); - } - - if (_upb_FieldDef_IsProto3Optional(f)) { - google_protobuf_FieldDescriptorProto_set_proto3_optional(proto, true); - } - - if (upb_FieldDef_HasOptions(f)) { - SET_OPTIONS(proto, FieldDescriptorProto, FieldOptions, - upb_FieldDef_Options(f), - _upb_DefPool_GeneratedExtensionRegistry( - upb_FileDef_Pool(upb_FieldDef_File(f)))); - } - - return proto; -} - -static google_protobuf_OneofDescriptorProto* oneofdef_toproto(upb_ToProto_Context* ctx, - const upb_OneofDef* o) { - google_protobuf_OneofDescriptorProto* proto = - google_protobuf_OneofDescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_OneofDescriptorProto_set_name(proto, - strviewdup(ctx, upb_OneofDef_Name(o))); - - if (upb_OneofDef_HasOptions(o)) { - SET_OPTIONS(proto, OneofDescriptorProto, OneofOptions, - upb_OneofDef_Options(o), - _upb_DefPool_GeneratedExtensionRegistry(upb_FileDef_Pool( - upb_MessageDef_File(upb_OneofDef_ContainingType(o))))); - } - - return proto; -} - -static google_protobuf_EnumValueDescriptorProto* enumvaldef_toproto( - upb_ToProto_Context* ctx, const upb_EnumValueDef* e) { - google_protobuf_EnumValueDescriptorProto* proto = - google_protobuf_EnumValueDescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_EnumValueDescriptorProto_set_name( - proto, strviewdup(ctx, upb_EnumValueDef_Name(e))); - google_protobuf_EnumValueDescriptorProto_set_number(proto, upb_EnumValueDef_Number(e)); - - if (upb_EnumValueDef_HasOptions(e)) { - SET_OPTIONS(proto, EnumValueDescriptorProto, EnumValueOptions, - upb_EnumValueDef_Options(e), - _upb_DefPool_GeneratedExtensionRegistry(upb_FileDef_Pool( - upb_EnumDef_File(upb_EnumValueDef_Enum(e))))); - } - - return proto; -} - -static google_protobuf_EnumDescriptorProto* enumdef_toproto(upb_ToProto_Context* ctx, - const upb_EnumDef* e) { - google_protobuf_EnumDescriptorProto* proto = - google_protobuf_EnumDescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_EnumDescriptorProto_set_name(proto, - strviewdup(ctx, upb_EnumDef_Name(e))); - - int n = upb_EnumDef_ValueCount(e); - google_protobuf_EnumValueDescriptorProto** vals = - google_protobuf_EnumDescriptorProto_resize_value(proto, n, ctx->arena); - CHK_OOM(vals); - for (int i = 0; i < n; i++) { - vals[i] = enumvaldef_toproto(ctx, upb_EnumDef_Value(e, i)); - } - - n = upb_EnumDef_ReservedRangeCount(e); - google_protobuf_EnumDescriptorProto_EnumReservedRange** res_ranges = - google_protobuf_EnumDescriptorProto_resize_reserved_range(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - res_ranges[i] = enumresrange_toproto(ctx, upb_EnumDef_ReservedRange(e, i)); - } - - n = upb_EnumDef_ReservedNameCount(e); - upb_StringView* res_names = - google_protobuf_EnumDescriptorProto_resize_reserved_name(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - res_names[i] = upb_EnumDef_ReservedName(e, i); - } - - if (upb_EnumDef_HasOptions(e)) { - SET_OPTIONS(proto, EnumDescriptorProto, EnumOptions, upb_EnumDef_Options(e), - _upb_DefPool_GeneratedExtensionRegistry( - upb_FileDef_Pool(upb_EnumDef_File(e)))); - } - - google_protobuf_SymbolVisibility visibility = upb_EnumDef_Visibility(e); - if (visibility != google_protobuf_VISIBILITY_UNSET) { - google_protobuf_EnumDescriptorProto_set_visibility(proto, visibility); - } - - return proto; -} - -static google_protobuf_DescriptorProto_ExtensionRange* extrange_toproto( - upb_ToProto_Context* ctx, const upb_MessageDef* m, - const upb_ExtensionRange* e) { - google_protobuf_DescriptorProto_ExtensionRange* proto = - google_protobuf_DescriptorProto_ExtensionRange_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_DescriptorProto_ExtensionRange_set_start(proto, - upb_ExtensionRange_Start(e)); - google_protobuf_DescriptorProto_ExtensionRange_set_end(proto, - upb_ExtensionRange_End(e)); - - if (upb_ExtensionRange_HasOptions(e)) { - SET_OPTIONS(proto, DescriptorProto_ExtensionRange, ExtensionRangeOptions, - upb_ExtensionRange_Options(e), - _upb_DefPool_GeneratedExtensionRegistry( - upb_FileDef_Pool(upb_MessageDef_File(m)))); - } - - return proto; -} - -static google_protobuf_DescriptorProto* msgdef_toproto(upb_ToProto_Context* ctx, - const upb_MessageDef* m) { - google_protobuf_DescriptorProto* proto = google_protobuf_DescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_DescriptorProto_set_name(proto, - strviewdup(ctx, upb_MessageDef_Name(m))); - - int n; - - n = upb_MessageDef_FieldCount(m); - google_protobuf_FieldDescriptorProto** fields = - google_protobuf_DescriptorProto_resize_field(proto, n, ctx->arena); - CHK_OOM(fields); - for (int i = 0; i < n; i++) { - fields[i] = fielddef_toproto(ctx, upb_MessageDef_Field(m, i)); - } - - n = upb_MessageDef_OneofCount(m); - google_protobuf_OneofDescriptorProto** oneofs = - google_protobuf_DescriptorProto_resize_oneof_decl(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - oneofs[i] = oneofdef_toproto(ctx, upb_MessageDef_Oneof(m, i)); - } - - n = upb_MessageDef_NestedMessageCount(m); - google_protobuf_DescriptorProto** nested_msgs = - google_protobuf_DescriptorProto_resize_nested_type(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - nested_msgs[i] = msgdef_toproto(ctx, upb_MessageDef_NestedMessage(m, i)); - } - - n = upb_MessageDef_NestedEnumCount(m); - google_protobuf_EnumDescriptorProto** nested_enums = - google_protobuf_DescriptorProto_resize_enum_type(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - nested_enums[i] = enumdef_toproto(ctx, upb_MessageDef_NestedEnum(m, i)); - } - - n = upb_MessageDef_NestedExtensionCount(m); - google_protobuf_FieldDescriptorProto** nested_exts = - google_protobuf_DescriptorProto_resize_extension(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - nested_exts[i] = - fielddef_toproto(ctx, upb_MessageDef_NestedExtension(m, i)); - } - - n = upb_MessageDef_ExtensionRangeCount(m); - google_protobuf_DescriptorProto_ExtensionRange** ext_ranges = - google_protobuf_DescriptorProto_resize_extension_range(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - ext_ranges[i] = - extrange_toproto(ctx, m, upb_MessageDef_ExtensionRange(m, i)); - } - - n = upb_MessageDef_ReservedRangeCount(m); - google_protobuf_DescriptorProto_ReservedRange** res_ranges = - google_protobuf_DescriptorProto_resize_reserved_range(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - res_ranges[i] = resrange_toproto(ctx, upb_MessageDef_ReservedRange(m, i)); - } - - n = upb_MessageDef_ReservedNameCount(m); - upb_StringView* res_names = - google_protobuf_DescriptorProto_resize_reserved_name(proto, n, ctx->arena); - for (int i = 0; i < n; i++) { - res_names[i] = upb_MessageDef_ReservedName(m, i); - } - - if (upb_MessageDef_HasOptions(m)) { - SET_OPTIONS(proto, DescriptorProto, MessageOptions, - upb_MessageDef_Options(m), - _upb_DefPool_GeneratedExtensionRegistry( - upb_FileDef_Pool(upb_MessageDef_File(m)))); - } - - google_protobuf_SymbolVisibility visibility = upb_MessageDef_Visibility(m); - if (visibility != google_protobuf_VISIBILITY_UNSET) { - google_protobuf_DescriptorProto_set_visibility(proto, visibility); - } - - return proto; -} - -static google_protobuf_MethodDescriptorProto* methoddef_toproto(upb_ToProto_Context* ctx, - const upb_MethodDef* m) { - google_protobuf_MethodDescriptorProto* proto = - google_protobuf_MethodDescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_MethodDescriptorProto_set_name(proto, - strviewdup(ctx, upb_MethodDef_Name(m))); - - google_protobuf_MethodDescriptorProto_set_input_type( - proto, - qual_dup(ctx, upb_MessageDef_FullName(upb_MethodDef_InputType(m)))); - google_protobuf_MethodDescriptorProto_set_output_type( - proto, - qual_dup(ctx, upb_MessageDef_FullName(upb_MethodDef_OutputType(m)))); - - if (upb_MethodDef_ClientStreaming(m)) { - google_protobuf_MethodDescriptorProto_set_client_streaming(proto, true); - } - - if (upb_MethodDef_ServerStreaming(m)) { - google_protobuf_MethodDescriptorProto_set_server_streaming(proto, true); - } - - if (upb_MethodDef_HasOptions(m)) { - SET_OPTIONS( - proto, MethodDescriptorProto, MethodOptions, upb_MethodDef_Options(m), - _upb_DefPool_GeneratedExtensionRegistry( - upb_FileDef_Pool(upb_ServiceDef_File(upb_MethodDef_Service(m))))); - } - - return proto; -} - -static google_protobuf_ServiceDescriptorProto* servicedef_toproto( - upb_ToProto_Context* ctx, const upb_ServiceDef* s) { - google_protobuf_ServiceDescriptorProto* proto = - google_protobuf_ServiceDescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_ServiceDescriptorProto_set_name( - proto, strviewdup(ctx, upb_ServiceDef_Name(s))); - - size_t n = upb_ServiceDef_MethodCount(s); - google_protobuf_MethodDescriptorProto** methods = - google_protobuf_ServiceDescriptorProto_resize_method(proto, n, ctx->arena); - for (size_t i = 0; i < n; i++) { - methods[i] = methoddef_toproto(ctx, upb_ServiceDef_Method(s, i)); - } - - if (upb_ServiceDef_HasOptions(s)) { - SET_OPTIONS(proto, ServiceDescriptorProto, ServiceOptions, - upb_ServiceDef_Options(s), - _upb_DefPool_GeneratedExtensionRegistry( - upb_FileDef_Pool(upb_ServiceDef_File(s)))); - } - - return proto; -} - -static google_protobuf_FileDescriptorProto* filedef_toproto(upb_ToProto_Context* ctx, - const upb_FileDef* f) { - google_protobuf_FileDescriptorProto* proto = - google_protobuf_FileDescriptorProto_new(ctx->arena); - CHK_OOM(proto); - - google_protobuf_FileDescriptorProto_set_name(proto, - strviewdup(ctx, upb_FileDef_Name(f))); - - const char* package = upb_FileDef_Package(f); - if (package) { - size_t n = strlen(package); - if (n) { - google_protobuf_FileDescriptorProto_set_package(proto, strviewdup(ctx, package)); - } - } - - google_protobuf_Edition edition = upb_FileDef_Edition(f); - - switch (edition) { - case google_protobuf_EDITION_PROTO2: - // We could set syntax to "proto2", but C++ omits it completely, which is - // equivalent. - break; - case google_protobuf_EDITION_PROTO3: - google_protobuf_FileDescriptorProto_set_syntax(proto, strviewdup(ctx, "proto3")); - break; - default: - google_protobuf_FileDescriptorProto_set_syntax(proto, strviewdup(ctx, "editions")); - google_protobuf_FileDescriptorProto_set_edition(proto, edition); - break; - } - - size_t n; - n = upb_FileDef_DependencyCount(f); - upb_StringView* deps = - google_protobuf_FileDescriptorProto_resize_dependency(proto, n, ctx->arena); - for (size_t i = 0; i < n; i++) { - deps[i] = strviewdup(ctx, upb_FileDef_Name(upb_FileDef_Dependency(f, i))); - } - - n = upb_FileDef_PublicDependencyCount(f); - int32_t* public_deps = - google_protobuf_FileDescriptorProto_resize_public_dependency(proto, n, ctx->arena); - const int32_t* public_dep_nums = _upb_FileDef_PublicDependencyIndexes(f); - if (n) memcpy(public_deps, public_dep_nums, n * sizeof(int32_t)); - - n = upb_FileDef_WeakDependencyCount(f); - int32_t* weak_deps = - google_protobuf_FileDescriptorProto_resize_weak_dependency(proto, n, ctx->arena); - const int32_t* weak_dep_nums = _upb_FileDef_WeakDependencyIndexes(f); - if (n) memcpy(weak_deps, weak_dep_nums, n * sizeof(int32_t)); - - n = upb_FileDef_TopLevelMessageCount(f); - google_protobuf_DescriptorProto** msgs = - google_protobuf_FileDescriptorProto_resize_message_type(proto, n, ctx->arena); - for (size_t i = 0; i < n; i++) { - msgs[i] = msgdef_toproto(ctx, upb_FileDef_TopLevelMessage(f, i)); - } - - n = upb_FileDef_TopLevelEnumCount(f); - google_protobuf_EnumDescriptorProto** enums = - google_protobuf_FileDescriptorProto_resize_enum_type(proto, n, ctx->arena); - for (size_t i = 0; i < n; i++) { - enums[i] = enumdef_toproto(ctx, upb_FileDef_TopLevelEnum(f, i)); - } - - n = upb_FileDef_ServiceCount(f); - google_protobuf_ServiceDescriptorProto** services = - google_protobuf_FileDescriptorProto_resize_service(proto, n, ctx->arena); - for (size_t i = 0; i < n; i++) { - services[i] = servicedef_toproto(ctx, upb_FileDef_Service(f, i)); - } - - n = upb_FileDef_TopLevelExtensionCount(f); - google_protobuf_FieldDescriptorProto** exts = - google_protobuf_FileDescriptorProto_resize_extension(proto, n, ctx->arena); - for (size_t i = 0; i < n; i++) { - exts[i] = fielddef_toproto(ctx, upb_FileDef_TopLevelExtension(f, i)); - } - - if (upb_FileDef_HasOptions(f)) { - SET_OPTIONS(proto, FileDescriptorProto, FileOptions, upb_FileDef_Options(f), - _upb_DefPool_GeneratedExtensionRegistry(upb_FileDef_Pool(f))); - } - - return proto; -} - -static google_protobuf_DescriptorProto* upb_ToProto_ConvertMessageDef( - upb_ToProto_Context* const ctx, const upb_MessageDef* const m) { - if (UPB_SETJMP(ctx->err)) return NULL; - return msgdef_toproto(ctx, m); -} - -google_protobuf_DescriptorProto* upb_MessageDef_ToProto(const upb_MessageDef* m, - upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertMessageDef(&ctx, m); -} - -google_protobuf_EnumDescriptorProto* upb_ToProto_ConvertEnumDef( - upb_ToProto_Context* const ctx, const upb_EnumDef* const e) { - if (UPB_SETJMP(ctx->err)) return NULL; - return enumdef_toproto(ctx, e); -} - -google_protobuf_EnumDescriptorProto* upb_EnumDef_ToProto(const upb_EnumDef* e, - upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertEnumDef(&ctx, e); -} - -google_protobuf_EnumValueDescriptorProto* upb_ToProto_ConvertEnumValueDef( - upb_ToProto_Context* const ctx, const upb_EnumValueDef* e) { - if (UPB_SETJMP(ctx->err)) return NULL; - return enumvaldef_toproto(ctx, e); -} - -google_protobuf_EnumValueDescriptorProto* upb_EnumValueDef_ToProto( - const upb_EnumValueDef* e, upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertEnumValueDef(&ctx, e); -} - -google_protobuf_FieldDescriptorProto* upb_ToProto_ConvertFieldDef( - upb_ToProto_Context* const ctx, const upb_FieldDef* f) { - if (UPB_SETJMP(ctx->err)) return NULL; - return fielddef_toproto(ctx, f); -} - -google_protobuf_FieldDescriptorProto* upb_FieldDef_ToProto(const upb_FieldDef* f, - upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertFieldDef(&ctx, f); -} - -google_protobuf_OneofDescriptorProto* upb_ToProto_ConvertOneofDef( - upb_ToProto_Context* const ctx, const upb_OneofDef* o) { - if (UPB_SETJMP(ctx->err)) return NULL; - return oneofdef_toproto(ctx, o); -} - -google_protobuf_OneofDescriptorProto* upb_OneofDef_ToProto(const upb_OneofDef* o, - upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertOneofDef(&ctx, o); -} - -google_protobuf_FileDescriptorProto* upb_ToProto_ConvertFileDef( - upb_ToProto_Context* const ctx, const upb_FileDef* const f) { - if (UPB_SETJMP(ctx->err)) return NULL; - return filedef_toproto(ctx, f); -} - -google_protobuf_FileDescriptorProto* upb_FileDef_ToProto(const upb_FileDef* f, - upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertFileDef(&ctx, f); -} - -google_protobuf_MethodDescriptorProto* upb_ToProto_ConvertMethodDef( - upb_ToProto_Context* const ctx, const upb_MethodDef* m) { - if (UPB_SETJMP(ctx->err)) return NULL; - return methoddef_toproto(ctx, m); -} - -google_protobuf_MethodDescriptorProto* upb_MethodDef_ToProto( - const upb_MethodDef* const m, upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertMethodDef(&ctx, m); -} - -google_protobuf_ServiceDescriptorProto* upb_ToProto_ConvertServiceDef( - upb_ToProto_Context* const ctx, const upb_ServiceDef* const s) { - if (UPB_SETJMP(ctx->err)) return NULL; - return servicedef_toproto(ctx, s); -} - -google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(const upb_ServiceDef* s, - upb_Arena* a) { - upb_ToProto_Context ctx = {a}; - return upb_ToProto_ConvertServiceDef(&ctx, s); -} diff --git a/vendor/upb/util/def_to_proto.h b/vendor/upb/util/def_to_proto.h deleted file mode 100644 index 1cc66b8..0000000 --- a/vendor/upb/util/def_to_proto.h +++ /dev/null @@ -1,49 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_UTIL_DEF_TO_PROTO_H_ -#define UPB_UTIL_DEF_TO_PROTO_H_ - -#include "google/protobuf/descriptor.upb.h" -#include "upb/mem/arena.h" -#include "upb/reflection/def.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Must be last -#include "upb/port/def.inc" - -// Functions for converting defs back to the equivalent descriptor proto. -// Ultimately the goal is that a round-trip proto->def->proto is lossless. Each -// function returns a new proto created in arena `a`, or NULL if memory -// allocation failed. -UPB_NODISCARD google_protobuf_DescriptorProto* upb_MessageDef_ToProto( - const upb_MessageDef* m, upb_Arena* a); -UPB_NODISCARD google_protobuf_EnumDescriptorProto* upb_EnumDef_ToProto( - const upb_EnumDef* e, upb_Arena* a); -UPB_NODISCARD google_protobuf_EnumValueDescriptorProto* upb_EnumValueDef_ToProto( - const upb_EnumValueDef* e, upb_Arena* a); -UPB_NODISCARD google_protobuf_FieldDescriptorProto* upb_FieldDef_ToProto( - const upb_FieldDef* f, upb_Arena* a); -UPB_NODISCARD google_protobuf_OneofDescriptorProto* upb_OneofDef_ToProto( - const upb_OneofDef* o, upb_Arena* a); -UPB_NODISCARD google_protobuf_FileDescriptorProto* upb_FileDef_ToProto( - const upb_FileDef* f, upb_Arena* a); -UPB_NODISCARD google_protobuf_MethodDescriptorProto* upb_MethodDef_ToProto( - const upb_MethodDef* m, upb_Arena* a); -UPB_NODISCARD google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto( - const upb_ServiceDef* s, upb_Arena* a); - -#include "upb/port/undef.inc" - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* UPB_UTIL_DEF_TO_PROTO_H_ */ diff --git a/vendor/upb/util/def_to_proto_editions_test.proto b/vendor/upb/util/def_to_proto_editions_test.proto deleted file mode 100644 index 91310d1..0000000 --- a/vendor/upb/util/def_to_proto_editions_test.proto +++ /dev/null @@ -1,8 +0,0 @@ -edition = "2023"; - -package pkg; - -message EditionsMessage { - int32 required_field = 1 [features.field_presence = LEGACY_REQUIRED]; - EditionsMessage delimited_field = 2 [features.message_encoding = DELIMITED]; -} diff --git a/vendor/upb/util/def_to_proto_fuzz_test.cc b/vendor/upb/util/def_to_proto_fuzz_test.cc deleted file mode 100644 index e96a087..0000000 --- a/vendor/upb/util/def_to_proto_fuzz_test.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include - -#include "google/protobuf/descriptor.pb.h" -#include -#include "testing/fuzzing/fuzztest.h" -#include "upb/util/def_to_proto_test.h" - -namespace upb_test { - -FUZZ_TEST(FuzzTest, RoundTripDescriptor) - .WithDomains( - ::fuzztest::Arbitrary().WithProtobufField( - "file", - ::fuzztest::Arbitrary() - // upb_FileDef_ToProto() does not attempt to preserve - // source_code_info. - .WithFieldUnset("source_code_info") - .WithProtobufField( - "service", - ::fuzztest::Arbitrary()))); - -} // namespace upb_test diff --git a/vendor/upb/util/def_to_proto_public_import_test.proto b/vendor/upb/util/def_to_proto_public_import_test.proto deleted file mode 100644 index 646118c..0000000 --- a/vendor/upb/util/def_to_proto_public_import_test.proto +++ /dev/null @@ -1,12 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto3"; - -package pkg; - -message PublicImportMessage {} diff --git a/vendor/upb/util/def_to_proto_regular_import_test.proto b/vendor/upb/util/def_to_proto_regular_import_test.proto deleted file mode 100644 index 7bf9e04..0000000 --- a/vendor/upb/util/def_to_proto_regular_import_test.proto +++ /dev/null @@ -1,16 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto3"; - -package pkg; - -message RegularImportMessage {} - -enum Proto3Enum { - PROTO3_ENUM_ZERO = 0; -} diff --git a/vendor/upb/util/def_to_proto_test.cc b/vendor/upb/util/def_to_proto_test.cc deleted file mode 100644 index d824d43..0000000 --- a/vendor/upb/util/def_to_proto_test.cc +++ /dev/null @@ -1,337 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/util/def_to_proto.h" - -#include -#include -#include - -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.upb.h" -#include "google/protobuf/descriptor.upbdefs.h" -#include -#include -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/util/message_differencer.h" -#include "upb/base/string_view.h" -#include "upb/mem/arena.hpp" -#include "upb/reflection/def.hpp" -#include "upb/test/parse_text_proto.h" -#include "upb/util/def_to_proto_editions_test.upbdefs.h" -#include "upb/util/def_to_proto_test.h" -#include "upb/util/def_to_proto_test.upbdefs.h" - -namespace upb_test { - -// Loads and retrieves a descriptor for `msgdef` into the given `pool`. -const google::protobuf::Descriptor* AddMessageDescriptor(upb::MessageDefPtr msgdef, - google::protobuf::DescriptorPool* pool) { - upb::Arena tmp_arena; - upb::FileDefPtr file = msgdef.file(); - google_protobuf_FileDescriptorProto* upb_proto = - upb_FileDef_ToProto(file.ptr(), tmp_arena.ptr()); - size_t size; - const char* buf = - google_protobuf_FileDescriptorProto_serialize(upb_proto, tmp_arena.ptr(), &size); - google::protobuf::FileDescriptorProto google_proto; - EXPECT_TRUE(google_proto.ParseFromString(absl::string_view(buf, size))); - const google::protobuf::FileDescriptor* file_desc = pool->BuildFile(google_proto); - EXPECT_TRUE(file_desc != nullptr); - return pool->FindMessageTypeByName(msgdef.full_name()); -} - -// Converts a upb `msg` (with type `msgdef`) into a protobuf Message object from -// the given factory and descriptor. -std::unique_ptr ToProto(const upb_Message* msg, - const upb_MessageDef* msgdef, - const google::protobuf::Descriptor* desc, - google::protobuf::MessageFactory* factory) { - upb::Arena arena; - EXPECT_TRUE(desc != nullptr); - std::unique_ptr google_msg( - factory->GetPrototype(desc)->New()); - char* buf; - size_t size; - upb_EncodeStatus status = upb_Encode(msg, upb_MessageDef_MiniTable(msgdef), 0, - arena.ptr(), &buf, &size); - EXPECT_EQ(status, kUpb_EncodeStatus_Ok); - EXPECT_TRUE(google_msg->ParseFromString(absl::string_view(buf, size))); - return google_msg; -} - -// A gtest matcher that verifies that a proto is equal to `proto`. Both `proto` -// and `arg` must be messages of type `msgdef_func` (a .upbdefs.h function that -// loads a known msgdef into the given defpool). -MATCHER_P2(EqualsUpbProto, proto, msgdef_func, - negation ? "are not equal" : "are equal") { - upb::DefPool defpool; - google::protobuf::DescriptorPool pool; - google::protobuf::DynamicMessageFactory factory; - upb::MessageDefPtr msgdef(msgdef_func(defpool.ptr())); - EXPECT_TRUE(msgdef.ptr() != nullptr); - const google::protobuf::Descriptor* desc = AddMessageDescriptor(msgdef, &pool); - EXPECT_TRUE(desc != nullptr); - std::unique_ptr m1( - ToProto(UPB_UPCAST(proto), msgdef.ptr(), desc, &factory)); - std::unique_ptr m2( - ToProto((upb_Message*)arg, msgdef.ptr(), desc, &factory)); - std::string differences; - google::protobuf::util::MessageDifferencer differencer; - differencer.ReportDifferencesToString(&differences); - bool eq = differencer.Compare(*m2, *m1); - if (!eq) { - *result_listener << differences; - } - return eq; -} - -// Verifies that the given upb FileDef can be converted to a proto that matches -// `proto`. -void CheckFile(const upb::FileDefPtr file, - const google_protobuf_FileDescriptorProto* proto) { - upb::Arena arena; - google_protobuf_FileDescriptorProto* proto2 = - upb_FileDef_ToProto(file.ptr(), arena.ptr()); - ASSERT_THAT(proto, - EqualsUpbProto(proto2, google_protobuf_FileDescriptorProto_getmsgdef)); -} - -// Verifies that upb/util/def_to_proto_test.proto can round-trip: -// serialized descriptor -> upb def -> serialized descriptor -TEST(DefToProto, Test) { - upb::Arena arena; - upb::DefPool defpool; - upb_StringView test_file_desc = - upb_util_def_to_proto_test_proto_upbdefinit.descriptor; - const auto* file_desc = google_protobuf_FileDescriptorProto_parse( - test_file_desc.data, test_file_desc.size, arena.ptr()); - - upb::MessageDefPtr msgdef(pkg_Message_getmsgdef(defpool.ptr())); - upb::FileDefPtr file = msgdef.file(); - CheckFile(file, file_desc); -} - -// Verifies that editions don't leak out legacy feature APIs (e.g. TYPE_GROUP -// and LABEL_REQUIRED): -// serialized descriptor -> upb def -> serialized descriptor -TEST(DefToProto, TestEditionsLegacyFeatures) { - upb::Arena arena; - upb::DefPool defpool; - upb_StringView test_file_desc = - upb_util_def_to_proto_editions_test_proto_upbdefinit - .descriptor; - const auto* file = google_protobuf_FileDescriptorProto_parse( - test_file_desc.data, test_file_desc.size, arena.ptr()); - - size_t size; - const auto* messages = google_protobuf_FileDescriptorProto_message_type(file, &size); - ASSERT_EQ(size, 1); - const auto* fields = google_protobuf_DescriptorProto_field(messages[0], &size); - ASSERT_EQ(size, 2); - EXPECT_EQ(google_protobuf_FieldDescriptorProto_label(fields[0]), - google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL); - EXPECT_EQ(google_protobuf_FieldDescriptorProto_type(fields[1]), - google_protobuf_FieldDescriptorProto_TYPE_MESSAGE); -} - -// Like the previous test, but uses a message layout built at runtime. -TEST(DefToProto, TestRuntimeReflection) { - upb::Arena arena; - upb::DefPool defpool; - upb_StringView test_file_desc = - upb_util_def_to_proto_test_proto_upbdefinit.descriptor; - const auto* file_desc = google_protobuf_FileDescriptorProto_parse( - test_file_desc.data, test_file_desc.size, arena.ptr()); - - _upb_DefPool_LoadDefInitEx( - defpool.ptr(), - &upb_util_def_to_proto_test_proto_upbdefinit, true); - upb::FileDefPtr file = defpool.FindFileByName( - upb_util_def_to_proto_test_proto_upbdefinit.filename); - CheckFile(file, file_desc); -} - -// Fuzz test regressions. - -TEST(FuzzTest, EmptyPackage) { - RoundTripDescriptor(ParseTextProtoOrDie(R"pb(file { package: "" })pb")); -} - -TEST(FuzzTest, EmptyName) { - RoundTripDescriptor(ParseTextProtoOrDie(R"pb(file { name: "" })pb")); -} - -TEST(FuzzTest, EmptyPackage2) { - RoundTripDescriptor( - ParseTextProtoOrDie(R"pb(file { name: "n" package: "" })pb")); -} - -TEST(FuzzTest, FileNameEmbeddedNull) { - RoundTripDescriptor(ParseTextProtoOrDie(R"pb(file { name: "\000" })pb")); -} - -TEST(FuzzTest, DuplicateOneofIndex) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "F" - message_type { - name: "M" - oneof_decl { name: "O" } - field { name: "f1" number: 1 type: TYPE_INT32 oneof_index: 0 } - field { name: "f2" number: 1 type: TYPE_INT32 oneof_index: 0 } - } - })pb")); -} - -TEST(FuzzTest, NanValue) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - enum_type { - value { - number: 0 - options { uninterpreted_option { double_value: nan } } - } - } - })pb")); -} - -TEST(FuzzTest, EnumValueEmbeddedNull) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "\035" - enum_type { - name: "f" - value { name: "\000" number: 0 } - } - })pb")); -} - -TEST(FuzzTest, EnumValueNoNumber) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "\035" - enum_type { - name: "f" - value { name: "abc" } - } - })pb")); -} - -TEST(FuzzTest, DefaultWithUnterminatedHex) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "\035" - message_type { - name: "A" - field { - name: "f" - number: 1 - label: LABEL_OPTIONAL - type: TYPE_BYTES - default_value: "\\x" - } - } - })pb")); -} - -TEST(FuzzTest, DefaultWithValidHexEscape) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "\035" - message_type { - name: "A" - field { - name: "f" - number: 1 - label: LABEL_OPTIONAL - type: TYPE_BYTES - default_value: "\\x03" - } - } - })pb")); -} - -TEST(FuzzTest, DefaultWithValidHexEscapePrintable) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "\035" - message_type { - name: "A" - field { - name: "f" - number: 1 - label: LABEL_OPTIONAL - type: TYPE_BYTES - default_value: "\\x23" # 0x32 = '#' - } - } - })pb")); -} - -TEST(FuzzTest, PackageStartsWithNumber) { - RoundTripDescriptor( - ParseTextProtoOrDie(R"pb(file { name: "" package: "0" })pb")); -} - -TEST(FuzzTest, RoundTripDescriptorRegression) { - RoundTripDescriptor(ParseTextProtoOrDie(R"pb(file { - name: "" - message_type { - name: "A" - field { - name: "B" - number: 1 - type: TYPE_BYTES - default_value: "\007" - } - } - })pb")); -} - -// Multiple oneof fields which have the same name. -TEST(FuzzTest, RoundTripDescriptorRegressionOneofSameName) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "N" - package: "" - message_type { - name: "b" - field { name: "W" number: 1 type: TYPE_BYTES oneof_index: 0 } - field { name: "W" number: 17 type: TYPE_UINT32 oneof_index: 0 } - oneof_decl { name: "k" } - } - })pb")); -} - -TEST(FuzzTest, NegativeOneofIndex) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - message_type { - name: "A" - field { name: "A" number: 0 type_name: "" oneof_index: -1 } - } - } - )pb")); -} - -TEST(FuzzTest, EnumVisibility) { - RoundTripDescriptor(ParseTextProtoOrDie( - R"pb(file { - name: "n" - package: "p" - enum_type { - name: "E" - value { name: "MM" number: 0 } - visibility: VISIBILITY_EXPORT - } - message_type { name: "M" visibility: VISIBILITY_EXPORT } - } - )pb")); -} - -} // namespace upb_test diff --git a/vendor/upb/util/def_to_proto_test.h b/vendor/upb/util/def_to_proto_test.h deleted file mode 100644 index cabf84d..0000000 --- a/vendor/upb/util/def_to_proto_test.h +++ /dev/null @@ -1,123 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_UTIL_DEF_TO_PROTO_TEST_H_ -#define UPB_UTIL_DEF_TO_PROTO_TEST_H_ - -#include - -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.upb.h" -#include -#include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/util/field_comparator.h" -#include "upb/base/status.hpp" -#include "upb/mem/arena.hpp" -#include "upb/reflection/def.hpp" -#include "upb/util/def_to_proto.h" - -namespace upb_test { - -// A gtest matcher that verifies that a proto is equal to `proto`. Both `proto` -// and `arg` must be messages of type `msgdef_func` (a .upbdefs.h function that -// loads a known msgdef into the given defpool). -MATCHER_P(EqualsProtoTreatNansAsEqual, proto, - negation ? "are not equal" : "are equal") { - upb::DefPool defpool; - std::string differences; - google::protobuf::util::DefaultFieldComparator comparator; - comparator.set_treat_nan_as_equal(true); - google::protobuf::util::MessageDifferencer differencer; - differencer.set_field_comparator(&comparator); - differencer.ReportDifferencesToString(&differences); - bool eq = differencer.Compare(proto, arg); - if (!eq) { - *result_listener << differences; - } - return eq; -} - -class NullErrorCollector : public google::protobuf::DescriptorPool::ErrorCollector { - void RecordError(absl::string_view filename, absl::string_view element_name, - const google::protobuf::Message* descriptor, ErrorLocation location, - absl::string_view message) override {} - void RecordWarning(absl::string_view filename, absl::string_view element_name, - const google::protobuf::Message* descriptor, ErrorLocation location, - absl::string_view message) override {} -}; - -static void AddFile(google::protobuf::FileDescriptorProto& file, upb::DefPool* pool, - google::protobuf::DescriptorPool* desc_pool) { - NullErrorCollector collector; - const google::protobuf::FileDescriptor* file_desc = - desc_pool->BuildFileCollectingErrors(file, &collector); - - if (file_desc != nullptr) { - // The file descriptor was valid according to proto2. - google::protobuf::FileDescriptorProto normalized_file; - file_desc->CopyTo(&normalized_file); - std::string serialized; - (void)normalized_file.SerializeToString(&serialized); - upb::Arena arena; - upb::Status status; - google_protobuf_FileDescriptorProto* proto = google_protobuf_FileDescriptorProto_parse( - serialized.data(), serialized.size(), arena.ptr()); - ASSERT_NE(proto, nullptr); - upb::FileDefPtr file_def = pool->AddFile(proto, &status); - - // Ideally we could assert that file_def is present here. After all, any - // descriptor accepted by C++ should be by definition valid. However C++ - // performs some of its validation at the .proto file parser level instead - // of when validating descriptors. As as result, C++ will accept some - // unreasonable descriptors like: - // file { name: "" package: "0" } - // - // There is no .proto file that will produce this descriptor, but - // BuildFile() accepts it. We should probably clean up these cases so C++ - // will reject them too. - if (!file_def) return; - - ASSERT_TRUE(status.ok()) << status.error_message(); - google_protobuf_FileDescriptorProto* upb_proto = - upb_FileDef_ToProto(file_def.ptr(), arena.ptr()); - size_t size; - const char* buf = - google_protobuf_FileDescriptorProto_serialize(upb_proto, arena.ptr(), &size); - google::protobuf::FileDescriptorProto google_proto; - bool ok = google_proto.ParseFromString(absl::string_view(buf, size)); - ASSERT_TRUE(ok); - EXPECT_THAT(google_proto, EqualsProtoTreatNansAsEqual(normalized_file)); - } else { - // This file was invalid according to proto2. When we parse it with upb, - // it may or may not be accepted, since upb does not perform as much - // validation as proto2. However it must not crash. - std::string serialized; - (void)file.SerializeToString(&serialized); - upb::Arena arena; - upb::Status status; - google_protobuf_FileDescriptorProto* proto = google_protobuf_FileDescriptorProto_parse( - serialized.data(), serialized.size(), arena.ptr()); - ASSERT_NE(proto, nullptr); - pool->AddFile(proto, &status); - } -} - -inline void RoundTripDescriptor(const google::protobuf::FileDescriptorSet& set) { - upb::DefPool defpool; - google::protobuf::DescriptorPool desc_pool; - desc_pool.EnforceWeakDependencies(true); - for (const auto& file : set.file()) { - google::protobuf::FileDescriptorProto mutable_file(file); - AddFile(mutable_file, &defpool, &desc_pool); - } -} - -} // namespace upb_test - -#endif // UPB_UTIL_DEF_TO_PROTO_TEST_H_ diff --git a/vendor/upb/util/def_to_proto_test.proto b/vendor/upb/util/def_to_proto_test.proto deleted file mode 100644 index e71c33a..0000000 --- a/vendor/upb/util/def_to_proto_test.proto +++ /dev/null @@ -1,110 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package pkg; - -import public "upb/util/def_to_proto_public_import_test.proto"; - -import "upb/util/def_to_proto_regular_import_test.proto"; - -option optimize_for = CODE_SIZE; -option go_package = "foo_go_package"; -option java_package = "bar_java_package"; -option java_outer_classname = "baz_java_outer_classname"; -option csharp_namespace = "quux_csharp_namespace"; -option objc_class_prefix = "the_objc_prefix"; -option cc_enable_arenas = true; - -message Message { - optional int32 a = 1 [default = 3]; - oneof foo { - string oneof_string = 2 [default = "abc\n"]; - string oneof_bool = 3 [default = "true"]; - bytes oneof_bytes = 4 [default = "abc\xef\xfe"]; - } - optional pkg.RegularImportMessage regular_import_message = 6; - optional pkg.PublicImportMessage public_import_message = 7; - optional pkg.Proto3Enum proto3_enum = 8; - extensions 1000 to max; - extend Message { - optional int32 ext = 1000; - } - - message NestedMessage {} - message NestedEnum {} - - // TODO: support reserved ranges in defs. - // (At the moment they are ignored and will not round-trip through defs). - // reserved 4, 6 to 8; -} - -enum Enum { - ZERO = 0; - ONE = 1; - NEGATIVE_ONE = -1; -} - -enum EnumUpper32Value { - UPPER32_VALUE = 40; -} - -enum HasDuplicateValues { - option allow_alias = true; - - A = 0; - B = 1; - C = 120; - D = 130; - - G = 120; - F = 1; - E = 0; - H = 121; - I = 121; - J = 121; - K = 121; -} - -service Service { - rpc Bar(Message) returns (Message); -} - -extend Message { - optional int32 ext = 1001; -} - -enum Has31 { - VALUE_31 = 31; -} - -message PretendMessageSet { - option message_set_wire_format = true; - - // Since this is message_set_wire_format, "max" here means INT32_MAX. - // (For normal messages "max" would mean 2**29 - 1). - extensions 4 to 529999999; - extensions 530000000 to max - [declaration = { - number: 2147483646 - full_name: ".pkg.MessageSetItem.message_set_extension" - type: ".pkg.MessageSetItem" - }]; -} - -message MessageSetItem { - extend PretendMessageSet { - // Since max is exclusive, this is INT32_MAX-1, not INT32_MAX. - optional MessageSetItem message_set_extension = 2147483646; - } -} - -message UnusualDefaults { - optional bytes foo = 1 [default = "\\X"]; - optional string bar = 2 [default = "\\X"]; -} diff --git a/vendor/upb/util/def_to_proto_weak_import_test.proto b/vendor/upb/util/def_to_proto_weak_import_test.proto deleted file mode 100644 index bc82f4a..0000000 --- a/vendor/upb/util/def_to_proto_weak_import_test.proto +++ /dev/null @@ -1,8 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto3"; diff --git a/vendor/upb/util/def_to_proto_wweak_import_test.proto b/vendor/upb/util/def_to_proto_wweak_import_test.proto deleted file mode 100644 index bc82f4a..0000000 --- a/vendor/upb/util/def_to_proto_wweak_import_test.proto +++ /dev/null @@ -1,8 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto3"; diff --git a/vendor/upb/util/required_fields.c b/vendor/upb/util/required_fields.c deleted file mode 100644 index c372386..0000000 --- a/vendor/upb/util/required_fields.c +++ /dev/null @@ -1,305 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/util/required_fields.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mem/alloc.h" -#include "upb/message/array.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/port/vsnprintf_compat.h" -#include "upb/reflection/def.h" -#include "upb/reflection/message.h" - -// Must be last. -#include "upb/port/def.inc" - -//////////////////////////////////////////////////////////////////////////////// -// upb_FieldPath_ToText() -//////////////////////////////////////////////////////////////////////////////// - -typedef struct { - char* buf; - char* ptr; - char* end; - size_t overflow; -} upb_PrintfAppender; - -UPB_PRINTF(2, 3) -static void upb_FieldPath_Printf(upb_PrintfAppender* a, const char* fmt, ...) { - size_t n; - size_t have = a->end - a->ptr; - va_list args; - - va_start(args, fmt); - n = _upb_vsnprintf(a->ptr, have, fmt, args); - va_end(args); - - if (UPB_LIKELY(have > n)) { - // We can't end up here if the user passed (NULL, 0), therefore ptr is known - // to be non-NULL, and UPB_PTRADD() is not necessary. - assert(a->ptr); - a->ptr += n; - } else { - a->ptr = UPB_PTRADD(a->ptr, have); - a->overflow += (n - have); - } -} - -static size_t upb_FieldPath_NullTerminate(upb_PrintfAppender* d, size_t size) { - size_t ret = d->ptr - d->buf + d->overflow; - - if (size > 0) { - if (d->ptr == d->end) d->ptr--; - *d->ptr = '\0'; - } - - return ret; -} - -static void upb_FieldPath_PutMapKey(upb_PrintfAppender* a, - upb_MessageValue map_key, - const upb_FieldDef* key_f) { - switch (upb_FieldDef_CType(key_f)) { - case kUpb_CType_Int32: - upb_FieldPath_Printf(a, "[%" PRId32 "]", map_key.int32_val); - break; - case kUpb_CType_Int64: - upb_FieldPath_Printf(a, "[%" PRId64 "]", map_key.int64_val); - break; - case kUpb_CType_UInt32: - upb_FieldPath_Printf(a, "[%" PRIu32 "]", map_key.uint32_val); - break; - case kUpb_CType_UInt64: - upb_FieldPath_Printf(a, "[%" PRIu64 "]", map_key.uint64_val); - break; - case kUpb_CType_Bool: - upb_FieldPath_Printf(a, "[%s]", map_key.bool_val ? "true" : "false"); - break; - case kUpb_CType_String: - upb_FieldPath_Printf(a, "[\""); - for (size_t i = 0; i < map_key.str_val.size; i++) { - char ch = map_key.str_val.data[i]; - if (ch == '"') { - upb_FieldPath_Printf(a, "\\\""); - } else { - upb_FieldPath_Printf(a, "%c", ch); - } - } - upb_FieldPath_Printf(a, "\"]"); - break; - default: - UPB_UNREACHABLE(); // Other types can't be map keys. - } -} - -size_t upb_FieldPath_ToText(upb_FieldPathEntry** path, char* buf, size_t size) { - upb_FieldPathEntry* ptr = *path; - upb_PrintfAppender appender; - appender.buf = buf; - appender.ptr = buf; - appender.end = UPB_PTRADD(buf, size); - appender.overflow = 0; - bool first = true; - - while (ptr->field) { - const upb_FieldDef* f = ptr->field; - - upb_FieldPath_Printf(&appender, first ? "%s" : ".%s", upb_FieldDef_Name(f)); - first = false; - ptr++; - - if (upb_FieldDef_IsMap(f)) { - const upb_FieldDef* key_f = - upb_MessageDef_Field(upb_FieldDef_MessageSubDef(f), 0); - upb_FieldPath_PutMapKey(&appender, ptr->map_key, key_f); - ptr++; - } else if (upb_FieldDef_IsRepeated(f)) { - upb_FieldPath_Printf(&appender, "[%zu]", ptr->array_index); - ptr++; - } - } - - // Advance beyond terminating NULL. - ptr++; - *path = ptr; - return upb_FieldPath_NullTerminate(&appender, size); -} - -//////////////////////////////////////////////////////////////////////////////// -// upb_util_HasUnsetRequired() -//////////////////////////////////////////////////////////////////////////////// - -typedef struct { - upb_FieldPathEntry* path; - size_t size; - size_t cap; -} upb_FieldPathVector; - -typedef struct { - upb_FieldPathVector stack; - upb_FieldPathVector out_fields; - const upb_DefPool* ext_pool; - jmp_buf err; - bool has_unset_required; - bool save_paths; -} upb_FindContext; - -static void upb_FieldPathVector_Init(upb_FieldPathVector* vec) { - vec->path = NULL; - vec->size = 0; - vec->cap = 0; -} - -static void upb_FieldPathVector_Reserve(upb_FindContext* ctx, - upb_FieldPathVector* vec, - size_t elems) { - if (vec->cap - vec->size < elems) { - const int oldsize = vec->cap * sizeof(*vec->path); - size_t need = vec->size + elems; - vec->cap = UPB_MAX(4, vec->cap); - while (vec->cap < need) vec->cap *= 2; - const int newsize = vec->cap * sizeof(*vec->path); - vec->path = upb_grealloc(vec->path, oldsize, newsize); - if (!vec->path) { - UPB_LONGJMP(ctx->err, 1); - } - } -} - -static void upb_FindContext_Push(upb_FindContext* ctx, upb_FieldPathEntry ent) { - if (!ctx->save_paths) return; - upb_FieldPathVector_Reserve(ctx, &ctx->stack, 1); - ctx->stack.path[ctx->stack.size++] = ent; -} - -static void upb_FindContext_Pop(upb_FindContext* ctx) { - if (!ctx->save_paths) return; - assert(ctx->stack.size != 0); - ctx->stack.size--; -} - -static void upb_util_FindUnsetInMessage(upb_FindContext* ctx, - const upb_Message* msg, - const upb_MessageDef* m) { - // Iterate over all fields to see if any required fields are missing. - for (int i = 0, n = upb_MessageDef_FieldCount(m); i < n; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - if (!upb_FieldDef_IsRequired(f)) continue; - - if (!msg || !upb_Message_HasFieldByDef(msg, f)) { - // A required field is missing. - ctx->has_unset_required = true; - - if (ctx->save_paths) { - // Append the contents of the stack to the out array, then - // NULL-terminate. - upb_FieldPathVector_Reserve(ctx, &ctx->out_fields, ctx->stack.size + 2); - if (ctx->stack.size) { - memcpy(&ctx->out_fields.path[ctx->out_fields.size], ctx->stack.path, - ctx->stack.size * sizeof(*ctx->stack.path)); - } - ctx->out_fields.size += ctx->stack.size; - ctx->out_fields.path[ctx->out_fields.size++] = - (upb_FieldPathEntry){.field = f}; - ctx->out_fields.path[ctx->out_fields.size++] = - (upb_FieldPathEntry){.field = NULL}; - } - } - } -} - -static void upb_util_FindUnsetRequiredInternal(upb_FindContext* ctx, - const upb_Message* msg, - const upb_MessageDef* m) { - // OPT: add markers in the schema for where we can avoid iterating: - // 1. messages with no required fields. - // 2. messages that cannot possibly reach any required fields. - - upb_util_FindUnsetInMessage(ctx, msg, m); - if (!msg) return; - - // Iterate over all present fields to find sub-messages that might be missing - // required fields. This may revisit some of the fields already inspected - // in the previous loop. We do this separately because this loop will also - // find present extensions, which the previous loop will not. - // - // TODO: consider changing upb_Message_Next() to be capable of - // visiting extensions only, for example with a kUpb_Message_BeginEXT - // constant. - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; - while (upb_Message_Next(msg, m, ctx->ext_pool, &f, &val, &iter)) { - // Skip non-submessage fields. - if (!upb_FieldDef_IsSubMessage(f)) continue; - - upb_FindContext_Push(ctx, (upb_FieldPathEntry){.field = f}); - const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); - - if (upb_FieldDef_IsMap(f)) { - // Map field. - const upb_FieldDef* val_f = upb_MessageDef_Field(sub_m, 1); - const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f); - if (!val_m) continue; - const upb_Map* map = val.map_val; - size_t iter = kUpb_Map_Begin; - upb_MessageValue key, map_val; - while (upb_Map_Next(map, &key, &map_val, &iter)) { - upb_FindContext_Push(ctx, (upb_FieldPathEntry){.map_key = key}); - upb_util_FindUnsetRequiredInternal(ctx, map_val.msg_val, val_m); - upb_FindContext_Pop(ctx); - } - } else if (upb_FieldDef_IsRepeated(f)) { - // Repeated field. - const upb_Array* arr = val.array_val; - for (size_t i = 0, n = upb_Array_Size(arr); i < n; i++) { - upb_MessageValue elem = upb_Array_Get(arr, i); - upb_FindContext_Push(ctx, (upb_FieldPathEntry){.array_index = i}); - upb_util_FindUnsetRequiredInternal(ctx, elem.msg_val, sub_m); - upb_FindContext_Pop(ctx); - } - } else { - // Scalar sub-message field. - upb_util_FindUnsetRequiredInternal(ctx, val.msg_val, sub_m); - } - - upb_FindContext_Pop(ctx); - } -} - -bool upb_util_HasUnsetRequired(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, - upb_FieldPathEntry** fields) { - upb_FindContext ctx; - ctx.has_unset_required = false; - ctx.save_paths = fields != NULL; - ctx.ext_pool = ext_pool; - upb_FieldPathVector_Init(&ctx.stack); - upb_FieldPathVector_Init(&ctx.out_fields); - upb_util_FindUnsetRequiredInternal(&ctx, msg, m); - upb_gfree(ctx.stack.path); - - if (ctx.has_unset_required && fields) { - upb_FieldPathVector_Reserve(&ctx, &ctx.out_fields, 1); - ctx.out_fields.path[ctx.out_fields.size] = - (upb_FieldPathEntry){.field = NULL}; - *fields = ctx.out_fields.path; - } - - return ctx.has_unset_required; -} diff --git a/vendor/upb/util/required_fields.h b/vendor/upb/util/required_fields.h deleted file mode 100644 index 1e6bb9a..0000000 --- a/vendor/upb/util/required_fields.h +++ /dev/null @@ -1,76 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_UTIL_REQUIRED_FIELDS_H_ -#define UPB_UTIL_REQUIRED_FIELDS_H_ - -#include - -#include "upb/reflection/def.h" -#include "upb/reflection/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// A FieldPath can be encoded as an array of upb_FieldPathEntry, in the -// following format: -// { {.field = f1}, {.field = f2} } # f1.f2 -// { {.field = f1}, {.index = 5}, {.field = f2} } # f1[5].f2 -// { {.field = f1}, {.key = "abc"}, {.field = f2} } # f1["abc"].f2 -// -// Users must look at the type of `field` to know if an index or map key -// follows. -// -// A field path may be NULL-terminated, in which case a NULL field indicates -// the end of the field path. -typedef union { - const upb_FieldDef* field; - size_t array_index; - upb_MessageValue map_key; -} upb_FieldPathEntry; - -// Writes a string representing `*path` to `buf` in the following textual -// format: -// foo.bar # Regular fields -// repeated_baz[2].bar # Repeated field -// int32_msg_map[5].bar # Integer-keyed map -// string_msg_map["abc"] # String-keyed map -// bool_msg_map[true] # Bool-keyed map -// -// The input array `*path` must be NULL-terminated. The pointer `*path` will be -// updated to point to one past the terminating NULL pointer of the input array. -// -// The output buffer `buf` will always be NULL-terminated. If the output data -// (including NULL terminator) exceeds `size`, the result will be truncated. -// Returns the string length of the data we attempted to write, excluding the -// terminating NULL. -size_t upb_FieldPath_ToText(upb_FieldPathEntry** path, char* buf, size_t size); - -// Checks whether `msg` or any of its children has unset required fields, -// returning `true` if any are found. `msg` may be NULL, in which case the -// message will be treated as empty. -// -// When this function returns true, `fields` is updated (if non-NULL) to point -// to a heap-allocated array encoding the field paths of the required fields -// that are missing. Each path is terminated with {.field = NULL}, and a final -// {.field = NULL} terminates the list of paths. The caller is responsible for -// freeing this array. -bool upb_util_HasUnsetRequired(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, - upb_FieldPathEntry** fields); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_UTIL_REQUIRED_FIELDS_H_ */ diff --git a/vendor/upb/util/required_fields_editions_test.proto b/vendor/upb/util/required_fields_editions_test.proto deleted file mode 100644 index b0f4100..0000000 --- a/vendor/upb/util/required_fields_editions_test.proto +++ /dev/null @@ -1,28 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -edition = "2023"; - -package upb_util_2023_test; - -message EmptyMessage {} - -message HasRequiredField { - int32 required_int32 = 1 [features.field_presence = LEGACY_REQUIRED]; -} - -message TestRequiredFields { - EmptyMessage required_message = 1 [features.field_presence = LEGACY_REQUIRED]; - TestRequiredFields optional_message = 2; - repeated HasRequiredField repeated_message = 3; - map map_int32_message = 4; - map map_int64_message = 5; - map map_uint32_message = 6; - map map_uint64_message = 7; - map map_bool_message = 8; - map map_string_message = 9; -} diff --git a/vendor/upb/util/required_fields_test.cc b/vendor/upb/util/required_fields_test.cc deleted file mode 100644 index 7698cfb..0000000 --- a/vendor/upb/util/required_fields_test.cc +++ /dev/null @@ -1,223 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/util/required_fields.h" - -#include - -#include -#include "absl/strings/string_view.h" -#include "upb/base/status.hpp" -#include "upb/base/upcast.h" -#include "upb/json/decode.h" -#include "upb/mem/arena.h" -#include "upb/mem/arena.hpp" -#include "upb/reflection/common.h" -#include "upb/reflection/def.hpp" -#include "upb/util/required_fields_editions_test.upb.h" -#include "upb/util/required_fields_editions_test.upbdefs.h" -#include "upb/util/required_fields_test.upb.h" -#include "upb/util/required_fields_test.upbdefs.h" - -std::vector PathsToText(upb_FieldPathEntry* entry) { - std::vector ret; - char buf[1024]; // Larger than anything we'll use in this test. - while (entry->field) { - upb_FieldPathEntry* before = entry; - size_t len = upb_FieldPath_ToText(&entry, buf, sizeof(buf)); - EXPECT_LT(len, sizeof(buf)); - assert(len <= sizeof(buf)); - ret.push_back(buf); - - // Ensure that we can have a short buffer and that it will be - // NULL-terminated. - char shortbuf[4]; - size_t len2 = upb_FieldPath_ToText(&before, shortbuf, sizeof(shortbuf)); - EXPECT_EQ(len, len2); - EXPECT_EQ(ret.back().substr(0, sizeof(shortbuf) - 1), - std::string(shortbuf)); - } - return ret; -} - -template -class RequiredFieldsTest : public testing::Test { - public: - void CheckRequired(absl::string_view json, - const std::vector& missing) { - upb::Arena arena; - upb::DefPool defpool; - auto* test_msg = T::NewMessage(arena.ptr()); - upb::MessageDefPtr m = T::GetMessageDef(defpool.ptr()); - upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(test_msg), - m.ptr(), defpool.ptr(), 0, arena.ptr(), - status.ptr())) - << status.error_message(); - upb_FieldPathEntry* entries = nullptr; - EXPECT_EQ(!missing.empty(), - upb_util_HasUnsetRequired(UPB_UPCAST(test_msg), m.ptr(), - defpool.ptr(), &entries)); - if (entries) { - EXPECT_EQ(missing, PathsToText(entries)); - free(entries); - } - - // Verify that we can pass a NULL pointer to entries when we don't care - // about them. - EXPECT_EQ(!missing.empty(), - upb_util_HasUnsetRequired(UPB_UPCAST(test_msg), m.ptr(), - defpool.ptr(), nullptr)); - } -}; - -class Proto2Type { - public: - using MessageType = upb_util_test_TestRequiredFields; - static MessageType* NewMessage(upb_Arena* arena) { - return upb_util_test_TestRequiredFields_new(arena); - } - static upb::MessageDefPtr GetMessageDef(upb_DefPool* defpool) { - return upb::MessageDefPtr( - upb_util_test_TestRequiredFields_getmsgdef(defpool)); - } -}; - -class Edition2023Type { - public: - using MessageType = upb_util_2023_test_TestRequiredFields; - static MessageType* NewMessage(upb_Arena* arena) { - return upb_util_2023_test_TestRequiredFields_new(arena); - } - static upb::MessageDefPtr GetMessageDef(upb_DefPool* defpool) { - return upb::MessageDefPtr( - upb_util_2023_test_TestRequiredFields_getmsgdef(defpool)); - } -}; - -using MyTypes = ::testing::Types; -TYPED_TEST_SUITE(RequiredFieldsTest, MyTypes); - -// message HasRequiredField { -// required int32 required_int32 = 1; -// } -// -// message TestRequiredFields { -// required EmptyMessage required_message = 1; -// optional TestRequiredFields optional_message = 2; -// repeated HasRequiredField repeated_message = 3; -// map map_int32_message = 4; -// } -TYPED_TEST(RequiredFieldsTest, TestRequired) { - TestFixture::CheckRequired(R"json({})json", {"required_message"}); - TestFixture::CheckRequired(R"json({"required_message": {}})json", {}); - TestFixture::CheckRequired( - R"json( - { - "optional_message": {} - } - )json", - {"required_message", "optional_message.required_message"}); - - // Repeated field. - TestFixture::CheckRequired( - R"json( - { - "optional_message": { - "repeated_message": [ - {"required_int32": 1}, - {}, - {"required_int32": 2} - ] - } - } - )json", - {"required_message", "optional_message.required_message", - "optional_message.repeated_message[1].required_int32"}); - - // Int32 map key. - TestFixture::CheckRequired( - R"json( - { - "required_message": {}, - "map_int32_message": { - "1": {"required_int32": 1}, - "5": {}, - "9": {"required_int32": 1} - } - } - )json", - {"map_int32_message[5].required_int32"}); - - // Int64 map key. - TestFixture::CheckRequired( - R"json( - { - "required_message": {}, - "map_int64_message": { - "1": {"required_int32": 1}, - "5": {}, - "9": {"required_int32": 1} - } - } - )json", - {"map_int64_message[5].required_int32"}); - - // Uint32 map key. - TestFixture::CheckRequired( - R"json( - { - "required_message": {}, - "map_uint32_message": { - "1": {"required_int32": 1}, - "5": {}, - "9": {"required_int32": 1} - } - } - )json", - {"map_uint32_message[5].required_int32"}); - - // Uint64 map key. - TestFixture::CheckRequired( - R"json( - { - "required_message": {}, - "map_uint64_message": { - "1": {"required_int32": 1}, - "5": {}, - "9": {"required_int32": 1} - } - } - )json", - {"map_uint64_message[5].required_int32"}); - - // Bool map key. - TestFixture::CheckRequired( - R"json( - { - "required_message": {}, - "map_bool_message": { - "false": {"required_int32": 1}, - "true": {} - } - } - )json", - {"map_bool_message[true].required_int32"}); - - // String map key. - TestFixture::CheckRequired( - R"json( - { - "required_message": {}, - "map_string_message": { - "abc": {"required_int32": 1}, - "d\"ef": {} - } - } - )json", - {R"(map_string_message["d\"ef"].required_int32)"}); -} diff --git a/vendor/upb/util/required_fields_test.proto b/vendor/upb/util/required_fields_test.proto deleted file mode 100644 index 082802f..0000000 --- a/vendor/upb/util/required_fields_test.proto +++ /dev/null @@ -1,28 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -syntax = "proto2"; - -package upb_util_test; - -message EmptyMessage {} - -message HasRequiredField { - required int32 required_int32 = 1; -} - -message TestRequiredFields { - required EmptyMessage required_message = 1; - optional TestRequiredFields optional_message = 2; - repeated HasRequiredField repeated_message = 3; - map map_int32_message = 4; - map map_int64_message = 5; - map map_uint32_message = 6; - map map_uint64_message = 7; - map map_bool_message = 8; - map map_string_message = 9; -} diff --git a/vendor/upb/wire/BUILD b/vendor/upb/wire/BUILD deleted file mode 100644 index 92a46b3..0000000 --- a/vendor/upb/wire/BUILD +++ /dev/null @@ -1,312 +0,0 @@ -# Copyright (c) 2009-2021, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:cc_binary.bzl", "cc_binary") -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//bazel:proto_library.bzl", "proto_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS", "UPB_DEFAULT_FEATURES") -load("//upb/bazel:upb_proto_library.bzl", "upb_proto_library") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "decoder", - srcs = [ - "internal/decoder.c", - ], - hdrs = [ - "decode.h", - "internal/decoder.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//upb:__pkg__", - "//upb/wire/decode_fast:__subpackages__", - ], - deps = [ - ":eps_copy_input_stream", - "//third_party/utf8_range", - "//upb/base", - "//upb/mem", - "//upb/mem:internal", - "//upb/message", - "//upb/message:internal", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - ], -) - -cc_library( - name = "wire", - srcs = [ - "decode.c", - "encode.c", - "internal/constants.h", - ], - hdrs = [ - "decode.h", - "encode.h", - "internal/encoder.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":decoder", - ":eps_copy_input_stream", - ":reader", - ":writer", - "//third_party/utf8_range", - "//upb/base", - "//upb/base:internal", - "//upb/hash", - "//upb/mem", - "//upb/mem:internal", - "//upb/message", - "//upb/message:internal", - "//upb/message:iterator", - "//upb/message:types", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - ] + select({ - "//upb:fasttable_enabled_setting": [ - "//upb/wire/decode_fast:dispatch", - ], - "//conditions:default": [], - }), -) - -cc_test( - name = "decode_test", - srcs = ["decode_test.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":wire", - "//upb/mem", - "//upb/message", - "//upb/message:message_cc", - "//upb/mini_descriptor", - "//upb/mini_table", - "//upb/port", - "//upb/wire/decode_fast:combinations", - "//upb/wire/test_util:field_types", - "//upb/wire/test_util:make_mini_table", - "//upb/wire/test_util:wire_message", - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -proto_library( - name = "encode_test_proto", - srcs = ["encode_test.proto"], -) - -upb_proto_library( - name = "encode_test_upb_proto", - deps = [":encode_test_proto"], -) - -cc_test( - name = "encode_test", - srcs = ["encode_test.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":encode_test_upb_proto", - ":wire", - "//upb/base", - "//upb/mem", - "//upb/message", - "//upb/message:internal", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_binary( - name = "decode_benchmark", - testonly = True, - srcs = ["decode_benchmark.cc"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - deps = [ - ":wire", - "//upb/mem", - "//upb/message", - "//upb/mini_table", - "//upb/port", - "//upb/wire/decode_fast:combinations", - "//upb/wire/test_util:field_types", - "//upb/wire/test_util:make_mini_table", - "//upb/wire/test_util:wire_message", - "@abseil-cpp//absl/container:flat_hash_set", - "@google_benchmark//:benchmark_main", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_library( - name = "reader_internal", - hdrs = ["internal/reader.h"], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//upb:__pkg__"], - deps = [ - ":eps_copy_input_stream", - "//upb/port", - ], -) - -cc_library( - name = "reader", - srcs = ["reader.c"], - hdrs = [ - "reader.h", - "types.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":eps_copy_input_stream", - ":reader_internal", - "//upb/base:internal", - "//upb/port", - ], -) - -cc_library( - name = "writer", - hdrs = [ - "writer.h", - ], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//upb:__pkg__", - "//upb/message:__pkg__", - ], - deps = [ - "//upb/port", - ], -) - -cc_library( - name = "byte_size", - srcs = ["byte_size.c"], - hdrs = ["byte_size.h"], - visibility = ["//visibility:public"], - deps = [ - ":wire", - "//upb/mem", - "//upb/message", - "//upb/mini_table", - "//upb/port", - ], -) - -cc_test( - name = "byte_size_test", - srcs = ["byte_size_test.cc"], - deps = [ - ":byte_size", - "//upb/base", - "//upb/mem", - "//upb/mini_table", - "//upb/test:test_messages_proto2_upb_minitable", - "//upb/test:test_messages_proto2_upb_proto", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_library( - name = "eps_copy_input_stream_internal", - hdrs = ["internal/eps_copy_input_stream.h"], - visibility = [ - "//upb:__pkg__", - "//upb/wire/decode_fast:__subpackages__", - ], - deps = [ - "//upb/base", - "//upb/mem", - "//upb/port", - ], -) - -cc_library( - name = "eps_copy_input_stream", - srcs = ["eps_copy_input_stream.c"], - hdrs = ["eps_copy_input_stream.h"], - copts = UPB_DEFAULT_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//visibility:public"], - deps = [ - ":eps_copy_input_stream_internal", - "//upb/base", - "//upb/mem", - "//upb/port", - ], -) - -cc_test( - name = "eps_copy_input_stream_test", - srcs = ["eps_copy_input_stream_test.cc"], - deps = [ - ":eps_copy_input_stream", - "//upb/base", - "//upb/mem", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -filegroup( - name = "source_files", - srcs = glob( - [ - "**/*.c", - "**/*.h", - ], - ), - visibility = [ - "//python/dist:__pkg__", - "//upb/cmake:__pkg__", - ], -) - -filegroup( - name = "test_srcs", - srcs = glob( - [ - "**/*test.cc", - ], - ), - visibility = ["//upb:__pkg__"], -) - -filegroup( - name = "test_protos", - srcs = glob( - [ - "**/*.proto", - ], - ), - visibility = ["//upb:__pkg__"], -) diff --git a/vendor/upb/wire/byte_size.c b/vendor/upb/wire/byte_size.c deleted file mode 100644 index b35a186..0000000 --- a/vendor/upb/wire/byte_size.c +++ /dev/null @@ -1,37 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/byte_size.h" - -#include - -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" -#include "upb/wire/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -size_t upb_ByteSize(const upb_Message* msg, const upb_MiniTable* mt) { - upb_Arena* arena = upb_Arena_New(); - char* buf; - size_t res = 0; - - upb_Encode(msg, mt, 0, arena, &buf, &res); - - upb_Arena_Free(arena); - return res; -} - -#ifdef __cplusplus -} // extern "C" -#endif \ No newline at end of file diff --git a/vendor/upb/wire/byte_size.h b/vendor/upb/wire/byte_size.h deleted file mode 100644 index 4018d74..0000000 --- a/vendor/upb/wire/byte_size.h +++ /dev/null @@ -1,31 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_BYTE_SIZE_H_ -#define UPB_WIRE_BYTE_SIZE_H_ - -#include - -#include "upb/message/message.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API size_t upb_ByteSize(const upb_Message* msg, const upb_MiniTable* mt); - -#ifdef __cplusplus -} // extern "C" -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_BYTE_SIZE_H_ diff --git a/vendor/upb/wire/byte_size_test.cc b/vendor/upb/wire/byte_size_test.cc deleted file mode 100644 index ea4ffda..0000000 --- a/vendor/upb/wire/byte_size_test.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2024 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/byte_size.h" - -#include -#include "google/protobuf/test_messages_proto2.upb.h" -#include "google/protobuf/test_messages_proto2.upb_minitable.h" -#include "upb/base/upcast.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/message.h" - -namespace { -static const upb_MiniTable* kTestMiniTable = - &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init; - -TEST(ByteSizeTest, UnpopulatedMsg) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - auto res = upb_ByteSize(UPB_UPCAST(msg), kTestMiniTable); - EXPECT_EQ(res, 0); - upb_Arena_Free(arena); -} - -TEST(ByteSizeTest, PopulatedMsg) { - upb_Arena* arena = upb_Arena_New(); - protobuf_test_messages_proto2_TestAllTypesProto2* msg = - protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); - protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_int32(msg, 322); - auto res = upb_ByteSize(UPB_UPCAST(msg), kTestMiniTable); - EXPECT_EQ(res, 3); - upb_Arena_Free(arena); -} - -} // namespace diff --git a/vendor/upb/wire/decode.c b/vendor/upb/wire/decode.c deleted file mode 100644 index 0f987eb..0000000 --- a/vendor/upb/wire/decode.c +++ /dev/null @@ -1,1311 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/decode.h" - -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/error_handler.h" -#include "upb/base/internal/endian.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/map_entry.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/message.h" -#include "upb/wire/encode.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/constants.h" -#include "upb/wire/internal/decoder.h" -#include "upb/wire/reader.h" - -// Our awkward dance for including fasttable only when it is enabled. -#include "upb/port/def.inc" -#if UPB_FASTTABLE -#define UPB_INCLUDE_FAST_DECODE -#endif -#include "upb/port/undef.inc" - -#ifdef UPB_INCLUDE_FAST_DECODE -#include "upb/wire/decode_fast/dispatch.h" -#endif - -#undef UPB_INCLUDE_FAST_DECODE - -// Must be last. -#include "upb/port/def.inc" - -// A few fake field types for our tables. -enum { - kUpb_FakeFieldType_FieldNotFound = 0, - kUpb_FakeFieldType_MessageSetItem = 19, -}; - -// DecodeOp: an action to be performed for a wire-type/field-type combination. -enum { - // Special ops: we don't write data to regular fields for these. - kUpb_DecodeOp_UnknownField = -1, - kUpb_DecodeOp_MessageSetItem = -2, - - // Scalar-only ops. - kUpb_DecodeOp_Scalar1Byte = 0, - kUpb_DecodeOp_Scalar4Byte = 2, - kUpb_DecodeOp_Scalar8Byte = 3, - - // Scalar/repeated ops. - kUpb_DecodeOp_String = 4, - kUpb_DecodeOp_Bytes = 5, - kUpb_DecodeOp_SubMessage = 6, - - // Repeated-only ops (also see macros below). - kUpb_DecodeOp_PackedEnum = 13, -}; - -// For packed fields it is helpful to be able to recover the lg2 of the data -// size from the op. -#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ -#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - -typedef union { - bool bool_val; - uint32_t uint32_val; - uint64_t uint64_val; - uint32_t size; -} wireval; - -static void _upb_Decoder_AssumeEpsHasErrorHandler(upb_Decoder* d) { - UPB_ASSUME(upb_EpsCopyInputStream_HasErrorHandler(&d->input)); -} - -#define EPS(d) (_upb_Decoder_AssumeEpsHasErrorHandler(d), &(d)->input) - -static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = - arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; - if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( - arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } - return need_realloc; -} - -typedef struct { - const char* ptr; - uint64_t val; -} _upb_DecodeLongVarintReturn; - -// This is identical to _upb_Decoder_DecodeTag() except that the maximum value -// is INT32_MAX instead of UINT32_MAX. -UPB_FORCEINLINE -const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, - uint32_t* size) { - int sz; - ptr = upb_WireReader_ReadSize(ptr, &sz, EPS(d)); - *size = sz; - return ptr; -} - -static void _upb_Decoder_MungeInt32(wireval* val) { - if (!upb_IsLittleEndian()) { - /* The next stage will memcpy(dst, &val, 4) */ - val->uint32_val = val->uint64_val; - } -} - -static void _upb_Decoder_Munge(const upb_MiniTableField* field, wireval* val) { - switch (field->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Bool: - val->bool_val = val->uint64_val != 0; - break; - case kUpb_FieldType_SInt32: { - uint32_t n = val->uint64_val; - val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); - break; - } - case kUpb_FieldType_SInt64: { - uint64_t n = val->uint64_val; - val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); - break; - } - case kUpb_FieldType_Int32: - case kUpb_FieldType_UInt32: - _upb_Decoder_MungeInt32(val); - break; - case kUpb_FieldType_Enum: - UPB_UNREACHABLE(); - } -} - -static upb_Message* _upb_Decoder_NewSubMessage2(upb_Decoder* d, - const upb_MiniTable* subl, - const upb_MiniTableField* field, - upb_Message** target) { - UPB_ASSERT(subl); - upb_Message* msg = _upb_Message_New(subl, &d->arena); - if (!msg) upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - - *target = msg; - return msg; -} - -static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, - const upb_MiniTableField* field, - upb_Message** target) { - const upb_MiniTable* subl = upb_MiniTable_GetSubMessageTable(field); - return _upb_Decoder_NewSubMessage2(d, subl, field, target); -} - -static const char* _upb_Decoder_ReadString2(upb_Decoder* d, const char* ptr, - int size, upb_StringView* str, - bool validate_utf8) { - if (!_upb_Decoder_ReadString(d, &ptr, size, str, validate_utf8)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t expected_end_group) { - if (--d->depth < 0) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_MaxDepthExceeded); - } - ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl); - d->depth++; - if (d->end_group != expected_end_group) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); - } - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeSubMessage(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTableField* field, - size_t size) { - ptrdiff_t delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size); - const upb_MiniTable* subl = upb_MiniTable_GetSubMessageTable(field); - UPB_ASSERT(subl); - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t number) { - if (upb_EpsCopyInputStream_IsDone(EPS(d), &ptr)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); - } - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, number); - d->end_group = DECODE_NOGROUP; - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeKnownGroup(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTableField* field) { - const upb_MiniTable* subl = upb_MiniTable_GetSubMessageTable(field); - UPB_ASSERT(subl); - return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, - field->UPB_PRIVATE(number)); -} - -#define kUpb_Decoder_EncodeVarint32MaxSize 5 -static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - *(ptr++) = byte; - } while (val); - return ptr; -} - -UPB_FORCEINLINE -void _upb_Decoder_AddEnumValueToUnknown(upb_Decoder* d, upb_Message* msg, - const upb_MiniTableField* field, - wireval* val) { - // Unrecognized enum goes into unknown fields. - // For packed fields the tag could be arbitrarily far in the past, - // so we just re-encode the tag and value here. - const uint32_t tag = - ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; - upb_Message* unknown_msg = - field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension ? d->original_msg - : msg; - char buf[2 * kUpb_Decoder_EncodeVarint32MaxSize]; - char* end = buf; - end = upb_Decoder_EncodeVarint32(tag, end); - end = upb_Decoder_EncodeVarint32(val->uint64_val, end); - - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(unknown_msg, buf, end - buf, - &d->arena, kUpb_AddUnknown_Copy)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeFixedPacked(upb_Decoder* d, const char* ptr, - upb_Array* arr, wireval* val, - const upb_MiniTableField* field, - int lg2) { - upb_StringView sv; - ptr = upb_EpsCopyInputStream_ReadStringEphemeral(&d->input, ptr, val->size, - &sv); - if (!ptr) upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); - int mask = (1 << lg2) - 1; - if (UPB_UNLIKELY((val->size & mask) != 0 || ptr == NULL)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); - } - size_t count = val->size >> lg2; - if (count == 0) return ptr; - _upb_Decoder_Reserve(d, arr, count); - void* mem = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), - arr->UPB_PRIVATE(size) << lg2, void); - arr->UPB_PRIVATE(size) += count; - if (upb_IsLittleEndian()) { - memcpy(mem, sv.data, sv.size); - } else { - const char* src = sv.data; - const char* src_end = src + sv.size; - char* dst = mem; - if (lg2 == 2) { - for (; src < src_end; src += 4, dst += 4) { - uint32_t x; - memcpy(&x, src, 4); - x = upb_BigEndian32(x); - memcpy(dst, &x, 4); - } - } else { - UPB_ASSERT(lg2 == 3); - for (; src < src_end; src += 8, dst += 8) { - uint64_t x; - memcpy(&x, src, 8); - x = upb_BigEndian64(x); - memcpy(dst, &x, 8); - } - } - } - - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeVarintPacked(upb_Decoder* d, const char* ptr, - upb_Array* arr, wireval* val, - const upb_MiniTableField* field, - int lg2) { - int scale = 1 << lg2; - ptrdiff_t delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), - arr->UPB_PRIVATE(size) << lg2, void); - while (!upb_EpsCopyInputStream_IsDone(EPS(d), &ptr)) { - wireval elem; - ptr = upb_WireReader_ReadVarint(ptr, &elem.uint64_val, EPS(d)); - _upb_Decoder_Munge(field, &elem); - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), - arr->UPB_PRIVATE(size) << lg2, void); - } - arr->UPB_PRIVATE(size)++; - memcpy(out, &elem, scale); - out += scale; - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); - return ptr; -} - -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumPacked( - upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, - const upb_MiniTableField* field, wireval* val) { - const upb_MiniTableEnum* e = upb_MiniTable_GetSubEnumTable(field); - ptrdiff_t delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), - arr->UPB_PRIVATE(size) * 4, void); - while (!upb_EpsCopyInputStream_IsDone(EPS(d), &ptr)) { - wireval elem; - ptr = upb_WireReader_ReadVarint(ptr, &elem.uint64_val, EPS(d)); - if (!upb_MiniTableEnum_CheckValue(e, elem.uint64_val)) { - _upb_Decoder_AddEnumValueToUnknown(d, msg, field, &elem); - continue; - } - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), - arr->UPB_PRIVATE(size) * 4, void); - } - arr->UPB_PRIVATE(size)++; - memcpy(out, &elem, 4); - out += 4; - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); - return ptr; -} - -static upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTableField* field) { - const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); - upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); - if (!ret) upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - return ret; -} - -static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTableField* field, - wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); - upb_Array* arr = *arrp; - void* mem; - - if (arr) { - _upb_Decoder_Reserve(d, arr, 1); - } else { - arr = _upb_Decoder_CreateArray(d, field); - *arrp = arr; - } - - switch (op) { - case kUpb_DecodeOp_Scalar1Byte: - case kUpb_DecodeOp_Scalar4Byte: - case kUpb_DecodeOp_Scalar8Byte: - /* Append scalar value. */ - mem = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), - arr->UPB_PRIVATE(size) << op, void); - arr->UPB_PRIVATE(size)++; - memcpy(mem, val, 1 << op); - return ptr; - case kUpb_DecodeOp_String: { - /* Append string. */ - upb_StringView* str = (upb_StringView*)upb_Array_MutableDataPtr(arr) + - arr->UPB_PRIVATE(size); - ptr = _upb_Decoder_ReadString2(d, ptr, val->size, str, - /*validate_utf8=*/true); - arr->UPB_PRIVATE(size)++; - return ptr; - } - case kUpb_DecodeOp_Bytes: { - /* Append bytes. */ - upb_StringView* str = (upb_StringView*)upb_Array_MutableDataPtr(arr) + - arr->UPB_PRIVATE(size); - ptr = _upb_Decoder_ReadString2(d, ptr, val->size, str, - /*validate_utf8=*/false); - arr->UPB_PRIVATE(size)++; - return ptr; - } - case kUpb_DecodeOp_SubMessage: { - /* Append submessage / group. */ - upb_Message** target = - UPB_PTR_AT(upb_Array_MutableDataPtr(arr), - arr->UPB_PRIVATE(size) * sizeof(void*), upb_Message*); - upb_Message* submsg = _upb_Decoder_NewSubMessage(d, field, target); - arr->UPB_PRIVATE(size)++; - if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Group)) { - return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, field); - } else { - return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, field, val->size); - } - } - case OP_FIXPCK_LG2(2): - case OP_FIXPCK_LG2(3): - return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field, - op - OP_FIXPCK_LG2(0)); - case OP_VARPCK_LG2(0): - case OP_VARPCK_LG2(2): - case OP_VARPCK_LG2(3): - return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field, - op - OP_VARPCK_LG2(0)); - case kUpb_DecodeOp_PackedEnum: - return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, field, val); - default: - UPB_UNREACHABLE(); - } -} - -static upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, - const upb_MiniTable* entry) { - // Maps descriptor type -> upb map size - static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type - [kUpb_FieldType_Double] = 8, - [kUpb_FieldType_Float] = 4, - [kUpb_FieldType_Int64] = 8, - [kUpb_FieldType_UInt64] = 8, - [kUpb_FieldType_Int32] = 4, - [kUpb_FieldType_Fixed64] = 8, - [kUpb_FieldType_Fixed32] = 4, - [kUpb_FieldType_Bool] = 1, - [kUpb_FieldType_String] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_Group] = sizeof(void*), - [kUpb_FieldType_Message] = sizeof(void*), - [kUpb_FieldType_Bytes] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_UInt32] = 4, - [kUpb_FieldType_Enum] = 4, - [kUpb_FieldType_SFixed32] = 4, - [kUpb_FieldType_SFixed64] = 8, - [kUpb_FieldType_SInt32] = 4, - [kUpb_FieldType_SInt64] = 8, - }; - - const upb_MiniTableField* key_field = &entry->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; - char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; - char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; - UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntry, k)); - UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntry, v)); - upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); - if (!ret) upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - return ret; -} - -UPB_NOINLINE static void _upb_Decoder_AddMapEntryUnknown( - upb_Decoder* d, upb_Message* msg, const upb_MiniTableField* field, - upb_Message* ent_msg, const upb_MiniTable* entry) { - char* buf; - size_t size; - upb_EncodeStatus status = - upb_Encode(ent_msg, entry, 0, &d->arena, &buf, &size); - if (status != kUpb_EncodeStatus_Ok) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } - char delim_buf[2 * kUpb_Decoder_EncodeVarint32MaxSize]; - char* delim_end = delim_buf; - uint32_t tag = - ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; - delim_end = upb_Decoder_EncodeVarint32(tag, delim_end); - delim_end = upb_Decoder_EncodeVarint32(size, delim_end); - upb_StringView unknown[] = { - {delim_buf, delim_end - delim_buf}, - {buf, size}, - }; - - if (!UPB_PRIVATE(_upb_Message_AddUnknownV)(msg, &d->arena, unknown, 2)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } -} - -static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTableField* field, - wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); - upb_Map* map = *map_p; - upb_MapEntry ent; - UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); - const upb_MiniTable* entry = upb_MiniTable_GetSubMessageTable(field); - - UPB_ASSERT(entry); - UPB_ASSERT(entry->UPB_PRIVATE(field_count) == 2); - UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[0])); - UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[1])); - - if (!map) { - map = _upb_Decoder_CreateMap(d, entry); - *map_p = map; - } - - // Parse map entry. - memset(&ent, 0, sizeof(ent)); - - bool value_is_message = - entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Message || - entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Group; - const upb_MiniTable* sub_table = - value_is_message - ? upb_MiniTable_GetSubMessageTable(&entry->UPB_PRIVATE(fields)[1]) - : NULL; - upb_Message* sub_msg = NULL; - - if (sub_table) { - // Create proactively to handle the case where it doesn't appear. - _upb_Decoder_NewSubMessage(d, &entry->UPB_PRIVATE(fields)[1], &sub_msg); - ent.v.val = upb_value_ptr(sub_msg); - } - - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, &ent.message, field, val->size); - - if (sub_msg && sub_table->UPB_PRIVATE(required_count)) { - // If the map entry did not contain a value on the wire, `sub_msg` is an - // empty message; we must check if it is missing any required fields. If the - // value was present, this check is redundant but harmless. - _upb_Decoder_CheckRequired(d, ptr, sub_msg, sub_table); - } - - if (upb_Message_HasUnknown(&ent.message)) { - _upb_Decoder_AddMapEntryUnknown(d, msg, field, &ent.message, entry); - } else { - if (_upb_Map_Insert(map, &ent.k, map->key_size, &ent.v, map->val_size, - &d->arena) == kUpb_MapInsertStatus_OutOfMemory) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } - } - return ptr; -} - -static const char* _upb_Decoder_DecodeToSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTableField* field, wireval* val, int op) { - void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); - int type = field->UPB_PRIVATE(descriptortype); - - // Set presence if necessary. - if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(field)) { - UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - // Oneof case - uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (op == kUpb_DecodeOp_SubMessage && - *oneof_case != field->UPB_PRIVATE(number)) { - memset(mem, 0, sizeof(void*)); - } - *oneof_case = field->UPB_PRIVATE(number); - } - - // Store into message. - switch (op) { - case kUpb_DecodeOp_SubMessage: { - upb_Message** submsgp = mem; - upb_Message* submsg = *submsgp; - if (!submsg) submsg = _upb_Decoder_NewSubMessage(d, field, submsgp); - if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { - ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, field); - } else { - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, field, val->size); - } - break; - } - case kUpb_DecodeOp_String: - return _upb_Decoder_ReadString2(d, ptr, val->size, mem, - /*validate_utf8=*/true); - case kUpb_DecodeOp_Bytes: - return _upb_Decoder_ReadString2(d, ptr, val->size, mem, - /*validate_utf8=*/false); - case kUpb_DecodeOp_Scalar8Byte: - memcpy(mem, val, 8); - break; - case kUpb_DecodeOp_Scalar4Byte: - memcpy(mem, val, 4); - break; - case kUpb_DecodeOp_Scalar1Byte: - memcpy(mem, val, 1); - break; - default: - UPB_UNREACHABLE(); - } - - return ptr; -} - -enum { - kStartItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_StartGroup), - kEndItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_EndGroup), - kTypeIdTag = ((kUpb_MsgSet_TypeId << 3) | kUpb_WireType_Varint), - kMessageTag = ((kUpb_MsgSet_Message << 3) | kUpb_WireType_Delimited), -}; - -static void upb_Decoder_AddKnownMessageSetItem( - upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, - const char* data, uint32_t size) { - upb_Extension* ext = - UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(msg, item_mt, &d->arena); - if (UPB_UNLIKELY(!ext)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } - upb_Message** submsgp = (upb_Message**)&ext->data.msg_val; - upb_Message* submsg = _upb_Decoder_NewSubMessage2( - d, ext->ext->UPB_PRIVATE(sub).UPB_PRIVATE(submsg), - &ext->ext->UPB_PRIVATE(field), submsgp); - // upb_Decode_LimitDepth() takes uint32_t, d->depth - 1 can not be negative. - if (d->depth <= 1) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_MaxDepthExceeded); - } - upb_DecodeStatus status = upb_Decode( - data, size, submsg, upb_MiniTableExtension_GetSubMessage(item_mt), - d->extreg, upb_Decode_LimitDepth(d->options, d->depth - 1), &d->arena); - if (status != kUpb_DecodeStatus_Ok) { - upb_ErrorHandler_ThrowError(d->err, status); - } -} - -static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, - upb_Message* msg, - uint32_t type_id, - const char* message_data, - uint32_t message_size) { - char buf[6 * kUpb_Decoder_EncodeVarint32MaxSize]; - char* ptr = buf; - ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); - ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); - ptr = upb_Decoder_EncodeVarint32(type_id, ptr); - ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); - ptr = upb_Decoder_EncodeVarint32(message_size, ptr); - char* split = ptr; - - ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); - char* end = ptr; - upb_StringView unknown[] = { - {buf, split - buf}, - {message_data, message_size}, - {split, end - split}, - }; - if (!UPB_PRIVATE(_upb_Message_AddUnknownV)(msg, &d->arena, unknown, 3)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } -} - -static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, - const upb_MiniTable* t, - uint32_t type_id, const char* data, - uint32_t size) { - const upb_MiniTableExtension* item_mt = - upb_ExtensionRegistry_Lookup(d->extreg, t, type_id); - if (item_mt) { - upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); - } else { - upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); - } -} - -static const char* upb_Decoder_DecodeMessageSetItem( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout) { - uint32_t type_id = 0; - upb_StringView preserved = {NULL, 0}; - typedef enum { - kUpb_HaveId = 1 << 0, - kUpb_HavePayload = 1 << 1, - } StateMask; - StateMask state_mask = 0; - while (!upb_EpsCopyInputStream_IsDone(EPS(d), &ptr)) { - uint32_t tag; - ptr = upb_WireReader_ReadTag(ptr, &tag, EPS(d)); - switch (tag) { - case kEndItemTag: - return ptr; - case kTypeIdTag: { - uint64_t tmp; - ptr = upb_WireReader_ReadVarint(ptr, &tmp, EPS(d)); - if (state_mask & kUpb_HaveId) break; // Ignore dup. - state_mask |= kUpb_HaveId; - type_id = tmp; - if (state_mask & kUpb_HavePayload) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, - preserved.size); - } - break; - } - case kMessageTag: { - uint32_t size; - upb_StringView sv; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - ptr = upb_EpsCopyInputStream_ReadStringAlwaysAlias(&d->input, ptr, size, - &sv); - if (!ptr) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); - } - if (state_mask & kUpb_HavePayload) break; // Ignore dup. - state_mask |= kUpb_HavePayload; - if (state_mask & kUpb_HaveId) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, sv.data, - sv.size); - } else { - // Out of order, we must preserve the payload. - preserved = sv; - } - break; - } - default: - // We do not preserve unexpected fields inside a message set item. - ptr = _upb_WireReader_SkipValue(ptr, tag, d->depth, &d->input); - break; - } - } - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); -} - -static upb_MiniTableField upb_Decoder_FieldNotFoundField = { - 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; - -UPB_NOINLINE const upb_MiniTableField* _upb_Decoder_FindExtensionField( - upb_Decoder* d, const upb_MiniTable* t, uint32_t field_number, int ext_mode, - uint32_t wire_type) { - // Treat a message set as an extendable message if it is a delimited field. - // This provides compatibility with encoders that are unaware of message - // sets and serialize them as normal extensions. - if (ext_mode == kUpb_ExtMode_Extendable || - (ext_mode == kUpb_ExtMode_IsMessageSet && - wire_type == kUpb_WireType_Delimited)) { - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); - if (ext) return &ext->UPB_PRIVATE(field); - } else if (ext_mode == kUpb_ExtMode_IsMessageSet) { - if (field_number == kUpb_MsgSet_Item) { - static upb_MiniTableField item = { - 0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0}; - return &item; - } - } - return &upb_Decoder_FieldNotFoundField; -} - -static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, - const upb_MiniTable* t, - uint32_t field_number, - uint32_t wire_type) { - UPB_ASSERT(t); - const upb_MiniTableField* field = - upb_MiniTable_FindFieldByNumber(t, field_number); - if (field) return field; - - if (d->extreg && t->UPB_PRIVATE(ext)) { - return _upb_Decoder_FindExtensionField(d, t, field_number, - t->UPB_PRIVATE(ext), wire_type); - } - - return &upb_Decoder_FieldNotFoundField; // Unknown field. -} - -static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { - static const int8_t kVarintOps[] = { - [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_Scalar1Byte, - [kUpb_FieldType_String] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - }; - - return kVarintOps[field->UPB_PRIVATE(descriptortype)]; -} - -UPB_FORCEINLINE -void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field, int* op) { - // If sub-message is not linked, treat as unknown. - if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return; - const upb_MiniTable* mt_sub = upb_MiniTable_GetSubMessageTable(field); - if (mt_sub != NULL) return; // Normal case, sub-message is linked. -#ifndef NDEBUG - const upb_MiniTableField* oneof = upb_MiniTable_GetOneof(mt, field); - if (oneof) { - // All other members of the oneof must be message fields that are also - // unlinked. - do { - UPB_ASSERT(upb_MiniTableField_CType(oneof) == kUpb_CType_Message); - const upb_MiniTable* oneof_sub = upb_MiniTable_GetSubMessageTable(oneof); - UPB_ASSERT(!oneof_sub); - } while (upb_MiniTable_NextOneofField(mt, &oneof)); - } -#endif // NDEBUG - *op = kUpb_DecodeOp_UnknownField; -} - -UPB_FORCEINLINE -void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d, - const upb_MiniTableField* field, int* op) { - UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bytes); - if (_upb_Decoder_FieldRequiresUtf8Validation(d, field)) { - *op = kUpb_DecodeOp_String; - } -} - -static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field) { - enum { kRepeatedBase = 19 }; - - static const int8_t kDelimitedOps[] = { - // For non-repeated field type. - [kUpb_FakeFieldType_FieldNotFound] = - kUpb_DecodeOp_UnknownField, // Field not found. - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_SubMessage, - // For repeated field type. - [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_UInt64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Int32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Fixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Fixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Bool] = OP_VARPCK_LG2(0), - [kRepeatedBase + kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kRepeatedBase + kUpb_FieldType_Group] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kRepeatedBase + kUpb_FieldType_UInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Enum] = kUpb_DecodeOp_PackedEnum, - [kRepeatedBase + kUpb_FieldType_SFixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SFixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_SInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SInt64] = OP_VARPCK_LG2(3), - // Omitting kUpb_FakeFieldType_MessageSetItem, because we never emit a - // repeated msgset type - }; - - int ndx = field->UPB_PRIVATE(descriptortype); - if (upb_MiniTableField_IsArray(field)) ndx += kRepeatedBase; - int op = kDelimitedOps[ndx]; - - if (op == kUpb_DecodeOp_SubMessage) { - _upb_Decoder_CheckUnlinked(d, mt, field, &op); - } else if (op == kUpb_DecodeOp_Bytes) { - _upb_Decoder_MaybeVerifyUtf8(d, field, &op); - } - - return op; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, - const upb_MiniTable* mt, - const upb_MiniTableField* field, - uint32_t wire_type, wireval* val, - int* op) { - static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | - (1 << kUpb_FieldType_Fixed32) | - (1 << kUpb_FieldType_SFixed32); - - static const unsigned kFixed64OkMask = (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Fixed64) | - (1 << kUpb_FieldType_SFixed64); - - switch (wire_type) { - case kUpb_WireType_Varint: - ptr = upb_WireReader_ReadVarint(ptr, &val->uint64_val, EPS(d)); - if (upb_MiniTableField_IsClosedEnum(field)) { - const upb_MiniTableEnum* e = upb_MiniTable_GetSubEnumTable(field); - if (!upb_MiniTableEnum_CheckValue(e, val->uint64_val)) { - *op = kUpb_DecodeOp_UnknownField; - return ptr; - } - _upb_Decoder_MungeInt32(val); - } else { - _upb_Decoder_Munge(field, val); - } - *op = _upb_Decoder_GetVarintOp(field); - return ptr; - case kUpb_WireType_32Bit: - *op = kUpb_DecodeOp_Scalar4Byte; - if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed32OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return upb_WireReader_ReadFixed32(ptr, &val->uint32_val, &d->input); - case kUpb_WireType_64Bit: - *op = kUpb_DecodeOp_Scalar8Byte; - if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed64OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return upb_WireReader_ReadFixed64(ptr, &val->uint64_val, &d->input); - case kUpb_WireType_Delimited: - ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); - *op = _upb_Decoder_GetDelimitedOp(d, mt, field); - return ptr; - case kUpb_WireType_StartGroup: - val->uint32_val = field->UPB_PRIVATE(number); - if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group) { - *op = kUpb_DecodeOp_SubMessage; - _upb_Decoder_CheckUnlinked(d, mt, field, op); - } else if (field->UPB_PRIVATE(descriptortype) == - kUpb_FakeFieldType_MessageSetItem) { - *op = kUpb_DecodeOp_MessageSetItem; - } else { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr; - default: - break; - } - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeKnownField(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTableField* field, - int op, wireval* val) { - uint8_t mode = field->UPB_PRIVATE(mode); - - if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { - const upb_MiniTableExtension* ext_layout = - (const upb_MiniTableExtension*)field; - upb_Extension* ext = UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( - msg, ext_layout, &d->arena); - if (UPB_UNLIKELY(!ext)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } - d->original_msg = msg; - msg = &ext->data.UPB_PRIVATE(ext_msg_val); - } - - switch (mode & kUpb_FieldMode_Mask) { - case kUpb_FieldMode_Array: - return _upb_Decoder_DecodeToArray(d, ptr, msg, field, val, op); - case kUpb_FieldMode_Map: - return _upb_Decoder_DecodeToMap(d, ptr, msg, field, val); - case kUpb_FieldMode_Scalar: - return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, field, val, op); - default: - UPB_UNREACHABLE(); - } -} - -static const char* _upb_Decoder_DecodeUnknownField( - upb_Decoder* d, const char* ptr, upb_Message* msg, uint32_t field_number, - uint32_t wire_type, wireval val, const char* start) { - if (field_number == 0) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); - } - - upb_EpsCopyInputStream_StartCapture(&d->input, start); - - if (wire_type == kUpb_WireType_Delimited) { - upb_StringView sv; - ptr = upb_EpsCopyInputStream_ReadStringEphemeral(&d->input, ptr, val.size, - &sv); - if (!ptr) upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_Malformed); - } else if (wire_type == kUpb_WireType_StartGroup) { - ptr = UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, field_number << 3, - d->depth, &d->input); - } - - upb_StringView sv; - upb_EpsCopyInputStream_EndCapture(&d->input, ptr, &sv); - - upb_AddUnknownMode mode = kUpb_AddUnknown_Copy; - if (d->options & kUpb_DecodeOption_AliasString) { - if (sv.data != d->input.buffer_start) { - // If the data is not from the beginning of the input buffer, then we can - // safely attempt to coalesce this region with the previous one. - mode = kUpb_AddUnknown_AliasAllowMerge; - } else { - mode = kUpb_AddUnknown_Alias; - } - } - - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, sv.data, sv.size, &d->arena, - mode)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_OutOfMemory); - } - - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeFieldTag(upb_Decoder* d, const char* ptr, - uint32_t* field_number, - uint32_t* wire_type) { - uint32_t tag; - UPB_ASSERT(ptr < d->input.limit_ptr); - ptr = upb_WireReader_ReadTag(ptr, &tag, EPS(d)); - *field_number = tag >> 3; - *wire_type = tag & 7; - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeFieldData( - upb_Decoder* d, const char* ptr, upb_Message* msg, const upb_MiniTable* mt, - uint32_t field_number, uint32_t wire_type, const char* start) { - int op; - wireval val; - - const upb_MiniTableField* field = - _upb_Decoder_FindField(d, mt, field_number, wire_type); - ptr = _upb_Decoder_DecodeWireValue(d, ptr, mt, field, wire_type, &val, &op); - - if (op >= 0) { - return _upb_Decoder_DecodeKnownField(d, ptr, msg, field, op, &val); - } else { - switch (op) { - case kUpb_DecodeOp_UnknownField: - return _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number, - wire_type, val, start); - case kUpb_DecodeOp_MessageSetItem: - return upb_Decoder_DecodeMessageSetItem(d, ptr, msg, mt); - default: - UPB_UNREACHABLE(); - } - } -} - -static const char* _upb_Decoder_EndMessage(upb_Decoder* d, const char* ptr) { - d->message_is_done = true; - return ptr; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeFieldNoFast(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* mt) { - uint32_t field_number; - uint32_t wire_type; - - const char* start = ptr; - ptr = _upb_Decoder_DecodeFieldTag(d, ptr, &field_number, &wire_type); - - if (wire_type == kUpb_WireType_EndGroup) { - d->end_group = field_number; - return _upb_Decoder_EndMessage(d, ptr); - } - - ptr = _upb_Decoder_DecodeFieldData(d, ptr, msg, mt, field_number, wire_type, - start); - _upb_Decoder_Trace(d, 'M'); - return ptr; -} - -UPB_FORCEINLINE -bool _upb_Decoder_TryDecodeMessageFast(upb_Decoder* d, const char** ptr, - upb_Message* msg, - const upb_MiniTable* mt, - uint64_t last_field_index, - uint64_t data) { -#ifdef UPB_ENABLE_FASTTABLE - if (mt->UPB_PRIVATE(table_mask) == (unsigned char)-1 || - (d->options & kUpb_DecodeOption_DisableFastTable)) { - // Fast table is unavailable or disabled. - return false; - } - - intptr_t table = decode_totable(mt); - const char* start = - UPB_PRIVATE(upb_EpsCopyInputStream_GetInputPtr)(&d->input, *ptr); - char* trace_next = _upb_Decoder_TraceNext(d); - - *ptr = upb_DecodeFast_Dispatch(d, *ptr, msg, table, 0, 0); - - if (d->message_is_done) { - // The entire message was successfully parsed fast. - return true; - } - - // *ptr now points to the beginning of a field that could not be parsed fast. - // It's possible that some fields were parsed fast, in which case *ptr will - // have been updated. However, it's also possible that the very first field - // encountered could not be parsed fast, in which case *ptr will be unchanged. - // - // If the fast decoder consumed any data, it must have emitted at least - // one 'F' event into the trace buffer (in addition to the 'D' event - // that is always emitted). - const char* end = - UPB_PRIVATE(upb_EpsCopyInputStream_GetInputPtr)(&d->input, *ptr); - char* trace_end = _upb_Decoder_TracePtr(d); - UPB_ASSERT(trace_end == NULL || trace_end != trace_next || end == start); - _upb_Decoder_Trace(d, '<'); -#endif - return false; -} - -UPB_FORCEINLINE -const char* _upb_Decoder_DecodeField(upb_Decoder* d, const char* ptr, - upb_Message* msg, const upb_MiniTable* mt, - uint64_t last_field_index, uint64_t data) { - if (_upb_Decoder_TryDecodeMessageFast(d, &ptr, msg, mt, last_field_index, - data)) { - return ptr; - } else if (upb_EpsCopyInputStream_IsDone(EPS(d), &ptr)) { - return _upb_Decoder_EndMessage(d, ptr); - } - - return _upb_Decoder_DecodeFieldNoFast(d, ptr, msg, mt); -} - -UPB_NOINLINE -const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* mt) { - UPB_ASSERT(mt); - UPB_ASSERT(d->message_is_done == false); - - do { - ptr = _upb_Decoder_DecodeField(d, ptr, msg, mt, 0, 0); - } while (!d->message_is_done); - d->message_is_done = false; - - return UPB_UNLIKELY(mt && mt->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, mt) - : ptr; -} - -static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d, - const char* buf, - upb_Message* msg, - const upb_MiniTable* m) { - _upb_Decoder_DecodeMessage(d, buf, msg, m); - if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; - if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; - return kUpb_DecodeStatus_Ok; -} - -static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, - const char* const buf, - upb_Message* const msg, - const upb_MiniTable* const m, - upb_Arena* const arena) { - if (UPB_SETJMP(decoder->err->buf) == 0) { - decoder->err->code = _upb_Decoder_DecodeTop(decoder, buf, msg, m); - } else { - UPB_ASSERT(decoder->err->code != kUpb_DecodeStatus_Ok); - } - - return upb_Decoder_Destroy(decoder, arena); -} - -static uint16_t upb_DecodeOptions_GetMaxDepth(uint32_t options) { - return options >> 16; -} - -uint16_t upb_DecodeOptions_GetEffectiveMaxDepth(uint32_t options) { - uint16_t max_depth = upb_DecodeOptions_GetMaxDepth(options); - return max_depth ? max_depth : kUpb_WireFormat_DefaultDepthLimit; -} - -upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, - const upb_MiniTable* mt, - const upb_ExtensionRegistry* extreg, int options, - upb_Arena* arena) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Decoder decoder; - upb_ErrorHandler err; - upb_ErrorHandler_Init(&err); - buf = upb_Decoder_Init(&decoder, buf, size, extreg, options, arena, &err, - NULL, 0); - - return upb_Decoder_Decode(&decoder, buf, msg, mt, arena); -} - -upb_DecodeStatus upb_DecodeWithTrace(const char* buf, size_t size, - upb_Message* msg, const upb_MiniTable* mt, - const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena, - char* trace_buf, size_t trace_size) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - upb_Decoder decoder; - upb_ErrorHandler err; - upb_ErrorHandler_Init(&err); - buf = upb_Decoder_Init(&decoder, buf, size, extreg, options, arena, &err, - trace_buf, trace_size); - - return upb_Decoder_Decode(&decoder, buf, msg, mt, arena); -} - -upb_DecodeStatus upb_DecodeLengthPrefixed(const char* buf, size_t size, - upb_Message* msg, - size_t* num_bytes_read, - const upb_MiniTable* mt, - const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena) { - // To avoid needing to make a Decoder just to decode the initial length, - // hand-decode the leading varint for the message length here. - uint64_t msg_len = 0; - for (size_t i = 0;; ++i) { - if (i >= size || i > 9) { - return kUpb_DecodeStatus_Malformed; - } - uint64_t b = *buf; - buf++; - msg_len += (b & 0x7f) << (i * 7); - if ((b & 0x80) == 0) { - *num_bytes_read = i + 1 + msg_len; - break; - } - } - - // If the total number of bytes we would read (= the bytes from the varint - // plus however many bytes that varint says we should read) is larger then the - // input buffer then error as malformed. - if (*num_bytes_read > size) { - return kUpb_DecodeStatus_Malformed; - } - if (msg_len > INT32_MAX) { - return kUpb_DecodeStatus_Malformed; - } - - return upb_Decode(buf, msg_len, msg, mt, extreg, options, arena); -} - -const char* upb_DecodeStatus_String(upb_DecodeStatus status) { - switch (status) { - case kUpb_DecodeStatus_Ok: - return "Ok"; - case kUpb_DecodeStatus_Malformed: - return "Wire format was corrupt"; - case kUpb_DecodeStatus_OutOfMemory: - return "Arena alloc failed"; - case kUpb_DecodeStatus_BadUtf8: - return "String field had bad UTF-8"; - case kUpb_DecodeStatus_MaxDepthExceeded: - return "Exceeded upb_DecodeOptions_MaxDepth"; - case kUpb_DecodeStatus_MissingRequired: - return "Missing required field"; - default: - return "Unknown decode status"; - } -} - -#undef OP_FIXPCK_LG2 -#undef OP_VARPCK_LG2 diff --git a/vendor/upb/wire/decode.h b/vendor/upb/wire/decode.h deleted file mode 100644 index e11da1a..0000000 --- a/vendor/upb/wire/decode.h +++ /dev/null @@ -1,126 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// upb_decode: parsing into a upb_Message using a upb_MiniTable. - -#ifndef UPB_WIRE_DECODE_H_ -#define UPB_WIRE_DECODE_H_ - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// LINT.IfChange -enum { - /* If set, strings and unknown fields will alias the input buffer instead of - * copying into the arena. */ - kUpb_DecodeOption_AliasString = 1, - - /* If set, the parse will return failure if any message is missing any - * required fields when the message data ends. The parse will still continue, - * and the failure will only be reported at the end. - * - * IMPORTANT CAVEATS: - * - * 1. This can throw a false positive failure if an incomplete message is seen - * on the wire but is later completed when the sub-message occurs again. - * For this reason, a second pass is required to verify a failure, to be - * truly robust. - * - * 2. This can return a false success if you are decoding into a message that - * already has some sub-message fields present. If the sub-message does - * not occur in the binary payload, we will never visit it and discover the - * incomplete sub-message. For this reason, this check is only useful for - * implementing ParseFromString() semantics. For MergeFromString(), a - * post-parse validation step will always be necessary. */ - kUpb_DecodeOption_CheckRequired = 2, - - /* EXPERIMENTAL: - * - * If set, decoding will enforce UTF-8 validation for string fields, even for - * proto2 or fields with `features.utf8_validation = NONE`. Normally, only - * proto3 string fields will be validated for UTF-8. Decoding will return - * kUpb_DecodeStatus_BadUtf8 for non-UTF-8 strings, which is the same behavior - * as non-UTF-8 proto3 string fields. - */ - kUpb_DecodeOption_AlwaysValidateUtf8 = 8, - - /* EXPERIMENTAL: - * - * If set, the fasttable decoder will not be used. */ - kUpb_DecodeOption_DisableFastTable = 16, -}; -// LINT.ThenChange(//depot/google3/third_party/upb/rust/wire.rs:decode_status) - -UPB_INLINE uint32_t upb_DecodeOptions_MaxDepth(uint16_t depth) { - return (uint32_t)depth << 16; -} - -uint16_t upb_DecodeOptions_GetEffectiveMaxDepth(uint32_t options); - -// Enforce an upper bound on recursion depth. -UPB_INLINE int upb_Decode_LimitDepth(uint32_t decode_options, uint32_t limit) { - uint32_t max_depth = upb_DecodeOptions_GetEffectiveMaxDepth(decode_options); - if (max_depth > limit) max_depth = limit; - return (int)(upb_DecodeOptions_MaxDepth(max_depth) | - (decode_options & 0xffff)); -} - -// LINT.IfChange -typedef enum { - kUpb_DecodeStatus_Ok = 0, - kUpb_DecodeStatus_OutOfMemory = 1, // Arena alloc failed - kUpb_DecodeStatus_Malformed = 2, // Wire format was corrupt - kUpb_DecodeStatus_BadUtf8 = 3, // String field had bad UTF-8 - kUpb_DecodeStatus_MaxDepthExceeded = - 4, // Exceeded upb_DecodeOptions_MaxDepth - - // kUpb_DecodeOption_CheckRequired failed (see above), but the parse otherwise - // succeeded. - kUpb_DecodeStatus_MissingRequired = 5, -} upb_DecodeStatus; -// LINT.ThenChange(//depot/google3/third_party/upb/rust/sys/wire/wire.rs:decode_status) - -UPB_NODISCARD UPB_API upb_DecodeStatus upb_Decode( - const char* buf, size_t size, upb_Message* msg, const upb_MiniTable* mt, - const upb_ExtensionRegistry* extreg, int options, upb_Arena* arena); - -// Same as upb_Decode but with a varint-encoded length prepended. -// On success 'num_bytes_read' will be set to the how many bytes were read, -// on failure the contents of num_bytes_read is undefined. -UPB_NODISCARD UPB_API upb_DecodeStatus upb_DecodeLengthPrefixed( - const char* buf, size_t size, upb_Message* msg, size_t* num_bytes_read, - const upb_MiniTable* mt, const upb_ExtensionRegistry* extreg, int options, - upb_Arena* arena); - -// For testing: decode with tracing. -UPB_NODISCARD UPB_API upb_DecodeStatus upb_DecodeWithTrace( - const char* buf, size_t size, upb_Message* msg, const upb_MiniTable* mt, - const upb_ExtensionRegistry* extreg, int options, upb_Arena* arena, - char* trace_buf, size_t trace_size); - -// Utility function for wrapper languages to get an error string from a -// upb_DecodeStatus. -UPB_API const char* upb_DecodeStatus_String(upb_DecodeStatus status); -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_WIRE_DECODE_H_ */ diff --git a/vendor/upb/wire/decode_benchmark.cc b/vendor/upb/wire/decode_benchmark.cc deleted file mode 100644 index 4d3a870..0000000 --- a/vendor/upb/wire/decode_benchmark.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include -#include -#include - -#include -#include -#include "absl/container/flat_hash_set.h" -#include "upb/mem/alloc.h" -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/test_util/field_types.h" -#include "upb/wire/test_util/make_mini_table.h" -#include "upb/wire/test_util/wire_message.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace upb { -namespace test { - -namespace { - -void BM_Decode(benchmark::State& state, const upb_MiniTable* mt, - std::string payload, bool alias, bool initial_block) { - char mem[4096]; - int decode_options = 0; - for (auto s : state) { - upb_Arena* arena = initial_block - ? upb_Arena_Init(mem, 4096, &upb_alloc_global) - : upb_Arena_New(); - upb_Message* msg = upb_Message_New(mt, arena); - upb_DecodeStatus result = upb_Decode(payload.data(), payload.size(), msg, - mt, nullptr, decode_options, arena); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - upb_Arena_Free(arena); - } - state.SetBytesProcessed(state.iterations() * payload.size()); -} - -[[maybe_unused]] upb_Arena* benchmark_registration = [] { - upb_Arena* arena = upb_Arena_New(); - std::vector sizes{8, 64, 512}; - for (size_t size : sizes) { - absl::flat_hash_set fast_types; - ForEachType([&](auto&& type) { - using Type = std::remove_reference_t; - // We only need to benchmark each wire type once, since they are all - // treated the same by the decoder. - if (!fast_types.insert(Type::kFastType).second) return; - std::vector initial_block{true, false}; - for (bool init : initial_block) { - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Scalar, arena); - std::string payload; - while (payload.size() < size) { - payload.append(ToBinaryPayload(wire_types::WireMessage{ - {1, Type::WireValue(typename Type::Value{})}})); - } - ::benchmark::RegisterBenchmark( - absl::StrFormat("BM_Decode/%s/%zu/%s", Type::kName, size, - init ? "InitialBlock" : "NoInitialBlock") - .c_str(), - BM_Decode, mt, payload, false, init); - } - }); - } - return arena; -}(); - -} // namespace - -} // namespace test -} // namespace upb diff --git a/vendor/upb/wire/decode_fast/BUILD b/vendor/upb/wire/decode_fast/BUILD deleted file mode 100644 index 5ad2647..0000000 --- a/vendor/upb/wire/decode_fast/BUILD +++ /dev/null @@ -1,184 +0,0 @@ -# Copyright (c) 2009-2025, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") -load("@rules_cc//cc:cc_binary.bzl", "cc_binary") -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -# Our preprocessor code does not work with the default (buggy) MSVC preprocessor. -# TODO: Remove this once the new preprocessor is enabled by default. -FASTTABLE_COPTS = UPB_DEFAULT_COPTS + select({ - "//build_defs:config_msvc": ["/Zc:preprocessor"], - "//conditions:default": [], -}) - -bool_flag( - name = "debug_trace", - build_setting_default = False, -) - -config_setting( - name = "debug_trace_setting", - flag_values = {":debug_trace": "True"}, -) - -cc_library( - name = "field_parsers", - srcs = [ - "cardinality.c", - "cardinality.h", - "field_fixed.c", - "field_generic.c", - "field_message.c", - "field_string.c", - "field_varint.c", - ], - hdrs = ["field_parsers.h"], - copts = FASTTABLE_COPTS, - defines = select({ - ":debug_trace_setting": ["UPB_TRACE_FASTDECODER=1"], - "//conditions:default": [], - }), - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//upb:__pkg__", - "//upb/mini_descriptor:__pkg__", - ], - deps = [ - ":combinations", - ":data", - ":dispatch", - ":select", - "//third_party/utf8_range", - "//upb/base", - "//upb/base:internal", - "//upb/mem", - "//upb/message", - "//upb/message:internal", - "//upb/message:types", - "//upb/mini_table", - "//upb/port", - "//upb/wire:decoder", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:reader", - ], -) - -cc_library( - name = "dispatch", - srcs = ["dispatch.c"], - hdrs = ["dispatch.h"], - copts = FASTTABLE_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//upb/wire:__pkg__"], - deps = [ - "//upb/message", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/wire:decoder", - "//upb/wire:eps_copy_input_stream", - "//upb/wire:eps_copy_input_stream_internal", - ], -) - -cc_library( - name = "select", - srcs = ["select.c"], - hdrs = ["select.h"], - copts = FASTTABLE_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//pkg:__pkg__", - "//upb/mini_descriptor:__pkg__", - "//upb_generator/minitable:__pkg__", - ], - deps = [ - ":combinations", - ":data", - "//upb/base", - "//upb/base:internal", - "//upb/mini_table", - "//upb/mini_table:internal", - "//upb/port", - "//upb/wire:reader", - ], -) - -cc_test( - name = "select_test", - srcs = ["select_test.cc"], - deps = [ - ":combinations", - ":select", - "@abseil-cpp//absl/base:core_headers", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) - -cc_library( - name = "combinations", - hdrs = ["combinations.h"], - copts = FASTTABLE_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//upb:__pkg__", - "//upb/wire:__subpackages__", - ], - deps = [ - "//upb/base:internal", - "//upb/port", - "//upb/wire:reader", - ], -) - -cc_library( - name = "data", - hdrs = ["data.h"], - copts = FASTTABLE_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//upb:__pkg__", - "//upb/wire:__subpackages__", - ], - deps = [ - "//upb/port", - ], -) - -cc_library( - name = "function_array", - srcs = ["function_array.c"], - hdrs = ["function_array.h"], - copts = FASTTABLE_COPTS, - features = UPB_DEFAULT_FEATURES, - visibility = [ - "//upb:__pkg__", - "//upb/mini_descriptor:__pkg__", - ], - deps = [ - ":combinations", - ":field_parsers", - "//upb/mini_table:internal", - "//upb/port", - ], -) - -cc_binary( - name = "bisect_helper", - srcs = ["bisect_helper.cc"], - deps = [ - ":select", - "@abseil-cpp//absl/flags:flag", - "@abseil-cpp//absl/flags:parse", - ], -) diff --git a/vendor/upb/wire/decode_fast/bisect.sh b/vendor/upb/wire/decode_fast/bisect.sh deleted file mode 100755 index ec710c7..0000000 --- a/vendor/upb/wire/decode_fast/bisect.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# -# Bisect the set of fasttable parsing functions to find the one(s) causing a -# test failure. -# -# Example usage: -# -# $ blaze test --//third_party/upb:fasttable_enabled=True third_party/upb/upb/... -# -# # We notice that //third_party/upb/upb/test:test_generated_code is failing -# # when fasttable is enabled. We can bisect the set of fasttable parsing -# # functions with this command: -# -# $ third_party/upb/upb/wire/decode_fast/bisect.sh third_party/upb/upb/test:test_generated_code - -if [[ $# -lt 1 ]]; then - echo "Usage: bisect.sh [blaze test flags] " - exit 1 -fi - -set -ex - -/google/data/ro/teams/tetralight/bin/bisect -low 0 -high 256 \ - "blaze test --//third_party/upb:fasttable_enabled=True \ - --per_file_copt=//third_party/upb/upb/wire/decode_fast:select@-DUPB_DECODEFAST_DISABLE_FUNCTIONS_ABOVE=\$X \ - --host_per_file_copt=//third_party/upb/upb/wire/decode_fast:select@-DUPB_DECODEFAST_DISABLE_FUNCTIONS_ABOVE=\$X \ - $*" diff --git a/vendor/upb/wire/decode_fast/bisect_helper.cc b/vendor/upb/wire/decode_fast/bisect_helper.cc deleted file mode 100644 index ed4effb..0000000 --- a/vendor/upb/wire/decode_fast/bisect_helper.cc +++ /dev/null @@ -1,19 +0,0 @@ - -#include - -#include "absl/flags/flag.h" -#include "absl/flags/parse.h" -#include "upb/wire/decode_fast/select.h" - -ABSL_FLAG(int, function_idx, -1, "The function index to test."); - -int main(int argc, char** argv) { - absl::ParseCommandLine(argc, argv); - if (absl::GetFlag(FLAGS_function_idx) < 0) { - std::cerr << "Usage: " << argv[0] << " \n"; - return 1; - } - std::cout << upb_DecodeFast_GetFunctionName(absl::GetFlag(FLAGS_function_idx)) - << "\n"; - return 0; -} diff --git a/vendor/upb/wire/decode_fast/cardinality.c b/vendor/upb/wire/decode_fast/cardinality.c deleted file mode 100644 index 06b86c9..0000000 --- a/vendor/upb/wire/decode_fast/cardinality.c +++ /dev/null @@ -1,15 +0,0 @@ - -#include "upb/wire/decode_fast/cardinality.h" - -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/decoder.h" - -UPB_PRESERVE_MOST -const char* upb_DecodeFast_IsDoneFallback(upb_Decoder* d, const char* ptr) { - int overrun; - upb_IsDoneStatus status = UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)( - &d->input, ptr, &overrun); - UPB_ASSERT(status == kUpb_IsDoneStatus_NeedFallback); - return UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallback)(&d->input, ptr, - overrun); -} diff --git a/vendor/upb/wire/decode_fast/cardinality.h b/vendor/upb/wire/decode_fast/cardinality.h deleted file mode 100644 index 8d930b2..0000000 --- a/vendor/upb/wire/decode_fast/cardinality.h +++ /dev/null @@ -1,519 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_DECODE_FAST_FIELD_CARDINALITY_H_ -#define UPB_WIRE_DECODE_FAST_FIELD_CARDINALITY_H_ - -#include -#include -#include - -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/types.h" -#include "upb/message/message.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/data.h" -#include "upb/wire/decode_fast/dispatch.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/decoder.h" -#include "upb/wire/types.h" - -#if UPB_TRACE_FASTDECODER -#include "upb/wire/decode_fast/select.h" -#endif - -// Must be last include. -#include "upb/port/def.inc" - -// We use the new calling convention where we return an integer indicating the -// next function to call. This is to work around musttail limitations without -// forcing all fasttable code to be in macros. - -typedef enum { - kUpb_DecodeFastNext_Dispatch = 0, - - // Fallback to the MiniTable decoder. This is used either to signal a fallback - // to the mini table or the end of the message if d->message_is_done is true. - kUpb_DecodeFastNext_FallbackToMiniTable = 1, - - // Signal an error. - kUpb_DecodeFastNext_Error = 2, - - // Handle the case where ptr >= limit, which is either end-of-message or - // end-of-buffer. - kUpb_DecodeFastNext_MessageIsDoneFallback = 3, - - // Tail call to the function to parse the current field, except parse it as - // packed instead of unpacked. - kUpb_DecodeFastNext_TailCallPacked = 4, - - // Tail call to the function to parse the current field, except parse it as - // unpacked instead of packed. - kUpb_DecodeFastNext_TailCallUnpacked = 5, -} upb_DecodeFastNext; - -UPB_INLINE bool upb_DecodeFast_SetExit(upb_DecodeFastNext* next, - upb_DecodeFastNext val, const char* sym, - const char* file, int line) { -#ifdef UPB_TRACE_FASTDECODER - fprintf(stderr, "Fasttable fallback @ %s:%d -> %s (%d)\n", file, line, sym, - val); -#endif - *next = val; - return false; -} - -UPB_INLINE bool upb_DecodeFast_SetError(upb_Decoder* d, - upb_DecodeFastNext* next, - upb_DecodeStatus val, const char* sym, - const char* file, int line) { -#ifdef UPB_TRACE_FASTDECODER - fprintf(stderr, "Fasttable error @ %s:%d -> %s (%d)\n", file, line, sym, val); -#endif - d->err->code = val; - *next = kUpb_DecodeFastNext_Error; - return false; -} - -// Call using the following pattern: -// // Will return false. -// return UPB_EXIT_FASTTABLE(kUpb_DecodeFastNext_FallbackToMiniTable); -#define UPB_DECODEFAST_EXIT(n, next) \ - upb_DecodeFast_SetExit(next, n, #n, __FILE__, __LINE__) -#define UPB_DECODEFAST_ERROR(d, st, next) \ - upb_DecodeFast_SetError(d, next, st, #st, __FILE__, __LINE__) - -#define UPB_DECODEFAST_NEXTMAYBEPACKED(next, func_unpacked, func_packed) \ - switch (next) { \ - case kUpb_DecodeFastNext_Dispatch: \ - UPB_MUSTTAIL return upb_DecodeFast_Dispatch(UPB_PARSE_ARGS); \ - case kUpb_DecodeFastNext_FallbackToMiniTable: \ - UPB_MUSTTAIL return _upb_FastDecoder_DecodeGeneric(UPB_PARSE_ARGS); \ - case kUpb_DecodeFastNext_Error: \ - UPB_ASSERT(d->err->code != kUpb_DecodeStatus_Ok); \ - return _upb_FastDecoder_ErrorJmp2(d); \ - case kUpb_DecodeFastNext_MessageIsDoneFallback: \ - UPB_MUSTTAIL return upb_DecodeFast_MessageIsDoneFallback( \ - UPB_PARSE_ARGS); \ - case kUpb_DecodeFastNext_TailCallPacked: \ - UPB_MUSTTAIL return func_packed(UPB_PARSE_ARGS); \ - case kUpb_DecodeFastNext_TailCallUnpacked: \ - UPB_MUSTTAIL return func_unpacked(UPB_PARSE_ARGS); \ - default: \ - UPB_UNREACHABLE(); \ - } - -UPB_INLINE const char* UPB_PRESERVE_NONE -upb_DecodeFast_Unreachable(UPB_PARSE_PARAMS) { - UPB_UNREACHABLE(); -} - -#define UPB_DECODEFAST_NEXT(next) \ - UPB_DECODEFAST_NEXTMAYBEPACKED(next, upb_DecodeFast_Unreachable, \ - upb_DecodeFast_Unreachable) - -UPB_FORCEINLINE -uint64_t upb_DecodeFast_LoadHasbits(upb_Message* msg) { - return *(uint32_t*)&msg[1]; -} - -/* Error function that will abort decoding with longjmp(). We can't declare this - * UPB_NORETURN, even though it is appropriate, because if we do then compilers - * will "helpfully" refuse to tailcall to it - * (see: https://stackoverflow.com/a/55657013), which will defeat a major goal - * of our optimizations. That is also why we must declare it in a separate file, - * otherwise the compiler will see that it calls longjmp() and deduce that it is - * noreturn. */ -const char* _upb_FastDecoder_ErrorJmp2(upb_Decoder* d); - -UPB_INLINE -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, upb_DecodeStatus status) { - d->err->code = status; - return _upb_FastDecoder_ErrorJmp2(d); -} - -// --- New cardinality functions --- - -// Old functions will be removed once the new ones are in use. -// -// We use the new calling convention where we return an integer indicating the -// next function to call. This is to work around musttail limitations without -// forcing all fasttable code to be in macros. - -typedef struct { - void* dst; - upb_Array* arr; - void* end; - uint16_t expected_tag; -} upb_DecodeFastArray; - -UPB_FORCEINLINE -void upb_DecodeFastField_SetArraySize(upb_DecodeFastArray* field, - upb_DecodeFast_Type type) { - field->arr->UPB_PRIVATE(size) = - ((uintptr_t)field->dst - - (uintptr_t)upb_Array_MutableDataPtr(field->arr)) / - upb_DecodeFast_ValueBytes(type); -} - -UPB_FORCEINLINE -int upb_DecodeFast_MaskTag(uint16_t data, upb_DecodeFast_TagSize tagsize) { - if (tagsize == kUpb_DecodeFast_Tag1Byte) { - return data & 0xff; - } else { - return data; - } -} - -UPB_FORCEINLINE -bool upb_DecodeFast_MaskedTagIsZero(uint16_t data, - upb_DecodeFast_TagSize tagsize) { - return upb_DecodeFast_MaskTag(data, tagsize) == 0; -} - -// Checks to see if the tag is packed when we were expecting unpacked, or vice -// versa. If so, flips the tag and returns true. -UPB_FORCEINLINE -bool upb_DecodeFast_TryFlipPacked(upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality card, - upb_DecodeFast_TagSize tagsize, - uint64_t* data) { - if (!upb_DecodeFast_IsRepeated(card)) return false; - *data ^= kUpb_WireType_Delimited ^ upb_DecodeFast_WireType(type); - return upb_DecodeFast_MaskedTagIsZero(*data, tagsize); -} - -UPB_FORCEINLINE -bool upb_DecodeFast_ArrayReserve(upb_Decoder* d, upb_Array* arr, - upb_DecodeFast_Type type, int elems, - upb_DecodeFastNext* next) { - UPB_ASSERT(arr); - - size_t existing = upb_Array_Size(arr); - if (upb_Array_Reserve(arr, existing + elems, &d->arena)) return true; - - return UPB_DECODEFAST_ERROR(d, kUpb_DecodeStatus_OutOfMemory, next); -} - -UPB_FORCEINLINE -bool upb_DecodeFast_GetScalarField(upb_Decoder* d, const char* ptr, - upb_Message* msg, uint64_t data, - uint64_t* hasbits, upb_DecodeFastNext* ret, - void** dst, - upb_DecodeFast_Cardinality card) { - UPB_ASSERT(!upb_Message_IsFrozen(msg)); - switch (card) { - case kUpb_DecodeFast_Scalar: { - // Set hasbit and return pointer to scalar field. - *dst = UPB_PTR_AT(msg, upb_DecodeFastData_GetOffset(data), char); - uint8_t hasbit_index = upb_DecodeFastData_GetPresence(data); - *hasbits |= 1ull << hasbit_index; - return true; - } - case kUpb_DecodeFast_Oneof: { - *dst = UPB_PTR_AT(msg, upb_DecodeFastData_GetOffset(data), char); - uint16_t case_ofs = upb_DecodeFastData_GetCaseOffset(data); - uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); - uint8_t field_number = upb_DecodeFastData_GetPresence(data); - *oneof_case = field_number; - return true; - } - default: - return false; - } -} - -UPB_FORCEINLINE -bool upb_DecodeFast_TagMatches(uint16_t expected, uint16_t tag, - upb_DecodeFast_TagSize tagsize) { - if (tagsize == kUpb_DecodeFast_Tag1Byte) { - return (uint8_t)tag == (uint8_t)expected; - } else { - return (uint16_t)tag == (uint16_t)expected; - } -} - -UPB_FORCEINLINE -bool upb_DecodeFast_TryMatchTag(upb_Decoder* d, const char* ptr, - uint16_t expected, upb_DecodeFastNext* next, - upb_DecodeFast_TagSize tagsize) { - int overrun; - if (UPB_UNLIKELY(UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)( - &d->input, ptr, &overrun) != - kUpb_IsDoneStatus_NotDone)) { - return UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_MessageIsDoneFallback, next); - } - - uint16_t tag = _upb_FastDecoder_LoadTag(ptr); - - return upb_DecodeFast_TagMatches(expected, tag, tagsize); -} - -UPB_FORCEINLINE -bool upb_DecodeFast_NextRepeated(upb_Decoder* d, const char** ptr, - upb_DecodeFastNext* next, - upb_DecodeFastArray* field, bool has_next, - upb_DecodeFast_Type type, - upb_DecodeFast_TagSize tagsize) { - field->dst = UPB_PTR_AT(field->dst, upb_DecodeFast_ValueBytes(type), char); - - if (has_next && field->dst == field->end) { - // Out of arena memory; fall back to MiniTable decoder which will realloc. - UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_FallbackToMiniTable, next); - has_next = false; - } - - if (!has_next) { - upb_DecodeFastField_SetArraySize(field, type); - return false; - } - - // Parse another instance of the repeated field. - *ptr += upb_DecodeFast_TagSizeBytes(tagsize); - return true; -} - -UPB_FORCEINLINE -bool upb_DecodeFast_CheckTag(const char** ptr, upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality card, - upb_DecodeFast_TagSize tagsize, uint64_t* data, - upb_DecodeFastNext flipped, - upb_DecodeFastNext* next) { -#if UPB_TRACE_FASTDECODER - size_t idx = UPB_DECODEFAST_FUNCTION_IDX(type, card, tagsize); - fprintf(stderr, "Fasttable enter (check tag) -> %s\n", - upb_DecodeFast_GetFunctionName(idx)); -#endif - // The dispatch sequence xors the actual tag with the expected tag, so - // if the masked tag is zero, we know that the tag is valid. - if (UPB_UNLIKELY(!upb_DecodeFast_MaskedTagIsZero(*data, tagsize))) { - // If this field is repeated and the field type is packable, we check - // whether the tag can be flipped (ie. packed -> unpacked or vice versa). - // If so, we can jump directly to the decoder for the flipped tag. - if (flipped && upb_DecodeFast_TryFlipPacked(type, card, tagsize, data)) { - // We can jump directly to the decoder for the flipped tag. - return UPB_DECODEFAST_EXIT(flipped, next); - } - return UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_FallbackToMiniTable, next); - } - *ptr += upb_DecodeFast_TagSizeBytes(tagsize); - return true; -} - -UPB_FORCEINLINE -bool upb_DecodeFast_GetArrayForAppend(upb_Decoder* d, const char* ptr, - upb_Message* msg, uint64_t data, - uint64_t* hasbits, - upb_DecodeFastArray* field, - upb_DecodeFast_Type type, int elems, - upb_DecodeFastNext* next) { - UPB_ASSERT(elems > 0); - - upb_Array** arr_p = - UPB_PTR_AT(msg, upb_DecodeFastData_GetOffset(data), upb_Array*); - upb_Array* arr = *arr_p; - int lg2 = upb_DecodeFast_ValueBytesLg2(type); - - // Sync hasbits so we don't have to preserve them across the repeated field. - upb_DecodeFast_SetHasbits(msg, *hasbits); - *hasbits = 0; - - if (UPB_LIKELY(!arr)) { - // upb_Array does not exist yet. Create if with an appropriate initial - // capacity, as long as the arena has enough size in the current block. - int start_cap = 8; - - // A few arbitrary choices on the initial capacity, could be tuned later. - while (start_cap < elems) start_cap *= 2; - - arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, start_cap, lg2); - if (!arr) { - return UPB_DECODEFAST_ERROR(d, kUpb_DecodeStatus_OutOfMemory, next); - } - *arr_p = arr; - } else if (!upb_DecodeFast_ArrayReserve(d, arr, type, elems, next)) { - return false; - } - - void* start = upb_Array_MutableDataPtr(arr); - int valbytes = upb_DecodeFast_ValueBytes(type); - - field->arr = arr; - field->dst = UPB_PTR_AT(start, upb_Array_Size(arr) * valbytes, void); - field->end = UPB_PTR_AT(start, upb_Array_Capacity(arr) * valbytes, void); - field->expected_tag = _upb_FastDecoder_LoadTag(ptr); - - return true; -} - -typedef bool upb_DecodeFast_Single(upb_Decoder* d, const char** ptr, void* dst, - upb_DecodeFast_Type type, - upb_DecodeFastNext* next, void* ctx); - -UPB_FORCEINLINE -bool upb_DecodeFast_Unpacked(upb_Decoder* d, const char** ptr, upb_Message* msg, - uint64_t* data, uint64_t* hasbits, - upb_DecodeFastNext* ret, upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality card, - upb_DecodeFast_TagSize tagsize, - upb_DecodeFast_Single* single, void* ctx) { - const char* p = *ptr; - if (!upb_DecodeFast_CheckTag(&p, type, card, tagsize, data, - kUpb_DecodeFastNext_TailCallPacked, ret)) { - return false; - } - - void* dst; - - if (upb_DecodeFast_GetScalarField(d, p, msg, *data, hasbits, ret, &dst, - card)) { - if (!single(d, &p, dst, type, ret, ctx)) return false; - *ptr = p; - _upb_Decoder_Trace(d, 'F'); - return true; - } - - upb_DecodeFastArray arr; - if (!upb_DecodeFast_GetArrayForAppend(d, *ptr, msg, *data, hasbits, &arr, - type, 1, ret)) { - return false; - } - - bool next_tag_matches; - do { - if (!single(d, &p, arr.dst, type, ret, ctx)) { - upb_DecodeFastField_SetArraySize(&arr, type); - return false; - } - *ptr = p; - _upb_Decoder_Trace(d, 'F'); - next_tag_matches = - upb_DecodeFast_TryMatchTag(d, p, arr.expected_tag, ret, tagsize); - } while (upb_DecodeFast_NextRepeated(d, &p, ret, &arr, next_tag_matches, type, - tagsize)); - - return true; -} - -UPB_FORCEINLINE -bool upb_DecodeFast_DecodeSize(upb_Decoder* d, const char** pp, int* size, - upb_DecodeFastNext* next) { - const char* ptr = *pp; - if ((ptr[0] & 0x80) == 0) { - *pp = ptr + 1; - *size = (uint8_t)*ptr; - return true; - } else if ((ptr[1] & 0x80) == 0) { - *pp = ptr + 2; - *size = ((uint8_t)ptr[1] << 7) | (ptr[0] & 0x7f); - return true; - } - - // We don't know if this is valid wire format or not, we didn't look at - // enough bytes to know if the varint is encoded overlong or the value - // is too large for the current message. So we let the MiniTable decoder - // handle it. - return UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_FallbackToMiniTable, next); -} - -UPB_FORCEINLINE -bool upb_DecodeFast_Delimited(upb_Decoder* d, const char** ptr, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, - upb_DecodeFastNext* ret, void* ctx) { - const char* p = *ptr; - int size; - - if (!upb_DecodeFast_DecodeSize(d, &p, &size, ret)) return false; - - if (upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &p, size, func, - ctx)) { - if (UPB_UNLIKELY(p == NULL)) goto fail; - } else { - ptrdiff_t delta = upb_EpsCopyInputStream_PushLimit(&d->input, p, size); - if (UPB_UNLIKELY(delta < 0)) { - // Corrupt wire format: invalid limit. - *ptr = NULL; - return UPB_DECODEFAST_ERROR(d, kUpb_DecodeStatus_Malformed, ret); - } - p = func(&d->input, p, size, ctx); - if (UPB_UNLIKELY(p == NULL)) goto fail; - upb_EpsCopyInputStream_PopLimit(&d->input, p, delta); - } - - *ptr = p; - return true; - -fail: - // We can't fall back to the mini table here because we may have already - // advanced past the previous buffer. - UPB_ASSERT(*ret != kUpb_DecodeFastNext_FallbackToMiniTable); - *ptr = NULL; - return false; -} - -UPB_FORCEINLINE -bool upb_DecodeFast_Packed(upb_Decoder* d, const char** ptr, - upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality card, - upb_DecodeFast_TagSize tagsize, uint64_t* data, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, - upb_DecodeFastNext* ret, void* ctx) { - const char* p = *ptr; - - if (!upb_DecodeFast_CheckTag(&p, type, card, tagsize, data, - kUpb_DecodeFastNext_TailCallUnpacked, ret) || - !upb_DecodeFast_Delimited(d, &p, func, ret, ctx)) { - return false; - } - - *ptr = p; - _upb_Decoder_Trace(d, 'F'); - return true; -} - -UPB_FORCEINLINE -void upb_DecodeFast_InlineMemcpy(void* dst, const char* src, size_t size) { - // Disabled for now because we haven't yet measured a benefit to justify - // the additional complexity. -#if false && defined(__x86_64__) && defined(__GNUC__) && \ - !UPB_HAS_FEATURE(memory_sanitizer) - // This is nearly as fast as memcpy(), but saves us from calling an external - // function and spilling all our registers. - __asm__ __volatile__("rep movsb" - : "+D"(dst), "+S"(src), "+c"(size)::"memory"); -#else - memcpy(dst, src, size); -#endif -} - -// Workaround for b/177688959. We need to ensure that this function never goes -// through PLT lookup. It follows that this function may not be called by -// any other cc_library(). -__attribute__((visibility("hidden"))) UPB_PRESERVE_MOST const char* -upb_DecodeFast_IsDoneFallback(upb_Decoder* d, const char* ptr); - -UPB_FORCEINLINE -bool upb_DecodeFast_IsDone(upb_Decoder* d, const char** ptr) { - int overrun; - upb_IsDoneStatus status = UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)( - &d->input, *ptr, &overrun); - switch (status) { - case kUpb_IsDoneStatus_Done: - return true; - case kUpb_IsDoneStatus_NotDone: - return false; - case kUpb_IsDoneStatus_NeedFallback: - *ptr = upb_DecodeFast_IsDoneFallback(d, *ptr); - return false; - default: - UPB_UNREACHABLE(); - } -} - -#endif // UPB_WIRE_DECODE_FAST_FIELD_CARDINALITY_H_ diff --git a/vendor/upb/wire/decode_fast/combinations.h b/vendor/upb/wire/decode_fast/combinations.h deleted file mode 100644 index 58a1e04..0000000 --- a/vendor/upb/wire/decode_fast/combinations.h +++ /dev/null @@ -1,221 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_COMBINATIONS_H_ -#define UPB_WIRE_INTERNAL_DECODE_FAST_COMBINATIONS_H_ - -#include - -#include "upb/base/internal/log2.h" -#include "upb/wire/types.h" - -// Must be last. -#include "upb/port/def.inc" - -// Each fast function is specialized for a cardinality, type, and tag size. -// These macros enumerate all possibilities for each of these three dimensions. -// -// These can be generated in any combination, except that non-primitive types -// cannot be packed. So we have: -// {1bt,2bt} x {s,o,r,p} x {b,v32,v64,z32,z64,f32,f64,ce} // Primitive -// {1bt,2bt} x {s,o,r} x {s,b,m} // Non-primitive - -#define UPB_DECODEFAST_CARDINALITIES(F, ...) \ - F(__VA_ARGS__, Scalar) \ - F(__VA_ARGS__, Oneof) \ - F(__VA_ARGS__, Repeated) \ - F(__VA_ARGS__, Packed) - -#define UPB_DECODEFAST_TYPES(F, ...) \ - F(__VA_ARGS__, Bool) \ - F(__VA_ARGS__, Varint32) \ - F(__VA_ARGS__, Varint64) \ - F(__VA_ARGS__, ZigZag32) \ - F(__VA_ARGS__, ZigZag64) \ - F(__VA_ARGS__, Fixed32) \ - F(__VA_ARGS__, Fixed64) \ - F(__VA_ARGS__, String) \ - F(__VA_ARGS__, Bytes) \ - F(__VA_ARGS__, Message) - -#define UPB_DECODEFAST_TAGSIZES(F, ...) \ - F(__VA_ARGS__, Tag1Byte) \ - F(__VA_ARGS__, Tag2Byte) - -#define ENUM_VAL(_, x) kUpb_DecodeFast_##x, - -typedef enum { - UPB_DECODEFAST_CARDINALITIES(ENUM_VAL) // kUpb_DecodeFast_Scalar = 0, etc. -} upb_DecodeFast_Cardinality; - -typedef enum { - UPB_DECODEFAST_TYPES(ENUM_VAL) // kUpb_DecodeFast_Bool = 0, etc. -} upb_DecodeFast_Type; - -typedef enum { - UPB_DECODEFAST_TAGSIZES(ENUM_VAL) // kUpb_DecodeFast_Tag1Byte = 0, etc. -} upb_DecodeFast_TagSize; - -#undef ENUM_VAL - -#define ADD(_, x) +1 - -enum { - // Counts of the number of enum values for each dimension. - kUpb_DecodeFast_CardinalityCount = UPB_DECODEFAST_CARDINALITIES(ADD), - kUpb_DecodeFast_TypeCount = UPB_DECODEFAST_TYPES(ADD), - kUpb_DecodeFast_TagSizeCount = UPB_DECODEFAST_TAGSIZES(ADD), -}; - -#undef ADD - -// Attributes of the various dimensions. - -UPB_INLINE int upb_DecodeFast_TagSizeBytes(upb_DecodeFast_TagSize size) { - switch (size) { - case kUpb_DecodeFast_Tag1Byte: - return 1; - case kUpb_DecodeFast_Tag2Byte: - return 2; - default: - UPB_UNREACHABLE(); - } -} - -UPB_INLINE int upb_DecodeFast_ValueBytes(upb_DecodeFast_Type type) { - switch (type) { - case kUpb_DecodeFast_Bool: - return 1; - case kUpb_DecodeFast_Varint32: - case kUpb_DecodeFast_ZigZag32: - case kUpb_DecodeFast_Fixed32: - return 4; - case kUpb_DecodeFast_Varint64: - case kUpb_DecodeFast_ZigZag64: - case kUpb_DecodeFast_Fixed64: - case kUpb_DecodeFast_Message: - return 8; - case kUpb_DecodeFast_String: - case kUpb_DecodeFast_Bytes: - return 16; - default: - UPB_UNREACHABLE(); - } -} - -UPB_INLINE upb_WireType upb_DecodeFast_WireType(upb_DecodeFast_Type type) { - switch (type) { - case kUpb_DecodeFast_Bool: - case kUpb_DecodeFast_Varint32: - case kUpb_DecodeFast_Varint64: - case kUpb_DecodeFast_ZigZag32: - case kUpb_DecodeFast_ZigZag64: - return kUpb_WireType_Varint; - case kUpb_DecodeFast_Fixed32: - return kUpb_WireType_32Bit; - case kUpb_DecodeFast_Fixed64: - return kUpb_WireType_64Bit; - case kUpb_DecodeFast_Message: - case kUpb_DecodeFast_String: - case kUpb_DecodeFast_Bytes: - return kUpb_WireType_Delimited; - default: - UPB_UNREACHABLE(); - } -} - -UPB_INLINE int upb_DecodeFast_ValueBytesLg2(upb_DecodeFast_Type type) { - return upb_Log2Ceiling(upb_DecodeFast_ValueBytes(type)); -} - -UPB_INLINE bool upb_DecodeFast_IsRepeated(upb_DecodeFast_Cardinality card) { - return card == kUpb_DecodeFast_Repeated || card == kUpb_DecodeFast_Packed; -} - -UPB_INLINE bool upb_DecodeFast_IsZigZag(upb_DecodeFast_Type type) { - switch (type) { - case kUpb_DecodeFast_ZigZag32: - case kUpb_DecodeFast_ZigZag64: - return true; - default: - return false; - } -} - -// The canonical ordering of functions, used by the arrays of function pointers -// and function names. This macro generates the full cross product of the -// cardinality, type, and tag size enums. -// -// This ordering generates some combinations that are not actually used (like -// packed strings or messages), but it's simpler than trying to avoid them. -// There are only 14 impossible combinations out of 120 total, so it's not -// worth optimizing for. -#define UPB_DECODEFAST_FUNCTIONS(F) \ - UPB_DECODEFAST_TYPES(UPB_DECODEFAST_CARDINALITIES, UPB_DECODEFAST_TAGSIZES, F) - -// The canonical index of a given function. This must be kept in sync with the -// ordering above, such that this index selects the same function as the -// corresponding UPB_DECODEFAST_FUNCNAME() macro. -#define UPB_DECODEFAST_FUNCTION_IDX(type, card, size) \ - (((uint32_t)type * kUpb_DecodeFast_CardinalityCount * \ - kUpb_DecodeFast_TagSizeCount) + \ - ((uint32_t)card * kUpb_DecodeFast_TagSizeCount) + (uint32_t)size) - -// Functions to decompose a function index into its constituent parts. -UPB_INLINE upb_DecodeFast_TagSize -upb_DecodeFast_GetTagSize(uint32_t function_idx) { - return (upb_DecodeFast_TagSize)(function_idx % kUpb_DecodeFast_TagSizeCount); -} - -UPB_INLINE upb_DecodeFast_Cardinality -upb_DecodeFast_GetCardinality(uint32_t function_idx) { - return (upb_DecodeFast_Cardinality)((function_idx / - kUpb_DecodeFast_TagSizeCount) % - kUpb_DecodeFast_CardinalityCount); -} - -UPB_INLINE upb_DecodeFast_Type upb_DecodeFast_GetType(uint32_t function_idx) { - return (upb_DecodeFast_Type)(function_idx / - (kUpb_DecodeFast_TagSizeCount * - kUpb_DecodeFast_CardinalityCount)); -} - -// The canonical function name for a given cardinality, type, and tag size. -#define UPB_DECODEFAST_FUNCNAME(type, card, size) \ - upb_DecodeFast_##type##_##card##_##size - -// Returns true if we should disable fast decode for this function_idx. This is -// useful for field types that are known not to work yet. It is also useful for -// bisecting a test failure to find which function(s) are broken. -// -// This must be a macro because it must evaluate to a compile-time constant, -// since we use it when initializing the fastdecode function array. -// -// This function only applies to field types that have been assigned a function -// index. Some field types (eg. groups) do not even have a function index at -// the moment, and so will be rejected by upb_DecodeFast_TryFillEntry() before -// we even get here. -#define UPB_DECODEFAST_COMBINATION_IS_ENABLED(type, card, size) \ - (type == kUpb_DecodeFast_Fixed32 || type == kUpb_DecodeFast_Fixed64 || \ - ((type == kUpb_DecodeFast_Varint32 || type == kUpb_DecodeFast_Varint64 || \ - type == kUpb_DecodeFast_ZigZag32 || type == kUpb_DecodeFast_ZigZag64 || \ - type == kUpb_DecodeFast_Bool || type == kUpb_DecodeFast_Bytes || \ - type == kUpb_DecodeFast_String || type == kUpb_DecodeFast_Message))) - -#ifdef UPB_DECODEFAST_DISABLE_FUNCTIONS_ABOVE -#define UPB_DECODEFAST_ISENABLED(type, card, size) \ - (UPB_DECODEFAST_COMBINATION_IS_ENABLED(type, card, size) && \ - (UPB_DECODEFAST_FUNCTION_IDX(type, card, size) <= \ - UPB_DECODEFAST_DISABLE_FUNCTIONS_ABOVE)) -#else -#define UPB_DECODEFAST_ISENABLED(type, card, size) \ - UPB_DECODEFAST_COMBINATION_IS_ENABLED(type, card, size) -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_INTERNAL_DECODE_FAST_COMBINATIONS_H_ diff --git a/vendor/upb/wire/decode_fast/data.h b/vendor/upb/wire/decode_fast/data.h deleted file mode 100644 index 4831c82..0000000 --- a/vendor/upb/wire/decode_fast/data.h +++ /dev/null @@ -1,73 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef GOOGLE_UPB_UPB_WIRE_INTERNAL_DECODE_FAST_DATALAYOUT_H__ -#define GOOGLE_UPB_UPB_WIRE_INTERNAL_DECODE_FAST_DATALAYOUT_H__ - -#include - -// Must be last. -#include "upb/port/def.inc" - -// The layout of the data field of _upb_FastTable_Entry.field_data is as -// follows: -// -// 48 32 16 0 -// |--------|--------|--------|--------|--------|--------|--------|--------| -// | offset (16) |case offset (16) |presence| index | exp. tag (16) | -// |--------|--------|--------|--------|--------|--------|--------|--------| -// -// - `offset` is the offset of the field in the message struct. -// - `case_offset` is the offset of the oneof selector for a oneof field -// (or 0 if not a oneof field). -// - `presence` is either hasbit index or field number for oneofs. -// - `field_index` is the index of the field in the mini table's fields -// array (or 0 if we don't need the field index to parse this field type). -// - `expected_tag` is the expected value of the tag for this field. - -UPB_INLINE bool upb_DecodeFast_MakeData(uint64_t offset, uint64_t case_offset, - uint64_t presence, uint64_t field_index, - uint64_t expected_tag, - uint64_t* out_data) { - if (offset > 0xffff || case_offset > 0xffff || presence > 0xff || - field_index > 0xff || expected_tag > 0xffff) { - return false; - } - - *out_data = (offset << 48) | (case_offset << 32) | (presence << 24) | - (field_index << 16) | expected_tag; - return true; -} - -UPB_INLINE uint16_t upb_DecodeFastData_GetOffset(uint64_t data) { - return data >> 48; -} - -UPB_INLINE uint16_t upb_DecodeFastData_GetCaseOffset(uint64_t data) { - return data >> 32; -} - -UPB_INLINE uint8_t upb_DecodeFastData_GetPresence(uint64_t data) { - return data >> 24; -} - -UPB_INLINE uint8_t upb_DecodeFastData_GetFieldIndex(uint64_t data) { - return data >> 16; -} - -UPB_INLINE uint16_t upb_DecodeFastData_GetExpectedTag(uint64_t data) { - return data; -} - -UPB_INLINE int upb_DecodeFastData_GetTableSlot(uint64_t data) { - uint16_t tag = upb_DecodeFastData_GetExpectedTag(data); - return (tag & 0xf8) >> 3; -} - -#include "upb/port/undef.inc" - -#endif // GOOGLE_UPB_UPB_WIRE_INTERNAL_DECODE_FAST_DATALAYOUT_H__ diff --git a/vendor/upb/wire/decode_fast/dispatch.c b/vendor/upb/wire/decode_fast/dispatch.c deleted file mode 100644 index 97d59dd..0000000 --- a/vendor/upb/wire/decode_fast/dispatch.c +++ /dev/null @@ -1,55 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/decode_fast/dispatch.h" - -#include - -#include "upb/message/message.h" -#include "upb/mini_table/message.h" -#include "upb/wire/internal/decoder.h" -#include "upb/wire/internal/eps_copy_input_stream.h" - -// Must be last. -#include "upb/port/def.inc" - -UPB_NOINLINE UPB_PRESERVE_NONE const char* upb_DecodeFast_MessageIsDoneFallback( - UPB_PARSE_PARAMS) { - int overrun; - switch (UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)(&d->input, ptr, - &overrun)) { - case kUpb_IsDoneStatus_Done: { - // We've reach end-of-message. Sync hasbits and maybe check required - // fields. - d->message_is_done = true; - upb_DecodeFast_SetHasbits(msg, hasbits); - const upb_MiniTable* m = decode_totablep(table); - return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, m) - : ptr; - } - case kUpb_IsDoneStatus_NeedFallback: - // We've reached end-of-buffer. Refresh the buffer. - ptr = UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallback)(&d->input, ptr, - overrun); - - // We successfully refreshed the buffer (otherwise the function above - // would have thrown an error with longjmp()). So continue with the - // fast decoder. - data = _upb_FastDecoder_LoadTag(ptr); - _upb_Decoder_Trace(d, 'r'); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); - case kUpb_IsDoneStatus_NotDone: // Handled by caller. - default: - UPB_UNREACHABLE(); - } -} - -const char* _upb_FastDecoder_ErrorJmp2(upb_Decoder* d) { - UPB_LONGJMP(d->err->buf, 1); - return NULL; -} diff --git a/vendor/upb/wire/decode_fast/dispatch.h b/vendor/upb/wire/decode_fast/dispatch.h deleted file mode 100644 index e70ffc7..0000000 --- a/vendor/upb/wire/decode_fast/dispatch.h +++ /dev/null @@ -1,95 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_DECODE_FAST_FIELD_DISPATCH_H_ -#define UPB_WIRE_DECODE_FAST_FIELD_DISPATCH_H_ - -#include -#include -#include -#include - -#include "upb/message/message.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/decoder.h" - -// Must be last. -#include "upb/port/def.inc" - -// The standard set of arguments passed to each parsing function. -// Thanks to x86-64 calling conventions, these will stay in registers. -#define UPB_PARSE_PARAMS \ - upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ - uint64_t hasbits, uint64_t data - -#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data - -UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { - uint16_t tag; - memcpy(&tag, ptr, 2); - return tag; -} - -// We have to disable HWASAN for this function because we steal the high byte -// of the `table` pointer for our own purposes (the table mask). This overwrites -// the tag that HWASAN depends on for its own checks. -__attribute__((no_sanitize("hwaddress"))) UPB_INLINE - UPB_PRESERVE_NONE const char* - _upb_FastDecoder_TagDispatch(struct upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t tag) { - const upb_MiniTable* table_p = decode_totablep(table); - uint8_t mask = table; - size_t ofs = tag & mask; - UPB_ASSUME((ofs & 0xf8) == ofs); - -#ifdef __cplusplus - // Unreachable, since this header is only used from C, but when the header - // module is compiled for C++ we need to avoid a compilation error. - UPB_UNREACHABLE(); - UPB_UNUSED(table_p); - _upb_FastTable_Entry* ent = NULL; -#else - const _upb_FastTable_Entry* ent = &table_p->UPB_PRIVATE(fasttable)[ofs >> 3]; -#endif - - UPB_MUSTTAIL return ent->field_parser(d, ptr, msg, table, hasbits, - ent->field_data ^ tag); -} - -UPB_NOINLINE UPB_PRESERVE_NONE const char* upb_DecodeFast_MessageIsDoneFallback( - UPB_PARSE_PARAMS); - -UPB_FORCEINLINE UPB_PRESERVE_NONE const char* upb_DecodeFast_Dispatch( - UPB_PARSE_PARAMS) { - int overrun; - upb_IsDoneStatus status = UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)( - &d->input, ptr, &overrun); - - if (UPB_UNLIKELY(status != kUpb_IsDoneStatus_NotDone)) { - // End-of-message or end-of-buffer. - UPB_MUSTTAIL return upb_DecodeFast_MessageIsDoneFallback(UPB_PARSE_ARGS); - } - - // Read two bytes of tag data (for a one-byte tag, the high byte is junk). - data = _upb_FastDecoder_LoadTag(ptr); - _upb_Decoder_Trace(d, 'D'); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); -} - -UPB_FORCEINLINE -void upb_DecodeFast_SetHasbits(upb_Message* msg, uint64_t hasbits) { - // TODO: Can we use `=` instead of` |=`? - *(uint32_t*)&msg[1] |= hasbits; -} - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_DECODE_FAST_FIELD_DISPATCH_H_ diff --git a/vendor/upb/wire/decode_fast/field_fixed.c b/vendor/upb/wire/decode_fast/field_fixed.c deleted file mode 100644 index 9444a09..0000000 --- a/vendor/upb/wire/decode_fast/field_fixed.c +++ /dev/null @@ -1,119 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include - -#include "upb/message/array.h" -#include "upb/message/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/decode_fast/cardinality.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/dispatch.h" -#include "upb/wire/decode_fast/field_parsers.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/decoder.h" - -// Must be last. -#include "upb/port/def.inc" - -static bool upb_DecodeFast_SingleFixed(upb_Decoder* d, const char** ptr, - void* dst, upb_DecodeFast_Type type, - upb_DecodeFastNext* next, void* ctx) { - UPB_UNUSED(ctx); - int valbytes = upb_DecodeFast_ValueBytes(type); - memcpy(dst, *ptr, valbytes); - *ptr += valbytes; - return true; -} - -typedef struct { - upb_Decoder* d; - upb_DecodeFast_Type type; - upb_Message* msg; - uint64_t* data; - uint64_t* hasbits; - upb_DecodeFastNext* ret; -} upb_DecodeFast_PackedFixedContext; - -static const char* upb_DecodeFast_PackedFixed(upb_EpsCopyInputStream* st, - const char* ptr, int size, - void* ctx) { - upb_DecodeFast_PackedFixedContext* c = - (upb_DecodeFast_PackedFixedContext*)ctx; - - int valbytes = upb_DecodeFast_ValueBytes(c->type); - - if (size == 0) return ptr; // 0-element packed fields are valid. - - if (size % valbytes != 0) { - UPB_DECODEFAST_ERROR(c->d, kUpb_DecodeStatus_Malformed, c->ret); - return NULL; - } - - upb_DecodeFastArray arr; - - if (!upb_DecodeFast_GetArrayForAppend(c->d, ptr, c->msg, *c->data, c->hasbits, - &arr, c->type, size / valbytes, - c->ret)) { - return NULL; - } - - upb_DecodeFast_InlineMemcpy(arr.dst, ptr, size); - arr.dst = UPB_PTR_AT(arr.dst, size, char); - upb_DecodeFastField_SetArraySize(&arr, c->type); - - return ptr + size; -} - -UPB_FORCEINLINE -void upb_DecodeFast_Fixed(upb_Decoder* d, const char** ptr, upb_Message* msg, - intptr_t table, uint64_t* hasbits, uint64_t* data, - upb_DecodeFastNext* ret, upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality card, - upb_DecodeFast_TagSize tagsize) { - if (card == kUpb_DecodeFast_Packed) { - upb_DecodeFast_PackedFixedContext ctx = { - .d = d, - .type = type, - .msg = msg, - .data = data, - .hasbits = hasbits, - .ret = ret, - }; - upb_DecodeFast_Packed(d, ptr, type, card, tagsize, data, - &upb_DecodeFast_PackedFixed, ret, &ctx); - } else { - upb_DecodeFast_Unpacked(d, ptr, msg, data, hasbits, ret, type, card, - tagsize, &upb_DecodeFast_SingleFixed, NULL); - } -} - -/* Generate all combinations: - * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ - -#define F(type, card, tagbytes) \ - UPB_NOINLINE UPB_PRESERVE_NONE const char* UPB_DECODEFAST_FUNCNAME( \ - type, card, tagbytes)(UPB_PARSE_PARAMS) { \ - upb_DecodeFastNext next = kUpb_DecodeFastNext_Dispatch; \ - upb_DecodeFast_Fixed(d, &ptr, msg, table, &hasbits, &data, &next, \ - kUpb_DecodeFast_##type, kUpb_DecodeFast_##card, \ - kUpb_DecodeFast_##tagbytes); \ - UPB_DECODEFAST_NEXTMAYBEPACKED( \ - next, UPB_DECODEFAST_FUNCNAME(type, Repeated, tagbytes), \ - UPB_DECODEFAST_FUNCNAME(type, Packed, tagbytes)); \ - } - -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, Fixed32) -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, Fixed64) - -#undef F -#undef FASTDECODE_FIXED -#undef FASTDECODE_PACKEDFIXED -#undef FASTDECODE_UNPACKEDFIXED - -#include "upb/port/undef.inc" diff --git a/vendor/upb/wire/decode_fast/field_generic.c b/vendor/upb/wire/decode_fast/field_generic.c deleted file mode 100644 index 4d5a6b2..0000000 --- a/vendor/upb/wire/decode_fast/field_generic.c +++ /dev/null @@ -1,27 +0,0 @@ - -#include - -#include "upb/message/message.h" -#include "upb/wire/decode_fast/cardinality.h" -#include "upb/wire/decode_fast/dispatch.h" -#include "upb/wire/internal/decoder.h" - -// Must be last. -#include "upb/port/def.inc" - -UPB_PRESERVE_NONE const char* _upb_FastDecoder_FallbackToMiniTable( - struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - (void)data; - upb_DecodeFast_SetHasbits(msg, hasbits); - return ptr; -} - -UPB_PRESERVE_NONE const char* _upb_FastDecoder_DecodeGeneric( - struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_DecodeFastNext ret; - UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_FallbackToMiniTable, &ret); - return _upb_FastDecoder_FallbackToMiniTable(d, ptr, msg, table, hasbits, - data); -} diff --git a/vendor/upb/wire/decode_fast/field_message.c b/vendor/upb/wire/decode_fast/field_message.c deleted file mode 100644 index 04aa71e..0000000 --- a/vendor/upb/wire/decode_fast/field_message.c +++ /dev/null @@ -1,117 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include - -#include "upb/message/internal/message.h" -#include "upb/message/message.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/decode_fast/cardinality.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/data.h" -#include "upb/wire/decode_fast/dispatch.h" -#include "upb/wire/decode_fast/field_parsers.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/decoder.h" - -// Must be last. -#include "upb/port/def.inc" - -typedef struct { - const upb_MiniTable* table; - bool is_repeated; - upb_Message* msg; -} upb_DecodeFast_MessageContext; - -static const char* upb_DecodeFast_MessageData(upb_EpsCopyInputStream* st, - const char* ptr, int size, - void* ctx) { - upb_Decoder* d = (upb_Decoder*)st; - upb_DecodeFast_MessageContext* c = ctx; - ptr = _upb_Decoder_DecodeMessage((upb_Decoder*)st, ptr, c->msg, c->table); - if (d->end_group != DECODE_NOGROUP) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - return ptr; -} - -static bool upb_DecodeFast_SingleMessage(upb_Decoder* d, const char** ptr, - void* dst, upb_DecodeFast_Type type, - upb_DecodeFastNext* next, void* ctx) { - upb_DecodeFast_MessageContext* c = ctx; - void** submsg_dst = dst; - - if (c->is_repeated || UPB_LIKELY(*submsg_dst == NULL)) { - c->msg = *submsg_dst = _upb_Message_New(c->table, &d->arena); - } else { - c->msg = *submsg_dst; // Reusing non-repeated message. - } - - return upb_DecodeFast_Delimited(d, ptr, &upb_DecodeFast_MessageData, next, c); -} - -void upb_DecodeFast_Message(upb_Decoder* d, const char** ptr, upb_Message* msg, - intptr_t table, uint64_t* hasbits, uint64_t* data, - upb_DecodeFastNext* ret, upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality card, - upb_DecodeFast_TagSize tagsize) { - uint16_t submsg_idx = upb_DecodeFastData_GetFieldIndex(*data); - const upb_MiniTable* tablep = decode_totablep(table); - - // OPT: we could remove an indirection by precomputing the offset directly - // to the submessage table pointer, instead of doing an extra hop through the - // field. - const upb_MiniTableField* field = - upb_MiniTable_GetFieldByIndex(tablep, submsg_idx); - const upb_MiniTable* subtablep = upb_MiniTable_GetSubMessageTable(field); - - upb_DecodeFast_MessageContext ctx = {subtablep, - card == kUpb_DecodeFast_Repeated}; - - if (subtablep == NULL) { - UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_FallbackToMiniTable, ret); - return; - } - - // This check is technically redundant because upb_DecodeFast_Unpacked will - // check the tag again. But we perform this check early to avoid erroring out - // for "bounds exceeded" if this is not actually a sub-message field. - // - // The compiler should be able to see that the tag was already checked, so - // the later check should be optimized away. - if (UPB_UNLIKELY(!upb_DecodeFast_MaskedTagIsZero(*data, tagsize))) { - UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_FallbackToMiniTable, ret); - return; - } - - if (--d->depth == 0) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); - } - - upb_DecodeFast_Unpacked(d, ptr, msg, data, hasbits, ret, type, card, tagsize, - &upb_DecodeFast_SingleMessage, &ctx); - - d->depth++; -} - -#define F(type, card, tagsize) \ - const char* UPB_PRESERVE_NONE UPB_DECODEFAST_FUNCNAME( \ - type, card, tagsize)(UPB_PARSE_PARAMS) { \ - upb_DecodeFastNext next = kUpb_DecodeFastNext_Dispatch; \ - upb_DecodeFast_Message(d, &ptr, msg, table, &hasbits, &data, &next, \ - kUpb_DecodeFast_##type, kUpb_DecodeFast_##card, \ - kUpb_DecodeFast_##tagsize); \ - UPB_DECODEFAST_NEXT(next); \ - } - -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, Message) - -#undef F -#undef FASTDECODE_SUBMSG diff --git a/vendor/upb/wire/decode_fast/field_parsers.h b/vendor/upb/wire/decode_fast/field_parsers.h deleted file mode 100644 index a166f87..0000000 --- a/vendor/upb/wire/decode_fast/field_parsers.h +++ /dev/null @@ -1,55 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_ -#define UPB_WIRE_INTERNAL_DECODE_FAST_H_ - -#include -#include - -#include "upb/message/message.h" -#include "upb/wire/decode_fast/combinations.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -struct upb_Decoder; - -// Declare all fast decoder functions. These are referenced by name from either -// the generated code or the array in decode_fast_function_array.c. - -#define PARSE_PARAMS \ - struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ - uint64_t hasbits, uint64_t data - -#define F(type, card, size) \ - UPB_PRESERVE_NONE const char* UPB_DECODEFAST_FUNCNAME(type, card, \ - size)(PARSE_PARAMS); - -UPB_DECODEFAST_FUNCTIONS(F); - -// This just uses the regular (non-fast) parser to parse a single field. -UPB_PRESERVE_NONE -const char* _upb_FastDecoder_FallbackToMiniTable(PARSE_PARAMS); - -UPB_PRESERVE_NONE -const char* _upb_FastDecoder_DecodeGeneric(PARSE_PARAMS); - -#undef F -#undef PARSE_PARAMS - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */ diff --git a/vendor/upb/wire/decode_fast/field_string.c b/vendor/upb/wire/decode_fast/field_string.c deleted file mode 100644 index 24359d2..0000000 --- a/vendor/upb/wire/decode_fast/field_string.c +++ /dev/null @@ -1,102 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include - -#include "upb/base/string_view.h" -#include "upb/wire/decode.h" -#include "upb/wire/decode_fast/cardinality.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/dispatch.h" -#include "upb/wire/decode_fast/field_parsers.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/decoder.h" -#include "utf8_range.h" - -// Must be last. -#include "upb/port/def.inc" - -UPB_FORCEINLINE -bool upb_DecodeFast_SingleStringAlias(upb_Decoder* d, const char** ptr, - void* dst, upb_DecodeFast_Type type, - upb_DecodeFastNext* next, void* ctx) { - UPB_UNUSED(ctx); - bool validate_utf8 = type == kUpb_DecodeFast_String; - upb_StringView* sv = dst; - int size; - - if (!upb_DecodeFast_DecodeSize(d, ptr, &size, next)) return false; - - const char* p = *ptr; - if (!upb_EpsCopyInputStream_ReadStringAlwaysAlias(&d->input, p, size, sv)) { - return UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_FallbackToMiniTable, next); - } - - if (validate_utf8 && !utf8_range_IsValid(sv->data, sv->size)) { - return UPB_DECODEFAST_ERROR(d, kUpb_DecodeStatus_BadUtf8, next); - } - - *ptr = p + size; - return true; -} - -UPB_FORCEINLINE -bool upb_DecodeFast_SingleStringCopy(upb_Decoder* d, const char** ptr, - void* dst, upb_DecodeFast_Type type, - upb_DecodeFastNext* next, void* ctx) { - bool validate_utf8 = type == kUpb_DecodeFast_String; - upb_StringView* sv = dst; - int size; - - if (!upb_DecodeFast_DecodeSize(d, ptr, &size, next)) return false; - - if (!_upb_Decoder_ReadString(d, ptr, size, sv, validate_utf8)) { - sv->size = 0; - return UPB_DECODEFAST_ERROR(d, kUpb_DecodeStatus_OutOfMemory, next); - } - - return true; -} - -#define F_COPY(type, card, tagsize) \ - UPB_NOINLINE UPB_PRESERVE_NONE static const char* UPB_DECODEFAST_FUNCNAME( \ - type, card, tagsize##_Copy)(UPB_PARSE_PARAMS) { \ - upb_DecodeFastNext next = kUpb_DecodeFastNext_Dispatch; \ - upb_DecodeFast_Unpacked(d, &ptr, msg, &data, &hasbits, &next, \ - kUpb_DecodeFast_##type, kUpb_DecodeFast_##card, \ - kUpb_DecodeFast_##tagsize, \ - &upb_DecodeFast_SingleStringCopy, NULL); \ - UPB_DECODEFAST_NEXT(next); \ - } - -#define F(type, card, tagsize) \ - F_COPY(type, card, tagsize) \ - const char* UPB_PRESERVE_NONE UPB_DECODEFAST_FUNCNAME( \ - type, card, tagsize)(UPB_PARSE_PARAMS) { \ - if (UPB_UNLIKELY((d->options & kUpb_DecodeOption_AliasString) == 0)) { \ - UPB_MUSTTAIL return UPB_DECODEFAST_FUNCNAME( \ - type, card, tagsize##_Copy)(UPB_PARSE_ARGS); \ - } \ - upb_DecodeFastNext next = kUpb_DecodeFastNext_Dispatch; \ - upb_DecodeFast_Unpacked(d, &ptr, msg, &data, &hasbits, &next, \ - kUpb_DecodeFast_##type, kUpb_DecodeFast_##card, \ - kUpb_DecodeFast_##tagsize, \ - &upb_DecodeFast_SingleStringAlias, NULL); \ - UPB_DECODEFAST_NEXT(next); \ - } - -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, String) -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, Bytes) - -#undef F -#undef F_COPY - -#undef F -#undef FASTDECODE_LONGSTRING -#undef FASTDECODE_COPYSTRING -#undef FASTDECODE_STRING diff --git a/vendor/upb/wire/decode_fast/field_varint.c b/vendor/upb/wire/decode_fast/field_varint.c deleted file mode 100644 index 2254156..0000000 --- a/vendor/upb/wire/decode_fast/field_varint.c +++ /dev/null @@ -1,167 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include -#include -#include - -#include "upb/base/internal/endian.h" -#include "upb/message/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/decode_fast/cardinality.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/dispatch.h" -#include "upb/wire/decode_fast/field_parsers.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/decoder.h" -#include "upb/wire/reader.h" - -// Must be last. -#include "upb/port/def.inc" - -static bool upb_DecodeFast_SingleVarint(upb_Decoder* d, const char** ptr, - void* dst, upb_DecodeFast_Type type, - upb_DecodeFastNext* next, void* ctx) { - UPB_ASSERT(dst); - UPB_UNUSED(ctx); - - const char* p = *ptr; - uint64_t val; - - p = upb_WireReader_ReadVarint(p, &val, &d->input); - if (!p) { - return UPB_DECODEFAST_ERROR(d, kUpb_DecodeStatus_Malformed, next); - } - - switch (type) { - case kUpb_DecodeFast_Bool: - val = val != 0; - break; - case kUpb_DecodeFast_ZigZag32: { - uint32_t n = val; - val = (n >> 1) ^ -(int32_t)(n & 1); - break; - } - case kUpb_DecodeFast_ZigZag64: { - val = (val >> 1) ^ -(int64_t)(val & 1); - break; - } - default: - break; - } - - UPB_ASSERT(upb_IsLittleEndian()); - memcpy(dst, &val, upb_DecodeFast_ValueBytes(type)); - *ptr = p; - return true; -} - -typedef struct { - upb_Decoder* decoder; - upb_DecodeFast_Type type; - upb_Message* msg; - uint64_t* data; - uint64_t* hasbits; - upb_DecodeFastNext* ret; -} upb_DecodeFast_PackedVarintContext; - -UPB_FORCEINLINE -int upb_DecodeFast_CountVarints(const char* ptr, const char* end) { - int count = 0; - for (; ptr < end; ptr++) { - count += (*ptr & 0x80) == 0; - } - return count; -} - -static const char* upb_DecodeFast_PackedVarint(upb_EpsCopyInputStream* st, - const char* ptr, int size, - void* ctx) { - upb_DecodeFast_PackedVarintContext* c = - (upb_DecodeFast_PackedVarintContext*)ctx; - - if (size == 0) return ptr; // 0-element packed fields are valid. - - upb_DecodeFastArray arr; - int count = upb_DecodeFast_CountVarints(ptr, ptr + size); - int valbytes = upb_DecodeFast_ValueBytes(c->type); - - // If the last byte is a continuation byte, we have a malformed varint. - if (count == 0 || (ptr[size - 1] & 0x80) != 0) { - UPB_DECODEFAST_ERROR(c->decoder, kUpb_DecodeStatus_Malformed, c->ret); - return NULL; - } - - if (!upb_DecodeFast_GetArrayForAppend(c->decoder, ptr, c->msg, *c->data, - c->hasbits, &arr, c->type, count, - c->ret)) { - return NULL; - } - - UPB_ASSERT(arr.dst); - - int read = 0; - while (!upb_DecodeFast_IsDone(c->decoder, &ptr)) { - UPB_ASSERT(read < count); - if (!upb_DecodeFast_SingleVarint(c->decoder, &ptr, arr.dst, c->type, c->ret, - NULL)) { - return NULL; - } - arr.dst = UPB_PTR_AT(arr.dst, valbytes, char); - ++read; - } - - upb_DecodeFastField_SetArraySize(&arr, c->type); - - return ptr; -} - -UPB_FORCEINLINE -void upb_DecodeFast_Varint(upb_Decoder* d, const char** ptr, upb_Message* msg, - intptr_t table, uint64_t* hasbits, uint64_t* data, - upb_DecodeFastNext* ret, upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality card, - upb_DecodeFast_TagSize tagsize) { - if (card == kUpb_DecodeFast_Packed) { - upb_DecodeFast_PackedVarintContext ctx = { - .decoder = d, - .type = type, - .msg = msg, - .data = data, - .hasbits = hasbits, - .ret = ret, - }; - upb_DecodeFast_Packed(d, ptr, type, card, tagsize, data, - &upb_DecodeFast_PackedVarint, ret, &ctx); - } else { - upb_DecodeFast_Unpacked(d, ptr, msg, data, hasbits, ret, type, card, - tagsize, &upb_DecodeFast_SingleVarint, NULL); - } -} - -/* Generate all combinations: - * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ - -#define F(type, card, tagsize) \ - UPB_NOINLINE UPB_PRESERVE_NONE const char* UPB_DECODEFAST_FUNCNAME( \ - type, card, tagsize)(UPB_PARSE_PARAMS) { \ - upb_DecodeFastNext next = kUpb_DecodeFastNext_Dispatch; \ - upb_DecodeFast_Varint(d, &ptr, msg, table, &hasbits, &data, &next, \ - kUpb_DecodeFast_##type, kUpb_DecodeFast_##card, \ - kUpb_DecodeFast_##tagsize); \ - UPB_DECODEFAST_NEXTMAYBEPACKED( \ - next, UPB_DECODEFAST_FUNCNAME(type, Repeated, tagsize), \ - UPB_DECODEFAST_FUNCNAME(type, Packed, tagsize)); \ - } - -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, Bool) -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, Varint32) -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, Varint64) -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, ZigZag32) -UPB_DECODEFAST_CARDINALITIES(UPB_DECODEFAST_TAGSIZES, F, ZigZag64) - -#undef F diff --git a/vendor/upb/wire/decode_fast/function_array.c b/vendor/upb/wire/decode_fast/function_array.c deleted file mode 100644 index 4f6f7d2..0000000 --- a/vendor/upb/wire/decode_fast/function_array.c +++ /dev/null @@ -1,35 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/decode_fast/function_array.h" - -#include -#include - -#include "upb/mini_table/internal/message.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/field_parsers.h" - -// Must be last. -#include "upb/port/def.inc" - -#define ADDR_OF_FUNC(type, card, size) \ - UPB_DECODEFAST_ISENABLED(kUpb_DecodeFast_##type, kUpb_DecodeFast_##card, \ - kUpb_DecodeFast_##size) \ - ? &UPB_DECODEFAST_FUNCNAME(type, card, size) : _upb_FastDecoder_DecodeGeneric, - -static _upb_FieldParser* funcs[] = {UPB_DECODEFAST_FUNCTIONS(ADDR_OF_FUNC)}; - -#undef ADDR_OF_FUNC - -_upb_FieldParser* upb_DecodeFast_GetFunctionPointer(uint32_t function_idx) { - if (function_idx == UINT32_MAX) return &_upb_FastDecoder_DecodeGeneric; - UPB_ASSERT(function_idx < UPB_ARRAY_SIZE(funcs)); - return funcs[function_idx]; -} - -#include "upb/port/undef.inc" diff --git a/vendor/upb/wire/decode_fast/function_array.h b/vendor/upb/wire/decode_fast/function_array.h deleted file mode 100644 index 973516b..0000000 --- a/vendor/upb/wire/decode_fast/function_array.h +++ /dev/null @@ -1,17 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_FUNCTION_ARRAY_H_ -#define UPB_WIRE_INTERNAL_DECODE_FAST_FUNCTION_ARRAY_H_ - -#include - -#include "upb/mini_table/internal/message.h" - -_upb_FieldParser* upb_DecodeFast_GetFunctionPointer(uint32_t function_idx); - -#endif // UPB_WIRE_INTERNAL_DECODE_FAST_FUNCTION_ARRAY_H_ diff --git a/vendor/upb/wire/decode_fast/select.c b/vendor/upb/wire/decode_fast/select.c deleted file mode 100644 index 883349c..0000000 --- a/vendor/upb/wire/decode_fast/select.c +++ /dev/null @@ -1,244 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/decode_fast/select.h" - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/internal/log2.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/data.h" -#include "upb/wire/types.h" - -// Must be last. -#include "upb/port/def.inc" - -uint32_t GetWireTypeForField(const upb_MiniTableField* field) { - if (upb_MiniTableField_IsPacked(field)) return kUpb_WireType_Delimited; - switch (upb_MiniTableField_Type(field)) { - case kUpb_FieldType_Double: - case kUpb_FieldType_Fixed64: - case kUpb_FieldType_SFixed64: - return kUpb_WireType_64Bit; - case kUpb_FieldType_Float: - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - return kUpb_WireType_32Bit; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - case kUpb_FieldType_Int32: - case kUpb_FieldType_Bool: - case kUpb_FieldType_UInt32: - case kUpb_FieldType_Enum: - case kUpb_FieldType_SInt32: - case kUpb_FieldType_SInt64: - return kUpb_WireType_Varint; - case kUpb_FieldType_Group: - return kUpb_WireType_StartGroup; - case kUpb_FieldType_Message: - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: - return kUpb_WireType_Delimited; - default: - UPB_UNREACHABLE(); - } -} - -static bool upb_DecodeFast_GetEncodedTag(const upb_MiniTableField* field, - uint16_t* out_tag, - upb_DecodeFast_TagSize* out_tag_size) { - uint32_t num = upb_MiniTableField_Number(field); - uint32_t wire_type = GetWireTypeForField(field); - if (num >= 2048) { - return false; // Tag >2 bytes, too large for fast decode. - } else if (num >= 16) { - *out_tag = ((num << 4) & 0x7f00) | 0x80 | ((num << 3) & 0x7f) | wire_type; - *out_tag_size = kUpb_DecodeFast_Tag2Byte; - return true; - } else { - *out_tag = (num << 3) | wire_type; - *out_tag_size = kUpb_DecodeFast_Tag1Byte; - return true; - } -} - -static bool upb_DecodeFast_GetFieldCardinality( - const upb_MiniTableField* field, - upb_DecodeFast_Cardinality* out_cardinality) { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Map: - return false; // Can't parse maps with fast decode. - case kUpb_FieldMode_Array: - *out_cardinality = upb_MiniTableField_IsPacked(field) - ? kUpb_DecodeFast_Packed - : kUpb_DecodeFast_Repeated; - return true; - case kUpb_FieldMode_Scalar: - *out_cardinality = upb_MiniTableField_IsInOneof(field) - ? kUpb_DecodeFast_Oneof - : kUpb_DecodeFast_Scalar; - return true; - } - UPB_UNREACHABLE(); -} - -static bool upb_DecodeFast_GetFieldType(const upb_MiniTable* m, - const upb_MiniTableField* field, - upb_DecodeFast_Type* out_type) { - // We use descriptortype directly instead of upb_MiniTableField_Type because - // we want the munging of field->descriptortype: - // - kUpb_FieldType_String -> kUpb_FieldType_Bytes if no UTF-8 validation is - // required. - // - kUpb_FieldType_Enum -> kUpb_FieldType_Int32 if the enum is open. - upb_FieldType type = field->UPB_PRIVATE(descriptortype); - - if (type == kUpb_FieldType_Group || upb_MiniTableField_IsClosedEnum(field)) { - return false; // Currently not supported. - } - - static const int8_t types[] = { - [kUpb_FieldType_Bool] = kUpb_DecodeFast_Bool, - [kUpb_FieldType_Enum] = kUpb_DecodeFast_Varint32, - [kUpb_FieldType_Int32] = kUpb_DecodeFast_Varint32, - [kUpb_FieldType_UInt32] = kUpb_DecodeFast_Varint32, - [kUpb_FieldType_Int64] = kUpb_DecodeFast_Varint64, - [kUpb_FieldType_UInt64] = kUpb_DecodeFast_Varint64, - [kUpb_FieldType_Fixed32] = kUpb_DecodeFast_Fixed32, - [kUpb_FieldType_SFixed32] = kUpb_DecodeFast_Fixed32, - [kUpb_FieldType_Float] = kUpb_DecodeFast_Fixed32, - [kUpb_FieldType_Fixed64] = kUpb_DecodeFast_Fixed64, - [kUpb_FieldType_SFixed64] = kUpb_DecodeFast_Fixed64, - [kUpb_FieldType_Double] = kUpb_DecodeFast_Fixed64, - [kUpb_FieldType_SInt32] = kUpb_DecodeFast_ZigZag32, - [kUpb_FieldType_SInt64] = kUpb_DecodeFast_ZigZag64, - [kUpb_FieldType_String] = kUpb_DecodeFast_String, - [kUpb_FieldType_Bytes] = kUpb_DecodeFast_Bytes, - [kUpb_FieldType_Message] = kUpb_DecodeFast_Message, - }; - - UPB_ASSERT(type < UPB_ARRAY_SIZE(types)); - *out_type = types[type]; - return true; -} - -static bool upb_DecodeFast_GetFunctionIndex(const upb_MiniTable* m, - const upb_MiniTableField* field, - upb_DecodeFast_TagSize tag_size, - uint32_t* out_index) { - upb_DecodeFast_Cardinality cardinality; - upb_DecodeFast_Type type; - if (!upb_DecodeFast_GetFieldCardinality(field, &cardinality)) return false; - if (!upb_DecodeFast_GetFieldType(m, field, &type)) return false; - - *out_index = type << 3 | cardinality << 1 | tag_size; - return true; -} - -static uint64_t upb_DecodeFast_GetPresence(const upb_MiniTableField* field, - uint64_t* out_data) { - if (upb_MiniTableField_IsInOneof(field)) { - *out_data = upb_MiniTableField_Number(field); - return true; - } else if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(field)) { - *out_data = field->presence - 64; - return *out_data < 32; // We use uint32_t for hasbits currently. - } else { - // We only store 32 bits of hasbits back to the message, so for fields that - // don't have a hasbit, we just set the high bit which won't be stored. - *out_data = 63; - return true; - } -} - -static bool upb_DecodeFast_GetFunctionData(const upb_MiniTable* m, - const upb_MiniTableField* field, - uint16_t tag, uint64_t* out_data) { - uint64_t offset = UPB_PRIVATE(_upb_MiniTableField_Offset)(field); - uint64_t case_offset = - upb_MiniTableField_IsInOneof(field) - ? UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(field) - : 0; - uint64_t field_index = upb_MiniTableField_IsSubMessage(field) - ? field - m->UPB_PRIVATE(fields) - : 0; - - uint64_t presence; - - return upb_DecodeFast_GetPresence(field, &presence) && - upb_DecodeFast_MakeData(offset, case_offset, presence, field_index, - tag, out_data); -} - -static bool upb_DecodeFast_TryFillEntry(const upb_MiniTable* m, - const upb_MiniTableField* field, - upb_DecodeFast_TableEntry* entry) { - UPB_ASSERT(!upb_MiniTableField_IsExtension(field)); - uint16_t tag; - upb_DecodeFast_TagSize tag_size; - return upb_DecodeFast_GetEncodedTag(field, &tag, &tag_size) && - upb_DecodeFast_GetFunctionIndex(m, field, tag_size, - &entry->function_idx) && - UPB_DECODEFAST_ISENABLED( - upb_DecodeFast_GetType(entry->function_idx), - upb_DecodeFast_GetCardinality(entry->function_idx), - upb_DecodeFast_GetTagSize(entry->function_idx)) && - upb_DecodeFast_GetFunctionData(m, field, tag, &entry->function_data); -} - -int upb_DecodeFast_BuildTable(const upb_MiniTable* m, - upb_DecodeFast_TableEntry table[32]) { - if (m->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry) return 0; - - for (size_t i = 0; i < 32; i++) { - table[i].function_idx = UINT32_MAX; - table[i].function_data = 0; - } - - int max = 0; - for (size_t i = 0, n = upb_MiniTable_FieldCount(m); i < n; i++) { - const upb_MiniTableField* field = upb_MiniTable_GetFieldByIndex(m, i); - upb_DecodeFast_TableEntry entry; - if (!upb_DecodeFast_TryFillEntry(m, field, &entry)) continue; - int slot = upb_DecodeFastData_GetTableSlot(entry.function_data); - if (table[slot].function_idx == UINT32_MAX) { - table[slot] = entry; - max = UPB_MAX(max, slot); - } - } - - return max == 0 ? 0 : upb_RoundUpToPowerOfTwo(max + 1); -} - -uint8_t upb_DecodeFast_GetTableMask(int table_size) { - return table_size > 0 ? (table_size - 1) << 3 : 255; -} - -const char* upb_DecodeFast_GetFunctionName(uint32_t function_idx) { -#define STRINGIFY1(x) #x -#define STRINGIFY2(x) STRINGIFY1(x) -#define FUNCSTR(...) STRINGIFY2(UPB_DECODEFAST_FUNCNAME(__VA_ARGS__)), - // Constructing all combinations of strings at compile time wastes ~2k of - // binary size and RAM compared with using eg. snprintf() at runtime. But - // this function is only used from the compiler, where 2k is inconsequential. - static const char* names[] = {UPB_DECODEFAST_FUNCTIONS(FUNCSTR)}; -#undef STRINGIFY1 -#undef STRINGIFY2 -#undef FUNCSTR - - if (function_idx == UINT32_MAX) return "_upb_FastDecoder_DecodeGeneric"; - UPB_ASSERT(function_idx < UPB_ARRAY_SIZE(names)); - return names[function_idx]; -} - -#include "upb/port/undef.inc" diff --git a/vendor/upb/wire/decode_fast/select.h b/vendor/upb/wire/decode_fast/select.h deleted file mode 100644 index 07b22a0..0000000 --- a/vendor/upb/wire/decode_fast/select.h +++ /dev/null @@ -1,66 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_SELECT_H_ -#define UPB_WIRE_INTERNAL_DECODE_FAST_SELECT_H_ - -#include -#include - -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - // The function that will be called to parse this field. The function - // pointer for it must be placed into _upb_FastTable_Entry.field_parser. - // - // The function pointer can be either looked up at runtime via - // upb_DecodeFast_GetFunctionPointer(), or be referenced in generated code via - // upb_DecodeFast_GetFunctionName(). - uint32_t function_idx; - - // The associated data that will be passed to the function. This must be - // placed into _upb_FastTable_Entry.field_data. - uint64_t function_data; -} upb_DecodeFast_TableEntry; - -// Builds the fasttable for the given message. The table will be written into -// the given array. Returns the number of entries in the table that were -// actually used, and should be written to the MiniTable (this number may be -// less than 32). -// -// This function will assume that the lower a field number, the hotter the field -// is. If at some point we get access to more information about field usage, -// we should consider using that instead. -int upb_DecodeFast_BuildTable(const upb_MiniTable* m, - upb_DecodeFast_TableEntry table[32]); - -// Returns the mask that should be placed into the table_mask field of the -// mini table for the given table size. -uint8_t upb_DecodeFast_GetTableMask(int table_size); - -// Translates a function index into the canonical function name which can be -// emitted into generated code. -const char* upb_DecodeFast_GetFunctionName(uint32_t function_idx); - -// Returns a function pointer for the given function index. -_upb_FieldParser* upb_DecodeFast_GetFunctionPointer(uint32_t function_idx); - -#ifdef __cplusplus -} // extern "C" -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_INTERNAL_DECODE_FAST_SELECT_H_ diff --git a/vendor/upb/wire/decode_fast/select_test.cc b/vendor/upb/wire/decode_fast/select_test.cc deleted file mode 100644 index 2a167c0..0000000 --- a/vendor/upb/wire/decode_fast/select_test.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "upb/wire/decode_fast/select.h" - -#include -#include -#include - -#include -#include "absl/base/macros.h" -#include "upb/wire/decode_fast/combinations.h" - -namespace { - -TEST(SelectTest, FunctionIndicesMatch) { - // Verify that UPB_DECODEFAST_FUNCTION_IDX() and UPB_DECODEFAST_FUNCTIONS() - // use the same ordering and the indexes correctly match. -#define IDX(type, card, size) \ - UPB_DECODEFAST_FUNCTION_IDX(kUpb_DecodeFast_##type, kUpb_DecodeFast_##card, \ - kUpb_DecodeFast_##size), - static const uint32_t numbers[] = {UPB_DECODEFAST_FUNCTIONS(IDX)}; - for (size_t i = 0; i < ABSL_ARRAYSIZE(numbers); i++) { - EXPECT_EQ(numbers[i], i) << upb_DecodeFast_GetFunctionName(i) << " vs " - << upb_DecodeFast_GetFunctionName(numbers[i]); - } -#undef IDX -} // namespace - -} // namespace diff --git a/vendor/upb/wire/decode_test.cc b/vendor/upb/wire/decode_test.cc deleted file mode 100644 index 48a4aa0..0000000 --- a/vendor/upb/wire/decode_test.cc +++ /dev/null @@ -1,408 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/decode.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" -#include "upb/mem/arena.hpp" -#include "upb/message/accessors.h" -#include "upb/message/accessors.hpp" -#include "upb/message/array.h" -#include "upb/message/message.h" -#include "upb/mini_descriptor/link.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/test_util/field_types.h" -#include "upb/wire/test_util/make_mini_table.h" -#include "upb/wire/test_util/wire_message.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace upb { -namespace test { - -namespace { - -template -struct TestValues { - static constexpr T kZero = 0; - static constexpr T kMin = std::numeric_limits::min(); - static constexpr T kMax = std::numeric_limits::max(); -}; - -template <> -struct TestValues { - static constexpr absl::string_view kZero = ""; - static constexpr absl::string_view kMin = "a very minimum valued string!"; - static constexpr absl::string_view kMax = "a very maximum valued string!"; -}; - -template -std::optional GetOptionalField(upb_Message* msg, - const upb_MiniTableField* field) { - if (upb_Message_HasBaseField(msg, field)) { - return GetMessageBaseField(msg, field, T{}); - } else { - return std::nullopt; - } -} - -template -class FieldTypeTest : public testing::Test {}; - -TYPED_TEST_SUITE(FieldTypeTest, FieldTypes); - -std::string ExpectedSingleFieldTrace(const upb_MiniTable* mt, - const upb_MiniTableField* field) { -#ifdef NDEBUG - return ""; -#else - return MiniTable::HasFastTableEntry(mt, field) ? "DF" : "M"; -#endif -} - -std::string ExpectedRepeatedFieldTrace(const upb_MiniTable* mt, - const upb_MiniTableField* field, - int count) { -#ifdef NDEBUG - return ""; -#else - if (MiniTable::HasFastTableEntry(mt, field)) { - // Fasttable repeated fields have a fast path where we bypass dispatch if - // the same tag is encountered consecutively. - return absl::StrCat("D", std::string(count, 'F')); - } else { - return std::string(count, 'M'); - } -#endif -} - -std::string FilteredTrace(absl::string_view trace) { - std::string filtered; - for (char c : trace) { - if (!absl::ascii_islower(c)) filtered.push_back(c); - } - return filtered; -} - -TYPED_TEST(FieldTypeTest, DecodeOptionalMaxValue) { - char trace_buf[64]; - using Value = typename TypeParam::Value; - upb::Arena arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Scalar, arena.ptr()); - upb_Message* msg = upb_Message_New(mt, arena.ptr()); - std::string payload = ToBinaryPayload(wire_types::WireMessage{ - {1, TypeParam::WireValue(Value(TestValues::kMax))}}); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetOptionalField(msg, field), TestValues::kMax); - EXPECT_EQ(absl::string_view(trace_buf), ExpectedSingleFieldTrace(mt, field)); -} - -TYPED_TEST(FieldTypeTest, DecodeOptionalMinValue) { - char trace_buf[64]; - using Value = typename TypeParam::Value; - upb::Arena arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Scalar, arena.ptr()); - upb_Message* msg = upb_Message_New(mt, arena.ptr()); - std::string payload = ToBinaryPayload(wire_types::WireMessage{ - {1, TypeParam::WireValue(Value(TestValues::kMin))}}); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetOptionalField(msg, field), TestValues::kMin); - EXPECT_EQ(absl::string_view(trace_buf), ExpectedSingleFieldTrace(mt, field)); -} - -TYPED_TEST(FieldTypeTest, DecodeOneofMaxValue) { - char trace_buf[64]; - using Value = typename TypeParam::Value; - upb::Arena arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Oneof, arena.ptr()); - upb_Message* msg = upb_Message_New(mt, arena.ptr()); - std::string payload = ToBinaryPayload(wire_types::WireMessage{ - {1, TypeParam::WireValue(Value(TestValues::kMax))}}); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetOptionalField(msg, field), TestValues::kMax); - EXPECT_EQ(absl::string_view(trace_buf), ExpectedSingleFieldTrace(mt, field)); -} - -TYPED_TEST(FieldTypeTest, DecodeRepeated) { - char trace_buf[64]; - using Value = typename TypeParam::Value; - Value value; - if constexpr (std::is_same_v) { - for (int i = 0; i < 1000; ++i) { - value.append("hello world! "); - } - } else { - value = std::numeric_limits::max(); - } - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Repeated, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - std::string payload = ToBinaryPayload(wire_types::WireMessage{ - {1, TypeParam::WireValue(Value(TestValues::kZero))}, - {1, TypeParam::WireValue(Value(TestValues::kMin))}, - {1, TypeParam::WireValue(Value(TestValues::kMax))}, - }); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetRepeatedField(msg, field), - (std::vector{Value(TestValues::kZero), - Value(TestValues::kMin), - Value(TestValues::kMax)})); - EXPECT_EQ(FilteredTrace(absl::string_view(trace_buf)), - ExpectedRepeatedFieldTrace(mt, field, 3)); -} - -template -class PackedTest : public testing::Test {}; - -TYPED_TEST_SUITE(PackedTest, PackableFieldTypes); - -TYPED_TEST(PackedTest, DecodePackedDataForPackedField) { - char trace_buf[64]; - using Value = typename TypeParam::Value; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Packed, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - std::string packed_value = ToBinaryPayload(TypeParam::WireValue(0)) + - ToBinaryPayload(TypeParam::WireValue(1 << 10)) + - ToBinaryPayload(TypeParam::WireValue(1 << 20)); - std::string payload = ToBinaryPayload( - wire_types::WireMessage{{1, wire_types::Delimited{packed_value}}}); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetRepeatedField(msg, field), - (std::vector{0, static_cast(1 << 10), - static_cast(1 << 20)})); - EXPECT_EQ(absl::string_view(trace_buf), ExpectedSingleFieldTrace(mt, field)); -} - -TYPED_TEST(PackedTest, DecodeTruncatedPackedField) { - char trace_buf[64]; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Packed, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - std::string packed_value = - ToBinaryPayload(TypeParam::WireValue(0)) + - ToBinaryPayload(TypeParam::WireValue(1 << 10)) + - // For varint fields, this will be a multi-byte varint, such that - // truncating the last byte will result in an invalid varint. - ToBinaryPayloadWithLongVarints(TypeParam::WireValue(1 << 20), 2, 2); - packed_value.resize(packed_value.size() - 1); // Truncate the last byte. - std::string payload = ToBinaryPayload( - wire_types::WireMessage{{1, wire_types::Delimited{packed_value}}}); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Malformed) - << upb_DecodeStatus_String(result); -} - -TYPED_TEST(PackedTest, DecodeEmptyPackedField) { - char trace_buf[64]; - using Value = typename TypeParam::Value; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Packed, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - std::string payload = - ToBinaryPayload(wire_types::WireMessage{{1, wire_types::Delimited{""}}}); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetRepeatedField(msg, field), (std::vector{})); - EXPECT_EQ(absl::string_view(trace_buf), ExpectedSingleFieldTrace(mt, field)); -} - -TYPED_TEST(PackedTest, DecodePackedDataForUnpackedField) { - // Schema says this is not a packed field, but we supply packed wire format. - char trace_buf[64]; - using Value = typename TypeParam::Value; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Repeated, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - std::string packed_value = ToBinaryPayload(TypeParam::WireValue(0)) + - ToBinaryPayload(TypeParam::WireValue(1 << 10)) + - ToBinaryPayload(TypeParam::WireValue(1 << 20)); - std::string payload = ToBinaryPayload( - wire_types::WireMessage{{1, wire_types::Delimited{packed_value}}}); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetRepeatedField(msg, field), - (std::vector{0, static_cast(1 << 10), - static_cast(1 << 20)})); - // Even though there is a mismatch, we can still parse this fast. - EXPECT_EQ(absl::string_view(trace_buf), ExpectedSingleFieldTrace(mt, field)); -} - -TYPED_TEST(PackedTest, DecodeUnpackedDataForPackedField) { - // Schema says this is a packed field, but we supply unpacked wire format. - char trace_buf[64]; - using Value = typename TypeParam::Value; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Packed, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - std::string payload = ToBinaryPayload(wire_types::WireMessage{ - {1, TypeParam::WireValue(0)}, - {1, TypeParam::WireValue(1 << 10)}, - {1, TypeParam::WireValue(1 << 20)}, - }); - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetRepeatedField(msg, field), - (std::vector{0, static_cast(1 << 10), - static_cast(1 << 20)})); - // Even though there is a mismatch, we can still parse this fast. - EXPECT_EQ(FilteredTrace(absl::string_view(trace_buf)), - ExpectedRepeatedFieldTrace(mt, field, 3)); -} - -TEST(RepeatedFieldTest, RepeatedMessageFallback) { - Arena mt_arena; - Arena msg_arena; - - auto [sub_mt, sub_field] = - test::MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Scalar, mt_arena.ptr()); - - auto [mt, field] = - test::MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Repeated, mt_arena.ptr()); - - const upb_MiniTable* subs[1] = {sub_mt}; - bool linked = - upb_MiniTable_Link(const_cast(mt), subs, 1, nullptr, 0); - ASSERT_TRUE(linked); - - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - - // Payload: - // Element 1: tag 1, len 2, int32 value 5 - // Element 2: tag 1, len 2 (parsed as overlong 3-byte varint to trigger - // fasttable fallback), int32 value 6 - std::string payload("\x0a\x02\x08\x05\x0a\x82\x80\x00\x08\x06", 10); - upb_DecodeStatus result = upb_Decode(payload.data(), payload.size(), msg, mt, - nullptr, 0, msg_arena.ptr()); - - // Fasttable fallback used to drop the first element for repeated messages - // because array size wasn't updated. - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - - const upb_Array* arr = upb_Message_GetArray(msg, field); - ASSERT_NE(arr, nullptr); - EXPECT_EQ(upb_Array_Size(arr), 2); -} - -TEST(RepeatedFieldTest, LongRepeatedField) { - auto trace_buf = std::make_unique>(); - using TypeParam = field_types::Fixed64; - using Value = typename TypeParam::Value; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Packed, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - wire_types::WireMessage wire_msg; - std::vector expected; - for (int i = 0; i < 256; ++i) { - wire_msg.push_back({1, TypeParam::WireValue(i)}); - expected.push_back(i); - } - std::string payload = ToBinaryPayload(wire_msg); - upb_DecodeStatus result = upb_DecodeWithTrace( - payload.data(), payload.size(), msg, mt, nullptr, 0, msg_arena.ptr(), - trace_buf->data(), trace_buf->size()); - ASSERT_EQ(result, kUpb_DecodeStatus_Ok) << upb_DecodeStatus_String(result); - EXPECT_EQ(GetRepeatedField(msg, field), expected); - - // We can't easily check the trace here because the large array size will - // force reallocations that cause fallbacks to the MiniTable decoder. -} - -TYPED_TEST(PackedTest, DecodeTruncatedPackedFieldMaxLen) { - char trace_buf[64]; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Packed, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - // Malformed payload with the maximum allowed varint length but only one byte - // of data. - std::string payload = "\012\xff\xff\xff\xff\x07\000\000\000\000"; - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Malformed) - << upb_DecodeStatus_String(result); -} - -TYPED_TEST(PackedTest, DecodeTruncatedPackedFieldShortLength) { - char trace_buf[64]; - upb::Arena msg_arena; - upb::Arena mt_arena; - auto [mt, field] = MiniTable::MakeSingleFieldTable( - 1, kUpb_DecodeFast_Packed, mt_arena.ptr()); - upb_Message* msg = upb_Message_New(mt, msg_arena.ptr()); - // Malformed payload with the maximum allowed varint length but only one byte - // of data. - std::string payload = "\012\001"; - upb_DecodeStatus result = - upb_DecodeWithTrace(payload.data(), payload.size(), msg, mt, nullptr, 0, - msg_arena.ptr(), trace_buf, sizeof(trace_buf)); - ASSERT_EQ(result, kUpb_DecodeStatus_Malformed) - << upb_DecodeStatus_String(result); -} - -} // namespace - -} // namespace test -} // namespace upb diff --git a/vendor/upb/wire/encode.c b/vendor/upb/wire/encode.c deleted file mode 100644 index e1fca7b..0000000 --- a/vendor/upb/wire/encode.c +++ /dev/null @@ -1,961 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// We encode backwards, to avoid pre-computing lengths (one-pass encode). - -#include "upb/wire/encode.h" - -#include -#include -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/internal/endian.h" -#include "upb/base/internal/log2.h" -#include "upb/base/string_view.h" -#include "upb/hash/common.h" -#include "upb/hash/int_table.h" -#include "upb/hash/str_table.h" -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/internal/accessors.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/extension.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/map_entry.h" -#include "upb/message/internal/map_sorter.h" -#include "upb/message/internal/message.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/message.h" -#include "upb/wire/internal/constants.h" -#include "upb/wire/internal/encoder.h" -#include "upb/wire/types.h" -#include "upb/wire/writer.h" - -// Must be last. -#include "upb/port/def.inc" - -static uint32_t encode_zz32(int32_t n) { - return ((uint32_t)n << 1) ^ (n >> 31); -} -static uint64_t encode_zz64(int64_t n) { - return ((uint64_t)n << 1) ^ (n >> 63); -} - -UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { - UPB_ASSERT(s != kUpb_EncodeStatus_Ok); - e->status = s; - UPB_LONGJMP(*e->err, 1); -} - -// Subtraction is used for bounds checks, and the C standard says that pointer -// subtraction is UB if the pointers aren't part of the same array or one past -// the end, so we must avoid NULL - NULL. C++ defines it though. -static char initial_buf_sentinel; - -UPB_NOINLINE static char* encode_growbuffer(char* ptr, upb_encstate* e, - size_t bytes) { - size_t old_size = e->limit - e->buf; - size_t needed_size = bytes + (e->limit - ptr); - if (needed_size < bytes) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - size_t new_size = upb_RoundUpToPowerOfTwo(UPB_MAX(128, needed_size)); - if (new_size == old_size) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - void* old_buf = e->buf == &initial_buf_sentinel ? NULL : (void*)e->buf; - char* new_buf = upb_Arena_Realloc(e->arena, old_buf, old_size, new_size); - - if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - - // We want previous data at the end, realloc() put it at the beginning. - // TODO: This is somewhat inefficient since we are copying twice. - // Maybe create a realloc() that copies to the end of the new buffer? - if (old_size > 0) { - memmove(new_buf + new_size - old_size, new_buf, old_size); - } - - e->buf = new_buf; - e->limit = new_buf + new_size; - return new_buf + new_size - needed_size; -} - -/* Call to ensure that at least `bytes` bytes are available for writing at - * ptr. */ -UPB_FORCEINLINE -char* encode_reserve(char* ptr, upb_encstate* e, size_t bytes) { - if ((size_t)(ptr - e->buf) < bytes) { - return encode_growbuffer(ptr, e, bytes); - } - - return ptr - bytes; -} - -static char* encode_bytes_unchecked(char* ptr, upb_encstate* e, - const void* data, size_t len) { - if (len == 0) return ptr; /* memcpy() with zero size is UB */ - ptr -= len; - memcpy(ptr, data, len); - return ptr; -} - -/* Writes the given bytes to the buffer, handling reserve/advance. */ -static char* encode_bytes(char* ptr, upb_encstate* e, const void* data, - size_t len) { - if (len == 0) return ptr; /* memcpy() with zero size is UB */ - ptr = encode_reserve(ptr, e, len); - memcpy(ptr, data, len); - return ptr; -} - -static char* encode_fixed64_unchecked(char* ptr, upb_encstate* e, - uint64_t val) { - val = upb_BigEndian64(val); - return encode_bytes_unchecked(ptr, e, &val, sizeof(uint64_t)); -} - -static char* encode_fixed32_unchecked(char* ptr, upb_encstate* e, - uint32_t val) { - val = upb_BigEndian32(val); - return encode_bytes_unchecked(ptr, e, &val, sizeof(uint32_t)); -} - -#define UPB_PB_VARINT_MAX_LEN 10 -#define UPB_PB_VARINT32_MAX_LEN 5 - -#if UPB_ARM64_ASM -// Each arm64 instruction encodes to 4 bytes, and it takes two intructions -// to process each byte of output, so we branch ahead by (4 + 4) * skip to -// avoid the remaining bytes. When BTI is on, we need to use specific -// "landing pad" instructions, so we pad those with nop to make it a power -// of 2, skipping 16 bytes at each stage instead of 8. This carries some -// overhead especially on in-order cores so they're not included unless -// building with branch protection. -#if UPB_ARM64_BTI_DEFAULT -// BTI is used with jc targets here because we don't control which register will -// be used for addr; if it's x16 or x17 a `br` is treated like a call. -#define UPB_BTI_JC "bti jc\n" -#define UPB_BTI_NOP "nop\n" -#define UPB_BTI_SHIFT_IMM "4\n" -#else -#define UPB_BTI_JC -#define UPB_BTI_NOP -#define UPB_BTI_SHIFT_IMM "3\n" -#endif -UPB_NOINLINE static char* encode_longvarint(char* ptr, upb_encstate* e, - uint64_t val) { - ptr = encode_reserve(ptr, e, UPB_PB_VARINT_MAX_LEN); - uint64_t clz; - __asm__("clz %[cnt], %[val]\n" : [cnt] "=r"(clz) : [val] "r"(val)); - - uint32_t skip = - UPB_PRIVATE(upb_WireWriter_VarintUnusedSizeFromLeadingZeros64)(clz); - - ptr += skip; - uint64_t addr, mask; - __asm__ volatile( - // Formatter keeps merging short lines - // clang-format off - "adr %[addr], 0f\n" - "add %[addr], %[addr], %[cnt], lsl #" UPB_BTI_SHIFT_IMM - "mov %w[mask], #0x80\n" - "br %[addr]\n" - // Work around llvm/llvm-project#47432, where alignment directives inside - // functions crash the compiler when generating SEH info on windows. - #ifndef __SEH__ - ".p2align " UPB_BTI_SHIFT_IMM - #endif - "0:\n" - // We don't need addr any more, but we've got the register for our whole - // assembly block so we'll use it as scratch to store the shift+masked - // values before storing them. - // The following stores are unsigned offset stores: - // strb Wt, [Xn, #imm] - UPB_BTI_JC - "orr %[addr], %[mask], %[val], lsr #56\n" - "strb %w[addr], [%[ptr], #8]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %[addr], %[mask], %[val], lsr #49\n" - "strb %w[addr], [%[ptr], #7]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %[addr], %[mask], %[val], lsr #42\n" - "strb %w[addr], [%[ptr], #6]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %[addr], %[mask], %[val], lsr #35\n" - "strb %w[addr], [%[ptr], #5]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %[addr], %[mask], %[val], lsr #28\n" - "strb %w[addr], [%[ptr], #4]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %w[addr], %w[mask], %w[val], lsr #21\n" - "strb %w[addr], [%[ptr], #3]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %w[addr], %w[mask], %w[val], lsr #14\n" - "strb %w[addr], [%[ptr], #2]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %w[addr], %w[mask], %w[val], lsr #7\n" - "strb %w[addr], [%[ptr], #1]\n" - UPB_BTI_NOP - - UPB_BTI_JC - "orr %w[addr], %w[val], #0x80\n" - "strb %w[addr], [%[ptr]]\n" - UPB_BTI_NOP - - UPB_BTI_JC - // clang-format on - : [addr] "=&r"(addr), [mask] "=&r"(mask) - : [val] "r"(val), [ptr] "r"(ptr), [cnt] "r"((uint64_t)skip) - : "memory"); - uint32_t continuations = UPB_PB_VARINT_MAX_LEN - 1 - skip; - // msan can't instrument stores in inline assembly - UPB_PRIVATE(upb_Xsan_MarkInitialized)(ptr, continuations); - // Encode the final byte after the continuation bytes. - ptr[continuations] = val >> (7 * continuations); - return ptr; -} -#undef UPB_BTI_JC -#undef UPB_BTI_NOP -#undef UPB_BTI_SHIFT_IMM -#else -UPB_NOINLINE -static char* encode_longvarint(char* ptr, upb_encstate* e, uint64_t val) { - ptr = encode_reserve(ptr, e, UPB_PB_VARINT_MAX_LEN); - size_t len = 0; - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - ptr[len++] = byte; - } while (val); - char* start = ptr + UPB_PB_VARINT_MAX_LEN - len; - memmove(start, ptr, len); - return start; -} -#endif - -UPB_FORCEINLINE -char* encode_varint_unchecked(char* ptr, upb_encstate* e, uint64_t val) { - if (val < 128) { - --ptr; - *ptr = val; - return ptr; - } else { - return encode_longvarint(ptr, e, val); - } -} -UPB_FORCEINLINE -char* encode_varint(char* ptr, upb_encstate* e, uint64_t val) { - if (val < 128 && ptr != e->buf) { - --ptr; - *ptr = val; - return ptr; - } else { - return encode_longvarint(ptr, e, val); - } -} - -UPB_NOINLINE -char* encode_longlength(char* ptr, upb_encstate* e, uint64_t val) { - if (val > INT32_MAX) { - encode_err(e, kUpb_EncodeStatus_MaxSizeExceeded); - } - return encode_longvarint(ptr, e, val); -} - -UPB_FORCEINLINE -char* encode_length(char* ptr, upb_encstate* e, uint64_t val) { - if (val < 128 && ptr != e->buf) { - --ptr; - *ptr = val; - return ptr; - } else { - return encode_longlength(ptr, e, val); - } -} - -UPB_FORCEINLINE -char* encode_length_unchecked(char* ptr, upb_encstate* e, uint64_t val) { - if (val < 128) { - --ptr; - *ptr = val; - return ptr; - } else { - return encode_longlength(ptr, e, val); - } -} - -static char* encode_double_unchecked(char* ptr, upb_encstate* e, double d) { - uint64_t u64; - UPB_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t), "bad double size"); - memcpy(&u64, &d, sizeof(uint64_t)); - return encode_fixed64_unchecked(ptr, e, u64); -} - -static char* encode_float_unchecked(char* ptr, upb_encstate* e, float d) { - uint32_t u32; - UPB_STATIC_ASSERT(sizeof(float) == sizeof(uint32_t), "bad float size"); - memcpy(&u32, &d, sizeof(uint32_t)); - return encode_fixed32_unchecked(ptr, e, u32); -} - -static char* encode_tag_unchecked(char* ptr, upb_encstate* e, - uint32_t field_number, uint8_t wire_type) { - return encode_varint_unchecked(ptr, e, (field_number << 3) | wire_type); -} - -static char* encode_tag(char* ptr, upb_encstate* e, uint32_t field_number, - uint8_t wire_type) { - return encode_varint(ptr, e, (field_number << 3) | wire_type); -} - -static char* encode_fixedarray(char* ptr, upb_encstate* e, const upb_Array* arr, - size_t elem_size, uint32_t tag) { - size_t bytes = upb_Array_Size(arr) * elem_size; - const char* data = upb_Array_DataPtr(arr); - const char* arr_ptr = data + bytes - elem_size; - - if (tag || !upb_IsLittleEndian()) { - while (true) { - if (elem_size == 4) { - uint32_t val; - memcpy(&val, arr_ptr, sizeof(val)); - val = upb_BigEndian32(val); - ptr = encode_bytes(ptr, e, &val, elem_size); - } else { - UPB_ASSERT(elem_size == 8); - uint64_t val; - memcpy(&val, arr_ptr, sizeof(val)); - val = upb_BigEndian64(val); - ptr = encode_bytes(ptr, e, &val, elem_size); - } - - if (tag) { - ptr = encode_varint(ptr, e, tag); - } - if (arr_ptr == data) break; - arr_ptr -= elem_size; - } - return ptr; - } else { - return encode_bytes(ptr, e, data, bytes); - } -} - -static char* encode_message(char* ptr, upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size); - -static char* encode_scalar(char* ptr, upb_encstate* e, const void* field_mem, - const upb_MiniTableField* f) { - // Max size is tag + 10 bytes for max varint or 8 for largest fixed size -#define CASE(ctype, type, wtype, encodeval) \ - { \ - const size_t bytes = UPB_PB_VARINT32_MAX_LEN + UPB_PB_VARINT_MAX_LEN; \ - ptr = encode_reserve(ptr, e, bytes); \ - ptr += bytes; \ - const ctype val = *(const ctype*)field_mem; \ - ptr = encode_##type##_unchecked(ptr, e, encodeval); \ - return encode_tag_unchecked(ptr, e, upb_MiniTableField_Number(f), wtype); \ - } - - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - CASE(double, double, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Float: - CASE(float, float, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - CASE(uint64_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_UInt32: - CASE(uint32_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Bool: - CASE(bool, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_SInt32: - CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); - case kUpb_FieldType_SInt64: - CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - upb_StringView view = *(upb_StringView*)field_mem; - const size_t max_size = - UPB_PB_VARINT32_MAX_LEN + UPB_PB_VARINT32_MAX_LEN + view.size; - ptr = encode_reserve(ptr, e, max_size); - ptr += max_size; - ptr = encode_bytes_unchecked(ptr, e, view.data, view.size); - ptr = encode_length_unchecked(ptr, e, view.size); - return encode_tag_unchecked(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_Delimited); - } - case kUpb_FieldType_Group: { - size_t size; - upb_Message* submsg = *(upb_Message**)field_mem; - const upb_MiniTable* subm = upb_MiniTable_GetSubMessageTable(f); - if (submsg == 0) { - return ptr; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - ptr = encode_tag(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_EndGroup); - ptr = encode_message(ptr, e, submsg, subm, &size); - e->depth++; - return encode_tag(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_StartGroup); - } - case kUpb_FieldType_Message: { - size_t size; - upb_Message* submsg = *(upb_Message**)field_mem; - const upb_MiniTable* subm = upb_MiniTable_GetSubMessageTable(f); - if (submsg == 0) { - return ptr; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - ptr = encode_message(ptr, e, submsg, subm, &size); - e->depth++; - size_t max_size = UPB_PB_VARINT32_MAX_LEN + UPB_PB_VARINT32_MAX_LEN; - ptr = encode_reserve(ptr, e, max_size); - ptr += max_size; - ptr = encode_length_unchecked(ptr, e, size); - return encode_tag_unchecked(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_Delimited); - } - default: - UPB_UNREACHABLE(); - } -#undef CASE -} - -static char* encode_array(char* ptr, upb_encstate* e, const upb_Message* msg, - const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); - bool packed = upb_MiniTableField_IsPacked(f); - size_t pre_len = e->limit - ptr; - - if (arr == NULL || upb_Array_Size(arr) == 0) { - return ptr; - } - -#define VARINT_CASE(ctype, encode) \ - { \ - const ctype* start = upb_Array_DataPtr(arr); \ - const ctype* arr_ptr = start + upb_Array_Size(arr); \ - if (packed) { \ - do { \ - arr_ptr--; \ - ptr = encode_varint(ptr, e, encode); \ - } while (arr_ptr != start); \ - } else { \ - uint32_t number = upb_MiniTableField_Number(f); \ - do { \ - arr_ptr--; \ - ptr = encode_varint(ptr, e, encode); \ - ptr = encode_tag(ptr, e, number, kUpb_WireType_Varint); \ - } while (arr_ptr != start); \ - } \ - } \ - break; - -#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) - - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - ptr = encode_fixedarray(ptr, e, arr, sizeof(double), - TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Float: - ptr = encode_fixedarray(ptr, e, arr, sizeof(float), - TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - ptr = encode_fixedarray(ptr, e, arr, sizeof(uint64_t), - TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - ptr = encode_fixedarray(ptr, e, arr, sizeof(uint32_t), - TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - VARINT_CASE(uint64_t, *arr_ptr); - case kUpb_FieldType_UInt32: - VARINT_CASE(uint32_t, *arr_ptr); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - VARINT_CASE(int32_t, (int64_t)*arr_ptr); - case kUpb_FieldType_Bool: - VARINT_CASE(bool, *arr_ptr); - case kUpb_FieldType_SInt32: - VARINT_CASE(int32_t, encode_zz32(*arr_ptr)); - case kUpb_FieldType_SInt64: - VARINT_CASE(int64_t, encode_zz64(*arr_ptr)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - const upb_StringView* start = upb_Array_DataPtr(arr); - const upb_StringView* str_ptr = start + upb_Array_Size(arr); - do { - str_ptr--; - ptr = encode_bytes(ptr, e, str_ptr->data, str_ptr->size); - ptr = encode_length(ptr, e, str_ptr->size); - ptr = encode_tag(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_Delimited); - } while (str_ptr != start); - return ptr; - } - case kUpb_FieldType_Group: { - const upb_Message* const* start = upb_Array_DataPtr(arr); - const upb_Message* const* arr_ptr = start + upb_Array_Size(arr); - const upb_MiniTable* subm = upb_MiniTable_GetSubMessageTable(f); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - arr_ptr--; - ptr = encode_tag(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_EndGroup); - ptr = encode_message(ptr, e, *arr_ptr, subm, &size); - ptr = encode_tag(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_StartGroup); - } while (arr_ptr != start); - e->depth++; - return ptr; - } - case kUpb_FieldType_Message: { - const upb_Message* const* start = upb_Array_DataPtr(arr); - const upb_Message* const* arr_ptr = start + upb_Array_Size(arr); - const upb_MiniTable* subm = upb_MiniTable_GetSubMessageTable(f); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - arr_ptr--; - ptr = encode_message(ptr, e, *arr_ptr, subm, &size); - ptr = encode_length(ptr, e, size); - ptr = encode_tag(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_Delimited); - } while (arr_ptr != start); - e->depth++; - return ptr; - } - } -#undef VARINT_CASE - - if (packed) { - ptr = encode_length(ptr, e, e->limit - ptr - pre_len); - ptr = encode_tag(ptr, e, upb_MiniTableField_Number(f), - kUpb_WireType_Delimited); - } - return ptr; -} - -static char* encode_mapentry(char* ptr, upb_encstate* e, uint32_t number, - const upb_MiniTable* layout, - const upb_MapEntry* ent) { - const upb_MiniTableField* key_field = upb_MiniTable_MapKey(layout); - const upb_MiniTableField* val_field = upb_MiniTable_MapValue(layout); - size_t pre_len = e->limit - ptr; - size_t size; - ptr = encode_scalar(ptr, e, &ent->v, val_field); - ptr = encode_scalar(ptr, e, &ent->k, key_field); - size = (e->limit - ptr) - pre_len; - ptr = encode_length(ptr, e, size); - ptr = encode_tag(ptr, e, number, kUpb_WireType_Delimited); - return ptr; -} - -static char* encode_map(char* ptr, upb_encstate* e, const upb_Message* msg, - const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); - const upb_MiniTable* layout = upb_MiniTable_MapEntrySubMessage(f); - UPB_ASSERT(upb_MiniTable_FieldCount(layout) == 2); - - if (!map || !upb_Map_Size(map)) return ptr; - - if (e->options & kUpb_EncodeOption_Deterministic) { - if (!map->UPB_PRIVATE(is_strtable)) { - // For inttable, first encode the array part, then sort the table entries. - intptr_t iter = UPB_INTTABLE_BEGIN; - while ((size_t)++iter < map->t.inttable.array_size) { - upb_value value = map->t.inttable.array[iter]; - if (upb_inttable_arrhas(&map->t.inttable, iter)) { - upb_MapEntry ent; - memcpy(&ent.k, &iter, sizeof(iter)); - _upb_map_fromvalue(value, &ent.v, map->val_size); - ptr = encode_mapentry(ptr, e, upb_MiniTableField_Number(f), layout, - &ent); - } - } - } - _upb_sortedmap sorted; - _upb_mapsorter_pushmap( - &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), - map, &sorted); - upb_MapEntry ent; - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - ptr = encode_mapentry(ptr, e, upb_MiniTableField_Number(f), layout, &ent); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - upb_value val; - if (map->UPB_PRIVATE(is_strtable)) { - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView strkey; - while (upb_strtable_next2(&map->t.strtable, &strkey, &val, &iter)) { - upb_MapEntry ent; - _upb_map_fromkey(strkey, &ent.k, map->key_size); - _upb_map_fromvalue(val, &ent.v, map->val_size); - ptr = - encode_mapentry(ptr, e, upb_MiniTableField_Number(f), layout, &ent); - } - } else { - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t intkey = 0; - while (upb_inttable_next(&map->t.inttable, &intkey, &val, &iter)) { - upb_MapEntry ent; - memcpy(&ent.k, &intkey, map->key_size); - _upb_map_fromvalue(val, &ent.v, map->val_size); - ptr = - encode_mapentry(ptr, e, upb_MiniTableField_Number(f), layout, &ent); - } - } - } - return ptr; -} - -static bool encode_shouldencode(const upb_Message* msg, - const upb_MiniTableField* f) { - if (f->presence == 0) { - // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { - case kUpb_FieldRep_1Byte: { - char ch; - memcpy(&ch, mem, 1); - return ch != 0; - } - case kUpb_FieldRep_4Byte: { - uint32_t u32; - memcpy(&u32, mem, 4); - return u32 != 0; - } - case kUpb_FieldRep_8Byte: { - uint64_t u64; - memcpy(&u64, mem, 8); - return u64 != 0; - } - case kUpb_FieldRep_StringView: { - const upb_StringView* str = (const upb_StringView*)mem; - return str->size != 0; - } - default: - UPB_UNREACHABLE(); - } - } else if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { - // Proto2 presence: hasbit. - return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); - } else { - // Field is in a oneof. - return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == - upb_MiniTableField_Number(f); - } -} - -static char* encode_field(char* ptr, upb_encstate* e, const upb_Message* msg, - const upb_MiniTableField* field) { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Array: - return encode_array(ptr, e, msg, field); - case kUpb_FieldMode_Map: - return encode_map(ptr, e, msg, field); - case kUpb_FieldMode_Scalar: - return encode_scalar( - ptr, e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), field); - default: - UPB_UNREACHABLE(); - } -} - -static char* encode_msgset_item(char* ptr, upb_encstate* e, - const upb_MiniTableExtension* ext, - const upb_MessageValue ext_val) { - size_t size; - ptr = encode_tag(ptr, e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); - ptr = encode_message(ptr, e, ext_val.msg_val, - upb_MiniTableExtension_GetSubMessage(ext), &size); - ptr = encode_varint(ptr, e, size); - ptr = encode_tag(ptr, e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); - ptr = encode_varint(ptr, e, upb_MiniTableExtension_Number(ext)); - ptr = encode_tag(ptr, e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); - ptr = encode_tag(ptr, e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); - return ptr; -} - -static char* encode_ext(char* ptr, upb_encstate* e, - const upb_MiniTableExtension* ext, - upb_MessageValue ext_val, bool is_message_set) { - if (UPB_UNLIKELY(is_message_set)) { - ptr = encode_msgset_item(ptr, e, ext, ext_val); - } else { - ptr = encode_field(ptr, e, &ext_val.UPB_PRIVATE(ext_msg_val), - &ext->UPB_PRIVATE(field)); - } - return ptr; -} - -static char* encode_exts(char* ptr, upb_encstate* e, const upb_MiniTable* m, - const upb_Message* msg) { - if (m->UPB_PRIVATE(ext) == kUpb_ExtMode_NonExtendable) return ptr; - - upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); - if (!in) return ptr; - - /* Encode all extensions together. Unlike C++, we do not attempt to keep - * these in field number order relative to normal fields or even to each - * other. */ - uintptr_t iter = kUpb_Message_ExtensionBegin; - const upb_MiniTableExtension* ext; - upb_MessageValue ext_val; - if (!UPB_PRIVATE(_upb_Message_NextExtensionReverse)(msg, &ext, &ext_val, - &iter)) { - // Message has no extensions. - return ptr; - } - - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - if (!_upb_mapsorter_pushexts(&e->sorter, in, &sorted)) { - // TODO: b/378744096 - handle alloc failure - } - const upb_Extension* ext; - while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { - ptr = encode_ext(ptr, e, ext->ext, ext->data, - m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - do { - ptr = encode_ext(ptr, e, ext, ext_val, - m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } while (UPB_PRIVATE(_upb_Message_NextExtensionReverse)(msg, &ext, &ext_val, - &iter)); - } - return ptr; -} - -static char* encode_message(char* ptr, upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size) { - size_t pre_len = e->limit - ptr; - - if (e->options & kUpb_EncodeOption_CheckRequired) { - if (m->UPB_PRIVATE(required_count)) { - if (!UPB_PRIVATE(_upb_Message_IsInitializedShallow)(msg, m)) { - encode_err(e, kUpb_EncodeStatus_MissingRequired); - } - } - } - - if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { - size_t unknown_size = 0; - uintptr_t iter = kUpb_Message_UnknownBegin; - upb_StringView unknown; - // Need to write in reverse order, but iteration is in-order; scan to - // reserve capacity up front, then write in-order - while (upb_Message_NextUnknown(msg, &unknown, &iter)) { - unknown_size += unknown.size; - } - if (unknown_size != 0) { - ptr = encode_reserve(ptr, e, unknown_size); - char* tmp_ptr = ptr; - iter = kUpb_Message_UnknownBegin; - while (upb_Message_NextUnknown(msg, &unknown, &iter)) { - memcpy(tmp_ptr, unknown.data, unknown.size); - tmp_ptr += unknown.size; - } - } - } - - ptr = encode_exts(ptr, e, m, msg); - - if (upb_MiniTable_FieldCount(m)) { - const upb_MiniTableField* f = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; - while (f != first) { - f--; - if (encode_shouldencode(msg, f)) { - ptr = encode_field(ptr, e, msg, f); - } - } - } - - *size = (e->limit - ptr) - pre_len; - return ptr; -} - -static upb_EncodeStatus upb_Encoder_Encode(char* ptr, - upb_encstate* const encoder, - const upb_Message* const msg, - const upb_MiniTable* const l, - char** const buf, size_t* const size, - bool prepend_len) { - // Unfortunately we must continue to perform hackery here because there are - // code paths which blindly copy the returned pointer without bothering to - // check for errors until much later (b/235839510). So we still set *buf to - // NULL on error and we still set it to non-NULL on a successful empty result. - if (UPB_SETJMP(*encoder->err) == 0) { - size_t encoded_msg_size; - ptr = encode_message(ptr, encoder, msg, l, &encoded_msg_size); - if (prepend_len) { - ptr = encode_length(ptr, encoder, encoded_msg_size); - } - *size = encoder->limit - ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(ptr); - *buf = ptr; - } - } else { - UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); - *buf = NULL; - *size = 0; - } - - _upb_mapsorter_destroy(&encoder->sorter); - return encoder->status; -} - -static uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) { - return options >> 16; -} - -uint16_t upb_EncodeOptions_GetEffectiveMaxDepth(uint32_t options) { - uint16_t max_depth = upb_EncodeOptions_GetMaxDepth(options); - return max_depth ? max_depth : kUpb_WireFormat_DefaultDepthLimit; -} - -static upb_EncodeStatus _upb_Encode(const upb_Message* msg, - const upb_MiniTable* l, int options, - upb_Arena* arena, char** buf, size_t* size, - bool prepend_len) { - upb_encstate e; - jmp_buf err; - - e.status = kUpb_EncodeStatus_Ok; - e.err = &err; - e.arena = arena; - e.buf = &initial_buf_sentinel; - e.limit = &initial_buf_sentinel; - e.depth = upb_EncodeOptions_GetEffectiveMaxDepth(options); - e.options = options; - _upb_mapsorter_init(&e.sorter); - - return upb_Encoder_Encode(&initial_buf_sentinel, &e, msg, l, buf, size, - prepend_len); -} - -upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size) { - return _upb_Encode(msg, l, options, arena, buf, size, false); -} - -upb_EncodeStatus UPB_PRIVATE(_upb_Encode_Field)(upb_encstate* e, - const upb_Message* msg, - const upb_MiniTableField* field, - char** buf, size_t* size, - int options) { - e->buf = &initial_buf_sentinel; - e->limit = &initial_buf_sentinel; - e->options = options; - e->depth = upb_EncodeOptions_GetEffectiveMaxDepth(options); - - char* ptr = &initial_buf_sentinel; - if (encode_shouldencode(msg, field)) { - ptr = encode_field(ptr, e, msg, field); - } - *size = e->limit - ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(ptr); - *buf = ptr; - } - return e->status; -} - -upb_EncodeStatus UPB_PRIVATE(_upb_Encode_Extension)( - upb_encstate* e, const upb_MiniTableExtension* ext, - upb_MessageValue ext_val, bool is_message_set, char** buf, size_t* size, - int options) { - e->buf = &initial_buf_sentinel; - e->limit = &initial_buf_sentinel; - e->options = options; - e->depth = upb_EncodeOptions_GetEffectiveMaxDepth(options); - - char* ptr = &initial_buf_sentinel; - ptr = encode_ext(ptr, e, ext, ext_val, is_message_set); - *size = e->limit - ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(ptr); - *buf = ptr; - } - return e->status; -} - -upb_EncodeStatus upb_EncodeLengthPrefixed(const upb_Message* msg, - const upb_MiniTable* l, int options, - upb_Arena* arena, char** buf, - size_t* size) { - return _upb_Encode(msg, l, options, arena, buf, size, true); -} - -const char* upb_EncodeStatus_String(upb_EncodeStatus status) { - switch (status) { - case kUpb_EncodeStatus_Ok: - return "Ok"; - case kUpb_EncodeStatus_MissingRequired: - return "Missing required field"; - case kUpb_EncodeStatus_MaxDepthExceeded: - return "Max depth exceeded"; - case kUpb_EncodeStatus_OutOfMemory: - return "Arena alloc failed"; - default: - return "Unknown encode status"; - } -} diff --git a/vendor/upb/wire/encode.h b/vendor/upb/wire/encode.h deleted file mode 100644 index 9f26608..0000000 --- a/vendor/upb/wire/encode.h +++ /dev/null @@ -1,91 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// upb_Encode: parsing from a upb_Message using a upb_MiniTable. - -#ifndef UPB_WIRE_ENCODE_H_ -#define UPB_WIRE_ENCODE_H_ - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - /* If set, the results of serializing will be deterministic across all - * instances of this binary. There are no guarantees across different - * binary builds. - * - * If your proto contains maps, the encoder will need to malloc()/free() - * memory during encode. */ - kUpb_EncodeOption_Deterministic = 1, - - // When set, unknown fields are not encoded. - kUpb_EncodeOption_SkipUnknown = 2, - - // When set, the encode will fail if any required fields are missing. - kUpb_EncodeOption_CheckRequired = 4, -}; - -// LINT.IfChange -typedef enum { - kUpb_EncodeStatus_Ok = 0, - kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed - kUpb_EncodeStatus_MaxDepthExceeded = 2, - - // One or more required fields are missing. Only returned if - // kUpb_EncodeOption_CheckRequired is set. - kUpb_EncodeStatus_MissingRequired = 3, - - // The message is larger than protobuf's 2GB size limit. - kUpb_EncodeStatus_MaxSizeExceeded = 4, -} upb_EncodeStatus; -// LINT.ThenChange(//depot/google3/third_party/upb/rust/sys/wire/wire.rs:encode_status) - -UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) { - return (uint32_t)depth << 16; -} - -uint16_t upb_EncodeOptions_GetEffectiveMaxDepth(uint32_t options); - -// Enforce an upper bound on recursion depth. -UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { - uint32_t max_depth = upb_EncodeOptions_GetEffectiveMaxDepth(encode_options); - if (max_depth > limit) max_depth = limit; - return (int)(upb_EncodeOptions_MaxDepth(max_depth) | - (encode_options & 0xffff)); -} - -UPB_NODISCARD UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, - const upb_MiniTable* l, - int options, upb_Arena* arena, - char** buf, size_t* size); - -// Encodes the message prepended by a varint of the serialized length. -UPB_NODISCARD UPB_API upb_EncodeStatus upb_EncodeLengthPrefixed( - const upb_Message* msg, const upb_MiniTable* l, int options, - upb_Arena* arena, char** buf, size_t* size); -// Utility function for wrapper languages to get an error string from a -// upb_EncodeStatus. -UPB_API const char* upb_EncodeStatus_String(upb_EncodeStatus status); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_WIRE_ENCODE_H_ */ diff --git a/vendor/upb/wire/encode_test.cc b/vendor/upb/wire/encode_test.cc deleted file mode 100644 index 21d247d..0000000 --- a/vendor/upb/wire/encode_test.cc +++ /dev/null @@ -1,209 +0,0 @@ -#include "upb/wire/encode.h" - -#include -#include - -#include -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/internal/map_sorter.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode_test.upb.h" -#include "upb/wire/internal/encoder.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace upb { -namespace { - -static void DoEncodeFieldMaxDepthExceeded(jmp_buf err, upb_encstate& e, - upb_Message* msg, - const upb_MiniTableField* field, - char*& buf, size_t& size) { - if (UPB_SETJMP(err) == 0) { - UPB_PRIVATE(_upb_Encode_Field)(&e, msg, field, &buf, &size, e.options); - FAIL() << "Should have jumped"; - } else { - EXPECT_EQ(e.status, kUpb_EncodeStatus_MaxDepthExceeded); - } -} - -static void DoEncodeExtensionMaxDepthExceeded(jmp_buf err, upb_encstate& e, - const upb_MiniTableExtension* ext, - upb_MessageValue ext_val, - char*& buf, size_t& size) { - if (UPB_SETJMP(err) == 0) { - UPB_PRIVATE(_upb_Encode_Extension)(&e, ext, ext_val, false, &buf, &size, - e.options); - FAIL() << "Should have jumped"; - } else { - EXPECT_EQ(e.status, kUpb_EncodeStatus_MaxDepthExceeded); - } -} - -TEST(EncodeTest, EncodeFieldSuccess) { - // Set up a message with a single int32 field. - upb_Arena* arena = upb_Arena_New(); - upb_wire_test_TestInt32* msg = upb_wire_test_TestInt32_new(arena); - upb_wire_test_TestInt32_set_i32(msg, 42); - - upb_encstate e; - jmp_buf err; - UPB_PRIVATE(_upb_encstate_init)(&e, &err, arena); - - // Encode field. - const upb_MiniTable* mt = &upb_0wire_0test__TestInt32_msg_init; - const upb_MiniTableField* field = upb_MiniTable_FindFieldByNumber(mt, 1); - char* buf; - size_t size; - upb_EncodeStatus status = UPB_PRIVATE(_upb_Encode_Field)( - &e, (upb_Message*)msg, field, &buf, &size, e.options); - EXPECT_EQ(status, kUpb_EncodeStatus_Ok); - EXPECT_GT(size, 0); - - // Verify that the encoded field can be decoded back to the original message - // with the same value. - upb_wire_test_TestInt32* decoded_msg = upb_wire_test_TestInt32_new(arena); - upb_DecodeStatus decode_status = - upb_Decode(buf, size, (upb_Message*)decoded_msg, mt, nullptr, 0, arena); - EXPECT_EQ(decode_status, kUpb_DecodeStatus_Ok); - EXPECT_EQ(upb_wire_test_TestInt32_i32(decoded_msg), 42); - - _upb_mapsorter_destroy(&e.sorter); - upb_Arena_Free(arena); -} - -TEST(EncodeTest, EncodeFieldSuccessEmptyMessage) { - // Set up a message with a single int32 field, but do not set the field value. - upb_Arena* arena = upb_Arena_New(); - upb_wire_test_TestInt32* msg = upb_wire_test_TestInt32_new(arena); - - upb_encstate e; - jmp_buf err; - UPB_PRIVATE(_upb_encstate_init)(&e, &err, arena); - - // Encode empty message field. - const upb_MiniTable* mt = &upb_0wire_0test__TestInt32_msg_init; - const upb_MiniTableField* field = upb_MiniTable_FindFieldByNumber(mt, 1); - char* buf; - size_t size; - upb_EncodeStatus status = UPB_PRIVATE(_upb_Encode_Field)( - &e, (upb_Message*)msg, field, &buf, &size, e.options); - EXPECT_EQ(status, kUpb_EncodeStatus_Ok); - EXPECT_EQ(size, 0); - - _upb_mapsorter_destroy(&e.sorter); - upb_Arena_Free(arena); -} - -TEST(EncodeTest, EncodeFieldMaxDepthExceeded) { - upb_Arena* arena = upb_Arena_New(); - upb_wire_test_TestRecursive* msg = upb_wire_test_TestRecursive_new(arena); - - upb_encstate e; - jmp_buf err; - UPB_PRIVATE(_upb_encstate_init)(&e, &err, arena); - - upb_wire_test_TestRecursive* sub_msg = upb_wire_test_TestRecursive_new(arena); - upb_wire_test_TestRecursive_set_recursive(msg, sub_msg); - - const upb_MiniTable* mt = &upb_0wire_0test__TestRecursive_msg_init; - const upb_MiniTableField* field = upb_MiniTable_FindFieldByNumber(mt, 1); - char* buf; - size_t size; - e.options = upb_EncodeOptions_MaxDepth(1); - DoEncodeFieldMaxDepthExceeded(err, e, (upb_Message*)msg, field, buf, size); - - _upb_mapsorter_destroy(&e.sorter); - upb_Arena_Free(arena); -} - -TEST(EncodeTest, EncodeExtensionSuccess) { - upb_Arena* arena = upb_Arena_New(); - - upb_encstate e; - jmp_buf err; - UPB_PRIVATE(_upb_encstate_init)(&e, &err, arena); - - const upb_MiniTableExtension* ext = upb_wire_test_ext_i32_ext; - upb_MessageValue ext_val; - ext_val.int32_val = 42; - - // Encode extension. - char* buf; - size_t size; - upb_EncodeStatus status = UPB_PRIVATE(_upb_Encode_Extension)( - &e, ext, ext_val, false, &buf, &size, e.options); - EXPECT_EQ(status, kUpb_EncodeStatus_Ok); - EXPECT_GT(size, 0); - - // Verify that the encoded extension can be decoded back to the original - // extension value. - upb_ExtensionRegistry* ext_reg = upb_ExtensionRegistry_New(arena); - const upb_MiniTableExtension* ext_array[1] = {upb_wire_test_ext_i32_ext}; - upb_ExtensionRegistry_AddArray(ext_reg, ext_array, 1); - - upb_wire_test_TestExtensions* decoded_msg = - upb_wire_test_TestExtensions_parse_ex(buf, size, ext_reg, 0, arena); - EXPECT_NE(decoded_msg, nullptr); - EXPECT_TRUE(upb_wire_test_has_ext_i32(decoded_msg)); - EXPECT_EQ(upb_wire_test_ext_i32(decoded_msg), 42); - - _upb_mapsorter_destroy(&e.sorter); - upb_Arena_Free(arena); -} - -TEST(EncodeTest, EncodeExtensionSuccessEmptyMessage) { - upb_Arena* arena = upb_Arena_New(); - - upb_encstate e; - jmp_buf err; - UPB_PRIVATE(_upb_encstate_init)(&e, &err, arena); - - const upb_MiniTableExtension* ext = upb_wire_test_ext_i32_ext; - // Zero int32 won't be serialized. - upb_MessageValue ext_val; - ext_val.int32_val = 0; - - // Encode empty extension. - char* buf; - size_t size; - upb_EncodeStatus status = UPB_PRIVATE(_upb_Encode_Extension)( - &e, ext, ext_val, false, &buf, &size, e.options); - EXPECT_EQ(status, kUpb_EncodeStatus_Ok); - EXPECT_GT(size, 0); - - _upb_mapsorter_destroy(&e.sorter); - upb_Arena_Free(arena); -} - -TEST(EncodeTest, EncodeExtensionMaxDepthExceeded) { - upb_Arena* arena = upb_Arena_New(); - - upb_encstate e; - jmp_buf err; - UPB_PRIVATE(_upb_encstate_init)(&e, &err, arena); - - const upb_MiniTableExtension* ext = upb_wire_test_ext_recursive_ext; - upb_MessageValue ext_val; - ext_val.msg_val = (upb_Message*)upb_wire_test_TestRecursive_new(arena); - - char* buf; - size_t size; - e.options = upb_EncodeOptions_MaxDepth(1); - DoEncodeExtensionMaxDepthExceeded(err, e, ext, ext_val, buf, size); - - _upb_mapsorter_destroy(&e.sorter); - upb_Arena_Free(arena); -} - -} // namespace -} // namespace upb - -#include "upb/port/undef.inc" diff --git a/vendor/upb/wire/encode_test.proto b/vendor/upb/wire/encode_test.proto deleted file mode 100644 index 7e58c59..0000000 --- a/vendor/upb/wire/encode_test.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto2"; - -package upb_wire_test; - -option java_multiple_files = true; -option java_outer_classname = "ConvertTest"; - -message TestInt32 { - optional int32 i32 = 1; -} - -message TestRecursive { - optional TestRecursive recursive = 1; -} - -message TestExtensions { - extensions 100 to max; -} - -extend TestExtensions { - optional int32 ext_i32 = 100; - optional TestRecursive ext_recursive = 101; -} diff --git a/vendor/upb/wire/eps_copy_input_stream.c b/vendor/upb/wire/eps_copy_input_stream.c deleted file mode 100644 index 49c9735..0000000 --- a/vendor/upb/wire/eps_copy_input_stream.c +++ /dev/null @@ -1,48 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/eps_copy_input_stream.h" - -#include -#include - -#include "upb/base/error_handler.h" -#include "upb/wire/internal/eps_copy_input_stream.h" - -// Must be last. -#include "upb/port/def.inc" - -const char* UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)( - upb_EpsCopyInputStream* e) { - e->error = true; - if (e->err) upb_ErrorHandler_ThrowError(e->err, kUpb_ErrorCode_Malformed); - return NULL; -} - -const char* UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallback)( - struct upb_EpsCopyInputStream* e, const char* ptr, int overrun) { - if (overrun < e->limit) { - // Need to copy remaining data into patch buffer. - UPB_ASSERT(overrun < kUpb_EpsCopyInputStream_SlopBytes); - const char* old_end = ptr; - const char* new_start = &e->patch[overrun]; - memset(&e->patch[kUpb_EpsCopyInputStream_SlopBytes], 0, - kUpb_EpsCopyInputStream_SlopBytes); - memcpy(e->patch, e->end, kUpb_EpsCopyInputStream_SlopBytes); - ptr = new_start; - e->end = &e->patch[kUpb_EpsCopyInputStream_SlopBytes]; - e->limit -= kUpb_EpsCopyInputStream_SlopBytes; - e->limit_ptr = e->end + e->limit; - UPB_ASSERT(ptr < e->limit_ptr); - e->input_delta = (uintptr_t)old_end - (uintptr_t)new_start; - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsChecked)(e); - return new_start; - } else { - UPB_ASSERT(overrun > e->limit); - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(e); - } -} diff --git a/vendor/upb/wire/eps_copy_input_stream.h b/vendor/upb/wire/eps_copy_input_stream.h deleted file mode 100644 index 96d1cfd..0000000 --- a/vendor/upb/wire/eps_copy_input_stream.h +++ /dev/null @@ -1,175 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_EPS_COPY_INPUT_STREAM_H_ -#define UPB_WIRE_EPS_COPY_INPUT_STREAM_H_ - -#include -#include - -#include "upb/base/error_handler.h" -#include "upb/base/string_view.h" -#include "upb/wire/internal/eps_copy_input_stream.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct upb_EpsCopyInputStream upb_EpsCopyInputStream; - -// Initializes a upb_EpsCopyInputStream using the contents of the buffer -// [*ptr, size]. Updates `*ptr` as necessary to guarantee that at least -// kUpb_EpsCopyInputStream_SlopBytes are available to read. -UPB_INLINE void upb_EpsCopyInputStream_Init(upb_EpsCopyInputStream* e, - const char** ptr, size_t size); - -// Like the previous function, but registers an error handler that will be -// called for any errors encountered. -UPB_INLINE void upb_EpsCopyInputStream_InitWithErrorHandler( - upb_EpsCopyInputStream* e, const char** ptr, size_t size, - upb_ErrorHandler* err); - -// Returns true if the stream has an error handler. -// -// This function is marked const, which indicates to the compiler that the -// return value is solely a function of the pointer value. This is not -// entirely true if the stream is reinitialized with -// upb_EpsCopyInputStream_Init*(), so users must not call this function in -// any context where the stream may be reinitialized between calls to this -// function, and the presence of an error handler changes when reinitialized. -UPB_ATTR_CONST -UPB_INLINE bool upb_EpsCopyInputStream_HasErrorHandler( - const upb_EpsCopyInputStream* e); - -// Returns true if the stream is in the error state. A stream enters the error -// state when the user reads past a limit (caught in IsDone()) or the -// ZeroCopyInputStream returns an error. -UPB_INLINE bool upb_EpsCopyInputStream_IsError(upb_EpsCopyInputStream* e); - -// Returns true if the stream has hit a limit, either the current delimited -// limit or the overall end-of-stream. As a side effect, this function may flip -// the pointer to a new buffer if there are less than -// kUpb_EpsCopyInputStream_SlopBytes of data to be read in the current buffer. -// -// Postcondition: if the function returns false, there are at least -// kUpb_EpsCopyInputStream_SlopBytes of data available to read at *ptr. -// -// If this returns true, the user must call upb_EpsCopyInputStream_IsError() -// to distinguish between EOF and error. -UPB_INLINE bool upb_EpsCopyInputStream_IsDone(upb_EpsCopyInputStream* e, - const char** ptr); - -// Returns true if the given delimited field size is valid (it does not extend -// beyond any previously-pushed limits). `ptr` should point to the beginning -// of the field data, after the delimited size. -// -// Note that this does *not* guarantee that all of the data for this field is in -// the current buffer. -UPB_INLINE bool upb_EpsCopyInputStream_CheckSize( - const upb_EpsCopyInputStream* e, const char* ptr, int size); - -// Marks the start of a capture operation. Only one capture operation may be -// active at a time. The capture operation will be finalized by a call to -// upb_EpsCopyInputStream_EndCapture(). The captured string will be returned in -// sv, and will point to the original input buffer if possible. -UPB_INLINE void upb_EpsCopyInputStream_StartCapture(upb_EpsCopyInputStream* e, - const char* ptr); - -// Ends a capture operation and returns the captured string. This may only be -// called once per capture operation. Returns false if the capture operation -// was invalid (the parsing pointer extends beyond the end of the stream). -UPB_INLINE bool upb_EpsCopyInputStream_EndCapture(upb_EpsCopyInputStream* e, - const char* ptr, - upb_StringView* sv); - -// Reads a string from the stream and advances the pointer accordingly. The -// returned string view will always alias the input buffer. -// -// Returns NULL if size extends beyond the end of the current input buffer. -// Currently, we only support a single input buffer, so this function will only -// fail if `size` overflows the end of the stream. -// -// If/when we support multiple input buffers, there may be cases where this -// function returns failure, even if the requested region is valid, because the -// requested region spans multiple buffers. In this case, the caller must -// attempt to read the string using other string reading functions before -// signaling an error. -UPB_INLINE const char* upb_EpsCopyInputStream_ReadStringAlwaysAlias( - upb_EpsCopyInputStream* e, const char* ptr, size_t size, - upb_StringView* sv); - -// Reads a string from the stream and advances the pointer accordingly. The -// returned string view is ephemeral, only valid until the next call to -// upb_EpsCopyInputStream. It may point to the patch buffer. -// -// Returns NULL if size extends beyond the end of the current buffer (which may -// be the patch buffer). -// -// IMPORTANT NOTE: If `size` extends beyond the end of the stream, the returned -// data may contain garbage bytes from the patch buffer. For efficiency, this -// function does not check that `size` is within the current limit or even the -// end of the stream. -// -// The bytes are guaranteed to be safe to read ephemerally, but they may contain -// garbage data that does not correspond to anything in the input. This error -// will be detected later, when calling upb_EpsCopyInputStream_IsDone() (because -// we will not end at the proper limit), but it may result in nonsense bytes -// ending up in the output. -UPB_INLINE const char* upb_EpsCopyInputStream_ReadStringEphemeral( - upb_EpsCopyInputStream* e, const char* ptr, size_t size, - upb_StringView* sv); - -// Pushes a limit onto the stack of limits for the current stream. The limit -// will extend for `size` bytes beyond the position in `ptr`. Future calls to -// upb_EpsCopyInputStream_IsDone() will return `true` when the stream position -// reaches this limit. -// -// Returns a delta that the caller must store and supply to PopLimit() below. -// -// A return value of <0 indicates that `size` is too large, and exceeds a -// previous limit. If this occurs, the stream is in an error state and must no -// longer be used. -UPB_INLINE ptrdiff_t upb_EpsCopyInputStream_PushLimit(upb_EpsCopyInputStream* e, - const char* ptr, - size_t size); - -// Pops the last limit that was pushed on this stream. This may only be called -// once IsDone() returns true. The user must pass the delta that was returned -// from PushLimit(). -UPB_INLINE void upb_EpsCopyInputStream_PopLimit(upb_EpsCopyInputStream* e, - const char* ptr, - ptrdiff_t saved_delta); - -// Tries to perform a fast-path handling of the given delimited message data. -// If the sub-message beginning at `*ptr` and extending for `len` is short and -// fits within this buffer, calls `func` with `ctx` as a parameter, where the -// pushing and popping of limits is handled automatically and with lower cost -// than the normal PushLimit()/PopLimit() sequence. -UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast( - upb_EpsCopyInputStream* e, const char** ptr, size_t size, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#ifdef __cplusplus -// Temporary overloads for functions whose signature has recently changed. -UPB_DEPRECATE_AND_INLINE() -UPB_INLINE void upb_EpsCopyInputStream_Init(upb_EpsCopyInputStream* e, - const char** ptr, size_t size, - bool enable_aliasing) { - upb_EpsCopyInputStream_Init(e, ptr, size); -} -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_EPS_COPY_INPUT_STREAM_H_ diff --git a/vendor/upb/wire/eps_copy_input_stream_test.cc b/vendor/upb/wire/eps_copy_input_stream_test.cc deleted file mode 100644 index 7d56193..0000000 --- a/vendor/upb/wire/eps_copy_input_stream_test.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/eps_copy_input_stream.h" - -#include -#include - -#include -#include -#include - -#include -#include "upb/base/string_view.h" -#include "upb/mem/arena.hpp" - -namespace { - -const char* DoYield(const char* start, const char* end) { return ""; } - -// Due to the overruning logic of the parse it could be that start >= end, -// we continue fetching data until we can yield actual data. This corresponds to -// the loop in DoneFallback of EpsCopyInputStream, where we keep fetching chunks -// and adjusting overrun until we can return actual data. -[[maybe_unused]] int YieldFunc(const char* start, const char* end) { - if (start < end) { - return DoYield(start, end) - end; - } else { - return start - end; - } -} - -// This is the logic of EpsCopyInputStream, state1 and state2 are labels -// corresponding to the states of EpsCopyInputStream. state1 corresponds to -// next_chunk_ != patch_buffer_ as here we going to doll out the chunk from -// ZeroCopyInputStream directly. state2 corresponds to next_chunk_ == -// patch_buffer_ as we are going to return data from patch_buffer_. -template -bool PushParse(ChunkStreamer chunk_stream) { - char buffer[32] = {0}; - int overrun = 16; - const char* ptr; - size_t size; - while (chunk_stream(&ptr, &size)) { - // buffer[0..16] holds leftover data from previous chunk. - // Of course only buffer[overrun..16] is what we care about. - const char* end; - if (size > 16) { - memcpy(buffer + 16, ptr, 16); - overrun = YieldFunc(buffer + overrun, buffer + 16); - [[maybe_unused]] state1: // ptr and size need to be saved across Yield - // point (next_chunk_ and size_ in - // EpsCopyInputStream). - end = ptr + size - 16; - overrun = YieldFunc(ptr + overrun, end); - } else { - memcpy(buffer + 16, ptr, size); - end = buffer + size; - overrun = YieldFunc(buffer + overrun, end); - } - [[maybe_unused]] state2: // end needs to be saved across Yield point - // (buffer_end_ in EpsCopyInputStream). - memmove(buffer, end, 16); - } - overrun = YieldFunc(buffer + overrun, buffer + 16); - return overrun = 0; -} - -TEST(EpsCopyInputStreamTest, ZeroSize) { - upb_EpsCopyInputStream stream; - const char* ptr = nullptr; - upb_EpsCopyInputStream_Init(&stream, &ptr, 0); - EXPECT_TRUE(upb_EpsCopyInputStream_IsDone(&stream, &ptr)); -} - -} // namespace diff --git a/vendor/upb/wire/internal/constants.h b/vendor/upb/wire/internal/constants.h deleted file mode 100644 index 8c6ef9f..0000000 --- a/vendor/upb/wire/internal/constants.h +++ /dev/null @@ -1,27 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ -#define UPB_WIRE_INTERNAL_CONSTANTS_H_ - -#define kUpb_WireFormat_DefaultDepthLimit 100 - -// MessageSet wire format is: -// message MessageSet { -// repeated group Item = 1 { -// required int32 type_id = 2; -// required bytes message = 3; -// } -// } - -enum { - kUpb_MsgSet_Item = 1, - kUpb_MsgSet_TypeId = 2, - kUpb_MsgSet_Message = 3, -}; - -#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */ diff --git a/vendor/upb/wire/internal/decoder.c b/vendor/upb/wire/internal/decoder.c deleted file mode 100644 index 0f132a0..0000000 --- a/vendor/upb/wire/internal/decoder.c +++ /dev/null @@ -1,30 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/internal/decoder.h" - -#include "upb/message/internal/accessors.h" -#include "upb/message/message.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/eps_copy_input_stream.h" - -// Must be last. -#include "upb/port/def.inc" - -UPB_NOINLINE -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* m) { - UPB_ASSERT(m->UPB_PRIVATE(required_count)); - if (UPB_UNLIKELY(d->options & kUpb_DecodeOption_CheckRequired)) { - d->missing_required = - d->missing_required || - !UPB_PRIVATE(_upb_Message_IsInitializedShallow)(msg, m); - } - return ptr; -} diff --git a/vendor/upb/wire/internal/decoder.h b/vendor/upb/wire/internal/decoder.h deleted file mode 100644 index 3f68401..0000000 --- a/vendor/upb/wire/internal/decoder.h +++ /dev/null @@ -1,223 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -/* - * Internal implementation details of the decoder that are shared between - * decode.c and decode_fast.c. - */ - -#ifndef UPB_WIRE_INTERNAL_DECODER_H_ -#define UPB_WIRE_INTERNAL_DECODER_H_ - -#include -#include -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/base/error_handler.h" -#include "upb/base/string_view.h" -#include "upb/mem/arena.h" -#include "upb/mem/internal/arena.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension_registry.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "utf8_range.h" - -// Must be last. -#include "upb/port/def.inc" - -#define DECODE_NOGROUP (uint32_t)-1 - -typedef struct upb_Decoder { - upb_EpsCopyInputStream input; - const upb_ExtensionRegistry* extreg; - upb_Message* original_msg; // Pointer to preserve data to - int depth; // Tracks recursion depth to bound stack usage. - uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. - uint16_t options; - bool missing_required; - bool message_is_done; - union { - upb_Arena arena; - void* foo[UPB_ARENA_SIZE_HACK / sizeof(void*)]; - }; - upb_ErrorHandler* err; - -#ifndef NDEBUG - char* trace_buf; - char* trace_ptr; - char* trace_end; -#endif -} upb_Decoder; - -UPB_INLINE const char* upb_Decoder_Init(upb_Decoder* d, const char* buf, - size_t size, - const upb_ExtensionRegistry* extreg, - int options, upb_Arena* arena, - upb_ErrorHandler* err, char* trace_buf, - size_t trace_size) { - d->err = err; - upb_EpsCopyInputStream_InitWithErrorHandler(&d->input, &buf, size, d->err); - - UPB_STATIC_ASSERT((int)kUpb_DecodeStatus_Ok == (int)kUpb_ErrorCode_Ok, - "mismatched error codes"); - UPB_STATIC_ASSERT( - (int)kUpb_DecodeStatus_OutOfMemory == (int)kUpb_ErrorCode_OutOfMemory, - "mismatched error codes"); - UPB_STATIC_ASSERT( - (int)kUpb_DecodeStatus_Malformed == (int)kUpb_ErrorCode_Malformed, - "mismatched error codes"); - - if (options & kUpb_DecodeOption_AlwaysValidateUtf8) { - // Fasttable decoder does not support this option. - options |= kUpb_DecodeOption_DisableFastTable; - } - - d->extreg = extreg; - d->depth = upb_DecodeOptions_GetEffectiveMaxDepth(options); - d->end_group = DECODE_NOGROUP; - d->options = (uint16_t)options; - d->missing_required = false; - d->message_is_done = false; -#ifndef NDEBUG - d->trace_buf = trace_buf; - d->trace_ptr = trace_buf; - d->trace_end = UPB_PTRADD(trace_buf, trace_size); -#endif - if (trace_buf) *trace_buf = 0; // Null-terminate. - - // Violating the encapsulation of the arena for performance reasons. - // This is a temporary arena that we swap into and swap out of when we are - // done. The temporary arena only needs to be able to handle allocation, - // not fuse or free, so it does not need many of the members to be initialized - // (particularly parent_or_count). - UPB_PRIVATE(_upb_Arena_SwapIn)(&d->arena, arena); - return buf; -} - -UPB_INLINE upb_DecodeStatus upb_Decoder_Destroy(upb_Decoder* d, - upb_Arena* arena) { - UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &d->arena); - return (upb_DecodeStatus)d->err->code; -} - -#ifndef NDEBUG -UPB_INLINE bool _upb_Decoder_TraceBufferHasBytesAvailable(upb_Decoder* d, - int n) { - return d->trace_ptr && d->trace_end && d->trace_end - d->trace_ptr > n; -} -#endif - -UPB_INLINE char* _upb_Decoder_TraceNext(upb_Decoder* d) { -#ifndef NDEBUG - return _upb_Decoder_TraceBufferHasBytesAvailable(d, 2) ? d->trace_ptr + 1 - : NULL; -#else - return NULL; -#endif -} - -UPB_INLINE char* _upb_Decoder_TracePtr(upb_Decoder* d) { -#ifndef NDEBUG - return d->trace_ptr; -#else - return NULL; -#endif -} - -// Trace events are used to trace the progress of the decoder. -// Events: -// 'D' Fast dispatch -// 'F' Field successfully parsed fast. -// '<' Fallback to MiniTable parser. -// 'M' Field successfully parsed with MiniTable. -// 'X' Truncated -- trace buffer is full, further events were discarded. -// -// Lower-case letters indicate events that are more subtle and therefore -// difficult to assert on, but may be useful information for debugging: -// 'r' Refresh buffer. -UPB_INLINE void _upb_Decoder_Trace(upb_Decoder* d, char event) { -#ifndef NDEBUG -#ifdef UPB_TRACE_FASTDECODER - fprintf(stderr, "Fasttable trace event: %c\n", event); -#endif - if (d->trace_ptr == NULL) return; - if (!_upb_Decoder_TraceBufferHasBytesAvailable(d, 1)) { - d->trace_ptr[-1] = 'X'; // Truncated. - return; - } - d->trace_ptr[0] = event; - d->trace_ptr[1] = '\0'; - d->trace_ptr++; -#endif -}; - -UPB_INLINE -bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { - return utf8_range_IsValid(ptr, len); -} - -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* m); - -/* x86-64 pointers always have the high 16 bits matching. So we can shift - * left 8 and right 8 without loss of information. */ -UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) { - return ((intptr_t)tablep << 8) | tablep->UPB_PRIVATE(table_mask); -} - -UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { - return (const upb_MiniTable*)(table >> 8); -} - -const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout); - -UPB_INLINE bool _upb_Decoder_FieldRequiresUtf8Validation( - const upb_Decoder* d, const upb_MiniTableField* field) { - if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_String) return true; - - if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bytes && - (field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) && - (d->options & kUpb_DecodeOption_AlwaysValidateUtf8)) { - return true; - } - - return false; -} - -UPB_INLINE bool _upb_Decoder_ReadString(upb_Decoder* d, const char** ptr, - size_t size, upb_StringView* sv, - bool validate_utf8) { - upb_StringView tmp; - *ptr = - upb_EpsCopyInputStream_ReadStringAlwaysAlias(&d->input, *ptr, size, &tmp); - if (*ptr == NULL) return false; - if (validate_utf8 && !utf8_range_IsValid(tmp.data, tmp.size)) { - upb_ErrorHandler_ThrowError(d->err, kUpb_DecodeStatus_BadUtf8); - return false; - } - if ((d->options & kUpb_DecodeOption_AliasString) == 0) { - char* data = (char*)upb_Arena_Malloc(&d->arena, tmp.size); - if (!data) return false; - memcpy(data, tmp.data, tmp.size); - tmp.data = data; - } - *sv = tmp; - return true; -} - -#include "upb/port/undef.inc" - -#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ diff --git a/vendor/upb/wire/internal/encoder.h b/vendor/upb/wire/internal/encoder.h deleted file mode 100644 index 1329340..0000000 --- a/vendor/upb/wire/internal/encoder.h +++ /dev/null @@ -1,78 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_ENCODE_H_ -#define UPB_WIRE_INTERNAL_ENCODE_H_ - -#include -#include - -#include "upb/mem/arena.h" -#include "upb/message/array.h" -#include "upb/message/internal/map_sorter.h" -#include "upb/message/message.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/wire/encode.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - upb_EncodeStatus status; - upb_Arena* arena; - // These should only be used for arithmetic and reallocation to allow full - // aliasing analysis on the ptr argument. - const char UPB_NODEREF *buf, *limit; - int options; - int depth; - _upb_mapsorter sorter; - jmp_buf* err; -} upb_encstate; - -UPB_INLINE void UPB_PRIVATE(_upb_encstate_init)(upb_encstate* e, jmp_buf* err, - upb_Arena* arena) { - e->status = kUpb_EncodeStatus_Ok; - e->arena = arena; - e->buf = NULL; - e->limit = NULL; - e->options = 0; - e->depth = 0; - e->err = err; - _upb_mapsorter_init(&e->sorter); -} - -// Internal version of upb_Encode that encodes a single field. -// -// The caller must clean up the `upb_encstate` by calling -// `_upb_mapsorter_destroy(&e->sorter)` when done. -upb_EncodeStatus UPB_PRIVATE(_upb_Encode_Field)(upb_encstate* e, - const upb_Message* msg, - const upb_MiniTableField* field, - char** buf, size_t* size, - int options); - -// Internal version of upb_Encode that encodes a single extension. -// -// The caller must clean up the `upb_encstate` by calling -// `_upb_mapsorter_destroy(&e->sorter)` when done. -upb_EncodeStatus UPB_PRIVATE(_upb_Encode_Extension)( - upb_encstate* e, const upb_MiniTableExtension* ext, - upb_MessageValue ext_val, bool is_message_set, char** buf, size_t* size, - int options); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif /* UPB_WIRE_INTERNAL_ENCODE_H_ */ diff --git a/vendor/upb/wire/internal/eps_copy_input_stream.h b/vendor/upb/wire/internal/eps_copy_input_stream.h deleted file mode 100644 index f8bc240..0000000 --- a/vendor/upb/wire/internal/eps_copy_input_stream.h +++ /dev/null @@ -1,339 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_EPS_COPY_INPUT_STREAM_H_ -#define UPB_WIRE_INTERNAL_EPS_COPY_INPUT_STREAM_H_ - -#include -#include -#include - -#include "upb/base/error_handler.h" -#include "upb/base/string_view.h" - -// Must be last. -#include "upb/port/def.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -// The maximum number of bytes a single protobuf field can take up in the -// wire format. We only want to do one bounds check per field, so the input -// stream guarantees that after upb_EpsCopyInputStream_IsDone() is called, -// the decoder can read this many bytes without performing another bounds -// check. The stream will copy into a patch buffer as necessary to guarantee -// this invariant. Since tags can only be up to 5 bytes, and a max-length scalar -// field can be 10 bytes, only 15 is required; but sizing up to 16 permits more -// efficient fixed size copies. -#define kUpb_EpsCopyInputStream_SlopBytes 16 - -struct upb_EpsCopyInputStream { - const char* end; // Can read up to SlopBytes bytes beyond this. - const char* limit_ptr; // For bounds checks, = end + UPB_MIN(limit, 0) - uintptr_t input_delta; // Diff between the original input pointer and patch - const char* buffer_start; // Pointer to the original input buffer - const char* capture_start; // If non-NULL, the start of the captured region. - ptrdiff_t limit; // Submessage limit relative to end - upb_ErrorHandler* err; // Error handler to use when things go wrong. - bool error; // To distinguish between EOF and error. -#ifndef NDEBUG - int guaranteed_bytes; -#endif - // Allocate double the size of what's required; this permits a fixed-size copy - // from the input buffer, regardless of how many bytes actually remain in the - // input buffer. - char patch[kUpb_EpsCopyInputStream_SlopBytes * 2]; -}; - -UPB_INLINE void UPB_PRIVATE(upb_EpsCopyInputStream_BoundsChecked)( - struct upb_EpsCopyInputStream* e); - -UPB_INLINE bool upb_EpsCopyInputStream_IsError( - struct upb_EpsCopyInputStream* e) { - return e->error; -} - -UPB_INLINE void upb_EpsCopyInputStream_InitWithErrorHandler( - struct upb_EpsCopyInputStream* e, const char** ptr, size_t size, - upb_ErrorHandler* err) { - e->buffer_start = *ptr; - e->capture_start = NULL; - e->err = err; - if (size <= kUpb_EpsCopyInputStream_SlopBytes) { - memset(&e->patch, 0, 32); - if (size) memcpy(&e->patch, *ptr, size); - e->input_delta = (uintptr_t)*ptr - (uintptr_t)e->patch; - *ptr = e->patch; - e->end = *ptr + size; - e->limit = 0; - } else { - e->end = *ptr + size - kUpb_EpsCopyInputStream_SlopBytes; - e->limit = kUpb_EpsCopyInputStream_SlopBytes; - e->input_delta = 0; - } - e->limit_ptr = e->end; - e->error = false; - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsChecked)(e); -} - -UPB_INLINE void upb_EpsCopyInputStream_Init(struct upb_EpsCopyInputStream* e, - const char** ptr, size_t size) { - upb_EpsCopyInputStream_InitWithErrorHandler(e, ptr, size, NULL); -} - -UPB_ATTR_CONST -UPB_INLINE bool upb_EpsCopyInputStream_HasErrorHandler( - const struct upb_EpsCopyInputStream* e) { - return e && e->err != NULL; -} - -// Call this function to signal an error. If an error handler is set, it will be -// called and the function will never return. Otherwise, returns NULL to -// indicate an error. -const char* UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)( - struct upb_EpsCopyInputStream* e); - -UPB_INLINE const char* UPB_PRIVATE(upb_EpsCopyInputStream_AssumeResult)( - struct upb_EpsCopyInputStream* e, const char* ptr) { - UPB_MAYBE_ASSUME(upb_EpsCopyInputStream_HasErrorHandler(e), ptr != NULL); - return ptr; -} - -//////////////////////////////////////////////////////////////////////////////// - -// Debug checks that attempt to ensure that no code paths will overrun the slop -// bytes even in the worst case. Since we are frequently parsing varints, it's -// possible that the user is trying to parse too many varints before calling -// upb_EpsCopyInputStream_IsDone(), but this error case is not detected because -// the varints are short. These checks ensure that will not overrun the slop -// bytes, even if each varint is its maximum possible length. - -UPB_INLINE void UPB_PRIVATE(upb_EpsCopyInputStream_BoundsChecked)( - struct upb_EpsCopyInputStream* e) { -#ifndef NDEBUG - e->guaranteed_bytes = kUpb_EpsCopyInputStream_SlopBytes; -#endif -} - -UPB_INLINE void UPB_PRIVATE(upb_EpsCopyInputStream_BoundsHit)( - struct upb_EpsCopyInputStream* e) { -#ifndef NDEBUG - e->guaranteed_bytes = 0; -#endif -} - -// Signals the maximum number that the operation about to be performed may -// consume. -UPB_INLINE void UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)( - struct upb_EpsCopyInputStream* e, int n) { -#ifndef NDEBUG - if (e) { - UPB_ASSERT(e->guaranteed_bytes >= n); - e->guaranteed_bytes -= n; - } -#endif -} - -//////////////////////////////////////////////////////////////////////////////// - -typedef enum { - // The current stream position is at a limit. - kUpb_IsDoneStatus_Done, - - // The current stream position is not at a limit. - kUpb_IsDoneStatus_NotDone, - - // The current stream position is not at a limit, and the stream needs to - // be flipped to a new buffer before more data can be read. - kUpb_IsDoneStatus_NeedFallback, -} upb_IsDoneStatus; - -// Returns the status of the current stream position. This is a low-level -// function, it is simpler to call upb_EpsCopyInputStream_IsDone() if possible. -UPB_INLINE upb_IsDoneStatus UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)( - struct upb_EpsCopyInputStream* e, const char* ptr, int* overrun) { - *overrun = ptr - e->end; - if (UPB_LIKELY(ptr < e->limit_ptr)) { - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsChecked)(e); - return kUpb_IsDoneStatus_NotDone; - } else if (UPB_LIKELY(*overrun == e->limit)) { - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsHit)(e); - return kUpb_IsDoneStatus_Done; - } else { - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsHit)(e); - return kUpb_IsDoneStatus_NeedFallback; - } -} - -const char* UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallback)( - struct upb_EpsCopyInputStream* e, const char* ptr, int overrun); - -UPB_INLINE bool upb_EpsCopyInputStream_IsDone(struct upb_EpsCopyInputStream* e, - const char** ptr) { - int overrun; - switch (UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)(e, *ptr, &overrun)) { - case kUpb_IsDoneStatus_Done: - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsHit)(e); - return true; - case kUpb_IsDoneStatus_NotDone: - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsChecked)(e); - return false; - case kUpb_IsDoneStatus_NeedFallback: - *ptr = - UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallback)(e, *ptr, overrun); - if (*ptr) { - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsChecked)(e); - } else { - UPB_PRIVATE(upb_EpsCopyInputStream_BoundsHit)(e); - } - return *ptr == NULL; - } - UPB_UNREACHABLE(); -} - -UPB_INLINE bool upb_EpsCopyInputStream_CheckSize( - const struct upb_EpsCopyInputStream* e, const char* ptr, int size) { - UPB_ASSERT(size >= 0); - return size <= e->limit - (ptr - e->end); -} - -// Returns a pointer into an input buffer that corresponds to the parsing -// pointer `ptr`. The returned pointer may be the same as `ptr`, but also may -// be different if we are currently parsing out of the patch buffer. -UPB_INLINE const char* UPB_PRIVATE(upb_EpsCopyInputStream_GetInputPtr)( - struct upb_EpsCopyInputStream* e, const char* ptr) { - // This somewhat silly looking add-and-subtract behavior provides provenance - // from the original input buffer's pointer. After optimization it produces - // the same assembly as just casting `(uintptr_t)ptr+input_delta` - // https://godbolt.org/z/zosG88oPn - size_t position = - (uintptr_t)ptr + e->input_delta - (uintptr_t)e->buffer_start; - return e->buffer_start + position; -} - -UPB_INLINE void upb_EpsCopyInputStream_StartCapture( - struct upb_EpsCopyInputStream* e, const char* ptr) { - UPB_ASSERT(e->capture_start == NULL); - e->capture_start = UPB_PRIVATE(upb_EpsCopyInputStream_GetInputPtr)(e, ptr); -} - -UPB_INLINE bool upb_EpsCopyInputStream_EndCapture( - struct upb_EpsCopyInputStream* e, const char* ptr, upb_StringView* sv) { - UPB_ASSERT(e->capture_start != NULL); - if (ptr - e->end > e->limit) { - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(e); - } - const char* end = UPB_PRIVATE(upb_EpsCopyInputStream_GetInputPtr)(e, ptr); - sv->data = e->capture_start; - sv->size = end - sv->data; - e->capture_start = NULL; - return true; -} - -UPB_INLINE const char* upb_EpsCopyInputStream_ReadStringAlwaysAlias( - struct upb_EpsCopyInputStream* e, const char* ptr, size_t size, - upb_StringView* sv) { - UPB_ASSERT(size <= PTRDIFF_MAX); - // The `size` must be within the input buffer. If `ptr` is in the input - // buffer, then using the slop bytes is fine (because they are real bytes from - // the tail of the input buffer). If `ptr` is in the patch buffer, then slop - // bytes represent bytes that do not actually exist in the original input - // buffer, so we must fail if the size extends into the slop bytes. - const char* limit = - e->end + (e->input_delta == 0) * kUpb_EpsCopyInputStream_SlopBytes; - if ((ptrdiff_t)size > limit - ptr) { - // For the moment, we consider this an error. In a multi-buffer world, - // it could be that the requested string extends into the next buffer, which - // is not an error and should be recoverable. - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(e); - } - const char* input = UPB_PRIVATE(upb_EpsCopyInputStream_GetInputPtr)(e, ptr); - *sv = upb_StringView_FromDataAndSize(input, size); - return ptr + size; -} - -UPB_INLINE const char* upb_EpsCopyInputStream_ReadStringEphemeral( - struct upb_EpsCopyInputStream* e, const char* ptr, size_t size, - upb_StringView* sv) { - UPB_ASSERT(size <= PTRDIFF_MAX); - // Size must be within the current buffer (including slop bytes). - const char* limit = e->end + kUpb_EpsCopyInputStream_SlopBytes; - if ((ptrdiff_t)size > limit - ptr) { - // For the moment, we consider this an error. In a multi-buffer world, - // it could be that the requested string extends into the next buffer, which - // is not an error and should be recoverable. - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(e); - } - *sv = upb_StringView_FromDataAndSize(ptr, size); - return ptr + size; -} - -UPB_INLINE void UPB_PRIVATE(upb_EpsCopyInputStream_CheckLimit)( - struct upb_EpsCopyInputStream* e) { - UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit)); -} - -UPB_INLINE ptrdiff_t upb_EpsCopyInputStream_PushLimit( - struct upb_EpsCopyInputStream* e, const char* ptr, size_t size) { - UPB_ASSERT(size <= PTRDIFF_MAX); - ptrdiff_t limit = (ptrdiff_t)size + (ptr - e->end); - ptrdiff_t delta = e->limit - limit; - UPB_PRIVATE(upb_EpsCopyInputStream_CheckLimit)(e); - e->limit = limit; - e->limit_ptr = e->end + UPB_MIN(0, limit); - UPB_PRIVATE(upb_EpsCopyInputStream_CheckLimit)(e); - if (UPB_UNLIKELY(delta < 0)) { - UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(e); - } - return delta; -} - -// Pops the last limit that was pushed on this stream. This may only be called -// once IsDone() returns true. The user must pass the delta that was returned -// from PushLimit(). -UPB_INLINE void upb_EpsCopyInputStream_PopLimit( - struct upb_EpsCopyInputStream* e, const char* ptr, ptrdiff_t saved_delta) { - UPB_ASSERT(ptr - e->end == e->limit); - UPB_PRIVATE(upb_EpsCopyInputStream_CheckLimit)(e); - e->limit += saved_delta; - e->limit_ptr = e->end + UPB_MIN(0, e->limit); - UPB_PRIVATE(upb_EpsCopyInputStream_CheckLimit)(e); -} - -typedef const char* upb_EpsCopyInputStream_ParseDelimitedFunc( - struct upb_EpsCopyInputStream* e, const char* ptr, int size, void* ctx); - -UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast( - struct upb_EpsCopyInputStream* e, const char** ptr, size_t size, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { - UPB_ASSERT(size <= PTRDIFF_MAX); - if ((ptrdiff_t)size > e->limit_ptr - *ptr) { - return false; - } - - // Fast case: Sub-message is <128 bytes and fits in the current buffer. - // This means we can preserve limit/limit_ptr verbatim. - const char* saved_limit_ptr = e->limit_ptr; - int saved_limit = e->limit; - e->limit_ptr = *ptr + size; - e->limit = e->limit_ptr - e->end; - UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit)); - *ptr = func(e, *ptr, size, ctx); - e->limit_ptr = saved_limit_ptr; - e->limit = saved_limit; - UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit)); - return true; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_INTERNAL_EPS_COPY_INPUT_STREAM_H_ diff --git a/vendor/upb/wire/internal/reader.h b/vendor/upb/wire/internal/reader.h deleted file mode 100644 index 5770e04..0000000 --- a/vendor/upb/wire/internal/reader.h +++ /dev/null @@ -1,97 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_INTERNAL_READER_H_ -#define UPB_WIRE_INTERNAL_READER_H_ - -#include -#include - -#include "upb/wire/eps_copy_input_stream.h" - -// Must be last. -#include "upb/port/def.inc" - -#define kUpb_WireReader_WireTypeBits 3 -#define kUpb_WireReader_WireTypeMask 7 - -typedef struct { - const char* ptr; - uint64_t val; -} UPB_PRIVATE(_upb_WireReader_LongVarint); - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_PRIVATE(_upb_WireReader_LongVarint) -UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val, - upb_EpsCopyInputStream* stream); -UPB_PRIVATE(_upb_WireReader_LongVarint) -UPB_PRIVATE(_upb_WireReader_ReadLongTag)(const char* ptr, uint64_t val, - upb_EpsCopyInputStream* stream); -UPB_PRIVATE(_upb_WireReader_LongVarint) -UPB_PRIVATE(_upb_WireReader_ReadLongSize)(const char* ptr, uint64_t val, - upb_EpsCopyInputStream* stream); - -UPB_FORCEINLINE const char* upb_WireReader_ReadVarint( - const char* ptr, uint64_t* val, upb_EpsCopyInputStream* stream) { - UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)(stream, 10); - uint8_t byte = *ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } - UPB_PRIVATE(_upb_WireReader_LongVarint) res; - res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte, stream); - *val = res.val; - return UPB_PRIVATE(upb_EpsCopyInputStream_AssumeResult)(stream, res.ptr); -} - -UPB_FORCEINLINE const char* upb_WireReader_ReadTag( - const char* ptr, uint32_t* val, upb_EpsCopyInputStream* stream) { - UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)(stream, 5); - uint8_t byte = *ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } - UPB_PRIVATE(_upb_WireReader_LongVarint) res; - res = UPB_PRIVATE(_upb_WireReader_ReadLongTag)(ptr, byte, stream); - *val = res.val; - return UPB_PRIVATE(upb_EpsCopyInputStream_AssumeResult)(stream, res.ptr); -} - -UPB_FORCEINLINE const char* upb_WireReader_ReadSize( - const char* ptr, int* val, upb_EpsCopyInputStream* stream) { - UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)(stream, 5); - uint8_t byte = *ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } - UPB_PRIVATE(_upb_WireReader_LongVarint) res; - res = UPB_PRIVATE(_upb_WireReader_ReadLongSize)(ptr, byte, stream); - *val = res.val; - return UPB_PRIVATE(upb_EpsCopyInputStream_AssumeResult)(stream, res.ptr); -} - -UPB_API_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { - return tag >> kUpb_WireReader_WireTypeBits; -} - -UPB_API_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { - return tag & kUpb_WireReader_WireTypeMask; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_INTERNAL_READER_H_ diff --git a/vendor/upb/wire/reader.c b/vendor/upb/wire/reader.c deleted file mode 100644 index 85cd386..0000000 --- a/vendor/upb/wire/reader.c +++ /dev/null @@ -1,80 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/reader.h" - -#include -#include - -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/types.h" - -// Must be last. -#include "upb/port/def.inc" - -UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) - UPB_PRIVATE(_upb_WireReader_ReadLongVarint)( - const char* ptr, uint64_t val, upb_EpsCopyInputStream* stream) { - for (int i = 1; i < 10; i++) { - uint64_t byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - return (UPB_PRIVATE(_upb_WireReader_LongVarint)){ptr + i + 1, val}; - } - } - return (UPB_PRIVATE(_upb_WireReader_LongVarint)){ - UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(stream), 0}; -} - -UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) - UPB_PRIVATE(_upb_WireReader_ReadLongTag)(const char* ptr, uint64_t val, - upb_EpsCopyInputStream* stream) { - for (int i = 1; i < 5; i++) { - uint64_t byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - if (val > UINT32_MAX) break; - return (UPB_PRIVATE(_upb_WireReader_LongVarint)){ptr + i + 1, val}; - } - } - return (UPB_PRIVATE(_upb_WireReader_LongVarint)){ - UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(stream), 0}; -} - -UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) - UPB_PRIVATE(_upb_WireReader_ReadLongSize)(const char* ptr, uint64_t val, - upb_EpsCopyInputStream* stream) { - for (int i = 1; i < 5; i++) { - uint64_t byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - if (val > INT32_MAX) break; - return (UPB_PRIVATE(_upb_WireReader_LongVarint)){ptr + i + 1, val}; - } - } - return (UPB_PRIVATE(_upb_WireReader_LongVarint)){ - UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(stream), 0}; -} - -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - if (--depth_limit < 0) { - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(stream); - } - uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; - while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { - uint32_t tag; - ptr = upb_WireReader_ReadTag(ptr, &tag, stream); - if (!ptr) break; - if (tag == end_group_tag) return ptr; - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); - if (!ptr) break; - } - // Encountered limit end before end group tag. - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(stream); -} diff --git a/vendor/upb/wire/reader.h b/vendor/upb/wire/reader.h deleted file mode 100644 index c69e777..0000000 --- a/vendor/upb/wire/reader.h +++ /dev/null @@ -1,177 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_READER_H_ -#define UPB_WIRE_READER_H_ - -#include -#include -#include - -#include "upb/base/internal/endian.h" -#include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/reader.h" -#include "upb/wire/types.h" // IWYU pragma: export - -// Must be last. -#include "upb/port/def.inc" - -// The upb_WireReader interface is suitable for general-purpose parsing of -// protobuf binary wire format. It is designed to be used along with -// upb_EpsCopyInputStream for buffering, and all parsing routines in this file -// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is -// available to read without any bounds checks. - -#ifdef __cplusplus -extern "C" { -#endif - -// Parses a tag into `tag`, and returns a pointer past the end of the tag, or -// NULL if there was an error in the tag data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_FORCEINLINE const char* upb_WireReader_ReadTag( - const char* ptr, uint32_t* tag, upb_EpsCopyInputStream* stream); - -// Given a tag, returns the field number. -UPB_API_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag); - -// Given a tag, returns the wire type. -UPB_API_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag); - -UPB_FORCEINLINE const char* upb_WireReader_ReadVarint( - const char* ptr, uint64_t* val, upb_EpsCopyInputStream* stream); - -// Skips data for a varint, returning a pointer past the end of the varint, or -// NULL if there was an error in the varint data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_SkipVarint( - const char* ptr, upb_EpsCopyInputStream* stream) { - uint64_t val; - return upb_WireReader_ReadVarint(ptr, &val, stream); -} - -// Reads a varint indicating the size of a delimited field into `size`, or -// NULL if there was an error in the varint data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size, - upb_EpsCopyInputStream* stream); - -// Reads a fixed32 field, performing byte swapping if necessary. -// -// REQUIRES: there must be at least 4 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadFixed32( - const char* ptr, void* val, upb_EpsCopyInputStream* stream) { - UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)(stream, 4); - uint32_t uval; - memcpy(&uval, ptr, 4); - uval = upb_BigEndian32(uval); - memcpy(val, &uval, 4); - return ptr + 4; -} - -// Reads a fixed64 field, performing byte swapping if necessary. -// -// REQUIRES: there must be at least 4 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadFixed64( - const char* ptr, void* val, upb_EpsCopyInputStream* stream) { - UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)(stream, 8); - uint64_t uval; - memcpy(&uval, ptr, 8); - uval = upb_BigEndian64(uval); - memcpy(val, &uval, 8); - return ptr + 8; -} - -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream); - -// Skips data for a group, returning a pointer past the end of the group, or -// NULL if there was an error parsing the group. The `tag` argument should be -// the start group tag that begins the group. The `depth_limit` argument -// indicates how many levels of recursion the group is allowed to have before -// reporting a parse error (this limit exists to protect against stack -// overflow). -// -// TODO: evaluate how the depth_limit should be specified. Do users need -// control over this? -UPB_INLINE const char* upb_WireReader_SkipGroup( - const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - const char* ret = - UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); - return UPB_PRIVATE(upb_EpsCopyInputStream_AssumeResult)(stream, ret); -} - -UPB_INLINE const char* _upb_WireReader_SkipValue( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - switch (upb_WireReader_GetWireType(tag)) { - case kUpb_WireType_Varint: - return upb_WireReader_SkipVarint(ptr, stream); - case kUpb_WireType_32Bit: - UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)(stream, 4); - return ptr + 4; - case kUpb_WireType_64Bit: - UPB_PRIVATE(upb_EpsCopyInputStream_ConsumeBytes)(stream, 8); - return ptr + 8; - case kUpb_WireType_Delimited: { - int size; - ptr = upb_WireReader_ReadSize(ptr, &size, stream); - if (!ptr || !upb_EpsCopyInputStream_CheckSize(stream, ptr, size)) { - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(stream); - } - ptr += size; - return ptr; - } - case kUpb_WireType_StartGroup: - return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, - stream); - case kUpb_WireType_EndGroup: - // Should be handled before now. - default: - // Unknown wire type. - return UPB_PRIVATE(upb_EpsCopyInputStream_ReturnError)(stream); - } -} - -// Skips data for a wire value of any type, returning a pointer past the end of -// the data, or NULL if there was an error parsing the group. The `tag` argument -// should be the tag that was just parsed. The `depth_limit` argument indicates -// how many levels of recursion a group is allowed to have before reporting a -// parse error (this limit exists to protect against stack overflow). -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -// -// TODO: evaluate how the depth_limit should be specified. Do users need -// control over this? -UPB_INLINE const char* upb_WireReader_SkipValue( - const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return _upb_WireReader_SkipValue(ptr, tag, 100, stream); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include "upb/port/undef.inc" - -#endif // UPB_WIRE_READER_H_ diff --git a/vendor/upb/wire/test_util/BUILD b/vendor/upb/wire/test_util/BUILD deleted file mode 100644 index 8073180..0000000 --- a/vendor/upb/wire/test_util/BUILD +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2025, Google LLC -# All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//upb/bazel:copts.bzl", "UPB_DEFAULT_CPPOPTS", "UPB_DEFAULT_FEATURES") - -package(default_applicable_licenses = ["//:license"]) - -cc_library( - name = "make_mini_table", - testonly = True, - srcs = ["make_mini_table.cc"], - hdrs = ["make_mini_table.h"], - copts = UPB_DEFAULT_CPPOPTS, - features = UPB_DEFAULT_FEATURES, - visibility = ["//upb:__subpackages__"], - deps = [ - "//upb/base", - "//upb/mem", - "//upb/mini_descriptor", - "//upb/mini_descriptor:internal", - "//upb/mini_table", - "//upb/port", - "//upb/wire:reader", - "//upb/wire/decode_fast:combinations", - "//upb/wire/decode_fast:data", - "@abseil-cpp//absl/log", - "@abseil-cpp//absl/log:absl_check", - ], -) - -cc_library( - name = "field_types", - testonly = True, - hdrs = ["field_types.h"], - visibility = ["//upb:__subpackages__"], - deps = [ - ":wire_message", - "//upb/base", - "//upb/wire/decode_fast:combinations", - "@abseil-cpp//absl/base", - "@abseil-cpp//absl/strings:string_view", - "@googletest//:gtest", - ], -) - -cc_library( - name = "wire_message", - testonly = True, - srcs = ["wire_message.cc"], - hdrs = ["wire_message.h"], - visibility = ["//upb:__subpackages__"], - deps = [ - "//upb/base:internal", - "//upb/wire:reader", - "@abseil-cpp//absl/log:absl_check", - "@abseil-cpp//absl/strings:string_view", - ], -) diff --git a/vendor/upb/wire/test_util/field_types.h b/vendor/upb/wire/test_util/field_types.h deleted file mode 100644 index 32ccd19..0000000 --- a/vendor/upb/wire/test_util/field_types.h +++ /dev/null @@ -1,271 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef GOOGLE_UPB_UPB_WIRE_TEST_WIRE_TYPES_H__ -#define GOOGLE_UPB_UPB_WIRE_TEST_WIRE_TYPES_H__ - -#include -#include - -#include -#include "absl/base/casts.h" -#include "absl/strings/string_view.h" -#include "upb/base/descriptor_constants.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/test_util/wire_message.h" - -namespace upb { -namespace test { -namespace field_types { - -// This set of field types is similar to upb_FieldType, but it also includes -// some extra distinctions like closed vs. open enum and validated vs. -// unvalidated UTF-8. - -struct Fixed32 { - using Value = uint32_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Fixed32; - inline static constexpr absl::string_view kName = "Fixed32"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Fixed32; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Fixed32(static_cast(value)); - } -}; - -struct Fixed64 { - using Value = uint64_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Fixed64; - inline static constexpr absl::string_view kName = "Fixed64"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Fixed64; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Fixed64(static_cast(value)); - } -}; - -struct SFixed32 { - using Value = int32_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_SFixed32; - inline static constexpr absl::string_view kName = "SFixed32"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Fixed32; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Fixed32(static_cast(value)); - } -}; - -struct SFixed64 { - using Value = int64_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_SFixed64; - inline static constexpr absl::string_view kName = "SFixed64"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Fixed64; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Fixed64(static_cast(value)); - } -}; - -struct Float { - using Value = float; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Float; - inline static constexpr absl::string_view kName = "Float"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Fixed32; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Fixed32( - absl::bit_cast(static_cast(value))); - } -}; - -struct Double { - using Value = double; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Double; - inline static constexpr absl::string_view kName = "Double"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Fixed64; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Fixed64( - absl::bit_cast(static_cast(value))); - } -}; - -struct Int32 { - using Value = int32_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Int32; - inline static constexpr absl::string_view kName = "Int32"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Varint32; - - template - static wire_types::WireValue WireValue(T value) { - // Need to sign-extend to 64-bit varint. - return wire_types::Varint(static_cast(static_cast(value))); - } -}; - -struct Int64 { - using Value = int64_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Int64; - inline static constexpr absl::string_view kName = "Int64"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Varint64; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Varint(static_cast(value)); - } -}; - -struct UInt32 { - using Value = uint32_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_UInt32; - inline static constexpr absl::string_view kName = "UInt32"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Varint32; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Varint(static_cast(value)); - } -}; - -struct UInt64 { - using Value = uint64_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_UInt64; - inline static constexpr absl::string_view kName = "UInt64"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Varint64; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Varint(static_cast(value)); - } -}; - -struct SInt32 { - using Value = int32_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_SInt32; - inline static constexpr absl::string_view kName = "SInt32"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_ZigZag32; - - template - static wire_types::WireValue WireValue(T value) { - int32_t v = static_cast(value); - uint32_t uvalue = ((uint32_t)v << 1) ^ (v >> 31); - return wire_types::Varint(uvalue); - } -}; - -struct SInt64 { - using Value = int64_t; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_SInt64; - inline static constexpr absl::string_view kName = "SInt64"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_ZigZag64; - - template - static wire_types::WireValue WireValue(T value) { - int64_t v = static_cast(value); - uint64_t uvalue = ((uint64_t)v << 1) ^ (v >> 63); - return wire_types::Varint(uvalue); - } -}; - -struct Bool { - using Value = bool; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Bool; - inline static constexpr absl::string_view kName = "Bool"; - inline static constexpr upb_DecodeFast_Type kFastType = kUpb_DecodeFast_Bool; - - template - static wire_types::WireValue WireValue(T value) { - return wire_types::Varint(static_cast(value)); - } -}; - -struct String { - using Value = std::string; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_String; - inline static constexpr absl::string_view kName = "String"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_String; - - static wire_types::WireValue WireValue(std::string value) { - return wire_types::Delimited(value); - } -}; - -struct Bytes { - using Value = std::string; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Bytes; - inline static constexpr absl::string_view kName = "Bytes"; - inline static constexpr upb_DecodeFast_Type kFastType = kUpb_DecodeFast_Bytes; - - static wire_types::WireValue WireValue(std::string value) { - return wire_types::Delimited(value); - } -}; - -struct Message { - using Value = std::string; - inline static constexpr upb_FieldType kFieldType = kUpb_FieldType_Message; - inline static constexpr absl::string_view kName = "Message"; - inline static constexpr upb_DecodeFast_Type kFastType = - kUpb_DecodeFast_Message; - - static wire_types::WireValue WireValue(std::string value) { - return wire_types::Delimited(value); - } -}; - -// TODO: Group, ClosedEnum - -} // namespace field_types - -using PackableFieldTypes = - testing::Types; - -using FieldTypes = - testing::Types; - -template -void ForEachTypeImpl(Func&& func, testing::Types) { - (std::forward(func)(Ts{}), ...); -} - -template -void ForEachType(Func&& func) { - ForEachTypeImpl(std::forward(func), FieldTypes{}); -} - -} // namespace test -} // namespace upb - -#endif // GOOGLE_UPB_UPB_WIRE_TEST_WIRE_TYPES_H__ diff --git a/vendor/upb/wire/test_util/make_mini_table.cc b/vendor/upb/wire/test_util/make_mini_table.cc deleted file mode 100644 index 1008be6..0000000 --- a/vendor/upb/wire/test_util/make_mini_table.cc +++ /dev/null @@ -1,109 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/test_util/make_mini_table.h" - -#include -#include - -#include "absl/log/absl_check.h" -#include "absl/log/log.h" -#include "upb/base/status.hpp" -#include "upb/mem/arena.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/mini_descriptor/internal/encode.hpp" -#include "upb/mini_descriptor/internal/modifiers.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode_fast/combinations.h" -#include "upb/wire/decode_fast/data.h" -#include "upb/wire/reader.h" - -// Must be last. -#include "upb/port/def.inc" - -namespace upb { -namespace test { - -int FieldModifiers(upb_DecodeFast_Type type, - upb_DecodeFast_Cardinality cardinality) { - int modifiers = 0; - switch (type) { - case kUpb_DecodeFast_String: - modifiers |= kUpb_FieldModifier_ValidateUtf8; - break; - default: - break; - } - switch (cardinality) { - case kUpb_DecodeFast_Repeated: - modifiers |= kUpb_FieldModifier_IsRepeated; - break; - case kUpb_DecodeFast_Packed: - modifiers |= kUpb_FieldModifier_IsRepeated | kUpb_FieldModifier_IsPacked; - break; - default: - return 0; - } - return modifiers; -} - -std::pair -MiniTable::MakeSingleFieldTable(int field_number, upb_FieldType type, - upb_DecodeFast_Type fast_type, - upb_DecodeFast_Cardinality cardinality, - upb_Arena* arena) { - MtDataEncoder encoder; - encoder.StartMessage(0); - encoder.PutField(type, 1, FieldModifiers(fast_type, cardinality)); - if (cardinality == kUpb_DecodeFast_Oneof) { - encoder.StartOneof(); - encoder.PutOneofField(field_number); - } - const std::string& data = encoder.data(); - upb::Status status; - const upb_MiniTable* table = - upb_MiniTable_Build(data.data(), data.size(), arena, status.ptr()); - ABSL_CHECK(status.ok()) << status.error_message(); - const upb_MiniTableField* field = upb_MiniTable_GetFieldByIndex(table, 0); - ABSL_CHECK(field != nullptr); -#if UPB_FASTTABLE - if (field_number < (1 << 11)) { - ABSL_CHECK_EQ(HasFastTableEntry(table, field), - UPB_DECODEFAST_ISENABLED(fast_type, cardinality, - kUpb_DecodeFast_Tag1Byte)) - << "fast type: " << fast_type << ", cardinality: " << cardinality; - } -#endif - return std::make_pair(table, upb_MiniTable_GetFieldByIndex(table, 0)); -} - -bool MiniTable::HasFastTableEntry(const upb_MiniTable* mt, - const upb_MiniTableField* field) { -#if UPB_FASTTABLE - int n = (int8_t)mt->UPB_PRIVATE(table_mask) + 1; - for (int i = 0; i < n; ++i) { - const _upb_FastTable_Entry* entry = &mt->UPB_PRIVATE(fasttable)[i]; - uint16_t encoded_tag = upb_DecodeFastData_GetExpectedTag(entry->field_data); - uint32_t tag; - char buf[16]; - memset(buf, 0, sizeof(buf)); - memcpy(buf, &encoded_tag, sizeof(encoded_tag)); - const char* end = upb_WireReader_ReadTag(buf, &tag, nullptr); - ABSL_CHECK(end == buf + 1 || end == buf + 2); - if (tag >> 3 == field->UPB_PRIVATE(number)) { - return true; - } - } - return false; -#else - return false; -#endif -} - -} // namespace test -} // namespace upb diff --git a/vendor/upb/wire/test_util/make_mini_table.h b/vendor/upb/wire/test_util/make_mini_table.h deleted file mode 100644 index 6902a25..0000000 --- a/vendor/upb/wire/test_util/make_mini_table.h +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_TEST_UTIL_MAKE_MINI_TABLE_H_ -#define UPB_MINI_TABLE_TEST_UTIL_MAKE_MINI_TABLE_H_ - -#include - -#include "upb/base/descriptor_constants.h" -#include "upb/mem/arena.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/message.h" -#include "upb/wire/decode_fast/combinations.h" - -namespace upb { -namespace test { - -class MiniTable { - public: - template - static std::pair - MakeSingleFieldTable(int field_number, upb_DecodeFast_Cardinality cardinality, - upb_Arena* arena) { - return MakeSingleFieldTable(field_number, Field::kFieldType, - Field::kFastType, cardinality, arena); - } - - static bool HasFastTableEntry(const upb_MiniTable* mt, - const upb_MiniTableField* field); - - private: - static std::pair - MakeSingleFieldTable(int field_number, upb_FieldType type, - upb_DecodeFast_Type fast_type, - upb_DecodeFast_Cardinality cardinality, - upb_Arena* arena); -}; - -} // namespace test -} // namespace upb - -#endif // UPB_MINI_TABLE_TEST_UTIL_MAKE_MINI_TABLE_H_ diff --git a/vendor/upb/wire/test_util/wire_message.cc b/vendor/upb/wire/test_util/wire_message.cc deleted file mode 100644 index 4aef40d..0000000 --- a/vendor/upb/wire/test_util/wire_message.cc +++ /dev/null @@ -1,122 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include "upb/wire/test_util/wire_message.h" - -#include -#include -#include -#include - -#include "absl/log/absl_check.h" -#include "upb/base/internal/endian.h" -#include "upb/wire/reader.h" -#include "upb/wire/types.h" - -namespace upb { -namespace test { - -using wire_types::Delimited; -using wire_types::Fixed32; -using wire_types::Fixed64; -using wire_types::Group; -using wire_types::Varint; -using wire_types::WireField; -using wire_types::WireMessage; -using wire_types::WireValue; - -static void EncodeVarint(uint64_t val, int varint_length, std::string* str) { - uint64_t v = val; - std::string tmp; - for (int i = 0; v > 0 || i < varint_length; i++) { - if (i > 0) tmp.back() |= 0x80; - tmp.push_back(v & 0x7fU); - v >>= 7; - } - - ABSL_CHECK_GE(tmp.size(), static_cast(varint_length)) << val; - uint64_t parsed_val; - ABSL_CHECK_EQ(upb_WireReader_ReadVarint(tmp.data(), &parsed_val, nullptr), - tmp.data() + tmp.size()) - << "val=" << val << ", size=" << tmp.size() - << ", varint_length=" << varint_length; - ABSL_CHECK_EQ(parsed_val, val); - - str->append(tmp); -} - -static void EncodeTag(const WireField& field, upb_WireType wire_type, - int min_tag_length, std::string* str) { - // Tags are 5 bytes max. - EncodeVarint(field.field_number << 3 | wire_type, min_tag_length, str); -} - -static upb_WireType WireType(const WireValue& value) { - if (std::holds_alternative(value)) { - return kUpb_WireType_Varint; - } else if (std::holds_alternative(value)) { - return kUpb_WireType_Delimited; - } else if (std::holds_alternative(value)) { - return kUpb_WireType_64Bit; - } else if (std::holds_alternative(value)) { - return kUpb_WireType_32Bit; - } else if (std::holds_alternative(value)) { - return kUpb_WireType_StartGroup; - } - ABSL_CHECK(false); - return kUpb_WireType_Varint; -} - -std::string ToBinaryPayloadWithLongVarints(const WireValue& value, - int min_tag_length, - int min_val_varint_length) { - std::string ret; - if (const auto* val = std::get_if(&value)) { - EncodeVarint(val->val, min_val_varint_length, &ret); - } else if (const auto* val = std::get_if(&value)) { - EncodeVarint(val->val.size(), min_val_varint_length, &ret); - ret.append(val->val); - } else if (const auto* val = std::get_if(&value)) { - uint64_t swapped = upb_BigEndian64(val->val); - ret.append(reinterpret_cast(&swapped), sizeof(swapped)); - } else if (const auto* val = std::get_if(&value)) { - uint32_t swapped = upb_BigEndian32(val->val); - ret.append(reinterpret_cast(&swapped), sizeof(swapped)); - } else if (const auto* val = std::get_if(&value)) { - ret.append(ToBinaryPayloadWithLongVarints(val->val, min_tag_length, - min_val_varint_length)); - } - return ret; -} - -std::string ToBinaryPayload(const WireValue& value) { - return ToBinaryPayloadWithLongVarints(value, 1, 1); -} - -std::string ToBinaryPayloadWithLongVarints(const WireMessage& msg, - int min_tag_length, - int min_val_varint_length) { - std::string ret; - - for (const auto& field : msg) { - EncodeTag(field, WireType(field.value), min_tag_length, &ret); - ret.append(ToBinaryPayloadWithLongVarints(field.value, min_tag_length, - min_val_varint_length)); - if (std::holds_alternative(field.value)) { - EncodeTag(field, kUpb_WireType_EndGroup, min_tag_length, &ret); - } - } - - return ret; -} - -std::string ToBinaryPayload(const WireMessage& msg) { - return ToBinaryPayloadWithLongVarints(msg, 1, 1); -} - -} // namespace test -} // namespace upb diff --git a/vendor/upb/wire/test_util/wire_message.h b/vendor/upb/wire/test_util/wire_message.h deleted file mode 100644 index 06a6b85..0000000 --- a/vendor/upb/wire/test_util/wire_message.h +++ /dev/null @@ -1,86 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2025 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// A data structure to represent arbitrary wire format messages, and functions -// to convert them to binary wire format. -// -// The data structure is "logical", in that it does not specify varint lengths. -// When converting to binary wire format, the varint lengths can be specified. - -#ifndef GOOGLE_UPB_UPB_TEST_WIRE_FIELD_H__ -#define GOOGLE_UPB_UPB_TEST_WIRE_FIELD_H__ - -#include - -#include -#include -#include -#include - -namespace upb { -namespace test { -namespace wire_types { - -struct WireField; - -using WireMessage = std::vector; - -struct Varint { - explicit Varint(uint64_t _val) : val(_val) {} - uint64_t val; -}; -struct Delimited { - explicit Delimited(std::string _val) : val(_val) {} - std::string val; -}; -struct Fixed64 { - explicit Fixed64(uint64_t _val) : val(_val) {} - uint64_t val; -}; -struct Fixed32 { - explicit Fixed32(uint32_t _val) : val(_val) {} - uint32_t val; -}; -struct Group { - Group(std::initializer_list _val); - WireMessage val; -}; - -using WireValue = std::variant; - -struct WireField { - uint32_t field_number; - WireValue value; -}; - -inline Group::Group(std::initializer_list _val) : val(_val) {} - -} // namespace wire_types - -// Converts a WireMessage to a binary payload, with normal varints of the -// shortest possible length. -std::string ToBinaryPayload(const wire_types::WireMessage& msg); -std::string ToBinaryPayload(const wire_types::WireValue& value); - -// Converts a WireMessage to a binary payload, forcing varints to be at least -// min_tag_length bytes long for tags and min_val_varint_length bytes long for -// values. This is useful for testing long varints. -// -// Note that this function will let you construct a payload that is not valid -// wire format. Tags may only be 5 bytes long, and values may only be 10 bytes -// long, but you can pass values larger than this to test invalid payloads. -std::string ToBinaryPayloadWithLongVarints(const wire_types::WireMessage& msg, - int min_tag_length, - int min_val_varint_length); -std::string ToBinaryPayloadWithLongVarints(const wire_types::WireValue& value, - int min_tag_length, - int min_val_varint_length); - -} // namespace test -} // namespace upb - -#endif // GOOGLE_UPB_UPB_TEST_WIRE_FIELD_H__ diff --git a/vendor/upb/wire/types.h b/vendor/upb/wire/types.h deleted file mode 100644 index 459f0dd..0000000 --- a/vendor/upb/wire/types.h +++ /dev/null @@ -1,21 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_WIRE_TYPES_H_ -#define UPB_WIRE_TYPES_H_ - -// A list of types as they are encoded on the wire. -typedef enum { - kUpb_WireType_Varint = 0, - kUpb_WireType_64Bit = 1, - kUpb_WireType_Delimited = 2, - kUpb_WireType_StartGroup = 3, - kUpb_WireType_EndGroup = 4, - kUpb_WireType_32Bit = 5 -} upb_WireType; - -#endif /* UPB_WIRE_TYPES_H_ */ diff --git a/vendor/upb/wire/writer.h b/vendor/upb/wire/writer.h deleted file mode 100644 index 47bae58..0000000 --- a/vendor/upb/wire/writer.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef GOOGLE_UPB_UPB_WIRE_WRITER_H__ -#define GOOGLE_UPB_UPB_WIRE_WRITER_H__ - -#include - -// Must be last. -#include "upb/port/def.inc" - -UPB_FORCEINLINE uint32_t -UPB_PRIVATE(upb_WireWriter_VarintUnusedSizeFromLeadingZeros64)(uint64_t clz) { - // Calculate how many bytes of the possible 10 bytes we will *not* encode, - // because they are part of a zero prefix. For the number 300, it would use 2 - // bytes encoded, so the number of bytes to skip would be 8. Adding 7 to the - // clz input ensures that we're rounding up. - return (((uint32_t)clz + 7) * 9) >> 6; -} - -#include "upb/port/undef.inc" - -#endif // GOOGLE_UPB_UPB_WIRE_WRITER_H__ diff --git a/vendor/utf8_range/BUILD.bazel b/vendor/utf8_range/BUILD.bazel deleted file mode 100644 index 719e91d..0000000 --- a/vendor/utf8_range/BUILD.bazel +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2022 Google LLC -# -# Use of this source code is governed by an MIT-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/MIT. - -load("@rules_cc//cc:cc_test.bzl", "cc_test") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_license//rules:license.bzl", "license") - -package( - default_applicable_licenses = [":license"], - default_visibility = ["//visibility:public"], -) - -license( - name = "license", - package_name = "utf8_range", -) - -licenses(["notice"]) - -exports_files([ - "LICENSE", - "rules_fuzzing.patch", -]) - -# TODO Remove this once callers have been Bazelified. -filegroup( - name = "utf8_range_srcs", - srcs = [ - "utf8_range.c", - "utf8_range.h", - "utf8_range_neon.inc", - "utf8_range_sse.inc", - ], - visibility = ["//:__subpackages__"], -) - -cc_library( - name = "utf8_range", - srcs = [ - "utf8_range.c", - ], - hdrs = [ - "utf8_range.h", - "utf8_range_neon.inc", - "utf8_range_sse.inc", - ], - strip_include_prefix = "/third_party/utf8_range", -) - -cc_library( - name = "utf8_validity", - hdrs = ["utf8_validity.h"], - strip_include_prefix = "/third_party/utf8_range", - deps = [ - ":utf8_range", - "@abseil-cpp//absl/strings", - ], -) - -cc_test( - name = "utf8_validity_test", - srcs = [ - "utf8_range.c", - "utf8_validity_test.cc", - ], - deps = [ - ":utf8_range", - ":utf8_validity", - "@abseil-cpp//absl/strings", - "@googletest//:gtest", - "@googletest//:gtest_main", - ], -) diff --git a/vendor/utf8_range/CMakeLists.txt b/vendor/utf8_range/CMakeLists.txt deleted file mode 100644 index 2311970..0000000 --- a/vendor/utf8_range/CMakeLists.txt +++ /dev/null @@ -1,97 +0,0 @@ -cmake_minimum_required (VERSION 3.16) -project (utf8_range C CXX) - -# option() honor variables -if (POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif (POLICY CMP0077) - -option (utf8_range_ENABLE_TESTS "Build test suite" ON) -option (utf8_range_ENABLE_INSTALL "Configure installation" ON) - -## -# Create the lightweight C library -add_library (utf8_range - utf8_range.c -) - -## -# A heavier-weight C++ wrapper that supports Abseil. -add_library (utf8_validity utf8_range.c) - -set_target_properties(utf8_range PROPERTIES - VERSION ${protobuf_VERSION} - OUTPUT_NAME ${LIB_PREFIX}utf8_range -) -set_target_properties(utf8_validity PROPERTIES - VERSION ${protobuf_VERSION} - OUTPUT_NAME ${LIB_PREFIX}utf8_validity -) - -target_include_directories(utf8_validity PUBLIC - $ -) - -# Load Abseil dependency. -if (NOT TARGET absl::strings) - if (NOT ABSL_ROOT_DIR) - find_package(absl REQUIRED CONFIG) - else () - set(ABSL_ENABLE_INSTALL ${utf8_range_ENABLE_INSTALL}) - set(ABSL_PROPAGATE_CXX_STD ON) - add_subdirectory(${ABSL_ROOT_DIR} third_party/abseil-cpp) - endif () -endif () -target_link_libraries(utf8_validity PUBLIC absl::strings) - -# Configure tests. -if (utf8_range_ENABLE_TESTS) - enable_testing() - - find_package(GTest REQUIRED) - - add_executable(tests utf8_validity_test.cc) - target_link_libraries(tests utf8_validity GTest::gmock_main) - - add_test(NAME utf8_validity_test COMMAND tests) - - add_custom_target(check - COMMAND tests - DEPENDS tests - ) -endif () - -# Configure installation. -if (utf8_range_ENABLE_INSTALL) - include(CMakePackageConfigHelpers) - include(GNUInstallDirs) - - install(EXPORT ${PROJECT_NAME}-targets - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - NAMESPACE utf8_range:: - ) - install(TARGETS utf8_validity utf8_range EXPORT ${PROJECT_NAME}-targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - - configure_package_config_file( - cmake/${PROJECT_NAME}-config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - ) - install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - ) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/utf8_range.pc.cmake - ${CMAKE_CURRENT_BINARY_DIR}/utf8_range.pc @ONLY) - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/utf8_range.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - - # Install public headers explicitly. - install(FILES utf8_range.h utf8_validity.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) -endif () diff --git a/vendor/utf8_range/LICENSE b/vendor/utf8_range/LICENSE deleted file mode 100644 index e59f14f..0000000 --- a/vendor/utf8_range/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -MIT License - -Copyright (c) 2019 Yibo Cai -Copyright 2022 Google LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/utf8_range/README.md b/vendor/utf8_range/README.md deleted file mode 100644 index 7971a10..0000000 --- a/vendor/utf8_range/README.md +++ /dev/null @@ -1,264 +0,0 @@ -[![Build Status](https://travis-ci.com/cyb70289/utf8.svg?branch=master)](https://travis-ci.com/cyb70289/utf8) - -# Fast UTF-8 validation with Range algorithm (NEON+SSE4+AVX2) - -This is a brand new algorithm to leverage SIMD for fast UTF-8 string validation. Both **NEON**(armv8a) and **SSE4** versions are implemented. **AVX2** implementation contributed by [ioioioio](https://github.com/ioioioio). - -Four UTF-8 validation methods are compared on both x86 and Arm platforms. Benchmark result shows range base algorithm is the best solution on Arm, and achieves same performance as [Lemire's approach](https://lemire.me/blog/2018/05/16/validating-utf-8-strings-using-as-little-as-0-7-cycles-per-byte/) on x86. - -* Range based algorithm - * range-neon.c: NEON version - * range-sse.c: SSE4 version - * range-avx2.c: AVX2 version - * range2-neon.c, range2-sse.c: Process two blocks in one iteration -* [Lemire's SIMD implementation](https://github.com/lemire/fastvalidate-utf-8) - * lemire-sse.c: SSE4 version - * lemire-avx2.c: AVX2 version - * lemire-neon.c: NEON porting -* naive.c: Naive UTF-8 validation byte by byte -* lookup.c: [Lookup-table method](http://bjoern.hoehrmann.de/utf-8/decoder/dfa/) - -## About the code - -* Run "make" to build. Built and tested with gcc-7.3. -* Run "./utf8" to see all command line options. -* Benchmark - * Run "./utf8 bench" to benchmark all algorithms with [default test file](https://raw.githubusercontent.com/cyb70289/utf8/master/UTF-8-demo.txt). - * Run "./utf8 bench size NUM" to benchmark specified string size. -* Run "./utf8 test" to test all algorithms with positive and negative test cases. -* To benchmark or test specific algorithm, run something like "./utf8 bench range". - -## Benchmark result (MB/s) - -### Method -1. Generate UTF-8 test buffer per [test file](https://raw.githubusercontent.com/cyb70289/utf8/master/UTF-8-demo.txt) or buffer size. -1. Call validation sub-routines in a loop until 1G bytes are checked. -1. Calculate speed(MB/s) of validating UTF-8 strings. - -### NEON(armv8a) -Test case | naive | lookup | lemire | range | range2 -:-------- | :---- | :----- | :----- | :---- | :----- -[UTF-demo.txt](https://raw.githubusercontent.com/cyb70289/utf8/master/UTF-8-demo.txt) | 562.25 | 412.84 | 1198.50 | 1411.72 | **1579.85** -32 bytes | 651.55 | 441.70 | 891.38 | 1003.95 | **1043.58** -33 bytes | 660.00 | 446.78 | 588.77 | 1009.31 | **1048.12** -129 bytes | 771.89 | 402.55 | 938.07 | 1283.77 | **1401.76** -1K bytes | 811.92 | 411.58 | 1188.96 | 1398.15 | **1560.23** -8K bytes | 812.25 | 412.74 | 1198.90 | 1412.18 | **1580.65** -64K bytes | 817.35 | 412.24 | 1200.20 | 1415.11 | **1583.86** -1M bytes | 815.70 | 411.93 | 1200.93 | 1415.65 | **1585.40** - -### SSE4(E5-2650) -Test case | naive | lookup | lemire | range | range2 -:-------- | :---- | :----- | :----- | :---- | :----- -[UTF-demo.txt](https://raw.githubusercontent.com/cyb70289/utf8/master/UTF-8-demo.txt) | 753.70 | 310.41 | 3954.74 | 3945.60 | **3986.13** -32 bytes | 1135.76 | 364.07 | **2890.52** | 2351.81 | 2173.02 -33 bytes | 1161.85 | 376.29 | 1352.95 | **2239.55** | 2041.43 -129 bytes | 1161.22 | 322.47 | 2742.49 | **3315.33** | 3249.35 -1K bytes | 1310.95 | 310.72 | 3755.88 | 3781.23 | **3874.17** -8K bytes | 1348.32 | 307.93 | 3860.71 | 3922.81 | **3968.93** -64K bytes | 1301.34 | 308.39 | 3935.15 | 3973.50 | **3983.44** -1M bytes | 1279.78 | 309.06 | 3923.51 | 3953.00 | **3960.49** - -## Range algorithm analysis - -Basic idea: -* Load 16 bytes -* Leverage SIMD to calculate value range for each byte efficiently -* Validate 16 bytes at once - -### UTF-8 coding format - -http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf, page 94 - -Table 3-7. Well-Formed UTF-8 Byte Sequences - -Code Points | First Byte | Second Byte | Third Byte | Fourth Byte | -:---------- | :--------- | :---------- | :--------- | :---------- | -U+0000..U+007F | 00..7F | | | | -U+0080..U+07FF | C2..DF | 80..BF | | | -U+0800..U+0FFF | E0 | ***A0***..BF| 80..BF | | -U+1000..U+CFFF | E1..EC | 80..BF | 80..BF | | -U+D000..U+D7FF | ED | 80..***9F***| 80..BF | | -U+E000..U+FFFF | EE..EF | 80..BF | 80..BF | | -U+10000..U+3FFFF | F0 | ***90***..BF| 80..BF | 80..BF | -U+40000..U+FFFFF | F1..F3 | 80..BF | 80..BF | 80..BF | -U+100000..U+10FFFF | F4 | 80..***8F***| 80..BF | 80..BF | - -To summarise UTF-8 encoding: -* Depending on First Byte, one legal character can be 1, 2, 3, 4 bytes - * For First Byte within C0..DF, character length = 2 - * For First Byte within E0..EF, character length = 3 - * For First Byte within F0..F4, character length = 4 -* C0, C1, F5..FF are not allowed -* Second,Third,Fourth Bytes must lie in 80..BF. -* There are four **special cases** for Second Byte, shown ***bold italic*** in above table. - -### Range table - -Range table maps range index 0 ~ 15 to minimal and maximum values allowed. Our task is to observe input string, find the pattern and set correct range index for each byte, then validate input string. - -Index | Min | Max | Byte type -:---- | :-- | :-- | :-------- -0 | 00 | 7F | First Byte, ASCII -1,2,3 | 80 | BF | Second, Third, Fourth Bytes -4 | A0 | BF | Second Byte after E0 -5 | 80 | 9F | Second Byte after ED -6 | 90 | BF | Second Byte after F0 -7 | 80 | 8F | Second Byte after F4 -8 | C2 | F4 | First Byte, non-ASCII -9..15(NEON) | FF | 00 | Illegal: unsigned char >= 255 && unsigned char <= 0 -9..15(SSE) | 7F | 80 | Illegal: signed char >= 127 && signed char <= -128 - -### Calculate byte ranges (ignore special cases) - -Ignoring the four special cases(E0,ED,F0,F4), how should we set range index for each byte? - -* Set range index to 0(00..7F) for all bytes by default -* Find non-ASCII First Byte (C0..FF), set their range index to 8(C2..F4) -* For First Byte within C0..DF, set next byte's range index to 1(80..BF) -* For First Byte within E0..EF, set next two byte's range index to 2,1(80..BF) in sequence -* For First Byte within F0..FF, set next three byte's range index to 3,2,1(80..BF) in sequence - -To implement above operations efficiently with SIMD: -* For 16 input bytes, use lookup table to map C0..DF to 1, E0..EF to 2, F0..FF to 3, others to 0. Save to first_len. -* Map C0..FF to 8, we get range indices for First Byte. -* Shift first_len one byte, we get range indices for Second Byte. -* Saturate subtract first_len by one(3->2, 2->1, 1->0, 0->0), then shift two bytes, we get range indices for Third Byte. -* Saturate subtract first_len by two(3->1, 2->0, 1->0, 0->0), then shift three bytes, we get range indices for Fourth Byte. - -Example(assume no previous data) - -Input | F1 | 80 | 80 | 80 | 80 | C2 | 80 | 80 | ... -:---- | :- | :- | :- | :- | :- | :- | :- | :- | :-- -*first_len* |*3* |*0* |*0* |*0* |*0* |*1* |*0* |*0* |*...* -First Byte | 8 | 0 | 0 | 0 | 0 | 8 | 0 | 0 | ... -Second Byte | 0 | 3 | 0 | 0 | 0 | 0 | 1 | 0 | ... -Third Byte | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | ... -Fourth Byte | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | ... -Range index | 8 | 3 | 2 | 1 | 0 | 8 | 1 | 0 | ... - -```c -Range_index = First_Byte | Second_Byte | Third_Byte | Fourth_Byte -``` - -#### Error handling - -* C0,C1,F5..FF are not included in range table and will always be detected. -* Illegal 80..BF will have range index 0(00..7F) and be detected. -* Based on First Byte, according Second, Third and Fourth Bytes will have range index 1/2/3, to make sure they must lie in 80..BF. -* If non-ASCII First Byte overlaps, above algorithm will set range index of the latter First Byte to 9,10,11, which are illegal ranges. E.g, Input = F1 80 C2 90 --> Range index = 8 3 10 1, where 10 indicates error. See table below. - -Overlapped non-ASCII First Byte - -Input | F1 | 80 | C2 | 90 -:---- | :- | :- | :- | :- -*first_len* |*3* |*0* |*1* |*0* -First Byte | 8 | 0 | 8 | 0 -Second Byte | 0 | 3 | 0 | 1 -Third Byte | 0 | 0 | 2 | 0 -Fourth Byte | 0 | 0 | 0 | 1 -Range index | 8 | 3 |***10***| 1 - -### Adjust Second Byte range for special cases - -Range index adjustment for four special cases - -First Byte | Second Byte | Before adjustment | Correct index | Adjustment | -:--------- | :---------- | :---------------- | :------------ | :--------- -E0 | A0..BF | 2 | 4 | **2** -ED | 80..9F | 2 | 5 | **3** -F0 | 90..BF | 3 | 6 | **3** -F4 | 80..8F | 3 | 7 | **4** - -Range index adjustment can be reduced to below problem: - -***Given 16 bytes, replace E0 with 2, ED with 3, F0 with 3, F4 with 4, others with 0.*** - -A naive SIMD approach: -1. Compare 16 bytes with E0, get the mask for eacy byte (FF if equal, 00 otherwise) -1. And the mask with 2 to get adjustment for E0 -1. Repeat step 1,2 for ED,F0,F4 - -At least **eight** operations are required for naive approach. - -Observing special bytes(E0,ED,F0,F4) are close to each other, we can do much better using lookup table. - -#### NEON - -NEON ```tbl``` instruction is very convenient for table lookup: -* Table can be up to 16x4 bytes in size -* Return zero if index is out of range - -Leverage these features, we can solve the problem with as few as **two** operations: -* Precreate a 16x2 lookup table, where table[0]=2, table[13]=3, table[16]=3, table[20]=4, table[others]=0. -* Subtract input bytes with E0 (E0 -> 0, ED -> 13, F0 -> 16, F4 -> 20). -* Use the subtracted byte as index of lookup table and get range adjustment directly. - * For indices less than 32, we get zero or required adjustment value per input byte - * For out of bound indices, we get zero per ```tbl``` behaviour - -#### SSE - -SSE ```pshufb``` instruction is not as friendly as NEON ```tbl``` in this case: -* Table can only be 16 bytes in size -* Out of bound indices are handled this way: - * If 7-th bit of index is 0, least four bits are used as index (E.g, index 0x73 returns 3rd element) - * If 7-th bit of index is 1, return 0 (E.g, index 0x83 returns 0) - -We can still leverage these features to solve the problem in **five** operations: -* Precreate two tables: - * table_df[1] = 2, table_df[14] = 3, table_df[others] = 0 - * table_ef[1] = 3, table_ef[5] = 4, table_ef[others] = 0 -* Subtract input bytes with EF (E0 -> 241, ED -> 254, F0 -> 1, F4 -> 5) to get the temporary indices -* Get range index for E0,ED - * Saturate subtract temporary indices with 240 (E0 -> 1, ED -> 14, all values below 240 becomes 0) - * Use subtracted indices to look up table_df, get the correct adjustment -* Get range index for F0,F4 - * Saturate add temporary indices with 112(0x70) (F0 -> 0x71, F4 -> 0x75, all values above 16 will be larger than 128(7-th bit set)) - * Use added indices to look up table_ef, get the correct adjustment (index 0x71,0x75 returns 1st,5th elements, per ```pshufb``` behaviour) - -#### Error handling - -* For overlapped non-ASCII First Byte, range index before adjustment is 9,10,11. After adjustment (adds 2,3,4 or 0), the range index will be 9 to 15, which is still illegal in range table. So the error will be detected. - -### Handling remaining bytes - -For remaining input less than 16 bytes, we will fallback to naive byte by byte approach to validate them, which is actually faster than SIMD processing. -* Look back last 16 bytes buffer to find First Byte. At most three bytes need to look back. Otherwise we either happen to be at character boundray, or there are some errors we already detected. -* Validate string byte by byte starting from the First Byte. - -## Tests - -It's necessary to design test cases to cover corner cases as more as possible. - -### Positive cases - -1. Prepare correct characters -2. Validate correct characters -3. Validate long strings - * Round concatenate characters starting from first character to 1024 bytes - * Validate 1024 bytes string - * Shift 1 byte, validate 1025 bytes string - * Shift 2 bytes, Validate 1026 bytes string - * ... - * Shift 16 bytes, validate 1040 bytes string -4. Repeat step3, test buffer starting from second character -5. Repeat step3, test buffer starting from third character -6. ... - -### Negative cases - -1. Prepare bad characters and bad strings - * Bad character - * Bad character cross 16 bytes boundary - * Bad character cross last 16 bytes and remaining bytes boundary -2. Test long strings - * Prepare correct long strings same as positive cases - * Append bad characters - * Shift one byte for each iteration - * Validate each shift - -## Code breakdown - -Below table shows how 16 bytes input are processed step by step. See [range-neon.c](range-neon.c) for according code. - -![Range based UTF-8 validation algorithm](https://raw.githubusercontent.com/cyb70289/utf8/master/range.png) diff --git a/vendor/utf8_range/UTF-8-demo.txt b/vendor/utf8_range/UTF-8-demo.txt deleted file mode 100644 index ff915b2..0000000 --- a/vendor/utf8_range/UTF-8-demo.txt +++ /dev/null @@ -1,212 +0,0 @@ - -UTF-8 encoded sample plain-text file -‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -Markus Kuhn [ˈmaʳkʊs kuːn] — 2002-07-25 CC BY - - -The ASCII compatible UTF-8 encoding used in this plain-text file -is defined in Unicode, ISO 10646-1, and RFC 2279. - - -Using Unicode/UTF-8, you can write in emails and source code things such as - -Mathematics and sciences: - - ∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i), ⎧⎡⎛┌─────┐⎞⎤⎫ - ⎪⎢⎜│a²+b³ ⎟⎥⎪ - ∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β), ⎪⎢⎜│───── ⎟⎥⎪ - ⎪⎢⎜⎷ c₈ ⎟⎥⎪ - ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⎨⎢⎜ ⎟⎥⎬ - ⎪⎢⎜ ∞ ⎟⎥⎪ - ⊥ < a ≠ b ≡ c ≤ d ≪ ⊤ ⇒ (⟦A⟧ ⇔ ⟪B⟫), ⎪⎢⎜ ⎲ ⎟⎥⎪ - ⎪⎢⎜ ⎳aⁱ-bⁱ⎟⎥⎪ - 2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm ⎩⎣⎝i=1 ⎠⎦⎭ - -Linguistics and dictionaries: - - ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn - Y [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ] - -APL: - - ((V⍳V)=⍳⍴V)/V←,V ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈ - -Nicer typography in plain text files: - - ╔══════════════════════════════════════════╗ - ║ ║ - ║ • ‘single’ and “double” quotes ║ - ║ ║ - ║ • Curly apostrophes: “We’ve been here” ║ - ║ ║ - ║ • Latin-1 apostrophe and accents: '´` ║ - ║ ║ - ║ • ‚deutsche‘ „Anführungszeichen“ ║ - ║ ║ - ║ • †, ‡, ‰, •, 3–4, —, −5/+5, ™, … ║ - ║ ║ - ║ • ASCII safety test: 1lI|, 0OD, 8B ║ - ║ ╭─────────╮ ║ - ║ • the euro symbol: │ 14.95 € │ ║ - ║ ╰─────────╯ ║ - ╚══════════════════════════════════════════╝ - -Combining characters: - - STARGΛ̊TE SG-1, a = v̇ = r̈, a⃑ ⊥ b⃑ - -Greek (in Polytonic): - - The Greek anthem: - - Σὲ γνωρίζω ἀπὸ τὴν κόψη - τοῦ σπαθιοῦ τὴν τρομερή, - σὲ γνωρίζω ἀπὸ τὴν ὄψη - ποὺ μὲ βία μετράει τὴ γῆ. - - ᾿Απ᾿ τὰ κόκκαλα βγαλμένη - τῶν ῾Ελλήνων τὰ ἱερά - καὶ σὰν πρῶτα ἀνδρειωμένη - χαῖρε, ὦ χαῖρε, ᾿Ελευθεριά! - - From a speech of Demosthenes in the 4th century BC: - - Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι, - ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς - λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ - τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿ - εἰς τοῦτο προήκοντα, ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ - πρότερον κακῶς σκέψασθαι δέον. οὐδέν οὖν ἄλλο μοι δοκοῦσιν - οἱ τὰ τοιαῦτα λέγοντες ἢ τὴν ὑπόθεσιν, περὶ ἧς βουλεύεσθαι, - οὐχὶ τὴν οὖσαν παριστάντες ὑμῖν ἁμαρτάνειν. ἐγὼ δέ, ὅτι μέν - ποτ᾿ ἐξῆν τῇ πόλει καὶ τὰ αὑτῆς ἔχειν ἀσφαλῶς καὶ Φίλιππον - τιμωρήσασθαι, καὶ μάλ᾿ ἀκριβῶς οἶδα· ἐπ᾿ ἐμοῦ γάρ, οὐ πάλαι - γέγονεν ταῦτ᾿ ἀμφότερα· νῦν μέντοι πέπεισμαι τοῦθ᾿ ἱκανὸν - προλαβεῖν ἡμῖν εἶναι τὴν πρώτην, ὅπως τοὺς συμμάχους - σώσομεν. ἐὰν γὰρ τοῦτο βεβαίως ὑπάρξῃ, τότε καὶ περὶ τοῦ - τίνα τιμωρήσεταί τις καὶ ὃν τρόπον ἐξέσται σκοπεῖν· πρὶν δὲ - τὴν ἀρχὴν ὀρθῶς ὑποθέσθαι, μάταιον ἡγοῦμαι περὶ τῆς - τελευτῆς ὁντινοῦν ποιεῖσθαι λόγον. - - Δημοσθένους, Γ´ ᾿Ολυνθιακὸς - -Georgian: - - From a Unicode conference invitation: - - გთხოვთ ახლავე გაიაროთ რეგისტრაცია Unicode-ის მეათე საერთაშორისო - კონფერენციაზე დასასწრებად, რომელიც გაიმართება 10-12 მარტს, - ქ. მაინცში, გერმანიაში. კონფერენცია შეჰკრებს ერთად მსოფლიოს - ექსპერტებს ისეთ დარგებში როგორიცაა ინტერნეტი და Unicode-ი, - ინტერნაციონალიზაცია და ლოკალიზაცია, Unicode-ის გამოყენება - ოპერაციულ სისტემებსა, და გამოყენებით პროგრამებში, შრიფტებში, - ტექსტების დამუშავებასა და მრავალენოვან კომპიუტერულ სისტემებში. - -Russian: - - From a Unicode conference invitation: - - Зарегистрируйтесь сейчас на Десятую Международную Конференцию по - Unicode, которая состоится 10-12 марта 1997 года в Майнце в Германии. - Конференция соберет широкий круг экспертов по вопросам глобального - Интернета и Unicode, локализации и интернационализации, воплощению и - применению Unicode в различных операционных системах и программных - приложениях, шрифтах, верстке и многоязычных компьютерных системах. - -Thai (UCS Level 2): - - Excerpt from a poetry on The Romance of The Three Kingdoms (a Chinese - classic 'San Gua'): - - [----------------------------|------------------------] - ๏ แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช พระปกเกศกองบู๊กู้ขึ้นใหม่ - สิบสองกษัตริย์ก่อนหน้าแลถัดไป สององค์ไซร้โง่เขลาเบาปัญญา - ทรงนับถือขันทีเป็นที่พึ่ง บ้านเมืองจึงวิปริตเป็นนักหนา - โฮจิ๋นเรียกทัพทั่วหัวเมืองมา หมายจะฆ่ามดชั่วตัวสำคัญ - เหมือนขับไสไล่เสือจากเคหา รับหมาป่าเข้ามาเลยอาสัญ - ฝ่ายอ้องอุ้นยุแยกให้แตกกัน ใช้สาวนั้นเป็นชนวนชื่นชวนใจ - พลันลิฉุยกุยกีกลับก่อเหตุ ช่างอาเพศจริงหนาฟ้าร้องไห้ - ต้องรบราฆ่าฟันจนบรรลัย ฤๅหาใครค้ำชูกู้บรรลังก์ ฯ - - (The above is a two-column text. If combining characters are handled - correctly, the lines of the second column should be aligned with the - | character above.) - -Ethiopian: - - Proverbs in the Amharic language: - - ሰማይ አይታረስ ንጉሥ አይከሰስ። - ብላ ካለኝ እንደአባቴ በቆመጠኝ። - ጌጥ ያለቤቱ ቁምጥና ነው። - ደሀ በሕልሙ ቅቤ ባይጠጣ ንጣት በገደለው። - የአፍ ወለምታ በቅቤ አይታሽም። - አይጥ በበላ ዳዋ ተመታ። - ሲተረጉሙ ይደረግሙ። - ቀስ በቀስ፥ ዕንቁላል በእግሩ ይሄዳል። - ድር ቢያብር አንበሳ ያስር። - ሰው እንደቤቱ እንጅ እንደ ጉረቤቱ አይተዳደርም። - እግዜር የከፈተውን ጉሮሮ ሳይዘጋው አይድርም። - የጎረቤት ሌባ፥ ቢያዩት ይስቅ ባያዩት ያጠልቅ። - ሥራ ከመፍታት ልጄን ላፋታት። - ዓባይ ማደሪያ የለው፥ ግንድ ይዞ ይዞራል። - የእስላም አገሩ መካ የአሞራ አገሩ ዋርካ። - ተንጋሎ ቢተፉ ተመልሶ ባፉ። - ወዳጅህ ማር ቢሆን ጨርስህ አትላሰው። - እግርህን በፍራሽህ ልክ ዘርጋ። - -Runes: - - ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ - - (Old English, which transcribed into Latin reads 'He cwaeth that he - bude thaem lande northweardum with tha Westsae.' and means 'He said - that he lived in the northern land near the Western Sea.') - -Braille: - - ⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌ - - ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠙⠑⠁⠙⠒ ⠞⠕ ⠃⠑⠛⠔ ⠺⠊⠹⠲ ⡹⠻⠑ ⠊⠎ ⠝⠕ ⠙⠳⠃⠞ - ⠱⠁⠞⠑⠧⠻ ⠁⠃⠳⠞ ⠹⠁⠞⠲ ⡹⠑ ⠗⠑⠛⠊⠌⠻ ⠕⠋ ⠙⠊⠎ ⠃⠥⠗⠊⠁⠇ ⠺⠁⠎ - ⠎⠊⠛⠝⠫ ⠃⠹ ⠹⠑ ⠊⠇⠻⠛⠹⠍⠁⠝⠂ ⠹⠑ ⠊⠇⠻⠅⠂ ⠹⠑ ⠥⠝⠙⠻⠞⠁⠅⠻⠂ - ⠁⠝⠙ ⠹⠑ ⠡⠊⠑⠋ ⠍⠳⠗⠝⠻⠲ ⡎⠊⠗⠕⠕⠛⠑ ⠎⠊⠛⠝⠫ ⠊⠞⠲ ⡁⠝⠙ - ⡎⠊⠗⠕⠕⠛⠑⠰⠎ ⠝⠁⠍⠑ ⠺⠁⠎ ⠛⠕⠕⠙ ⠥⠏⠕⠝ ⠰⡡⠁⠝⠛⠑⠂ ⠋⠕⠗ ⠁⠝⠹⠹⠔⠛ ⠙⠑ - ⠡⠕⠎⠑ ⠞⠕ ⠏⠥⠞ ⠙⠊⠎ ⠙⠁⠝⠙ ⠞⠕⠲ - - ⡕⠇⠙ ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲ - - ⡍⠔⠙⠖ ⡊ ⠙⠕⠝⠰⠞ ⠍⠑⠁⠝ ⠞⠕ ⠎⠁⠹ ⠹⠁⠞ ⡊ ⠅⠝⠪⠂ ⠕⠋ ⠍⠹ - ⠪⠝ ⠅⠝⠪⠇⠫⠛⠑⠂ ⠱⠁⠞ ⠹⠻⠑ ⠊⠎ ⠏⠜⠞⠊⠊⠥⠇⠜⠇⠹ ⠙⠑⠁⠙ ⠁⠃⠳⠞ - ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲ ⡊ ⠍⠊⠣⠞ ⠙⠁⠧⠑ ⠃⠑⠲ ⠔⠊⠇⠔⠫⠂ ⠍⠹⠎⠑⠇⠋⠂ ⠞⠕ - ⠗⠑⠛⠜⠙ ⠁ ⠊⠕⠋⠋⠔⠤⠝⠁⠊⠇ ⠁⠎ ⠹⠑ ⠙⠑⠁⠙⠑⠌ ⠏⠊⠑⠊⠑ ⠕⠋ ⠊⠗⠕⠝⠍⠕⠝⠛⠻⠹ - ⠔ ⠹⠑ ⠞⠗⠁⠙⠑⠲ ⡃⠥⠞ ⠹⠑ ⠺⠊⠎⠙⠕⠍ ⠕⠋ ⠳⠗ ⠁⠝⠊⠑⠌⠕⠗⠎ - ⠊⠎ ⠔ ⠹⠑ ⠎⠊⠍⠊⠇⠑⠆ ⠁⠝⠙ ⠍⠹ ⠥⠝⠙⠁⠇⠇⠪⠫ ⠙⠁⠝⠙⠎ - ⠩⠁⠇⠇ ⠝⠕⠞ ⠙⠊⠌⠥⠗⠃ ⠊⠞⠂ ⠕⠗ ⠹⠑ ⡊⠳⠝⠞⠗⠹⠰⠎ ⠙⠕⠝⠑ ⠋⠕⠗⠲ ⡹⠳ - ⠺⠊⠇⠇ ⠹⠻⠑⠋⠕⠗⠑ ⠏⠻⠍⠊⠞ ⠍⠑ ⠞⠕ ⠗⠑⠏⠑⠁⠞⠂ ⠑⠍⠏⠙⠁⠞⠊⠊⠁⠇⠇⠹⠂ ⠹⠁⠞ - ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲ - - (The first couple of paragraphs of "A Christmas Carol" by Dickens) - -Compact font selection example text: - - ABCDEFGHIJKLMNOPQRSTUVWXYZ /0123456789 - abcdefghijklmnopqrstuvwxyz £©µÀÆÖÞßéöÿ - –—‘“”„†•…‰™œŠŸž€ ΑΒΓΔΩαβγδω АБВГДабвгд - ∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi�⑀₂ἠḂӥẄɐː⍎אԱა - -Greetings in various languages: - - Hello world, Καλημέρα κόσμε, コンニチハ - -Box drawing alignment tests: █ - ▉ - ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳ - ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳ - ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳ - ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳ - ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎ - ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏ - ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ ▗▄▖▛▀▜ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█ - ▝▀▘▙▄▟ diff --git a/vendor/utf8_range/ascii.cpp b/vendor/utf8_range/ascii.cpp deleted file mode 100644 index 9c5d183..0000000 --- a/vendor/utf8_range/ascii.cpp +++ /dev/null @@ -1,222 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include - -static inline int ascii_std(const uint8_t *data, int len) { - return !std::any_of(data, data + len, [](int8_t b) { return b < 0; }); -} - -static inline int ascii_u64(const uint8_t *data, int len) { - uint8_t orall = 0; - - if (len >= 16) { - uint64_t or1 = 0, or2 = 0; - const uint8_t *data2 = data + 8; - - do { - or1 |= *(const uint64_t *)data; - or2 |= *(const uint64_t *)data2; - data += 16; - data2 += 16; - len -= 16; - } while (len >= 16); - - /* - * Idea from Benny Halevy - * - 7-th bit set ==> orall = !(non-zero) - 1 = 0 - 1 = 0xFF - * - 7-th bit clear ==> orall = !0 - 1 = 1 - 1 = 0x00 - */ - orall = !((or1 | or2) & 0x8080808080808080ULL) - 1; - } - - while (len--) orall |= *data++; - - return orall < 0x80; -} - -#if defined(__x86_64__) -#include - -static inline int ascii_simd(const uint8_t *data, int len) { - if (len >= 32) { - const uint8_t *data2 = data + 16; - - __m128i or1 = _mm_set1_epi8(0), or2 = or1; - - while (len >= 32) { - __m128i input1 = _mm_loadu_si128((const __m128i *)data); - __m128i input2 = _mm_loadu_si128((const __m128i *)data2); - - or1 = _mm_or_si128(or1, input1); - or2 = _mm_or_si128(or2, input2); - - data += 32; - data2 += 32; - len -= 32; - } - - or1 = _mm_or_si128(or1, or2); - if (_mm_movemask_epi8(_mm_cmplt_epi8(or1, _mm_set1_epi8(0)))) return 0; - } - - return ascii_u64(data, len); -} - -#elif defined(__aarch64__) -#include - -static inline int ascii_simd(const uint8_t *data, int len) { - if (len >= 32) { - const uint8_t *data2 = data + 16; - - uint8x16_t or1 = vdupq_n_u8(0), or2 = or1; - - while (len >= 32) { - const uint8x16_t input1 = vld1q_u8(data); - const uint8x16_t input2 = vld1q_u8(data2); - - or1 = vorrq_u8(or1, input1); - or2 = vorrq_u8(or2, input2); - - data += 32; - data2 += 32; - len -= 32; - } - - or1 = vorrq_u8(or1, or2); - if (vmaxvq_u8(or1) >= 0x80) return 0; - } - - return ascii_u64(data, len); -} - -#endif - -struct ftab { - const char *name; - int (*func)(const uint8_t *data, int len); -}; - -static const std::vector _f = { - { - .name = "std", - .func = ascii_std, - }, - { - .name = "u64", - .func = ascii_u64, - }, - { - .name = "simd", - .func = ascii_simd, - }, -}; - -static void load_test_buf(uint8_t *data, int len) { - uint8_t v = 0; - - for (int i = 0; i < len; ++i) { - data[i] = v++; - v &= 0x7F; - } -} - -static void bench(const struct ftab &f, const uint8_t *data, int len) { - const int loops = 1024 * 1024 * 1024 / len; - int ret = 1; - double time_aligned, time_unaligned, size; - struct timeval tv1, tv2; - - fprintf(stderr, "bench %s (%d bytes)... ", f.name, len); - - /* aligned */ - gettimeofday(&tv1, 0); - for (int i = 0; i < loops; ++i) ret &= f.func(data, len); - gettimeofday(&tv2, 0); - time_aligned = tv2.tv_usec - tv1.tv_usec; - time_aligned = time_aligned / 1000000 + tv2.tv_sec - tv1.tv_sec; - - /* unaligned */ - gettimeofday(&tv1, 0); - for (int i = 0; i < loops; ++i) ret &= f.func(data + 1, len); - gettimeofday(&tv2, 0); - time_unaligned = tv2.tv_usec - tv1.tv_usec; - time_unaligned = time_unaligned / 1000000 + tv2.tv_sec - tv1.tv_sec; - - printf("%s ", ret ? "pass" : "FAIL"); - - size = ((double)len * loops) / (1024 * 1024); - printf("%.0f/%.0f MB/s\n", size / time_aligned, size / time_unaligned); -} - -static void test(const struct ftab &f, uint8_t *data, int len) { - int error = 0; - - fprintf(stderr, "test %s (%d bytes)... ", f.name, len); - - /* positive */ - error |= !f.func(data, len); - - /* negative */ - if (len < 100 * 1024) { - for (int i = 0; i < len; ++i) { - data[i] += 0x80; - error |= f.func(data, len); - data[i] -= 0x80; - } - } - - printf("%s\n", error ? "FAIL" : "pass"); -} - -/* ./ascii [test|bench] [alg] */ -int main(int argc, const char *argv[]) { - int do_test = 1, do_bench = 1; - const char *alg = NULL; - - if (argc > 1) { - do_bench &= !!strcmp(argv[1], "test"); - do_test &= !!strcmp(argv[1], "bench"); - } - - if (do_bench && argc > 2) alg = argv[2]; - - const std::vector size = { - 9, 16 + 1, 32 - 1, 128 + 1, - 1024 + 15, 16 * 1024 + 1, 64 * 1024 + 15, 1024 * 1024}; - - int max_size = *std::max_element(size.begin(), size.end()); - uint8_t *_data = new uint8_t[max_size + 1]; - assert(((uintptr_t)_data & 7) == 0); - uint8_t *data = _data + 1; /* Unalign buffer address */ - - _data[0] = 0; - load_test_buf(data, max_size); - - if (do_test) { - printf("==================== Test ====================\n"); - for (int sz : size) { - for (auto &f : _f) { - test(f, data, sz); - } - } - } - - if (do_bench) { - printf("==================== Bench ====================\n"); - for (int sz : size) { - for (auto &f : _f) { - if (!alg || strcmp(alg, f.name) == 0) bench(f, _data, sz); - } - printf("-----------------------------------------------\n"); - } - } - - delete _data; - return 0; -} diff --git a/vendor/utf8_range/boost.cpp b/vendor/utf8_range/boost.cpp deleted file mode 100644 index c41d019..0000000 --- a/vendor/utf8_range/boost.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -using namespace std; - -/* Return 0 on success, -1 on error */ -extern "C" int utf8_boost(const unsigned char* data, int len) { - try { - boost::locale::conv::utf_to_utf(data, data + len, - boost::locale::conv::stop); - } catch (const boost::locale::conv::conversion_error& ex) { - return -1; - } - - return 0; -} diff --git a/vendor/utf8_range/cmake/utf8_range-config.cmake.in b/vendor/utf8_range/cmake/utf8_range-config.cmake.in deleted file mode 100644 index e9b9331..0000000 --- a/vendor/utf8_range/cmake/utf8_range-config.cmake.in +++ /dev/null @@ -1,7 +0,0 @@ -# Depend packages -if(NOT TARGET absl::strings) - find_package(absl CONFIG) -endif() - -# Imported targets -include("${CMAKE_CURRENT_LIST_DIR}/utf8_range-targets.cmake") diff --git a/vendor/utf8_range/cmake/utf8_range.pc.cmake b/vendor/utf8_range/cmake/utf8_range.pc.cmake deleted file mode 100644 index 64b4b77..0000000 --- a/vendor/utf8_range/cmake/utf8_range.pc.cmake +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ - -Name: UTF8 Range -Description: Google's UTF8 Library -Version: 1.0 -Requires: absl_strings -Libs: -L${libdir} -lutf8_validity -lutf8_range @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} diff --git a/vendor/utf8_range/fuzz/BUILD.bazel b/vendor/utf8_range/fuzz/BUILD.bazel deleted file mode 100644 index f02ce23..0000000 --- a/vendor/utf8_range/fuzz/BUILD.bazel +++ /dev/null @@ -1,14 +0,0 @@ -load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test") - -package(default_applicable_licenses = ["//third_party/utf8_range:license"]) - -cc_fuzz_test( - name = "utf8_validity_fuzzer", - testonly = 1, - srcs = ["utf8_validity_fuzzer.cc"], - dicts = ["utf8_fuzzer.dict"], - deps = [ - "//third_party/utf8_range:utf8_validity", - "@abseil-cpp//absl/strings:string_view", - ], -) diff --git a/vendor/utf8_range/fuzz/utf8_fuzzer.dict b/vendor/utf8_range/fuzz/utf8_fuzzer.dict deleted file mode 100644 index 33e80e1..0000000 --- a/vendor/utf8_range/fuzz/utf8_fuzzer.dict +++ /dev/null @@ -1,7 +0,0 @@ -# 1, 2, 3 and 4 letter unicode symbols. Also 16 byte non ascii symbols to faster -# test the SIMD case -"z" -"\xd1\x8f" -"\xe2\x8f\xa9" -"\xf0\x9f\x94\x8b" -"\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f\xd1\x8f" diff --git a/vendor/utf8_range/fuzz/utf8_validity_fuzzer.cc b/vendor/utf8_range/fuzz/utf8_validity_fuzzer.cc deleted file mode 100644 index c09e52d..0000000 --- a/vendor/utf8_range/fuzz/utf8_validity_fuzzer.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2022 Google LLC -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -#include -#include - -#include "absl/strings/string_view.h" -#include "utf8_validity.h" - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - utf8_range::IsStructurallyValid( - absl::string_view(reinterpret_cast(data), size)); - utf8_range::SpanStructurallyValid( - absl::string_view(reinterpret_cast(data), size)); - return 0; -} diff --git a/vendor/utf8_range/lemire-avx2.c b/vendor/utf8_range/lemire-avx2.c deleted file mode 100644 index ab61c2c..0000000 --- a/vendor/utf8_range/lemire-avx2.c +++ /dev/null @@ -1,233 +0,0 @@ -// Adapted from https://github.com/lemire/fastvalidate-utf-8 - -#ifdef __AVX2__ - -#include -#include -#include -#include -#include - -/* - * legal utf-8 byte sequence - * http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf - page 94 - * - * Code Points 1st 2s 3s 4s - * U+0000..U+007F 00..7F - * U+0080..U+07FF C2..DF 80..BF - * U+0800..U+0FFF E0 A0..BF 80..BF - * U+1000..U+CFFF E1..EC 80..BF 80..BF - * U+D000..U+D7FF ED 80..9F 80..BF - * U+E000..U+FFFF EE..EF 80..BF 80..BF - * U+10000..U+3FFFF F0 90..BF 80..BF 80..BF - * U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF - * U+100000..U+10FFFF F4 80..8F 80..BF 80..BF - * - */ - -#if 0 -static void print256(const char *s, const __m256i v256) -{ - const unsigned char *v8 = (const unsigned char *)&v256; - if (s) - printf("%s:\t", s); - for (int i = 0; i < 32; i++) - printf("%02x ", v8[i]); - printf("\n"); -} -#endif - -static inline __m256i push_last_byte_of_a_to_b(__m256i a, __m256i b) { - return _mm256_alignr_epi8(b, _mm256_permute2x128_si256(a, b, 0x21), 15); -} - -static inline __m256i push_last_2bytes_of_a_to_b(__m256i a, __m256i b) { - return _mm256_alignr_epi8(b, _mm256_permute2x128_si256(a, b, 0x21), 14); -} - -// all byte values must be no larger than 0xF4 -static inline void avxcheckSmallerThan0xF4(__m256i current_bytes, - __m256i *has_error) { - // unsigned, saturates to 0 below max - *has_error = _mm256_or_si256( - *has_error, _mm256_subs_epu8(current_bytes, _mm256_set1_epi8(0xF4))); -} - -static inline __m256i avxcontinuationLengths(__m256i high_nibbles) { - return _mm256_shuffle_epi8( - _mm256_setr_epi8(1, 1, 1, 1, 1, 1, 1, 1, // 0xxx (ASCII) - 0, 0, 0, 0, // 10xx (continuation) - 2, 2, // 110x - 3, // 1110 - 4, // 1111, next should be 0 (not checked here) - 1, 1, 1, 1, 1, 1, 1, 1, // 0xxx (ASCII) - 0, 0, 0, 0, // 10xx (continuation) - 2, 2, // 110x - 3, // 1110 - 4 // 1111, next should be 0 (not checked here) - ), - high_nibbles); -} - -static inline __m256i avxcarryContinuations(__m256i initial_lengths, - __m256i previous_carries) { - - __m256i right1 = _mm256_subs_epu8( - push_last_byte_of_a_to_b(previous_carries, initial_lengths), - _mm256_set1_epi8(1)); - __m256i sum = _mm256_add_epi8(initial_lengths, right1); - - __m256i right2 = _mm256_subs_epu8( - push_last_2bytes_of_a_to_b(previous_carries, sum), _mm256_set1_epi8(2)); - return _mm256_add_epi8(sum, right2); -} - -static inline void avxcheckContinuations(__m256i initial_lengths, - __m256i carries, __m256i *has_error) { - - // overlap || underlap - // carry > length && length > 0 || !(carry > length) && !(length > 0) - // (carries > length) == (lengths > 0) - __m256i overunder = _mm256_cmpeq_epi8( - _mm256_cmpgt_epi8(carries, initial_lengths), - _mm256_cmpgt_epi8(initial_lengths, _mm256_setzero_si256())); - - *has_error = _mm256_or_si256(*has_error, overunder); -} - -// when 0xED is found, next byte must be no larger than 0x9F -// when 0xF4 is found, next byte must be no larger than 0x8F -// next byte must be continuation, ie sign bit is set, so signed < is ok -static inline void avxcheckFirstContinuationMax(__m256i current_bytes, - __m256i off1_current_bytes, - __m256i *has_error) { - __m256i maskED = - _mm256_cmpeq_epi8(off1_current_bytes, _mm256_set1_epi8(0xED)); - __m256i maskF4 = - _mm256_cmpeq_epi8(off1_current_bytes, _mm256_set1_epi8(0xF4)); - - __m256i badfollowED = _mm256_and_si256( - _mm256_cmpgt_epi8(current_bytes, _mm256_set1_epi8(0x9F)), maskED); - __m256i badfollowF4 = _mm256_and_si256( - _mm256_cmpgt_epi8(current_bytes, _mm256_set1_epi8(0x8F)), maskF4); - - *has_error = - _mm256_or_si256(*has_error, _mm256_or_si256(badfollowED, badfollowF4)); -} - -// map off1_hibits => error condition -// hibits off1 cur -// C => < C2 && true -// E => < E1 && < A0 -// F => < F1 && < 90 -// else false && false -static inline void avxcheckOverlong(__m256i current_bytes, - __m256i off1_current_bytes, __m256i hibits, - __m256i previous_hibits, - __m256i *has_error) { - __m256i off1_hibits = push_last_byte_of_a_to_b(previous_hibits, hibits); - __m256i initial_mins = _mm256_shuffle_epi8( - _mm256_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, -128, // 10xx => false - 0xC2, -128, // 110x - 0xE1, // 1110 - 0xF1, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, -128, -128, // 10xx => false - 0xC2, -128, // 110x - 0xE1, // 1110 - 0xF1), - off1_hibits); - - __m256i initial_under = _mm256_cmpgt_epi8(initial_mins, off1_current_bytes); - - __m256i second_mins = _mm256_shuffle_epi8( - _mm256_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, -128, // 10xx => false - 127, 127, // 110x => true - 0xA0, // 1110 - 0x90, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, -128, -128, // 10xx => false - 127, 127, // 110x => true - 0xA0, // 1110 - 0x90), - off1_hibits); - __m256i second_under = _mm256_cmpgt_epi8(second_mins, current_bytes); - *has_error = _mm256_or_si256(*has_error, - _mm256_and_si256(initial_under, second_under)); -} - -struct avx_processed_utf_bytes { - __m256i rawbytes; - __m256i high_nibbles; - __m256i carried_continuations; -}; - -static inline void avx_count_nibbles(__m256i bytes, - struct avx_processed_utf_bytes *answer) { - answer->rawbytes = bytes; - answer->high_nibbles = - _mm256_and_si256(_mm256_srli_epi16(bytes, 4), _mm256_set1_epi8(0x0F)); -} - -// check whether the current bytes are valid UTF-8 -// at the end of the function, previous gets updated -static struct avx_processed_utf_bytes -avxcheckUTF8Bytes(__m256i current_bytes, - struct avx_processed_utf_bytes *previous, - __m256i *has_error) { - struct avx_processed_utf_bytes pb; - avx_count_nibbles(current_bytes, &pb); - - avxcheckSmallerThan0xF4(current_bytes, has_error); - - __m256i initial_lengths = avxcontinuationLengths(pb.high_nibbles); - - pb.carried_continuations = - avxcarryContinuations(initial_lengths, previous->carried_continuations); - - avxcheckContinuations(initial_lengths, pb.carried_continuations, has_error); - - __m256i off1_current_bytes = - push_last_byte_of_a_to_b(previous->rawbytes, pb.rawbytes); - avxcheckFirstContinuationMax(current_bytes, off1_current_bytes, has_error); - - avxcheckOverlong(current_bytes, off1_current_bytes, pb.high_nibbles, - previous->high_nibbles, has_error); - return pb; -} - -/* Return 0 on success, -1 on error */ -int utf8_lemire_avx2(const unsigned char *src, int len) { - size_t i = 0; - __m256i has_error = _mm256_setzero_si256(); - struct avx_processed_utf_bytes previous = { - .rawbytes = _mm256_setzero_si256(), - .high_nibbles = _mm256_setzero_si256(), - .carried_continuations = _mm256_setzero_si256()}; - if (len >= 32) { - for (; i <= len - 32; i += 32) { - __m256i current_bytes = _mm256_loadu_si256((const __m256i *)(src + i)); - previous = avxcheckUTF8Bytes(current_bytes, &previous, &has_error); - } - } - - // last part - if (i < len) { - char buffer[32]; - memset(buffer, 0, 32); - memcpy(buffer, src + i, len - i); - __m256i current_bytes = _mm256_loadu_si256((const __m256i *)(buffer)); - previous = avxcheckUTF8Bytes(current_bytes, &previous, &has_error); - } else { - has_error = _mm256_or_si256( - _mm256_cmpgt_epi8(previous.carried_continuations, - _mm256_setr_epi8(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 1)), - has_error); - } - - return _mm256_testz_si256(has_error, has_error) ? 0 : -1; -} - -#endif diff --git a/vendor/utf8_range/lemire-neon.c b/vendor/utf8_range/lemire-neon.c deleted file mode 100644 index be419af..0000000 --- a/vendor/utf8_range/lemire-neon.c +++ /dev/null @@ -1,215 +0,0 @@ -// Adapted from https://github.com/lemire/fastvalidate-utf-8 - -#ifdef __aarch64__ - -#include -#include -#include -#include -#include -#include - -/* - * legal utf-8 byte sequence - * http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf - page 94 - * - * Code Points 1st 2s 3s 4s - * U+0000..U+007F 00..7F - * U+0080..U+07FF C2..DF 80..BF - * U+0800..U+0FFF E0 A0..BF 80..BF - * U+1000..U+CFFF E1..EC 80..BF 80..BF - * U+D000..U+D7FF ED 80..9F 80..BF - * U+E000..U+FFFF EE..EF 80..BF 80..BF - * U+10000..U+3FFFF F0 90..BF 80..BF 80..BF - * U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF - * U+100000..U+10FFFF F4 80..8F 80..BF 80..BF - * - */ - -#if 0 -static void print128(const char *s, const int8x16_t *v128) -{ - int8_t v8[16]; - vst1q_s8(v8, *v128); - - if (s) - printf("%s:\t", s); - for (int i = 0; i < 16; ++i) - printf("%02x ", (unsigned char)v8[i]); - printf("\n"); -} -#endif - -// all byte values must be no larger than 0xF4 -static inline void checkSmallerThan0xF4(int8x16_t current_bytes, - int8x16_t *has_error) { - // unsigned, saturates to 0 below max - *has_error = vorrq_s8(*has_error, - vreinterpretq_s8_u8(vqsubq_u8(vreinterpretq_u8_s8(current_bytes), vdupq_n_u8(0xF4)))); -} - -static const int8_t _nibbles[] = { - 1, 1, 1, 1, 1, 1, 1, 1, // 0xxx (ASCII) - 0, 0, 0, 0, // 10xx (continuation) - 2, 2, // 110x - 3, // 1110 - 4, // 1111, next should be 0 (not checked here) -}; - -static inline int8x16_t continuationLengths(int8x16_t high_nibbles) { - return vqtbl1q_s8(vld1q_s8(_nibbles), vreinterpretq_u8_s8(high_nibbles)); -} - -static inline int8x16_t carryContinuations(int8x16_t initial_lengths, - int8x16_t previous_carries) { - - int8x16_t right1 = - vreinterpretq_s8_u8(vqsubq_u8(vreinterpretq_u8_s8(vextq_s8(previous_carries, initial_lengths, 16 - 1)), - vdupq_n_u8(1))); - int8x16_t sum = vaddq_s8(initial_lengths, right1); - - int8x16_t right2 = vreinterpretq_s8_u8(vqsubq_u8(vreinterpretq_u8_s8(vextq_s8(previous_carries, sum, 16 - 2)), - vdupq_n_u8(2))); - return vaddq_s8(sum, right2); -} - -static inline void checkContinuations(int8x16_t initial_lengths, int8x16_t carries, - int8x16_t *has_error) { - - // overlap || underlap - // carry > length && length > 0 || !(carry > length) && !(length > 0) - // (carries > length) == (lengths > 0) - uint8x16_t overunder = - vceqq_u8(vcgtq_s8(carries, initial_lengths), - vcgtq_s8(initial_lengths, vdupq_n_s8(0))); - - *has_error = vorrq_s8(*has_error, vreinterpretq_s8_u8(overunder)); -} - -// when 0xED is found, next byte must be no larger than 0x9F -// when 0xF4 is found, next byte must be no larger than 0x8F -// next byte must be continuation, ie sign bit is set, so signed < is ok -static inline void checkFirstContinuationMax(int8x16_t current_bytes, - int8x16_t off1_current_bytes, - int8x16_t *has_error) { - uint8x16_t maskED = vceqq_s8(off1_current_bytes, vdupq_n_s8(0xED)); - uint8x16_t maskF4 = vceqq_s8(off1_current_bytes, vdupq_n_s8(0xF4)); - - uint8x16_t badfollowED = - vandq_u8(vcgtq_s8(current_bytes, vdupq_n_s8(0x9F)), maskED); - uint8x16_t badfollowF4 = - vandq_u8(vcgtq_s8(current_bytes, vdupq_n_s8(0x8F)), maskF4); - - *has_error = vorrq_s8(*has_error, vreinterpretq_s8_u8(vorrq_u8(badfollowED, badfollowF4))); -} - -static const int8_t _initial_mins[] = { - -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, // 10xx => false - 0xC2, -128, // 110x - 0xE1, // 1110 - 0xF1, -}; - -static const int8_t _second_mins[] = { - -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, // 10xx => false - 127, 127, // 110x => true - 0xA0, // 1110 - 0x90, -}; - -// map off1_hibits => error condition -// hibits off1 cur -// C => < C2 && true -// E => < E1 && < A0 -// F => < F1 && < 90 -// else false && false -static inline void checkOverlong(int8x16_t current_bytes, - int8x16_t off1_current_bytes, int8x16_t hibits, - int8x16_t previous_hibits, int8x16_t *has_error) { - int8x16_t off1_hibits = vextq_s8(previous_hibits, hibits, 16 - 1); - int8x16_t initial_mins = vqtbl1q_s8(vld1q_s8(_initial_mins), vreinterpretq_u8_s8(off1_hibits)); - - uint8x16_t initial_under = vcgtq_s8(initial_mins, off1_current_bytes); - - int8x16_t second_mins = vqtbl1q_s8(vld1q_s8(_second_mins), vreinterpretq_u8_s8(off1_hibits)); - uint8x16_t second_under = vcgtq_s8(second_mins, current_bytes); - *has_error = - vorrq_s8(*has_error, vreinterpretq_s8_u8(vandq_u8(initial_under, second_under))); -} - -struct processed_utf_bytes { - int8x16_t rawbytes; - int8x16_t high_nibbles; - int8x16_t carried_continuations; -}; - -static inline void count_nibbles(int8x16_t bytes, - struct processed_utf_bytes *answer) { - answer->rawbytes = bytes; - answer->high_nibbles = - vreinterpretq_s8_u8(vshrq_n_u8(vreinterpretq_u8_s8(bytes), 4)); -} - -// check whether the current bytes are valid UTF-8 -// at the end of the function, previous gets updated -static inline struct processed_utf_bytes -checkUTF8Bytes(int8x16_t current_bytes, struct processed_utf_bytes *previous, - int8x16_t *has_error) { - struct processed_utf_bytes pb; - count_nibbles(current_bytes, &pb); - - checkSmallerThan0xF4(current_bytes, has_error); - - int8x16_t initial_lengths = continuationLengths(pb.high_nibbles); - - pb.carried_continuations = - carryContinuations(initial_lengths, previous->carried_continuations); - - checkContinuations(initial_lengths, pb.carried_continuations, has_error); - - int8x16_t off1_current_bytes = - vextq_s8(previous->rawbytes, pb.rawbytes, 16 - 1); - checkFirstContinuationMax(current_bytes, off1_current_bytes, has_error); - - checkOverlong(current_bytes, off1_current_bytes, pb.high_nibbles, - previous->high_nibbles, has_error); - return pb; -} - -static const int8_t _verror[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1}; - -/* Return 0 on success, -1 on error */ -int utf8_lemire(const unsigned char *src, int len) { - size_t i = 0; - int8x16_t has_error = vdupq_n_s8(0); - struct processed_utf_bytes previous = {.rawbytes = vdupq_n_s8(0), - .high_nibbles = vdupq_n_s8(0), - .carried_continuations = - vdupq_n_s8(0)}; - if (len >= 16) { - for (; i <= len - 16; i += 16) { - int8x16_t current_bytes = vld1q_s8((int8_t*)(src + i)); - previous = checkUTF8Bytes(current_bytes, &previous, &has_error); - } - } - - // last part - if (i < len) { - char buffer[16]; - memset(buffer, 0, 16); - memcpy(buffer, src + i, len - i); - int8x16_t current_bytes = vld1q_s8((int8_t *)buffer); - previous = checkUTF8Bytes(current_bytes, &previous, &has_error); - } else { - has_error = - vorrq_s8(vreinterpretq_s8_u8(vcgtq_s8(previous.carried_continuations, - vld1q_s8(_verror))), - has_error); - } - - return vmaxvq_u8(vreinterpretq_u8_s8(has_error)) == 0 ? 0 : -1; -} - -#endif diff --git a/vendor/utf8_range/lemire-sse.c b/vendor/utf8_range/lemire-sse.c deleted file mode 100644 index 72a9ebe..0000000 --- a/vendor/utf8_range/lemire-sse.c +++ /dev/null @@ -1,206 +0,0 @@ -// Adapted from https://github.com/lemire/fastvalidate-utf-8 - -#ifdef __x86_64__ - -#include -#include -#include -#include -#include - -/* - * legal utf-8 byte sequence - * http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf - page 94 - * - * Code Points 1st 2s 3s 4s - * U+0000..U+007F 00..7F - * U+0080..U+07FF C2..DF 80..BF - * U+0800..U+0FFF E0 A0..BF 80..BF - * U+1000..U+CFFF E1..EC 80..BF 80..BF - * U+D000..U+D7FF ED 80..9F 80..BF - * U+E000..U+FFFF EE..EF 80..BF 80..BF - * U+10000..U+3FFFF F0 90..BF 80..BF 80..BF - * U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF - * U+100000..U+10FFFF F4 80..8F 80..BF 80..BF - * - */ - -#if 0 -static void print128(const char *s, const __m128i *v128) -{ - const unsigned char *v8 = (const unsigned char *)v128; - if (s) - printf("%s: ", s); - for (int i = 0; i < 16; i++) - printf("%02x ", v8[i]); - printf("\n"); -} -#endif - -// all byte values must be no larger than 0xF4 -static inline void checkSmallerThan0xF4(__m128i current_bytes, - __m128i *has_error) { - // unsigned, saturates to 0 below max - *has_error = _mm_or_si128(*has_error, - _mm_subs_epu8(current_bytes, _mm_set1_epi8(0xF4))); -} - -static inline __m128i continuationLengths(__m128i high_nibbles) { - return _mm_shuffle_epi8( - _mm_setr_epi8(1, 1, 1, 1, 1, 1, 1, 1, // 0xxx (ASCII) - 0, 0, 0, 0, // 10xx (continuation) - 2, 2, // 110x - 3, // 1110 - 4), // 1111, next should be 0 (not checked here) - high_nibbles); -} - -static inline __m128i carryContinuations(__m128i initial_lengths, - __m128i previous_carries) { - - __m128i right1 = - _mm_subs_epu8(_mm_alignr_epi8(initial_lengths, previous_carries, 16 - 1), - _mm_set1_epi8(1)); - __m128i sum = _mm_add_epi8(initial_lengths, right1); - - __m128i right2 = _mm_subs_epu8(_mm_alignr_epi8(sum, previous_carries, 16 - 2), - _mm_set1_epi8(2)); - return _mm_add_epi8(sum, right2); -} - -static inline void checkContinuations(__m128i initial_lengths, __m128i carries, - __m128i *has_error) { - - // overlap || underlap - // carry > length && length > 0 || !(carry > length) && !(length > 0) - // (carries > length) == (lengths > 0) - __m128i overunder = - _mm_cmpeq_epi8(_mm_cmpgt_epi8(carries, initial_lengths), - _mm_cmpgt_epi8(initial_lengths, _mm_setzero_si128())); - - *has_error = _mm_or_si128(*has_error, overunder); -} - -// when 0xED is found, next byte must be no larger than 0x9F -// when 0xF4 is found, next byte must be no larger than 0x8F -// next byte must be continuation, ie sign bit is set, so signed < is ok -static inline void checkFirstContinuationMax(__m128i current_bytes, - __m128i off1_current_bytes, - __m128i *has_error) { - __m128i maskED = _mm_cmpeq_epi8(off1_current_bytes, _mm_set1_epi8(0xED)); - __m128i maskF4 = _mm_cmpeq_epi8(off1_current_bytes, _mm_set1_epi8(0xF4)); - - __m128i badfollowED = - _mm_and_si128(_mm_cmpgt_epi8(current_bytes, _mm_set1_epi8(0x9F)), maskED); - __m128i badfollowF4 = - _mm_and_si128(_mm_cmpgt_epi8(current_bytes, _mm_set1_epi8(0x8F)), maskF4); - - *has_error = _mm_or_si128(*has_error, _mm_or_si128(badfollowED, badfollowF4)); -} - -// map off1_hibits => error condition -// hibits off1 cur -// C => < C2 && true -// E => < E1 && < A0 -// F => < F1 && < 90 -// else false && false -static inline void checkOverlong(__m128i current_bytes, - __m128i off1_current_bytes, __m128i hibits, - __m128i previous_hibits, __m128i *has_error) { - __m128i off1_hibits = _mm_alignr_epi8(hibits, previous_hibits, 16 - 1); - __m128i initial_mins = _mm_shuffle_epi8( - _mm_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, // 10xx => false - 0xC2, -128, // 110x - 0xE1, // 1110 - 0xF1), - off1_hibits); - - __m128i initial_under = _mm_cmpgt_epi8(initial_mins, off1_current_bytes); - - __m128i second_mins = _mm_shuffle_epi8( - _mm_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, - -128, -128, // 10xx => false - 127, 127, // 110x => true - 0xA0, // 1110 - 0x90), - off1_hibits); - __m128i second_under = _mm_cmpgt_epi8(second_mins, current_bytes); - *has_error = - _mm_or_si128(*has_error, _mm_and_si128(initial_under, second_under)); -} - -struct processed_utf_bytes { - __m128i rawbytes; - __m128i high_nibbles; - __m128i carried_continuations; -}; - -static inline void count_nibbles(__m128i bytes, - struct processed_utf_bytes *answer) { - answer->rawbytes = bytes; - answer->high_nibbles = - _mm_and_si128(_mm_srli_epi16(bytes, 4), _mm_set1_epi8(0x0F)); -} - -// check whether the current bytes are valid UTF-8 -// at the end of the function, previous gets updated -static inline struct processed_utf_bytes -checkUTF8Bytes(__m128i current_bytes, struct processed_utf_bytes *previous, - __m128i *has_error) { - - struct processed_utf_bytes pb; - count_nibbles(current_bytes, &pb); - - checkSmallerThan0xF4(current_bytes, has_error); - - __m128i initial_lengths = continuationLengths(pb.high_nibbles); - - pb.carried_continuations = - carryContinuations(initial_lengths, previous->carried_continuations); - - checkContinuations(initial_lengths, pb.carried_continuations, has_error); - - __m128i off1_current_bytes = - _mm_alignr_epi8(pb.rawbytes, previous->rawbytes, 16 - 1); - checkFirstContinuationMax(current_bytes, off1_current_bytes, has_error); - - checkOverlong(current_bytes, off1_current_bytes, pb.high_nibbles, - previous->high_nibbles, has_error); - return pb; -} - -/* Return 0 on success, -1 on error */ -int utf8_lemire(const unsigned char *src, int len) { - size_t i = 0; - __m128i has_error = _mm_setzero_si128(); - struct processed_utf_bytes previous = {.rawbytes = _mm_setzero_si128(), - .high_nibbles = _mm_setzero_si128(), - .carried_continuations = - _mm_setzero_si128()}; - if (len >= 16) { - for (; i <= len - 16; i += 16) { - __m128i current_bytes = _mm_loadu_si128((const __m128i *)(src + i)); - previous = checkUTF8Bytes(current_bytes, &previous, &has_error); - } - } - - // last part - if (i < len) { - char buffer[16]; - memset(buffer, 0, 16); - memcpy(buffer, src + i, len - i); - __m128i current_bytes = _mm_loadu_si128((const __m128i *)(buffer)); - previous = checkUTF8Bytes(current_bytes, &previous, &has_error); - } else { - has_error = - _mm_or_si128(_mm_cmpgt_epi8(previous.carried_continuations, - _mm_setr_epi8(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 1)), - has_error); - } - - return _mm_testz_si128(has_error, has_error) ? 0 : -1; -} - -#endif diff --git a/vendor/utf8_range/lookup.c b/vendor/utf8_range/lookup.c deleted file mode 100644 index 2eb8925..0000000 --- a/vendor/utf8_range/lookup.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -/* http://bjoern.hoehrmann.de/utf-8/decoder/dfa */ -/* Optimized version based on Rich Felker's variant. */ -#define UTF8_ACCEPT 0 -#define UTF8_REJECT 12 - -static const unsigned char utf8d[] = { - /* The first part of the table maps bytes to character classes that - * to reduce the size of the transition table and create bitmasks. */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8 -}; -/* Note: Splitting the table improves performance on ARM due to its simpler - * addressing modes not being able to encode x[y + 256]. */ -static const unsigned char utf8s[] = { - /* The second part is a transition table that maps a combination - * of a state of the automaton and a character class to a state. */ - 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12, - 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12, - 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12, - 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12, - 12,36,12,12,12,12,12,12,12,12,12,12 -}; - -/* Return 0 on success, -1 on error */ -int utf8_lookup(const unsigned char *data, int len) -{ - int state = 0; - - while (len-- && state != UTF8_REJECT) - state = utf8s[state + utf8d[*data++]]; - - return state == UTF8_ACCEPT ? 0 : -1; -} diff --git a/vendor/utf8_range/main.c b/vendor/utf8_range/main.c deleted file mode 100644 index b0ca3e1..0000000 --- a/vendor/utf8_range/main.c +++ /dev/null @@ -1,405 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int utf8_naive(const unsigned char *data, int len); -int utf8_lookup(const unsigned char *data, int len); -int utf8_boost(const unsigned char *data, int len); -int utf8_lemire(const unsigned char *data, int len); -int utf8_range(const unsigned char *data, int len); -int utf8_range2(const unsigned char *data, int len); -#ifdef __AVX2__ -int utf8_lemire_avx2(const unsigned char *data, int len); -int utf8_range_avx2(const unsigned char *data, int len); -#endif - -static struct ftab { - const char *name; - int (*func)(const unsigned char *data, int len); -} ftab[] = { - { - .name = "naive", - .func = utf8_naive, - }, - { - .name = "lookup", - .func = utf8_lookup, - }, - { - .name = "lemire", - .func = utf8_lemire, - }, - { - .name = "range", - .func = utf8_range, - }, - { - .name = "range2", - .func = utf8_range2, - }, -#ifdef __AVX2__ - { - .name = "lemire_avx2", - .func = utf8_lemire_avx2, - }, - { - .name = "range_avx2", - .func = utf8_range_avx2, - }, -#endif -#ifdef BOOST - { - .name = "boost", - .func = utf8_boost, - }, -#endif -}; - -static unsigned char *load_test_buf(int len) -{ - const char utf8[] = "\xF0\x90\xBF\x80"; - const int utf8_len = sizeof(utf8)/sizeof(utf8[0]) - 1; - - unsigned char *data = malloc(len); - unsigned char *p = data; - - while (len >= utf8_len) { - memcpy(p, utf8, utf8_len); - p += utf8_len; - len -= utf8_len; - } - - while (len--) - *p++ = 0x7F; - - return data; -} - -static unsigned char *load_test_file(int *len) -{ - unsigned char *data; - int fd; - struct stat stat; - - fd = open("./UTF-8-demo.txt", O_RDONLY); - if (fd == -1) { - printf("Failed to open UTF-8-demo.txt!\n"); - exit(1); - } - if (fstat(fd, &stat) == -1) { - printf("Failed to get file size!\n"); - exit(1); - } - - *len = stat.st_size; - data = malloc(*len); - if (read(fd, data, *len) != *len) { - printf("Failed to read file!\n"); - exit(1); - } - - utf8_range(data, *len); -#ifdef __AVX2__ - utf8_range_avx2(data, *len); -#endif - close(fd); - - return data; -} - -static void print_test(const unsigned char *data, int len) -{ - while (len--) - printf("\\x%02X", *data++); - - printf("\n"); -} - -struct test { - const unsigned char *data; - int len; -}; - -static void prepare_test_buf(unsigned char *buf, const struct test *pos, - int pos_len, int pos_idx) -{ - /* Round concatenate correct tokens to 1024 bytes */ - int buf_idx = 0; - while (buf_idx < 1024) { - int buf_len = 1024 - buf_idx; - - if (buf_len >= pos[pos_idx].len) { - memcpy(buf+buf_idx, pos[pos_idx].data, pos[pos_idx].len); - buf_idx += pos[pos_idx].len; - } else { - memset(buf+buf_idx, 0, buf_len); - buf_idx += buf_len; - } - - if (++pos_idx == pos_len) - pos_idx = 0; - } -} - -/* Return 0 on success, -1 on error */ -static int test_manual(const struct ftab *ftab) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpointer-sign" - /* positive tests */ - static const struct test pos[] = { - {"", 0}, - {"\x00", 1}, - {"\x66", 1}, - {"\x7F", 1}, - {"\x00\x7F", 2}, - {"\x7F\x00", 2}, - {"\xC2\x80", 2}, - {"\xDF\xBF", 2}, - {"\xE0\xA0\x80", 3}, - {"\xE0\xA0\xBF", 3}, - {"\xED\x9F\x80", 3}, - {"\xEF\x80\xBF", 3}, - {"\xF0\x90\xBF\x80", 4}, - {"\xF2\x81\xBE\x99", 4}, - {"\xF4\x8F\x88\xAA", 4}, - }; - - /* negative tests */ - static const struct test neg[] = { - {"\x80", 1}, - {"\xBF", 1}, - {"\xC0\x80", 2}, - {"\xC1\x00", 2}, - {"\xC2\x7F", 2}, - {"\xDF\xC0", 2}, - {"\xE0\x9F\x80", 3}, - {"\xE0\xC2\x80", 3}, - {"\xED\xA0\x80", 3}, - {"\xED\x7F\x80", 3}, - {"\xEF\x80\x00", 3}, - {"\xF0\x8F\x80\x80", 4}, - {"\xF0\xEE\x80\x80", 4}, - {"\xF2\x90\x91\x7F", 4}, - {"\xF4\x90\x88\xAA", 4}, - {"\xF4\x00\xBF\xBF", 4}, - {"\x00\x00\x00\x00\x00\xC2\x80\x00\x00\x00\xE1\x80\x80\x00\x00\xC2" \ - "\xC2\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - 32}, - {"\x00\x00\x00\x00\x00\xC2\xC2\x80\x00\x00\xE1\x80\x80\x00\x00\x00", - 16}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1\x80", - 32}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1", - 32}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1\x80" \ - "\x80", 33}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1\x80" \ - "\xC2\x80", 34}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0" \ - "\x80\x80\x80", 35}, - }; -#pragma GCC diagnostic push - - /* Test single token */ - for (int i = 0; i < sizeof(pos)/sizeof(pos[0]); ++i) { - if (ftab->func(pos[i].data, pos[i].len) != 0) { - printf("FAILED positive test: "); - print_test(pos[i].data, pos[i].len); - return -1; - } - } - for (int i = 0; i < sizeof(neg)/sizeof(neg[0]); ++i) { - if (ftab->func(neg[i].data, neg[i].len) == 0) { - printf("FAILED negative test: "); - print_test(neg[i].data, neg[i].len); - return -1; - } - } - - /* Test shifted buffer to cover 1k length */ - /* buffer size must be greater than 1024 + 16 + max(test string length) */ - const int max_size = 1024*2; - uint64_t buf64[max_size/8 + 2]; - /* Offset 8 bytes by 1 byte */ - unsigned char *buf = ((unsigned char *)buf64) + 1; - int buf_len; - - for (int i = 0; i < sizeof(pos)/sizeof(pos[0]); ++i) { - /* Positive test: shift 16 bytes, validate each shift */ - prepare_test_buf(buf, pos, sizeof(pos)/sizeof(pos[0]), i); - buf_len = 1024; - for (int j = 0; j < 16; ++j) { - if (ftab->func(buf, buf_len) != 0) { - printf("FAILED positive test: "); - print_test(buf, buf_len); - return -1; - } - for (int k = buf_len; k >= 1; --k) - buf[k] = buf[k-1]; - buf[0] = '\x55'; - ++buf_len; - } - - /* Negative test: trunk last non ascii */ - while (buf_len >= 1 && buf[buf_len-1] <= 0x7F) - --buf_len; - if (buf_len && ftab->func(buf, buf_len-1) == 0) { - printf("FAILED negative test: "); - print_test(buf, buf_len); - return -1; - } - } - - /* Negative test */ - for (int i = 0; i < sizeof(neg)/sizeof(neg[0]); ++i) { - /* Append one error token, shift 16 bytes, validate each shift */ - int pos_idx = i % (sizeof(pos)/sizeof(pos[0])); - prepare_test_buf(buf, pos, sizeof(pos)/sizeof(pos[0]), pos_idx); - memcpy(buf+1024, neg[i].data, neg[i].len); - buf_len = 1024 + neg[i].len; - for (int j = 0; j < 16; ++j) { - if (ftab->func(buf, buf_len) == 0) { - printf("FAILED negative test: "); - print_test(buf, buf_len); - return -1; - } - for (int k = buf_len; k >= 1; --k) - buf[k] = buf[k-1]; - buf[0] = '\x66'; - ++buf_len; - } - } - - return 0; -} - -static int test(const unsigned char *data, int len, const struct ftab *ftab) -{ - int ret_standard = ftab->func(data, len); - int ret_manual = test_manual(ftab); - printf("%s\n", ftab->name); - printf("standard test: %s\n", ret_standard ? "FAIL" : "pass"); - printf("manual test: %s\n", ret_manual ? "FAIL" : "pass"); - - return ret_standard | ret_manual; -} - -static int bench(const unsigned char *data, int len, const struct ftab *ftab) -{ - const int loops = 1024*1024*1024/len; - int ret = 0; - double time, size; - struct timeval tv1, tv2; - - fprintf(stderr, "bench %s... ", ftab->name); - gettimeofday(&tv1, 0); - for (int i = 0; i < loops; ++i) - ret |= ftab->func(data, len); - gettimeofday(&tv2, 0); - printf("%s\n", ret?"FAIL":"pass"); - - time = tv2.tv_usec - tv1.tv_usec; - time = time / 1000000 + tv2.tv_sec - tv1.tv_sec; - size = ((double)len * loops) / (1024*1024); - printf("time: %.4f s\n", time); - printf("data: %.0f MB\n", size); - printf("BW: %.2f MB/s\n", size / time); - - return 0; -} - -static void usage(const char *bin) -{ - printf("Usage:\n"); - printf("%s test [alg] ==> test all or one algorithm\n", bin); - printf("%s bench [alg] ==> benchmark all or one algorithm\n", bin); - printf("%s bench size NUM ==> benchmark with specific buffer size\n", bin); - printf("alg = "); - for (int i = 0; i < sizeof(ftab)/sizeof(ftab[0]); ++i) - printf("%s ", ftab[i].name); - printf("\nNUM = buffer size in bytes, 1 ~ 67108864(64M)\n"); -} - -int main(int argc, char *argv[]) -{ - int len = 0; - unsigned char *data; - const char *alg = NULL; - int (*tb)(const unsigned char *data, int len, const struct ftab *ftab); - - tb = NULL; - if (argc >= 2) { - if (strcmp(argv[1], "test") == 0) - tb = test; - else if (strcmp(argv[1], "bench") == 0) - tb = bench; - if (argc >= 3) { - alg = argv[2]; - if (strcmp(alg, "size") == 0) { - if (argc < 4) { - tb = NULL; - } else { - alg = NULL; - len = atoi(argv[3]); - if (len <= 0 || len > 67108864) { - printf("Buffer size error!\n\n"); - tb = NULL; - } - } - } - } - } - - if (tb == NULL) { - usage(argv[0]); - return 1; - } - - /* Load UTF8 test buffer */ - if (len) - data = load_test_buf(len); - else - data = load_test_file(&len); - - int ret = 0; - if (tb == bench) - printf("=============== Bench UTF8 (%d bytes) ===============\n", len); - for (int i = 0; i < sizeof(ftab)/sizeof(ftab[0]); ++i) { - if (alg && strcmp(alg, ftab[i].name) != 0) - continue; - ret |= tb((const unsigned char *)data, len, &ftab[i]); - printf("\n"); - } - -#if 0 - if (tb == bench) { - printf("==================== Bench ASCII ====================\n"); - /* Change test buffer to ascii */ - for (int i = 0; i < len; i++) - data[i] &= 0x7F; - - for (int i = 0; i < sizeof(ftab)/sizeof(ftab[0]); ++i) { - if (alg && strcmp(alg, ftab[i].name) != 0) - continue; - tb((const unsigned char *)data, len, &ftab[i]); - printf("\n"); - } - } -#endif - - free(data); - - return ret; -} diff --git a/vendor/utf8_range/naive.c b/vendor/utf8_range/naive.c deleted file mode 100644 index 9b7e5bb..0000000 --- a/vendor/utf8_range/naive.c +++ /dev/null @@ -1,92 +0,0 @@ -#include - -/* - * http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf - page 94 - * - * Table 3-7. Well-Formed UTF-8 Byte Sequences - * - * +--------------------+------------+-------------+------------+-------------+ - * | Code Points | First Byte | Second Byte | Third Byte | Fourth Byte | - * +--------------------+------------+-------------+------------+-------------+ - * | U+0000..U+007F | 00..7F | | | | - * +--------------------+------------+-------------+------------+-------------+ - * | U+0080..U+07FF | C2..DF | 80..BF | | | - * +--------------------+------------+-------------+------------+-------------+ - * | U+0800..U+0FFF | E0 | A0..BF | 80..BF | | - * +--------------------+------------+-------------+------------+-------------+ - * | U+1000..U+CFFF | E1..EC | 80..BF | 80..BF | | - * +--------------------+------------+-------------+------------+-------------+ - * | U+D000..U+D7FF | ED | 80..9F | 80..BF | | - * +--------------------+------------+-------------+------------+-------------+ - * | U+E000..U+FFFF | EE..EF | 80..BF | 80..BF | | - * +--------------------+------------+-------------+------------+-------------+ - * | U+10000..U+3FFFF | F0 | 90..BF | 80..BF | 80..BF | - * +--------------------+------------+-------------+------------+-------------+ - * | U+40000..U+FFFFF | F1..F3 | 80..BF | 80..BF | 80..BF | - * +--------------------+------------+-------------+------------+-------------+ - * | U+100000..U+10FFFF | F4 | 80..8F | 80..BF | 80..BF | - * +--------------------+------------+-------------+------------+-------------+ - */ - -/* Return 0 - success, >0 - index(1 based) of first error char */ -int utf8_naive(const unsigned char *data, int len) -{ - int err_pos = 1; - - while (len) { - int bytes; - const unsigned char byte1 = data[0]; - - /* 00..7F */ - if (byte1 <= 0x7F) { - bytes = 1; - /* C2..DF, 80..BF */ - } else if (len >= 2 && byte1 >= 0xC2 && byte1 <= 0xDF && - (signed char)data[1] <= (signed char)0xBF) { - bytes = 2; - } else if (len >= 3) { - const unsigned char byte2 = data[1]; - - /* Is byte2, byte3 between 0x80 ~ 0xBF */ - const int byte2_ok = (signed char)byte2 <= (signed char)0xBF; - const int byte3_ok = (signed char)data[2] <= (signed char)0xBF; - - if (byte2_ok && byte3_ok && - /* E0, A0..BF, 80..BF */ - ((byte1 == 0xE0 && byte2 >= 0xA0) || - /* E1..EC, 80..BF, 80..BF */ - (byte1 >= 0xE1 && byte1 <= 0xEC) || - /* ED, 80..9F, 80..BF */ - (byte1 == 0xED && byte2 <= 0x9F) || - /* EE..EF, 80..BF, 80..BF */ - (byte1 >= 0xEE && byte1 <= 0xEF))) { - bytes = 3; - } else if (len >= 4) { - /* Is byte4 between 0x80 ~ 0xBF */ - const int byte4_ok = (signed char)data[3] <= (signed char)0xBF; - - if (byte2_ok && byte3_ok && byte4_ok && - /* F0, 90..BF, 80..BF, 80..BF */ - ((byte1 == 0xF0 && byte2 >= 0x90) || - /* F1..F3, 80..BF, 80..BF, 80..BF */ - (byte1 >= 0xF1 && byte1 <= 0xF3) || - /* F4, 80..8F, 80..BF, 80..BF */ - (byte1 == 0xF4 && byte2 <= 0x8F))) { - bytes = 4; - } else { - return err_pos; - } - } else { - return err_pos; - } - } else { - return err_pos; - } - - len -= bytes; - err_pos += bytes; - data += bytes; - } - - return 0; -} diff --git a/vendor/utf8_range/range-avx2.c b/vendor/utf8_range/range-avx2.c deleted file mode 100644 index d892284..0000000 --- a/vendor/utf8_range/range-avx2.c +++ /dev/null @@ -1,277 +0,0 @@ -#ifdef __AVX2__ - -#include -#include -#include - -int utf8_naive(const unsigned char *data, int len); - -#if 0 -static void print256(const char *s, const __m256i v256) -{ - const unsigned char *v8 = (const unsigned char *)&v256; - if (s) - printf("%s:\t", s); - for (int i = 0; i < 32; i++) - printf("%02x ", v8[i]); - printf("\n"); -} -#endif - -/* - * Map high nibble of "First Byte" to legal character length minus 1 - * 0x00 ~ 0xBF --> 0 - * 0xC0 ~ 0xDF --> 1 - * 0xE0 ~ 0xEF --> 2 - * 0xF0 ~ 0xFF --> 3 - */ -static const int8_t _first_len_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, -}; - -/* Map "First Byte" to 8-th item of range table (0xC2 ~ 0xF4) */ -static const int8_t _first_range_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, -}; - -/* - * Range table, map range index to min and max values - * Index 0 : 00 ~ 7F (First Byte, ascii) - * Index 1,2,3: 80 ~ BF (Second, Third, Fourth Byte) - * Index 4 : A0 ~ BF (Second Byte after E0) - * Index 5 : 80 ~ 9F (Second Byte after ED) - * Index 6 : 90 ~ BF (Second Byte after F0) - * Index 7 : 80 ~ 8F (Second Byte after F4) - * Index 8 : C2 ~ F4 (First Byte, non ascii) - * Index 9~15 : illegal: i >= 127 && i <= -128 - */ -static const int8_t _range_min_tbl[] = { - 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, - 0xC2, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, - 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, - 0xC2, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, -}; -static const int8_t _range_max_tbl[] = { - 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, - 0xF4, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, - 0xF4, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -}; - -/* - * Tables for fast handling of four special First Bytes(E0,ED,F0,F4), after - * which the Second Byte are not 80~BF. It contains "range index adjustment". - * +------------+---------------+------------------+----------------+ - * | First Byte | original range| range adjustment | adjusted range | - * +------------+---------------+------------------+----------------+ - * | E0 | 2 | 2 | 4 | - * +------------+---------------+------------------+----------------+ - * | ED | 2 | 3 | 5 | - * +------------+---------------+------------------+----------------+ - * | F0 | 3 | 3 | 6 | - * +------------+---------------+------------------+----------------+ - * | F4 | 4 | 4 | 8 | - * +------------+---------------+------------------+----------------+ - */ -/* index1 -> E0, index14 -> ED */ -static const int8_t _df_ee_tbl[] = { - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -}; -/* index1 -> F0, index5 -> F4 */ -static const int8_t _ef_fe_tbl[] = { - 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -#define RET_ERR_IDX 0 /* Define 1 to return index of first error char */ - -static inline __m256i push_last_byte_of_a_to_b(__m256i a, __m256i b) { - return _mm256_alignr_epi8(b, _mm256_permute2x128_si256(a, b, 0x21), 15); -} - -static inline __m256i push_last_2bytes_of_a_to_b(__m256i a, __m256i b) { - return _mm256_alignr_epi8(b, _mm256_permute2x128_si256(a, b, 0x21), 14); -} - -static inline __m256i push_last_3bytes_of_a_to_b(__m256i a, __m256i b) { - return _mm256_alignr_epi8(b, _mm256_permute2x128_si256(a, b, 0x21), 13); -} - -/* 5x faster than naive method */ -/* Return 0 - success, -1 - error, >0 - first error char(if RET_ERR_IDX = 1) */ -int utf8_range_avx2(const unsigned char *data, int len) -{ -#if RET_ERR_IDX - int err_pos = 1; -#endif - - if (len >= 32) { - __m256i prev_input = _mm256_set1_epi8(0); - __m256i prev_first_len = _mm256_set1_epi8(0); - - /* Cached tables */ - const __m256i first_len_tbl = - _mm256_loadu_si256((const __m256i *)_first_len_tbl); - const __m256i first_range_tbl = - _mm256_loadu_si256((const __m256i *)_first_range_tbl); - const __m256i range_min_tbl = - _mm256_loadu_si256((const __m256i *)_range_min_tbl); - const __m256i range_max_tbl = - _mm256_loadu_si256((const __m256i *)_range_max_tbl); - const __m256i df_ee_tbl = - _mm256_loadu_si256((const __m256i *)_df_ee_tbl); - const __m256i ef_fe_tbl = - _mm256_loadu_si256((const __m256i *)_ef_fe_tbl); - -#if !RET_ERR_IDX - __m256i error1 = _mm256_set1_epi8(0); - __m256i error2 = _mm256_set1_epi8(0); -#endif - - while (len >= 32) { - const __m256i input = _mm256_loadu_si256((const __m256i *)data); - - /* high_nibbles = input >> 4 */ - const __m256i high_nibbles = - _mm256_and_si256(_mm256_srli_epi16(input, 4), _mm256_set1_epi8(0x0F)); - - /* first_len = legal character length minus 1 */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* first_len = first_len_tbl[high_nibbles] */ - __m256i first_len = _mm256_shuffle_epi8(first_len_tbl, high_nibbles); - - /* First Byte: set range index to 8 for bytes within 0xC0 ~ 0xFF */ - /* range = first_range_tbl[high_nibbles] */ - __m256i range = _mm256_shuffle_epi8(first_range_tbl, high_nibbles); - - /* Second Byte: set range index to first_len */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* range |= (first_len, prev_first_len) << 1 byte */ - range = _mm256_or_si256( - range, push_last_byte_of_a_to_b(prev_first_len, first_len)); - - /* Third Byte: set range index to saturate_sub(first_len, 1) */ - /* 0 for 00~7F, 0 for C0~DF, 1 for E0~EF, 2 for F0~FF */ - __m256i tmp1, tmp2; - - /* tmp1 = (first_len, prev_first_len) << 2 bytes */ - tmp1 = push_last_2bytes_of_a_to_b(prev_first_len, first_len); - /* tmp2 = saturate_sub(tmp1, 1) */ - tmp2 = _mm256_subs_epu8(tmp1, _mm256_set1_epi8(1)); - - /* range |= tmp2 */ - range = _mm256_or_si256(range, tmp2); - - /* Fourth Byte: set range index to saturate_sub(first_len, 2) */ - /* 0 for 00~7F, 0 for C0~DF, 0 for E0~EF, 1 for F0~FF */ - /* tmp1 = (first_len, prev_first_len) << 3 bytes */ - tmp1 = push_last_3bytes_of_a_to_b(prev_first_len, first_len); - /* tmp2 = saturate_sub(tmp1, 2) */ - tmp2 = _mm256_subs_epu8(tmp1, _mm256_set1_epi8(2)); - /* range |= tmp2 */ - range = _mm256_or_si256(range, tmp2); - - /* - * Now we have below range indices calculated - * Correct cases: - * - 8 for C0~FF - * - 3 for 1st byte after F0~FF - * - 2 for 1st byte after E0~EF or 2nd byte after F0~FF - * - 1 for 1st byte after C0~DF or 2nd byte after E0~EF or - * 3rd byte after F0~FF - * - 0 for others - * Error cases: - * 9,10,11 if non ascii First Byte overlaps - * E.g., F1 80 C2 90 --> 8 3 10 2, where 10 indicates error - */ - - /* Adjust Second Byte range for special First Bytes(E0,ED,F0,F4) */ - /* Overlaps lead to index 9~15, which are illegal in range table */ - __m256i shift1, pos, range2; - /* shift1 = (input, prev_input) << 1 byte */ - shift1 = push_last_byte_of_a_to_b(prev_input, input); - pos = _mm256_sub_epi8(shift1, _mm256_set1_epi8(0xEF)); - /* - * shift1: | EF F0 ... FE | FF 00 ... ... DE | DF E0 ... EE | - * pos: | 0 1 15 | 16 17 239| 240 241 255| - * pos-240: | 0 0 0 | 0 0 0 | 0 1 15 | - * pos+112: | 112 113 127| >= 128 | >= 128 | - */ - tmp1 = _mm256_subs_epu8(pos, _mm256_set1_epi8(240)); - range2 = _mm256_shuffle_epi8(df_ee_tbl, tmp1); - tmp2 = _mm256_adds_epu8(pos, _mm256_set1_epi8(112)); - range2 = _mm256_add_epi8(range2, _mm256_shuffle_epi8(ef_fe_tbl, tmp2)); - - range = _mm256_add_epi8(range, range2); - - /* Load min and max values per calculated range index */ - __m256i minv = _mm256_shuffle_epi8(range_min_tbl, range); - __m256i maxv = _mm256_shuffle_epi8(range_max_tbl, range); - - /* Check value range */ -#if RET_ERR_IDX - __m256i error = _mm256_cmpgt_epi8(minv, input); - error = _mm256_or_si256(error, _mm256_cmpgt_epi8(input, maxv)); - /* 5% performance drop from this conditional branch */ - if (!_mm256_testz_si256(error, error)) - break; -#else - error1 = _mm256_or_si256(error1, _mm256_cmpgt_epi8(minv, input)); - error2 = _mm256_or_si256(error2, _mm256_cmpgt_epi8(input, maxv)); -#endif - - prev_input = input; - prev_first_len = first_len; - - data += 32; - len -= 32; -#if RET_ERR_IDX - err_pos += 32; -#endif - } - -#if RET_ERR_IDX - /* Error in first 16 bytes */ - if (err_pos == 1) - goto do_naive; -#else - __m256i error = _mm256_or_si256(error1, error2); - if (!_mm256_testz_si256(error, error)) - return -1; -#endif - - /* Find previous token (not 80~BF) */ - int32_t token4 = _mm256_extract_epi32(prev_input, 7); - const int8_t *token = (const int8_t *)&token4; - int lookahead = 0; - if (token[3] > (int8_t)0xBF) - lookahead = 1; - else if (token[2] > (int8_t)0xBF) - lookahead = 2; - else if (token[1] > (int8_t)0xBF) - lookahead = 3; - - data -= lookahead; - len += lookahead; -#if RET_ERR_IDX - err_pos -= lookahead; -#endif - } - - /* Check remaining bytes with naive method */ -#if RET_ERR_IDX - int err_pos2; -do_naive: - err_pos2 = utf8_naive(data, len); - if (err_pos2) - return err_pos + err_pos2 - 1; - return 0; -#else - return utf8_naive(data, len); -#endif -} - -#endif diff --git a/vendor/utf8_range/range-neon.c b/vendor/utf8_range/range-neon.c deleted file mode 100644 index e8c533c..0000000 --- a/vendor/utf8_range/range-neon.c +++ /dev/null @@ -1,228 +0,0 @@ -#ifdef __aarch64__ - -#include -#include -#include - -int utf8_naive(const unsigned char *data, int len); - -#if 0 -static void print128(const char *s, const uint8x16_t v128) -{ - unsigned char v8[16]; - vst1q_u8(v8, v128); - - if (s) - printf("%s:\t", s); - for (int i = 0; i < 16; ++i) - printf("%02x ", v8[i]); - printf("\n"); -} -#endif - -/* - * Map high nibble of "First Byte" to legal character length minus 1 - * 0x00 ~ 0xBF --> 0 - * 0xC0 ~ 0xDF --> 1 - * 0xE0 ~ 0xEF --> 2 - * 0xF0 ~ 0xFF --> 3 - */ -static const uint8_t _first_len_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, -}; - -/* Map "First Byte" to 8-th item of range table (0xC2 ~ 0xF4) */ -static const uint8_t _first_range_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, -}; - -/* - * Range table, map range index to min and max values - * Index 0 : 00 ~ 7F (First Byte, ascii) - * Index 1,2,3: 80 ~ BF (Second, Third, Fourth Byte) - * Index 4 : A0 ~ BF (Second Byte after E0) - * Index 5 : 80 ~ 9F (Second Byte after ED) - * Index 6 : 90 ~ BF (Second Byte after F0) - * Index 7 : 80 ~ 8F (Second Byte after F4) - * Index 8 : C2 ~ F4 (First Byte, non ascii) - * Index 9~15 : illegal: u >= 255 && u <= 0 - */ -static const uint8_t _range_min_tbl[] = { - 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, - 0xC2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -}; -static const uint8_t _range_max_tbl[] = { - 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, - 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -/* - * This table is for fast handling four special First Bytes(E0,ED,F0,F4), after - * which the Second Byte are not 80~BF. It contains "range index adjustment". - * - The idea is to minus byte with E0, use the result(0~31) as the index to - * lookup the "range index adjustment". Then add the adjustment to original - * range index to get the correct range. - * - Range index adjustment - * +------------+---------------+------------------+----------------+ - * | First Byte | original range| range adjustment | adjusted range | - * +------------+---------------+------------------+----------------+ - * | E0 | 2 | 2 | 4 | - * +------------+---------------+------------------+----------------+ - * | ED | 2 | 3 | 5 | - * +------------+---------------+------------------+----------------+ - * | F0 | 3 | 3 | 6 | - * +------------+---------------+------------------+----------------+ - * | F4 | 4 | 4 | 8 | - * +------------+---------------+------------------+----------------+ - * - Below is a uint8x16x2 table, data is interleaved in NEON register. So I'm - * putting it vertically. 1st column is for E0~EF, 2nd column for F0~FF. - */ -static const uint8_t _range_adjust_tbl[] = { - /* index -> 0~15 16~31 <- index */ - /* E0 -> */ 2, 3, /* <- F0 */ - 0, 0, - 0, 0, - 0, 0, - 0, 4, /* <- F4 */ - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - /* ED -> */ 3, 0, - 0, 0, - 0, 0, -}; - -/* 2x ~ 4x faster than naive method */ -/* Return 0 on success, -1 on error */ -int utf8_range(const unsigned char *data, int len) -{ - if (len >= 16) { - uint8x16_t prev_input = vdupq_n_u8(0); - uint8x16_t prev_first_len = vdupq_n_u8(0); - - /* Cached tables */ - const uint8x16_t first_len_tbl = vld1q_u8(_first_len_tbl); - const uint8x16_t first_range_tbl = vld1q_u8(_first_range_tbl); - const uint8x16_t range_min_tbl = vld1q_u8(_range_min_tbl); - const uint8x16_t range_max_tbl = vld1q_u8(_range_max_tbl); - const uint8x16x2_t range_adjust_tbl = vld2q_u8(_range_adjust_tbl); - - /* Cached values */ - const uint8x16_t const_1 = vdupq_n_u8(1); - const uint8x16_t const_2 = vdupq_n_u8(2); - const uint8x16_t const_e0 = vdupq_n_u8(0xE0); - - /* We use two error registers to remove a dependency. */ - uint8x16_t error1 = vdupq_n_u8(0); - uint8x16_t error2 = vdupq_n_u8(0); - - while (len >= 16) { - const uint8x16_t input = vld1q_u8(data); - - /* high_nibbles = input >> 4 */ - const uint8x16_t high_nibbles = vshrq_n_u8(input, 4); - - /* first_len = legal character length minus 1 */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* first_len = first_len_tbl[high_nibbles] */ - const uint8x16_t first_len = - vqtbl1q_u8(first_len_tbl, high_nibbles); - - /* First Byte: set range index to 8 for bytes within 0xC0 ~ 0xFF */ - /* range = first_range_tbl[high_nibbles] */ - uint8x16_t range = vqtbl1q_u8(first_range_tbl, high_nibbles); - - /* Second Byte: set range index to first_len */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* range |= (first_len, prev_first_len) << 1 byte */ - range = - vorrq_u8(range, vextq_u8(prev_first_len, first_len, 15)); - - /* Third Byte: set range index to saturate_sub(first_len, 1) */ - /* 0 for 00~7F, 0 for C0~DF, 1 for E0~EF, 2 for F0~FF */ - uint8x16_t tmp1, tmp2; - /* tmp1 = (first_len, prev_first_len) << 2 bytes */ - tmp1 = vextq_u8(prev_first_len, first_len, 14); - /* tmp1 = saturate_sub(tmp1, 1) */ - tmp1 = vqsubq_u8(tmp1, const_1); - /* range |= tmp1 */ - range = vorrq_u8(range, tmp1); - - /* Fourth Byte: set range index to saturate_sub(first_len, 2) */ - /* 0 for 00~7F, 0 for C0~DF, 0 for E0~EF, 1 for F0~FF */ - /* tmp2 = (first_len, prev_first_len) << 3 bytes */ - tmp2 = vextq_u8(prev_first_len, first_len, 13); - /* tmp2 = saturate_sub(tmp2, 2) */ - tmp2 = vqsubq_u8(tmp2, const_2); - /* range |= tmp2 */ - range = vorrq_u8(range, tmp2); - - /* - * Now we have below range indices calculated - * Correct cases: - * - 8 for C0~FF - * - 3 for 1st byte after F0~FF - * - 2 for 1st byte after E0~EF or 2nd byte after F0~FF - * - 1 for 1st byte after C0~DF or 2nd byte after E0~EF or - * 3rd byte after F0~FF - * - 0 for others - * Error cases: - * 9,10,11 if non ascii First Byte overlaps - * E.g., F1 80 C2 90 --> 8 3 10 2, where 10 indicates error - */ - - /* Adjust Second Byte range for special First Bytes(E0,ED,F0,F4) */ - /* See _range_adjust_tbl[] definition for details */ - /* Overlaps lead to index 9~15, which are illegal in range table */ - uint8x16_t shift1 = vextq_u8(prev_input, input, 15); - uint8x16_t pos = vsubq_u8(shift1, const_e0); - range = vaddq_u8(range, vqtbl2q_u8(range_adjust_tbl, pos)); - - /* Load min and max values per calculated range index */ - uint8x16_t minv = vqtbl1q_u8(range_min_tbl, range); - uint8x16_t maxv = vqtbl1q_u8(range_max_tbl, range); - - /* Check value range */ - error1 = vorrq_u8(error1, vcltq_u8(input, minv)); - error2 = vorrq_u8(error2, vcgtq_u8(input, maxv)); - - prev_input = input; - prev_first_len = first_len; - - data += 16; - len -= 16; - } - /* Merge our error counters together */ - error1 = vorrq_u8(error1, error2); - - /* Delay error check till loop ends */ - if (vmaxvq_u8(error1)) - return -1; - - /* Find previous token (not 80~BF) */ - uint32_t token4; - vst1q_lane_u32(&token4, vreinterpretq_u32_u8(prev_input), 3); - - const int8_t *token = (const int8_t *)&token4; - int lookahead = 0; - if (token[3] > (int8_t)0xBF) - lookahead = 1; - else if (token[2] > (int8_t)0xBF) - lookahead = 2; - else if (token[1] > (int8_t)0xBF) - lookahead = 3; - - data -= lookahead; - len += lookahead; - } - - /* Check remaining bytes with naive method */ - return utf8_naive(data, len); -} - -#endif diff --git a/vendor/utf8_range/range-sse.c b/vendor/utf8_range/range-sse.c deleted file mode 100644 index 41d1559..0000000 --- a/vendor/utf8_range/range-sse.c +++ /dev/null @@ -1,255 +0,0 @@ -#ifdef __x86_64__ - -#include -#include -#include - -int utf8_naive(const unsigned char *data, int len); - -#if 0 -static void print128(const char *s, const __m128i v128) -{ - const unsigned char *v8 = (const unsigned char *)&v128; - if (s) - printf("%s:\t", s); - for (int i = 0; i < 16; i++) - printf("%02x ", v8[i]); - printf("\n"); -} -#endif - -/* - * Map high nibble of "First Byte" to legal character length minus 1 - * 0x00 ~ 0xBF --> 0 - * 0xC0 ~ 0xDF --> 1 - * 0xE0 ~ 0xEF --> 2 - * 0xF0 ~ 0xFF --> 3 - */ -static const int8_t _first_len_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, -}; - -/* Map "First Byte" to 8-th item of range table (0xC2 ~ 0xF4) */ -static const int8_t _first_range_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, -}; - -/* - * Range table, map range index to min and max values - * Index 0 : 00 ~ 7F (First Byte, ascii) - * Index 1,2,3: 80 ~ BF (Second, Third, Fourth Byte) - * Index 4 : A0 ~ BF (Second Byte after E0) - * Index 5 : 80 ~ 9F (Second Byte after ED) - * Index 6 : 90 ~ BF (Second Byte after F0) - * Index 7 : 80 ~ 8F (Second Byte after F4) - * Index 8 : C2 ~ F4 (First Byte, non ascii) - * Index 9~15 : illegal: i >= 127 && i <= -128 - */ -static const int8_t _range_min_tbl[] = { - 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, - 0xC2, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, -}; -static const int8_t _range_max_tbl[] = { - 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, - 0xF4, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -}; - -/* - * Tables for fast handling of four special First Bytes(E0,ED,F0,F4), after - * which the Second Byte are not 80~BF. It contains "range index adjustment". - * +------------+---------------+------------------+----------------+ - * | First Byte | original range| range adjustment | adjusted range | - * +------------+---------------+------------------+----------------+ - * | E0 | 2 | 2 | 4 | - * +------------+---------------+------------------+----------------+ - * | ED | 2 | 3 | 5 | - * +------------+---------------+------------------+----------------+ - * | F0 | 3 | 3 | 6 | - * +------------+---------------+------------------+----------------+ - * | F4 | 4 | 4 | 8 | - * +------------+---------------+------------------+----------------+ - */ -/* index1 -> E0, index14 -> ED */ -static const int8_t _df_ee_tbl[] = { - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -}; -/* index1 -> F0, index5 -> F4 */ -static const int8_t _ef_fe_tbl[] = { - 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -#define RET_ERR_IDX 0 /* Define 1 to return index of first error char */ - -/* 5x faster than naive method */ -/* Return 0 - success, -1 - error, >0 - first error char(if RET_ERR_IDX = 1) */ -int utf8_range(const unsigned char *data, int len) -{ -#if RET_ERR_IDX - int err_pos = 1; -#endif - - if (len >= 16) { - __m128i prev_input = _mm_set1_epi8(0); - __m128i prev_first_len = _mm_set1_epi8(0); - - /* Cached tables */ - const __m128i first_len_tbl = - _mm_loadu_si128((const __m128i *)_first_len_tbl); - const __m128i first_range_tbl = - _mm_loadu_si128((const __m128i *)_first_range_tbl); - const __m128i range_min_tbl = - _mm_loadu_si128((const __m128i *)_range_min_tbl); - const __m128i range_max_tbl = - _mm_loadu_si128((const __m128i *)_range_max_tbl); - const __m128i df_ee_tbl = - _mm_loadu_si128((const __m128i *)_df_ee_tbl); - const __m128i ef_fe_tbl = - _mm_loadu_si128((const __m128i *)_ef_fe_tbl); - - __m128i error = _mm_set1_epi8(0); - - while (len >= 16) { - const __m128i input = _mm_loadu_si128((const __m128i *)data); - - /* high_nibbles = input >> 4 */ - const __m128i high_nibbles = - _mm_and_si128(_mm_srli_epi16(input, 4), _mm_set1_epi8(0x0F)); - - /* first_len = legal character length minus 1 */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* first_len = first_len_tbl[high_nibbles] */ - __m128i first_len = _mm_shuffle_epi8(first_len_tbl, high_nibbles); - - /* First Byte: set range index to 8 for bytes within 0xC0 ~ 0xFF */ - /* range = first_range_tbl[high_nibbles] */ - __m128i range = _mm_shuffle_epi8(first_range_tbl, high_nibbles); - - /* Second Byte: set range index to first_len */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* range |= (first_len, prev_first_len) << 1 byte */ - range = _mm_or_si128( - range, _mm_alignr_epi8(first_len, prev_first_len, 15)); - - /* Third Byte: set range index to saturate_sub(first_len, 1) */ - /* 0 for 00~7F, 0 for C0~DF, 1 for E0~EF, 2 for F0~FF */ - __m128i tmp; - /* tmp = (first_len, prev_first_len) << 2 bytes */ - tmp = _mm_alignr_epi8(first_len, prev_first_len, 14); - /* tmp = saturate_sub(tmp, 1) */ - tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(1)); - /* range |= tmp */ - range = _mm_or_si128(range, tmp); - - /* Fourth Byte: set range index to saturate_sub(first_len, 2) */ - /* 0 for 00~7F, 0 for C0~DF, 0 for E0~EF, 1 for F0~FF */ - /* tmp = (first_len, prev_first_len) << 3 bytes */ - tmp = _mm_alignr_epi8(first_len, prev_first_len, 13); - /* tmp = saturate_sub(tmp, 2) */ - tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(2)); - /* range |= tmp */ - range = _mm_or_si128(range, tmp); - - /* - * Now we have below range indices calculated - * Correct cases: - * - 8 for C0~FF - * - 3 for 1st byte after F0~FF - * - 2 for 1st byte after E0~EF or 2nd byte after F0~FF - * - 1 for 1st byte after C0~DF or 2nd byte after E0~EF or - * 3rd byte after F0~FF - * - 0 for others - * Error cases: - * 9,10,11 if non ascii First Byte overlaps - * E.g., F1 80 C2 90 --> 8 3 10 2, where 10 indicates error - */ - - /* Adjust Second Byte range for special First Bytes(E0,ED,F0,F4) */ - /* Overlaps lead to index 9~15, which are illegal in range table */ - __m128i shift1, pos, range2; - /* shift1 = (input, prev_input) << 1 byte */ - shift1 = _mm_alignr_epi8(input, prev_input, 15); - pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); - /* - * shift1: | EF F0 ... FE | FF 00 ... ... DE | DF E0 ... EE | - * pos: | 0 1 15 | 16 17 239| 240 241 255| - * pos-240: | 0 0 0 | 0 0 0 | 0 1 15 | - * pos+112: | 112 113 127| >= 128 | >= 128 | - */ - tmp = _mm_subs_epu8(pos, _mm_set1_epi8(0xF0)); - range2 = _mm_shuffle_epi8(df_ee_tbl, tmp); - tmp = _mm_adds_epu8(pos, _mm_set1_epi8(0x70)); - range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_tbl, tmp)); - - range = _mm_add_epi8(range, range2); - - /* Load min and max values per calculated range index */ - __m128i minv = _mm_shuffle_epi8(range_min_tbl, range); - __m128i maxv = _mm_shuffle_epi8(range_max_tbl, range); - - /* Check value range */ -#if RET_ERR_IDX - error = _mm_cmplt_epi8(input, minv); - error = _mm_or_si128(error, _mm_cmpgt_epi8(input, maxv)); - /* 5% performance drop from this conditional branch */ - if (!_mm_testz_si128(error, error)) - break; -#else - /* error |= (input < minv) | (input > maxv) */ - tmp = _mm_or_si128( - _mm_cmplt_epi8(input, minv), - _mm_cmpgt_epi8(input, maxv) - ); - error = _mm_or_si128(error, tmp); -#endif - - prev_input = input; - prev_first_len = first_len; - - data += 16; - len -= 16; -#if RET_ERR_IDX - err_pos += 16; -#endif - } - -#if RET_ERR_IDX - /* Error in first 16 bytes */ - if (err_pos == 1) - goto do_naive; -#else - if (!_mm_testz_si128(error, error)) - return -1; -#endif - - /* Find previous token (not 80~BF) */ - int32_t token4 = _mm_extract_epi32(prev_input, 3); - const int8_t *token = (const int8_t *)&token4; - int lookahead = 0; - if (token[3] > (int8_t)0xBF) - lookahead = 1; - else if (token[2] > (int8_t)0xBF) - lookahead = 2; - else if (token[1] > (int8_t)0xBF) - lookahead = 3; - - data -= lookahead; - len += lookahead; -#if RET_ERR_IDX - err_pos -= lookahead; -#endif - } - - /* Check remaining bytes with naive method */ -#if RET_ERR_IDX - int err_pos2; -do_naive: - err_pos2 = utf8_naive(data, len); - if (err_pos2) - return err_pos + err_pos2 - 1; - return 0; -#else - return utf8_naive(data, len); -#endif -} - -#endif diff --git a/vendor/utf8_range/range2-neon.c b/vendor/utf8_range/range2-neon.c deleted file mode 100644 index 5367b6e..0000000 --- a/vendor/utf8_range/range2-neon.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Process 2x16 bytes in each iteration. - * Comments removed for brevity. See range-neon.c for details. - */ -#ifdef __aarch64__ - -#include -#include -#include - -int utf8_naive(const unsigned char *data, int len); - -static const uint8_t _first_len_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, -}; - -static const uint8_t _first_range_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, -}; - -static const uint8_t _range_min_tbl[] = { - 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, - 0xC2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -}; -static const uint8_t _range_max_tbl[] = { - 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, - 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -static const uint8_t _range_adjust_tbl[] = { - 2, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, -}; - -/* Return 0 on success, -1 on error */ -int utf8_range2(const unsigned char *data, int len) -{ - if (len >= 32) { - uint8x16_t prev_input = vdupq_n_u8(0); - uint8x16_t prev_first_len = vdupq_n_u8(0); - - const uint8x16_t first_len_tbl = vld1q_u8(_first_len_tbl); - const uint8x16_t first_range_tbl = vld1q_u8(_first_range_tbl); - const uint8x16_t range_min_tbl = vld1q_u8(_range_min_tbl); - const uint8x16_t range_max_tbl = vld1q_u8(_range_max_tbl); - const uint8x16x2_t range_adjust_tbl = vld2q_u8(_range_adjust_tbl); - - const uint8x16_t const_1 = vdupq_n_u8(1); - const uint8x16_t const_2 = vdupq_n_u8(2); - const uint8x16_t const_e0 = vdupq_n_u8(0xE0); - - uint8x16_t error1 = vdupq_n_u8(0); - uint8x16_t error2 = vdupq_n_u8(0); - uint8x16_t error3 = vdupq_n_u8(0); - uint8x16_t error4 = vdupq_n_u8(0); - - while (len >= 32) { - /******************* two blocks interleaved **********************/ - -#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 8) - /* gcc doesn't support vldq1_u8_x2 until version 8 */ - const uint8x16_t input_a = vld1q_u8(data); - const uint8x16_t input_b = vld1q_u8(data + 16); -#else - /* Forces a double load on Clang */ - const uint8x16x2_t input_pair = vld1q_u8_x2(data); - const uint8x16_t input_a = input_pair.val[0]; - const uint8x16_t input_b = input_pair.val[1]; -#endif - - const uint8x16_t high_nibbles_a = vshrq_n_u8(input_a, 4); - const uint8x16_t high_nibbles_b = vshrq_n_u8(input_b, 4); - - const uint8x16_t first_len_a = - vqtbl1q_u8(first_len_tbl, high_nibbles_a); - const uint8x16_t first_len_b = - vqtbl1q_u8(first_len_tbl, high_nibbles_b); - - uint8x16_t range_a = vqtbl1q_u8(first_range_tbl, high_nibbles_a); - uint8x16_t range_b = vqtbl1q_u8(first_range_tbl, high_nibbles_b); - - range_a = - vorrq_u8(range_a, vextq_u8(prev_first_len, first_len_a, 15)); - range_b = - vorrq_u8(range_b, vextq_u8(first_len_a, first_len_b, 15)); - - uint8x16_t tmp1_a, tmp2_a, tmp1_b, tmp2_b; - tmp1_a = vextq_u8(prev_first_len, first_len_a, 14); - tmp1_a = vqsubq_u8(tmp1_a, const_1); - range_a = vorrq_u8(range_a, tmp1_a); - - tmp1_b = vextq_u8(first_len_a, first_len_b, 14); - tmp1_b = vqsubq_u8(tmp1_b, const_1); - range_b = vorrq_u8(range_b, tmp1_b); - - tmp2_a = vextq_u8(prev_first_len, first_len_a, 13); - tmp2_a = vqsubq_u8(tmp2_a, const_2); - range_a = vorrq_u8(range_a, tmp2_a); - - tmp2_b = vextq_u8(first_len_a, first_len_b, 13); - tmp2_b = vqsubq_u8(tmp2_b, const_2); - range_b = vorrq_u8(range_b, tmp2_b); - - uint8x16_t shift1_a = vextq_u8(prev_input, input_a, 15); - uint8x16_t pos_a = vsubq_u8(shift1_a, const_e0); - range_a = vaddq_u8(range_a, vqtbl2q_u8(range_adjust_tbl, pos_a)); - - uint8x16_t shift1_b = vextq_u8(input_a, input_b, 15); - uint8x16_t pos_b = vsubq_u8(shift1_b, const_e0); - range_b = vaddq_u8(range_b, vqtbl2q_u8(range_adjust_tbl, pos_b)); - - uint8x16_t minv_a = vqtbl1q_u8(range_min_tbl, range_a); - uint8x16_t maxv_a = vqtbl1q_u8(range_max_tbl, range_a); - - uint8x16_t minv_b = vqtbl1q_u8(range_min_tbl, range_b); - uint8x16_t maxv_b = vqtbl1q_u8(range_max_tbl, range_b); - - error1 = vorrq_u8(error1, vcltq_u8(input_a, minv_a)); - error2 = vorrq_u8(error2, vcgtq_u8(input_a, maxv_a)); - - error3 = vorrq_u8(error3, vcltq_u8(input_b, minv_b)); - error4 = vorrq_u8(error4, vcgtq_u8(input_b, maxv_b)); - - /************************ next iteration *************************/ - prev_input = input_b; - prev_first_len = first_len_b; - - data += 32; - len -= 32; - } - error1 = vorrq_u8(error1, error2); - error1 = vorrq_u8(error1, error3); - error1 = vorrq_u8(error1, error4); - - if (vmaxvq_u8(error1)) - return -1; - - uint32_t token4; - vst1q_lane_u32(&token4, vreinterpretq_u32_u8(prev_input), 3); - - const int8_t *token = (const int8_t *)&token4; - int lookahead = 0; - if (token[3] > (int8_t)0xBF) - lookahead = 1; - else if (token[2] > (int8_t)0xBF) - lookahead = 2; - else if (token[1] > (int8_t)0xBF) - lookahead = 3; - - data -= lookahead; - len += lookahead; - } - - return utf8_naive(data, len); -} - -#endif diff --git a/vendor/utf8_range/range2-sse.c b/vendor/utf8_range/range2-sse.c deleted file mode 100644 index f3deb86..0000000 --- a/vendor/utf8_range/range2-sse.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Process 2x16 bytes in each iteration. - * Comments removed for brevity. See range-sse.c for details. - */ -#ifdef __SSE4_1__ - -#include -#include -#include - -int utf8_naive(const unsigned char *data, int len); - -static const int8_t _first_len_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, -}; - -static const int8_t _first_range_tbl[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, -}; - -static const int8_t _range_min_tbl[] = { - 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, - 0xC2, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, -}; -static const int8_t _range_max_tbl[] = { - 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, - 0xF4, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -}; - -static const int8_t _df_ee_tbl[] = { - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -}; -static const int8_t _ef_fe_tbl[] = { - 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -/* Return 0 on success, -1 on error */ -int utf8_range2(const unsigned char *data, int len) -{ - if (len >= 32) { - __m128i prev_input = _mm_set1_epi8(0); - __m128i prev_first_len = _mm_set1_epi8(0); - - const __m128i first_len_tbl = - _mm_loadu_si128((const __m128i *)_first_len_tbl); - const __m128i first_range_tbl = - _mm_loadu_si128((const __m128i *)_first_range_tbl); - const __m128i range_min_tbl = - _mm_loadu_si128((const __m128i *)_range_min_tbl); - const __m128i range_max_tbl = - _mm_loadu_si128((const __m128i *)_range_max_tbl); - const __m128i df_ee_tbl = - _mm_loadu_si128((const __m128i *)_df_ee_tbl); - const __m128i ef_fe_tbl = - _mm_loadu_si128((const __m128i *)_ef_fe_tbl); - - __m128i error = _mm_set1_epi8(0); - - while (len >= 32) { - /***************************** block 1 ****************************/ - const __m128i input_a = _mm_loadu_si128((const __m128i *)data); - - __m128i high_nibbles = - _mm_and_si128(_mm_srli_epi16(input_a, 4), _mm_set1_epi8(0x0F)); - - __m128i first_len_a = _mm_shuffle_epi8(first_len_tbl, high_nibbles); - - __m128i range_a = _mm_shuffle_epi8(first_range_tbl, high_nibbles); - - range_a = _mm_or_si128( - range_a, _mm_alignr_epi8(first_len_a, prev_first_len, 15)); - - __m128i tmp; - tmp = _mm_alignr_epi8(first_len_a, prev_first_len, 14); - tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(1)); - range_a = _mm_or_si128(range_a, tmp); - - tmp = _mm_alignr_epi8(first_len_a, prev_first_len, 13); - tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(2)); - range_a = _mm_or_si128(range_a, tmp); - - __m128i shift1, pos, range2; - shift1 = _mm_alignr_epi8(input_a, prev_input, 15); - pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); - tmp = _mm_subs_epu8(pos, _mm_set1_epi8(0xF0)); - range2 = _mm_shuffle_epi8(df_ee_tbl, tmp); - tmp = _mm_adds_epu8(pos, _mm_set1_epi8(0x70)); - range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_tbl, tmp)); - - range_a = _mm_add_epi8(range_a, range2); - - __m128i minv = _mm_shuffle_epi8(range_min_tbl, range_a); - __m128i maxv = _mm_shuffle_epi8(range_max_tbl, range_a); - - tmp = _mm_or_si128( - _mm_cmplt_epi8(input_a, minv), - _mm_cmpgt_epi8(input_a, maxv) - ); - error = _mm_or_si128(error, tmp); - - /***************************** block 2 ****************************/ - const __m128i input_b = _mm_loadu_si128((const __m128i *)(data+16)); - - high_nibbles = - _mm_and_si128(_mm_srli_epi16(input_b, 4), _mm_set1_epi8(0x0F)); - - __m128i first_len_b = _mm_shuffle_epi8(first_len_tbl, high_nibbles); - - __m128i range_b = _mm_shuffle_epi8(first_range_tbl, high_nibbles); - - range_b = _mm_or_si128( - range_b, _mm_alignr_epi8(first_len_b, first_len_a, 15)); - - - tmp = _mm_alignr_epi8(first_len_b, first_len_a, 14); - tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(1)); - range_b = _mm_or_si128(range_b, tmp); - - tmp = _mm_alignr_epi8(first_len_b, first_len_a, 13); - tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(2)); - range_b = _mm_or_si128(range_b, tmp); - - shift1 = _mm_alignr_epi8(input_b, input_a, 15); - pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); - tmp = _mm_subs_epu8(pos, _mm_set1_epi8(0xF0)); - range2 = _mm_shuffle_epi8(df_ee_tbl, tmp); - tmp = _mm_adds_epu8(pos, _mm_set1_epi8(0x70)); - range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_tbl, tmp)); - - range_b = _mm_add_epi8(range_b, range2); - - minv = _mm_shuffle_epi8(range_min_tbl, range_b); - maxv = _mm_shuffle_epi8(range_max_tbl, range_b); - - - tmp = _mm_or_si128( - _mm_cmplt_epi8(input_b, minv), - _mm_cmpgt_epi8(input_b, maxv) - ); - error = _mm_or_si128(error, tmp); - - /************************ next iteration **************************/ - prev_input = input_b; - prev_first_len = first_len_b; - - data += 32; - len -= 32; - } - - if (!_mm_testz_si128(error, error)) - return -1; - - int32_t token4 = _mm_extract_epi32(prev_input, 3); - const int8_t *token = (const int8_t *)&token4; - int lookahead = 0; - if (token[3] > (int8_t)0xBF) - lookahead = 1; - else if (token[2] > (int8_t)0xBF) - lookahead = 2; - else if (token[1] > (int8_t)0xBF) - lookahead = 3; - - data -= lookahead; - len += lookahead; - } - - return utf8_naive(data, len); -} - -#endif diff --git a/vendor/utf8_range/utf8_corpus_dir/utf8_corpus_durst.txt b/vendor/utf8_range/utf8_corpus_dir/utf8_corpus_durst.txt deleted file mode 100644 index b8157db..0000000 --- a/vendor/utf8_range/utf8_corpus_dir/utf8_corpus_durst.txt +++ /dev/null @@ -1,213 +0,0 @@ - - - UTF-8 test file - -

Original by Markus Kuhn, adapted for HTML by Martin Dürst.

-
-UTF-8 encoded sample plain-text file
-‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-
-Markus Kuhn [ˈmaʳkʊs kuːn] <mkuhn@acm.org> — 1999-08-20
-
-
-The ASCII compatible UTF-8 encoding of ISO 10646 and Unicode
-plain-text files is defined in RFC 2279 and in ISO 10646-1 Annex R.
-
-
-Using Unicode/UTF-8, you can write in emails and source code things such as
-
-Mathematics and Sciences:
-
-  ∮ E⋅da = Q,  n → ∞, ∑ f(i) = ∏ g(i), ∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β),
-
-  ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⊥ < a ≠ b ≡ c ≤ d ≪ ⊤ ⇒ (A ⇔ B),
-
-  2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm
-
-Linguistics and dictionaries:
-
-  ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn
-  Y [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]
-
-APL:
-
-  ((V⍳V)=⍳⍴V)/V←,V    ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈
-
-Nicer typography in plain text files:
-
-  ╔══════════════════════════════════════════╗
-  ║                                          ║
-  ║   • ‘single’ and “double” quotes         ║
-  ║                                          ║
-  ║   • Curly apostrophes: “We’ve been here” ║
-  ║                                          ║
-  ║   • Latin-1 apostrophe and accents: '´`  ║
-  ║                                          ║
-  ║   • ‚deutsche‘ „Anführungszeichen“       ║
-  ║                                          ║
-  ║   • †, ‡, ‰, •, 3–4, —, −5/+5, ™, …      ║
-  ║                                          ║
-  ║   • ASCII safety test: 1lI|, 0OD, 8B     ║
-  ║                      ╭─────────╮         ║
-  ║   • the euro symbol: │ 14.95 € │         ║
-  ║                      ╰─────────╯         ║
-  ╚══════════════════════════════════════════╝
-
-Greek (in Polytonic):
-
-  The Greek anthem:
-
-  Σὲ γνωρίζω ἀπὸ τὴν κόψη
-  τοῦ σπαθιοῦ τὴν τρομερή,
-  σὲ γνωρίζω ἀπὸ τὴν ὄψη
-  ποὺ μὲ βία μετράει τὴ γῆ.
-
-  ᾿Απ᾿ τὰ κόκκαλα βγαλμένη
-  τῶν ῾Ελλήνων τὰ ἱερά
-  καὶ σὰν πρῶτα ἀνδρειωμένη
-  χαῖρε, ὦ χαῖρε, ᾿Ελευθεριά!
-
-  From a speech of Demosthenes in the 4th century BC:
-
-  Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
-  ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
-  λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
-  τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿ 
-  εἰς τοῦτο προήκοντα,  ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
-  πρότερον κακῶς σκέψασθαι δέον. οὐδέν οὖν ἄλλο μοι δοκοῦσιν
-  οἱ τὰ τοιαῦτα λέγοντες ἢ τὴν ὑπόθεσιν, περὶ ἧς βουλεύεσθαι,
-  οὐχὶ τὴν οὖσαν παριστάντες ὑμῖν ἁμαρτάνειν. ἐγὼ δέ, ὅτι μέν
-  ποτ᾿ ἐξῆν τῇ πόλει καὶ τὰ αὑτῆς ἔχειν ἀσφαλῶς καὶ Φίλιππον
-  τιμωρήσασθαι, καὶ μάλ᾿ ἀκριβῶς οἶδα· ἐπ᾿ ἐμοῦ γάρ, οὐ πάλαι
-  γέγονεν ταῦτ᾿ ἀμφότερα· νῦν μέντοι πέπεισμαι τοῦθ᾿ ἱκανὸν
-  προλαβεῖν ἡμῖν εἶναι τὴν πρώτην, ὅπως τοὺς συμμάχους
-  σώσομεν. ἐὰν γὰρ τοῦτο βεβαίως ὑπάρξῃ, τότε καὶ περὶ τοῦ
-  τίνα τιμωρήσεταί τις καὶ ὃν τρόπον ἐξέσται σκοπεῖν· πρὶν δὲ
-  τὴν ἀρχὴν ὀρθῶς ὑποθέσθαι, μάταιον ἡγοῦμαι περὶ τῆς
-  τελευτῆς ὁντινοῦν ποιεῖσθαι λόγον.
-
-  Δημοσθένους, Γ´ ᾿Ολυνθιακὸς
-
-Georgian:
-
-  From a Unicode conference invitation:
-
-  გთხოვთ ახლავე გაიაროთ რეგისტრაცია Unicode-ის მეათე საერთაშორისო
-  კონფერენციაზე დასასწრებად, რომელიც გაიმართება 10-12 მარტს,
-  ქ. მაინცში, გერმანიაში. კონფერენცია შეჰკრებს ერთად მსოფლიოს
-  ექსპერტებს ისეთ დარგებში როგორიცაა ინტერნეტი და Unicode-ი,
-  ინტერნაციონალიზაცია და ლოკალიზაცია, Unicode-ის გამოყენება
-  ოპერაციულ სისტემებსა, და გამოყენებით პროგრამებში, შრიფტებში,
-  ტექსტების დამუშავებასა და მრავალენოვან კომპიუტერულ სისტემებში.
-
-Russian:
-
-  From a Unicode conference invitation:
-
-  Зарегистрируйтесь сейчас на Десятую Международную Конференцию по
-  Unicode, которая состоится 10-12 марта 1997 года в Майнце в Германии.
-  Конференция соберет широкий круг экспертов по  вопросам глобального
-  Интернета и Unicode, локализации и интернационализации, воплощению и
-  применению Unicode в различных операционных системах и программных
-  приложениях, шрифтах, верстке и многоязычных компьютерных системах.
-
-Thai (UCS Level 2):
-
-  Excerpt from a poetry on The Romance of The Three Kingdoms (a Chinese
-  classic 'San Gua'):
-
-  [----------------------------|------------------------]
-    ๏ แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช  พระปกเกศกองบู๊กู้ขึ้นใหม่
-  สิบสองกษัตริย์ก่อนหน้าแลถัดไป       สององค์ไซร้โง่เขลาเบาปัญญา
-    ทรงนับถือขันทีเป็นที่พึ่ง           บ้านเมืองจึงวิปริตเป็นนักหนา
-  โฮจิ๋นเรียกทัพทั่วหัวเมืองมา         หมายจะฆ่ามดชั่วตัวสำคัญ
-    เหมือนขับไสไล่เสือจากเคหา      รับหมาป่าเข้ามาเลยอาสัญ
-  ฝ่ายอ้องอุ้นยุแยกให้แตกกัน          ใช้สาวนั้นเป็นชนวนชื่นชวนใจ
-    พลันลิฉุยกุยกีกลับก่อเหตุ          ช่างอาเพศจริงหนาฟ้าร้องไห้
-  ต้องรบราฆ่าฟันจนบรรลัย           ฤๅหาใครค้ำชูกู้บรรลังก์ ฯ
-
-  (The above is a two-column text. If combining characters are handled
-  correctly, the lines of the second column should be aligned with the
-  | character above.)
-
-Ethiopian:
-
-  Proverbs in the Amharic language:
-
-  ሰማይ አይታረስ ንጉሥ አይከሰስ።
-  ብላ ካለኝ እንደአባቴ በቆመጠኝ።
-  ጌጥ ያለቤቱ ቁምጥና ነው።
-  ደሀ በሕልሙ ቅቤ ባይጠጣ ንጣት በገደለው።
-  የአፍ ወለምታ በቅቤ አይታሽም።
-  አይጥ በበላ ዳዋ ተመታ።
-  ሲተረጉሙ ይደረግሙ።
-  ቀስ በቀስ፥ ዕንቁላል በእግሩ ይሄዳል።
-  ድር ቢያብር አንበሳ ያስር።
-  ሰው እንደቤቱ እንጅ እንደ ጉረቤቱ አይተዳደርም።
-  እግዜር የከፈተውን ጉሮሮ ሳይዘጋው አይድርም።
-  የጎረቤት ሌባ፥ ቢያዩት ይስቅ ባያዩት ያጠልቅ።
-  ሥራ ከመፍታት ልጄን ላፋታት።
-  ዓባይ ማደሪያ የለው፥ ግንድ ይዞ ይዞራል።
-  የእስላም አገሩ መካ የአሞራ አገሩ ዋርካ።
-  ተንጋሎ ቢተፉ ተመልሶ ባፉ።
-  ወዳጅህ ማር ቢሆን ጨርስህ አትላሰው።
-  እግርህን በፍራሽህ ልክ ዘርጋ።
-
-Runes:
-
-  ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ
-
-  (Old English, which transcribed into Latin reads 'He cwaeth that he
-  bude thaem lande northweardum with tha Westsae.' and means 'He said
-  that he lived in the northern land near the Western Sea.')
-
-Braille:
-
-  ⡌⠁⠧⠑ ⠼⠁⠒  ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌
-
-  ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠙⠑⠁⠙⠒ ⠞⠕ ⠃⠑⠛⠔ ⠺⠊⠹⠲ ⡹⠻⠑ ⠊⠎ ⠝⠕ ⠙⠳⠃⠞
-  ⠱⠁⠞⠑⠧⠻ ⠁⠃⠳⠞ ⠹⠁⠞⠲ ⡹⠑ ⠗⠑⠛⠊⠌⠻ ⠕⠋ ⠙⠊⠎ ⠃⠥⠗⠊⠁⠇ ⠺⠁⠎
-  ⠎⠊⠛⠝⠫ ⠃⠹ ⠹⠑ ⠊⠇⠻⠛⠹⠍⠁⠝⠂ ⠹⠑ ⠊⠇⠻⠅⠂ ⠹⠑ ⠥⠝⠙⠻⠞⠁⠅⠻⠂
-  ⠁⠝⠙ ⠹⠑ ⠡⠊⠑⠋ ⠍⠳⠗⠝⠻⠲ ⡎⠊⠗⠕⠕⠛⠑ ⠎⠊⠛⠝⠫ ⠊⠞⠲ ⡁⠝⠙
-  ⡎⠊⠗⠕⠕⠛⠑⠰⠎ ⠝⠁⠍⠑ ⠺⠁⠎ ⠛⠕⠕⠙ ⠥⠏⠕⠝ ⠰⡡⠁⠝⠛⠑⠂ ⠋⠕⠗ ⠁⠝⠹⠹⠔⠛ ⠙⠑ 
-  ⠡⠕⠎⠑ ⠞⠕ ⠏⠥⠞ ⠙⠊⠎ ⠙⠁⠝⠙ ⠞⠕⠲
-
-  ⡕⠇⠙ ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
-
-  ⡍⠔⠙⠖ ⡊ ⠙⠕⠝⠰⠞ ⠍⠑⠁⠝ ⠞⠕ ⠎⠁⠹ ⠹⠁⠞ ⡊ ⠅⠝⠪⠂ ⠕⠋ ⠍⠹
-  ⠪⠝ ⠅⠝⠪⠇⠫⠛⠑⠂ ⠱⠁⠞ ⠹⠻⠑ ⠊⠎ ⠏⠜⠞⠊⠊⠥⠇⠜⠇⠹ ⠙⠑⠁⠙ ⠁⠃⠳⠞
-  ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲ ⡊ ⠍⠊⠣⠞ ⠙⠁⠧⠑ ⠃⠑⠲ ⠔⠊⠇⠔⠫⠂ ⠍⠹⠎⠑⠇⠋⠂ ⠞⠕
-  ⠗⠑⠛⠜⠙ ⠁ ⠊⠕⠋⠋⠔⠤⠝⠁⠊⠇ ⠁⠎ ⠹⠑ ⠙⠑⠁⠙⠑⠌ ⠏⠊⠑⠊⠑ ⠕⠋ ⠊⠗⠕⠝⠍⠕⠝⠛⠻⠹ 
-  ⠔ ⠹⠑ ⠞⠗⠁⠙⠑⠲ ⡃⠥⠞ ⠹⠑ ⠺⠊⠎⠙⠕⠍ ⠕⠋ ⠳⠗ ⠁⠝⠊⠑⠌⠕⠗⠎ 
-  ⠊⠎ ⠔ ⠹⠑ ⠎⠊⠍⠊⠇⠑⠆ ⠁⠝⠙ ⠍⠹ ⠥⠝⠙⠁⠇⠇⠪⠫ ⠙⠁⠝⠙⠎
-  ⠩⠁⠇⠇ ⠝⠕⠞ ⠙⠊⠌⠥⠗⠃ ⠊⠞⠂ ⠕⠗ ⠹⠑ ⡊⠳⠝⠞⠗⠹⠰⠎ ⠙⠕⠝⠑ ⠋⠕⠗⠲ ⡹⠳
-  ⠺⠊⠇⠇ ⠹⠻⠑⠋⠕⠗⠑ ⠏⠻⠍⠊⠞ ⠍⠑ ⠞⠕ ⠗⠑⠏⠑⠁⠞⠂ ⠑⠍⠏⠙⠁⠞⠊⠊⠁⠇⠇⠹⠂ ⠹⠁⠞
-  ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
-
-  (The first couple of paragraphs of "A Christmas Carol" by Dickens)
-
-Compact font selection example text:
-
-  ABCDEFGHIJKLMNOPQRSTUVWXYZ /0123456789
-  abcdefghijklmnopqrstuvwxyz £©µÀÆÖÞßéöÿ
-  –—‘“”„†•…‰™œŠŸž€ ΑΒΓΔΩαβγδω АБВГДабвгд
-  ∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi�⑀₂ἠḂӥẄɐː⍎אԱა
-
-Greetings in various languages:
-
-  Hello world, Καλημέρα κόσμε, コンニチハ
-
-Box drawing alignment tests:                                          █
-                                                                      ▉
-  ╔══╦══╗  ┌──┬──┐  ╭──┬──╮  ╭──┬──╮  ┏━━┳━━┓  ┎┒┏┑   ╷  ╻ ┏┯┓ ┌┰┐    ▊ ╱╲╱╲╳╳╳
-  ║┌─╨─┐║  │╔═╧═╗│  │╒═╪═╕│  │╓─╁─╖│  ┃┌─╂─┐┃  ┗╃╄┙  ╶┼╴╺╋╸┠┼┨ ┝╋┥    ▋ ╲╱╲╱╳╳╳
-  ║│╲ ╱│║  │║   ║│  ││ │ ││  │║ ┃ ║│  ┃│ ╿ │┃  ┍╅╆┓   ╵  ╹ ┗┷┛ └┸┘    ▌ ╱╲╱╲╳╳╳
-  ╠╡ ╳ ╞╣  ├╢   ╟┤  ├┼─┼─┼┤  ├╫─╂─╫┤  ┣┿╾┼╼┿┫  ┕┛┖┚     ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
-  ║│╱ ╲│║  │║   ║│  ││ │ ││  │║ ┃ ║│  ┃│ ╽ │┃  ░░▒▒▓▓██ ┊  ┆ ╎ ╏  ┇ ┋ ▎
-  ║└─╥─┘║  │╚═╤═╝│  │╘═╪═╛│  │╙─╀─╜│  ┃└─╂─┘┃  ░░▒▒▓▓██ ┊  ┆ ╎ ╏  ┇ ┋ ▏
-  ╚══╩══╝  └──┴──┘  ╰──┴──╯  ╰──┴──╯  ┗━━┻━━┛           └╌╌┘ ╎ ┗╍╍┛ ┋  ▁▂▃▄▅▆▇█
-
-
- - diff --git a/vendor/utf8_range/utf8_corpus_dir/utf8_corpus_kuhn.txt b/vendor/utf8_range/utf8_corpus_dir/utf8_corpus_kuhn.txt deleted file mode 100644 index e870817..0000000 Binary files a/vendor/utf8_range/utf8_corpus_dir/utf8_corpus_kuhn.txt and /dev/null differ diff --git a/vendor/utf8_range/utf8_range.c b/vendor/utf8_range/utf8_range.c deleted file mode 100644 index f3301cc..0000000 --- a/vendor/utf8_range/utf8_range.c +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2023 Google LLC -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -/* This is a wrapper for the Google range-sse.cc algorithm which checks whether - * a sequence of bytes is a valid UTF-8 sequence and finds the longest valid - * prefix of the UTF-8 sequence. - * - * The key difference is that it checks for as much ASCII symbols as possible - * and then falls back to the range-sse.cc algorithm. The changes to the - * algorithm are cosmetic, mostly to trick the clang compiler to produce optimal - * code. - * - * For API see the utf8_validity.h header. - */ -#include "utf8_range.h" - -#include -#include -#include - -#if defined(__GNUC__) -#define FORCE_INLINE_ATTR __attribute__((always_inline)) inline -#elif defined(_MSC_VER) -#define FORCE_INLINE_ATTR __forceinline -#else -#define FORCE_INLINE_ATTR inline -#endif - -static FORCE_INLINE_ATTR uint64_t utf8_range_UnalignedLoad64( - const void* p) { - uint64_t t; - memcpy(&t, p, sizeof t); - return t; -} - -static FORCE_INLINE_ATTR int utf8_range_AsciiIsAscii(unsigned char c) { - return c < 128; -} - -static FORCE_INLINE_ATTR int utf8_range_IsTrailByteOk(const char c) { - return (int8_t)(c) <= (int8_t)(0xBF); -} - -/* If return_position is false then it returns 1 if |data| is a valid utf8 - * sequence, otherwise returns 0. - * If return_position is set to true, returns the length in bytes of the prefix - of |data| that is all structurally valid UTF-8. - */ -static size_t utf8_range_ValidateUTF8Naive(const char* data, const char* end, - int return_position) { - /* We return err_pos in the loop which is always 0 if !return_position */ - size_t err_pos = 0; - size_t codepoint_bytes = 0; - /* The early check is done because of early continue's on codepoints of all - * sizes, i.e. we first check for ascii and if it is, we call continue, then - * for 2 byte codepoints, etc. This is done in order to reduce indentation and - * improve readability of the codepoint validity check. - */ - while (data + codepoint_bytes < end) { - if (return_position) { - err_pos += codepoint_bytes; - } - data += codepoint_bytes; - const size_t len = end - data; - const unsigned char byte1 = data[0]; - - /* We do not skip many ascii bytes at the same time as this function is - used for tail checking (< 16 bytes) and for non x86 platforms. We also - don't think that cases where non-ASCII codepoints are followed by ascii - happen often. For small strings it also introduces some penalty. For - purely ascii UTF8 strings (which is the overwhelming case) we call - SkipAscii function which is multiplatform and extremely fast. - */ - /* [00..7F] ASCII -> 1 byte */ - if (utf8_range_AsciiIsAscii(byte1)) { - codepoint_bytes = 1; - continue; - } - /* [C2..DF], [80..BF] -> 2 bytes */ - if (len >= 2 && byte1 >= 0xC2 && byte1 <= 0xDF && - utf8_range_IsTrailByteOk(data[1])) { - codepoint_bytes = 2; - continue; - } - if (len >= 3) { - const unsigned char byte2 = data[1]; - const unsigned char byte3 = data[2]; - - /* Is byte2, byte3 between [0x80, 0xBF] - * Check for 0x80 was done above. - */ - if (!utf8_range_IsTrailByteOk(byte2) || - !utf8_range_IsTrailByteOk(byte3)) { - return err_pos; - } - - if (/* E0, A0..BF, 80..BF */ - ((byte1 == 0xE0 && byte2 >= 0xA0) || - /* E1..EC, 80..BF, 80..BF */ - (byte1 >= 0xE1 && byte1 <= 0xEC) || - /* ED, 80..9F, 80..BF */ - (byte1 == 0xED && byte2 <= 0x9F) || - /* EE..EF, 80..BF, 80..BF */ - (byte1 >= 0xEE && byte1 <= 0xEF))) { - codepoint_bytes = 3; - continue; - } - if (len >= 4) { - const unsigned char byte4 = data[3]; - /* Is byte4 between 0x80 ~ 0xBF */ - if (!utf8_range_IsTrailByteOk(byte4)) { - return err_pos; - } - - if (/* F0, 90..BF, 80..BF, 80..BF */ - ((byte1 == 0xF0 && byte2 >= 0x90) || - /* F1..F3, 80..BF, 80..BF, 80..BF */ - (byte1 >= 0xF1 && byte1 <= 0xF3) || - /* F4, 80..8F, 80..BF, 80..BF */ - (byte1 == 0xF4 && byte2 <= 0x8F))) { - codepoint_bytes = 4; - continue; - } - } - } - return err_pos; - } - if (return_position) { - err_pos += codepoint_bytes; - } - /* if return_position is false, this returns 1. - * if return_position is true, this returns err_pos. - */ - return err_pos + (1 - return_position); -} - -#if defined(__SSE4_1__) || (defined(__ARM_NEON) && defined(__ARM_64BIT_STATE)) -/* Returns the number of bytes needed to skip backwards to get to the first - byte of codepoint. - */ -static inline int utf8_range_CodepointSkipBackwards(int32_t codepoint_word) { - const int8_t* const codepoint = (const int8_t*)(&codepoint_word); - if (!utf8_range_IsTrailByteOk(codepoint[3])) { - return 1; - } else if (!utf8_range_IsTrailByteOk(codepoint[2])) { - return 2; - } else if (!utf8_range_IsTrailByteOk(codepoint[1])) { - return 3; - } - return 0; -} -#endif // __SSE4_1__ - -/* Skipping over ASCII as much as possible, per 8 bytes. It is intentional - as most strings to check for validity consist only of 1 byte codepoints. - */ -static inline const char* utf8_range_SkipAscii(const char* data, - const char* end) { - while (8 <= end - data && - (utf8_range_UnalignedLoad64(data) & 0x8080808080808080) == 0) { - data += 8; - } - while (data < end && utf8_range_AsciiIsAscii(*data)) { - ++data; - } - return data; -} - -#if defined(__SSE4_1__) -#include "utf8_range_sse.inc" -#elif defined(__ARM_NEON) && defined(__ARM_64BIT_STATE) -#include "utf8_range_neon.inc" -#endif - -static FORCE_INLINE_ATTR size_t utf8_range_Validate( - const char* data, size_t len, int return_position) { - if (len == 0) return 1 - return_position; - // Save buffer start address for later use - const char* const data_original = data; - const char* const end = data + len; - data = utf8_range_SkipAscii(data, end); - /* SIMD algorithm always outperforms the naive version for any data of - length >=16. - */ - if (end - data < 16) { - return (return_position ? (data - data_original) : 0) + - utf8_range_ValidateUTF8Naive(data, end, return_position); - } -#if defined(__SSE4_1__) || (defined(__ARM_NEON) && defined(__ARM_64BIT_STATE)) - return utf8_range_ValidateUTF8Simd( - data_original, data, end, return_position); -#else - return (return_position ? (data - data_original) : 0) + - utf8_range_ValidateUTF8Naive(data, end, return_position); -#endif -} - -bool utf8_range_IsValid(const char* data, size_t len) { - return utf8_range_Validate(data, len, /*return_position=*/0) != 0; -} - -size_t utf8_range_ValidPrefix(const char* data, size_t len) { - return utf8_range_Validate(data, len, /*return_position=*/1); -} diff --git a/vendor/utf8_range/utf8_range.h b/vendor/utf8_range/utf8_range.h deleted file mode 100644 index 5942d80..0000000 --- a/vendor/utf8_range/utf8_range.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef THIRD_PARTY_UTF8_RANGE_UTF8_RANGE_H_ -#define THIRD_PARTY_UTF8_RANGE_UTF8_RANGE_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// Returns 1 if the sequence of characters is a valid UTF-8 sequence, otherwise -// 0. -bool utf8_range_IsValid(const char* data, size_t len); - -// Returns the length in bytes of the prefix of str that is all -// structurally valid UTF-8. -size_t utf8_range_ValidPrefix(const char* data, size_t len); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // THIRD_PARTY_UTF8_RANGE_UTF8_RANGE_H_ diff --git a/vendor/utf8_range/utf8_range_neon.inc b/vendor/utf8_range/utf8_range_neon.inc deleted file mode 100644 index ab73754..0000000 --- a/vendor/utf8_range/utf8_range_neon.inc +++ /dev/null @@ -1,117 +0,0 @@ -#include - -/* This code is almost the same as SSE implementation, please reference - * utf8-range-sse.inc for detailed explanation. - * The only difference is the range adjustment step. NEON code is more - * straightforward. - */ - -static FORCE_INLINE_ATTR size_t utf8_range_ValidateUTF8Simd( - const char* data_original, const char* data, const char* end, - int return_position) { - const uint8x16_t first_len_tbl = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, - }; - const uint8x16_t first_range_tbl = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, - }; - const uint8x16_t range_min_tbl = { - 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, - 0xC2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - }; - const uint8x16_t range_max_tbl = { - 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, - 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - /* Range adjustment in NEON uint8x16x2 table. Note that lanes are interleaved - * in register. The table below is plotted vertically to ease understanding. - * The 1st column is for E0~EF, 2nd column for F0~FF. - */ - // clang-format off - const uint8_t range_adjust_tbl_data[] = { - /* index -> 0~15 16~31 <- index */ - /* E0 -> */ 2, 3, /* <- F0 */ - 0, 0, - 0, 0, - 0, 0, - 0, 4, /* <- F4 */ - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - /* ED -> */ 3, 0, - 0, 0, - 0, 0, - }; - // clang-format on - const uint8x16x2_t range_adjust_tbl = vld2q_u8(range_adjust_tbl_data); - - const uint8x16_t const_1 = vdupq_n_u8(1); - const uint8x16_t const_2 = vdupq_n_u8(2); - const uint8x16_t const_e0 = vdupq_n_u8(0xE0); - - uint8x16_t prev_input = vdupq_n_u8(0); - uint8x16_t prev_first_len = vdupq_n_u8(0); - uint8x16_t error = vdupq_n_u8(0); - - while (end - data >= 16) { - const uint8x16_t input = vld1q_u8((const uint8_t*)data); - - const uint8x16_t high_nibbles = vshrq_n_u8(input, 4); - - const uint8x16_t first_len = vqtbl1q_u8(first_len_tbl, high_nibbles); - - uint8x16_t range = vqtbl1q_u8(first_range_tbl, high_nibbles); - - range = vorrq_u8(range, vextq_u8(prev_first_len, first_len, 15)); - - uint8x16_t shift2 = vextq_u8(prev_first_len, first_len, 14); - shift2 = vqsubq_u8(shift2, const_1); - range = vorrq_u8(range, shift2); - - uint8x16_t shift3 = vextq_u8(prev_first_len, first_len, 13); - shift3 = vqsubq_u8(shift3, const_2); - range = vorrq_u8(range, shift3); - - uint8x16_t shift1 = vextq_u8(prev_input, input, 15); - shift1 = vsubq_u8(shift1, const_e0); - range = vaddq_u8(range, vqtbl2q_u8(range_adjust_tbl, shift1)); - - const uint8x16_t min_range = vqtbl1q_u8(range_min_tbl, range); - const uint8x16_t max_range = vqtbl1q_u8(range_max_tbl, range); - - if (return_position) { - error = vcltq_u8(input, min_range); - error = vorrq_u8(error, vcgtq_u8(input, max_range)); - if (vmaxvq_u32(vreinterpretq_u32_u8(error))) { - break; - } - } else { - error = vorrq_u8(error, vcltq_u8(input, min_range)); - error = vorrq_u8(error, vcgtq_u8(input, max_range)); - } - - prev_input = input; - prev_first_len = first_len; - - data += 16; - } - - if (return_position && data == data_original) { - return utf8_range_ValidateUTF8Naive(data, end, return_position); - } - const int32_t prev = vgetq_lane_s32(vreinterpretq_s32_u8(prev_input), 3); - data -= utf8_range_CodepointSkipBackwards(prev); - if (return_position) { - return (data - data_original) + - utf8_range_ValidateUTF8Naive(data, end, return_position); - } - if (vmaxvq_u32(vreinterpretq_u32_u8(error))) { - return 0; - } - return utf8_range_ValidateUTF8Naive(data, end, return_position); -} diff --git a/vendor/utf8_range/utf8_range_sse.inc b/vendor/utf8_range/utf8_range_sse.inc deleted file mode 100644 index c93fa96..0000000 --- a/vendor/utf8_range/utf8_range_sse.inc +++ /dev/null @@ -1,272 +0,0 @@ -#include -#include -#include - -static FORCE_INLINE_ATTR size_t utf8_range_ValidateUTF8Simd( - const char* data_original, const char* data, const char* end, - int return_position) { - /* This code checks that utf-8 ranges are structurally valid 16 bytes at once - * using superscalar instructions. - * The mapping between ranges of codepoint and their corresponding utf-8 - * sequences is below. - */ - - /* - * U+0000...U+007F 00...7F - * U+0080...U+07FF C2...DF 80...BF - * U+0800...U+0FFF E0 A0...BF 80...BF - * U+1000...U+CFFF E1...EC 80...BF 80...BF - * U+D000...U+D7FF ED 80...9F 80...BF - * U+E000...U+FFFF EE...EF 80...BF 80...BF - * U+10000...U+3FFFF F0 90...BF 80...BF 80...BF - * U+40000...U+FFFFF F1...F3 80...BF 80...BF 80...BF - * U+100000...U+10FFFF F4 80...8F 80...BF 80...BF - */ - - /* First we compute the type for each byte, as given by the table below. - * This type will be used as an index later on. - */ - - /* - * Index Min Max Byte Type - * 0 00 7F Single byte sequence - * 1,2,3 80 BF Second, third and fourth byte for many of the sequences. - * 4 A0 BF Second byte after E0 - * 5 80 9F Second byte after ED - * 6 90 BF Second byte after F0 - * 7 80 8F Second byte after F4 - * 8 C2 F4 First non ASCII byte - * 9..15 7F 80 Invalid byte - */ - - /* After the first step we compute the index for all bytes, then we permute - the bytes according to their indices to check the ranges from the range - table. - * The range for a given type can be found in the range_min_table and - range_max_table, the range for type/index X is in range_min_table[X] ... - range_max_table[X]. - */ - - /* Algorithm: - * Put index zero to all bytes. - * Find all non ASCII characters, give them index 8. - * For each tail byte in a codepoint sequence, give it an index corresponding - to the 1 based index from the end. - * If the first byte of the codepoint is in the [C0...DF] range, we write - index 1 in the following byte. - * If the first byte of the codepoint is in the range [E0...EF], we write - indices 2 and 1 in the next two bytes. - * If the first byte of the codepoint is in the range [F0...FF] we write - indices 3,2,1 into the next three bytes. - * For finding the number of bytes we need to look at high nibbles (4 bits) - and do the lookup from the table, it can be done with shift by 4 + shuffle - instructions. We call it `first_len`. - * Then we shift first_len by 8 bits to get the indices of the 2nd bytes. - * Saturating sub 1 and shift by 8 bits to get the indices of the 3rd bytes. - * Again to get the indices of the 4th bytes. - * Take OR of all that 4 values and check within range. - */ - /* For example: - * input C3 80 68 E2 80 20 A6 F0 A0 80 AC 20 F0 93 80 80 - * first_len 1 0 0 2 0 0 0 3 0 0 0 0 3 0 0 0 - * 1st byte 8 0 0 8 0 0 0 8 0 0 0 0 8 0 0 0 - * 2nd byte 0 1 0 0 2 0 0 0 3 0 0 0 0 3 0 0 // Shift + sub - * 3rd byte 0 0 0 0 0 1 0 0 0 2 0 0 0 0 2 0 // Shift + sub - * 4th byte 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 // Shift + sub - * Index 8 1 0 8 2 1 0 8 3 2 1 0 8 3 2 1 // OR of results - */ - - /* Checking for errors: - * Error checking is done by looking up the high nibble (4 bits) of each byte - against an error checking table. - * Because the lookup value for the second byte depends of the value of the - first byte in codepoint, we use saturated operations to adjust the index. - * Specifically we need to add 2 for E0, 3 for ED, 3 for F0 and 4 for F4 to - match the correct index. - * If we subtract from all bytes EF then EO -> 241, ED -> 254, F0 -> 1, - F4 -> 5 - * Do saturating sub 240, then E0 -> 1, ED -> 14 and we can do lookup to - match the adjustment - * Add saturating 112, then F0 -> 113, F4 -> 117, all that were > 16 will - be more 128 and lookup in ef_fe_table will return 0 but for F0 - and F4 it will be 4 and 5 accordingly - */ - /* - * Then just check the appropriate ranges with greater/smaller equal - instructions. Check tail with a naive algorithm. - * To save from previous 16 byte checks we just align previous_first_len to - get correct continuations of the codepoints. - */ - - /* - * Map high nibble of "First Byte" to legal character length minus 1 - * 0x00 ~ 0xBF --> 0 - * 0xC0 ~ 0xDF --> 1 - * 0xE0 ~ 0xEF --> 2 - * 0xF0 ~ 0xFF --> 3 - */ - const __m128i first_len_table = - _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3); - - /* Map "First Byte" to 8-th item of range table (0xC2 ~ 0xF4) */ - const __m128i first_range_table = - _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8); - - /* - * Range table, map range index to min and max values - */ - const __m128i range_min_table = - _mm_setr_epi8(0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, 0xC2, 0x7F, - 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F); - - const __m128i range_max_table = - _mm_setr_epi8(0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, 0xF4, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); - - /* - * Tables for fast handling of four special First Bytes(E0,ED,F0,F4), after - * which the Second Byte are not 80~BF. It contains "range index adjustment". - * +------------+---------------+------------------+----------------+ - * | First Byte | original range| range adjustment | adjusted range | - * +------------+---------------+------------------+----------------+ - * | E0 | 2 | 2 | 4 | - * +------------+---------------+------------------+----------------+ - * | ED | 2 | 3 | 5 | - * +------------+---------------+------------------+----------------+ - * | F0 | 3 | 3 | 6 | - * +------------+---------------+------------------+----------------+ - * | F4 | 4 | 4 | 8 | - * +------------+---------------+------------------+----------------+ - */ - - /* df_ee_table[1] -> E0, df_ee_table[14] -> ED as ED - E0 = 13 */ - // The values represent the adjustment in the Range Index table for a correct - // index. - const __m128i df_ee_table = - _mm_setr_epi8(0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0); - - /* ef_fe_table[1] -> F0, ef_fe_table[5] -> F4, F4 - F0 = 4 */ - // The values represent the adjustment in the Range Index table for a correct - // index. - const __m128i ef_fe_table = - _mm_setr_epi8(0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - __m128i prev_input = _mm_set1_epi8(0); - __m128i prev_first_len = _mm_set1_epi8(0); - __m128i error = _mm_set1_epi8(0); - - while (end - data >= 16) { - const __m128i input = _mm_loadu_si128((const __m128i*)(data)); - - /* high_nibbles = input >> 4 */ - const __m128i high_nibbles = - _mm_and_si128(_mm_srli_epi16(input, 4), _mm_set1_epi8(0x0F)); - - /* first_len = legal character length minus 1 */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* first_len = first_len_table[high_nibbles] */ - __m128i first_len = _mm_shuffle_epi8(first_len_table, high_nibbles); - - /* First Byte: set range index to 8 for bytes within 0xC0 ~ 0xFF */ - /* range = first_range_table[high_nibbles] */ - __m128i range = _mm_shuffle_epi8(first_range_table, high_nibbles); - - /* Second Byte: set range index to first_len */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* range |= (first_len, prev_first_len) << 1 byte */ - range = _mm_or_si128(range, _mm_alignr_epi8(first_len, prev_first_len, 15)); - - /* Third Byte: set range index to saturate_sub(first_len, 1) */ - /* 0 for 00~7F, 0 for C0~DF, 1 for E0~EF, 2 for F0~FF */ - __m128i tmp1; - __m128i tmp2; - /* tmp1 = saturate_sub(first_len, 1) */ - tmp1 = _mm_subs_epu8(first_len, _mm_set1_epi8(1)); - /* tmp2 = saturate_sub(prev_first_len, 1) */ - tmp2 = _mm_subs_epu8(prev_first_len, _mm_set1_epi8(1)); - /* range |= (tmp1, tmp2) << 2 bytes */ - range = _mm_or_si128(range, _mm_alignr_epi8(tmp1, tmp2, 14)); - - /* Fourth Byte: set range index to saturate_sub(first_len, 2) */ - /* 0 for 00~7F, 0 for C0~DF, 0 for E0~EF, 1 for F0~FF */ - /* tmp1 = saturate_sub(first_len, 2) */ - tmp1 = _mm_subs_epu8(first_len, _mm_set1_epi8(2)); - /* tmp2 = saturate_sub(prev_first_len, 2) */ - tmp2 = _mm_subs_epu8(prev_first_len, _mm_set1_epi8(2)); - /* range |= (tmp1, tmp2) << 3 bytes */ - range = _mm_or_si128(range, _mm_alignr_epi8(tmp1, tmp2, 13)); - - /* - * Now we have below range indices calculated - * Correct cases: - * - 8 for C0~FF - * - 3 for 1st byte after F0~FF - * - 2 for 1st byte after E0~EF or 2nd byte after F0~FF - * - 1 for 1st byte after C0~DF or 2nd byte after E0~EF or - * 3rd byte after F0~FF - * - 0 for others - * Error cases: - * >9 for non ascii First Byte overlapping - * E.g., F1 80 C2 90 --> 8 3 10 2, where 10 indicates error - */ - - /* Adjust Second Byte range for special First Bytes(E0,ED,F0,F4) */ - /* Overlaps lead to index 9~15, which are illegal in range table */ - __m128i shift1; - __m128i pos; - __m128i range2; - /* shift1 = (input, prev_input) << 1 byte */ - shift1 = _mm_alignr_epi8(input, prev_input, 15); - pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); - /* - * shift1: | EF F0 ... FE | FF 00 ... ... DE | DF E0 ... EE | - * pos: | 0 1 15 | 16 17 239| 240 241 255| - * pos-240: | 0 0 0 | 0 0 0 | 0 1 15 | - * pos+112: | 112 113 127| >= 128 | >= 128 | - */ - tmp1 = _mm_subs_epu8(pos, _mm_set1_epi8(-16)); - range2 = _mm_shuffle_epi8(df_ee_table, tmp1); - tmp2 = _mm_adds_epu8(pos, _mm_set1_epi8(112)); - range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_table, tmp2)); - - range = _mm_add_epi8(range, range2); - - /* Load min and max values per calculated range index */ - __m128i min_range = _mm_shuffle_epi8(range_min_table, range); - __m128i max_range = _mm_shuffle_epi8(range_max_table, range); - - /* Check value range */ - if (return_position) { - error = _mm_cmplt_epi8(input, min_range); - error = _mm_or_si128(error, _mm_cmpgt_epi8(input, max_range)); - /* 5% performance drop from this conditional branch */ - if (!_mm_testz_si128(error, error)) { - break; - } - } else { - error = _mm_or_si128(error, _mm_cmplt_epi8(input, min_range)); - error = _mm_or_si128(error, _mm_cmpgt_epi8(input, max_range)); - } - - prev_input = input; - prev_first_len = first_len; - - data += 16; - } - /* If we got to the end, we don't need to skip any bytes backwards */ - if (return_position && data == data_original) { - return utf8_range_ValidateUTF8Naive(data, end, return_position); - } - /* Find previous codepoint (not 80~BF) */ - data -= utf8_range_CodepointSkipBackwards(_mm_extract_epi32(prev_input, 3)); - if (return_position) { - return (data - data_original) + - utf8_range_ValidateUTF8Naive(data, end, return_position); - } - /* Test if there was any error */ - if (!_mm_testz_si128(error, error)) { - return 0; - } - /* Check the tail */ - return utf8_range_ValidateUTF8Naive(data, end, return_position); -} diff --git a/vendor/utf8_range/utf8_to_utf16/Makefile b/vendor/utf8_range/utf8_to_utf16/Makefile deleted file mode 100644 index 853ffa4..0000000 --- a/vendor/utf8_range/utf8_to_utf16/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -CC = gcc -CPPFLAGS = -g -O3 -Wall -march=native - -OBJS = main.o iconv.o naive.o - -utf8to16: ${OBJS} - gcc $^ -o $@ - -.PHONY: clean -clean: - rm -f utf8to16 *.o diff --git a/vendor/utf8_range/utf8_to_utf16/iconv.c b/vendor/utf8_range/utf8_to_utf16/iconv.c deleted file mode 100644 index 35aebb6..0000000 --- a/vendor/utf8_range/utf8_to_utf16/iconv.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include - -static iconv_t s_cd; - -/* Call iconv_open only once so the benchmark will be faster? */ -static void __attribute__ ((constructor)) init_iconv(void) -{ -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - s_cd = iconv_open("UTF-16LE", "UTF-8"); -#else - s_cd = iconv_open("UTF-16BE", "UTF-8"); -#endif - if (s_cd == (iconv_t)-1) { - perror("iconv_open"); - exit(1); - } -} - -/* - * Parameters: - * - buf8, len8: input utf-8 string - * - buf16: buffer to store decoded utf-16 string - * - *len16: on entry - utf-16 buffer length in bytes - * on exit - length in bytes of valid decoded utf-16 string - * Returns: - * - 0: success - * - >0: error position of input utf-8 string - * - -1: utf-16 buffer overflow - * LE/BE depends on host - */ -int utf8_to16_iconv(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t *len16) -{ - size_t ret, len16_save = *len16; - const unsigned char *buf8_0 = buf8; - - ret = iconv(s_cd, (char **)&buf8, &len8, (char **)&buf16, len16); - - *len16 = len16_save - *len16; - - if (ret != (size_t)-1) - return 0; - - if (errno == E2BIG) - return -1; /* Output buffer full */ - - return buf8 - buf8_0 + 1; /* EILSEQ, EINVAL, error position */ -} diff --git a/vendor/utf8_range/utf8_to_utf16/main.c b/vendor/utf8_range/utf8_to_utf16/main.c deleted file mode 100644 index 9e6751e..0000000 --- a/vendor/utf8_range/utf8_to_utf16/main.c +++ /dev/null @@ -1,424 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int utf8_to16_iconv(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t *len16); -int utf8_to16_naive(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t *len16); - -static struct ftab { - const char *name; - int (*func)(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t *len16); -} ftab[] = { - { - .name = "iconv", - .func = utf8_to16_iconv, - }, { - .name = "naive", - .func = utf8_to16_naive, - }, -}; - -static unsigned char *load_test_buf(int len) -{ - const char utf8[] = "\xF0\x90\xBF\x80"; - const int utf8_len = sizeof(utf8)/sizeof(utf8[0]) - 1; - - unsigned char *data = malloc(len); - unsigned char *p = data; - - while (len >= utf8_len) { - memcpy(p, utf8, utf8_len); - p += utf8_len; - len -= utf8_len; - } - - while (len--) - *p++ = 0x7F; - - return data; -} - -static unsigned char *load_test_file(int *len) -{ - unsigned char *data; - int fd; - struct stat stat; - - fd = open("../UTF-8-demo.txt", O_RDONLY); - if (fd == -1) { - printf("Failed to open ../UTF-8-demo.txt!\n"); - exit(1); - } - if (fstat(fd, &stat) == -1) { - printf("Failed to get file size!\n"); - exit(1); - } - - *len = stat.st_size; - data = malloc(*len); - if (read(fd, data, *len) != *len) { - printf("Failed to read file!\n"); - exit(1); - } - - close(fd); - - return data; -} - -static void print_test(const unsigned char *data, int len) -{ - printf(" [len=%d] \"", len); - while (len--) - printf("\\x%02X", *data++); - - printf("\"\n"); -} - -struct test { - const unsigned char *data; - int len; -}; - -static void prepare_test_buf(unsigned char *buf, const struct test *pos, - int pos_len, int pos_idx) -{ - /* Round concatenate correct tokens to 1024 bytes */ - int buf_idx = 0; - while (buf_idx < 1024) { - int buf_len = 1024 - buf_idx; - - if (buf_len >= pos[pos_idx].len) { - memcpy(buf+buf_idx, pos[pos_idx].data, pos[pos_idx].len); - buf_idx += pos[pos_idx].len; - } else { - memset(buf+buf_idx, 0, buf_len); - buf_idx += buf_len; - } - - if (++pos_idx == pos_len) - pos_idx = 0; - } -} - -/* Return 0 on success, -1 on error */ -static int test_manual(const struct ftab *ftab, unsigned short *buf16, - unsigned short *_buf16) -{ -#define LEN16 4096 - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpointer-sign" - /* positive tests */ - static const struct test pos[] = { - {"", 0}, - {"\x00", 1}, - {"\x66", 1}, - {"\x7F", 1}, - {"\x00\x7F", 2}, - {"\x7F\x00", 2}, - {"\xC2\x80", 2}, - {"\xDF\xBF", 2}, - {"\xE0\xA0\x80", 3}, - {"\xE0\xA0\xBF", 3}, - {"\xED\x9F\x80", 3}, - {"\xEF\x80\xBF", 3}, - {"\xF0\x90\xBF\x80", 4}, - {"\xF2\x81\xBE\x99", 4}, - {"\xF4\x8F\x88\xAA", 4}, - }; - - /* negative tests */ - static const struct test neg[] = { - {"\x80", 1}, - {"\xBF", 1}, - {"\xC0\x80", 2}, - {"\xC1\x00", 2}, - {"\xC2\x7F", 2}, - {"\xDF\xC0", 2}, - {"\xE0\x9F\x80", 3}, - {"\xE0\xC2\x80", 3}, - {"\xED\xA0\x80", 3}, - {"\xED\x7F\x80", 3}, - {"\xEF\x80\x00", 3}, - {"\xF0\x8F\x80\x80", 4}, - {"\xF0\xEE\x80\x80", 4}, - {"\xF2\x90\x91\x7F", 4}, - {"\xF4\x90\x88\xAA", 4}, - {"\xF4\x00\xBF\xBF", 4}, - {"\x00\x00\x00\x00\x00\xC2\x80\x00\x00\x00\xE1\x80\x80\x00\x00\xC2" \ - "\xC2\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - 32}, - {"\x00\x00\x00\x00\x00\xC2\xC2\x80\x00\x00\xE1\x80\x80\x00\x00\x00", - 16}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1\x80", - 32}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1", - 32}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1\x80" \ - "\x80", 33}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF1\x80" \ - "\xC2\x80", 34}, - {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0" \ - "\x80\x80\x80", 35}, - }; -#pragma GCC diagnostic push - - size_t len16 = LEN16, _len16 = LEN16; - int ret, _ret; - - /* Test single token */ - for (int i = 0; i < sizeof(pos)/sizeof(pos[0]); ++i) { - ret = ftab->func(pos[i].data, pos[i].len, buf16, &len16); - _ret = utf8_to16_iconv(pos[i].data, pos[i].len, _buf16, &_len16); - if (ret != _ret || len16 != _len16 || memcmp(buf16, _buf16, len16)) { - printf("FAILED positive test(%d:%d, %lu:%lu): ", - ret, _ret, len16, _len16); - print_test(pos[i].data, pos[i].len); - return -1; - } - len16 = _len16 = LEN16; - } - for (int i = 0; i < sizeof(neg)/sizeof(neg[0]); ++i) { - ret = ftab->func(neg[i].data, neg[i].len, buf16, &len16); - _ret = utf8_to16_iconv(neg[i].data, neg[i].len, _buf16, &_len16); - if (ret != _ret || len16 != _len16 || memcmp(buf16, _buf16, len16)) { - printf("FAILED negative test(%d:%d, %lu:%lu): ", - ret, _ret, len16, _len16); - print_test(neg[i].data, neg[i].len); - return -1; - } - len16 = _len16 = LEN16; - } - - /* Test shifted buffer to cover 1k length */ - /* buffer size must be greater than 1024 + 16 + max(test string length) */ - const int max_size = 1024*2; - uint64_t buf64[max_size/8 + 2]; - /* Offset 8 bytes by 1 byte */ - unsigned char *buf = ((unsigned char *)buf64) + 1; - int buf_len; - - for (int i = 0; i < sizeof(pos)/sizeof(pos[0]); ++i) { - /* Positive test: shift 16 bytes, validate each shift */ - prepare_test_buf(buf, pos, sizeof(pos)/sizeof(pos[0]), i); - buf_len = 1024; - for (int j = 0; j < 16; ++j) { - ret = ftab->func(buf, buf_len, buf16, &len16); - _ret = utf8_to16_iconv(buf, buf_len, _buf16, &_len16); - if (ret != _ret || len16 != _len16 || \ - memcmp(buf16, _buf16, len16)) { - printf("FAILED positive test(%d:%d, %lu:%lu): ", - ret, _ret, len16, _len16); - print_test(buf, buf_len); - return -1; - } - len16 = _len16 = LEN16; - for (int k = buf_len; k >= 1; --k) - buf[k] = buf[k-1]; - buf[0] = '\x55'; - ++buf_len; - } - - /* Negative test: trunk last non ascii */ - while (buf_len >= 1 && buf[buf_len-1] <= 0x7F) - --buf_len; - if (buf_len) { - ret = ftab->func(buf, buf_len-1, buf16, &len16); - _ret = utf8_to16_iconv(buf, buf_len-1, _buf16, &_len16); - if (ret != _ret || len16 != _len16 || \ - memcmp(buf16, _buf16, len16)) { - printf("FAILED negative test(%d:%d, %lu:%lu): ", - ret, _ret, len16, _len16); - print_test(buf, buf_len-1); - return -1; - } - len16 = _len16 = LEN16; - } - } - - /* Negative test */ - for (int i = 0; i < sizeof(neg)/sizeof(neg[0]); ++i) { - /* Append one error token, shift 16 bytes, validate each shift */ - int pos_idx = i % (sizeof(pos)/sizeof(pos[0])); - prepare_test_buf(buf, pos, sizeof(pos)/sizeof(pos[0]), pos_idx); - memcpy(buf+1024, neg[i].data, neg[i].len); - buf_len = 1024 + neg[i].len; - for (int j = 0; j < 16; ++j) { - ret = ftab->func(buf, buf_len, buf16, &len16); - _ret = utf8_to16_iconv(buf, buf_len, _buf16, &_len16); - if (ret != _ret || len16 != _len16 || \ - memcmp(buf16, _buf16, len16)) { - printf("FAILED negative test(%d:%d, %lu:%lu): ", - ret, _ret, len16, _len16); - print_test(buf, buf_len); - return -1; - } - len16 = _len16 = LEN16; - for (int k = buf_len; k >= 1; --k) - buf[k] = buf[k-1]; - buf[0] = '\x66'; - ++buf_len; - } - } - - return 0; -} - -static void test(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t len16, const struct ftab *ftab) -{ - /* Use iconv as the reference answer */ - if (strcmp(ftab->name, "iconv") == 0) - return; - - printf("%s\n", ftab->name); - - /* Test file or buffer */ - size_t _len16 = len16; - unsigned short *_buf16 = (unsigned short *)malloc(_len16); - if (utf8_to16_iconv(buf8, len8, _buf16, &_len16)) { - printf("Invalid test file or buffer!\n"); - exit(1); - } - printf("standard test: "); - if (ftab->func(buf8, len8, buf16, &len16) || len16 != _len16 || \ - memcmp(buf16, _buf16, len16) != 0) - printf("FAIL\n"); - else - printf("pass\n"); - free(_buf16); - - /* Manual cases */ - unsigned short *mbuf8 = (unsigned short *)malloc(LEN16); - unsigned short *mbuf16 = (unsigned short *)malloc(LEN16); - printf("manual test: %s\n", - test_manual(ftab, mbuf8, mbuf16) ? "FAIL" : "pass"); - free(mbuf8); - free(mbuf16); - printf("\n"); -} - -static void bench(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t len16, const struct ftab *ftab) -{ - const int loops = 1024*1024*1024/len8; - int ret = 0; - double time, size; - struct timeval tv1, tv2; - - fprintf(stderr, "bench %s... ", ftab->name); - gettimeofday(&tv1, 0); - for (int i = 0; i < loops; ++i) - ret |= ftab->func(buf8, len8, buf16, &len16); - gettimeofday(&tv2, 0); - printf("%s\n", ret?"FAIL":"pass"); - - time = tv2.tv_usec - tv1.tv_usec; - time = time / 1000000 + tv2.tv_sec - tv1.tv_sec; - size = ((double)len8 * loops) / (1024*1024); - printf("time: %.4f s\n", time); - printf("data: %.0f MB\n", size); - printf("BW: %.2f MB/s\n", size / time); - printf("\n"); -} - -static void usage(const char *bin) -{ - printf("Usage:\n"); - printf("%s test [alg] ==> test all or one algorithm\n", bin); - printf("%s bench [alg] ==> benchmark all or one algorithm\n", bin); - printf("%s bench size NUM ==> benchmark with specific buffer size\n", bin); - printf("alg = "); - for (int i = 0; i < sizeof(ftab)/sizeof(ftab[0]); ++i) - printf("%s ", ftab[i].name); - printf("\nNUM = buffer size in bytes, 1 ~ 67108864(64M)\n"); -} - -int main(int argc, char *argv[]) -{ - int len8 = 0, len16; - unsigned char *buf8; - unsigned short *buf16; - const char *alg = NULL; - void (*tb)(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t len16, const struct ftab *ftab); - - tb = NULL; - if (argc >= 2) { - if (strcmp(argv[1], "test") == 0) - tb = test; - else if (strcmp(argv[1], "bench") == 0) - tb = bench; - if (argc >= 3) { - alg = argv[2]; - if (strcmp(alg, "size") == 0) { - if (argc < 4) { - tb = NULL; - } else { - alg = NULL; - len8 = atoi(argv[3]); - if (len8 <= 0 || len8 > 67108864) { - printf("Buffer size error!\n\n"); - tb = NULL; - } - } - } - } - } - - if (tb == NULL) { - usage(argv[0]); - return 1; - } - - /* Load UTF8 test buffer */ - if (len8) - buf8 = load_test_buf(len8); - else - buf8 = load_test_file(&len8); - - /* Prepare UTF16 buffer large enough */ - len16 = len8 * 2; - buf16 = (unsigned short *)malloc(len16); - - if (tb == bench) - printf("============== Bench UTF8 (%d bytes) ==============\n", len8); - for (int i = 0; i < sizeof(ftab)/sizeof(ftab[0]); ++i) { - if (alg && strcmp(alg, ftab[i].name) != 0) - continue; - tb((const unsigned char *)buf8, len8, buf16, len16, &ftab[i]); - } - -#if 0 - if (tb == bench) { - printf("==================== Bench ASCII ====================\n"); - /* Change test buffer to ascii */ - for (int i = 0; i < len; i++) - data[i] &= 0x7F; - - for (int i = 0; i < sizeof(ftab)/sizeof(ftab[0]); ++i) { - if (alg && strcmp(alg, ftab[i].name) != 0) - continue; - tb((const unsigned char *)data, len, &ftab[i]); - printf("\n"); - } - } -#endif - - return 0; -} diff --git a/vendor/utf8_range/utf8_to_utf16/naive.c b/vendor/utf8_range/utf8_to_utf16/naive.c deleted file mode 100644 index 05ab07b..0000000 --- a/vendor/utf8_range/utf8_to_utf16/naive.c +++ /dev/null @@ -1,133 +0,0 @@ -#include - -/* - * UTF-8 to UTF-16 - * Table from https://woboq.com/blog/utf-8-processing-using-simd.html - * - * +-------------------------------------+-------------------+ - * | UTF-8 | UTF-16LE (HI LO) | - * +-------------------------------------+-------------------+ - * | 0aaaaaaa | 00000000 0aaaaaaa | - * +-------------------------------------+-------------------+ - * | 110bbbbb 10aaaaaa | 00000bbb bbaaaaaa | - * +-------------------------------------+-------------------+ - * | 1110cccc 10bbbbbb 10aaaaaa | ccccbbbb bbaaaaaa | - * +-------------------------------------+-------------------+ - * | 11110ddd 10ddcccc 10bbbbbb 10aaaaaa | 110110uu uuccccbb | - * + uuuu = ddddd - 1 | 110111bb bbaaaaaa | - * +-------------------------------------+-------------------+ - */ - -/* - * Parameters: - * - buf8, len8: input utf-8 string - * - buf16: buffer to store decoded utf-16 string - * - *len16: on entry - utf-16 buffer length in bytes - * on exit - length in bytes of valid decoded utf-16 string - * Returns: - * - 0: success - * - >0: error position of input utf-8 string - * - -1: utf-16 buffer overflow - * LE/BE depends on host - */ -int utf8_to16_naive(const unsigned char *buf8, size_t len8, - unsigned short *buf16, size_t *len16) -{ - int err_pos = 1; - size_t len16_left = *len16; - - *len16 = 0; - - while (len8) { - unsigned char b0, b1, b2, b3; - unsigned int u; - - /* Output buffer full */ - if (len16_left < 2) - return -1; - - /* 1st byte */ - b0 = buf8[0]; - - if ((b0 & 0x80) == 0) { - /* 0aaaaaaa -> 00000000 0aaaaaaa */ - *buf16++ = b0; - ++buf8; - --len8; - ++err_pos; - *len16 += 2; - len16_left -= 2; - continue; - } - - /* Character length */ - size_t clen = b0 & 0xF0; - clen >>= 4; /* 10xx, 110x, 1110, 1111 */ - clen -= 12; /* -4~-1, 0/1, 2, 3 */ - clen += !clen; /* -4~-1, 1, 2, 3 */ - - /* String too short or invalid 1st byte (10xxxxxx) */ - if (len8 <= clen) - return err_pos; - - /* Trailing bytes must be within 0x80 ~ 0xBF */ - b1 = buf8[1]; - if ((signed char)b1 >= (signed char)0xC0) - return err_pos; - b1 &= 0x3F; - - ++clen; - if (clen == 2) { - u = b0 & 0x1F; - u <<= 6; - u |= b1; - if (u <= 0x7F) - return err_pos; - *buf16++ = u; - } else { - b2 = buf8[2]; - if ((signed char)b2 >= (signed char)0xC0) - return err_pos; - b2 &= 0x3F; - if (clen == 3) { - u = b0 & 0x0F; - u <<= 6; - u |= b1; - u <<= 6; - u |= b2; - if (u <= 0x7FF || (u >= 0xD800 && u <= 0xDFFF)) - return err_pos; - *buf16++ = u; - } else { - /* clen == 4 */ - if (len16_left < 4) - return -1; /* Output buffer full */ - b3 = buf8[3]; - if ((signed char)b3 >= (signed char)0xC0) - return err_pos; - u = b0 & 0x07; - u <<= 6; - u |= b1; - u <<= 6; - u |= b2; - u <<= 6; - u |= (b3 & 0x3F); - if (u <= 0xFFFF || u > 0x10FFFF) - return err_pos; - u -= 0x10000; - *buf16++ = (((u >> 10) & 0x3FF) | 0xD800); - *buf16++ = ((u & 0x3FF) | 0xDC00); - *len16 += 2; - len16_left -= 2; - } - } - - buf8 += clen; - len8 -= clen; - err_pos += clen; - *len16 += 2; - len16_left -= 2; - } - - return 0; -} diff --git a/vendor/utf8_range/utf8_validity.h b/vendor/utf8_range/utf8_validity.h deleted file mode 100644 index cd6d06a..0000000 --- a/vendor/utf8_range/utf8_validity.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 Google LLC -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -#ifndef THIRD_PARTY_UTF8_RANGE_UTF8_VALIDITY_H_ -#define THIRD_PARTY_UTF8_RANGE_UTF8_VALIDITY_H_ - -#include - -#include "absl/strings/string_view.h" -#include "utf8_range.h" - -namespace utf8_range { - -// Returns true if the sequence of characters is a valid UTF-8 sequence. -inline bool IsStructurallyValid(absl::string_view str) { - return utf8_range_IsValid(str.data(), str.size()); -} - -// Returns the length in bytes of the prefix of str that is all -// structurally valid UTF-8. -inline size_t SpanStructurallyValid(absl::string_view str) { - return utf8_range_ValidPrefix(str.data(), str.size()); -} - -} // namespace utf8_range - -#endif // THIRD_PARTY_UTF8_RANGE_UTF8_VALIDITY_H_ diff --git a/vendor/utf8_range/utf8_validity_test.cc b/vendor/utf8_range/utf8_validity_test.cc deleted file mode 100644 index 9a76f67..0000000 --- a/vendor/utf8_range/utf8_validity_test.cc +++ /dev/null @@ -1,76 +0,0 @@ -#include "utf8_validity.h" - -#include -#include "absl/strings/string_view.h" - -namespace utf8_range { - -TEST(Utf8Validity, SpanStructurallyValid) { - // Test simple good strings - EXPECT_EQ(4, SpanStructurallyValid("abcd")); - EXPECT_EQ(4, SpanStructurallyValid(absl::string_view("a\0cd", 4))); // NULL - EXPECT_EQ(4, SpanStructurallyValid("ab\xc2\x81")); // 2-byte - EXPECT_EQ(4, SpanStructurallyValid("a\xe2\x81\x81")); // 3-byte - EXPECT_EQ(4, SpanStructurallyValid("\xf2\x81\x81\x81")); // 4 - - // Test simple bad strings - EXPECT_EQ(3, SpanStructurallyValid("abc\x80")); // bad char - EXPECT_EQ(3, SpanStructurallyValid("abc\xc2")); // trunc 2 - EXPECT_EQ(2, SpanStructurallyValid("ab\xe2\x81")); // trunc 3 - EXPECT_EQ(1, SpanStructurallyValid("a\xf2\x81\x81")); // trunc 4 - EXPECT_EQ(2, SpanStructurallyValid("ab\xc0\x81")); // not 1 - EXPECT_EQ(1, SpanStructurallyValid("a\xe0\x81\x81")); // not 2 - EXPECT_EQ(0, SpanStructurallyValid("\xf0\x81\x81\x81")); // not 3 - EXPECT_EQ(0, SpanStructurallyValid("\xf4\xbf\xbf\xbf")); // big - // surrogate min, max - EXPECT_EQ(0, SpanStructurallyValid("\xED\xA0\x80")); // U+D800 - EXPECT_EQ(0, SpanStructurallyValid("\xED\xBF\xBF")); // U+DFFF - - // non-shortest forms should all return false - EXPECT_EQ(0, SpanStructurallyValid("\xc0\x80")); - EXPECT_EQ(0, SpanStructurallyValid("\xc1\xbf")); - EXPECT_EQ(0, SpanStructurallyValid("\xe0\x80\x80")); - EXPECT_EQ(0, SpanStructurallyValid("\xe0\x9f\xbf")); - EXPECT_EQ(0, SpanStructurallyValid("\xf0\x80\x80\x80")); - EXPECT_EQ(0, SpanStructurallyValid("\xf0\x83\xbf\xbf")); - - // This string unchecked caused GWS to crash 7/2006: - // invalid sequence 0xc7 0xc8 0xcd 0xcb - EXPECT_EQ(0, SpanStructurallyValid("\xc7\xc8\xcd\xcb")); -} - -TEST(Utf8Validity, IsStructurallyValid) { - // Test simple good strings - EXPECT_TRUE(IsStructurallyValid("abcd")); - EXPECT_TRUE(IsStructurallyValid(absl::string_view("a\0cd", 4))); // NULL - EXPECT_TRUE(IsStructurallyValid("ab\xc2\x81")); // 2-byte - EXPECT_TRUE(IsStructurallyValid("a\xe2\x81\x81")); // 3-byte - EXPECT_TRUE(IsStructurallyValid("\xf2\x81\x81\x81")); // 4 - - // Test simple bad strings - EXPECT_FALSE(IsStructurallyValid("abc\x80")); // bad char - EXPECT_FALSE(IsStructurallyValid("abc\xc2")); // trunc 2 - EXPECT_FALSE(IsStructurallyValid("ab\xe2\x81")); // trunc 3 - EXPECT_FALSE(IsStructurallyValid("a\xf2\x81\x81")); // trunc 4 - EXPECT_FALSE(IsStructurallyValid("ab\xc0\x81")); // not 1 - EXPECT_FALSE(IsStructurallyValid("a\xe0\x81\x81")); // not 2 - EXPECT_FALSE(IsStructurallyValid("\xf0\x81\x81\x81")); // not 3 - EXPECT_FALSE(IsStructurallyValid("\xf4\xbf\xbf\xbf")); // big - // surrogate min, max - EXPECT_FALSE(IsStructurallyValid("\xED\xA0\x80")); // U+D800 - EXPECT_FALSE(IsStructurallyValid("\xED\xBF\xBF")); // U+DFFF - - // non-shortest forms should all return false - EXPECT_FALSE(IsStructurallyValid("\xc0\x80")); - EXPECT_FALSE(IsStructurallyValid("\xc1\xbf")); - EXPECT_FALSE(IsStructurallyValid("\xe0\x80\x80")); - EXPECT_FALSE(IsStructurallyValid("\xe0\x9f\xbf")); - EXPECT_FALSE(IsStructurallyValid("\xf0\x80\x80\x80")); - EXPECT_FALSE(IsStructurallyValid("\xf0\x83\xbf\xbf")); - - // This string unchecked caused GWS to crash 7/2006: - // invalid sequence 0xc7 0xc8 0xcd 0xcb - EXPECT_FALSE(IsStructurallyValid("\xc7\xc8\xcd\xcb")); -} - -} // namespace utf8_range