From 26bec4b84c6f98d6879bb73360394539f6f1b423 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 29 Apr 2020 17:16:03 -0700 Subject: [PATCH 01/26] Added changelog for 3.12.x. (#7442) * Added changelog for 3.12.x. * Updated the wording of the changelog for proot3 presence. Also removed notice for change that was rolled back for Java enums. * A bit more teaking of the wording. --- CHANGES.txt | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index cbd3a20a88..0ced8012c5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,110 @@ +2020-04-28 version 3.12.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Protocol Compiler + * [experimental] Singular, non-message typed fields in proto3 now support + presence tracking. This is enabled by adding the "optional" field label and + passing the --experimental_allow_proto3_optional flag to protoc. + * For usage info, see docs/field_presence.md. + * During this experimental phase, code generators should update to support + proto3 presence, see docs/implementing_proto3_presence.md for instructions. + * Allow duplicate symbol names when multiple descriptor sets are passed on + the command-line, to match the behavior when multiple .proto files are passed. + * Deterministic `protoc --descriptor_set_out` (#7175) + + C++ + * [experimental] Added proto3 presence support. + * New descriptor APIs to support proto3 presence. + * Enable Arenas by default on all .proto files. + * Documented that users are not allowed to subclass Message or MessageLite. + * Mark generated classes as final; inheriting from protos is strongly discouraged. + * Add stack overflow protection for text format with unknown fields. + * Add accessors for map key and value FieldDescriptors. + * Add FieldMaskUtil::FromFieldNumbers(). + * MessageDifferencer: use ParsePartial() on Any fields so the diff does not + fail when there are missing required fields. + * ReflectionOps::Merge(): lookup messages in the right factory, if it can. + * Added Descriptor::WellKnownTypes enum and Descriptor::well_known_type() + accessor as an easier way of determining if a message is a Well-Known Type. + * Optimized RepeatedField::Add() when it is used in a loop. + * Made proto move/swap more efficient. + * De-virtualize the GetArena() method in MessageLite. + * Improves performance of json_stream_parser.cc by factor 1000 (#7230) + * bug: #7076 undefine Windows OUT and OPTIONAL macros (#7087) + * Fixed a bug in FieldDescriptor::DebugString() that would erroneously print + an "optional" label for a field in a oneof. + * Fix bug in parsing bool extensions that assumed they are always 1 byte. + * Fix off-by-one error in FieldOptions::ByteSize() when extensions are present. + * Clarified the comments to show an example of the difference between + Descriptor::extension and DescriptorPool::FindAllExtensions. + * Add a compiler option 'code_size' to force optimize_for=code_size on all + protos where this is possible. + + Java + * [experimental] Added proto3 presence support. + * Mark java enum _VALUE constants as @Deprecated if the enum field is deprecated + * reduce size for enums with allow_alias set to true. + * Sort map fields alphabetically by the field's key when printing textproto. + * TextFormat.merge() handles Any as top level type. + * Throw a descriptive IllegalArgumentException when calling + getValueDescriptor() on enum special value UNRECOGNIZED instead of + ArrayIndexOutOfBoundsException. + * Fixed an issue with JsonFormat.printer() where setting printingEnumsAsInts() + would override the configuration passed into includingDefaultValueFields(). + * Implement overrides of indexOf() and contains() on primitive lists returned + for repeated fields to avoid autoboxing the list contents. + * Add overload to FieldMaskUtil.fromStringList that accepts a descriptor. + * [bazel] Move Java runtime/toolchains into //java (#7190) + + Python + * [experimental] Added proto3 presence support. + * [experimental] fast import protobuf module, only works with cpp generated code linked in. + * Truncate 'float' fields to 4 bytes of precision in setters for pure-Python + implementation (C++ extension was already doing this). + * Fixed a memory leak in C++ bindings. + * Added a deprecation warning when code tries to create Descriptor objects + directly. + * Fix unintended comparison between bytes and string in descriptor.py. + * Avoid printing excess digits for float fields in TextFormat. + * Remove Python 2.5 syntax compatibility from the proto compiler generated _pb2.py module code. + * Drop 3.3, 3.4 and use single version docker images for all python tests (#7396) + + JavaScript + * Fix js message pivot selection (#6813) + + PHP + * Persistent Descriptor Pool (#6899) + * Implement lazy loading of php class for proto messages (#6911) + * Correct @return in Any.unpack docblock (#7089) + + Ruby + * [experimental] Implemented proto3 presence for Ruby. (#7406) + * Fix for wrappers with a zero value (#7195) + * Fix for JSON serialization of 0/empty-valued wrapper types (#7198) + * Call "Class#new" over rb_class_new_instance in decoding (#7352) + * Build extensions for Ruby 2.7 (#7027) + * assigning 'nil' to submessage should clear the field. (#7397) + + C# + * [experimental] Add support for proto3 presence fields in C# (#7382) + * Cleanup various bits of Google.Protobuf (#6674) + * Fix conformance test failures for Google.Protobuf (#6910) + * Fix latest ArgumentException for C# extensions (#6938) + * Remove unnecessary branch from ReadTag (#7289) + * Enforce recursion depth checking for unknown fields (#7132) + + Objective-C + * [experimental] ObjC Proto3 optional support (#7421) + * Block subclassing of generated classes (#7124) + * Use references to Obj C classes instead of names in descriptors. (#7026) + * Revisit how the WKTs are bundled with ObjC. (#7173) + + Other + * Add a proto_lang_toolchain for javalite (#6882) + * [bazel] Update gtest and deprecate //external:{gtest,gtest_main} (#7237) + * Add application note for explicit presence tracking. (#7390) + * Howto doc for implementing proto3 presence in a code generator. (#7407) + + 2020-02-14 version 3.11.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) C# From a9f11d7d640b59157167f683fa3fb9ca28d5b64a Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 30 Apr 2020 15:34:10 -0700 Subject: [PATCH 02/26] Updated version to 3.12.0-rc1. (#7449) --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 26 ++++++++++++++----- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- src/Makefile.am | 2 +- src/google/protobuf/any.pb.h | 4 +-- src/google/protobuf/api.pb.h | 4 +-- src/google/protobuf/compiler/plugin.pb.h | 4 +-- src/google/protobuf/descriptor.pb.h | 4 +-- src/google/protobuf/duration.pb.h | 4 +-- src/google/protobuf/empty.pb.h | 4 +-- src/google/protobuf/field_mask.pb.h | 4 +-- src/google/protobuf/port_def.inc | 8 +++--- src/google/protobuf/source_context.pb.h | 4 +-- src/google/protobuf/struct.pb.h | 4 +-- src/google/protobuf/stubs/common.h | 8 +++--- src/google/protobuf/timestamp.pb.h | 4 +-- src/google/protobuf/type.pb.h | 4 +-- src/google/protobuf/wrappers.pb.h | 4 +-- 31 files changed, 68 insertions(+), 54 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index dcb9f4d705..4b53cb9ff7 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.11.4' + s.version = '3.12.0-rc1' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index d6d6a8e785..ae98d556d7 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.11.4' + s.version = '3.12.0-rc1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index a86499a571..881c028d21 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.11.4],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.12.0-rc-1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 91d28ed140..f20ecb807b 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.11.4 + 3.12.0-rc1 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 53f45febc7..b1e71e7a59 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.11.4 + 3.12.0-rc1 6 Google Inc. netstandard1.0;netstandard2.0;net45 diff --git a/java/bom/pom.xml b/java/bom/pom.xml index f499bd132b..1b3874d633 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.11.4 + 3.12.0-rc-1 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 79a1e714ab..9d25bc2d04 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.11.4 + 3.12.0-rc-1 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 9c7d6eff62..c5e10cc654 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.11.4 + 3.12.0-rc-1 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index d1928ec4f5..8f7435a7fd 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.11.4 + 3.12.0-rc-1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 58d05d2972..a23ff1ccea 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.11.4 + 3.12.0-rc-1 protobuf-java-util diff --git a/js/package.json b/js/package.json index 14186bec1f..d7095c1477 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.11.4", + "version": "3.12.0-rc.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 5cb2b4648c..1862a6f9a6 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,15 +10,15 @@ protobuf-opensource@google.com yes - 2020-02-12 - + 2020-04-30 + - 3.11.4 - 3.11.4 + 3.12.0RC1 + 3.12.0 - stable - stable + beta + beta 3-Clause BSD License GA release. @@ -529,5 +529,19 @@ G A release. 3-Clause BSD License GA release. + + + 3.12.0RC1 + 3.12.0 + + + beta + beta + + 2020-04-30 + + 3-Clause BSD License + GA release. + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 88cc4005d9..76eced8d74 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.11.4" +#define PHP_PROTOBUF_VERSION "3.12.0RC1" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 327e3d7f3d..9363a2bde6 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.11.4 + 3.12.0-rc-1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index cc9a06a0ef..35bb943ff5 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.11.4' +__version__ = '3.12.0rc1' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index cd9af71b6e..332aaf9158 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.11.4" + s.version = "3.12.0.rc.1" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/src/Makefile.am b/src/Makefile.am index 3212a505ae..1837279801 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 22:4:0 +PROTOBUF_VERSION = 23:0:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 187f7d81ba..61b4722950 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 66ac61af89..8646a39aca 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 80ebc07a7d..1fd2a29a99 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 4a6dbf489b..2d978df82a 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index fcc21035ca..5b5da9efa8 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 8172d7a707..be58106ee0 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index f5f1ff2d4d..b3070f322b 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 81080c8e7d..2a93c6dfb2 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -300,14 +300,14 @@ // Shared google3/opensource definitions. ////////////////////////////////////// -#define PROTOBUF_VERSION 3011004 -#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3011000 -#define PROTOBUF_MIN_PROTOC_VERSION 3011000 +#define PROTOBUF_VERSION 3012000 +#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3012000 +#define PROTOBUF_MIN_PROTOC_VERSION 3012000 #define PROTOBUF_VERSION_SUFFIX "" // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3011000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3012000 #if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI #define PROTOBUF_RTTI 0 diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 1cf16f6dd9..1bc08cef02 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 993de2c67f..da13b937e1 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 1c9084f3fc..74fbada96f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -81,7 +81,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3011004 +#define GOOGLE_PROTOBUF_VERSION 3012000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" @@ -89,15 +89,15 @@ namespace internal { // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 3011000; +static const int kMinHeaderVersionForLibrary = 3012000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3011000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3012000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 3011000; +static const int kMinHeaderVersionForProtoc = 3012000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 84c74406d7..943c5accf9 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 680679f0d9..470e3f6542 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 7a1cc4dccb..1baa8f25a8 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3011000 +#if PROTOBUF_VERSION < 3012000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3011004 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. From e19bfc0e280996a261aee96cd43fde208c684307 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 1 May 2020 12:35:09 -0700 Subject: [PATCH 03/26] Stop building binary gems for ruby <2.5. (#7453) It is no longer possible to "bundle install" these versions: $ bundle install Fetching gem metadata from https://rubygems.org/................. reline-0.1.3 requires ruby version >= 2.5, which is incompatible with the current version, ruby 2.4.9p362 --- kokoro/release/ruby/macos/ruby/ruby_build_environment.sh | 2 +- ruby/Rakefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh index a4bf9e051e..7ff1ce5696 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh @@ -63,7 +63,7 @@ set +x rvm use 2.5.0 set -x ruby --version | grep 'ruby 2.5.0' -for v in 2.6.0 2.5.1 2.4.0 2.3.0 ; do +for v in 2.6.0 2.5.1 ; do ccache -c rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin11 MAKE="$MAKE" done diff --git a/ruby/Rakefile b/ruby/Rakefile index 2aa7743e20..53241fd515 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -73,7 +73,7 @@ else ['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat| RakeCompilerDock.sh <<-"EOT", platform: plat bundle && \ - IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0:2.4.0:2.3.0 + IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0 EOT end end @@ -81,7 +81,7 @@ else if RUBY_PLATFORM =~ /darwin/ task 'gem:native' do system "rake genproto" - system "rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.1:2.4.0:2.3.0" + system "rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.1" end else task 'gem:native' => [:genproto, 'gem:windows'] From ef7cc8111676076d8c2b6f9929096477cc868dc3 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 1 May 2020 13:10:28 -0700 Subject: [PATCH 04/26] Added changelog entry for removing binary gems for Ruby <2.5. (#7454) --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 0ced8012c5..bcd163a453 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -78,6 +78,7 @@ Ruby * [experimental] Implemented proto3 presence for Ruby. (#7406) + * Stop building binary gems for ruby <2.5 (#7453) * Fix for wrappers with a zero value (#7195) * Fix for JSON serialization of 0/empty-valued wrapper types (#7198) * Call "Class#new" over rb_class_new_instance in decoding (#7352) From d001f8cee4c2c0ff08c14e9c4957c0490c05860e Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 5 May 2020 18:12:27 -0700 Subject: [PATCH 05/26] Ignore unknown enum value when ignore_unknown specified (#7455) (#7462) --- php/ext/google/protobuf/map.c | 4 +- php/ext/google/protobuf/upb.c | 3194 ++++++++++-------- php/ext/google/protobuf/upb.h | 2515 ++++++-------- php/src/Google/Protobuf/Internal/Message.php | 44 +- php/tests/encode_decode_test.php | 5 + 5 files changed, 3007 insertions(+), 2755 deletions(-) diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 1878a0ae67..2dded9224e 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -516,8 +516,8 @@ bool map_done(MapIter *iter) { } const char *map_iter_key(MapIter *iter, int *len) { - *len = upb_strtable_iter_keylength(&iter->it); - return upb_strtable_iter_key(&iter->it); + *len = upb_strtable_iter_key(&iter->it).size; + return upb_strtable_iter_key(&iter->it).data; } upb_value map_iter_value(MapIter *iter, int *len) { diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c index 7608fe727c..cf27432f03 100644 --- a/php/ext/google/protobuf/upb.c +++ b/php/ext/google/protobuf/upb.c @@ -22,9 +22,8 @@ * * This file is private and must not be included by users! */ -#ifndef UINTPTR_MAX -#error must include stdint.h first -#endif +#include +#include #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 @@ -32,17 +31,21 @@ #define UPB_SIZE(size32, size64) size64 #endif -#define UPB_FIELD_AT(msg, fieldtype, offset) \ - *(fieldtype*)((const char*)(msg) + offset) +/* 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))) #define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \ - UPB_FIELD_AT(msg, int, case_offset) == case_val \ - ? UPB_FIELD_AT(msg, fieldtype, offset) \ + *UPB_PTR_AT(msg, case_offset, int) == case_val \ + ? *UPB_PTR_AT(msg, offset, fieldtype) \ : default #define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \ - UPB_FIELD_AT(msg, int, case_offset) = case_val; \ - UPB_FIELD_AT(msg, fieldtype, offset) = value; + *UPB_PTR_AT(msg, case_offset, int) = case_val; \ + *UPB_PTR_AT(msg, offset, fieldtype) = value; + +#define UPB_MAPTYPE_STRING 0 /* UPB_INLINE: inline if possible, emit standalone code if required. */ #ifdef __cplusplus @@ -53,6 +56,11 @@ #define UPB_INLINE static #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, 16) +#define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) + /* Hints to the compiler about likely/unlikely branches. */ #if defined (__GNUC__) || defined(__clang__) #define UPB_LIKELY(x) __builtin_expect((x),1) @@ -127,6 +135,18 @@ int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg); #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() +#else +#define UPB_ASSUME(expr) do {} if (false && (expr)) +#endif +#else +#define UPB_ASSUME(expr) assert(expr) +#endif + /* UPB_ASSERT(): in release mode, we use the expression without letting it be * evaluated. This prevents "unused variable" warnings. */ #ifdef NDEBUG @@ -153,607 +173,572 @@ int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg); #define UPB_INFINITY (1.0 / 0.0) #endif +#include #include + /* Maps descriptor type -> upb field type. */ -const uint8_t upb_desctype_to_fieldtype[] = { - UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */ - UPB_TYPE_DOUBLE, /* DOUBLE */ - UPB_TYPE_FLOAT, /* FLOAT */ - UPB_TYPE_INT64, /* INT64 */ - UPB_TYPE_UINT64, /* UINT64 */ - UPB_TYPE_INT32, /* INT32 */ - UPB_TYPE_UINT64, /* FIXED64 */ - UPB_TYPE_UINT32, /* FIXED32 */ - UPB_TYPE_BOOL, /* BOOL */ - UPB_TYPE_STRING, /* STRING */ - UPB_TYPE_MESSAGE, /* GROUP */ - UPB_TYPE_MESSAGE, /* MESSAGE */ - UPB_TYPE_BYTES, /* BYTES */ - UPB_TYPE_UINT32, /* UINT32 */ - UPB_TYPE_ENUM, /* ENUM */ - UPB_TYPE_INT32, /* SFIXED32 */ - UPB_TYPE_INT64, /* SFIXED64 */ - UPB_TYPE_INT32, /* SINT32 */ - UPB_TYPE_INT64, /* SINT64 */ +static const uint8_t desctype_to_fieldtype[] = { + -1, /* invalid descriptor type */ + UPB_TYPE_DOUBLE, /* DOUBLE */ + UPB_TYPE_FLOAT, /* FLOAT */ + UPB_TYPE_INT64, /* INT64 */ + UPB_TYPE_UINT64, /* UINT64 */ + UPB_TYPE_INT32, /* INT32 */ + UPB_TYPE_UINT64, /* FIXED64 */ + UPB_TYPE_UINT32, /* FIXED32 */ + UPB_TYPE_BOOL, /* BOOL */ + UPB_TYPE_STRING, /* STRING */ + UPB_TYPE_MESSAGE, /* GROUP */ + UPB_TYPE_MESSAGE, /* MESSAGE */ + UPB_TYPE_BYTES, /* BYTES */ + UPB_TYPE_UINT32, /* UINT32 */ + UPB_TYPE_ENUM, /* ENUM */ + UPB_TYPE_INT32, /* SFIXED32 */ + UPB_TYPE_INT64, /* SFIXED64 */ + UPB_TYPE_INT32, /* SINT32 */ + UPB_TYPE_INT64, /* SINT64 */ +}; + +/* Maps descriptor type -> upb map size. */ +static const uint8_t desctype_to_mapsize[] = { + -1, /* invalid descriptor type */ + 8, /* DOUBLE */ + 4, /* FLOAT */ + 8, /* INT64 */ + 8, /* UINT64 */ + 4, /* INT32 */ + 8, /* FIXED64 */ + 4, /* FIXED32 */ + 1, /* BOOL */ + UPB_MAPTYPE_STRING, /* STRING */ + sizeof(void *), /* GROUP */ + sizeof(void *), /* MESSAGE */ + UPB_MAPTYPE_STRING, /* BYTES */ + 4, /* UINT32 */ + 4, /* ENUM */ + 4, /* SFIXED32 */ + 8, /* SFIXED64 */ + 4, /* SINT32 */ + 8, /* SINT64 */ +}; + +static const unsigned fixed32_ok = (1 << UPB_DTYPE_FLOAT) | + (1 << UPB_DTYPE_FIXED32) | + (1 << UPB_DTYPE_SFIXED32); + +static const unsigned fixed64_ok = (1 << UPB_DTYPE_DOUBLE) | + (1 << UPB_DTYPE_FIXED64) | + (1 << UPB_DTYPE_SFIXED64); + +/* Op: an action to be performed for a wire-type/field-type combination. */ +#define OP_SCALAR_LG2(n) (n) +#define OP_FIXPCK_LG2(n) (n + 4) +#define OP_VARPCK_LG2(n) (n + 8) +#define OP_STRING 4 +#define OP_SUBMSG 5 + +static const int8_t varint_ops[19] = { + -1, /* field not found */ + -1, /* DOUBLE */ + -1, /* FLOAT */ + OP_SCALAR_LG2(3), /* INT64 */ + OP_SCALAR_LG2(3), /* UINT64 */ + OP_SCALAR_LG2(2), /* INT32 */ + -1, /* FIXED64 */ + -1, /* FIXED32 */ + OP_SCALAR_LG2(0), /* BOOL */ + -1, /* STRING */ + -1, /* GROUP */ + -1, /* MESSAGE */ + -1, /* BYTES */ + OP_SCALAR_LG2(2), /* UINT32 */ + OP_SCALAR_LG2(2), /* ENUM */ + -1, /* SFIXED32 */ + -1, /* SFIXED64 */ + OP_SCALAR_LG2(2), /* SINT32 */ + OP_SCALAR_LG2(3), /* SINT64 */ +}; + +static const int8_t delim_ops[37] = { + /* For non-repeated field type. */ + -1, /* field not found */ + -1, /* DOUBLE */ + -1, /* FLOAT */ + -1, /* INT64 */ + -1, /* UINT64 */ + -1, /* INT32 */ + -1, /* FIXED64 */ + -1, /* FIXED32 */ + -1, /* BOOL */ + OP_STRING, /* STRING */ + -1, /* GROUP */ + OP_SUBMSG, /* MESSAGE */ + OP_STRING, /* BYTES */ + -1, /* UINT32 */ + -1, /* ENUM */ + -1, /* SFIXED32 */ + -1, /* SFIXED64 */ + -1, /* SINT32 */ + -1, /* SINT64 */ + /* For repeated field type. */ + OP_FIXPCK_LG2(3), /* REPEATED DOUBLE */ + OP_FIXPCK_LG2(2), /* REPEATED FLOAT */ + OP_VARPCK_LG2(3), /* REPEATED INT64 */ + OP_VARPCK_LG2(3), /* REPEATED UINT64 */ + OP_VARPCK_LG2(2), /* REPEATED INT32 */ + OP_FIXPCK_LG2(3), /* REPEATED FIXED64 */ + OP_FIXPCK_LG2(2), /* REPEATED FIXED32 */ + OP_VARPCK_LG2(0), /* REPEATED BOOL */ + OP_STRING, /* REPEATED STRING */ + OP_SUBMSG, /* REPEATED GROUP */ + OP_SUBMSG, /* REPEATED MESSAGE */ + OP_STRING, /* REPEATED BYTES */ + OP_VARPCK_LG2(2), /* REPEATED UINT32 */ + OP_VARPCK_LG2(2), /* REPEATED ENUM */ + OP_FIXPCK_LG2(2), /* REPEATED SFIXED32 */ + OP_FIXPCK_LG2(3), /* REPEATED SFIXED64 */ + OP_VARPCK_LG2(2), /* REPEATED SINT32 */ + OP_VARPCK_LG2(3), /* REPEATED SINT64 */ }; /* Data pertaining to the parse. */ typedef struct { - const char *ptr; /* Current parsing position. */ - const char *field_start; /* Start of this field. */ - const char *limit; /* End of delimited region or end of buffer. */ + const char *limit; /* End of delimited region or end of buffer. */ upb_arena *arena; int depth; - uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */ + uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */ + jmp_buf err; } upb_decstate; -/* Data passed by value to each parsing function. */ -typedef struct { - char *msg; - const upb_msglayout *layout; - upb_decstate *state; -} upb_decframe; +typedef union { + bool bool_val; + int32_t int32_val; + int64_t int64_val; + uint32_t uint32_val; + uint64_t uint64_val; + upb_strview str_val; +} wireval; -#define CHK(x) if (!(x)) { return 0; } +static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, + const upb_msglayout *layout); -static bool upb_skip_unknowngroup(upb_decstate *d, int field_number); -static bool upb_decode_message(upb_decstate *d, char *msg, - const upb_msglayout *l); +UPB_NORETURN static void decode_err(upb_decstate *d) { longjmp(d->err, 1); } + +static bool decode_reserve(upb_decstate *d, upb_array *arr, int elem) { + bool need_realloc = arr->size - arr->len < elem; + if (need_realloc && !_upb_array_realloc(arr, arr->len + elem, d->arena)) { + decode_err(d); + } + return need_realloc; +} -static bool upb_decode_varint(const char **ptr, const char *limit, - uint64_t *val) { +UPB_NOINLINE +static const char *decode_longvarint64(upb_decstate *d, const char *ptr, + const char *limit, uint64_t *val) { uint8_t byte; int bitpos = 0; - const char *p = *ptr; - *val = 0; + uint64_t out = 0; do { - CHK(bitpos < 70 && p < limit); - byte = *p; - *val |= (uint64_t)(byte & 0x7F) << bitpos; - p++; + if (bitpos >= 70 || ptr == limit) decode_err(d); + byte = *ptr; + out |= (uint64_t)(byte & 0x7F) << bitpos; + ptr++; bitpos += 7; } while (byte & 0x80); - *ptr = p; - return true; -} - -static bool upb_decode_varint32(const char **ptr, const char *limit, - uint32_t *val) { - uint64_t u64; - CHK(upb_decode_varint(ptr, limit, &u64) && u64 <= UINT32_MAX); - *val = (uint32_t)u64; - return true; -} - -static bool upb_decode_64bit(const char **ptr, const char *limit, - uint64_t *val) { - CHK(limit - *ptr >= 8); - memcpy(val, *ptr, 8); - *ptr += 8; - return true; -} - -static bool upb_decode_32bit(const char **ptr, const char *limit, - uint32_t *val) { - CHK(limit - *ptr >= 4); - memcpy(val, *ptr, 4); - *ptr += 4; - return true; -} - -static int32_t upb_zzdecode_32(uint32_t n) { - return (n >> 1) ^ -(int32_t)(n & 1); -} - -static int64_t upb_zzdecode_64(uint64_t n) { - return (n >> 1) ^ -(int64_t)(n & 1); + *val = out; + return ptr; } -static bool upb_decode_string(const char **ptr, const char *limit, - int *outlen) { - uint32_t len; - - CHK(upb_decode_varint32(ptr, limit, &len) && - len < INT32_MAX && - limit - *ptr >= (int32_t)len); - - *outlen = len; - return true; -} - -static void upb_set32(void *msg, size_t ofs, uint32_t val) { - memcpy((char*)msg + ofs, &val, sizeof(val)); +UPB_FORCEINLINE +static const char *decode_varint64(upb_decstate *d, const char *ptr, + const char *limit, uint64_t *val) { + if (UPB_LIKELY(ptr < limit && (*ptr & 0x80) == 0)) { + *val = (uint8_t)*ptr; + return ptr + 1; + } else { + return decode_longvarint64(d, ptr, limit, val); + } } -static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame) { - upb_msg_addunknown(frame->msg, d->field_start, d->ptr - d->field_start, - d->arena); - return true; +static const char *decode_varint32(upb_decstate *d, const char *ptr, + const char *limit, uint32_t *val) { + uint64_t u64; + ptr = decode_varint64(d, ptr, limit, &u64); + if (u64 > UINT32_MAX) decode_err(d); + *val = (uint32_t)u64; + return ptr; } - -static bool upb_skip_unknownfielddata(upb_decstate *d, uint32_t tag, - uint32_t group_fieldnum) { - switch (tag & 7) { - case UPB_WIRE_TYPE_VARINT: { - uint64_t val; - return upb_decode_varint(&d->ptr, d->limit, &val); - } - case UPB_WIRE_TYPE_32BIT: { - uint32_t val; - return upb_decode_32bit(&d->ptr, d->limit, &val); - } - case UPB_WIRE_TYPE_64BIT: { - uint64_t val; - return upb_decode_64bit(&d->ptr, d->limit, &val); +static void decode_munge(int type, wireval *val) { + switch (type) { + case UPB_DESCRIPTOR_TYPE_BOOL: + val->bool_val = val->uint64_val != 0; + break; + case UPB_DESCRIPTOR_TYPE_SINT32: { + uint32_t n = val->uint32_val; + val->int32_val = (n >> 1) ^ -(int32_t)(n & 1); + break; } - case UPB_WIRE_TYPE_DELIMITED: { - int len; - CHK(upb_decode_string(&d->ptr, d->limit, &len)); - d->ptr += len; - return true; + case UPB_DESCRIPTOR_TYPE_SINT64: { + uint64_t n = val->uint64_val; + val->int64_val = (n >> 1) ^ -(int64_t)(n & 1); + break; } - case UPB_WIRE_TYPE_START_GROUP: - return upb_skip_unknowngroup(d, tag >> 3); - case UPB_WIRE_TYPE_END_GROUP: - return (tag >> 3) == group_fieldnum; - } - return false; -} - -static bool upb_skip_unknowngroup(upb_decstate *d, int field_number) { - while (d->ptr < d->limit && d->end_group == 0) { - uint32_t tag = 0; - CHK(upb_decode_varint32(&d->ptr, d->limit, &tag)); - CHK(upb_skip_unknownfielddata(d, tag, field_number)); } - - CHK(d->end_group == field_number); - d->end_group = 0; - return true; } -static bool upb_array_grow(upb_array *arr, size_t elements, size_t elem_size, - upb_arena *arena) { - size_t needed = arr->len + elements; - size_t new_size = UPB_MAX(arr->size, 8); - size_t new_bytes; - size_t old_bytes; - void *new_data; - upb_alloc *alloc = upb_arena_alloc(arena); +static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, + uint32_t field_number) { + static upb_msglayout_field none = {0}; - while (new_size < needed) { - new_size *= 2; + /* Lots of optimization opportunities here. */ + int i; + if (l == NULL) return &none; + for (i = 0; i < l->field_count; i++) { + if (l->fields[i].number == field_number) { + return &l->fields[i]; + } } - old_bytes = arr->len * elem_size; - new_bytes = new_size * elem_size; - new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes); - CHK(new_data); - - arr->data = new_data; - arr->size = new_size; - return true; + return &none; /* Unknown field. */ } -static void *upb_array_reserve(upb_array *arr, size_t elements, - size_t elem_size, upb_arena *arena) { - if (arr->size - arr->len < elements) { - CHK(upb_array_grow(arr, elements, elem_size, arena)); - } - return (char*)arr->data + (arr->len * elem_size); +static upb_msg *decode_newsubmsg(upb_decstate *d, const upb_msglayout *layout, + const upb_msglayout_field *field) { + const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + return _upb_msg_new(subl, d->arena); } -bool upb_array_add(upb_array *arr, size_t elements, size_t elem_size, - const void *data, upb_arena *arena) { - void *dest = upb_array_reserve(arr, elements, elem_size, arena); - - CHK(dest); - arr->len += elements; - memcpy(dest, data, elements * elem_size); +static void decode_tosubmsg(upb_decstate *d, upb_msg *submsg, + const upb_msglayout *layout, + const upb_msglayout_field *field, upb_strview val) { + const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + const char *saved_limit = d->limit; + if (--d->depth < 0) decode_err(d); + d->limit = val.data + val.size; + decode_msg(d, val.data, submsg, subl); + d->limit = saved_limit; + if (d->end_group != 0) decode_err(d); + d->depth++; +} - return true; +static const char *decode_group(upb_decstate *d, const char *ptr, + upb_msg *submsg, const upb_msglayout *subl, + uint32_t number) { + if (--d->depth < 0) decode_err(d); + ptr = decode_msg(d, ptr, submsg, subl); + if (d->end_group != number) decode_err(d); + d->end_group = 0; + d->depth++; + return ptr; } -static upb_array *upb_getarr(upb_decframe *frame, - const upb_msglayout_field *field) { - UPB_ASSERT(field->label == UPB_LABEL_REPEATED); - return *(upb_array**)&frame->msg[field->offset]; +static const char *decode_togroup(upb_decstate *d, const char *ptr, + upb_msg *submsg, const upb_msglayout *layout, + const upb_msglayout_field *field) { + const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + return decode_group(d, ptr, submsg, subl, field->number); } -static upb_array *upb_getorcreatearr(upb_decframe *frame, - const upb_msglayout_field *field) { - upb_array *arr = upb_getarr(frame, field); +static const char *decode_toarray(upb_decstate *d, const char *ptr, + upb_msg *msg, const upb_msglayout *layout, + const upb_msglayout_field *field, wireval val, + int op) { + upb_array **arrp = UPB_PTR_AT(msg, field->offset, void); + upb_array *arr = *arrp; + void *mem; if (!arr) { - arr = upb_array_new(frame->state->arena); - CHK(arr); - *(upb_array**)&frame->msg[field->offset] = arr; + upb_fieldtype_t type = desctype_to_fieldtype[field->descriptortype]; + arr = _upb_array_new(d->arena, type); + if (!arr) decode_err(d); + *arrp = arr; } - return arr; -} - -static upb_msg *upb_getorcreatemsg(upb_decframe *frame, - const upb_msglayout_field *field, - const upb_msglayout **subm) { - upb_msg **submsg = (void*)(frame->msg + field->offset); - *subm = frame->layout->submsgs[field->submsg_index]; - - UPB_ASSERT(field->label != UPB_LABEL_REPEATED); + decode_reserve(d, arr, 1); - if (!*submsg) { - *submsg = upb_msg_new(*subm, frame->state->arena); - CHK(*submsg); + switch (op) { + case OP_SCALAR_LG2(0): + case OP_SCALAR_LG2(2): + case OP_SCALAR_LG2(3): + /* Append scalar value. */ + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void); + arr->len++; + memcpy(mem, &val, 1 << op); + return ptr; + case OP_STRING: + /* Append string. */ + mem = + UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(upb_strview), void); + arr->len++; + memcpy(mem, &val, sizeof(upb_strview)); + return ptr; + case OP_SUBMSG: { + /* Append submessage / group. */ + upb_msg *submsg = decode_newsubmsg(d, layout, field); + *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void *), upb_msg *) = + submsg; + arr->len++; + if (UPB_UNLIKELY(field->descriptortype == UPB_DTYPE_GROUP)) { + ptr = decode_togroup(d, ptr, submsg, layout, field); + } else { + decode_tosubmsg(d, submsg, layout, field, val.str_val); + } + return ptr; + } + case OP_FIXPCK_LG2(2): + case OP_FIXPCK_LG2(3): { + /* Fixed packed. */ + int lg2 = op - OP_FIXPCK_LG2(0); + int mask = (1 << lg2) - 1; + int count = val.str_val.size >> lg2; + if ((val.str_val.size & mask) != 0) { + decode_err(d); /* Length isn't a round multiple of elem size. */ + } + decode_reserve(d, arr, count); + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + arr->len += count; + memcpy(mem, val.str_val.data, val.str_val.size); + return ptr; + } + case OP_VARPCK_LG2(0): + case OP_VARPCK_LG2(2): + case OP_VARPCK_LG2(3): { + /* Varint packed. */ + int lg2 = op - OP_VARPCK_LG2(0); + int scale = 1 << lg2; + const char *ptr = val.str_val.data; + const char *end = ptr + val.str_val.size; + char *out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + while (ptr < end) { + wireval elem; + ptr = decode_varint64(d, ptr, end, &elem.uint64_val); + decode_munge(field->descriptortype, &elem); + if (decode_reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + } + arr->len++; + memcpy(out, &elem, scale); + out += scale; + } + if (ptr != end) decode_err(d); + return ptr; + } + default: + UPB_UNREACHABLE(); } - - return *submsg; } -static upb_msg *upb_addmsg(upb_decframe *frame, - const upb_msglayout_field *field, - const upb_msglayout **subm) { - upb_msg *submsg; - upb_array *arr = upb_getorcreatearr(frame, field); - - *subm = frame->layout->submsgs[field->submsg_index]; - submsg = upb_msg_new(*subm, frame->state->arena); - CHK(submsg); - upb_array_add(arr, 1, sizeof(submsg), &submsg, frame->state->arena); - - return submsg; -} - -static void upb_sethasbit(upb_decframe *frame, - const upb_msglayout_field *field) { - int32_t hasbit = field->presence; - UPB_ASSERT(field->presence > 0); - frame->msg[hasbit / 8] |= (1 << (hasbit % 8)); -} - -static void upb_setoneofcase(upb_decframe *frame, - const upb_msglayout_field *field) { - UPB_ASSERT(field->presence < 0); - upb_set32(frame->msg, ~field->presence, field->number); -} - -static bool upb_decode_addval(upb_decframe *frame, - const upb_msglayout_field *field, void *val, - size_t size) { - char *field_mem = frame->msg + field->offset; - upb_array *arr; +static void decode_tomap(upb_decstate *d, upb_msg *msg, + const upb_msglayout *layout, + const upb_msglayout_field *field, wireval val) { + upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *); + upb_map *map = *map_p; + upb_map_entry ent; + const upb_msglayout *entry = layout->submsgs[field->submsg_index]; - if (field->label == UPB_LABEL_REPEATED) { - arr = upb_getorcreatearr(frame, field); - CHK(arr); - field_mem = upb_array_reserve(arr, 1, size, frame->state->arena); - CHK(field_mem); + if (!map) { + /* Lazily create map. */ + const upb_msglayout *entry = layout->submsgs[field->submsg_index]; + const upb_msglayout_field *key_field = &entry->fields[0]; + const upb_msglayout_field *val_field = &entry->fields[1]; + char key_size = desctype_to_mapsize[key_field->descriptortype]; + char val_size = desctype_to_mapsize[val_field->descriptortype]; + UPB_ASSERT(key_field->offset == 0); + UPB_ASSERT(val_field->offset == sizeof(upb_strview)); + map = _upb_map_new(d->arena, key_size, val_size); + *map_p = map; } - memcpy(field_mem, val, size); - return true; -} + /* Parse map entry. */ + memset(&ent, 0, sizeof(ent)); -static void upb_decode_setpresent(upb_decframe *frame, - const upb_msglayout_field *field) { - if (field->label == UPB_LABEL_REPEATED) { - upb_array *arr = upb_getarr(frame, field); - UPB_ASSERT(arr->len < arr->size); - arr->len++; - } else if (field->presence < 0) { - upb_setoneofcase(frame, field); - } else if (field->presence > 0) { - upb_sethasbit(frame, field); + if (entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE || + entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_GROUP) { + /* Create proactively to handle the case where it doesn't appear. */ + ent.v.val.val = (uint64_t)_upb_msg_new(entry->submsgs[0], d->arena); } -} -static bool upb_decode_msgfield(upb_decstate *d, upb_msg *msg, - const upb_msglayout *layout, int limit) { - const char* saved_limit = d->limit; - d->limit = d->ptr + limit; - CHK(--d->depth >= 0); - upb_decode_message(d, msg, layout); - d->depth++; - d->limit = saved_limit; - CHK(d->end_group == 0); - return true; -} + decode_tosubmsg(d, &ent.k, layout, field, val.str_val); -static bool upb_decode_groupfield(upb_decstate *d, upb_msg *msg, - const upb_msglayout *layout, - int field_number) { - CHK(--d->depth >= 0); - upb_decode_message(d, msg, layout); - d->depth++; - CHK(d->end_group == field_number); - d->end_group = 0; - return true; + /* Insert into map. */ + _upb_map_set(map, &ent.k, map->key_size, &ent.v, map->val_size, d->arena); } -static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, - const upb_msglayout_field *field) { - uint64_t val; - CHK(upb_decode_varint(&d->ptr, d->limit, &val)); +static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, + const upb_msglayout *layout, + const upb_msglayout_field *field, wireval val, + int op) { + void *mem = UPB_PTR_AT(msg, field->offset, void); + int type = field->descriptortype; - switch (field->descriptortype) { - case UPB_DESCRIPTOR_TYPE_INT64: - case UPB_DESCRIPTOR_TYPE_UINT64: - CHK(upb_decode_addval(frame, field, &val, sizeof(val))); - break; - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_UINT32: - case UPB_DESCRIPTOR_TYPE_ENUM: { - uint32_t val32 = (uint32_t)val; - CHK(upb_decode_addval(frame, field, &val32, sizeof(val32))); - break; - } - case UPB_DESCRIPTOR_TYPE_BOOL: { - bool valbool = val != 0; - CHK(upb_decode_addval(frame, field, &valbool, sizeof(valbool))); + /* Set presence if necessary. */ + if (field->presence < 0) { + /* Oneof case */ + *UPB_PTR_AT(msg, -field->presence, int32_t) = field->number; + } else if (field->presence > 0) { + /* Hasbit */ + uint32_t hasbit = field->presence; + *UPB_PTR_AT(msg, hasbit / 8, uint8_t) |= (1 << (hasbit % 8)); + } + + /* Store into message. */ + switch (op) { + case OP_SUBMSG: { + upb_msg **submsgp = mem; + upb_msg *submsg = *submsgp; + if (!submsg) { + submsg = decode_newsubmsg(d, layout, field); + *submsgp = submsg; + } + if (UPB_UNLIKELY(type == UPB_DTYPE_GROUP)) { + ptr = decode_togroup(d, ptr, submsg, layout, field); + } else { + decode_tosubmsg(d, submsg, layout, field, val.str_val); + } break; } - case UPB_DESCRIPTOR_TYPE_SINT32: { - int32_t decoded = upb_zzdecode_32((uint32_t)val); - CHK(upb_decode_addval(frame, field, &decoded, sizeof(decoded))); + case OP_STRING: + memcpy(mem, &val, sizeof(upb_strview)); break; - } - case UPB_DESCRIPTOR_TYPE_SINT64: { - int64_t decoded = upb_zzdecode_64(val); - CHK(upb_decode_addval(frame, field, &decoded, sizeof(decoded))); + case OP_SCALAR_LG2(3): + memcpy(mem, &val, 8); break; - } - default: - return upb_append_unknown(d, frame); - } - - upb_decode_setpresent(frame, field); - return true; -} - -static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame, - const upb_msglayout_field *field) { - uint64_t val; - CHK(upb_decode_64bit(&d->ptr, d->limit, &val)); - - switch (field->descriptortype) { - case UPB_DESCRIPTOR_TYPE_DOUBLE: - case UPB_DESCRIPTOR_TYPE_FIXED64: - case UPB_DESCRIPTOR_TYPE_SFIXED64: - CHK(upb_decode_addval(frame, field, &val, sizeof(val))); + case OP_SCALAR_LG2(2): + memcpy(mem, &val, 4); break; - default: - return upb_append_unknown(d, frame); - } - - upb_decode_setpresent(frame, field); - return true; -} - -static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame, - const upb_msglayout_field *field) { - uint32_t val; - CHK(upb_decode_32bit(&d->ptr, d->limit, &val)); - - switch (field->descriptortype) { - case UPB_DESCRIPTOR_TYPE_FLOAT: - case UPB_DESCRIPTOR_TYPE_FIXED32: - case UPB_DESCRIPTOR_TYPE_SFIXED32: - CHK(upb_decode_addval(frame, field, &val, sizeof(val))); + case OP_SCALAR_LG2(0): + memcpy(mem, &val, 1); break; default: - return upb_append_unknown(d, frame); + UPB_UNREACHABLE(); } - upb_decode_setpresent(frame, field); - return true; + return ptr; } -static bool upb_decode_fixedpacked(upb_decstate *d, upb_array *arr, - uint32_t len, int elem_size) { - size_t elements = len / elem_size; - - CHK((size_t)(elements * elem_size) == len); - CHK(upb_array_add(arr, elements, elem_size, d->ptr, d->arena)); - d->ptr += len; - - return true; -} - -static upb_strview upb_decode_strfield(upb_decstate *d, uint32_t len) { - upb_strview ret; - ret.data = d->ptr; - ret.size = len; - d->ptr += len; - return ret; -} - -static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, - const upb_msglayout_field *field, int len) { - upb_array *arr = upb_getorcreatearr(frame, field); - CHK(arr); - -#define VARINT_CASE(ctype, decode) \ - VARINT_CASE_EX(ctype, decode, decode) - -#define VARINT_CASE_EX(ctype, decode, dtype) \ - { \ - const char *ptr = d->ptr; \ - const char *limit = ptr + len; \ - while (ptr < limit) { \ - uint64_t val; \ - ctype decoded; \ - CHK(upb_decode_varint(&ptr, limit, &val)); \ - decoded = (decode)((dtype)val); \ - CHK(upb_array_add(arr, 1, sizeof(decoded), &decoded, d->arena)); \ - } \ - d->ptr = ptr; \ - return true; \ - } - - switch (field->descriptortype) { - case UPB_DESCRIPTOR_TYPE_STRING: - case UPB_DESCRIPTOR_TYPE_BYTES: { - upb_strview str = upb_decode_strfield(d, len); - return upb_array_add(arr, 1, sizeof(str), &str, d->arena); - } - case UPB_DESCRIPTOR_TYPE_FLOAT: - case UPB_DESCRIPTOR_TYPE_FIXED32: - case UPB_DESCRIPTOR_TYPE_SFIXED32: - return upb_decode_fixedpacked(d, arr, len, sizeof(int32_t)); - case UPB_DESCRIPTOR_TYPE_DOUBLE: - case UPB_DESCRIPTOR_TYPE_FIXED64: - case UPB_DESCRIPTOR_TYPE_SFIXED64: - return upb_decode_fixedpacked(d, arr, len, sizeof(int64_t)); - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_UINT32: - case UPB_DESCRIPTOR_TYPE_ENUM: - VARINT_CASE(uint32_t, uint32_t); - case UPB_DESCRIPTOR_TYPE_INT64: - case UPB_DESCRIPTOR_TYPE_UINT64: - VARINT_CASE(uint64_t, uint64_t); - case UPB_DESCRIPTOR_TYPE_BOOL: - VARINT_CASE(bool, bool); - case UPB_DESCRIPTOR_TYPE_SINT32: - VARINT_CASE_EX(int32_t, upb_zzdecode_32, uint32_t); - case UPB_DESCRIPTOR_TYPE_SINT64: - VARINT_CASE_EX(int64_t, upb_zzdecode_64, uint64_t); - case UPB_DESCRIPTOR_TYPE_MESSAGE: { - const upb_msglayout *subm; - upb_msg *submsg = upb_addmsg(frame, field, &subm); - CHK(submsg); - return upb_decode_msgfield(d, submsg, subm, len); - } - case UPB_DESCRIPTOR_TYPE_GROUP: - return upb_append_unknown(d, frame); - } -#undef VARINT_CASE - UPB_UNREACHABLE(); -} - -static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, - const upb_msglayout_field *field) { - int len; - - CHK(upb_decode_string(&d->ptr, d->limit, &len)); - - if (field->label == UPB_LABEL_REPEATED) { - return upb_decode_toarray(d, frame, field, len); - } else { - switch (field->descriptortype) { - case UPB_DESCRIPTOR_TYPE_STRING: - case UPB_DESCRIPTOR_TYPE_BYTES: { - upb_strview str = upb_decode_strfield(d, len); - CHK(upb_decode_addval(frame, field, &str, sizeof(str))); - break; - } - case UPB_DESCRIPTOR_TYPE_MESSAGE: { - const upb_msglayout *subm; - upb_msg *submsg = upb_getorcreatemsg(frame, field, &subm); - CHK(submsg); - CHK(upb_decode_msgfield(d, submsg, subm, len)); - break; - } - default: - /* TODO(haberman): should we accept the last element of a packed? */ - d->ptr += len; - return upb_append_unknown(d, frame); - } - upb_decode_setpresent(frame, field); - return true; - } -} - -static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, - uint32_t field_number) { - /* Lots of optimization opportunities here. */ - int i; - for (i = 0; i < l->field_count; i++) { - if (l->fields[i].number == field_number) { - return &l->fields[i]; - } - } +static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, + const upb_msglayout *layout) { + while (ptr < d->limit) { + uint32_t tag; + const upb_msglayout_field *field; + int field_number; + int wire_type; + const char *field_start = ptr; + wireval val; + int op; - return NULL; /* Unknown field. */ -} + ptr = decode_varint32(d, ptr, d->limit, &tag); + field_number = tag >> 3; + wire_type = tag & 7; -static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { - uint32_t tag; - const upb_msglayout_field *field; - int field_number; + field = upb_find_field(layout, field_number); - d->field_start = d->ptr; - CHK(upb_decode_varint32(&d->ptr, d->limit, &tag)); - field_number = tag >> 3; - field = upb_find_field(frame->layout, field_number); - - if (field) { - switch (tag & 7) { + switch (wire_type) { case UPB_WIRE_TYPE_VARINT: - return upb_decode_varintfield(d, frame, field); + ptr = decode_varint64(d, ptr, d->limit, &val.uint64_val); + op = varint_ops[field->descriptortype]; + decode_munge(field->descriptortype, &val); + break; case UPB_WIRE_TYPE_32BIT: - return upb_decode_32bitfield(d, frame, field); + if (d->limit - ptr < 4) decode_err(d); + memcpy(&val, ptr, 4); + ptr += 4; + op = OP_SCALAR_LG2(2); + if (((1 << field->descriptortype) & fixed32_ok) == 0) goto unknown; + break; case UPB_WIRE_TYPE_64BIT: - return upb_decode_64bitfield(d, frame, field); - case UPB_WIRE_TYPE_DELIMITED: - return upb_decode_delimitedfield(d, frame, field); - case UPB_WIRE_TYPE_START_GROUP: { - const upb_msglayout *layout; - upb_msg *group; - - if (field->label == UPB_LABEL_REPEATED) { - group = upb_addmsg(frame, field, &layout); - } else { - group = upb_getorcreatemsg(frame, field, &layout); + if (d->limit - ptr < 8) decode_err(d); + memcpy(&val, ptr, 8); + ptr += 8; + op = OP_SCALAR_LG2(3); + if (((1 << field->descriptortype) & fixed64_ok) == 0) goto unknown; + break; + case UPB_WIRE_TYPE_DELIMITED: { + uint32_t size; + int ndx = field->descriptortype; + if (_upb_isrepeated(field)) ndx += 18; + ptr = decode_varint32(d, ptr, d->limit, &size); + if (size >= INT32_MAX || (size_t)(d->limit - ptr) < size) { + decode_err(d); /* Length overflow. */ } - - return upb_decode_groupfield(d, group, layout, field_number); + val.str_val.data = ptr; + val.str_val.size = size; + ptr += size; + op = delim_ops[ndx]; + break; } + case UPB_WIRE_TYPE_START_GROUP: + val.int32_val = field_number; + op = OP_SUBMSG; + if (field->descriptortype != UPB_DTYPE_GROUP) goto unknown; + break; case UPB_WIRE_TYPE_END_GROUP: d->end_group = field_number; - return true; + return ptr; default: - CHK(false); + decode_err(d); + } + + if (op >= 0) { + /* Parse, using op for dispatch. */ + switch (field->label) { + case UPB_LABEL_REPEATED: + case _UPB_LABEL_PACKED: + ptr = decode_toarray(d, ptr, msg, layout, field, val, op); + break; + case _UPB_LABEL_MAP: + decode_tomap(d, msg, layout, field, val); + break; + default: + ptr = decode_tomsg(d, ptr, msg, layout, field, val, op); + break; + } + } else { + unknown: + /* Skip unknown field. */ + if (field_number == 0) decode_err(d); + if (wire_type == UPB_WIRE_TYPE_START_GROUP) { + ptr = decode_group(d, ptr, NULL, NULL, field_number); + } + if (msg) { + if (!_upb_msg_addunknown(msg, field_start, ptr - field_start, + d->arena)) { + decode_err(d); + } + } } - } else { - CHK(field_number != 0); - CHK(upb_skip_unknownfielddata(d, tag, -1)); - CHK(upb_append_unknown(d, frame)); - return true; - } - UPB_UNREACHABLE(); -} - -static bool upb_decode_message(upb_decstate *d, char *msg, const upb_msglayout *l) { - upb_decframe frame; - frame.msg = msg; - frame.layout = l; - frame.state = d; - - while (d->ptr < d->limit) { - CHK(upb_decode_field(d, &frame)); } - return true; + if (ptr != d->limit) decode_err(d); + return ptr; } bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l, upb_arena *arena) { upb_decstate state; - state.ptr = buf; state.limit = buf + size; state.arena = arena; state.depth = 64; state.end_group = 0; - CHK(upb_decode_message(&state, msg, l)); + if (setjmp(state.err)) return false; + + if (size == 0) return true; + decode_msg(&state, buf, msg, l); + return state.end_group == 0; } -#undef CHK +#undef OP_SCALAR_LG2 +#undef OP_FIXPCK_LG2 +#undef OP_VARPCK_LG2 +#undef OP_STRING +#undef OP_SUBMSG /* We encode backwards, to avoid pre-computing lengths (one-pass encode). */ @@ -822,6 +807,7 @@ static bool upb_encode_reserve(upb_encstate *e, size_t bytes) { /* Writes the given bytes to the buffer, handling reserve/advance. */ static bool upb_put_bytes(upb_encstate *e, const void *data, size_t len) { + if (len == 0) return true; CHK(upb_encode_reserve(e, len)); memcpy(e->ptr, data, len); return true; @@ -864,15 +850,14 @@ static bool upb_put_float(upb_encstate *e, float d) { static uint32_t upb_readcase(const char *msg, const upb_msglayout_field *f) { uint32_t ret; - uint32_t offset = ~f->presence; - memcpy(&ret, msg + offset, sizeof(ret)); + memcpy(&ret, msg - f->presence, sizeof(ret)); return ret; } static bool upb_readhasbit(const char *msg, const upb_msglayout_field *f) { uint32_t hasbit = f->presence; UPB_ASSERT(f->presence > 0); - return msg[hasbit / 8] & (1 << (hasbit % 8)); + return (*UPB_PTR_AT(msg, hasbit / 8, uint8_t)) & (1 << (hasbit % 8)); } static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) { @@ -880,116 +865,30 @@ static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) { } static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr, - size_t size) { - size_t bytes = arr->len * size; - return upb_put_bytes(e, arr->data, bytes) && upb_put_varint(e, bytes); + size_t elem_size, uint32_t tag) { + size_t bytes = arr->len * elem_size; + const char* data = _upb_array_constptr(arr); + const char* ptr = data + bytes - elem_size; + if (tag) { + while (true) { + CHK(upb_put_bytes(e, ptr, elem_size) && upb_put_varint(e, tag)); + if (ptr == data) break; + ptr -= elem_size; + } + return true; + } else { + return upb_put_bytes(e, data, bytes) && upb_put_varint(e, bytes); + } } bool upb_encode_message(upb_encstate *e, const char *msg, const upb_msglayout *m, size_t *size); -static bool upb_encode_array(upb_encstate *e, const char *field_mem, - const upb_msglayout *m, - const upb_msglayout_field *f) { - const upb_array *arr = *(const upb_array**)field_mem; - - if (arr == NULL || arr->len == 0) { - return true; - } - -#define VARINT_CASE(ctype, encode) { \ - ctype *start = arr->data; \ - ctype *ptr = start + arr->len; \ - size_t pre_len = e->limit - e->ptr; \ - do { \ - ptr--; \ - CHK(upb_put_varint(e, encode)); \ - } while (ptr != start); \ - CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \ -} \ -break; \ -do { ; } while(0) - - switch (f->descriptortype) { - case UPB_DESCRIPTOR_TYPE_DOUBLE: - CHK(upb_put_fixedarray(e, arr, sizeof(double))); - break; - case UPB_DESCRIPTOR_TYPE_FLOAT: - CHK(upb_put_fixedarray(e, arr, sizeof(float))); - break; - case UPB_DESCRIPTOR_TYPE_SFIXED64: - case UPB_DESCRIPTOR_TYPE_FIXED64: - CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t))); - break; - case UPB_DESCRIPTOR_TYPE_FIXED32: - case UPB_DESCRIPTOR_TYPE_SFIXED32: - CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t))); - break; - case UPB_DESCRIPTOR_TYPE_INT64: - case UPB_DESCRIPTOR_TYPE_UINT64: - VARINT_CASE(uint64_t, *ptr); - case UPB_DESCRIPTOR_TYPE_UINT32: - VARINT_CASE(uint32_t, *ptr); - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_ENUM: - VARINT_CASE(int32_t, (int64_t)*ptr); - case UPB_DESCRIPTOR_TYPE_BOOL: - VARINT_CASE(bool, *ptr); - case UPB_DESCRIPTOR_TYPE_SINT32: - VARINT_CASE(int32_t, upb_zzencode_32(*ptr)); - case UPB_DESCRIPTOR_TYPE_SINT64: - VARINT_CASE(int64_t, upb_zzencode_64(*ptr)); - case UPB_DESCRIPTOR_TYPE_STRING: - case UPB_DESCRIPTOR_TYPE_BYTES: { - upb_strview *start = arr->data; - upb_strview *ptr = start + arr->len; - do { - ptr--; - CHK(upb_put_bytes(e, ptr->data, ptr->size) && - upb_put_varint(e, ptr->size) && - upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); - } while (ptr != start); - return true; - } - case UPB_DESCRIPTOR_TYPE_GROUP: { - void **start = arr->data; - void **ptr = start + arr->len; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; - do { - size_t size; - ptr--; - CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && - upb_encode_message(e, *ptr, subm, &size) && - upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP)); - } while (ptr != start); - return true; - } - case UPB_DESCRIPTOR_TYPE_MESSAGE: { - void **start = arr->data; - void **ptr = start + arr->len; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; - do { - size_t size; - ptr--; - CHK(upb_encode_message(e, *ptr, subm, &size) && - upb_put_varint(e, size) && - upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); - } while (ptr != start); - return true; - } - } -#undef VARINT_CASE - - /* We encode all primitive arrays as packed, regardless of what was specified - * in the .proto file. Could special case 1-sized arrays. */ - CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); - return true; -} - -static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, +static bool upb_encode_scalarfield(upb_encstate *e, const void *_field_mem, const upb_msglayout *m, const upb_msglayout_field *f, bool skip_zero_value) { + const char *field_mem = _field_mem; #define CASE(ctype, type, wire_type, encodeval) do { \ ctype val = *(ctype*)field_mem; \ if (skip_zero_value && val == 0) { \ @@ -1038,29 +937,169 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, size_t size; void *submsg = *(void **)field_mem; const upb_msglayout *subm = m->submsgs[f->submsg_index]; - if (submsg == NULL) { - return true; - } - return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && - upb_encode_message(e, submsg, subm, &size) && - upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP); + if (submsg == NULL) { + return true; + } + return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && + upb_encode_message(e, submsg, subm, &size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP); + } + case UPB_DESCRIPTOR_TYPE_MESSAGE: { + size_t size; + void *submsg = *(void **)field_mem; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; + if (submsg == NULL) { + return true; + } + return upb_encode_message(e, submsg, subm, &size) && + upb_put_varint(e, size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED); + } + } +#undef CASE + UPB_UNREACHABLE(); +} + +static bool upb_encode_array(upb_encstate *e, const char *field_mem, + const upb_msglayout *m, + const upb_msglayout_field *f) { + const upb_array *arr = *(const upb_array**)field_mem; + bool packed = f->label == _UPB_LABEL_PACKED; + + if (arr == NULL || arr->len == 0) { + return true; + } + +#define VARINT_CASE(ctype, encode) \ + { \ + const ctype *start = _upb_array_constptr(arr); \ + const ctype *ptr = start + arr->len; \ + size_t pre_len = e->limit - e->ptr; \ + uint32_t tag = packed ? 0 : (f->number << 3) | UPB_WIRE_TYPE_VARINT; \ + do { \ + ptr--; \ + CHK(upb_put_varint(e, encode)); \ + if (tag) CHK(upb_put_varint(e, tag)); \ + } while (ptr != start); \ + if (!tag) CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \ + } \ + break; \ + do { \ + ; \ + } while (0) + +#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type)) + + switch (f->descriptortype) { + case UPB_DESCRIPTOR_TYPE_DOUBLE: + CHK(upb_put_fixedarray(e, arr, sizeof(double), TAG(UPB_WIRE_TYPE_64BIT))); + break; + case UPB_DESCRIPTOR_TYPE_FLOAT: + CHK(upb_put_fixedarray(e, arr, sizeof(float), TAG(UPB_WIRE_TYPE_32BIT))); + break; + case UPB_DESCRIPTOR_TYPE_SFIXED64: + case UPB_DESCRIPTOR_TYPE_FIXED64: + CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t), TAG(UPB_WIRE_TYPE_64BIT))); + break; + case UPB_DESCRIPTOR_TYPE_FIXED32: + case UPB_DESCRIPTOR_TYPE_SFIXED32: + CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t), TAG(UPB_WIRE_TYPE_32BIT))); + break; + case UPB_DESCRIPTOR_TYPE_INT64: + case UPB_DESCRIPTOR_TYPE_UINT64: + VARINT_CASE(uint64_t, *ptr); + case UPB_DESCRIPTOR_TYPE_UINT32: + VARINT_CASE(uint32_t, *ptr); + case UPB_DESCRIPTOR_TYPE_INT32: + case UPB_DESCRIPTOR_TYPE_ENUM: + VARINT_CASE(int32_t, (int64_t)*ptr); + case UPB_DESCRIPTOR_TYPE_BOOL: + VARINT_CASE(bool, *ptr); + case UPB_DESCRIPTOR_TYPE_SINT32: + VARINT_CASE(int32_t, upb_zzencode_32(*ptr)); + case UPB_DESCRIPTOR_TYPE_SINT64: + VARINT_CASE(int64_t, upb_zzencode_64(*ptr)); + case UPB_DESCRIPTOR_TYPE_STRING: + case UPB_DESCRIPTOR_TYPE_BYTES: { + const upb_strview *start = _upb_array_constptr(arr); + const upb_strview *ptr = start + arr->len; + do { + ptr--; + CHK(upb_put_bytes(e, ptr->data, ptr->size) && + upb_put_varint(e, ptr->size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); + } while (ptr != start); + return true; + } + case UPB_DESCRIPTOR_TYPE_GROUP: { + const void *const*start = _upb_array_constptr(arr); + const void *const*ptr = start + arr->len; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; + do { + size_t size; + ptr--; + CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && + upb_encode_message(e, *ptr, subm, &size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP)); + } while (ptr != start); + return true; } case UPB_DESCRIPTOR_TYPE_MESSAGE: { - size_t size; - void *submsg = *(void **)field_mem; + const void *const*start = _upb_array_constptr(arr); + const void *const*ptr = start + arr->len; const upb_msglayout *subm = m->submsgs[f->submsg_index]; - if (submsg == NULL) { - return true; - } - return upb_encode_message(e, submsg, subm, &size) && - upb_put_varint(e, size) && - upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED); + do { + size_t size; + ptr--; + CHK(upb_encode_message(e, *ptr, subm, &size) && + upb_put_varint(e, size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); + } while (ptr != start); + return true; } } -#undef CASE - UPB_UNREACHABLE(); +#undef VARINT_CASE + + if (packed) { + CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); + } + return true; +} + +static bool upb_encode_map(upb_encstate *e, const char *field_mem, + const upb_msglayout *m, + const upb_msglayout_field *f) { + const upb_map *map = *(const upb_map**)field_mem; + const upb_msglayout *entry = m->submsgs[f->submsg_index]; + const upb_msglayout_field *key_field = &entry->fields[0]; + const upb_msglayout_field *val_field = &entry->fields[1]; + upb_strtable_iter i; + if (map == NULL) { + return true; + } + + upb_strtable_begin(&i, &map->table); + for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { + size_t pre_len = e->limit - e->ptr; + size_t size; + upb_strview key = upb_strtable_iter_key(&i); + const upb_value val = upb_strtable_iter_value(&i); + const void *keyp = + map->key_size == UPB_MAPTYPE_STRING ? (void *)&key : key.data; + const void *valp = + map->val_size == UPB_MAPTYPE_STRING ? upb_value_getptr(val) : &val; + + CHK(upb_encode_scalarfield(e, valp, entry, val_field, false)); + CHK(upb_encode_scalarfield(e, keyp, entry, key_field, false)); + size = (e->limit - e->ptr) - pre_len; + CHK(upb_put_varint(e, size)); + CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); + } + + return true; } + bool upb_encode_message(upb_encstate *e, const char *msg, const upb_msglayout *m, size_t *size) { int i; @@ -1068,11 +1107,19 @@ bool upb_encode_message(upb_encstate *e, const char *msg, const char *unknown; size_t unknown_size; + unknown = upb_msg_getunknown(msg, &unknown_size); + + if (unknown) { + upb_put_bytes(e, unknown, unknown_size); + } + for (i = m->field_count - 1; i >= 0; i--) { const upb_msglayout_field *f = &m->fields[i]; - if (f->label == UPB_LABEL_REPEATED) { + if (_upb_isrepeated(f)) { CHK(upb_encode_array(e, msg + f->offset, m, f)); + } else if (f->label == _UPB_LABEL_MAP) { + CHK(upb_encode_map(e, msg + f->offset, m, f)); } else { bool skip_empty = false; if (f->presence == 0) { @@ -1093,12 +1140,6 @@ bool upb_encode_message(upb_encstate *e, const char *msg, } } - unknown = upb_msg_getunknown(msg, &unknown_size); - - if (unknown) { - upb_put_bytes(e, unknown, unknown_size); - } - *size = (e->limit - e->ptr) - pre_len; return true; } @@ -1132,24 +1173,27 @@ char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena, -#define VOIDPTR_AT(msg, ofs) (void*)((char*)msg + (int)ofs) - -/* Internal members of a upb_msg. We can change this without breaking binary - * compatibility. We put these before the user's data. The user's upb_msg* - * points after the upb_msg_internal. */ +/** upb_msg *******************************************************************/ -/* Used when a message is not extendable. */ -typedef struct { - char *unknown; - size_t unknown_len; - size_t unknown_size; -} upb_msg_internal; +static const char _upb_fieldtype_to_sizelg2[12] = { + 0, + 0, /* UPB_TYPE_BOOL */ + 2, /* UPB_TYPE_FLOAT */ + 2, /* UPB_TYPE_INT32 */ + 2, /* UPB_TYPE_UINT32 */ + 2, /* UPB_TYPE_ENUM */ + UPB_SIZE(2, 3), /* UPB_TYPE_MESSAGE */ + 3, /* UPB_TYPE_DOUBLE */ + 3, /* UPB_TYPE_INT64 */ + 3, /* UPB_TYPE_UINT64 */ + UPB_SIZE(3, 4), /* UPB_TYPE_STRING */ + UPB_SIZE(3, 4), /* UPB_TYPE_BYTES */ +}; -/* Used when a message is extendable. */ -typedef struct { - upb_inttable *extdict; - upb_msg_internal base; -} upb_msg_internal_withext; +static uintptr_t tag_arrptr(void* ptr, int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 <= 4); + return (uintptr_t)ptr | elem_size_lg2; +} static int upb_msg_internalsize(const upb_msglayout *l) { return sizeof(upb_msg_internal) - l->extendable * sizeof(void *); @@ -1160,22 +1204,22 @@ static size_t upb_msg_sizeof(const upb_msglayout *l) { } static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) { - return VOIDPTR_AT(msg, -sizeof(upb_msg_internal)); + return UPB_PTR_AT(msg, -sizeof(upb_msg_internal), upb_msg_internal); } static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) { - return VOIDPTR_AT(msg, -sizeof(upb_msg_internal)); + return UPB_PTR_AT(msg, -sizeof(upb_msg_internal), upb_msg_internal); } static upb_msg_internal_withext *upb_msg_getinternalwithext( upb_msg *msg, const upb_msglayout *l) { UPB_ASSERT(l->extendable); - return VOIDPTR_AT(msg, -sizeof(upb_msg_internal_withext)); + return UPB_PTR_AT(msg, -sizeof(upb_msg_internal_withext), + upb_msg_internal_withext); } -upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a) { - upb_alloc *alloc = upb_arena_alloc(a); - void *mem = upb_malloc(alloc, upb_msg_sizeof(l)); +upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a) { + void *mem = upb_arena_malloc(a, upb_msg_sizeof(l)); upb_msg_internal *in; upb_msg *msg; @@ -1183,7 +1227,7 @@ upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a) { return NULL; } - msg = VOIDPTR_AT(mem, upb_msg_internalsize(l)); + msg = UPB_PTR_AT(mem, upb_msg_internalsize(l), upb_msg); /* Initialize normal members. */ memset(msg, 0, l->size); @@ -1201,66 +1245,122 @@ upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a) { return msg; } -upb_array *upb_array_new(upb_arena *a) { - upb_array *ret = upb_arena_malloc(a, sizeof(upb_array)); - - if (!ret) { - return NULL; - } - - ret->data = NULL; - ret->len = 0; - ret->size = 0; - - return ret; -} - -void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, - upb_arena *arena) { +bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, + upb_arena *arena) { upb_msg_internal *in = upb_msg_getinternal(msg); if (len > in->unknown_size - in->unknown_len) { upb_alloc *alloc = upb_arena_alloc(arena); size_t need = in->unknown_size + len; size_t newsize = UPB_MAX(in->unknown_size * 2, need); - in->unknown = upb_realloc(alloc, in->unknown, in->unknown_size, newsize); + void *mem = upb_realloc(alloc, in->unknown, in->unknown_size, newsize); + if (!mem) return false; + in->unknown = mem; in->unknown_size = newsize; } memcpy(in->unknown + in->unknown_len, data, len); in->unknown_len += len; + return true; } const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { - const upb_msg_internal* in = upb_msg_getinternal_const(msg); + const upb_msg_internal *in = upb_msg_getinternal_const(msg); *len = in->unknown_len; return in->unknown; } -#undef VOIDPTR_AT +/** upb_array *****************************************************************/ +upb_array *_upb_array_new(upb_arena *a, upb_fieldtype_t type) { + upb_array *arr = upb_arena_malloc(a, sizeof(upb_array)); -#ifdef UPB_MSVC_VSNPRINTF -/* Visual C++ earlier than 2015 doesn't have standard C99 snprintf and - * vsnprintf. To support them, missing functions are manually implemented - * using the existing secure functions. */ -int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg) { - if (!s) { - return _vscprintf(format, arg); + if (!arr) { + return NULL; } - int ret = _vsnprintf_s(s, n, _TRUNCATE, format, arg); - if (ret < 0) { - ret = _vscprintf(format, arg); + + arr->data = tag_arrptr(NULL, _upb_fieldtype_to_sizelg2[type]); + arr->len = 0; + arr->size = 0; + + return arr; +} + +bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) { + size_t new_size = UPB_MAX(arr->size, 4); + int elem_size_lg2 = arr->data & 7; + size_t old_bytes = arr->size << elem_size_lg2; + size_t new_bytes; + void* ptr = _upb_array_ptr(arr); + + /* Log2 ceiling of size. */ + while (new_size < min_size) new_size *= 2; + + new_bytes = new_size << elem_size_lg2; + ptr = upb_arena_realloc(arena, ptr, old_bytes, new_bytes); + + if (!ptr) { + return false; } - return ret; + + arr->data = tag_arrptr(ptr, elem_size_lg2); + arr->size = new_size; + return true; } -int msvc_snprintf(char* s, size_t n, const char* format, ...) { - va_list arg; - va_start(arg, format); - int ret = msvc_vsnprintf(s, n, format, arg); - va_end(arg); - return ret; +static upb_array *getorcreate_array(upb_array **arr_ptr, upb_fieldtype_t type, + upb_arena *arena) { + upb_array *arr = *arr_ptr; + if (!arr) { + arr = _upb_array_new(arena, type); + if (!arr) return NULL; + *arr_ptr = arr; + } + return arr; +} + +static bool resize_array(upb_array *arr, size_t size, upb_arena *arena) { + if (size > arr->size && !_upb_array_realloc(arr, size, arena)) { + return false; + } + + arr->len = size; + return true; +} + +void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size, + upb_fieldtype_t type, upb_arena *arena) { + upb_array *arr = getorcreate_array(arr_ptr, type, arena); + return arr && resize_array(arr, size, arena) ? _upb_array_ptr(arr) : NULL; +} + +bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value, + upb_fieldtype_t type, upb_arena *arena) { + upb_array *arr = getorcreate_array(arr_ptr, type, arena); + size_t elem = arr->len; + int lg2 = _upb_fieldtype_to_sizelg2[type]; + char *data; + + if (!arr || !resize_array(arr, elem + 1, arena)) return false; + + data = _upb_array_ptr(arr); + memcpy(data + (elem << lg2), value, 1 << lg2); + return true; +} + +/** upb_map *******************************************************************/ + +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; + } + + upb_strtable_init2(&map->table, UPB_CTYPE_INT32, upb_arena_alloc(a)); + map->key_size = key_size; + map->val_size = value_size; + + return map; } -#endif /* ** upb_table Implementation ** @@ -1277,12 +1377,6 @@ int msvc_snprintf(char* s, size_t n, const char* format, ...) { #define ARRAY_SIZE(x) \ ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) -static void upb_check_alloc(upb_table *t, upb_alloc *a) { - UPB_UNUSED(t); - UPB_UNUSED(a); - UPB_ASSERT_DEBUGVAR(t->alloc == a); -} - static const double MAX_LOAD = 0.85; /* The minimum utilization of the array part of a mixed hash/array table. This @@ -1361,17 +1455,12 @@ static bool isfull(upb_table *t) { } } -static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2, - upb_alloc *a) { +static bool init(upb_table *t, uint8_t size_lg2, upb_alloc *a) { size_t bytes; t->count = 0; - t->ctype = ctype; t->size_lg2 = size_lg2; t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; -#ifndef NDEBUG - t->alloc = a; -#endif bytes = upb_table_size(t) * sizeof(upb_tabent); if (bytes > 0) { t->entries = upb_malloc(a, bytes); @@ -1384,7 +1473,6 @@ static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2, } static void uninit(upb_table *t, upb_alloc *a) { - upb_check_alloc(t, a); upb_free(a, mutable_entries(t)); } @@ -1420,7 +1508,7 @@ static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v, const upb_tabent *e = findentry(t, key, hash, eql); if (e) { if (v) { - _upb_value_setval(v, e->val.val, t->ctype); + _upb_value_setval(v, e->val.val); } return true; } else { @@ -1436,7 +1524,6 @@ static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, upb_tabent *our_e; UPB_ASSERT(findentry(t, key, hash, eql) == NULL); - UPB_ASSERT_DEBUGVAR(val.ctype == t->ctype); t->count++; mainpos_e = getentry_mutable(t, hash); @@ -1482,7 +1569,7 @@ static bool rm(upb_table *t, lookupkey_t key, upb_value *val, if (eql(chain->key, key)) { /* Element to remove is at the head of its chain. */ t->count--; - if (val) _upb_value_setval(val, chain->val.val, t->ctype); + if (val) _upb_value_setval(val, chain->val.val); if (removed) *removed = chain->key; if (chain->next) { upb_tabent *move = (upb_tabent*)chain->next; @@ -1502,7 +1589,7 @@ static bool rm(upb_table *t, lookupkey_t key, upb_value *val, /* Found element to remove. */ upb_tabent *rm = (upb_tabent*)chain->next; t->count--; - if (val) _upb_value_setval(val, chain->next->val.val, t->ctype); + if (val) _upb_value_setval(val, chain->next->val.val); if (removed) *removed = rm->key; rm->key = 0; /* Make the slot empty. */ chain->next = rm->next; @@ -1555,7 +1642,13 @@ static bool streql(upb_tabkey k1, lookupkey_t k2) { } bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) { - return init(&t->t, ctype, 2, a); + return init(&t->t, 2, 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); } void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) { @@ -1569,18 +1662,14 @@ bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a) { upb_strtable new_table; upb_strtable_iter i; - upb_check_alloc(&t->t, a); - - if (!init(&new_table.t, t->t.ctype, size_lg2, a)) + if (!init(&new_table.t, size_lg2, a)) return false; upb_strtable_begin(&i, t); for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) { + upb_strview key = upb_strtable_iter_key(&i); upb_strtable_insert3( - &new_table, - upb_strtable_iter_key(&i), - upb_strtable_iter_keylength(&i), - upb_strtable_iter_value(&i), - a); + &new_table, key.data, key.size, + upb_strtable_iter_value(&i), a); } upb_strtable_uninit2(t, a); *t = new_table; @@ -1593,8 +1682,6 @@ bool upb_strtable_insert3(upb_strtable *t, const char *k, size_t len, upb_tabkey tabkey; uint32_t hash; - upb_check_alloc(&t->t, a); - if (isfull(&t->t)) { /* Need to resize. New table of double the size, add old elements to it. */ if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) { @@ -1622,7 +1709,10 @@ bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len, uint32_t hash = upb_murmur_hash2(key, len, 0); upb_tabkey tabkey; if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) { - upb_free(alloc, (void*)tabkey); + if (alloc) { + /* Arena-based allocs don't need to free and won't pass this. */ + upb_free(alloc, (void*)tabkey); + } return true; } else { return false; @@ -1631,10 +1721,6 @@ bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len, /* Iteration */ -static 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) { i->t = t; i->index = begin(&t->t); @@ -1650,21 +1736,18 @@ bool upb_strtable_done(const upb_strtable_iter *i) { upb_tabent_isempty(str_tabent(i)); } -const char *upb_strtable_iter_key(const upb_strtable_iter *i) { - UPB_ASSERT(!upb_strtable_done(i)); - return upb_tabstr(str_tabent(i)->key, NULL); -} - -size_t upb_strtable_iter_keylength(const upb_strtable_iter *i) { +upb_strview upb_strtable_iter_key(const upb_strtable_iter *i) { + upb_strview key; uint32_t len; UPB_ASSERT(!upb_strtable_done(i)); - upb_tabstr(str_tabent(i)->key, &len); - return len; + key.data = upb_tabstr(str_tabent(i)->key, &len); + key.size = len; + return key; } upb_value upb_strtable_iter_value(const upb_strtable_iter *i) { UPB_ASSERT(!upb_strtable_done(i)); - return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype); + return _upb_value_val(str_tabent(i)->val.val); } void upb_strtable_iter_setdone(upb_strtable_iter *i) { @@ -1730,11 +1813,11 @@ static void check(upb_inttable *t) { #endif } -bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype, - size_t asize, int hsize_lg2, upb_alloc *a) { +bool upb_inttable_sizedinit(upb_inttable *t, size_t asize, int hsize_lg2, + upb_alloc *a) { size_t array_bytes; - if (!init(&t->t, ctype, hsize_lg2, a)) return false; + 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); @@ -1751,7 +1834,7 @@ bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype, } bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) { - return upb_inttable_sizedinit(t, ctype, 0, 4, a); + return upb_inttable_sizedinit(t, 0, 4, a); } void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) { @@ -1765,8 +1848,6 @@ bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val, tabval.val = val.val; UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */ - upb_check_alloc(&t->t, a); - if (key < t->array_size) { UPB_ASSERT(!upb_arrhas(t->array[key])); t->array_count++; @@ -1777,7 +1858,7 @@ bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val, size_t i; upb_table new_table; - if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1, a)) { + if (!init(&new_table, t->t.size_lg2 + 1, a)) { return false; } @@ -1786,7 +1867,7 @@ bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val, uint32_t hash; upb_value v; - _upb_value_setval(&v, e->val.val, t->t.ctype); + _upb_value_setval(&v, e->val.val); hash = upb_inthash(e->key); insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); } @@ -1805,7 +1886,7 @@ bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val, bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) { const upb_tabval *table_v = inttable_val_const(t, key); if (!table_v) return false; - if (v) _upb_value_setval(v, table_v->val, t->t.ctype); + if (v) _upb_value_setval(v, table_v->val); return true; } @@ -1823,7 +1904,7 @@ bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val) { upb_tabval empty = UPB_TABVALUE_EMPTY_INIT; t->array_count--; if (val) { - _upb_value_setval(val, t->array[key].val, t->t.ctype); + _upb_value_setval(val, t->array[key].val); } mutable_array(t)[key] = empty; success = true; @@ -1838,7 +1919,6 @@ bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val) { } bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) { - upb_check_alloc(&t->t, a); return upb_inttable_insert2(t, upb_inttable_count(t), val, a); } @@ -1851,7 +1931,6 @@ upb_value upb_inttable_pop(upb_inttable *t) { bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val, upb_alloc *a) { - upb_check_alloc(&t->t, a); return upb_inttable_insert2(t, (uintptr_t)key, val, a); } @@ -1876,8 +1955,6 @@ void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) { int size_lg2; upb_inttable new_t; - upb_check_alloc(&t->t, a); - upb_inttable_begin(&i, t); for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { uintptr_t key = upb_inttable_iter_key(&i); @@ -1910,7 +1987,7 @@ void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) { size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; int hashsize_lg2 = log2ceil(hash_size); - upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2, a); + upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a); upb_inttable_begin(&i, t); for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { uintptr_t k = upb_inttable_iter_key(&i); @@ -1976,8 +2053,7 @@ uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) { upb_value upb_inttable_iter_value(const upb_inttable_iter *i) { UPB_ASSERT(!upb_inttable_done(i)); return _upb_value_val( - i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val, - i->t->t.ctype); + i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val); } void upb_inttable_iter_setdone(upb_inttable_iter *i) { @@ -2017,7 +2093,8 @@ uint32_t upb_murmur_hash2(const void *key, size_t len, uint32_t seed) { /* Mix 4 bytes at a time into the hash */ const uint8_t * data = (const uint8_t *)key; while(len >= 4) { - uint32_t k = *(uint32_t *)data; + uint32_t k; + memcpy(&k, data, sizeof(k)); k *= m; k ^= k >> r; @@ -2182,17 +2259,6 @@ uint32_t upb_murmur_hash2(const void * key, size_t len, uint32_t seed) { #include -/* Guarantee null-termination and provide ellipsis truncation. - * It may be tempting to "optimize" this by initializing these final - * four bytes up-front and then being careful never to overwrite them, - * this is safer and simpler. */ -static void nullz(upb_status *status) { - const char *ellipsis = "..."; - size_t len = strlen(ellipsis); - UPB_ASSERT(sizeof(status->msg) > len); - memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len); -} - /* upb_status *****************************************************************/ void upb_status_clear(upb_status *status) { @@ -2208,8 +2274,8 @@ const char *upb_status_errmsg(const upb_status *status) { return status->msg; } void upb_status_seterrmsg(upb_status *status, const char *msg) { if (!status) return; status->ok = false; - strncpy(status->msg, msg, sizeof(status->msg)); - nullz(status); + strncpy(status->msg, msg, UPB_STATUS_MAX_MESSAGE - 1); + status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0'; } void upb_status_seterrf(upb_status *status, const char *fmt, ...) { @@ -2223,7 +2289,7 @@ void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { if (!status) return; status->ok = false; _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); - nullz(status); + status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0'; } /* upb_alloc ******************************************************************/ @@ -2245,190 +2311,216 @@ upb_alloc upb_alloc_global = {&upb_global_allocfunc}; /* upb_arena ******************************************************************/ /* Be conservative and choose 16 in case anyone is using SSE. */ -static const size_t maxalign = 16; -static size_t align_up_max(size_t size) { - return ((size + maxalign - 1) / maxalign) * maxalign; -} +typedef struct mem_block { + struct mem_block *next; + uint32_t size; + uint32_t cleanups; + /* Data follows. */ +} mem_block; + +typedef struct cleanup_ent { + upb_cleanup_func *cleanup; + void *ud; +} cleanup_ent; struct upb_arena { - /* We implement the allocator interface. - * This must be the first member of upb_arena! */ - upb_alloc alloc; + _upb_arena_head head; + uint32_t *cleanups; /* Allocator to allocate arena blocks. We are responsible for freeing these * when we are destroyed. */ upb_alloc *block_alloc; + uint32_t last_size; - size_t bytes_allocated; - size_t next_block_size; - size_t max_block_size; - - /* Linked list of blocks. Points to an arena_block, defined in env.c */ - void *block_head; + /* 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. */ + uint32_t refcount; /* Only used when a->parent == a */ + struct upb_arena *parent; - /* Cleanup entries. Pointer to a cleanup_ent, defined in env.c */ - void *cleanup_head; + /* Linked list of blocks to free/cleanup. */ + mem_block *freelist, *freelist_tail; }; -typedef struct mem_block { - struct mem_block *next; - size_t size; - size_t used; - bool owned; - /* Data follows. */ -} mem_block; - -typedef struct cleanup_ent { - struct cleanup_ent *next; - upb_cleanup_func *cleanup; - void *ud; -} cleanup_ent; +static const size_t memblock_reserve = UPB_ALIGN_UP(sizeof(mem_block), 16); -static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size, - bool owned) { +static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size) { mem_block *block = ptr; - block->next = a->block_head; + block->next = a->freelist; block->size = size; - block->used = align_up_max(sizeof(mem_block)); - block->owned = owned; + block->cleanups = 0; + a->freelist = block; + a->last_size = size; + if (!a->freelist_tail) a->freelist_tail = block; - a->block_head = block; + a->head.ptr = UPB_PTR_AT(block, memblock_reserve, char); + a->head.end = UPB_PTR_AT(block, size, char); + a->cleanups = &block->cleanups; /* TODO(haberman): ASAN poison. */ } -static mem_block *upb_arena_allocblock(upb_arena *a, size_t size) { - size_t block_size = UPB_MAX(size, a->next_block_size) + sizeof(mem_block); +static bool upb_arena_allocblock(upb_arena *a, size_t size) { + size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve; mem_block *block = upb_malloc(a->block_alloc, block_size); - if (!block) { - return NULL; - } + if (!block) return false; + upb_arena_addblock(a, block, block_size); + return true; +} - upb_arena_addblock(a, block, block_size, true); - a->next_block_size = UPB_MIN(block_size * 2, a->max_block_size); +static bool arena_has(upb_arena *a, size_t size) { + _upb_arena_head *h = (_upb_arena_head*)a; + return (size_t)(h->end - h->ptr) >= size; +} - return block; +void *_upb_arena_slowmalloc(upb_arena *a, size_t size) { + if (!upb_arena_allocblock(a, size)) return NULL; /* Out of memory. */ + UPB_ASSERT(arena_has(a, size)); + return upb_arena_malloc(a, size); } static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize, size_t size) { upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */ - mem_block *block = a->block_head; - void *ret; + return upb_arena_realloc(a, ptr, oldsize, size); +} - if (size == 0) { - return NULL; /* We are an arena, don't need individual frees. */ +static upb_arena *arena_findroot(upb_arena *a) { + /* Path splitting keeps time complexity down, see: + * https://en.wikipedia.org/wiki/Disjoint-set_data_structure */ + while (a->parent != a) { + upb_arena *next = a->parent; + a->parent = next->parent; + a = next; } + return a; +} - size = align_up_max(size); - - /* TODO(haberman): special-case if this is a realloc of the last alloc? */ +/* Public Arena API ***********************************************************/ - if (!block || block->size - block->used < size) { - /* Slow path: have to allocate a new block. */ - block = upb_arena_allocblock(a, size); +upb_arena *arena_initslow(void *mem, size_t n, upb_alloc *alloc) { + const size_t first_block_overhead = sizeof(upb_arena) + memblock_reserve; + upb_arena *a; - if (!block) { - return NULL; /* Out of memory. */ - } + /* We need to malloc the initial block. */ + n = first_block_overhead + 256; + if (!alloc || !(mem = upb_malloc(alloc, n))) { + return NULL; } - ret = (char*)block + block->used; - block->used += size; + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_arena); + n -= sizeof(*a); - if (oldsize > 0) { - memcpy(ret, ptr, oldsize); /* Preserve existing data. */ - } + a->head.alloc.func = &upb_arena_doalloc; + a->block_alloc = alloc; + a->parent = a; + a->refcount = 1; + a->freelist = NULL; + a->freelist_tail = NULL; - /* TODO(haberman): ASAN unpoison. */ + upb_arena_addblock(a, mem, n); - a->bytes_allocated += size; - return ret; + return a; } -/* Public Arena API ***********************************************************/ - -#define upb_alignof(type) offsetof (struct { char c; type member; }, member) - upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc) { - const size_t first_block_overhead = sizeof(upb_arena) + sizeof(mem_block); upb_arena *a; - bool owned = false; /* Round block size down to alignof(*a) since we will allocate the arena * itself at the end. */ - n &= ~(upb_alignof(upb_arena) - 1); + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_arena)); - if (n < first_block_overhead) { - /* We need to malloc the initial block. */ - n = first_block_overhead + 256; - owned = true; - if (!alloc || !(mem = upb_malloc(alloc, n))) { - return NULL; - } + if (UPB_UNLIKELY(n < sizeof(upb_arena))) { + return arena_initslow(mem, n, alloc); } - a = (void*)((char*)mem + n - sizeof(*a)); + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_arena); n -= sizeof(*a); - a->alloc.func = &upb_arena_doalloc; - a->block_alloc = &upb_alloc_global; - a->bytes_allocated = 0; - a->next_block_size = 256; - a->max_block_size = 16384; - a->cleanup_head = NULL; - a->block_head = NULL; + a->head.alloc.func = &upb_arena_doalloc; a->block_alloc = alloc; - - upb_arena_addblock(a, mem, n, owned); + a->parent = a; + a->refcount = 1; + a->last_size = 128; + a->head.ptr = mem; + a->head.end = UPB_PTR_AT(mem, n, char); + a->freelist = NULL; + a->cleanups = NULL; return a; } -#undef upb_alignof - -void upb_arena_free(upb_arena *a) { - cleanup_ent *ent = a->cleanup_head; - mem_block *block = a->block_head; - - while (ent) { - ent->cleanup(ent->ud); - ent = ent->next; - } +static void arena_dofree(upb_arena *a) { + mem_block *block = a->freelist; + UPB_ASSERT(a->parent == a); + UPB_ASSERT(a->refcount == 0); - /* Must do this after running cleanup functions, because this will delete - * the memory we store our cleanup entries in! */ while (block) { /* Load first since we are deleting block. */ mem_block *next = block->next; - if (block->owned) { - upb_free(a->block_alloc, block); + if (block->cleanups > 0) { + cleanup_ent *end = UPB_PTR_AT(block, block->size, void); + cleanup_ent *ptr = end - block->cleanups; + + for (; ptr < end; ptr++) { + ptr->cleanup(ptr->ud); + } } + upb_free(a->block_alloc, block); block = next; } } +void upb_arena_free(upb_arena *a) { + a = arena_findroot(a); + if (--a->refcount == 0) arena_dofree(a); +} + bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func) { - cleanup_ent *ent = upb_malloc(&a->alloc, sizeof(cleanup_ent)); - if (!ent) { - return false; /* Out of memory. */ + cleanup_ent *ent; + + if (!a->cleanups || !arena_has(a, sizeof(cleanup_ent))) { + if (!upb_arena_allocblock(a, 128)) return false; /* Out of memory. */ + UPB_ASSERT(arena_has(a, sizeof(cleanup_ent))); } + a->head.end -= sizeof(cleanup_ent); + ent = (cleanup_ent*)a->head.end; + (*a->cleanups)++; + ent->cleanup = func; ent->ud = ud; - ent->next = a->cleanup_head; - a->cleanup_head = ent; return true; } -size_t upb_arena_bytesallocated(const upb_arena *a) { - return a->bytes_allocated; +void upb_arena_fuse(upb_arena *a1, upb_arena *a2) { + upb_arena *r1 = arena_findroot(a1); + upb_arena *r2 = arena_findroot(a2); + + if (r1 == r2) return; /* Already fused. */ + + /* We want to join the smaller tree to the larger tree. + * So swap first if they are backwards. */ + if (r1->refcount < r2->refcount) { + upb_arena *tmp = r1; + r1 = r2; + r2 = tmp; + } + + /* r1 takes over r2's freelist and refcount. */ + r1->refcount += r2->refcount; + if (r2->freelist_tail) { + UPB_ASSERT(r2->freelist_tail->next == NULL); + r2->freelist_tail->next = r1->freelist; + r1->freelist = r2->freelist; + } + r2->parent = r1; } /* This file was generated by upbc (the upb compiler) from the input * file: @@ -2559,23 +2651,24 @@ static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1 &google_protobuf_FieldOptions_msginit, }; -static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[10] = { - {1, UPB_SIZE(32, 32), 5, 0, 9, 1}, - {2, UPB_SIZE(40, 48), 6, 0, 9, 1}, +static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = { + {1, UPB_SIZE(36, 40), 6, 0, 9, 1}, + {2, UPB_SIZE(44, 56), 7, 0, 9, 1}, {3, UPB_SIZE(24, 24), 3, 0, 5, 1}, {4, UPB_SIZE(8, 8), 1, 0, 14, 1}, {5, UPB_SIZE(16, 16), 2, 0, 14, 1}, - {6, UPB_SIZE(48, 64), 7, 0, 9, 1}, - {7, UPB_SIZE(56, 80), 8, 0, 9, 1}, - {8, UPB_SIZE(72, 112), 10, 0, 11, 1}, + {6, UPB_SIZE(52, 72), 8, 0, 9, 1}, + {7, UPB_SIZE(60, 88), 9, 0, 9, 1}, + {8, UPB_SIZE(76, 120), 11, 0, 11, 1}, {9, UPB_SIZE(28, 28), 4, 0, 5, 1}, - {10, UPB_SIZE(64, 96), 9, 0, 9, 1}, + {10, UPB_SIZE(68, 104), 10, 0, 9, 1}, + {17, UPB_SIZE(32, 32), 5, 0, 8, 1}, }; const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = { &google_protobuf_FieldDescriptorProto_submsgs[0], &google_protobuf_FieldDescriptorProto__fields[0], - UPB_SIZE(80, 128), 10, false, + UPB_SIZE(80, 128), 11, false, }; static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = { @@ -2870,8 +2963,8 @@ const upb_msglayout google_protobuf_SourceCodeInfo_msginit = { }; static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, UPB_SIZE(20, 40), 0, 0, 5, 3}, - {2, UPB_SIZE(24, 48), 0, 0, 5, 3}, + {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_LABEL_PACKED}, + {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_LABEL_PACKED}, {3, UPB_SIZE(4, 8), 1, 0, 9, 1}, {4, UPB_SIZE(12, 24), 2, 0, 9, 1}, {6, UPB_SIZE(28, 56), 0, 0, 9, 3}, @@ -2898,7 +2991,7 @@ const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = { }; static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { - {1, UPB_SIZE(20, 32), 0, 0, 5, 3}, + {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED}, {2, UPB_SIZE(12, 16), 3, 0, 9, 1}, {3, UPB_SIZE(4, 4), 1, 0, 5, 1}, {4, UPB_SIZE(8, 8), 2, 0, 5, 1}, @@ -2937,6 +3030,7 @@ struct upb_fielddef { const upb_filedef *file; const upb_msgdef *msgdef; const char *full_name; + const char *json_name; union { int64_t sint; uint64_t uint; @@ -2952,16 +3046,19 @@ struct upb_fielddef { const google_protobuf_FieldDescriptorProto *unresolved; } sub; uint32_t number_; - uint32_t index_; + uint16_t index_; + uint16_t layout_index; uint32_t selector_base; /* Used to index into a upb::Handlers table. */ bool is_extension_; bool lazy_; bool packed_; + bool proto3_optional_; upb_descriptortype_t type_; upb_label_t label_; }; struct upb_msgdef { + const upb_msglayout *layout; const upb_filedef *file; const char *full_name; uint32_t selector_count; @@ -2975,6 +3072,7 @@ struct upb_msgdef { const upb_oneofdef *oneofs; int field_count; int oneof_count; + int real_oneof_count; /* Is this a map-entry message? */ bool map_entry; @@ -3025,10 +3123,15 @@ struct upb_symtab { /* Inside a symtab we store tagged pointers to specific def types. */ typedef enum { - UPB_DEFTYPE_MSG = 0, - UPB_DEFTYPE_ENUM = 1, - UPB_DEFTYPE_FIELD = 2, - UPB_DEFTYPE_ONEOF = 3 + UPB_DEFTYPE_FIELD = 0, + + /* Only inside symtab table. */ + UPB_DEFTYPE_MSG = 1, + UPB_DEFTYPE_ENUM = 2, + + /* Only inside message table. */ + UPB_DEFTYPE_ONEOF = 1, + UPB_DEFTYPE_FIELD_JSONNAME = 2 } upb_deftype_t; static const void *unpack_def(upb_value v, upb_deftype_t type) { @@ -3141,11 +3244,14 @@ static uint32_t upb_handlers_selectorcount(const upb_fielddef *f) { return ret; } +static void upb_status_setoom(upb_status *status) { + upb_status_seterrmsg(status, "out of memory"); +} + static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the * lowest indexes, but we do not publicly guarantee this. */ upb_msg_field_iter j; - upb_msg_oneof_iter k; int i; uint32_t selector; int n = upb_msgdef_numfields(m); @@ -3186,14 +3292,38 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { } m->selector_count = selector; - for(upb_msg_oneof_begin(&k, m), i = 0; - !upb_msg_oneof_done(&k); - upb_msg_oneof_next(&k), i++) { - upb_oneofdef *o = (upb_oneofdef*)upb_msg_iter_oneof(&k); - o->index = i; + upb_gfree(fields); + return true; +} + +static bool check_oneofs(upb_msgdef *m, upb_status *s) { + int i; + int first_synthetic = -1; + upb_oneofdef *mutable_oneofs = (upb_oneofdef*)m->oneofs; + + for (i = 0; i < m->oneof_count; i++) { + mutable_oneofs[i].index = i; + + if (upb_oneofdef_issynthetic(&mutable_oneofs[i])) { + if (first_synthetic == -1) { + first_synthetic = i; + } + } else { + if (first_synthetic != -1) { + upb_status_seterrf( + s, "Synthetic oneofs must be after all other oneofs: %s", + upb_oneofdef_name(&mutable_oneofs[i])); + return false; + } + } + } + + if (first_synthetic == -1) { + m->real_oneof_count = m->oneof_count; + } else { + m->real_oneof_count = first_synthetic; } - upb_gfree(fields); return true; } @@ -3261,7 +3391,7 @@ int32_t upb_enumdef_default(const upb_enumdef *e) { } int upb_enumdef_numvals(const upb_enumdef *e) { - return upb_strtable_count(&e->ntoi); + return (int)upb_strtable_count(&e->ntoi); } void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) { @@ -3289,7 +3419,7 @@ const char *upb_enumdef_iton(const upb_enumdef *def, int32_t num) { } const char *upb_enum_iter_name(upb_enum_iter *iter) { - return upb_strtable_iter_key(iter); + return upb_strtable_iter_key(iter).data; } int32_t upb_enum_iter_number(upb_enum_iter *iter) { @@ -3364,53 +3494,22 @@ bool upb_fielddef_lazy(const upb_fielddef *f) { bool upb_fielddef_packed(const upb_fielddef *f) { return f->packed_; -} - -const char *upb_fielddef_name(const upb_fielddef *f) { - return shortdefname(f->full_name); -} - -uint32_t upb_fielddef_selectorbase(const upb_fielddef *f) { - return f->selector_base; -} - -size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len) { - const char *name = upb_fielddef_name(f); - size_t src, dst = 0; - bool ucase_next = false; - -#define WRITE(byte) \ - ++dst; \ - if (dst < len) buf[dst - 1] = byte; \ - else if (dst == len) buf[dst - 1] = '\0' - - if (!name) { - WRITE('\0'); - return 0; - } +} - /* Implement the transformation as described in the spec: - * 1. upper case all letters after an underscore. - * 2. remove all underscores. - */ - for (src = 0; name[src]; src++) { - if (name[src] == '_') { - ucase_next = true; - continue; - } +const char *upb_fielddef_name(const upb_fielddef *f) { + return shortdefname(f->full_name); +} - if (ucase_next) { - WRITE(toupper(name[src])); - ucase_next = false; - } else { - WRITE(name[src]); - } - } +const char *upb_fielddef_jsonname(const upb_fielddef *f) { + return f->json_name; +} - WRITE('\0'); - return dst; +uint32_t upb_fielddef_selectorbase(const upb_fielddef *f) { + return f->selector_base; +} -#undef WRITE +const upb_filedef *upb_fielddef_file(const upb_fielddef *f) { + return f->file; } const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { @@ -3421,6 +3520,11 @@ const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) { return f->oneof; } +const upb_oneofdef *upb_fielddef_realcontainingoneof(const upb_fielddef *f) { + if (!f->oneof || upb_oneofdef_issynthetic(f->oneof)) return NULL; + return f->oneof; +} + static void chkdefaulttype(const upb_fielddef *f, int ctype) { UPB_UNUSED(f); UPB_UNUSED(ctype); @@ -3433,7 +3537,7 @@ int64_t upb_fielddef_defaultint64(const upb_fielddef *f) { int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { chkdefaulttype(f, UPB_TYPE_INT32); - return f->defaultval.sint; + return (int32_t)f->defaultval.sint; } uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { @@ -3443,7 +3547,7 @@ uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) { chkdefaulttype(f, UPB_TYPE_UINT32); - return f->defaultval.uint; + return (uint32_t)f->defaultval.uint; } bool upb_fielddef_defaultbool(const upb_fielddef *f) { @@ -3485,6 +3589,10 @@ const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f) { return f->sub.enumdef; } +const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f) { + return &f->msgdef->layout->fields[f->layout_index]; +} + bool upb_fielddef_issubmsg(const upb_fielddef *f) { return upb_fielddef_type(f) == UPB_TYPE_MESSAGE; } @@ -3513,8 +3621,8 @@ bool upb_fielddef_hassubdef(const upb_fielddef *f) { bool upb_fielddef_haspresence(const upb_fielddef *f) { if (upb_fielddef_isseq(f)) return false; - if (upb_fielddef_issubmsg(f)) return true; - return f->file->syntax == UPB_SYNTAX_PROTO2; + return upb_fielddef_issubmsg(f) || upb_fielddef_containingoneof(f) || + f->file->syntax == UPB_SYNTAX_PROTO2; } static bool between(int32_t x, int32_t low, int32_t high) { @@ -3593,18 +3701,43 @@ bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len, *o = unpack_def(val, UPB_DEFTYPE_ONEOF); *f = unpack_def(val, UPB_DEFTYPE_FIELD); - UPB_ASSERT((*o != NULL) ^ (*f != NULL)); /* Exactly one of the two should be set. */ - return true; + return *o || *f; /* False if this was a JSON name. */ +} + +const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m, + const char *name, size_t len) { + upb_value val; + const upb_fielddef* f; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return NULL; + } + + f = unpack_def(val, UPB_DEFTYPE_FIELD); + if (!f) f = unpack_def(val, UPB_DEFTYPE_FIELD_JSONNAME); + + return f; } int upb_msgdef_numfields(const upb_msgdef *m) { - /* The number table contains only fields. */ - return upb_inttable_count(&m->itof); + return m->field_count; } int upb_msgdef_numoneofs(const upb_msgdef *m) { - /* The name table includes oneofs, and the number table does not. */ - return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof); + return m->oneof_count; +} + +int upb_msgdef_numrealoneofs(const upb_msgdef *m) { + return m->real_oneof_count; +} + +const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m) { + return m->layout; +} + +const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i) { + if (i >= m->field_count) return NULL; + return &m->fields[i]; } bool upb_msgdef_mapentry(const upb_msgdef *m) { @@ -3689,13 +3822,23 @@ const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { } int upb_oneofdef_numfields(const upb_oneofdef *o) { - return upb_strtable_count(&o->ntof); + return (int)upb_strtable_count(&o->ntof); } uint32_t upb_oneofdef_index(const upb_oneofdef *o) { return o->index; } +bool upb_oneofdef_issynthetic(const upb_oneofdef *o) { + upb_inttable_iter iter; + const upb_fielddef *f; + upb_inttable_begin(&iter, &o->itof); + if (upb_oneofdef_numfields(o) != 1) return false; + f = upb_value_getptr(upb_inttable_iter_value(&iter)); + UPB_ASSERT(f); + return f->proto3_optional_; +} + const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o, const char *name, size_t length) { upb_value val; @@ -3729,6 +3872,215 @@ void upb_oneof_iter_setdone(upb_oneof_iter *iter) { upb_inttable_iter_setdone(iter); } +/* Dynamic Layout Generation. *************************************************/ + +static size_t div_round_up(size_t n, size_t d) { + return (n + d - 1) / d; +} + +static size_t upb_msgval_sizeof(upb_fieldtype_t type) { + switch (type) { + case UPB_TYPE_DOUBLE: + case UPB_TYPE_INT64: + case UPB_TYPE_UINT64: + return 8; + case UPB_TYPE_ENUM: + case UPB_TYPE_INT32: + case UPB_TYPE_UINT32: + case UPB_TYPE_FLOAT: + return 4; + case UPB_TYPE_BOOL: + return 1; + case UPB_TYPE_MESSAGE: + return sizeof(void*); + case UPB_TYPE_BYTES: + case UPB_TYPE_STRING: + return sizeof(upb_strview); + } + UPB_UNREACHABLE(); +} + +static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { + if (upb_msgdef_mapentry(upb_fielddef_containingtype(f))) { + upb_map_entry ent; + UPB_ASSERT(sizeof(ent.k) == sizeof(ent.v)); + return sizeof(ent.k); + } else if (upb_fielddef_isseq(f)) { + return sizeof(void*); + } else { + return upb_msgval_sizeof(upb_fielddef_type(f)); + } +} + +static uint32_t upb_msglayout_place(upb_msglayout *l, size_t size) { + uint32_t ret; + + l->size = UPB_ALIGN_UP(l->size, size); + ret = l->size; + l->size += size; + return ret; +} + +/* This function is the dynamic equivalent of message_layout.{cc,h} in upbc. + * It computes a dynamic layout for all of the fields in |m|. */ +static bool make_layout(const upb_symtab *symtab, const upb_msgdef *m) { + upb_msglayout *l = (upb_msglayout*)m->layout; + upb_msg_field_iter it; + upb_msg_oneof_iter oit; + size_t hasbit; + size_t submsg_count = m->submsg_field_count; + const upb_msglayout **submsgs; + upb_msglayout_field *fields; + upb_alloc *alloc = upb_arena_alloc(symtab->arena); + + memset(l, 0, sizeof(*l)); + + fields = upb_malloc(alloc, upb_msgdef_numfields(m) * sizeof(*fields)); + submsgs = upb_malloc(alloc, submsg_count * sizeof(*submsgs)); + + if ((!fields && upb_msgdef_numfields(m)) || + (!submsgs && submsg_count)) { + /* OOM. */ + return false; + } + + l->field_count = upb_msgdef_numfields(m); + l->fields = fields; + l->submsgs = submsgs; + + if (upb_msgdef_mapentry(m)) { + /* TODO(haberman): refactor this method so this special case is more + * elegant. */ + const upb_fielddef *key = upb_msgdef_itof(m, 1); + const upb_fielddef *val = upb_msgdef_itof(m, 2); + fields[0].number = 1; + fields[1].number = 2; + fields[0].label = UPB_LABEL_OPTIONAL; + fields[1].label = UPB_LABEL_OPTIONAL; + fields[0].presence = 0; + fields[1].presence = 0; + fields[0].descriptortype = upb_fielddef_descriptortype(key); + fields[1].descriptortype = upb_fielddef_descriptortype(val); + fields[0].offset = 0; + fields[1].offset = sizeof(upb_strview); + fields[1].submsg_index = 0; + + if (upb_fielddef_type(val) == UPB_TYPE_MESSAGE) { + submsgs[0] = upb_fielddef_msgsubdef(val)->layout; + } + + l->field_count = 2; + l->size = 2 * sizeof(upb_strview); + l->size = UPB_ALIGN_UP(l->size, 8); + return true; + } + + /* Allocate data offsets in three stages: + * + * 1. hasbits. + * 2. regular fields. + * 3. oneof fields. + * + * OPT: There is a lot of room for optimization here to minimize the size. + */ + + /* Allocate hasbits and set basic field attributes. */ + submsg_count = 0; + for (upb_msg_field_begin(&it, m), hasbit = 0; + !upb_msg_field_done(&it); + upb_msg_field_next(&it)) { + upb_fielddef* f = upb_msg_iter_field(&it); + upb_msglayout_field *field = &fields[upb_fielddef_index(f)]; + + field->number = upb_fielddef_number(f); + field->descriptortype = upb_fielddef_descriptortype(f); + field->label = upb_fielddef_label(f); + + if (upb_fielddef_ismap(f)) { + field->label = _UPB_LABEL_MAP; + } else if (upb_fielddef_packed(f)) { + field->label = _UPB_LABEL_PACKED; + } + + /* TODO: we probably should sort the fields by field number to match the + * output of upbc, and to improve search speed for the table parser. */ + f->layout_index = f->index_; + + if (upb_fielddef_issubmsg(f)) { + const upb_msgdef *subm = upb_fielddef_msgsubdef(f); + field->submsg_index = submsg_count++; + submsgs[field->submsg_index] = subm->layout; + } + + if (upb_fielddef_haspresence(f) && !upb_fielddef_realcontainingoneof(f)) { + /* We don't use hasbit 0, so that 0 can indicate "no presence" in the + * table. This wastes one hasbit, but we don't worry about it for now. */ + field->presence = ++hasbit; + } else { + field->presence = 0; + } + } + + /* Account for space used by hasbits. */ + l->size = div_round_up(hasbit, 8); + + /* Allocate non-oneof fields. */ + for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); + upb_msg_field_next(&it)) { + const upb_fielddef* f = upb_msg_iter_field(&it); + size_t field_size = upb_msg_fielddefsize(f); + size_t index = upb_fielddef_index(f); + + if (upb_fielddef_realcontainingoneof(f)) { + /* Oneofs are handled separately below. */ + continue; + } + + fields[index].offset = upb_msglayout_place(l, field_size); + } + + /* Allocate oneof fields. Each oneof field consists of a uint32 for the case + * and space for the actual data. */ + for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit); + upb_msg_oneof_next(&oit)) { + const upb_oneofdef* o = upb_msg_iter_oneof(&oit); + upb_oneof_iter fit; + + size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ + size_t field_size = 0; + uint32_t case_offset; + uint32_t data_offset; + + if (upb_oneofdef_issynthetic(o)) continue; + + /* Calculate field size: the max of all field sizes. */ + for (upb_oneof_begin(&fit, o); + !upb_oneof_done(&fit); + upb_oneof_next(&fit)) { + const upb_fielddef* f = upb_oneof_iter_field(&fit); + field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f)); + } + + /* Align and allocate case offset. */ + case_offset = upb_msglayout_place(l, case_size); + data_offset = upb_msglayout_place(l, field_size); + + for (upb_oneof_begin(&fit, o); + !upb_oneof_done(&fit); + upb_oneof_next(&fit)) { + const upb_fielddef* f = upb_oneof_iter_field(&fit); + fields[upb_fielddef_index(f)].offset = data_offset; + fields[upb_fielddef_index(f)].presence = ~case_offset; + } + } + + /* Size of the entire structure should be a multiple of its greatest + * alignment. TODO: track overall alignment for real? */ + l->size = UPB_ALIGN_UP(l->size, 8); + + return true; +} + /* Code to build defs from descriptor protos. *********************************/ /* There is a question of how much validation to do here. It will be difficult @@ -3741,11 +4093,12 @@ void upb_oneof_iter_setdone(upb_oneof_iter *iter) { typedef struct { const upb_symtab *symtab; - upb_filedef *file; /* File we are building. */ - upb_alloc *alloc; /* Allocate defs here. */ - upb_alloc *tmp; /* Alloc for addtab and any other tmp data. */ - upb_strtable *addtab; /* full_name -> packed def ptr for new defs. */ - upb_status *status; /* Record errors here. */ + upb_filedef *file; /* File we are building. */ + upb_alloc *alloc; /* Allocate defs here. */ + upb_alloc *tmp; /* Alloc for addtab and any other tmp data. */ + upb_strtable *addtab; /* full_name -> packed def ptr for new defs */ + const upb_msglayout **layouts; /* NULL if we should build layouts. */ + upb_status *status; /* Record errors here. */ } symtab_addctx; static char* strviewdup(const symtab_addctx *ctx, upb_strview view) { @@ -3777,6 +4130,51 @@ static const char *makefullname(const symtab_addctx *ctx, const char *prefix, } } +size_t getjsonname(const char *name, char *buf, size_t len) { + size_t src, dst = 0; + bool ucase_next = false; + +#define WRITE(byte) \ + ++dst; \ + if (dst < len) buf[dst - 1] = byte; \ + else if (dst == len) buf[dst - 1] = '\0' + + if (!name) { + WRITE('\0'); + return 0; + } + + /* Implement the transformation as described in the spec: + * 1. upper case all letters after an underscore. + * 2. remove all underscores. + */ + for (src = 0; name[src]; src++) { + if (name[src] == '_') { + ucase_next = true; + continue; + } + + if (ucase_next) { + WRITE(toupper(name[src])); + ucase_next = false; + } else { + WRITE(name[src]); + } + } + + WRITE('\0'); + return dst; + +#undef WRITE +} + +static char* makejsonname(const char* name, upb_alloc *alloc) { + size_t size = getjsonname(name, NULL, 0); + char* json_name = upb_malloc(alloc, size); + getjsonname(name, json_name, size); + return json_name; +} + static bool symtab_add(const symtab_addctx *ctx, const char *name, upb_value v) { upb_value tmp; @@ -3900,7 +4298,7 @@ static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len, } case UPB_TYPE_INT64: { /* XXX: Need to write our own strtoll, since it's not available in c89. */ - long long val = strtol(str, &end, 0); + int64_t val = strtol(str, &end, 0); CHK(val <= INT64_MAX && val >= INT64_MIN && errno != ERANGE && !*end); f->defaultval.sint = val; break; @@ -3913,7 +4311,7 @@ static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len, } case UPB_TYPE_UINT64: { /* XXX: Need to write our own strtoull, since it's not available in c89. */ - unsigned long long val = strtoul(str, &end, 0); + uint64_t val = strtoul(str, &end, 0); CHK(val <= UINT64_MAX && errno != ERANGE && !*end); f->defaultval.uint = val; break; @@ -3990,6 +4388,7 @@ static bool create_fielddef( const google_protobuf_FieldOptions *options; upb_strview name; const char *full_name; + const char *json_name; const char *shortname; uint32_t field_number; @@ -4003,6 +4402,13 @@ static bool create_fielddef( full_name = makefullname(ctx, prefix, name); shortname = shortdefname(full_name); + if (google_protobuf_FieldDescriptorProto_has_json_name(field_proto)) { + json_name = strviewdup( + ctx, google_protobuf_FieldDescriptorProto_json_name(field_proto)); + } else { + json_name = makejsonname(shortname, ctx->alloc); + } + field_number = google_protobuf_FieldDescriptorProto_number(field_proto); if (field_number == 0 || field_number > UPB_MAX_FIELDNUMBER) { @@ -4012,38 +4418,72 @@ static bool create_fielddef( if (m) { /* direct message field. */ - upb_value v, packed_v; + upb_value v, field_v, json_v; + size_t json_size; f = (upb_fielddef*)&m->fields[m->field_count++]; f->msgdef = m; f->is_extension_ = false; - packed_v = pack_def(f, UPB_DEFTYPE_FIELD); - v = upb_value_constptr(f); - - if (!upb_strtable_insert3(&m->ntof, name.data, name.size, packed_v, alloc)) { + if (upb_strtable_lookup(&m->ntof, shortname, NULL)) { upb_status_seterrf(ctx->status, "duplicate field name (%s)", shortname); return false; } - if (!upb_inttable_insert2(&m->itof, field_number, v, alloc)) { + if (upb_strtable_lookup(&m->ntof, json_name, NULL)) { + upb_status_seterrf(ctx->status, "duplicate json_name (%s)", json_name); + return false; + } + + if (upb_inttable_lookup(&m->itof, field_number, NULL)) { upb_status_seterrf(ctx->status, "duplicate field number (%u)", field_number); return false; } + + field_v = pack_def(f, UPB_DEFTYPE_FIELD); + json_v = pack_def(f, UPB_DEFTYPE_FIELD_JSONNAME); + v = upb_value_constptr(f); + json_size = strlen(json_name); + + CHK_OOM( + upb_strtable_insert3(&m->ntof, name.data, name.size, field_v, alloc)); + CHK_OOM(upb_inttable_insert2(&m->itof, field_number, v, alloc)); + + if (strcmp(shortname, json_name) != 0) { + upb_strtable_insert3(&m->ntof, json_name, json_size, json_v, alloc); + } + + if (ctx->layouts) { + const upb_msglayout_field *fields = m->layout->fields; + int count = m->layout->field_count; + bool found = false; + int i; + for (i = 0; i < count; i++) { + if (fields[i].number == field_number) { + f->layout_index = i; + found = true; + break; + } + } + UPB_ASSERT(found); + } } else { /* extension field. */ - f = (upb_fielddef*)&ctx->file->exts[ctx->file->ext_count]; + f = (upb_fielddef*)&ctx->file->exts[ctx->file->ext_count++]; f->is_extension_ = true; CHK_OOM(symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_FIELD))); } f->full_name = full_name; + f->json_name = json_name; f->file = ctx->file; f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); f->number_ = field_number; f->oneof = NULL; + f->proto3_optional_ = + google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); /* 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 @@ -4167,7 +4607,7 @@ static bool create_enumdef( return true; } -static bool create_msgdef(const symtab_addctx *ctx, const char *prefix, +static bool create_msgdef(symtab_addctx *ctx, const char *prefix, const google_protobuf_DescriptorProto *msg_proto) { upb_msgdef *m; const google_protobuf_MessageOptions *options; @@ -4197,6 +4637,14 @@ static bool create_msgdef(const symtab_addctx *ctx, const char *prefix, m->map_entry = google_protobuf_MessageOptions_map_entry(options); } + if (ctx->layouts) { + m->layout = *ctx->layouts; + ctx->layouts++; + } else { + /* Allocate now (to allow cross-linking), populate later. */ + m->layout = upb_malloc(ctx->alloc, sizeof(*m->layout)); + } + oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n); m->oneof_count = 0; m->oneofs = upb_malloc(ctx->alloc, sizeof(*m->oneofs) * n); @@ -4212,6 +4660,7 @@ static bool create_msgdef(const symtab_addctx *ctx, const char *prefix, } CHK(assign_msg_indices(m, ctx->status)); + CHK(check_oneofs(m, ctx->status)); assign_msg_wellknowntype(m); upb_inttable_compact2(&m->itof, ctx->alloc); @@ -4343,7 +4792,7 @@ static bool resolve_fielddef(const symtab_addctx *ctx, const char *prefix, } static bool build_filedef( - const symtab_addctx *ctx, upb_filedef *file, + symtab_addctx *ctx, upb_filedef *file, const google_protobuf_FileDescriptorProto *file_proto) { upb_alloc *alloc = ctx->alloc; const google_protobuf_FileOptions *file_options_proto; @@ -4397,7 +4846,8 @@ static bool build_filedef( } else if (streql_view(syntax, "proto3")) { file->syntax = UPB_SYNTAX_PROTO3; } else { - upb_status_seterrf(ctx->status, "Invalid syntax '%s'", syntax); + upb_status_seterrf(ctx->status, "Invalid syntax '" UPB_STRVIEW_FORMAT "'", + UPB_STRVIEW_ARGS(syntax)); return false; } } else { @@ -4457,7 +4907,7 @@ static bool build_filedef( CHK(create_fielddef(ctx, file->package, NULL, exts[i])); } - /* Now that all names are in the table, resolve references. */ + /* Now that all names are in the table, build layouts and resolve refs. */ for (i = 0; i < file->ext_count; i++) { CHK(resolve_fielddef(ctx, file->package, (upb_fielddef*)&file->exts[i])); } @@ -4470,6 +4920,13 @@ static bool build_filedef( } } + if (!ctx->layouts) { + for (i = 0; i < file->msg_count; i++) { + const upb_msgdef *m = &file->msgs[i]; + make_layout(ctx->symtab, m); + } + } + return true; } @@ -4484,10 +4941,9 @@ static bool upb_symtab_addtotabs(upb_symtab *s, symtab_addctx *ctx, upb_strtable_begin(&iter, ctx->addtab); for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { - const char *key = upb_strtable_iter_key(&iter); - size_t keylen = upb_strtable_iter_keylength(&iter); + upb_strview key = upb_strtable_iter_key(&iter); upb_value value = upb_strtable_iter_value(&iter); - CHK_OOM(upb_strtable_insert3(&s->syms, key, keylen, value, alloc)); + CHK_OOM(upb_strtable_insert3(&s->syms, key.data, key.size, value, alloc)); } return true; @@ -4596,9 +5052,13 @@ const upb_filedef *upb_symtab_lookupfile2( upb_value_getconstptr(v) : NULL; } -const upb_filedef *upb_symtab_addfile( +int upb_symtab_filecount(const upb_symtab *s) { + return (int)upb_strtable_count(&s->files); +} + +static const upb_filedef *_upb_symtab_addfile( upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, - upb_status *status) { + const upb_msglayout **layouts, upb_status *status) { upb_arena *tmparena = upb_arena_new(); upb_strtable addtab; upb_alloc *alloc = upb_arena_alloc(s->arena); @@ -4611,6 +5071,7 @@ const upb_filedef *upb_symtab_addfile( ctx.alloc = alloc; ctx.tmp = upb_arena_alloc(tmparena); ctx.addtab = &addtab; + ctx.layouts = layouts; ctx.status = status; ok = file && @@ -4622,6 +5083,12 @@ const upb_filedef *upb_symtab_addfile( return ok ? file : NULL; } +const upb_filedef *upb_symtab_addfile( + upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, + upb_status *status) { + return _upb_symtab_addfile(s, file_proto, NULL, status); +} + /* Include here since we want most of this file to be stdio-free. */ #include @@ -4657,7 +5124,7 @@ bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) { goto err; } - if (!upb_symtab_addfile(s, file, &status)) goto err; + if (!_upb_symtab_addfile(s, file, init->layouts, &status)) goto err; upb_arena_free(arena); return true; @@ -4673,250 +5140,311 @@ err: #undef CHK_OOM +#include + + +static char field_size[] = { + 0,/* 0 */ + 8, /* UPB_DESCRIPTOR_TYPE_DOUBLE */ + 4, /* UPB_DESCRIPTOR_TYPE_FLOAT */ + 8, /* UPB_DESCRIPTOR_TYPE_INT64 */ + 8, /* UPB_DESCRIPTOR_TYPE_UINT64 */ + 4, /* UPB_DESCRIPTOR_TYPE_INT32 */ + 8, /* UPB_DESCRIPTOR_TYPE_FIXED64 */ + 4, /* UPB_DESCRIPTOR_TYPE_FIXED32 */ + 1, /* UPB_DESCRIPTOR_TYPE_BOOL */ + sizeof(upb_strview), /* UPB_DESCRIPTOR_TYPE_STRING */ + sizeof(void*), /* UPB_DESCRIPTOR_TYPE_GROUP */ + sizeof(void*), /* UPB_DESCRIPTOR_TYPE_MESSAGE */ + sizeof(upb_strview), /* UPB_DESCRIPTOR_TYPE_BYTES */ + 4, /* UPB_DESCRIPTOR_TYPE_UINT32 */ + 4, /* UPB_DESCRIPTOR_TYPE_ENUM */ + 4, /* UPB_DESCRIPTOR_TYPE_SFIXED32 */ + 8, /* UPB_DESCRIPTOR_TYPE_SFIXED64 */ + 4, /* UPB_DESCRIPTOR_TYPE_SINT32 */ + 8, /* UPB_DESCRIPTOR_TYPE_SINT64 */ +}; + +/* Strings/bytes are special-cased in maps. */ +static char _upb_fieldtype_to_mapsize[12] = { + 0, + 1, /* UPB_TYPE_BOOL */ + 4, /* UPB_TYPE_FLOAT */ + 4, /* UPB_TYPE_INT32 */ + 4, /* UPB_TYPE_UINT32 */ + 4, /* UPB_TYPE_ENUM */ + sizeof(void*), /* UPB_TYPE_MESSAGE */ + 8, /* UPB_TYPE_DOUBLE */ + 8, /* UPB_TYPE_INT64 */ + 8, /* UPB_TYPE_UINT64 */ + 0, /* UPB_TYPE_STRING */ + 0, /* UPB_TYPE_BYTES */ +}; + +/** upb_msg *******************************************************************/ -static bool is_power_of_two(size_t val) { - return (val & (val - 1)) == 0; +upb_msg *upb_msg_new(const upb_msgdef *m, upb_arena *a) { + return _upb_msg_new(upb_msgdef_layout(m), a); } -/* Align up to the given power of 2. */ -static size_t align_up(size_t val, size_t align) { - UPB_ASSERT(is_power_of_two(align)); - return (val + align - 1) & ~(align - 1); +static bool in_oneof(const upb_msglayout_field *field) { + return field->presence < 0; } -static size_t div_round_up(size_t n, size_t d) { - return (n + d - 1) / d; +static uint32_t *oneofcase(const upb_msg *msg, + const upb_msglayout_field *field) { + UPB_ASSERT(in_oneof(field)); + return UPB_PTR_AT(msg, -field->presence, uint32_t); } -static size_t upb_msgval_sizeof2(upb_fieldtype_t type) { - switch (type) { - case UPB_TYPE_DOUBLE: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT64: - return 8; - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - case UPB_TYPE_UINT32: - case UPB_TYPE_FLOAT: - return 4; - case UPB_TYPE_BOOL: - return 1; - case UPB_TYPE_MESSAGE: - return sizeof(void*); - case UPB_TYPE_BYTES: - case UPB_TYPE_STRING: - return sizeof(upb_strview); - } - UPB_UNREACHABLE(); +static upb_msgval _upb_msg_getraw(const upb_msg *msg, const upb_fielddef *f) { + const upb_msglayout_field *field = upb_fielddef_layout(f); + const char *mem = UPB_PTR_AT(msg, field->offset, char); + upb_msgval val = {0}; + int size = upb_fielddef_isseq(f) ? sizeof(void *) + : field_size[field->descriptortype]; + memcpy(&val, mem, size); + return val; } -static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { - if (upb_fielddef_isseq(f)) { - return sizeof(void*); +bool upb_msg_has(const upb_msg *msg, const upb_fielddef *f) { + const upb_msglayout_field *field = upb_fielddef_layout(f); + if (in_oneof(field)) { + return *oneofcase(msg, field) == field->number; + } else if (field->presence > 0) { + uint32_t hasbit = field->presence; + return *UPB_PTR_AT(msg, hasbit / 8, uint8_t) & (1 << (hasbit % 8)); } else { - return upb_msgval_sizeof2(upb_fielddef_type(f)); + UPB_ASSERT(field->descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE || + field->descriptortype == UPB_DESCRIPTOR_TYPE_GROUP); + return _upb_msg_getraw(msg, f).msg_val != NULL; } } +bool upb_msg_hasoneof(const upb_msg *msg, const upb_oneofdef *o) { + upb_oneof_iter i; + const upb_fielddef *f; + const upb_msglayout_field *field; -/** upb_msglayout *************************************************************/ - -static void upb_msglayout_free(upb_msglayout *l) { - upb_gfree(l); -} - -static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { - size_t ret; - - l->size = align_up(l->size, size); - ret = l->size; - l->size += size; - return ret; + upb_oneof_begin(&i, o); + if (upb_oneof_done(&i)) return false; + f = upb_oneof_iter_field(&i); + field = upb_fielddef_layout(f); + return *oneofcase(msg, field) != 0; } -static bool upb_msglayout_init(const upb_msgdef *m, - upb_msglayout *l, - upb_msgfactory *factory) { - upb_msg_field_iter it; - upb_msg_oneof_iter oit; - size_t hasbit; - size_t submsg_count = 0; - const upb_msglayout **submsgs; - upb_msglayout_field *fields; - - for (upb_msg_field_begin(&it, m); - !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); - if (upb_fielddef_issubmsg(f)) { - submsg_count++; +upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f) { + if (!upb_fielddef_haspresence(f) || upb_msg_has(msg, f)) { + return _upb_msg_getraw(msg, f); + } else { + /* TODO(haberman): change upb_fielddef to not require this switch(). */ + upb_msgval val = {0}; + switch (upb_fielddef_type(f)) { + case UPB_TYPE_INT32: + case UPB_TYPE_ENUM: + val.int32_val = upb_fielddef_defaultint32(f); + break; + case UPB_TYPE_INT64: + val.int64_val = upb_fielddef_defaultint64(f); + break; + case UPB_TYPE_UINT32: + val.uint32_val = upb_fielddef_defaultuint32(f); + break; + case UPB_TYPE_UINT64: + val.uint64_val = upb_fielddef_defaultuint64(f); + break; + case UPB_TYPE_FLOAT: + val.float_val = upb_fielddef_defaultfloat(f); + break; + case UPB_TYPE_DOUBLE: + val.double_val = upb_fielddef_defaultdouble(f); + break; + case UPB_TYPE_BOOL: + val.double_val = upb_fielddef_defaultbool(f); + break; + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: + val.str_val.data = upb_fielddef_defaultstr(f, &val.str_val.size); + break; + case UPB_TYPE_MESSAGE: + val.msg_val = NULL; + break; } + return val; } +} - memset(l, 0, sizeof(*l)); - - fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields)); - submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs)); - - if ((!fields && upb_msgdef_numfields(m)) || - (!submsgs && submsg_count)) { - /* OOM. */ - upb_gfree(fields); - upb_gfree(submsgs); - return false; - } - - l->field_count = upb_msgdef_numfields(m); - l->fields = fields; - l->submsgs = submsgs; - - /* Allocate data offsets in three stages: - * - * 1. hasbits. - * 2. regular fields. - * 3. oneof fields. - * - * OPT: There is a lot of room for optimization here to minimize the size. - */ - - /* Allocate hasbits and set basic field attributes. */ - submsg_count = 0; - for (upb_msg_field_begin(&it, m), hasbit = 0; - !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); - upb_msglayout_field *field = &fields[upb_fielddef_index(f)]; +upb_mutmsgval upb_msg_mutable(upb_msg *msg, const upb_fielddef *f, + upb_arena *a) { + const upb_msglayout_field *field = upb_fielddef_layout(f); + upb_mutmsgval ret; + char *mem = UPB_PTR_AT(msg, field->offset, char); + bool wrong_oneof = in_oneof(field) && *oneofcase(msg, field) != field->number; - field->number = upb_fielddef_number(f); - field->descriptortype = upb_fielddef_descriptortype(f); - field->label = upb_fielddef_label(f); + memcpy(&ret, mem, sizeof(void*)); - if (upb_fielddef_issubmsg(f)) { - const upb_msglayout *sub_layout = - upb_msgfactory_getlayout(factory, upb_fielddef_msgsubdef(f)); - field->submsg_index = submsg_count++; - submsgs[field->submsg_index] = sub_layout; + if (a && (!ret.msg || wrong_oneof)) { + if (upb_fielddef_ismap(f)) { + const upb_msgdef *entry = upb_fielddef_msgsubdef(f); + const upb_fielddef *key = upb_msgdef_itof(entry, UPB_MAPENTRY_KEY); + const upb_fielddef *value = upb_msgdef_itof(entry, UPB_MAPENTRY_VALUE); + ret.map = upb_map_new(a, upb_fielddef_type(key), upb_fielddef_type(value)); + } else if (upb_fielddef_isseq(f)) { + ret.array = upb_array_new(a, upb_fielddef_type(f)); + } else { + UPB_ASSERT(upb_fielddef_issubmsg(f)); + ret.msg = upb_msg_new(upb_fielddef_msgsubdef(f), a); } - if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { - field->presence = (hasbit++); - } else { - field->presence = 0; + memcpy(mem, &ret, sizeof(void*)); + + if (wrong_oneof) { + *oneofcase(msg, field) = field->number; } } + return ret; +} - /* Account for space used by hasbits. */ - l->size = div_round_up(hasbit, 8); +void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val, + upb_arena *a) { + const upb_msglayout_field *field = upb_fielddef_layout(f); + char *mem = UPB_PTR_AT(msg, field->offset, char); + int size = upb_fielddef_isseq(f) ? sizeof(void *) + : field_size[field->descriptortype]; + memcpy(mem, &val, size); + if (in_oneof(field)) { + *oneofcase(msg, field) = field->number; + } +} - /* Allocate non-oneof fields. */ - for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); - size_t field_size = upb_msg_fielddefsize(f); - size_t index = upb_fielddef_index(f); +bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, + const upb_symtab *ext_pool, const upb_fielddef **out_f, + upb_msgval *out_val, size_t *iter) { + size_t i = *iter; + const upb_msgval zero = {0}; + const upb_fielddef *f; + while ((f = _upb_msgdef_field(m, (int)++i)) != NULL) { + upb_msgval val = _upb_msg_getraw(msg, f); - if (upb_fielddef_containingoneof(f)) { - /* Oneofs are handled separately below. */ - continue; + /* Skip field if unset or empty. */ + if (upb_fielddef_haspresence(f)) { + if (!upb_msg_has(msg, f)) continue; + } else { + upb_msgval test = val; + if (upb_fielddef_isstring(f) && !upb_fielddef_isseq(f)) { + /* Clear string pointer, only size matters (ptr could be non-NULL). */ + test.str_val.data = NULL; + } + /* Continue if NULL or 0. */ + if (memcmp(&test, &zero, sizeof(test)) == 0) continue; + + /* Continue on empty array or map. */ + if (upb_fielddef_ismap(f)) { + if (upb_map_size(test.map_val) == 0) continue; + } else if (upb_fielddef_isseq(f)) { + if (upb_array_size(test.array_val) == 0) continue; + } } - fields[index].offset = upb_msglayout_place(l, field_size); + *out_val = val; + *out_f = f; + *iter = i; + return true; } + *iter = i; + return false; +} - /* Allocate oneof fields. Each oneof field consists of a uint32 for the case - * and space for the actual data. */ - for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit); - upb_msg_oneof_next(&oit)) { - const upb_oneofdef* o = upb_msg_iter_oneof(&oit); - upb_oneof_iter fit; - - size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ - size_t field_size = 0; - uint32_t case_offset; - uint32_t data_offset; +/** upb_array *****************************************************************/ - /* Calculate field size: the max of all field sizes. */ - for (upb_oneof_begin(&fit, o); - !upb_oneof_done(&fit); - upb_oneof_next(&fit)) { - const upb_fielddef* f = upb_oneof_iter_field(&fit); - field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f)); - } +upb_array *upb_array_new(upb_arena *a, upb_fieldtype_t type) { + return _upb_array_new(a, type); +} - /* Align and allocate case offset. */ - case_offset = upb_msglayout_place(l, case_size); - data_offset = upb_msglayout_place(l, field_size); +size_t upb_array_size(const upb_array *arr) { + return arr->len; +} - for (upb_oneof_begin(&fit, o); - !upb_oneof_done(&fit); - upb_oneof_next(&fit)) { - const upb_fielddef* f = upb_oneof_iter_field(&fit); - fields[upb_fielddef_index(f)].offset = data_offset; - fields[upb_fielddef_index(f)].presence = ~case_offset; - } - } +upb_msgval upb_array_get(const upb_array *arr, size_t i) { + upb_msgval ret; + const char* data = _upb_array_constptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->len); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} - /* Size of the entire structure should be a multiple of its greatest - * alignment. TODO: track overall alignment for real? */ - l->size = align_up(l->size, 8); +void upb_array_set(upb_array *arr, size_t i, upb_msgval val) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->len); + memcpy(data + (i << lg2), &val, 1 << lg2); +} +bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) { + if (!_upb_array_realloc(arr, arr->len + 1, arena)) { + return false; + } + arr->len++; + upb_array_set(arr, arr->len - 1, val); return true; } +/* Resizes the array to the given size, reallocating if necessary, and returns a + * pointer to the new array elements. */ +bool upb_array_resize(upb_array *arr, size_t size, upb_arena *arena) { + return _upb_array_realloc(arr, size, arena); +} -/** upb_msgfactory ************************************************************/ - -struct upb_msgfactory { - const upb_symtab *symtab; /* We own a ref. */ - upb_inttable layouts; -}; +/** upb_map *******************************************************************/ -upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) { - upb_msgfactory *ret = upb_gmalloc(sizeof(*ret)); +upb_map *upb_map_new(upb_arena *a, upb_fieldtype_t key_type, + upb_fieldtype_t value_type) { + return _upb_map_new(a, _upb_fieldtype_to_mapsize[key_type], + _upb_fieldtype_to_mapsize[value_type]); +} - ret->symtab = symtab; - upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR); +size_t upb_map_size(const upb_map *map) { + return _upb_map_size(map); +} - return ret; +bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val) { + return _upb_map_get(map, &key, map->key_size, val, map->val_size); } -void upb_msgfactory_free(upb_msgfactory *f) { - upb_inttable_iter i; - upb_inttable_begin(&i, &f->layouts); - for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { - upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i)); - upb_msglayout_free(l); - } +bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, + upb_arena *arena) { + return _upb_map_set(map, &key, map->key_size, &val, map->val_size, arena); +} - upb_inttable_uninit(&f->layouts); - upb_gfree(f); +bool upb_map_delete(upb_map *map, upb_msgval key) { + return _upb_map_delete(map, &key, map->key_size); } -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) { - return f->symtab; +bool upb_mapiter_next(const upb_map *map, size_t *iter) { + return _upb_map_next(map, iter); } -const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, - const upb_msgdef *m) { - upb_value v; - UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m); - UPB_ASSERT(!upb_msgdef_mapentry(m)); +/* Returns the key and value for this entry of the map. */ +upb_msgval upb_mapiter_key(const upb_map *map, size_t iter) { + upb_strtable_iter i; + upb_msgval ret; + i.t = &map->table; + i.index = iter; + _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size); + return ret; +} - if (upb_inttable_lookupptr(&f->layouts, m, &v)) { - UPB_ASSERT(upb_value_getptr(v)); - return upb_value_getptr(v); - } else { - /* In case of circular dependency, layout has to be inserted first. */ - upb_msglayout *l = upb_gmalloc(sizeof(*l)); - upb_msgfactory *mutable_f = (void*)f; - upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l)); - UPB_ASSERT(l); - if (!upb_msglayout_init(m, l, f)) { - upb_msglayout_free(l); - } - return l; - } +upb_msgval upb_mapiter_value(const upb_map *map, size_t iter) { + upb_strtable_iter i; + upb_msgval ret; + i.t = &map->table; + i.index = iter; + _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size); + return ret; } + +/* void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value); */ /* ** TODO(haberman): it's unclear whether a lot of the consistency checks should ** UPB_ASSERT() or return false. @@ -5096,7 +5624,8 @@ static upb_handlers *upb_handlers_new(const upb_msgdef *md, int extra; upb_handlers *h; - extra = sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1); + extra = + (int)(sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1)); h = upb_calloc(arena, sizeof(*h) + extra); if (!h) return NULL; @@ -5497,6 +6026,31 @@ bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink sink) { } return ret; } + + +#ifdef UPB_MSVC_VSNPRINTF +/* Visual C++ earlier than 2015 doesn't have standard C99 snprintf and + * vsnprintf. To support them, missing functions are manually implemented + * using the existing secure functions. */ +int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg) { + if (!s) { + return _vscprintf(format, arg); + } + int ret = _vsnprintf_s(s, n, _TRUNCATE, format, arg); + if (ret < 0) { + ret = _vscprintf(format, arg); + } + return ret; +} + +int msvc_snprintf(char* s, size_t n, const char* format, ...) { + va_list arg; + va_start(arg, format); + int ret = msvc_vsnprintf(s, n, format, arg); + va_end(arg); + return ret; +} +#endif /* ** protobuf decoder bytecode compiler ** @@ -5652,7 +6206,9 @@ static void setofs(uint32_t *instruction, int32_t ofs) { UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */ } -static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } +static uint32_t pcofs(compiler *c) { + return (uint32_t)(c->pc - c->group->bytecode); +} /* Defines a local label at the current PC location. All previous forward * references are updated to point to this location. The location is noted @@ -5666,7 +6222,7 @@ static void label(compiler *c, unsigned int label) { codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; while (codep) { int ofs = getofs(*codep); - setofs(codep, c->pc - codep - instruction_len(*codep)); + setofs(codep, (int32_t)(c->pc - codep - instruction_len(*codep))); codep = ofs ? codep + ofs : NULL; } c->fwd_labels[label] = EMPTYLABEL; @@ -5688,7 +6244,7 @@ static int32_t labelref(compiler *c, int label) { return 0; } else if (label < 0) { /* Backward local label. Relative to the next instruction. */ - uint32_t from = (c->pc + 1) - c->group->bytecode; + uint32_t from = (uint32_t)((c->pc + 1) - c->group->bytecode); return c->back_labels[-label] - from; } else { /* Forward local label: prepend to (possibly-empty) linked list. */ @@ -5722,7 +6278,7 @@ static void putop(compiler *c, int op, ...) { case OP_SETDISPATCH: { uintptr_t ptr = (uintptr_t)va_arg(ap, void*); put32(c, OP_SETDISPATCH); - put32(c, ptr); + put32(c, (uint32_t)ptr); if (sizeof(uintptr_t) > sizeof(uint32_t)) put32(c, (uint64_t)ptr >> 32); break; @@ -5781,7 +6337,7 @@ static void putop(compiler *c, int op, ...) { case OP_TAG2: { int label = va_arg(ap, int); uint64_t tag = va_arg(ap, uint64_t); - uint32_t instruction = op | (tag << 16); + uint32_t instruction = (uint32_t)(op | (tag << 16)); UPB_ASSERT(tag <= 0xffff); setofs(&instruction, labelref(c, label)); put32(c, instruction); @@ -5793,7 +6349,7 @@ static void putop(compiler *c, int op, ...) { uint32_t instruction = op | (upb_value_size(tag) << 16); setofs(&instruction, labelref(c, label)); put32(c, instruction); - put32(c, tag); + put32(c, (uint32_t)tag); put32(c, tag >> 32); break; } @@ -6406,11 +6962,11 @@ const upb_pbdecodermethod *upb_pbcodecache_get(upb_pbcodecache *c, } else { g = mgroup_new(h, c->lazy); ok = upb_inttable_insertptr(&c->groups, md, upb_value_constptr(g)); - UPB_ASSERT(ok); + UPB_ASSUME(ok); } ok = upb_inttable_lookupptr(&g->methods, h, &v); - UPB_ASSERT(ok); + UPB_ASSUME(ok); return upb_value_getptr(v); } /* @@ -6597,7 +7153,7 @@ static int32_t skip(upb_pbdecoder *d, size_t bytes) { UPB_ASSERT(d->skip == 0); if (bytes > delim_remaining(d)) { seterr(d, "Skipped value extended beyond enclosing submessage."); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } else if (bufleft(d) >= bytes) { /* Skipped data is all in current buffer, and more is still available. */ advance(d, bytes); @@ -6610,7 +7166,7 @@ static int32_t skip(upb_pbdecoder *d, size_t bytes) { d->bufstart_ofs += (d->end - d->buf); d->residual_end = d->residual; switchtobuf(d, d->residual, d->residual_end); - return d->size_param + d->skip; + return (int32_t)(d->size_param + d->skip); } } @@ -6650,7 +7206,7 @@ int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, /* NULL buf is ok if its entire span is covered by the "skip" above, but * by this point we know that "skip" doesn't cover the buffer. */ seterr(d, "Passed NULL buffer over non-skippable region."); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } if (d->residual_end > d->residual) { @@ -6760,9 +7316,9 @@ UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, return DECODE_OK; } else if (d->data_end == d->delim_end) { seterr(d, "Submessage ended in the middle of a value or group"); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } else { - return suspend_save(d); + return (int32_t)suspend_save(d); } } @@ -6818,7 +7374,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, } if(bitpos == 70 && (byte & 0x80)) { seterr(d, kUnterminatedVarint); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } return DECODE_OK; } @@ -6835,7 +7391,7 @@ UPB_FORCEINLINE static int32_t decode_varint(upb_pbdecoder *d, uint64_t *u64) { upb_decoderet r = upb_vdecode_fast(d->ptr); if (r.p == NULL) { seterr(d, kUnterminatedVarint); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } advance(d, r.p - d->ptr); *u64 = r.val; @@ -6859,9 +7415,9 @@ UPB_FORCEINLINE static int32_t decode_v32(upb_pbdecoder *d, uint32_t *u32) { * Right now the size_t -> int32_t can overflow and produce negative values. */ *u32 = 0; - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } - *u32 = u64; + *u32 = (uint32_t)u64; return DECODE_OK; } @@ -6937,7 +7493,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, UPB_ASSERT(ok < 0); return DECODE_OK; } else if (read < bytes && memcmp(&data, &expected, read) == 0) { - return suspend_save(d); + return (int32_t)suspend_save(d); } else { return DECODE_MISMATCH; } @@ -6957,7 +7513,7 @@ int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, have_tag: if (fieldnum == 0) { seterr(d, "Saw invalid field number (0)"); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } switch (wire_type) { @@ -6979,7 +7535,9 @@ have_tag: break; } case UPB_WIRE_TYPE_START_GROUP: - CHECK_SUSPEND(pushtagdelim(d, -fieldnum)); + if (!pushtagdelim(d, -fieldnum)) { + return (int32_t)upb_pbdecoder_suspend(d); + } break; case UPB_WIRE_TYPE_END_GROUP: if (fieldnum == -d->top->groupnum) { @@ -6988,12 +7546,12 @@ have_tag: return DECODE_ENDGROUP; } else { seterr(d, "Unmatched ENDGROUP tag."); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } break; default: seterr(d, "Invalid wire type"); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } if (d->top->groupnum >= 0) { @@ -7165,7 +7723,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, subsink, arg)); ) VMCASE(OP_STARTSTR, - uint32_t len = delim_remaining(d); + uint32_t len = (uint32_t)delim_remaining(d); upb_pbdecoder_frame *outer = outer_frame(d); CHECK_SUSPEND(upb_sink_startstr(outer->sink, arg, len, &d->top->sink)); if (len == 0) { @@ -7173,7 +7731,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, } ) VMCASE(OP_STRING, - uint32_t len = curbufleft(d); + uint32_t len = (uint32_t)curbufleft(d); size_t n = upb_sink_putstring(d->top->sink, arg, d->ptr, len, handle); if (n > len) { if (n > delim_remaining(d)) { @@ -7379,9 +7937,6 @@ void upb_pbdecoder_reset(upb_pbdecoder *d) { upb_pbdecoder *upb_pbdecoder_create(upb_arena *a, const upb_pbdecodermethod *m, upb_sink sink, upb_status *status) { const size_t default_max_nesting = 64; -#ifndef NDEBUG - size_t size_before = upb_arena_bytesallocated(a); -#endif upb_pbdecoder *d = upb_arena_malloc(a, sizeof(upb_pbdecoder)); if (!d) return NULL; @@ -7407,9 +7962,6 @@ upb_pbdecoder *upb_pbdecoder_create(upb_arena *a, const upb_pbdecodermethod *m, } d->top->sink = sink; - /* If this fails, increase the value in decoder.h. */ - UPB_ASSERT_DEBUGVAR(upb_arena_bytesallocated(a) - size_before <= - UPB_PB_DECODER_SIZE); return d; } @@ -7708,7 +8260,7 @@ static bool start_delim(upb_pb_encoder *e) { e->runbegin = e->ptr; } - *e->top = e->segptr - e->segbuf; + *e->top = (int)(e->segptr - e->segbuf); e->segptr->seglen = 0; e->segptr->msglen = 0; @@ -7994,9 +8546,6 @@ upb_pb_encoder *upb_pb_encoder_create(upb_arena *arena, const upb_handlers *h, const size_t initial_segbufsize = 16; /* TODO(haberman): make this configurable. */ const size_t stack_size = 64; -#ifndef NDEBUG - const size_t size_before = upb_arena_bytesallocated(arena); -#endif upb_pb_encoder *e = upb_arena_malloc(arena, sizeof(upb_pb_encoder)); if (!e) return NULL; @@ -8021,9 +8570,6 @@ upb_pb_encoder *upb_pb_encoder_create(upb_arena *arena, const upb_handlers *h, e->subc = output.closure; e->ptr = e->buf; - /* If this fails, increase the value in encoder.h. */ - UPB_ASSERT_DEBUGVAR(upb_arena_bytesallocated(arena) - size_before <= - UPB_PB_ENCODER_SIZE); return e; } @@ -8439,7 +8985,7 @@ done: return r; } -// #line 1 "upb/json/parser.rl" +#line 1 "upb/json/parser.rl" /* ** upb::json::Parser (upb_json_parser) ** @@ -8828,7 +9374,7 @@ static upb_selector_t getsel_for_handlertype(upb_json_parser *p, upb_handlertype_t type) { upb_selector_t sel; bool ok = upb_handlers_getselector(p->top->f, type, &sel); - UPB_ASSERT(ok); + UPB_ASSUME(ok); return sel; } @@ -8853,7 +9399,7 @@ static void set_name_table(upb_json_parser *p, upb_jsonparser_frame *frame) { const upb_json_parsermethod *method; ok = upb_inttable_lookupptr(&cache->methods, frame->m, &v); - UPB_ASSERT(ok); + UPB_ASSUME(ok); method = upb_value_getconstptr(v); frame->name_table = &method->name_table; @@ -9172,7 +9718,9 @@ static bool multipart_text(upb_json_parser *p, const char *buf, size_t len, /* Note: this invalidates the accumulate buffer! Call only after reading its * contents. */ static void multipart_end(upb_json_parser *p) { - UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE); + /* This is false sometimes. Probably a bug of some sort, but this code is + * intended for deletion soon. */ + /* UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE); */ p->multipart_state = MULTIPART_INACTIVE; accumulate_clear(p); } @@ -9407,7 +9955,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf, } else if (val > INT32_MAX || val < INT32_MIN) { return false; } else { - upb_sink_putint32(p->top->sink, parser_getsel(p), val); + upb_sink_putint32(p->top->sink, parser_getsel(p), (int32_t)val); return true; } } @@ -9418,7 +9966,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf, } else if (val > UINT32_MAX || errno == ERANGE) { return false; } else { - upb_sink_putuint32(p->top->sink, parser_getsel(p), val); + upb_sink_putuint32(p->top->sink, parser_getsel(p), (uint32_t)val); return true; } } @@ -9706,7 +10254,7 @@ static bool start_stringval(upb_json_parser *p) { } else if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL && upb_fielddef_type(p->top->f) != UPB_TYPE_MESSAGE) { /* No need to push a frame -- numeric values in quotes remain in the - * current parser frame. These values must accumulate so we can convert + * current parser frame. These values must accmulate so we can convert * them all at once at the end. */ multipart_startaccum(p); return true; @@ -9807,7 +10355,12 @@ static bool end_stringval_nontop(upb_json_parser *p) { upb_selector_t sel = parser_getsel(p); upb_sink_putint32(p->top->sink, sel, int_val); } else { - upb_status_seterrf(p->status, "Enum value unknown: '%.*s'", len, buf); + if (p->ignore_json_unknown) { + ok = true; + /* TODO(teboring): Should also clean this field. */ + } else { + upb_status_seterrf(p->status, "Enum value unknown: '%.*s'", len, buf); + } } break; @@ -10458,7 +11011,7 @@ static void end_member(upb_json_parser *p) { /* send ENDSUBMSG in repeated-field-of-mapentries frame. */ p->top--; ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); - UPB_ASSERT(ok); + UPB_ASSUME(ok); upb_sink_endsubmsg(p->top->sink, (p->top + 1)->sink, sel); } @@ -11012,11 +11565,11 @@ static bool does_fieldmask_end(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -// #line 2780 "upb/json/parser.rl" +#line 2787 "upb/json/parser.rl" -// #line 2583 "upb/json/parser.c" +#line 2590 "upb/json/parser.c" static const char _json_actions[] = { 0, 1, 0, 1, 1, 1, 3, 1, 4, 1, 6, 1, 7, 1, 8, 1, @@ -11271,7 +11824,7 @@ static const int json_en_value_machine = 78; static const int json_en_main = 1; -// #line 2783 "upb/json/parser.rl" +#line 2790 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -11294,7 +11847,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -// #line 2861 "upb/json/parser.c" +#line 2868 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -11369,147 +11922,147 @@ _match: switch ( *_acts++ ) { case 1: -// #line 2588 "upb/json/parser.rl" +#line 2595 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 2: -// #line 2590 "upb/json/parser.rl" +#line 2597 "upb/json/parser.rl" { p--; {stack[top++] = cs; cs = 23;goto _again;} } break; case 3: -// #line 2594 "upb/json/parser.rl" +#line 2601 "upb/json/parser.rl" { start_text(parser, p); } break; case 4: -// #line 2595 "upb/json/parser.rl" +#line 2602 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 5: -// #line 2601 "upb/json/parser.rl" +#line 2608 "upb/json/parser.rl" { start_hex(parser); } break; case 6: -// #line 2602 "upb/json/parser.rl" +#line 2609 "upb/json/parser.rl" { hexdigit(parser, p); } break; case 7: -// #line 2603 "upb/json/parser.rl" +#line 2610 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hex(parser)); } break; case 8: -// #line 2609 "upb/json/parser.rl" +#line 2616 "upb/json/parser.rl" { CHECK_RETURN_TOP(escape(parser, p)); } break; case 9: -// #line 2615 "upb/json/parser.rl" +#line 2622 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 10: -// #line 2620 "upb/json/parser.rl" +#line 2627 "upb/json/parser.rl" { start_year(parser, p); } break; case 11: -// #line 2621 "upb/json/parser.rl" +#line 2628 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_year(parser, p)); } break; case 12: -// #line 2625 "upb/json/parser.rl" +#line 2632 "upb/json/parser.rl" { start_month(parser, p); } break; case 13: -// #line 2626 "upb/json/parser.rl" +#line 2633 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_month(parser, p)); } break; case 14: -// #line 2630 "upb/json/parser.rl" +#line 2637 "upb/json/parser.rl" { start_day(parser, p); } break; case 15: -// #line 2631 "upb/json/parser.rl" +#line 2638 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_day(parser, p)); } break; case 16: -// #line 2635 "upb/json/parser.rl" +#line 2642 "upb/json/parser.rl" { start_hour(parser, p); } break; case 17: -// #line 2636 "upb/json/parser.rl" +#line 2643 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hour(parser, p)); } break; case 18: -// #line 2640 "upb/json/parser.rl" +#line 2647 "upb/json/parser.rl" { start_minute(parser, p); } break; case 19: -// #line 2641 "upb/json/parser.rl" +#line 2648 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_minute(parser, p)); } break; case 20: -// #line 2645 "upb/json/parser.rl" +#line 2652 "upb/json/parser.rl" { start_second(parser, p); } break; case 21: -// #line 2646 "upb/json/parser.rl" +#line 2653 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_second(parser, p)); } break; case 22: -// #line 2651 "upb/json/parser.rl" +#line 2658 "upb/json/parser.rl" { start_duration_base(parser, p); } break; case 23: -// #line 2652 "upb/json/parser.rl" +#line 2659 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_duration_base(parser, p)); } break; case 24: -// #line 2654 "upb/json/parser.rl" +#line 2661 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 25: -// #line 2659 "upb/json/parser.rl" +#line 2666 "upb/json/parser.rl" { start_timestamp_base(parser); } break; case 26: -// #line 2661 "upb/json/parser.rl" +#line 2668 "upb/json/parser.rl" { start_timestamp_fraction(parser, p); } break; case 27: -// #line 2662 "upb/json/parser.rl" +#line 2669 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } break; case 28: -// #line 2664 "upb/json/parser.rl" +#line 2671 "upb/json/parser.rl" { start_timestamp_zone(parser, p); } break; case 29: -// #line 2665 "upb/json/parser.rl" +#line 2672 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } break; case 30: -// #line 2667 "upb/json/parser.rl" +#line 2674 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 31: -// #line 2672 "upb/json/parser.rl" +#line 2679 "upb/json/parser.rl" { start_fieldmask_path_text(parser, p); } break; case 32: -// #line 2673 "upb/json/parser.rl" +#line 2680 "upb/json/parser.rl" { end_fieldmask_path_text(parser, p); } break; case 33: -// #line 2678 "upb/json/parser.rl" +#line 2685 "upb/json/parser.rl" { start_fieldmask_path(parser); } break; case 34: -// #line 2679 "upb/json/parser.rl" +#line 2686 "upb/json/parser.rl" { end_fieldmask_path(parser); } break; case 35: -// #line 2685 "upb/json/parser.rl" +#line 2692 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 36: -// #line 2690 "upb/json/parser.rl" +#line 2697 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { {stack[top++] = cs; cs = 47;goto _again;} @@ -11523,11 +12076,11 @@ _match: } break; case 37: -// #line 2703 "upb/json/parser.rl" +#line 2710 "upb/json/parser.rl" { p--; {stack[top++] = cs; cs = 78;goto _again;} } break; case 38: -// #line 2708 "upb/json/parser.rl" +#line 2715 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { start_any_member(parser, p); @@ -11537,11 +12090,11 @@ _match: } break; case 39: -// #line 2715 "upb/json/parser.rl" +#line 2722 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_membername(parser)); } break; case 40: -// #line 2718 "upb/json/parser.rl" +#line 2725 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { end_any_member(parser, p); @@ -11551,7 +12104,7 @@ _match: } break; case 41: -// #line 2729 "upb/json/parser.rl" +#line 2736 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { start_any_object(parser, p); @@ -11561,7 +12114,7 @@ _match: } break; case 42: -// #line 2738 "upb/json/parser.rl" +#line 2745 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { CHECK_RETURN_TOP(end_any_object(parser, p)); @@ -11571,54 +12124,54 @@ _match: } break; case 43: -// #line 2750 "upb/json/parser.rl" +#line 2757 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_array(parser)); } break; case 44: -// #line 2754 "upb/json/parser.rl" +#line 2761 "upb/json/parser.rl" { end_array(parser); } break; case 45: -// #line 2759 "upb/json/parser.rl" +#line 2766 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_number(parser, p)); } break; case 46: -// #line 2760 "upb/json/parser.rl" +#line 2767 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; case 47: -// #line 2762 "upb/json/parser.rl" +#line 2769 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_stringval(parser)); } break; case 48: -// #line 2763 "upb/json/parser.rl" +#line 2770 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_stringval(parser)); } break; case 49: -// #line 2765 "upb/json/parser.rl" +#line 2772 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; case 50: -// #line 2767 "upb/json/parser.rl" +#line 2774 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; case 51: -// #line 2769 "upb/json/parser.rl" +#line 2776 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_null(parser)); } break; case 52: -// #line 2771 "upb/json/parser.rl" +#line 2778 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_subobject_full(parser)); } break; case 53: -// #line 2772 "upb/json/parser.rl" +#line 2779 "upb/json/parser.rl" { end_subobject_full(parser); } break; case 54: -// #line 2777 "upb/json/parser.rl" +#line 2784 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -// #line 3185 "upb/json/parser.c" +#line 3192 "upb/json/parser.c" } } @@ -11635,32 +12188,32 @@ _again: while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 0: -// #line 2586 "upb/json/parser.rl" +#line 2593 "upb/json/parser.rl" { p--; {cs = stack[--top]; if ( p == pe ) goto _test_eof; goto _again;} } break; case 46: -// #line 2760 "upb/json/parser.rl" +#line 2767 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; case 49: -// #line 2765 "upb/json/parser.rl" +#line 2772 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; case 50: -// #line 2767 "upb/json/parser.rl" +#line 2774 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; case 51: -// #line 2769 "upb/json/parser.rl" +#line 2776 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_null(parser)); } break; case 53: -// #line 2772 "upb/json/parser.rl" +#line 2779 "upb/json/parser.rl" { end_subobject_full(parser); } break; -// #line 3227 "upb/json/parser.c" +#line 3234 "upb/json/parser.c" } } } @@ -11668,7 +12221,7 @@ goto _again;} } _out: {} } -// #line 2805 "upb/json/parser.rl" +#line 2812 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -11711,13 +12264,13 @@ static void json_parser_reset(upb_json_parser *p) { /* Emit Ragel initialization of the parser. */ -// #line 3278 "upb/json/parser.c" +#line 3285 "upb/json/parser.c" { cs = json_start; top = 0; } -// #line 2847 "upb/json/parser.rl" +#line 2854 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -11748,15 +12301,13 @@ static upb_json_parsermethod *parsermethod_new(upb_json_codecache *c, upb_msg_field_next(&i)) { const upb_fielddef *f = upb_msg_iter_field(&i); upb_value v = upb_value_constptr(f); - char *buf; + const char *name; /* Add an entry for the JSON name. */ - size_t len = upb_fielddef_getjsonname(f, NULL, 0); - buf = upb_malloc(alloc, len); - upb_fielddef_getjsonname(f, buf, len); - upb_strtable_insert3(&m->name_table, buf, strlen(buf), v, alloc); + name = upb_fielddef_jsonname(f); + upb_strtable_insert3(&m->name_table, name, strlen(name), v, alloc); - if (strcmp(buf, upb_fielddef_name(f)) != 0) { + if (strcmp(name, upb_fielddef_name(f)) != 0) { /* Since the JSON name is different from the regular field name, add an * entry for the raw name (compliant proto3 JSON parsers must accept * both). */ @@ -11776,9 +12327,6 @@ upb_json_parser *upb_json_parser_create(upb_arena *arena, upb_sink output, upb_status *status, bool ignore_json_unknown) { -#ifndef NDEBUG - const size_t size_before = upb_arena_bytesallocated(arena); -#endif upb_json_parser *p = upb_arena_malloc(arena, sizeof(upb_json_parser)); if (!p) return false; @@ -11805,10 +12353,6 @@ upb_json_parser *upb_json_parser_create(upb_arena *arena, p->ignore_json_unknown = ignore_json_unknown; - /* If this fails, uncomment and increase the value in parser.h. */ - /* fprintf(stderr, "%zd\n", upb_arena_bytesallocated(arena) - size_before); */ - UPB_ASSERT_DEBUGVAR(upb_arena_bytesallocated(arena) - size_before <= - UPB_JSON_PARSER_SIZE); return p; } @@ -11882,6 +12426,7 @@ const upb_json_parsermethod *upb_json_codecache_get(upb_json_codecache *c, #include +#include #include #include #include @@ -11939,12 +12484,8 @@ strpc *newstrpc(upb_handlers *h, const upb_fielddef *f, ret->ptr = upb_gstrdup(upb_fielddef_name(f)); ret->len = strlen(ret->ptr); } else { - size_t len; - ret->len = upb_fielddef_getjsonname(f, NULL, 0); - ret->ptr = upb_gmalloc(ret->len); - len = upb_fielddef_getjsonname(f, ret->ptr, ret->len); - UPB_ASSERT(len == ret->len); - ret->len--; /* NULL */ + ret->ptr = upb_gstrdup(upb_fielddef_jsonname(f)); + ret->len = strlen(ret->ptr); } upb_handlers_addcleanup(h, ret, freestrpc); @@ -11963,7 +12504,7 @@ strpc *newstrpc_str(upb_handlers *h, const char * str) { /* ------------ JSON string printing: values, maps, arrays ------------------ */ static void print_data( - upb_json_printer *p, const char *buf, unsigned int len) { + upb_json_printer *p, const char *buf, size_t len) { /* TODO: Will need to change if we support pushback from the sink. */ size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL); UPB_ASSERT(n == len); @@ -12003,7 +12544,7 @@ UPB_INLINE const char* json_nice_escape(char c) { /* Write a properly escaped string chunk. The surrounding quotes are *not* * printed; this is so that the caller has the option of emitting the string * content in chunks. */ -static void putstring(upb_json_printer *p, const char *buf, unsigned int len) { +static void putstring(upb_json_printer *p, const char *buf, size_t len) { const char* unescaped_run = NULL; unsigned int i; for (i = 0; i < len; i++) { @@ -12083,28 +12624,26 @@ static size_t fmt_bool(bool val, char* buf, size_t length) { return n; } -static size_t fmt_int64_as_number(long long val, char* buf, size_t length) { - size_t n = _upb_snprintf(buf, length, "%lld", val); +static size_t fmt_int64_as_number(int64_t val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "%" PRId64, val); CHKLENGTH(n > 0 && n < length); return n; } -static size_t fmt_uint64_as_number( - unsigned long long val, char* buf, size_t length) { - size_t n = _upb_snprintf(buf, length, "%llu", val); +static size_t fmt_uint64_as_number(uint64_t val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "%" PRIu64, val); CHKLENGTH(n > 0 && n < length); return n; } -static size_t fmt_int64_as_string(long long val, char* buf, size_t length) { - size_t n = _upb_snprintf(buf, length, "\"%lld\"", val); +static size_t fmt_int64_as_string(int64_t val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "\"%" PRId64 "\"", val); CHKLENGTH(n > 0 && n < length); return n; } -static size_t fmt_uint64_as_string( - unsigned long long val, char* buf, size_t length) { - size_t n = _upb_snprintf(buf, length, "\"%llu\"", val); +static size_t fmt_uint64_as_string(uint64_t val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "\"%" PRIu64 "\"", val); CHKLENGTH(n > 0 && n < length); return n; } @@ -13247,10 +13786,6 @@ static void json_printer_reset(upb_json_printer *p) { upb_json_printer *upb_json_printer_create(upb_arena *a, const upb_handlers *h, upb_bytessink output) { -#ifndef NDEBUG - size_t size_before = upb_arena_bytesallocated(a); -#endif - upb_json_printer *p = upb_arena_malloc(a, sizeof(upb_json_printer)); if (!p) return NULL; @@ -13260,9 +13795,6 @@ upb_json_printer *upb_json_printer_create(upb_arena *a, const upb_handlers *h, p->seconds = 0; p->nanos = 0; - /* If this fails, increase the value in printer.h. */ - UPB_ASSERT_DEBUGVAR(upb_arena_bytesallocated(a) - size_before <= - UPB_JSON_PRINTER_SIZE); return p; } @@ -13281,17 +13813,23 @@ upb_handlercache *upb_json_printer_newcache(bool preserve_proto_fieldnames) { } /* See port_def.inc. This should #undef all macros #defined there. */ +#undef UPB_MAPTYPE_STRING #undef UPB_SIZE -#undef UPB_FIELD_AT +#undef UPB_PTR_AT #undef UPB_READ_ONEOF #undef UPB_WRITE_ONEOF #undef UPB_INLINE +#undef UPB_ALIGN_UP +#undef UPB_ALIGN_DOWN +#undef UPB_ALIGN_MALLOC +#undef UPB_ALIGN_OF #undef UPB_FORCEINLINE #undef UPB_NOINLINE #undef UPB_NORETURN #undef UPB_MAX #undef UPB_MIN #undef UPB_UNUSED +#undef UPB_ASSUME #undef UPB_ASSERT #undef UPB_ASSERT_DEBUGVAR #undef UPB_UNREACHABLE diff --git a/php/ext/google/protobuf/upb.h b/php/ext/google/protobuf/upb.h index 6746476c29..179e498777 100644 --- a/php/ext/google/protobuf/upb.h +++ b/php/ext/google/protobuf/upb.h @@ -28,9 +28,8 @@ * * This file is private and must not be included by users! */ -#ifndef UINTPTR_MAX -#error must include stdint.h first -#endif +#include +#include #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 @@ -38,17 +37,21 @@ #define UPB_SIZE(size32, size64) size64 #endif -#define UPB_FIELD_AT(msg, fieldtype, offset) \ - *(fieldtype*)((const char*)(msg) + offset) +/* 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))) #define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \ - UPB_FIELD_AT(msg, int, case_offset) == case_val \ - ? UPB_FIELD_AT(msg, fieldtype, offset) \ + *UPB_PTR_AT(msg, case_offset, int) == case_val \ + ? *UPB_PTR_AT(msg, offset, fieldtype) \ : default #define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \ - UPB_FIELD_AT(msg, int, case_offset) = case_val; \ - UPB_FIELD_AT(msg, fieldtype, offset) = value; + *UPB_PTR_AT(msg, case_offset, int) = case_val; \ + *UPB_PTR_AT(msg, offset, fieldtype) = value; + +#define UPB_MAPTYPE_STRING 0 /* UPB_INLINE: inline if possible, emit standalone code if required. */ #ifdef __cplusplus @@ -59,6 +62,11 @@ #define UPB_INLINE static #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, 16) +#define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) + /* Hints to the compiler about likely/unlikely branches. */ #if defined (__GNUC__) || defined(__clang__) #define UPB_LIKELY(x) __builtin_expect((x),1) @@ -133,6 +141,18 @@ int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg); #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() +#else +#define UPB_ASSUME(expr) do {} if (false && (expr)) +#endif +#else +#define UPB_ASSUME(expr) assert(expr) +#endif + /* UPB_ASSERT(): in release mode, we use the expression without letting it be * evaluated. This prevents "unused variable" warnings. */ #ifdef NDEBUG @@ -159,10 +179,51 @@ int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg); #define UPB_INFINITY (1.0 / 0.0) #endif /* -** This file contains shared definitions that are widely used across upb. +** upb_decode: parsing into a upb_msg using a upb_msglayout. +*/ + +#ifndef UPB_DECODE_H_ +#define UPB_DECODE_H_ + +/* +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. ** -** This is a mixed C/C++ interface that offers a full API to both languages. -** See the top-level README for more information. +** The definitions in this file are internal to upb. +**/ + +#ifndef UPB_MSG_H_ +#define UPB_MSG_H_ + +#include +#include + +/* +** 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 homogenous (all values of the same type). In debug +** mode, we check this on insert and lookup. +*/ + +#ifndef UPB_TABLE_H_ +#define UPB_TABLE_H_ + +#include +#include +/* +** This file contains shared definitions that are widely used across upb. */ #ifndef UPB_H_ @@ -175,23 +236,13 @@ int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg); #include #include + #ifdef __cplusplus -#include -namespace upb { -class Arena; -class Status; -template class InlinedArena; -} +extern "C" { #endif - /* upb_status *****************************************************************/ -/* upb_status represents a success or failure status and error message. - * It owns no resources and allocates no memory, so it should work - * even in OOM situations. */ - -/* The maximum length of an error message before it will get truncated. */ #define UPB_STATUS_MAX_MESSAGE 127 typedef struct { @@ -199,59 +250,15 @@ typedef struct { char msg[UPB_STATUS_MAX_MESSAGE]; /* Error message; NULL-terminated. */ } upb_status; -#ifdef __cplusplus -extern "C" { -#endif - const char *upb_status_errmsg(const upb_status *status); bool upb_ok(const upb_status *status); -/* Any of the functions that write to a status object allow status to be NULL, - * to support use cases where the function's caller does not care about the - * status message. */ +/* These are no-op if |status| is NULL. */ void upb_status_clear(upb_status *status); void upb_status_seterrmsg(upb_status *status, const char *msg); void upb_status_seterrf(upb_status *status, const char *fmt, ...); void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args); -UPB_INLINE void upb_status_setoom(upb_status *status) { - upb_status_seterrmsg(status, "out of memory"); -} - -#ifdef __cplusplus -} /* extern "C" */ - -class upb::Status { - public: - Status() { upb_status_clear(&status_); } - - upb_status* ptr() { return &status_; } - - /* Returns true if there is no error. */ - bool ok() const { return upb_ok(&status_); } - - /* Guaranteed to be NULL-terminated. */ - const char *error_message() const { return upb_status_errmsg(&status_); } - - /* The error message will be truncated if it is longer than - * UPB_STATUS_MAX_MESSAGE-4. */ - void SetErrorMessage(const char *msg) { upb_status_seterrmsg(&status_, msg); } - void SetFormattedErrorMessage(const char *fmt, ...) { - va_list args; - va_start(args, fmt); - upb_status_vseterrf(&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_; -}; - -#endif /* __cplusplus */ - /** upb_strview ************************************************************/ typedef struct { @@ -318,16 +325,8 @@ UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) { /* The global allocator used by upb. Uses the standard malloc()/free(). */ -#ifdef __cplusplus -extern "C" { -#endif - extern upb_alloc upb_alloc_global; -#ifdef __cplusplus -} /* extern "C" */ -#endif - /* Functions that hard-code the global malloc. * * We still get benefit because we can put custom logic into our global @@ -364,9 +363,14 @@ typedef void upb_cleanup_func(void *ud); struct upb_arena; typedef struct upb_arena upb_arena; -#ifdef __cplusplus -extern "C" { -#endif +typedef struct { + /* We implement the allocator interface. + * This must be the first member of upb_arena! + * TODO(haberman): remove once handlers are gone. */ + upb_alloc alloc; + + char *ptr, *end; +} _upb_arena_head; /* Creates an arena from the given initial block (if any -- n may be 0). * Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this @@ -374,83 +378,40 @@ extern "C" { upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc); void upb_arena_free(upb_arena *a); bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func); -size_t upb_arena_bytesallocated(const upb_arena *a); +void upb_arena_fuse(upb_arena *a, upb_arena *b); +void *_upb_arena_slowmalloc(upb_arena *a, size_t size); UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; } -/* Convenience wrappers around upb_alloc functions. */ - UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) { - return upb_malloc(upb_arena_alloc(a), size); + _upb_arena_head *h = (_upb_arena_head*)a; + void* ret; + size = UPB_ALIGN_MALLOC(size); + + if (UPB_UNLIKELY((size_t)(h->end - h->ptr) < size)) { + return _upb_arena_slowmalloc(a, size); + } + + ret = h->ptr; + h->ptr += size; + return ret; } UPB_INLINE void *upb_arena_realloc(upb_arena *a, void *ptr, size_t oldsize, size_t size) { - return upb_realloc(upb_arena_alloc(a), ptr, oldsize, size); + void *ret = upb_arena_malloc(a, size); + + if (ret && oldsize > 0) { + memcpy(ret, ptr, oldsize); + } + + return ret; } UPB_INLINE upb_arena *upb_arena_new(void) { return upb_arena_init(NULL, 0, &upb_alloc_global); } -#ifdef __cplusplus -} /* extern "C" */ - -class upb::Arena { - public: - /* A simple arena with no initial memory block and the default allocator. */ - Arena() : ptr_(upb_arena_new(), upb_arena_free) {} - - upb_arena* ptr() { return ptr_.get(); } - - /* Allows this arena to be used as a generic allocator. - * - * The arena does not need free() calls so when using Arena as an allocator - * it is safe to skip them. However they are no-ops so there is no harm in - * calling free() either. */ - upb_alloc *allocator() { return upb_arena_alloc(ptr_.get()); } - - /* Add a cleanup function to run when the arena is destroyed. - * Returns false on out-of-memory. */ - bool AddCleanup(void *ud, upb_cleanup_func* func) { - return upb_arena_addcleanup(ptr_.get(), ud, func); - } - - /* Total number of bytes that have been allocated. It is undefined what - * Realloc() does to &arena_ counter. */ - size_t BytesAllocated() const { return upb_arena_bytesallocated(ptr_.get()); } - - private: - std::unique_ptr ptr_; -}; - -#endif - -/* upb::InlinedArena **********************************************************/ - -/* upb::InlinedArena seeds the arenas with a predefined amount of memory. No - * heap memory will be allocated until the initial block is exceeded. - * - * These types only exist in C++ */ - -#ifdef __cplusplus - -template class upb::InlinedArena : public upb::Arena { - public: - InlinedArena() : ptr_(upb_arena_new(&initial_block_, N, &upb_alloc_global)) {} - - upb_arena* ptr() { return ptr_.get(); } - - private: - InlinedArena(const InlinedArena*) = delete; - InlinedArena& operator=(const InlinedArena*) = delete; - - std::unique_ptr ptr_; - char initial_block_[N]; -}; - -#endif /* __cplusplus */ - /* Constants ******************************************************************/ /* Generic function type. */ @@ -470,21 +431,17 @@ typedef enum { * types defined in descriptor.proto, which gives INT32 and SINT32 separate * types (we distinguish the two with the "integer encoding" enum below). */ typedef enum { - /* Types stored in 1 byte. */ UPB_TYPE_BOOL = 1, - /* Types stored in 4 bytes. */ UPB_TYPE_FLOAT = 2, UPB_TYPE_INT32 = 3, UPB_TYPE_UINT32 = 4, UPB_TYPE_ENUM = 5, /* Enum values are int32. */ - /* Types stored as pointers (probably 4 or 8 bytes). */ - UPB_TYPE_STRING = 6, - UPB_TYPE_BYTES = 7, - UPB_TYPE_MESSAGE = 8, - /* Types stored as 8 bytes. */ - UPB_TYPE_DOUBLE = 9, - UPB_TYPE_INT64 = 10, - UPB_TYPE_UINT64 = 11 + UPB_TYPE_MESSAGE = 6, + UPB_TYPE_DOUBLE = 7, + UPB_TYPE_INT64 = 8, + UPB_TYPE_UINT64 = 9, + UPB_TYPE_STRING = 10, + UPB_TYPE_BYTES = 11 } upb_fieldtype_t; /* The repeated-ness of each field; this matches descriptor.proto. */ @@ -496,6 +453,7 @@ typedef enum { /* Descriptor types, as defined in descriptor.proto. */ typedef enum { + /* Old (long) names. TODO(haberman): remove */ UPB_DESCRIPTOR_TYPE_DOUBLE = 1, UPB_DESCRIPTOR_TYPE_FLOAT = 2, UPB_DESCRIPTOR_TYPE_INT64 = 3, @@ -513,251 +471,125 @@ typedef enum { UPB_DESCRIPTOR_TYPE_SFIXED32 = 15, UPB_DESCRIPTOR_TYPE_SFIXED64 = 16, UPB_DESCRIPTOR_TYPE_SINT32 = 17, - UPB_DESCRIPTOR_TYPE_SINT64 = 18 + UPB_DESCRIPTOR_TYPE_SINT64 = 18, + + UPB_DTYPE_DOUBLE = 1, + UPB_DTYPE_FLOAT = 2, + UPB_DTYPE_INT64 = 3, + UPB_DTYPE_UINT64 = 4, + UPB_DTYPE_INT32 = 5, + UPB_DTYPE_FIXED64 = 6, + UPB_DTYPE_FIXED32 = 7, + UPB_DTYPE_BOOL = 8, + UPB_DTYPE_STRING = 9, + UPB_DTYPE_GROUP = 10, + UPB_DTYPE_MESSAGE = 11, + UPB_DTYPE_BYTES = 12, + UPB_DTYPE_UINT32 = 13, + UPB_DTYPE_ENUM = 14, + UPB_DTYPE_SFIXED32 = 15, + UPB_DTYPE_SFIXED64 = 16, + UPB_DTYPE_SINT32 = 17, + UPB_DTYPE_SINT64 = 18 } upb_descriptortype_t; -extern const uint8_t upb_desctype_to_fieldtype[]; - - -#endif /* UPB_H_ */ -/* -** upb_decode: parsing into a upb_msg using a upb_msglayout. -*/ +#define UPB_MAP_BEGIN -1 -#ifndef UPB_DECODE_H_ -#define UPB_DECODE_H_ -/* -** Data structures for message tables, used for parsing and serialization. -** This are much lighter-weight than full reflection, but they are do not -** have enough information to convert to text format, JSON, etc. -** -** The definitions in this file are internal to upb. -**/ +#ifdef __cplusplus +} /* extern "C" */ +#endif -#ifndef UPB_MSG_H_ -#define UPB_MSG_H_ +#endif /* UPB_H_ */ -#include -#include #ifdef __cplusplus extern "C" { #endif -typedef void upb_msg; -/** upb_msglayout *************************************************************/ +/* upb_value ******************************************************************/ -/* upb_msglayout represents the memory layout of a given upb_msgdef. The - * members are public so generated code can initialize them, but users MUST NOT - * read or write any of its members. */ +/* A tagged union (stored untagged inside the table) so that we can check that + * clients calling table accessors are correctly typed without having to have + * an explosion of accessors. */ +typedef enum { + UPB_CTYPE_INT32 = 1, + UPB_CTYPE_INT64 = 2, + UPB_CTYPE_UINT32 = 3, + UPB_CTYPE_UINT64 = 4, + UPB_CTYPE_BOOL = 5, + UPB_CTYPE_CSTR = 6, + UPB_CTYPE_PTR = 7, + UPB_CTYPE_CONSTPTR = 8, + UPB_CTYPE_FPTR = 9, + UPB_CTYPE_FLOAT = 10, + UPB_CTYPE_DOUBLE = 11 +} upb_ctype_t; typedef struct { - uint32_t number; - uint16_t offset; - int16_t presence; /* If >0, hasbit_index+1. If <0, oneof_index+1. */ - uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */ - uint8_t descriptortype; - uint8_t label; -} upb_msglayout_field; + uint64_t val; +} upb_value; -typedef struct upb_msglayout { - const struct upb_msglayout *const* submsgs; - const upb_msglayout_field *fields; - /* Must be aligned to sizeof(void*). Doesn't include internal members like - * unknown fields, extension dict, pointer to msglayout, etc. */ - uint16_t size; - uint16_t field_count; - bool extendable; -} upb_msglayout; +/* Like strdup(), which isn't always available since it's not ANSI C. */ +char *upb_strdup(const char *s, upb_alloc *a); +/* 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_alloc *a); -/** Message internal representation *******************************************/ +UPB_INLINE char *upb_gstrdup(const char *s) { + return upb_strdup(s, &upb_alloc_global); +} -/* Our internal representation for repeated fields. */ -typedef struct { - void *data; /* Each element is element_size. */ - size_t len; /* Measured in elements. */ - size_t size; /* Measured in elements. */ -} upb_array; +UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val) { + v->val = val; +} -upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a); -upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a); +UPB_INLINE upb_value _upb_value_val(uint64_t val) { + upb_value ret; + _upb_value_setval(&ret, val); + return ret; +} -void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, - upb_arena *arena); -const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); +/* 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, proto_type) \ + UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \ + val->val = (converter)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; \ + } -upb_array *upb_array_new(upb_arena *a); +FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32) +FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64) +FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32) +FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64) +FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL) +FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR) +FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR) +FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR) +FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR) -#ifdef __cplusplus -} /* extern "C" */ -#endif +#undef FUNCS -#endif /* UPB_MSG_H_ */ - -#ifdef __cplusplus -extern "C" { -#endif - -bool upb_decode(const char *buf, size_t size, upb_msg *msg, - const upb_msglayout *l, upb_arena *arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* UPB_DECODE_H_ */ -/* -** upb_encode: parsing into a upb_msg using a upb_msglayout. -*/ - -#ifndef UPB_ENCODE_H_ -#define UPB_ENCODE_H_ - - -#ifdef __cplusplus -extern "C" { -#endif - -char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena, - size_t *size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* UPB_ENCODE_H_ */ -/* -** 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 homogenous (all values of the same type). In debug -** mode, we check this on insert and lookup. -*/ - -#ifndef UPB_TABLE_H_ -#define UPB_TABLE_H_ - -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif - - -/* upb_value ******************************************************************/ - -/* A tagged union (stored untagged inside the table) so that we can check that - * clients calling table accessors are correctly typed without having to have - * an explosion of accessors. */ -typedef enum { - UPB_CTYPE_INT32 = 1, - UPB_CTYPE_INT64 = 2, - UPB_CTYPE_UINT32 = 3, - UPB_CTYPE_UINT64 = 4, - UPB_CTYPE_BOOL = 5, - UPB_CTYPE_CSTR = 6, - UPB_CTYPE_PTR = 7, - UPB_CTYPE_CONSTPTR = 8, - UPB_CTYPE_FPTR = 9, - UPB_CTYPE_FLOAT = 10, - UPB_CTYPE_DOUBLE = 11 -} upb_ctype_t; - -typedef struct { - uint64_t val; -#ifndef NDEBUG - /* In debug mode we carry the value type around also so we can check accesses - * to be sure the right member is being read. */ - upb_ctype_t ctype; -#endif -} upb_value; - -#ifdef NDEBUG -#define SET_TYPE(dest, val) UPB_UNUSED(val) -#else -#define SET_TYPE(dest, val) dest = val -#endif - -/* Like strdup(), which isn't always available since it's not ANSI C. */ -char *upb_strdup(const char *s, upb_alloc *a); -/* 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_alloc *a); - -UPB_INLINE char *upb_gstrdup(const char *s) { - return upb_strdup(s, &upb_alloc_global); -} - -UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val, - upb_ctype_t ctype) { - v->val = val; - SET_TYPE(v->ctype, ctype); -} - -UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) { - upb_value ret; - _upb_value_setval(&ret, val, ctype); - return ret; -} - -/* 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, proto_type) \ - UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \ - val->val = (converter)cval; \ - SET_TYPE(val->ctype, proto_type); \ - } \ - 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) { \ - UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \ - return (type_t)(converter)val.val; \ - } - -FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32) -FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64) -FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32) -FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64) -FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL) -FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR) -FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR) -FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR) -FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR) - -#undef FUNCS - -UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) { - memcpy(&val->val, &cval, sizeof(cval)); - SET_TYPE(val->ctype, UPB_CTYPE_FLOAT); -} +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)); - SET_TYPE(val->ctype, UPB_CTYPE_DOUBLE); } UPB_INLINE upb_value upb_value_float(float cval) { @@ -801,7 +633,6 @@ typedef struct { #define UPB_TABVALUE_EMPTY_INIT {-1} - /* upb_table ******************************************************************/ typedef struct _upb_tabent { @@ -818,7 +649,6 @@ typedef struct _upb_tabent { typedef struct { size_t count; /* Number of entries in the hash part. */ size_t mask; /* Mask to turn hash value -> bucket. */ - upb_ctype_t ctype; /* Type of all values. */ uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ /* Hash table entries. @@ -828,17 +658,6 @@ typedef struct { * initialize const hash tables. Then we cast away const when we have to. */ const upb_tabent *entries; - -#ifndef NDEBUG - /* This table's allocator. We make the user pass it in to every relevant - * function and only use this to check it in debug mode. We do this solely - * to keep upb_table as small as possible. This might seem slightly paranoid - * but the plan is to use upb_table for all map fields and extension sets in - * a forthcoming message representation, so there could be a lot of these. - * If this turns out to be too annoying later, we can change it (since this - * is an internal-only header file). */ - upb_alloc *alloc; -#endif } upb_table; typedef struct { @@ -852,12 +671,6 @@ typedef struct { size_t array_count; /* Array part number of elements. */ } upb_inttable; -#define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \ - {UPB_TABLE_INIT(count, mask, ctype, size_lg2, ent), a, asize, acount} - -#define UPB_EMPTY_INTTABLE_INIT(ctype) \ - UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0) - #define UPB_ARRAY_EMPTYENT -1 UPB_INLINE size_t upb_table_size(const upb_table *t) { @@ -926,6 +739,7 @@ upb_inttable *upb_inttable_pack(const upb_inttable *t, void *p, size_t *ofs, size_t size); upb_strtable *upb_strtable_pack(const upb_strtable *t, void *p, size_t *ofs, size_t size); +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. For string tables, the key must be @@ -1027,7 +841,7 @@ UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key, if (key < t->array_size) { upb_tabval arrval = t->array[key]; if (upb_arrhas(arrval)) { - _upb_value_setval(v, arrval.val, t->t.ctype); + _upb_value_setval(v, arrval.val); return true; } else { return false; @@ -1037,7 +851,7 @@ UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key, if (t->t.entries == NULL) return false; for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) { if ((uint32_t)e->key == key) { - _upb_value_setval(v, e->val.val, t->t.ctype); + _upb_value_setval(v, e->val.val); return true; } if (e->next == NULL) return false; @@ -1091,8 +905,7 @@ typedef struct { 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); -const char *upb_strtable_iter_key(const upb_strtable_iter *i); -size_t upb_strtable_iter_keylength(const upb_strtable_iter *i); +upb_strview 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, @@ -1116,6 +929,10 @@ typedef struct { bool array_part; } upb_inttable_iter; +UPB_INLINE const upb_tabent *str_tabent(const upb_strtable_iter *i) { + return &i->t->t.entries[i->index]; +} + void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t); void upb_inttable_next(upb_inttable_iter *i); bool upb_inttable_done(const upb_inttable_iter *i); @@ -1132,36 +949,140 @@ bool upb_inttable_iter_isequal(const upb_inttable_iter *i1, #endif /* UPB_TABLE_H_ */ -/* This file was generated by upbc (the upb compiler) from the input - * file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. */ -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -/* -** Functions for use by generated code. These are not public and users must -** not call them directly. -*/ +#ifdef __cplusplus +extern "C" { +#endif -#ifndef UPB_GENERATED_UTIL_H_ -#define UPB_GENERATED_UTIL_H_ +#define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs) -#include +typedef void upb_msg; +/** upb_msglayout *************************************************************/ -#define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs) +/* upb_msglayout represents the memory layout of a given upb_msgdef. The + * members are public so generated code can initialize them, but users MUST NOT + * read or write any of its members. */ + +/* These aren't real labels according to descriptor.proto, but in the table we + * use these for map/packed fields instead of UPB_LABEL_REPEATED. */ +enum { + _UPB_LABEL_MAP = 4, + _UPB_LABEL_PACKED = 7 /* Low 3 bits are common with UPB_LABEL_REPEATED. */ +}; + +typedef struct { + uint32_t number; + uint16_t offset; + int16_t presence; /* If >0, hasbit_index. If <0, -oneof_index. */ + uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */ + uint8_t descriptortype; + uint8_t label; +} upb_msglayout_field; + +typedef struct upb_msglayout { + const struct upb_msglayout *const* submsgs; + const upb_msglayout_field *fields; + /* Must be aligned to sizeof(void*). Doesn't include internal members like + * unknown fields, extension dict, pointer to msglayout, etc. */ + uint16_t size; + uint16_t field_count; + bool extendable; +} upb_msglayout; + +/** upb_msg *******************************************************************/ + +/* Internal members of a upb_msg. We can change this without breaking binary + * compatibility. We put these before the user's data. The user's upb_msg* + * points after the upb_msg_internal. */ + +/* Used when a message is not extendable. */ +typedef struct { + char *unknown; + size_t unknown_len; + size_t unknown_size; +} upb_msg_internal; + +/* Used when a message is extendable. */ +typedef struct { + upb_inttable *extdict; + upb_msg_internal base; +} upb_msg_internal_withext; + +/* Maps upb_fieldtype_t -> memory size. */ +extern char _upb_fieldtype_to_size[12]; + +/* Creates a new messages with the given layout on the given arena. */ +upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a); + +/* Adds unknown data (serialized protobuf data) to the given message. The data + * is copied into the message instance. */ +bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, + upb_arena *arena); + +/* Returns a reference to the message's unknown data. */ +const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); + +UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) { + return (*PTR_AT(msg, idx / 8, const char) & (1 << (idx % 8))) != 0; +} + +UPB_INLINE bool _upb_sethas(const void *msg, size_t idx) { + return (*PTR_AT(msg, idx / 8, char)) |= (char)(1 << (idx % 8)); +} + +UPB_INLINE bool _upb_clearhas(const void *msg, size_t idx) { + return (*PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8))); +} + +UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) { + return *PTR_AT(msg, case_ofs, int32_t) == num; +} + +UPB_INLINE bool _upb_has_submsg_nohasbit(const void *msg, size_t ofs) { + return *PTR_AT(msg, ofs, const void*) != NULL; +} + +UPB_INLINE bool _upb_isrepeated(const upb_msglayout_field *field) { + return (field->label & 3) == UPB_LABEL_REPEATED; +} + +/** upb_array *****************************************************************/ + +/* Our internal representation for repeated fields. */ +typedef struct { + uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ + size_t len; /* Measured in elements. */ + size_t size; /* Measured in elements. */ +} upb_array; + +UPB_INLINE const void *_upb_array_constptr(const upb_array *arr) { + return (void*)(arr->data & ~(uintptr_t)7); +} + +UPB_INLINE void *_upb_array_ptr(upb_array *arr) { + return (void*)_upb_array_constptr(arr); +} + +/* Creates a new array on the given arena. */ +upb_array *_upb_array_new(upb_arena *a, upb_fieldtype_t type); + +/* Resizes the capacity of the array to be at least min_size. */ +bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena); + +/* Fallback functions for when the accessors require a resize. */ +void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size, + upb_fieldtype_t type, upb_arena *arena); +bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value, + upb_fieldtype_t type, upb_arena *arena); UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs, size_t *size) { const upb_array *arr = *PTR_AT(msg, ofs, const upb_array*); if (arr) { if (size) *size = arr->len; - return arr->data; + return _upb_array_constptr(arr); } else { if (size) *size = 0; return NULL; @@ -1173,78 +1094,295 @@ UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs, upb_array *arr = *PTR_AT(msg, ofs, upb_array*); if (arr) { if (size) *size = arr->len; - return arr->data; + return _upb_array_ptr(arr); } else { if (size) *size = 0; return NULL; } } -/* TODO(haberman): this is a mess. It will improve when upb_array no longer - * carries reflective state (type, elem_size). */ UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size, - size_t elem_size, upb_fieldtype_t type, upb_arena *arena) { - upb_array *arr = *PTR_AT(msg, ofs, upb_array*); - - if (!arr) { - arr = upb_array_new(arena); - if (!arr) return NULL; - *PTR_AT(msg, ofs, upb_array*) = arr; + upb_array **arr_ptr = PTR_AT(msg, ofs, upb_array*); + upb_array *arr = *arr_ptr; + if (!arr || arr->size < size) { + return _upb_array_resize_fallback(arr_ptr, size, type, arena); } - - if (size > arr->size) { - size_t new_size = UPB_MAX(arr->size, 4); - size_t old_bytes = arr->size * elem_size; - size_t new_bytes; - while (new_size < size) new_size *= 2; - new_bytes = new_size * elem_size; - arr->data = upb_arena_realloc(arena, arr->data, old_bytes, new_bytes); - if (!arr->data) { - return NULL; - } - arr->size = new_size; - } - arr->len = size; - return arr->data; + return _upb_array_ptr(arr); } + UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs, size_t elem_size, upb_fieldtype_t type, const void *value, upb_arena *arena) { - upb_array *arr = *PTR_AT(msg, ofs, upb_array*); - size_t i = arr ? arr->len : 0; - void *data = - _upb_array_resize_accessor(msg, ofs, i + 1, elem_size, type, arena); - if (!data) return false; - memcpy(PTR_AT(data, i * elem_size, char), value, elem_size); + upb_array **arr_ptr = PTR_AT(msg, ofs, upb_array*); + upb_array *arr = *arr_ptr; + void* ptr; + if (!arr || arr->len == arr->size) { + return _upb_array_append_fallback(arr_ptr, value, type, arena); + } + ptr = _upb_array_ptr(arr); + memcpy(PTR_AT(ptr, arr->len * elem_size, char), value, elem_size); + arr->len++; return true; } -UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) { - return (*PTR_AT(msg, idx / 8, const char) & (1 << (idx % 8))) != 0; -} +/** upb_map *******************************************************************/ -UPB_INLINE bool _upb_sethas(const void *msg, size_t idx) { - return (*PTR_AT(msg, idx / 8, char)) |= (char)(1 << (idx % 8)); -} +/* Right now we use strmaps for everything. We'll likely want to use + * integer-specific maps for integer-keyed maps.*/ +typedef struct { + /* 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; -UPB_INLINE bool _upb_clearhas(const void *msg, size_t idx) { - return (*PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8))); -} + upb_strtable table; +} upb_map; -UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) { - return *PTR_AT(msg, case_ofs, int32_t) == num; +/* Map entries aren't actually stored, they are only used during parsing. For + * parsing, it helps a lot if all map entry messages have the same layout. + * The compiler and def.c must ensure that all map entries have this layout. */ +typedef struct { + upb_msg_internal internal; + union { + upb_strview str; /* For str/bytes. */ + upb_value val; /* For all other types. */ + } k; + union { + upb_strview str; /* For str/bytes. */ + upb_value val; /* For all other types. */ + } v; +} upb_map_entry; + +/* Creates a new map on the given arena with this key/value type. */ +upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size); + +/* 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_strview _upb_map_tokey(const void *key, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + return *(upb_strview*)key; + } else { + return upb_strview_make((const char*)key, size); + } +} + +UPB_INLINE void _upb_map_fromkey(upb_strview key, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + memcpy(out, &key, sizeof(key)); + } else { + memcpy(out, key.data, size); + } +} + +UPB_INLINE upb_value _upb_map_tovalue(const void *val, size_t size, + upb_arena *a) { + upb_value ret = {0}; + if (size == UPB_MAPTYPE_STRING) { + upb_strview *strp = (upb_strview*)upb_arena_malloc(a, sizeof(*strp)); + *strp = *(upb_strview*)val; + memcpy(&ret, &strp, sizeof(strp)); + } else { + memcpy(&ret, val, size); + } + return ret; +} + +UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + const upb_strview *strp = (const upb_strview*)upb_value_getptr(val); + memcpy(out, strp, sizeof(upb_strview)); + } else { + memcpy(out, &val, size); + } +} + +/* Map operations, shared by reflection and generated code. */ + +UPB_INLINE size_t _upb_map_size(const upb_map *map) { + return map->table.t.count; +} + +UPB_INLINE bool _upb_map_get(const upb_map *map, const void *key, + size_t key_size, void *val, size_t val_size) { + upb_value tabval; + upb_strview k = _upb_map_tokey(key, key_size); + bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); + if (ret) { + _upb_map_fromvalue(tabval, val, val_size); + } + return ret; +} + +UPB_INLINE void* _upb_map_next(const upb_map *map, size_t *iter) { + upb_strtable_iter it; + it.t = &map->table; + it.index = *iter; + upb_strtable_next(&it); + if (upb_strtable_done(&it)) return NULL; + *iter = it.index; + return (void*)str_tabent(&it); +} + +UPB_INLINE bool _upb_map_set(upb_map *map, const void *key, size_t key_size, + void *val, size_t val_size, upb_arena *arena) { + upb_strview strkey = _upb_map_tokey(key, key_size); + upb_value tabval = _upb_map_tovalue(val, val_size, arena); + upb_alloc *a = upb_arena_alloc(arena); + + /* TODO(haberman): add overwrite operation to minimize number of lookups. */ + upb_strtable_remove3(&map->table, strkey.data, strkey.size, NULL, a); + return upb_strtable_insert3(&map->table, strkey.data, strkey.size, tabval, a); +} + +UPB_INLINE bool _upb_map_delete(upb_map *map, const void *key, size_t key_size) { + upb_strview k = _upb_map_tokey(key, key_size); + return upb_strtable_remove3(&map->table, k.data, k.size, NULL, NULL); +} + +UPB_INLINE void _upb_map_clear(upb_map *map) { + upb_strtable_clear(&map->table); +} + +/* Message map operations, these get the map from the message first. */ + +UPB_INLINE size_t _upb_msg_map_size(const upb_msg *msg, size_t ofs) { + upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); + return map ? _upb_map_size(map) : 0; +} + +UPB_INLINE bool _upb_msg_map_get(const upb_msg *msg, size_t ofs, + const void *key, size_t key_size, void *val, + size_t val_size) { + upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); + if (!map) return false; + return _upb_map_get(map, key, key_size, val, val_size); +} + +UPB_INLINE void *_upb_msg_map_next(const upb_msg *msg, size_t ofs, + size_t *iter) { + upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); + if (!map) return NULL; + return _upb_map_next(map, iter); +} + +UPB_INLINE bool _upb_msg_map_set(upb_msg *msg, size_t ofs, const void *key, + size_t key_size, void *val, size_t val_size, + upb_arena *arena) { + upb_map **map = PTR_AT(msg, ofs, upb_map *); + if (!*map) { + *map = _upb_map_new(arena, key_size, val_size); + } + return _upb_map_set(*map, key, key_size, val, val_size, arena); +} + +UPB_INLINE bool _upb_msg_map_delete(upb_msg *msg, size_t ofs, const void *key, + size_t key_size) { + upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); + if (!map) return false; + return _upb_map_delete(map, key, key_size); +} + +UPB_INLINE void _upb_msg_map_clear(upb_msg *msg, size_t ofs) { + upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); + if (!map) return; + _upb_map_clear(map); +} + +/* Accessing map key/value from a pointer, used by generated code only. */ + +UPB_INLINE void _upb_msg_map_key(const void* msg, void* key, size_t size) { + const upb_tabent *ent = (const upb_tabent*)msg; + uint32_t u32len; + upb_strview k; + k.data = upb_tabstr(ent->key, &u32len); + k.size = u32len; + _upb_map_fromkey(k, key, size); +} + +UPB_INLINE void _upb_msg_map_value(const void* msg, void* val, size_t size) { + const upb_tabent *ent = (const upb_tabent*)msg; + upb_value v; + _upb_value_setval(&v, ent->val.val); + _upb_map_fromvalue(v, val, size); +} + +UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, size_t size) { + upb_tabent *ent = (upb_tabent*)msg; + /* This is like _upb_map_tovalue() except the entry already exists so we can + * reuse the allocated upb_strview for string fields. */ + if (size == UPB_MAPTYPE_STRING) { + upb_strview *strp = (upb_strview*)ent->val.val; + memcpy(strp, val, sizeof(*strp)); + } else { + memcpy(&ent->val.val, val, size); + } } #undef PTR_AT +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MSG_H_ */ + +#ifdef __cplusplus +extern "C" { +#endif + +bool upb_decode(const char *buf, size_t size, upb_msg *msg, + const upb_msglayout *l, upb_arena *arena); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* UPB_DECODE_H_ */ +/* +** upb_encode: parsing into a upb_msg using a upb_msglayout. +*/ + +#ifndef UPB_ENCODE_H_ +#define UPB_ENCODE_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena, + size_t *size); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* UPB_ENCODE_H_ */ +/* This file was generated by upbc (the upb compiler) from the input + * file: + * + * google/protobuf/descriptor.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ +#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -#endif /* UPB_GENERATED_UTIL_H_ */ #ifdef __cplusplus @@ -1388,7 +1526,7 @@ typedef enum { /* google.protobuf.FileDescriptorSet */ UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) { - return (google_protobuf_FileDescriptorSet *)upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena); + return (google_protobuf_FileDescriptorSet *)_upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena); } UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1399,16 +1537,17 @@ UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protob return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len); } +UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg, size_t *len) { return (const google_protobuf_FileDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet *msg, size_t *len) { return (google_protobuf_FileDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet *msg, upb_arena *arena) { - struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); + struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1418,7 +1557,7 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescr /* google.protobuf.FileDescriptorProto */ UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_FileDescriptorProto *)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); + return (google_protobuf_FileDescriptorProto *)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1430,49 +1569,53 @@ UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_prot } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); } +UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); } UPB_INLINE upb_strview const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); } +UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); } +UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(44, 88)); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); } +UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(48, 96)); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(48, 96), len); } +UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(52, 104)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 4); } -UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FileOptions*, UPB_SIZE(28, 56)); } +UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_FileOptions*); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 5); } -UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)); } +UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_SourceCodeInfo*); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(56, 112), len); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(60, 120), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); } +UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value; } UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena); + return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_TYPE_STRING, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(36, 72), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(36, 72), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, + arena); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1482,10 +1625,10 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len); } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(44, 88), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1495,10 +1638,10 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len); } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(48, 96), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(48, 96), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); + struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(48, 96), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1508,10 +1651,10 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(52, 104), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(52, 104), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(52, 104), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1519,12 +1662,12 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDesc } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { _upb_sethas(msg, 4); - UPB_FIELD_AT(msg, google_protobuf_FileOptions*, UPB_SIZE(28, 56)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_FileOptions*) = 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_msg_new(&google_protobuf_FileOptions_msginit, arena); + sub = (struct google_protobuf_FileOptions*)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_options(msg, sub); } @@ -1532,12 +1675,12 @@ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorPro } UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { _upb_sethas(msg, 5); - UPB_FIELD_AT(msg, google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 64), google_protobuf_SourceCodeInfo*) = 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_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); + sub = (struct google_protobuf_SourceCodeInfo*)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub); } @@ -1547,31 +1690,31 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 112), len); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(56, 112), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena); + return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(56, 112), len, UPB_TYPE_INT32, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(56, 112), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(56, 112), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, + arena); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(60, 120), len); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(60, 120), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena); + return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(60, 120), len, UPB_TYPE_INT32, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(60, 120), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(60, 120), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, + arena); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value; } /* google.protobuf.DescriptorProto */ UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { - return (google_protobuf_DescriptorProto *)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); + return (google_protobuf_DescriptorProto *)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1583,30 +1726,37 @@ UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); } +UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } +UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(24, 48)); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } +UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 56)); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); } +UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 64)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(32, 64), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MessageOptions*, UPB_SIZE(12, 24)); } +UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_MessageOptions*); } +UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); } +UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); } UPB_INLINE upb_strview const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); } UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1616,10 +1766,10 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mut return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1629,10 +1779,10 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(24, 48), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1642,10 +1792,10 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); + struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(28, 56), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1655,10 +1805,10 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(32, 64), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(32, 64), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(32, 64), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1666,12 +1816,12 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, google_protobuf_MessageOptions*, UPB_SIZE(12, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_MessageOptions*) = 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_msg_new(&google_protobuf_MessageOptions_msginit, arena); + sub = (struct google_protobuf_MessageOptions*)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_set_options(msg, sub); } @@ -1681,10 +1831,10 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); + struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(36, 72), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1694,10 +1844,10 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len); } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); + struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1707,17 +1857,17 @@ UPB_INLINE upb_strview* google_protobuf_DescriptorProto_mutable_reserved_name(go return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len); } UPB_INLINE upb_strview* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena); + return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_TYPE_STRING, arena); } UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, + arena); } /* google.protobuf.DescriptorProto.ExtensionRange */ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { - return (google_protobuf_DescriptorProto_ExtensionRange *)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); + return (google_protobuf_DescriptorProto_ExtensionRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1729,28 +1879,28 @@ UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)); } +UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const google_protobuf_ExtensionRangeOptions*); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value; } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 16), google_protobuf_ExtensionRangeOptions*) = 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_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); + sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub); } @@ -1760,7 +1910,7 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_Descrip /* google.protobuf.DescriptorProto.ReservedRange */ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { - return (google_protobuf_DescriptorProto_ReservedRange *)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); + return (google_protobuf_DescriptorProto_ReservedRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1772,23 +1922,23 @@ UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const g } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value; } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } /* google.protobuf.ExtensionRangeOptions */ UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { - return (google_protobuf_ExtensionRangeOptions *)upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); + return (google_protobuf_ExtensionRangeOptions *)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); } UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1799,16 +1949,17 @@ UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_pr return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len); } +UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1818,7 +1969,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_Extension /* google.protobuf.FieldDescriptorProto */ UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto *)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); + return (google_protobuf_FieldDescriptorProto *)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1829,63 +1980,65 @@ UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_pro return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len); } -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 5); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); } -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 6); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 6); } +UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_strview); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 7); } +UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_strview); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), int32_t); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)); } -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 7); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); } -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 8); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)); } -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 10); } -UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FieldOptions*, UPB_SIZE(72, 112)); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 8); } +UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_strview); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 9); } +UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 88), upb_strview); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 11); } +UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 120), const google_protobuf_FieldOptions*); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 4); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)); } -UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 9); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 28), int32_t); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 10); } +UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 104), upb_strview); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 5); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), bool); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { - _upb_sethas(msg, 5); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value; + _upb_sethas(msg, 6); + *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_strview) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { - _upb_sethas(msg, 6); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value; + _upb_sethas(msg, 7); + *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_strview) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), int32_t) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { - _upb_sethas(msg, 7); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value; + _upb_sethas(msg, 8); + *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_strview) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { - _upb_sethas(msg, 8); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)) = value; + _upb_sethas(msg, 9); + *UPB_PTR_AT(msg, UPB_SIZE(60, 88), upb_strview) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { - _upb_sethas(msg, 10); - UPB_FIELD_AT(msg, google_protobuf_FieldOptions*, UPB_SIZE(72, 112)) = value; + _upb_sethas(msg, 11); + *UPB_PTR_AT(msg, UPB_SIZE(76, 120), google_protobuf_FieldOptions*) = 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_msg_new(&google_protobuf_FieldOptions_msginit, arena); + sub = (struct google_protobuf_FieldOptions*)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FieldDescriptorProto_set_options(msg, sub); } @@ -1893,17 +2046,21 @@ UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorP } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 4); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 28), int32_t) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { - _upb_sethas(msg, 9); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)) = value; + _upb_sethas(msg, 10); + *UPB_PTR_AT(msg, UPB_SIZE(68, 104), upb_strview) = value; +} +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { + _upb_sethas(msg, 5); + *UPB_PTR_AT(msg, UPB_SIZE(32, 32), bool) = value; } /* google.protobuf.OneofDescriptorProto */ UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_OneofDescriptorProto *)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); + return (google_protobuf_OneofDescriptorProto *)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1915,22 +2072,22 @@ UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_pro } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_OneofOptions*, UPB_SIZE(12, 24)); } +UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, google_protobuf_OneofOptions*, UPB_SIZE(12, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_OneofOptions*) = 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_msg_new(&google_protobuf_OneofOptions_msginit, arena); + sub = (struct google_protobuf_OneofOptions*)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); if (!sub) return NULL; google_protobuf_OneofDescriptorProto_set_options(msg, sub); } @@ -1940,7 +2097,7 @@ UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorP /* google.protobuf.EnumDescriptorProto */ UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto *)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); + return (google_protobuf_EnumDescriptorProto *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -1952,25 +2109,27 @@ UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_prot } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumOptions*, UPB_SIZE(12, 24)); } +UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_EnumOptions*); } +UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE upb_strview const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); + struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -1978,12 +2137,12 @@ UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_Enum } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, google_protobuf_EnumOptions*, UPB_SIZE(12, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_EnumOptions*) = 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_msg_new(&google_protobuf_EnumOptions_msginit, arena); + sub = (struct google_protobuf_EnumOptions*)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumDescriptorProto_set_options(msg, sub); } @@ -1993,10 +2152,10 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); + struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2006,17 +2165,17 @@ UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_mutable_reserved_nam return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena); + return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_STRING, arena); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, + arena); } /* google.protobuf.EnumDescriptorProto.EnumReservedRange */ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2028,23 +2187,23 @@ UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value; } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } /* google.protobuf.EnumValueDescriptorProto */ UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_EnumValueDescriptorProto *)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); + return (google_protobuf_EnumValueDescriptorProto *)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2056,28 +2215,28 @@ UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)); } +UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview); } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)); } +UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview) = value; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), google_protobuf_EnumValueOptions*) = 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_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); + sub = (struct google_protobuf_EnumValueOptions*)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumValueDescriptorProto_set_options(msg, sub); } @@ -2087,7 +2246,7 @@ UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDes /* google.protobuf.ServiceDescriptorProto */ UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_ServiceDescriptorProto *)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); + return (google_protobuf_ServiceDescriptorProto *)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2099,23 +2258,24 @@ UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_p } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg, size_t *len) { return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)); } +UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_ServiceOptions*); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto *msg, size_t *len) { return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); + struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2123,12 +2283,12 @@ UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_Service } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_ServiceOptions*) = 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_msg_new(&google_protobuf_ServiceOptions_msginit, arena); + sub = (struct google_protobuf_ServiceOptions*)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); if (!sub) return NULL; google_protobuf_ServiceDescriptorProto_set_options(msg, sub); } @@ -2138,7 +2298,7 @@ UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescrip /* google.protobuf.MethodDescriptorProto */ UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_MethodDescriptorProto *)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); + return (google_protobuf_MethodDescriptorProto *)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2150,38 +2310,38 @@ UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_pr } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 4); } -UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); } +UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 5); } -UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); } +UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 6); } -UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MethodOptions*, UPB_SIZE(28, 56)); } +UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } +UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 4); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) { _upb_sethas(msg, 5); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { _upb_sethas(msg, 6); - UPB_FIELD_AT(msg, google_protobuf_MethodOptions*, UPB_SIZE(28, 56)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_MethodOptions*) = 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_msg_new(&google_protobuf_MethodOptions_msginit, arena); + sub = (struct google_protobuf_MethodOptions*)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); if (!sub) return NULL; google_protobuf_MethodDescriptorProto_set_options(msg, sub); } @@ -2189,17 +2349,17 @@ UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescripto } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value; } /* google.protobuf.FileOptions */ UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { - return (google_protobuf_FileOptions *)upb_msg_new(&google_protobuf_FileOptions_msginit, arena); + return (google_protobuf_FileOptions *)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena); } UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2211,135 +2371,136 @@ UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_Fil } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 11); } -UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 32), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 12); } -UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 48), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); } +UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 13); } -UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 64), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)); } +UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(17, 17), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 4); } -UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)); } +UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(18, 18), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 5); } -UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)); } +UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(19, 19), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 6); } -UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)); } +UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 7); } -UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)); } +UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(21, 21), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 8); } -UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)); } +UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(22, 22), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 9); } -UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)); } +UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(23, 23), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 14); } -UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 80), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 15); } -UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 96), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 16); } -UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 112), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 17); } -UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 128), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 18); } -UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(84, 144), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 10); } -UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); } +UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool); } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 19); } -UPB_INLINE upb_strview google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(92, 160)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(92, 160), upb_strview); } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 20); } -UPB_INLINE upb_strview google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(100, 176)); } +UPB_INLINE upb_strview google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(100, 176), upb_strview); } +UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(108, 192)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(108, 192), len); } UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 11); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 32), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 12); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(36, 48), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 13); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(44, 64), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(17, 17), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 4); - UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(18, 18), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 5); - UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(19, 19), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 6); - UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 7); - UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(21, 21), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 8); - UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(22, 22), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 9); - UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(23, 23), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 14); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(52, 80), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 15); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(60, 96), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 16); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(68, 112), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 17); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(76, 128), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 18); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(84, 144), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 10); - UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 19); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(92, 160)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(92, 160), upb_strview) = value; } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_strview value) { _upb_sethas(msg, 20); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(100, 176)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(100, 176), upb_strview) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(108, 192), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(108, 192), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(108, 192), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(108, 192), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2349,7 +2510,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptio /* google.protobuf.MessageOptions */ UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { - return (google_protobuf_MessageOptions *)upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); + return (google_protobuf_MessageOptions *)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); } UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2361,39 +2522,40 @@ UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_ } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } +UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)); } +UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool); } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 4); } -UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)); } +UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool); } +UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(8, 8), len); } UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; } UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value; } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool) = value; } UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { _upb_sethas(msg, 4); - UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 8), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(8, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(8, 8), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(8, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2403,7 +2565,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOp /* google.protobuf.FieldOptions */ UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { - return (google_protobuf_FieldOptions *)upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); + return (google_protobuf_FieldOptions *)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); } UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2415,51 +2577,52 @@ UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_Fi } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); } +UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool); } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 4); } -UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)); } +UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(25, 25), bool); } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 5); } -UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)); } +UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(26, 26), bool); } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)); } +UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 6); } -UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)); } +UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(27, 27), bool); } +UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 32)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(28, 32), len); } UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool) = value; } UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { _upb_sethas(msg, 4); - UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(25, 25), bool) = value; } UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { _upb_sethas(msg, 5); - UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(26, 26), bool) = value; } UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value; } UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { _upb_sethas(msg, 6); - UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(27, 27), bool) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 32), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 32), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(28, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2469,7 +2632,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOpti /* google.protobuf.OneofOptions */ UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { - return (google_protobuf_OneofOptions *)upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); + return (google_protobuf_OneofOptions *)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); } UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2480,16 +2643,17 @@ UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_On return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len); } +UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2499,7 +2663,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOpti /* google.protobuf.EnumOptions */ UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { - return (google_protobuf_EnumOptions *)upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); + return (google_protobuf_EnumOptions *)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); } UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2511,27 +2675,28 @@ UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_Enu } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } +UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); } +UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); } UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2541,7 +2706,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptio /* google.protobuf.EnumValueOptions */ UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { - return (google_protobuf_EnumValueOptions *)upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); + return (google_protobuf_EnumValueOptions *)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); } UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2553,21 +2718,22 @@ UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobu } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); } UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2577,7 +2743,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValue /* google.protobuf.ServiceOptions */ UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { - return (google_protobuf_ServiceOptions *)upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); + return (google_protobuf_ServiceOptions *)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); } UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2589,21 +2755,22 @@ UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); } UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2613,7 +2780,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOp /* google.protobuf.MethodOptions */ UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { - return (google_protobuf_MethodOptions *)upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); + return (google_protobuf_MethodOptions *)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); } UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2625,27 +2792,28 @@ UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_M } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); } +UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } +UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 24)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(20, 24), len); } UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value; } UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 24), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 24), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 24), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(20, 24), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2655,7 +2823,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOpt /* google.protobuf.UninterpretedOption */ UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { - return (google_protobuf_UninterpretedOption *)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); + return (google_protobuf_UninterpretedOption *)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); } UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2666,28 +2834,29 @@ UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_prot return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len); } +UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(56, 80)); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg, size_t *len) { return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_accessor(msg, UPB_SIZE(56, 80), len); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 4); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); } +UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)); } +UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)); } +UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)); } +UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 5); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); } +UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 6); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); } +UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption *msg, size_t *len) { return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 80), len); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor(msg, UPB_SIZE(56, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor(msg, UPB_SIZE(56, 80), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); + struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(56, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2695,33 +2864,33 @@ UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_ } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_strview value) { _upb_sethas(msg, 4); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_strview value) { _upb_sethas(msg, 5); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_strview value) { _upb_sethas(msg, 6); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview) = 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_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); + return (google_protobuf_UninterpretedOption_NamePart *)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2733,23 +2902,23 @@ UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const go } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_strview value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; } /* google.protobuf.SourceCodeInfo */ UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { - return (google_protobuf_SourceCodeInfo *)upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); + return (google_protobuf_SourceCodeInfo *)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); } UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2760,16 +2929,17 @@ UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_ return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len); } +UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg, size_t *len) { return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo *msg, size_t *len) { return (google_protobuf_SourceCodeInfo_Location**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo *msg, size_t len, upb_arena *arena) { - return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo *msg, upb_arena *arena) { - struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); + struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2779,7 +2949,7 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_Sourc /* google.protobuf.SourceCodeInfo.Location */ UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { - return (google_protobuf_SourceCodeInfo_Location *)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); + return (google_protobuf_SourceCodeInfo_Location *)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); } UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2793,54 +2963,54 @@ UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); } +UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); } +UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); } UPB_INLINE upb_strview const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena); + return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_INT32, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(20, 40), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(20, 40), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, + arena); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena); + return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_INT32, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(24, 48), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(24, 48), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, + arena); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value; } UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena); + return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_TYPE_STRING, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, + arena); } /* google.protobuf.GeneratedCodeInfo */ UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { - return (google_protobuf_GeneratedCodeInfo *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena); + return (google_protobuf_GeneratedCodeInfo *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena); } UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2851,16 +3021,17 @@ UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protob return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len); } +UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg, size_t *len) { return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t *len) { return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t len, upb_arena *arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena) { - struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); + struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); bool ok = _upb_array_append_accessor( msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena); if (!ok) return NULL; @@ -2870,7 +3041,7 @@ UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_ /* google.protobuf.GeneratedCodeInfo.Annotation */ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse(const char *buf, size_t size, upb_arena *arena) { @@ -2883,33 +3054,33 @@ UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const go UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 32), len); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 3); } -UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)); } +UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 1); } -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 2); } -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 32), len); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 32), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena); + return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 32), len, UPB_TYPE_INT32, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor( - msg, UPB_SIZE(20, 32), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena); + return _upb_array_append_accessor(msg, UPB_SIZE(20, 32), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, + arena); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_strview value) { _upb_sethas(msg, 3); - UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 1); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 2); - UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } #ifdef __cplusplus @@ -2922,38 +3093,23 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_prot ** Defs are upb's internal representation of the constructs that can appear ** in a .proto file: ** -** - upb::MessageDefPtr (upb_msgdef): describes a "message" construct. -** - upb::FieldDefPtr (upb_fielddef): describes a message field. -** - upb::FileDefPtr (upb_filedef): describes a .proto file and its defs. -** - upb::EnumDefPtr (upb_enumdef): describes an enum. -** - upb::OneofDefPtr (upb_oneofdef): describes a oneof. +** - upb_msgdef: describes a "message" construct. +** - upb_fielddef: describes a message field. +** - upb_filedef: describes a .proto file and its defs. +** - upb_enumdef: describes an enum. +** - upb_oneofdef: describes a oneof. ** ** TODO: definitions of services. -** -** This is a mixed C/C++ interface that offers a full API to both languages. -** See the top-level README for more information. */ #ifndef UPB_DEF_H_ #define UPB_DEF_H_ -#ifdef __cplusplus -#include -#include -#include -#include - -namespace upb { -class EnumDefPtr; -class FieldDefPtr; -class FileDefPtr; -class MessageDefPtr; -class OneofDefPtr; -class SymbolTable; -} -#endif +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ struct upb_enumdef; typedef struct upb_enumdef upb_enumdef; @@ -3005,22 +3161,20 @@ typedef enum { * protobuf wire format. */ #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) -#ifdef __cplusplus -extern "C" { -#endif - const char *upb_fielddef_fullname(const upb_fielddef *f); upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f); upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f); upb_label_t upb_fielddef_label(const upb_fielddef *f); uint32_t upb_fielddef_number(const upb_fielddef *f); const char *upb_fielddef_name(const upb_fielddef *f); +const char *upb_fielddef_jsonname(const upb_fielddef *f); bool upb_fielddef_isextension(const upb_fielddef *f); bool upb_fielddef_lazy(const upb_fielddef *f); bool upb_fielddef_packed(const upb_fielddef *f); -size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len); +const upb_filedef *upb_fielddef_file(const upb_fielddef *f); const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f); const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f); +const upb_oneofdef *upb_fielddef_realcontainingoneof(const upb_fielddef *f); uint32_t upb_fielddef_index(const upb_fielddef *f); bool upb_fielddef_issubmsg(const upb_fielddef *f); bool upb_fielddef_isstring(const upb_fielddef *f); @@ -3039,155 +3193,20 @@ bool upb_fielddef_hassubdef(const upb_fielddef *f); bool upb_fielddef_haspresence(const upb_fielddef *f); const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f); const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f); +const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f); /* Internal only. */ uint32_t upb_fielddef_selectorbase(const upb_fielddef *f); -#ifdef __cplusplus -} /* extern "C" */ - -/* A upb_fielddef describes a single field in a message. It is most often - * found as a part of a upb_msgdef, but can also stand alone to represent - * an extension. */ -class upb::FieldDefPtr { - public: - FieldDefPtr() : ptr_(nullptr) {} - explicit FieldDefPtr(const upb_fielddef *ptr) : ptr_(ptr) {} - - const upb_fielddef* ptr() const { return ptr_; } - explicit operator bool() const { return ptr_ != nullptr; } - - typedef upb_fieldtype_t Type; - typedef upb_label_t Label; - typedef upb_descriptortype_t DescriptorType; - - const char* full_name() const { return upb_fielddef_fullname(ptr_); } - - Type type() const { return upb_fielddef_type(ptr_); } - Label label() const { return upb_fielddef_label(ptr_); } - const char* name() const { return upb_fielddef_name(ptr_); } - uint32_t number() const { return upb_fielddef_number(ptr_); } - bool is_extension() const { return upb_fielddef_isextension(ptr_); } - - /* Copies the JSON name for this field into the given buffer. Returns the - * actual size of the JSON name, including the NULL terminator. If the - * return value is 0, the JSON name is unset. If the return value is - * greater than len, the JSON name was truncated. The buffer is always - * NULL-terminated if len > 0. - * - * The JSON name always defaults to a camelCased version of the regular - * name. However if the regular name is unset, the JSON name will be unset - * also. - */ - size_t GetJsonName(char *buf, size_t len) const { - return upb_fielddef_getjsonname(ptr_, buf, len); - } - - /* Convenience version of the above function which copies the JSON name - * into the given string, returning false if the name is not set. */ - template - bool GetJsonName(T* str) { - str->resize(GetJsonName(NULL, 0)); - GetJsonName(&(*str)[0], str->size()); - return str->size() > 0; - } - - /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false, - * indicates whether this field should have lazy parsing handlers that yield - * the unparsed string for the submessage. - * - * TODO(haberman): I think we want to move this into a FieldOptions container - * when we add support for custom options (the FieldOptions struct will - * contain both regular FieldOptions like "lazy" *and* custom options). */ - bool lazy() const { return upb_fielddef_lazy(ptr_); } - - /* For non-string, non-submessage fields, this indicates whether binary - * protobufs are encoded in packed or non-packed format. - * - * TODO(haberman): see note above about putting options like this into a - * FieldOptions container. */ - bool packed() const { return upb_fielddef_packed(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. */ - uint32_t index() const { return upb_fielddef_index(ptr_); } - - /* The MessageDef to which this field belongs. - * - * If this field has been added to a MessageDef, that message can be retrieved - * directly (this is always the case for frozen FieldDefs). - * - * If the field has not yet been added to a MessageDef, you can set the name - * of the containing type symbolically instead. This is mostly useful for - * extensions, where the extension is declared separately from the message. */ - MessageDefPtr containing_type() const; - - /* The OneofDef to which this field belongs, or NULL if this field is not part - * of a oneof. */ - OneofDefPtr containing_oneof() const; - - /* The field's type according to the enum in descriptor.proto. This is not - * the same as UPB_TYPE_*, because it distinguishes between (for example) - * INT32 and SINT32, whereas our "type" enum does not. This return of - * descriptor_type() is a function of type(), integer_format(), and - * is_tag_delimited(). */ - DescriptorType descriptor_type() const { - return upb_fielddef_descriptortype(ptr_); - } - - /* Convenient field type tests. */ - bool IsSubMessage() const { return upb_fielddef_issubmsg(ptr_); } - bool IsString() const { return upb_fielddef_isstring(ptr_); } - bool IsSequence() const { return upb_fielddef_isseq(ptr_); } - bool IsPrimitive() const { return upb_fielddef_isprimitive(ptr_); } - bool IsMap() const { return upb_fielddef_ismap(ptr_); } - - /* Returns the non-string default value for this fielddef, which may either - * be something the client set explicitly or the "default default" (0 for - * numbers, empty for strings). The field's type indicates the type of the - * returned value, except for enum fields that are still mutable. - * - * Requires that the given function matches the field's current type. */ - int64_t default_int64() const { return upb_fielddef_defaultint64(ptr_); } - int32_t default_int32() const { return upb_fielddef_defaultint32(ptr_); } - uint64_t default_uint64() const { return upb_fielddef_defaultuint64(ptr_); } - uint32_t default_uint32() const { return upb_fielddef_defaultuint32(ptr_); } - bool default_bool() const { return upb_fielddef_defaultbool(ptr_); } - float default_float() const { return upb_fielddef_defaultfloat(ptr_); } - double default_double() const { return upb_fielddef_defaultdouble(ptr_); } - - /* The resulting string is always NULL-terminated. If non-NULL, the length - * will be stored in *len. */ - const char *default_string(size_t * len) const { - return upb_fielddef_defaultstr(ptr_, len); - } - - /* 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() == UPB_TYPE_ENUM). */ - EnumDefPtr enum_subdef() const; - MessageDefPtr message_subdef() const; - - private: - const upb_fielddef *ptr_; -}; - -#endif /* __cplusplus */ - /* upb_oneofdef ***************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif - typedef upb_inttable_iter upb_oneof_iter; const char *upb_oneofdef_name(const upb_oneofdef *o); const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o); int upb_oneofdef_numfields(const upb_oneofdef *o); uint32_t upb_oneofdef_index(const upb_oneofdef *o); +bool upb_oneofdef_issynthetic(const upb_oneofdef *o); /* Oneof lookups: * - ntof: look up a field by name. @@ -3214,92 +3233,6 @@ void upb_oneof_iter_setdone(upb_oneof_iter *iter); bool upb_oneof_iter_isequal(const upb_oneof_iter *iter1, const upb_oneof_iter *iter2); -#ifdef __cplusplus -} /* extern "C" */ - -/* Class that represents a oneof. */ -class upb::OneofDefPtr { - public: - OneofDefPtr() : ptr_(nullptr) {} - explicit OneofDefPtr(const upb_oneofdef *ptr) : ptr_(ptr) {} - - const upb_oneofdef* ptr() const { return ptr_; } - explicit operator bool() { return ptr_ != nullptr; } - - /* Returns the MessageDef that owns this OneofDef. */ - MessageDefPtr containing_type() const; - - /* Returns the name of this oneof. This is the name used to look up the oneof - * by name once added to a message def. */ - const char* name() const { return upb_oneofdef_name(ptr_); } - - /* Returns the number of fields currently defined in the oneof. */ - int field_count() const { return upb_oneofdef_numfields(ptr_); } - - /* Looks up by name. */ - FieldDefPtr FindFieldByName(const char *name, size_t len) const { - return FieldDefPtr(upb_oneofdef_ntof(ptr_, name, len)); - } - FieldDefPtr FindFieldByName(const char* name) const { - return FieldDefPtr(upb_oneofdef_ntofz(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_itof(ptr_, num)); - } - - class const_iterator - : public std::iterator { - public: - void operator++() { upb_oneof_next(&iter_); } - - FieldDefPtr operator*() const { - return FieldDefPtr(upb_oneof_iter_field(&iter_)); - } - - bool operator!=(const const_iterator& other) const { - return !upb_oneof_iter_isequal(&iter_, &other.iter_); - } - - bool operator==(const const_iterator& other) const { - return upb_oneof_iter_isequal(&iter_, &other.iter_); - } - - private: - friend class OneofDefPtr; - - const_iterator() {} - explicit const_iterator(OneofDefPtr o) { - upb_oneof_begin(&iter_, o.ptr()); - } - static const_iterator end() { - const_iterator iter; - upb_oneof_iter_setdone(&iter.iter_); - return iter; - } - - upb_oneof_iter iter_; - }; - - const_iterator begin() const { return const_iterator(*this); } - const_iterator end() const { return const_iterator::end(); } - - private: - const upb_oneofdef *ptr_; -}; - -inline upb::OneofDefPtr upb::FieldDefPtr::containing_oneof() const { - return OneofDefPtr(upb_fielddef_containingoneof(ptr_)); -} - -#endif /* __cplusplus */ - /* upb_msgdef *****************************************************************/ typedef upb_inttable_iter upb_msg_field_iter; @@ -3321,26 +3254,23 @@ typedef upb_strtable_iter upb_msg_oneof_iter; #define UPB_TIMESTAMP_SECONDS 1 #define UPB_TIMESTAMP_NANOS 2 -#ifdef __cplusplus -extern "C" { -#endif - const char *upb_msgdef_fullname(const upb_msgdef *m); const upb_filedef *upb_msgdef_file(const upb_msgdef *m); const char *upb_msgdef_name(const upb_msgdef *m); +int upb_msgdef_numfields(const upb_msgdef *m); int upb_msgdef_numoneofs(const upb_msgdef *m); +int upb_msgdef_numrealoneofs(const upb_msgdef *m); upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m); bool upb_msgdef_mapentry(const upb_msgdef *m); upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m); bool upb_msgdef_isnumberwrapper(const upb_msgdef *m); -bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax); const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i); const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, size_t len); const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, size_t len); -int upb_msgdef_numfields(const upb_msgdef *m); -int upb_msgdef_numoneofs(const upb_msgdef *m); +const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m); +const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i); UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m, const char *name) { @@ -3368,6 +3298,10 @@ UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name, return upb_msgdef_lookupname(m, name, strlen(name), f, o); } +/* Returns a field by either JSON name or regular proto name. */ +const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m, + const char *name, size_t len); + /* Iteration over fields and oneofs. For example: * * upb_msg_field_iter i; @@ -3399,194 +3333,6 @@ void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter * iter); bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1, const upb_msg_oneof_iter *iter2); -#ifdef __cplusplus -} /* extern "C" */ - -/* Structure that describes a single .proto message type. */ -class upb::MessageDefPtr { - public: - MessageDefPtr() : ptr_(nullptr) {} - explicit MessageDefPtr(const upb_msgdef *ptr) : ptr_(ptr) {} - - const upb_msgdef *ptr() const { return ptr_; } - explicit operator bool() const { return ptr_ != nullptr; } - - const char* full_name() const { return upb_msgdef_fullname(ptr_); } - const char* name() const { return upb_msgdef_name(ptr_); } - - /* The number of fields that belong to the MessageDef. */ - int field_count() const { return upb_msgdef_numfields(ptr_); } - - /* The number of oneofs that belong to the MessageDef. */ - int oneof_count() const { return upb_msgdef_numoneofs(ptr_); } - - upb_syntax_t syntax() const { return upb_msgdef_syntax(ptr_); } - - /* These return null pointers if the field is not found. */ - FieldDefPtr FindFieldByNumber(uint32_t number) const { - return FieldDefPtr(upb_msgdef_itof(ptr_, number)); - } - FieldDefPtr FindFieldByName(const char* name, size_t len) const { - return FieldDefPtr(upb_msgdef_ntof(ptr_, name, len)); - } - FieldDefPtr FindFieldByName(const char *name) const { - return FieldDefPtr(upb_msgdef_ntofz(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_msgdef_ntoo(ptr_, name, len)); - } - - OneofDefPtr FindOneofByName(const char *name) const { - return OneofDefPtr(upb_msgdef_ntooz(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_msgdef_mapentry(ptr_); } - - /* Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for - * non-well-known message. */ - upb_wellknowntype_t wellknowntype() const { - return upb_msgdef_wellknowntype(ptr_); - } - - /* Whether is a number wrapper. */ - bool isnumberwrapper() const { return upb_msgdef_isnumberwrapper(ptr_); } - - /* Iteration over fields. The order is undefined. */ - class const_field_iterator - : public std::iterator { - public: - void operator++() { upb_msg_field_next(&iter_); } - - FieldDefPtr operator*() const { - return FieldDefPtr(upb_msg_iter_field(&iter_)); - } - - bool operator!=(const const_field_iterator &other) const { - return !upb_msg_field_iter_isequal(&iter_, &other.iter_); - } - - bool operator==(const const_field_iterator &other) const { - return upb_msg_field_iter_isequal(&iter_, &other.iter_); - } - - private: - friend class MessageDefPtr; - - explicit const_field_iterator() {} - - explicit const_field_iterator(MessageDefPtr msg) { - upb_msg_field_begin(&iter_, msg.ptr()); - } - - static const_field_iterator end() { - const_field_iterator iter; - upb_msg_field_iter_setdone(&iter.iter_); - return iter; - } - - upb_msg_field_iter iter_; - }; - - /* Iteration over oneofs. The order is undefined. */ - class const_oneof_iterator - : public std::iterator { - public: - - void operator++() { upb_msg_oneof_next(&iter_); } - - OneofDefPtr operator*() const { - return OneofDefPtr(upb_msg_iter_oneof(&iter_)); - } - - bool operator!=(const const_oneof_iterator& other) const { - return !upb_msg_oneof_iter_isequal(&iter_, &other.iter_); - } - - bool operator==(const const_oneof_iterator &other) const { - return upb_msg_oneof_iter_isequal(&iter_, &other.iter_); - } - - private: - friend class MessageDefPtr; - - const_oneof_iterator() {} - - explicit const_oneof_iterator(MessageDefPtr msg) { - upb_msg_oneof_begin(&iter_, msg.ptr()); - } - - static const_oneof_iterator end() { - const_oneof_iterator iter; - upb_msg_oneof_iter_setdone(&iter.iter_); - return iter; - } - - upb_msg_oneof_iter iter_; - }; - - class ConstFieldAccessor { - public: - explicit ConstFieldAccessor(const upb_msgdef* md) : md_(md) {} - const_field_iterator begin() { return MessageDefPtr(md_).field_begin(); } - const_field_iterator end() { return MessageDefPtr(md_).field_end(); } - private: - const upb_msgdef* md_; - }; - - class ConstOneofAccessor { - public: - explicit ConstOneofAccessor(const upb_msgdef* md) : md_(md) {} - const_oneof_iterator begin() { return MessageDefPtr(md_).oneof_begin(); } - const_oneof_iterator end() { return MessageDefPtr(md_).oneof_end(); } - private: - const upb_msgdef* md_; - }; - - const_field_iterator field_begin() const { - return const_field_iterator(*this); - } - - const_field_iterator field_end() const { return const_field_iterator::end(); } - - const_oneof_iterator oneof_begin() const { - return const_oneof_iterator(*this); - } - - const_oneof_iterator oneof_end() const { return const_oneof_iterator::end(); } - - ConstFieldAccessor fields() const { return ConstFieldAccessor(ptr()); } - ConstOneofAccessor oneofs() const { return ConstOneofAccessor(ptr()); } - - private: - const upb_msgdef* ptr_; -}; - -inline upb::MessageDefPtr upb::FieldDefPtr::message_subdef() const { - return MessageDefPtr(upb_fielddef_msgsubdef(ptr_)); -} - -inline upb::MessageDefPtr upb::FieldDefPtr::containing_type() const { - return MessageDefPtr(upb_fielddef_containingtype(ptr_)); -} - -inline upb::MessageDefPtr upb::OneofDefPtr::containing_type() const { - return MessageDefPtr(upb_oneofdef_containingtype(ptr_)); -} - -#endif /* __cplusplus */ - /* upb_enumdef ****************************************************************/ typedef upb_strtable_iter upb_enum_iter; @@ -3621,75 +3367,8 @@ bool upb_enum_done(upb_enum_iter *iter); const char *upb_enum_iter_name(upb_enum_iter *iter); int32_t upb_enum_iter_number(upb_enum_iter *iter); -#ifdef __cplusplus - -class upb::EnumDefPtr { - public: - EnumDefPtr() : ptr_(nullptr) {} - explicit EnumDefPtr(const upb_enumdef* ptr) : ptr_(ptr) {} - - const upb_enumdef* ptr() const { return ptr_; } - explicit operator bool() const { return ptr_ != nullptr; } - - const char* full_name() const { return upb_enumdef_fullname(ptr_); } - const char* name() const { return upb_enumdef_name(ptr_); } - - /* 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_numvals(ptr_); } - - /* Lookups from name to integer, returning true if found. */ - bool FindValueByName(const char *name, int32_t *num) const { - return upb_enumdef_ntoiz(ptr_, name, num); - } - - /* 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. */ - const char *FindValueByNumber(int32_t num) const { - return upb_enumdef_iton(ptr_, num); - } - - /* Iteration over name/value pairs. The order is undefined. - * Adding an enum val invalidates any iterators. - * - * TODO: make compatible with range-for, with elements as pairs? */ - class Iterator { - public: - explicit Iterator(EnumDefPtr e) { upb_enum_begin(&iter_, e.ptr()); } - - int32_t number() { return upb_enum_iter_number(&iter_); } - const char *name() { return upb_enum_iter_name(&iter_); } - bool Done() { return upb_enum_done(&iter_); } - void Next() { return upb_enum_next(&iter_); } - - private: - upb_enum_iter iter_; - }; - - private: - const upb_enumdef *ptr_; -}; - -inline upb::EnumDefPtr upb::FieldDefPtr::enum_subdef() const { - return EnumDefPtr(upb_fielddef_enumsubdef(ptr_)); -} - -#endif /* __cplusplus */ - /* upb_filedef ****************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif - const char *upb_filedef_name(const upb_filedef *f); const char *upb_filedef_package(const upb_filedef *f); const char *upb_filedef_phpprefix(const upb_filedef *f); @@ -3702,57 +3381,8 @@ const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i); const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i); const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i); -#ifdef __cplusplus -} /* extern "C" */ - -/* 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 upb::FileDefPtr { - public: - explicit FileDefPtr(const upb_filedef *ptr) : ptr_(ptr) {} - - const upb_filedef* ptr() const { return ptr_; } - explicit operator bool() const { return ptr_ != nullptr; } - - /* 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_); } - - /* Sets the php class prefix which is prepended to all php generated classes - * from this .proto. Default is empty. */ - const char* phpprefix() const { return upb_filedef_phpprefix(ptr_); } - - /* Use this option to change the namespace of php generated classes. Default - * is empty. When this option is empty, the package name will be used for - * determining the namespace. */ - const char* phpnamespace() const { return upb_filedef_phpnamespace(ptr_); } - - /* Syntax for the file. Defaults to proto2. */ - upb_syntax_t syntax() const { return upb_filedef_syntax(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_depcount(ptr_); } - const FileDefPtr dependency(int index) const { - return FileDefPtr(upb_filedef_dep(ptr_, index)); - } - - private: - const upb_filedef* ptr_; -}; - -#endif /* __cplusplus */ - /* upb_symtab *****************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif - upb_symtab *upb_symtab_new(void); void upb_symtab_free(upb_symtab* s); const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym); @@ -3769,107 +3399,171 @@ const upb_filedef *upb_symtab_addfile( /* For generated code only: loads a generated descriptor. */ typedef struct upb_def_init { - struct upb_def_init **deps; + struct upb_def_init **deps; /* Dependencies of this file. */ + const upb_msglayout **layouts; /* Pre-order layouts of all messages. */ const char *filename; - upb_strview descriptor; + upb_strview descriptor; /* Serialized descriptor. */ } upb_def_init; bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init); + #ifdef __cplusplus } /* extern "C" */ +#endif /* __cplusplus */ -/* Non-const methods in upb::SymbolTable are NOT thread-safe. */ -class upb::SymbolTable { - public: - SymbolTable() : ptr_(upb_symtab_new(), upb_symtab_free) {} - explicit SymbolTable(upb_symtab* s) : ptr_(s, upb_symtab_free) {} +#endif /* UPB_DEF_H_ */ - const upb_symtab* ptr() const { return ptr_.get(); } - upb_symtab* ptr() { return ptr_.get(); } +#ifndef UPB_REFLECTION_H_ +#define UPB_REFLECTION_H_ - /* Finds an entry in the symbol table with this exact name. If not found, - * returns NULL. */ - MessageDefPtr LookupMessage(const char *sym) const { - return MessageDefPtr(upb_symtab_lookupmsg(ptr_.get(), sym)); - } - EnumDefPtr LookupEnum(const char *sym) const { - return EnumDefPtr(upb_symtab_lookupenum(ptr_.get(), sym)); - } - FileDefPtr LookupFile(const char *name) const { - return FileDefPtr(upb_symtab_lookupfile(ptr_.get(), name)); - } +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 upb_map* map_val; + const upb_msg* msg_val; + const upb_array* array_val; + upb_strview str_val; +} upb_msgval; - /* TODO: iteration? */ +typedef union { + upb_map* map; + upb_msg* msg; + upb_array* array; +} upb_mutmsgval; - /* Adds the given serialized FileDescriptorProto to the pool. */ - FileDefPtr AddFile(const google_protobuf_FileDescriptorProto *file_proto, - Status *status) { - return FileDefPtr( - upb_symtab_addfile(ptr_.get(), file_proto, status->ptr())); - } +/** upb_msg *******************************************************************/ - private: - std::unique_ptr ptr_; -}; +/* Creates a new message of the given type in the given arena. */ +upb_msg *upb_msg_new(const upb_msgdef *m, upb_arena *a); -UPB_INLINE const char* upb_safecstr(const std::string& str) { - UPB_ASSERT(str.size() == std::strlen(str.c_str())); - return str.c_str(); -} +/* Returns the value associated with this field. */ +upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f); -#endif /* __cplusplus */ +/* 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_mutmsgval upb_msg_mutable(upb_msg *msg, const upb_fielddef *f, upb_arena *a); +/* May only be called for fields where upb_fielddef_haspresence(f) == true. */ +bool upb_msg_has(const upb_msg *msg, const upb_fielddef *f); -#endif /* UPB_DEF_H_ */ +/* Returns whether any field is set in the oneof. */ +bool upb_msg_hasoneof(const upb_msg *msg, const upb_oneofdef *o); +/* Sets the given field to the given value. For a msg/array/map/string, the + * value must be in the same arena. */ +void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val, + upb_arena *a); -#ifndef UPB_MSGFACTORY_H_ -#define UPB_MSGFACTORY_H_ +/* Clears any field presence and sets the value back to its default. */ +void upb_msg_clearfield(upb_msg *msg, const upb_fielddef *f); -/** upb_msgfactory ************************************************************/ +/* Iterate over present fields. + * + * size_t iter = UPB_MSG_BEGIN; + * const upb_fielddef *f; + * upb_msgval val; + * while (upb_msg_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. + */ -struct upb_msgfactory; -typedef struct upb_msgfactory upb_msgfactory; +#define UPB_MSG_BEGIN -1 +bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, + const upb_symtab *ext_pool, const upb_fielddef **f, + upb_msgval *val, size_t *iter); -#ifdef __cplusplus -extern "C" { -#endif +/* Adds unknown data (serialized protobuf data) to the given message. The data + * is copied into the message instance. */ +void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, + upb_arena *arena); -/* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and - * upb_visitorplan objects. These are the objects necessary to represent, - * populate, and and visit upb_msg objects. - * - * These caches are all populated by upb_msgdef, and lazily created on demand. - */ +/* Returns a reference to the message's unknown data. */ +const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); -/* Creates and destroys a msgfactory, respectively. The messages for this - * msgfactory must come from |symtab| (which should outlive the msgfactory). */ -upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab); -void upb_msgfactory_free(upb_msgfactory *f); +/** upb_array *****************************************************************/ -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f); +/* Creates a new array on the given arena that holds elements of this type. */ +upb_array *upb_array_new(upb_arena *a, upb_fieldtype_t type); -/* The functions to get cached objects, lazily creating them on demand. These - * all require: - * - * - m is in upb_msgfactory_symtab(f) - * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts). +/* Returns the size of the array. */ +size_t upb_array_size(const upb_array *arr); + +/* Returns the given element, which must be within the array's current size. */ +upb_msgval upb_array_get(const upb_array *arr, size_t i); + +/* Sets the given element, which must be within the array's current size. */ +void upb_array_set(upb_array *arr, size_t i, upb_msgval val); + +/* Appends an element to the array. Returns false on allocation failure. */ +bool upb_array_append(upb_array *array, upb_msgval val, upb_arena *arena); + +/* Changes the size of a vector. New elements are initialized to empty/0. + * Returns false on allocation failure. */ +bool upb_array_resize(upb_array *array, size_t size, upb_arena *arena); + +/** upb_map *******************************************************************/ + +/* Creates a new map on the given arena with the given key/value size. */ +upb_map *upb_map_new(upb_arena *a, upb_fieldtype_t key_type, + upb_fieldtype_t value_type); + +/* Returns the number of entries in the map. */ +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. */ +bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val); + +/* Removes all entries in the map. */ +void upb_map_clear(upb_map *map); + +/* Sets the given key to the given value. Returns true if this was a new key in + * the map, or false if an existing key was replaced. */ +bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, + upb_arena *arena); + +/* Deletes this key from the table. Returns true if the key was present. */ +bool upb_map_delete(upb_map *map, upb_msgval key); + +/* Map iteration: * - * The returned objects will live for as long as the msgfactory does. + * size_t iter = UPB_MAP_BEGIN; + * while (upb_mapiter_next(map, &iter)) { + * upb_msgval key = upb_mapiter_key(map, iter); + * upb_msgval val = upb_mapiter_value(map, iter); * - * TODO(haberman): consider making this thread-safe and take a const - * upb_msgfactory. */ -const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, - const upb_msgdef *m); + * // If mutating is desired. + * upb_mapiter_setvalue(map, iter, value2); + * } + */ + +/* Advances to the next entry. Returns false if no more entries are present. */ +bool upb_mapiter_next(const upb_map *map, size_t *iter); + +/* Returns the key and value for this entry of the map. */ +upb_msgval upb_mapiter_key(const upb_map *map, size_t iter); +upb_msgval upb_mapiter_value(const upb_map *map, size_t iter); + +/* Sets the value for this entry. The iterator must not be done, and the + * iterator must not have been initialized const. */ +void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value); -#ifdef __cplusplus -} /* extern "C" */ -#endif -#endif /* UPB_MSGFACTORY_H_ */ +#endif /* UPB_REFLECTION_H_ */ /* ** upb::Handlers (upb_handlers) ** @@ -6378,7 +6072,7 @@ typedef struct { typedef struct { /* Space optimization note: we store two pointers here that the JIT * doesn't need at all; the upb_handlers* inside the sink and - * the dispatch table pointer. We can optimize so that the JIT uses + * the dispatch table pointer. We can optimze so that the JIT uses * smaller stack frames than the interpreter. The only thing we need * to guarantee is that the fallback routines can find end_ofs. */ upb_sink sink; @@ -6455,7 +6149,7 @@ struct upb_pbdecoder { char residual[UPB_DECODER_MAX_RESIDUAL_BYTES]; char *residual_end; - /* Bytes of data that should be discarded from the input before we start + /* Bytes of data that should be discarded from the input beore we start * parsing again. We set this when we internally determine that we can * safely skip the next N bytes, but this region extends past the current * user buffer. */ @@ -6577,21 +6271,22 @@ extern "C" { * descriptor type (upb_descriptortype_t). */ extern const uint8_t upb_pb_native_wire_types[]; -UPB_INLINE uint64_t byteswap64(uint64_t val) -{ - return ((((val) & 0xff00000000000000ull) >> 56) - | (((val) & 0x00ff000000000000ull) >> 40) - | (((val) & 0x0000ff0000000000ull) >> 24) - | (((val) & 0x000000ff00000000ull) >> 8) - | (((val) & 0x00000000ff000000ull) << 8) - | (((val) & 0x0000000000ff0000ull) << 24) - | (((val) & 0x000000000000ff00ull) << 40) - | (((val) & 0x00000000000000ffull) << 56)); +UPB_INLINE uint64_t byteswap64(uint64_t val) { + uint64_t byte = 0xff; + return (val & (byte << 56) >> 56) + | (val & (byte << 48) >> 40) + | (val & (byte << 40) >> 24) + | (val & (byte << 32) >> 8) + | (val & (byte << 24) << 8) + | (val & (byte << 16) << 24) + | (val & (byte << 8) << 40) + | (val & (byte << 0) << 56); } /* Zig-zag encoding/decoding **************************************************/ -UPB_INLINE int32_t upb_zzdec_32(uint32_t n) { +UPB_INLINE int32_t upb_zzdec_32(uint64_t _n) { + uint32_t n = (uint32_t)_n; return (n >> 1) ^ -(int32_t)(n & 1); } UPB_INLINE int64_t upb_zzdec_64(uint64_t n) { @@ -7074,17 +6769,23 @@ class upb::json::PrinterPtr { #endif /* UPB_JSON_TYPED_PRINTER_H_ */ /* See port_def.inc. This should #undef all macros #defined there. */ +#undef UPB_MAPTYPE_STRING #undef UPB_SIZE -#undef UPB_FIELD_AT +#undef UPB_PTR_AT #undef UPB_READ_ONEOF #undef UPB_WRITE_ONEOF #undef UPB_INLINE +#undef UPB_ALIGN_UP +#undef UPB_ALIGN_DOWN +#undef UPB_ALIGN_MALLOC +#undef UPB_ALIGN_OF #undef UPB_FORCEINLINE #undef UPB_NOINLINE #undef UPB_NORETURN #undef UPB_MAX #undef UPB_MIN #undef UPB_UNUSED +#undef UPB_ASSUME #undef UPB_ASSERT #undef UPB_ASSERT_DEBUGVAR #undef UPB_UNREACHABLE diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index e292026f37..77614bc0e9 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -773,10 +773,10 @@ class Message * @return null. * @throws \Exception Invalid data. */ - public function mergeFromJsonString($data) + public function mergeFromJsonString($data, $ignore_unknown = false) { $input = new RawInputStream($data); - $this->parseFromJsonStream($input); + $this->parseFromJsonStream($input, $ignore_unknown); } /** @@ -801,6 +801,7 @@ class Message private function convertJsonValueToProtoValue( $value, $field, + $ignore_unknown, $is_map_key = false) { switch ($field->getType()) { @@ -849,7 +850,7 @@ class Message } elseif (!is_object($value) && !is_array($value)) { throw new GPBDecodeException("Expect message."); } - $submsg->mergeFromJsonArray($value); + $submsg->mergeFromJsonArray($value, $ignore_unknown); } return $submsg; case GPBType::ENUM: @@ -862,9 +863,12 @@ class Message $enum_value = $field->getEnumType()->getValueByName($value); if (!is_null($enum_value)) { return $enum_value->getNumber(); + } else if ($ignore_unknown) { + return $this->defaultValue($field); + } else { + throw new GPBDecodeException( + "Enum field only accepts integer or enum value name"); } - throw new GPBDecodeException( - "Enum field only accepts integer or enum value name"); case GPBType::STRING: if (is_null($value)) { return $this->defaultValue($field); @@ -1125,17 +1129,17 @@ class Message } } - protected function mergeFromJsonArray($array) + protected function mergeFromJsonArray($array, $ignore_unknown) { if (is_a($this, "Google\Protobuf\Any")) { $this->clear(); $this->setTypeUrl($array["@type"]); $msg = $this->unpack(); if (GPBUtil::hasSpecialJsonMapping($msg)) { - $msg->mergeFromJsonArray($array["value"]); + $msg->mergeFromJsonArray($array["value"], $ignore_unknown); } else { unset($array["@type"]); - $msg->mergeFromJsonArray($array); + $msg->mergeFromJsonArray($array, $ignore_unknown); } $this->setValue($msg->serializeToString()); return; @@ -1171,7 +1175,7 @@ class Message $fields = $this->getFields(); foreach($array as $key => $value) { $v = new Value(); - $v->mergeFromJsonArray($value); + $v->mergeFromJsonArray($value, $ignore_unknown); $fields[$key] = $v; } } @@ -1194,7 +1198,7 @@ class Message } foreach ($array as $key => $v) { $value = new Value(); - $value->mergeFromJsonArray($v); + $value->mergeFromJsonArray($v, $ignore_unknown); $values = $struct_value->getFields(); $values[$key]= $value; } @@ -1207,7 +1211,7 @@ class Message } foreach ($array as $v) { $value = new Value(); - $value->mergeFromJsonArray($v); + $value->mergeFromJsonArray($v, $ignore_unknown); $values = $list_value->getValues(); $values[]= $value; } @@ -1217,10 +1221,10 @@ class Message } return; } - $this->mergeFromArrayJsonImpl($array); + $this->mergeFromArrayJsonImpl($array, $ignore_unknown); } - private function mergeFromArrayJsonImpl($array) + private function mergeFromArrayJsonImpl($array, $ignore_unknown) { foreach ($array as $key => $value) { $field = $this->desc->getFieldByJsonName($key); @@ -1244,10 +1248,12 @@ class Message $proto_key = $this->convertJsonValueToProtoValue( $tmp_key, $key_field, + $ignore_unknown, true); $proto_value = $this->convertJsonValueToProtoValue( $tmp_value, - $value_field); + $value_field, + $ignore_unknown); self::kvUpdateHelper($field, $proto_key, $proto_value); } } else if ($field->isRepeated()) { @@ -1261,14 +1267,16 @@ class Message } $proto_value = $this->convertJsonValueToProtoValue( $tmp, - $field); + $field, + $ignore_unknown); self::appendHelper($field, $proto_value); } } else { $setter = $field->getSetter(); $proto_value = $this->convertJsonValueToProtoValue( $value, - $field); + $field, + $ignore_unknown); if ($field->getType() === GPBType::MESSAGE) { if (is_null($proto_value)) { continue; @@ -1288,7 +1296,7 @@ class Message /** * @ignore */ - public function parseFromJsonStream($input) + public function parseFromJsonStream($input, $ignore_unknown) { $array = json_decode($input->getData(), true, 512, JSON_BIGINT_AS_STRING); if ($this instanceof \Google\Protobuf\ListValue) { @@ -1304,7 +1312,7 @@ class Message } } try { - $this->mergeFromJsonArray($array); + $this->mergeFromJsonArray($array, $ignore_unknown); } catch (\Exception $e) { throw new GPBDecodeException($e->getMessage()); } diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 319e3321d2..5442f504d5 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -884,6 +884,11 @@ class EncodeDecodeTest extends TestBase $m->mergeFromJsonString("{\"unknown\":{\"a\":1, \"b\":1}, \"optionalInt32\":1}", true); $this->assertSame(1, $m->getOptionalInt32()); + + // Test unknown enum value + $m = new TestMessage(); + $m->mergeFromJsonString("{\"optionalEnum\":\"UNKNOWN\"}", true); + $this->assertSame(0, $m->getOptionalEnum()); } public function testJsonEncode() From 6a84e31818fa1e06a83a3572b4a214023cd3bcc2 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 27 Apr 2020 07:18:23 +0100 Subject: [PATCH 06/26] Don't generate Has/Clear members for proto2 message fields. This is a breaking change in terms of proto2 code generation: users who were previously using these members will have to change to null checks for message fields. After toying with removing Has/Clear for proto2 oneof fields, I've left them alone in this commit, for consistency with other languages. The inconsistency between proto2 and proto3 won't come up here, because proto3 oneof fields can never be explicitly optional. Fixes #7395. --- .../protobuf/compiler/csharp/csharp_helpers.h | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index d295bbe803..90ead89c11 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -159,24 +159,23 @@ inline bool IsProto2(const FileDescriptor* descriptor) { } inline bool SupportsPresenceApi(const FieldDescriptor* descriptor) { - // We don't use descriptor->is_singular_with_presence() as C# has slightly - // different behavior to other languages. - - if (IsProto2(descriptor->file())) { - // We generate Has/Clear for oneof fields in C#, as well as for messages. - // It's possible that we shouldn't, but stopping doing so would be a - // breaking change for proto2. Fortunately the decision is moot for - // onoeof in proto3: you can't use "optional" inside a oneof. - // Proto2: every singular field has presence. (Even fields in oneofs.) - return !descriptor->is_repeated(); - } else { - // Proto3: only for explictly-optional fields that aren't messages. - // (Repeated fields can never be explicitly optional, so we don't need - // to check for that.) Currently we can't get at proto3_optional directly, - // but we can use has_optional_keyword() as a surrogate check. - return descriptor->has_optional_keyword() && - descriptor->type() != FieldDescriptor::TYPE_MESSAGE; + // Unlike most languages, we don't generate Has/Clear members for message + // types, because they can always be set to null in C#. They're not really + // needed for oneof fields in proto2 either, as everything can be done via + // oneof case, but we follow the convention from other languages. Proto3 + // oneof fields never have Has/Clear members - but will also never have + // the explicit optional keyword either. + // + // None of the built-in helpers (descriptor->has_presence() etc) describe + // quite the behavior we want, so the rules are explicit below. + + if (descriptor->is_repeated() || + descriptor->type() == FieldDescriptor::TYPE_MESSAGE) { + return false; } + // has_optional_keyword() has more complex rules for proto2, but that + // doesn't matter given the first part of this condition. + return IsProto2(descriptor->file()) || descriptor->has_optional_keyword(); } inline bool RequiresPresenceBit(const FieldDescriptor* descriptor) { From 13df985bff8bdab86775d9cd24bcbe1241b91a87 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 27 Apr 2020 07:18:45 +0100 Subject: [PATCH 07/26] Regenerate C# code based on the previous commit (This removes the Has/Clear members for message types in proto2.) --- .../TestMessagesProto2.cs | 142 +-- .../Unittest.cs | 924 +++++------------- .../Google.Protobuf/Reflection/Descriptor.cs | 240 ++--- 3 files changed, 371 insertions(+), 935 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs index 1ba1275fb6..ca2888473b 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs @@ -290,13 +290,13 @@ namespace ProtobufTestMessages.Proto2 { optionalBool_ = other.optionalBool_; optionalString_ = other.optionalString_; optionalBytes_ = other.optionalBytes_; - optionalNestedMessage_ = other.HasOptionalNestedMessage ? other.optionalNestedMessage_.Clone() : null; - optionalForeignMessage_ = other.HasOptionalForeignMessage ? other.optionalForeignMessage_.Clone() : null; + optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null; + optionalForeignMessage_ = other.optionalForeignMessage_ != null ? other.optionalForeignMessage_.Clone() : null; optionalNestedEnum_ = other.optionalNestedEnum_; optionalForeignEnum_ = other.optionalForeignEnum_; optionalStringPiece_ = other.optionalStringPiece_; optionalCord_ = other.optionalCord_; - recursiveMessage_ = other.HasRecursiveMessage ? other.recursiveMessage_.Clone() : null; + recursiveMessage_ = other.recursiveMessage_ != null ? other.recursiveMessage_.Clone() : null; repeatedInt32_ = other.repeatedInt32_.Clone(); repeatedInt64_ = other.repeatedInt64_.Clone(); repeatedUint32_ = other.repeatedUint32_.Clone(); @@ -794,16 +794,6 @@ namespace ProtobufTestMessages.Proto2 { optionalNestedMessage_ = value; } } - /// Gets whether the optional_nested_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalNestedMessage { - get { return optionalNestedMessage_ != null; } - } - /// Clears the value of the optional_nested_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalNestedMessage() { - optionalNestedMessage_ = null; - } /// Field number for the "optional_foreign_message" field. public const int OptionalForeignMessageFieldNumber = 19; @@ -815,16 +805,6 @@ namespace ProtobufTestMessages.Proto2 { optionalForeignMessage_ = value; } } - /// Gets whether the optional_foreign_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalForeignMessage { - get { return optionalForeignMessage_ != null; } - } - /// Clears the value of the optional_foreign_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalForeignMessage() { - optionalForeignMessage_ = null; - } /// Field number for the "optional_nested_enum" field. public const int OptionalNestedEnumFieldNumber = 21; @@ -930,16 +910,6 @@ namespace ProtobufTestMessages.Proto2 { recursiveMessage_ = value; } } - /// Gets whether the recursive_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasRecursiveMessage { - get { return recursiveMessage_ != null; } - } - /// Clears the value of the recursive_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearRecursiveMessage() { - recursiveMessage_ = null; - } /// Field number for the "repeated_int32" field. public const int RepeatedInt32FieldNumber = 31; @@ -1660,24 +1630,12 @@ namespace ProtobufTestMessages.Proto2 { public const int OneofNestedMessageFieldNumber = 112; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage OneofNestedMessage { - get { return HasOneofNestedMessage ? (global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage) oneofField_ : null; } + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage ? (global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage) oneofField_ : null; } set { oneofField_ = value; oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofNestedMessage; } } - /// Gets whether the "oneof_nested_message" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOneofNestedMessage { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage; } - } - /// Clears the value of the oneof if it's currently set to "oneof_nested_message" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOneofNestedMessage() { - if (HasOneofNestedMessage) { - ClearOneofField(); - } - } /// Field number for the "oneof_string" field. public const int OneofStringFieldNumber = 113; @@ -2479,13 +2437,13 @@ namespace ProtobufTestMessages.Proto2 { if (HasOptionalBool) hash ^= OptionalBool.GetHashCode(); if (HasOptionalString) hash ^= OptionalString.GetHashCode(); if (HasOptionalBytes) hash ^= OptionalBytes.GetHashCode(); - if (HasOptionalNestedMessage) hash ^= OptionalNestedMessage.GetHashCode(); - if (HasOptionalForeignMessage) hash ^= OptionalForeignMessage.GetHashCode(); + if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode(); + if (optionalForeignMessage_ != null) hash ^= OptionalForeignMessage.GetHashCode(); if (HasOptionalNestedEnum) hash ^= OptionalNestedEnum.GetHashCode(); if (HasOptionalForeignEnum) hash ^= OptionalForeignEnum.GetHashCode(); if (HasOptionalStringPiece) hash ^= OptionalStringPiece.GetHashCode(); if (HasOptionalCord) hash ^= OptionalCord.GetHashCode(); - if (HasRecursiveMessage) hash ^= RecursiveMessage.GetHashCode(); + if (recursiveMessage_ != null) hash ^= RecursiveMessage.GetHashCode(); hash ^= repeatedInt32_.GetHashCode(); hash ^= repeatedInt64_.GetHashCode(); hash ^= repeatedUint32_.GetHashCode(); @@ -2555,7 +2513,7 @@ namespace ProtobufTestMessages.Proto2 { hash ^= MapStringNestedEnum.GetHashCode(); hash ^= MapStringForeignEnum.GetHashCode(); if (HasOneofUint32) hash ^= OneofUint32.GetHashCode(); - if (HasOneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode(); if (HasOneofString) hash ^= OneofString.GetHashCode(); if (HasOneofBytes) hash ^= OneofBytes.GetHashCode(); if (HasOneofBool) hash ^= OneofBool.GetHashCode(); @@ -2659,11 +2617,11 @@ namespace ProtobufTestMessages.Proto2 { output.WriteRawTag(122); output.WriteBytes(OptionalBytes); } - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { output.WriteRawTag(146, 1); output.WriteMessage(OptionalNestedMessage); } - if (HasOptionalForeignMessage) { + if (optionalForeignMessage_ != null) { output.WriteRawTag(154, 1); output.WriteMessage(OptionalForeignMessage); } @@ -2683,7 +2641,7 @@ namespace ProtobufTestMessages.Proto2 { output.WriteRawTag(202, 1); output.WriteString(OptionalCord); } - if (HasRecursiveMessage) { + if (recursiveMessage_ != null) { output.WriteRawTag(218, 1); output.WriteMessage(RecursiveMessage); } @@ -2759,7 +2717,7 @@ namespace ProtobufTestMessages.Proto2 { output.WriteRawTag(248, 6); output.WriteUInt32(OneofUint32); } - if (HasOneofNestedMessage) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { output.WriteRawTag(130, 7); output.WriteMessage(OneofNestedMessage); } @@ -2924,10 +2882,10 @@ namespace ProtobufTestMessages.Proto2 { if (HasOptionalBytes) { size += 1 + pb::CodedOutputStream.ComputeBytesSize(OptionalBytes); } - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage); } - if (HasOptionalForeignMessage) { + if (optionalForeignMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalForeignMessage); } if (HasOptionalNestedEnum) { @@ -2942,7 +2900,7 @@ namespace ProtobufTestMessages.Proto2 { if (HasOptionalCord) { size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalCord); } - if (HasRecursiveMessage) { + if (recursiveMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(RecursiveMessage); } size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec); @@ -3016,7 +2974,7 @@ namespace ProtobufTestMessages.Proto2 { if (HasOneofUint32) { size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32); } - if (HasOneofNestedMessage) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage); } if (HasOneofString) { @@ -3156,14 +3114,14 @@ namespace ProtobufTestMessages.Proto2 { if (other.HasOptionalBytes) { OptionalBytes = other.OptionalBytes; } - if (other.HasOptionalNestedMessage) { - if (!HasOptionalNestedMessage) { + if (other.optionalNestedMessage_ != null) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage(); } OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage); } - if (other.HasOptionalForeignMessage) { - if (!HasOptionalForeignMessage) { + if (other.optionalForeignMessage_ != null) { + if (optionalForeignMessage_ == null) { OptionalForeignMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2(); } OptionalForeignMessage.MergeFrom(other.OptionalForeignMessage); @@ -3180,8 +3138,8 @@ namespace ProtobufTestMessages.Proto2 { if (other.HasOptionalCord) { OptionalCord = other.OptionalCord; } - if (other.HasRecursiveMessage) { - if (!HasRecursiveMessage) { + if (other.recursiveMessage_ != null) { + if (recursiveMessage_ == null) { RecursiveMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2(); } RecursiveMessage.MergeFrom(other.RecursiveMessage); @@ -3422,14 +3380,14 @@ namespace ProtobufTestMessages.Proto2 { break; } case 146: { - if (!HasOptionalNestedMessage) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage(); } input.ReadMessage(OptionalNestedMessage); break; } case 154: { - if (!HasOptionalForeignMessage) { + if (optionalForeignMessage_ == null) { OptionalForeignMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2(); } input.ReadMessage(OptionalForeignMessage); @@ -3452,7 +3410,7 @@ namespace ProtobufTestMessages.Proto2 { break; } case 218: { - if (!HasRecursiveMessage) { + if (recursiveMessage_ == null) { RecursiveMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2(); } input.ReadMessage(RecursiveMessage); @@ -3779,7 +3737,7 @@ namespace ProtobufTestMessages.Proto2 { } case 898: { global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage subBuilder = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage(); - if (HasOneofNestedMessage) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { subBuilder.MergeFrom(OneofNestedMessage); } input.ReadMessage(subBuilder); @@ -3962,7 +3920,7 @@ namespace ProtobufTestMessages.Proto2 { public NestedMessage(NestedMessage other) : this() { _hasBits0 = other._hasBits0; a_ = other.a_; - corecursive_ = other.HasCorecursive ? other.corecursive_.Clone() : null; + corecursive_ = other.corecursive_ != null ? other.corecursive_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -4005,16 +3963,6 @@ namespace ProtobufTestMessages.Proto2 { corecursive_ = value; } } - /// Gets whether the corecursive field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasCorecursive { - get { return corecursive_ != null; } - } - /// Clears the value of the corecursive field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearCorecursive() { - corecursive_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -4038,7 +3986,7 @@ namespace ProtobufTestMessages.Proto2 { public override int GetHashCode() { int hash = 1; if (HasA) hash ^= A.GetHashCode(); - if (HasCorecursive) hash ^= Corecursive.GetHashCode(); + if (corecursive_ != null) hash ^= Corecursive.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -4056,7 +4004,7 @@ namespace ProtobufTestMessages.Proto2 { output.WriteRawTag(8); output.WriteInt32(A); } - if (HasCorecursive) { + if (corecursive_ != null) { output.WriteRawTag(18); output.WriteMessage(Corecursive); } @@ -4071,7 +4019,7 @@ namespace ProtobufTestMessages.Proto2 { if (HasA) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(A); } - if (HasCorecursive) { + if (corecursive_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Corecursive); } if (_unknownFields != null) { @@ -4088,8 +4036,8 @@ namespace ProtobufTestMessages.Proto2 { if (other.HasA) { A = other.A; } - if (other.HasCorecursive) { - if (!HasCorecursive) { + if (other.corecursive_ != null) { + if (corecursive_ == null) { Corecursive = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2(); } Corecursive.MergeFrom(other.Corecursive); @@ -4110,7 +4058,7 @@ namespace ProtobufTestMessages.Proto2 { break; } case 18: { - if (!HasCorecursive) { + if (corecursive_ == null) { Corecursive = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2(); } input.ReadMessage(Corecursive); @@ -4937,7 +4885,7 @@ namespace ProtobufTestMessages.Proto2 { _hasBits0 = other._hasBits0; optionalInt32_ = other.optionalInt32_; optionalString_ = other.optionalString_; - nestedMessage_ = other.HasNestedMessage ? other.nestedMessage_.Clone() : null; + nestedMessage_ = other.nestedMessage_ != null ? other.nestedMessage_.Clone() : null; optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null; optionalBool_ = other.optionalBool_; repeatedInt32_ = other.repeatedInt32_.Clone(); @@ -5006,16 +4954,6 @@ namespace ProtobufTestMessages.Proto2 { nestedMessage_ = value; } } - /// Gets whether the nested_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasNestedMessage { - get { return nestedMessage_ != null; } - } - /// Clears the value of the nested_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearNestedMessage() { - nestedMessage_ = null; - } /// Field number for the "optionalgroup" field. public const int OptionalGroupFieldNumber = 1004; @@ -5099,7 +5037,7 @@ namespace ProtobufTestMessages.Proto2 { int hash = 1; if (HasOptionalInt32) hash ^= OptionalInt32.GetHashCode(); if (HasOptionalString) hash ^= OptionalString.GetHashCode(); - if (HasNestedMessage) hash ^= NestedMessage.GetHashCode(); + if (nestedMessage_ != null) hash ^= NestedMessage.GetHashCode(); if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode(); if (HasOptionalBool) hash ^= OptionalBool.GetHashCode(); hash ^= repeatedInt32_.GetHashCode(); @@ -5124,7 +5062,7 @@ namespace ProtobufTestMessages.Proto2 { output.WriteRawTag(210, 62); output.WriteString(OptionalString); } - if (HasNestedMessage) { + if (nestedMessage_ != null) { output.WriteRawTag(218, 62); output.WriteMessage(NestedMessage); } @@ -5152,7 +5090,7 @@ namespace ProtobufTestMessages.Proto2 { if (HasOptionalString) { size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalString); } - if (HasNestedMessage) { + if (nestedMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(NestedMessage); } if (HasOptionalGroup) { @@ -5179,8 +5117,8 @@ namespace ProtobufTestMessages.Proto2 { if (other.HasOptionalString) { OptionalString = other.OptionalString; } - if (other.HasNestedMessage) { - if (!HasNestedMessage) { + if (other.nestedMessage_ != null) { + if (nestedMessage_ == null) { NestedMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2(); } NestedMessage.MergeFrom(other.NestedMessage); @@ -5215,7 +5153,7 @@ namespace ProtobufTestMessages.Proto2 { break; } case 8026: { - if (!HasNestedMessage) { + if (nestedMessage_ == null) { NestedMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2(); } input.ReadMessage(NestedMessage); diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs index 25fecb9b29..fc69603a52 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs @@ -1165,16 +1165,16 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalString_ = other.optionalString_; optionalBytes_ = other.optionalBytes_; optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null; - optionalNestedMessage_ = other.HasOptionalNestedMessage ? other.optionalNestedMessage_.Clone() : null; - optionalForeignMessage_ = other.HasOptionalForeignMessage ? other.optionalForeignMessage_.Clone() : null; - optionalImportMessage_ = other.HasOptionalImportMessage ? other.optionalImportMessage_.Clone() : null; + optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null; + optionalForeignMessage_ = other.optionalForeignMessage_ != null ? other.optionalForeignMessage_.Clone() : null; + optionalImportMessage_ = other.optionalImportMessage_ != null ? other.optionalImportMessage_.Clone() : null; optionalNestedEnum_ = other.optionalNestedEnum_; optionalForeignEnum_ = other.optionalForeignEnum_; optionalImportEnum_ = other.optionalImportEnum_; optionalStringPiece_ = other.optionalStringPiece_; optionalCord_ = other.optionalCord_; - optionalPublicImportMessage_ = other.HasOptionalPublicImportMessage ? other.optionalPublicImportMessage_.Clone() : null; - optionalLazyMessage_ = other.HasOptionalLazyMessage ? other.optionalLazyMessage_.Clone() : null; + optionalPublicImportMessage_ = other.optionalPublicImportMessage_ != null ? other.optionalPublicImportMessage_.Clone() : null; + optionalLazyMessage_ = other.optionalLazyMessage_ != null ? other.optionalLazyMessage_.Clone() : null; repeatedInt32_ = other.repeatedInt32_.Clone(); repeatedInt64_ = other.repeatedInt64_.Clone(); repeatedUint32_ = other.repeatedUint32_.Clone(); @@ -1635,16 +1635,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalNestedMessage_ = value; } } - /// Gets whether the optional_nested_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalNestedMessage { - get { return optionalNestedMessage_ != null; } - } - /// Clears the value of the optional_nested_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalNestedMessage() { - optionalNestedMessage_ = null; - } /// Field number for the "optional_foreign_message" field. public const int OptionalForeignMessageFieldNumber = 19; @@ -1656,16 +1646,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalForeignMessage_ = value; } } - /// Gets whether the optional_foreign_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalForeignMessage { - get { return optionalForeignMessage_ != null; } - } - /// Clears the value of the optional_foreign_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalForeignMessage() { - optionalForeignMessage_ = null; - } /// Field number for the "optional_import_message" field. public const int OptionalImportMessageFieldNumber = 20; @@ -1677,16 +1657,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalImportMessage_ = value; } } - /// Gets whether the optional_import_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalImportMessage { - get { return optionalImportMessage_ != null; } - } - /// Clears the value of the optional_import_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalImportMessage() { - optionalImportMessage_ = null; - } /// Field number for the "optional_nested_enum" field. public const int OptionalNestedEnumFieldNumber = 21; @@ -1819,16 +1789,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalPublicImportMessage_ = value; } } - /// Gets whether the optional_public_import_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalPublicImportMessage { - get { return optionalPublicImportMessage_ != null; } - } - /// Clears the value of the optional_public_import_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalPublicImportMessage() { - optionalPublicImportMessage_ = null; - } /// Field number for the "optional_lazy_message" field. public const int OptionalLazyMessageFieldNumber = 27; @@ -1840,16 +1800,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalLazyMessage_ = value; } } - /// Gets whether the optional_lazy_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalLazyMessage { - get { return optionalLazyMessage_ != null; } - } - /// Clears the value of the optional_lazy_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalLazyMessage() { - optionalLazyMessage_ = null; - } /// Field number for the "repeated_int32" field. public const int RepeatedInt32FieldNumber = 31; @@ -2610,24 +2560,12 @@ namespace Google.Protobuf.TestProtos.Proto2 { public const int OneofNestedMessageFieldNumber = 112; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage OneofNestedMessage { - get { return HasOneofNestedMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage) oneofField_ : null; } + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage) oneofField_ : null; } set { oneofField_ = value; oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofNestedMessage; } } - /// Gets whether the "oneof_nested_message" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOneofNestedMessage { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage; } - } - /// Clears the value of the oneof if it's currently set to "oneof_nested_message" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOneofNestedMessage() { - if (HasOneofNestedMessage) { - ClearOneofField(); - } - } /// Field number for the "oneof_string" field. public const int OneofStringFieldNumber = 113; @@ -2807,16 +2745,16 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasOptionalString) hash ^= OptionalString.GetHashCode(); if (HasOptionalBytes) hash ^= OptionalBytes.GetHashCode(); if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode(); - if (HasOptionalNestedMessage) hash ^= OptionalNestedMessage.GetHashCode(); - if (HasOptionalForeignMessage) hash ^= OptionalForeignMessage.GetHashCode(); - if (HasOptionalImportMessage) hash ^= OptionalImportMessage.GetHashCode(); + if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode(); + if (optionalForeignMessage_ != null) hash ^= OptionalForeignMessage.GetHashCode(); + if (optionalImportMessage_ != null) hash ^= OptionalImportMessage.GetHashCode(); if (HasOptionalNestedEnum) hash ^= OptionalNestedEnum.GetHashCode(); if (HasOptionalForeignEnum) hash ^= OptionalForeignEnum.GetHashCode(); if (HasOptionalImportEnum) hash ^= OptionalImportEnum.GetHashCode(); if (HasOptionalStringPiece) hash ^= OptionalStringPiece.GetHashCode(); if (HasOptionalCord) hash ^= OptionalCord.GetHashCode(); - if (HasOptionalPublicImportMessage) hash ^= OptionalPublicImportMessage.GetHashCode(); - if (HasOptionalLazyMessage) hash ^= OptionalLazyMessage.GetHashCode(); + if (optionalPublicImportMessage_ != null) hash ^= OptionalPublicImportMessage.GetHashCode(); + if (optionalLazyMessage_ != null) hash ^= OptionalLazyMessage.GetHashCode(); hash ^= repeatedInt32_.GetHashCode(); hash ^= repeatedInt64_.GetHashCode(); hash ^= repeatedUint32_.GetHashCode(); @@ -2863,7 +2801,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasDefaultStringPiece) hash ^= DefaultStringPiece.GetHashCode(); if (HasDefaultCord) hash ^= DefaultCord.GetHashCode(); if (HasOneofUint32) hash ^= OneofUint32.GetHashCode(); - if (HasOneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode(); if (HasOneofString) hash ^= OneofString.GetHashCode(); if (HasOneofBytes) hash ^= OneofBytes.GetHashCode(); hash ^= (int) oneofFieldCase_; @@ -2945,15 +2883,15 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteGroup(OptionalGroup); output.WriteRawTag(132, 1); } - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { output.WriteRawTag(146, 1); output.WriteMessage(OptionalNestedMessage); } - if (HasOptionalForeignMessage) { + if (optionalForeignMessage_ != null) { output.WriteRawTag(154, 1); output.WriteMessage(OptionalForeignMessage); } - if (HasOptionalImportMessage) { + if (optionalImportMessage_ != null) { output.WriteRawTag(162, 1); output.WriteMessage(OptionalImportMessage); } @@ -2977,11 +2915,11 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(202, 1); output.WriteString(OptionalCord); } - if (HasOptionalPublicImportMessage) { + if (optionalPublicImportMessage_ != null) { output.WriteRawTag(210, 1); output.WriteMessage(OptionalPublicImportMessage); } - if (HasOptionalLazyMessage) { + if (optionalLazyMessage_ != null) { output.WriteRawTag(218, 1); output.WriteMessage(OptionalLazyMessage); } @@ -3094,7 +3032,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(248, 6); output.WriteUInt32(OneofUint32); } - if (HasOneofNestedMessage) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { output.WriteRawTag(130, 7); output.WriteMessage(OneofNestedMessage); } @@ -3162,13 +3100,13 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasOptionalGroup) { size += 4 + pb::CodedOutputStream.ComputeGroupSize(OptionalGroup); } - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage); } - if (HasOptionalForeignMessage) { + if (optionalForeignMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalForeignMessage); } - if (HasOptionalImportMessage) { + if (optionalImportMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalImportMessage); } if (HasOptionalNestedEnum) { @@ -3186,10 +3124,10 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasOptionalCord) { size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalCord); } - if (HasOptionalPublicImportMessage) { + if (optionalPublicImportMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalPublicImportMessage); } - if (HasOptionalLazyMessage) { + if (optionalLazyMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalLazyMessage); } size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec); @@ -3280,7 +3218,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasOneofUint32) { size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32); } - if (HasOneofNestedMessage) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage); } if (HasOneofString) { @@ -3351,20 +3289,20 @@ namespace Google.Protobuf.TestProtos.Proto2 { } OptionalGroup.MergeFrom(other.OptionalGroup); } - if (other.HasOptionalNestedMessage) { - if (!HasOptionalNestedMessage) { + if (other.optionalNestedMessage_ != null) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); } OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage); } - if (other.HasOptionalForeignMessage) { - if (!HasOptionalForeignMessage) { + if (other.optionalForeignMessage_ != null) { + if (optionalForeignMessage_ == null) { OptionalForeignMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } OptionalForeignMessage.MergeFrom(other.OptionalForeignMessage); } - if (other.HasOptionalImportMessage) { - if (!HasOptionalImportMessage) { + if (other.optionalImportMessage_ != null) { + if (optionalImportMessage_ == null) { OptionalImportMessage = new global::Google.Protobuf.TestProtos.Proto2.ImportMessage(); } OptionalImportMessage.MergeFrom(other.OptionalImportMessage); @@ -3384,14 +3322,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other.HasOptionalCord) { OptionalCord = other.OptionalCord; } - if (other.HasOptionalPublicImportMessage) { - if (!HasOptionalPublicImportMessage) { + if (other.optionalPublicImportMessage_ != null) { + if (optionalPublicImportMessage_ == null) { OptionalPublicImportMessage = new global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage(); } OptionalPublicImportMessage.MergeFrom(other.OptionalPublicImportMessage); } - if (other.HasOptionalLazyMessage) { - if (!HasOptionalLazyMessage) { + if (other.optionalLazyMessage_ != null) { + if (optionalLazyMessage_ == null) { OptionalLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); } OptionalLazyMessage.MergeFrom(other.OptionalLazyMessage); @@ -3578,21 +3516,21 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 146: { - if (!HasOptionalNestedMessage) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); } input.ReadMessage(OptionalNestedMessage); break; } case 154: { - if (!HasOptionalForeignMessage) { + if (optionalForeignMessage_ == null) { OptionalForeignMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } input.ReadMessage(OptionalForeignMessage); break; } case 162: { - if (!HasOptionalImportMessage) { + if (optionalImportMessage_ == null) { OptionalImportMessage = new global::Google.Protobuf.TestProtos.Proto2.ImportMessage(); } input.ReadMessage(OptionalImportMessage); @@ -3619,14 +3557,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 210: { - if (!HasOptionalPublicImportMessage) { + if (optionalPublicImportMessage_ == null) { OptionalPublicImportMessage = new global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage(); } input.ReadMessage(OptionalPublicImportMessage); break; } case 218: { - if (!HasOptionalLazyMessage) { + if (optionalLazyMessage_ == null) { OptionalLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); } input.ReadMessage(OptionalLazyMessage); @@ -3834,7 +3772,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } case 898: { global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); - if (HasOneofNestedMessage) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { subBuilder.MergeFrom(OneofNestedMessage); } input.ReadMessage(subBuilder); @@ -4341,8 +4279,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public NestedTestAllTypes(NestedTestAllTypes other) : this() { - child_ = other.HasChild ? other.child_.Clone() : null; - payload_ = other.HasPayload ? other.payload_.Clone() : null; + child_ = other.child_ != null ? other.child_.Clone() : null; + payload_ = other.payload_ != null ? other.payload_.Clone() : null; repeatedChild_ = other.repeatedChild_.Clone(); _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -4362,16 +4300,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { child_ = value; } } - /// Gets whether the child field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasChild { - get { return child_ != null; } - } - /// Clears the value of the child field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearChild() { - child_ = null; - } /// Field number for the "payload" field. public const int PayloadFieldNumber = 2; @@ -4383,16 +4311,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { payload_ = value; } } - /// Gets whether the payload field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasPayload { - get { return payload_ != null; } - } - /// Clears the value of the payload field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearPayload() { - payload_ = null; - } /// Field number for the "repeated_child" field. public const int RepeatedChildFieldNumber = 3; @@ -4426,8 +4344,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasChild) hash ^= Child.GetHashCode(); - if (HasPayload) hash ^= Payload.GetHashCode(); + if (child_ != null) hash ^= Child.GetHashCode(); + if (payload_ != null) hash ^= Payload.GetHashCode(); hash ^= repeatedChild_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -4442,11 +4360,11 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasChild) { + if (child_ != null) { output.WriteRawTag(10); output.WriteMessage(Child); } - if (HasPayload) { + if (payload_ != null) { output.WriteRawTag(18); output.WriteMessage(Payload); } @@ -4459,10 +4377,10 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasChild) { + if (child_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Child); } - if (HasPayload) { + if (payload_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Payload); } size += repeatedChild_.CalculateSize(_repeated_repeatedChild_codec); @@ -4477,14 +4395,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasChild) { - if (!HasChild) { + if (other.child_ != null) { + if (child_ == null) { Child = new global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes(); } Child.MergeFrom(other.Child); } - if (other.HasPayload) { - if (!HasPayload) { + if (other.payload_ != null) { + if (payload_ == null) { Payload = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } Payload.MergeFrom(other.Payload); @@ -4502,14 +4420,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasChild) { + if (child_ == null) { Child = new global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes(); } input.ReadMessage(Child); break; } case 18: { - if (!HasPayload) { + if (payload_ == null) { Payload = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(Payload); @@ -7835,7 +7753,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestRequiredForeign(TestRequiredForeign other) : this() { _hasBits0 = other._hasBits0; - optionalMessage_ = other.HasOptionalMessage ? other.optionalMessage_.Clone() : null; + optionalMessage_ = other.optionalMessage_ != null ? other.optionalMessage_.Clone() : null; repeatedMessage_ = other.repeatedMessage_.Clone(); dummy_ = other.dummy_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -7856,16 +7774,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalMessage_ = value; } } - /// Gets whether the optional_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalMessage { - get { return optionalMessage_ != null; } - } - /// Clears the value of the optional_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalMessage() { - optionalMessage_ = null; - } /// Field number for the "repeated_message" field. public const int RepeatedMessageFieldNumber = 2; @@ -7923,7 +7831,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasOptionalMessage) hash ^= OptionalMessage.GetHashCode(); + if (optionalMessage_ != null) hash ^= OptionalMessage.GetHashCode(); hash ^= repeatedMessage_.GetHashCode(); if (HasDummy) hash ^= Dummy.GetHashCode(); if (_unknownFields != null) { @@ -7939,7 +7847,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasOptionalMessage) { + if (optionalMessage_ != null) { output.WriteRawTag(10); output.WriteMessage(OptionalMessage); } @@ -7956,7 +7864,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasOptionalMessage) { + if (optionalMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalMessage); } size += repeatedMessage_.CalculateSize(_repeated_repeatedMessage_codec); @@ -7974,8 +7882,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasOptionalMessage) { - if (!HasOptionalMessage) { + if (other.optionalMessage_ != null) { + if (optionalMessage_ == null) { OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); } OptionalMessage.MergeFrom(other.OptionalMessage); @@ -7996,7 +7904,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasOptionalMessage) { + if (optionalMessage_ == null) { OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); } input.ReadMessage(OptionalMessage); @@ -8041,9 +7949,9 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestRequiredMessage(TestRequiredMessage other) : this() { - optionalMessage_ = other.HasOptionalMessage ? other.optionalMessage_.Clone() : null; + optionalMessage_ = other.optionalMessage_ != null ? other.optionalMessage_.Clone() : null; repeatedMessage_ = other.repeatedMessage_.Clone(); - requiredMessage_ = other.HasRequiredMessage ? other.requiredMessage_.Clone() : null; + requiredMessage_ = other.requiredMessage_ != null ? other.requiredMessage_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -8062,16 +7970,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalMessage_ = value; } } - /// Gets whether the optional_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalMessage { - get { return optionalMessage_ != null; } - } - /// Clears the value of the optional_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalMessage() { - optionalMessage_ = null; - } /// Field number for the "repeated_message" field. public const int RepeatedMessageFieldNumber = 2; @@ -8093,16 +7991,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { requiredMessage_ = value; } } - /// Gets whether the required_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasRequiredMessage { - get { return requiredMessage_ != null; } - } - /// Clears the value of the required_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearRequiredMessage() { - requiredMessage_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -8126,9 +8014,9 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasOptionalMessage) hash ^= OptionalMessage.GetHashCode(); + if (optionalMessage_ != null) hash ^= OptionalMessage.GetHashCode(); hash ^= repeatedMessage_.GetHashCode(); - if (HasRequiredMessage) hash ^= RequiredMessage.GetHashCode(); + if (requiredMessage_ != null) hash ^= RequiredMessage.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -8142,12 +8030,12 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasOptionalMessage) { + if (optionalMessage_ != null) { output.WriteRawTag(10); output.WriteMessage(OptionalMessage); } repeatedMessage_.WriteTo(output, _repeated_repeatedMessage_codec); - if (HasRequiredMessage) { + if (requiredMessage_ != null) { output.WriteRawTag(26); output.WriteMessage(RequiredMessage); } @@ -8159,11 +8047,11 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasOptionalMessage) { + if (optionalMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalMessage); } size += repeatedMessage_.CalculateSize(_repeated_repeatedMessage_codec); - if (HasRequiredMessage) { + if (requiredMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(RequiredMessage); } if (_unknownFields != null) { @@ -8177,15 +8065,15 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasOptionalMessage) { - if (!HasOptionalMessage) { + if (other.optionalMessage_ != null) { + if (optionalMessage_ == null) { OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); } OptionalMessage.MergeFrom(other.OptionalMessage); } repeatedMessage_.Add(other.repeatedMessage_); - if (other.HasRequiredMessage) { - if (!HasRequiredMessage) { + if (other.requiredMessage_ != null) { + if (requiredMessage_ == null) { RequiredMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); } RequiredMessage.MergeFrom(other.RequiredMessage); @@ -8202,7 +8090,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasOptionalMessage) { + if (optionalMessage_ == null) { OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); } input.ReadMessage(OptionalMessage); @@ -8213,7 +8101,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 26: { - if (!HasRequiredMessage) { + if (requiredMessage_ == null) { RequiredMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); } input.ReadMessage(RequiredMessage); @@ -8253,7 +8141,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestForeignNested(TestForeignNested other) : this() { - foreignNested_ = other.HasForeignNested ? other.foreignNested_.Clone() : null; + foreignNested_ = other.foreignNested_ != null ? other.foreignNested_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -8272,16 +8160,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { foreignNested_ = value; } } - /// Gets whether the foreign_nested field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasForeignNested { - get { return foreignNested_ != null; } - } - /// Clears the value of the foreign_nested field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearForeignNested() { - foreignNested_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -8303,7 +8181,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasForeignNested) hash ^= ForeignNested.GetHashCode(); + if (foreignNested_ != null) hash ^= ForeignNested.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -8317,7 +8195,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasForeignNested) { + if (foreignNested_ != null) { output.WriteRawTag(10); output.WriteMessage(ForeignNested); } @@ -8329,7 +8207,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasForeignNested) { + if (foreignNested_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(ForeignNested); } if (_unknownFields != null) { @@ -8343,8 +8221,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasForeignNested) { - if (!HasForeignNested) { + if (other.foreignNested_ != null) { + if (foreignNested_ == null) { ForeignNested = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); } ForeignNested.MergeFrom(other.ForeignNested); @@ -8361,7 +8239,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasForeignNested) { + if (foreignNested_ == null) { ForeignNested = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); } input.ReadMessage(ForeignNested); @@ -8982,7 +8860,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestRecursiveMessage(TestRecursiveMessage other) : this() { _hasBits0 = other._hasBits0; - a_ = other.HasA ? other.a_.Clone() : null; + a_ = other.a_ != null ? other.a_.Clone() : null; i_ = other.i_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -9002,16 +8880,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { a_ = value; } } - /// Gets whether the a field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasA { - get { return a_ != null; } - } - /// Clears the value of the a field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearA() { - a_ = null; - } /// Field number for the "i" field. public const int IFieldNumber = 2; @@ -9058,7 +8926,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasA) hash ^= A.GetHashCode(); + if (a_ != null) hash ^= A.GetHashCode(); if (HasI) hash ^= I.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -9073,7 +8941,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasA) { + if (a_ != null) { output.WriteRawTag(10); output.WriteMessage(A); } @@ -9089,7 +8957,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasA) { + if (a_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(A); } if (HasI) { @@ -9106,8 +8974,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasA) { - if (!HasA) { + if (other.a_ != null) { + if (a_ == null) { A = new global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage(); } A.MergeFrom(other.A); @@ -9127,7 +8995,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasA) { + if (a_ == null) { A = new global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage(); } input.ReadMessage(A); @@ -9171,7 +9039,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestMutualRecursionA(TestMutualRecursionA other) : this() { - bb_ = other.HasBb ? other.bb_.Clone() : null; + bb_ = other.bb_ != null ? other.bb_.Clone() : null; subGroup_ = other.HasSubGroup ? other.subGroup_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -9191,16 +9059,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { bb_ = value; } } - /// Gets whether the bb field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasBb { - get { return bb_ != null; } - } - /// Clears the value of the bb field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearBb() { - bb_ = null; - } /// Field number for the "subgroup" field. public const int SubGroupFieldNumber = 2; @@ -9244,7 +9102,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasBb) hash ^= Bb.GetHashCode(); + if (bb_ != null) hash ^= Bb.GetHashCode(); if (HasSubGroup) hash ^= SubGroup.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -9259,7 +9117,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasBb) { + if (bb_ != null) { output.WriteRawTag(10); output.WriteMessage(Bb); } @@ -9276,7 +9134,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasBb) { + if (bb_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Bb); } if (HasSubGroup) { @@ -9293,8 +9151,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasBb) { - if (!HasBb) { + if (other.bb_ != null) { + if (bb_ == null) { Bb = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB(); } Bb.MergeFrom(other.Bb); @@ -9317,7 +9175,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasBb) { + if (bb_ == null) { Bb = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB(); } input.ReadMessage(Bb); @@ -9363,7 +9221,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public SubMessage(SubMessage other) : this() { - b_ = other.HasB ? other.b_.Clone() : null; + b_ = other.b_ != null ? other.b_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -9382,16 +9240,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { b_ = value; } } - /// Gets whether the b field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasB { - get { return b_ != null; } - } - /// Clears the value of the b field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearB() { - b_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -9413,7 +9261,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasB) hash ^= B.GetHashCode(); + if (b_ != null) hash ^= B.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -9427,7 +9275,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasB) { + if (b_ != null) { output.WriteRawTag(10); output.WriteMessage(B); } @@ -9439,7 +9287,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasB) { + if (b_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(B); } if (_unknownFields != null) { @@ -9453,8 +9301,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasB) { - if (!HasB) { + if (other.b_ != null) { + if (b_ == null) { B = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB(); } B.MergeFrom(other.B); @@ -9471,7 +9319,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasB) { + if (b_ == null) { B = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB(); } input.ReadMessage(B); @@ -9508,8 +9356,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public SubGroup(SubGroup other) : this() { - subMessage_ = other.HasSubMessage ? other.subMessage_.Clone() : null; - notInThisScc_ = other.HasNotInThisScc ? other.notInThisScc_.Clone() : null; + subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null; + notInThisScc_ = other.notInThisScc_ != null ? other.notInThisScc_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -9531,16 +9379,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { subMessage_ = value; } } - /// Gets whether the sub_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasSubMessage { - get { return subMessage_ != null; } - } - /// Clears the value of the sub_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearSubMessage() { - subMessage_ = null; - } /// Field number for the "not_in_this_scc" field. public const int NotInThisSccFieldNumber = 4; @@ -9552,16 +9390,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { notInThisScc_ = value; } } - /// Gets whether the not_in_this_scc field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasNotInThisScc { - get { return notInThisScc_ != null; } - } - /// Clears the value of the not_in_this_scc field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearNotInThisScc() { - notInThisScc_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -9584,8 +9412,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasSubMessage) hash ^= SubMessage.GetHashCode(); - if (HasNotInThisScc) hash ^= NotInThisScc.GetHashCode(); + if (subMessage_ != null) hash ^= SubMessage.GetHashCode(); + if (notInThisScc_ != null) hash ^= NotInThisScc.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -9599,11 +9427,11 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasSubMessage) { + if (subMessage_ != null) { output.WriteRawTag(26); output.WriteMessage(SubMessage); } - if (HasNotInThisScc) { + if (notInThisScc_ != null) { output.WriteRawTag(34); output.WriteMessage(NotInThisScc); } @@ -9615,10 +9443,10 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasSubMessage) { + if (subMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage); } - if (HasNotInThisScc) { + if (notInThisScc_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(NotInThisScc); } if (_unknownFields != null) { @@ -9632,14 +9460,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasSubMessage) { - if (!HasSubMessage) { + if (other.subMessage_ != null) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage(); } SubMessage.MergeFrom(other.SubMessage); } - if (other.HasNotInThisScc) { - if (!HasNotInThisScc) { + if (other.notInThisScc_ != null) { + if (notInThisScc_ == null) { NotInThisScc = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } NotInThisScc.MergeFrom(other.NotInThisScc); @@ -9658,14 +9486,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 26: { - if (!HasSubMessage) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage(); } input.ReadMessage(SubMessage); break; } case 34: { - if (!HasNotInThisScc) { + if (notInThisScc_ == null) { NotInThisScc = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(NotInThisScc); @@ -9709,7 +9537,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestMutualRecursionB(TestMutualRecursionB other) : this() { _hasBits0 = other._hasBits0; - a_ = other.HasA ? other.a_.Clone() : null; + a_ = other.a_ != null ? other.a_.Clone() : null; optionalInt32_ = other.optionalInt32_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -9729,16 +9557,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { a_ = value; } } - /// Gets whether the a field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasA { - get { return a_ != null; } - } - /// Clears the value of the a field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearA() { - a_ = null; - } /// Field number for the "optional_int32" field. public const int OptionalInt32FieldNumber = 2; @@ -9785,7 +9603,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasA) hash ^= A.GetHashCode(); + if (a_ != null) hash ^= A.GetHashCode(); if (HasOptionalInt32) hash ^= OptionalInt32.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -9800,7 +9618,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasA) { + if (a_ != null) { output.WriteRawTag(10); output.WriteMessage(A); } @@ -9816,7 +9634,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasA) { + if (a_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(A); } if (HasOptionalInt32) { @@ -9833,8 +9651,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasA) { - if (!HasA) { + if (other.a_ != null) { + if (a_ == null) { A = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA(); } A.MergeFrom(other.A); @@ -9854,7 +9672,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasA) { + if (a_ == null) { A = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA(); } input.ReadMessage(A); @@ -9895,7 +9713,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestIsInitialized(TestIsInitialized other) : this() { - subMessage_ = other.HasSubMessage ? other.subMessage_.Clone() : null; + subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -9914,16 +9732,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { subMessage_ = value; } } - /// Gets whether the sub_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasSubMessage { - get { return subMessage_ != null; } - } - /// Clears the value of the sub_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearSubMessage() { - subMessage_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -9945,7 +9753,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasSubMessage) hash ^= SubMessage.GetHashCode(); + if (subMessage_ != null) hash ^= SubMessage.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -9959,7 +9767,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasSubMessage) { + if (subMessage_ != null) { output.WriteRawTag(10); output.WriteMessage(SubMessage); } @@ -9971,7 +9779,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasSubMessage) { + if (subMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage); } if (_unknownFields != null) { @@ -9985,8 +9793,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasSubMessage) { - if (!HasSubMessage) { + if (other.subMessage_ != null) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage(); } SubMessage.MergeFrom(other.SubMessage); @@ -10003,7 +9811,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasSubMessage) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage(); } input.ReadMessage(SubMessage); @@ -10891,7 +10699,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestEagerMessage(TestEagerMessage other) : this() { - subMessage_ = other.HasSubMessage ? other.subMessage_.Clone() : null; + subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -10910,16 +10718,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { subMessage_ = value; } } - /// Gets whether the sub_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasSubMessage { - get { return subMessage_ != null; } - } - /// Clears the value of the sub_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearSubMessage() { - subMessage_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -10941,7 +10739,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasSubMessage) hash ^= SubMessage.GetHashCode(); + if (subMessage_ != null) hash ^= SubMessage.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -10955,7 +10753,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasSubMessage) { + if (subMessage_ != null) { output.WriteRawTag(10); output.WriteMessage(SubMessage); } @@ -10967,7 +10765,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasSubMessage) { + if (subMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage); } if (_unknownFields != null) { @@ -10981,8 +10779,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasSubMessage) { - if (!HasSubMessage) { + if (other.subMessage_ != null) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } SubMessage.MergeFrom(other.SubMessage); @@ -10999,7 +10797,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasSubMessage) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(SubMessage); @@ -11036,7 +10834,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestLazyMessage(TestLazyMessage other) : this() { - subMessage_ = other.HasSubMessage ? other.subMessage_.Clone() : null; + subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -11055,16 +10853,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { subMessage_ = value; } } - /// Gets whether the sub_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasSubMessage { - get { return subMessage_ != null; } - } - /// Clears the value of the sub_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearSubMessage() { - subMessage_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -11086,7 +10874,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasSubMessage) hash ^= SubMessage.GetHashCode(); + if (subMessage_ != null) hash ^= SubMessage.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -11100,7 +10888,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasSubMessage) { + if (subMessage_ != null) { output.WriteRawTag(10); output.WriteMessage(SubMessage); } @@ -11112,7 +10900,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasSubMessage) { + if (subMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage); } if (_unknownFields != null) { @@ -11126,8 +10914,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasSubMessage) { - if (!HasSubMessage) { + if (other.subMessage_ != null) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } SubMessage.MergeFrom(other.SubMessage); @@ -11144,7 +10932,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasSubMessage) { + if (subMessage_ == null) { SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(SubMessage); @@ -11184,7 +10972,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestNestedMessageHasBits(TestNestedMessageHasBits other) : this() { - optionalNestedMessage_ = other.HasOptionalNestedMessage ? other.optionalNestedMessage_.Clone() : null; + optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -11203,16 +10991,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalNestedMessage_ = value; } } - /// Gets whether the optional_nested_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalNestedMessage { - get { return optionalNestedMessage_ != null; } - } - /// Clears the value of the optional_nested_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalNestedMessage() { - optionalNestedMessage_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -11234,7 +11012,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasOptionalNestedMessage) hash ^= OptionalNestedMessage.GetHashCode(); + if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -11248,7 +11026,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { output.WriteRawTag(10); output.WriteMessage(OptionalNestedMessage); } @@ -11260,7 +11038,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage); } if (_unknownFields != null) { @@ -11274,8 +11052,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasOptionalNestedMessage) { - if (!HasOptionalNestedMessage) { + if (other.optionalNestedMessage_ != null) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage(); } OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage); @@ -11292,7 +11070,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { - if (!HasOptionalNestedMessage) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage(); } input.ReadMessage(OptionalNestedMessage); @@ -11487,7 +11265,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { primitiveField_ = other.primitiveField_; stringField_ = other.stringField_; enumField_ = other.enumField_; - messageField_ = other.HasMessageField ? other.messageField_.Clone() : null; + messageField_ = other.messageField_ != null ? other.messageField_.Clone() : null; stringPieceField_ = other.stringPieceField_; cordField_ = other.cordField_; repeatedPrimitiveField_ = other.repeatedPrimitiveField_.Clone(); @@ -11585,16 +11363,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { messageField_ = value; } } - /// Gets whether the MessageField field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasMessageField { - get { return messageField_ != null; } - } - /// Clears the value of the MessageField field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearMessageField() { - messageField_ = null; - } /// Field number for the "StringPieceField" field. public const int StringPieceFieldFieldNumber = 5; @@ -11736,7 +11504,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasPrimitiveField) hash ^= PrimitiveField.GetHashCode(); if (HasStringField) hash ^= StringField.GetHashCode(); if (HasEnumField) hash ^= EnumField.GetHashCode(); - if (HasMessageField) hash ^= MessageField.GetHashCode(); + if (messageField_ != null) hash ^= MessageField.GetHashCode(); if (HasStringPieceField) hash ^= StringPieceField.GetHashCode(); if (HasCordField) hash ^= CordField.GetHashCode(); hash ^= repeatedPrimitiveField_.GetHashCode(); @@ -11770,7 +11538,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(24); output.WriteEnum((int) EnumField); } - if (HasMessageField) { + if (messageField_ != null) { output.WriteRawTag(34); output.WriteMessage(MessageField); } @@ -11805,7 +11573,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasEnumField) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EnumField); } - if (HasMessageField) { + if (messageField_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(MessageField); } if (HasStringPieceField) { @@ -11840,8 +11608,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other.HasEnumField) { EnumField = other.EnumField; } - if (other.HasMessageField) { - if (!HasMessageField) { + if (other.messageField_ != null) { + if (messageField_ == null) { MessageField = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } MessageField.MergeFrom(other.MessageField); @@ -11882,7 +11650,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 34: { - if (!HasMessageField) { + if (messageField_ == null) { MessageField = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } input.ReadMessage(MessageField); @@ -11964,7 +11732,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { myString_ = other.myString_; myInt_ = other.myInt_; myFloat_ = other.myFloat_; - optionalNestedMessage_ = other.HasOptionalNestedMessage ? other.optionalNestedMessage_.Clone() : null; + optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); _extensions = pb::ExtensionSet.Clone(other._extensions); } @@ -12055,16 +11823,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalNestedMessage_ = value; } } - /// Gets whether the optional_nested_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalNestedMessage { - get { return optionalNestedMessage_ != null; } - } - /// Clears the value of the optional_nested_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalNestedMessage() { - optionalNestedMessage_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -12095,7 +11853,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasMyString) hash ^= MyString.GetHashCode(); if (HasMyInt) hash ^= MyInt.GetHashCode(); if (HasMyFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(MyFloat); - if (HasOptionalNestedMessage) hash ^= OptionalNestedMessage.GetHashCode(); + if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode(); if (_extensions != null) { hash ^= _extensions.GetHashCode(); } @@ -12124,7 +11882,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(173, 6); output.WriteFloat(MyFloat); } - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { output.WriteRawTag(194, 12); output.WriteMessage(OptionalNestedMessage); } @@ -12148,7 +11906,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasMyFloat) { size += 2 + 4; } - if (HasOptionalNestedMessage) { + if (optionalNestedMessage_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage); } if (_extensions != null) { @@ -12174,8 +11932,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other.HasMyFloat) { MyFloat = other.MyFloat; } - if (other.HasOptionalNestedMessage) { - if (!HasOptionalNestedMessage) { + if (other.optionalNestedMessage_ != null) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage(); } OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage); @@ -12207,7 +11965,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 1602: { - if (!HasOptionalNestedMessage) { + if (optionalNestedMessage_ == null) { OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage(); } input.ReadMessage(OptionalNestedMessage); @@ -15616,24 +15374,12 @@ namespace Google.Protobuf.TestProtos.Proto2 { public const int FooMessageFieldNumber = 3; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes FooMessage { - get { return HasFooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes) foo_ : null; } + get { return fooCase_ == FooOneofCase.FooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes) foo_ : null; } set { foo_ = value; fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooMessage; } } - /// Gets whether the "foo_message" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasFooMessage { - get { return fooCase_ == FooOneofCase.FooMessage; } - } - /// Clears the value of the oneof if it's currently set to "foo_message" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearFooMessage() { - if (HasFooMessage) { - ClearFoo(); - } - } /// Field number for the "foogroup" field. public const int FooGroupFieldNumber = 4; @@ -15705,7 +15451,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { int hash = 1; if (HasFooInt) hash ^= FooInt.GetHashCode(); if (HasFooString) hash ^= FooString.GetHashCode(); - if (HasFooMessage) hash ^= FooMessage.GetHashCode(); + if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode(); if (HasFooGroup) hash ^= FooGroup.GetHashCode(); hash ^= (int) fooCase_; if (_unknownFields != null) { @@ -15729,7 +15475,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(18); output.WriteString(FooString); } - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { output.WriteRawTag(26); output.WriteMessage(FooMessage); } @@ -15752,7 +15498,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasFooString) { size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString); } - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage); } if (HasFooGroup) { @@ -15811,7 +15557,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } case 26: { global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { subBuilder.MergeFrom(FooMessage); } input.ReadMessage(subBuilder); @@ -16055,7 +15801,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _hasBits0 = other._hasBits0; fooInt_ = other.fooInt_; fooString_ = other.fooString_; - fooMessage_ = other.HasFooMessage ? other.fooMessage_.Clone() : null; + fooMessage_ = other.fooMessage_ != null ? other.fooMessage_.Clone() : null; fooGroup_ = other.HasFooGroup ? other.fooGroup_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -16122,16 +15868,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { fooMessage_ = value; } } - /// Gets whether the foo_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasFooMessage { - get { return fooMessage_ != null; } - } - /// Clears the value of the foo_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearFooMessage() { - fooMessage_ = null; - } /// Field number for the "foogroup" field. public const int FooGroupFieldNumber = 4; @@ -16179,7 +15915,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { int hash = 1; if (HasFooInt) hash ^= FooInt.GetHashCode(); if (HasFooString) hash ^= FooString.GetHashCode(); - if (HasFooMessage) hash ^= FooMessage.GetHashCode(); + if (fooMessage_ != null) hash ^= FooMessage.GetHashCode(); if (HasFooGroup) hash ^= FooGroup.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -16202,7 +15938,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(18); output.WriteString(FooString); } - if (HasFooMessage) { + if (fooMessage_ != null) { output.WriteRawTag(26); output.WriteMessage(FooMessage); } @@ -16225,7 +15961,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasFooString) { size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString); } - if (HasFooMessage) { + if (fooMessage_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage); } if (HasFooGroup) { @@ -16248,8 +15984,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other.HasFooString) { FooString = other.FooString; } - if (other.HasFooMessage) { - if (!HasFooMessage) { + if (other.fooMessage_ != null) { + if (fooMessage_ == null) { FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } FooMessage.MergeFrom(other.FooMessage); @@ -16280,7 +16016,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 26: { - if (!HasFooMessage) { + if (fooMessage_ == null) { FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(FooMessage); @@ -16722,24 +16458,12 @@ namespace Google.Protobuf.TestProtos.Proto2 { public const int FooMessageFieldNumber = 7; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage FooMessage { - get { return HasFooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage) foo_ : null; } + get { return fooCase_ == FooOneofCase.FooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage) foo_ : null; } set { foo_ = value; fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooMessage; } } - /// Gets whether the "foo_message" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasFooMessage { - get { return fooCase_ == FooOneofCase.FooMessage; } - } - /// Clears the value of the oneof if it's currently set to "foo_message" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearFooMessage() { - if (HasFooMessage) { - ClearFoo(); - } - } /// Field number for the "foogroup" field. public const int FooGroupFieldNumber = 8; @@ -16768,24 +16492,12 @@ namespace Google.Protobuf.TestProtos.Proto2 { public const int FooLazyMessageFieldNumber = 11; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage FooLazyMessage { - get { return HasFooLazyMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage) foo_ : null; } + get { return fooCase_ == FooOneofCase.FooLazyMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage) foo_ : null; } set { foo_ = value; fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooLazyMessage; } } - /// Gets whether the "foo_lazy_message" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasFooLazyMessage { - get { return fooCase_ == FooOneofCase.FooLazyMessage; } - } - /// Clears the value of the oneof if it's currently set to "foo_lazy_message" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearFooLazyMessage() { - if (HasFooLazyMessage) { - ClearFoo(); - } - } /// Field number for the "bar_int" field. public const int BarIntFieldNumber = 12; @@ -17065,9 +16777,9 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasFooStringPiece) hash ^= FooStringPiece.GetHashCode(); if (HasFooBytes) hash ^= FooBytes.GetHashCode(); if (HasFooEnum) hash ^= FooEnum.GetHashCode(); - if (HasFooMessage) hash ^= FooMessage.GetHashCode(); + if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode(); if (HasFooGroup) hash ^= FooGroup.GetHashCode(); - if (HasFooLazyMessage) hash ^= FooLazyMessage.GetHashCode(); + if (fooCase_ == FooOneofCase.FooLazyMessage) hash ^= FooLazyMessage.GetHashCode(); if (HasBarInt) hash ^= BarInt.GetHashCode(); if (HasBarString) hash ^= BarString.GetHashCode(); if (HasBarCord) hash ^= BarCord.GetHashCode(); @@ -17115,7 +16827,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(48); output.WriteEnum((int) FooEnum); } - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { output.WriteRawTag(58); output.WriteMessage(FooMessage); } @@ -17124,7 +16836,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteGroup(FooGroup); output.WriteRawTag(68); } - if (HasFooLazyMessage) { + if (fooCase_ == FooOneofCase.FooLazyMessage) { output.WriteRawTag(90); output.WriteMessage(FooLazyMessage); } @@ -17186,13 +16898,13 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasFooEnum) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) FooEnum); } - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage); } if (HasFooGroup) { size += 2 + pb::CodedOutputStream.ComputeGroupSize(FooGroup); } - if (HasFooLazyMessage) { + if (fooCase_ == FooOneofCase.FooLazyMessage) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooLazyMessage); } if (HasBarInt) { @@ -17334,7 +17046,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } case 58: { global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage(); - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { subBuilder.MergeFrom(FooMessage); } input.ReadMessage(subBuilder); @@ -17352,7 +17064,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } case 90: { global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage(); - if (HasFooLazyMessage) { + if (fooCase_ == FooOneofCase.FooLazyMessage) { subBuilder.MergeFrom(FooLazyMessage); } input.ReadMessage(subBuilder); @@ -17857,24 +17569,12 @@ namespace Google.Protobuf.TestProtos.Proto2 { public const int FooMessageFieldNumber = 3; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage FooMessage { - get { return HasFooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage) foo_ : null; } + get { return fooCase_ == FooOneofCase.FooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage) foo_ : null; } set { foo_ = value; fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooMessage; } } - /// Gets whether the "foo_message" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasFooMessage { - get { return fooCase_ == FooOneofCase.FooMessage; } - } - /// Clears the value of the oneof if it's currently set to "foo_message" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearFooMessage() { - if (HasFooMessage) { - ClearFoo(); - } - } private object foo_; /// Enum of possible cases for the "foo" oneof. @@ -17921,7 +17621,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { int hash = 1; if (HasFooInt) hash ^= FooInt.GetHashCode(); if (HasFooString) hash ^= FooString.GetHashCode(); - if (HasFooMessage) hash ^= FooMessage.GetHashCode(); + if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode(); hash ^= (int) fooCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -17944,7 +17644,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(18); output.WriteString(FooString); } - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { output.WriteRawTag(26); output.WriteMessage(FooMessage); } @@ -17962,7 +17662,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasFooString) { size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString); } - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage); } if (_unknownFields != null) { @@ -18012,7 +17712,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } case 26: { global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage(); - if (HasFooMessage) { + if (fooCase_ == FooOneofCase.FooMessage) { subBuilder.MergeFrom(FooMessage); } input.ReadMessage(subBuilder); @@ -19559,8 +19259,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { scalarExtension_ = other.scalarExtension_; enumExtension_ = other.enumExtension_; dynamicEnumExtension_ = other.dynamicEnumExtension_; - messageExtension_ = other.HasMessageExtension ? other.messageExtension_.Clone() : null; - dynamicMessageExtension_ = other.HasDynamicMessageExtension ? other.dynamicMessageExtension_.Clone() : null; + messageExtension_ = other.messageExtension_ != null ? other.messageExtension_.Clone() : null; + dynamicMessageExtension_ = other.dynamicMessageExtension_ != null ? other.dynamicMessageExtension_.Clone() : null; repeatedExtension_ = other.repeatedExtension_.Clone(); packedExtension_ = other.packedExtension_.Clone(); _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -19653,16 +19353,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { messageExtension_ = value; } } - /// Gets whether the message_extension field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasMessageExtension { - get { return messageExtension_ != null; } - } - /// Clears the value of the message_extension field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearMessageExtension() { - messageExtension_ = null; - } /// Field number for the "dynamic_message_extension" field. public const int DynamicMessageExtensionFieldNumber = 2004; @@ -19674,16 +19364,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { dynamicMessageExtension_ = value; } } - /// Gets whether the dynamic_message_extension field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasDynamicMessageExtension { - get { return dynamicMessageExtension_ != null; } - } - /// Clears the value of the dynamic_message_extension field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearDynamicMessageExtension() { - dynamicMessageExtension_ = null; - } /// Field number for the "repeated_extension" field. public const int RepeatedExtensionFieldNumber = 2005; @@ -19734,8 +19414,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasScalarExtension) hash ^= ScalarExtension.GetHashCode(); if (HasEnumExtension) hash ^= EnumExtension.GetHashCode(); if (HasDynamicEnumExtension) hash ^= DynamicEnumExtension.GetHashCode(); - if (HasMessageExtension) hash ^= MessageExtension.GetHashCode(); - if (HasDynamicMessageExtension) hash ^= DynamicMessageExtension.GetHashCode(); + if (messageExtension_ != null) hash ^= MessageExtension.GetHashCode(); + if (dynamicMessageExtension_ != null) hash ^= DynamicMessageExtension.GetHashCode(); hash ^= repeatedExtension_.GetHashCode(); hash ^= packedExtension_.GetHashCode(); if (_unknownFields != null) { @@ -19763,11 +19443,11 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(144, 125); output.WriteEnum((int) DynamicEnumExtension); } - if (HasMessageExtension) { + if (messageExtension_ != null) { output.WriteRawTag(154, 125); output.WriteMessage(MessageExtension); } - if (HasDynamicMessageExtension) { + if (dynamicMessageExtension_ != null) { output.WriteRawTag(162, 125); output.WriteMessage(DynamicMessageExtension); } @@ -19790,10 +19470,10 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasDynamicEnumExtension) { size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) DynamicEnumExtension); } - if (HasMessageExtension) { + if (messageExtension_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(MessageExtension); } - if (HasDynamicMessageExtension) { + if (dynamicMessageExtension_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(DynamicMessageExtension); } size += repeatedExtension_.CalculateSize(_repeated_repeatedExtension_codec); @@ -19818,14 +19498,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other.HasDynamicEnumExtension) { DynamicEnumExtension = other.DynamicEnumExtension; } - if (other.HasMessageExtension) { - if (!HasMessageExtension) { + if (other.messageExtension_ != null) { + if (messageExtension_ == null) { MessageExtension = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } MessageExtension.MergeFrom(other.MessageExtension); } - if (other.HasDynamicMessageExtension) { - if (!HasDynamicMessageExtension) { + if (other.dynamicMessageExtension_ != null) { + if (dynamicMessageExtension_ == null) { DynamicMessageExtension = new global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType(); } DynamicMessageExtension.MergeFrom(other.DynamicMessageExtension); @@ -19856,14 +19536,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 16026: { - if (!HasMessageExtension) { + if (messageExtension_ == null) { MessageExtension = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } input.ReadMessage(MessageExtension); break; } case 16034: { - if (!HasDynamicMessageExtension) { + if (dynamicMessageExtension_ == null) { DynamicMessageExtension = new global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType(); } input.ReadMessage(DynamicMessageExtension); @@ -20313,8 +19993,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public TestParsingMerge(TestParsingMerge other) : this() { - requiredAllTypes_ = other.HasRequiredAllTypes ? other.requiredAllTypes_.Clone() : null; - optionalAllTypes_ = other.HasOptionalAllTypes ? other.optionalAllTypes_.Clone() : null; + requiredAllTypes_ = other.requiredAllTypes_ != null ? other.requiredAllTypes_.Clone() : null; + optionalAllTypes_ = other.optionalAllTypes_ != null ? other.optionalAllTypes_.Clone() : null; repeatedAllTypes_ = other.repeatedAllTypes_.Clone(); optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null; repeatedGroup_ = other.repeatedGroup_.Clone(); @@ -20337,16 +20017,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { requiredAllTypes_ = value; } } - /// Gets whether the required_all_types field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasRequiredAllTypes { - get { return requiredAllTypes_ != null; } - } - /// Clears the value of the required_all_types field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearRequiredAllTypes() { - requiredAllTypes_ = null; - } /// Field number for the "optional_all_types" field. public const int OptionalAllTypesFieldNumber = 2; @@ -20358,16 +20028,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalAllTypes_ = value; } } - /// Gets whether the optional_all_types field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalAllTypes { - get { return optionalAllTypes_ != null; } - } - /// Clears the value of the optional_all_types field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalAllTypes() { - optionalAllTypes_ = null; - } /// Field number for the "repeated_all_types" field. public const int RepeatedAllTypesFieldNumber = 3; @@ -20437,8 +20097,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasRequiredAllTypes) hash ^= RequiredAllTypes.GetHashCode(); - if (HasOptionalAllTypes) hash ^= OptionalAllTypes.GetHashCode(); + if (requiredAllTypes_ != null) hash ^= RequiredAllTypes.GetHashCode(); + if (optionalAllTypes_ != null) hash ^= OptionalAllTypes.GetHashCode(); hash ^= repeatedAllTypes_.GetHashCode(); if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode(); hash ^= repeatedGroup_.GetHashCode(); @@ -20458,11 +20118,11 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasRequiredAllTypes) { + if (requiredAllTypes_ != null) { output.WriteRawTag(10); output.WriteMessage(RequiredAllTypes); } - if (HasOptionalAllTypes) { + if (optionalAllTypes_ != null) { output.WriteRawTag(18); output.WriteMessage(OptionalAllTypes); } @@ -20484,10 +20144,10 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasRequiredAllTypes) { + if (requiredAllTypes_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(RequiredAllTypes); } - if (HasOptionalAllTypes) { + if (optionalAllTypes_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalAllTypes); } size += repeatedAllTypes_.CalculateSize(_repeated_repeatedAllTypes_codec); @@ -20509,14 +20169,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasRequiredAllTypes) { - if (!HasRequiredAllTypes) { + if (other.requiredAllTypes_ != null) { + if (requiredAllTypes_ == null) { RequiredAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } RequiredAllTypes.MergeFrom(other.RequiredAllTypes); } - if (other.HasOptionalAllTypes) { - if (!HasOptionalAllTypes) { + if (other.optionalAllTypes_ != null) { + if (optionalAllTypes_ == null) { OptionalAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } OptionalAllTypes.MergeFrom(other.OptionalAllTypes); @@ -20544,14 +20204,14 @@ namespace Google.Protobuf.TestProtos.Proto2 { } break; case 10: { - if (!HasRequiredAllTypes) { + if (requiredAllTypes_ == null) { RequiredAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(RequiredAllTypes); break; } case 18: { - if (!HasOptionalAllTypes) { + if (optionalAllTypes_ == null) { OptionalAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(OptionalAllTypes); @@ -20877,7 +20537,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public Group1(Group1 other) : this() { - field1_ = other.HasField1 ? other.field1_.Clone() : null; + field1_ = other.field1_ != null ? other.field1_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -20896,16 +20556,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { field1_ = value; } } - /// Gets whether the field1 field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasField1 { - get { return field1_ != null; } - } - /// Clears the value of the field1 field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearField1() { - field1_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -20927,7 +20577,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasField1) hash ^= Field1.GetHashCode(); + if (field1_ != null) hash ^= Field1.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -20941,7 +20591,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasField1) { + if (field1_ != null) { output.WriteRawTag(90); output.WriteMessage(Field1); } @@ -20953,7 +20603,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasField1) { + if (field1_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Field1); } if (_unknownFields != null) { @@ -20967,8 +20617,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasField1) { - if (!HasField1) { + if (other.field1_ != null) { + if (field1_ == null) { Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } Field1.MergeFrom(other.Field1); @@ -20987,7 +20637,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 90: { - if (!HasField1) { + if (field1_ == null) { Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(Field1); @@ -21024,7 +20674,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public Group2(Group2 other) : this() { - field1_ = other.HasField1 ? other.field1_.Clone() : null; + field1_ = other.field1_ != null ? other.field1_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -21043,16 +20693,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { field1_ = value; } } - /// Gets whether the field1 field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasField1 { - get { return field1_ != null; } - } - /// Clears the value of the field1 field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearField1() { - field1_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -21074,7 +20714,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasField1) hash ^= Field1.GetHashCode(); + if (field1_ != null) hash ^= Field1.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -21088,7 +20728,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasField1) { + if (field1_ != null) { output.WriteRawTag(170, 1); output.WriteMessage(Field1); } @@ -21100,7 +20740,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasField1) { + if (field1_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(Field1); } if (_unknownFields != null) { @@ -21114,8 +20754,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasField1) { - if (!HasField1) { + if (other.field1_ != null) { + if (field1_ == null) { Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } Field1.MergeFrom(other.Field1); @@ -21134,7 +20774,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 170: { - if (!HasField1) { + if (field1_ == null) { Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(Field1); @@ -21176,7 +20816,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public OptionalGroup(OptionalGroup other) : this() { - optionalGroupAllTypes_ = other.HasOptionalGroupAllTypes ? other.optionalGroupAllTypes_.Clone() : null; + optionalGroupAllTypes_ = other.optionalGroupAllTypes_ != null ? other.optionalGroupAllTypes_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -21195,16 +20835,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalGroupAllTypes_ = value; } } - /// Gets whether the optional_group_all_types field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalGroupAllTypes { - get { return optionalGroupAllTypes_ != null; } - } - /// Clears the value of the optional_group_all_types field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalGroupAllTypes() { - optionalGroupAllTypes_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -21226,7 +20856,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasOptionalGroupAllTypes) hash ^= OptionalGroupAllTypes.GetHashCode(); + if (optionalGroupAllTypes_ != null) hash ^= OptionalGroupAllTypes.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -21240,7 +20870,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasOptionalGroupAllTypes) { + if (optionalGroupAllTypes_ != null) { output.WriteRawTag(90); output.WriteMessage(OptionalGroupAllTypes); } @@ -21252,7 +20882,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasOptionalGroupAllTypes) { + if (optionalGroupAllTypes_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalGroupAllTypes); } if (_unknownFields != null) { @@ -21266,8 +20896,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasOptionalGroupAllTypes) { - if (!HasOptionalGroupAllTypes) { + if (other.optionalGroupAllTypes_ != null) { + if (optionalGroupAllTypes_ == null) { OptionalGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } OptionalGroupAllTypes.MergeFrom(other.OptionalGroupAllTypes); @@ -21286,7 +20916,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 90: { - if (!HasOptionalGroupAllTypes) { + if (optionalGroupAllTypes_ == null) { OptionalGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(OptionalGroupAllTypes); @@ -21323,7 +20953,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public RepeatedGroup(RepeatedGroup other) : this() { - repeatedGroupAllTypes_ = other.HasRepeatedGroupAllTypes ? other.repeatedGroupAllTypes_.Clone() : null; + repeatedGroupAllTypes_ = other.repeatedGroupAllTypes_ != null ? other.repeatedGroupAllTypes_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -21342,16 +20972,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { repeatedGroupAllTypes_ = value; } } - /// Gets whether the repeated_group_all_types field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasRepeatedGroupAllTypes { - get { return repeatedGroupAllTypes_ != null; } - } - /// Clears the value of the repeated_group_all_types field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearRepeatedGroupAllTypes() { - repeatedGroupAllTypes_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -21373,7 +20993,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (HasRepeatedGroupAllTypes) hash ^= RepeatedGroupAllTypes.GetHashCode(); + if (repeatedGroupAllTypes_ != null) hash ^= RepeatedGroupAllTypes.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -21387,7 +21007,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (HasRepeatedGroupAllTypes) { + if (repeatedGroupAllTypes_ != null) { output.WriteRawTag(170, 1); output.WriteMessage(RepeatedGroupAllTypes); } @@ -21399,7 +21019,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (HasRepeatedGroupAllTypes) { + if (repeatedGroupAllTypes_ != null) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(RepeatedGroupAllTypes); } if (_unknownFields != null) { @@ -21413,8 +21033,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - if (other.HasRepeatedGroupAllTypes) { - if (!HasRepeatedGroupAllTypes) { + if (other.repeatedGroupAllTypes_ != null) { + if (repeatedGroupAllTypes_ == null) { RepeatedGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } RepeatedGroupAllTypes.MergeFrom(other.RepeatedGroupAllTypes); @@ -21433,7 +21053,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 170: { - if (!HasRepeatedGroupAllTypes) { + if (repeatedGroupAllTypes_ == null) { RepeatedGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); } input.ReadMessage(RepeatedGroupAllTypes); @@ -22599,7 +22219,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalEnum_ = other.optionalEnum_; optionalString_ = other.optionalString_; optionalBytes_ = other.optionalBytes_; - optionalMessage_ = other.HasOptionalMessage ? other.optionalMessage_.Clone() : null; + optionalMessage_ = other.optionalMessage_ != null ? other.optionalMessage_.Clone() : null; optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null; stringStringMap_ = other.stringStringMap_.Clone(); switch (other.OneofFieldCase) { @@ -22774,16 +22394,6 @@ namespace Google.Protobuf.TestProtos.Proto2 { optionalMessage_ = value; } } - /// Gets whether the optional_message field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptionalMessage { - get { return optionalMessage_ != null; } - } - /// Clears the value of the optional_message field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptionalMessage() { - optionalMessage_ = null; - } /// Field number for the "optionalgroup" field. public const int OptionalGroupFieldNumber = 536870008; @@ -22843,24 +22453,12 @@ namespace Google.Protobuf.TestProtos.Proto2 { public const int OneofTestAllTypesFieldNumber = 536870012; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes OneofTestAllTypes { - get { return HasOneofTestAllTypes ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes) oneofField_ : null; } + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes) oneofField_ : null; } set { oneofField_ = value; oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofTestAllTypes; } } - /// Gets whether the "oneof_test_all_types" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOneofTestAllTypes { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes; } - } - /// Clears the value of the oneof if it's currently set to "oneof_test_all_types" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOneofTestAllTypes() { - if (HasOneofTestAllTypes) { - ClearOneofField(); - } - } /// Field number for the "oneof_string" field. public const int OneofStringFieldNumber = 536870013; @@ -22973,11 +22571,11 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasOptionalEnum) hash ^= OptionalEnum.GetHashCode(); if (HasOptionalString) hash ^= OptionalString.GetHashCode(); if (HasOptionalBytes) hash ^= OptionalBytes.GetHashCode(); - if (HasOptionalMessage) hash ^= OptionalMessage.GetHashCode(); + if (optionalMessage_ != null) hash ^= OptionalMessage.GetHashCode(); if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode(); hash ^= StringStringMap.GetHashCode(); if (HasOneofUint32) hash ^= OneofUint32.GetHashCode(); - if (HasOneofTestAllTypes) hash ^= OneofTestAllTypes.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) hash ^= OneofTestAllTypes.GetHashCode(); if (HasOneofString) hash ^= OneofString.GetHashCode(); if (HasOneofBytes) hash ^= OneofBytes.GetHashCode(); hash ^= (int) oneofFieldCase_; @@ -23019,7 +22617,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(178, 199, 255, 255, 15); output.WriteBytes(OptionalBytes); } - if (HasOptionalMessage) { + if (optionalMessage_ != null) { output.WriteRawTag(186, 199, 255, 255, 15); output.WriteMessage(OptionalMessage); } @@ -23033,7 +22631,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { output.WriteRawTag(216, 199, 255, 255, 15); output.WriteUInt32(OneofUint32); } - if (HasOneofTestAllTypes) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) { output.WriteRawTag(226, 199, 255, 255, 15); output.WriteMessage(OneofTestAllTypes); } @@ -23073,7 +22671,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasOptionalBytes) { size += 5 + pb::CodedOutputStream.ComputeBytesSize(OptionalBytes); } - if (HasOptionalMessage) { + if (optionalMessage_ != null) { size += 5 + pb::CodedOutputStream.ComputeMessageSize(OptionalMessage); } if (HasOptionalGroup) { @@ -23083,7 +22681,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (HasOneofUint32) { size += 5 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32); } - if (HasOneofTestAllTypes) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) { size += 5 + pb::CodedOutputStream.ComputeMessageSize(OneofTestAllTypes); } if (HasOneofString) { @@ -23123,8 +22721,8 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other.HasOptionalBytes) { OptionalBytes = other.OptionalBytes; } - if (other.HasOptionalMessage) { - if (!HasOptionalMessage) { + if (other.optionalMessage_ != null) { + if (optionalMessage_ == null) { OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } OptionalMessage.MergeFrom(other.OptionalMessage); @@ -23199,7 +22797,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { break; } case 4294960058: { - if (!HasOptionalMessage) { + if (optionalMessage_ == null) { OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); } input.ReadMessage(OptionalMessage); @@ -23222,7 +22820,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } case 4294960098: { global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); - if (HasOneofTestAllTypes) { + if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) { subBuilder.MergeFrom(OneofTestAllTypes); } input.ReadMessage(subBuilder); diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index c9ba6328b9..1fa232b114 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -352,8 +352,8 @@ namespace Google.Protobuf.Reflection { enumType_ = other.enumType_.Clone(); service_ = other.service_.Clone(); extension_ = other.extension_.Clone(); - options_ = other.HasOptions ? other.options_.Clone() : null; - sourceCodeInfo_ = other.HasSourceCodeInfo ? other.sourceCodeInfo_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; + sourceCodeInfo_ = other.sourceCodeInfo_ != null ? other.sourceCodeInfo_.Clone() : null; syntax_ = other.syntax_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -508,16 +508,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } /// Field number for the "source_code_info" field. public const int SourceCodeInfoFieldNumber = 9; @@ -535,16 +525,6 @@ namespace Google.Protobuf.Reflection { sourceCodeInfo_ = value; } } - /// Gets whether the source_code_info field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasSourceCodeInfo { - get { return sourceCodeInfo_ != null; } - } - /// Clears the value of the source_code_info field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearSourceCodeInfo() { - sourceCodeInfo_ = null; - } /// Field number for the "syntax" field. public const int SyntaxFieldNumber = 12; @@ -613,8 +593,8 @@ namespace Google.Protobuf.Reflection { hash ^= enumType_.GetHashCode(); hash ^= service_.GetHashCode(); hash ^= extension_.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); - if (HasSourceCodeInfo) hash ^= SourceCodeInfo.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (sourceCodeInfo_ != null) hash ^= SourceCodeInfo.GetHashCode(); if (HasSyntax) hash ^= Syntax.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -642,11 +622,11 @@ namespace Google.Protobuf.Reflection { enumType_.WriteTo(output, _repeated_enumType_codec); service_.WriteTo(output, _repeated_service_codec); extension_.WriteTo(output, _repeated_extension_codec); - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(66); output.WriteMessage(Options); } - if (HasSourceCodeInfo) { + if (sourceCodeInfo_ != null) { output.WriteRawTag(74); output.WriteMessage(SourceCodeInfo); } @@ -677,10 +657,10 @@ namespace Google.Protobuf.Reflection { size += enumType_.CalculateSize(_repeated_enumType_codec); size += service_.CalculateSize(_repeated_service_codec); size += extension_.CalculateSize(_repeated_extension_codec); - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } - if (HasSourceCodeInfo) { + if (sourceCodeInfo_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceCodeInfo); } if (HasSyntax) { @@ -710,14 +690,14 @@ namespace Google.Protobuf.Reflection { enumType_.Add(other.enumType_); service_.Add(other.service_); extension_.Add(other.extension_); - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.FileOptions(); } Options.MergeFrom(other.Options); } - if (other.HasSourceCodeInfo) { - if (!HasSourceCodeInfo) { + if (other.sourceCodeInfo_ != null) { + if (sourceCodeInfo_ == null) { SourceCodeInfo = new global::Google.Protobuf.Reflection.SourceCodeInfo(); } SourceCodeInfo.MergeFrom(other.SourceCodeInfo); @@ -765,14 +745,14 @@ namespace Google.Protobuf.Reflection { break; } case 66: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.FileOptions(); } input.ReadMessage(Options); break; } case 74: { - if (!HasSourceCodeInfo) { + if (sourceCodeInfo_ == null) { SourceCodeInfo = new global::Google.Protobuf.Reflection.SourceCodeInfo(); } input.ReadMessage(SourceCodeInfo); @@ -833,7 +813,7 @@ namespace Google.Protobuf.Reflection { enumType_ = other.enumType_.Clone(); extensionRange_ = other.extensionRange_.Clone(); oneofDecl_ = other.oneofDecl_.Clone(); - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; reservedRange_ = other.reservedRange_.Clone(); reservedName_ = other.reservedName_.Clone(); _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -937,16 +917,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } /// Field number for the "reserved_range" field. public const int ReservedRangeFieldNumber = 9; @@ -1008,7 +978,7 @@ namespace Google.Protobuf.Reflection { hash ^= enumType_.GetHashCode(); hash ^= extensionRange_.GetHashCode(); hash ^= oneofDecl_.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); hash ^= reservedRange_.GetHashCode(); hash ^= reservedName_.GetHashCode(); if (_unknownFields != null) { @@ -1033,7 +1003,7 @@ namespace Google.Protobuf.Reflection { enumType_.WriteTo(output, _repeated_enumType_codec); extensionRange_.WriteTo(output, _repeated_extensionRange_codec); extension_.WriteTo(output, _repeated_extension_codec); - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(58); output.WriteMessage(Options); } @@ -1057,7 +1027,7 @@ namespace Google.Protobuf.Reflection { size += enumType_.CalculateSize(_repeated_enumType_codec); size += extensionRange_.CalculateSize(_repeated_extensionRange_codec); size += oneofDecl_.CalculateSize(_repeated_oneofDecl_codec); - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } size += reservedRange_.CalculateSize(_repeated_reservedRange_codec); @@ -1082,8 +1052,8 @@ namespace Google.Protobuf.Reflection { enumType_.Add(other.enumType_); extensionRange_.Add(other.extensionRange_); oneofDecl_.Add(other.oneofDecl_); - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.MessageOptions(); } Options.MergeFrom(other.Options); @@ -1126,7 +1096,7 @@ namespace Google.Protobuf.Reflection { break; } case 58: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.MessageOptions(); } input.ReadMessage(Options); @@ -1181,7 +1151,7 @@ namespace Google.Protobuf.Reflection { _hasBits0 = other._hasBits0; start_ = other.start_; end_ = other.end_; - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -1254,16 +1224,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -1289,7 +1249,7 @@ namespace Google.Protobuf.Reflection { int hash = 1; if (HasStart) hash ^= Start.GetHashCode(); if (HasEnd) hash ^= End.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -1311,7 +1271,7 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(16); output.WriteInt32(End); } - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(26); output.WriteMessage(Options); } @@ -1329,7 +1289,7 @@ namespace Google.Protobuf.Reflection { if (HasEnd) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(End); } - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } if (_unknownFields != null) { @@ -1349,8 +1309,8 @@ namespace Google.Protobuf.Reflection { if (other.HasEnd) { End = other.End; } - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.ExtensionRangeOptions(); } Options.MergeFrom(other.Options); @@ -1375,7 +1335,7 @@ namespace Google.Protobuf.Reflection { break; } case 26: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.ExtensionRangeOptions(); } input.ReadMessage(Options); @@ -1791,7 +1751,7 @@ namespace Google.Protobuf.Reflection { defaultValue_ = other.defaultValue_; oneofIndex_ = other.oneofIndex_; jsonName_ = other.jsonName_; - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; proto3Optional_ = other.proto3Optional_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -2054,16 +2014,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } /// Field number for the "proto3_optional" field. public const int Proto3OptionalFieldNumber = 17; @@ -2151,7 +2101,7 @@ namespace Google.Protobuf.Reflection { if (HasDefaultValue) hash ^= DefaultValue.GetHashCode(); if (HasOneofIndex) hash ^= OneofIndex.GetHashCode(); if (HasJsonName) hash ^= JsonName.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); if (HasProto3Optional) hash ^= Proto3Optional.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -2194,7 +2144,7 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(58); output.WriteString(DefaultValue); } - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(66); output.WriteMessage(Options); } @@ -2245,7 +2195,7 @@ namespace Google.Protobuf.Reflection { if (HasJsonName) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonName); } - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } if (HasProto3Optional) { @@ -2289,8 +2239,8 @@ namespace Google.Protobuf.Reflection { if (other.HasJsonName) { JsonName = other.JsonName; } - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.FieldOptions(); } Options.MergeFrom(other.Options); @@ -2338,7 +2288,7 @@ namespace Google.Protobuf.Reflection { break; } case 66: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.FieldOptions(); } input.ReadMessage(Options); @@ -2458,7 +2408,7 @@ namespace Google.Protobuf.Reflection { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public OneofDescriptorProto(OneofDescriptorProto other) : this() { name_ = other.name_; - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -2500,16 +2450,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -2533,7 +2473,7 @@ namespace Google.Protobuf.Reflection { public override int GetHashCode() { int hash = 1; if (HasName) hash ^= Name.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -2551,7 +2491,7 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(10); output.WriteString(Name); } - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(18); output.WriteMessage(Options); } @@ -2566,7 +2506,7 @@ namespace Google.Protobuf.Reflection { if (HasName) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); } - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } if (_unknownFields != null) { @@ -2583,8 +2523,8 @@ namespace Google.Protobuf.Reflection { if (other.HasName) { Name = other.Name; } - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.OneofOptions(); } Options.MergeFrom(other.Options); @@ -2605,7 +2545,7 @@ namespace Google.Protobuf.Reflection { break; } case 18: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.OneofOptions(); } input.ReadMessage(Options); @@ -2647,7 +2587,7 @@ namespace Google.Protobuf.Reflection { public EnumDescriptorProto(EnumDescriptorProto other) : this() { name_ = other.name_; value_ = other.value_.Clone(); - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; reservedRange_ = other.reservedRange_.Clone(); reservedName_ = other.reservedName_.Clone(); _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -2701,16 +2641,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } /// Field number for the "reserved_range" field. public const int ReservedRangeFieldNumber = 4; @@ -2767,7 +2697,7 @@ namespace Google.Protobuf.Reflection { int hash = 1; if (HasName) hash ^= Name.GetHashCode(); hash ^= value_.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); hash ^= reservedRange_.GetHashCode(); hash ^= reservedName_.GetHashCode(); if (_unknownFields != null) { @@ -2788,7 +2718,7 @@ namespace Google.Protobuf.Reflection { output.WriteString(Name); } value_.WriteTo(output, _repeated_value_codec); - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(26); output.WriteMessage(Options); } @@ -2806,7 +2736,7 @@ namespace Google.Protobuf.Reflection { size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); } size += value_.CalculateSize(_repeated_value_codec); - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } size += reservedRange_.CalculateSize(_repeated_reservedRange_codec); @@ -2826,8 +2756,8 @@ namespace Google.Protobuf.Reflection { Name = other.Name; } value_.Add(other.value_); - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.EnumOptions(); } Options.MergeFrom(other.Options); @@ -2854,7 +2784,7 @@ namespace Google.Protobuf.Reflection { break; } case 26: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.EnumOptions(); } input.ReadMessage(Options); @@ -3112,7 +3042,7 @@ namespace Google.Protobuf.Reflection { _hasBits0 = other._hasBits0; name_ = other.name_; number_ = other.number_; - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -3178,16 +3108,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -3213,7 +3133,7 @@ namespace Google.Protobuf.Reflection { int hash = 1; if (HasName) hash ^= Name.GetHashCode(); if (HasNumber) hash ^= Number.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -3235,7 +3155,7 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(16); output.WriteInt32(Number); } - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(26); output.WriteMessage(Options); } @@ -3253,7 +3173,7 @@ namespace Google.Protobuf.Reflection { if (HasNumber) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number); } - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } if (_unknownFields != null) { @@ -3273,8 +3193,8 @@ namespace Google.Protobuf.Reflection { if (other.HasNumber) { Number = other.Number; } - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.EnumValueOptions(); } Options.MergeFrom(other.Options); @@ -3299,7 +3219,7 @@ namespace Google.Protobuf.Reflection { break; } case 26: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.EnumValueOptions(); } input.ReadMessage(Options); @@ -3341,7 +3261,7 @@ namespace Google.Protobuf.Reflection { public ServiceDescriptorProto(ServiceDescriptorProto other) : this() { name_ = other.name_; method_ = other.method_.Clone(); - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -3393,16 +3313,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { @@ -3428,7 +3338,7 @@ namespace Google.Protobuf.Reflection { int hash = 1; if (HasName) hash ^= Name.GetHashCode(); hash ^= method_.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -3447,7 +3357,7 @@ namespace Google.Protobuf.Reflection { output.WriteString(Name); } method_.WriteTo(output, _repeated_method_codec); - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(26); output.WriteMessage(Options); } @@ -3463,7 +3373,7 @@ namespace Google.Protobuf.Reflection { size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); } size += method_.CalculateSize(_repeated_method_codec); - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } if (_unknownFields != null) { @@ -3481,8 +3391,8 @@ namespace Google.Protobuf.Reflection { Name = other.Name; } method_.Add(other.method_); - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.ServiceOptions(); } Options.MergeFrom(other.Options); @@ -3507,7 +3417,7 @@ namespace Google.Protobuf.Reflection { break; } case 26: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.ServiceOptions(); } input.ReadMessage(Options); @@ -3552,7 +3462,7 @@ namespace Google.Protobuf.Reflection { name_ = other.name_; inputType_ = other.inputType_; outputType_ = other.outputType_; - options_ = other.HasOptions ? other.options_.Clone() : null; + options_ = other.options_ != null ? other.options_.Clone() : null; clientStreaming_ = other.clientStreaming_; serverStreaming_ = other.serverStreaming_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -3646,16 +3556,6 @@ namespace Google.Protobuf.Reflection { options_ = value; } } - /// Gets whether the options field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool HasOptions { - get { return options_ != null; } - } - /// Clears the value of the options field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void ClearOptions() { - options_ = null; - } /// Field number for the "client_streaming" field. public const int ClientStreamingFieldNumber = 5; @@ -3739,7 +3639,7 @@ namespace Google.Protobuf.Reflection { if (HasName) hash ^= Name.GetHashCode(); if (HasInputType) hash ^= InputType.GetHashCode(); if (HasOutputType) hash ^= OutputType.GetHashCode(); - if (HasOptions) hash ^= Options.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); if (HasClientStreaming) hash ^= ClientStreaming.GetHashCode(); if (HasServerStreaming) hash ^= ServerStreaming.GetHashCode(); if (_unknownFields != null) { @@ -3767,7 +3667,7 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(26); output.WriteString(OutputType); } - if (HasOptions) { + if (options_ != null) { output.WriteRawTag(34); output.WriteMessage(Options); } @@ -3796,7 +3696,7 @@ namespace Google.Protobuf.Reflection { if (HasOutputType) { size += 1 + pb::CodedOutputStream.ComputeStringSize(OutputType); } - if (HasOptions) { + if (options_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); } if (HasClientStreaming) { @@ -3825,8 +3725,8 @@ namespace Google.Protobuf.Reflection { if (other.HasOutputType) { OutputType = other.OutputType; } - if (other.HasOptions) { - if (!HasOptions) { + if (other.options_ != null) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.MethodOptions(); } Options.MergeFrom(other.Options); @@ -3861,7 +3761,7 @@ namespace Google.Protobuf.Reflection { break; } case 34: { - if (!HasOptions) { + if (options_ == null) { Options = new global::Google.Protobuf.Reflection.MethodOptions(); } input.ReadMessage(Options); From 807ea2f3527780dc14a9aadb661ca253f3fa5644 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 27 Apr 2020 07:20:53 +0100 Subject: [PATCH 08/26] Fix to C# support library code (This was the only use of a HasXyz property for a message type.) --- csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 69bab4f010..4d87bd7561 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -394,7 +394,7 @@ namespace Google.Protobuf.Reflection File.DescriptorPool.AddFieldByNumber(this); - if (ContainingType != null && ContainingType.Proto.HasOptions && ContainingType.Proto.Options.MessageSetWireFormat) + if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat) { throw new DescriptorValidationException(this, "MessageSet format is not supported."); } From fc5ded36bc53d3f4657260a685e0b07eff9fe7ff Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 11 May 2020 09:40:51 +0200 Subject: [PATCH 09/26] Merge pull request #7434 from jtattermusch/csharp_expose_options C#: Get rid of broken GetOption API and expose the "GetOptions()" method on descriptors instead --- .../Reflection/CustomOptionsTest.cs | 150 ++++++++++-------- .../Reflection/EnumDescriptor.cs | 12 +- .../Reflection/EnumValueDescriptor.cs | 12 +- .../Reflection/FieldDescriptor.cs | 12 +- .../Reflection/FileDescriptor.cs | 12 +- .../Reflection/MessageDescriptor.cs | 12 +- .../Reflection/MethodDescriptor.cs | 12 +- .../Reflection/OneofDescriptor.cs | 12 +- .../Reflection/ServiceDescriptor.cs | 12 +- 9 files changed, 176 insertions(+), 70 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index bfee5f5d43..d066baec93 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -71,25 +71,49 @@ namespace Google.Protobuf.Test.Reflection }; } + [Test] + public void BuiltinOptionsCanBeRetrieved() + { + // non-custom options (that are not extensions but regular fields) can only be accessed via descriptor.Options + var fileOptions = UnittestProto3Reflection.Descriptor.GetOptions(); + Assert.AreEqual("Google.Protobuf.TestProtos", fileOptions.CsharpNamespace); + } + + [Test] + public void OptionPresenceCanBeDetected() + { + // case 1: the descriptor has no options at all so the options message is not present + Assert.IsNull(TestAllTypes.Descriptor.GetOptions()); + + // case 2: the descriptor has some options, but not the one we're looking for + // HasExtension will be false and GetExtension returns extension's default value + Assert.IsFalse(UnittestProto3Reflection.Descriptor.GetOptions().HasExtension(FileOpt1)); + Assert.AreEqual(0, UnittestProto3Reflection.Descriptor.GetOptions().GetExtension(FileOpt1)); + + // case 3: option is present + Assert.IsTrue(UnittestCustomOptionsProto3Reflection.Descriptor.GetOptions().HasExtension(FileOpt1)); + Assert.AreEqual(9876543210UL, UnittestCustomOptionsProto3Reflection.Descriptor.GetOptions().GetExtension(FileOpt1)); + } + [Test] public void ScalarOptions() { var d = CustomOptionOtherValues.Descriptor; - var options = d.CustomOptions; - AssertOption(-100, options.TryGetInt32, Int32Opt, d.GetOption); - AssertOption(12.3456789f, options.TryGetFloat, FloatOpt, d.GetOption); - AssertOption(1.234567890123456789d, options.TryGetDouble, DoubleOpt, d.GetOption); - AssertOption("Hello, \"World\"", options.TryGetString, StringOpt, d.GetOption); - AssertOption(ByteString.CopyFromUtf8("Hello\0World"), options.TryGetBytes, BytesOpt, d.GetOption); - AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(options), EnumOpt, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(-100, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(12.3456789f, customOptions.TryGetFloat, FloatOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(1.234567890123456789d, customOptions.TryGetDouble, DoubleOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption("Hello, \"World\"", customOptions.TryGetString, StringOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ByteString.CopyFromUtf8("Hello\0World"), customOptions.TryGetBytes, BytesOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(customOptions), EnumOpt, d.GetOption, d.GetOptions().GetExtension); } [Test] public void MessageOptions() { var d = VariousComplexOptions.Descriptor; - var options = d.CustomOptions; - AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, options.TryGetMessage, ComplexOpt1, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, customOptions.TryGetMessage, ComplexOpt1, d.GetOption, d.GetOptions().GetExtension); AssertOption(new ComplexOptionType2 { Baz = 987, @@ -97,85 +121,84 @@ namespace Google.Protobuf.Test.Reflection Fred = new ComplexOptionType4 { Waldo = 321 }, Barney = { new ComplexOptionType4 { Waldo = 101 }, new ComplexOptionType4 { Waldo = 212 } } }, - options.TryGetMessage, ComplexOpt2, d.GetOption); - AssertOption(new ComplexOptionType3 { Qux = 9 }, options.TryGetMessage, ComplexOpt3, d.GetOption); + customOptions.TryGetMessage, ComplexOpt2, d.GetOption, d.GetOptions().GetExtension); + AssertOption(new ComplexOptionType3 { Qux = 9 }, customOptions.TryGetMessage, ComplexOpt3, d.GetOption, d.GetOptions().GetExtension); } [Test] public void OptionLocations() { - var fileOptions = UnittestCustomOptionsProto3Reflection.Descriptor.CustomOptions; - AssertOption(9876543210UL, fileOptions.TryGetUInt64, FileOpt1, UnittestCustomOptionsProto3Reflection.Descriptor.GetOption); + var fileDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor; + AssertOption(9876543210UL, fileDescriptor.CustomOptions.TryGetUInt64, FileOpt1, fileDescriptor.GetOption, fileDescriptor.GetOptions().GetExtension); - var messageOptions = TestMessageWithCustomOptions.Descriptor.CustomOptions; - AssertOption(-56, messageOptions.TryGetInt32, MessageOpt1, TestMessageWithCustomOptions.Descriptor.GetOption); + var messageDescriptor = TestMessageWithCustomOptions.Descriptor; + AssertOption(-56, messageDescriptor.CustomOptions.TryGetInt32, MessageOpt1, messageDescriptor.GetOption, messageDescriptor.GetOptions().GetExtension); - var fieldOptions = TestMessageWithCustomOptions.Descriptor.Fields["field1"].CustomOptions; - AssertOption(8765432109UL, fieldOptions.TryGetFixed64, FieldOpt1, TestMessageWithCustomOptions.Descriptor.Fields["field1"].GetOption); + var fieldDescriptor = TestMessageWithCustomOptions.Descriptor.Fields["field1"]; + AssertOption(8765432109UL, fieldDescriptor.CustomOptions.TryGetFixed64, FieldOpt1, fieldDescriptor.GetOption, fieldDescriptor.GetOptions().GetExtension); - var oneofOptions = TestMessageWithCustomOptions.Descriptor.Oneofs[0].CustomOptions; - AssertOption(-99, oneofOptions.TryGetInt32, OneofOpt1, TestMessageWithCustomOptions.Descriptor.Oneofs[0].GetOption); + var oneofDescriptor = TestMessageWithCustomOptions.Descriptor.Oneofs[0]; + AssertOption(-99, oneofDescriptor.CustomOptions.TryGetInt32, OneofOpt1, oneofDescriptor.GetOption, oneofDescriptor.GetOptions().GetExtension); - var enumOptions = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].CustomOptions; - AssertOption(-789, enumOptions.TryGetSFixed32, EnumOpt1, TestMessageWithCustomOptions.Descriptor.EnumTypes[0].GetOption); + var enumDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0]; + AssertOption(-789, enumDescriptor.CustomOptions.TryGetSFixed32, EnumOpt1, enumDescriptor.GetOption, enumDescriptor.GetOptions().GetExtension); - var enumValueOptions = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2).CustomOptions; - AssertOption(123, enumValueOptions.TryGetInt32, EnumValueOpt1, TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2).GetOption); + var enumValueDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2); + AssertOption(123, enumValueDescriptor.CustomOptions.TryGetInt32, EnumValueOpt1, enumValueDescriptor.GetOption, enumValueDescriptor.GetOptions().GetExtension); - var service = UnittestCustomOptionsProto3Reflection.Descriptor.Services + var serviceDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor.Services .Single(s => s.Name == "TestServiceWithCustomOptions"); - var serviceOptions = service.CustomOptions; - AssertOption(-9876543210, serviceOptions.TryGetSInt64, ServiceOpt1, service.GetOption); + AssertOption(-9876543210, serviceDescriptor.CustomOptions.TryGetSInt64, ServiceOpt1, serviceDescriptor.GetOption, serviceDescriptor.GetOptions().GetExtension); - var methodOptions = service.Methods[0].CustomOptions; - AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, service.Methods[0].GetOption); + var methodDescriptor = serviceDescriptor.Methods[0]; + AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodDescriptor.CustomOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, methodDescriptor.GetOption, methodDescriptor.GetOptions().GetExtension); } [Test] public void MinValues() { var d = CustomOptionMinIntegerValues.Descriptor; - var options = d.CustomOptions; - AssertOption(false, options.TryGetBool, BoolOpt, d.GetOption); - AssertOption(int.MinValue, options.TryGetInt32, Int32Opt, d.GetOption); - AssertOption(long.MinValue, options.TryGetInt64, Int64Opt, d.GetOption); - AssertOption(uint.MinValue, options.TryGetUInt32, Uint32Opt, d.GetOption); - AssertOption(ulong.MinValue, options.TryGetUInt64, Uint64Opt, d.GetOption); - AssertOption(int.MinValue, options.TryGetSInt32, Sint32Opt, d.GetOption); - AssertOption(long.MinValue, options.TryGetSInt64, Sint64Opt, d.GetOption); - AssertOption(uint.MinValue, options.TryGetUInt32, Fixed32Opt, d.GetOption); - AssertOption(ulong.MinValue, options.TryGetUInt64, Fixed64Opt, d.GetOption); - AssertOption(int.MinValue, options.TryGetInt32, Sfixed32Opt, d.GetOption); - AssertOption(long.MinValue, options.TryGetInt64, Sfixed64Opt, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(false, customOptions.TryGetBool, BoolOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MinValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MinValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Fixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Fixed64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Sfixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Sfixed64Opt, d.GetOption, d.GetOptions().GetExtension); } [Test] public void MaxValues() { var d = CustomOptionMaxIntegerValues.Descriptor; - var options = d.CustomOptions; - AssertOption(true, options.TryGetBool, BoolOpt, d.GetOption); - AssertOption(int.MaxValue, options.TryGetInt32, Int32Opt, d.GetOption); - AssertOption(long.MaxValue, options.TryGetInt64, Int64Opt, d.GetOption); - AssertOption(uint.MaxValue, options.TryGetUInt32, Uint32Opt, d.GetOption); - AssertOption(ulong.MaxValue, options.TryGetUInt64, Uint64Opt, d.GetOption); - AssertOption(int.MaxValue, options.TryGetSInt32, Sint32Opt, d.GetOption); - AssertOption(long.MaxValue, options.TryGetSInt64, Sint64Opt, d.GetOption); - AssertOption(uint.MaxValue, options.TryGetFixed32, Fixed32Opt, d.GetOption); - AssertOption(ulong.MaxValue, options.TryGetFixed64, Fixed64Opt, d.GetOption); - AssertOption(int.MaxValue, options.TryGetSFixed32, Sfixed32Opt, d.GetOption); - AssertOption(long.MaxValue, options.TryGetSFixed64, Sfixed64Opt, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(true, customOptions.TryGetBool, BoolOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetFixed32, Fixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetFixed64, Fixed64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSFixed32, Sfixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSFixed64, Sfixed64Opt, d.GetOption, d.GetOptions().GetExtension); } [Test] public void AggregateOptions() { // Just two examples - var messageOptions = AggregateMessage.Descriptor.CustomOptions; - AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageOptions.TryGetMessage, Msgopt, AggregateMessage.Descriptor.GetOption); + var messageDescriptor = AggregateMessage.Descriptor; + AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageDescriptor.CustomOptions.TryGetMessage, Msgopt, messageDescriptor.GetOption, messageDescriptor.GetOptions().GetExtension); - var fieldOptions = AggregateMessage.Descriptor.Fields["fieldname"].CustomOptions; - AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldOptions.TryGetMessage, Fieldopt, AggregateMessage.Descriptor.Fields["fieldname"].GetOption); + var fieldDescriptor = messageDescriptor.Fields["fieldname"]; + AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldDescriptor.CustomOptions.TryGetMessage, Fieldopt, fieldDescriptor.GetOption, fieldDescriptor.GetOptions().GetExtension); } [Test] @@ -199,16 +222,19 @@ namespace Google.Protobuf.Test.Reflection var descriptor = UnittestIssue6936CReflection.Descriptor; var foo = Foo.Descriptor; var bar = Bar.Descriptor; - AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.GetOption); - AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.GetOption); + AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.GetOption, foo.GetOptions().GetExtension); + AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.GetOption, bar.GetOptions().GetExtension); } - private void AssertOption(T expected, OptionFetcher fetcher, Extension extension, Func, T> descriptorOptionFetcher) where D : IExtendableMessage + private void AssertOption(T expected, OptionFetcher customOptionFetcher, Extension extension, Func, T> getOptionFetcher, Func, T> extensionFetcher) where D : IExtendableMessage { - T customOptionsValue; - T extensionValue = descriptorOptionFetcher(extension); - Assert.IsTrue(fetcher(extension.FieldNumber, out customOptionsValue)); + Assert.IsTrue(customOptionFetcher(extension.FieldNumber, out T customOptionsValue)); Assert.AreEqual(expected, customOptionsValue); + + T getOptionValue = getOptionFetcher(extension); + Assert.AreEqual(expected, getOptionValue); + + T extensionValue = extensionFetcher(extension); Assert.AreEqual(expected, extensionValue); } } diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index 264a88a063..f7e8b5b5f2 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -128,12 +128,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this enum. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// The EnumOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public EnumOptions GetOptions() => Proto.Options?.Clone(); + /// /// Gets a single value enum option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -143,6 +152,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value enum option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs index 3933820105..05097bd1da 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -73,12 +73,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this enum value. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// The EnumValueOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public EnumValueOptions GetOptions() => Proto.Options?.Clone(); + /// /// Gets a single value enum value option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -88,6 +97,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value enum value option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 4d87bd7561..3f50fdb3bd 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -304,12 +304,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this field. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// The FieldOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public FieldOptions GetOptions() => Proto.Options?.Clone(); + /// /// Gets a single value field option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -319,6 +328,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value field option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 56c0caacfd..88e4a9de96 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -547,12 +547,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this file. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// The FileOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public FileOptions GetOptions() => Proto.Options?.Clone(); + /// /// Gets a single value file option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -562,6 +571,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value file option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index 6217081fbc..7b5ab2fb48 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -287,12 +287,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this message. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// The MessageOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public MessageOptions GetOptions() => Proto.Options?.Clone(); + /// /// Gets a single value message option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -302,6 +311,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value message option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public Collections.RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs index 92250ba662..8e1503767b 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -73,12 +73,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this method. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// The MethodOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public MethodOptions GetOptions() => Proto.Options?.Clone(); + /// /// Gets a single value method option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -88,6 +97,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value method option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs index 7cceabd7c3..0df4f534b2 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -117,12 +117,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this oneof. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions method.")] public CustomOptions CustomOptions => new CustomOptions(proto.Options?._extensions?.ValuesByNumber); + /// + /// The OneofOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public OneofOptions GetOptions() => proto.Options?.Clone(); + /// /// Gets a single value oneof option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = proto.Options.GetExtension(extension); @@ -132,6 +141,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value oneof option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index 21417ec641..dab348b6f8 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -94,12 +94,21 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this service. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// The ServiceOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public ServiceOptions GetOptions() => Proto.Options?.Clone(); + /// /// Gets a single value service option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -109,6 +118,7 @@ namespace Google.Protobuf.Reflection /// /// Gets a repeated value service option for this descriptor /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); From 3c3646fa7821f4b22822e173bbc36620fd80ac11 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 5 May 2020 06:53:00 +0100 Subject: [PATCH 10/26] Implement HasPresence for C# FieldDescriptor.HasPresence returns true if both ClearValue and HasValue (on the accessor) can be expected to work. Some fields have a working ClearValue, but no HasValue; HasPresence returns false for those fields. Generally: - Extension fields have presence if and only if they're singular - Repeated fields do not support presence - Map fields do not support presence - Message fields support presence - Oneof fields support presence (this includes synthetic oneof fields, so that covers proto3 optional singular fields) - Proto2 singular primitive fields support presence - Proto3 singular primitive fields do not support presence (unless they're in a oneof, covered above) --- .../Reflection/FieldAccessTest.cs | 171 ++++++++++++++++-- csharp/src/Google.Protobuf/Extension.cs | 6 + .../Reflection/FieldDescriptor.cs | 15 ++ .../Reflection/SingleFieldAccessor.cs | 93 +++++----- 4 files changed, 221 insertions(+), 64 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs index 0d4034c5b1..b4dcdabdc7 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs @@ -98,7 +98,48 @@ namespace Google.Protobuf.Reflection } [Test] - public void HasValue_Proto3() + public void HasValue_Proto3_Message() + { + var message = new TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[TestProtos.TestAllTypes.SingleForeignMessageFieldNumber].Accessor; + Assert.False(accessor.HasValue(message)); + message.SingleForeignMessage = new ForeignMessage(); + Assert.True(accessor.HasValue(message)); + message.SingleForeignMessage = null; + Assert.False(accessor.HasValue(message)); + } + + [Test] + public void HasValue_Proto3_Oneof() + { + TestAllTypes message = new TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[TestProtos.TestAllTypes.OneofStringFieldNumber].Accessor; + Assert.False(accessor.HasValue(message)); + // Even though it's the default value, we still have a value. + message.OneofString = ""; + Assert.True(accessor.HasValue(message)); + message.OneofString = "hello"; + Assert.True(accessor.HasValue(message)); + message.OneofUint32 = 10; + Assert.False(accessor.HasValue(message)); + } + + [Test] + public void HasValue_Proto3_Primitive_Optional() + { + var message = new TestProto3Optional(); + var accessor = ((IMessage) message).Descriptor.Fields[TestProto3Optional.OptionalInt64FieldNumber].Accessor; + Assert.IsFalse(accessor.HasValue(message)); + message.OptionalInt64 = 5L; + Assert.IsTrue(accessor.HasValue(message)); + message.ClearOptionalInt64(); + Assert.IsFalse(accessor.HasValue(message)); + message.OptionalInt64 = 0L; + Assert.IsTrue(accessor.HasValue(message)); + } + + [Test] + public void HasValue_Proto3_Primitive_NotOptional() { IMessage message = SampleMessages.CreateFullTestAllTypes(); var fields = message.Descriptor.Fields; @@ -106,36 +147,63 @@ namespace Google.Protobuf.Reflection } [Test] - public void HasValue_Proto3Optional() + public void HasValue_Proto3_Repeated() { - IMessage message = new TestProto3Optional - { - OptionalInt32 = 0, - LazyNestedMessage = new TestProto3Optional.Types.NestedMessage() - }; - var fields = message.Descriptor.Fields; - Assert.IsFalse(fields[TestProto3Optional.OptionalInt64FieldNumber].Accessor.HasValue(message)); - Assert.IsFalse(fields[TestProto3Optional.OptionalNestedMessageFieldNumber].Accessor.HasValue(message)); - Assert.IsTrue(fields[TestProto3Optional.LazyNestedMessageFieldNumber].Accessor.HasValue(message)); - Assert.IsTrue(fields[TestProto3Optional.OptionalInt32FieldNumber].Accessor.HasValue(message)); + var message = new TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[TestProtos.TestAllTypes.RepeatedBoolFieldNumber].Accessor; + Assert.Throws(() => accessor.HasValue(message)); } [Test] - public void HasValue() + public void HasValue_Proto2_Primitive() { - IMessage message = new Proto2.TestAllTypes(); - var fields = message.Descriptor.Fields; - var accessor = fields[Proto2.TestAllTypes.OptionalBoolFieldNumber].Accessor; + var message = new Proto2.TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[Proto2.TestAllTypes.OptionalInt64FieldNumber].Accessor; + + Assert.IsFalse(accessor.HasValue(message)); + message.OptionalInt64 = 5L; + Assert.IsTrue(accessor.HasValue(message)); + message.ClearOptionalInt64(); + Assert.IsFalse(accessor.HasValue(message)); + message.OptionalInt64 = 0L; + Assert.IsTrue(accessor.HasValue(message)); + } - Assert.False(accessor.HasValue(message)); + [Test] + public void HasValue_Proto2_Message() + { + var message = new Proto2.TestAllTypes(); + var field = ((IMessage) message).Descriptor.Fields[Proto2.TestAllTypes.OptionalForeignMessageFieldNumber]; + Assert.False(field.Accessor.HasValue(message)); + message.OptionalForeignMessage = new Proto2.ForeignMessage(); + Assert.True(field.Accessor.HasValue(message)); + message.OptionalForeignMessage = null; + Assert.False(field.Accessor.HasValue(message)); + } - accessor.SetValue(message, true); + [Test] + public void HasValue_Proto2_Oneof() + { + var message = new Proto2.TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[Proto2.TestAllTypes.OneofStringFieldNumber].Accessor; + Assert.False(accessor.HasValue(message)); + // Even though it's the default value, we still have a value. + message.OneofString = ""; Assert.True(accessor.HasValue(message)); - - accessor.Clear(message); + message.OneofString = "hello"; + Assert.True(accessor.HasValue(message)); + message.OneofUint32 = 10; Assert.False(accessor.HasValue(message)); } + [Test] + public void HasValue_Proto2_Repeated() + { + var message = new Proto2.TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[Proto2.TestAllTypes.RepeatedBoolFieldNumber].Accessor; + Assert.Throws(() => accessor.HasValue(message)); + } + [Test] public void SetValue_SingleFields() { @@ -262,6 +330,42 @@ namespace Google.Protobuf.Reflection Assert.Null(message.OptionalNestedMessage); } + [Test] + public void Clear_Proto3_Oneof() + { + var message = new TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[TestProtos.TestAllTypes.OneofUint32FieldNumber].Accessor; + + // The field accessor Clear method only affects a oneof if the current case is the one being cleared. + message.OneofString = "hello"; + Assert.AreEqual(TestProtos.TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase); + accessor.Clear(message); + Assert.AreEqual(TestProtos.TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase); + + message.OneofUint32 = 100; + Assert.AreEqual(TestProtos.TestAllTypes.OneofFieldOneofCase.OneofUint32, message.OneofFieldCase); + accessor.Clear(message); + Assert.AreEqual(TestProtos.TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); + } + + [Test] + public void Clear_Proto2_Oneof() + { + var message = new Proto2.TestAllTypes(); + var accessor = ((IMessage) message).Descriptor.Fields[Proto2.TestAllTypes.OneofUint32FieldNumber].Accessor; + + // The field accessor Clear method only affects a oneof if the current case is the one being cleared. + message.OneofString = "hello"; + Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase); + accessor.Clear(message); + Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase); + + message.OneofUint32 = 100; + Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.OneofUint32, message.OneofFieldCase); + accessor.Clear(message); + Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); + } + [Test] public void FieldDescriptor_ByName() { @@ -301,5 +405,32 @@ namespace Google.Protobuf.Reflection message.ClearExtension(RepeatedBoolExtension); Assert.IsNull(message.GetExtension(RepeatedBoolExtension)); } + + [Test] + public void HasPresence() + { + // Proto3 + var fields = TestProtos.TestAllTypes.Descriptor.Fields; + Assert.IsFalse(fields[TestProtos.TestAllTypes.SingleBoolFieldNumber].HasPresence); + Assert.IsTrue(fields[TestProtos.TestAllTypes.OneofBytesFieldNumber].HasPresence); + Assert.IsTrue(fields[TestProtos.TestAllTypes.SingleForeignMessageFieldNumber].HasPresence); + Assert.IsFalse(fields[TestProtos.TestAllTypes.RepeatedBoolFieldNumber].HasPresence); + + fields = TestMap.Descriptor.Fields; + Assert.IsFalse(fields[TestMap.MapBoolBoolFieldNumber].HasPresence); + + fields = TestProto3Optional.Descriptor.Fields; + Assert.IsTrue(fields[TestProto3Optional.OptionalBoolFieldNumber].HasPresence); + + // Proto2 + fields = Proto2.TestAllTypes.Descriptor.Fields; + Assert.IsTrue(fields[Proto2.TestAllTypes.OptionalBoolFieldNumber].HasPresence); + Assert.IsTrue(fields[Proto2.TestAllTypes.OneofBytesFieldNumber].HasPresence); + Assert.IsTrue(fields[Proto2.TestAllTypes.OptionalForeignMessageFieldNumber].HasPresence); + Assert.IsFalse(fields[Proto2.TestAllTypes.RepeatedBoolFieldNumber].HasPresence); + + fields = Proto2.TestRequired.Descriptor.Fields; + Assert.IsTrue(fields[Proto2.TestRequired.AFieldNumber].HasPresence); + } } } diff --git a/csharp/src/Google.Protobuf/Extension.cs b/csharp/src/Google.Protobuf/Extension.cs index a96f8d29b6..6dd1ceaa8e 100644 --- a/csharp/src/Google.Protobuf/Extension.cs +++ b/csharp/src/Google.Protobuf/Extension.cs @@ -55,6 +55,8 @@ namespace Google.Protobuf /// Gets the field number of this extension /// public int FieldNumber { get; } + + internal abstract bool IsRepeated { get; } } /// @@ -79,6 +81,8 @@ namespace Google.Protobuf internal override Type TargetType => typeof(TTarget); + internal override bool IsRepeated => false; + internal override IExtensionValue CreateValue() { return new ExtensionValue(codec); @@ -105,6 +109,8 @@ namespace Google.Protobuf internal override Type TargetType => typeof(TTarget); + internal override bool IsRepeated => true; + internal override IExtensionValue CreateValue() { return new RepeatedExtensionValue(codec); diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 3f50fdb3bd..7324e3dfc6 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -70,6 +70,21 @@ namespace Google.Protobuf.Reflection /// public string JsonName { get; } + /// + /// Indicates whether this field supports presence, either implicitly (e.g. due to it being a message + /// type field) or explicitly via Has/Clear members. If this returns true, it is safe to call + /// and + /// on this field's accessor with a suitable message. + /// + public bool HasPresence => + Extension != null ? !Extension.IsRepeated + : IsRepeated ? false + : IsMap ? false + : FieldType == FieldType.Message ? true + // This covers "real oneof members" and "proto3 optional fields" + : ContainingOneof != null ? true + : File.Syntax == Syntax.Proto2; + internal FieldDescriptorProto Proto { get; } /// diff --git a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs index ed844bc51d..07d84d7fb9 100644 --- a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs +++ b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs @@ -57,63 +57,68 @@ namespace Google.Protobuf.Reflection throw new ArgumentException("Not all required properties/methods available"); } setValueDelegate = ReflectionUtil.CreateActionIMessageObject(property.GetSetMethod()); - if (descriptor.File.Syntax == Syntax.Proto3 && !descriptor.Proto.Proto3Optional) + + // Note: this looks worrying in that we access the containing oneof, which isn't valid until cross-linking + // is complete... but field accessors aren't created until after cross-linking. + // The oneof itself won't be cross-linked yet, but that's okay: the oneof accessor is created + // earlier. + + // Message fields always support presence, via null checks. + if (descriptor.FieldType == FieldType.Message) + { + hasDelegate = message => GetValue(message) != null; + clearDelegate = message => SetValue(message, null); + } + // Oneof fields always support presence, via case checks. + // Note that clearing the field is a no-op unless that specific field is the current "case". + else if (descriptor.RealContainingOneof != null) { - hasDelegate = message => + var oneofAccessor = descriptor.RealContainingOneof.Accessor; + hasDelegate = message => oneofAccessor.GetCaseFieldDescriptor(message) == descriptor; + clearDelegate = message => { - throw new InvalidOperationException("HasValue is not implemented for non-optional proto3 fields"); + // Clear on a field only affects the oneof itself if the current case is the field we're accessing. + if (oneofAccessor.GetCaseFieldDescriptor(message) == descriptor) + { + oneofAccessor.Clear(message); + } }; - var clrType = property.PropertyType; - - // TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.) - object defaultValue = - descriptor.FieldType == FieldType.Message ? null - : clrType == typeof(string) ? "" - : clrType == typeof(ByteString) ? ByteString.Empty - : Activator.CreateInstance(clrType); - clearDelegate = message => SetValue(message, defaultValue); } - else + // Primitive fields always support presence in proto2, and support presence in proto3 for optional fields. + else if (descriptor.File.Syntax == Syntax.Proto2 || descriptor.Proto.Proto3Optional) { - // For message fields, just compare with null and set to null. - // For primitive fields, use the Has/Clear methods. - - if (descriptor.FieldType == FieldType.Message) + MethodInfo hasMethod = property.DeclaringType.GetRuntimeProperty("Has" + property.Name).GetMethod; + if (hasMethod == null) { - hasDelegate = message => GetValue(message) != null; - clearDelegate = message => SetValue(message, null); + throw new ArgumentException("Not all required properties/methods are available"); } - else + hasDelegate = ReflectionUtil.CreateFuncIMessageBool(hasMethod); + MethodInfo clearMethod = property.DeclaringType.GetRuntimeMethod("Clear" + property.Name, ReflectionUtil.EmptyTypes); + if (clearMethod == null) { - MethodInfo hasMethod = property.DeclaringType.GetRuntimeProperty("Has" + property.Name).GetMethod; - if (hasMethod == null) - { - throw new ArgumentException("Not all required properties/methods are available"); - } - hasDelegate = ReflectionUtil.CreateFuncIMessageBool(hasMethod); - MethodInfo clearMethod = property.DeclaringType.GetRuntimeMethod("Clear" + property.Name, ReflectionUtil.EmptyTypes); - if (clearMethod == null) - { - throw new ArgumentException("Not all required properties/methods are available"); - } - clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod); + throw new ArgumentException("Not all required properties/methods are available"); } + clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod); } - } + // What's left? + // Primitive proto3 fields without the optional keyword, which aren't in oneofs. + else + { + hasDelegate = message => { throw new InvalidOperationException("Presence is not implemented for this field"); }; - public override void Clear(IMessage message) - { - clearDelegate(message); - } + // While presence isn't supported, clearing still is; it's just setting to a default value. + var clrType = property.PropertyType; - public override bool HasValue(IMessage message) - { - return hasDelegate(message); + object defaultValue = + clrType == typeof(string) ? "" + : clrType == typeof(ByteString) ? ByteString.Empty + : Activator.CreateInstance(clrType); + clearDelegate = message => SetValue(message, defaultValue); + } } - public override void SetValue(IMessage message, object value) - { - setValueDelegate(message, value); - } + public override void Clear(IMessage message) => clearDelegate(message); + public override bool HasValue(IMessage message) => hasDelegate(message); + public override void SetValue(IMessage message, object value) => setValueDelegate(message, value); } } From c0b1ce00f3bcefd0047f0bcfe117510ca678bb6e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 12 May 2020 11:06:05 -0700 Subject: [PATCH 11/26] Cherry-pick the fix for https://github.com/protocolbuffers/protobuf/issues/7463. --- src/google/protobuf/generated_message_reflection.cc | 2 +- src/google/protobuf/proto3_arena_unittest.cc | 12 +++++++++--- src/google/protobuf/unittest_proto3_optional.proto | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 6ee8c984e8..da6ba406bb 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -1061,7 +1061,7 @@ void Reflection::ListFields(const Message& message, if (oneof_case_array[containing_oneof->index()] == field->number()) { output->push_back(field); } - } else if (has_bits) { + } else if (has_bits && has_bits_indices[i] != -1) { // Equivalent to: HasBit(message, field) if (IsIndexInHasBitSet(has_bits, has_bits_indices[i])) { output->push_back(field); diff --git a/src/google/protobuf/proto3_arena_unittest.cc b/src/google/protobuf/proto3_arena_unittest.cc index 27fb58b44c..72fd8257db 100644 --- a/src/google/protobuf/proto3_arena_unittest.cc +++ b/src/google/protobuf/proto3_arena_unittest.cc @@ -217,9 +217,15 @@ TEST(Proto3OptionalTest, OptionalFieldDescriptor) { for (int i = 0; i < d->field_count(); i++) { const FieldDescriptor* f = d->field(i); - EXPECT_TRUE(f->has_optional_keyword()) << f->full_name(); - EXPECT_TRUE(f->has_presence()) << f->full_name(); - EXPECT_TRUE(f->containing_oneof()) << f->full_name(); + if (HasPrefixString(f->name(), "singular")) { + EXPECT_FALSE(f->has_optional_keyword()) << f->full_name(); + EXPECT_FALSE(f->has_presence()) << f->full_name(); + EXPECT_FALSE(f->containing_oneof()) << f->full_name(); + } else { + EXPECT_TRUE(f->has_optional_keyword()) << f->full_name(); + EXPECT_TRUE(f->has_presence()) << f->full_name(); + EXPECT_TRUE(f->containing_oneof()) << f->full_name(); + } } } diff --git a/src/google/protobuf/unittest_proto3_optional.proto b/src/google/protobuf/unittest_proto3_optional.proto index b32a5d22b7..3c47f12e28 100644 --- a/src/google/protobuf/unittest_proto3_optional.proto +++ b/src/google/protobuf/unittest_proto3_optional.proto @@ -72,4 +72,8 @@ message TestProto3Optional { optional NestedMessage optional_nested_message = 18; optional NestedMessage lazy_nested_message = 19 [lazy = true]; optional NestedEnum optional_nested_enum = 21; + + // Add some non-optional fields to verify we can mix them. + int32 singular_int32 = 22; + int64 singular_int64 = 23; } From 01e8c0fa348d38caddc25619d50d346a376172ff Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 12 May 2020 11:34:02 -0700 Subject: [PATCH 12/26] Cherry-pick the fix to #7480 from #7485. --- java/core/generate-test-sources-build.xml | 1 + .../google/protobuf/FieldPresenceTest.java | 108 ++++++++++++++++++ .../com/google/protobuf/TextFormatTest.java | 20 ++++ java/lite/generate-test-sources-build.xml | 1 + .../internal/test_proto3_optional.proto | 5 +- .../protobuf/compiler/java/java_enum_field.cc | 1 + 6 files changed, 132 insertions(+), 4 deletions(-) diff --git a/java/core/generate-test-sources-build.xml b/java/core/generate-test-sources-build.xml index 92c0b1c8ae..71a88d07b3 100644 --- a/java/core/generate-test-sources-build.xml +++ b/java/core/generate-test-sources-build.xml @@ -17,6 +17,7 @@ + diff --git a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java index 53ec6fe68c..a1c98c0cef 100644 --- a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java +++ b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java @@ -38,6 +38,7 @@ import com.google.protobuf.Descriptors.OneofDescriptor; import com.google.protobuf.FieldPresenceTestProto.TestAllTypes; import com.google.protobuf.FieldPresenceTestProto.TestOptionalFieldsOnly; import com.google.protobuf.FieldPresenceTestProto.TestRepeatedFieldsOnly; +import com.google.protobuf.testing.proto.TestProto3Optional; import protobuf_unittest.UnittestProto; import junit.framework.TestCase; @@ -101,6 +102,113 @@ public class FieldPresenceTest extends TestCase { UnittestProto.TestAllTypes.Builder.class, TestAllTypes.Builder.class, "OneofBytes"); } + public void testHasMethodForProto3Optional() throws Exception { + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalInt32()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalInt64()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalUint32()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalUint64()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalSint32()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalSint64()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalFixed32()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalFixed64()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalFloat()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalDouble()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalBool()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalString()); + assertFalse(TestProto3Optional.getDefaultInstance().hasOptionalBytes()); + + TestProto3Optional.Builder builder = TestProto3Optional.newBuilder().setOptionalInt32(0); + assertTrue(builder.hasOptionalInt32()); + assertTrue(builder.build().hasOptionalInt32()); + + TestProto3Optional.Builder otherBuilder = TestProto3Optional.newBuilder().setOptionalInt32(1); + otherBuilder.mergeFrom(builder.build()); + assertTrue(otherBuilder.hasOptionalInt32()); + assertEquals(0, otherBuilder.getOptionalInt32()); + + TestProto3Optional.Builder builder3 = + TestProto3Optional.newBuilder().setOptionalNestedEnumValue(5); + assertTrue(builder3.hasOptionalNestedEnum()); + + TestProto3Optional.Builder builder4 = + TestProto3Optional.newBuilder().setOptionalNestedEnum(TestProto3Optional.NestedEnum.FOO); + assertTrue(builder4.hasOptionalNestedEnum()); + + TestProto3Optional proto = TestProto3Optional.parseFrom(builder.build().toByteArray()); + assertTrue(proto.hasOptionalInt32()); + assertTrue(proto.toBuilder().hasOptionalInt32()); + } + + private static void assertProto3OptionalReflection(String name) throws Exception { + FieldDescriptor fieldDescriptor = TestProto3Optional.getDescriptor().findFieldByName(name); + OneofDescriptor oneofDescriptor = fieldDescriptor.getContainingOneof(); + assertNotNull(fieldDescriptor.getContainingOneof()); + assertTrue(fieldDescriptor.hasOptionalKeyword()); + assertTrue(fieldDescriptor.hasPresence()); + + assertFalse(TestProto3Optional.getDefaultInstance().hasOneof(oneofDescriptor)); + assertNull(TestProto3Optional.getDefaultInstance().getOneofFieldDescriptor(oneofDescriptor)); + + TestProto3Optional.Builder builder = TestProto3Optional.newBuilder(); + builder.setField(fieldDescriptor, fieldDescriptor.getDefaultValue()); + assertTrue(builder.hasField(fieldDescriptor)); + assertEquals(fieldDescriptor.getDefaultValue(), builder.getField(fieldDescriptor)); + assertTrue(builder.build().hasField(fieldDescriptor)); + assertEquals(fieldDescriptor.getDefaultValue(), builder.build().getField(fieldDescriptor)); + assertTrue(builder.hasOneof(oneofDescriptor)); + assertEquals(fieldDescriptor, builder.getOneofFieldDescriptor(oneofDescriptor)); + assertTrue(builder.build().hasOneof(oneofDescriptor)); + assertEquals(fieldDescriptor, builder.build().getOneofFieldDescriptor(oneofDescriptor)); + + TestProto3Optional.Builder otherBuilder = TestProto3Optional.newBuilder(); + otherBuilder.mergeFrom(builder.build()); + assertTrue(otherBuilder.hasField(fieldDescriptor)); + assertEquals(fieldDescriptor.getDefaultValue(), otherBuilder.getField(fieldDescriptor)); + + TestProto3Optional proto = TestProto3Optional.parseFrom(builder.build().toByteArray()); + assertTrue(proto.hasField(fieldDescriptor)); + assertTrue(proto.toBuilder().hasField(fieldDescriptor)); + + DynamicMessage.Builder dynamicBuilder = + DynamicMessage.newBuilder(TestProto3Optional.getDescriptor()); + dynamicBuilder.setField(fieldDescriptor, fieldDescriptor.getDefaultValue()); + assertTrue(dynamicBuilder.hasField(fieldDescriptor)); + assertEquals(fieldDescriptor.getDefaultValue(), dynamicBuilder.getField(fieldDescriptor)); + assertTrue(dynamicBuilder.build().hasField(fieldDescriptor)); + assertEquals( + fieldDescriptor.getDefaultValue(), dynamicBuilder.build().getField(fieldDescriptor)); + assertTrue(dynamicBuilder.hasOneof(oneofDescriptor)); + assertEquals(fieldDescriptor, dynamicBuilder.getOneofFieldDescriptor(oneofDescriptor)); + assertTrue(dynamicBuilder.build().hasOneof(oneofDescriptor)); + assertEquals(fieldDescriptor, dynamicBuilder.build().getOneofFieldDescriptor(oneofDescriptor)); + + DynamicMessage.Builder otherDynamicBuilder = + DynamicMessage.newBuilder(TestProto3Optional.getDescriptor()); + otherDynamicBuilder.mergeFrom(dynamicBuilder.build()); + assertTrue(otherDynamicBuilder.hasField(fieldDescriptor)); + assertEquals(fieldDescriptor.getDefaultValue(), otherDynamicBuilder.getField(fieldDescriptor)); + + DynamicMessage dynamicProto = + DynamicMessage.parseFrom(TestProto3Optional.getDescriptor(), builder.build().toByteArray()); + assertTrue(dynamicProto.hasField(fieldDescriptor)); + assertTrue(dynamicProto.toBuilder().hasField(fieldDescriptor)); + } + + public void testProto3Optional_reflection() throws Exception { + assertProto3OptionalReflection("optional_int32"); + assertProto3OptionalReflection("optional_int64"); + assertProto3OptionalReflection("optional_uint32"); + assertProto3OptionalReflection("optional_uint64"); + assertProto3OptionalReflection("optional_sint32"); + assertProto3OptionalReflection("optional_sint64"); + assertProto3OptionalReflection("optional_fixed32"); + assertProto3OptionalReflection("optional_fixed64"); + assertProto3OptionalReflection("optional_float"); + assertProto3OptionalReflection("optional_double"); + assertProto3OptionalReflection("optional_bool"); + assertProto3OptionalReflection("optional_string"); + assertProto3OptionalReflection("optional_bytes"); + } public void testOneofEquals() throws Exception { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 50ba0168da..6ca3ae111f 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -40,6 +40,8 @@ import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.TextFormat.Parser.SingularOverwritePolicy; +import com.google.protobuf.testing.proto.TestProto3Optional; +import com.google.protobuf.testing.proto.TestProto3Optional.NestedEnum; import any_test.AnyTestProto.TestAny; import map_test.MapTestProto.TestMap; import protobuf_unittest.UnittestMset.TestMessageSetExtension1; @@ -319,6 +321,24 @@ public class TextFormatTest extends TestCase { assertEquals(canonicalExoticText, message.toString()); } + public void testRoundtripProto3Optional() throws Exception { + Message message = + TestProto3Optional.newBuilder() + .setOptionalInt32(1) + .setOptionalInt64(2) + .setOptionalNestedEnum(NestedEnum.BAZ) + .build(); + TestProto3Optional.Builder message2 = TestProto3Optional.newBuilder(); + TextFormat.merge(message.toString(), message2); + + assertTrue(message2.hasOptionalInt32()); + assertTrue(message2.hasOptionalInt64()); + assertTrue(message2.hasOptionalNestedEnum()); + assertEquals(1, message2.getOptionalInt32()); + assertEquals(2, message2.getOptionalInt64()); + assertEquals(NestedEnum.BAZ, message2.getOptionalNestedEnum()); + } + public void testPrintMessageSet() throws Exception { TestMessageSet messageSet = TestMessageSet.newBuilder() diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml index 1c1a18c544..62bca93c86 100644 --- a/java/lite/generate-test-sources-build.xml +++ b/java/lite/generate-test-sources-build.xml @@ -15,6 +15,7 @@ + diff --git a/python/google/protobuf/internal/test_proto3_optional.proto b/python/google/protobuf/internal/test_proto3_optional.proto index a5abd19d13..f3e0a2e761 100644 --- a/python/google/protobuf/internal/test_proto3_optional.proto +++ b/python/google/protobuf/internal/test_proto3_optional.proto @@ -30,10 +30,7 @@ syntax = "proto3"; -package protobuf_unittest; - -option java_multiple_files = true; -option java_package = "com.google.protobuf.testing.proto"; +package google.protobuf.python.internal; message TestProto3Optional { message NestedMessage { diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc index 6322ee566e..32cff15fec 100644 --- a/src/google/protobuf/compiler/java/java_enum_field.cc +++ b/src/google/protobuf/compiler/java/java_enum_field.cc @@ -225,6 +225,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$Value$}$(int value) {\n" + " $set_has_field_bit_builder$\n" " $name$_ = value;\n" " $on_changed$\n" " return this;\n" From f597a246275b69f6dbb477456d0fa401a5546438 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 12 May 2020 12:49:46 -0700 Subject: [PATCH 13/26] Update protobuf version --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../UnittestProto3Optional.cs | 92 +++++++++++++++--- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 334214 -> 334461 bytes .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 20 +++- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- 18 files changed, 108 insertions(+), 34 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 4b53cb9ff7..f6536fd095 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.12.0-rc1' + s.version = '3.12.0-rc2' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index ae98d556d7..5fe982a7f7 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.12.0-rc1' + s.version = '3.12.0-rc2' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 881c028d21..b94fe1006a 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.12.0-rc-1],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.12.0-rc-2],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index f20ecb807b..e2a46ce4fe 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.12.0-rc1 + 3.12.0-rc2 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs index cbad5899e5..14a50a2cda 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs @@ -25,7 +25,7 @@ namespace ProtobufUnittest { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "Ci5nb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfcHJvdG8zX29wdGlvbmFsLnBy", - "b3RvEhFwcm90b2J1Zl91bml0dGVzdCKBCgoSVGVzdFByb3RvM09wdGlvbmFs", + "b3RvEhFwcm90b2J1Zl91bml0dGVzdCKxCgoSVGVzdFByb3RvM09wdGlvbmFs", "EhsKDm9wdGlvbmFsX2ludDMyGAEgASgFSACIAQESGwoOb3B0aW9uYWxfaW50", "NjQYAiABKANIAYgBARIcCg9vcHRpb25hbF91aW50MzIYAyABKA1IAogBARIc", "Cg9vcHRpb25hbF91aW50NjQYBCABKARIA4gBARIcCg9vcHRpb25hbF9zaW50", @@ -42,24 +42,25 @@ namespace ProtobufUnittest { "dGVkX21lc3NhZ2UYEyABKAsyMy5wcm90b2J1Zl91bml0dGVzdC5UZXN0UHJv", "dG8zT3B0aW9uYWwuTmVzdGVkTWVzc2FnZUICKAFIEYgBARJTChRvcHRpb25h", "bF9uZXN0ZWRfZW51bRgVIAEoDjIwLnByb3RvYnVmX3VuaXR0ZXN0LlRlc3RQ", - "cm90bzNPcHRpb25hbC5OZXN0ZWRFbnVtSBKIAQEaJwoNTmVzdGVkTWVzc2Fn", - "ZRIPCgJiYhgBIAEoBUgAiAEBQgUKA19iYiJKCgpOZXN0ZWRFbnVtEg8KC1VO", - "U1BFQ0lGSUVEEAASBwoDRk9PEAESBwoDQkFSEAISBwoDQkFaEAMSEAoDTkVH", - "EP///////////wFCEQoPX29wdGlvbmFsX2ludDMyQhEKD19vcHRpb25hbF9p", - "bnQ2NEISChBfb3B0aW9uYWxfdWludDMyQhIKEF9vcHRpb25hbF91aW50NjRC", - "EgoQX29wdGlvbmFsX3NpbnQzMkISChBfb3B0aW9uYWxfc2ludDY0QhMKEV9v", - "cHRpb25hbF9maXhlZDMyQhMKEV9vcHRpb25hbF9maXhlZDY0QhQKEl9vcHRp", - "b25hbF9zZml4ZWQzMkIUChJfb3B0aW9uYWxfc2ZpeGVkNjRCEQoPX29wdGlv", - "bmFsX2Zsb2F0QhIKEF9vcHRpb25hbF9kb3VibGVCEAoOX29wdGlvbmFsX2Jv", - "b2xCEgoQX29wdGlvbmFsX3N0cmluZ0IRCg9fb3B0aW9uYWxfYnl0ZXNCEAoO", - "X29wdGlvbmFsX2NvcmRCGgoYX29wdGlvbmFsX25lc3RlZF9tZXNzYWdlQhYK", - "FF9sYXp5X25lc3RlZF9tZXNzYWdlQhcKFV9vcHRpb25hbF9uZXN0ZWRfZW51", - "bUIlCiFjb20uZ29vZ2xlLnByb3RvYnVmLnRlc3RpbmcucHJvdG9QAWIGcHJv", - "dG8z")); + "cm90bzNPcHRpb25hbC5OZXN0ZWRFbnVtSBKIAQESFgoOc2luZ3VsYXJfaW50", + "MzIYFiABKAUSFgoOc2luZ3VsYXJfaW50NjQYFyABKAMaJwoNTmVzdGVkTWVz", + "c2FnZRIPCgJiYhgBIAEoBUgAiAEBQgUKA19iYiJKCgpOZXN0ZWRFbnVtEg8K", + "C1VOU1BFQ0lGSUVEEAASBwoDRk9PEAESBwoDQkFSEAISBwoDQkFaEAMSEAoD", + "TkVHEP///////////wFCEQoPX29wdGlvbmFsX2ludDMyQhEKD19vcHRpb25h", + "bF9pbnQ2NEISChBfb3B0aW9uYWxfdWludDMyQhIKEF9vcHRpb25hbF91aW50", + "NjRCEgoQX29wdGlvbmFsX3NpbnQzMkISChBfb3B0aW9uYWxfc2ludDY0QhMK", + "EV9vcHRpb25hbF9maXhlZDMyQhMKEV9vcHRpb25hbF9maXhlZDY0QhQKEl9v", + "cHRpb25hbF9zZml4ZWQzMkIUChJfb3B0aW9uYWxfc2ZpeGVkNjRCEQoPX29w", + "dGlvbmFsX2Zsb2F0QhIKEF9vcHRpb25hbF9kb3VibGVCEAoOX29wdGlvbmFs", + "X2Jvb2xCEgoQX29wdGlvbmFsX3N0cmluZ0IRCg9fb3B0aW9uYWxfYnl0ZXNC", + "EAoOX29wdGlvbmFsX2NvcmRCGgoYX29wdGlvbmFsX25lc3RlZF9tZXNzYWdl", + "QhYKFF9sYXp5X25lc3RlZF9tZXNzYWdlQhcKFV9vcHRpb25hbF9uZXN0ZWRf", + "ZW51bUIlCiFjb20uZ29vZ2xlLnByb3RvYnVmLnRlc3RpbmcucHJvdG9QAWIG", + "cHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional), global::ProtobufUnittest.TestProto3Optional.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum" }, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum" }, new[]{ typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage), global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage.Parser, new[]{ "Bb" }, new[]{ "Bb" }, null, null, null)}) + new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional), global::ProtobufUnittest.TestProto3Optional.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum", "SingularInt32", "SingularInt64" }, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum" }, new[]{ typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage), global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage.Parser, new[]{ "Bb" }, new[]{ "Bb" }, null, null, null)}) })); } #endregion @@ -112,6 +113,8 @@ namespace ProtobufUnittest { optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null; lazyNestedMessage_ = other.lazyNestedMessage_ != null ? other.lazyNestedMessage_.Clone() : null; optionalNestedEnum_ = other.optionalNestedEnum_; + singularInt32_ = other.singularInt32_; + singularInt64_ = other.singularInt64_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -516,6 +519,31 @@ namespace ProtobufUnittest { _hasBits0 &= ~8192; } + /// Field number for the "singular_int32" field. + public const int SingularInt32FieldNumber = 22; + private int singularInt32_; + /// + /// Add some non-optional fields to verify we can mix them. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int SingularInt32 { + get { return singularInt32_; } + set { + singularInt32_ = value; + } + } + + /// Field number for the "singular_int64" field. + public const int SingularInt64FieldNumber = 23; + private long singularInt64_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long SingularInt64 { + get { return singularInt64_; } + set { + singularInt64_ = value; + } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { return Equals(other as TestProto3Optional); @@ -548,6 +576,8 @@ namespace ProtobufUnittest { if (!object.Equals(OptionalNestedMessage, other.OptionalNestedMessage)) return false; if (!object.Equals(LazyNestedMessage, other.LazyNestedMessage)) return false; if (OptionalNestedEnum != other.OptionalNestedEnum) return false; + if (SingularInt32 != other.SingularInt32) return false; + if (SingularInt64 != other.SingularInt64) return false; return Equals(_unknownFields, other._unknownFields); } @@ -573,6 +603,8 @@ namespace ProtobufUnittest { if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode(); if (lazyNestedMessage_ != null) hash ^= LazyNestedMessage.GetHashCode(); if (HasOptionalNestedEnum) hash ^= OptionalNestedEnum.GetHashCode(); + if (SingularInt32 != 0) hash ^= SingularInt32.GetHashCode(); + if (SingularInt64 != 0L) hash ^= SingularInt64.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -662,6 +694,14 @@ namespace ProtobufUnittest { output.WriteRawTag(168, 1); output.WriteEnum((int) OptionalNestedEnum); } + if (SingularInt32 != 0) { + output.WriteRawTag(176, 1); + output.WriteInt32(SingularInt32); + } + if (SingularInt64 != 0L) { + output.WriteRawTag(184, 1); + output.WriteInt64(SingularInt64); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -727,6 +767,12 @@ namespace ProtobufUnittest { if (HasOptionalNestedEnum) { size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalNestedEnum); } + if (SingularInt32 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(SingularInt32); + } + if (SingularInt64 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(SingularInt64); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -801,6 +847,12 @@ namespace ProtobufUnittest { if (other.HasOptionalNestedEnum) { OptionalNestedEnum = other.OptionalNestedEnum; } + if (other.SingularInt32 != 0) { + SingularInt32 = other.SingularInt32; + } + if (other.SingularInt64 != 0L) { + SingularInt64 = other.SingularInt64; + } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -894,6 +946,14 @@ namespace ProtobufUnittest { OptionalNestedEnum = (global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum) input.ReadEnum(); break; } + case 176: { + SingularInt32 = input.ReadInt32(); + break; + } + case 184: { + SingularInt64 = input.ReadInt64(); + break; + } } } } diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 1758578eb773eb9caffd2c6e5ccbca57f12109f6..d2a01a42cbd6393a2734275f9e3ebadac4f1cac9 100644 GIT binary patch delta 329 zcmZqMEb@1YNJ9%_3sVbo3(FSPcowEPI@1$bSY4RJ% zafrcq%s`%`G#5A6MiC)qUnUtNsGJB;pD$dW2vDCdT%QO~pRc5J5?eu0eo4MD0Pm4W A;s5{u delta 80 zcmV-W0I&c3v=oN36o7;QgaU*Egaot&UjzcBDwkmd1w;bD47aBQ1w90}G6@AN0txIK m3I-Ac9so+WuuB732A9AQ1vLRmxAqYQ)&~e;25@q3bZ;}-`4^G^ diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index b1e71e7a59..24ea40b425 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.12.0-rc1 + 3.12.0-rc2 6 Google Inc. netstandard1.0;netstandard2.0;net45 diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 1b3874d633..04bd3f5bda 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.12.0-rc-1 + 3.12.0-rc-2 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 9d25bc2d04..5fb5045955 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-1 + 3.12.0-rc-2 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index c5e10cc654..6ce28ee5e1 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-1 + 3.12.0-rc-2 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 8f7435a7fd..eb15314247 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-1 + 3.12.0-rc-2 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index a23ff1ccea..b7d96766f7 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-1 + 3.12.0-rc-2 protobuf-java-util diff --git a/js/package.json b/js/package.json index d7095c1477..0b2adb81a1 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.12.0-rc.1", + "version": "3.12.0-rc.2", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 1862a6f9a6..4b9066a32d 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,10 +10,10 @@ protobuf-opensource@google.com yes - 2020-04-30 - + 2020-05-12 + - 3.12.0RC1 + 3.12.0RC2 3.12.0 @@ -543,5 +543,19 @@ G A release. 3-Clause BSD License GA release. + + + 3.12.0RC2 + 3.12.0 + + + beta + beta + + 2020-05-12 + + 3-Clause BSD License + GA release. + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 76eced8d74..bc293b8030 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.12.0RC1" +#define PHP_PROTOBUF_VERSION "3.12.0RC2" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 9363a2bde6..ae72dbbfa6 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.12.0-rc-1 + 3.12.0-rc-2 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 35bb943ff5..cee24d7ab1 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.12.0rc1' +__version__ = '3.12.0rc2' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 332aaf9158..29af94801a 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.12.0.rc.1" + s.version = "3.12.0.rc.2" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" From 805352584636a750e653ffc9be56c09d235a77cd Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 12 May 2020 14:39:14 -0700 Subject: [PATCH 14/26] Updated Changelog for 3.12.0-rc2. --- CHANGES.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index bcd163a453..317930626e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -2020-04-28 version 3.12.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) +2020-05-12 version 3.12.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Protocol Compiler * [experimental] Singular, non-message typed fields in proto3 now support @@ -75,6 +75,7 @@ * Persistent Descriptor Pool (#6899) * Implement lazy loading of php class for proto messages (#6911) * Correct @return in Any.unpack docblock (#7089) + * Ignore unknown enum value when ignore_unknown specified (#7455) Ruby * [experimental] Implemented proto3 presence for Ruby. (#7406) @@ -87,11 +88,13 @@ C# * [experimental] Add support for proto3 presence fields in C# (#7382) - * Cleanup various bits of Google.Protobuf (#6674) + * Mark GetOption API as obsolete and expose the "GetOptions()" method on descriptors instead (#7491) + * Remove Has/Clear members for C# message fields in proto2 (#7429) + * Enforce recursion depth checking for unknown fields (#7132) * Fix conformance test failures for Google.Protobuf (#6910) + * Cleanup various bits of Google.Protobuf (#6674) * Fix latest ArgumentException for C# extensions (#6938) * Remove unnecessary branch from ReadTag (#7289) - * Enforce recursion depth checking for unknown fields (#7132) Objective-C * [experimental] ObjC Proto3 optional support (#7421) From 4bbdffacf208480cf6333782664f5eebdb7c9c26 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 13 May 2020 12:49:21 -0700 Subject: [PATCH 15/26] Added background information about proto3 presence. (#7501) --- docs/implementing_proto3_presence.md | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/implementing_proto3_presence.md b/docs/implementing_proto3_presence.md index 08f9c51321..fae2eb589a 100644 --- a/docs/implementing_proto3_presence.md +++ b/docs/implementing_proto3_presence.md @@ -5,6 +5,8 @@ proto3. Proto3 optional fields track presence like in proto2. For background information about what presence tracking means, please see [docs/field_presence](field_presence.md). +## Document Summary + This document is targeted at developers who own or maintain protobuf code generators. All code generators will need to be updated to support proto3 optional fields. First-party code generators developed by Google are being @@ -14,6 +16,7 @@ independently by their authors. This includes: - implementations of Protocol Buffers for other languges. - alternate implementations of Protocol Buffers that target specialized use cases. +- RPC code generators that create generated APIs for service calls. - code generators that implement some utility code on top of protobuf generated classes. @@ -21,6 +24,53 @@ While this document speaks in terms of "code generators", these same principles apply to implementations that dynamically generate a protocol buffer API "on the fly", directly from a descriptor, in languages that support this kind of usage. +## Background + +Presence tracking was added to proto3 in response to user feedback, both from +inside Google and [from open-source +users](https://github.com/protocolbuffers/protobuf/issues/1606). The [proto3 +wrapper +types](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto) +were previously the only supported presence mechanism for proto3. Users have +pointed to both efficiency and usability issues with the wrapper types. + +Presence in proto3 uses exactly the same syntax and semantics as in proto2. +Proto3 Fields marked `optional` will track presence like proto2, while fields +without any label (known as "singular fields"), will continue to omit presence +information. The `optional` keyword was chosen to minimize differences with +proto2. + +Unfortunately, for the current descriptor protos and `Descriptor` API (as of +3.11.4) it is not possible to use the same representation as proto2. Proto3 +descriptors already use `LABEL_OPTIONAL` for proto3 singular fields, which do +not track presence. There is a lot of existing code that reflects over proto3 +protos and assumes that `LABEL_OPTIONAL` in proto3 means "no presence." Changing +the semantics now would be risky, since old software would likely drop proto3 +presence information, which would be a data loss bug. + +To minimize this risk we chose a descriptor representation that is semantically +compatible with existing proto3 reflection. Every proto3 optional field is +placed into a one-field `oneof`. We call this a "synthetic" oneof, as it was not +present in the source `.proto` file. + +Since oneof fields in proto3 already track presence, existing proto3 +reflection-based algorithms should correctly preserve presence for proto3 +optional fields with no code changes. For example, the JSON and TextFormat +parsers/serializers in C++ and Java did not require any changes to support +proto3 presence. This is the major benefit of synthetic oneofs. + +This design does leave some cruft in descriptors. Synthetic oneofs are a +compatibility measure that we can hopefully clean up in the future. For now +though, it is important to preserve them across different descriptor formats and +APIs. It is never safe to drop synthetic oneofs from a proto schema. Code +generators can (and should) skip synthetic oneofs when generating a user-facing +API or user-facing documentation. But for any schema representation that is +consumed programmatically, it is important to keep the synthetic oneofs around. + +In APIs it can be helpful to offer separate accessors that refer to "real" +oneofs (see [API Changes](#api-changes) below). This is a convenient way to omit +synthetic oneofs in code generators. + ## Updating a Code Generator When a user adds an `optional` field to proto3, this is internally rewritten as From 7276738e79e4584ede41504e3aef15428b11ecb4 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 14 May 2020 17:04:20 -0700 Subject: [PATCH 16/26] Fixed bug in map key sorting for Java TextFormat. (#7508) Fixes: https://github.com/protocolbuffers/protobuf/issues/7505 --- .../java/com/google/protobuf/TextFormat.java | 22 +++---------------- .../com/google/protobuf/TextFormatTest.java | 21 ++++++++++++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/TextFormat.java b/java/core/src/main/java/com/google/protobuf/TextFormat.java index 673343d4ea..bec9623fe8 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -490,27 +490,11 @@ public final class TextFormat { } switch (fieldType) { case BOOLEAN: - boolean aBoolean = (boolean) getKey(); - boolean bBoolean = (boolean) b.getKey(); - if (aBoolean == bBoolean) { - return 0; - } else if (aBoolean) { - return 1; - } else { - return -1; - } + return Boolean.compare((boolean) getKey(), (boolean) b.getKey()); case LONG: - long aLong = (long) getKey(); - long bLong = (long) b.getKey(); - if (aLong < bLong) { - return -1; - } else if (aLong > bLong) { - return 1; - } else { - return 0; - } + return Long.compare((long) getKey(), (long) b.getKey()); case INT: - return (int) getKey() - (int) b.getKey(); + return Integer.compare((int) getKey(), (int) b.getKey()); case STRING: String aString = (String) getKey(); String bString = (String) b.getKey(); diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 6ca3ae111f..dc75f842ef 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -1404,6 +1404,27 @@ public class TextFormatTest extends TestCase { } } + public void testMapDuplicateKeys() throws Exception { + String input = + "int32_to_int32_field: {\n" + + " key: 1\n" + + " value: 1\n" + + "}\n" + + "int32_to_int32_field: {\n" + + " key: -2147483647\n" + + " value: 5\n" + + "}\n" + + "int32_to_int32_field: {\n" + + " key: 1\n" + + " value: -1\n" + + "}\n"; + TestMap msg = TextFormat.parse(input, TestMap.class); + int val1 = msg.getInt32ToInt32Field().get(1); + TestMap msg2 = TextFormat.parse(msg.toString(), TestMap.class); + int val2 = msg2.getInt32ToInt32Field().get(1); + assertEquals(val1, val2); + } + public void testMapShortForm() throws Exception { String text = "string_to_int32_field [{ key: 'x' value: 10 }, { key: 'y' value: 20 }]\n" From e90b71cdee08a31532245dc15686c779b0cb4e60 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 15 May 2020 13:28:07 -0700 Subject: [PATCH 17/26] Update protobuf version --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 24 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- 16 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index f6536fd095..a472bf57e4 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.12.0-rc2' + s.version = '3.12.0' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 5fe982a7f7..5ff3597e0e 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.12.0-rc2' + s.version = '3.12.0' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index b94fe1006a..d05b327ec3 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.12.0-rc-2],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.12.0],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index e2a46ce4fe..d28a44e0ef 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.12.0-rc2 + 3.12.0 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 24ea40b425..61fc21470a 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.12.0-rc2 + 3.12.0 6 Google Inc. netstandard1.0;netstandard2.0;net45 diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 04bd3f5bda..6fca4aa45b 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.12.0-rc-2 + 3.12.0 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 5fb5045955..1bbf90e0e9 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-2 + 3.12.0 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 6ce28ee5e1..c5901a2c3f 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-2 + 3.12.0 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index eb15314247..706e43dd8b 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-2 + 3.12.0 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index b7d96766f7..5d2cbc0081 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0-rc-2 + 3.12.0 protobuf-java-util diff --git a/js/package.json b/js/package.json index 0b2adb81a1..766052ebe6 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.12.0-rc.2", + "version": "3.12.0", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 4b9066a32d..687c43de0f 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,15 +10,15 @@ protobuf-opensource@google.com yes - 2020-05-12 - + 2020-05-15 + - 3.12.0RC2 + 3.12.0 3.12.0 - beta - beta + stable + stable 3-Clause BSD License GA release. @@ -557,5 +557,19 @@ G A release. 3-Clause BSD License GA release. + + + 3.12.0 + 3.12.0 + + + stable + stable + + 2020-05-15 + + 3-Clause BSD License + GA release. + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index bc293b8030..4f40ec224b 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.12.0RC2" +#define PHP_PROTOBUF_VERSION "3.12.0" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index ae72dbbfa6..c64afb1d7d 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.12.0-rc-2 + 3.12.0 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index cee24d7ab1..7861888ae5 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.12.0rc2' +__version__ = '3.12.0' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 29af94801a..17df6fec50 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.12.0.rc.2" + s.version = "3.12.0" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" From 0dd036d675508a4ecf69e61626fd0c88235a661d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 15 May 2020 15:11:25 -0700 Subject: [PATCH 18/26] Added a changelog entry about the Java fix. (#7516) --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 317930626e..6234f1635d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -44,6 +44,7 @@ * Mark java enum _VALUE constants as @Deprecated if the enum field is deprecated * reduce size for enums with allow_alias set to true. * Sort map fields alphabetically by the field's key when printing textproto. + * Fixed a bug in map sorting that appeared in -rc1 and -rc2 (#7508). * TextFormat.merge() handles Any as top level type. * Throw a descriptive IllegalArgumentException when calling getValueDescriptor() on enum special value UNRECOGNIZED instead of From cf81f38b5d6775739f25fb7d62d7274f93a4348a Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Tue, 19 May 2020 15:52:59 -0700 Subject: [PATCH 19/26] Restore binary builds of Ruby 2.3 and 2.4 (#7529) (#7531) --- kokoro/release/ruby/linux/ruby/ruby_build.sh | 2 +- kokoro/release/ruby/macos/ruby/ruby_build.sh | 2 +- kokoro/release/ruby/macos/ruby/ruby_build_environment.sh | 2 +- ruby/Rakefile | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kokoro/release/ruby/linux/ruby/ruby_build.sh b/kokoro/release/ruby/linux/ruby/ruby_build.sh index 95f1dea906..f8ae9623f2 100755 --- a/kokoro/release/ruby/linux/ruby/ruby_build.sh +++ b/kokoro/release/ruby/linux/ruby/ruby_build.sh @@ -12,7 +12,7 @@ fi umask 0022 pushd ruby gem install bundler -v 2.1.4 -bundle install && bundle exec rake gem:native +bundle update && bundle exec rake gem:native ls pkg mv pkg/* $ARTIFACT_DIR popd diff --git a/kokoro/release/ruby/macos/ruby/ruby_build.sh b/kokoro/release/ruby/macos/ruby/ruby_build.sh index 9fc42b13eb..7f6c18fe8e 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build.sh @@ -11,7 +11,7 @@ fi umask 0022 pushd ruby -bundle install && bundle exec rake gem:native +bundle update && bundle exec rake gem:native ls pkg mv pkg/* $ARTIFACT_DIR popd diff --git a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh index 7ff1ce5696..880c23390c 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh @@ -63,7 +63,7 @@ set +x rvm use 2.5.0 set -x ruby --version | grep 'ruby 2.5.0' -for v in 2.6.0 2.5.1 ; do +for v in 2.6.0 2.5.1 2.4.0 2.3.0; do ccache -c rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin11 MAKE="$MAKE" done diff --git a/ruby/Rakefile b/ruby/Rakefile index 53241fd515..2aa7743e20 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -73,7 +73,7 @@ else ['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat| RakeCompilerDock.sh <<-"EOT", platform: plat bundle && \ - IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0 + IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0:2.4.0:2.3.0 EOT end end @@ -81,7 +81,7 @@ else if RUBY_PLATFORM =~ /darwin/ task 'gem:native' do system "rake genproto" - system "rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.1" + system "rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.1:2.4.0:2.3.0" end else task 'gem:native' => [:genproto, 'gem:windows'] From 6ad138d85aa7a1c5beb4cc1d7b92fb91f732cb0e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 20 May 2020 10:54:29 -0700 Subject: [PATCH 20/26] Update protobuf version (#7535) --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 22 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- src/Makefile.am | 2 +- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.h | 2 +- src/google/protobuf/descriptor.pb.h | 2 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 2 +- src/google/protobuf/stubs/common.h | 2 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 2 +- src/google/protobuf/wrappers.pb.h | 2 +- 31 files changed, 48 insertions(+), 34 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index a472bf57e4..c3ccbcdad3 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.12.0' + s.version = '3.12.1' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 5ff3597e0e..485cc582fa 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.12.0' + s.version = '3.12.1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index d05b327ec3..03d628b75c 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.12.0],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.12.1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index d28a44e0ef..40853009da 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.12.0 + 3.12.1 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 61fc21470a..3e1ff61417 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.12.0 + 3.12.1 6 Google Inc. netstandard1.0;netstandard2.0;net45 diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 6fca4aa45b..e2f81bfd93 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.12.0 + 3.12.1 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 1bbf90e0e9..816e6ff88e 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0 + 3.12.1 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index c5901a2c3f..1f010ac1ce 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0 + 3.12.1 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 706e43dd8b..469459552c 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0 + 3.12.1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 5d2cbc0081..6e16de3005 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.0 + 3.12.1 protobuf-java-util diff --git a/js/package.json b/js/package.json index 766052ebe6..dd23d1f4f2 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.12.0", + "version": "3.12.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 687c43de0f..243178d9fc 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2020-05-15 - + 2020-05-20 + - 3.12.0 - 3.12.0 + 3.12.1 + 3.12.1 stable @@ -571,5 +571,19 @@ G A release. 3-Clause BSD License GA release. + + + 3.12.1 + 3.12.1 + + + stable + stable + + 2020-05-20 + + 3-Clause BSD License + GA release. + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 4f40ec224b..9f8dfe030c 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.12.0" +#define PHP_PROTOBUF_VERSION "3.12.1" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index c64afb1d7d..119559138b 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.12.0 + 3.12.1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 7861888ae5..a7f3d68157 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.12.0' +__version__ = '3.12.1' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 17df6fec50..c1a203de02 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.12.0" + s.version = "3.12.1" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/src/Makefile.am b/src/Makefile.am index 1837279801..96f663a7e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 23:0:0 +PROTOBUF_VERSION = 23:1:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 61b4722950..ff7499d774 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 8646a39aca..3c032776eb 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 1fd2a29a99..2bbef610a4 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 2d978df82a..ba18f649b1 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 5b5da9efa8..a400c5369d 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index be58106ee0..8ecf3b4b8f 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index b3070f322b..51c9e21936 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 2a93c6dfb2..31cb88e95c 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -300,7 +300,7 @@ // Shared google3/opensource definitions. ////////////////////////////////////// -#define PROTOBUF_VERSION 3012000 +#define PROTOBUF_VERSION 3012001 #define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3012000 #define PROTOBUF_MIN_PROTOC_VERSION 3012000 #define PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 1bc08cef02..7746bf2b47 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index da13b937e1..aa35010670 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 74fbada96f..7e56797efe 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -81,7 +81,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3012000 +#define GOOGLE_PROTOBUF_VERSION 3012001 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 943c5accf9..aa6e482f53 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 470e3f6542..7c74d1c6fe 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 1baa8f25a8..629b8d5959 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. From a37cc13b2f6d11303811011b0bfbc867e7c0bf2b Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 20 May 2020 12:06:30 -0700 Subject: [PATCH 21/26] Added changelog entry for 3.12.1. --- CHANGES.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 6234f1635d..3c093e34c7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,10 @@ +2020-05-20 version 3.12.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * Re-add binary gems for Ruby 2.3 and 2.4. These are EOL upstream, however + many people still use them and dropping support will require more + coordination. + 2020-05-12 version 3.12.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Protocol Compiler From 29de97cc5d25c4ae11de1212f9564823f9d7b72c Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 21 May 2020 12:45:34 -0700 Subject: [PATCH 22/26] Cherry-pick of df719723: Simplify template exporting macros (#7539) * Cherry-pick of df719723: Simplify template exporting macros * Fix macro usage --- src/google/protobuf/parse_context.h | 4 +- src/google/protobuf/port_def.inc | 178 ++------------------------ src/google/protobuf/port_undef.inc | 13 -- src/google/protobuf/repeated_field.cc | 24 ++-- src/google/protobuf/repeated_field.h | 23 ++-- 5 files changed, 32 insertions(+), 210 deletions(-) diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index c83eed94cf..c0427bc5fc 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -744,7 +744,7 @@ PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedEnumParser( void* object, const char* ptr, ParseContext* ctx); template -PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) +PROTOBUF_EXPORT_TEMPLATE_DEFINE PROTOBUF_MUST_USE_RESULT const char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx, bool (*is_valid)(int), InternalMetadata* metadata, @@ -760,7 +760,7 @@ PROTOBUF_MUST_USE_RESULT const } template -PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) +PROTOBUF_EXPORT_TEMPLATE_DEFINE PROTOBUF_MUST_USE_RESULT const char* PackedEnumParserArg(void* object, const char* ptr, ParseContext* ctx, bool (*is_valid)(const void*, int), diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 31cb88e95c..3a18e466e2 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -358,20 +358,28 @@ #if defined(PROTOBUF_USE_DLLS) #if defined(_MSC_VER) #ifdef LIBPROTOBUF_EXPORTS - #define PROTOBUF_EXPORT __declspec(dllexport) + #define PROTOBUF_EXPORT __declspec(dllexport) + #define PROTOBUF_EXPORT_TEMPLATE_DECLARE + #define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport) #else - #define PROTOBUF_EXPORT __declspec(dllimport) + #define PROTOBUF_EXPORT __declspec(dllimport) + #define PROTOBUF_EXPORT_TEMPLATE_DECLARE + #define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport) #endif #ifdef LIBPROTOC_EXPORTS - #define PROTOC_EXPORT __declspec(dllexport) + #define PROTOC_EXPORT __declspec(dllexport) #else - #define PROTOC_EXPORT __declspec(dllimport) + #define PROTOC_EXPORT __declspec(dllimport) #endif #else // defined(_MSC_VER) #ifdef LIBPROTOBUF_EXPORTS #define PROTOBUF_EXPORT __attribute__((visibility("default"))) + #define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default"))) + #define PROTOBUF_EXPORT_TEMPLATE_DEFINE #else #define PROTOBUF_EXPORT + #define PROTOBUF_EXPORT_TEMPLATE_DECLARE + #define PROTOBUF_EXPORT_TEMPLATE_DEFINE #endif #ifdef LIBPROTOC_EXPORTS #define PROTOC_EXPORT __attribute__((visibility("default"))) @@ -382,168 +390,10 @@ #else // defined(PROTOBUF_USE_DLLS) #define PROTOBUF_EXPORT #define PROTOC_EXPORT + #define PROTOBUF_EXPORT_TEMPLATE_DECLARE + #define PROTOBUF_EXPORT_TEMPLATE_DEFINE #endif - -// This portion provides macros for using FOO_EXPORT macros with explicit -// template instantiation declarations and definitions. -// Generally, the FOO_EXPORT macros are used at declarations, -// and GCC requires them to be used at explicit instantiation declarations, -// but MSVC requires __declspec(dllexport) to be used at the explicit -// instantiation definitions instead. - -// Usage -// -// In a header file, write: -// -// extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(FOO_EXPORT) foo; -// -// In a source file, write: -// -// template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(FOO_EXPORT) foo; -// -// Where FOO_EXPORT is either PROTOBUF_EXPORT or PROTOC_EXPORT - -// Implementation notes -// -// The implementation of these macros uses some subtle macro semantics to -// detect what the provided FOO_EXPORT value was defined as and then -// to dispatch to appropriate macro definitions. Unfortunately, -// MSVC's C preprocessor is rather non-compliant and requires special -// care to make it work. -// -// Issue 1. -// -// #define F(x) -// F() -// -// MSVC emits warning C4003 ("not enough actual parameters for macro -// 'F'), even though it's a valid macro invocation. This affects the -// macros below that take just an "export" parameter, because export -// may be empty. -// -// As a workaround, we can add a dummy parameter and arguments: -// -// #define F(x,_) -// F(,) -// -// Issue 2. -// -// #define F(x) G##x -// #define Gj() ok -// F(j()) -// -// The correct replacement for "F(j())" is "ok", but MSVC replaces it -// with "Gj()". As a workaround, we can pass the result to an -// identity macro to force MSVC to look for replacements again. (This -// is why PROTOBUF_EXPORT_TEMPLATE_STYLE_3 exists.) - -#define PROTOBUF_EXPORT_TEMPLATE_DECLARE(export) \ - PROTOBUF_EXPORT_TEMPLATE_INVOKE( \ - DECLARE, PROTOBUF_EXPORT_TEMPLATE_STYLE(export, ), export) -#define PROTOBUF_EXPORT_TEMPLATE_DEFINE(export) \ - PROTOBUF_EXPORT_TEMPLATE_INVOKE( \ - DEFINE, PROTOBUF_EXPORT_TEMPLATE_STYLE(export, ), export) - -// INVOKE is an internal helper macro to perform parameter replacements -// and token pasting to chain invoke another macro. E.g., -// PROTOBUF_EXPORT_TEMPLATE_INVOKE(DECLARE, DEFAULT, FOO_EXPORT) -// will export to call -// PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT(FOO_EXPORT, ) -// (but with FOO_EXPORT expanded too). -#define PROTOBUF_EXPORT_TEMPLATE_INVOKE(which, style, export) \ - PROTOBUF_EXPORT_TEMPLATE_INVOKE_2(which, style, export) -#define PROTOBUF_EXPORT_TEMPLATE_INVOKE_2(which, style, export) \ - PROTOBUF_EXPORT_TEMPLATE_##which##_##style(export, ) - -// Default style is to apply the FOO_EXPORT macro at declaration sites. -#define PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT(export, _) export -#define PROTOBUF_EXPORT_TEMPLATE_DEFINE_DEFAULT(export, _) - -// The "MSVC hack" style is used when FOO_EXPORT is defined -// as __declspec(dllexport), which MSVC requires to be used at -// definition sites instead. -#define PROTOBUF_EXPORT_TEMPLATE_DECLARE_MSVC_HACK(export, _) -#define PROTOBUF_EXPORT_TEMPLATE_DEFINE_MSVC_HACK(export, _) export - -// PROTOBUF_EXPORT_TEMPLATE_STYLE is an internal helper macro that identifies -// which export style needs to be used for the provided FOO_EXPORT macro -// definition. "", "__attribute__(...)", and "__declspec(dllimport)" are -// mapped to "DEFAULT"; while "__declspec(dllexport)" is mapped to "MSVC_HACK". -// -// It's implemented with token pasting to transform the __attribute__ and -// __declspec annotations into macro invocations. E.g., if FOO_EXPORT is -// defined as "__declspec(dllimport)", it undergoes the following sequence of -// macro substitutions: -// PROTOBUF_EXPORT_TEMPLATE_STYLE(FOO_EXPORT, ) -// PROTOBUF_EXPORT_TEMPLATE_STYLE_2(__declspec(dllimport), ) -// PROTOBUF_EXPORT_TEMPLATE_STYLE_3( -// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport)) -// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport) -// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport -// DEFAULT -#define PROTOBUF_EXPORT_TEMPLATE_STYLE(export, _) \ - PROTOBUF_EXPORT_TEMPLATE_STYLE_2(export, ) -#define PROTOBUF_EXPORT_TEMPLATE_STYLE_2(export, _) \ - PROTOBUF_EXPORT_TEMPLATE_STYLE_3( \ - PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA##export) -#define PROTOBUF_EXPORT_TEMPLATE_STYLE_3(style) style - -// Internal helper macros for PROTOBUF_EXPORT_TEMPLATE_STYLE. -// -// XXX: C++ reserves all identifiers containing "__" for the implementation, -// but "__attribute__" and "__declspec" already contain "__" and the token-paste -// operator can only add characters; not remove them. To minimize the risk of -// conflict with implementations, we include "foj3FJo5StF0OvIzl7oMxA" (a random -// 128-bit string, encoded in Base64) in the macro name. -#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA DEFAULT -#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__attribute__(...) \ - DEFAULT -#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec(arg) \ - PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_##arg - -// Internal helper macros for PROTOBUF_EXPORT_TEMPLATE_STYLE. -#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport MSVC_HACK -#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport DEFAULT - -// Sanity checks. -// -// PROTOBUF_EXPORT_TEMPLATE_TEST uses the same macro invocation pattern as -// PROTOBUF_EXPORT_TEMPLATE_DECLARE and PROTOBUF_EXPORT_TEMPLATE_DEFINE do to -// check that they're working correctly. When they're working correctly, the -// sequence of macro replacements should go something like: -// -// PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport)); -// -// static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT, -// PROTOBUF_EXPORT_TEMPLATE_STYLE(__declspec(dllimport), ), -// __declspec(dllimport)), "__declspec(dllimport)"); -// -// static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT, -// DEFAULT, __declspec(dllimport)), "__declspec(dllimport)"); -// -// static_assert(PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT( -// __declspec(dllimport)), "__declspec(dllimport)"); -// -// static_assert(true, "__declspec(dllimport)"); -// -// When they're not working correctly, a syntax error should occur instead. -#define PROTOBUF_EXPORT_TEMPLATE_TEST(want, export) \ - static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE( \ - TEST_##want, PROTOBUF_EXPORT_TEMPLATE_STYLE(export, ), \ - export), #export) -#define PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT(...) true -#define PROTOBUF_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK(...) true - -PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, ); -PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __attribute__((visibility("default")))); -PROTOBUF_EXPORT_TEMPLATE_TEST(MSVC_HACK, __declspec(dllexport)); -PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport)); - -#undef PROTOBUF_EXPORT_TEMPLATE_TEST -#undef PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT -#undef PROTOBUF_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK - // Windows declares several inconvenient macro names. We #undef them and then // restore them in port_undef.inc. #ifdef _MSC_VER diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index 68339f62b0..b35e8568fc 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -69,19 +69,6 @@ #undef PROTOBUF_EXPORT_TEMPLATE_DECLARE #undef PROTOBUF_EXPORT_TEMPLATE_DEFINE #undef PROTOBUF_ALIGNAS -#undef PROTOBUF_EXPORT_TEMPLATE_INVOKE_2 -#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT -#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE_DEFAULT -#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE_MSVC_HACK -#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE_MSVC_HACK -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_2 -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_3 -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__attribute__ -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport -#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport #undef PROTOBUF_FINAL // Restore macro that may have been #undef'd in port_def.inc. diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc index 1b5a0b8d15..6450679122 100644 --- a/src/google/protobuf/repeated_field.cc +++ b/src/google/protobuf/repeated_field.cc @@ -123,22 +123,14 @@ MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) { } // namespace internal -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedField; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedField; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedField; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedField; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedField; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedField; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedField; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) - RepeatedPtrField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedPtrField; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 9e2788286e..fd01a667ec 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -2816,21 +2816,14 @@ UnsafeArenaAllocatedRepeatedPtrFieldBackInserter( } // Extern declarations of common instantiations to reduce library bloat. -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) - RepeatedField; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) - RepeatedField; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) - RepeatedField; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) - RepeatedField; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) - RepeatedField; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) - RepeatedField; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) - RepeatedField; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedPtrField; } // namespace protobuf From ef22086980e148da5e8264647b96ccf1f7d1feaf Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 21 May 2020 12:46:35 -0700 Subject: [PATCH 23/26] Fix :protobuf_objc bazel target (#7538) * Potential 3.12 ObjC bazel patch * Add test targets to bazel test * Remove :protobuf_objc test target --- BUILD | 30 ++++++++++++++++++++---------- kokoro/linux/bazel/build.sh | 3 +++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/BUILD b/BUILD index 8ab4cb413e..b32a1f1610 100644 --- a/BUILD +++ b/BUILD @@ -969,6 +969,16 @@ alias( objc_library( name = "protobuf_objc", hdrs = [ + "objectivec/GPBAny.pbobjc.h", + "objectivec/GPBApi.pbobjc.h", + "objectivec/GPBDuration.pbobjc.h", + "objectivec/GPBEmpty.pbobjc.h", + "objectivec/GPBFieldMask.pbobjc.h", + "objectivec/GPBSourceContext.pbobjc.h", + "objectivec/GPBStruct.pbobjc.h", + "objectivec/GPBTimestamp.pbobjc.h", + "objectivec/GPBType.pbobjc.h", + "objectivec/GPBWrappers.pbobjc.h", "objectivec/GPBArray.h", "objectivec/GPBBootstrap.h", "objectivec/GPBCodedInputStream.h", @@ -1017,6 +1027,16 @@ objc_library( "objectivec", ], non_arc_srcs = [ + "objectivec/GPBAny.pbobjc.m", + "objectivec/GPBApi.pbobjc.m", + "objectivec/GPBDuration.pbobjc.m", + "objectivec/GPBEmpty.pbobjc.m", + "objectivec/GPBFieldMask.pbobjc.m", + "objectivec/GPBSourceContext.pbobjc.m", + "objectivec/GPBStruct.pbobjc.m", + "objectivec/GPBTimestamp.pbobjc.m", + "objectivec/GPBType.pbobjc.m", + "objectivec/GPBWrappers.pbobjc.m", "objectivec/GPBArray.m", "objectivec/GPBCodedInputStream.m", "objectivec/GPBCodedOutputStream.m", @@ -1031,16 +1051,6 @@ objc_library( "objectivec/GPBUtilities.m", "objectivec/GPBWellKnownTypes.m", "objectivec/GPBWireFormat.m", - "objectivec/google/protobuf/Any.pbobjc.m", - "objectivec/google/protobuf/Api.pbobjc.m", - "objectivec/google/protobuf/Duration.pbobjc.m", - "objectivec/google/protobuf/Empty.pbobjc.m", - "objectivec/google/protobuf/FieldMask.pbobjc.m", - "objectivec/google/protobuf/SourceContext.pbobjc.m", - "objectivec/google/protobuf/Struct.pbobjc.m", - "objectivec/google/protobuf/Timestamp.pbobjc.m", - "objectivec/google/protobuf/Type.pbobjc.m", - "objectivec/google/protobuf/Wrappers.pbobjc.m", ], visibility = ["//visibility:public"], ) diff --git a/kokoro/linux/bazel/build.sh b/kokoro/linux/bazel/build.sh index 9355ebae30..5f34bea30e 100755 --- a/kokoro/linux/bazel/build.sh +++ b/kokoro/linux/bazel/build.sh @@ -26,6 +26,9 @@ trap print_test_logs EXIT bazel test --copt=-Werror --host_copt=-Werror \ //:build_files_updated_unittest \ //java/... \ + //:protoc \ + //:protobuf \ + //:protobuf_python \ //:protobuf_test \ @com_google_protobuf//:cc_proto_blacklist_test trap - EXIT From 746c46ed9d1792a347035de5bc4288d8ed2ce0ff Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 26 May 2020 13:48:47 -0700 Subject: [PATCH 24/26] Switch to using git@ for clone, to avoid having to enter password. (#7556) --- php/release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/release.sh b/php/release.sh index 6b0baac78f..ec9ec0eeb3 100755 --- a/php/release.sh +++ b/php/release.sh @@ -10,8 +10,8 @@ set -ex VERSION=$1 -git clone https://github.com/protocolbuffers/protobuf-php.git -git clone https://github.com/protocolbuffers/protobuf.git +git clone git@github.com:protocolbuffers/protobuf-php.git +git clone git@github.com:protocolbuffers/protobuf.git # Clean old files pushd protobuf-php From beeb621f5049f67cfb3f777bfe1251f9a99a2d52 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 26 May 2020 15:46:39 -0700 Subject: [PATCH 25/26] Update protobuf version (#7557) --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 22 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- src/Makefile.am | 2 +- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.h | 2 +- src/google/protobuf/descriptor.pb.h | 2 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 2 +- src/google/protobuf/stubs/common.h | 2 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 2 +- src/google/protobuf/wrappers.pb.h | 2 +- 31 files changed, 48 insertions(+), 34 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index c3ccbcdad3..67a96cc7a0 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.12.1' + s.version = '3.12.2' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 485cc582fa..a05b712326 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.12.1' + s.version = '3.12.2' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 03d628b75c..e473a57914 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.12.1],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.12.2],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 40853009da..50aca1b506 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.12.1 + 3.12.2 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 3e1ff61417..c79357ef5f 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.12.1 + 3.12.2 6 Google Inc. netstandard1.0;netstandard2.0;net45 diff --git a/java/bom/pom.xml b/java/bom/pom.xml index e2f81bfd93..5a63a1dc71 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.12.1 + 3.12.2 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 816e6ff88e..4112eb2c17 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.1 + 3.12.2 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 1f010ac1ce..30e6f37132 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.1 + 3.12.2 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 469459552c..f61c85755d 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.1 + 3.12.2 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 6e16de3005..a9b8b4ab00 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.12.1 + 3.12.2 protobuf-java-util diff --git a/js/package.json b/js/package.json index dd23d1f4f2..7fd5e69679 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.12.1", + "version": "3.12.2", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 243178d9fc..5c9d810584 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2020-05-20 - + 2020-05-26 + - 3.12.1 - 3.12.1 + 3.12.2 + 3.12.2 stable @@ -585,5 +585,19 @@ G A release. 3-Clause BSD License GA release. + + + 3.12.2 + 3.12.2 + + + stable + stable + + 2020-05-26 + + 3-Clause BSD License + GA release. + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 9f8dfe030c..090f96018c 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.12.1" +#define PHP_PROTOBUF_VERSION "3.12.2" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 119559138b..ed028d5d4e 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.12.1 + 3.12.2 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index a7f3d68157..8b3b580922 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.12.1' +__version__ = '3.12.2' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index c1a203de02..469074fe85 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.12.1" + s.version = "3.12.2" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/src/Makefile.am b/src/Makefile.am index 96f663a7e4..d73195c405 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 23:1:0 +PROTOBUF_VERSION = 23:2:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index ff7499d774..36c69edbd2 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 3c032776eb..d1a054ade9 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 2bbef610a4..0fee42a759 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index ba18f649b1..54eac71967 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index a400c5369d..b8b16340db 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 8ecf3b4b8f..cf77a6995f 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 51c9e21936..da74b583df 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 3a18e466e2..4aa0969623 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -300,7 +300,7 @@ // Shared google3/opensource definitions. ////////////////////////////////////// -#define PROTOBUF_VERSION 3012001 +#define PROTOBUF_VERSION 3012002 #define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3012000 #define PROTOBUF_MIN_PROTOC_VERSION 3012000 #define PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 7746bf2b47..ccfcb88dc5 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index aa35010670..7d8fd61369 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 7e56797efe..0fd679a6fb 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -81,7 +81,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3012001 +#define GOOGLE_PROTOBUF_VERSION 3012002 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index aa6e482f53..64249978e7 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 7c74d1c6fe..ffe832d0be 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 629b8d5959..e8f82007fe 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3012001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. From 678da4f76eb9168c9965afc2149944a66cd48546 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 26 May 2020 15:55:45 -0700 Subject: [PATCH 26/26] Updated the changelog for the 3.12.2 release. --- CHANGES.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 3c093e34c7..4b18dbbec3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,11 @@ +2020-05-26 version 3.12.2 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + C++ + * Simplified the template export macros to fix the build for mingw32. (#7539) + + Objective-C + * Fix for the :protobuf_objc target in the Bazel BUILD file. (#7538) + 2020-05-20 version 3.12.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Ruby