From 6688b60c366d29f095485354915c0c2138baea30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20He=C3=9F?= Date: Mon, 26 Nov 2018 12:05:40 +0100 Subject: [PATCH 01/70] Windows: install missing headers --- cmake/extract_includes.bat.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in index 3818c4ef5b..29c04fb070 100644 --- a/cmake/extract_includes.bat.in +++ b/cmake/extract_includes.bat.in @@ -72,6 +72,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message.h" include\go copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message_lite.h" include\google\protobuf\message_lite.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h" include\google\protobuf\metadata.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata_lite.h" include\google\protobuf\metadata_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\parse_context.h" include\google\protobuf\parse_context.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port.h" include\google\protobuf\port.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_def.inc" include\google\protobuf\port_def.inc copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_undef.inc" include\google\protobuf\port_undef.inc @@ -97,6 +98,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\singleton.h" in copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\status.h" include\google\protobuf\stubs\status.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stl_util.h" include\google\protobuf\stubs\stl_util.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stringpiece.h" include\google\protobuf\stubs\stringpiece.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\strutil.h" include\google\protobuf\stubs\strutil.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\template_util.h" include\google\protobuf\stubs\template_util.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h" include\google\protobuf\text_format.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.pb.h" include\google\protobuf\timestamp.pb.h From 35aa9fdcbdff0210efa1279021423ad18c6fc7cc Mon Sep 17 00:00:00 2001 From: Abdel Younes Date: Mon, 10 Dec 2018 14:55:17 +0100 Subject: [PATCH 02/70] fix: cmake install --- cmake/extract_includes.bat.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in index 3818c4ef5b..5cbd5f426a 100644 --- a/cmake/extract_includes.bat.in +++ b/cmake/extract_includes.bat.in @@ -72,6 +72,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message.h" include\go copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message_lite.h" include\google\protobuf\message_lite.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h" include\google\protobuf\metadata.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata_lite.h" include\google\protobuf\metadata_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\parse_context.h" include\google\protobuf\parse_context.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port.h" include\google\protobuf\port.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_def.inc" include\google\protobuf\port_def.inc copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_undef.inc" include\google\protobuf\port_undef.inc @@ -96,6 +97,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\port.h" include copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\singleton.h" include\google\protobuf\stubs\singleton.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\status.h" include\google\protobuf\stubs\status.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stl_util.h" include\google\protobuf\stubs\stl_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\strutil.h" include\google\protobuf\stubs\strutil.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stringpiece.h" include\google\protobuf\stubs\stringpiece.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\template_util.h" include\google\protobuf\stubs\template_util.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h" include\google\protobuf\text_format.h From 24638088c67116f9cf94548dec7b0e4d135762bb Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Mon, 10 Dec 2018 10:22:41 -0800 Subject: [PATCH 03/70] Make Protobuf compatible with C# 6 --- csharp/src/Google.Protobuf/FieldMaskTree.cs | 5 +- .../Reflection/FileDescriptor.cs | 95 ++++++++++--------- .../Reflection/SingleFieldAccessor.cs | 15 ++- .../WellKnownTypes/TimestampPartial.cs | 2 +- 4 files changed, 65 insertions(+), 52 deletions(-) diff --git a/csharp/src/Google.Protobuf/FieldMaskTree.cs b/csharp/src/Google.Protobuf/FieldMaskTree.cs index 36c823bed0..ff9e088773 100644 --- a/csharp/src/Google.Protobuf/FieldMaskTree.cs +++ b/csharp/src/Google.Protobuf/FieldMaskTree.cs @@ -120,7 +120,8 @@ namespace Google.Protobuf return this; } - if (!node.Children.TryGetValue(part, out var childNode)) + Node childNode; + if (!node.Children.TryGetValue(part, out childNode)) { createNewBranch = true; childNode = new Node(); @@ -361,4 +362,4 @@ namespace Google.Protobuf } } } -} \ No newline at end of file +} diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 6d4520c0bc..992b792ada 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -98,64 +98,65 @@ namespace Google.Protobuf.Reflection } } return dictionary; + } - IDescriptor FindDescriptorForPath(IList path) + private IDescriptor FindDescriptorForPath(IList path) + { + // All complete declarations have an even, non-empty path length + // (There can be an empty path for a descriptor declaration, but that can't have any comments, + // so we currently ignore it.) + if (path.Count == 0 || (path.Count & 1) != 0) { - // All complete declarations have an even, non-empty path length - // (There can be an empty path for a descriptor declaration, but that can't have any comments, - // so we currently ignore it.) - if (path.Count == 0 || (path.Count & 1) != 0) - { - return null; - } - IReadOnlyList topLevelList = GetNestedDescriptorListForField(path[0]); - DescriptorBase current = GetDescriptorFromList(topLevelList, path[1]); + return null; + } + IReadOnlyList topLevelList = GetNestedDescriptorListForField(path[0]); + DescriptorBase current = GetDescriptorFromList(topLevelList, path[1]); - for (int i = 2; current != null && i < path.Count; i += 2) - { - var list = current.GetNestedDescriptorListForField(path[i]); - current = GetDescriptorFromList(list, path[i + 1]); - } - return current; + for (int i = 2; current != null && i < path.Count; i += 2) + { + var list = current.GetNestedDescriptorListForField(path[i]); + current = GetDescriptorFromList(list, path[i + 1]); } + return current; + } - DescriptorBase GetDescriptorFromList(IReadOnlyList list, int index) + private DescriptorBase GetDescriptorFromList(IReadOnlyList list, int index) + { + // This is fine: it may be a newer version of protobuf than we understand, with a new descriptor + // field. + if (list == null) { - // This is fine: it may be a newer version of protobuf than we understand, with a new descriptor - // field. - if (list == null) - { - return null; - } - // We *could* return null to silently continue, but this is basically data corruption. - if (index < 0 || index >= list.Count) - { - // We don't have much extra information to give at this point unfortunately. If this becomes a problem, - // we can pass in the complete path and report that and the file name. - throw new InvalidProtocolBufferException($"Invalid descriptor location path: index out of range"); - } - return list[index]; + return null; + } + // We *could* return null to silently continue, but this is basically data corruption. + if (index < 0 || index >= list.Count) + { + // We don't have much extra information to give at this point unfortunately. If this becomes a problem, + // we can pass in the complete path and report that and the file name. + throw new InvalidProtocolBufferException($"Invalid descriptor location path: index out of range"); } + return list[index]; + } - IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + private IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) { - switch (fieldNumber) - { - case FileDescriptorProto.ServiceFieldNumber: - return (IReadOnlyList) Services; - case FileDescriptorProto.MessageTypeFieldNumber: - return (IReadOnlyList) MessageTypes; - case FileDescriptorProto.EnumTypeFieldNumber: - return (IReadOnlyList) EnumTypes; - default: - return null; - } + case FileDescriptorProto.ServiceFieldNumber: + return (IReadOnlyList) Services; + case FileDescriptorProto.MessageTypeFieldNumber: + return (IReadOnlyList) MessageTypes; + case FileDescriptorProto.EnumTypeFieldNumber: + return (IReadOnlyList) EnumTypes; + default: + return null; } } internal DescriptorDeclaration GetDeclaration(IDescriptor descriptor) { - declarations.Value.TryGetValue(descriptor, out var declaration); + DescriptorDeclaration declaration; + declarations.Value.TryGetValue(descriptor, out declaration); return declaration; } @@ -191,7 +192,8 @@ namespace Google.Protobuf.Reflection throw new DescriptorValidationException(@this, "Invalid public dependency index."); } string name = proto.Dependency[index]; - if (!nameToFileMap.TryGetValue(name, out var file)) + FileDescriptor file; + if (!nameToFileMap.TryGetValue(name, out file)) { if (!allowUnknownDependencies) { @@ -414,7 +416,8 @@ namespace Google.Protobuf.Reflection var dependencies = new List(); foreach (var dependencyName in proto.Dependency) { - if (!descriptorsByName.TryGetValue(dependencyName, out var dependency)) + FileDescriptor dependency; + if (!descriptorsByName.TryGetValue(dependencyName, out dependency)) { throw new ArgumentException($"Dependency missing: {dependencyName}"); } diff --git a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs index d541570fd1..5872ee20d1 100644 --- a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs +++ b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs @@ -60,13 +60,22 @@ namespace Google.Protobuf.Reflection if (descriptor.File.Proto.Syntax == "proto2") { MethodInfo hasMethod = property.DeclaringType.GetRuntimeProperty("Has" + property.Name).GetMethod; - hasDelegate = ReflectionUtil.CreateFuncIMessageBool(hasMethod ?? throw new ArgumentException("Not all required properties/methods are available")); + 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); - clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod ?? throw new ArgumentException("Not all required properties/methods are available")); + if (clearMethod == null) { + throw new ArgumentException("Not all required properties/methods are available"); + } + clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod); } else { - hasDelegate = (_) => throw new InvalidOperationException("HasValue is not implemented for proto3 fields"); var clrType = property.PropertyType; + hasDelegate = message => { + throw new InvalidOperationException("HasValue is not implemented for proto3 fields"); + }; + 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 = diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs index a92519745b..bf467702d9 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs @@ -308,7 +308,7 @@ namespace Google.Protobuf.WellKnownTypes /// true if the two timestamps refer to the same nanosecond public static bool operator ==(Timestamp a, Timestamp b) { - return ReferenceEquals(a, b) || (a is null ? (b is null ? true : false) : a.Equals(b)); + return ReferenceEquals(a, b) || (a == null ? (b == null ? true : false) : a.Equals(b)); } /// From 3d207c33a4962b4e42ad6072b59ef5fd54e0656c Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Mon, 10 Dec 2018 13:41:15 -0800 Subject: [PATCH 04/70] Fix TimestampPartial operator == overload implementation: Cannot call == inside it, otherwise it would cause stack overflow --- csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs index bf467702d9..2f5172f1ca 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs @@ -308,7 +308,7 @@ namespace Google.Protobuf.WellKnownTypes /// true if the two timestamps refer to the same nanosecond public static bool operator ==(Timestamp a, Timestamp b) { - return ReferenceEquals(a, b) || (a == null ? (b == null ? true : false) : a.Equals(b)); + return ReferenceEquals(a, b) || (ReferenceEquals(a, null) ? (ReferenceEquals(b, null) ? true : false) : a.Equals(b)); } /// From db0a9e0b962084cdb7f51a31d9ed670f54189981 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Mon, 10 Dec 2018 15:21:01 -0800 Subject: [PATCH 05/70] Add 6 to the core protobuf C# project to prevent future incompatibility --- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 8ea3818a4a..e65d3969d5 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -5,6 +5,7 @@ Copyright 2015, Google Inc. Google Protocol Buffers 3.6.1 + 6 Google Inc. netstandard1.0;net45 true From 8bd15429800124fcb6c2404216531b4e6c46d786 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 10 Dec 2018 16:32:56 -0800 Subject: [PATCH 06/70] Add docker file for php testing. (#5447) --- .../linux/dockerfile/push_testing_images.sh | 29 +++ kokoro/linux/dockerfile/test/php/Dockerfile | 166 ++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100755 kokoro/linux/dockerfile/push_testing_images.sh create mode 100644 kokoro/linux/dockerfile/test/php/Dockerfile diff --git a/kokoro/linux/dockerfile/push_testing_images.sh b/kokoro/linux/dockerfile/push_testing_images.sh new file mode 100755 index 0000000000..ec1ead57cf --- /dev/null +++ b/kokoro/linux/dockerfile/push_testing_images.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -ex + +cd $(dirname $0)/../../.. +git_root=$(pwd) +cd - + +DOCKERHUB_ORGANIZATION=protobuf + +for DOCKERFILE_DIR in test/* +do + # Generate image name based on Dockerfile checksum. That works well as long + # as can count on dockerfiles being written in a way that changing the logical + # contents of the docker image always changes the SHA (e.g. using "ADD file" + # cmd in the dockerfile in not ok as contents of the added file will not be + # reflected in the SHA). + DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) + + echo $DOCKER_IMAGE_NAME + # skip the image if it already exists in the repo + curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/latest > /dev/null \ + && continue + + docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} ${DOCKERFILE_DIR} + + # "docker login" needs to be run in advance + docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} +done diff --git a/kokoro/linux/dockerfile/test/php/Dockerfile b/kokoro/linux/dockerfile/test/php/Dockerfile new file mode 100644 index 0000000000..8cb74c69cf --- /dev/null +++ b/kokoro/linux/dockerfile/test/php/Dockerfile @@ -0,0 +1,166 @@ +FROM debian:stretch + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + php \ + libxml2-dev \ + && apt-get clean + +# Install other dependencies +RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h +RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-2.6.4.tar.gz \ + && cd /var/local/bison-2.6.4 \ + && ./configure \ + && make \ + && make install + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php +RUN mv composer.phar /usr/local/bin/composer + +# Download php source code +RUN git clone https://github.com/php/php-src + +# php 5.5 +RUN cd php-src \ + && git checkout PHP-5.5.38 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure --enable-bcmath --prefix=/usr/local/php-5.5 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-4.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-5.5 \ + && mv phpunit /usr/local/php-5.5-zts + +# php 5.6 +RUN cd php-src \ + && git checkout PHP-5.6.39 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure --enable-bcmath --prefix=/usr/local/php-5.6 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.6-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-5.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-5.6 \ + && mv phpunit /usr/local/php-5.6-zts + +# php 7.0 +RUN cd php-src \ + && git checkout PHP-7.0.33 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure --enable-bcmath --prefix=/usr/local/php-7.0 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.0-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-6.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.0 \ + && mv phpunit /usr/local/php-7.0-zts + +# php 7.1 +RUN cd php-src \ + && git checkout PHP-7.1.25 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure --enable-bcmath --prefix=/usr/local/php-7.1 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.1-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.1 \ + && mv phpunit /usr/local/php-7.1-zts + +# php 7.2 +RUN cd php-src \ + && git checkout PHP-7.2.13 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure --enable-bcmath --prefix=/usr/local/php-7.2 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.2-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.2 \ + && mv phpunit /usr/local/php-7.2-zts + +# php 7.3 +RUN cd php-src \ + && git checkout PHP-7.3.0 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure --enable-bcmath --prefix=/usr/local/php-7.3 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.3-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.3 \ + && mv phpunit /usr/local/php-7.3-zts From 802d543173d39ad4087cb188008a6eb01c6cef96 Mon Sep 17 00:00:00 2001 From: Cody Schroeder Date: Tue, 11 Dec 2018 11:58:26 -0800 Subject: [PATCH 07/70] Add Bazel config for zlib support (#5389) * Add Bazel config for optional zlib support * Add hard dependency on zlib * Remove unused config_setting --- BUILD | 16 +++++++++-- WORKSPACE | 16 ++++++++++- third_party/zlib.BUILD | 60 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 third_party/zlib.BUILD diff --git a/BUILD b/BUILD index 80ae3e5297..eb8077ae74 100644 --- a/BUILD +++ b/BUILD @@ -15,6 +15,12 @@ config_setting( }, ) +################################################################################ +# ZLIB configuration +################################################################################ + +ZLIB_DEPS = ["//external:zlib"] + ################################################################################ # Protobuf Runtime Library ################################################################################ @@ -42,6 +48,7 @@ COPTS = select({ ":msvc" : MSVC_COPTS, "//conditions:default": [ "-DHAVE_PTHREAD", + "-DHAVE_ZLIB", "-Wall", "-Woverloaded-virtual", "-Wno-sign-compare", @@ -117,6 +124,11 @@ cc_library( visibility = ["//visibility:public"], ) +PROTOBUF_DEPS = select({ + ":msvc": [], + "//conditions:default": ZLIB_DEPS, +}) + cc_library( name = "protobuf", srcs = [ @@ -182,7 +194,7 @@ cc_library( includes = ["src/"], linkopts = LINK_OPTS, visibility = ["//visibility:public"], - deps = [":protobuf_lite"], + deps = [":protobuf_lite"] + PROTOBUF_DEPS, ) # This provides just the header files for use in projects that need to build @@ -590,7 +602,7 @@ cc_test( ":protobuf", ":protoc_lib", "//external:gtest_main", - ], + ] + PROTOBUF_DEPS, ) ################################################################################ diff --git a/WORKSPACE b/WORKSPACE index f3020843f1..0fa64583a9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,10 +1,11 @@ workspace(name = "com_google_protobuf") + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") new_local_repository( name = "submodule_gmock", + build_file = "@//:third_party/googletest/BUILD.bazel", path = "third_party/googletest", - build_file = "@//:third_party/googletest/BUILD.bazel" ) http_archive( @@ -21,6 +22,14 @@ http_archive( urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"], ) +http_archive( + name = "net_zlib", + build_file = "//:third_party/zlib.BUILD", + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", + strip_prefix = "zlib-1.2.11", + urls = ["https://zlib.net/zlib-1.2.11.tar.gz"], +) + bind( name = "python_headers", actual = "//util/python:python_headers", @@ -60,3 +69,8 @@ bind( name = "gson", actual = "@gson_maven//jar", ) + +bind( + name = "zlib", + actual = "@net_zlib//:zlib", +) diff --git a/third_party/zlib.BUILD b/third_party/zlib.BUILD new file mode 100644 index 0000000000..f948117417 --- /dev/null +++ b/third_party/zlib.BUILD @@ -0,0 +1,60 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) # BSD/MIT-like license (for zlib) + +_ZLIB_HEADERS = [ + "crc32.h", + "deflate.h", + "gzguts.h", + "inffast.h", + "inffixed.h", + "inflate.h", + "inftrees.h", + "trees.h", + "zconf.h", + "zlib.h", + "zutil.h", +] + +_ZLIB_PREFIXED_HEADERS = ["zlib/include/" + hdr for hdr in _ZLIB_HEADERS] + +# In order to limit the damage from the `includes` propagation +# via `:zlib`, copy the public headers to a subdirectory and +# expose those. +genrule( + name = "copy_public_headers", + srcs = _ZLIB_HEADERS, + outs = _ZLIB_PREFIXED_HEADERS, + cmd = "cp $(SRCS) $(@D)/zlib/include/", + visibility = ["//visibility:private"], +) + +cc_library( + name = "zlib", + srcs = [ + "adler32.c", + "compress.c", + "crc32.c", + "deflate.c", + "gzclose.c", + "gzlib.c", + "gzread.c", + "gzwrite.c", + "infback.c", + "inffast.c", + "inflate.c", + "inftrees.c", + "trees.c", + "uncompr.c", + "zutil.c", + # Include the un-prefixed headers in srcs to work + # around the fact that zlib isn't consistent in its + # choice of <> or "" delimiter when including itself. + ] + _ZLIB_HEADERS, + hdrs = _ZLIB_PREFIXED_HEADERS, + copts = [ + "-Wno-unused-variable", + "-Wno-implicit-function-declaration", + ], + includes = ["zlib/include/"], +) From 1d90079873a21de9ca5ae746c574a66de4af69c2 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 11 Dec 2018 14:00:51 -0800 Subject: [PATCH 08/70] Add composer config to Dockerfile (#5451) --- kokoro/linux/dockerfile/test/php/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kokoro/linux/dockerfile/test/php/Dockerfile b/kokoro/linux/dockerfile/test/php/Dockerfile index 8cb74c69cf..10862f3e2e 100644 --- a/kokoro/linux/dockerfile/test/php/Dockerfile +++ b/kokoro/linux/dockerfile/test/php/Dockerfile @@ -164,3 +164,6 @@ RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ && chmod +x phpunit \ && cp phpunit /usr/local/php-7.3 \ && mv phpunit /usr/local/php-7.3-zts + +# Additional config +RUN composer config -g -- disable-tls true From 9851c703ae371236e4d4b4dbe537d3de8760931e Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Tue, 11 Dec 2018 16:43:05 -0800 Subject: [PATCH 09/70] Rename StringPieceTrimWhitespace() for rewriting purposes. --- .../protobuf/compiler/objectivec/objectivec_helpers.cc | 6 +++--- .../protobuf/compiler/objectivec/objectivec_helpers.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index c25b0c9de9..ef81f5776f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -364,7 +364,7 @@ string StripProto(const string& filename) { } } -void StringPieceTrimWhitespace(StringPiece* input) { +void TrimWhitespace(StringPiece* input) { while (!input->empty() && ascii_isspace(*input->data())) { input->remove_prefix(1); } @@ -1054,8 +1054,8 @@ bool ExpectedPrefixesCollector::ConsumeLine( } StringPiece package(line, 0, offset); StringPiece prefix(line, offset + 1, line.length() - offset - 1); - StringPieceTrimWhitespace(&package); - StringPieceTrimWhitespace(&prefix); + TrimWhitespace(&package); + TrimWhitespace(&prefix); // Don't really worry about error checking the package/prefix for // being valid. Assume the file is validated when it is created/edited. (*prefix_map_)[package.ToString()] = prefix.ToString(); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index e2f70245d9..98ec7db8fb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -62,7 +62,7 @@ string PROTOC_EXPORT EscapeTrigraphs(const string& to_escape); string PROTOC_EXPORT StripProto(const string& filename); // Remove white space from either end of a StringPiece. -void PROTOC_EXPORT StringPieceTrimWhitespace(StringPiece* input); +void PROTOC_EXPORT TrimWhitespace(StringPiece* input); // Returns true if the name requires a ns_returns_not_retained attribute applied // to it. From e03c0d22a76c302b9af50260817eb9cc10b800bc Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 11 Dec 2018 15:57:26 -0800 Subject: [PATCH 10/70] Updated Bazel workspace in examples/ to handle zlib dependency To make this work, I created a symlink to the existing zlib.BUILD file. Maybe there is a better way to do this, but this is at least a quick workaround to fix the build. --- Makefile.am | 1 + examples/WORKSPACE | 15 +++++++++++++++ examples/third_party/zlib.BUILD | 1 + 3 files changed, 17 insertions(+) create mode 120000 examples/third_party/zlib.BUILD diff --git a/Makefile.am b/Makefile.am index 4873663094..4e71a37d05 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1103,6 +1103,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ examples/list_people.py \ examples/list_people_test.go \ examples/pubspec.yaml \ + examples/third_party/zlib.BUILD \ protobuf.bzl \ python/release/wheel/build_wheel_manylinux.sh \ python/release/wheel/Dockerfile \ diff --git a/examples/WORKSPACE b/examples/WORKSPACE index f6c0ef09b0..878b25582f 100644 --- a/examples/WORKSPACE +++ b/examples/WORKSPACE @@ -1,3 +1,5 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + # This com_google_protobuf repository is required for proto_library rule. # It provides the protocol compiler binary (i.e., protoc). http_archive( @@ -39,5 +41,18 @@ http_archive( urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"], ) +http_archive( + name = "net_zlib", + build_file = "//:third_party/zlib.BUILD", + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", + strip_prefix = "zlib-1.2.11", + urls = ["https://zlib.net/zlib-1.2.11.tar.gz"], +) + +bind( + name = "zlib", + actual = "@net_zlib//:zlib", +) + load("@bazel_skylib//lib:versions.bzl", "versions") versions.check(minimum_bazel_version = "0.5.4") diff --git a/examples/third_party/zlib.BUILD b/examples/third_party/zlib.BUILD new file mode 120000 index 0000000000..1bbef2dbab --- /dev/null +++ b/examples/third_party/zlib.BUILD @@ -0,0 +1 @@ +../../third_party/zlib.BUILD \ No newline at end of file From 15c30d72a4c9c6763bbbb60decbe2ebc672f4ce4 Mon Sep 17 00:00:00 2001 From: Hao Nguyen <45579440+haon4@users.noreply.github.com> Date: Wed, 12 Dec 2018 15:38:14 -0800 Subject: [PATCH 11/70] Create a script to help update the version automatically (#5454) * Create a script to help update the version automatically * Update comment in the update_version script * Update script to fix special handling for common.h and Makefile.am * Revise update_version script to only update the other constants in common.h if it is a major release. Reset Makefile.am version to 17:0:0 --- src/Makefile.am | 8 +++-- update_version.sh | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100755 update_version.sh diff --git a/src/Makefile.am b/src/Makefile.am index e5ba9b728b..2d7e4f0371 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,8 @@ else PTHREAD_DEF = endif +PROTOBUF_VERSION = 17:0:0 + if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison # in Google so our code base have tons of such warnings). @@ -169,7 +171,7 @@ nobase_include_HEADERS = \ lib_LTLIBRARIES = libprotobuf-lite.la libprotobuf.la libprotoc.la libprotobuf_lite_la_LIBADD = $(PTHREAD_LIBS) $(LIBATOMIC_LIBS) -libprotobuf_lite_la_LDFLAGS = -version-info 17:0:0 -export-dynamic -no-undefined +libprotobuf_lite_la_LDFLAGS = -version-info $(PROTOBUF_VERSION) -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotobuf_lite_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf-lite.map EXTRA_libprotobuf_lite_la_DEPENDENCIES = libprotobuf-lite.map @@ -214,7 +216,7 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/io/zero_copy_stream_impl_lite.cc libprotobuf_la_LIBADD = $(PTHREAD_LIBS) $(LIBATOMIC_LIBS) -libprotobuf_la_LDFLAGS = -version-info 17:0:0 -export-dynamic -no-undefined +libprotobuf_la_LDFLAGS = -version-info $(PROTOBUF_VERSION) -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotobuf_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf.map EXTRA_libprotobuf_la_DEPENDENCIES = libprotobuf.map @@ -305,7 +307,7 @@ libprotobuf_la_SOURCES = \ nodist_libprotobuf_la_SOURCES = $(nodist_libprotobuf_lite_la_SOURCES) libprotoc_la_LIBADD = $(PTHREAD_LIBS) libprotobuf.la -libprotoc_la_LDFLAGS = -version-info 17:0:0 -export-dynamic -no-undefined +libprotoc_la_LDFLAGS = -version-info $(PROTOBUF_VERSION) -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotoc_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotoc.map EXTRA_libprotoc_la_DEPENDENCIES = libprotoc.map diff --git a/update_version.sh b/update_version.sh new file mode 100755 index 0000000000..746578b75e --- /dev/null +++ b/update_version.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# Helper script to update version number in various files. +# Each file has it own string matching syntax to avoid accidentally updating +# the wrong version number of other dependencies. + +if [ "$#" -eq 1 ]; then + VERSION=$1 + IFS='.' read -ra VERSION_INFO <<< "$VERSION" +fi + +if [ "$#" -ne 1 ] || [ ${#VERSION_INFO[@]} -ne 3 ]; then + echo " +Usage: $0 VERSION + +Example: +$0 2.1.3 +" + exit 1 +fi + +update_version() { + file=$2 + # Replace the version number in the given file. + sed -ri "$1" $file + # Verify that the version number is updated successfully. + if [ $(grep -c $VERSION $file) -eq 0 ]; then + echo "$file version is not updated successfully. Please verify." + exit 1 + fi +} + +update_version "s/\[Protocol Buffers\],\[.*\],\[protobuf@googlegroups.com\]/[Protocol Buffers],[$VERSION],[protobuf@googlegroups.com]/g" configure.ac +update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" java/pom.xml +update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" java/core/pom.xml +update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" java/util/pom.xml +update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" protoc-artifacts/pom.xml +update_version "s/^ s.version = '.*'/ s.version = '$VERSION'/g" Protobuf.podspec +update_version "s/^__version__ = '.*'/__version__ = '$VERSION'/g" python/google/protobuf/__init__.py +update_version "s/^ .*<\/VersionPrefix>/ $VERSION<\/VersionPrefix>/g" csharp/src/Google.Protobuf/Google.Protobuf.csproj +update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" csharp/Google.Protobuf.Tools.nuspec +update_version "s/^ \"version\": \".*\",/ \"version\": \"$VERSION\",/g" js/package.json +update_version "s/^ s.version = \".*\"/ s.version = \"$VERSION\"/g" ruby/google-protobuf.gemspec + +# Special handling for C++ file, where version is X.Y.Z is transformed to X00Y00Z +CPP_VERSION=${VERSION_INFO[0]}00${VERSION_INFO[1]}00${VERSION_INFO[2]} +sed -ri "s/^#define GOOGLE_PROTOBUF_VERSION .*/#define GOOGLE_PROTOBUF_VERSION $CPP_VERSION/g" src/google/protobuf/stubs/common.h + +# Only update these constants if it is a major release. +if [ ${VERSION_INFO[2]} -eq 0 ]; then + sed -ri "s/^#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION .*/#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION $CPP_VERSION/g" src/google/protobuf/stubs/common.h + sed -ri "s/^#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION .*/#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION $CPP_VERSION/g" src/google/protobuf/stubs/common.h + sed -ri "s/^static const int kMinHeaderVersionForLibrary = .*/static const int kMinHeaderVersionForLibrary = $CPP_VERSION;/g" src/google/protobuf/stubs/common.h + sed -ri "s/^static const int kMinHeaderVersionForProtoc = .*/static const int kMinHeaderVersionForProtoc = $CPP_VERSION;/g" src/google/protobuf/stubs/common.h + + if [ $(grep -c $CPP_VERSION src/google/protobuf/stubs/common.h) -ne 5 ]; then + echo "src/google/protobuf/stubs/common.h version is not updated successfully. Please verify." + exit 1 + fi +else + if [ $(grep -c $CPP_VERSION src/google/protobuf/stubs/common.h) -ne 1 ]; then + echo "src/google/protobuf/stubs/common.h version is not updated successfully. Please verify." + exit 1 + fi +fi + +# Special handling for src/Makefile.am. If version is X.Y.Z, then the +# version here should be [Y+OFFSET]:Z:0 where OFFSET is some constant +# such that the version number is always increasing. +PROTOBUF_VERSION_OFFSET=11 +EXPECTED_MAJOR_VERSION=3 +if [ ${VERSION_INFO[0]} -ne ${EXPECTED_MAJOR_VERSION} ]; then + echo "Major protobuf version has changed. Please update $0 to readjust +the PROTOBUF_VERSION_OFFSET and EXPECTED_MAJOR_VERSION such that the +PROTOBUF_VERSION in src/Makefile.am is always increasing. + " + exit 1 +fi + +PROTOBUF_VERSION_INFO=$((${VERSION_INFO[1]} + $PROTOBUF_VERSION_OFFSET)):${VERSION_INFO[2]}:0 +sed -ri "s/^PROTOBUF_VERSION = .*/PROTOBUF_VERSION = $PROTOBUF_VERSION_INFO/g" src/Makefile.am + +if [ $(grep -c $PROTOBUF_VERSION_INFO src/Makefile.am) -eq 0 ]; then + echo "src/Makefile.am version is not updated successfully. Please verify." + exit 1 +fi From b6311767e61c77f0adaea3c389d7a2963201c75d Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Tue, 11 Dec 2018 16:32:48 -0800 Subject: [PATCH 12/70] Minimize amount of filepaths being copied into protos. By putting the NSAssert behind a DEBUG flag we aren't copying filepaths into release builds. --- objectivec/google/protobuf/Any.pbobjc.m | 4 ++- objectivec/google/protobuf/Api.pbobjc.m | 12 +++++-- objectivec/google/protobuf/Duration.pbobjc.m | 4 ++- objectivec/google/protobuf/Empty.pbobjc.m | 4 ++- objectivec/google/protobuf/FieldMask.pbobjc.m | 4 ++- .../google/protobuf/SourceContext.pbobjc.m | 4 ++- objectivec/google/protobuf/Struct.pbobjc.m | 12 +++++-- objectivec/google/protobuf/Timestamp.pbobjc.m | 4 ++- objectivec/google/protobuf/Type.pbobjc.m | 20 ++++++++--- objectivec/google/protobuf/Wrappers.pbobjc.m | 36 ++++++++++++++----- .../compiler/objectivec/objectivec_message.cc | 4 ++- 11 files changed, 81 insertions(+), 27 deletions(-) diff --git a/objectivec/google/protobuf/Any.pbobjc.m b/objectivec/google/protobuf/Any.pbobjc.m index d210643f05..7ca84ff40a 100644 --- a/objectivec/google/protobuf/Any.pbobjc.m +++ b/objectivec/google/protobuf/Any.pbobjc.m @@ -98,7 +98,9 @@ typedef struct GPBAny__storage_ { "\001\001\004\241!!\000"; [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; #endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/Api.pbobjc.m b/objectivec/google/protobuf/Api.pbobjc.m index 58b47157de..d63a3e696a 100644 --- a/objectivec/google/protobuf/Api.pbobjc.m +++ b/objectivec/google/protobuf/Api.pbobjc.m @@ -152,7 +152,9 @@ typedef struct GPBApi__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBApi__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -276,7 +278,9 @@ typedef struct GPBMethod__storage_ { "\002\002\007\244\241!!\000\004\010\244\241!!\000"; [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; #endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -342,7 +346,9 @@ typedef struct GPBMixin__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBMixin__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/Duration.pbobjc.m b/objectivec/google/protobuf/Duration.pbobjc.m index bafb64a04f..3fa702435f 100644 --- a/objectivec/google/protobuf/Duration.pbobjc.m +++ b/objectivec/google/protobuf/Duration.pbobjc.m @@ -93,7 +93,9 @@ typedef struct GPBDuration__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBDuration__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/Empty.pbobjc.m b/objectivec/google/protobuf/Empty.pbobjc.m index 506b500e04..51f15f365c 100644 --- a/objectivec/google/protobuf/Empty.pbobjc.m +++ b/objectivec/google/protobuf/Empty.pbobjc.m @@ -69,7 +69,9 @@ typedef struct GPBEmpty__storage_ { fieldCount:0 storageSize:sizeof(GPBEmpty__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/FieldMask.pbobjc.m b/objectivec/google/protobuf/FieldMask.pbobjc.m index b0915af450..ff27318a21 100644 --- a/objectivec/google/protobuf/FieldMask.pbobjc.m +++ b/objectivec/google/protobuf/FieldMask.pbobjc.m @@ -82,7 +82,9 @@ typedef struct GPBFieldMask__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBFieldMask__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/SourceContext.pbobjc.m b/objectivec/google/protobuf/SourceContext.pbobjc.m index 83bfa3460b..c93871ed3e 100644 --- a/objectivec/google/protobuf/SourceContext.pbobjc.m +++ b/objectivec/google/protobuf/SourceContext.pbobjc.m @@ -82,7 +82,9 @@ typedef struct GPBSourceContext__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBSourceContext__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/Struct.pbobjc.m b/objectivec/google/protobuf/Struct.pbobjc.m index 816fd6df56..169a275813 100644 --- a/objectivec/google/protobuf/Struct.pbobjc.m +++ b/objectivec/google/protobuf/Struct.pbobjc.m @@ -118,7 +118,9 @@ typedef struct GPBStruct__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBStruct__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -222,7 +224,9 @@ typedef struct GPBValue__storage_ { [localDescriptor setupOneofs:oneofs count:(uint32_t)(sizeof(oneofs) / sizeof(char*)) firstHasIndex:-1]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -282,7 +286,9 @@ typedef struct GPBListValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBListValue__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/Timestamp.pbobjc.m b/objectivec/google/protobuf/Timestamp.pbobjc.m index 4ab159fb9c..b6393e37aa 100644 --- a/objectivec/google/protobuf/Timestamp.pbobjc.m +++ b/objectivec/google/protobuf/Timestamp.pbobjc.m @@ -93,7 +93,9 @@ typedef struct GPBTimestamp__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBTimestamp__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/Type.pbobjc.m b/objectivec/google/protobuf/Type.pbobjc.m index bb64d87649..6b88a4b5c6 100644 --- a/objectivec/google/protobuf/Type.pbobjc.m +++ b/objectivec/google/protobuf/Type.pbobjc.m @@ -178,7 +178,9 @@ typedef struct GPBType__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBType__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -336,7 +338,9 @@ typedef struct GPBField__storage_ { "\001\006\004\241!!\000"; [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; #endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -561,7 +565,9 @@ typedef struct GPBEnum__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBEnum__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -638,7 +644,9 @@ typedef struct GPBEnumValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBEnumValue__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -692,7 +700,9 @@ typedef struct GPBOption__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBOption__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/google/protobuf/Wrappers.pbobjc.m b/objectivec/google/protobuf/Wrappers.pbobjc.m index 5479eb127b..0a163fa8ff 100644 --- a/objectivec/google/protobuf/Wrappers.pbobjc.m +++ b/objectivec/google/protobuf/Wrappers.pbobjc.m @@ -82,7 +82,9 @@ typedef struct GPBDoubleValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBDoubleValue__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -125,7 +127,9 @@ typedef struct GPBFloatValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBFloatValue__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -168,7 +172,9 @@ typedef struct GPBInt64Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBInt64Value__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -211,7 +217,9 @@ typedef struct GPBUInt64Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBUInt64Value__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -254,7 +262,9 @@ typedef struct GPBInt32Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBInt32Value__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -297,7 +307,9 @@ typedef struct GPBUInt32Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBUInt32Value__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -339,7 +351,9 @@ typedef struct GPBBoolValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBBoolValue__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -382,7 +396,9 @@ typedef struct GPBStringValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBStringValue__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -425,7 +441,9 @@ typedef struct GPBBytesValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBBytesValue__storage_) flags:GPBDescriptorInitializationFlag_None]; - NSAssert(descriptor == nil, @"Startup recursed!"); + #if defined(DEBUG) && DEBUG + NSAssert(descriptor == nil, @"Startup recursed!"); + #endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 71ca00d592..2f1f08d0f9 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -604,7 +604,9 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { "suffix", suffix_added); } printer->Print( - " NSAssert(descriptor == nil, @\"Startup recursed!\");\n" + " #if defined(DEBUG) && DEBUG\n" + " NSAssert(descriptor == nil, @\"Startup recursed!\");\n" + " #endif // DEBUG\n" " descriptor = localDescriptor;\n" " }\n" " return descriptor;\n" From 5518c016a7b9088bfbb3436e352b3e8ad308c6b4 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 13 Dec 2018 14:45:34 -0800 Subject: [PATCH 13/70] Compile php source to enable openssl and add php7.3 support (#5466) --- .../linux/dockerfile/push_testing_images.sh | 2 +- kokoro/linux/dockerfile/test/php/Dockerfile | 100 ++++++++++++++---- 2 files changed, 83 insertions(+), 19 deletions(-) diff --git a/kokoro/linux/dockerfile/push_testing_images.sh b/kokoro/linux/dockerfile/push_testing_images.sh index ec1ead57cf..8bc1097ccb 100755 --- a/kokoro/linux/dockerfile/push_testing_images.sh +++ b/kokoro/linux/dockerfile/push_testing_images.sh @@ -6,7 +6,7 @@ cd $(dirname $0)/../../.. git_root=$(pwd) cd - -DOCKERHUB_ORGANIZATION=protobuf +DOCKERHUB_ORGANIZATION=protobuftesting for DOCKERFILE_DIR in test/* do diff --git a/kokoro/linux/dockerfile/test/php/Dockerfile b/kokoro/linux/dockerfile/test/php/Dockerfile index 10862f3e2e..632d783a44 100644 --- a/kokoro/linux/dockerfile/test/php/Dockerfile +++ b/kokoro/linux/dockerfile/test/php/Dockerfile @@ -1,8 +1,8 @@ -FROM debian:stretch +FROM debian:jessie # Install dependencies. We start with the basic ones require to build protoc # and the C++ build -RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ +RUN apt-get update && apt-get install -y \ autoconf \ autotools-dev \ build-essential \ @@ -24,8 +24,15 @@ RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ # Install php dependencies RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ - php \ + php5 \ + libcurl4-openssl-dev \ + libgmp-dev \ + libgmp3-dev \ + libssl-dev \ libxml2-dev \ + unzip \ + zlib1g-dev \ + pkg-config \ && apt-get clean # Install other dependencies @@ -50,12 +57,22 @@ RUN cd php-src \ && git checkout PHP-5.5.38 \ && ./buildconf --force RUN cd php-src \ - && ./configure --enable-bcmath --prefix=/usr/local/php-5.5 \ + && ./configure \ + --enable-bcmath \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.5 \ && make \ && make install \ && make clean RUN cd php-src \ - && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts \ + && ./configure \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.5-zts \ && make \ && make install \ && make clean @@ -70,12 +87,22 @@ RUN cd php-src \ && git checkout PHP-5.6.39 \ && ./buildconf --force RUN cd php-src \ - && ./configure --enable-bcmath --prefix=/usr/local/php-5.6 \ + && ./configure \ + --enable-bcmath \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.6 \ && make \ && make install \ && make clean RUN cd php-src \ - && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.6-zts \ + && ./configure \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.6-zts \ && make \ && make install \ && make clean @@ -90,12 +117,22 @@ RUN cd php-src \ && git checkout PHP-7.0.33 \ && ./buildconf --force RUN cd php-src \ - && ./configure --enable-bcmath --prefix=/usr/local/php-7.0 \ + && ./configure \ + --enable-bcmath \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0 \ && make \ && make install \ && make clean RUN cd php-src \ - && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.0-zts \ + && ./configure \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0-zts \ && make \ && make install \ && make clean @@ -110,12 +147,22 @@ RUN cd php-src \ && git checkout PHP-7.1.25 \ && ./buildconf --force RUN cd php-src \ - && ./configure --enable-bcmath --prefix=/usr/local/php-7.1 \ + && ./configure \ + --enable-bcmath \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1 \ && make \ && make install \ && make clean RUN cd php-src \ - && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.1-zts \ + && ./configure \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1-zts \ && make \ && make install \ && make clean @@ -130,12 +177,22 @@ RUN cd php-src \ && git checkout PHP-7.2.13 \ && ./buildconf --force RUN cd php-src \ - && ./configure --enable-bcmath --prefix=/usr/local/php-7.2 \ + && ./configure \ + --enable-bcmath \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2 \ && make \ && make install \ && make clean RUN cd php-src \ - && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.2-zts \ + && ./configure \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2-zts \ && make \ && make install \ && make clean @@ -150,12 +207,22 @@ RUN cd php-src \ && git checkout PHP-7.3.0 \ && ./buildconf --force RUN cd php-src \ - && ./configure --enable-bcmath --prefix=/usr/local/php-7.3 \ + && ./configure \ + --enable-bcmath \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3 \ && make \ && make install \ && make clean RUN cd php-src \ - && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.3-zts \ + && ./configure \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3-zts \ && make \ && make install \ && make clean @@ -164,6 +231,3 @@ RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ && chmod +x phpunit \ && cp phpunit /usr/local/php-7.3 \ && mv phpunit /usr/local/php-7.3-zts - -# Additional config -RUN composer config -g -- disable-tls true From 6cb87bd157876b68b41703158380298b9a03c597 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Thu, 13 Dec 2018 15:20:25 -0800 Subject: [PATCH 14/70] Use docker for csharp, java_compatibility, and python_compatibility. Remove prepare_build_linux_rc that is no longer needed. --- java/compatibility_tests/v2.5.0/test.sh | 17 ++++++++++------- kokoro/linux/csharp/build.sh | 16 +++++++++++----- kokoro/linux/java_compatibility/build.sh | 16 +++++++++++----- kokoro/linux/prepare_build_linux_rc | 13 ------------- kokoro/linux/python_compatibility/build.sh | 16 +++++++++++----- 5 files changed, 43 insertions(+), 35 deletions(-) delete mode 100644 kokoro/linux/prepare_build_linux_rc diff --git a/java/compatibility_tests/v2.5.0/test.sh b/java/compatibility_tests/v2.5.0/test.sh index 2ea5b9302c..eea8328504 100755 --- a/java/compatibility_tests/v2.5.0/test.sh +++ b/java/compatibility_tests/v2.5.0/test.sh @@ -5,6 +5,9 @@ set -ex # Change to the script's directory. cd $(dirname $0) +MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository +MVN="mvn --batch-mode -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY" + # Version of the tests (i.e., the version of protobuf from where we extracted # these tests). TEST_VERSION=`grep "^ .*" pom.xml | sed "s| \(.*\)|\1|"` @@ -59,7 +62,7 @@ echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION" # Build and install protobuf-java-$VERSION_NUMBER.jar [ -f ../../core/target/protobuf-java-$VERSION_NUMBER.jar ] || { pushd ../.. - mvn install -Dmaven.test.skip=true + $MVN install -Dmaven.test.skip=true popd } @@ -81,7 +84,7 @@ chmod +x protoc # Test A.1: # protos: use new version # more_protos: use old version -mvn clean test \ +$MVN clean test \ -Dprotobuf.test.source.path=$(pwd)/protobuf \ -Dprotoc.path=$(pwd)/protoc \ -Dprotos.protoc.path=$(pwd)/../../../src/protoc \ @@ -90,7 +93,7 @@ mvn clean test \ # Test A.2: # protos: use old version # more_protos: use new version -mvn clean test \ +$MVN clean test \ -Dprotobuf.test.source.path=$(pwd)/protobuf \ -Dprotoc.path=$(pwd)/protoc \ -Dmore_protos.protoc.path=$(pwd)/../../../src/protoc \ @@ -103,12 +106,12 @@ mvn clean test \ # make it easier to run binary compatibility test (where we will need to run # the jar files directly). cd deps -mvn assembly:single +$MVN assembly:single cd .. cp -f deps/target/compatibility-test-deps-${TEST_VERSION}-jar-with-dependencies.jar deps.jar # Build the old version of all 3 artifacts. -mvn clean install -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/protoc -Dprotobuf.version=$OLD_VERSION +$MVN clean install -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/protoc -Dprotobuf.version=$OLD_VERSION cp -f protos/target/compatibility-protos-${TEST_VERSION}.jar protos.jar cp -f more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar more_protos.jar cp -f tests/target/compatibility-tests-${TEST_VERSION}.jar tests.jar @@ -125,7 +128,7 @@ cd .. # Test B.2: update protos.jar only. cd protos -mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER +$MVN clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER cd .. cd protobuf java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos/target/compatibility-protos-${TEST_VERSION}.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS @@ -133,7 +136,7 @@ cd .. # Test B.3: update more_protos.jar only. cd more_protos -mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER +$MVN clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER cd .. cd protobuf java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS diff --git a/kokoro/linux/csharp/build.sh b/kokoro/linux/csharp/build.sh index de178b844d..27cb549dac 100755 --- a/kokoro/linux/csharp/build.sh +++ b/kokoro/linux/csharp/build.sh @@ -1,11 +1,17 @@ #!/bin/bash # -# Build file to set up and run tests +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. # Change to repo root cd $(dirname $0)/../../.. -# Prepare worker environment to run tests -source kokoro/linux/prepare_build_linux_rc - -./tests.sh csharp +export DOCKERFILE_DIR=kokoro/linux/64-bit +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="csharp" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/java_compatibility/build.sh b/kokoro/linux/java_compatibility/build.sh index b1ef27963f..de88454fc7 100755 --- a/kokoro/linux/java_compatibility/build.sh +++ b/kokoro/linux/java_compatibility/build.sh @@ -1,11 +1,17 @@ #!/bin/bash # -# Build file to set up and run tests +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. # Change to repo root cd $(dirname $0)/../../.. -# Prepare worker environment to run tests -source kokoro/linux/prepare_build_linux_rc - -./tests.sh java_compatibility +export DOCKERFILE_DIR=kokoro/linux/64-bit +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="java_compatibility" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/prepare_build_linux_rc b/kokoro/linux/prepare_build_linux_rc deleted file mode 100644 index d9b3bec3aa..0000000000 --- a/kokoro/linux/prepare_build_linux_rc +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Source this rc script to prepare the environment for Linux builds - -# Set up dotnet -sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main" > /etc/apt/sources.list.d/dotnetdev.list' -sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF -sudo apt-get update -# We use the .NET Core SDK 2.x to build... -sudo apt-get install -y dotnet-sdk-2.1.3 -# But we also need the 1.x framework to test against, as we -# target netstandard1.x -sudo apt-get install -y dotnet-sharedframework-microsoft.netcore.app-1.0.5 diff --git a/kokoro/linux/python_compatibility/build.sh b/kokoro/linux/python_compatibility/build.sh index 041e65ffb6..1ba35394d1 100755 --- a/kokoro/linux/python_compatibility/build.sh +++ b/kokoro/linux/python_compatibility/build.sh @@ -1,11 +1,17 @@ #!/bin/bash # -# Build file to set up and run tests +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. # Change to repo root cd $(dirname $0)/../../.. -# Prepare worker environment to run tests -source kokoro/linux/prepare_build_linux_rc - -./tests.sh python_compatibility +export DOCKERFILE_DIR=kokoro/linux/64-bit +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python_compatibility" +./kokoro/linux/build_and_run_docker.sh From eff1a6a01492988448685c6f9771e80e735d6030 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 13 Dec 2018 16:29:34 -0800 Subject: [PATCH 15/70] More fixes for import. --- .../compiler/objectivec/objectivec_helpers.cc | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index ef81f5776f..9db79b871c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -659,7 +659,7 @@ string GetCapitalizedType(const FieldDescriptor* field) { // Some compilers report reaching end of function even though all cases of // the enum are handed in the switch. GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; + return string(); } ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type) { @@ -1052,13 +1052,13 @@ bool ExpectedPrefixesCollector::ConsumeLine( line.ToString() + "'."; return false; } - StringPiece package(line, 0, offset); - StringPiece prefix(line, offset + 1, line.length() - offset - 1); + StringPiece package = line.substr(0, offset); + StringPiece prefix = line.substr(offset + 1); TrimWhitespace(&package); TrimWhitespace(&prefix); // Don't really worry about error checking the package/prefix for // being valid. Assume the file is validated when it is created/edited. - (*prefix_map_)[package.ToString()] = prefix.ToString(); + (*prefix_map_)[string(package)] = string(prefix); return true; } @@ -1474,7 +1474,7 @@ class Parser { bool Parser::ParseChunk(StringPiece chunk) { if (!leftover_.empty()) { - chunk.AppendToString(&leftover_); + leftover_ += chunk; p_ = StringPiece(leftover_); } else { p_ = chunk; @@ -1483,7 +1483,7 @@ bool Parser::ParseChunk(StringPiece chunk) { if (p_.empty()) { leftover_.clear(); } else { - leftover_ = p_.ToString(); + leftover_ = string(p_); } return result; } @@ -1506,7 +1506,7 @@ bool Parser::ParseLoop() { while (ReadLine(&p_, &line)) { ++line_; RemoveComment(&line); - StringPieceTrimWhitespace(&line); + TrimWhitespace(&line); if (line.size() == 0) { continue; // Blank line. } @@ -1698,7 +1698,7 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( } StringPiece framework_name(line, 0, offset); StringPiece proto_file_list(line, offset + 1, line.length() - offset - 1); - StringPieceTrimWhitespace(&framework_name); + TrimWhitespace(&framework_name); int start = 0; while (start < proto_file_list.length()) { @@ -1708,24 +1708,24 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( } StringPiece proto_file(proto_file_list, start, offset - start); - StringPieceTrimWhitespace(&proto_file); + TrimWhitespace(&proto_file); if (proto_file.size() != 0) { std::map::iterator existing_entry = - map_->find(proto_file.ToString()); + map_->find(string(proto_file)); if (existing_entry != map_->end()) { std::cerr << "warning: duplicate proto file reference, replacing framework entry for '" - << proto_file.ToString() << "' with '" << framework_name.ToString() + << string(proto_file) << "' with '" << string(framework_name) << "' (was '" << existing_entry->second << "')." << std::endl; std::cerr.flush(); } if (proto_file.find(' ') != StringPiece::npos) { std::cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '" - << proto_file.ToString() << "'" << std::endl; + << string(proto_file) << "'" << std::endl; std::cerr.flush(); } - (*map_)[proto_file.ToString()] = framework_name.ToString(); + (*map_)[string(proto_file)] = string(framework_name); } start = offset + 1; From 401db44e6a1f4216925f26642db3dd68edc1b103 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 13 Dec 2018 17:48:52 -0800 Subject: [PATCH 16/70] More fixes. --- .../compiler/objectivec/objectivec_helpers.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 9db79b871c..1d6aaa9f52 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -48,9 +48,9 @@ #include #include #include +#include #include - // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for errors. @@ -859,7 +859,7 @@ string DefaultValue(const FieldDescriptor* field) { // Some compilers report reaching end of function even though all cases of // the enum are handed in the switch. GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; + return string(); } bool HasNonZeroDefaultValue(const FieldDescriptor* field) { @@ -1047,9 +1047,8 @@ bool ExpectedPrefixesCollector::ConsumeLine( const StringPiece& line, string* out_error) { int offset = line.find('='); if (offset == StringPiece::npos) { - *out_error = - string("Expected prefixes file line without equal sign: '") + - line.ToString() + "'."; + *out_error = string("Expected prefixes file line without equal sign: '") + + string(line) + "'."; return false; } StringPiece package = line.substr(0, offset); @@ -1474,7 +1473,7 @@ class Parser { bool Parser::ParseChunk(StringPiece chunk) { if (!leftover_.empty()) { - leftover_ += chunk; + leftover_ += string(chunk); p_ = StringPiece(leftover_); } else { p_ = chunk; @@ -1693,11 +1692,11 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( if (offset == StringPiece::npos) { *out_error = string("Framework/proto file mapping line without colon sign: '") + - line.ToString() + "'."; + string(line) + "'."; return false; } - StringPiece framework_name(line, 0, offset); - StringPiece proto_file_list(line, offset + 1, line.length() - offset - 1); + StringPiece framework_name = line.substr(0, offset); + StringPiece proto_file_list = line.substr(offset + 1); TrimWhitespace(&framework_name); int start = 0; From 5eb34cd72714668c66339d66a3476c24e279843f Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 13 Dec 2018 18:02:04 -0800 Subject: [PATCH 17/70] More fixes. --- .../compiler/objectivec/objectivec_helpers.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 1d6aaa9f52..3d0b0d2933 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -787,7 +787,7 @@ string GPBGenericValueFieldName(const FieldDescriptor* field) { // Some compilers report reaching end of function even though all cases of // the enum are handed in the switch. GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; + return string(); } @@ -1706,21 +1706,23 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( offset = proto_file_list.length(); } - StringPiece proto_file(proto_file_list, start, offset - start); + StringPiece proto_file = proto_file_list.substr(start, offset - start); TrimWhitespace(&proto_file); if (proto_file.size() != 0) { std::map::iterator existing_entry = map_->find(string(proto_file)); if (existing_entry != map_->end()) { - std::cerr << "warning: duplicate proto file reference, replacing framework entry for '" - << string(proto_file) << "' with '" << string(framework_name) - << "' (was '" << existing_entry->second << "')." << std::endl; + std::cerr << "warning: duplicate proto file reference, replacing " + "framework entry for '" + << string(proto_file) << "' with '" << string(framework_name) + << "' (was '" << existing_entry->second << "')." << std::endl; std::cerr.flush(); } if (proto_file.find(' ') != StringPiece::npos) { - std::cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '" - << string(proto_file) << "'" << std::endl; + std::cerr << "note: framework mapping file had a proto file with a " + "space in, hopefully that isn't a missing comma: '" + << string(proto_file) << "'" << std::endl; std::cerr.flush(); } From 073487b302047c4ab6efe93c881951d853177556 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Fri, 14 Dec 2018 12:53:36 +0100 Subject: [PATCH 18/70] Exclude command_line_interface_unittest.cc in MSVC build --- BUILD | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/BUILD b/BUILD index eb8077ae74..253bc3edb2 100644 --- a/BUILD +++ b/BUILD @@ -514,7 +514,6 @@ cc_test( "src/google/protobuf/arena_unittest.cc", "src/google/protobuf/arenastring_unittest.cc", "src/google/protobuf/compiler/annotation_test_util.cc", - "src/google/protobuf/compiler/command_line_interface_unittest.cc", "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc", "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc", "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc", @@ -583,7 +582,13 @@ cc_test( "src/google/protobuf/util/type_resolver_util_test.cc", "src/google/protobuf/well_known_types_unittest.cc", "src/google/protobuf/wire_format_unittest.cc", - ], + ] + select({ + "//conditions:default" : [ + # Doesn't pass on Windows with MSVC + "src/google/protobuf/compiler/command_line_interface_unittest.cc", + ], + ":msvc": [] + }), copts = COPTS, data = [ ":test_plugin", From 9349e23827ef68c706c2db1f7c02d93e32a4d483 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Fri, 14 Dec 2018 15:05:48 -0800 Subject: [PATCH 19/70] Replace update_version shell script with a python script, which is much better at handling XML rewrite. Update the PHP version too. As part of rewrite, some XML file format will change a little, but the semantics is still the same so it should be okay. --- csharp/Google.Protobuf.Tools.nuspec | 42 +-- .../Google.Protobuf/Google.Protobuf.csproj | 6 +- java/core/pom.xml | 6 +- java/pom.xml | 6 +- java/util/pom.xml | 14 +- php/ext/google/protobuf/package.xml | 36 ++- protoc-artifacts/pom.xml | 8 +- update_version.py | 247 ++++++++++++++++++ update_version.sh | 85 ------ 9 files changed, 301 insertions(+), 149 deletions(-) create mode 100755 update_version.py delete mode 100755 update_version.sh diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 05779d442e..2ed8c884bc 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -1,4 +1,4 @@ - + Google.Protobuf.Tools @@ -16,24 +16,24 @@ Protocol Buffers Binary Serialization Format Google proto proto3 - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index e65d3969d5..b965f4c1ea 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -1,4 +1,4 @@ - + C# runtime library for Protocol Buffers - Google's data interchange format. @@ -30,7 +30,7 @@ - + - + \ No newline at end of file diff --git a/java/core/pom.xml b/java/core/pom.xml index 9dbaff15c5..1ef06a7445 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 com.google.protobuf @@ -156,4 +154,4 @@ - + \ No newline at end of file diff --git a/java/pom.xml b/java/pom.xml index c46e52bc8b..7cd1e71a69 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 com.google.protobuf @@ -218,4 +216,4 @@ util - + \ No newline at end of file diff --git a/java/util/pom.xml b/java/util/pom.xml index bcf4f19b05..9e82633495 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 com.google.protobuf @@ -69,10 +67,10 @@ - - - - + + + + @@ -128,4 +126,4 @@ - + \ No newline at end of file diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index a3bf2752e7..c60ab6e615 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -21,26 +21,24 @@ stable 3-Clause BSD License - -GA release. - + GA release. - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -54,7 +52,7 @@ GA release. protobuf - + diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 3f85890823..e7f3365fb0 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 com.google @@ -98,7 +96,7 @@ subsequent deployments it should be set to what Sonatype has created, so that all deployments will go to the same repository. --> - + @@ -133,4 +131,4 @@ - + \ No newline at end of file diff --git a/update_version.py b/update_version.py new file mode 100755 index 0000000000..148e62b04f --- /dev/null +++ b/update_version.py @@ -0,0 +1,247 @@ +#!/usr/bin/env python + +import datetime +import re +import sys +from xml.dom import minidom + +if len(sys.argv) < 2: + print """ +[ERROR] Please specify a version. + +Example: +./update_version.py 2.1.3 +""" + exit(1) + +NEW_VERSION = sys.argv[1] +NEW_VERSION_INFO = NEW_VERSION.split('.') +if len(NEW_VERSION_INFO) != 3: + print """ +[ERROR] Version must be in the format .. + +Example: +./update_version.py 2.1.3 +""" + exit(1) + + +def Find(elem, tagname): + for child in elem.childNodes: + if child.nodeName == tagname: + return child + return None + + +def FindAndClone(elem, tagname): + return Find(elem, tagname).cloneNode(True) + + +def ReplaceText(elem, text): + elem.firstChild.replaceWholeText(text) + + +def RewriteXml(filename, rewriter, add_xml_prefix=True): + document = minidom.parse(filename) + rewriter(document) + # document.toxml() always prepend the XML version without inserting new line. + # We wants to preserve as much of the original formatting as possible, so we + # will remove the default XML version and replace it with our custom one when + # whever necessary. + content = document.toxml().replace('', '') + file_handle = open(filename, 'wb') + if add_xml_prefix: + file_handle.write('\n') + file_handle.write(content) + file_handle.close() + + +def RewriteTextFile(filename, line_rewriter): + lines = open(filename, 'r').readlines() + updated_lines = [] + for line in lines: + updated_lines.append(line_rewriter(line)) + if lines == updated_lines: + print '%s was not updated. Please double check.' % filename + f = open(filename, 'w') + f.write(''.join(updated_lines)) + f.close() + + +def UpdateConfigure(): + RewriteTextFile('configure.ac', + lambda line : re.sub( + r'^AC_INIT\(\[Protocol Buffers\],\[.*\],\[protobuf@googlegroups.com\],\[protobuf\]\)$', + ('AC_INIT([Protocol Buffers],[%s],[protobuf@googlegroups.com],[protobuf])' + % NEW_VERSION), + line)) + + +def UpdateCpp(): + cpp_version = '%s00%s00%s' % ( + NEW_VERSION_INFO[0], NEW_VERSION_INFO[1], NEW_VERSION_INFO[2]) + def RewriteCpp(line): + line = re.sub( + r'^#define GOOGLE_PROTOBUF_VERSION .*$', + '#define GOOGLE_PROTOBUF_VERSION %s' % cpp_version, + line) + if NEW_VERSION_INFO[2] == '0': + line = re.sub( + r'^#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION .*$', + '#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION %s' % cpp_version, + line) + line = re.sub( + r'^#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION .*$', + '#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION %s' % cpp_version, + line) + line = re.sub( + r'^static const int kMinHeaderVersionForLibrary = .*$', + 'static const int kMinHeaderVersionForLibrary = %s;' % cpp_version, + line) + line = re.sub( + r'^static const int kMinHeaderVersionForProtoc = .*$', + 'static const int kMinHeaderVersionForProtoc = %s;' % cpp_version, + line) + return line + RewriteTextFile('src/google/protobuf/stubs/common.h', RewriteCpp) + + +def UpdateCsharp(): + RewriteXml('csharp/src/Google.Protobuf/Google.Protobuf.csproj', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'PropertyGroup'), 'VersionPrefix'), + NEW_VERSION), + add_xml_prefix=False) + + RewriteXml('csharp/Google.Protobuf.Tools.nuspec', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'metadata'), 'version'), + NEW_VERSION)) + + +def UpdateJava(): + RewriteXml('java/pom.xml', + lambda document : ReplaceText( + Find(document.documentElement, 'version'), NEW_VERSION)) + + RewriteXml('java/core/pom.xml', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'parent'), 'version'), + NEW_VERSION)) + + RewriteXml('java/util/pom.xml', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'parent'), 'version'), + NEW_VERSION)) + + RewriteXml('protoc-artifacts/pom.xml', + lambda document : ReplaceText( + Find(document.documentElement, 'version'), NEW_VERSION)) + + +def UpdateJavaScript(): + RewriteTextFile('js/package.json', + lambda line : re.sub( + r'^ "version": ".*",$', + ' "version": "%s",' % NEW_VERSION, + line)) + + +def UpdateMakefile(): + protobuf_version_offset = 11 + expected_major_version = '3' + if NEW_VERSION_INFO[0] != expected_major_version: + print """[ERROR] Major protobuf version has changed. Please update +update_version.py to readjust the protobuf_version_offset and +expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is +always increasing. + """ + exit(1) + + protobuf_version_info = '%s:%s:0' % ( + int(NEW_VERSION_INFO[1]) + protobuf_version_offset, NEW_VERSION_INFO[2]) + RewriteTextFile('src/Makefile.am', + lambda line : re.sub( + r'^PROTOBUF_VERSION = .*$', + 'PROTOBUF_VERSION = %s' % protobuf_version_info, + line)) + + +def UpdateObjectiveC(): + RewriteTextFile('Protobuf.podspec', + lambda line : re.sub( + r"^ s.version = '.*'$", + " s.version = '%s'" % NEW_VERSION, + line)) + + +def UpdatePhp(): + def Callback(document): + def CreateNode(tagname, indent, children): + elem = document.createElement(tagname) + indent += 1 + for child in children: + elem.appendChild(document.createTextNode('\n' + (' ' * indent))) + elem.appendChild(child) + indent -= 1 + elem.appendChild(document.createTextNode('\n' + (' ' * indent))) + return elem + + root = document.documentElement + version = Find(root, 'version') + ReplaceText(Find(version, 'release'), NEW_VERSION) + ReplaceText(Find(version, 'api'), NEW_VERSION) + now = datetime.datetime.now() + ReplaceText(Find(root, 'date'), now.strftime('%Y-%m-%d')) + ReplaceText(Find(root, 'time'), now.strftime('%H:%M:%S')) + changelog = Find(root, 'changelog') + for old_version in changelog.getElementsByTagName('version'): + if Find(old_version, 'release').firstChild.nodeValue == NEW_VERSION: + print ('[WARNING] Version %s already exists in the change log.' + % NEW_VERSION) + return + changelog.appendChild(document.createTextNode(' ')) + stability = Find(root, 'stability') + release = CreateNode('release', 2, [ + CreateNode('version', 3, [ + FindAndClone(version, 'release'), + FindAndClone(version, 'api') + ]), + CreateNode('stability', 3, [ + FindAndClone(stability, 'release'), + FindAndClone(stability, 'api') + ]), + FindAndClone(root, 'date'), + FindAndClone(root, 'time'), + FindAndClone(root, 'license'), + FindAndClone(root, 'notes') + ]) + changelog.appendChild(release) + changelog.appendChild(document.createTextNode('\n ')) + RewriteXml('php/ext/google/protobuf/package.xml', Callback) + +def UpdatePython(): + RewriteTextFile('python/google/protobuf/__init__.py', + lambda line : re.sub( + r"^__version__ = '.*'$", + "__version__ = '%s'" % NEW_VERSION, + line)) + +def UpdateRuby(): + RewriteTextFile('ruby/google-protobuf.gemspec', + lambda line : re.sub( + r'^ s.version = ".*"$', + ' s.version = "%s"' % NEW_VERSION, + line)) + + +UpdateConfigure() +UpdateCsharp() +UpdateCpp() +UpdateJava() +UpdateJavaScript() +UpdateMakefile() +UpdateObjectiveC() +UpdatePhp() +UpdatePython() +UpdateRuby() diff --git a/update_version.sh b/update_version.sh deleted file mode 100755 index 746578b75e..0000000000 --- a/update_version.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash -# Helper script to update version number in various files. -# Each file has it own string matching syntax to avoid accidentally updating -# the wrong version number of other dependencies. - -if [ "$#" -eq 1 ]; then - VERSION=$1 - IFS='.' read -ra VERSION_INFO <<< "$VERSION" -fi - -if [ "$#" -ne 1 ] || [ ${#VERSION_INFO[@]} -ne 3 ]; then - echo " -Usage: $0 VERSION - -Example: -$0 2.1.3 -" - exit 1 -fi - -update_version() { - file=$2 - # Replace the version number in the given file. - sed -ri "$1" $file - # Verify that the version number is updated successfully. - if [ $(grep -c $VERSION $file) -eq 0 ]; then - echo "$file version is not updated successfully. Please verify." - exit 1 - fi -} - -update_version "s/\[Protocol Buffers\],\[.*\],\[protobuf@googlegroups.com\]/[Protocol Buffers],[$VERSION],[protobuf@googlegroups.com]/g" configure.ac -update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" java/pom.xml -update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" java/core/pom.xml -update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" java/util/pom.xml -update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" protoc-artifacts/pom.xml -update_version "s/^ s.version = '.*'/ s.version = '$VERSION'/g" Protobuf.podspec -update_version "s/^__version__ = '.*'/__version__ = '$VERSION'/g" python/google/protobuf/__init__.py -update_version "s/^ .*<\/VersionPrefix>/ $VERSION<\/VersionPrefix>/g" csharp/src/Google.Protobuf/Google.Protobuf.csproj -update_version "s/^ .*<\/version>/ $VERSION<\/version>/g" csharp/Google.Protobuf.Tools.nuspec -update_version "s/^ \"version\": \".*\",/ \"version\": \"$VERSION\",/g" js/package.json -update_version "s/^ s.version = \".*\"/ s.version = \"$VERSION\"/g" ruby/google-protobuf.gemspec - -# Special handling for C++ file, where version is X.Y.Z is transformed to X00Y00Z -CPP_VERSION=${VERSION_INFO[0]}00${VERSION_INFO[1]}00${VERSION_INFO[2]} -sed -ri "s/^#define GOOGLE_PROTOBUF_VERSION .*/#define GOOGLE_PROTOBUF_VERSION $CPP_VERSION/g" src/google/protobuf/stubs/common.h - -# Only update these constants if it is a major release. -if [ ${VERSION_INFO[2]} -eq 0 ]; then - sed -ri "s/^#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION .*/#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION $CPP_VERSION/g" src/google/protobuf/stubs/common.h - sed -ri "s/^#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION .*/#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION $CPP_VERSION/g" src/google/protobuf/stubs/common.h - sed -ri "s/^static const int kMinHeaderVersionForLibrary = .*/static const int kMinHeaderVersionForLibrary = $CPP_VERSION;/g" src/google/protobuf/stubs/common.h - sed -ri "s/^static const int kMinHeaderVersionForProtoc = .*/static const int kMinHeaderVersionForProtoc = $CPP_VERSION;/g" src/google/protobuf/stubs/common.h - - if [ $(grep -c $CPP_VERSION src/google/protobuf/stubs/common.h) -ne 5 ]; then - echo "src/google/protobuf/stubs/common.h version is not updated successfully. Please verify." - exit 1 - fi -else - if [ $(grep -c $CPP_VERSION src/google/protobuf/stubs/common.h) -ne 1 ]; then - echo "src/google/protobuf/stubs/common.h version is not updated successfully. Please verify." - exit 1 - fi -fi - -# Special handling for src/Makefile.am. If version is X.Y.Z, then the -# version here should be [Y+OFFSET]:Z:0 where OFFSET is some constant -# such that the version number is always increasing. -PROTOBUF_VERSION_OFFSET=11 -EXPECTED_MAJOR_VERSION=3 -if [ ${VERSION_INFO[0]} -ne ${EXPECTED_MAJOR_VERSION} ]; then - echo "Major protobuf version has changed. Please update $0 to readjust -the PROTOBUF_VERSION_OFFSET and EXPECTED_MAJOR_VERSION such that the -PROTOBUF_VERSION in src/Makefile.am is always increasing. - " - exit 1 -fi - -PROTOBUF_VERSION_INFO=$((${VERSION_INFO[1]} + $PROTOBUF_VERSION_OFFSET)):${VERSION_INFO[2]}:0 -sed -ri "s/^PROTOBUF_VERSION = .*/PROTOBUF_VERSION = $PROTOBUF_VERSION_INFO/g" src/Makefile.am - -if [ $(grep -c $PROTOBUF_VERSION_INFO src/Makefile.am) -eq 0 ]; then - echo "src/Makefile.am version is not updated successfully. Please verify." - exit 1 -fi From 4b02f652e0c6d8184d406787dda99277a2f84f38 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Fri, 14 Dec 2018 15:10:11 -0800 Subject: [PATCH 20/70] Make sure to add a new line at the end of XML files --- csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 2 +- java/core/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- protoc-artifacts/pom.xml | 2 +- update_version.py | 1 + 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 2ed8c884bc..411ee28058 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -36,4 +36,4 @@ - \ No newline at end of file + diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index b965f4c1ea..8306c7484e 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -33,4 +33,4 @@ - \ No newline at end of file + diff --git a/java/core/pom.xml b/java/core/pom.xml index 1ef06a7445..f50ed6f9fb 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -154,4 +154,4 @@ - \ No newline at end of file + diff --git a/java/pom.xml b/java/pom.xml index 7cd1e71a69..0c5b699583 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -216,4 +216,4 @@ util - \ No newline at end of file + diff --git a/java/util/pom.xml b/java/util/pom.xml index 9e82633495..57df6d2aaf 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -126,4 +126,4 @@ - \ No newline at end of file + diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index e7f3365fb0..6d4fa023ad 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -131,4 +131,4 @@ - \ No newline at end of file + diff --git a/update_version.py b/update_version.py index 148e62b04f..fc4c15c14b 100755 --- a/update_version.py +++ b/update_version.py @@ -53,6 +53,7 @@ def RewriteXml(filename, rewriter, add_xml_prefix=True): if add_xml_prefix: file_handle.write('\n') file_handle.write(content) + file_handle.write('\n') file_handle.close() From cecba296b8c49b9dca789a9dc24e01c6c3cfa98f Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 14 Dec 2018 16:05:03 -0800 Subject: [PATCH 21/70] Down-integrate internal changes (#5467) * Down-integrate internal changes * Update generated code for php, objc and csharp. * Add missing dependency in conformance_php --- cmake/conformance.cmake | 4 +- cmake/libprotobuf-lite.cmake | 2 + conformance/Makefile.am | 4 +- conformance/binary_json_conformance_main.cc | 37 + ...pl.cc => binary_json_conformance_suite.cc} | 186 +++-- conformance/binary_json_conformance_suite.h | 121 +++ conformance/conformance.proto | 19 + conformance/conformance_cpp.cc | 5 + conformance/conformance_php.php | 1 + conformance/conformance_test.cc | 98 +-- conformance/conformance_test.h | 40 +- conformance/conformance_test_runner.cc | 18 + .../Conformance.cs | 289 ++++++- java/util/pom.xml | 5 + .../Internal/FieldDescriptorProto/Label.php | 1 + .../Internal/FieldDescriptorProto/Type.php | 1 + .../Protobuf/Internal/FieldOptions/CType.php | 1 + .../Protobuf/Internal/FieldOptions/JSType.php | 1 + .../Internal/FileOptions/OptimizeMode.php | 1 + .../MethodOptions/IdempotencyLevel.php | 1 + protobuf.bzl | 773 +++++++++--------- src/Makefile.am | 1 + src/google/protobuf/stubs/port.h | 4 + 23 files changed, 1043 insertions(+), 570 deletions(-) create mode 100644 conformance/binary_json_conformance_main.cc rename conformance/{conformance_test_impl.cc => binary_json_conformance_suite.cc} (94%) create mode 100644 conformance/binary_json_conformance_suite.h diff --git a/cmake/conformance.cmake b/cmake/conformance.cmake index ec1f9e007d..82b4cf580a 100644 --- a/cmake/conformance.cmake +++ b/cmake/conformance.cmake @@ -21,7 +21,9 @@ add_custom_command( add_executable(conformance_test_runner ${protobuf_source_dir}/conformance/conformance.pb.cc ${protobuf_source_dir}/conformance/conformance_test.cc - ${protobuf_source_dir}/conformance/conformance_test_impl.cc + ${protobuf_source_dir}/conformance/binary_json_conformance_main.cc + ${protobuf_source_dir}/conformance/binary_json_conformance_suite.cc + ${protobuf_source_dir}/conformance/binary_json_conformance_suite.h ${protobuf_source_dir}/conformance/conformance_test_runner.cc ${protobuf_source_dir}/conformance/third_party/jsoncpp/json.h ${protobuf_source_dir}/conformance/third_party/jsoncpp/jsoncpp.cpp diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index 1d0b0b848a..7bd8332f73 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -5,6 +5,7 @@ set(libprotobuf_lite_files ${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven_lite.cc ${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.cc + ${protobuf_source_dir}/src/google/protobuf/parse_context.cc ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -30,6 +31,7 @@ set(libprotobuf_lite_includes ${protobuf_source_dir}/src/google/protobuf/extension_set.h ${protobuf_source_dir}/src/google/protobuf/generated_message_util.h ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.h + ${protobuf_source_dir}/src/google/protobuf/parse_context.h ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h diff --git a/conformance/Makefile.am b/conformance/Makefile.am index 29d9a981c2..97e252ec3a 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -206,7 +206,9 @@ EXTRA_DIST = \ conformance_test_runner_LDADD = $(top_srcdir)/src/libprotobuf.la conformance_test_runner_SOURCES = conformance_test.h conformance_test.cc \ - conformance_test_impl.cc \ + binary_json_conformance_main.cc \ + binary_json_conformance_suite.h \ + binary_json_conformance_suite.cc \ conformance_test_runner.cc \ third_party/jsoncpp/json.h \ third_party/jsoncpp/jsoncpp.cpp diff --git a/conformance/binary_json_conformance_main.cc b/conformance/binary_json_conformance_main.cc new file mode 100644 index 0000000000..3e8df7343f --- /dev/null +++ b/conformance/binary_json_conformance_main.cc @@ -0,0 +1,37 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "binary_json_conformance_suite.h" +#include "conformance_test.h" + +int main(int argc, char *argv[]) { + google::protobuf::BinaryAndJsonConformanceSuite suite; + return google::protobuf::ForkPipeRunner::Run(argc, argv, &suite); +} diff --git a/conformance/conformance_test_impl.cc b/conformance/binary_json_conformance_suite.cc similarity index 94% rename from conformance/conformance_test_impl.cc rename to conformance/binary_json_conformance_suite.cc index a884deaaab..53430a719e 100644 --- a/conformance/conformance_test_impl.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -28,6 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include "binary_json_conformance_suite.h" #include "conformance_test.h" #include "third_party/jsoncpp/json.h" @@ -37,11 +38,13 @@ #include #include #include +#include #include #include using conformance::ConformanceRequest; using conformance::ConformanceResponse; +using conformance::WireFormat; using google::protobuf::Descriptor; using google::protobuf::FieldDescriptor; using google::protobuf::Message; @@ -189,73 +192,83 @@ std::unique_ptr NewTestMessage(bool is_proto3) { namespace google { namespace protobuf { -class ConformanceTestSuiteImpl : public ConformanceTestSuite { - public: - ConformanceTestSuiteImpl() {} - - private: - void RunSuiteImpl(); - void RunValidJsonTest(const string& test_name, - ConformanceLevel level, - const string& input_json, - const string& equivalent_text_format); - void RunValidJsonTestWithProtobufInput( - const string& test_name, - ConformanceLevel level, - const protobuf_test_messages::proto3::TestAllTypesProto3& input, - const string& equivalent_text_format); - void RunValidJsonIgnoreUnknownTest( - const string& test_name, ConformanceLevel level, const string& input_json, - const string& equivalent_text_format); - void RunValidProtobufTest(const string& test_name, ConformanceLevel level, - const string& input_protobuf, - const string& equivalent_text_format, - bool is_proto3); - void RunValidBinaryProtobufTest(const string& test_name, - ConformanceLevel level, - const string& input_protobuf, - bool is_proto3); - void RunValidProtobufTestWithMessage( - const string& test_name, ConformanceLevel level, - const Message *input, - const string& equivalent_text_format, - bool is_proto3); - - typedef std::function Validator; - void RunValidJsonTestWithValidator(const string& test_name, - ConformanceLevel level, - const string& input_json, - const Validator& validator); - void ExpectParseFailureForJson(const string& test_name, - ConformanceLevel level, - const string& input_json); - void ExpectSerializeFailureForJson(const string& test_name, - ConformanceLevel level, - const string& text_format); - void ExpectParseFailureForProtoWithProtoVersion (const string& proto, - const string& test_name, - ConformanceLevel level, - bool is_proto3); - void ExpectParseFailureForProto(const std::string& proto, - const std::string& test_name, - ConformanceLevel level); - void ExpectHardParseFailureForProto(const std::string& proto, - const std::string& test_name, - ConformanceLevel level); - void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); - void TestIllegalTags(); - template - void TestOneofMessage (MessageType &message, - bool is_proto3); - template - void TestUnknownMessage (MessageType &message, - bool is_proto3); - void TestValidDataForType( - google::protobuf::FieldDescriptor::Type, - std::vector> values); -}; - -void ConformanceTestSuiteImpl::ExpectParseFailureForProtoWithProtoVersion ( +bool BinaryAndJsonConformanceSuite::ParseJsonResponse( + const ConformanceResponse& response, + Message* test_message) { + string binary_protobuf; + util::Status status = + JsonToBinaryString(type_resolver_.get(), type_url_, + response.json_payload(), &binary_protobuf); + + if (!status.ok()) { + return false; + } + + if (!test_message->ParseFromString(binary_protobuf)) { + GOOGLE_LOG(FATAL) + << "INTERNAL ERROR: internal JSON->protobuf transcode " + << "yielded unparseable proto."; + return false; + } + + return true; +} + +bool BinaryAndJsonConformanceSuite::ParseResponse( + const ConformanceResponse& response, + const ConformanceRequestSetting& setting, + Message* test_message) { + const ConformanceRequest& request = setting.GetRequest(); + WireFormat requested_output = request.requested_output_format(); + const string& test_name = setting.GetTestName(); + ConformanceLevel level = setting.GetLevel(); + + switch (response.result_case()) { + case ConformanceResponse::kProtobufPayload: { + if (requested_output != conformance::PROTOBUF) { + ReportFailure( + test_name, level, request, response, + StrCat("Test was asked for ", WireFormatToString(requested_output), + " output but provided PROTOBUF instead.").c_str()); + return false; + } + + if (!test_message->ParseFromString(response.protobuf_payload())) { + ReportFailure(test_name, level, request, response, + "Protobuf output we received from test was unparseable."); + return false; + } + + break; + } + + case ConformanceResponse::kJsonPayload: { + if (requested_output != conformance::JSON) { + ReportFailure( + test_name, level, request, response, + StrCat("Test was asked for ", WireFormatToString(requested_output), + " output but provided JSON instead.").c_str()); + return false; + } + + if (!ParseJsonResponse(response, test_message)) { + ReportFailure(test_name, level, request, response, + "JSON output we received from test was unparseable."); + return false; + } + + break; + } + + default: + GOOGLE_LOG(FATAL) << test_name << ": unknown payload type: " + << response.result_case(); + } + + return true; +} + +void BinaryAndJsonConformanceSuite::ExpectParseFailureForProtoWithProtoVersion ( const string& proto, const string& test_name, ConformanceLevel level, bool is_proto3) { std::unique_ptr prototype = NewTestMessage(is_proto3); @@ -285,7 +298,7 @@ void ConformanceTestSuiteImpl::ExpectParseFailureForProtoWithProtoVersion ( } // Expect that this precise protobuf will cause a parse error. -void ConformanceTestSuiteImpl::ExpectParseFailureForProto( +void BinaryAndJsonConformanceSuite::ExpectParseFailureForProto( const string& proto, const string& test_name, ConformanceLevel level) { ExpectParseFailureForProtoWithProtoVersion(proto, test_name, level, true); ExpectParseFailureForProtoWithProtoVersion(proto, test_name, level, false); @@ -296,12 +309,12 @@ void ConformanceTestSuiteImpl::ExpectParseFailureForProto( // data verbatim and once with this data followed by some valid data. // // TODO(haberman): implement the second of these. -void ConformanceTestSuiteImpl::ExpectHardParseFailureForProto( +void BinaryAndJsonConformanceSuite::ExpectHardParseFailureForProto( const string& proto, const string& test_name, ConformanceLevel level) { return ExpectParseFailureForProto(proto, test_name, level); } -void ConformanceTestSuiteImpl::RunValidJsonTest( +void BinaryAndJsonConformanceSuite::RunValidJsonTest( const string& test_name, ConformanceLevel level, const string& input_json, const string& equivalent_text_format) { TestAllTypesProto3 prototype; @@ -317,7 +330,7 @@ void ConformanceTestSuiteImpl::RunValidJsonTest( RunValidInputTest(setting2, equivalent_text_format); } -void ConformanceTestSuiteImpl::RunValidJsonTestWithProtobufInput( +void BinaryAndJsonConformanceSuite::RunValidJsonTestWithProtobufInput( const string& test_name, ConformanceLevel level, const TestAllTypesProto3& input, const string& equivalent_text_format) { ConformanceRequestSetting setting( @@ -327,7 +340,7 @@ void ConformanceTestSuiteImpl::RunValidJsonTestWithProtobufInput( RunValidInputTest(setting, equivalent_text_format); } -void ConformanceTestSuiteImpl::RunValidJsonIgnoreUnknownTest( +void BinaryAndJsonConformanceSuite::RunValidJsonIgnoreUnknownTest( const string& test_name, ConformanceLevel level, const string& input_json, const string& equivalent_text_format) { TestAllTypesProto3 prototype; @@ -338,7 +351,7 @@ void ConformanceTestSuiteImpl::RunValidJsonIgnoreUnknownTest( RunValidInputTest(setting, equivalent_text_format); } -void ConformanceTestSuiteImpl::RunValidProtobufTest( +void BinaryAndJsonConformanceSuite::RunValidProtobufTest( const string& test_name, ConformanceLevel level, const string& input_protobuf, const string& equivalent_text_format, bool is_proto3) { @@ -359,7 +372,7 @@ void ConformanceTestSuiteImpl::RunValidProtobufTest( } } -void ConformanceTestSuiteImpl::RunValidBinaryProtobufTest( +void BinaryAndJsonConformanceSuite::RunValidBinaryProtobufTest( const string& test_name, ConformanceLevel level, const string& input_protobuf, bool is_proto3) { std::unique_ptr prototype = NewTestMessage(is_proto3); @@ -370,7 +383,7 @@ void ConformanceTestSuiteImpl::RunValidBinaryProtobufTest( RunValidBinaryInputTest(setting, input_protobuf); } -void ConformanceTestSuiteImpl::RunValidProtobufTestWithMessage( +void BinaryAndJsonConformanceSuite::RunValidProtobufTestWithMessage( const string& test_name, ConformanceLevel level, const Message *input, const string& equivalent_text_format, bool is_proto3) { RunValidProtobufTest(test_name, level, input->SerializeAsString(), @@ -382,7 +395,7 @@ void ConformanceTestSuiteImpl::RunValidProtobufTestWithMessage( // numbers while the parser is allowed to accept them as JSON strings). This // method allows strict checking on a proto3 JSON serializer by inspecting // the JSON output directly. -void ConformanceTestSuiteImpl::RunValidJsonTestWithValidator( +void BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator( const string& test_name, ConformanceLevel level, const string& input_json, const Validator& validator) { TestAllTypesProto3 prototype; @@ -426,7 +439,7 @@ void ConformanceTestSuiteImpl::RunValidJsonTestWithValidator( ReportSuccess(effective_test_name); } -void ConformanceTestSuiteImpl::ExpectParseFailureForJson( +void BinaryAndJsonConformanceSuite::ExpectParseFailureForJson( const string& test_name, ConformanceLevel level, const string& input_json) { TestAllTypesProto3 prototype; // We don't expect output, but if the program erroneously accepts the protobuf @@ -452,7 +465,7 @@ void ConformanceTestSuiteImpl::ExpectParseFailureForJson( } } -void ConformanceTestSuiteImpl::ExpectSerializeFailureForJson( +void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson( const string& test_name, ConformanceLevel level, const string& text_format) { TestAllTypesProto3 payload_message; GOOGLE_CHECK( @@ -482,7 +495,7 @@ void ConformanceTestSuiteImpl::ExpectSerializeFailureForJson( } //TODO: proto2? -void ConformanceTestSuiteImpl::TestPrematureEOFForType( +void BinaryAndJsonConformanceSuite::TestPrematureEOFForType( FieldDescriptor::Type type) { // Incomplete values for each wire type. static const string incompletes[6] = { @@ -570,7 +583,7 @@ void ConformanceTestSuiteImpl::TestPrematureEOFForType( } } -void ConformanceTestSuiteImpl::TestValidDataForType( +void BinaryAndJsonConformanceSuite::TestValidDataForType( FieldDescriptor::Type type, std::vector> values) { for (int is_proto3 = 0; is_proto3 < 2; is_proto3++) { @@ -606,7 +619,7 @@ void ConformanceTestSuiteImpl::TestValidDataForType( } // TODO: proto2? -void ConformanceTestSuiteImpl::TestIllegalTags() { +void BinaryAndJsonConformanceSuite::TestIllegalTags() { // field num 0 is illegal string nullfield[] = { "\1DEADBEEF", @@ -621,7 +634,7 @@ void ConformanceTestSuiteImpl::TestIllegalTags() { } } template -void ConformanceTestSuiteImpl::TestOneofMessage ( +void BinaryAndJsonConformanceSuite::TestOneofMessage ( MessageType &message, bool is_proto3) { message.set_oneof_uint32(0); RunValidProtobufTestWithMessage( @@ -660,14 +673,14 @@ void ConformanceTestSuiteImpl::TestOneofMessage ( } template -void ConformanceTestSuiteImpl::TestUnknownMessage( +void BinaryAndJsonConformanceSuite::TestUnknownMessage( MessageType& message, bool is_proto3) { message.ParseFromString("\xA8\x1F\x01"); RunValidBinaryProtobufTest("UnknownVarint", REQUIRED, message.SerializeAsString(), is_proto3); } -void ConformanceTestSuiteImpl::RunSuiteImpl() { +void BinaryAndJsonConformanceSuite::RunSuiteImpl() { type_resolver_.reset(NewTypeResolverForDescriptorPool( kTypeUrlPrefix, DescriptorPool::generated_pool())); type_url_ = GetTypeUrl(TestAllTypesProto3::descriptor()); @@ -2360,8 +2373,3 @@ void ConformanceTestSuiteImpl::RunSuiteImpl() { } // namespace protobuf } // namespace google - -int main(int argc, char *argv[]) { - google::protobuf::ConformanceTestSuiteImpl suite; - return google::protobuf::ForkPipeRunner::Run(argc, argv, &suite); -} diff --git a/conformance/binary_json_conformance_suite.h b/conformance/binary_json_conformance_suite.h new file mode 100644 index 0000000000..7a03545fa5 --- /dev/null +++ b/conformance/binary_json_conformance_suite.h @@ -0,0 +1,121 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H +#define CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H + +#include "conformance_test.h" +#include "third_party/jsoncpp/json.h" + +namespace google { +namespace protobuf { + +class BinaryAndJsonConformanceSuite : public ConformanceTestSuite { + public: + BinaryAndJsonConformanceSuite() {} + + private: + void RunSuiteImpl(); + void RunValidJsonTest(const string& test_name, + ConformanceLevel level, + const string& input_json, + const string& equivalent_text_format); + void RunValidJsonTestWithProtobufInput( + const string& test_name, + ConformanceLevel level, + const protobuf_test_messages::proto3::TestAllTypesProto3& input, + const string& equivalent_text_format); + void RunValidJsonIgnoreUnknownTest( + const string& test_name, ConformanceLevel level, const string& input_json, + const string& equivalent_text_format); + void RunValidProtobufTest(const string& test_name, ConformanceLevel level, + const string& input_protobuf, + const string& equivalent_text_format, + bool is_proto3); + void RunValidBinaryProtobufTest(const string& test_name, + ConformanceLevel level, + const string& input_protobuf, + bool is_proto3); + void RunValidProtobufTestWithMessage( + const string& test_name, ConformanceLevel level, + const Message *input, + const string& equivalent_text_format, + bool is_proto3); + + bool ParseJsonResponse( + const conformance::ConformanceResponse& response, + Message* test_message); + bool ParseResponse( + const conformance::ConformanceResponse& response, + const ConformanceRequestSetting& setting, + Message* test_message) override; + + typedef std::function Validator; + void RunValidJsonTestWithValidator(const string& test_name, + ConformanceLevel level, + const string& input_json, + const Validator& validator); + void ExpectParseFailureForJson(const string& test_name, + ConformanceLevel level, + const string& input_json); + void ExpectSerializeFailureForJson(const string& test_name, + ConformanceLevel level, + const string& text_format); + void ExpectParseFailureForProtoWithProtoVersion (const string& proto, + const string& test_name, + ConformanceLevel level, + bool is_proto3); + void ExpectParseFailureForProto(const std::string& proto, + const std::string& test_name, + ConformanceLevel level); + void ExpectHardParseFailureForProto(const std::string& proto, + const std::string& test_name, + ConformanceLevel level); + void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); + void TestIllegalTags(); + template + void TestOneofMessage (MessageType &message, + bool is_proto3); + template + void TestUnknownMessage (MessageType &message, + bool is_proto3); + void TestValidDataForType( + google::protobuf::FieldDescriptor::Type, + std::vector> values); + + std::unique_ptr + type_resolver_; + std::string type_url_; +}; + +} // namespace protobuf +} // namespace google + +#endif // CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H diff --git a/conformance/conformance.proto b/conformance/conformance.proto index af89152d10..b0dc762919 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto @@ -55,6 +55,7 @@ enum WireFormat { UNSPECIFIED = 0; PROTOBUF = 1; JSON = 2; + JSPB = 3; // Google internal only. Opensource testees just skip it. } enum TestCategory { @@ -67,6 +68,8 @@ enum TestCategory { // https://developers.google.com/protocol-buffers/docs/proto3#json_options // for more detail. JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; + JSPB_TEST = 4; // Test jspb wire format. Google internal only. + // Opensource testees just skip it. } // Represents a single test case's input. The testee should: @@ -85,6 +88,8 @@ message ConformanceRequest { oneof payload { bytes protobuf_payload = 1; string json_payload = 2; + string jspb_payload = 7; // Google internal only. + // Opensource testees just skip it. } // Which format should the testee serialize its message to? @@ -99,6 +104,9 @@ message ConformanceRequest { // spedific support in testee programs. Refer to the defintion of TestCategory // for more information. TestCategory test_category = 5; + + // Specify details for how to encode jspb. + JspbEncodingConfig jspb_encoding_options = 6; } // Represents a single test case's output. @@ -132,5 +140,16 @@ message ConformanceResponse { // For when the testee skipped the test, likely because a certain feature // wasn't supported, like JSON input/output. string skipped = 5; + + // If the input was successfully parsed and the requested output was JSPB, + // serialize to JSPB and set it in this field. JSPB is google internal only + // format. Opensource testees can just skip it. + string jspb_payload = 7; } } + +// Encoding options for jspb format. +message JspbEncodingConfig { + // Encode the value field of Any as jspb array if ture, otherwise binary. + bool use_jspb_array_any_format = 1; +} diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc index ac2f6dea1b..ce333ee7f9 100644 --- a/conformance/conformance_cpp.cc +++ b/conformance/conformance_cpp.cc @@ -137,6 +137,11 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { case ConformanceRequest::PAYLOAD_NOT_SET: GOOGLE_LOG(FATAL) << "Request didn't have payload."; break; + + default: + GOOGLE_LOG(FATAL) << "unknown payload type: " + << request.payload_case(); + break; } switch (request.requested_output_format()) { diff --git a/conformance/conformance_php.php b/conformance/conformance_php.php index 799cc3e361..cc6d4b9f0a 100755 --- a/conformance/conformance_php.php +++ b/conformance/conformance_php.php @@ -3,6 +3,7 @@ require_once("Conformance/WireFormat.php"); require_once("Conformance/ConformanceResponse.php"); require_once("Conformance/ConformanceRequest.php"); +require_once("Conformance/JspbEncodingConfig.php"); require_once("Conformance/TestCategory.php"); require_once("Protobuf_test_messages/Proto3/ForeignMessage.php"); require_once("Protobuf_test_messages/Proto3/ForeignEnum.php"); diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index 2d822c2e7a..68b813df4d 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -80,6 +80,11 @@ ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting( break; } + case conformance::JSPB: { + request_.set_jspb_payload(input); + break; + } + default: GOOGLE_LOG(FATAL) << "Unspecified input format"; } @@ -215,23 +220,27 @@ void ConformanceTestSuite::RunValidInputTest( void ConformanceTestSuite::RunValidBinaryInputTest( const ConformanceRequestSetting& setting, const string& equivalent_wire_format) { + const ConformanceRequest& request = setting.GetRequest(); + ConformanceResponse response; + RunTest(setting.GetTestName(), request, &response); + VerifyResponse(setting, equivalent_wire_format, response, true); +} + +void ConformanceTestSuite::VerifyResponse( + const ConformanceRequestSetting& setting, + const string& equivalent_wire_format, + const ConformanceResponse& response, + bool need_report_success) { + Message* test_message = setting.GetTestMessage(); + const ConformanceRequest& request = setting.GetRequest(); const string& test_name = setting.GetTestName(); ConformanceLevel level = setting.GetLevel(); - Message* reference_message = setting.GetTestMessage(); + GOOGLE_CHECK( reference_message->ParseFromString(equivalent_wire_format)) << "Failed to parse wire data for test case: " << test_name; - const ConformanceRequest& request = setting.GetRequest(); - ConformanceResponse response; - - RunTest(test_name, request, &response); - - Message* test_message = setting.GetTestMessage(); - - WireFormat requested_output = request.requested_output_format(); - switch (response.result_case()) { case ConformanceResponse::RESULT_NOT_SET: ReportFailure(test_name, level, request, response, @@ -249,53 +258,8 @@ void ConformanceTestSuite::RunValidBinaryInputTest( ReportSkip(test_name, request, response); return; - case ConformanceResponse::kJsonPayload: { - if (requested_output != conformance::JSON) { - ReportFailure( - test_name, level, request, response, - "Test was asked for protobuf output but provided JSON instead."); - return; - } - string binary_protobuf; - Status status = - JsonToBinaryString(type_resolver_.get(), type_url_, - response.json_payload(), &binary_protobuf); - if (!status.ok()) { - ReportFailure(test_name, level, request, response, - "JSON output we received from test was unparseable."); - return; - } - - if (!test_message->ParseFromString(binary_protobuf)) { - ReportFailure(test_name, level, request, response, - "INTERNAL ERROR: internal JSON->protobuf transcode " - "yielded unparseable proto."); - return; - } - - break; - } - - case ConformanceResponse::kProtobufPayload: { - if (requested_output != conformance::PROTOBUF) { - ReportFailure( - test_name, level, request, response, - "Test was asked for JSON output but provided protobuf instead."); - return; - } - - if (!test_message->ParseFromString(response.protobuf_payload())) { - ReportFailure(test_name, level, request, response, - "Protobuf output we received from test was unparseable."); - return; - } - - break; - } - default: - GOOGLE_LOG(FATAL) << test_name << ": unknown payload type: " - << response.result_case(); + if (!ParseResponse(response, setting, test_message)) return; } MessageDifferencer differencer; @@ -308,7 +272,9 @@ void ConformanceTestSuite::RunValidBinaryInputTest( bool check; check = differencer.Compare(*reference_message, *test_message); if (check) { - ReportSuccess(test_name); + if (need_report_success) { + ReportSuccess(test_name); + } } else { ReportFailure(test_name, level, request, response, "Output was not equivalent to reference message: %s.", @@ -375,6 +341,24 @@ bool ConformanceTestSuite::CheckSetEmpty( } } +string ConformanceTestSuite::WireFormatToString( + WireFormat wire_format) { + switch (wire_format) { + case conformance::PROTOBUF: + return "PROTOBUF"; + case conformance::JSON: + return "JSON"; + case conformance::JSPB: + return "JSPB"; + case conformance::UNSPECIFIED: + return "UNSPECIFIED"; + default: + GOOGLE_LOG(FATAL) << "unknown wire type: " + << wire_format; + } + return ""; +} + bool ConformanceTestSuite::RunSuite( ConformanceTestRunner* runner, std::string* output) { runner_ = runner; diff --git a/conformance/conformance_test.h b/conformance/conformance_test.h index d5c2f3d464..ab82bbe676 100644 --- a/conformance/conformance_test.h +++ b/conformance/conformance_test.h @@ -87,7 +87,6 @@ class ForkPipeRunner : public ConformanceTestRunner { static int Run(int argc, char *argv[], ConformanceTestSuite* suite); - private: ForkPipeRunner(const std::string &executable) : child_pid_(-1), executable_(executable) {} @@ -97,24 +96,7 @@ class ForkPipeRunner : public ConformanceTestRunner { const std::string& request, std::string* response); - // TODO(haberman): make this work on Windows, instead of using these - // UNIX-specific APIs. - // - // There is a platform-agnostic API in - // src/google/protobuf/compiler/subprocess.h - // - // However that API only supports sending a single message to the subprocess. - // We really want to be able to send messages and receive responses one at a - // time: - // - // 1. Spawning a new process for each test would take way too long for thousands - // of tests and subprocesses like java that can take 100ms or more to start - // up. - // - // 2. Sending all the tests in one big message and receiving all results in one - // big message would take away our visibility about which test(s) caused a - // crash or other fatal error. It would also give us only a single failure - // instead of all of them. + private: void SpawnTestProgram(); void CheckedWrite(int fd, const void *buf, size_t len); @@ -237,6 +219,7 @@ class ConformanceTestSuite { protected: virtual string InputFormatString(conformance::WireFormat format) const; virtual string OutputFormatString(conformance::WireFormat format) const; + conformance::ConformanceRequest request_; private: ConformanceLevel level_; @@ -244,11 +227,24 @@ class ConformanceTestSuite { ::conformance::WireFormat output_format_; const Message& prototype_message_; string test_name_; - conformance::ConformanceRequest request_; }; bool CheckSetEmpty(const std::set& set_to_check, const std::string& write_to_file, const std::string& msg); + string WireFormatToString(conformance::WireFormat wire_format); + + // Parse payload in the response to the given message. Returns true on + // success. + virtual bool ParseResponse( + const conformance::ConformanceResponse& response, + const ConformanceRequestSetting& setting, + Message* test_message) = 0; + + void VerifyResponse( + const ConformanceRequestSetting& setting, + const string& equivalent_wire_format, + const conformance::ConformanceResponse& response, + bool need_report_success); void ReportSuccess(const std::string& test_name); void ReportFailure(const string& test_name, @@ -295,10 +291,6 @@ class ConformanceTestSuite { // The set of tests that the testee opted out of; std::set skipped_; - - std::unique_ptr - type_resolver_; - std::string type_url_; }; } // namespace protobuf diff --git a/conformance/conformance_test_runner.cc b/conformance/conformance_test_runner.cc index 9c377124ff..8b44752e58 100644 --- a/conformance/conformance_test_runner.cc +++ b/conformance/conformance_test_runner.cc @@ -212,6 +212,24 @@ int ForkPipeRunner::Run( return ok ? EXIT_SUCCESS : EXIT_FAILURE; } +// TODO(haberman): make this work on Windows, instead of using these +// UNIX-specific APIs. +// +// There is a platform-agnostic API in +// src/google/protobuf/compiler/subprocess.h +// +// However that API only supports sending a single message to the subprocess. +// We really want to be able to send messages and receive responses one at a +// time: +// +// 1. Spawning a new process for each test would take way too long for thousands +// of tests and subprocesses like java that can take 100ms or more to start +// up. +// +// 2. Sending all the tests in one big message and receiving all results in one +// big message would take away our visibility about which test(s) caused a +// crash or other fatal error. It would also give us only a single failure +// instead of all of them. void ForkPipeRunner::SpawnTestProgram() { int toproc_pipe_fd[2]; int fromproc_pipe_fd[2]; diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 1642669e92..725d2b28b3 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -24,26 +24,31 @@ namespace Conformance { static ConformanceReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2Ui1QEKEkNvbmZvcm1h", + "ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2UirQIKEkNvbmZvcm1h", "bmNlUmVxdWVzdBIaChBwcm90b2J1Zl9wYXlsb2FkGAEgASgMSAASFgoManNv", - "bl9wYXlsb2FkGAIgASgJSAASOAoXcmVxdWVzdGVkX291dHB1dF9mb3JtYXQY", - "AyABKA4yFy5jb25mb3JtYW5jZS5XaXJlRm9ybWF0EhQKDG1lc3NhZ2VfdHlw", - "ZRgEIAEoCRIwCg10ZXN0X2NhdGVnb3J5GAUgASgOMhkuY29uZm9ybWFuY2Uu", - "VGVzdENhdGVnb3J5QgkKB3BheWxvYWQisQEKE0NvbmZvcm1hbmNlUmVzcG9u", - "c2USFQoLcGFyc2VfZXJyb3IYASABKAlIABIZCg9zZXJpYWxpemVfZXJyb3IY", - "BiABKAlIABIXCg1ydW50aW1lX2Vycm9yGAIgASgJSAASGgoQcHJvdG9idWZf", - "cGF5bG9hZBgDIAEoDEgAEhYKDGpzb25fcGF5bG9hZBgEIAEoCUgAEhEKB3Nr", - "aXBwZWQYBSABKAlIAEIICgZyZXN1bHQqNQoKV2lyZUZvcm1hdBIPCgtVTlNQ", - "RUNJRklFRBAAEgwKCFBST1RPQlVGEAESCAoESlNPThACKmoKDFRlc3RDYXRl", - "Z29yeRIUChBVTlNQRUNJRklFRF9URVNUEAASDwoLQklOQVJZX1RFU1QQARIN", - "CglKU09OX1RFU1QQAhIkCiBKU09OX0lHTk9SRV9VTktOT1dOX1BBUlNJTkdf", - "VEVTVBADQiEKH2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFuY2ViBnBy", - "b3RvMw==")); + "bl9wYXlsb2FkGAIgASgJSAASFgoManNwYl9wYXlsb2FkGAcgASgJSAASOAoX", + "cmVxdWVzdGVkX291dHB1dF9mb3JtYXQYAyABKA4yFy5jb25mb3JtYW5jZS5X", + "aXJlRm9ybWF0EhQKDG1lc3NhZ2VfdHlwZRgEIAEoCRIwCg10ZXN0X2NhdGVn", + "b3J5GAUgASgOMhkuY29uZm9ybWFuY2UuVGVzdENhdGVnb3J5Ej4KFWpzcGJf", + "ZW5jb2Rpbmdfb3B0aW9ucxgGIAEoCzIfLmNvbmZvcm1hbmNlLkpzcGJFbmNv", + "ZGluZ0NvbmZpZ0IJCgdwYXlsb2FkIskBChNDb25mb3JtYW5jZVJlc3BvbnNl", + "EhUKC3BhcnNlX2Vycm9yGAEgASgJSAASGQoPc2VyaWFsaXplX2Vycm9yGAYg", + "ASgJSAASFwoNcnVudGltZV9lcnJvchgCIAEoCUgAEhoKEHByb3RvYnVmX3Bh", + "eWxvYWQYAyABKAxIABIWCgxqc29uX3BheWxvYWQYBCABKAlIABIRCgdza2lw", + "cGVkGAUgASgJSAASFgoManNwYl9wYXlsb2FkGAcgASgJSABCCAoGcmVzdWx0", + "IjcKEkpzcGJFbmNvZGluZ0NvbmZpZxIhChl1c2VfanNwYl9hcnJheV9hbnlf", + "Zm9ybWF0GAEgASgIKj8KCldpcmVGb3JtYXQSDwoLVU5TUEVDSUZJRUQQABIM", + "CghQUk9UT0JVRhABEggKBEpTT04QAhIICgRKU1BCEAMqeQoMVGVzdENhdGVn", + "b3J5EhQKEFVOU1BFQ0lGSUVEX1RFU1QQABIPCgtCSU5BUllfVEVTVBABEg0K", + "CUpTT05fVEVTVBACEiQKIEpTT05fSUdOT1JFX1VOS05PV05fUEFSU0lOR19U", + "RVNUEAMSDQoJSlNQQl9URVNUEARCIQofY29tLmdvb2dsZS5wcm90b2J1Zi5j", + "b25mb3JtYW5jZWIGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "RequestedOutputFormat", "MessageType", "TestCategory" }, new[]{ "Payload" }, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped" }, new[]{ "Result" }, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions" }, new[]{ "Payload" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload" }, new[]{ "Result" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null) })); } #endregion @@ -54,6 +59,10 @@ namespace Conformance { [pbr::OriginalName("UNSPECIFIED")] Unspecified = 0, [pbr::OriginalName("PROTOBUF")] Protobuf = 1, [pbr::OriginalName("JSON")] Json = 2, + /// + /// Google internal only. Opensource testees just skip it. + /// + [pbr::OriginalName("JSPB")] Jspb = 3, } public enum TestCategory { @@ -74,6 +83,10 @@ namespace Conformance { /// for more detail. /// [pbr::OriginalName("JSON_IGNORE_UNKNOWN_PARSING_TEST")] JsonIgnoreUnknownParsingTest = 3, + /// + /// Test jspb wire format. Google internal only. + /// + [pbr::OriginalName("JSPB_TEST")] JspbTest = 4, } #endregion @@ -114,6 +127,7 @@ namespace Conformance { requestedOutputFormat_ = other.requestedOutputFormat_; messageType_ = other.messageType_; testCategory_ = other.testCategory_; + jspbEncodingOptions_ = other.jspbEncodingOptions_ != null ? other.jspbEncodingOptions_.Clone() : null; switch (other.PayloadCase) { case PayloadOneofCase.ProtobufPayload: ProtobufPayload = other.ProtobufPayload; @@ -121,6 +135,9 @@ namespace Conformance { case PayloadOneofCase.JsonPayload: JsonPayload = other.JsonPayload; break; + case PayloadOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; } _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -153,6 +170,20 @@ namespace Conformance { } } + /// Field number for the "jspb_payload" field. + public const int JspbPayloadFieldNumber = 7; + /// + /// Google internal only. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string JspbPayload { + get { return payloadCase_ == PayloadOneofCase.JspbPayload ? (string) payload_ : ""; } + set { + payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + payloadCase_ = PayloadOneofCase.JspbPayload; + } + } + /// Field number for the "requested_output_format" field. public const int RequestedOutputFormatFieldNumber = 3; private global::Conformance.WireFormat requestedOutputFormat_ = 0; @@ -199,12 +230,27 @@ namespace Conformance { } } + /// Field number for the "jspb_encoding_options" field. + public const int JspbEncodingOptionsFieldNumber = 6; + private global::Conformance.JspbEncodingConfig jspbEncodingOptions_; + /// + /// Specify details for how to encode jspb. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Conformance.JspbEncodingConfig JspbEncodingOptions { + get { return jspbEncodingOptions_; } + set { + jspbEncodingOptions_ = value; + } + } + private object payload_; /// Enum of possible cases for the "payload" oneof. public enum PayloadOneofCase { None = 0, ProtobufPayload = 1, JsonPayload = 2, + JspbPayload = 7, } private PayloadOneofCase payloadCase_ = PayloadOneofCase.None; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -233,9 +279,11 @@ namespace Conformance { } if (ProtobufPayload != other.ProtobufPayload) return false; if (JsonPayload != other.JsonPayload) return false; + if (JspbPayload != other.JspbPayload) return false; if (RequestedOutputFormat != other.RequestedOutputFormat) return false; if (MessageType != other.MessageType) return false; if (TestCategory != other.TestCategory) return false; + if (!object.Equals(JspbEncodingOptions, other.JspbEncodingOptions)) return false; if (PayloadCase != other.PayloadCase) return false; return Equals(_unknownFields, other._unknownFields); } @@ -245,9 +293,11 @@ namespace Conformance { int hash = 1; if (payloadCase_ == PayloadOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); + if (payloadCase_ == PayloadOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode(); if (MessageType.Length != 0) hash ^= MessageType.GetHashCode(); if (TestCategory != 0) hash ^= TestCategory.GetHashCode(); + if (jspbEncodingOptions_ != null) hash ^= JspbEncodingOptions.GetHashCode(); hash ^= (int) payloadCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -282,6 +332,14 @@ namespace Conformance { output.WriteRawTag(40); output.WriteEnum((int) TestCategory); } + if (jspbEncodingOptions_ != null) { + output.WriteRawTag(50); + output.WriteMessage(JspbEncodingOptions); + } + if (payloadCase_ == PayloadOneofCase.JspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -296,6 +354,9 @@ namespace Conformance { if (payloadCase_ == PayloadOneofCase.JsonPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonPayload); } + if (payloadCase_ == PayloadOneofCase.JspbPayload) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); + } if (RequestedOutputFormat != 0) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) RequestedOutputFormat); } @@ -305,6 +366,9 @@ namespace Conformance { if (TestCategory != 0) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) TestCategory); } + if (jspbEncodingOptions_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(JspbEncodingOptions); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -325,6 +389,12 @@ namespace Conformance { if (other.TestCategory != 0) { TestCategory = other.TestCategory; } + if (other.jspbEncodingOptions_ != null) { + if (jspbEncodingOptions_ == null) { + JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); + } + JspbEncodingOptions.MergeFrom(other.JspbEncodingOptions); + } switch (other.PayloadCase) { case PayloadOneofCase.ProtobufPayload: ProtobufPayload = other.ProtobufPayload; @@ -332,6 +402,9 @@ namespace Conformance { case PayloadOneofCase.JsonPayload: JsonPayload = other.JsonPayload; break; + case PayloadOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); @@ -367,6 +440,17 @@ namespace Conformance { TestCategory = (global::Conformance.TestCategory) input.ReadEnum(); break; } + case 50: { + if (jspbEncodingOptions_ == null) { + JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); + } + input.ReadMessage(JspbEncodingOptions); + break; + } + case 58: { + JspbPayload = input.ReadString(); + break; + } } } } @@ -420,6 +504,9 @@ namespace Conformance { case ResultOneofCase.Skipped: Skipped = other.Skipped; break; + case ResultOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; } _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -525,6 +612,22 @@ namespace Conformance { } } + /// Field number for the "jspb_payload" field. + public const int JspbPayloadFieldNumber = 7; + /// + /// If the input was successfully parsed and the requested output was JSPB, + /// serialize to JSPB and set it in this field. JSPB is google internal only + /// format. Opensource testees can just skip it. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string JspbPayload { + get { return resultCase_ == ResultOneofCase.JspbPayload ? (string) result_ : ""; } + set { + result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + resultCase_ = ResultOneofCase.JspbPayload; + } + } + private object result_; /// Enum of possible cases for the "result" oneof. public enum ResultOneofCase { @@ -535,6 +638,7 @@ namespace Conformance { ProtobufPayload = 3, JsonPayload = 4, Skipped = 5, + JspbPayload = 7, } private ResultOneofCase resultCase_ = ResultOneofCase.None; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -567,6 +671,7 @@ namespace Conformance { if (ProtobufPayload != other.ProtobufPayload) return false; if (JsonPayload != other.JsonPayload) return false; if (Skipped != other.Skipped) return false; + if (JspbPayload != other.JspbPayload) return false; if (ResultCase != other.ResultCase) return false; return Equals(_unknownFields, other._unknownFields); } @@ -580,6 +685,7 @@ namespace Conformance { if (resultCase_ == ResultOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (resultCase_ == ResultOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); if (resultCase_ == ResultOneofCase.Skipped) hash ^= Skipped.GetHashCode(); + if (resultCase_ == ResultOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); hash ^= (int) resultCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -618,6 +724,10 @@ namespace Conformance { output.WriteRawTag(50); output.WriteString(SerializeError); } + if (resultCase_ == ResultOneofCase.JspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -644,6 +754,9 @@ namespace Conformance { if (resultCase_ == ResultOneofCase.Skipped) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Skipped); } + if (resultCase_ == ResultOneofCase.JspbPayload) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -674,6 +787,9 @@ namespace Conformance { case ResultOneofCase.Skipped: Skipped = other.Skipped; break; + case ResultOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); @@ -713,6 +829,147 @@ namespace Conformance { SerializeError = input.ReadString(); break; } + case 58: { + JspbPayload = input.ReadString(); + break; + } + } + } + } + + } + + /// + /// Encoding options for jspb format. + /// + public sealed partial class JspbEncodingConfig : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new JspbEncodingConfig()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public JspbEncodingConfig() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public JspbEncodingConfig(JspbEncodingConfig other) : this() { + useJspbArrayAnyFormat_ = other.useJspbArrayAnyFormat_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public JspbEncodingConfig Clone() { + return new JspbEncodingConfig(this); + } + + /// Field number for the "use_jspb_array_any_format" field. + public const int UseJspbArrayAnyFormatFieldNumber = 1; + private bool useJspbArrayAnyFormat_; + /// + /// Encode the value field of Any as jspb array if ture, otherwise binary. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool UseJspbArrayAnyFormat { + get { return useJspbArrayAnyFormat_; } + set { + useJspbArrayAnyFormat_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as JspbEncodingConfig); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(JspbEncodingConfig other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (UseJspbArrayAnyFormat != other.UseJspbArrayAnyFormat) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (UseJspbArrayAnyFormat != false) hash ^= UseJspbArrayAnyFormat.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (UseJspbArrayAnyFormat != false) { + output.WriteRawTag(8); + output.WriteBool(UseJspbArrayAnyFormat); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (UseJspbArrayAnyFormat != false) { + size += 1 + 1; + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(JspbEncodingConfig other) { + if (other == null) { + return; + } + if (other.UseJspbArrayAnyFormat != false) { + UseJspbArrayAnyFormat = other.UseJspbArrayAnyFormat; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { + return; + } + break; + case 8: { + UseJspbArrayAnyFormat = input.ReadBool(); + break; + } } } } diff --git a/java/util/pom.xml b/java/util/pom.xml index 57df6d2aaf..054c5899d9 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -22,6 +22,11 @@ com.google.guava guava + + com.google.errorprone + error_prone_annotations + 2.3.2 + com.google.guava guava-testlib diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php index f10505724b..a54b228f1b 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php @@ -41,6 +41,7 @@ class Label return self::$valueToName[$value]; } + public static function value($name) { $const = __CLASS__ . '::' . strtoupper($name); diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php index 74559978a2..6072e9990f 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php @@ -136,6 +136,7 @@ class Type return self::$valueToName[$value]; } + public static function value($name) { $const = __CLASS__ . '::' . strtoupper($name); diff --git a/php/src/Google/Protobuf/Internal/FieldOptions/CType.php b/php/src/Google/Protobuf/Internal/FieldOptions/CType.php index 9043640cb7..ba9eb4adb8 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions/CType.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions/CType.php @@ -41,6 +41,7 @@ class CType return self::$valueToName[$value]; } + public static function value($name) { $const = __CLASS__ . '::' . strtoupper($name); diff --git a/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php b/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php index 5ff81620ef..175a4330bb 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php @@ -45,6 +45,7 @@ class JSType return self::$valueToName[$value]; } + public static function value($name) { $const = __CLASS__ . '::' . strtoupper($name); diff --git a/php/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php b/php/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php index 119b23a90d..0df27b5335 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php +++ b/php/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php @@ -47,6 +47,7 @@ class OptimizeMode return self::$valueToName[$value]; } + public static function value($name) { $const = __CLASS__ . '::' . strtoupper($name); diff --git a/php/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php b/php/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php index ab94458f73..ce3c062c69 100644 --- a/php/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php +++ b/php/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php @@ -47,6 +47,7 @@ class IdempotencyLevel return self::$valueToName[$value]; } + public static function value($name) { $const = __CLASS__ . '::' . strtoupper($name); diff --git a/protobuf.bzl b/protobuf.bzl index 88eeb87f14..e764859b4a 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -1,174 +1,177 @@ load("@bazel_skylib//lib:versions.bzl", "versions") def _GetPath(ctx, path): - if ctx.label.workspace_root: - return ctx.label.workspace_root + '/' + path - else: - return path + if ctx.label.workspace_root: + return ctx.label.workspace_root + "/" + path + else: + return path def _IsNewExternal(ctx): - # Bazel 0.4.4 and older have genfiles paths that look like: - # bazel-out/local-fastbuild/genfiles/external/repo/foo - # After the exec root rearrangement, they look like: - # ../repo/bazel-out/local-fastbuild/genfiles/foo - return ctx.label.workspace_root.startswith("../") + # Bazel 0.4.4 and older have genfiles paths that look like: + # bazel-out/local-fastbuild/genfiles/external/repo/foo + # After the exec root rearrangement, they look like: + # ../repo/bazel-out/local-fastbuild/genfiles/foo + return ctx.label.workspace_root.startswith("../") def _GenDir(ctx): - if _IsNewExternal(ctx): - # We are using the fact that Bazel 0.4.4+ provides repository-relative paths - # for ctx.genfiles_dir. - return ctx.genfiles_dir.path + ( - "/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else "") - # This means that we're either in the old version OR the new version in the local repo. - # Either way, appending the source path to the genfiles dir works. - return ctx.var["GENDIR"] + "/" + _SourceDir(ctx) + if _IsNewExternal(ctx): + # We are using the fact that Bazel 0.4.4+ provides repository-relative paths + # for ctx.genfiles_dir. + return ctx.genfiles_dir.path + ( + "/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else "" + ) + + # This means that we're either in the old version OR the new version in the local repo. + # Either way, appending the source path to the genfiles dir works. + return ctx.var["GENDIR"] + "/" + _SourceDir(ctx) def _SourceDir(ctx): - if not ctx.attr.includes: - return ctx.label.workspace_root - if not ctx.attr.includes[0]: - return _GetPath(ctx, ctx.label.package) - if not ctx.label.package: - return _GetPath(ctx, ctx.attr.includes[0]) - return _GetPath(ctx, ctx.label.package + '/' + ctx.attr.includes[0]) - -def _CcHdrs(srcs, use_grpc_plugin=False): - ret = [s[:-len(".proto")] + ".pb.h" for s in srcs] - if use_grpc_plugin: - ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs] - return ret - -def _CcSrcs(srcs, use_grpc_plugin=False): - ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs] - if use_grpc_plugin: - ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs] - return ret - -def _CcOuts(srcs, use_grpc_plugin=False): - return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin) - -def _PyOuts(srcs, use_grpc_plugin=False): - ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs] - if use_grpc_plugin: - ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs] - return ret - -def _RelativeOutputPath(path, include, dest=""): - if include == None: - return path - - if not path.startswith(include): - fail("Include path %s isn't part of the path %s." % (include, path)) - - if include and include[-1] != '/': - include = include + '/' - if dest and dest[-1] != '/': - dest = dest + '/' - - path = path[len(include):] - return dest + path + if not ctx.attr.includes: + return ctx.label.workspace_root + if not ctx.attr.includes[0]: + return _GetPath(ctx, ctx.label.package) + if not ctx.label.package: + return _GetPath(ctx, ctx.attr.includes[0]) + return _GetPath(ctx, ctx.label.package + "/" + ctx.attr.includes[0]) + +def _CcHdrs(srcs, use_grpc_plugin = False): + ret = [s[:-len(".proto")] + ".pb.h" for s in srcs] + if use_grpc_plugin: + ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs] + return ret + +def _CcSrcs(srcs, use_grpc_plugin = False): + ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs] + if use_grpc_plugin: + ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs] + return ret + +def _CcOuts(srcs, use_grpc_plugin = False): + return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin) + +def _PyOuts(srcs, use_grpc_plugin = False): + ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs] + if use_grpc_plugin: + ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs] + return ret + +def _RelativeOutputPath(path, include, dest = ""): + if include == None: + return path + + if not path.startswith(include): + fail("Include path %s isn't part of the path %s." % (include, path)) + + if include and include[-1] != "/": + include = include + "/" + if dest and dest[-1] != "/": + dest = dest + "/" + + path = path[len(include):] + return dest + path def _proto_gen_impl(ctx): - """General implementation for generating protos""" - srcs = ctx.files.srcs - deps = [] - deps += ctx.files.srcs - source_dir = _SourceDir(ctx) - gen_dir = _GenDir(ctx).rstrip('/') - if source_dir: - import_flags = ["-I" + source_dir, "-I" + gen_dir] - else: - import_flags = ["-I."] - - for dep in ctx.attr.deps: - import_flags += dep.proto.import_flags - deps += dep.proto.deps - - if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin: - return struct( - proto=struct( - srcs=srcs, - import_flags=import_flags, - deps=deps, - ), - ) - - for src in srcs: - args = [] - - in_gen_dir = src.root.path == gen_dir - if in_gen_dir: - import_flags_real = [] - for f in depset(import_flags): - path = f.replace('-I', '') - import_flags_real.append('-I$(realpath -s %s)' % path) - - outs = [] - use_grpc_plugin = (ctx.attr.plugin_language == "grpc" and ctx.attr.plugin) - path_tpl = "$(realpath %s)" if in_gen_dir else "%s" - if ctx.attr.gen_cc: - args += [("--cpp_out=" + path_tpl) % gen_dir] - outs.extend(_CcOuts([src.basename], use_grpc_plugin=use_grpc_plugin)) - if ctx.attr.gen_py: - args += [("--python_out=" + path_tpl) % gen_dir] - outs.extend(_PyOuts([src.basename], use_grpc_plugin=use_grpc_plugin)) - - outs = [ctx.actions.declare_file(out, sibling=src) for out in outs] - inputs = [src] + deps - if ctx.executable.plugin: - plugin = ctx.executable.plugin - lang = ctx.attr.plugin_language - if not lang and plugin.basename.startswith('protoc-gen-'): - lang = plugin.basename[len('protoc-gen-'):] - if not lang: - fail("cannot infer the target language of plugin", "plugin_language") - - outdir = "." if in_gen_dir else gen_dir - - if ctx.attr.plugin_options: - outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir - args += [("--plugin=protoc-gen-%s=" + path_tpl) % (lang, plugin.path)] - args += ["--%s_out=%s" % (lang, outdir)] - inputs += [plugin] - - if not in_gen_dir: - ctx.actions.run( - inputs=inputs, - outputs=outs, - arguments=args + import_flags + [src.path], - executable=ctx.executable.protoc, - mnemonic="ProtoCompile", - use_default_shell_env=True, - ) + """General implementation for generating protos""" + srcs = ctx.files.srcs + deps = [] + deps += ctx.files.srcs + source_dir = _SourceDir(ctx) + gen_dir = _GenDir(ctx).rstrip("/") + if source_dir: + import_flags = ["-I" + source_dir, "-I" + gen_dir] else: - for out in outs: - orig_command = " ".join( - ["$(realpath %s)" % ctx.executable.protoc.path] + args + - import_flags_real + ["-I.", src.basename]) - command = ";".join([ - 'CMD="%s"' % orig_command, - "cd %s" % src.dirname, - "${CMD}", - "cd -", - ]) - generated_out = '/'.join([gen_dir, out.basename]) - if generated_out != out.path: - command += ";mv %s %s" % (generated_out, out.path) - ctx.actions.run_shell( - inputs=inputs + [ctx.executable.protoc], - outputs=[out], - command=command, - mnemonic="ProtoCompile", - use_default_shell_env=True, + import_flags = ["-I."] + + for dep in ctx.attr.deps: + import_flags += dep.proto.import_flags + deps += dep.proto.deps + + if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin: + return struct( + proto = struct( + srcs = srcs, + import_flags = import_flags, + deps = deps, + ), ) - return struct( - proto=struct( - srcs=srcs, - import_flags=import_flags, - deps=deps, - ), - ) + for src in srcs: + args = [] + + in_gen_dir = src.root.path == gen_dir + if in_gen_dir: + import_flags_real = [] + for f in depset(import_flags).to_list(): + path = f.replace("-I", "") + import_flags_real.append("-I$(realpath -s %s)" % path) + + outs = [] + use_grpc_plugin = (ctx.attr.plugin_language == "grpc" and ctx.attr.plugin) + path_tpl = "$(realpath %s)" if in_gen_dir else "%s" + if ctx.attr.gen_cc: + args += [("--cpp_out=" + path_tpl) % gen_dir] + outs.extend(_CcOuts([src.basename], use_grpc_plugin = use_grpc_plugin)) + if ctx.attr.gen_py: + args += [("--python_out=" + path_tpl) % gen_dir] + outs.extend(_PyOuts([src.basename], use_grpc_plugin = use_grpc_plugin)) + + outs = [ctx.actions.declare_file(out, sibling = src) for out in outs] + inputs = [src] + deps + if ctx.executable.plugin: + plugin = ctx.executable.plugin + lang = ctx.attr.plugin_language + if not lang and plugin.basename.startswith("protoc-gen-"): + lang = plugin.basename[len("protoc-gen-"):] + if not lang: + fail("cannot infer the target language of plugin", "plugin_language") + + outdir = "." if in_gen_dir else gen_dir + + if ctx.attr.plugin_options: + outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir + args += [("--plugin=protoc-gen-%s=" + path_tpl) % (lang, plugin.path)] + args += ["--%s_out=%s" % (lang, outdir)] + inputs += [plugin] + + if not in_gen_dir: + ctx.actions.run( + inputs = inputs, + outputs = outs, + arguments = args + import_flags + [src.path], + executable = ctx.executable.protoc, + mnemonic = "ProtoCompile", + use_default_shell_env = True, + ) + else: + for out in outs: + orig_command = " ".join( + ["$(realpath %s)" % ctx.executable.protoc.path] + args + + import_flags_real + ["-I.", src.basename], + ) + command = ";".join([ + 'CMD="%s"' % orig_command, + "cd %s" % src.dirname, + "${CMD}", + "cd -", + ]) + generated_out = "/".join([gen_dir, out.basename]) + if generated_out != out.path: + command += ";mv %s %s" % (generated_out, out.path) + ctx.actions.run_shell( + inputs = inputs + [ctx.executable.protoc], + outputs = [out], + command = command, + mnemonic = "ProtoCompile", + use_default_shell_env = True, + ) + + return struct( + proto = struct( + srcs = srcs, + import_flags = import_flags, + deps = deps, + ), + ) proto_gen = rule( attrs = { @@ -218,245 +221,251 @@ Args: def cc_proto_library( name, - srcs=[], - deps=[], - cc_libs=[], - include=None, - protoc="@com_google_protobuf//:protoc", - internal_bootstrap_hack=False, - use_grpc_plugin=False, - default_runtime="@com_google_protobuf//:protobuf", + srcs = [], + deps = [], + cc_libs = [], + include = None, + protoc = "@com_google_protobuf//:protoc", + internal_bootstrap_hack = False, + use_grpc_plugin = False, + default_runtime = "@com_google_protobuf//:protobuf", **kargs): - """Bazel rule to create a C++ protobuf library from proto source files - - NOTE: the rule is only an internal workaround to generate protos. The - interface may change and the rule may be removed when bazel has introduced - the native rule. - - Args: - name: the name of the cc_proto_library. - srcs: the .proto files of the cc_proto_library. - deps: a list of dependency labels; must be cc_proto_library. - cc_libs: a list of other cc_library targets depended by the generated - cc_library. - include: a string indicating the include path of the .proto files. - protoc: the label of the protocol compiler to generate the sources. - internal_bootstrap_hack: a flag indicate the cc_proto_library is used only - for bootstraping. When it is set to True, no files will be generated. - The rule will simply be a provider for .proto files, so that other - cc_proto_library can depend on it. - use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin - when processing the proto files. - default_runtime: the implicitly default runtime which will be depended on by - the generated cc_library target. - **kargs: other keyword arguments that are passed to cc_library. - - """ - - includes = [] - if include != None: - includes = [include] - - if internal_bootstrap_hack: - # For pre-checked-in generated files, we add the internal_bootstrap_hack - # which will skip the codegen action. + """Bazel rule to create a C++ protobuf library from proto source files + + NOTE: the rule is only an internal workaround to generate protos. The + interface may change and the rule may be removed when bazel has introduced + the native rule. + + Args: + name: the name of the cc_proto_library. + srcs: the .proto files of the cc_proto_library. + deps: a list of dependency labels; must be cc_proto_library. + cc_libs: a list of other cc_library targets depended by the generated + cc_library. + include: a string indicating the include path of the .proto files. + protoc: the label of the protocol compiler to generate the sources. + internal_bootstrap_hack: a flag indicate the cc_proto_library is used only + for bootstraping. When it is set to True, no files will be generated. + The rule will simply be a provider for .proto files, so that other + cc_proto_library can depend on it. + use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin + when processing the proto files. + default_runtime: the implicitly default runtime which will be depended on by + the generated cc_library target. + **kargs: other keyword arguments that are passed to cc_library. + + """ + + includes = [] + if include != None: + includes = [include] + + if internal_bootstrap_hack: + # For pre-checked-in generated files, we add the internal_bootstrap_hack + # which will skip the codegen action. + proto_gen( + name = name + "_genproto", + srcs = srcs, + deps = [s + "_genproto" for s in deps], + includes = includes, + protoc = protoc, + visibility = ["//visibility:public"], + ) + + # An empty cc_library to make rule dependency consistent. + native.cc_library( + name = name, + **kargs + ) + return + + grpc_cpp_plugin = None + if use_grpc_plugin: + grpc_cpp_plugin = "//external:grpc_cpp_plugin" + + gen_srcs = _CcSrcs(srcs, use_grpc_plugin) + gen_hdrs = _CcHdrs(srcs, use_grpc_plugin) + outs = gen_srcs + gen_hdrs + proto_gen( - name=name + "_genproto", - srcs=srcs, - deps=[s + "_genproto" for s in deps], - includes=includes, - protoc=protoc, - visibility=["//visibility:public"], + name = name + "_genproto", + srcs = srcs, + deps = [s + "_genproto" for s in deps], + includes = includes, + protoc = protoc, + plugin = grpc_cpp_plugin, + plugin_language = "grpc", + gen_cc = 1, + outs = outs, + visibility = ["//visibility:public"], ) - # An empty cc_library to make rule dependency consistent. + + if default_runtime and not default_runtime in cc_libs: + cc_libs = cc_libs + [default_runtime] + if use_grpc_plugin: + cc_libs = cc_libs + ["//external:grpc_lib"] + native.cc_library( - name=name, - **kargs) - return - - grpc_cpp_plugin = None - if use_grpc_plugin: - grpc_cpp_plugin = "//external:grpc_cpp_plugin" - - gen_srcs = _CcSrcs(srcs, use_grpc_plugin) - gen_hdrs = _CcHdrs(srcs, use_grpc_plugin) - outs = gen_srcs + gen_hdrs - - proto_gen( - name=name + "_genproto", - srcs=srcs, - deps=[s + "_genproto" for s in deps], - includes=includes, - protoc=protoc, - plugin=grpc_cpp_plugin, - plugin_language="grpc", - gen_cc=1, - outs=outs, - visibility=["//visibility:public"], - ) - - if default_runtime and not default_runtime in cc_libs: - cc_libs = cc_libs + [default_runtime] - if use_grpc_plugin: - cc_libs = cc_libs + ["//external:grpc_lib"] - - native.cc_library( - name=name, - srcs=gen_srcs, - hdrs=gen_hdrs, - deps=cc_libs + deps, - includes=includes, - **kargs) + name = name, + srcs = gen_srcs, + hdrs = gen_hdrs, + deps = cc_libs + deps, + includes = includes, + **kargs + ) def internal_gen_well_known_protos_java(srcs): - """Bazel rule to generate the gen_well_known_protos_java genrule - - Args: - srcs: the well known protos - """ - root = Label("%s//protobuf_java" % (native.repository_name())).workspace_root - pkg = native.package_name() + "/" if native.package_name() else "" - if root == "": - include = " -I%ssrc " % pkg - else: - include = " -I%s/%ssrc " % (root, pkg) - native.genrule( - name = "gen_well_known_protos_java", - srcs = srcs, - outs = [ - "wellknown.srcjar", - ], - cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" + - " %s $(SRCS) " % include + - " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar", - tools = [":protoc"], - ) + """Bazel rule to generate the gen_well_known_protos_java genrule + + Args: + srcs: the well known protos + """ + root = Label("%s//protobuf_java" % (native.repository_name())).workspace_root + pkg = native.package_name() + "/" if native.package_name() else "" + if root == "": + include = " -I%ssrc " % pkg + else: + include = " -I%s/%ssrc " % (root, pkg) + native.genrule( + name = "gen_well_known_protos_java", + srcs = srcs, + outs = [ + "wellknown.srcjar", + ], + cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" + + " %s $(SRCS) " % include + + " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar", + tools = [":protoc"], + ) def internal_copied_filegroup(name, srcs, strip_prefix, dest, **kwargs): - """Macro to copy files to a different directory and then create a filegroup. - - This is used by the //:protobuf_python py_proto_library target to work around - an issue caused by Python source files that are part of the same Python - package being in separate directories. - - Args: - srcs: The source files to copy and add to the filegroup. - strip_prefix: Path to the root of the files to copy. - dest: The directory to copy the source files into. - **kwargs: extra arguments that will be passesd to the filegroup. - """ - outs = [_RelativeOutputPath(s, strip_prefix, dest) for s in srcs] - - native.genrule( - name = name + "_genrule", - srcs = srcs, - outs = outs, - cmd = " && ".join( - ["cp $(location %s) $(location %s)" % - (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs]), - ) - - native.filegroup( - name = name, - srcs = outs, - **kwargs) + """Macro to copy files to a different directory and then create a filegroup. + + This is used by the //:protobuf_python py_proto_library target to work around + an issue caused by Python source files that are part of the same Python + package being in separate directories. + + Args: + srcs: The source files to copy and add to the filegroup. + strip_prefix: Path to the root of the files to copy. + dest: The directory to copy the source files into. + **kwargs: extra arguments that will be passesd to the filegroup. + """ + outs = [_RelativeOutputPath(s, strip_prefix, dest) for s in srcs] + + native.genrule( + name = name + "_genrule", + srcs = srcs, + outs = outs, + cmd = " && ".join( + ["cp $(location %s) $(location %s)" % + (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs], + ), + ) + + native.filegroup( + name = name, + srcs = outs, + **kwargs + ) def py_proto_library( name, - srcs=[], - deps=[], - py_libs=[], - py_extra_srcs=[], - include=None, - default_runtime="@com_google_protobuf//:protobuf_python", - protoc="@com_google_protobuf//:protoc", - use_grpc_plugin=False, + srcs = [], + deps = [], + py_libs = [], + py_extra_srcs = [], + include = None, + default_runtime = "@com_google_protobuf//:protobuf_python", + protoc = "@com_google_protobuf//:protoc", + use_grpc_plugin = False, **kargs): - """Bazel rule to create a Python protobuf library from proto source files - - NOTE: the rule is only an internal workaround to generate protos. The - interface may change and the rule may be removed when bazel has introduced - the native rule. - - Args: - name: the name of the py_proto_library. - srcs: the .proto files of the py_proto_library. - deps: a list of dependency labels; must be py_proto_library. - py_libs: a list of other py_library targets depended by the generated - py_library. - py_extra_srcs: extra source files that will be added to the output - py_library. This attribute is used for internal bootstrapping. - include: a string indicating the include path of the .proto files. - default_runtime: the implicitly default runtime which will be depended on by - the generated py_library target. - protoc: the label of the protocol compiler to generate the sources. - use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin - when processing the proto files. - **kargs: other keyword arguments that are passed to cc_library. - - """ - outs = _PyOuts(srcs, use_grpc_plugin) - - includes = [] - if include != None: - includes = [include] - - grpc_python_plugin = None - if use_grpc_plugin: - grpc_python_plugin = "//external:grpc_python_plugin" - # Note: Generated grpc code depends on Python grpc module. This dependency - # is not explicitly listed in py_libs. Instead, host system is assumed to - # have grpc installed. - - proto_gen( - name=name + "_genproto", - srcs=srcs, - deps=[s + "_genproto" for s in deps], - includes=includes, - protoc=protoc, - gen_py=1, - outs=outs, - visibility=["//visibility:public"], - plugin=grpc_python_plugin, - plugin_language="grpc" - ) - - if default_runtime and not default_runtime in py_libs + deps: - py_libs = py_libs + [default_runtime] - - native.py_library( - name=name, - srcs=outs+py_extra_srcs, - deps=py_libs+deps, - imports=includes, - **kargs) + """Bazel rule to create a Python protobuf library from proto source files + + NOTE: the rule is only an internal workaround to generate protos. The + interface may change and the rule may be removed when bazel has introduced + the native rule. + + Args: + name: the name of the py_proto_library. + srcs: the .proto files of the py_proto_library. + deps: a list of dependency labels; must be py_proto_library. + py_libs: a list of other py_library targets depended by the generated + py_library. + py_extra_srcs: extra source files that will be added to the output + py_library. This attribute is used for internal bootstrapping. + include: a string indicating the include path of the .proto files. + default_runtime: the implicitly default runtime which will be depended on by + the generated py_library target. + protoc: the label of the protocol compiler to generate the sources. + use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin + when processing the proto files. + **kargs: other keyword arguments that are passed to cc_library. + + """ + outs = _PyOuts(srcs, use_grpc_plugin) + + includes = [] + if include != None: + includes = [include] + + grpc_python_plugin = None + if use_grpc_plugin: + grpc_python_plugin = "//external:grpc_python_plugin" + # Note: Generated grpc code depends on Python grpc module. This dependency + # is not explicitly listed in py_libs. Instead, host system is assumed to + # have grpc installed. -def internal_protobuf_py_tests( - name, - modules=[], - **kargs): - """Bazel rules to create batch tests for protobuf internal. - - Args: - name: the name of the rule. - modules: a list of modules for tests. The macro will create a py_test for - each of the parameter with the source "google/protobuf/%s.py" - kargs: extra parameters that will be passed into the py_test. - - """ - for m in modules: - s = "python/google/protobuf/internal/%s.py" % m - native.py_test( - name="py_%s" % m, - srcs=[s], - main=s, - **kargs) + proto_gen( + name = name + "_genproto", + srcs = srcs, + deps = [s + "_genproto" for s in deps], + includes = includes, + protoc = protoc, + gen_py = 1, + outs = outs, + visibility = ["//visibility:public"], + plugin = grpc_python_plugin, + plugin_language = "grpc", + ) + + if default_runtime and not default_runtime in py_libs + deps: + py_libs = py_libs + [default_runtime] + + native.py_library( + name = name, + srcs = outs + py_extra_srcs, + deps = py_libs + deps, + imports = includes, + **kargs + ) +def internal_protobuf_py_tests( + name, + modules = [], + **kargs): + """Bazel rules to create batch tests for protobuf internal. + + Args: + name: the name of the rule. + modules: a list of modules for tests. The macro will create a py_test for + each of the parameter with the source "google/protobuf/%s.py" + kargs: extra parameters that will be passed into the py_test. + + """ + for m in modules: + s = "python/google/protobuf/internal/%s.py" % m + native.py_test( + name = "py_%s" % m, + srcs = [s], + main = s, + **kargs + ) def check_protobuf_required_bazel_version(): - """For WORKSPACE files, to check the installed version of bazel. + """For WORKSPACE files, to check the installed version of bazel. - This ensures bazel supports our approach to proto_library() depending on a - copied filegroup. (Fixed in bazel 0.5.4) - """ - versions.check(minimum_bazel_version = "0.5.4") + This ensures bazel supports our approach to proto_library() depending on a + copied filegroup. (Fixed in bazel 0.5.4) + """ + versions.check(minimum_bazel_version = "0.5.4") diff --git a/src/Makefile.am b/src/Makefile.am index 2d7e4f0371..9251d121a6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -208,6 +208,7 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/generated_message_table_driven_lite.cc \ google/protobuf/implicit_weak_message.cc \ google/protobuf/message_lite.cc \ + google/protobuf/parse_context.cc \ google/protobuf/repeated_field.cc \ google/protobuf/wire_format_lite.cc \ google/protobuf/io/coded_stream.cc \ diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index 4884a27756..d87e9938e7 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -431,7 +431,11 @@ class BigEndian { } // namespace protobuf } // namespace google +#ifdef PROTOBUF_ENABLE_EXPERIMENTAL_PARSER +#define GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER 1 +#else #define GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER 0 +#endif #include From 3d46d8dfe43150244a6c52ebfb0ea6ce29756aa2 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Fri, 14 Dec 2018 16:41:44 -0800 Subject: [PATCH 22/70] Add conformance test for enum alias of the same name with different case --- conformance/conformance_test_impl.cc | 17 +++++++++++++++++ src/google/protobuf/test_messages_proto3.proto | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/conformance/conformance_test_impl.cc b/conformance/conformance_test_impl.cc index a884deaaab..0597cda898 100644 --- a/conformance/conformance_test_impl.cc +++ b/conformance/conformance_test_impl.cc @@ -1373,6 +1373,23 @@ void ConformanceTestSuiteImpl::RunSuiteImpl() { "EnumField", REQUIRED, R"({"optionalNestedEnum": "FOO"})", "optional_nested_enum: FOO"); + // Enum fields with alias + RunValidJsonTest( + "EnumFieldWithAlias", REQUIRED, + R"({"optionalAliasedEnum": "ALIAS_BAZ"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest( + "EnumFieldWithAliasUseAlias", REQUIRED, + R"({"optionalAliasedEnum": "QUX"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest( + "EnumFieldWithAliasLowerCase", REQUIRED, + R"({"optionalAliasedEnum": "qux"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest( + "EnumFieldWithAliasDifferentCase", REQUIRED, + R"({"optionalAliasedEnum": "bAz"})", + "optional_aliased_enum: ALIAS_BAZ"); // Enum values must be represented as strings. ExpectParseFailureForJson( "EnumFieldNotQuoted", REQUIRED, diff --git a/src/google/protobuf/test_messages_proto3.proto b/src/google/protobuf/test_messages_proto3.proto index 4f295aac49..e47856d07f 100644 --- a/src/google/protobuf/test_messages_proto3.proto +++ b/src/google/protobuf/test_messages_proto3.proto @@ -73,6 +73,17 @@ message TestAllTypesProto3 { NEG = -1; // Intentionally negative. } + enum AliasedEnum { + option allow_alias = true; + + ALIAS_FOO = 0; + ALIAS_BAR = 1; + ALIAS_BAZ = 2; + QUX = 2; + qux = 2; + bAz = 2; + } + // Singular int32 optional_int32 = 1; int64 optional_int64 = 2; @@ -95,6 +106,7 @@ message TestAllTypesProto3 { NestedEnum optional_nested_enum = 21; ForeignEnum optional_foreign_enum = 22; + AliasedEnum optional_aliased_enum = 23; string optional_string_piece = 24 [ctype=STRING_PIECE]; string optional_cord = 25 [ctype=CORD]; From 00b9b2303cc5057691ce131350b9dc14fa4b304c Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Fri, 14 Dec 2018 16:48:06 -0800 Subject: [PATCH 23/70] Add conformance test for enum alias with same name but different case --- conformance/binary_json_conformance_suite.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index bdc3691239..404488c8c7 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -1387,6 +1387,23 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { R"({"optionalNestedEnum": "FOO"})", "optional_nested_enum: FOO"); // Enum fields with alias + RunValidJsonTest( + "EnumFieldWithAlias", REQUIRED, + R"({"optionalAliasedEnum": "ALIAS_BAZ"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest( + "EnumFieldWithAliasUseAlias", REQUIRED, + R"({"optionalAliasedEnum": "QUX"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest( + "EnumFieldWithAliasLowerCase", REQUIRED, + R"({"optionalAliasedEnum": "qux"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest( + "EnumFieldWithAliasDifferentCase", REQUIRED, + R"({"optionalAliasedEnum": "bAz"})", + "optional_aliased_enum: ALIAS_BAZ"); + // Enum fields with alias RunValidJsonTest( "EnumFieldWithAlias", REQUIRED, R"({"optionalAliasedEnum": "ALIAS_BAZ"})", From 37dbfd6c463ade173b93202d65911afe084bf781 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Fri, 14 Dec 2018 17:06:11 -0800 Subject: [PATCH 24/70] Do not require ruby enum to be uppercase --- conformance/binary_json_conformance_suite.cc | 17 ----------------- ruby/ext/google/protobuf_c/message.c | 12 ++++++------ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 404488c8c7..bdc3691239 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -1387,23 +1387,6 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { R"({"optionalNestedEnum": "FOO"})", "optional_nested_enum: FOO"); // Enum fields with alias - RunValidJsonTest( - "EnumFieldWithAlias", REQUIRED, - R"({"optionalAliasedEnum": "ALIAS_BAZ"})", - "optional_aliased_enum: ALIAS_BAZ"); - RunValidJsonTest( - "EnumFieldWithAliasUseAlias", REQUIRED, - R"({"optionalAliasedEnum": "QUX"})", - "optional_aliased_enum: ALIAS_BAZ"); - RunValidJsonTest( - "EnumFieldWithAliasLowerCase", REQUIRED, - R"({"optionalAliasedEnum": "qux"})", - "optional_aliased_enum: ALIAS_BAZ"); - RunValidJsonTest( - "EnumFieldWithAliasDifferentCase", REQUIRED, - R"({"optionalAliasedEnum": "bAz"})", - "optional_aliased_enum: ALIAS_BAZ"); - // Enum fields with alias RunValidJsonTest( "EnumFieldWithAlias", REQUIRED, R"({"optionalAliasedEnum": "ALIAS_BAZ"})", diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 81a782766f..edd14c2ffd 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -697,12 +697,12 @@ VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) { upb_enum_next(&it)) { const char* name = upb_enum_iter_name(&it); int32_t value = upb_enum_iter_number(&it); - if (name[0] < 'A' || name[0] > 'Z') { - rb_raise(cTypeError, - "Enum value '%s' does not start with an uppercase letter " - "as is required for Ruby constants.", - name); - } + // if (name[0] < 'A' || name[0] > 'Z') { + // rb_raise(cTypeError, + // "Enum value '%s' does not start with an uppercase letter " + // "as is required for Ruby constants.", + // name); + // } rb_define_const(mod, name, INT2NUM(value)); } From c11096c10d1dff47f0126fc7eed9565804a02669 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Fri, 14 Dec 2018 17:06:36 -0800 Subject: [PATCH 25/70] Do not require Ruby enum to be upper case --- ruby/ext/google/protobuf_c/message.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index edd14c2ffd..2f14ef6ecf 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -697,12 +697,6 @@ VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) { upb_enum_next(&it)) { const char* name = upb_enum_iter_name(&it); int32_t value = upb_enum_iter_number(&it); - // if (name[0] < 'A' || name[0] > 'Z') { - // rb_raise(cTypeError, - // "Enum value '%s' does not start with an uppercase letter " - // "as is required for Ruby constants.", - // name); - // } rb_define_const(mod, name, INT2NUM(value)); } From 4c559316e0a623872172a6665367a7c6339ac223 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 17 Dec 2018 17:19:10 -0500 Subject: [PATCH 26/70] Small fix to -[GPBEnumDescriptor getValue:forEnumTextFormatName:] Don't look up the TextFormat for the value as aliases can trip that up, instead check the TextFormat names directly and then fetch the value. --- objectivec/GPBDescriptor.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/objectivec/GPBDescriptor.m b/objectivec/GPBDescriptor.m index a349f87b99..41bf5adbcb 100644 --- a/objectivec/GPBDescriptor.m +++ b/objectivec/GPBDescriptor.m @@ -872,11 +872,10 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { if (nameOffsets_ == NULL) return NO; for (uint32_t i = 0; i < valueCount_; ++i) { - int32_t value = values_[i]; - NSString *valueTextFormatName = [self textFormatNameForValue:value]; + NSString *valueTextFormatName = [self getEnumTextFormatNameForIndex:i]; if ([valueTextFormatName isEqual:textFormatName]) { if (outValue) { - *outValue = value; + *outValue = values_[i]; } return YES; } From d529720e2f11ff76b9094fd537888b7bfe448a58 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 17 Dec 2018 17:20:56 -0500 Subject: [PATCH 27/70] If enum aliases overlap in ObjC names skip generating the extras. Some protos have enum values of "FOO" and "Foo", which the ObjC generation then makes into the same thing. Just skip generating the enum element for the duplicate as it would be a compile error because of the name collision. The descriptors are still generated to support reflection and TextFormat more completely. --- objectivec/Tests/GPBDescriptorTests.m | 37 +++++++++++++++++++ objectivec/Tests/unittest_objc.proto | 15 ++++++++ .../compiler/objectivec/objectivec_enum.cc | 23 ++++++++++++ .../compiler/objectivec/objectivec_enum.h | 1 + 4 files changed, 76 insertions(+) diff --git a/objectivec/Tests/GPBDescriptorTests.m b/objectivec/Tests/GPBDescriptorTests.m index d47cc30fce..46c1729150 100644 --- a/objectivec/Tests/GPBDescriptorTests.m +++ b/objectivec/Tests/GPBDescriptorTests.m @@ -244,7 +244,44 @@ XCTAssertTrue([descriptor getValue:&value forEnumName:enumName]); XCTAssertEqual(value, 2); XCTAssertEqualObjects([descriptor getEnumTextFormatNameForIndex:4], @"BAR2"); +} + +- (void)testEnumAliasNameCollisions { + GPBEnumDescriptor *descriptor = TestEnumObjCNameCollision_EnumDescriptor(); + NSString *textFormatName; + int32_t value; + + XCTAssertEqual(descriptor.enumNameCount, 5U); + + XCTAssertEqualObjects([descriptor getEnumNameForIndex:0], @"TestEnumObjCNameCollision_Foo"); + textFormatName = [descriptor getEnumTextFormatNameForIndex:0]; + XCTAssertEqualObjects(textFormatName, @"FOO"); + XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:textFormatName]); + XCTAssertEqual(value, 1); + XCTAssertEqualObjects([descriptor getEnumNameForIndex:1], @"TestEnumObjCNameCollision_Foo"); + textFormatName = [descriptor getEnumTextFormatNameForIndex:1]; + XCTAssertEqualObjects(textFormatName, @"foo"); + XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:textFormatName]); + XCTAssertEqual(value, 1); + + XCTAssertEqualObjects([descriptor getEnumNameForIndex:2], @"TestEnumObjCNameCollision_Bar"); + textFormatName = [descriptor getEnumTextFormatNameForIndex:2]; + XCTAssertEqualObjects(textFormatName, @"BAR"); + XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:textFormatName]); + XCTAssertEqual(value, 2); + + XCTAssertEqualObjects([descriptor getEnumNameForIndex:3], @"TestEnumObjCNameCollision_Mumble"); + textFormatName = [descriptor getEnumTextFormatNameForIndex:3]; + XCTAssertEqualObjects(textFormatName, @"mumble"); + XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:textFormatName]); + XCTAssertEqual(value, 2); + + XCTAssertEqualObjects([descriptor getEnumNameForIndex:4], @"TestEnumObjCNameCollision_Mumble"); + textFormatName = [descriptor getEnumTextFormatNameForIndex:4]; + XCTAssertEqualObjects(textFormatName, @"MUMBLE"); + XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:textFormatName]); + XCTAssertEqual(value, 2); } - (void)testEnumValueValidator { diff --git a/objectivec/Tests/unittest_objc.proto b/objectivec/Tests/unittest_objc.proto index 1245ebefa0..91c213921e 100644 --- a/objectivec/Tests/unittest_objc.proto +++ b/objectivec/Tests/unittest_objc.proto @@ -867,3 +867,18 @@ message BoolOnlyMessage { message WKTRefereceMessage { optional google.protobuf.Any an_any = 1; } + +// This is in part a compile test, it ensures that when aliases end up with +// the same ObjC name, we drop them to avoid the duplication names. There +// is a test to ensure the descriptors are still generated to support +// reflection and TextFormat. +enum TestEnumObjCNameCollision { + option allow_alias = true; + + FOO = 1; + foo = 1; + + BAR = 2; + mumble = 2; + MUMBLE = 2; +} diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc index 978e985cf5..3b2ca55368 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc @@ -35,6 +35,7 @@ #include #include #include +#include // std::find() namespace google { namespace protobuf { @@ -44,6 +45,17 @@ namespace objectivec { EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor) : descriptor_(descriptor), name_(EnumName(descriptor_)) { + // Track the names for the enum values, and if an alias overlaps a base + // value, skip making a name for it. Likewise if two alias overlap, the + // first one wins. + // The one gap in this logic is if two base values overlap, but for that + // to happen you have to have "Foo" and "FOO" or "FOO_BAR" and "FooBar", + // and if an enum has that, it is already going to be confusing and a + // compile error is just fine. + // The values are still tracked to support the reflection apis and + // TextFormat handing since they are different there. + std::set value_names; + for (int i = 0; i < descriptor_->value_count(); i++) { const EnumValueDescriptor* value = descriptor_->value(i); const EnumValueDescriptor* canonical_value = @@ -51,6 +63,14 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor) if (value == canonical_value) { base_values_.push_back(value); + value_names.insert(EnumValueName(value)); + } else { + string value_name(EnumValueName(value)); + if (value_names.find(value_name) != value_names.end()) { + alias_values_to_skip_.insert(value); + } else { + value_names.insert(value_name); + } } all_values_.push_back(value); } @@ -90,6 +110,9 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { "name", name_); } for (int i = 0; i < all_values_.size(); i++) { + if (alias_values_to_skip_.find(all_values_[i]) != alias_values_to_skip_.end()) { + continue; + } SourceLocation location; if (all_values_[i]->GetSourceLocation(&location)) { string comments = BuildCommentsString(location, true).c_str(); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.h b/src/google/protobuf/compiler/objectivec/objectivec_enum.h index d9dfc8a1d9..50a6564479 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.h @@ -59,6 +59,7 @@ class EnumGenerator { const EnumDescriptor* descriptor_; std::vector base_values_; std::vector all_values_; + std::set alias_values_to_skip_; const string name_; }; From d7c4409589b13e15522f946ca506fbc9091d59ca Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 18 Dec 2018 10:57:03 -0800 Subject: [PATCH 28/70] Php 7.3 fix (#5434) * Inherit from message instead of implement When regestering class (implmenets other class) during MINIT, zend_class_implements would call zend_class_entry->interface_gets_implemented(). In PHP-7.3 interface_gets_implemented shares the same location with create_object. However, during MINIT, the global object storeage hasn't been initialized. And thus, caused segment fault in php 7.3. * Use zend_string_init where interned string may be the value. zend_string_dup will keep using the existing interned string. In php 7.3, interned string cannot be destroyed from user's code. * Uncommment debug code * Use latest phpunit for each php versions * Revert change in Dockerfile * Update php test to use the new docker image * Update composer * Change docker organization * Update phpunit * Debug phpunit * Store phpunit into bin dir in docker image * Install valgrind to docker * Fix compatibility test * Remove generated_service_test from compatibility c extension test * Update 32bit php test to the new docker image * Install bison * Fix build.sh * Fix DOCKERIMAGE_PREFIX * Fix basename * Add comment to build_and_run_docker2.sh * Remove commented code * Fix comments --- .gitignore | 2 + kokoro/linux/32-bit/build.sh | 3 +- kokoro/linux/build_and_run_docker.sh | 14 +- kokoro/linux/dockerfile/test/php/Dockerfile | 29 ++- .../dockerfile/test/php_32bit/Dockerfile | 224 ++++++++++++++++++ kokoro/linux/php_all/build.sh | 3 +- php/ext/google/protobuf/message.c | 26 -- php/ext/google/protobuf/protobuf.h | 6 +- php/ext/google/protobuf/storage.c | 6 +- php/tests/array_test.php | 2 +- php/tests/compatibility_test.sh | 4 + php/tests/encode_decode_test.php | 6 + php/tests/generated_class_test.php | 10 + php/tests/map_field_test.php | 2 +- php/tests/test_base.php | 3 +- php/tests/well_known_test.php | 1 + tests.sh | 55 ++--- 17 files changed, 309 insertions(+), 87 deletions(-) create mode 100644 kokoro/linux/dockerfile/test/php_32bit/Dockerfile diff --git a/.gitignore b/.gitignore index 0b85d391ab..a7ca0e2438 100644 --- a/.gitignore +++ b/.gitignore @@ -145,7 +145,9 @@ php/ext/google/protobuf/Makefile.objects php/ext/google/protobuf/acinclude.m4 php/ext/google/protobuf/build/ php/ext/google/protobuf/config.h +php/ext/google/protobuf/config.h.in~ php/ext/google/protobuf/config.nice +php/ext/google/protobuf/configure.ac php/ext/google/protobuf/configure.in php/ext/google/protobuf/mkinstalldirs php/ext/google/protobuf/run-tests.php diff --git a/kokoro/linux/32-bit/build.sh b/kokoro/linux/32-bit/build.sh index 04383a5701..8c0a41ea2e 100755 --- a/kokoro/linux/32-bit/build.sh +++ b/kokoro/linux/32-bit/build.sh @@ -10,7 +10,8 @@ # Change to repo root cd $(dirname $0)/../../.. -export DOCKERFILE_DIR=kokoro/linux/32-bit +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/php_32bit export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh export OUTPUT_DIR=testoutput export TEST_SET="php_all_32" diff --git a/kokoro/linux/build_and_run_docker.sh b/kokoro/linux/build_and_run_docker.sh index b81a3684b7..3dc5dbb82f 100755 --- a/kokoro/linux/build_and_run_docker.sh +++ b/kokoro/linux/build_and_run_docker.sh @@ -3,6 +3,8 @@ # Builds docker image and runs a command under it. # This is a generic script that is configured with the following variables: # +# DOCKERHUB_ORGANIZATION - The organization on docker hub storing the +# Dockerfile. # DOCKERFILE_DIR - Directory in which Dockerfile file is located. # DOCKER_RUN_SCRIPT - Script to run under docker (relative to protobuf repo root) # OUTPUT_DIR - Directory that will be copied from inside docker after finishing. @@ -15,8 +17,16 @@ git_root=$(pwd) cd - # Use image name based on Dockerfile sha1 -DOCKERHUB_ORGANIZATION=grpctesting/protobuf -DOCKER_IMAGE_NAME=${DOCKERHUB_ORGANIZATION}_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) +if [ -z "$DOCKERHUB_ORGANIZATION" ] +then + DOCKERHUB_ORGANIZATION=grpctesting/protobuf + DOCKER_IMAGE_NAME=${DOCKERHUB_ORGANIZATION}_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) +else + # TODO(teboring): Remove this when all tests have been migrated to separate + # docker images. + DOCKERFILE_PREFIX=$(basename $DOCKERFILE_DIR) + DOCKER_IMAGE_NAME=${DOCKERHUB_ORGANIZATION}/${DOCKERFILE_PREFIX}_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) +fi # Pull dockerimage from Dockerhub docker pull $DOCKER_IMAGE_NAME diff --git a/kokoro/linux/dockerfile/test/php/Dockerfile b/kokoro/linux/dockerfile/test/php/Dockerfile index 632d783a44..276cb73a41 100644 --- a/kokoro/linux/dockerfile/test/php/Dockerfile +++ b/kokoro/linux/dockerfile/test/php/Dockerfile @@ -79,8 +79,8 @@ RUN cd php-src \ RUN wget -O phpunit https://phar.phpunit.de/phpunit-4.phar \ && chmod +x phpunit \ - && cp phpunit /usr/local/php-5.5 \ - && mv phpunit /usr/local/php-5.5-zts + && cp phpunit /usr/local/php-5.5/bin \ + && mv phpunit /usr/local/php-5.5-zts/bin # php 5.6 RUN cd php-src \ @@ -109,8 +109,8 @@ RUN cd php-src \ RUN wget -O phpunit https://phar.phpunit.de/phpunit-5.phar \ && chmod +x phpunit \ - && cp phpunit /usr/local/php-5.6 \ - && mv phpunit /usr/local/php-5.6-zts + && cp phpunit /usr/local/php-5.6/bin \ + && mv phpunit /usr/local/php-5.6-zts/bin # php 7.0 RUN cd php-src \ @@ -139,8 +139,8 @@ RUN cd php-src \ RUN wget -O phpunit https://phar.phpunit.de/phpunit-6.phar \ && chmod +x phpunit \ - && cp phpunit /usr/local/php-7.0 \ - && mv phpunit /usr/local/php-7.0-zts + && cp phpunit /usr/local/php-7.0/bin \ + && mv phpunit /usr/local/php-7.0-zts/bin # php 7.1 RUN cd php-src \ @@ -169,8 +169,8 @@ RUN cd php-src \ RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ && chmod +x phpunit \ - && cp phpunit /usr/local/php-7.1 \ - && mv phpunit /usr/local/php-7.1-zts + && cp phpunit /usr/local/php-7.1/bin \ + && mv phpunit /usr/local/php-7.1-zts/bin # php 7.2 RUN cd php-src \ @@ -199,8 +199,8 @@ RUN cd php-src \ RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ && chmod +x phpunit \ - && cp phpunit /usr/local/php-7.2 \ - && mv phpunit /usr/local/php-7.2-zts + && cp phpunit /usr/local/php-7.2/bin \ + && mv phpunit /usr/local/php-7.2-zts/bin # php 7.3 RUN cd php-src \ @@ -229,5 +229,10 @@ RUN cd php-src \ RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ && chmod +x phpunit \ - && cp phpunit /usr/local/php-7.3 \ - && mv phpunit /usr/local/php-7.3-zts + && cp phpunit /usr/local/php-7.3/bin \ + && mv phpunit /usr/local/php-7.3-zts/bin + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + valgrind \ + && apt-get clean diff --git a/kokoro/linux/dockerfile/test/php_32bit/Dockerfile b/kokoro/linux/dockerfile/test/php_32bit/Dockerfile new file mode 100644 index 0000000000..f8027c48e7 --- /dev/null +++ b/kokoro/linux/dockerfile/test/php_32bit/Dockerfile @@ -0,0 +1,224 @@ +FROM 32bit/debian:jessie + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + bison \ + php5 \ + libcurl4-openssl-dev \ + libssl-dev \ + libxml2-dev \ + unzip \ + zlib1g-dev \ + pkg-config \ + && apt-get clean + +# Install other dependencies +RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-2.6.4.tar.gz \ + && cd /var/local/bison-2.6.4 \ + && ./configure \ + && make \ + && make install + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php +RUN mv composer.phar /usr/local/bin/composer + +# Download php source code +RUN git clone https://github.com/php/php-src + +# php 5.5 +RUN cd php-src \ + && git checkout PHP-5.5.38 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.5 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.5-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-4.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-5.5/bin \ + && mv phpunit /usr/local/php-5.5-zts/bin + +# php 5.6 +RUN cd php-src \ + && git checkout PHP-5.6.39 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.6 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.6-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-5.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-5.6/bin \ + && mv phpunit /usr/local/php-5.6-zts/bin + +# php 7.0 +RUN cd php-src \ + && git checkout PHP-7.0.33 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-6.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.0/bin \ + && mv phpunit /usr/local/php-7.0-zts/bin + +# php 7.1 +RUN cd php-src \ + && git checkout PHP-7.1.25 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.1/bin \ + && mv phpunit /usr/local/php-7.1-zts/bin + +# php 7.2 +RUN cd php-src \ + && git checkout PHP-7.2.13 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.2/bin \ + && mv phpunit /usr/local/php-7.2-zts/bin + +# php 7.3 +RUN cd php-src \ + && git checkout PHP-7.3.0 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.3/bin \ + && mv phpunit /usr/local/php-7.3-zts/bin + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + valgrind \ + && apt-get clean diff --git a/kokoro/linux/php_all/build.sh b/kokoro/linux/php_all/build.sh index e9ab84cb5d..23468a7010 100755 --- a/kokoro/linux/php_all/build.sh +++ b/kokoro/linux/php_all/build.sh @@ -10,7 +10,8 @@ # Change to repo root cd $(dirname $0)/../../.. -export DOCKERFILE_DIR=kokoro/linux/64-bit +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/php export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh export OUTPUT_DIR=testoutput export TEST_SET="php_all" diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 2843321640..08a4793ff7 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -1231,7 +1231,6 @@ zend_class_entry* any_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Any", Any, any) - zend_class_implements(any_type TSRMLS_CC, 1, message_type); zend_declare_property_string(any_type, "type_url", strlen("type_url"), "" ,ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_string(any_type, "value", strlen("value"), @@ -1421,7 +1420,6 @@ zend_class_entry* duration_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Duration", Duration, duration) - zend_class_implements(duration_type TSRMLS_CC, 1, message_type); zend_declare_property_long(duration_type, "seconds", strlen("seconds"), 0 ,ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_long(duration_type, "nanos", strlen("nanos"), @@ -1457,7 +1455,6 @@ zend_class_entry* timestamp_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Timestamp", Timestamp, timestamp) - zend_class_implements(timestamp_type TSRMLS_CC, 1, message_type); zend_declare_property_long(timestamp_type, "seconds", strlen("seconds"), 0 ,ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_long(timestamp_type, "nanos", strlen("nanos"), @@ -1650,7 +1647,6 @@ zend_class_entry* api_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Api", Api, api) - zend_class_implements(api_type TSRMLS_CC, 1, message_type); zend_declare_property_null(api_type, "name", strlen("name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(api_type, "methods", strlen("methods"), @@ -1697,7 +1693,6 @@ zend_class_entry* bool_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\BoolValue", BoolValue, bool_value) - zend_class_implements(bool_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(bool_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -1726,7 +1721,6 @@ zend_class_entry* bytes_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\BytesValue", BytesValue, bytes_value) - zend_class_implements(bytes_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(bytes_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -1755,7 +1749,6 @@ zend_class_entry* double_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\DoubleValue", DoubleValue, double_value) - zend_class_implements(double_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(double_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -1792,7 +1785,6 @@ zend_class_entry* enum_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Enum", Enum, enum) - zend_class_implements(enum_type TSRMLS_CC, 1, message_type); zend_declare_property_null(enum_type, "name", strlen("name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(enum_type, "enumvalue", strlen("enumvalue"), @@ -1837,7 +1829,6 @@ zend_class_entry* enum_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\EnumValue", EnumValue, enum_value) - zend_class_implements(enum_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(enum_value_type, "name", strlen("name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(enum_value_type, "number", strlen("number"), @@ -1872,7 +1863,6 @@ zend_class_entry* field_mask_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\FieldMask", FieldMask, field_mask) - zend_class_implements(field_mask_type TSRMLS_CC, 1, message_type); zend_declare_property_null(field_mask_type, "paths", strlen("paths"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -1919,7 +1909,6 @@ zend_class_entry* field_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Field", Field, field) - zend_class_implements(field_type TSRMLS_CC, 1, message_type); zend_declare_property_null(field_type, "kind", strlen("kind"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(field_type, "cardinality", strlen("cardinality"), @@ -1975,7 +1964,6 @@ zend_class_entry* float_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\FloatValue", FloatValue, float_value) - zend_class_implements(float_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(float_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2002,7 +1990,6 @@ zend_class_entry* empty_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\GPBEmpty", GPBEmpty, empty) - zend_class_implements(empty_type TSRMLS_CC, 1, message_type); PHP_PROTO_INIT_SUBMSGCLASS_END PHP_METHOD(GPBEmpty, __construct) { @@ -2028,7 +2015,6 @@ zend_class_entry* int32_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Int32Value", Int32Value, int32_value) - zend_class_implements(int32_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(int32_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2057,7 +2043,6 @@ zend_class_entry* int64_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Int64Value", Int64Value, int64_value) - zend_class_implements(int64_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(int64_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2086,7 +2071,6 @@ zend_class_entry* list_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\ListValue", ListValue, list_value) - zend_class_implements(list_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(list_value_type, "values", strlen("values"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2127,7 +2111,6 @@ zend_class_entry* method_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Method", Method, method) - zend_class_implements(method_type TSRMLS_CC, 1, message_type); zend_declare_property_null(method_type, "name", strlen("name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(method_type, "request_type_url", strlen("request_type_url"), @@ -2176,7 +2159,6 @@ zend_class_entry* mixin_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Mixin", Mixin, mixin) - zend_class_implements(mixin_type TSRMLS_CC, 1, message_type); zend_declare_property_null(mixin_type, "name", strlen("name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(mixin_type, "root", strlen("root"), @@ -2210,7 +2192,6 @@ zend_class_entry* option_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Option", Option, option) - zend_class_implements(option_type TSRMLS_CC, 1, message_type); zend_declare_property_null(option_type, "name", strlen("name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(option_type, "value", strlen("value"), @@ -2242,7 +2223,6 @@ zend_class_entry* source_context_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\SourceContext", SourceContext, source_context) - zend_class_implements(source_context_type TSRMLS_CC, 1, message_type); zend_declare_property_null(source_context_type, "file_name", strlen("file_name"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2271,7 +2251,6 @@ zend_class_entry* string_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\StringValue", StringValue, string_value) - zend_class_implements(string_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(string_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2300,7 +2279,6 @@ zend_class_entry* struct_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Struct", Struct, struct) - zend_class_implements(struct_type TSRMLS_CC, 1, message_type); zend_declare_property_null(struct_type, "fields", strlen("fields"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2339,7 +2317,6 @@ zend_class_entry* type_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Type", Type, type) - zend_class_implements(type_type TSRMLS_CC, 1, message_type); zend_declare_property_null(type_type, "name", strlen("name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(type_type, "fields", strlen("fields"), @@ -2383,7 +2360,6 @@ zend_class_entry* u_int32_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\UInt32Value", UInt32Value, u_int32_value) - zend_class_implements(u_int32_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(u_int32_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2412,7 +2388,6 @@ zend_class_entry* u_int64_value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\UInt64Value", UInt64Value, u_int64_value) - zend_class_implements(u_int64_value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(u_int64_value_type, "value", strlen("value"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END @@ -2452,7 +2427,6 @@ zend_class_entry* value_type; // Init class entry. PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Value", Value, value) - zend_class_implements(value_type TSRMLS_CC, 1, message_type); zend_declare_property_null(value_type, "kind", strlen("kind"), ZEND_ACC_PRIVATE TSRMLS_CC); PHP_PROTO_INIT_SUBMSGCLASS_END diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 0045358a44..5cbf348b02 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -137,7 +137,8 @@ const char* class_name = CLASSNAME; \ INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ LOWWERNAME##_methods); \ - LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ + LOWWERNAME##_type = zend_register_internal_class_ex( \ + &class_type, message_type, NULL TSRMLS_CC); \ LOWWERNAME##_type->create_object = message_create; \ zend_do_inheritance(LOWWERNAME##_type, message_type TSRMLS_CC); #define PHP_PROTO_INIT_SUBMSGCLASS_END \ @@ -404,7 +405,8 @@ static inline int php_proto_zend_hash_get_current_data_ex(HashTable* ht, const char* class_name = CLASSNAME; \ INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ LOWWERNAME##_methods); \ - LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ + LOWWERNAME##_type = zend_register_internal_class_ex( \ + &class_type, message_type TSRMLS_CC); \ zend_do_inheritance(LOWWERNAME##_type, message_type TSRMLS_CC); #define PHP_PROTO_INIT_SUBMSGCLASS_END \ } diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index a60fbe393b..93a16ddab4 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -180,7 +180,8 @@ bool native_slot_set_by_array(upb_fieldtype_t type, PHP_PROTO_ZVAL_STRINGL(DEREF(memory, zval*), Z_STRVAL_P(value), Z_STRLEN_P(value), 1); #else - *(zend_string**)memory = zend_string_dup(Z_STR_P(value), 0); + *(zend_string**)memory = + zend_string_init(Z_STRVAL_P(value), Z_STRLEN_P(value), 0); #endif break; } @@ -231,7 +232,8 @@ bool native_slot_set_by_map(upb_fieldtype_t type, const zend_class_entry* klass, PHP_PROTO_ZVAL_STRINGL(DEREF(memory, zval*), Z_STRVAL_P(value), Z_STRLEN_P(value), 1); #else - *(zend_string**)memory = zend_string_dup(Z_STR_P(value), 0); + *(zend_string**)memory = + zend_string_init(Z_STRVAL_P(value), Z_STRLEN_P(value), 0); #endif break; } diff --git a/php/tests/array_test.php b/php/tests/array_test.php index 36a649ed19..b0084332c9 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -7,7 +7,7 @@ use Google\Protobuf\Internal\GPBType; use Foo\TestMessage; use Foo\TestMessage\Sub; -class RepeatedFieldTest extends PHPUnit_Framework_TestCase +class RepeatedFieldTest extends \PHPUnit\Framework\TestCase { ######################################################### diff --git a/php/tests/compatibility_test.sh b/php/tests/compatibility_test.sh index dc8de5dc6e..f4af52471b 100755 --- a/php/tests/compatibility_test.sh +++ b/php/tests/compatibility_test.sh @@ -123,8 +123,12 @@ tests=( array_test.php encode_decode_test.php generated_class_test.php map_field sed -i.bak '/php_implementation_test.php/d' phpunit.xml sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh +sed -i.bak 's/generated_service_test.php//g' tests/test.sh sed -i.bak '/memory_leak_test.php/d' tests/test.sh sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php +sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php +sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php +sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php for t in "${tests[@]}" do remove_error_test tests/$t diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 8168eeb135..06f9a9006c 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -31,6 +31,7 @@ class EncodeDecodeTest extends TestBase { $m = new TestMessage(); $m->mergeFromJsonString("{\"optionalInt32\":1}"); + $this->assertEquals(1, $m->getOptionalInt32()); } public function testDecodeTopLevelBoolValue() @@ -276,6 +277,7 @@ class EncodeDecodeTest extends TestBase $to = new TestPackedMessage(); $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); TestUtil::assertTestPackedMessage($to); + $this->assertTrue(true); } public function testPackedDecodeUnpacked() @@ -283,6 +285,7 @@ class EncodeDecodeTest extends TestBase $to = new TestPackedMessage(); $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); TestUtil::assertTestPackedMessage($to); + $this->assertTrue(true); } public function testUnpackedEncode() @@ -298,6 +301,7 @@ class EncodeDecodeTest extends TestBase $to = new TestUnpackedMessage(); $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); TestUtil::assertTestPackedMessage($to); + $this->assertTrue(true); } public function testUnpackedDecodeUnpacked() @@ -305,6 +309,7 @@ class EncodeDecodeTest extends TestBase $to = new TestUnpackedMessage(); $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); TestUtil::assertTestPackedMessage($to); + $this->assertTrue(true); } public function testDecodeInt64() @@ -361,6 +366,7 @@ class EncodeDecodeTest extends TestBase $data = hex2bin('c80501'); $m = new TestMessage(); $m->mergeFromString($data); + $this->assertTrue(true); } public function testEncodeNegativeInt32() diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 96dad228a5..38c380969c 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -260,12 +260,14 @@ class GeneratedClassTest extends TestBase { $m = new TestMessage(); $m->setOptionalNestedEnum(NestedEnum::ZERO); + $this->assertTrue(true); } public function testLegacyNestedEnum() { $m = new TestMessage(); $m->setOptionalNestedEnum(\Foo\TestMessage_NestedEnum::ZERO); + $this->assertTrue(true); } public function testLegacyTypehintWithNestedEnums() @@ -405,6 +407,7 @@ class GeneratedClassTest extends TestBase $m = new TestMessage(); $hex = hex2bin("ff"); $m->setOptionalBytes($hex); + $this->assertTrue(true); } ######################################################### @@ -709,6 +712,8 @@ class GeneratedClassTest extends TestBase // test nested messages $sub = new NoNamespaceMessage\NestedMessage(); $n->setNestedMessage($sub); + + $this->assertTrue(true); } public function testEnumWithoutNamespace() @@ -718,6 +723,7 @@ class GeneratedClassTest extends TestBase $repeatedNoNamespaceEnum = $m->getRepeatedNoNamespaceEnum(); $repeatedNoNamespaceEnum[] = NoNameSpaceEnum::VALUE_A; $m->setRepeatedNoNamespaceEnum($repeatedNoNamespaceEnum); + $this->assertTrue(true); } ######################################################### @@ -1262,6 +1268,8 @@ class GeneratedClassTest extends TestBase $m = \Upper_enum_value\NotAllowed::NULL; $m = \Upper_enum_value\NotAllowed::VOID; $m = \Upper_enum_value\NotAllowed::ITERABLE; + + $this->assertTrue(true); } ######################################################### @@ -1297,6 +1305,7 @@ class GeneratedClassTest extends TestBase { $m = new testLowerCaseMessage(); $n = testLowerCaseEnum::VALUE; + $this->assertTrue(true); } ######################################################### @@ -1363,6 +1372,7 @@ class GeneratedClassTest extends TestBase ]); TestUtil::assertTestMessage($m); + $this->assertTrue(true); } ######################################################### diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php index 447bdd9b36..0260879328 100644 --- a/php/tests/map_field_test.php +++ b/php/tests/map_field_test.php @@ -7,7 +7,7 @@ use Google\Protobuf\Internal\MapField; use Foo\TestMessage; use Foo\TestMessage\Sub; -class MapFieldTest extends PHPUnit_Framework_TestCase { +class MapFieldTest extends \PHPUnit\Framework\TestCase { ######################################################### # Test int32 field. diff --git a/php/tests/test_base.php b/php/tests/test_base.php index 80f603c77a..27efc87a9e 100644 --- a/php/tests/test_base.php +++ b/php/tests/test_base.php @@ -4,7 +4,7 @@ use Foo\TestMessage; use Foo\TestEnum; use Foo\TestMessage\Sub; -class TestBase extends PHPUnit_Framework_TestCase +class TestBase extends \PHPUnit\Framework\TestCase { public function setFields(TestMessage $m) @@ -338,5 +338,6 @@ class TestBase extends PHPUnit_Framework_TestCase // This test is to avoid the warning of no test by php unit. public function testNone() { + $this->assertTrue(true); } } diff --git a/php/tests/well_known_test.php b/php/tests/well_known_test.php index db5d5a7a04..a16e070a45 100644 --- a/php/tests/well_known_test.php +++ b/php/tests/well_known_test.php @@ -48,6 +48,7 @@ class WellKnownTest extends TestBase { public function testImportDescriptorProto() { $msg = new TestImportDescriptorProto(); + $this->assertTrue(true); } public function testAny() diff --git a/tests.sh b/tests.sh index 047d579baa..80269d21aa 100755 --- a/tests.sh +++ b/tests.sh @@ -302,34 +302,25 @@ generate_php_test_proto() { use_php() { VERSION=$1 - PHP=`which php` - PHP_CONFIG=`which php-config` - PHPIZE=`which phpize` - ln -sfn "/usr/local/php-${VERSION}/bin/php" $PHP - ln -sfn "/usr/local/php-${VERSION}/bin/php-config" $PHP_CONFIG - ln -sfn "/usr/local/php-${VERSION}/bin/phpize" $PHPIZE + export PATH=/usr/local/php-${VERSION}/bin:$PATH + export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$CPLUS_INCLUDE_PATH + export C_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$C_INCLUDE_PATH generate_php_test_proto } use_php_zts() { VERSION=$1 - PHP=`which php` - PHP_CONFIG=`which php-config` - PHPIZE=`which phpize` - ln -sfn "/usr/local/php-${VERSION}-zts/bin/php" $PHP - ln -sfn "/usr/local/php-${VERSION}-zts/bin/php-config" $PHP_CONFIG - ln -sfn "/usr/local/php-${VERSION}-zts/bin/phpize" $PHPIZE + export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH + export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$CPLUS_INCLUDE_PATH + export C_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$C_INCLUDE_PATH generate_php_test_proto } use_php_bc() { VERSION=$1 - PHP=`which php` - PHP_CONFIG=`which php-config` - PHPIZE=`which phpize` - ln -sfn "/usr/local/php-${VERSION}-bc/bin/php" $PHP - ln -sfn "/usr/local/php-${VERSION}-bc/bin/php-config" $PHP_CONFIG - ln -sfn "/usr/local/php-${VERSION}-bc/bin/phpize" $PHPIZE + export PATH=/usr/local/php-${VERSION}-bc/bin:$PATH + export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$CPLUS_INCLUDE_PATH + export C_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$C_INCLUDE_PATH generate_php_test_proto } @@ -338,9 +329,8 @@ build_php5.5() { pushd php rm -rf vendor - cp -r /usr/local/vendor-5.5 vendor - wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit - phpunit + composer update + ./vendor/bin/phpunit popd pushd conformance make test_php @@ -349,7 +339,6 @@ build_php5.5() { build_php5.5_c() { use_php 5.5 - wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit pushd php/tests /bin/bash ./test.sh 5.5 popd @@ -361,7 +350,6 @@ build_php5.5_c() { build_php5.5_zts_c() { use_php_zts 5.5 - wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../.. # TODO(teboring): Add it back # pushd conformance @@ -373,9 +361,8 @@ build_php5.6() { use_php 5.6 pushd php rm -rf vendor - cp -r /usr/local/vendor-5.6 vendor - wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit - phpunit + composer update + ./vendor/bin/phpunit popd pushd conformance make test_php @@ -384,7 +371,6 @@ build_php5.6() { build_php5.6_c() { use_php 5.6 - wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh 5.6 && cd ../.. # TODO(teboring): Add it back # pushd conformance @@ -394,7 +380,6 @@ build_php5.6_c() { build_php5.6_zts_c() { use_php_zts 5.6 - wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../.. # TODO(teboring): Add it back # pushd conformance @@ -431,9 +416,8 @@ build_php7.0() { use_php 7.0 pushd php rm -rf vendor - cp -r /usr/local/vendor-7.0 vendor - wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit - phpunit + composer update + ./vendor/bin/phpunit popd pushd conformance make test_php @@ -442,7 +426,6 @@ build_php7.0() { build_php7.0_c() { use_php 7.0 - wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh 7.0 && cd ../.. # TODO(teboring): Add it back # pushd conformance @@ -452,7 +435,6 @@ build_php7.0_c() { build_php7.0_zts_c() { use_php_zts 7.0 - wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../.. # TODO(teboring): Add it back. # pushd conformance @@ -494,9 +476,8 @@ build_php7.1() { use_php 7.1 pushd php rm -rf vendor - cp -r /usr/local/vendor-7.1 vendor - wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit - phpunit + composer update + ./vendor/bin/phpunit popd pushd conformance make test_php @@ -506,7 +487,6 @@ build_php7.1() { build_php7.1_c() { ENABLE_CONFORMANCE_TEST=$1 use_php 7.1 - wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh 7.1 && cd ../.. if [ "$ENABLE_CONFORMANCE_TEST" = "true" ] then @@ -518,7 +498,6 @@ build_php7.1_c() { build_php7.1_zts_c() { use_php_zts 7.1 - wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../.. pushd conformance # make test_php_c From 453274b72d3f7a90bc2ceb178aeeba16e80ee008 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 18 Dec 2018 13:42:31 -0800 Subject: [PATCH 29/70] Removed Kokoro config for 64-bit Linux This Kokoro configuration is no longer being used and the build.sh script does not work anymore, so let's delete this configuration. --- kokoro/linux/64-bit/build.sh | 17 ----------------- kokoro/linux/64-bit/continuous.cfg | 11 ----------- kokoro/linux/64-bit/presubmit.cfg | 11 ----------- 3 files changed, 39 deletions(-) delete mode 100755 kokoro/linux/64-bit/build.sh delete mode 100644 kokoro/linux/64-bit/continuous.cfg delete mode 100644 kokoro/linux/64-bit/presubmit.cfg diff --git a/kokoro/linux/64-bit/build.sh b/kokoro/linux/64-bit/build.sh deleted file mode 100755 index 48ddbce532..0000000000 --- a/kokoro/linux/64-bit/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERFILE_DIR=kokoro/linux/64-bit -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="csharp java_jdk7 javanano_jdk7 java_oracle7 javanano_oracle7 python python_cpp ruby_all javascript golang php_all" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/64-bit/continuous.cfg b/kokoro/linux/64-bit/continuous.cfg deleted file mode 100644 index 3a4faac117..0000000000 --- a/kokoro/linux/64-bit/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/64-bit/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/64-bit/presubmit.cfg b/kokoro/linux/64-bit/presubmit.cfg deleted file mode 100644 index 3a4faac117..0000000000 --- a/kokoro/linux/64-bit/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/64-bit/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} From 6adc3d74fbe0668b2fee4c9e3b22f3d8fbaf374f Mon Sep 17 00:00:00 2001 From: Yilun Chong Date: Tue, 18 Dec 2018 16:20:23 -0800 Subject: [PATCH 30/70] Fix benchmark to use docker image on kokoro (#5481) * Fix benchmark to use docker image on kokoro * Deleted pure php benchmark and fix long time benchmark --- benchmarks/php/PhpBenchmark.php | 2 +- benchmarks/python/py_benchmark.py | 7 +- benchmarks/util/result_uploader.py | 8 +-- kokoro/linux/benchmark/build.sh | 109 ++--------------------------- kokoro/linux/benchmark/run.sh | 105 +++++++++++++++++++++++++++ tests.sh | 8 ++- 6 files changed, 126 insertions(+), 113 deletions(-) mode change 100755 => 100644 kokoro/linux/benchmark/build.sh create mode 100755 kokoro/linux/benchmark/run.sh diff --git a/benchmarks/php/PhpBenchmark.php b/benchmarks/php/PhpBenchmark.php index 9c1132d073..7220638762 100644 --- a/benchmarks/php/PhpBenchmark.php +++ b/benchmarks/php/PhpBenchmark.php @@ -62,7 +62,7 @@ class Benchmark $t = $this->runBenchmarkWithTimes(1); $times = ceil($this->benchmark_time / $t); return $this->total_bytes * $times / - $this->runBenchmarkWithTimes($times) * + ($times == 1 ? $t : $this->runBenchmarkWithTimes($times)) * $this->coefficient; } diff --git a/benchmarks/python/py_benchmark.py b/benchmarks/python/py_benchmark.py index ebb1974936..40c7af58a0 100755 --- a/benchmarks/python/py_benchmark.py +++ b/benchmarks/python/py_benchmark.py @@ -134,9 +134,10 @@ class Benchmark: t = self.dry_run(test_method_args, setup_method_args); if t < 3 : reps = int(math.ceil(3 / t)) * self.full_iteration - t = timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args), - setup=self.full_setup_code(setup_method_args), - number=reps); + if reps != self.full_iteration: + t = timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args), + setup=self.full_setup_code(setup_method_args), + number=reps); return self.total_bytes * 1.0 / 2 ** 20 / (1.0 * t / reps) diff --git a/benchmarks/util/result_uploader.py b/benchmarks/util/result_uploader.py index cff2d9d2a2..021cc54622 100755 --- a/benchmarks/util/result_uploader.py +++ b/benchmarks/util/result_uploader.py @@ -61,12 +61,12 @@ def upload_result(result_list, metadata): new_result["timestamp"] = _INITIAL_TIME print(labels_string) - bq = big_query_utils.create_big_query() - row = big_query_utils.make_row(str(uuid.uuid4()), new_result) - if not big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET, + bq = big_query_utils.create_big_query() + row = big_query_utils.make_row(str(uuid.uuid4()), new_result) + if not big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET, _TABLE + "$" + _NOW, [row]): - print('Error when uploading result', new_result) + print('Error when uploading result', new_result) if __name__ == "__main__": diff --git a/kokoro/linux/benchmark/build.sh b/kokoro/linux/benchmark/build.sh old mode 100755 new mode 100644 index d83275397e..bec52b8ef7 --- a/kokoro/linux/benchmark/build.sh +++ b/kokoro/linux/benchmark/build.sh @@ -1,108 +1,9 @@ #!/bin/bash -# -# Change to repo root + cd $(dirname $0)/../../.. +export DOCKERFILE_DIR=kokoro/linux/64-bit +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh export OUTPUT_DIR=testoutput -oldpwd=`pwd` - -# tcmalloc -if [ ! -f gperftools/.libs/libtcmalloc.so ]; then - git clone https://github.com/gperftools/gperftools.git - cd gperftools - ./autogen.sh - ./configure - make -j8 - cd .. -fi - -# download datasets for benchmark -cd benchmarks -./download_data.sh -datasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs) -echo $datasets -cd $oldpwd - -# build Python protobuf -./autogen.sh -./configure CXXFLAGS="-fPIC -O2" -make -j8 -cd python -python setup.py build --cpp_implementation -pip install . --user - - -# build and run Python benchmark -cd ../benchmarks -make python-pure-python-benchmark -make python-cpp-reflection-benchmark -make -j8 python-cpp-generated-code-benchmark -echo "[" > tmp/python_result.json -echo "benchmarking pure python..." -./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets >> tmp/python_result.json -echo "," >> "tmp/python_result.json" -echo "benchmarking python cpp reflection..." -env LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/src/.libs" ./python-cpp-reflection-benchmark --json --behavior_prefix="cpp-reflection-benchmark" $datasets >> tmp/python_result.json -echo "," >> "tmp/python_result.json" -echo "benchmarking python cpp generated code..." -env LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/src/.libs" ./python-cpp-generated-code-benchmark --json --behavior_prefix="cpp-generated-code-benchmark" $datasets >> tmp/python_result.json -echo "]" >> "tmp/python_result.json" -cd $oldpwd - -# build CPP protobuf -./configure -make clean && make -j8 - -# build Java protobuf -cd java -mvn package -cd .. - -# build CPP benchmark -cd benchmarks -mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp -echo "benchmarking cpp..." -env LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets -cd $oldpwd - -# build go protobuf -export PATH="`pwd`/src:$PATH" -export GOPATH="$HOME/gocode" -mkdir -p "$GOPATH/src/github.com/google" -rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf" -ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf" -export PATH="$GOPATH/bin:$PATH" -go get github.com/golang/protobuf/protoc-gen-go - -# build go benchmark -cd benchmarks -make go-benchmark -echo "benchmarking go..." -./go-benchmark $datasets > tmp/go_result.txt - -# build java benchmark -make java-benchmark -echo "benchmarking java..." -./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets - -make js-benchmark -echo "benchmarking js..." -./js-benchmark $datasets --json_output=$(pwd)/tmp/node_result.json - -make -j8 generate_proto3_data -proto3_datasets=$(for file in $datasets; do echo $(pwd)/tmp/proto3_data/${file#$(pwd)}; done | xargs) -echo $proto3_datasets - -# build php benchmark -make -j8 php-benchmark -echo "benchmarking php..." -./php-benchmark $proto3_datasets --json --behavior_prefix="php" > tmp/php_result.json -make -j8 php-c-benchmark -echo "benchmarking php_c..." -./php-c-benchmark $proto3_datasets --json --behavior_prefix="php_c" > tmp/php_c_result.json - -# upload result to bq -make python_add_init -env LD_LIBRARY_PATH="$oldpwd/src/.libs" python -m util.result_uploader -php="../tmp/php_result.json" -php_c="../tmp/php_c_result.json" \ - -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -go="../tmp/go_result.txt" -python="../tmp/python_result.json" -node="../tmp/node_result.json" -cd $oldpwd +export TEST_SET="benchmark" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/benchmark/run.sh b/kokoro/linux/benchmark/run.sh new file mode 100755 index 0000000000..264bdaa14c --- /dev/null +++ b/kokoro/linux/benchmark/run.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Change to repo root +cd $(dirname $0)/../../.. + +export OUTPUT_DIR=testoutput +oldpwd=`pwd` + +# tcmalloc +if [ ! -f gperftools/.libs/libtcmalloc.so ]; then + git clone https://github.com/gperftools/gperftools.git + cd gperftools + ./autogen.sh + ./configure + make -j8 + cd .. +fi + +# download datasets for benchmark +cd benchmarks +./download_data.sh +datasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs) +echo $datasets +cd $oldpwd + +# build Python protobuf +./autogen.sh +./configure CXXFLAGS="-fPIC -O2" +make -j8 +cd python +python setup.py build --cpp_implementation +pip install . --user + + +# build and run Python benchmark +cd ../benchmarks +make python-pure-python-benchmark +make python-cpp-reflection-benchmark +make -j8 python-cpp-generated-code-benchmark +echo "[" > tmp/python_result.json +echo "benchmarking pure python..." +./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets >> tmp/python_result.json +echo "," >> "tmp/python_result.json" +echo "benchmarking python cpp reflection..." +env LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/src/.libs" ./python-cpp-reflection-benchmark --json --behavior_prefix="cpp-reflection-benchmark" $datasets >> tmp/python_result.json +echo "," >> "tmp/python_result.json" +echo "benchmarking python cpp generated code..." +env LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/src/.libs" ./python-cpp-generated-code-benchmark --json --behavior_prefix="cpp-generated-code-benchmark" $datasets >> tmp/python_result.json +echo "]" >> "tmp/python_result.json" +cd $oldpwd + +# build CPP protobuf +./configure +make clean && make -j8 + +# build Java protobuf +cd java +mvn package +cd .. + +# build CPP benchmark +cd benchmarks +mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp +echo "benchmarking cpp..." +env LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets +cd $oldpwd + +# build go protobuf +export PATH="`pwd`/src:$PATH" +export GOPATH="$HOME/gocode" +mkdir -p "$GOPATH/src/github.com/google" +rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf" +ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf" +export PATH="$GOPATH/bin:$PATH" +go get github.com/golang/protobuf/protoc-gen-go + +# build go benchmark +cd benchmarks +make go-benchmark +echo "benchmarking go..." +./go-benchmark $datasets > tmp/go_result.txt + +# build java benchmark +make java-benchmark +echo "benchmarking java..." +./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets + +make js-benchmark +echo "benchmarking js..." +./js-benchmark $datasets --json_output=$(pwd)/tmp/node_result.json + +make -j8 generate_proto3_data +proto3_datasets=$(for file in $datasets; do echo $(pwd)/tmp/proto3_data/${file#$(pwd)}; done | xargs) +echo $proto3_datasets + +# build php benchmark +make -j8 php-c-benchmark +echo "benchmarking php_c..." +./php-c-benchmark $proto3_datasets --json --behavior_prefix="php_c" > tmp/php_c_result.json + +# upload result to bq +make python_add_init +env LD_LIBRARY_PATH="$oldpwd/src/.libs" python -m util.result_uploader -php_c="../tmp/php_c_result.json" \ + -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -go="../tmp/go_result.txt" -python="../tmp/python_result.json" -node="../tmp/node_result.json" +cd $oldpwd diff --git a/tests.sh b/tests.sh index 80269d21aa..331e95059c 100755 --- a/tests.sh +++ b/tests.sh @@ -524,6 +524,11 @@ build_php_all() { build_php_compatibility } +build_benchmark() { + use_php 7.1 + cd kokoro/linux/benchmark && ./run.sh +} + # -------- main -------- if [ "$#" -ne 1 ]; then @@ -556,7 +561,8 @@ Usage: $0 { cpp | php_compatibility | php7.1 | php7.1_c | - php_all) + php_all | + benchmark) " exit 1 fi From 4dec4f93710f70829a72849daa7f752a10e28c4d Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 18 Dec 2018 18:07:24 -0800 Subject: [PATCH 31/70] Rebuild python docker image (#5475) * Rebuild python docker image * Update docker image * Change call to build_and_run_docker.sh * Set up python tests for different versions * Fix comments --- .../dockerfile/test/python_jessie/Dockerfile | 39 +++++++++++ .../dockerfile/test/python_stretch/Dockerfile | 47 +++++++++++++ kokoro/linux/python27/build.sh | 18 +++++ kokoro/linux/python27/continuous.cfg | 11 ++++ kokoro/linux/python27/presubmit.cfg | 11 ++++ kokoro/linux/python27_cpp/build.sh | 18 +++++ kokoro/linux/python27_cpp/continuous.cfg | 11 ++++ kokoro/linux/python27_cpp/presubmit.cfg | 11 ++++ kokoro/linux/python33/build.sh | 18 +++++ kokoro/linux/python33/continuous.cfg | 11 ++++ kokoro/linux/python33/presubmit.cfg | 11 ++++ kokoro/linux/python33_cpp/build.sh | 18 +++++ kokoro/linux/python33_cpp/continuous.cfg | 11 ++++ kokoro/linux/python33_cpp/presubmit.cfg | 11 ++++ kokoro/linux/python34/build.sh | 18 +++++ kokoro/linux/python34/continuous.cfg | 11 ++++ kokoro/linux/python34/presubmit.cfg | 11 ++++ kokoro/linux/python34_cpp/build.sh | 18 +++++ kokoro/linux/python34_cpp/continuous.cfg | 11 ++++ kokoro/linux/python34_cpp/presubmit.cfg | 11 ++++ kokoro/linux/python35/build.sh | 18 +++++ kokoro/linux/python35/continuous.cfg | 11 ++++ kokoro/linux/python35/presubmit.cfg | 11 ++++ kokoro/linux/python35_cpp/build.sh | 18 +++++ kokoro/linux/python35_cpp/continuous.cfg | 11 ++++ kokoro/linux/python35_cpp/presubmit.cfg | 11 ++++ kokoro/linux/python36/build.sh | 18 +++++ kokoro/linux/python36/continuous.cfg | 11 ++++ kokoro/linux/python36/presubmit.cfg | 11 ++++ kokoro/linux/python36_cpp/build.sh | 18 +++++ kokoro/linux/python36_cpp/continuous.cfg | 11 ++++ kokoro/linux/python36_cpp/presubmit.cfg | 11 ++++ kokoro/linux/python37/build.sh | 18 +++++ kokoro/linux/python37/continuous.cfg | 11 ++++ kokoro/linux/python37/presubmit.cfg | 11 ++++ kokoro/linux/python37_cpp/build.sh | 18 +++++ kokoro/linux/python37_cpp/continuous.cfg | 11 ++++ kokoro/linux/python37_cpp/presubmit.cfg | 11 ++++ python/setup.py | 3 + tests.sh | 66 +++++++++++++++++++ 40 files changed, 635 insertions(+) create mode 100644 kokoro/linux/dockerfile/test/python_jessie/Dockerfile create mode 100644 kokoro/linux/dockerfile/test/python_stretch/Dockerfile create mode 100755 kokoro/linux/python27/build.sh create mode 100644 kokoro/linux/python27/continuous.cfg create mode 100644 kokoro/linux/python27/presubmit.cfg create mode 100755 kokoro/linux/python27_cpp/build.sh create mode 100644 kokoro/linux/python27_cpp/continuous.cfg create mode 100644 kokoro/linux/python27_cpp/presubmit.cfg create mode 100755 kokoro/linux/python33/build.sh create mode 100644 kokoro/linux/python33/continuous.cfg create mode 100644 kokoro/linux/python33/presubmit.cfg create mode 100755 kokoro/linux/python33_cpp/build.sh create mode 100644 kokoro/linux/python33_cpp/continuous.cfg create mode 100644 kokoro/linux/python33_cpp/presubmit.cfg create mode 100755 kokoro/linux/python34/build.sh create mode 100644 kokoro/linux/python34/continuous.cfg create mode 100644 kokoro/linux/python34/presubmit.cfg create mode 100755 kokoro/linux/python34_cpp/build.sh create mode 100644 kokoro/linux/python34_cpp/continuous.cfg create mode 100644 kokoro/linux/python34_cpp/presubmit.cfg create mode 100755 kokoro/linux/python35/build.sh create mode 100644 kokoro/linux/python35/continuous.cfg create mode 100644 kokoro/linux/python35/presubmit.cfg create mode 100755 kokoro/linux/python35_cpp/build.sh create mode 100644 kokoro/linux/python35_cpp/continuous.cfg create mode 100644 kokoro/linux/python35_cpp/presubmit.cfg create mode 100755 kokoro/linux/python36/build.sh create mode 100644 kokoro/linux/python36/continuous.cfg create mode 100644 kokoro/linux/python36/presubmit.cfg create mode 100755 kokoro/linux/python36_cpp/build.sh create mode 100644 kokoro/linux/python36_cpp/continuous.cfg create mode 100644 kokoro/linux/python36_cpp/presubmit.cfg create mode 100755 kokoro/linux/python37/build.sh create mode 100644 kokoro/linux/python37/continuous.cfg create mode 100644 kokoro/linux/python37/presubmit.cfg create mode 100755 kokoro/linux/python37_cpp/build.sh create mode 100644 kokoro/linux/python37_cpp/continuous.cfg create mode 100644 kokoro/linux/python37_cpp/presubmit.cfg diff --git a/kokoro/linux/dockerfile/test/python_jessie/Dockerfile b/kokoro/linux/dockerfile/test/python_jessie/Dockerfile new file mode 100644 index 0000000000..b5a53a3e5f --- /dev/null +++ b/kokoro/linux/dockerfile/test/python_jessie/Dockerfile @@ -0,0 +1,39 @@ +FROM debian:jessie + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean + +# Install python dependencies +RUN apt-get update && apt-get install -y \ + python-setuptools \ + python-all-dev \ + python3-all-dev \ + python-pip + +# Install Python packages from PyPI +RUN pip install --upgrade pip==10.0.1 +RUN pip install virtualenv +RUN pip install six==1.10.0 twisted==17.5.0 + +# Install pip and virtualenv for Python 3.4 +RUN curl https://bootstrap.pypa.io/get-pip.py | python3.4 +RUN python3.4 -m pip install virtualenv diff --git a/kokoro/linux/dockerfile/test/python_stretch/Dockerfile b/kokoro/linux/dockerfile/test/python_stretch/Dockerfile new file mode 100644 index 0000000000..1dba53087f --- /dev/null +++ b/kokoro/linux/dockerfile/test/python_stretch/Dockerfile @@ -0,0 +1,47 @@ +FROM debian:stretch + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean + +# Install Python 2.7 +RUN apt-get update && apt-get install -y python2.7 python-all-dev +RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 + +# Install python dependencies +RUN apt-get update && apt-get install -y \ + python-setuptools \ + python-pip + +# Add Debian 'testing' repository +RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local + +# Install Python3 +RUN apt-get update && apt-get -t testing install -y \ + python3.5 \ + python3.6 \ + python3.7 \ + python3-all-dev + +RUN curl https://bootstrap.pypa.io/get-pip.py | python3.5 +RUN curl https://bootstrap.pypa.io/get-pip.py | python3.6 +RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7 diff --git a/kokoro/linux/python27/build.sh b/kokoro/linux/python27/build.sh new file mode 100755 index 0000000000..8c40ba3604 --- /dev/null +++ b/kokoro/linux/python27/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_jessie +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python27" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python27/continuous.cfg b/kokoro/linux/python27/continuous.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python27/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python27/presubmit.cfg b/kokoro/linux/python27/presubmit.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python27/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python27_cpp/build.sh b/kokoro/linux/python27_cpp/build.sh new file mode 100755 index 0000000000..2ff09a21fd --- /dev/null +++ b/kokoro/linux/python27_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_jessie +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python27_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python27_cpp/continuous.cfg b/kokoro/linux/python27_cpp/continuous.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python27_cpp/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python27_cpp/presubmit.cfg b/kokoro/linux/python27_cpp/presubmit.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python27_cpp/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python33/build.sh b/kokoro/linux/python33/build.sh new file mode 100755 index 0000000000..84a9acdb73 --- /dev/null +++ b/kokoro/linux/python33/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_jessie +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python33" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python33/continuous.cfg b/kokoro/linux/python33/continuous.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python33/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python33/presubmit.cfg b/kokoro/linux/python33/presubmit.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python33/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python33_cpp/build.sh b/kokoro/linux/python33_cpp/build.sh new file mode 100755 index 0000000000..ad33e89d25 --- /dev/null +++ b/kokoro/linux/python33_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_jessie +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python33_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python33_cpp/continuous.cfg b/kokoro/linux/python33_cpp/continuous.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python33_cpp/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python33_cpp/presubmit.cfg b/kokoro/linux/python33_cpp/presubmit.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python33_cpp/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python34/build.sh b/kokoro/linux/python34/build.sh new file mode 100755 index 0000000000..25dfd5dfcd --- /dev/null +++ b/kokoro/linux/python34/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_jessie +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python34" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python34/continuous.cfg b/kokoro/linux/python34/continuous.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python34/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python34/presubmit.cfg b/kokoro/linux/python34/presubmit.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python34/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python34_cpp/build.sh b/kokoro/linux/python34_cpp/build.sh new file mode 100755 index 0000000000..e4590ffbad --- /dev/null +++ b/kokoro/linux/python34_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_jessie +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python34_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python34_cpp/continuous.cfg b/kokoro/linux/python34_cpp/continuous.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python34_cpp/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python34_cpp/presubmit.cfg b/kokoro/linux/python34_cpp/presubmit.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python34_cpp/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python35/build.sh b/kokoro/linux/python35/build.sh new file mode 100755 index 0000000000..f978e2ad11 --- /dev/null +++ b/kokoro/linux/python35/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python35" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python35/continuous.cfg b/kokoro/linux/python35/continuous.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python35/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python35/presubmit.cfg b/kokoro/linux/python35/presubmit.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python35/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python35_cpp/build.sh b/kokoro/linux/python35_cpp/build.sh new file mode 100755 index 0000000000..2a79246d59 --- /dev/null +++ b/kokoro/linux/python35_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python35_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python35_cpp/continuous.cfg b/kokoro/linux/python35_cpp/continuous.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python35_cpp/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python35_cpp/presubmit.cfg b/kokoro/linux/python35_cpp/presubmit.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python35_cpp/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python36/build.sh b/kokoro/linux/python36/build.sh new file mode 100755 index 0000000000..633145bcec --- /dev/null +++ b/kokoro/linux/python36/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python36" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python36/continuous.cfg b/kokoro/linux/python36/continuous.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python36/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python36/presubmit.cfg b/kokoro/linux/python36/presubmit.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python36/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python36_cpp/build.sh b/kokoro/linux/python36_cpp/build.sh new file mode 100755 index 0000000000..8e120ff37c --- /dev/null +++ b/kokoro/linux/python36_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python36_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python36_cpp/continuous.cfg b/kokoro/linux/python36_cpp/continuous.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python36_cpp/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python36_cpp/presubmit.cfg b/kokoro/linux/python36_cpp/presubmit.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python36_cpp/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python37/build.sh b/kokoro/linux/python37/build.sh new file mode 100755 index 0000000000..554aa09448 --- /dev/null +++ b/kokoro/linux/python37/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python37" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python37/continuous.cfg b/kokoro/linux/python37/continuous.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python37/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python37/presubmit.cfg b/kokoro/linux/python37/presubmit.cfg new file mode 100644 index 0000000000..e2fc4136f0 --- /dev/null +++ b/kokoro/linux/python37/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python37_cpp/build.sh b/kokoro/linux/python37_cpp/build.sh new file mode 100755 index 0000000000..8fdc8f9339 --- /dev/null +++ b/kokoro/linux/python37_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python37_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python37_cpp/continuous.cfg b/kokoro/linux/python37_cpp/continuous.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python37_cpp/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/python37_cpp/presubmit.cfg b/kokoro/linux/python37_cpp/presubmit.cfg new file mode 100644 index 0000000000..b1b0e550ff --- /dev/null +++ b/kokoro/linux/python37_cpp/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/python/setup.py b/python/setup.py index e884acbe32..5f052673e1 100755 --- a/python/setup.py +++ b/python/setup.py @@ -262,6 +262,9 @@ if __name__ == '__main__': "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", ], namespace_packages=['google'], packages=find_packages( diff --git a/tests.sh b/tests.sh index 331e95059c..fdc3600044 100755 --- a/tests.sh +++ b/tests.sh @@ -220,6 +220,38 @@ build_python() { cd .. } +build_python_version() { + internal_build_cpp + cd python + envlist=$1 + tox -e $envlist + cd .. +} + +build_python27() { + build_python_version py27-python +} + +build_python33() { + build_python_version py33-python +} + +build_python34() { + build_python_version py34-python +} + +build_python35() { + build_python_version py35-python +} + +build_python36() { + build_python_version py36-python +} + +build_python37() { + build_python_version py37-python +} + build_python_cpp() { internal_build_cpp export LD_LIBRARY_PATH=../src/.libs # for Linux @@ -234,6 +266,40 @@ build_python_cpp() { cd .. } +build_python_cpp_version() { + internal_build_cpp + export LD_LIBRARY_PATH=../src/.libs # for Linux + export DYLD_LIBRARY_PATH=../src/.libs # for OS X + cd python + envlist=$1 + tox -e $envlist + cd .. +} + +build_python27_cpp() { + build_python_cpp_version py27-cpp +} + +build_python33_cpp() { + build_python_cpp_version py33-cpp +} + +build_python34_cpp() { + build_python_cpp_version py34-cpp +} + +build_python35_cpp() { + build_python_cpp_version py35-cpp +} + +build_python36_cpp() { + build_python_cpp_version py36-cpp +} + +build_python37_cpp() { + build_python_cpp_version py37-cpp +} + build_python_compatibility() { internal_build_cpp # Use the unit-tests extraced from 2.5.0 to test the compatibilty. From 8c9e0ff0f711616afa0c1a3252be587a3c0e53c7 Mon Sep 17 00:00:00 2001 From: Aaron Bray Date: Tue, 18 Dec 2018 21:55:22 -0500 Subject: [PATCH 32/70] Use NoLocalStrtod for international compliance Recieved errors pasing json files with decimal floats from European colleagues --- src/google/protobuf/stubs/strutil.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index 5bf9f2e6a8..d45b3282ae 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc @@ -41,6 +41,7 @@ #include #include +#include #ifdef _WIN32 // MSVC has only _snprintf, not snprintf. @@ -1286,7 +1287,7 @@ char* DoubleToBuffer(double value, char* buffer) { // of a double. This long double may have extra bits that make it compare // unequal to "value" even though it would be exactly equal if it were // truncated to a double. - volatile double parsed_value = strtod(buffer, nullptr); + volatile double parsed_value = io::NoLocaleStrtod(buffer, nullptr); if (parsed_value != value) { int snprintf_result = snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value); @@ -1338,7 +1339,7 @@ bool safe_strtof(const char* str, float* value) { char* endptr; errno = 0; // errno only gets set on errors #if defined(_WIN32) || defined (__hpux) // has no strtof() - *value = strtod(str, &endptr); + *value = io::NoLocaleStrtod(str, &endptr); #else *value = strtof(str, &endptr); #endif @@ -1347,7 +1348,7 @@ bool safe_strtof(const char* str, float* value) { bool safe_strtod(const char* str, double* value) { char* endptr; - *value = strtod(str, &endptr); + *value = io::NoLocaleStrtod(str, &endptr); if (endptr != str) { while (ascii_isspace(*endptr)) ++endptr; } From 3c547fcdf377d8caf1f9170f8b76f16306231e8b Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Wed, 19 Dec 2018 11:25:53 -0800 Subject: [PATCH 33/70] Lower the severity of lower-case ruby enum to warning. Add conformance test for allow_alias with lower_case enums --- ruby/ext/google/protobuf_c/message.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 2f14ef6ecf..b1d6a5e289 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -697,6 +697,11 @@ VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) { upb_enum_next(&it)) { const char* name = upb_enum_iter_name(&it); int32_t value = upb_enum_iter_number(&it); + if (name[0] < 'A' || name[0] > 'Z') { + rb_warn("Enum value '%s' does not start with an uppercase letter " + "as is required for Ruby constants.", + name); + } rb_define_const(mod, name, INT2NUM(value)); } From e24d9a8aba909f4d74f7659cf9c98636ed18d05c Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Wed, 19 Dec 2018 15:48:57 -0800 Subject: [PATCH 34/70] Add dependency to AliasedEnum in PHP --- conformance/conformance_php.php | 1 + 1 file changed, 1 insertion(+) diff --git a/conformance/conformance_php.php b/conformance/conformance_php.php index cc6d4b9f0a..80860c9504 100755 --- a/conformance/conformance_php.php +++ b/conformance/conformance_php.php @@ -8,6 +8,7 @@ require_once("Conformance/TestCategory.php"); require_once("Protobuf_test_messages/Proto3/ForeignMessage.php"); require_once("Protobuf_test_messages/Proto3/ForeignEnum.php"); require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3.php"); +require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php"); require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php"); require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php"); From 71fc8b4b252897ea6c674f19e9659dfdea1da641 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 19 Dec 2018 16:08:57 -0800 Subject: [PATCH 35/70] Update kokoro badges for python tests (#5495) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa266603fd..f6229563e0 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ how to install protobuf runtime for that specific language: |--------------------------------------|-------------------------------------------------------------|--------|-------|---------| | C++ (include C++ runtime and protoc) | [src](src) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-cpp_distcheck.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fcpp_distcheck%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-bazel.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fbazel%2Fcontinuous) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fcpp%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-cpp_distcheck.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fcpp_distcheck%2Fcontinuous) | [![Build status](https://ci.appveyor.com/api/projects/status/73ctee6ua4w2ruin?svg=true)](https://ci.appveyor.com/project/protobuf/protobuf) | | Java | [java](java) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-java_compatibility.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fjava_compatibility%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-java_jdk7.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fjava_jdk7%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-java_oracle7.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fjava_oracle7%2Fcontinuous) | | | -| Python | [python](python) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python_compatibility.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_compatibility%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_cpp%2Fcontinuous) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython_cpp%2Fcontinuous) | | +| Python | [python](python) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python27.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython27%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python33.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython33%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python34.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython34%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python35.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython35%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python36.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython36%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python37.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython37%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python_compatibility.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_compatibility%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python27_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython27_cpp%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python33_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython33_cpp%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python34_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython34_cpp%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python35_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython35_cpp%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python36_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython36_cpp%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python37_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython37_cpp%2Fcontinuous) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython_cpp%2Fcontinuous) | | | Objective-C | [objectivec](objectivec) | | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_cocoapods_integration.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_cocoapods_integration%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_ios_debug.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_ios_debug%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_ios_release.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_ios_release%2Fcontinuous)
[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_osx.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_osx%2Fcontinuous) | | | C# | [csharp](csharp) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-csharp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fcsharp%2Fcontinuous) | | [![Build status](https://ci.appveyor.com/api/projects/status/73ctee6ua4w2ruin?svg=true)](https://ci.appveyor.com/project/protobuf/protobuf) | | JavaScript | [js](js) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-javascript.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fjavascript%2Fcontinuous) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-javascript.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fjavascript%2Fcontinuous) | | From 424308216a40f9c0104cd86a311fafea9f8b6989 Mon Sep 17 00:00:00 2001 From: Aaron Bray Date: Thu, 20 Dec 2018 14:13:57 -0500 Subject: [PATCH 36/70] Add strtod to libprotobuf-lite --- cmake/libprotobuf-lite.cmake | 2 ++ cmake/libprotobuf.cmake | 2 -- src/Makefile.am | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index 1d0b0b848a..2ae21a9eb6 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -6,6 +6,7 @@ set(libprotobuf_lite_files ${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.cc ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc + ${protobuf_source_dir}/src/google/protobuf/io/strtod.cc ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc ${protobuf_source_dir}/src/google/protobuf/message_lite.cc @@ -31,6 +32,7 @@ set(libprotobuf_lite_includes ${protobuf_source_dir}/src/google/protobuf/generated_message_util.h ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.h ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h + ${protobuf_source_dir}/src/google/protobuf/io/strtod.h ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h ${protobuf_source_dir}/src/google/protobuf/message_lite.h diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index bd570be7d9..9a434a7db6 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -16,7 +16,6 @@ set(libprotobuf_files ${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven.cc ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc ${protobuf_source_dir}/src/google/protobuf/io/printer.cc - ${protobuf_source_dir}/src/google/protobuf/io/strtod.cc ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.cc ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc ${protobuf_source_dir}/src/google/protobuf/map_field.cc @@ -72,7 +71,6 @@ set(libprotobuf_includes ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.h ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.h ${protobuf_source_dir}/src/google/protobuf/io/printer.h - ${protobuf_source_dir}/src/google/protobuf/io/strtod.h ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.h ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.h ${protobuf_source_dir}/src/google/protobuf/map_field.h diff --git a/src/Makefile.am b/src/Makefile.am index 24c63669fd..b74284a75b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -209,6 +209,7 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/wire_format_lite.cc \ google/protobuf/io/coded_stream.cc \ google/protobuf/io/coded_stream_inl.h \ + google/protobuf/io/strtod.cc \ google/protobuf/io/zero_copy_stream.cc \ google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -253,7 +254,6 @@ libprotobuf_la_SOURCES = \ google/protobuf/wrappers.pb.cc \ google/protobuf/io/gzip_stream.cc \ google/protobuf/io/printer.cc \ - google/protobuf/io/strtod.cc \ google/protobuf/io/tokenizer.cc \ google/protobuf/io/zero_copy_stream_impl.cc \ google/protobuf/compiler/importer.cc \ From 624a40a387e1b2da4c6bbde44ad3d0a5efb9879b Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Thu, 20 Dec 2018 14:21:20 -0800 Subject: [PATCH 37/70] Down-integrate internal changes to github. --- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 204331 -> 204331 bytes .../java/com/google/protobuf/Descriptors.java | 19 +- .../google/protobuf/GeneratedMessageV3.java | 9 + .../java/com/google/protobuf/TextFormat.java | 61 +- .../java/com/google/protobuf/UnsafeUtil.java | 4 +- .../main/java/com/google/protobuf/Utf8.java | 3 +- .../google/protobuf/DynamicMessageTest.java | 13 + .../google/protobuf/GeneratedMessageTest.java | 23 + .../com/google/protobuf/map_lite_test.proto | 5 +- .../com/google/protobuf/util/Durations.java | 30 +- .../google/protobuf/util/FieldMaskTree.java | 21 +- .../google/protobuf/util/FieldMaskUtil.java | 49 +- .../com/google/protobuf/util/JsonFormat.java | 13 +- .../com/google/protobuf/util/Timestamps.java | 26 +- .../google/protobuf/util/JsonFormatTest.java | 57 +- .../com/google/protobuf/util/json_test.proto | 14 +- js/binary/constants.js | 4 +- js/binary/decoder.js | 2 +- js/binary/reader.js | 2 +- js/message_test.js | 484 +++--- .../protobuf/internal/json_format_test.py | 45 +- .../internal/missing_enum_values.proto | 1 + .../protobuf/internal/python_message.py | 6 +- .../protobuf/internal/text_format_test.py | 36 +- .../protobuf/internal/unknown_fields_test.py | 13 + python/google/protobuf/json_format.py | 86 +- python/google/protobuf/pyext/map_container.cc | 8 +- python/google/protobuf/text_format.py | 18 +- src/google/protobuf/any.pb.cc | 19 +- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.cc | 87 +- src/google/protobuf/api.pb.h | 6 +- .../protobuf/compiler/cpp/cpp_helpers.cc | 1297 ++++++++++------- .../protobuf/compiler/cpp/cpp_helpers.h | 2 + .../protobuf/compiler/cpp/cpp_map_field.cc | 5 +- .../protobuf/compiler/cpp/cpp_message.cc | 29 +- .../compiler/cpp/cpp_message_field.cc | 5 +- .../protobuf/compiler/cpp/cpp_options.h | 4 +- .../protobuf/compiler/cpp/cpp_string_field.cc | 16 +- .../cpp/cpp_test_bad_identifiers.proto | 1 + .../protobuf/compiler/cpp/cpp_unittest.cc | 3 +- .../protobuf/compiler/cpp/cpp_unittest.inc | 1 + .../protobuf/compiler/js/js_generator.cc | 12 +- src/google/protobuf/compiler/parser.cc | 8 +- .../protobuf/compiler/parser_unittest.cc | 27 + src/google/protobuf/compiler/plugin.pb.cc | 92 +- src/google/protobuf/compiler/plugin.pb.h | 8 +- .../compiler/python/python_generator.cc | 22 + src/google/protobuf/compiler/zip_writer.h | 5 - src/google/protobuf/descriptor.cc | 10 +- src/google/protobuf/descriptor.h | 18 + src/google/protobuf/descriptor.pb.cc | 751 ++++------ src/google/protobuf/descriptor.pb.h | 54 +- src/google/protobuf/descriptor_unittest.cc | 62 +- src/google/protobuf/duration.pb.cc | 18 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.cc | 13 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/extension_set.h | 20 +- src/google/protobuf/extension_set_heavy.cc | 65 +- src/google/protobuf/extension_set_inl.h | 8 +- src/google/protobuf/field_mask.pb.cc | 17 +- src/google/protobuf/field_mask.pb.h | 2 +- .../protobuf/generated_message_reflection.cc | 12 +- .../protobuf/generated_message_reflection.h | 7 +- .../protobuf/generated_message_table_driven.h | 137 ++ src/google/protobuf/generated_message_util.cc | 35 +- src/google/protobuf/generated_message_util.h | 133 -- src/google/protobuf/implicit_weak_message.cc | 1 - src/google/protobuf/io/coded_stream.h | 36 +- src/google/protobuf/map_entry_lite.h | 8 +- src/google/protobuf/map_field.h | 2 +- src/google/protobuf/map_test.cc | 13 +- src/google/protobuf/map_type_handler.h | 24 +- src/google/protobuf/message.cc | 44 +- src/google/protobuf/message.h | 7 +- src/google/protobuf/message_lite.cc | 72 +- src/google/protobuf/message_lite.h | 10 +- src/google/protobuf/parse_context.cc | 138 +- src/google/protobuf/parse_context.h | 91 +- src/google/protobuf/port_def.inc | 8 +- src/google/protobuf/reflection_ops.cc | 45 +- src/google/protobuf/source_context.pb.cc | 17 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.cc | 71 +- src/google/protobuf/struct.pb.h | 6 +- src/google/protobuf/text_format.cc | 2 +- src/google/protobuf/timestamp.pb.cc | 18 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.cc | 145 +- src/google/protobuf/type.pb.h | 10 +- src/google/protobuf/unknown_field_set.cc | 112 +- src/google/protobuf/unknown_field_set.h | 35 +- .../protobuf/util/internal/datapiece.cc | 14 +- src/google/protobuf/util/internal/datapiece.h | 6 +- .../internal/default_value_objectwriter.h | 2 +- .../util/internal/json_objectwriter.h | 29 +- .../util/internal/json_stream_parser_test.cc | 2 +- .../protobuf/util/internal/proto_writer.cc | 12 +- .../protobuf/util/internal/proto_writer.h | 8 + .../util/internal/protostream_objectsource.cc | 5 +- .../util/internal/protostream_objectsource.h | 6 +- .../internal/protostream_objectsource_test.cc | 16 +- .../util/internal/protostream_objectwriter.cc | 2 + .../util/internal/protostream_objectwriter.h | 5 + .../internal/protostream_objectwriter_test.cc | 81 + src/google/protobuf/util/json_util.cc | 18 +- src/google/protobuf/util/json_util.h | 12 +- src/google/protobuf/util/json_util_test.cc | 40 +- .../protobuf/util/message_differencer.cc | 30 +- .../protobuf/util/message_differencer.h | 5 +- .../util/message_differencer_unittest.cc | 61 + src/google/protobuf/wire_format.cc | 8 +- src/google/protobuf/wire_format_lite.cc | 31 +- src/google/protobuf/wire_format_lite.h | 12 +- src/google/protobuf/wire_format_lite_inl.h | 26 +- src/google/protobuf/wrappers.pb.cc | 142 +- src/google/protobuf/wrappers.pb.h | 18 +- 118 files changed, 2968 insertions(+), 2611 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 7affb95dab9fa11064f21681b5b5b27c5406ca41..cf1a89a8ca041d034694df980457a50040ccb7ed 100644 GIT binary patch delta 73 zcmZ3zhiCO3o(=h4j7*aYye2R*ZD#bYxXsA4y-JO-f|HSH`e%K{Kp@xEfKgl+NXI%e amM}9iwO?{$+DyJH*hv}YBt`&iCl=oT delta 73 zcmZ3zhiCO3o(=h4jNFq8ye2SmZ)WtaxXsADy-JO-f|HSZ`e%K{Kp@xEfKgl+NXI%e amM}ANw_kE&+DyJH*hv}YBt`&svlk}- diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index 8f751925c4..6f8696e852 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -32,7 +32,22 @@ package com.google.protobuf; import static com.google.protobuf.Internal.checkNotNull; -import com.google.protobuf.DescriptorProtos.*; +import com.google.protobuf.DescriptorProtos.DescriptorProto; +import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; +import com.google.protobuf.DescriptorProtos.EnumOptions; +import com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto; +import com.google.protobuf.DescriptorProtos.EnumValueOptions; +import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; +import com.google.protobuf.DescriptorProtos.FieldOptions; +import com.google.protobuf.DescriptorProtos.FileDescriptorProto; +import com.google.protobuf.DescriptorProtos.FileOptions; +import com.google.protobuf.DescriptorProtos.MessageOptions; +import com.google.protobuf.DescriptorProtos.MethodDescriptorProto; +import com.google.protobuf.DescriptorProtos.MethodOptions; +import com.google.protobuf.DescriptorProtos.OneofDescriptorProto; +import com.google.protobuf.DescriptorProtos.OneofOptions; +import com.google.protobuf.DescriptorProtos.ServiceDescriptorProto; +import com.google.protobuf.DescriptorProtos.ServiceOptions; import com.google.protobuf.Descriptors.FileDescriptor.Syntax; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -1211,7 +1226,7 @@ public final class Descriptors { StringBuilder result = new StringBuilder(name.length()); boolean isNextUpperCase = false; for (int i = 0; i < name.length(); i++) { - Character ch = name.charAt(i); + char ch = name.charAt(i); if (ch == '_') { isNextUpperCase = true; } else if (isNextUpperCase) { diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 53af544fc3..cacfa05c05 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -1681,6 +1681,15 @@ public abstract class GeneratedMessageV3 extends AbstractMessage } } + @Override + public Message.Builder newBuilderForField(final FieldDescriptor field) { + if (field.isExtension()) { + return DynamicMessage.newBuilder(field.getMessageType()); + } else { + return super.newBuilderForField(field); + } + } + protected final void mergeExtensionFields(final ExtendableMessage other) { ensureExtensionsIsMutable(); extensions.mergeFrom(other.extensions); 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 aaea0972c8..f00c812fc5 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -1127,7 +1127,6 @@ public final class TextFormat { PARSER.merge(input, builder); } - /** * Parse a text-format message from {@code input}. * @@ -1167,7 +1166,6 @@ public final class TextFormat { PARSER.merge(input, extensionRegistry, builder); } - /** * Parse a text-format message from {@code input}. Extensions will be recognized if they are * registered in {@code extensionRegistry}. @@ -1187,7 +1185,6 @@ public final class TextFormat { } - /** * Parser for text-format proto2 instances. This class is thread-safe. The implementation largely * follows google/protobuf/text_format.cc. @@ -1217,36 +1214,6 @@ public final class TextFormat { FORBID_SINGULAR_OVERWRITES } - /** - * Determines how to deal with repeated values for singular Message fields. For example, - * given a field "foo" containing subfields "baz" and "qux": - * - *
    - *
  • "foo { baz: 1 } foo { baz: 2 }", or - *
  • "foo { baz: 1 } foo { qux: 2 }" - *
- */ - public enum MergingStyle { - /** - * Merge the values in standard protobuf fashion: - * - *
    - *
  • "foo { baz: 2 }" and - *
  • "foo { baz: 1, qux: 2 }", respectively. - *
- */ - RECURSIVE, - /** - * Later values overwrite ("clobber") previous values: - * - *
    - *
  • "foo { baz: 2 }" and - *
  • "foo { qux: 2 }", respectively. - *
- */ - NON_RECURSIVE - } - private final boolean allowUnknownFields; private final boolean allowUnknownEnumValues; private final boolean allowUnknownExtensions; @@ -1349,7 +1316,6 @@ public final class TextFormat { } - private static final int BUFFER_SIZE = 4096; // TODO(chrisn): See if working around java.io.Reader#read(CharBuffer) @@ -1435,20 +1401,18 @@ public final class TextFormat { List unknownFields = new ArrayList(); while (!tokenizer.atEnd()) { - mergeField(tokenizer, extensionRegistry, target, MergingStyle.RECURSIVE, unknownFields); + mergeField(tokenizer, extensionRegistry, target, unknownFields); } checkUnknownFields(unknownFields); } - /** Parse a single field from {@code tokenizer} and merge it into {@code builder}. */ private void mergeField( final Tokenizer tokenizer, final ExtensionRegistry extensionRegistry, final MessageReflection.MergeTarget target, - final MergingStyle mergingStyle, List unknownFields) throws ParseException { mergeField( @@ -1456,7 +1420,6 @@ public final class TextFormat { extensionRegistry, target, parseInfoTreeBuilder, - mergingStyle, unknownFields); } @@ -1466,7 +1429,6 @@ public final class TextFormat { final ExtensionRegistry extensionRegistry, final MessageReflection.MergeTarget target, TextFormatParseInfoTree.Builder parseTreeBuilder, - final MergingStyle mergingStyle, List unknownFields) throws ParseException { FieldDescriptor field = null; @@ -1573,7 +1535,6 @@ public final class TextFormat { field, extension, childParseTreeBuilder, - mergingStyle, unknownFields); } else { consumeFieldValues( @@ -1583,7 +1544,6 @@ public final class TextFormat { field, extension, parseTreeBuilder, - mergingStyle, unknownFields); } } else { @@ -1595,7 +1555,6 @@ public final class TextFormat { field, extension, parseTreeBuilder, - mergingStyle, unknownFields); } @@ -1620,7 +1579,6 @@ public final class TextFormat { final FieldDescriptor field, final ExtensionRegistry.ExtensionInfo extension, final TextFormatParseInfoTree.Builder parseTreeBuilder, - final MergingStyle mergingStyle, List unknownFields) throws ParseException { // Support specifying repeated field values as a comma-separated list. @@ -1635,7 +1593,6 @@ public final class TextFormat { field, extension, parseTreeBuilder, - mergingStyle, unknownFields); if (tokenizer.tryConsume("]")) { // End of list. @@ -1652,7 +1609,6 @@ public final class TextFormat { field, extension, parseTreeBuilder, - mergingStyle, unknownFields); } } @@ -1665,7 +1621,6 @@ public final class TextFormat { final FieldDescriptor field, final ExtensionRegistry.ExtensionInfo extension, final TextFormatParseInfoTree.Builder parseTreeBuilder, - final MergingStyle mergingStyle, List unknownFields) throws ParseException { if (singularOverwritePolicy == SingularOverwritePolicy.FORBID_SINGULAR_OVERWRITES @@ -1698,18 +1653,9 @@ public final class TextFormat { endToken = "}"; } - final MessageReflection.MergeTarget subField; Message defaultInstance = (extension == null) ? null : extension.defaultInstance; - switch (mergingStyle) { - case RECURSIVE: - subField = target.newMergeTargetForField(field, defaultInstance); - break; - case NON_RECURSIVE: - subField = target.newEmptyTargetForField(field, defaultInstance); - break; - default: - throw new AssertionError(); - } + MessageReflection.MergeTarget subField = + target.newMergeTargetForField(field, defaultInstance); while (!tokenizer.tryConsume(endToken)) { if (tokenizer.atEnd()) { @@ -1720,7 +1666,6 @@ public final class TextFormat { extensionRegistry, subField, parseTreeBuilder, - mergingStyle, unknownFields); } diff --git a/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java b/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java index 17df54a16e..ddd358564b 100644 --- a/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java +++ b/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java @@ -391,14 +391,12 @@ final class UnsafeUtil { } /** - * Gets the field with the given name within the class, or {@code null} if not found. If found, - * the field is made accessible. + * Gets the field with the given name within the class, or {@code null} if not found. */ private static Field field(Class clazz, String fieldName) { Field field; try { field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); } catch (Throwable t) { // Failed to access the fields. field = null; diff --git a/java/core/src/main/java/com/google/protobuf/Utf8.java b/java/core/src/main/java/com/google/protobuf/Utf8.java index 4512bf9b56..9fe1383a9f 100644 --- a/java/core/src/main/java/com/google/protobuf/Utf8.java +++ b/java/core/src/main/java/com/google/protobuf/Utf8.java @@ -1104,7 +1104,8 @@ final class Utf8 { private static int partialIsValidUtf8NonAscii(byte[] bytes, int index, int limit) { for (; ; ) { - int byte1, byte2; + int byte1; + int byte2; // Optimize for interior runs of ASCII bytes. do { diff --git a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java index 0514241a67..fe37ea8087 100644 --- a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java @@ -33,8 +33,10 @@ package com.google.protobuf; import com.google.protobuf.Descriptors.EnumDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; +import protobuf_unittest.UnittestProto; import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; +import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage; import protobuf_unittest.UnittestProto.TestEmptyMessage; import protobuf_unittest.UnittestProto.TestPackedTypes; import java.util.Arrays; @@ -223,6 +225,17 @@ public class DynamicMessageTest extends TestCase { packedReflectionTester.assertPackedFieldsSetViaReflection(message3); } + public void testGetBuilderForExtensionField() { + DynamicMessage.Builder builder = DynamicMessage.newBuilder(TestAllExtensions.getDescriptor()); + Message.Builder fieldBuilder = + builder.newBuilderForField(UnittestProto.optionalNestedMessageExtension.getDescriptor()); + final int expected = 7432; + FieldDescriptor field = + NestedMessage.getDescriptor().findFieldByNumber(NestedMessage.BB_FIELD_NUMBER); + fieldBuilder.setField(field, expected); + assertEquals(expected, fieldBuilder.build().getField(field)); + } + public void testDynamicMessageCopy() throws Exception { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); TestUtil.setAllFields(builder); diff --git a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java index 13457bc07d..2d025feecd 100644 --- a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java @@ -578,6 +578,29 @@ public class GeneratedMessageTest extends TestCase { TestUtil.assertAllExtensionsSet(message); } + public void testGetBuilderForExtensionField() { + TestAllExtensions.Builder builder = TestAllExtensions.newBuilder(); + Message.Builder fieldBuilder = + builder.newBuilderForField(UnittestProto.optionalNestedMessageExtension.getDescriptor()); + final int expected = 7432; + FieldDescriptor field = + NestedMessage.getDescriptor().findFieldByNumber(NestedMessage.BB_FIELD_NUMBER); + fieldBuilder.setField(field, expected); + assertEquals(expected, fieldBuilder.build().getField(field)); + } + + + public void testGetBuilderForNonMessageExtensionField() { + TestAllExtensions.Builder builder = TestAllExtensions.newBuilder(); + try { + // This should throw an exception because the extension field is not a message. + builder.newBuilderForField(UnittestProto.optionalInt32Extension.getDescriptor()); + fail("Exception was not thrown"); + } catch (UnsupportedOperationException e) { + // This exception is expected. + } + } + public void testExtensionRepeatedSetters() throws Exception { TestAllExtensions.Builder builder = TestAllExtensions.newBuilder(); TestUtil.setAllExtensions(builder); diff --git a/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto b/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto index 7324653f81..240600f2de 100644 --- a/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto @@ -30,10 +30,9 @@ syntax = "proto3"; -package map_lite_test; +package map_test; -option optimize_for = LITE_RUNTIME; -option java_package = "map_lite_test"; +option java_package = "map_test"; option java_outer_classname = "MapTestProto"; message TestMap { diff --git a/java/util/src/main/java/com/google/protobuf/util/Durations.java b/java/util/src/main/java/com/google/protobuf/util/Durations.java index 7836ccf95f..0ecac2505d 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Durations.java +++ b/java/util/src/main/java/com/google/protobuf/util/Durations.java @@ -42,6 +42,7 @@ import static com.google.protobuf.util.Timestamps.NANOS_PER_MICROSECOND; import static com.google.protobuf.util.Timestamps.NANOS_PER_MILLISECOND; import static com.google.protobuf.util.Timestamps.NANOS_PER_SECOND; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.protobuf.Duration; import java.text.ParseException; import java.util.Comparator; @@ -91,8 +92,8 @@ public final class Durations { } /** - * Compares two durations. The value returned is identical to what would be returned by: - * {@code Durations.comparator().compare(x, y)}. + * Compares two durations. The value returned is identical to what would be returned by: {@code + * Durations.comparator().compare(x, y)}. * * @return the value {@code 0} if {@code x == y}; a value less than {@code 0} if {@code x < y}; * and a value greater than {@code 0} if {@code x > y} @@ -151,6 +152,7 @@ public final class Durations { * @throws IllegalArgumentException if {@code duration} is negative or invalid * @throws NullPointerException if {@code duration} is {@code null} */ + @CanIgnoreReturnValue public static Duration checkNotNegative(Duration duration) { checkValid(duration); checkArgument(!isNegative(duration), "duration (%s) must not be negative", toString(duration)); @@ -163,6 +165,7 @@ public final class Durations { * @throws IllegalArgumentException if {@code duration} is negative, {@code ZERO}, or invalid * @throws NullPointerException if {@code duration} is {@code null} */ + @CanIgnoreReturnValue public static Duration checkPositive(Duration duration) { checkValid(duration); checkArgument( @@ -173,19 +176,32 @@ public final class Durations { } /** Throws an {@link IllegalArgumentException} if the given {@link Duration} is not valid. */ + @CanIgnoreReturnValue public static Duration checkValid(Duration duration) { long seconds = duration.getSeconds(); int nanos = duration.getNanos(); if (!isValid(seconds, nanos)) { - throw new IllegalArgumentException(String.format( - "Duration is not valid. See proto definition for valid values. " - + "Seconds (%s) must be in range [-315,576,000,000, +315,576,000,000]. " - + "Nanos (%s) must be in range [-999,999,999, +999,999,999]. " - + "Nanos must have the same sign as seconds", seconds, nanos)); + throw new IllegalArgumentException( + String.format( + "Duration is not valid. See proto definition for valid values. " + + "Seconds (%s) must be in range [-315,576,000,000, +315,576,000,000]. " + + "Nanos (%s) must be in range [-999,999,999, +999,999,999]. " + + "Nanos must have the same sign as seconds", + seconds, nanos)); } return duration; } + /** + * Builds the given builder and throws an {@link IllegalArgumentException} if it is not valid. See + * {@link #checkValid(Duration}). + * + * @return A valid, built {@link Duration}. + */ + public static Duration checkValid(Duration.Builder durationBuilder) { + return checkValid(durationBuilder.build()); + } + /** * Convert Duration to string format. The string format will contains 3, 6, or 9 fractional digits * depending on the precision required to represent the exact Duration value. For example: "1s", diff --git a/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java b/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java index 86f56ad99f..d07731d248 100644 --- a/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java +++ b/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java @@ -30,6 +30,7 @@ package com.google.protobuf.util; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.FieldMask; @@ -88,15 +89,14 @@ final class FieldMaskTree { } /** - * Adds a field path to the tree. In a FieldMask, every field path matches the - * specified field as well as all its sub-fields. For example, a field path - * "foo.bar" matches field "foo.bar" and also "foo.bar.baz", etc. When adding - * a field path to the tree, redundant sub-paths will be removed. That is, - * after adding "foo.bar" to the tree, "foo.bar.baz" will be removed if it - * exists, which will turn the tree node for "foo.bar" to a leaf node. - * Likewise, if the field path to add is a sub-path of an existing leaf node, - * nothing will be changed in the tree. + * Adds a field path to the tree. In a FieldMask, every field path matches the specified field as + * well as all its sub-fields. For example, a field path "foo.bar" matches field "foo.bar" and + * also "foo.bar.baz", etc. When adding a field path to the tree, redundant sub-paths will be + * removed. That is, after adding "foo.bar" to the tree, "foo.bar.baz" will be removed if it + * exists, which will turn the tree node for "foo.bar" to a leaf node. Likewise, if the field path + * to add is a sub-path of an existing leaf node, nothing will be changed in the tree. */ + @CanIgnoreReturnValue FieldMaskTree addFieldPath(String path) { String[] parts = path.split(FIELD_PATH_SEPARATOR_REGEX); if (parts.length == 0) { @@ -125,9 +125,8 @@ final class FieldMaskTree { return this; } - /** - * Merges all field paths in a FieldMask into this tree. - */ + /** Merges all field paths in a FieldMask into this tree. */ + @CanIgnoreReturnValue FieldMaskTree mergeFromFieldMask(FieldMask mask) { for (String path : mask.getPathsList()) { addFieldPath(path); diff --git a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java index aedc5eac21..6af1493331 100644 --- a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java +++ b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java @@ -36,12 +36,12 @@ import com.google.common.base.CaseFormat; import com.google.common.base.Joiner; import com.google.common.base.Splitter; import com.google.common.primitives.Ints; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.FieldMask; import com.google.protobuf.Internal; import com.google.protobuf.Message; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -277,9 +277,7 @@ public class FieldMaskUtil { /** * Whether to replace message fields (i.e., discard existing content in - * destination message fields) when merging. - * Default behavior is to merge the source message field into the - * destination message field. + * destination message fields). */ public boolean replaceMessageFields() { return replaceMessageFields; @@ -287,9 +285,7 @@ public class FieldMaskUtil { /** * Whether to replace repeated fields (i.e., discard existing content in - * destination repeated fields) when merging. - * Default behavior is to append elements from source repeated field to the - * destination repeated field. + * destination repeated fields). */ public boolean replaceRepeatedFields() { return replaceRepeatedFields; @@ -297,30 +293,51 @@ public class FieldMaskUtil { /** * Whether to replace primitive (non-repeated and non-message) fields in - * destination message fields with the source primitive fields (i.e., if the - * field is set in the source, the value is copied to the - * destination; if the field is unset in the source, the field is cleared - * from the destination) when merging. - * - *

Default behavior is to always set the value of the source primitive - * field to the destination primitive field, and if the source field is - * unset, the default value of the source field is copied to the - * destination. + * destination message fields with the source primitive fields (i.e., clear + * destination field if source field is not set). */ public boolean replacePrimitiveFields() { return replacePrimitiveFields; } + /** + * Specify whether to replace message fields. Defaults to false. + * + *

If true, discard existing content in destination message fields when merging. + * + *

If false, merge the source message field into the destination message field. + */ + @CanIgnoreReturnValue public MergeOptions setReplaceMessageFields(boolean value) { replaceMessageFields = value; return this; } + /** + * Specify whether to replace repeated fields. Defaults to false. + * + *

If true, discard existing content in destination repeated fields) when merging. + * + *

If false, append elements from source repeated field to the destination repeated field. + */ + @CanIgnoreReturnValue public MergeOptions setReplaceRepeatedFields(boolean value) { replaceRepeatedFields = value; return this; } + /** + * Specify whether to replace primitive (non-repeated and non-message) fields in destination + * message fields with the source primitive fields. Defaults to false. + * + *

If true, set the value of the destination primitive field to the source primitive field if + * the source field is set, but clear the destination field otherwise. + * + *

If false, always set the value of the destination primitive field to the source primitive + * field, and if the source field is unset, the default value of the source field is copied to + * the destination. + */ + @CanIgnoreReturnValue public MergeOptions setReplacePrimitiveFields(boolean value) { replacePrimitiveFields = value; return this; diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java index 3301e02f3e..77c837e6fd 100644 --- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java +++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java @@ -32,6 +32,7 @@ package com.google.protobuf.util; import com.google.common.base.Preconditions; import com.google.common.io.BaseEncoding; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -226,7 +227,7 @@ public class JsonFormat { return new Printer( registry, false, - fieldsToAlwaysOutput, + Collections.unmodifiableSet(new HashSet<>(fieldsToAlwaysOutput)), preservingProtoFieldNames, omittingInsignificantWhitespace, printingEnumsAsInts, @@ -467,9 +468,10 @@ public class JsonFormat { private Builder() {} /** - * Adds a message type and all types defined in the same .proto file as - * well as all transitively imported .proto files to this {@link Builder}. + * Adds a message type and all types defined in the same .proto file as well as all + * transitively imported .proto files to this {@link Builder}. */ + @CanIgnoreReturnValue public Builder add(Descriptor messageType) { if (types == null) { throw new IllegalStateException("A TypeRegistry.Builer can only be used once."); @@ -479,9 +481,10 @@ public class JsonFormat { } /** - * Adds message types and all types defined in the same .proto file as - * well as all transitively imported .proto files to this {@link Builder}. + * Adds message types and all types defined in the same .proto file as well as all + * transitively imported .proto files to this {@link Builder}. */ + @CanIgnoreReturnValue public Builder add(Iterable messageTypes) { if (types == null) { throw new IllegalStateException("A TypeRegistry.Builder can only be used once."); diff --git a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java index 83f3a9d649..96608e53e0 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java +++ b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java @@ -36,6 +36,7 @@ import static com.google.common.math.LongMath.checkedAdd; import static com.google.common.math.LongMath.checkedMultiply; import static com.google.common.math.LongMath.checkedSubtract; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.protobuf.Duration; import com.google.protobuf.Timestamp; import java.text.ParseException; @@ -119,8 +120,8 @@ public final class Timestamps { } /** - * Compares two timestamps. The value returned is identical to what would be returned by: - * {@code Timestamps.comparator().compare(x, y)}. + * Compares two timestamps. The value returned is identical to what would be returned by: {@code + * Timestamps.comparator().compare(x, y)}. * * @return the value {@code 0} if {@code x == y}; a value less than {@code 0} if {@code x < y}; * and a value greater than {@code 0} if {@code x > y} @@ -162,18 +163,31 @@ public final class Timestamps { } /** Throws an {@link IllegalArgumentException} if the given {@link Timestamp} is not valid. */ + @CanIgnoreReturnValue public static Timestamp checkValid(Timestamp timestamp) { long seconds = timestamp.getSeconds(); int nanos = timestamp.getNanos(); if (!isValid(seconds, nanos)) { - throw new IllegalArgumentException(String.format( - "Timestamp is not valid. See proto definition for valid values. " - + "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. " - + "Nanos (%s) must be in range [0, +999,999,999].", seconds, nanos)); + throw new IllegalArgumentException( + String.format( + "Timestamp is not valid. See proto definition for valid values. " + + "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. " + + "Nanos (%s) must be in range [0, +999,999,999].", + seconds, nanos)); } return timestamp; } + /** + * Builds the given builder and throws an {@link IllegalArgumentException} if it is not valid. See + * {@link #checkValid(Timestamp}). + * + * @return A valid, built {@link Timestamp}. + */ + public static Timestamp checkValid(Timestamp.Builder timestampBuilder) { + return checkValid(timestampBuilder.build()); + } + /** * Convert Timestamp to RFC 3339 date string format. The output will always be Z-normalized and * uses 3, 6 or 9 fractional digits as required to represent the exact value. Note that Timestamp diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index 6095068b15..9805737b88 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -49,19 +49,20 @@ import com.google.protobuf.UInt32Value; import com.google.protobuf.UInt64Value; import com.google.protobuf.Value; import com.google.protobuf.util.JsonFormat.TypeRegistry; -import com.google.protobuf.util.JsonTestProto.TestAllTypes; -import com.google.protobuf.util.JsonTestProto.TestAllTypes.NestedEnum; -import com.google.protobuf.util.JsonTestProto.TestAllTypes.NestedMessage; -import com.google.protobuf.util.JsonTestProto.TestAny; -import com.google.protobuf.util.JsonTestProto.TestCustomJsonName; -import com.google.protobuf.util.JsonTestProto.TestDuration; -import com.google.protobuf.util.JsonTestProto.TestFieldMask; -import com.google.protobuf.util.JsonTestProto.TestMap; -import com.google.protobuf.util.JsonTestProto.TestOneof; -import com.google.protobuf.util.JsonTestProto.TestRecursive; -import com.google.protobuf.util.JsonTestProto.TestStruct; -import com.google.protobuf.util.JsonTestProto.TestTimestamp; -import com.google.protobuf.util.JsonTestProto.TestWrappers; +import com.google.protobuf.util.proto.JsonTestProto.TestAllTypes; +import com.google.protobuf.util.proto.JsonTestProto.TestAllTypes.AliasedEnum; +import com.google.protobuf.util.proto.JsonTestProto.TestAllTypes.NestedEnum; +import com.google.protobuf.util.proto.JsonTestProto.TestAllTypes.NestedMessage; +import com.google.protobuf.util.proto.JsonTestProto.TestAny; +import com.google.protobuf.util.proto.JsonTestProto.TestCustomJsonName; +import com.google.protobuf.util.proto.JsonTestProto.TestDuration; +import com.google.protobuf.util.proto.JsonTestProto.TestFieldMask; +import com.google.protobuf.util.proto.JsonTestProto.TestMap; +import com.google.protobuf.util.proto.JsonTestProto.TestOneof; +import com.google.protobuf.util.proto.JsonTestProto.TestRecursive; +import com.google.protobuf.util.proto.JsonTestProto.TestStruct; +import com.google.protobuf.util.proto.JsonTestProto.TestTimestamp; +import com.google.protobuf.util.proto.JsonTestProto.TestWrappers; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -676,7 +677,7 @@ public class JsonFormatTest extends TestCase { + "}", builder); fail(); - + } catch (InvalidProtocolBufferException e) { // Exception expected. } @@ -1159,8 +1160,8 @@ public class JsonFormatTest extends TestCase { } public void testParserAcceptBase64Variants() throws Exception { - assertAccepts("optionalBytes", "AQI"); // No padding - assertAccepts("optionalBytes", "-_w"); // base64Url, no padding + assertAccepts("optionalBytes", "AQI"); // No padding + assertAccepts("optionalBytes", "-_w"); // base64Url, no padding } public void testParserRejectInvalidEnumValue() throws Exception { @@ -1197,6 +1198,23 @@ public class JsonFormatTest extends TestCase { assertEquals(0, builder.getOptionalNestedEnumValue()); } + public void testParserSupportAliasEnums() throws Exception { + TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + String json = "{\n" + " \"optionalAliasedEnum\": \"QUX\"\n" + "}"; + JsonFormat.parser().merge(json, builder); + assertEquals(AliasedEnum.ALIAS_BAZ, builder.getOptionalAliasedEnum()); + + builder = TestAllTypes.newBuilder(); + json = "{\n" + " \"optionalAliasedEnum\": \"qux\"\n" + "}"; + JsonFormat.parser().merge(json, builder); + assertEquals(AliasedEnum.ALIAS_BAZ, builder.getOptionalAliasedEnum()); + + builder = TestAllTypes.newBuilder(); + json = "{\n" + " \"optionalAliasedEnum\": \"bAz\"\n" + "}"; + JsonFormat.parser().merge(json, builder); + assertEquals(AliasedEnum.ALIAS_BAZ, builder.getOptionalAliasedEnum()); + } + public void testUnknownEnumMap() throws Exception { TestMap.Builder builder = TestMap.newBuilder(); JsonFormat.parser() @@ -1280,7 +1298,8 @@ public class JsonFormatTest extends TestCase { + " \"repeatedString\": [],\n" + " \"repeatedBytes\": [],\n" + " \"repeatedNestedMessage\": [],\n" - + " \"repeatedNestedEnum\": []\n" + + " \"repeatedNestedEnum\": [],\n" + + " \"optionalAliasedEnum\": \"ALIAS_FOO\"\n" + "}", JsonFormat.printer().includingDefaultValueFields().print(message)); @@ -1644,11 +1663,11 @@ public class JsonFormatTest extends TestCase { mapBuilder.putStringToInt32Map("\ud834\udd20", 3); // utf-8 F0 9D 84 A0 mapBuilder.putStringToInt32Map("foo", 99); mapBuilder.putStringToInt32Map("xxx", 123); - mapBuilder.putStringToInt32Map("\u20ac", 1); // utf-8 E2 82 AC + mapBuilder.putStringToInt32Map("\u20ac", 1); // utf-8 E2 82 AC mapBuilder.putStringToInt32Map("abc", 20); mapBuilder.putStringToInt32Map("19", 19); mapBuilder.putStringToInt32Map("8", 8); - mapBuilder.putStringToInt32Map("\ufb00", 2); // utf-8 EF AC 80 + mapBuilder.putStringToInt32Map("\ufb00", 2); // utf-8 EF AC 80 mapBuilder.putInt32ToInt32Map(3, 3); mapBuilder.putInt32ToInt32Map(10, 10); mapBuilder.putInt32ToInt32Map(5, 5); diff --git a/java/util/src/test/proto/com/google/protobuf/util/json_test.proto b/java/util/src/test/proto/com/google/protobuf/util/json_test.proto index d1248cfb71..26d06240a1 100644 --- a/java/util/src/test/proto/com/google/protobuf/util/json_test.proto +++ b/java/util/src/test/proto/com/google/protobuf/util/json_test.proto @@ -32,7 +32,7 @@ syntax = "proto3"; package json_test; -option java_package = "com.google.protobuf.util"; +option java_package = "com.google.protobuf.util.proto"; option java_outer_classname = "JsonTestProto"; import "google/protobuf/any.proto"; @@ -48,6 +48,17 @@ message TestAllTypes { BAR = 1; BAZ = 2; } + + enum AliasedEnum { + option allow_alias = true; + + ALIAS_FOO = 0; + ALIAS_BAR = 1; + ALIAS_BAZ = 2; + QUX = 2; + qux = 2; + bAz = 2; + } message NestedMessage { int32 value = 1; } @@ -69,6 +80,7 @@ message TestAllTypes { bytes optional_bytes = 15; NestedMessage optional_nested_message = 18; NestedEnum optional_nested_enum = 21; + AliasedEnum optional_aliased_enum = 52; // Repeated repeated int32 repeated_int32 = 31; diff --git a/js/binary/constants.js b/js/binary/constants.js index 5c53a3605d..f8b13a8b9e 100644 --- a/js/binary/constants.js +++ b/js/binary/constants.js @@ -55,7 +55,7 @@ goog.forwardDeclare('jspb.BinaryMessage'); goog.forwardDeclare('jspb.BinaryReader'); goog.forwardDeclare('jspb.BinaryWriter'); goog.forwardDeclare('jspb.Message'); -goog.forwardDeclare('jsproto.BinaryExtension'); +goog.forwardDeclare('jsprotolib.BinaryExtension'); @@ -122,7 +122,7 @@ jspb.RepeatedFieldType; !Uint8Array| !jspb.ConstBinaryMessage| !jspb.BinaryMessage| - !jsproto.BinaryExtension} + !jsprotolib.BinaryExtension} */ jspb.AnyFieldType; diff --git a/js/binary/decoder.js b/js/binary/decoder.js index e33bf1be9c..d47c20e4af 100644 --- a/js/binary/decoder.js +++ b/js/binary/decoder.js @@ -63,7 +63,7 @@ goog.require('jspb.utils'); * @struct */ jspb.BinaryIterator = function(opt_decoder, opt_next, opt_elements) { - /** @private {jspb.BinaryDecoder} */ + /** @private {?jspb.BinaryDecoder} */ this.decoder_ = null; /** diff --git a/js/binary/reader.js b/js/binary/reader.js index 731587c7e1..91c7b6dacf 100644 --- a/js/binary/reader.js +++ b/js/binary/reader.js @@ -97,7 +97,7 @@ jspb.BinaryReader = function(opt_bytes, opt_start, opt_length) { /** * User-defined reader callbacks. - * @private {Object} + * @private {?Object} */ this.readCallbacks_ = null; }; diff --git a/js/message_test.js b/js/message_test.js index c237d066ef..7d2cdbae80 100644 --- a/js/message_test.js +++ b/js/message_test.js @@ -149,58 +149,60 @@ describe('Message test suite', function() { }); it('testComplexConversion', function() { - var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; - var data2 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; + var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1]; + var data2 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1]; var foo = new proto.jspb.test.Complex(data1); var bar = new proto.jspb.test.Complex(data2); var result = foo.toObject(); - assertObjectEquals({ - aString: 'a', - anOutOfOrderBool: 1, - aNestedMessage: { - anInt: 11 - }, - aRepeatedMessageList: [{anInt: 22}, {anInt: 33}], - aRepeatedStringList: ['s1', 's2'] - }, result); + assertObjectEquals( + { + aString: 'a', + anOutOfOrderBool: 1, + aNestedMessage: {anInt: 11}, + aRepeatedMessageList: [{anInt: 22}, {anInt: 33}], + aRepeatedStringList: ['s1', 's2'] + }, + result); // Now test with the jspb instances included. result = foo.toObject(true /* opt_includeInstance */); - assertObjectEquals({ - aString: 'a', - anOutOfOrderBool: 1, - aNestedMessage: { - anInt: 11, - $jspbMessageInstance: foo.getANestedMessage() - }, - aRepeatedMessageList: [ - {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]}, - {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]} - ], - aRepeatedStringList: ['s1', 's2'], - $jspbMessageInstance: foo - }, result); + assertObjectEquals( + { + aString: 'a', + anOutOfOrderBool: 1, + aNestedMessage: + {anInt: 11, $jspbMessageInstance: foo.getANestedMessage()}, + aRepeatedMessageList: [ + {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]}, + {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]} + ], + aRepeatedStringList: ['s1', 's2'], + $jspbMessageInstance: foo + }, + result); }); it('testMissingFields', function() { var foo = new proto.jspb.test.Complex([ - undefined, undefined, undefined, [], - undefined, undefined, undefined, undefined]); + undefined, undefined, undefined, [], undefined, undefined, undefined, + undefined + ]); var bar = new proto.jspb.test.Complex([ - undefined, undefined, undefined, [], - undefined, undefined, undefined, undefined]); + undefined, undefined, undefined, [], undefined, undefined, undefined, + undefined + ]); var result = foo.toObject(); - assertObjectEquals({ - aString: undefined, - anOutOfOrderBool: undefined, - aNestedMessage: { - anInt: undefined - }, - // Note: JsPb converts undefined repeated fields to empty arrays. - aRepeatedMessageList: [], - aRepeatedStringList: [] - }, result); + assertObjectEquals( + { + aString: undefined, + anOutOfOrderBool: undefined, + aNestedMessage: {anInt: undefined}, + // Note: JsPb converts undefined repeated fields to empty arrays. + aRepeatedMessageList: [], + aRepeatedStringList: [] + }, + result); }); @@ -214,20 +216,21 @@ describe('Message test suite', function() { it('testSpecialCases', function() { // Note: Some property names are reserved in JavaScript. // These names are converted to the Js property named pb_. - var special = - new proto.jspb.test.SpecialCases(['normal', 'default', 'function', - 'var']); + var special = new proto.jspb.test.SpecialCases( + ['normal', 'default', 'function', 'var']); var result = special.toObject(); - assertObjectEquals({ - normal: 'normal', - pb_default: 'default', - pb_function: 'function', - pb_var: 'var' - }, result); + assertObjectEquals( + { + normal: 'normal', + pb_default: 'default', + pb_function: 'function', + pb_var: 'var' + }, + result); }); it('testDefaultValues', function() { - var defaultString = "default<>\'\"abc"; + var defaultString = 'default<>\'"abc'; var response = new proto.jspb.test.DefaultValues(); // Test toObject @@ -291,8 +294,10 @@ describe('Message test suite', function() { // Test that clearing the values reverts them to the default state. response = makeDefault(['blah', false, 111, 77]); - response.clearStringField(); response.clearBoolField(); - response.clearIntField(); response.clearEnumField(); + response.clearStringField(); + response.clearBoolField(); + response.clearIntField(); + response.clearEnumField(); assertEquals(defaultString, response.getStringField()); assertEquals(true, response.getBoolField()); assertEquals(11, response.getIntField()); @@ -304,8 +309,10 @@ describe('Message test suite', function() { // Test that setFoo(null) clears the values. response = makeDefault(['blah', false, 111, 77]); - response.setStringField(null); response.setBoolField(null); - response.setIntField(undefined); response.setEnumField(undefined); + response.setStringField(null); + response.setBoolField(null); + response.setIntField(undefined); + response.setEnumField(undefined); assertEquals(defaultString, response.getStringField()); assertEquals(true, response.getBoolField()); assertEquals(11, response.getIntField()); @@ -321,13 +328,13 @@ describe('Message test suite', function() { assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi']))); assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye']))); var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]); - assertTrue(jspb.Message.equals(s1b, - new proto.jspb.test.Simple1(['hi', ['hello']]))); - assertTrue(jspb.Message.equals(s1b, - new proto.jspb.test.Simple1(['hi', ['hello', undefined, - undefined, undefined]]))); - assertFalse(jspb.Message.equals(s1b, - new proto.jspb.test.Simple1(['no', ['hello']]))); + assertTrue(jspb.Message.equals( + s1b, new proto.jspb.test.Simple1(['hi', ['hello']]))); + assertTrue(jspb.Message.equals(s1b, new proto.jspb.test.Simple1([ + 'hi', ['hello', undefined, undefined, undefined] + ]))); + assertFalse(jspb.Message.equals( + s1b, new proto.jspb.test.Simple1(['no', ['hello']]))); // Test with messages of different types var s2 = new proto.jspb.test.Simple2(['hi']); assertFalse(jspb.Message.equals(s1, s2)); @@ -335,18 +342,18 @@ describe('Message test suite', function() { it('testEquals_softComparison', function() { var s1 = new proto.jspb.test.Simple1(['hi', [], null]); - assertTrue(jspb.Message.equals(s1, - new proto.jspb.test.Simple1(['hi', []]))); + assertTrue( + jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi', []]))); var s1b = new proto.jspb.test.Simple1(['hi', [], true]); - assertTrue(jspb.Message.equals(s1b, - new proto.jspb.test.Simple1(['hi', [], 1]))); + assertTrue( + jspb.Message.equals(s1b, new proto.jspb.test.Simple1(['hi', [], 1]))); }); it('testEqualsComplex', function() { - var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; - var data2 = ['a',,, [, 11], [[, 22], [, 34]],, ['s1', 's2'],, 1]; - var data3 = ['a',,, [, 11], [[, 22]],, ['s1', 's2'],, 1]; + var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1]; + var data2 = ['a', , , [, 11], [[, 22], [, 34]], , ['s1', 's2'], , 1]; + var data3 = ['a', , , [, 11], [[, 22]], , ['s1', 's2'], , 1]; var data4 = ['hi']; var c1a = new proto.jspb.test.Complex(data1); var c1b = new proto.jspb.test.Complex(data1); @@ -363,42 +370,34 @@ describe('Message test suite', function() { it('testEqualsExtensionsConstructed', function() { assertTrue(jspb.Message.equals( new proto.jspb.test.HasExtensions([]), - new proto.jspb.test.HasExtensions([{}]) - )); + new proto.jspb.test.HasExtensions([{}]))); assertTrue(jspb.Message.equals( new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), - new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]) - )); + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]))); assertFalse(jspb.Message.equals( new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), - new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}]) - )); + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}]))); assertTrue(jspb.Message.equals( new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]), - new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]) - )); + new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]))); assertTrue(jspb.Message.equals( new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]), - new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]) - )); + new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}]))); assertTrue(jspb.Message.equals( - new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]), - new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]) - )); + new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]))); assertTrue(jspb.Message.equals( new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), - new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]) - )); + new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}]))); assertTrue(jspb.Message.equals( - new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]), - new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]) - )); + new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]))); }); it('testEqualsExtensionsUnconstructed', function() { assertTrue(jspb.Message.compareFields([], [{}])); - assertTrue(jspb.Message.compareFields([,,, {}], [])); - assertTrue(jspb.Message.compareFields([,,, {}], [,, {}])); + assertTrue(jspb.Message.compareFields([, , , {}], [])); + assertTrue(jspb.Message.compareFields([, , , {}], [, , {}])); assertTrue(jspb.Message.compareFields( ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); assertFalse(jspb.Message.compareFields( @@ -406,13 +405,13 @@ describe('Message test suite', function() { assertTrue(jspb.Message.compareFields( [{100: [{200: 'a'}]}], [{100: [{200: 'a'}]}])); assertTrue(jspb.Message.compareFields( - [{100: [{200: 'a'}]}], [,,, {100: [{200: 'a'}]}])); + [{100: [{200: 'a'}]}], [, , , {100: [{200: 'a'}]}])); assertTrue(jspb.Message.compareFields( - [,,, {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}])); + [, , , {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}])); assertTrue(jspb.Message.compareFields( - ['hi', {100: [{200: 'a'}]}], ['hi',,, {100: [{200: 'a'}]}])); + ['hi', {100: [{200: 'a'}]}], ['hi', , , {100: [{200: 'a'}]}])); assertTrue(jspb.Message.compareFields( - ['hi',,, {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); + ['hi', , , {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); }); it('testInitializeMessageWithLastFieldNull', function() { @@ -436,13 +435,13 @@ describe('Message test suite', function() { it('testToMap', function() { var p1 = new proto.jspb.test.Simple1(['k', ['v']]); var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]); - var soymap = jspb.Message.toMap([p1, p2], - proto.jspb.test.Simple1.prototype.getAString, + var soymap = jspb.Message.toMap( + [p1, p2], proto.jspb.test.Simple1.prototype.getAString, proto.jspb.test.Simple1.prototype.toObject); assertEquals('k', soymap['k'].aString); assertArrayEquals(['v'], soymap['k'].aRepeatedStringList); - var protomap = jspb.Message.toMap([p1, p2], - proto.jspb.test.Simple1.prototype.getAString); + var protomap = jspb.Message.toMap( + [p1, p2], proto.jspb.test.Simple1.prototype.getAString); assertEquals('k', protomap['k'].getAString()); assertArrayEquals(['v'], protomap['k'].getARepeatedStringList()); }); @@ -463,8 +462,12 @@ describe('Message test suite', function() { extension.setExt('e1'); original.setExtension(proto.jspb.test.IsExtension.extField, extension); var clone = original.clone(); - assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, - [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }], + assertArrayEquals( + [ + 'v1', , ['x1', ['y1', 'z1']], , + [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, , + {100: [, 'e1']} + ], clone.toArray()); clone.setStr('v2'); var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]); @@ -481,11 +484,19 @@ describe('Message test suite', function() { var newExtension = new proto.jspb.test.CloneExtension(); newExtension.setExt('e2'); clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension); - assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],, - [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2,, { 100: [, 'e2'] }], + assertArrayEquals( + [ + 'v2', , ['a1', ['b1', 'c1']], , + [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2, , + {100: [, 'e2']} + ], clone.toArray()); - assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, - [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }], + assertArrayEquals( + [ + 'v1', , ['x1', ['y1', 'z1']], , + [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, , + {100: [, 'e1']} + ], original.toArray()); }); @@ -517,11 +528,12 @@ describe('Message test suite', function() { jspb.Message.copyInto(original, dest); assertArrayEquals(original.toArray(), dest.toArray()); assertEquals('x1', dest.getSimple1().getAString()); - assertEquals('e1', + assertEquals( + 'e1', dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt()); dest.getSimple1().setAString('new value'); - assertNotEquals(dest.getSimple1().getAString(), - original.getSimple1().getAString()); + assertNotEquals( + dest.getSimple1().getAString(), original.getSimple1().getAString()); if (supportsUint8Array) { dest.getBytesField()[0] = 7; assertObjectEquals(bytes1, original.getBytesField()); @@ -531,12 +543,12 @@ describe('Message test suite', function() { assertObjectEquals(bytes1, original.getBytesField()); assertObjectEquals('789', dest.getBytesField()); } - dest.getExtension(proto.jspb.test.CloneExtension.extField). - setExt('new value'); + dest.getExtension(proto.jspb.test.CloneExtension.extField) + .setExt('new value'); assertNotEquals( dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(), - original.getExtension( - proto.jspb.test.CloneExtension.extField).getExt()); + original.getExtension(proto.jspb.test.CloneExtension.extField) + .getExt()); }); it('testCopyInto_notSameType', function() { @@ -554,26 +566,32 @@ describe('Message test suite', function() { var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2']]); var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1); - extendable.setExtension(proto.jspb.test.IndirectExtension.simple, - extension2); + extendable.setExtension( + proto.jspb.test.IndirectExtension.simple, extension2); extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy'); - extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList, - ['a', 'b']); + extendable.setExtension( + proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']); var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]); var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2']]); extendable.setExtension( - proto.jspb.test.IndirectExtension.repeatedSimpleList, - [s1, s2]); - assertObjectEquals(extension1, + proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]); + assertObjectEquals( + extension1, extendable.getExtension(proto.jspb.test.IsExtension.extField)); - assertObjectEquals(extension2, + assertObjectEquals( + extension2, extendable.getExtension(proto.jspb.test.IndirectExtension.simple)); - assertObjectEquals('xyzzy', + assertObjectEquals( + 'xyzzy', extendable.getExtension(proto.jspb.test.IndirectExtension.str)); - assertObjectEquals(['a', 'b'], extendable.getExtension( - proto.jspb.test.IndirectExtension.repeatedStrList)); - assertObjectEquals([s1, s2], extendable.getExtension( - proto.jspb.test.IndirectExtension.repeatedSimpleList)); + assertObjectEquals( + ['a', 'b'], + extendable.getExtension( + proto.jspb.test.IndirectExtension.repeatedStrList)); + assertObjectEquals( + [s1, s2], + extendable.getExtension( + proto.jspb.test.IndirectExtension.repeatedSimpleList)); // Not supported yet, but it should work... extendable.setExtension(proto.jspb.test.IndirectExtension.simple, null); assertNull( @@ -592,29 +610,35 @@ describe('Message test suite', function() { var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); var extension = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]); extendable.setExtension(proto.jspb.test.simple1, extension); - assertObjectEquals(extension, - extendable.getExtension(proto.jspb.test.simple1)); + assertObjectEquals( + extension, extendable.getExtension(proto.jspb.test.simple1)); // From _lib mode. extension = new proto.jspb.test.ExtensionMessage(['s1']); extendable = new proto.jspb.test.TestExtensionsMessage([16]); extendable.setExtension(proto.jspb.test.floatingMsgField, extension); extendable.setExtension(proto.jspb.test.floatingStrField, 's2'); - assertObjectEquals(extension, - extendable.getExtension(proto.jspb.test.floatingMsgField)); - assertObjectEquals('s2', - extendable.getExtension(proto.jspb.test.floatingStrField)); + assertObjectEquals( + extension, extendable.getExtension(proto.jspb.test.floatingMsgField)); + assertObjectEquals( + 's2', extendable.getExtension(proto.jspb.test.floatingStrField)); assertNotUndefined(proto.jspb.exttest.floatingMsgField); assertNotUndefined(proto.jspb.exttest.floatingMsgFieldTwo); assertNotUndefined(proto.jspb.exttest.beta.floatingStrField); }); it('testNestedExtensions', function() { - var extendable = new proto.jspb.exttest.nested.TestNestedExtensionsMessage(); - var extension = new proto.jspb.exttest.nested.TestOuterMessage.NestedExtensionMessage(['s1']); - extendable.setExtension(proto.jspb.exttest.nested.TestOuterMessage.innerExtension, extension); - assertObjectEquals(extension, - extendable.getExtension(proto.jspb.exttest.nested.TestOuterMessage.innerExtension)); + var extendable = + new proto.jspb.exttest.nested.TestNestedExtensionsMessage(); + var extension = + new proto.jspb.exttest.nested.TestOuterMessage.NestedExtensionMessage( + ['s1']); + extendable.setExtension( + proto.jspb.exttest.nested.TestOuterMessage.innerExtension, extension); + assertObjectEquals( + extension, + extendable.getExtension( + proto.jspb.exttest.nested.TestOuterMessage.innerExtension)); }); it('testToObject_extendedObject', function() { @@ -622,60 +646,72 @@ describe('Message test suite', function() { var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2'], true]); var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1); - extendable.setExtension(proto.jspb.test.IndirectExtension.simple, - extension2); + extendable.setExtension( + proto.jspb.test.IndirectExtension.simple, extension2); extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy'); - extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList, - ['a', 'b']); + extendable.setExtension( + proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']); var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2'], true]); var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2'], false]); extendable.setExtension( - proto.jspb.test.IndirectExtension.repeatedSimpleList, - [s1, s2]); - assertObjectEquals({ - str1: 'v1', str2: 'v2', str3: 'v3', - extField: { ext1: 'ext1field' }, - simple: { - aString: 'str', aRepeatedStringList: ['s1', 's2'], aBoolean: true - }, - str: 'xyzzy', - repeatedStrList: ['a', 'b'], - repeatedSimpleList: [ - { aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true}, - { aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false} - ] - }, extendable.toObject()); + proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]); + assertObjectEquals( + { + str1: 'v1', + str2: 'v2', + str3: 'v3', + extField: {ext1: 'ext1field'}, + simple: { + aString: 'str', + aRepeatedStringList: ['s1', 's2'], + aBoolean: true + }, + str: 'xyzzy', + repeatedStrList: ['a', 'b'], + repeatedSimpleList: [ + {aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true}, + {aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false} + ] + }, + extendable.toObject()); // Now, with instances included. - assertObjectEquals({ - str1: 'v1', str2: 'v2', str3: 'v3', - extField: { - ext1: 'ext1field', - $jspbMessageInstance: - extendable.getExtension(proto.jspb.test.IsExtension.extField) - }, - simple: { - aString: 'str', - aRepeatedStringList: ['s1', 's2'], - aBoolean: true, - $jspbMessageInstance: - extendable.getExtension(proto.jspb.test.IndirectExtension.simple) - }, - str: 'xyzzy', - repeatedStrList: ['a', 'b'], - repeatedSimpleList: [{ - aString: 'foo', - aRepeatedStringList: ['s1', 's2'], - aBoolean: true, - $jspbMessageInstance: s1 - }, { - aString: 'bar', - aRepeatedStringList: ['t1', 't2'], - aBoolean: false, - $jspbMessageInstance: s2 - }], - $jspbMessageInstance: extendable - }, extendable.toObject(true /* opt_includeInstance */)); + assertObjectEquals( + { + str1: 'v1', + str2: 'v2', + str3: 'v3', + extField: { + ext1: 'ext1field', + $jspbMessageInstance: + extendable.getExtension(proto.jspb.test.IsExtension.extField) + }, + simple: { + aString: 'str', + aRepeatedStringList: ['s1', 's2'], + aBoolean: true, + $jspbMessageInstance: extendable.getExtension( + proto.jspb.test.IndirectExtension.simple) + }, + str: 'xyzzy', + repeatedStrList: ['a', 'b'], + repeatedSimpleList: [ + { + aString: 'foo', + aRepeatedStringList: ['s1', 's2'], + aBoolean: true, + $jspbMessageInstance: s1 + }, + { + aString: 'bar', + aRepeatedStringList: ['t1', 't2'], + aBoolean: false, + $jspbMessageInstance: s2 + } + ], + $jspbMessageInstance: extendable + }, + extendable.toObject(true /* opt_includeInstance */)); }); it('testInitialization_emptyArray', function() { @@ -708,7 +744,8 @@ describe('Message test suite', function() { }); it('testToObject_hasExtensionField', function() { - var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1'], 102: ''}]); + var data = + new proto.jspb.test.HasExtensions(['str1', {100: ['ext1'], 102: ''}]); var obj = data.toObject(); assertEquals('str1', obj.str1); assertEquals('ext1', obj.extField.ext1); @@ -728,8 +765,7 @@ describe('Message test suite', function() { var extensionMessage = new proto.jspb.test.IsExtension(['is_extension']); data.setExtension(proto.jspb.test.IsExtension.extField, extensionMessage); var obj = data.toObject(); - assertNotNull( - data.getExtension(proto.jspb.test.IsExtension.extField)); + assertNotNull(data.getExtension(proto.jspb.test.IsExtension.extField)); assertEquals('is_extension', obj.extField.ext1); }); @@ -746,16 +782,18 @@ describe('Message test suite', function() { var groups = group.getRepeatedGroupList(); assertEquals('g1', groups[0].getId()); assertObjectEquals([true, false], groups[0].getSomeBoolList()); - assertObjectEquals({id: 'g1', someBoolList: [true, false]}, - groups[0].toObject()); - assertObjectEquals({ - repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}], - requiredGroup: {id: undefined}, - optionalGroup: undefined, - requiredSimple: {aRepeatedStringList: [], aString: undefined}, - optionalSimple: undefined, - id: undefined - }, group.toObject()); + assertObjectEquals( + {id: 'g1', someBoolList: [true, false]}, groups[0].toObject()); + assertObjectEquals( + { + repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}], + requiredGroup: {id: undefined}, + optionalGroup: undefined, + requiredSimple: {aRepeatedStringList: [], aString: undefined}, + optionalSimple: undefined, + id: undefined + }, + group.toObject()); var group1 = new proto.jspb.test.TestGroup1(); group1.setGroup(someGroup); assertEquals(someGroup, group1.getGroup()); @@ -772,28 +810,29 @@ describe('Message test suite', function() { message.setExtension$(11); message.setExtension(proto.jspb.test.TestReservedNamesExtension.foo, 12); assertEquals(11, message.getExtension$()); - assertEquals(12, message.getExtension( - proto.jspb.test.TestReservedNamesExtension.foo)); + assertEquals( + 12, + message.getExtension(proto.jspb.test.TestReservedNamesExtension.foo)); assertObjectEquals({extension: 11, foo: 12}, message.toObject()); }); it('testInitializeMessageWithUnsetOneof', function() { var message = new proto.jspb.test.TestMessageWithOneof([]); assertEquals( - proto.jspb.test.TestMessageWithOneof.PartialOneofCase. - PARTIAL_ONEOF_NOT_SET, + proto.jspb.test.TestMessageWithOneof.PartialOneofCase + .PARTIAL_ONEOF_NOT_SET, message.getPartialOneofCase()); assertEquals( - proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase. - RECURSIVE_ONEOF_NOT_SET, + proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase + .RECURSIVE_ONEOF_NOT_SET, message.getRecursiveOneofCase()); }); it('testUnsetsOneofCaseWhenFieldIsCleared', function() { var message = new proto.jspb.test.TestMessageWithOneof; assertEquals( - proto.jspb.test.TestMessageWithOneof.PartialOneofCase. - PARTIAL_ONEOF_NOT_SET, + proto.jspb.test.TestMessageWithOneof.PartialOneofCase + .PARTIAL_ONEOF_NOT_SET, message.getPartialOneofCase()); message.setPone('hi'); @@ -803,20 +842,20 @@ describe('Message test suite', function() { message.clearPone(); assertEquals( - proto.jspb.test.TestMessageWithOneof.PartialOneofCase. - PARTIAL_ONEOF_NOT_SET, + proto.jspb.test.TestMessageWithOneof.PartialOneofCase + .PARTIAL_ONEOF_NOT_SET, message.getPartialOneofCase()); }); it('testFloatingPointFieldsSupportNan', function() { var assertNan = function(x) { - assertTrue('Expected ' + x + ' (' + goog.typeOf(x) + ') to be NaN.', + assertTrue( + 'Expected ' + x + ' (' + goog.typeOf(x) + ') to be NaN.', goog.isNumber(x) && isNaN(x)); }; var message = new proto.jspb.test.FloatingPointFields([ - 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN', - 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN' + 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN', 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN' ]); assertNan(message.getOptionalFloatField()); assertNan(message.getRequiredFloatField()); @@ -837,12 +876,9 @@ describe('Message test suite', function() { message2.setExtension( proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1.a, 233); message2.setExtension( - proto - .jspb - .exttest - .reverse - .TestExtensionReverseOrderMessage1 - .TestExtensionReverseOrderNestedMessage1.b, 2333); + proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1 + .TestExtensionReverseOrderNestedMessage1.b, + 2333); message2.setExtension(proto.jspb.exttest.reverse.c, 23333); assertEquals( @@ -852,15 +888,9 @@ describe('Message test suite', function() { assertEquals( 2333, message2.getExtension( - proto - .jspb - .exttest - .reverse - .TestExtensionReverseOrderMessage1 + proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1 .TestExtensionReverseOrderNestedMessage1.b)); - assertEquals( - 23333, - message2.getExtension(proto.jspb.exttest.reverse.c)); + assertEquals(23333, message2.getExtension(proto.jspb.exttest.reverse.c)); }); it('testCircularDepsBaseOnMessageField', function() { @@ -983,16 +1013,14 @@ describe('Message test suite', function() { var package1Message = new proto.jspb.filenametest.package1.TestMessage; var package2Message = new proto.jspb.filenametest.package2.TestMessage; - package1Message.setExtension( - proto.jspb.filenametest.package1.a, 10); - package1Message.setExtension( - proto.jspb.filenametest.package1.b, 11); + package1Message.setExtension(proto.jspb.filenametest.package1.a, 10); + package1Message.setExtension(proto.jspb.filenametest.package1.b, 11); package2Message.setA(12); - assertEquals(10, - package1Message.getExtension(proto.jspb.filenametest.package1.a)); - assertEquals(11, - package1Message.getExtension(proto.jspb.filenametest.package1.b)); + assertEquals( + 10, package1Message.getExtension(proto.jspb.filenametest.package1.a)); + assertEquals( + 11, package1Message.getExtension(proto.jspb.filenametest.package1.b)); assertEquals(12, package2Message.getA()); }); diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index 9112f5e240..abec864039 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -49,9 +49,11 @@ from google.protobuf import field_mask_pb2 from google.protobuf import struct_pb2 from google.protobuf import timestamp_pb2 from google.protobuf import wrappers_pb2 +from google.protobuf import any_test_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 from google.protobuf.internal import well_known_types +from google.protobuf import descriptor_pool from google.protobuf import json_format from google.protobuf.util import json_format_proto3_pb2 @@ -202,8 +204,8 @@ class JsonFormatTest(JsonFormatBase): def testJsonParseDictToAnyDoesNotAlterInput(self): orig_dict = { - "int32Value": 20, - "@type": "type.googleapis.com/proto3.TestMessage" + 'int32Value': 20, + '@type': 'type.googleapis.com/proto3.TestMessage' } copied_dict = json.loads(json.dumps(orig_dict)) parsed_message = any_pb2.Any() @@ -628,6 +630,19 @@ class JsonFormatTest(JsonFormatBase): ' "value": {\n' ' "@type": "type.googleapis.com/proto3.TestMessage"') + def testAnyMessageDescriptorPoolMissingType(self): + packed_message = unittest_pb2.OneString() + packed_message.data = 'string' + message = any_test_pb2.TestAny() + message.any_value.Pack(packed_message) + empty_pool = descriptor_pool.DescriptorPool() + with self.assertRaises(TypeError) as cm: + json_format.MessageToJson(message, True, descriptor_pool=empty_pool) + self.assertEqual( + 'Can not find message descriptor by type_url:' + ' type.googleapis.com/protobuf_unittest.OneString.', + str(cm.exception)) + def testWellKnownInAnyMessage(self): message = any_pb2.Any() int32_value = wrappers_pb2.Int32Value() @@ -1016,6 +1031,32 @@ class JsonFormatTest(JsonFormatBase): json_format.ParseDict(js_dict, message) self.assertEqual(expected, message.int32_value) + def testParseDictAnyDescriptorPoolMissingType(self): + # Confirm that ParseDict does not raise ParseError with default pool + js_dict = { + 'any_value': { + '@type': 'type.googleapis.com/proto3.MessageType', + 'value': 1234 + } + } + json_format.ParseDict(js_dict, any_test_pb2.TestAny()) + # Check ParseDict raises ParseError with empty pool + js_dict = { + 'any_value': { + '@type': 'type.googleapis.com/proto3.MessageType', + 'value': 1234 + } + } + with self.assertRaises(json_format.ParseError) as cm: + empty_pool = descriptor_pool.DescriptorPool() + json_format.ParseDict(js_dict, + any_test_pb2.TestAny(), + descriptor_pool=empty_pool) + self.assertEqual( + str(cm.exception), + 'Failed to parse any_value field: Can not find message descriptor by' + ' type_url: type.googleapis.com/proto3.MessageType..') + def testMessageToDict(self): message = json_format_proto3_pb2.TestMessage() message.int32_value = 12345 diff --git a/python/google/protobuf/internal/missing_enum_values.proto b/python/google/protobuf/internal/missing_enum_values.proto index 1850be5bb7..5c0f499dba 100644 --- a/python/google/protobuf/internal/missing_enum_values.proto +++ b/python/google/protobuf/internal/missing_enum_values.proto @@ -30,6 +30,7 @@ syntax = "proto2"; + package google.protobuf.python.internal; message TestEnumValues { diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py index f77c44b188..4b5df99c5a 100755 --- a/python/google/protobuf/internal/python_message.py +++ b/python/google/protobuf/internal/python_message.py @@ -1406,7 +1406,11 @@ def _DiscardUnknownFields(self): self._unknown_field_set = None # pylint: disable=protected-access for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: - if field.label == _FieldDescriptor.LABEL_REPEATED: + if _IsMapField(field): + if _IsMessageMapField(field): + for key in value: + value[key].DiscardUnknownFields() + elif field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 3580677b02..16a3f534e9 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -715,6 +715,24 @@ class TextFormatParserTests(TextFormatBase): self.assertEqual(m.optional_string, self._GOLDEN_UNICODE) self.assertEqual(m.repeated_bytes[0], self._GOLDEN_BYTES) + def testParseDuplicateMessages(self, message_module): + message = message_module.TestAllTypes() + text = ('optional_nested_message { bb: 1 } ' + 'optional_nested_message { bb: 2 }') + six.assertRaisesRegex(self, text_format.ParseError, ( + r'1:59 : Message type "\w+.TestAllTypes" ' + r'should not have multiple "optional_nested_message" fields.'), + text_format.Parse, text, + message) + + def testParseDuplicateScalars(self, message_module): + message = message_module.TestAllTypes() + text = ('optional_int32: 42 ' 'optional_int32: 67') + six.assertRaisesRegex(self, text_format.ParseError, ( + r'1:36 : Message type "\w+.TestAllTypes" should not ' + r'have multiple "optional_int32" fields.'), text_format.Parse, text, + message) + @_parameterized.parameters(unittest_pb2, unittest_proto3_arena_pb2) class TextFormatMergeTests(TextFormatBase): @@ -1293,16 +1311,6 @@ class Proto2Tests(TextFormatBase): '"protobuf_unittest.optional_int32_extension" extensions.'), text_format.Parse, text, message) - def testParseDuplicateMessages(self): - message = unittest_pb2.TestAllTypes() - text = ('optional_nested_message { bb: 1 } ' - 'optional_nested_message { bb: 2 }') - six.assertRaisesRegex(self, text_format.ParseError, ( - '1:59 : Message type "protobuf_unittest.TestAllTypes" ' - 'should not have multiple "optional_nested_message" fields.'), - text_format.Parse, text, - message) - def testParseDuplicateExtensionMessages(self): message = unittest_pb2.TestAllExtensions() text = ('[protobuf_unittest.optional_nested_message_extension]: {} ' @@ -1313,14 +1321,6 @@ class Proto2Tests(TextFormatBase): '"protobuf_unittest.optional_nested_message_extension" extensions.'), text_format.Parse, text, message) - def testParseDuplicateScalars(self): - message = unittest_pb2.TestAllTypes() - text = ('optional_int32: 42 ' 'optional_int32: 67') - six.assertRaisesRegex(self, text_format.ParseError, ( - '1:36 : Message type "protobuf_unittest.TestAllTypes" should not ' - 'have multiple "optional_int32" fields.'), text_format.Parse, text, - message) - def testParseGroupNotClosed(self): message = unittest_pb2.TestAllTypes() text = 'RepeatedGroup: <' diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index fceadf718e..ab0260e010 100755 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -39,6 +39,7 @@ try: import unittest2 as unittest #PY26 except ImportError: import unittest +from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 from google.protobuf import unittest_proto3_arena_pb2 @@ -138,6 +139,18 @@ class UnknownFieldsTest(BaseTestCase): self.assertEqual( b'', message.repeated_nested_message[0].SerializeToString()) + msg = map_unittest_pb2.TestMap() + msg.map_int32_all_types[1].optional_nested_message.ParseFromString( + other_message.SerializeToString()) + msg.map_string_string['1'] = 'test' + self.assertNotEqual( + b'', + msg.map_int32_all_types[1].optional_nested_message.SerializeToString()) + msg.DiscardUnknownFields() + self.assertEqual( + b'', + msg.map_int32_all_types[1].optional_nested_message.SerializeToString()) + class UnknownFieldsAccessorsTest(BaseTestCase): diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index 3f2c1bfbe2..a184fa99aa 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -96,12 +96,14 @@ class ParseError(Error): """Thrown in case of parsing error.""" -def MessageToJson(message, - including_default_value_fields=False, - preserving_proto_field_name=False, - indent=2, - sort_keys=False, - use_integers_for_enums=False): +def MessageToJson( + message, + including_default_value_fields=False, + preserving_proto_field_name=False, + indent=2, + sort_keys=False, + use_integers_for_enums=False, + descriptor_pool=None): """Converts protobuf message to JSON format. Args: @@ -117,20 +119,26 @@ def MessageToJson(message, An indent level of 0 or negative will only insert newlines. sort_keys: If True, then the output will be sorted by field names. use_integers_for_enums: If true, print integers instead of enum names. + descriptor_pool: A Descriptor Pool for resolving types. If None use the + default. Returns: A string containing the JSON formatted protocol buffer message. """ - printer = _Printer(including_default_value_fields, - preserving_proto_field_name, - use_integers_for_enums) + printer = _Printer( + including_default_value_fields, + preserving_proto_field_name, + use_integers_for_enums, + descriptor_pool) return printer.ToJsonString(message, indent, sort_keys) -def MessageToDict(message, - including_default_value_fields=False, - preserving_proto_field_name=False, - use_integers_for_enums=False): +def MessageToDict( + message, + including_default_value_fields=False, + preserving_proto_field_name=False, + use_integers_for_enums=False, + descriptor_pool=None): """Converts protobuf message to a dictionary. When the dictionary is encoded to JSON, it conforms to proto3 JSON spec. @@ -145,13 +153,17 @@ def MessageToDict(message, names as defined in the .proto file. If False, convert the field names to lowerCamelCase. use_integers_for_enums: If true, print integers instead of enum names. + descriptor_pool: A Descriptor Pool for resolving types. If None use the + default. Returns: A dict representation of the protocol buffer message. """ - printer = _Printer(including_default_value_fields, - preserving_proto_field_name, - use_integers_for_enums) + printer = _Printer( + including_default_value_fields, + preserving_proto_field_name, + use_integers_for_enums, + descriptor_pool) # pylint: disable=protected-access return printer._MessageToJsonObject(message) @@ -165,13 +177,16 @@ def _IsMapEntry(field): class _Printer(object): """JSON format printer for protocol message.""" - def __init__(self, - including_default_value_fields=False, - preserving_proto_field_name=False, - use_integers_for_enums=False): + def __init__( + self, + including_default_value_fields=False, + preserving_proto_field_name=False, + use_integers_for_enums=False, + descriptor_pool=None): self.including_default_value_fields = including_default_value_fields self.preserving_proto_field_name = preserving_proto_field_name self.use_integers_for_enums = use_integers_for_enums + self.descriptor_pool = descriptor_pool def ToJsonString(self, message, indent, sort_keys): js = self._MessageToJsonObject(message) @@ -300,7 +315,7 @@ class _Printer(object): js = OrderedDict() type_url = message.type_url js['@type'] = type_url - sub_message = _CreateMessageFromTypeUrl(type_url) + sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool) sub_message.ParseFromString(message.value) message_descriptor = sub_message.DESCRIPTOR full_name = message_descriptor.full_name @@ -366,13 +381,13 @@ def _DuplicateChecker(js): return result -def _CreateMessageFromTypeUrl(type_url): - # TODO(jieluo): Should add a way that users can register the type resolver - # instead of the default one. +def _CreateMessageFromTypeUrl(type_url, descriptor_pool): + """Creates a message from a type URL.""" db = symbol_database.Default() + pool = db.pool if descriptor_pool is None else descriptor_pool type_name = type_url.split('/')[-1] try: - message_descriptor = db.pool.FindMessageTypeByName(type_name) + message_descriptor = pool.FindMessageTypeByName(type_name) except KeyError: raise TypeError( 'Can not find message descriptor by type_url: {0}.'.format(type_url)) @@ -380,13 +395,15 @@ def _CreateMessageFromTypeUrl(type_url): return message_class() -def Parse(text, message, ignore_unknown_fields=False): +def Parse(text, message, ignore_unknown_fields=False, descriptor_pool=None): """Parses a JSON representation of a protocol message into a message. Args: text: Message JSON representation. message: A protocol buffer message to merge into. ignore_unknown_fields: If True, do not raise errors for unknown fields. + descriptor_pool: A Descriptor Pool for resolving types. If None use the + default. Returns: The same message passed as argument. @@ -399,21 +416,26 @@ def Parse(text, message, ignore_unknown_fields=False): js = json.loads(text, object_pairs_hook=_DuplicateChecker) except ValueError as e: raise ParseError('Failed to load JSON: {0}.'.format(str(e))) - return ParseDict(js, message, ignore_unknown_fields) + return ParseDict(js, message, ignore_unknown_fields, descriptor_pool) -def ParseDict(js_dict, message, ignore_unknown_fields=False): +def ParseDict(js_dict, + message, + ignore_unknown_fields=False, + descriptor_pool=None): """Parses a JSON dictionary representation into a message. Args: js_dict: Dict representation of a JSON message. message: A protocol buffer message to merge into. ignore_unknown_fields: If True, do not raise errors for unknown fields. + descriptor_pool: A Descriptor Pool for resolving types. If None use the + default. Returns: The same message passed as argument. """ - parser = _Parser(ignore_unknown_fields) + parser = _Parser(ignore_unknown_fields, descriptor_pool) parser.ConvertMessage(js_dict, message) return message @@ -424,9 +446,9 @@ _INT_OR_FLOAT = six.integer_types + (float,) class _Parser(object): """JSON format parser for protocol message.""" - def __init__(self, - ignore_unknown_fields): + def __init__(self, ignore_unknown_fields, descriptor_pool): self.ignore_unknown_fields = ignore_unknown_fields + self.descriptor_pool = descriptor_pool def ConvertMessage(self, value, message): """Convert a JSON object into a message. @@ -562,7 +584,7 @@ class _Parser(object): except KeyError: raise ParseError('@type is missing when parsing any message.') - sub_message = _CreateMessageFromTypeUrl(type_url) + sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool) message_descriptor = sub_message.DESCRIPTOR full_name = message_descriptor.full_name if _IsWrapperMessage(message_descriptor): diff --git a/python/google/protobuf/pyext/map_container.cc b/python/google/protobuf/pyext/map_container.cc index 9f74e2a5c5..d85840219d 100644 --- a/python/google/protobuf/pyext/map_container.cc +++ b/python/google/protobuf/pyext/map_container.cc @@ -346,11 +346,11 @@ PyObject* MapReflectionFriend::MergeFrom(PyObject* _self, PyObject* arg) { const Message* other_message = other_map->message; const Reflection* reflection = message->GetReflection(); const Reflection* other_reflection = other_message->GetReflection(); - internal::MapFieldBase* field = reflection->MapData( + internal::MapFieldBase* field = reflection->MutableMapData( message, self->parent_field_descriptor); - internal::MapFieldBase* other_field = - other_reflection->MapData(const_cast(other_message), - self->parent_field_descriptor); + const internal::MapFieldBase* other_field = + other_reflection->GetMapData(*other_message, + self->parent_field_descriptor); field->MergeFrom(*other_field); self->version++; Py_RETURN_NONE; diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index f7053c61d3..1d965fa9bd 100755 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -937,11 +937,9 @@ class _Parser(object): else: getattr(message, field.name).append(value) else: - # Proto3 doesn't represent presence so we can't test if multiple scalars - # have occurred. We have to allow them. - can_check_presence = not self._IsProto3Syntax(message) if field.is_extension: - if (not self._allow_multiple_scalars and can_check_presence and + if (not self._allow_multiple_scalars and + not self._IsProto3Syntax(message) and message.HasExtension(field)): raise tokenizer.ParseErrorPreviousToken( 'Message type "%s" should not have multiple "%s" extensions.' % @@ -949,8 +947,16 @@ class _Parser(object): else: message.Extensions[field] = value else: - if (not self._allow_multiple_scalars and can_check_presence and - message.HasField(field.name)): + duplicate_error = False + if not self._allow_multiple_scalars: + if self._IsProto3Syntax(message): + # Proto3 doesn't represent presence so we try best effort to check + # multiple scalars by compare to default values. + duplicate_error = bool(getattr(message, field.name)) + else: + duplicate_error = message.HasField(field.name) + + if duplicate_error: raise tokenizer.ParseErrorPreviousToken( 'Message type "%s" should not have multiple "%s" fields.' % (message.DESCRIPTOR.full_name, field.name)) diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index d37b23c707..1c95380d27 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -201,13 +201,13 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string type_url = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Any.type_url"); auto str = msg->mutable_type_url(); @@ -226,7 +226,7 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object // bytes value = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); auto str = msg->mutable_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { @@ -242,7 +242,7 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -256,13 +256,9 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Any::MergePartialFromCodedStream( @@ -352,8 +348,7 @@ void Any::SerializeWithCachedSizes( } ::google::protobuf::uint8* Any::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index a56549a4b4..ba93762273 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -148,7 +148,7 @@ class PROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_inser void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 846ea6b7ae..2a5c466efb 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -307,13 +307,13 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Api.name"); auto str = msg->mutable_name(); @@ -333,7 +333,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Method::_InternalParse; object = msg->add_methods(); @@ -351,7 +351,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -368,7 +368,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object // string version = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Api.version"); auto str = msg->mutable_version(); @@ -387,7 +387,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object // .google.protobuf.SourceContext source_context = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); @@ -403,7 +403,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Mixin::_InternalParse; object = msg->add_mixins(); @@ -421,14 +421,14 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); msg->set_syntax(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -442,13 +442,9 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Api::MergePartialFromCodedStream( @@ -643,8 +639,7 @@ void Api::SerializeWithCachedSizes( } ::google::protobuf::uint8* Api::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Api) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -665,7 +660,7 @@ void Api::SerializeWithCachedSizes( n = static_cast(this->methods_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, this->methods(static_cast(i)), deterministic, target); + 2, this->methods(static_cast(i)), target); } // repeated .google.protobuf.Option options = 3; @@ -673,7 +668,7 @@ void Api::SerializeWithCachedSizes( n = static_cast(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, this->options(static_cast(i)), deterministic, target); + 3, this->options(static_cast(i)), target); } // string version = 4; @@ -691,7 +686,7 @@ void Api::SerializeWithCachedSizes( if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 5, HasBitSetters::source_context(this), deterministic, target); + 5, HasBitSetters::source_context(this), target); } // repeated .google.protobuf.Mixin mixins = 6; @@ -699,7 +694,7 @@ void Api::SerializeWithCachedSizes( n = static_cast(this->mixins_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 6, this->mixins(static_cast(i)), deterministic, target); + 6, this->mixins(static_cast(i)), target); } // .google.protobuf.Syntax syntax = 7; @@ -983,13 +978,13 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.name"); auto str = msg->mutable_name(); @@ -1008,7 +1003,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj // string request_type_url = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.request_type_url"); auto str = msg->mutable_request_type_url(); @@ -1028,7 +1023,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_request_streaming(value); @@ -1037,7 +1032,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj // string response_type_url = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.response_type_url"); auto str = msg->mutable_response_type_url(); @@ -1057,7 +1052,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_response_streaming(value); @@ -1067,7 +1062,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -1085,14 +1080,14 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); msg->set_syntax(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1106,13 +1101,9 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Method::MergePartialFromCodedStream( @@ -1311,8 +1302,7 @@ void Method::SerializeWithCachedSizes( } ::google::protobuf::uint8* Method::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Method) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1365,7 +1355,7 @@ void Method::SerializeWithCachedSizes( n = static_cast(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 6, this->options(static_cast(i)), deterministic, target); + 6, this->options(static_cast(i)), target); } // .google.protobuf.Syntax syntax = 7; @@ -1617,13 +1607,13 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Mixin.name"); auto str = msg->mutable_name(); @@ -1642,7 +1632,7 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje // string root = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Mixin.root"); auto str = msg->mutable_root(); @@ -1659,7 +1649,7 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1673,13 +1663,9 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Mixin::MergePartialFromCodedStream( @@ -1777,8 +1763,7 @@ void Mixin::SerializeWithCachedSizes( } ::google::protobuf::uint8* Mixin::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Mixin) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 10edb98483..518c6be844 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -142,7 +142,7 @@ class PROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_inser void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -332,7 +332,7 @@ class PROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc_in void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -515,7 +515,7 @@ class PROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ins void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index a1cceecaa2..dc540cfa27 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -74,20 +74,90 @@ string DotsToColons(const string& name) { return StringReplace(name, ".", "::", true); } -const char* const kKeywordList[] = { - "alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor", - "bool", "break", "case", "catch", "char", "class", "compl", "const", - "constexpr", "const_cast", "continue", "decltype", "default", "delete", "do", - "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", - "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", - "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", - "operator", "or", "or_eq", "private", "protected", "public", "register", - "reinterpret_cast", "return", "short", "signed", "sizeof", "static", - "static_assert", "static_cast", "struct", "switch", "template", "this", - "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", - "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", - "while", "xor", "xor_eq" -}; +const char* const kKeywordList[] = { // + "NULL", + "alignas", + "alignof", + "and", + "and_eq", + "asm", + "auto", + "bitand", + "bitor", + "bool", + "break", + "case", + "catch", + "char", + "class", + "compl", + "const", + "constexpr", + "const_cast", + "continue", + "decltype", + "default", + "delete", + "do", + "double", + "dynamic_cast", + "else", + "enum", + "explicit", + "export", + "extern", + "false", + "float", + "for", + "friend", + "goto", + "if", + "inline", + "int", + "long", + "mutable", + "namespace", + "new", + "noexcept", + "not", + "not_eq", + "nullptr", + "operator", + "or", + "or_eq", + "private", + "protected", + "public", + "register", + "reinterpret_cast", + "return", + "short", + "signed", + "sizeof", + "static", + "static_assert", + "static_cast", + "struct", + "switch", + "template", + "this", + "thread_local", + "throw", + "true", + "try", + "typedef", + "typeid", + "typename", + "union", + "unsigned", + "using", + "virtual", + "void", + "volatile", + "wchar_t", + "while", + "xor", + "xor_eq"}; std::unordered_set MakeKeywordsMap() { std::unordered_set result; @@ -173,9 +243,15 @@ void SetCommonVars(const Options& options, // split them. It might not strictly matter since we don't generate google3 // code in open-source. But it's good to prevent surprising things from // happening. - (*variables)["GOOGLE_PROTOBUF"] = "GOOGLE3" "_PROTOBUF"; - (*variables)["CHK"] = "CH" "ECK"; - (*variables)["DCHK"] = "DCH" "ECK"; + (*variables)["GOOGLE_PROTOBUF"] = + "GOOGLE3" + "_PROTOBUF"; + (*variables)["CHK"] = + "CH" + "ECK"; + (*variables)["DCHK"] = + "DCH" + "ECK"; } SetIntVar(options, "uint8", variables); @@ -212,9 +288,9 @@ string UnderscoresToCamelCase(const string& input, bool cap_next_letter) { } const char kThickSeparator[] = - "// ===================================================================\n"; + "// ===================================================================\n"; const char kThinSeparator[] = - "// -------------------------------------------------------------------\n"; + "// -------------------------------------------------------------------\n"; bool CanInitializeByZeroing(const FieldDescriptor* field) { if (field->is_repeated() || field->is_extension()) return false; @@ -250,7 +326,7 @@ string ClassName(const Descriptor* descriptor) { } string ClassName(const EnumDescriptor* enum_descriptor) { - if (enum_descriptor->containing_type() == NULL) { + if (enum_descriptor->containing_type() == nullptr) { return enum_descriptor->name(); } else { return ClassName(enum_descriptor->containing_type()) + "_" + @@ -280,7 +356,7 @@ string Namespace(const EnumDescriptor* d) { return Namespace(d->file()); } string DefaultInstanceName(const Descriptor* descriptor) { string prefix = descriptor->file()->package().empty() ? "" : "::"; return prefix + DotsToColons(descriptor->file()->package()) + "::_" + - ClassName(descriptor, false) + "_default_instance_"; + ClassName(descriptor, false) + "_default_instance_"; } string ReferenceFunctionName(const Descriptor* descriptor) { @@ -311,7 +387,7 @@ string EnumValueName(const EnumValueDescriptor* enum_value) { } int EstimateAlignmentSize(const FieldDescriptor* field) { - if (field == NULL) return 0; + if (field == nullptr) return 0; if (field->is_repeated()) return 8; switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_BOOL: @@ -334,13 +410,13 @@ int EstimateAlignmentSize(const FieldDescriptor* field) { return -1; // Make compiler happy. } -string FieldConstantName(const FieldDescriptor *field) { +string FieldConstantName(const FieldDescriptor* field) { string field_name = UnderscoresToCamelCase(field->name(), true); string result = "k" + field_name + "FieldNumber"; if (!field->is_extension() && field->containing_type()->FindFieldByCamelcaseName( - field->camelcase_name()) != field) { + field->camelcase_name()) != field) { // This field's camelcase name is not unique. As a hack, add the field // number to the constant name. This makes the constant rather useless, // but what can we do? @@ -366,23 +442,33 @@ string StripProto(const string& filename) { const char* PrimitiveTypeName(FieldDescriptor::CppType type) { switch (type) { - case FieldDescriptor::CPPTYPE_INT32 : return "::google::protobuf::int32"; - case FieldDescriptor::CPPTYPE_INT64 : return "::google::protobuf::int64"; - case FieldDescriptor::CPPTYPE_UINT32 : return "::google::protobuf::uint32"; - case FieldDescriptor::CPPTYPE_UINT64 : return "::google::protobuf::uint64"; - case FieldDescriptor::CPPTYPE_DOUBLE : return "double"; - case FieldDescriptor::CPPTYPE_FLOAT : return "float"; - case FieldDescriptor::CPPTYPE_BOOL : return "bool"; - case FieldDescriptor::CPPTYPE_ENUM : return "int"; - case FieldDescriptor::CPPTYPE_STRING : return "::std::string"; - case FieldDescriptor::CPPTYPE_MESSAGE: return NULL; + case FieldDescriptor::CPPTYPE_INT32: + return "::google::protobuf::int32"; + case FieldDescriptor::CPPTYPE_INT64: + return "::google::protobuf::int64"; + case FieldDescriptor::CPPTYPE_UINT32: + return "::google::protobuf::uint32"; + case FieldDescriptor::CPPTYPE_UINT64: + return "::google::protobuf::uint64"; + case FieldDescriptor::CPPTYPE_DOUBLE: + return "double"; + case FieldDescriptor::CPPTYPE_FLOAT: + return "float"; + case FieldDescriptor::CPPTYPE_BOOL: + return "bool"; + case FieldDescriptor::CPPTYPE_ENUM: + return "int"; + case FieldDescriptor::CPPTYPE_STRING: + return "::std::string"; + case FieldDescriptor::CPPTYPE_MESSAGE: + return nullptr; - // No default because we want the compiler to complain if any new - // CppTypes are added. + // No default because we want the compiler to complain if any new + // CppTypes are added. } GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; + return nullptr; } string PrimitiveTypeName(const Options& options, @@ -419,29 +505,47 @@ string PrimitiveTypeName(const Options& options, const char* DeclaredTypeMethodName(FieldDescriptor::Type type) { switch (type) { - case FieldDescriptor::TYPE_INT32 : return "Int32"; - case FieldDescriptor::TYPE_INT64 : return "Int64"; - case FieldDescriptor::TYPE_UINT32 : return "UInt32"; - case FieldDescriptor::TYPE_UINT64 : return "UInt64"; - case FieldDescriptor::TYPE_SINT32 : return "SInt32"; - case FieldDescriptor::TYPE_SINT64 : return "SInt64"; - case FieldDescriptor::TYPE_FIXED32 : return "Fixed32"; - case FieldDescriptor::TYPE_FIXED64 : return "Fixed64"; - case FieldDescriptor::TYPE_SFIXED32: return "SFixed32"; - case FieldDescriptor::TYPE_SFIXED64: return "SFixed64"; - case FieldDescriptor::TYPE_FLOAT : return "Float"; - case FieldDescriptor::TYPE_DOUBLE : return "Double"; - - case FieldDescriptor::TYPE_BOOL : return "Bool"; - case FieldDescriptor::TYPE_ENUM : return "Enum"; - - case FieldDescriptor::TYPE_STRING : return "String"; - case FieldDescriptor::TYPE_BYTES : return "Bytes"; - case FieldDescriptor::TYPE_GROUP : return "Group"; - case FieldDescriptor::TYPE_MESSAGE : return "Message"; - - // No default because we want the compiler to complain if any new - // types are added. + case FieldDescriptor::TYPE_INT32: + return "Int32"; + case FieldDescriptor::TYPE_INT64: + return "Int64"; + case FieldDescriptor::TYPE_UINT32: + return "UInt32"; + case FieldDescriptor::TYPE_UINT64: + return "UInt64"; + case FieldDescriptor::TYPE_SINT32: + return "SInt32"; + case FieldDescriptor::TYPE_SINT64: + return "SInt64"; + case FieldDescriptor::TYPE_FIXED32: + return "Fixed32"; + case FieldDescriptor::TYPE_FIXED64: + return "Fixed64"; + case FieldDescriptor::TYPE_SFIXED32: + return "SFixed32"; + case FieldDescriptor::TYPE_SFIXED64: + return "SFixed64"; + case FieldDescriptor::TYPE_FLOAT: + return "Float"; + case FieldDescriptor::TYPE_DOUBLE: + return "Double"; + + case FieldDescriptor::TYPE_BOOL: + return "Bool"; + case FieldDescriptor::TYPE_ENUM: + return "Enum"; + + case FieldDescriptor::TYPE_STRING: + return "String"; + case FieldDescriptor::TYPE_BYTES: + return "Bytes"; + case FieldDescriptor::TYPE_GROUP: + return "Group"; + case FieldDescriptor::TYPE_MESSAGE: + return "Message"; + + // No default because we want the compiler to complain if any new + // types are added. } GOOGLE_LOG(FATAL) << "Can't get here."; return ""; @@ -504,39 +608,37 @@ string DefaultValue(const Options& options, const FieldDescriptor* field) { return SimpleDtoa(value); } } - case FieldDescriptor::CPPTYPE_FLOAT: - { - float value = field->default_value_float(); - if (value == std::numeric_limits::infinity()) { - return "std::numeric_limits::infinity()"; - } else if (value == -std::numeric_limits::infinity()) { - return "-std::numeric_limits::infinity()"; - } else if (value != value) { - return "std::numeric_limits::quiet_NaN()"; - } else { - string float_value = SimpleFtoa(value); - // If floating point value contains a period (.) or an exponent - // (either E or e), then append suffix 'f' to make it a float - // literal. - if (float_value.find_first_of(".eE") != string::npos) { - float_value.push_back('f'); - } - return float_value; + case FieldDescriptor::CPPTYPE_FLOAT: { + float value = field->default_value_float(); + if (value == std::numeric_limits::infinity()) { + return "std::numeric_limits::infinity()"; + } else if (value == -std::numeric_limits::infinity()) { + return "-std::numeric_limits::infinity()"; + } else if (value != value) { + return "std::numeric_limits::quiet_NaN()"; + } else { + string float_value = SimpleFtoa(value); + // If floating point value contains a period (.) or an exponent + // (either E or e), then append suffix 'f' to make it a float + // literal. + if (float_value.find_first_of(".eE") != string::npos) { + float_value.push_back('f'); } + return float_value; } + } case FieldDescriptor::CPPTYPE_BOOL: return field->default_value_bool() ? "true" : "false"; case FieldDescriptor::CPPTYPE_ENUM: // Lazy: Generate a static_cast because we don't have a helper function // that constructs the full name of an enum value. return strings::Substitute( - "static_cast< $0 >($1)", - ClassName(field->enum_type(), true), + "static_cast< $0 >($1)", ClassName(field->enum_type(), true), Int32ToString(field->default_value_enum()->number())); case FieldDescriptor::CPPTYPE_STRING: - return "\"" + EscapeTrigraphs( - CEscape(field->default_value_string())) + - "\""; + return "\"" + + EscapeTrigraphs(CEscape(field->default_value_string())) + + "\""; case FieldDescriptor::CPPTYPE_MESSAGE: return "*" + FieldMessageTypeName(field) + "::internal_default_instance()"; @@ -583,8 +685,7 @@ string EscapeTrigraphs(const string& to_escape) { // Escaped function name to eliminate naming conflict. string SafeFunctionName(const Descriptor* descriptor, - const FieldDescriptor* field, - const string& prefix) { + const FieldDescriptor* field, const string& prefix) { // Do not use FieldName() since it will escape keywords. string name = field->name(); LowerString(&name); @@ -601,6 +702,25 @@ string SafeFunctionName(const Descriptor* descriptor, return function_name; } +bool IsStringInlined(const FieldDescriptor* descriptor, + const Options& options) { + if (options.opensource_runtime) return false; + + // TODO(ckennelly): Handle inlining for any.proto. + if (IsAnyMessage(descriptor->containing_type(), options)) return false; + if (descriptor->containing_type()->options().map_entry()) return false; + + // Limit to proto2, as we rely on has bits to distinguish field presence for + // release_$name$. On proto3, we cannot use the address of the string + // instance when the field has been inlined. + if (!HasFieldPresence(descriptor->file())) return false; + + if (options.access_info_map) { + if (descriptor->is_required()) return true; + } + return false; +} + static bool HasLazyFields(const Descriptor* descriptor, const Options& options) { for (int field_idx = 0; field_idx < descriptor->field_count(); field_idx++) { @@ -809,7 +929,7 @@ bool IsWellKnownMessage(const FileDescriptor* descriptor) { enum Utf8CheckMode { STRICT = 0, // Parsing will fail if non UTF-8 data is in string fields. VERIFY = 1, // Only log an error but parsing will succeed. - NONE = 2, // No UTF-8 check. + NONE = 2, // No UTF-8 check. }; static bool FieldEnforceUtf8(const FieldDescriptor* field, @@ -954,7 +1074,7 @@ bool IsImplicitWeakField(const FieldDescriptor* field, const Options& options, return UsingImplicitWeakFields(field->file(), options) && field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_required() && !field->is_map() && - field->containing_oneof() == NULL && + field->containing_oneof() == nullptr && !IsWellKnownMessage(field->message_type()->file()) && // We do not support implicit weak fields between messages in the same // strongly-connected component. @@ -1114,8 +1234,8 @@ bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context, "#define PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n" "#include \"$forward_to_basename$.pb.h\" // IWYU pragma: export\n" "#endif // PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n", - "forward_to_basename", forward_to_basename, - "filename_identifier", FilenameIdentifier(*basename)); + "forward_to_basename", forward_to_basename, "filename_identifier", + FilenameIdentifier(*basename)); if (!options.opensource_runtime) { // HACK HACK HACK, tech debt from the deeps of proto1 and SWIG @@ -1141,8 +1261,8 @@ bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context, "export\n" "#endif // " "PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PROTO_H\n", - "forward_to_basename", forward_to_basename, - "filename_identifier", FilenameIdentifier(*basename)); + "forward_to_basename", forward_to_basename, "filename_identifier", + FilenameIdentifier(*basename)); } { @@ -1174,502 +1294,571 @@ bool ShouldRepeat(const FieldDescriptor* descriptor, wiretype != internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED); } -void GenerateStrings(const FieldDescriptor* field, const Options& options, - const Formatter& format, bool check_utf8) { - string utf8; - if (check_utf8) { - utf8 = GetUtf8Suffix(field, options); - if (!utf8.empty()) { - string name = "nullptr"; - if (HasDescriptorMethods(field->file(), options)) { - name = "\"" + field->full_name() + "\""; - } - format("ctx->extra_parse_data().SetFieldName($1$);\n", name); +class ParseLoopGenerator { + public: + ParseLoopGenerator(const Options& options, MessageSCCAnalyzer* scc_analyzer, + io::Printer* printer) + : scc_analyzer_(scc_analyzer), options_(options), format_(printer) {} + + void GenerateParserLoop(const Descriptor* descriptor) { + format_.Set("classname", ClassName(descriptor)); + format_.Set("proto_ns", ProtobufNamespace(options_)); + format_.Set("GOOGLE_PROTOBUF", MacroPrefix(options_)); + std::map vars; + SetCommonVars(options_, &vars); + format_.AddMap(vars); + + std::vector ordered_fields; + for (auto field : FieldRange(descriptor)) { + ordered_fields.push_back(field); } - } - format( - "auto str = msg->$1$_$2$();\n" - "if (size > end - ptr + " - "::$proto_ns$::internal::ParseContext::kSlopBytes) {\n" - " object = str;\n", - field->is_repeated() && !field->is_packable() ? "add" : "mutable", - FieldName(field)); - string name; - if (field->options().ctype() == FieldOptions::STRING || - (IsProto1(field->file(), options) && - field->options().ctype() == FieldOptions::STRING_PIECE)) { - name = "GreedyStringParser"; - format(" str->clear();\n"); - // TODO(gerbens) evaluate security - format(" str->reserve(size);\n"); - } else if (field->options().ctype() == FieldOptions::CORD) { - name = "CordParser"; - format(" str->Clear();\n"); - } else if (field->options().ctype() == FieldOptions::STRING_PIECE) { - name = "StringPieceParser"; - format(" str->Clear();\n"); - } - format( - " parser_till_end = ::$proto_ns$::internal::$1$$2$;\n" - " goto len_delim_till_end;\n" - "}\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(::$proto_ns$::internal::StringCheck$2$(" - "ptr, size, ctx));\n" - "::$proto_ns$::internal::Inline$1$(str, ptr, size, ctx);\n" - "ptr += size;\n", - name, utf8); -} - -void GenerateLengthDelim( - const FieldDescriptor* field, const Options& options, - MessageSCCAnalyzer* scc_analyzer, - const Formatter& format) { - format( - "ptr = Varint::Parse32Inline(ptr, &size);\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); - if (!IsProto1(field->file(), options) && field->is_packable()) { - if (!HasPreservingUnknownEnumSemantics(field->file()) && - field->type() == FieldDescriptor::TYPE_ENUM) { - format( - "ctx->extra_parse_data().SetEnumValidator($1$_IsValid, " - "msg->mutable_unknown_fields(), $2$);\n" - "parser_till_end = " - "::$proto_ns$::internal::PackedValidEnumParser$3$;\n" - "object = msg->mutable_$4$();\n", - QualifiedClassName(field->enum_type()), field->number(), - UseUnknownFieldSet(field->file(), options) ? "" : "Lite", - FieldName(field)); + std::sort(ordered_fields.begin(), ordered_fields.end(), + [](const FieldDescriptor* a, const FieldDescriptor* b) { + return a->number() < b->number(); + }); + + format_( + "const char* $classname$::_InternalParse(const char* begin, const " + "char* " + "end, void* object,\n" + " ::$proto_ns$::internal::ParseContext* ctx) {\n" + " auto msg = static_cast<$classname$*>(object);\n" + " $uint32$ size; (void)size;\n" + " int depth; (void)depth;\n" + " $uint32$ tag;\n" + " ::$proto_ns$::internal::ParseFunc parser_till_end; " + "(void)parser_till_end;\n" + " auto ptr = begin;\n" + " while (ptr < end) {\n" + " ptr = ::$proto_ns$::io::Parse32(ptr, &tag);\n" + " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n" + " switch (tag >> 3) {\n"); + + format_.Indent(); + format_.Indent(); + format_.Indent(); + + bool use_handle_unusual = false; + for (const auto* field : ordered_fields) { + if (IsProto1(descriptor->file(), options_)) { + if (field->number() >= (1 << 14)) continue; + } + // Print the field's (or oneof's) proto-syntax definition as a comment. + // We don't want to print group bodies so we cut off after the first + // line. + string def; + { + DebugStringOptions options; + options.elide_group_body = true; + options.elide_oneof_body = true; + def = field->DebugStringWithOptions(options); + def = def.substr(0, def.find_first_of('\n')); + } + format_( + "// $1$\n" + "case $2$: {\n", + def, field->number()); + format_.Indent(); + use_handle_unusual = true; + GenerateCaseBody(field); + format_.Outdent(); + format_("}\n"); // case + } // for fields + format_("default: {\n"); + if (use_handle_unusual) format_("handle_unusual:\n"); + format_( + " if ((tag & 7) == 4 || tag == 0) {\n" + " ctx->EndGroup(tag);\n" + " return ptr;\n" + " }\n"); + if (IsMapEntryMessage(descriptor)) { + format_( + " break;\n" + "}\n"); } else { - format( - "parser_till_end = ::$proto_ns$::internal::Packed$1$Parser;\n" - "object = msg->mutable_$2$();\n", - DeclaredTypeMethodName(field->type()), FieldName(field)); + if (descriptor->extension_range_count() > 0) { + format_("if ("); + for (int i = 0; i < descriptor->extension_range_count(); i++) { + const Descriptor::ExtensionRange* range = + descriptor->extension_range(i); + if (i > 0) format_(" ||\n "); + + uint32 start_tag = WireFormatLite::MakeTag( + range->start, static_cast(0)); + uint32 end_tag = WireFormatLite::MakeTag( + range->end, static_cast(0)); + + if (range->end > FieldDescriptor::kMaxNumber) { + format_("($1$u <= tag)", start_tag); + } else { + format_("($1$u <= tag && tag < $2$u)", start_tag, end_tag); + } + } + format_(") {\n"); + format_( + " auto res = msg->_extensions_.ParseField(tag, {_InternalParse, " + "msg}, ptr, end,\n" + " internal_default_instance(), &msg->_internal_metadata_, " + "ctx);\n" + " ptr = res.first;\n" + " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr != nullptr);\n" + " if (res.second) return ptr;\n" + " continue;\n" + "}\n"); + } + format_( + " auto res = UnknownFieldParse(tag, {_InternalParse, msg},\n" + " ptr, end, msg->_internal_metadata_.mutable_unknown_fields(), " + "ctx);\n" + " ptr = res.first;\n" + " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr != nullptr);\n" + " if (res.second) return ptr;\n" + "}\n"); // default case } - format( - "if (size > end - ptr) goto len_delim_till_end;\n" - "auto newend = ptr + size;\n" - "if (size) ptr = parser_till_end(ptr, newend, object, ctx);\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr == newend);\n"); - } else { - auto field_type = field->type(); - if (IsProto1(field->file(), options)) { - if (field->is_packable()) { - // Sigh ... packed fields endup as a string in proto1 - field_type = FieldDescriptor::TYPE_BYTES; + format_.Outdent(); + format_.Outdent(); + format_.Outdent(); + format_( + " } // switch\n" + " } // while\n" + " return ptr;\n"); + if (use_length_delimited_) { + format_( + "len_delim_till_end:\n" + " return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg},\n" + " {parser_till_end, object}, size);\n"); + } + if (use_group_) { + // Group crossed end and must be continued. Either this a parse failure + // or we need to resume on the next chunk and thus save the state. + format_( + "group_continues:\n" + " $DCHK$(ptr >= end);\n" + " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ctx->StoreGroup(\n " + " {_InternalParse, msg}, {parser_till_end, object}, depth, tag));\n" + " return ptr;\n"); + } + format_("}\n"); + } + + private: + MessageSCCAnalyzer* scc_analyzer_; + const Options& options_; + Formatter format_; + bool use_length_delimited_ = false; + bool use_group_ = false; + + using WireFormat = internal::WireFormat; + using WireFormatLite = internal::WireFormatLite; + + void GenerateArenaString(const FieldDescriptor* field, const string& utf8) { + format_( + "if (size > end - ptr + " + "::$proto_ns$::internal::ParseContext::kSlopBytes) {\n" + " auto str = msg->mutable_$1$();\n" + " str->clear();\n" + // TODO(gerbens) evaluate security + " str->reserve(size);\n" + " object = str;\n" + " parser_till_end = ::$proto_ns$::internal::GreedyStringParser$2$;\n" + " goto len_delim_till_end;\n" + "}\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(::$proto_ns$::internal::StringCheck$2$" + "(ptr, size, ctx));\n", + FieldName(field), utf8); + if (HasFieldPresence(field->file())) { + format_("HasBitSetters::set_has_$1$(msg);\n", FieldName(field)); + } + format_( + "::$proto_ns$::internal::CopyIntoArenaString(ptr, size, &msg->$1$_, " + "msg->GetArenaNoVirtual());\n" + "ptr += size;\n", + FieldName(field)); + } + + void GenerateStrings(const FieldDescriptor* field, bool check_utf8) { + string utf8; + if (check_utf8) { + utf8 = GetUtf8Suffix(field, options_); + if (!utf8.empty()) { + string name = "nullptr"; + if (HasDescriptorMethods(field->file(), options_)) { + name = "\"" + field->full_name() + "\""; + } + format_("ctx->extra_parse_data().SetFieldName($1$);\n", name); } - if (field_type == FieldDescriptor::TYPE_STRING) { - // In proto1 strings are treated as bytes - field_type = FieldDescriptor::TYPE_BYTES; + } + FieldOptions::CType ctype = FieldOptions::STRING; + if (!options_.opensource_runtime) { + // Open source doesn't support other ctypes; + ctype = field->options().ctype(); + if (IsProto1(field->file(), options_) && + ctype == FieldOptions::STRING_PIECE) { + // proto1 doesn't support STRING_PIECE + ctype = FieldOptions::STRING; } } - switch (field_type) { - case FieldDescriptor::TYPE_STRING: - GenerateStrings(field, options, format, true /* utf8 */); + if (field->file()->options().cc_enable_arenas() && !field->is_repeated() && + !options_.opensource_runtime && + GetOptimizeFor(field->file(), options_) != FileOptions::LITE_RUNTIME && + // For now only use arena string for strings with empty defaults. + field->default_value_string().empty() && + !IsProto1(field->file(), options_) && + !IsStringInlined(field, options_) && + field->containing_oneof() == nullptr && ctype == FieldOptions::STRING) { + GenerateArenaString(field, utf8); + return; + } + format_( + "auto str = msg->$1$_$2$();\n" + "if (size > end - ptr + " + "::$proto_ns$::internal::ParseContext::kSlopBytes) {\n" + " object = str;\n", + field->is_repeated() && !field->is_packable() ? "add" : "mutable", + FieldName(field)); + string name; + switch (ctype) { + case FieldOptions::STRING: + name = "GreedyStringParser"; + format_( + " str->clear();\n" + // TODO(gerbens) evaluate security + " str->reserve(size);\n"); break; - case FieldDescriptor::TYPE_BYTES: - GenerateStrings(field, options, format, false /* utf8 */); + case FieldOptions::CORD: + name = "CordParser"; + format_(" str->Clear();\n"); break; - case FieldDescriptor::TYPE_MESSAGE: { - GOOGLE_CHECK(field->message_type()); - if (!IsProto1(field->file(), options) && field->is_map()) { - const FieldDescriptor* val = - field->message_type()->FindFieldByName("value"); - GOOGLE_CHECK(val); - if (HasFieldPresence(field->file()) && - val->type() == FieldDescriptor::TYPE_ENUM) { - format( - "ctx->extra_parse_data().field_number = $1$;\n" - "ctx->extra_parse_data().unknown_fields = " - "&msg->_internal_metadata_;\n", - field->number()); - } - format( - "parser_till_end = ::$proto_ns$::internal::SlowMapEntryParser;\n" - "auto parse_map = $1$::_ParseMap;\n" - "ctx->extra_parse_data().payload.clear();\n" - "ctx->extra_parse_data().parse_map = parse_map;\n" - "object = &msg->$2$_;\n" - "if (size > end - ptr) goto len_delim_till_end;\n" - "auto newend = ptr + size;\n" - "GOOGLE_PROTOBUF_PARSER_ASSERT(parse_map(ptr, newend, " - "object, ctx));\n" - "ptr = newend;\n", - QualifiedClassName(field->message_type()), FieldName(field)); - break; + case FieldOptions::STRING_PIECE: + name = "StringPieceParser"; + format_(" str->Clear();\n"); + break; + } + format_( + " parser_till_end = ::$proto_ns$::internal::$1$$2$;\n" + " goto len_delim_till_end;\n" + "}\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(::$proto_ns$::internal::StringCheck$2$" + "(" + "ptr, size, ctx));\n" + "::$proto_ns$::internal::Inline$1$(str, ptr, size, ctx);\n" + "ptr += size;\n", + name, utf8); + } + + void GenerateLengthDelim(const FieldDescriptor* field) { + format_( + "ptr = ::$proto_ns$::io::Parse32(ptr, &size);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); + if (!IsProto1(field->file(), options_) && field->is_packable()) { + if (!HasPreservingUnknownEnumSemantics(field->file()) && + field->type() == FieldDescriptor::TYPE_ENUM) { + format_( + "ctx->extra_parse_data().SetEnumValidator($1$_IsValid, " + "msg->mutable_unknown_fields(), $2$);\n" + "parser_till_end = " + "::$proto_ns$::internal::PackedValidEnumParser$3$;\n" + "object = msg->mutable_$4$();\n", + QualifiedClassName(field->enum_type()), field->number(), + UseUnknownFieldSet(field->file(), options_) ? "" : "Lite", + FieldName(field)); + } else { + format_( + "parser_till_end = ::$proto_ns$::internal::Packed$1$Parser;\n" + "object = msg->mutable_$2$();\n", + DeclaredTypeMethodName(field->type()), FieldName(field)); + } + format_( + "if (size > end - ptr) goto len_delim_till_end;\n" + "auto newend = ptr + size;\n" + "if (size) ptr = parser_till_end(ptr, newend, object, ctx);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr == newend);\n"); + } else { + auto field_type = field->type(); + if (IsProto1(field->file(), options_)) { + if (field->is_packable()) { + // Sigh ... packed fields endup as a string in proto1 + field_type = FieldDescriptor::TYPE_BYTES; } - if (!IsProto1(field->file(), options) && IsLazy(field, options)) { - if (field->containing_oneof() != nullptr) { - format( - "if (!msg->has_$1$()) {\n" - " msg->clear_$1$();\n" - " msg->$2$_.$1$_ = ::google::protobuf::Arena::CreateMessage<\n" - " ::google::protobuf::internal::LazyField>(msg->GetArenaNoVirtual());\n" - " msg->set_has_$1$();\n" - "}\n" - "auto parse_closure = msg->$2$_.$1$_->_ParseClosure();\n", - FieldName(field), field->containing_oneof()->name()); - } else if (HasFieldPresence(field->file())) { - format( - "HasBitSetters::set_has_$1$(msg);\n" - "auto parse_closure = msg->$1$_._ParseClosure();\n", - FieldName(field)); + if (field_type == FieldDescriptor::TYPE_STRING) { + // In proto1 strings are treated as bytes + field_type = FieldDescriptor::TYPE_BYTES; + } + } + switch (field_type) { + case FieldDescriptor::TYPE_STRING: + GenerateStrings(field, true /* utf8 */); + break; + case FieldDescriptor::TYPE_BYTES: + GenerateStrings(field, false /* utf8 */); + break; + case FieldDescriptor::TYPE_MESSAGE: { + GOOGLE_CHECK(field->message_type()); + if (!IsProto1(field->file(), options_) && field->is_map()) { + const FieldDescriptor* val = + field->message_type()->FindFieldByName("value"); + GOOGLE_CHECK(val); + if (HasFieldPresence(field->file()) && + val->type() == FieldDescriptor::TYPE_ENUM) { + format_( + "ctx->extra_parse_data().field_number = $1$;\n" + "ctx->extra_parse_data().unknown_fields = " + "&msg->_internal_metadata_;\n", + field->number()); + } + format_( + "parser_till_end = " + "::$proto_ns$::internal::SlowMapEntryParser;\n" + "auto parse_map = $1$::_ParseMap;\n" + "ctx->extra_parse_data().payload.clear();\n" + "ctx->extra_parse_data().parse_map = parse_map;\n" + "object = &msg->$2$_;\n" + "if (size > end - ptr) goto len_delim_till_end;\n" + "auto newend = ptr + size;\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(parse_map(ptr, newend, " + "object, ctx));\n" + "ptr = newend;\n", + QualifiedClassName(field->message_type()), FieldName(field)); + break; + } + if (!IsProto1(field->file(), options_) && IsLazy(field, options_)) { + if (field->containing_oneof() != nullptr) { + format_( + "if (!msg->has_$1$()) {\n" + " msg->clear_$1$();\n" + " msg->$2$_.$1$_ = ::$proto_ns$::Arena::CreateMessage<\n" + " ::$proto_ns$::internal::LazyField>(" + "msg->GetArenaNoVirtual());\n" + " msg->set_has_$1$();\n" + "}\n" + "auto parse_closure = msg->$2$_.$1$_->_ParseClosure();\n", + FieldName(field), field->containing_oneof()->name()); + } else if (HasFieldPresence(field->file())) { + format_( + "HasBitSetters::set_has_$1$(msg);\n" + "auto parse_closure = msg->$1$_._ParseClosure();\n", + FieldName(field)); + } else { + format_("auto parse_closure = msg->$1$_._ParseClosure();\n", + FieldName(field)); + } + format_( + "parser_till_end = parse_closure.func;\n" + "object = parse_closure.object;\n" + "if (size > end - ptr) goto len_delim_till_end;\n" + "auto newend = ptr + size;\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ctx->ParseExactRange(\n" + " parse_closure, ptr, newend));\n" + "ptr = newend;\n"); + break; + } + if (IsImplicitWeakField(field, options_, scc_analyzer_)) { + if (!field->is_repeated()) { + format_("object = HasBitSetters::mutable_$1$(msg);\n", + FieldName(field)); + } else { + format_( + "object = " + "CastToBase(&msg->$1$_)->AddWeak(reinterpret_cast(&$2$::_$3$_default_instance_));" + "\n", + FieldName(field), Namespace(field->message_type()), + ClassName(field->message_type())); + } + format_( + "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" + "object)->_ParseFunc();\n"); + } else if (IsWeak(field, options_)) { + if (IsProto1(field->file(), options_)) { + format_("object = msg->internal_mutable_$1$();\n", + FieldName(field)); + } else { + format_( + "object = msg->_weak_field_map_.MutableMessage($1$, " + "_$classname$_default_instance_.$2$_);\n", + field->number(), FieldName(field)); + } + format_( + "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" + "object)->_ParseFunc();\n"); } else { - format( - "auto parse_closure = msg->$1$_._ParseClosure();\n", - FieldName(field)); + format_( + "parser_till_end = $1$::_InternalParse;\n" + "object = msg->$2$_$3$();\n", + QualifiedClassName(field->message_type()), + field->is_repeated() ? "add" : "mutable", FieldName(field)); } - format( - "parser_till_end = parse_closure.func;\n" - "object = parse_closure.object;\n" + format_( "if (size > end - ptr) goto len_delim_till_end;\n" "auto newend = ptr + size;\n" - "GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange(parse_closure, ptr, newend));\n" + "bool ok = ctx->ParseExactRange({parser_till_end, object},\n" + " ptr, newend);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ok);\n" "ptr = newend;\n"); break; } - if (IsImplicitWeakField(field, options, scc_analyzer)) { - if (!field->is_repeated()) { - format("object = HasBitSetters::mutable_$1$(msg);\n", - FieldName(field)); - } else { - format( - "object = " - "CastToBase(&msg->$1$_)->AddWeak(reinterpret_cast(&$2$::_$3$_default_instance_));\n", - FieldName(field), Namespace(field->message_type()), - ClassName(field->message_type())); - } - format( - "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" - "object)->_ParseFunc();\n"); - } else if (IsWeak(field, options)) { - if (IsProto1(field->file(), options)) { - format("object = msg->internal_mutable_$1$();\n", - FieldName(field)); - } else { - format( - "object = msg->_weak_field_map_.MutableMessage($1$, " - "_$classname$_default_instance_.$2$_);\n", - field->number(), FieldName(field)); + default: + GOOGLE_LOG(FATAL) << "Illegal combination for length delimited wiretype " + << " filed type is " << field->type(); + } + } + } + + void GenerateCaseBody(internal::WireFormatLite::WireType wiretype, + const FieldDescriptor* field) { + if (ShouldRepeat(field, wiretype)) { + format_("do {\n"); + format_.Indent(); + } + switch (wiretype) { + case WireFormatLite::WIRETYPE_VARINT: { + format_( + "$uint64$ val;\n" + "ptr = ::$proto_ns$::io::Parse64(ptr, &val);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); + string type = PrimitiveTypeName(options_, field->cpp_type()); + if ((field->type() == FieldDescriptor::TYPE_SINT32 || + field->type() == FieldDescriptor::TYPE_SINT64) && + !IsProto1(field->file(), options_)) { + int size = field->type() == FieldDescriptor::TYPE_SINT32 ? 32 : 64; + format_( + "$1$ value = " + "::$proto_ns$::internal::WireFormatLite::ZigZagDecode$2$(val);\n", + type, size); + } else if (field->type() == FieldDescriptor::TYPE_ENUM && + !IsProto1(field->file(), options_)) { + if (!HasPreservingUnknownEnumSemantics(field->file())) { + format_( + "if (!$1$_IsValid(val)) {\n" + " ::$proto_ns$::internal::WriteVarint($2$, val, " + "msg->mutable_unknown_fields());\n" + " break;\n" + "}\n", + QualifiedClassName(field->enum_type()), field->number()); } - format( - "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" - "object)->_ParseFunc();\n"); + format_("$1$ value = static_cast<$1$>(val);\n", + QualifiedClassName(field->enum_type())); } else { - format( - "parser_till_end = $1$::_InternalParse;\n" - "object = msg->$2$_$3$();\n", - QualifiedClassName(field->message_type()), - field->is_repeated() ? "add" : "mutable", FieldName(field)); + format_("$1$ value = val;\n", type); + } + if (field->is_repeated()) { + format_("msg->add_$1$(value);\n", FieldName(field)); + } else { + format_("msg->set_$1$(value);\n", FieldName(field)); } - format( - "if (size > end - ptr) goto len_delim_till_end;\n" - "auto newend = ptr + size;\n" - "bool ok = ctx->ParseExactRange({parser_till_end, object},\n" - " ptr, newend);\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ok);\n" - "ptr = newend;\n"); break; } - default: - GOOGLE_LOG(FATAL) << "Illegal combination for length delimited wiretype " - << " filed type is " << field->type(); - } - } -} - -void GenerateCaseBody(internal::WireFormatLite::WireType wiretype, - const FieldDescriptor* field, const Options& options, - MessageSCCAnalyzer* scc_analyzer, - const Formatter& format) { - using internal::WireFormat; - using internal::WireFormatLite; - - if (ShouldRepeat(field, wiretype)) { - format("do {\n"); - format.Indent(); - } - switch (wiretype) { - case WireFormatLite::WIRETYPE_VARINT: { - format( - "$uint64$ val;\n" - "ptr = Varint::Parse64(ptr, &val);\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); - string type = PrimitiveTypeName(options, field->cpp_type()); - if ((field->type() == FieldDescriptor::TYPE_SINT32 || - field->type() == FieldDescriptor::TYPE_SINT64) && - !IsProto1(field->file(), options)) { - int size = EstimateAlignmentSize(field) * 8; - format( - "$1$ value = " - "::$proto_ns$::internal::WireFormatLite::ZigZagDecode$2$(val);\n", - type, size); - } else if (field->type() == FieldDescriptor::TYPE_ENUM && - !IsProto1(field->file(), options)) { - if (!HasPreservingUnknownEnumSemantics(field->file())) { - format( - "if (!$1$_IsValid(val)) {\n" - " ::$proto_ns$::internal::WriteVarint($2$, val, " - "msg->mutable_unknown_fields());\n" - " break;\n" - "}\n", - QualifiedClassName(field->enum_type()), field->number()); + case WireFormatLite::WIRETYPE_FIXED64: { + string type = PrimitiveTypeName(options_, field->cpp_type()); + format_( + "$1$ val;\n" + "::std::memcpy(&val, ptr, 8);\n" + "ptr += 8;\n", + type); + if (field->is_repeated()) { + format_("msg->add_$1$(val);\n", FieldName(field)); + } else { + format_("msg->set_$1$(val);\n", FieldName(field)); } - format("$1$ value = static_cast<$1$>(val);\n", - QualifiedClassName(field->enum_type())); - } else { - format("$1$ value = val;\n", type); + break; } - if (field->is_repeated()) { - format("msg->add_$1$(value);\n", FieldName(field)); - } else { - format("msg->set_$1$(value);\n", FieldName(field)); + case WireFormatLite::WIRETYPE_LENGTH_DELIMITED: { + use_length_delimited_ = true; + GenerateLengthDelim(field); + break; } - break; - } - case WireFormatLite::WIRETYPE_FIXED64: { - string type = PrimitiveTypeName(options, field->cpp_type()); - format( - "$1$ val;\n" - "::std::memcpy(&val, ptr, 8);\n" - "ptr += 8;\n", - type); - if (field->is_repeated()) { - format("msg->add_$1$(val);\n", FieldName(field)); - } else { - format("msg->set_$1$(val);\n", FieldName(field)); + case WireFormatLite::WIRETYPE_START_GROUP: { + use_group_ = true; + format_( + "parser_till_end = $1$::_InternalParse;\n" + "object = msg->$2$_$3$();\n" + "auto res = ctx->ParseGroup(tag, {parser_till_end, object}, ptr, " + "end, " + "&depth);\n" + "ptr = res.first;\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n" + "if (res.second) goto group_continues;\n", + QualifiedClassName(field->message_type()), + field->is_repeated() ? "add" : "mutable", FieldName(field)); + break; } - break; - } - case WireFormatLite::WIRETYPE_LENGTH_DELIMITED: { - GenerateLengthDelim(field, options, scc_analyzer, format); - break; - } - case WireFormatLite::WIRETYPE_START_GROUP: { - format( - "parser_till_end = $1$::_InternalParse;\n" - "object = msg->$2$_$3$();\n" - "auto res = ctx->ParseGroup(tag, {parser_till_end, object}, ptr, " - "end, " - "&depth);\n" - "ptr = res.first;\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n" - "if (res.second) goto group_continues;\n", - QualifiedClassName(field->message_type()), - field->is_repeated() ? "add" : "mutable", FieldName(field)); - break; - } - case WireFormatLite::WIRETYPE_END_GROUP: { - GOOGLE_LOG(FATAL) << "Can't have end group field\n"; - break; - } - case WireFormatLite::WIRETYPE_FIXED32: { - string type = PrimitiveTypeName(options, field->cpp_type()); - format( - "$1$ val;\n" - "std::memcpy(&val, ptr, 4);\n" - "ptr += 4;\n", - type); - if (field->is_repeated()) { - format("msg->add_$1$(val);\n", FieldName(field)); - } else { - format("msg->set_$1$(val);\n", FieldName(field)); + case WireFormatLite::WIRETYPE_END_GROUP: { + GOOGLE_LOG(FATAL) << "Can't have end group field\n"; + break; } - break; - } - } // switch (wire_type) - - if (ShouldRepeat(field, wiretype)) { - format("if (ptr >= end) break;\n"); - uint32 x = field->number() * 8 + wiretype; - uint64 y = 0; - int cnt = 0; - do { - y += static_cast((x & 0x7F) + (x >= 128 ? 128 : 0)) - << (cnt++ * 8); - x >>= 7; - } while (x); - uint64 mask = (1ull << (cnt * 8)) - 1; - format.Outdent(); - format( - "} while ((::$proto_ns$::io::UnalignedLoad<$uint64$>(ptr) & $1$) == " - "$2$ && (ptr += $3$));\n", - mask, y, cnt); - } - format("break;\n"); -} - -void GenerateCaseBody(const FieldDescriptor* field, const Options& options, - MessageSCCAnalyzer* scc_analyzer, - const Formatter& format) { - using internal::WireFormat; - using internal::WireFormatLite; - - if (!IsProto1(field->file(), options) && field->is_packable()) { - auto expected_wiretype = WireFormat::WireTypeForFieldType(field->type()); - GOOGLE_CHECK(expected_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED); - uint32 expected_tag = - WireFormatLite::MakeTag(field->number(), expected_wiretype); - auto fallback_wiretype = WireFormatLite::WIRETYPE_LENGTH_DELIMITED; - uint32 fallback_tag = - WireFormatLite::MakeTag(field->number(), fallback_wiretype); - - if (field->is_packed()) { - std::swap(expected_tag, fallback_tag); - std::swap(expected_wiretype, fallback_wiretype); + case WireFormatLite::WIRETYPE_FIXED32: { + string type = PrimitiveTypeName(options_, field->cpp_type()); + format_( + "$1$ val;\n" + "std::memcpy(&val, ptr, 4);\n" + "ptr += 4;\n", + type); + if (field->is_repeated()) { + format_("msg->add_$1$(val);\n", FieldName(field)); + } else { + format_("msg->set_$1$(val);\n", FieldName(field)); + } + break; + } + } // switch (wire_type) + + if (ShouldRepeat(field, wiretype)) { + format_("if (ptr >= end) break;\n"); + uint32 x = field->number() * 8 + wiretype; + uint64 y = 0; + int cnt = 0; + do { + y += static_cast((x & 0x7F) + (x >= 128 ? 128 : 0)) + << (cnt++ * 8); + x >>= 7; + } while (x); + uint64 mask = (1ull << (cnt * 8)) - 1; + format_.Outdent(); + format_( + "} while ((::$proto_ns$::io::UnalignedLoad<$uint64$>(ptr) & $1$) == " + "$2$ && (ptr += $3$));\n", + mask, y, cnt); } + format_("break;\n"); + } + + void GenerateCaseBody(const FieldDescriptor* field) { + if (!IsProto1(field->file(), options_) && field->is_packable()) { + auto expected_wiretype = WireFormat::WireTypeForFieldType(field->type()); + GOOGLE_CHECK(expected_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED); + uint32 expected_tag = + WireFormatLite::MakeTag(field->number(), expected_wiretype); + auto fallback_wiretype = WireFormatLite::WIRETYPE_LENGTH_DELIMITED; + uint32 fallback_tag = + WireFormatLite::MakeTag(field->number(), fallback_wiretype); + + if (field->is_packed()) { + std::swap(expected_tag, fallback_tag); + std::swap(expected_wiretype, fallback_wiretype); + } - format("if (static_cast<$uint8$>(tag) == $1$) {\n", expected_tag & 0xFF); - format.Indent(); - GenerateCaseBody(expected_wiretype, field, options, scc_analyzer, format); - format.Outdent(); - format( - "} else if (static_cast<$uint8$>(tag) != $1$) goto handle_unusual;\n", - fallback_tag & 0xFF); - GenerateCaseBody(fallback_wiretype, field, options, scc_analyzer, format); - } else { - auto wiretype = WireFormat::WireTypeForField(field); - format("if (static_cast<$uint8$>(tag) != $1$) goto handle_unusual;\n", - WireFormat::MakeTag(field) & 0xFF); - GenerateCaseBody(wiretype, field, options, scc_analyzer, format); + format_("if (static_cast<$uint8$>(tag) == $1$) {\n", expected_tag & 0xFF); + format_.Indent(); + GenerateCaseBody(expected_wiretype, field); + format_.Outdent(); + format_( + "} else if (static_cast<$uint8$>(tag) != $1$) goto handle_unusual;\n", + fallback_tag & 0xFF); + GenerateCaseBody(fallback_wiretype, field); + } else { + auto wiretype = WireFormat::WireTypeForField(field); + format_("if (static_cast<$uint8$>(tag) != $1$) goto handle_unusual;\n", + WireFormat::MakeTag(field) & 0xFF); + GenerateCaseBody(wiretype, field); + } } -} +}; void GenerateParserLoop(const Descriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer, io::Printer* printer) { - using internal::WireFormat; - using internal::WireFormatLite; - - Formatter format(printer); - format.Set("classname", ClassName(descriptor)); - format.Set("proto_ns", ProtobufNamespace(options)); - std::map vars; - SetCommonVars(options, &vars); - format.AddMap(vars); - - std::vector ordered_fields; - for (auto field : FieldRange(descriptor)) { - ordered_fields.push_back(field); - } - std::sort(ordered_fields.begin(), ordered_fields.end(), - [](const FieldDescriptor* a, const FieldDescriptor* b) { - return a->number() < b->number(); - }); - - format( - "const char* $classname$::_InternalParse(const char* begin, const char* " - "end, void* object,\n" - " ::$proto_ns$::internal::ParseContext* ctx) {\n" - " auto msg = static_cast<$classname$*>(object);\n" - " $uint32$ size; (void)size;\n" - " int depth; (void)depth;\n" - " $uint32$ tag;\n" - " ::$proto_ns$::internal::ParseFunc parser_till_end; " - "(void)parser_till_end;\n" - " auto ptr = begin;\n" - " while (ptr < end) {\n" - " ptr = Varint::Parse32Inline(ptr, &tag);\n" - " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n" - " switch (tag >> 3) {\n"); - - format.Indent(); - format.Indent(); - format.Indent(); - - for (const auto* field : ordered_fields) { - if (IsProto1(descriptor->file(), options)) { - if (field->number() >= (1 << 14)) continue; - } - // Print the field's (or oneof's) proto-syntax definition as a comment. - // We don't want to print group bodies so we cut off after the first - // line. - string def; - { - DebugStringOptions options; - options.elide_group_body = true; - options.elide_oneof_body = true; - def = field->DebugStringWithOptions(options); - def = def.substr(0, def.find_first_of('\n')); - } - format( - "// $1$\n" - "case $2$: {\n", - def, field->number()); - format.Indent(); - GenerateCaseBody(field, options, scc_analyzer, format); - format.Outdent(); - format("}\n"); // case - } // for fields - format( - "default: {\n" - "handle_unusual: (void)&&handle_unusual;\n" - " if ((tag & 7) == 4 || tag == 0) {\n" - " ctx->EndGroup(tag);\n" - " return ptr;\n" - " }\n"); - if (IsMapEntryMessage(descriptor)) { - format( - " break;\n" - "}\n"); - } else { - if (descriptor->extension_range_count() > 0) { - format("if ("); - for (int i = 0; i < descriptor->extension_range_count(); i++) { - const Descriptor::ExtensionRange* range = - descriptor->extension_range(i); - if (i > 0) format(" ||\n "); - - uint32 start_tag = WireFormatLite::MakeTag( - range->start, static_cast(0)); - uint32 end_tag = WireFormatLite::MakeTag( - range->end, static_cast(0)); - - if (range->end > FieldDescriptor::kMaxNumber) { - format("($1$u <= tag)", start_tag); - } else { - format("($1$u <= tag && tag < $2$u)", start_tag, end_tag); - } - } - format(") {\n"); - format( - " auto res = msg->_extensions_.ParseField(tag, {_InternalParse, " - "msg}, ptr, end,\n" - " internal_default_instance(), &msg->_internal_metadata_, " - "ctx);\n" - " ptr = res.first;\n" - " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr != nullptr);\n" - " if (res.second) return ptr;\n" - " continue;\n" - "}\n"); - } - format( - " auto res = UnknownFieldParse(tag, {_InternalParse, msg},\n" - " ptr, end, msg->_internal_metadata_.mutable_unknown_fields(), " - "ctx);\n" - " ptr = res.first;\n" - " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr != nullptr);\n" - " if (res.second) return ptr;\n" - "}\n"); // default case - } - format.Outdent(); - format.Outdent(); - format.Outdent(); - format( - " } // switch\n" - " } // while\n" - " return ptr;\n" - "len_delim_till_end: (void)&&len_delim_till_end;\n" - " return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg},\n" - " {parser_till_end, object}, size);\n" - "group_continues: (void)&&group_continues;\n" - " $DCHK$(ptr >= end);\n" - // Group crossed end and must be continued. Either this a parse failure - // or we need to resume on the next chunk and thus save the state. - " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}," - " {parser_till_end, object}, depth, tag));\n" - " return ptr;\n" - "}\n"); + ParseLoopGenerator generator(options, scc_analyzer, printer); + generator.GenerateParserLoop(descriptor); } } // namespace cpp diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index 07010179f3..a055702c00 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -271,6 +271,8 @@ inline bool IsWeak(const FieldDescriptor* field, const Options& options) { return false; } +bool IsStringInlined(const FieldDescriptor* descriptor, const Options& options); + // For a string field, returns the effective ctype. If the actual ctype is // not supported, returns the default of STRING. FieldOptions::CType EffectiveStringCType(const FieldDescriptor* field, diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc index c9816731f3..b44677f5e6 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -262,8 +262,7 @@ static void GenerateSerializationLoop(const Formatter& format, if (to_array) { format( "target = ::$proto_ns$::internal::WireFormatLite::InternalWrite" - "$declared_type$NoVirtualToArray($number$, *entry, deterministic, " - "target);\n"); + "$declared_type$NoVirtualToArray($number$, *entry, target);\n"); } else { format( "::$proto_ns$::internal::WireFormatLite::Write$stream_writer$($number$," @@ -365,7 +364,7 @@ void MapFieldGenerator::GenerateSerializeWithCachedSizes(io::Printer* printer, " items[static_cast(n)] = SortItem(&*it);\n" " }\n" " ::std::sort(&items[0], &items[static_cast(n)], Less());\n", - to_array ? "deterministic" : "output->IsSerializationDeterministic()"); + to_array ? "false" : "output->IsSerializationDeterministic()"); format.Indent(); GenerateSerializationLoop(format, SupportsArenas(descriptor_), string_key, string_value, to_array, true); diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 96354dd45b..a729282080 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -800,7 +800,8 @@ void MessageGenerator::GenerateSingularFieldHasBits( } else { format( "inline bool $classname$::has_$name$() const {\n" - " return this != internal_default_instance() && $name$_ != nullptr;\n" + " return this != internal_default_instance() " + "&& $name$_ != nullptr;\n" "}\n"); } } @@ -941,7 +942,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { "public:\n" "#if $GOOGLE_PROTOBUF$_ENABLE_EXPERIMENTAL_PARSER\n" "static bool _ParseMap(const char* begin, const " - "char* end, void* object, ::google::protobuf::internal::ParseContext* ctx);\n" + "char* end, void* object, ::$proto_ns$::internal::ParseContext* ctx);\n" "#endif // $GOOGLE_PROTOBUF$_ENABLE_EXPERIMENTAL_PARSER\n" " typedef ::$proto_ns$::internal::MapEntry$lite$<$classname$, \n" " $key_cpp$, $val_cpp$,\n" @@ -1190,7 +1191,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { if (HasFastArraySerialization(descriptor_->file(), options_)) { format( "$uint8$* InternalSerializeWithCachedSizesToArray(\n" - " bool deterministic, $uint8$* target) const final;\n"); + " $uint8$* target) const final;\n"); } } @@ -1654,8 +1655,10 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { return 2; } format( - "{PROTOBUF_FIELD_OFFSET($classtype$, _cached_size_), 0, 0, 0, nullptr},\n"); + "{PROTOBUF_FIELD_OFFSET($classtype$, _cached_size_)," + " 0, 0, 0, nullptr},\n"); std::vector sorted_extensions; + sorted_extensions.reserve(descriptor_->extension_range_count()); for (int i = 0; i < descriptor_->extension_range_count(); ++i) { sorted_extensions.push_back(descriptor_->extension_range(i)); } @@ -1864,8 +1867,8 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { } format( "#if $GOOGLE_PROTOBUF$_ENABLE_EXPERIMENTAL_PARSER\n" - "bool $classname$::_ParseMap(const char* begin, const " - "char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) {\n" + "bool $classname$::_ParseMap(const char* begin, const char* end, " + "void* object, ::$proto_ns$::internal::ParseContext* ctx) {\n" " using MF = ::$proto_ns$::internal::MapField$1$<\n" " $classname$, EntryKeyType, EntryValueType,\n" " kEntryKeyFieldType, kEntryValueFieldType,\n" @@ -1885,7 +1888,8 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { format( " DO_(parser.ParseMapEnumValidation(\n" " begin, end, ctx->extra_parse_data().field_number,\n" - " static_cast<::google::protobuf::internal::InternalMetadataWithArena$1$*>(" + " static_cast<::$proto_ns$::internal::" + "InternalMetadataWithArena$1$*>(" "ctx->extra_parse_data().unknown_fields), $2$_IsValid));\n", HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite", QualifiedClassName(val->enum_type())); @@ -3769,7 +3773,7 @@ void MessageGenerator::GenerateSerializeOneExtensionRange( if (to_array) { format( "target = _extensions_.InternalSerializeWithCachedSizesToArray(\n" - " $start$, $end$, deterministic, target);\n\n"); + " $start$, $end$, target);\n\n"); } else { format( "_extensions_.SerializeWithCachedSizes($start$, $end$, output);\n" @@ -3819,10 +3823,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesToArray( // Special-case MessageSet. format( "$uint8$* $classname$::InternalSerializeWithCachedSizesToArray(\n" - " bool deterministic, $uint8$* target) const {\n" + " $uint8$* target) const {\n" " target = _extensions_." - "InternalSerializeMessageSetWithCachedSizesToArray(\n" - " deterministic, target);\n"); + "InternalSerializeMessageSetWithCachedSizesToArray(target);\n"); GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_)); std::map vars; SetUnknkownFieldsVariable(descriptor_, options_, &vars); @@ -3839,10 +3842,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesToArray( format( "$uint8$* $classname$::InternalSerializeWithCachedSizesToArray(\n" - " bool deterministic, $uint8$* target) const {\n"); + " $uint8$* target) const {\n"); format.Indent(); - format("(void)deterministic; // Unused\n"); format("// @@protoc_insertion_point(serialize_to_array_start:$full_name$)\n"); GenerateSerializeWithCachedSizesBody(printer, true); @@ -3937,6 +3939,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( SortFieldsByNumber(descriptor_); std::vector sorted_extensions; + sorted_extensions.reserve(descriptor_->extension_range_count()); for (int i = 0; i < descriptor_->extension_range_count(); ++i) { sorted_extensions.push_back(descriptor_->extension_range(i)); } diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc index 1df2508e76..a29372da21 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc @@ -477,7 +477,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { format( "target = ::$proto_ns$::internal::WireFormatLite::\n" " InternalWrite$declared_type$ToArray(\n" - " $number$, HasBitSetters::$name$(this), deterministic, target);\n"); + " $number$, HasBitSetters::$name$(this), target);\n"); } void MessageFieldGenerator:: @@ -812,8 +812,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { " n = static_cast(this->$name$_size()); i < n; i++) {\n" " target = ::$proto_ns$::internal::WireFormatLite::\n" " InternalWrite$declared_type$ToArray(\n" - " $number$, this->$name$(static_cast(i)), deterministic, " - "target);\n" + " $number$, this->$name$(static_cast(i)), target);\n" "}\n"); } diff --git a/src/google/protobuf/compiler/cpp/cpp_options.h b/src/google/protobuf/compiler/cpp/cpp_options.h index 181a562840..4056eccf52 100644 --- a/src/google/protobuf/compiler/cpp/cpp_options.h +++ b/src/google/protobuf/compiler/cpp/cpp_options.h @@ -43,8 +43,8 @@ class AccessInfoMap; namespace cpp { enum class EnforceOptimizeMode { - kNoEnforcement, // Use the runtime specified by the file specific options. - kSpeed, // This is the full runtime. + kNoEnforcement, // Use the runtime specified by the file specific options. + kSpeed, // This is the full runtime. kLiteRuntime, }; diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 2676bb59cb..74a3f34baa 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc @@ -89,21 +89,7 @@ StringFieldGenerator::StringFieldGenerator(const FieldDescriptor* descriptor, const Options& options) : FieldGenerator(descriptor, options), lite_(!HasDescriptorMethods(descriptor->file(), options)), - inlined_(false) { - - // TODO(ckennelly): Handle inlining for any.proto. - if (IsAnyMessage(descriptor_->containing_type(), options_)) { - inlined_ = false; - } - if (descriptor_->containing_type()->options().map_entry()) { - inlined_ = false; - } - - // Limit to proto2, as we rely on has bits to distinguish field presence for - // release_$name$. On proto3, we cannot use the address of the string - // instance when the field has been inlined. - inlined_ = inlined_ && HasFieldPresence(descriptor_->file()); - + inlined_(IsStringInlined(descriptor, options)) { SetStringVariables(descriptor, &variables_, options); } diff --git a/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto b/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto index 7fe9875978..0f15f39ac7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto +++ b/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto @@ -147,6 +147,7 @@ enum ConflictingEnum { // NO_PROTO3 NOT_EQ = 1; // NO_PROTO3 volatile = 2; // NO_PROTO3 return = 3; // NO_PROTO3 + NULL = 4; // NO_PROTO3 } // NO_PROTO3 message DummyMessage {} diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc index 2cf030eb2c..a17ed8bd70 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc @@ -107,12 +107,13 @@ TEST(GENERATED_MESSAGE_TEST_NAME, TestConflictingEnumNames) { message.set_conflicting_enum(protobuf_unittest::TestConflictingEnumNames_NestedConflictingEnum_XOR); EXPECT_EQ(5, message.conflicting_enum()); - protobuf_unittest::ConflictingEnum conflicting_enum; conflicting_enum = protobuf_unittest::NOT_EQ; EXPECT_EQ(1, conflicting_enum); conflicting_enum = protobuf_unittest::return_; EXPECT_EQ(3, conflicting_enum); + conflicting_enum = protobuf_unittest::NULL_; + EXPECT_EQ(4, conflicting_enum); } } // namespace cpp_unittest diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.inc b/src/google/protobuf/compiler/cpp/cpp_unittest.inc index 0323e4efe6..e6aded7b12 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.inc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.inc @@ -2154,6 +2154,7 @@ TEST(HELPERS_TEST_NAME, TestSCC) { MessageSCCAnalyzer scc_analyzer((Options())); const SCC* scc = scc_analyzer.GetSCC(a.GetDescriptor()); std::vector names; + names.reserve(scc->descriptors.size()); for (int i = 0; i < scc->descriptors.size(); i++) { names.push_back(scc->descriptors[i]->full_name()); } diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 7e547af780..db19ff58dd 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2430,6 +2430,9 @@ void Generator::GenerateClassFromObject(const GeneratorOptions& options, " * @param {!Object} obj The object representation of this proto to\n" " * load the data from.\n" " * @return {!$classname$}\n" + " * @suppress {missingProperties} To prevent JSCompiler errors at " + "the\n" + " * `goog.isDef(obj.)` lookups.\n" " */\n" "$classname$.fromObject = function(obj) {\n" " var msg = new $classname$();\n", @@ -2437,7 +2440,9 @@ void Generator::GenerateClassFromObject(const GeneratorOptions& options, for (int i = 0; i < desc->field_count(); i++) { const FieldDescriptor* field = desc->field(i); - GenerateClassFieldFromObject(options, printer, field); + if (!IgnoreField(field)) { + GenerateClassFieldFromObject(options, printer, field); + } } printer->Print( @@ -2479,9 +2484,8 @@ void Generator::GenerateClassFieldFromObject( printer->Print( " goog.isDef(obj.$name$) && " "jspb.Message.setRepeatedWrapperField(\n" - " msg, $index$, goog.array.map(obj.$name$, function(i) {\n" - " return $fieldclass$.fromObject(i);\n" - " }));\n", + " msg, $index$, obj.$name$.map(\n" + " $fieldclass$.fromObject));\n", "name", JSObjectFieldName(options, field), "index", JSFieldIndex(field), "fieldclass", SubmessageTypeRef(options, field)); diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index c533c6aa04..1a3171a802 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -1564,15 +1564,18 @@ bool Parser::ParseExtensions(DescriptorProto* message, // name literals. bool Parser::ParseReserved(DescriptorProto* message, const LocationRecorder& message_location) { + io::Tokenizer::Token start_token = input_->current(); // Parse the declaration. DO(Consume("reserved")); if (LookingAtType(io::Tokenizer::TYPE_STRING)) { LocationRecorder location(message_location, DescriptorProto::kReservedNameFieldNumber); + location.StartAt(start_token); return ParseReservedNames(message, location); } else { LocationRecorder location(message_location, DescriptorProto::kReservedRangeFieldNumber); + location.StartAt(start_token); return ParseReservedNumbers(message, location); } } @@ -1638,16 +1641,19 @@ bool Parser::ParseReservedNumbers(DescriptorProto* message, } bool Parser::ParseReserved(EnumDescriptorProto* message, - const LocationRecorder& message_location) { + const LocationRecorder& message_location) { + io::Tokenizer::Token start_token = input_->current(); // Parse the declaration. DO(Consume("reserved")); if (LookingAtType(io::Tokenizer::TYPE_STRING)) { LocationRecorder location(message_location, DescriptorProto::kReservedNameFieldNumber); + location.StartAt(start_token); return ParseReservedNames(message, location); } else { LocationRecorder location(message_location, DescriptorProto::kReservedRangeFieldNumber); + location.StartAt(start_token); return ParseReservedNumbers(message, location); } } diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index e63739b0b1..4c67c78ab9 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -2739,6 +2739,33 @@ TEST_F(SourceInfoTest, ExtensionRanges) { EXPECT_TRUE(HasSpan(file_.message_type(0), "name")); } +TEST_F(SourceInfoTest, ReservedRanges) { + EXPECT_TRUE( + Parse("message Message {\n" + " $a$reserved $b$1$c$ to $d$4$e$, $f$6$g$;$h$\n" + "}\n")); + + const DescriptorProto::ReservedRange& range1 = + file_.message_type(0).reserved_range(0); + const DescriptorProto::ReservedRange& range2 = + file_.message_type(0).reserved_range(1); + + EXPECT_TRUE(HasSpan('a', 'h', file_.message_type(0), "reserved_range")); + + EXPECT_TRUE(HasSpan('b', 'e', range1)); + EXPECT_TRUE(HasSpan('b', 'c', range1, "start")); + EXPECT_TRUE(HasSpan('d', 'e', range1, "end")); + + EXPECT_TRUE(HasSpan('f', 'g', range2)); + EXPECT_TRUE(HasSpan('f', 'g', range2, "start")); + EXPECT_TRUE(HasSpan('f', 'g', range2, "end")); + + // Ignore these. + EXPECT_TRUE(HasSpan(file_)); + EXPECT_TRUE(HasSpan(file_.message_type(0))); + EXPECT_TRUE(HasSpan(file_.message_type(0), "name")); +} + TEST_F(SourceInfoTest, Oneofs) { EXPECT_TRUE(Parse( "message Foo {\n" diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 89291a1e8b..9b34152949 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -320,14 +320,14 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional int32 major = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_major(value); @@ -337,7 +337,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_minor(value); @@ -347,7 +347,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_patch(value); @@ -356,7 +356,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob // optional string suffix = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.Version.suffix"); auto str = msg->mutable_suffix(); @@ -373,7 +373,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -387,13 +387,9 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Version::MergePartialFromCodedStream( @@ -521,8 +517,7 @@ void Version::SerializeWithCachedSizes( } ::google::protobuf::uint8* Version::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.Version) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -804,14 +799,14 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated string file_to_generate = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.file_to_generate"); auto str = msg->add_file_to_generate(); @@ -832,7 +827,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* // optional string parameter = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.parameter"); auto str = msg->mutable_parameter(); @@ -851,7 +846,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* // optional .google.protobuf.compiler.Version compiler_version = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::compiler::Version::_InternalParse; object = msg->mutable_compiler_version(); @@ -867,7 +862,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* case 15: { if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FileDescriptorProto::_InternalParse; object = msg->add_proto_file(); @@ -882,7 +877,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -896,13 +891,9 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool CodeGeneratorRequest::MergePartialFromCodedStream( @@ -1039,8 +1030,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( } ::google::protobuf::uint8* CodeGeneratorRequest::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorRequest) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1071,7 +1061,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, HasBitSetters::compiler_version(this), deterministic, target); + 3, HasBitSetters::compiler_version(this), target); } // repeated .google.protobuf.FileDescriptorProto proto_file = 15; @@ -1079,7 +1069,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( n = static_cast(this->proto_file_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 15, this->proto_file(static_cast(i)), deterministic, target); + 15, this->proto_file(static_cast(i)), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -1328,13 +1318,13 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.name"); auto str = msg->mutable_name(); @@ -1353,7 +1343,7 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const // optional string insertion_point = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point"); auto str = msg->mutable_insertion_point(); @@ -1372,7 +1362,7 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const // optional string content = 15; case 15: { if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.content"); auto str = msg->mutable_content(); @@ -1389,7 +1379,7 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1403,13 +1393,9 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool CodeGeneratorResponse_File::MergePartialFromCodedStream( @@ -1533,8 +1519,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( } ::google::protobuf::uint8* CodeGeneratorResponse_File::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse.File) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1785,13 +1770,13 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string error = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.error"); auto str = msg->mutable_error(); @@ -1811,7 +1796,7 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* case 15: { if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::compiler::CodeGeneratorResponse_File::_InternalParse; object = msg->add_file(); @@ -1826,7 +1811,7 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1840,13 +1825,9 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool CodeGeneratorResponse::MergePartialFromCodedStream( @@ -1940,8 +1921,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( } ::google::protobuf::uint8* CodeGeneratorResponse::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1963,7 +1943,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( n = static_cast(this->file_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 15, this->file(static_cast(i)), deterministic, target); + 15, this->file(static_cast(i)), target); } if (_internal_metadata_.have_unknown_fields()) { diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index b33bc60646..a8e4479fb4 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -161,7 +161,7 @@ class PROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_ins void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -313,7 +313,7 @@ class PROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -487,7 +487,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Mess void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -647,7 +647,7 @@ class PROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Message / void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index ba7ecdeaf8..bbe83525e0 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -359,6 +359,22 @@ bool Generator::Generate(const FileDescriptor* file, return !printer.failed(); } +// BEGIN GOOGLE-INTERNAL +// Strip the google3.third_party.py. prefix off of a module name as we +// NEVER want that invalid module import path to be generated in google3. +// Our sys.path has google3/third_party/py/ in it. All modules from +// that tree need to be imported using just their own name. +// See http://go/ThirdPartyPython +void StripThirdPartyPy(string* module_name) { + const string third_party_py_prefix = "google3.third_party.py."; + int len = third_party_py_prefix.length(); + if (module_name->compare(0, len, + third_party_py_prefix, 0, + len) == 0) { + *module_name = module_name->erase(0, len); + } +} +// END GOOGLE-INTERNAL // Prints Python imports for all modules imported by |file|. void Generator::PrintImports() const { @@ -367,6 +383,9 @@ void Generator::PrintImports() const { string module_name = ModuleName(filename); string module_alias = ModuleAlias(filename); + // BEGIN GOOGLE-INTERNAL + StripThirdPartyPy(&module_name); + // END GOOGLE-INTERNAL if (ContainsPythonKeyword(module_name)) { // If the module path contains a Python keyword, we have to quote the // module name and import it using importlib. Otherwise the usual kind of @@ -397,6 +416,9 @@ void Generator::PrintImports() const { // Print public imports. for (int i = 0; i < file_->public_dependency_count(); ++i) { string module_name = ModuleName(file_->public_dependency(i)->name()); + // BEGIN GOOGLE-INTERNAL + StripThirdPartyPy(&module_name); + // END GOOGLE-INTERNAL printer_->Print("from $module$ import *\n", "module", module_name); } printer_->Print("\n"); diff --git a/src/google/protobuf/compiler/zip_writer.h b/src/google/protobuf/compiler/zip_writer.h index 9f56d68b66..a99bb78ce7 100644 --- a/src/google/protobuf/compiler/zip_writer.h +++ b/src/google/protobuf/compiler/zip_writer.h @@ -60,9 +60,6 @@ // Author: kenton@google.com (Kenton Varda) -#ifndef GOOGLE_PROTOBUF_COMPILER_ZIP_WRITER_H__ -#define GOOGLE_PROTOBUF_COMPILER_ZIP_WRITER_H__ - #include #include #include @@ -94,5 +91,3 @@ class ZipWriter { } // namespace compiler } // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_ZIP_WRITER_H__ diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 5b7bd9069a..caed8a94bd 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -5073,10 +5073,12 @@ void DescriptorBuilder::CheckEnumValueUniqueness( if (!inserted && insert_result.first->second->name() != value->name() && insert_result.first->second->number() != value->number()) { string error_message = - "When enum name is stripped and label is PascalCased (" + stripped + - "), this value label conflicts with " + values[stripped]->name() + - ". This will make the proto fail to compile for some languages, such " - "as C#."; + "Enum name " + value->name() + " has the same name as " + + values[stripped]->name() + + " if you ignore case and strip out the enum name prefix (if any). " + "This is error-prone and can lead to undefined behavior. " + "Please avoid doing this. If you are using allow_alias, please " + "assign the same numeric value to both enums."; // There are proto2 enums out there with conflicting names, so to preserve // compatibility we issue only a warning for proto2. if (result->file()->syntax() == FileDescriptor::SYNTAX_PROTO2) { diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index cf0a52bb0c..ac4d8b23eb 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -232,6 +232,8 @@ class PROTOBUF_EXPORT LazyDescriptor { // Use DescriptorPool to construct your own descriptors. class PROTOBUF_EXPORT Descriptor { public: + typedef DescriptorProto Proto; + // The name of the message type, not including its scope. const std::string& name() const; @@ -345,6 +347,8 @@ class PROTOBUF_EXPORT Descriptor { // A range of field numbers which are designated for third-party // extensions. struct ExtensionRange { + typedef DescriptorProto_ExtensionRange Proto; + typedef ExtensionRangeOptions OptionsType; // See Descriptor::CopyTo(). @@ -511,6 +515,8 @@ class PROTOBUF_EXPORT Descriptor { // Use DescriptorPool to construct your own descriptors. class PROTOBUF_EXPORT FieldDescriptor { public: + typedef FieldDescriptorProto Proto; + // Identifies a field type. 0 is reserved for errors. The order is weird // for historical reasons. Types 12 and up are new in proto2. enum Type { @@ -821,6 +827,8 @@ class PROTOBUF_EXPORT FieldDescriptor { // Describes a oneof defined in a message type. class PROTOBUF_EXPORT OneofDescriptor { public: + typedef OneofDescriptorProto Proto; + const std::string& name() const; // Name of this oneof. const std::string& full_name() const; // Fully-qualified name of the oneof. @@ -895,6 +903,8 @@ class PROTOBUF_EXPORT OneofDescriptor { // to construct your own descriptors. class PROTOBUF_EXPORT EnumDescriptor { public: + typedef EnumDescriptorProto Proto; + // The name of this enum type in the containing scope. const std::string& name() const; @@ -1051,6 +1061,8 @@ class PROTOBUF_EXPORT EnumDescriptor { // your own descriptors. class PROTOBUF_EXPORT EnumValueDescriptor { public: + typedef EnumValueDescriptorProto Proto; + const std::string& name() const; // Name of this enum constant. int index() const; // Index within the enums's Descriptor. int number() const; // Numeric value of this enum constant. @@ -1129,6 +1141,8 @@ class PROTOBUF_EXPORT EnumValueDescriptor { // ServiceDescriptor. Use DescriptorPool to construct your own descriptors. class PROTOBUF_EXPORT ServiceDescriptor { public: + typedef ServiceDescriptorProto Proto; + // The name of the service, not including its containing scope. const std::string& name() const; // The fully-qualified name of the service, scope delimited by periods. @@ -1209,6 +1223,8 @@ class PROTOBUF_EXPORT ServiceDescriptor { // own descriptors. class PROTOBUF_EXPORT MethodDescriptor { public: + typedef MethodDescriptorProto Proto; + // Name of this method, not including containing scope. const std::string& name() const; // The fully-qualified name of the method, scope delimited by periods. @@ -1294,6 +1310,8 @@ class PROTOBUF_EXPORT MethodDescriptor { // descriptor->file(). Use DescriptorPool to construct your own descriptors. class PROTOBUF_EXPORT FileDescriptor { public: + typedef FileDescriptorProto Proto; + // The filename, relative to the source tree. // e.g. "foo/bar/baz.proto" const std::string& name() const; diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index d4552676e1..198bcca7f0 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1474,14 +1474,14 @@ const char* FileDescriptorSet::_InternalParse(const char* begin, const char* end ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated .google.protobuf.FileDescriptorProto file = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FileDescriptorProto::_InternalParse; object = msg->add_file(); @@ -1496,7 +1496,7 @@ const char* FileDescriptorSet::_InternalParse(const char* begin, const char* end break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1510,13 +1510,9 @@ const char* FileDescriptorSet::_InternalParse(const char* begin, const char* end } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool FileDescriptorSet::MergePartialFromCodedStream( @@ -1584,8 +1580,7 @@ void FileDescriptorSet::SerializeWithCachedSizes( } ::google::protobuf::uint8* FileDescriptorSet::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorSet) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1595,7 +1590,7 @@ void FileDescriptorSet::SerializeWithCachedSizes( n = static_cast(this->file_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 1, this->file(static_cast(i)), deterministic, target); + 1, this->file(static_cast(i)), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -1935,13 +1930,13 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.name"); auto str = msg->mutable_name(); @@ -1960,7 +1955,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional string package = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.package"); auto str = msg->mutable_package(); @@ -1980,7 +1975,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.dependency"); auto str = msg->add_dependency(); @@ -2002,7 +1997,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto::_InternalParse; object = msg->add_message_type(); @@ -2020,7 +2015,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumDescriptorProto::_InternalParse; object = msg->add_enum_type(); @@ -2038,7 +2033,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ServiceDescriptorProto::_InternalParse; object = msg->add_service(); @@ -2056,7 +2051,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_extension(); @@ -2073,7 +2068,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional .google.protobuf.FileOptions options = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FileOptions::_InternalParse; object = msg->mutable_options(); @@ -2088,7 +2083,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional .google.protobuf.SourceCodeInfo source_code_info = 9; case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceCodeInfo::_InternalParse; object = msg->mutable_source_code_info(); @@ -2105,7 +2100,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e if (static_cast<::google::protobuf::uint8>(tag) == 80) { do { ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->add_public_dependency(value); @@ -2113,7 +2108,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 80 && (ptr += 1)); break; } else if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_public_dependency(); @@ -2128,7 +2123,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e if (static_cast<::google::protobuf::uint8>(tag) == 88) { do { ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->add_weak_dependency(value); @@ -2136,7 +2131,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 88 && (ptr += 1)); break; } else if (static_cast<::google::protobuf::uint8>(tag) != 90) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_weak_dependency(); @@ -2149,7 +2144,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional string syntax = 12; case 12: { if (static_cast<::google::protobuf::uint8>(tag) != 98) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.syntax"); auto str = msg->mutable_syntax(); @@ -2166,7 +2161,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -2180,13 +2175,9 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool FileDescriptorProto::MergePartialFromCodedStream( @@ -2494,8 +2485,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* FileDescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2538,7 +2528,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( n = static_cast(this->message_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 4, this->message_type(static_cast(i)), deterministic, target); + 4, this->message_type(static_cast(i)), target); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; @@ -2546,7 +2536,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( n = static_cast(this->enum_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 5, this->enum_type(static_cast(i)), deterministic, target); + 5, this->enum_type(static_cast(i)), target); } // repeated .google.protobuf.ServiceDescriptorProto service = 6; @@ -2554,7 +2544,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( n = static_cast(this->service_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 6, this->service(static_cast(i)), deterministic, target); + 6, this->service(static_cast(i)), target); } // repeated .google.protobuf.FieldDescriptorProto extension = 7; @@ -2562,21 +2552,21 @@ void FileDescriptorProto::SerializeWithCachedSizes( n = static_cast(this->extension_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 7, this->extension(static_cast(i)), deterministic, target); + 7, this->extension(static_cast(i)), target); } // optional .google.protobuf.FileOptions options = 8; if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 8, HasBitSetters::options(this), deterministic, target); + 8, HasBitSetters::options(this), target); } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; if (cached_has_bits & 0x00000010u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 9, HasBitSetters::source_code_info(this), deterministic, target); + 9, HasBitSetters::source_code_info(this), target); } // repeated int32 public_dependency = 10; @@ -2986,14 +2976,14 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_start(value); @@ -3003,7 +2993,7 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_end(value); @@ -3012,7 +3002,7 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co // optional .google.protobuf.ExtensionRangeOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ExtensionRangeOptions::_InternalParse; object = msg->mutable_options(); @@ -3025,7 +3015,7 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -3039,13 +3029,9 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream( @@ -3147,8 +3133,7 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( } ::google::protobuf::uint8* DescriptorProto_ExtensionRange::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ExtensionRange) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -3168,7 +3153,7 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, HasBitSetters::options(this), deterministic, target); + 3, HasBitSetters::options(this), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -3411,14 +3396,14 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* begin, con ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_start(value); @@ -3428,14 +3413,14 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* begin, con case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_end(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -3449,13 +3434,6 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* begin, con } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool DescriptorProto_ReservedRange::MergePartialFromCodedStream( @@ -3540,8 +3518,7 @@ void DescriptorProto_ReservedRange::SerializeWithCachedSizes( } ::google::protobuf::uint8* DescriptorProto_ReservedRange::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ReservedRange) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -3849,13 +3826,13 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.DescriptorProto.name"); auto str = msg->mutable_name(); @@ -3875,7 +3852,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_field(); @@ -3893,7 +3870,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto::_InternalParse; object = msg->add_nested_type(); @@ -3911,7 +3888,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumDescriptorProto::_InternalParse; object = msg->add_enum_type(); @@ -3929,7 +3906,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto_ExtensionRange::_InternalParse; object = msg->add_extension_range(); @@ -3947,7 +3924,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_extension(); @@ -3964,7 +3941,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, // optional .google.protobuf.MessageOptions options = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::MessageOptions::_InternalParse; object = msg->mutable_options(); @@ -3980,7 +3957,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::OneofDescriptorProto::_InternalParse; object = msg->add_oneof_decl(); @@ -3998,7 +3975,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto_ReservedRange::_InternalParse; object = msg->add_reserved_range(); @@ -4016,7 +3993,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.DescriptorProto.reserved_name"); auto str = msg->add_reserved_name(); @@ -4035,7 +4012,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -4049,13 +4026,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool DescriptorProto::MergePartialFromCodedStream( @@ -4312,8 +4285,7 @@ void DescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* DescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -4335,7 +4307,7 @@ void DescriptorProto::SerializeWithCachedSizes( n = static_cast(this->field_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, this->field(static_cast(i)), deterministic, target); + 2, this->field(static_cast(i)), target); } // repeated .google.protobuf.DescriptorProto nested_type = 3; @@ -4343,7 +4315,7 @@ void DescriptorProto::SerializeWithCachedSizes( n = static_cast(this->nested_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, this->nested_type(static_cast(i)), deterministic, target); + 3, this->nested_type(static_cast(i)), target); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; @@ -4351,7 +4323,7 @@ void DescriptorProto::SerializeWithCachedSizes( n = static_cast(this->enum_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 4, this->enum_type(static_cast(i)), deterministic, target); + 4, this->enum_type(static_cast(i)), target); } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; @@ -4359,7 +4331,7 @@ void DescriptorProto::SerializeWithCachedSizes( n = static_cast(this->extension_range_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 5, this->extension_range(static_cast(i)), deterministic, target); + 5, this->extension_range(static_cast(i)), target); } // repeated .google.protobuf.FieldDescriptorProto extension = 6; @@ -4367,14 +4339,14 @@ void DescriptorProto::SerializeWithCachedSizes( n = static_cast(this->extension_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 6, this->extension(static_cast(i)), deterministic, target); + 6, this->extension(static_cast(i)), target); } // optional .google.protobuf.MessageOptions options = 7; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 7, HasBitSetters::options(this), deterministic, target); + 7, HasBitSetters::options(this), target); } // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; @@ -4382,7 +4354,7 @@ void DescriptorProto::SerializeWithCachedSizes( n = static_cast(this->oneof_decl_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 8, this->oneof_decl(static_cast(i)), deterministic, target); + 8, this->oneof_decl(static_cast(i)), target); } // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; @@ -4390,7 +4362,7 @@ void DescriptorProto::SerializeWithCachedSizes( n = static_cast(this->reserved_range_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 9, this->reserved_range(static_cast(i)), deterministic, target); + 9, this->reserved_range(static_cast(i)), target); } // repeated string reserved_name = 10; @@ -4728,14 +4700,14 @@ const char* ExtensionRangeOptions::_InternalParse(const char* begin, const char* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -4750,7 +4722,7 @@ const char* ExtensionRangeOptions::_InternalParse(const char* begin, const char* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -4772,13 +4744,9 @@ const char* ExtensionRangeOptions::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool ExtensionRangeOptions::MergePartialFromCodedStream( @@ -4855,8 +4823,7 @@ void ExtensionRangeOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* ExtensionRangeOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ExtensionRangeOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -4866,12 +4833,12 @@ void ExtensionRangeOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -5214,13 +5181,13 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.name"); auto str = msg->mutable_name(); @@ -5239,7 +5206,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string extendee = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.extendee"); auto str = msg->mutable_extendee(); @@ -5259,7 +5226,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_number(value); @@ -5269,7 +5236,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (!::google::protobuf::FieldDescriptorProto_Label_IsValid(val)) { ::google::protobuf::internal::WriteVarint(4, val, msg->mutable_unknown_fields()); @@ -5283,7 +5250,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (!::google::protobuf::FieldDescriptorProto_Type_IsValid(val)) { ::google::protobuf::internal::WriteVarint(5, val, msg->mutable_unknown_fields()); @@ -5296,7 +5263,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string type_name = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.type_name"); auto str = msg->mutable_type_name(); @@ -5315,7 +5282,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string default_value = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.default_value"); auto str = msg->mutable_default_value(); @@ -5334,7 +5301,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional .google.protobuf.FieldOptions options = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldOptions::_InternalParse; object = msg->mutable_options(); @@ -5350,7 +5317,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 72) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_oneof_index(value); @@ -5359,7 +5326,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string json_name = 10; case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.json_name"); auto str = msg->mutable_json_name(); @@ -5376,7 +5343,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -5390,13 +5357,9 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool FieldDescriptorProto::MergePartialFromCodedStream( @@ -5673,8 +5636,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* FieldDescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -5745,7 +5707,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( if (cached_has_bits & 0x00000020u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 8, HasBitSetters::options(this), deterministic, target); + 8, HasBitSetters::options(this), target); } // optional int32 oneof_index = 9; @@ -6123,13 +6085,13 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.OneofDescriptorProto.name"); auto str = msg->mutable_name(); @@ -6148,7 +6110,7 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* // optional .google.protobuf.OneofOptions options = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::OneofOptions::_InternalParse; object = msg->mutable_options(); @@ -6161,7 +6123,7 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -6175,13 +6137,9 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool OneofDescriptorProto::MergePartialFromCodedStream( @@ -6272,8 +6230,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* OneofDescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -6294,7 +6251,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes( if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, HasBitSetters::options(this), deterministic, target); + 2, HasBitSetters::options(this), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -6526,14 +6483,14 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* be ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_start(value); @@ -6543,14 +6500,14 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* be case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_end(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -6564,13 +6521,6 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* be } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool EnumDescriptorProto_EnumReservedRange::MergePartialFromCodedStream( @@ -6655,8 +6605,7 @@ void EnumDescriptorProto_EnumReservedRange::SerializeWithCachedSizes( } ::google::protobuf::uint8* EnumDescriptorProto_EnumReservedRange::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -6944,13 +6893,13 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumDescriptorProto.name"); auto str = msg->mutable_name(); @@ -6970,7 +6919,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumValueDescriptorProto::_InternalParse; object = msg->add_value(); @@ -6987,7 +6936,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e // optional .google.protobuf.EnumOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumOptions::_InternalParse; object = msg->mutable_options(); @@ -7003,7 +6952,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumDescriptorProto_EnumReservedRange::_InternalParse; object = msg->add_reserved_range(); @@ -7021,7 +6970,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumDescriptorProto.reserved_name"); auto str = msg->add_reserved_name(); @@ -7040,7 +6989,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -7054,13 +7003,9 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool EnumDescriptorProto::MergePartialFromCodedStream( @@ -7217,8 +7162,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* EnumDescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -7240,14 +7184,14 @@ void EnumDescriptorProto::SerializeWithCachedSizes( n = static_cast(this->value_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, this->value(static_cast(i)), deterministic, target); + 2, this->value(static_cast(i)), target); } // optional .google.protobuf.EnumOptions options = 3; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, HasBitSetters::options(this), deterministic, target); + 3, HasBitSetters::options(this), target); } // repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; @@ -7255,7 +7199,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( n = static_cast(this->reserved_range_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 4, this->reserved_range(static_cast(i)), deterministic, target); + 4, this->reserved_range(static_cast(i)), target); } // repeated string reserved_name = 5; @@ -7576,13 +7520,13 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumValueDescriptorProto.name"); auto str = msg->mutable_name(); @@ -7602,7 +7546,7 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_number(value); @@ -7611,7 +7555,7 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch // optional .google.protobuf.EnumValueOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumValueOptions::_InternalParse; object = msg->mutable_options(); @@ -7624,7 +7568,7 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -7638,13 +7582,9 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool EnumValueDescriptorProto::MergePartialFromCodedStream( @@ -7753,8 +7693,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* EnumValueDescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -7780,7 +7719,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, HasBitSetters::options(this), deterministic, target); + 3, HasBitSetters::options(this), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -8062,13 +8001,13 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.ServiceDescriptorProto.name"); auto str = msg->mutable_name(); @@ -8088,7 +8027,7 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::MethodDescriptorProto::_InternalParse; object = msg->add_method(); @@ -8105,7 +8044,7 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char // optional .google.protobuf.ServiceOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ServiceOptions::_InternalParse; object = msg->mutable_options(); @@ -8118,7 +8057,7 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -8132,13 +8071,9 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool ServiceDescriptorProto::MergePartialFromCodedStream( @@ -8249,8 +8184,7 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* ServiceDescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -8272,14 +8206,14 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( n = static_cast(this->method_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, this->method(static_cast(i)), deterministic, target); + 2, this->method(static_cast(i)), target); } // optional .google.protobuf.ServiceOptions options = 3; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, HasBitSetters::options(this), deterministic, target); + 3, HasBitSetters::options(this), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -8603,13 +8537,13 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.name"); auto str = msg->mutable_name(); @@ -8628,7 +8562,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* // optional string input_type = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.input_type"); auto str = msg->mutable_input_type(); @@ -8647,7 +8581,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* // optional string output_type = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.output_type"); auto str = msg->mutable_output_type(); @@ -8666,7 +8600,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* // optional .google.protobuf.MethodOptions options = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::MethodOptions::_InternalParse; object = msg->mutable_options(); @@ -8682,7 +8616,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_client_streaming(value); @@ -8692,14 +8626,14 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 48) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_server_streaming(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -8713,13 +8647,9 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool MethodDescriptorProto::MergePartialFromCodedStream( @@ -8896,8 +8826,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( } ::google::protobuf::uint8* MethodDescriptorProto::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -8940,7 +8869,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 4, HasBitSetters::options(this), deterministic, target); + 4, HasBitSetters::options(this), target); } // optional bool client_streaming = 5 [default = false]; @@ -9417,13 +9346,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional string java_package = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.java_package"); auto str = msg->mutable_java_package(); @@ -9442,7 +9371,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string java_outer_classname = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.java_outer_classname"); auto str = msg->mutable_java_outer_classname(); @@ -9462,7 +9391,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 72) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (!::google::protobuf::FileOptions_OptimizeMode_IsValid(val)) { ::google::protobuf::internal::WriteVarint(9, val, msg->mutable_unknown_fields()); @@ -9476,7 +9405,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 80) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_java_multiple_files(value); @@ -9485,7 +9414,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string go_package = 11; case 11: { if (static_cast<::google::protobuf::uint8>(tag) != 90) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.go_package"); auto str = msg->mutable_go_package(); @@ -9505,7 +9434,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 16: { if (static_cast<::google::protobuf::uint8>(tag) != 128) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_cc_generic_services(value); @@ -9515,7 +9444,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 17: { if (static_cast<::google::protobuf::uint8>(tag) != 136) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_java_generic_services(value); @@ -9525,7 +9454,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 18: { if (static_cast<::google::protobuf::uint8>(tag) != 144) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_py_generic_services(value); @@ -9535,7 +9464,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 20: { if (static_cast<::google::protobuf::uint8>(tag) != 160) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_java_generate_equals_and_hash(value); @@ -9545,7 +9474,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 23: { if (static_cast<::google::protobuf::uint8>(tag) != 184) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_deprecated(value); @@ -9555,7 +9484,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 27: { if (static_cast<::google::protobuf::uint8>(tag) != 216) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_java_string_check_utf8(value); @@ -9565,7 +9494,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 31: { if (static_cast<::google::protobuf::uint8>(tag) != 248) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_cc_enable_arenas(value); @@ -9574,7 +9503,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string objc_class_prefix = 36; case 36: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.objc_class_prefix"); auto str = msg->mutable_objc_class_prefix(); @@ -9593,7 +9522,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string csharp_namespace = 37; case 37: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.csharp_namespace"); auto str = msg->mutable_csharp_namespace(); @@ -9612,7 +9541,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string swift_prefix = 39; case 39: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.swift_prefix"); auto str = msg->mutable_swift_prefix(); @@ -9631,7 +9560,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string php_class_prefix = 40; case 40: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_class_prefix"); auto str = msg->mutable_php_class_prefix(); @@ -9650,7 +9579,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string php_namespace = 41; case 41: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_namespace"); auto str = msg->mutable_php_namespace(); @@ -9670,7 +9599,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 42: { if (static_cast<::google::protobuf::uint8>(tag) != 80) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_php_generic_services(value); @@ -9679,7 +9608,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string php_metadata_namespace = 44; case 44: { if (static_cast<::google::protobuf::uint8>(tag) != 98) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_metadata_namespace"); auto str = msg->mutable_php_metadata_namespace(); @@ -9698,7 +9627,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string ruby_package = 45; case 45: { if (static_cast<::google::protobuf::uint8>(tag) != 106) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.ruby_package"); auto str = msg->mutable_ruby_package(); @@ -9718,7 +9647,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -9733,7 +9662,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -9755,13 +9684,9 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool FileOptions::MergePartialFromCodedStream( @@ -10276,8 +10201,7 @@ void FileOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* FileOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -10449,12 +10373,12 @@ void FileOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -10916,14 +10840,14 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional bool message_set_wire_format = 1 [default = false]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_message_set_wire_format(value); @@ -10933,7 +10857,7 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_no_standard_descriptor_accessor(value); @@ -10943,7 +10867,7 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_deprecated(value); @@ -10953,7 +10877,7 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_map_entry(value); @@ -10963,7 +10887,7 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -10978,7 +10902,7 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -11000,13 +10924,9 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool MessageOptions::MergePartialFromCodedStream( @@ -11156,8 +11076,7 @@ void MessageOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* MessageOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MessageOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -11188,12 +11107,12 @@ void MessageOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -11482,14 +11401,14 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (!::google::protobuf::FieldOptions_CType_IsValid(val)) { ::google::protobuf::internal::WriteVarint(1, val, msg->mutable_unknown_fields()); @@ -11503,7 +11422,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_packed(value); @@ -11513,7 +11432,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_deprecated(value); @@ -11523,7 +11442,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_lazy(value); @@ -11533,7 +11452,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 48) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (!::google::protobuf::FieldOptions_JSType_IsValid(val)) { ::google::protobuf::internal::WriteVarint(6, val, msg->mutable_unknown_fields()); @@ -11547,7 +11466,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 80) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_weak(value); @@ -11557,7 +11476,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -11572,7 +11491,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -11594,13 +11513,9 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool FieldOptions::MergePartialFromCodedStream( @@ -11800,8 +11715,7 @@ void FieldOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* FieldOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -11844,12 +11758,12 @@ void FieldOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -12122,14 +12036,14 @@ const char* OneofOptions::_InternalParse(const char* begin, const char* end, voi ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -12144,7 +12058,7 @@ const char* OneofOptions::_InternalParse(const char* begin, const char* end, voi break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -12166,13 +12080,9 @@ const char* OneofOptions::_InternalParse(const char* begin, const char* end, voi } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool OneofOptions::MergePartialFromCodedStream( @@ -12249,8 +12159,7 @@ void OneofOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* OneofOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -12260,12 +12169,12 @@ void OneofOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -12492,14 +12401,14 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional bool allow_alias = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_allow_alias(value); @@ -12509,7 +12418,7 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_deprecated(value); @@ -12519,7 +12428,7 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -12534,7 +12443,7 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -12556,13 +12465,9 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool EnumOptions::MergePartialFromCodedStream( @@ -12676,8 +12581,7 @@ void EnumOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* EnumOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -12698,12 +12602,12 @@ void EnumOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -12945,14 +12849,14 @@ const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional bool deprecated = 1 [default = false]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_deprecated(value); @@ -12962,7 +12866,7 @@ const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -12977,7 +12881,7 @@ const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -12999,13 +12903,9 @@ const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool EnumValueOptions::MergePartialFromCodedStream( @@ -13101,8 +13001,7 @@ void EnumValueOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* EnumValueOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -13118,12 +13017,12 @@ void EnumValueOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -13350,14 +13249,14 @@ const char* ServiceOptions::_InternalParse(const char* begin, const char* end, v ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional bool deprecated = 33 [default = false]; case 33: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_deprecated(value); @@ -13367,7 +13266,7 @@ const char* ServiceOptions::_InternalParse(const char* begin, const char* end, v case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -13382,7 +13281,7 @@ const char* ServiceOptions::_InternalParse(const char* begin, const char* end, v break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -13404,13 +13303,9 @@ const char* ServiceOptions::_InternalParse(const char* begin, const char* end, v } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool ServiceOptions::MergePartialFromCodedStream( @@ -13506,8 +13401,7 @@ void ServiceOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* ServiceOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -13523,12 +13417,12 @@ void ServiceOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -13768,14 +13662,14 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // optional bool deprecated = 33 [default = false]; case 33: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_deprecated(value); @@ -13785,7 +13679,7 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo case 34: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (!::google::protobuf::MethodOptions_IdempotencyLevel_IsValid(val)) { ::google::protobuf::internal::WriteVarint(34, val, msg->mutable_unknown_fields()); @@ -13799,7 +13693,7 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -13814,7 +13708,7 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -13836,13 +13730,9 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool MethodOptions::MergePartialFromCodedStream( @@ -13963,8 +13853,7 @@ void MethodOptions::SerializeWithCachedSizes( } ::google::protobuf::uint8* MethodOptions::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -13986,12 +13875,12 @@ void MethodOptions::SerializeWithCachedSizes( n = static_cast(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 999, this->uninterpreted_option(static_cast(i)), deterministic, target); + 999, this->uninterpreted_option(static_cast(i)), target); } // Extension range [1000, 536870912) target = _extensions_.InternalSerializeWithCachedSizesToArray( - 1000, 536870912, deterministic, target); + 1000, 536870912, target); if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( @@ -14242,13 +14131,13 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* begin, cons ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // required string name_part = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.NamePart.name_part"); auto str = msg->mutable_name_part(); @@ -14268,14 +14157,14 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* begin, cons case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_is_extension(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -14289,13 +14178,9 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* begin, cons } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool UninterpretedOption_NamePart::MergePartialFromCodedStream( @@ -14387,8 +14272,7 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes( } ::google::protobuf::uint8* UninterpretedOption_NamePart::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption.NamePart) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -14705,14 +14589,14 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption_NamePart::_InternalParse; object = msg->add_name(); @@ -14729,7 +14613,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e // optional string identifier_value = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.identifier_value"); auto str = msg->mutable_identifier_value(); @@ -14749,7 +14633,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::uint64 value = val; msg->set_positive_int_value(value); @@ -14759,7 +14643,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int64 value = val; msg->set_negative_int_value(value); @@ -14777,7 +14661,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e // optional bytes string_value = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); auto str = msg->mutable_string_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { @@ -14795,7 +14679,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e // optional string aggregate_value = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.aggregate_value"); auto str = msg->mutable_aggregate_value(); @@ -14812,7 +14696,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -14826,13 +14710,9 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool UninterpretedOption::MergePartialFromCodedStream( @@ -15022,8 +14902,7 @@ void UninterpretedOption::SerializeWithCachedSizes( } ::google::protobuf::uint8* UninterpretedOption::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -15033,7 +14912,7 @@ void UninterpretedOption::SerializeWithCachedSizes( n = static_cast(this->name_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, this->name(static_cast(i)), deterministic, target); + 2, this->name(static_cast(i)), target); } cached_has_bits = _has_bits_[0]; @@ -15391,13 +15270,13 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated int32 path = 1 [packed = true]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) == 10) { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_path(); @@ -15409,7 +15288,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha } else if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; do { ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->add_path(value); @@ -15420,7 +15299,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha // repeated int32 span = 2 [packed = true]; case 2: { if (static_cast<::google::protobuf::uint8>(tag) == 18) { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_span(); @@ -15432,7 +15311,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha } else if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; do { ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->add_span(value); @@ -15443,7 +15322,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha // optional string leading_comments = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.leading_comments"); auto str = msg->mutable_leading_comments(); @@ -15462,7 +15341,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha // optional string trailing_comments = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.trailing_comments"); auto str = msg->mutable_trailing_comments(); @@ -15482,7 +15361,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.leading_detached_comments"); auto str = msg->add_leading_detached_comments(); @@ -15501,7 +15380,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -15515,13 +15394,9 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool SourceCodeInfo_Location::MergePartialFromCodedStream( @@ -15700,8 +15575,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( } ::google::protobuf::uint8* SourceCodeInfo_Location::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo.Location) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -16022,14 +15896,14 @@ const char* SourceCodeInfo::_InternalParse(const char* begin, const char* end, v ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated .google.protobuf.SourceCodeInfo.Location location = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceCodeInfo_Location::_InternalParse; object = msg->add_location(); @@ -16044,7 +15918,7 @@ const char* SourceCodeInfo::_InternalParse(const char* begin, const char* end, v break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -16058,13 +15932,9 @@ const char* SourceCodeInfo::_InternalParse(const char* begin, const char* end, v } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool SourceCodeInfo::MergePartialFromCodedStream( @@ -16132,8 +16002,7 @@ void SourceCodeInfo::SerializeWithCachedSizes( } ::google::protobuf::uint8* SourceCodeInfo::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -16143,7 +16012,7 @@ void SourceCodeInfo::SerializeWithCachedSizes( n = static_cast(this->location_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 1, this->location(static_cast(i)), deterministic, target); + 1, this->location(static_cast(i)), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -16376,13 +16245,13 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated int32 path = 1 [packed = true]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) == 10) { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_path(); @@ -16394,7 +16263,7 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons } else if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; do { ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->add_path(value); @@ -16405,7 +16274,7 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons // optional string source_file = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.GeneratedCodeInfo.Annotation.source_file"); auto str = msg->mutable_source_file(); @@ -16425,7 +16294,7 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_begin(value); @@ -16435,14 +16304,14 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_end(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -16456,13 +16325,9 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( @@ -16599,8 +16464,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( } ::google::protobuf::uint8* GeneratedCodeInfo_Annotation::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo.Annotation) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -16881,14 +16745,14 @@ const char* GeneratedCodeInfo::_InternalParse(const char* begin, const char* end ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::GeneratedCodeInfo_Annotation::_InternalParse; object = msg->add_annotation(); @@ -16903,7 +16767,7 @@ const char* GeneratedCodeInfo::_InternalParse(const char* begin, const char* end break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -16917,13 +16781,9 @@ const char* GeneratedCodeInfo::_InternalParse(const char* begin, const char* end } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool GeneratedCodeInfo::MergePartialFromCodedStream( @@ -16991,8 +16851,7 @@ void GeneratedCodeInfo::SerializeWithCachedSizes( } ::google::protobuf::uint8* GeneratedCodeInfo::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -17002,7 +16861,7 @@ void GeneratedCodeInfo::SerializeWithCachedSizes( n = static_cast(this->annotation_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 1, this->annotation(static_cast(i)), deterministic, target); + 1, this->annotation(static_cast(i)), target); } if (_internal_metadata_.have_unknown_fields()) { diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 4775db70da..5ec9398fd5 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -386,7 +386,7 @@ class PROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message /* void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -526,7 +526,7 @@ class PROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Message / void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -855,7 +855,7 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::protobuf void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1011,7 +1011,7 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protobuf: void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1154,7 +1154,7 @@ class PROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* @@ void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1436,7 +1436,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions : public ::google::protobuf::Message void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1579,7 +1579,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Message void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1962,7 +1962,7 @@ class PROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Message void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -2127,7 +2127,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange : public ::google::p void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -2270,7 +2270,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Message / void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -2486,7 +2486,7 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::Mess void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -2659,7 +2659,7 @@ class PROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Messag void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -2837,7 +2837,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Message void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -3068,7 +3068,7 @@ class PROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@prot void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -3569,7 +3569,7 @@ class PROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* @@p void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -3744,7 +3744,7 @@ class PROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@pro void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -3991,7 +3991,7 @@ class PROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@pro void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -4134,7 +4134,7 @@ class PROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@prot void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -4293,7 +4293,7 @@ class PROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message /* @ void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -4444,7 +4444,7 @@ class PROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* @@p void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -4595,7 +4595,7 @@ class PROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @@pr void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -4782,7 +4782,7 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobuf:: void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -4945,7 +4945,7 @@ class PROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Message / void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -5186,7 +5186,7 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Messa void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -5414,7 +5414,7 @@ class PROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* @@p void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -5556,7 +5556,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobuf:: void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -5738,7 +5738,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message /* void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index e48e440fcf..3ed11aa3a7 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -6005,6 +6005,34 @@ TEST_F(ValidationErrorTest, MapEntryConflictsWithEnum) { "with an existing enum type.\n"); } +TEST_F(ValidationErrorTest, EnumValuesConflictWithDifferentCasing) { + BuildFileWithErrors( + "syntax: 'proto3'" + "name: 'foo.proto' " + "enum_type {" + " name: 'FooEnum' " + " value { name: 'BAR' number: 0 }" + " value { name: 'bar' number: 1 }" + "}", + "foo.proto: bar: NAME: Enum name bar has the same name as BAR " + "if you ignore case and strip out the enum name prefix (if any). " + "This is error-prone and can lead to undefined behavior. " + "Please avoid doing this. If you are using allow_alias, please assign " + "the same numeric value to both enums.\n"); + + // Not an error because both enums are mapped to the same value. + BuildFile( + "syntax: 'proto3'" + "name: 'foo.proto' " + "enum_type {" + " name: 'FooEnum' " + " options { allow_alias: true }" + " value { name: 'UNKNOWN' number: 0 }" + " value { name: 'BAR' number: 1 }" + " value { name: 'bar' number: 1 }" + "}"); +} + TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { BuildFileWithErrors( "syntax: 'proto3'" @@ -6014,9 +6042,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'FOO_ENUM_BAZ' number: 0 }" " value { name: 'BAZ' number: 1 }" "}", - "foo.proto: BAZ: NAME: When enum name is stripped and label is " - "PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ. This " - "will make the proto fail to compile for some languages, such as C#.\n"); + "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOO_ENUM_BAZ " + "if you ignore case and strip out the enum name prefix (if any). " + "This is error-prone and can lead to undefined behavior. " + "Please avoid doing this. If you are using allow_alias, please assign " + "the same numeric value to both enums.\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6026,9 +6056,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'FOOENUM_BAZ' number: 0 }" " value { name: 'BAZ' number: 1 }" "}", - "foo.proto: BAZ: NAME: When enum name is stripped and label is " - "PascalCased (Baz), this value label conflicts with FOOENUM_BAZ. This " - "will make the proto fail to compile for some languages, such as C#.\n"); + "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOOENUM_BAZ " + "if you ignore case and strip out the enum name prefix (if any). " + "This is error-prone and can lead to undefined behavior. " + "Please avoid doing this. If you are using allow_alias, please assign " + "the same numeric value to both enums.\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6038,10 +6070,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'FOO_ENUM_BAR_BAZ' number: 0 }" " value { name: 'BAR__BAZ' number: 1 }" "}", - "foo.proto: BAR__BAZ: NAME: When enum name is stripped and label is " - "PascalCased (BarBaz), this value label conflicts with " - "FOO_ENUM_BAR_BAZ. This will make the proto fail to compile for some " - "languages, such as C#.\n"); + "foo.proto: BAR__BAZ: NAME: Enum name BAR__BAZ has the same name as " + "FOO_ENUM_BAR_BAZ if you ignore case and strip out the enum name prefix " + "(if any). This is error-prone and can lead to undefined behavior. " + "Please avoid doing this. If you are using allow_alias, please assign " + "the same numeric value to both enums.\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6051,10 +6084,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'FOO_ENUM__BAR_BAZ' number: 0 }" " value { name: 'BAR_BAZ' number: 1 }" "}", - "foo.proto: BAR_BAZ: NAME: When enum name is stripped and label is " - "PascalCased (BarBaz), this value label conflicts with " - "FOO_ENUM__BAR_BAZ. This will make the proto fail to compile for some " - "languages, such as C#.\n"); + "foo.proto: BAR_BAZ: NAME: Enum name BAR_BAZ has the same name as " + "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name prefix " + "(if any). This is error-prone and can lead to undefined behavior. " + "Please avoid doing this. If you are using allow_alias, please assign " + "the same numeric value to both enums.\n"); // This isn't an error because the underscore will cause the PascalCase to // differ by case (BarBaz vs. Barbaz). diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 53c1a55994..41fdbec664 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -182,14 +182,14 @@ const char* Duration::_InternalParse(const char* begin, const char* end, void* o ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // int64 seconds = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int64 value = val; msg->set_seconds(value); @@ -199,14 +199,14 @@ const char* Duration::_InternalParse(const char* begin, const char* end, void* o case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_nanos(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -220,13 +220,6 @@ const char* Duration::_InternalParse(const char* begin, const char* end, void* o } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Duration::MergePartialFromCodedStream( @@ -310,8 +303,7 @@ void Duration::SerializeWithCachedSizes( } ::google::protobuf::uint8* Duration::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 7735f2c69f..a3b55d3afc 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -139,7 +139,7 @@ class PROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@protoc_ void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 1dd90474b0..7f401fe032 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -168,11 +168,10 @@ const char* Empty::_InternalParse(const char* begin, const char* end, void* obje ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { default: { - handle_unusual: (void)&&handle_unusual; if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -186,13 +185,6 @@ const char* Empty::_InternalParse(const char* begin, const char* end, void* obje } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Empty::MergePartialFromCodedStream( @@ -235,8 +227,7 @@ void Empty::SerializeWithCachedSizes( } ::google::protobuf::uint8* Empty::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Empty) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 0a717a60bb..2e64a6f24b 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -139,7 +139,7 @@ class PROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ins void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index 57dbdefbaa..e5ae3d4137 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -461,13 +462,11 @@ class PROTOBUF_EXPORT ExtensionSet { // Returns a pointer past the last written byte. uint8* InternalSerializeWithCachedSizesToArray(int start_field_number, int end_field_number, - bool deterministic, uint8* target) const; // Like above but serializes in MessageSet format. void SerializeMessageSetWithCachedSizes(io::CodedOutputStream* output) const; - uint8* InternalSerializeMessageSetWithCachedSizesToArray(bool deterministic, - uint8* target) const; + uint8* InternalSerializeMessageSetWithCachedSizesToArray(uint8* target) const; // For backward-compatibility, versions of two of the above methods that // serialize deterministically iff SetDefaultSerializationDeterministic() @@ -531,12 +530,6 @@ class PROTOBUF_EXPORT ExtensionSet { virtual void WriteMessage(int number, io::CodedOutputStream* output) const = 0; virtual uint8* WriteMessageToArray(int number, uint8* target) const = 0; - virtual uint8* InternalWriteMessageToArray(int number, bool, - uint8* target) const { - // TODO(gpike): make this pure virtual. This is a placeholder because we - // need to update third_party/upb, for example. - return WriteMessageToArray(number, target); - } private: virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable. @@ -606,12 +599,11 @@ class PROTOBUF_EXPORT ExtensionSet { void SerializeFieldWithCachedSizes(int number, io::CodedOutputStream* output) const; uint8* InternalSerializeFieldWithCachedSizesToArray(int number, - bool deterministic, uint8* target) const; void SerializeMessageSetItemWithCachedSizes( int number, io::CodedOutputStream* output) const; uint8* InternalSerializeMessageSetItemWithCachedSizesToArray( - int number, bool deterministic, uint8* target) const; + int number, uint8* target) const; size_t ByteSize(int number) const; size_t MessageSetItemByteSize(int number) const; void Clear(); @@ -819,11 +811,10 @@ const char* ParseMessageSet(const char* begin, const char* end, Msg* msg, ExtensionSet* ext, Metadata* metadata, internal::ParseContext* ctx) { auto ptr = begin; - int depth; - (void)depth; + int depth = 0; while (ptr < end) { uint32 tag; - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (tag == WireFormatLite::kMessageSetItemStartTag) { ctx->extra_parse_data().payload.clear(); @@ -848,6 +839,7 @@ const char* ParseMessageSet(const char* begin, const char* end, Msg* msg, } return ptr; } + #endif // These are just for convenience... diff --git a/src/google/protobuf/extension_set_heavy.cc b/src/google/protobuf/extension_set_heavy.cc index 90a96b571a..36422507ea 100644 --- a/src/google/protobuf/extension_set_heavy.cc +++ b/src/google/protobuf/extension_set_heavy.cc @@ -399,7 +399,7 @@ const char* ExtensionSet::ParseMessageSetItem( uint32 tag = *ptr++; if (tag == WireFormatLite::kMessageSetTypeIdTag) { uint32 type_id; - ptr = Varint::Parse32(ptr, &type_id); + ptr = io::Parse32(ptr, &type_id); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); if (ctx->extra_parse_data().payload.empty()) { @@ -439,7 +439,7 @@ const char* ExtensionSet::ParseMessageSetItem( break; } else if (tag == WireFormatLite::kMessageSetMessageTag) { uint32 size; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ParseClosure child = {internal::StringParser, &ctx->extra_parse_data().payload}; @@ -452,7 +452,7 @@ const char* ExtensionSet::ParseMessageSetItem( } } else { ptr--; - ptr = Varint::Parse32(ptr, &tag); + ptr = io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); auto res = ParseField(tag, parent, ptr, end, containing_type, metadata, ctx); @@ -555,26 +555,23 @@ size_t ExtensionSet::Extension::SpaceUsedExcludingSelfLong() const { uint8* ExtensionSet::SerializeWithCachedSizesToArray(int start_field_number, int end_field_number, uint8* target) const { - return InternalSerializeWithCachedSizesToArray( - start_field_number, end_field_number, - io::CodedOutputStream::IsDefaultSerializationDeterministic(), target); + return InternalSerializeWithCachedSizesToArray(start_field_number, + end_field_number, target); } uint8* ExtensionSet::SerializeMessageSetWithCachedSizesToArray( uint8* target) const { - return InternalSerializeMessageSetWithCachedSizesToArray( - io::CodedOutputStream::IsDefaultSerializationDeterministic(), target); + return InternalSerializeMessageSetWithCachedSizesToArray(target); } uint8* ExtensionSet::InternalSerializeWithCachedSizesToArray( - int start_field_number, int end_field_number, bool deterministic, - uint8* target) const { + int start_field_number, int end_field_number, uint8* target) const { if (PROTOBUF_PREDICT_FALSE(is_large())) { const auto& end = map_.large->end(); for (auto it = map_.large->lower_bound(start_field_number); it != end && it->first < end_field_number; ++it) { target = it->second.InternalSerializeFieldWithCachedSizesToArray( - it->first, deterministic, target); + it->first, target); } return target; } @@ -582,23 +579,23 @@ uint8* ExtensionSet::InternalSerializeWithCachedSizesToArray( for (const KeyValue* it = std::lower_bound( flat_begin(), end, start_field_number, KeyValue::FirstComparator()); it != end && it->first < end_field_number; ++it) { - target = it->second.InternalSerializeFieldWithCachedSizesToArray( - it->first, deterministic, target); + target = it->second.InternalSerializeFieldWithCachedSizesToArray(it->first, + target); } return target; } uint8* ExtensionSet::InternalSerializeMessageSetWithCachedSizesToArray( - bool deterministic, uint8* target) const { - ForEach([deterministic, &target](int number, const Extension& ext) { - target = ext.InternalSerializeMessageSetItemWithCachedSizesToArray( - number, deterministic, target); + uint8* target) const { + ForEach([&target](int number, const Extension& ext) { + target = ext.InternalSerializeMessageSetItemWithCachedSizesToArray(number, + target); }); return target; } uint8* ExtensionSet::Extension::InternalSerializeFieldWithCachedSizesToArray( - int number, bool deterministic, uint8* target) const { + int number, uint8* target) const { if (is_repeated) { if (is_packed) { if (cached_size == 0) return target; @@ -666,14 +663,13 @@ uint8* ExtensionSet::Extension::InternalSerializeFieldWithCachedSizesToArray( HANDLE_TYPE( BYTES, Bytes, string); HANDLE_TYPE( ENUM, Enum, enum); #undef HANDLE_TYPE -#define HANDLE_TYPE(UPPERCASE, CAMELCASE, LOWERCASE) \ - case FieldDescriptor::TYPE_##UPPERCASE: \ - for (int i = 0; i < repeated_##LOWERCASE##_value->size(); i++) { \ - target = WireFormatLite::InternalWrite##CAMELCASE##ToArray( \ - number, repeated_##LOWERCASE##_value->Get(i), \ - deterministic, target); \ - } \ - break +#define HANDLE_TYPE(UPPERCASE, CAMELCASE, LOWERCASE) \ + case FieldDescriptor::TYPE_##UPPERCASE: \ + for (int i = 0; i < repeated_##LOWERCASE##_value->size(); i++) { \ + target = WireFormatLite::InternalWrite##CAMELCASE##ToArray( \ + number, repeated_##LOWERCASE##_value->Get(i), target); \ + } \ + break HANDLE_TYPE( GROUP, Group, message); HANDLE_TYPE( MESSAGE, Message, message); @@ -708,11 +704,10 @@ uint8* ExtensionSet::Extension::InternalSerializeFieldWithCachedSizesToArray( #undef HANDLE_TYPE case FieldDescriptor::TYPE_MESSAGE: if (is_lazy) { - target = lazymessage_value->InternalWriteMessageToArray( - number, deterministic, target); + target = lazymessage_value->WriteMessageToArray(number, target); } else { target = WireFormatLite::InternalWriteMessageToArray( - number, *message_value, deterministic, target); + number, *message_value, target); } break; } @@ -722,12 +717,11 @@ uint8* ExtensionSet::Extension::InternalSerializeFieldWithCachedSizesToArray( uint8* ExtensionSet::Extension::InternalSerializeMessageSetItemWithCachedSizesToArray( - int number, bool deterministic, uint8* target) const { + int number, uint8* target) const { if (type != WireFormatLite::TYPE_MESSAGE || is_repeated) { // Not a valid MessageSet extension, but serialize it the normal way. GOOGLE_LOG(WARNING) << "Invalid message set extension."; - return InternalSerializeFieldWithCachedSizesToArray(number, deterministic, - target); + return InternalSerializeFieldWithCachedSizesToArray(number, target); } if (is_cleared) return target; @@ -740,12 +734,11 @@ ExtensionSet::Extension::InternalSerializeMessageSetItemWithCachedSizesToArray( WireFormatLite::kMessageSetTypeIdNumber, number, target); // Write message. if (is_lazy) { - target = lazymessage_value->InternalWriteMessageToArray( - WireFormatLite::kMessageSetMessageNumber, deterministic, target); + target = lazymessage_value->WriteMessageToArray( + WireFormatLite::kMessageSetMessageNumber, target); } else { target = WireFormatLite::InternalWriteMessageToArray( - WireFormatLite::kMessageSetMessageNumber, *message_value, deterministic, - target); + WireFormatLite::kMessageSetMessageNumber, *message_value, target); } // End group. target = io::CodedOutputStream::WriteTagToArray( diff --git a/src/google/protobuf/extension_set_inl.h b/src/google/protobuf/extension_set_inl.h index 93a0558a15..ed9f19c5fd 100644 --- a/src/google/protobuf/extension_set_inl.h +++ b/src/google/protobuf/extension_set_inl.h @@ -92,7 +92,7 @@ std::pair ExtensionSet::ParseFieldWithExtensionInfo( #define HANDLE_VARINT_TYPE(UPPERCASE, CPP_CAMELCASE) \ case WireFormatLite::TYPE_##UPPERCASE: { \ uint64 value; \ - ptr = Varint::Parse64(ptr, &value); \ + ptr = io::Parse64(ptr, &value); \ GOOGLE_PROTOBUF_ASSERT_RETURN(ptr, std::make_pair(nullptr, true)); \ if (extension.is_repeated) { \ Add##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, \ @@ -111,7 +111,7 @@ std::pair ExtensionSet::ParseFieldWithExtensionInfo( #define HANDLE_SVARINT_TYPE(UPPERCASE, CPP_CAMELCASE, SIZE) \ case WireFormatLite::TYPE_##UPPERCASE: { \ uint64 val; \ - ptr = Varint::Parse64(ptr, &val); \ + ptr = io::Parse64(ptr, &val); \ GOOGLE_PROTOBUF_ASSERT_RETURN(ptr, std::make_pair(nullptr, true)); \ auto value = WireFormatLite::ZigZagDecode##SIZE(val); \ if (extension.is_repeated) { \ @@ -151,7 +151,7 @@ std::pair ExtensionSet::ParseFieldWithExtensionInfo( case WireFormatLite::TYPE_ENUM: { uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = io::Parse64(ptr, &val); GOOGLE_PROTOBUF_ASSERT_RETURN(ptr, std::make_pair(nullptr, true)); int value = val; @@ -221,7 +221,7 @@ std::pair ExtensionSet::ParseFieldWithExtensionInfo( length_delim: uint32 size; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = io::Parse32(ptr, &size); GOOGLE_PROTOBUF_ASSERT_RETURN(ptr, std::make_pair(nullptr, true)); if (size > end - ptr) goto len_delim_till_end; { diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index f58a99e89d..f266ca2da1 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -176,14 +176,14 @@ const char* FieldMask::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated string paths = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldMask.paths"); auto str = msg->add_paths(); @@ -202,7 +202,7 @@ const char* FieldMask::_InternalParse(const char* begin, const char* end, void* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -216,13 +216,9 @@ const char* FieldMask::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool FieldMask::MergePartialFromCodedStream( @@ -296,8 +292,7 @@ void FieldMask::SerializeWithCachedSizes( } ::google::protobuf::uint8* FieldMask::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 10155215fc..8ad3f6b9f5 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -139,7 +139,7 @@ class PROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@protoc void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index f926da274e..96852ea7c8 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -1706,8 +1706,6 @@ void* GeneratedMessageReflection::MutableRawRepeatedField( if (field->cpp_type() != cpptype) ReportReflectionUsageTypeError(descriptor_, field, "MutableRawRepeatedField", cpptype); - if (ctype >= 0 && !field->is_extension()) - GOOGLE_CHECK_EQ(field->options().ctype(), ctype) << "subtype mismatch"; if (desc != NULL) GOOGLE_CHECK_EQ(field->message_type(), desc) << "wrong submessage type"; if (field->is_extension()) { @@ -2224,7 +2222,7 @@ void* GeneratedMessageReflection::RepeatedFieldData( } } -MapFieldBase* GeneratedMessageReflection::MapData( +MapFieldBase* GeneratedMessageReflection::MutableMapData( Message* message, const FieldDescriptor* field) const { USAGE_CHECK(IsMapFieldInApi(field), "GetMapData", @@ -2232,6 +2230,14 @@ MapFieldBase* GeneratedMessageReflection::MapData( return MutableRaw(message, field); } +const MapFieldBase* GeneratedMessageReflection::GetMapData( + const Message& message, const FieldDescriptor* field) const { + USAGE_CHECK(IsMapFieldInApi(field), + "GetMapData", + "Field is not a map field."); + return &(GetRaw(message, field)); +} + namespace { // Helper function to transform migration schema into reflection schema. diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index 0ffb3ff270..d1544784c0 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -670,8 +670,11 @@ class GeneratedMessageReflection final : public Reflection { Message* sub_message, const FieldDescriptor* field) const; - internal::MapFieldBase* MapData(Message* message, - const FieldDescriptor* field) const override; + internal::MapFieldBase* MutableMapData( + Message* message, const FieldDescriptor* field) const override; + + const internal::MapFieldBase* GetMapData( + const Message& message, const FieldDescriptor* field) const override; friend inline // inline so nobody can call this function. void diff --git a/src/google/protobuf/generated_message_table_driven.h b/src/google/protobuf/generated_message_table_driven.h index eb85ef5bde..8fee7ab6c0 100644 --- a/src/google/protobuf/generated_message_table_driven.h +++ b/src/google/protobuf/generated_message_table_driven.h @@ -52,6 +52,8 @@ #error "You cannot SWIG proto headers" #endif +#include + namespace google { namespace protobuf { namespace internal { @@ -79,6 +81,41 @@ enum ProcessingTypes { static_assert(TYPE_MAP < kRepeatedMask, "Invalid enum"); +struct PROTOBUF_EXPORT FieldMetadata { + uint32 offset; // offset of this field in the struct + uint32 tag; // field * 8 + wire_type + // byte offset * 8 + bit_offset; + // if the high bit is set then this is the byte offset of the oneof_case + // for this field. + uint32 has_offset; + uint32 type; // the type of this field. + const void* ptr; // auxiliary data + + // From the serializer point of view each fundamental type can occur in + // 4 different ways. For simplicity we treat all combinations as a cartesion + // product although not all combinations are allowed. + enum FieldTypeClass { + kPresence, + kNoPresence, + kRepeated, + kPacked, + kOneOf, + kNumTypeClasses // must be last enum + }; + // C++ protobuf has 20 fundamental types, were we added Cord and StringPiece + // and also distinquish the same types if they have different wire format. + enum { + kCordType = 19, + kStringPieceType = 20, + kInlinedType = 21, + kNumTypes = 21, + kSpecial = kNumTypes * kNumTypeClasses, + }; + + static int CalculateType(int fundamental_type, FieldTypeClass type_class); +}; + + // TODO(ckennelly): Add a static assertion to ensure that these masks do not // conflict with wiretypes. @@ -199,8 +236,108 @@ bool ParseMap(io::CodedInputStream* input, void* map_field) { return WireFormatLite::ReadMessageNoVirtual(input, &parser); } +struct SerializationTable { + int num_fields; + const FieldMetadata* field_table; +}; + +PROTOBUF_EXPORT void SerializeInternal(const uint8* base, + const FieldMetadata* table, + int32 num_fields, + io::CodedOutputStream* output); + +inline void TableSerialize(const MessageLite& msg, + const SerializationTable* table, + io::CodedOutputStream* output) { + const FieldMetadata* field_table = table->field_table; + int num_fields = table->num_fields - 1; + const uint8* base = reinterpret_cast(&msg); + // TODO(gerbens) This skips the first test if we could use the fast + // array serialization path, we should make this + // int cached_size = + // *reinterpret_cast(base + field_table->offset); + // SerializeWithCachedSize(msg, field_table + 1, num_fields, cached_size, ...) + // But we keep conformance with the old way for now. + SerializeInternal(base, field_table + 1, num_fields, output); +} + +uint8* SerializeInternalToArray(const uint8* base, const FieldMetadata* table, + int32 num_fields, bool is_deterministic, + uint8* buffer); + +inline uint8* TableSerializeToArray(const MessageLite& msg, + const SerializationTable* table, + bool is_deterministic, uint8* buffer) { + const uint8* base = reinterpret_cast(&msg); + const FieldMetadata* field_table = table->field_table + 1; + int num_fields = table->num_fields - 1; + return SerializeInternalToArray(base, field_table, num_fields, + is_deterministic, buffer); +} + +template +struct CompareHelper { + bool operator()(const T& a, const T& b) { return a < b; } +}; + +template <> +struct CompareHelper { + bool operator()(const ArenaStringPtr& a, const ArenaStringPtr& b) { + return a.Get() < b.Get(); + } +}; + +struct CompareMapKey { + template + bool operator()(const MapEntryHelper& a, const MapEntryHelper& b) { + return Compare(a.key_, b.key_); + } + template + bool Compare(const T& a, const T& b) { + return CompareHelper()(a, b); + } +}; + +template +void MapFieldSerializer(const uint8* base, uint32 offset, uint32 tag, + uint32 has_offset, io::CodedOutputStream* output) { + typedef MapEntryHelper Entry; + typedef typename MapFieldType::MapType::const_iterator Iter; + + const MapFieldType& map_field = + *reinterpret_cast(base + offset); + const SerializationTable* t = + table + + has_offset; // has_offset is overloaded for maps to mean table offset + if (!output->IsSerializationDeterministic()) { + for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end(); + ++it) { + Entry map_entry(*it); + output->WriteVarint32(tag); + output->WriteVarint32(map_entry._cached_size_); + SerializeInternal(reinterpret_cast(&map_entry), + t->field_table, t->num_fields, output); + } + } else { + std::vector v; + for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end(); + ++it) { + v.push_back(Entry(*it)); + } + std::sort(v.begin(), v.end(), CompareMapKey()); + for (int i = 0; i < v.size(); i++) { + output->WriteVarint32(tag); + output->WriteVarint32(v[i]._cached_size_); + SerializeInternal(reinterpret_cast(&v[i]), t->field_table, + t->num_fields, output); + } + } +} + } // namespace internal } // namespace protobuf } // namespace google +#include + #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__ diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index 32afb7dba5..028c8ccdb3 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -293,8 +294,15 @@ void SerializeMessageNoTable(const MessageLite* msg, } void SerializeMessageNoTable(const MessageLite* msg, ArrayOutput* output) { - output->ptr = msg->InternalSerializeWithCachedSizesToArray( - output->is_deterministic, output->ptr); + if (output->is_deterministic) { + io::ArrayOutputStream array_stream(output->ptr, INT_MAX); + io::CodedOutputStream o(&array_stream); + o.SetSerializationDeterministic(true); + msg->SerializeWithCachedSizes(&o); + output->ptr += o.ByteCount(); + } else { + output->ptr = msg->InternalSerializeWithCachedSizesToArray(output->ptr); + } } // Helper to branch to fast path if possible @@ -303,14 +311,15 @@ void SerializeMessageDispatch(const MessageLite& msg, int32 cached_size, io::CodedOutputStream* output) { const uint8* base = reinterpret_cast(&msg); - // Try the fast path - uint8* ptr = output->GetDirectBufferForNBytesAndAdvance(cached_size); - if (ptr) { - // We use virtual dispatch to enable dedicated generated code for the - // fast path. - msg.InternalSerializeWithCachedSizesToArray( - output->IsSerializationDeterministic(), ptr); - return; + if (!output->IsSerializationDeterministic()) { + // Try the fast path + uint8* ptr = output->GetDirectBufferForNBytesAndAdvance(cached_size); + if (ptr) { + // We use virtual dispatch to enable dedicated generated code for the + // fast path. + msg.InternalSerializeWithCachedSizesToArray(ptr); + return; + } } SerializeInternal(base, field_table, num_fields, output); } @@ -647,7 +656,7 @@ void SerializeInternal(const uint8* base, // Special cases case FieldMetadata::kSpecial: - func = reinterpret_cast( + func = reinterpret_cast( const_cast(field_metadata.ptr)); func (base, field_metadata.offset, field_metadata.tag, field_metadata.has_offset, output); @@ -694,9 +703,9 @@ uint8* SerializeInternalToArray(const uint8* base, io::ArrayOutputStream array_stream(array_output.ptr, INT_MAX); io::CodedOutputStream output(&array_stream); output.SetSerializationDeterministic(is_deterministic); - func = reinterpret_cast( + func = reinterpret_cast( const_cast(field_metadata.ptr)); - func (base, field_metadata.offset, field_metadata.tag, + func (base, field_metadata.offset, field_metadata.tag, field_metadata.has_offset, &output); array_output.ptr += output.ByteCount(); } break; diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index ca6cc9c607..2e29fd3842 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -49,7 +49,6 @@ #include #include #include -#include #include #include // Add direct dep on port for pb.cc #include @@ -108,40 +107,6 @@ bool AllAreInitializedWeak(const RepeatedPtrField& t) { return true; } -struct PROTOBUF_EXPORT FieldMetadata { - uint32 offset; // offset of this field in the struct - uint32 tag; // field * 8 + wire_type - // byte offset * 8 + bit_offset; - // if the high bit is set then this is the byte offset of the oneof_case - // for this field. - uint32 has_offset; - uint32 type; // the type of this field. - const void* ptr; // auxiliary data - - // From the serializer point of view each fundamental type can occur in - // 4 different ways. For simplicity we treat all combinations as a cartesion - // product although not all combinations are allowed. - enum FieldTypeClass { - kPresence, - kNoPresence, - kRepeated, - kPacked, - kOneOf, - kNumTypeClasses // must be last enum - }; - // C++ protobuf has 20 fundamental types, were we added Cord and StringPiece - // and also distinquish the same types if they have different wire format. - enum { - kCordType = 19, - kStringPieceType = 20, - kInlinedType = 21, - kNumTypes = 21, - kSpecial = kNumTypes * kNumTypeClasses, - }; - - static int CalculateType(int fundamental_type, FieldTypeClass type_class); -}; - inline bool IsPresent(const void* base, uint32 hasbit) { const uint32* has_bits_array = static_cast(base); return (has_bits_array[hasbit / 32] & (1u << (hasbit & 31))) != 0; @@ -165,104 +130,6 @@ PROTOBUF_EXPORT void UnknownFieldSerializerLite(const uint8* base, uint32 has_offset, io::CodedOutputStream* output); -struct SerializationTable { - int num_fields; - const FieldMetadata* field_table; -}; - -PROTOBUF_EXPORT void SerializeInternal(const uint8* base, - const FieldMetadata* table, - int32 num_fields, - io::CodedOutputStream* output); - -inline void TableSerialize(const MessageLite& msg, - const SerializationTable* table, - io::CodedOutputStream* output) { - const FieldMetadata* field_table = table->field_table; - int num_fields = table->num_fields - 1; - const uint8* base = reinterpret_cast(&msg); - // TODO(gerbens) This skips the first test if we could use the fast - // array serialization path, we should make this - // int cached_size = - // *reinterpret_cast(base + field_table->offset); - // SerializeWithCachedSize(msg, field_table + 1, num_fields, cached_size, ...) - // But we keep conformance with the old way for now. - SerializeInternal(base, field_table + 1, num_fields, output); -} - -uint8* SerializeInternalToArray(const uint8* base, const FieldMetadata* table, - int32 num_fields, bool is_deterministic, - uint8* buffer); - -inline uint8* TableSerializeToArray(const MessageLite& msg, - const SerializationTable* table, - bool is_deterministic, uint8* buffer) { - const uint8* base = reinterpret_cast(&msg); - const FieldMetadata* field_table = table->field_table + 1; - int num_fields = table->num_fields - 1; - return SerializeInternalToArray(base, field_table, num_fields, - is_deterministic, buffer); -} - -template -struct CompareHelper { - bool operator()(const T& a, const T& b) { return a < b; } -}; - -template <> -struct CompareHelper { - bool operator()(const ArenaStringPtr& a, const ArenaStringPtr& b) { - return a.Get() < b.Get(); - } -}; - -struct CompareMapKey { - template - bool operator()(const MapEntryHelper& a, const MapEntryHelper& b) { - return Compare(a.key_, b.key_); - } - template - bool Compare(const T& a, const T& b) { - return CompareHelper()(a, b); - } -}; - -template -void MapFieldSerializer(const uint8* base, uint32 offset, uint32 tag, - uint32 has_offset, io::CodedOutputStream* output) { - typedef MapEntryHelper Entry; - typedef typename MapFieldType::MapType::const_iterator Iter; - - const MapFieldType& map_field = - *reinterpret_cast(base + offset); - const SerializationTable* t = - table + - has_offset; // has_offset is overloaded for maps to mean table offset - if (!output->IsSerializationDeterministic()) { - for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end(); - ++it) { - Entry map_entry(*it); - output->WriteVarint32(tag); - output->WriteVarint32(map_entry._cached_size_); - SerializeInternal(reinterpret_cast(&map_entry), - t->field_table, t->num_fields, output); - } - } else { - std::vector v; - for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end(); - ++it) { - v.push_back(Entry(*it)); - } - std::sort(v.begin(), v.end(), CompareMapKey()); - for (int i = 0; i < v.size(); i++) { - output->WriteVarint32(tag); - output->WriteVarint32(v[i]._cached_size_); - SerializeInternal(reinterpret_cast(&v[i]), t->field_table, - t->num_fields, output); - } - } -} - PROTOBUF_EXPORT MessageLite* DuplicateIfNonNullInternal(MessageLite* message); PROTOBUF_EXPORT MessageLite* GetOwnedMessageInternal(Arena* message_arena, MessageLite* submessage, diff --git a/src/google/protobuf/implicit_weak_message.cc b/src/google/protobuf/implicit_weak_message.cc index b26f44124e..5cc718f945 100644 --- a/src/google/protobuf/implicit_weak_message.cc +++ b/src/google/protobuf/implicit_weak_message.cc @@ -34,7 +34,6 @@ #include #include #include -#include #include diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index a66ace57d2..9bafafbccb 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -139,10 +139,6 @@ #include -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -#include "util/coding/varint.h" -#endif - namespace google { namespace protobuf { @@ -168,6 +164,35 @@ T UnalignedLoad(const void* p) { return res; } +// TODO(gerbens) Experiment with best implementation. +// Clang unrolls loop and generating pretty good code on O2, gcc doesn't. +// Unclear if we want 64 bit parse loop unrolled, inlined or opaque function +// call. Hence experimentation is needed. +// Important guarantee is that it doesn't read more than size bytes from p. +template +const char* VarintParse(const char* p, T* out) { + T res = 0; + T extra = 0; + for (int i = 0; i < size; i++) { + T byte = static_cast(p[i]); + res += byte << (i * 7); + int j = i + 1; + if (PROTOBUF_PREDICT_TRUE(byte < 128)) { + *out = res - extra; + return p + j; + } + extra += 128ull << (i * 7); + } + return nullptr; +} + +inline const char* Parse32(const char* p, uint32* out) { + return VarintParse<5>(p, out); +} +inline const char* Parse64(const char* p, uint64* out) { + return VarintParse<10>(p, out); +} + // Class which reads and decodes binary data which is composed of varint- // encoded integers and fixed-width pieces. Wraps a ZeroCopyInputStream. // Most users will not need to deal with CodedInputStream. @@ -175,6 +200,8 @@ T UnalignedLoad(const void* p) { // Most methods of CodedInputStream that return a bool return false if an // underlying I/O error occurs or if the data is malformed. Once such a // failure occurs, the CodedInputStream is broken and is no longer useful. +// After a failure, callers also should assume writes to "out" args may have +// occurred, though nothing useful can be determined from those writes. class PROTOBUF_EXPORT CodedInputStream { public: // Create a CodedInputStream that reads from the given ZeroCopyInputStream. @@ -418,6 +445,7 @@ class PROTOBUF_EXPORT CodedInputStream { void SetRecursionLimit(int limit); int RecursionBudget() { return recursion_budget_; } + static int GetDefaultRecursionLimit() { return default_recursion_limit_; } // Increments the current recursion depth. Returns true if the depth is // under the limit, false if it has gone over. diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 08a02acd3b..2b36b0b917 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -249,11 +249,9 @@ class MapEntryImpl : public Base { } ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const override { - output = KeyTypeHandler::InternalWriteToArray(kKeyFieldNumber, key(), - deterministic, output); - output = ValueTypeHandler::InternalWriteToArray(kValueFieldNumber, value(), - deterministic, output); + ::google::protobuf::uint8* output) const override { + output = KeyTypeHandler::WriteToArray(kKeyFieldNumber, key(), output); + output = ValueTypeHandler::WriteToArray(kValueFieldNumber, value(), output); return output; } diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index bba5d8ae7f..5e598b8e0d 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -742,7 +742,7 @@ class PROTOBUF_EXPORT MapIterator { public: MapIterator(Message* message, const FieldDescriptor* field) { const Reflection* reflection = message->GetReflection(); - map_ = reflection->MapData(message, field); + map_ = reflection->MutableMapData(message, field); key_.SetType(field->message_type()->FindFieldByName("key")->cpp_type()); value_.SetType(field->message_type()->FindFieldByName("value")->cpp_type()); map_->InitializeIterator(this); diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index 41d9c379ec..06ebf5d3f8 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -2042,19 +2042,30 @@ TEST(GeneratedMapFieldTest, DynamicMessageMergeFromDynamicMessage) { unittest::TestMap::descriptor()); reflection_tester.SetMapFieldsViaMapReflection(message1.get()); + // message2 is created by same factory. std::unique_ptr message2; message2.reset( factory.GetPrototype(unittest::TestMap::descriptor())->New()); reflection_tester.SetMapFieldsViaMapReflection(message2.get()); + // message3 is created by different factory. + DynamicMessageFactory factory3; + std::unique_ptr message3; + message3.reset( + factory3.GetPrototype(unittest::TestMap::descriptor())->New()); + reflection_tester.SetMapFieldsViaMapReflection(message3.get()); + message2->MergeFrom(*message1); + message3->MergeFrom(*message1); // Test MergeFrom does not sync to repeated fields and // there is no duplicate keys in text format. - string output1, output2; + string output1, output2, output3; TextFormat::PrintToString(*message1, &output1); TextFormat::PrintToString(*message2, &output2); + TextFormat::PrintToString(*message3, &output3); EXPECT_EQ(output1, output2); + EXPECT_EQ(output1, output3); } TEST(GeneratedMapFieldTest, DynamicMessageCopyFrom) { diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index 2db3dc6c9f..a8220b65c1 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -167,9 +167,6 @@ class MapTypeHandler { MapEntryAccessorType* value); static inline void Write(int field, const MapEntryAccessorType& value, io::CodedOutputStream* output); - static inline uint8* InternalWriteToArray(int field, - const MapEntryAccessorType& value, - bool deterministic, uint8* target); static inline uint8* WriteToArray(int field, const MapEntryAccessorType& value, uint8* target); @@ -226,14 +223,9 @@ class MapTypeHandler { MapEntryAccessorType* value); \ static inline void Write(int field, const MapEntryAccessorType& value, \ io::CodedOutputStream* output); \ - static inline uint8* InternalWriteToArray( \ - int field, const MapEntryAccessorType& value, bool deterministic, \ - uint8* target); \ static inline uint8* WriteToArray(int field, \ const MapEntryAccessorType& value, \ - uint8* target) { \ - return InternalWriteToArray(field, value, false, target); \ - } \ + uint8* target); \ static inline const MapEntryAccessorType& GetExternalReference( \ const TypeOnMemory& value); \ static inline void DeleteNoArena(const TypeOnMemory& x); \ @@ -374,12 +366,9 @@ inline void MapTypeHandler::Write( } template -inline uint8* -MapTypeHandler::InternalWriteToArray( - int field, const MapEntryAccessorType& value, bool deterministic, - uint8* target) { - return WireFormatLite::InternalWriteMessageToArray(field, value, - deterministic, target); +inline uint8* MapTypeHandler::WriteToArray( + int field, const MapEntryAccessorType& value, uint8* target) { + return WireFormatLite::InternalWriteMessageToArray(field, value, target); } #define WRITE_METHOD(FieldType, DeclaredType) \ @@ -391,9 +380,8 @@ MapTypeHandler::InternalWriteToArray( } \ template \ inline uint8* \ - MapTypeHandler::InternalWriteToArray( \ - int field, const MapEntryAccessorType& value, bool, uint8* target) { \ + MapTypeHandler::WriteToArray( \ + int field, const MapEntryAccessorType& value, uint8* target) { \ return WireFormatLite::Write##DeclaredType##ToArray(field, value, target); \ } diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index fc307f04f1..37725949d3 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -290,7 +290,6 @@ ParseClosure GetPackedField(const FieldDescriptor* field, Message* msg, if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) { return {internal::PackedEnumParser, object}; } else { - GOOGLE_CHECK_EQ(field->file()->options().cc_api_version(), 2); ctx->extra_parse_data().SetEnumValidatorArg( ReflectiveValidator, field->enum_type(), reflection->MutableUnknownFields(msg), field->number()); @@ -307,6 +306,7 @@ ParseClosure GetPackedField(const FieldDescriptor* field, Message* msg, default: GOOGLE_LOG(FATAL) << "Type is not packable " << field->type(); + return {}; // Make compiler happy } } @@ -315,19 +315,13 @@ ParseClosure GetLenDelim(int field_number, const FieldDescriptor* field, internal::ParseContext* ctx) { if (WireFormat::WireTypeForFieldType(field->type()) != WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { - ABSL_ASSERT(field->is_packable()); + GOOGLE_DCHECK(field->is_packable()); return GetPackedField(field, msg, reflection, ctx); } enum { kNone = 0, kVerify, kStrict } utf8_level = kNone; internal::ParseFunc string_parsers[] = {internal::StringParser, internal::StringParserUTF8Verify, internal::StringParserUTF8}; - internal::ParseFunc cord_parsers[] = {internal::CordParser, - internal::CordParserUTF8Verify, - internal::CordParserUTF8}; - internal::ParseFunc string_piece_parsers[] = { - internal::StringPieceParser, internal::StringPieceParserUTF8Verify, - internal::StringPieceParserUTF8}; switch (field->type()) { case FieldDescriptor::TYPE_STRING: if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 @@ -339,7 +333,7 @@ ParseClosure GetLenDelim(int field_number, const FieldDescriptor* field, ctx->extra_parse_data().SetFieldName(field->full_name().c_str()); utf8_level = kVerify; } - FALLTHROUGH_INTENDED; + PROTOBUF_FALLTHROUGH_INTENDED; case FieldDescriptor::TYPE_BYTES: { if (field->is_repeated()) { int index = reflection->FieldSize(*msg, field); @@ -350,17 +344,10 @@ ParseClosure GetLenDelim(int field_number, const FieldDescriptor* field, auto object = reflection->MutableRepeatedPtrField(msg, field) ->Mutable(index); return {string_parsers[utf8_level], object}; - } else if (field->options().ctype() == FieldOptions::CORD) { - auto object = reflection->MutableRepeatedField(msg, field) + } else { + auto object = reflection->MutableRepeatedPtrField(msg, field) ->Mutable(index); - return {cord_parsers[utf8_level], object}; - } else if (field->options().ctype() == FieldOptions::STRING_PIECE) { - auto object = - reflection - ->MutableRepeatedPtrField(msg, - field) - ->Mutable(index); - return {string_piece_parsers[utf8_level], object}; + return {string_parsers[utf8_level], object}; } } else { // Clear value and make sure it's set. @@ -372,16 +359,10 @@ ParseClosure GetLenDelim(int field_number, const FieldDescriptor* field, reflection->GetStringReference(*msg, field, nullptr)); return {string_parsers[utf8_level], object}; } else { - void* object = - internal::ReflectionAccessor::GetOffset(msg, field, reflection); - if (field->containing_oneof()) { - object = *static_cast(object); - } - if (field->options().ctype() == FieldOptions::CORD) { - return {cord_parsers[utf8_level], object}; - } else if (field->options().ctype() == FieldOptions::STRING_PIECE) { - return {string_piece_parsers[utf8_level], object}; - } + // HACK around inability to get mutable_string in reflection + string* object = &const_cast( + reflection->GetStringReference(*msg, field, nullptr)); + return {string_parsers[utf8_level], object}; } } GOOGLE_LOG(FATAL) << "No other type than string supported"; @@ -399,6 +380,7 @@ ParseClosure GetLenDelim(int field_number, const FieldDescriptor* field, default: GOOGLE_LOG(FATAL) << "Wrong type for length delim " << field->type(); } + return {}; // Make compiler happy. } ParseClosure GetGroup(int field_number, const FieldDescriptor* field, @@ -507,8 +489,8 @@ const char* Message::_InternalParse(const char* begin, const char* end, reflection_(msg->GetReflection()), ctx_(ctx), is_item_(is_item) { - GOOGLE_CHECK(descriptor_) << typeid(*this).name(); - GOOGLE_CHECK(reflection_) << descriptor_->name() << " " << typeid(*this).name(); + GOOGLE_CHECK(descriptor_) << msg->GetTypeName(); + GOOGLE_CHECK(reflection_) << msg->GetTypeName(); } const FieldDescriptor* Field(int num, int wire_type) { diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 0734df5c58..02cca530c9 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -1049,11 +1049,16 @@ class PROTOBUF_EXPORT Reflection { // Help method for MapIterator. friend class MapIterator; - virtual internal::MapFieldBase* MapData( + virtual internal::MapFieldBase* MutableMapData( Message* /* message */, const FieldDescriptor* /* field */) const { return NULL; } + virtual const internal::MapFieldBase* GetMapData( + const Message& /* message */, const FieldDescriptor* /* field */) const { + return NULL; + } + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reflection); }; diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 8edae78627..fb1da49e54 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -287,8 +288,9 @@ bool MessageLite::MergePartialFromCodedStream(io::CodedInputStream* input) { } range = next(); } + if (!parser.Done()) return false; input->SetConsumed(); - return parser.Done(); + return true; } #endif @@ -355,8 +357,27 @@ bool MessageLite::ParsePartialFromArray(const void* data, int size) { // =================================================================== uint8* MessageLite::SerializeWithCachedSizesToArray(uint8* target) const { - return InternalSerializeWithCachedSizesToArray( - io::CodedOutputStream::IsDefaultSerializationDeterministic(), target); + const internal::SerializationTable* table = + static_cast(InternalGetTable()); + auto deterministic = + io::CodedOutputStream::IsDefaultSerializationDeterministic(); + if (table) { + return internal::TableSerializeToArray(*this, table, deterministic, target); + } else { + if (deterministic) { + // We only optimize this when using optimize_for = SPEED. In other cases + // we just use the CodedOutputStream path. + int size = GetCachedSize(); + io::ArrayOutputStream out(target, size); + io::CodedOutputStream coded_out(&out); + coded_out.SetSerializationDeterministic(true); + SerializeWithCachedSizes(&coded_out); + GOOGLE_CHECK(!coded_out.HadError()); + return target + size; + } else { + return InternalSerializeWithCachedSizesToArray(target); + } + } } bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const { @@ -373,29 +394,29 @@ bool MessageLite::SerializePartialToCodedStream( return false; } - uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size); - if (buffer != NULL) { - uint8* end = InternalSerializeWithCachedSizesToArray( - output->IsSerializationDeterministic(), buffer); - if (end - buffer != size) { - ByteSizeConsistencyError(size, ByteSizeLong(), end - buffer, *this); - } - return true; - } else { - int original_byte_count = output->ByteCount(); - SerializeWithCachedSizes(output); - if (output->HadError()) { - return false; - } - int final_byte_count = output->ByteCount(); - - if (final_byte_count - original_byte_count != size) { - ByteSizeConsistencyError(size, ByteSizeLong(), - final_byte_count - original_byte_count, *this); + if (!output->IsSerializationDeterministic()) { + uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size); + if (buffer != nullptr) { + uint8* end = InternalSerializeWithCachedSizesToArray(buffer); + if (end - buffer != size) { + ByteSizeConsistencyError(size, ByteSizeLong(), end - buffer, *this); + } + return true; } + } + int original_byte_count = output->ByteCount(); + SerializeWithCachedSizes(output); + if (output->HadError()) { + return false; + } + int final_byte_count = output->ByteCount(); - return true; + if (final_byte_count - original_byte_count != size) { + ByteSizeConsistencyError(size, ByteSizeLong(), + final_byte_count - original_byte_count, *this); } + + return true; } bool MessageLite::SerializeToZeroCopyStream( @@ -496,7 +517,7 @@ void MessageLite::SerializeWithCachedSizes( // generated code for maximum speed. If the proto is optimized for size or // is lite, then we need to specialize this to avoid infinite recursion. uint8* MessageLite::InternalSerializeWithCachedSizesToArray( - bool deterministic, uint8* target) const { + uint8* target) const { const internal::SerializationTable* table = static_cast(InternalGetTable()); if (table == NULL) { @@ -505,12 +526,11 @@ uint8* MessageLite::InternalSerializeWithCachedSizesToArray( int size = GetCachedSize(); io::ArrayOutputStream out(target, size); io::CodedOutputStream coded_out(&out); - coded_out.SetSerializationDeterministic(deterministic); SerializeWithCachedSizes(&coded_out); GOOGLE_CHECK(!coded_out.HadError()); return target + size; } else { - return internal::TableSerializeToArray(*this, table, deterministic, target); + return internal::TableSerializeToArray(*this, table, false, target); } } diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 39c9e8ff00..1e0714115a 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -400,12 +400,9 @@ class PROTOBUF_EXPORT MessageLite { // method.) virtual int GetCachedSize() const = 0; - virtual uint8* InternalSerializeWithCachedSizesToArray(bool deterministic, - uint8* target) const; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER virtual internal::ParseFunc _ParseFunc() const { - GOOGLE_LOG(FATAL) << "Type " << typeid(*this).name() + GOOGLE_LOG(FATAL) << "Type " << GetTypeName() << " doesn't implement _InternalParse"; return nullptr; } @@ -451,6 +448,11 @@ class PROTOBUF_EXPORT MessageLite { // TODO(gerbens) make this a pure abstract function virtual const void* InternalGetTable() const { return NULL; } + // Fast path when conditions match (ie. non-deterministic) + public: + virtual uint8* InternalSerializeWithCachedSizesToArray(uint8* target) const; + + private: friend class internal::WireFormatLite; friend class Message; friend class internal::WeakFieldMap; diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index 39026379e1..a522966df4 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc @@ -30,18 +30,12 @@ #include -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - #include #include #include #include -#include #include -#include "third_party/absl/strings/str_format.h" #include -#include "util/coding/varint.h" -#include "util/utf8/public/unilib.h" #include @@ -50,8 +44,8 @@ namespace protobuf { namespace internal { bool ParseContext::ParseEndsInSlopRegion(const char* begin, int overrun) const { - ABSL_ASSERT(overrun >= 0); - ABSL_ASSERT(overrun <= kSlopBytes); + GOOGLE_DCHECK(overrun >= 0); + GOOGLE_DCHECK(overrun <= kSlopBytes); auto ptr = begin + overrun; auto end = begin + kSlopBytes; int n = end - ptr; @@ -60,7 +54,7 @@ bool ParseContext::ParseEndsInSlopRegion(const char* begin, int overrun) const { // bytes (or more if on the stack there are further limits) int d = depth_; if (limit_ != -1) { - ABSL_ASSERT(d < start_depth_); // Top-level never has a limit. + GOOGLE_DCHECK(d < start_depth_); // Top-level never has a limit. // rewind the stack until all limits disappear. int limit = limit_; if (limit >= n) return false; @@ -93,7 +87,7 @@ bool ParseContext::ParseEndsInSlopRegion(const char* begin, int overrun) const { // any way so we make no attempt to leave the stream at a well specified pos. while (ptr < end) { uint32 tag; - ptr = Varint::Parse32(ptr, &tag); + ptr = io::Parse32(ptr, &tag); if (ptr == nullptr || ptr > end) return false; // ending on 0 tag is allowed and is the major reason for the necessity of // this function. @@ -101,7 +95,7 @@ bool ParseContext::ParseEndsInSlopRegion(const char* begin, int overrun) const { switch (tag & 7) { case 0: { // Varint uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = io::Parse64(ptr, &val); if (ptr == nullptr) return false; break; } @@ -111,7 +105,7 @@ bool ParseContext::ParseEndsInSlopRegion(const char* begin, int overrun) const { } case 2: { // len delim uint32 size; - ptr = Varint::Parse32(ptr, &size); + ptr = io::Parse32(ptr, &size); if (ptr == nullptr) return false; ptr += size; break; @@ -145,12 +139,12 @@ std::pair ParseContext::ParseRangeWithLimit(const char* begin, const char* end) { auto ptr = begin; do { - ABSL_ASSERT(ptr < end); + GOOGLE_DCHECK(ptr < end); const char* limited_end; if (limit_ == -1) { limited_end = end; } else { - ABSL_ASSERT(limit_ > 0); + GOOGLE_DCHECK(limit_ > 0); limited_end = ptr + std::min(static_cast(end - ptr), limit_); limit_ -= limited_end - ptr; } @@ -159,7 +153,7 @@ std::pair ParseContext::ParseRangeWithLimit(const char* begin, // an end-group. If this is the case we continue parsing the range with // the parent parser. do { - ABSL_ASSERT(ptr < limited_end); + GOOGLE_DCHECK(ptr < limited_end); ptr = parser_(ptr, limited_end, this); if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) { // Clear last_tag_minus_1_ so that the hard error encountered is not @@ -170,16 +164,16 @@ std::pair ParseContext::ParseRangeWithLimit(const char* begin, if (!EndedOnTag()) { // The parser ended still parsing the initial message. This can only // happen because it crossed the end. - ABSL_ASSERT(ptr >= limited_end); + GOOGLE_DCHECK(ptr >= limited_end); break; } // Child parser terminated on an end-group / 0 tag. - ABSL_ASSERT(depth_ <= start_depth_); + GOOGLE_DCHECK(depth_ <= start_depth_); if (depth_ == start_depth_) { // The parse was already at the top-level and there is no parent. // This can happen due to encountering 0 or due to this parser being // called for parsing a sub-group message in custom parsing code. - return {false, ptr - end}; + return {false, static_cast(ptr - end)}; } auto state = Pop(); // Verify the ending tag is correct and continue parsing the range with @@ -192,8 +186,8 @@ std::pair ParseContext::ParseRangeWithLimit(const char* begin, parser_ = state.parser; // Load parent parser } while (ptr < limited_end); int overrun = ptr - limited_end; - ABSL_ASSERT(overrun >= 0); - ABSL_ASSERT(overrun <= kSlopBytes); // wireformat guarantees this limit + GOOGLE_DCHECK(overrun >= 0); + GOOGLE_DCHECK(overrun <= kSlopBytes); // wireformat guarantees this limit if (limit_ != -1) { limit_ -= overrun; // Adjust limit relative to new position. if (limit_ < 0) return {}; // We overrun the limit @@ -201,7 +195,7 @@ std::pair ParseContext::ParseRangeWithLimit(const char* begin, // We are at an actual ending of a length delimited field. // The top level has no limit (ie. limit_ == -1) so we can assert // that the stack is non-empty. - ABSL_ASSERT(depth_ < start_depth_); + GOOGLE_DCHECK(depth_ < start_depth_); // else continue parsing the parent message. auto state = Pop(); parser_ = state.parser; @@ -212,7 +206,7 @@ std::pair ParseContext::ParseRangeWithLimit(const char* begin, } } } while (ptr < end); - return {true, ptr - end}; + return {true, static_cast(ptr - end)}; } const char* StringParser(const char* begin, const char* end, void* object, @@ -222,41 +216,6 @@ const char* StringParser(const char* begin, const char* end, void* object, return end; } -const char* CordParser(const char* begin, const char* end, void* object, - ParseContext* ctx) { - auto cord = static_cast(object); - cord->Append(StringPiece(begin, end - begin)); - return end; -} - -void StringPieceField::Append(const char *begin, size_t chunk_size, int limit) { - if (size_ == 0) { - auto tot = chunk_size + limit; - if (tot > scratch_size_) { - auto old_scratch_size = scratch_size_; - scratch_size_ = tot; - // TODO(gerbens) Security against big - if (arena_ != NULL) { - scratch_ = ::google::protobuf::Arena::CreateArray(arena_, scratch_size_); - } else { - std::allocator().deallocate(scratch_, old_scratch_size); - scratch_ = std::allocator().allocate(scratch_size_); - } - } - data_ = scratch_; - } - std::memcpy(scratch_ + size_, begin, chunk_size); - size_ += chunk_size; -} - -const char* StringPieceParser(const char* begin, const char* end, void* object, - ParseContext* ctx) { - auto s = static_cast(object); - auto limit = ctx->CurrentLimit(); - s->Append(begin, end - begin, limit); - return end; -} - // Defined in wire_format_lite.cc void PrintUTF8ErrorLog(const char* field_name, const char* operation_str, bool emit_stacktrace); @@ -269,14 +228,6 @@ bool VerifyUTF8(StringPiece str, ParseContext* ctx) { return true; } -bool VerifyUTF8Cord(const Cord& value, ParseContext* ctx) { - if (!UniLib::CordIsStructurallyValid(value)) { - PrintUTF8ErrorLog(ctx->extra_parse_data().FieldName(), "parsing", false); - return false; - } - return true; -} - const char* StringParserUTF8(const char* begin, const char* end, void* object, ParseContext* ctx) { StringParser(begin, end, object, ctx); @@ -287,26 +238,6 @@ const char* StringParserUTF8(const char* begin, const char* end, void* object, return end; } -const char* CordParserUTF8(const char* begin, const char* end, void* object, - ParseContext* ctx) { - CordParser(begin, end, object, ctx); - if (ctx->AtLimit()) { - auto str = static_cast(object); - GOOGLE_PROTOBUF_PARSER_ASSERT(VerifyUTF8Cord(*str, ctx)); - } - return end; -} - -const char* StringPieceParserUTF8(const char* begin, const char* end, - void* object, ParseContext* ctx) { - StringPieceParser(begin, end, object, ctx); - if (ctx->AtLimit()) { - auto s = static_cast(object); - GOOGLE_PROTOBUF_PARSER_ASSERT(VerifyUTF8(s->Get(), ctx)); - } - return end; -} - const char* StringParserUTF8Verify(const char* begin, const char* end, void* object, ParseContext* ctx) { StringParser(begin, end, object, ctx); @@ -319,35 +250,12 @@ const char* StringParserUTF8Verify(const char* begin, const char* end, return end; } -const char* CordParserUTF8Verify(const char* begin, const char* end, - void* object, ParseContext* ctx) { - CordParser(begin, end, object, ctx); -#ifndef NDEBUG - if (ctx->AtLimit()) { - auto str = static_cast(object); - VerifyUTF8Cord(*str, ctx); - } -#endif - return end; -} - -const char* StringPieceParserUTF8Verify(const char* begin, const char* end, - void* object, ParseContext* ctx) { - return StringPieceParser(begin, end, object, ctx); -#ifndef NDEBUG - if (ctx->AtLimit()) { - auto s = static_cast(object); - VerifyUTF8(s->Get(), ctx); - } -#endif - return end; -} const char* GreedyStringParser(const char* begin, const char* end, void* object, ParseContext* ctx) { auto str = static_cast(object); auto limit = ctx->CurrentLimit(); - ABSL_ASSERT(limit != -1); // Always length delimited + GOOGLE_DCHECK(limit != -1); // Always length delimited end += std::min(limit, ParseContext::kSlopBytes); str->append(begin, end - begin); return end; @@ -356,7 +264,7 @@ const char* GreedyStringParser(const char* begin, const char* end, void* object, const char* GreedyStringParserUTF8(const char* begin, const char* end, void* object, ParseContext* ctx) { auto limit = ctx->CurrentLimit(); - ABSL_ASSERT(limit != -1); // Always length delimited + GOOGLE_DCHECK(limit != -1); // Always length delimited bool at_end; if (limit <= ParseContext::kSlopBytes) { end += limit; @@ -376,7 +284,7 @@ const char* GreedyStringParserUTF8(const char* begin, const char* end, void* obj const char* GreedyStringParserUTF8Verify(const char* begin, const char* end, void* object, ParseContext* ctx) { auto limit = ctx->CurrentLimit(); - ABSL_ASSERT(limit != -1); // Always length delimited + GOOGLE_DCHECK(limit != -1); // Always length delimited bool at_end; if (limit <= ParseContext::kSlopBytes) { end += limit; @@ -402,7 +310,7 @@ const char* VarintParser(const char* begin, const char* end, void* object, auto ptr = begin; while (ptr < end) { uint64 varint; - ptr = Varint::Parse64(ptr, &varint); + ptr = io::Parse64(ptr, &varint); if (!ptr) return nullptr; T val; if (sign) { @@ -467,7 +375,7 @@ const char* PackedValidEnumParserLite(const char* begin, const char* end, auto ptr = begin; while (ptr < end) { uint64 varint; - ptr = Varint::Parse64(ptr, &varint); + ptr = io::Parse64(ptr, &varint); if (!ptr) return nullptr; int val = varint; if (ctx->extra_parse_data().ValidateEnum(val)) @@ -482,7 +390,7 @@ const char* PackedValidEnumParserLiteArg(const char* begin, const char* end, auto ptr = begin; while (ptr < end) { uint64 varint; - ptr = Varint::Parse64(ptr, &varint); + ptr = io::Parse64(ptr, &varint); if (!ptr) return nullptr; int val = varint; if (ctx->extra_parse_data().ValidateEnumArg(val)) @@ -623,5 +531,3 @@ const char* SlowMapEntryParser(const char* begin, const char* end, void* object, } // namespace internal } // namespace protobuf } // namespace google - -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index c7d37db978..4de3908114 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -31,17 +31,13 @@ #ifndef GOOGLE_PROTOBUF_PARSE_CONTEXT_H__ #define GOOGLE_PROTOBUF_PARSE_CONTEXT_H__ +#include #include -#include - -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER #include +#include #include -#include -#include "third_party/absl/base/optimization.h" #include -#include "util/coding/varint.h" #include @@ -55,7 +51,8 @@ class MessageFactory; namespace internal { // Template code below needs to know about the existence of these functions. -void WriteVarint(uint32 num, uint64 val, std::string* s); +PROTOBUF_EXPORT void WriteVarint(uint32 num, uint64 val, std::string* s); +PROTOBUF_EXPORT void WriteLengthDelimited(uint32 num, StringPiece val, std::string* s); // Inline because it is just forwarding to s->WriteVarint inline void WriteVarint(uint32 num, uint64 val, UnknownFieldSet* s); @@ -141,7 +138,7 @@ struct ParseClosure { // All tag/value pairs between in [begin, retval) are parsed and retval // points to start of a tag. const char* operator()(const char* ptr, const char* end, ParseContext* ctx) { - ABSL_ASSERT(ptr < end); + GOOGLE_DCHECK(ptr < end); return func(ptr, end, object, ctx); } }; @@ -157,7 +154,7 @@ struct ParseClosure { // all the parser code that deals with seams is located in what would otherwise // be error paths of a parser that wouldn't need to deal with seams. -class ParseContext { +class PROTOBUF_EXPORT ParseContext { public: enum { // Tag is atmost 5 bytes, varint is atmost 10 resulting in 15 bytes. We @@ -243,7 +240,7 @@ class ParseContext { inlined_depth_(std::max(0, rec_limit - kInlinedDepth)) {} ~ParseContext() { - if (inlined_depth_ == -1) delete stack_; + if (inlined_depth_ == -1) delete[] stack_; } void StartParse(ParseClosure parser) { parser_ = parser; } @@ -261,9 +258,10 @@ class ParseContext { // EndedOnTag() to find if the parse failed due to an error or ended on // terminating tag. bool ParseRange(StringPiece chunk, int* overrun_ptr) { - ABSL_ASSERT(!chunk.empty()); + GOOGLE_DCHECK(!chunk.empty()); int& overrun = *overrun_ptr; - if (overrun >= chunk.size()) { + GOOGLE_DCHECK(overrun >= 0); + if (overrun >= static_cast(chunk.size())) { // This case can easily happen in patch buffers and we like to inline // this case. overrun -= chunk.size(); @@ -317,7 +315,7 @@ class ParseContext { if (!EndedOnTag()) { // The group hasn't been terminated by an end-group and thus continues, // hence it must have ended because it crossed "end". - ABSL_ASSERT(ptr >= end); + GOOGLE_DCHECK(ptr >= end); return {ptr, true}; } // Verify that the terminating tag matches the start group tag. As an extra @@ -332,7 +330,7 @@ class ParseContext { } void EndGroup(uint32 tag) { - ABSL_ASSERT(tag == 0 || (tag & 7) == 4); + GOOGLE_DCHECK(tag == 0 || (tag & 7) == 4); // Because of the above assert last_tag_minus_1 is never set to 0, and the // caller can verify the child parser was terminated, by comparing to 0. last_tag_minus_1_ = tag - 1; @@ -355,7 +353,7 @@ class ParseContext { // overflow. int64 safe_new_limit = size - static_cast(end - ptr); if (safe_new_limit > INT_MAX) return nullptr; - ABSL_ASSERT(safe_new_limit > 0); // only call this if it's crossing end + GOOGLE_DCHECK(safe_new_limit > 0); // only call this if it's crossing end int32 new_limit = static_cast(safe_new_limit); int32 delta; if (limit_ != -1) { @@ -373,6 +371,10 @@ class ParseContext { } // Helper function for a child group that has crossed the boundary. +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif // defined(__GNUC__) && !defined(__clang__) bool StoreGroup(ParseClosure current_parser, ParseClosure child_parser, int depth, uint32 tag) { // The group must still read an end-group tag, so it can't be at a limit. @@ -386,10 +388,13 @@ class ParseContext { // parse context in this case. We need to make the child parser active. parser_ = child_parser; } - if (ABSL_PREDICT_FALSE(depth < inlined_depth_)) SwitchStack(); + if (PROTOBUF_PREDICT_FALSE(depth < inlined_depth_)) SwitchStack(); stack_[depth] = {current_parser, static_cast(~(tag >> 3))}; return true; } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif // defined(__GNUC__) && !defined(__clang__) private: // This the "active" or current parser. @@ -428,9 +433,9 @@ class ParseContext { int inlined_depth_; bool Push(ParseClosure parser, int32 delta) { - ABSL_ASSERT(delta >= -1); // Make sure it's a valid len-delim + GOOGLE_DCHECK(delta >= -1); // Make sure it's a valid len-delim if (PROTOBUF_PREDICT_FALSE(--depth_ < 0)) return false; - if (ABSL_PREDICT_FALSE(depth_ < inlined_depth_)) SwitchStack(); + if (PROTOBUF_PREDICT_FALSE(depth_ < inlined_depth_)) SwitchStack(); stack_[depth_] = {parser, delta}; return true; } @@ -537,7 +542,7 @@ class EpsCopyParser { // EndedOnTag() on the underlying ParseContext to find out if the parse ended // correctly on a terminating tag. bool Parse(StringPiece range) { - ABSL_ASSERT(!range.empty()); + GOOGLE_DCHECK(!range.empty()); auto size = range.size(); if (size > kSlopBytes) { // The buffer is large enough to be able to parse the (size - kSlopBytes) @@ -563,7 +568,7 @@ class EpsCopyParser { // We care about leaving the stream at the right place and the stream will // indeed terminate, so just parse it. auto res = ParseRange({buffer_, kSlopBytes}, size); - ABSL_ASSERT(!res); + GOOGLE_DCHECK(!res); return false; } return true; @@ -582,7 +587,7 @@ class EpsCopyParser { // The reason of ensure_non_negative_skip and ParseEndsInSlopRegion is that // the following assert holds. Which implies the stream doesn't need to // backup. - ABSL_ASSERT(!ensure_non_negative_skip || overrun_ >= 0); + GOOGLE_DCHECK(!ensure_non_negative_skip || overrun_ >= 0); return overrun_; } @@ -623,7 +628,7 @@ std::pair FieldParser(uint64 tag, ParseClosure parent, const char* end, ParseContext* ctx) { auto ptr = begin; uint32 number = tag >> 3; - if (ABSL_PREDICT_FALSE(number == 0)) { + if (PROTOBUF_PREDICT_FALSE(number == 0)) { GOOGLE_PROTOBUF_ASSERT_RETURN(tag == 0, {}); // Special case scenario of 0 termination. ctx->EndGroup(tag); @@ -633,7 +638,7 @@ std::pair FieldParser(uint64 tag, ParseClosure parent, switch (tag & 7) { case WireType::WIRETYPE_VARINT: { uint64 value; - ptr = Varint::Parse64(ptr, &value); + ptr = io::Parse64(ptr, &value); GOOGLE_PROTOBUF_ASSERT_RETURN(ptr != nullptr, {}); field_parser.AddVarint(number, value); break; @@ -646,7 +651,7 @@ std::pair FieldParser(uint64 tag, ParseClosure parent, } case WireType::WIRETYPE_LENGTH_DELIMITED: { uint32 size; - ptr = Varint::Parse32(ptr, &size); + ptr = io::Parse32(ptr, &size); GOOGLE_PROTOBUF_ASSERT_RETURN(ptr != nullptr, {}); ParseClosure child = field_parser.AddLengthDelimited(number, size); if (size > end - ptr) { @@ -685,7 +690,7 @@ std::pair FieldParser(uint64 tag, ParseClosure parent, default: GOOGLE_PROTOBUF_ASSERT_RETURN(false, {}); } - ABSL_ASSERT(ptr != nullptr); + GOOGLE_DCHECK(ptr != nullptr); return {ptr, false}; } @@ -696,7 +701,7 @@ const char* WireFormatParser(ParseClosure parent, T field_parser, auto ptr = begin; while (ptr < end) { uint32 tag; - ptr = Varint::Parse32(ptr, &tag); + ptr = io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr != nullptr); auto res = FieldParser(tag, parent, field_parser, ptr, end, ctx); ptr = res.first; @@ -714,45 +719,61 @@ const char* WireFormatParser(ParseClosure parent, T field_parser, // caller needs to set prior to the call. // The null parser does not do anything, but is useful as a substitute. +PROTOBUF_EXPORT const char* NullParser(const char* begin, const char* end, void* object, ParseContext*); // Helper for verification of utf8 +PROTOBUF_EXPORT bool VerifyUTF8(StringPiece s, ParseContext* ctx); // All the string parsers with or without UTF checking and for all CTypes. +PROTOBUF_EXPORT const char* StringParser(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* CordParser(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* StringPieceParser(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* StringParserUTF8(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* CordParserUTF8(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* StringPieceParserUTF8(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* StringParserUTF8Verify(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* CordParserUTF8Verify(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* StringPieceParserUTF8Verify(const char* begin, const char* end, void* object, ParseContext*); // Parsers that also eat the slopbytes if possible. Can only be called in a // ParseContext where limit_ is set properly. +PROTOBUF_EXPORT const char* GreedyStringParser(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* GreedyStringParserUTF8(const char* begin, const char* end, void* object, ParseContext*); +PROTOBUF_EXPORT const char* GreedyStringParserUTF8Verify(const char* begin, const char* end, void* object, ParseContext*); // This is the only recursive parser. +PROTOBUF_EXPORT const char* UnknownGroupLiteParse(const char* begin, const char* end, void* object, ParseContext* ctx); // This is a helper to for the UnknownGroupLiteParse but is actually also // useful in the generated code. It uses overload on string* vs // UnknownFieldSet* to make the generated code isomorphic between full and lite. +PROTOBUF_EXPORT std::pair UnknownFieldParse(uint32 tag, ParseClosure parent, const char* begin, const char* end, std::string* unknown, @@ -762,44 +783,60 @@ std::pair UnknownFieldParse(uint32 tag, ParseClosure parent, // corresponding field // These are packed varints +PROTOBUF_EXPORT const char* PackedInt32Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedUInt32Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedInt64Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedUInt64Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedSInt32Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedSInt64Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedBoolParser(const char* begin, const char* end, void* object, ParseContext* ctx); // Enums in proto3 do not require verification +PROTOBUF_EXPORT const char* PackedEnumParser(const char* begin, const char* end, void* object, ParseContext* ctx); // Enums in proto2 require verification. So an additional verification function // needs to be passed into ExtraParseData. // If it's a generated verification function we only need the function pointer. +PROTOBUF_EXPORT const char* PackedValidEnumParserLite(const char* begin, const char* end, void* object, ParseContext* ctx); // If it's reflective we need a function that takes an additional argument. +PROTOBUF_EXPORT const char* PackedValidEnumParserLiteArg(const char* begin, const char* end, void* object, ParseContext* ctx); // These are the packed fixed field parsers. +PROTOBUF_EXPORT const char* PackedFixed32Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedSFixed32Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedFixed64Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedSFixed64Parser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedFloatParser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedDoubleParser(const char* begin, const char* end, void* object, ParseContext* ctx); @@ -808,6 +845,7 @@ const char* PackedDoubleParser(const char* begin, const char* end, void* object, // to a MapField in which we parse the payload upon done (we detect this when // this function is called with limit_ == 0), by calling parse_map (also stored // in ctx) on the resulting string. +PROTOBUF_EXPORT const char* SlowMapEntryParser(const char* begin, const char* end, void* object, internal::ParseContext* ctx); @@ -817,5 +855,4 @@ const char* SlowMapEntryParser(const char* begin, const char* end, void* object, #include -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER #endif // GOOGLE_PROTOBUF_PARSE_CONTEXT_H__ diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 65d0821752..24b3003be3 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -48,10 +48,10 @@ // detect/prohibit anytime it is #included twice without a corresponding // #undef. -// These macros are private and should always be #undef'd from headers. -// If any of these errors fire, you should either properly #include -// port_undef.h at the end of your header that #includes port.h, or -// don't #include port.h twice in a .cc file. +// These macros are private and should always be +// ::util::RetrieveErrorSpace(*this) headers. If any of these errors fire, you +// should either properly #include port_undef.h at the end of your header that +// #includes port.h, or don't #include port.h twice in a .cc file. #ifdef PROTOBUF_NAMESPACE #error PROTOBUF_NAMESPACE was previously defined #endif diff --git a/src/google/protobuf/reflection_ops.cc b/src/google/protobuf/reflection_ops.cc index 233ba7df12..541fee943c 100644 --- a/src/google/protobuf/reflection_ops.cc +++ b/src/google/protobuf/reflection_ops.cc @@ -77,6 +77,10 @@ void ReflectionOps::Merge(const Message& from, Message* to) { const Reflection* from_reflection = GetReflectionOrDie(from); const Reflection* to_reflection = GetReflectionOrDie(*to); + bool is_from_generated = (from_reflection->GetMessageFactory() == + google::protobuf::MessageFactory::generated_factory()); + bool is_to_generated = (to_reflection->GetMessageFactory() == + google::protobuf::MessageFactory::generated_factory()); std::vector fields; from_reflection->ListFields(from, &fields); @@ -84,15 +88,17 @@ void ReflectionOps::Merge(const Message& from, Message* to) { const FieldDescriptor* field = fields[i]; if (field->is_repeated()) { - if (field->is_map()) { - MapFieldBase* from_field = - from_reflection->MapData(const_cast(&from), field); + // Use map reflection if both are in map status and have the + // same map type to avoid sync with repeated field. + // Note: As from and to messages have the same descriptor, the + // map field types are the same if they are both generated + // messages or both dynamic messages. + if (is_from_generated == is_to_generated && field->is_map()) { + const MapFieldBase* from_field = + from_reflection->GetMapData(from, field); MapFieldBase* to_field = - to_reflection->MapData(const_cast(to), field); - // Use map reflection if both are in map status and have the - // same map type to avoid sync with repeated field. - if (to_field->IsMapValid() && from_field->IsMapValid() - && typeid(*from_field) == typeid(*to_field)) { + to_reflection->MutableMapData(to, field); + if (to_field->IsMapValid() && from_field->IsMapValid()) { to_field->MergeFrom(*from_field); continue; } @@ -189,8 +195,8 @@ bool ReflectionOps::IsInitialized(const Message& message) { if (field->is_map()) { const FieldDescriptor* value_field = field->message_type()->field(1); if (value_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - MapFieldBase* map_field = - reflection->MapData(const_cast(&message), field); + const MapFieldBase* map_field = + reflection->GetMapData(message, field); if (map_field->IsMapValid()) { MapIterator iter(const_cast(&message), field); MapIterator end(const_cast(&message), field); @@ -238,6 +244,25 @@ void ReflectionOps::DiscardUnknownFields(Message* message) { const FieldDescriptor* field = fields[i]; if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { if (field->is_repeated()) { + if (field->is_map()) { + const FieldDescriptor* value_field = field->message_type()->field(1); + if (value_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + const MapFieldBase* map_field = + reflection->MutableMapData(message, field); + if (map_field->IsMapValid()) { + MapIterator iter(message, field); + MapIterator end(message, field); + for (map_field->MapBegin(&iter), map_field->MapEnd(&end); + iter != end; ++iter) { + iter.MutableValueRef()->MutableMessageValue() + ->DiscardUnknownFields(); + } + continue; + } + } else { + continue; + } + } int size = reflection->FieldSize(*message, field); for (int j = 0; j < size; j++) { reflection->MutableRepeatedMessage(message, field, j) diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 5ee61e7fcb..ff0668be6b 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -167,13 +167,13 @@ const char* SourceContext::_InternalParse(const char* begin, const char* end, vo ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string file_name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceContext.file_name"); auto str = msg->mutable_file_name(); @@ -190,7 +190,7 @@ const char* SourceContext::_InternalParse(const char* begin, const char* end, vo break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -204,13 +204,9 @@ const char* SourceContext::_InternalParse(const char* begin, const char* end, vo } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool SourceContext::MergePartialFromCodedStream( @@ -283,8 +279,7 @@ void SourceContext::SerializeWithCachedSizes( } ::google::protobuf::uint8* SourceContext::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 10c0148e4f..b3d7834ce2 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -132,7 +132,7 @@ class PROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @@pr void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 464436f9ba..317d5dc156 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -306,14 +306,14 @@ const char* Struct::_InternalParse(const char* begin, const char* end, void* obj ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // map fields = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::SlowMapEntryParser; auto parse_map = ::google::protobuf::Struct_FieldsEntry_DoNotUse::_ParseMap; @@ -329,7 +329,7 @@ const char* Struct::_InternalParse(const char* begin, const char* end, void* obj break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -343,13 +343,9 @@ const char* Struct::_InternalParse(const char* begin, const char* end, void* obj } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Struct::MergePartialFromCodedStream( @@ -470,8 +466,7 @@ void Struct::SerializeWithCachedSizes( } ::google::protobuf::uint8* Struct::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -491,7 +486,7 @@ void Struct::SerializeWithCachedSizes( } }; - if (deterministic && + if (false && this->fields().size() > 1) { ::std::unique_ptr items( new SortItem[this->fields().size()]); @@ -506,7 +501,7 @@ void Struct::SerializeWithCachedSizes( ::std::unique_ptr entry; for (size_type i = 0; i < n; i++) { entry.reset(fields_.NewEntryWrapper(items[static_cast(i)]->first, items[static_cast(i)]->second)); - target = ::google::protobuf::internal::WireFormatLite::InternalWriteMessageNoVirtualToArray(1, *entry, deterministic, target); + target = ::google::protobuf::internal::WireFormatLite::InternalWriteMessageNoVirtualToArray(1, *entry, target); if (entry->GetArena() != nullptr) { entry.release(); } @@ -518,7 +513,7 @@ void Struct::SerializeWithCachedSizes( it = this->fields().begin(); it != this->fields().end(); ++it) { entry.reset(fields_.NewEntryWrapper(it->first, it->second)); - target = ::google::protobuf::internal::WireFormatLite::InternalWriteMessageNoVirtualToArray(1, *entry, deterministic, target); + target = ::google::protobuf::internal::WireFormatLite::InternalWriteMessageNoVirtualToArray(1, *entry, target); if (entry->GetArena() != nullptr) { entry.release(); } @@ -855,14 +850,14 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // .google.protobuf.NullValue null_value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::NullValue value = static_cast<::google::protobuf::NullValue>(val); msg->set_null_value(value); @@ -880,7 +875,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje // string string_value = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Value.string_value"); auto str = msg->mutable_string_value(); @@ -900,7 +895,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_bool_value(value); @@ -909,7 +904,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje // .google.protobuf.Struct struct_value = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Struct::_InternalParse; object = msg->mutable_struct_value(); @@ -924,7 +919,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje // .google.protobuf.ListValue list_value = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ListValue::_InternalParse; object = msg->mutable_list_value(); @@ -937,7 +932,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -951,13 +946,9 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Value::MergePartialFromCodedStream( @@ -1122,8 +1113,7 @@ void Value::SerializeWithCachedSizes( } ::google::protobuf::uint8* Value::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1159,14 +1149,14 @@ void Value::SerializeWithCachedSizes( if (has_struct_value()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 5, HasBitSetters::struct_value(this), deterministic, target); + 5, HasBitSetters::struct_value(this), target); } // .google.protobuf.ListValue list_value = 6; if (has_list_value()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 6, HasBitSetters::list_value(this), deterministic, target); + 6, HasBitSetters::list_value(this), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -1422,14 +1412,14 @@ const char* ListValue::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // repeated .google.protobuf.Value values = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Value::_InternalParse; object = msg->add_values(); @@ -1444,7 +1434,7 @@ const char* ListValue::_InternalParse(const char* begin, const char* end, void* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1458,13 +1448,9 @@ const char* ListValue::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool ListValue::MergePartialFromCodedStream( @@ -1532,8 +1518,7 @@ void ListValue::SerializeWithCachedSizes( } ::google::protobuf::uint8* ListValue::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ListValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1543,7 +1528,7 @@ void ListValue::SerializeWithCachedSizes( n = static_cast(this->values_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 1, this->values(static_cast(i)), deterministic, target); + 1, this->values(static_cast(i)), target); } if (_internal_metadata_.have_unknown_fields()) { diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 857d67d2fd..e44bcbd5ed 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -199,7 +199,7 @@ class PROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc_in void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -344,7 +344,7 @@ class PROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ins void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -562,7 +562,7 @@ class PROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@protoc void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index a434509ef8..50e2b1cb3c 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -2049,7 +2049,7 @@ bool MapFieldPrinterHelper::SortMap( std::vector* sorted_map_field) { bool need_release = false; const MapFieldBase& base = - *reflection->MapData(const_cast(&message), field); + *reflection->GetMapData(message, field); if (base.IsRepeatedFieldValid()) { const RepeatedPtrField& map_field = diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 650c18a48d..bf30404af1 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -182,14 +182,14 @@ const char* Timestamp::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // int64 seconds = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int64 value = val; msg->set_seconds(value); @@ -199,14 +199,14 @@ const char* Timestamp::_InternalParse(const char* begin, const char* end, void* case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_nanos(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -220,13 +220,6 @@ const char* Timestamp::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Timestamp::MergePartialFromCodedStream( @@ -310,8 +303,7 @@ void Timestamp::SerializeWithCachedSizes( } ::google::protobuf::uint8* Timestamp::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Timestamp) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 8f0fba0777..ccb2890a81 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -139,7 +139,7 @@ class PROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@protoc void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index a84e34cacd..1696bfa965 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -509,13 +509,13 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Type.name"); auto str = msg->mutable_name(); @@ -535,7 +535,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Field::_InternalParse; object = msg->add_fields(); @@ -553,7 +553,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Type.oneofs"); auto str = msg->add_oneofs(); @@ -575,7 +575,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -592,7 +592,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec // .google.protobuf.SourceContext source_context = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); @@ -608,14 +608,14 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 48) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); msg->set_syntax(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -629,13 +629,9 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Type::MergePartialFromCodedStream( @@ -811,8 +807,7 @@ void Type::SerializeWithCachedSizes( } ::google::protobuf::uint8* Type::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Type) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -833,7 +828,7 @@ void Type::SerializeWithCachedSizes( n = static_cast(this->fields_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, this->fields(static_cast(i)), deterministic, target); + 2, this->fields(static_cast(i)), target); } // repeated string oneofs = 3; @@ -851,14 +846,14 @@ void Type::SerializeWithCachedSizes( n = static_cast(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 4, this->options(static_cast(i)), deterministic, target); + 4, this->options(static_cast(i)), target); } // .google.protobuf.SourceContext source_context = 5; if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 5, HasBitSetters::source_context(this), deterministic, target); + 5, HasBitSetters::source_context(this), target); } // .google.protobuf.Syntax syntax = 6; @@ -1166,14 +1161,14 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // .google.protobuf.Field.Kind kind = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::Field_Kind value = static_cast<::google::protobuf::Field_Kind>(val); msg->set_kind(value); @@ -1183,7 +1178,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::Field_Cardinality value = static_cast<::google::protobuf::Field_Cardinality>(val); msg->set_cardinality(value); @@ -1193,7 +1188,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_number(value); @@ -1202,7 +1197,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string name = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.name"); auto str = msg->mutable_name(); @@ -1221,7 +1216,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string type_url = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.type_url"); auto str = msg->mutable_type_url(); @@ -1241,7 +1236,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_oneof_index(value); @@ -1251,7 +1246,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 64) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_packed(value); @@ -1261,7 +1256,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -1278,7 +1273,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string json_name = 10; case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.json_name"); auto str = msg->mutable_json_name(); @@ -1297,7 +1292,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string default_value = 11; case 11: { if (static_cast<::google::protobuf::uint8>(tag) != 90) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.default_value"); auto str = msg->mutable_default_value(); @@ -1314,7 +1309,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1328,13 +1323,9 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Field::MergePartialFromCodedStream( @@ -1596,8 +1587,7 @@ void Field::SerializeWithCachedSizes( } ::google::protobuf::uint8* Field::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Field) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1656,7 +1646,7 @@ void Field::SerializeWithCachedSizes( n = static_cast(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 9, this->options(static_cast(i)), deterministic, target); + 9, this->options(static_cast(i)), target); } // string json_name = 10; @@ -2029,13 +2019,13 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Enum.name"); auto str = msg->mutable_name(); @@ -2055,7 +2045,7 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumValue::_InternalParse; object = msg->add_enumvalue(); @@ -2073,7 +2063,7 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -2090,7 +2080,7 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec // .google.protobuf.SourceContext source_context = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); @@ -2106,14 +2096,14 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); msg->set_syntax(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -2127,13 +2117,9 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Enum::MergePartialFromCodedStream( @@ -2283,8 +2269,7 @@ void Enum::SerializeWithCachedSizes( } ::google::protobuf::uint8* Enum::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Enum) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2305,7 +2290,7 @@ void Enum::SerializeWithCachedSizes( n = static_cast(this->enumvalue_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, this->enumvalue(static_cast(i)), deterministic, target); + 2, this->enumvalue(static_cast(i)), target); } // repeated .google.protobuf.Option options = 3; @@ -2313,14 +2298,14 @@ void Enum::SerializeWithCachedSizes( n = static_cast(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, this->options(static_cast(i)), deterministic, target); + 3, this->options(static_cast(i)), target); } // .google.protobuf.SourceContext source_context = 4; if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 4, HasBitSetters::source_context(this), deterministic, target); + 4, HasBitSetters::source_context(this), target); } // .google.protobuf.Syntax syntax = 5; @@ -2581,13 +2566,13 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumValue.name"); auto str = msg->mutable_name(); @@ -2607,7 +2592,7 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_number(value); @@ -2617,7 +2602,7 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -2632,7 +2617,7 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -2646,13 +2631,9 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool EnumValue::MergePartialFromCodedStream( @@ -2763,8 +2744,7 @@ void EnumValue::SerializeWithCachedSizes( } ::google::protobuf::uint8* EnumValue::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2790,7 +2770,7 @@ void EnumValue::SerializeWithCachedSizes( n = static_cast(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, this->options(static_cast(i)), deterministic, target); + 3, this->options(static_cast(i)), target); } if (_internal_metadata_.have_unknown_fields()) { @@ -3052,13 +3032,13 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Option.name"); auto str = msg->mutable_name(); @@ -3077,7 +3057,7 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj // .google.protobuf.Any value = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Any::_InternalParse; object = msg->mutable_value(); @@ -3090,7 +3070,7 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -3104,13 +3084,9 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Option::MergePartialFromCodedStream( @@ -3200,8 +3176,7 @@ void Option::SerializeWithCachedSizes( } ::google::protobuf::uint8* Option::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Option) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -3221,7 +3196,7 @@ void Option::SerializeWithCachedSizes( if (this->has_value()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageToArray( - 2, HasBitSetters::value(this), deterministic, target); + 2, HasBitSetters::value(this), target); } if (_internal_metadata_.have_unknown_fields()) { diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 0df534190d..fe39afb4a1 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -240,7 +240,7 @@ class PROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_inse void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -452,7 +452,7 @@ class PROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ins void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -805,7 +805,7 @@ class PROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_inse void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -994,7 +994,7 @@ class PROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@protoc void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1157,7 +1157,7 @@ class PROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc_in void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index fe3c8250c1..f0f9ee278f 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -54,22 +54,21 @@ const UnknownFieldSet* UnknownFieldSet::default_instance() { } void UnknownFieldSet::ClearFallback() { - GOOGLE_DCHECK(fields_ != NULL && fields_->size() > 0); - int n = fields_->size(); + GOOGLE_DCHECK(!fields_.empty()); + int n = fields_.size(); do { - (*fields_)[--n].Delete(); + (fields_)[--n].Delete(); } while (n > 0); - delete fields_; - fields_ = NULL; + fields_.clear(); } void UnknownFieldSet::InternalMergeFrom(const UnknownFieldSet& other) { int other_field_count = other.field_count(); if (other_field_count > 0) { - fields_ = new std::vector(); + fields_.reserve(fields_.size() + other_field_count); for (int i = 0; i < other_field_count; i++) { - fields_->push_back((*other.fields_)[i]); - fields_->back().DeepCopy((*other.fields_)[i]); + fields_.push_back((other.fields_)[i]); + fields_.back().DeepCopy((other.fields_)[i]); } } } @@ -77,10 +76,10 @@ void UnknownFieldSet::InternalMergeFrom(const UnknownFieldSet& other) { void UnknownFieldSet::MergeFrom(const UnknownFieldSet& other) { int other_field_count = other.field_count(); if (other_field_count > 0) { - if (fields_ == NULL) fields_ = new std::vector(); + fields_.reserve(fields_.size() + other_field_count); for (int i = 0; i < other_field_count; i++) { - fields_->push_back((*other.fields_)[i]); - fields_->back().DeepCopy((*other.fields_)[i]); + fields_.push_back((other.fields_)[i]); + fields_.back().DeepCopy((other.fields_)[i]); } } } @@ -88,16 +87,14 @@ void UnknownFieldSet::MergeFrom(const UnknownFieldSet& other) { // A specialized MergeFrom for performance when we are merging from an UFS that // is temporary and can be destroyed in the process. void UnknownFieldSet::MergeFromAndDestroy(UnknownFieldSet* other) { - int other_field_count = other->field_count(); - if (other_field_count > 0) { - if (fields_ == NULL) fields_ = new std::vector(); - for (int i = 0; i < other_field_count; i++) { - fields_->push_back((*other->fields_)[i]); - (*other->fields_)[i].Reset(); - } + if (fields_.empty()) { + fields_ = std::move(other->fields_); + } else { + fields_.insert(fields_.end(), + std::make_move_iterator(other->fields_.begin()), + std::make_move_iterator(other->fields_.end())); } - delete other->fields_; - other->fields_ = NULL; + other->fields_.clear(); } void UnknownFieldSet::MergeToInternalMetdata( @@ -107,12 +104,12 @@ void UnknownFieldSet::MergeToInternalMetdata( } size_t UnknownFieldSet::SpaceUsedExcludingSelfLong() const { - if (fields_ == NULL) return 0; + if (fields_.empty()) return 0; - size_t total_size = sizeof(*fields_) + sizeof(UnknownField) * fields_->size(); + size_t total_size = sizeof(fields_) + sizeof(UnknownField) * fields_.size(); - for (int i = 0; i < fields_->size(); i++) { - const UnknownField& field = (*fields_)[i]; + for (int i = 0; i < fields_.size(); i++) { + const UnknownField& field = (fields_)[i]; switch (field.type()) { case UnknownField::TYPE_LENGTH_DELIMITED: total_size += sizeof(*field.data_.length_delimited_.string_value_) + @@ -138,8 +135,7 @@ void UnknownFieldSet::AddVarint(int number, uint64 value) { field.number_ = number; field.SetType(UnknownField::TYPE_VARINT); field.data_.varint_ = value; - if (fields_ == NULL) fields_ = new std::vector(); - fields_->push_back(field); + fields_.push_back(field); } void UnknownFieldSet::AddFixed32(int number, uint32 value) { @@ -147,8 +143,7 @@ void UnknownFieldSet::AddFixed32(int number, uint32 value) { field.number_ = number; field.SetType(UnknownField::TYPE_FIXED32); field.data_.fixed32_ = value; - if (fields_ == NULL) fields_ = new std::vector(); - fields_->push_back(field); + fields_.push_back(field); } void UnknownFieldSet::AddFixed64(int number, uint64 value) { @@ -156,8 +151,7 @@ void UnknownFieldSet::AddFixed64(int number, uint64 value) { field.number_ = number; field.SetType(UnknownField::TYPE_FIXED64); field.data_.fixed64_ = value; - if (fields_ == NULL) fields_ = new std::vector(); - fields_->push_back(field); + fields_.push_back(field); } string* UnknownFieldSet::AddLengthDelimited(int number) { @@ -165,8 +159,7 @@ string* UnknownFieldSet::AddLengthDelimited(int number) { field.number_ = number; field.SetType(UnknownField::TYPE_LENGTH_DELIMITED); field.data_.length_delimited_.string_value_ = new string; - if (fields_ == NULL) fields_ = new std::vector(); - fields_->push_back(field); + fields_.push_back(field); return field.data_.length_delimited_.string_value_; } @@ -176,57 +169,44 @@ UnknownFieldSet* UnknownFieldSet::AddGroup(int number) { field.number_ = number; field.SetType(UnknownField::TYPE_GROUP); field.data_.group_ = new UnknownFieldSet; - if (fields_ == NULL) fields_ = new std::vector(); - fields_->push_back(field); + fields_.push_back(field); return field.data_.group_; } void UnknownFieldSet::AddField(const UnknownField& field) { - if (fields_ == NULL) fields_ = new std::vector(); - fields_->push_back(field); - fields_->back().DeepCopy(field); + fields_.push_back(field); + fields_.back().DeepCopy(field); } void UnknownFieldSet::DeleteSubrange(int start, int num) { // Delete the specified fields. for (int i = 0; i < num; ++i) { - (*fields_)[i + start].Delete(); + (fields_)[i + start].Delete(); } // Slide down the remaining fields. - for (int i = start + num; i < fields_->size(); ++i) { - (*fields_)[i - num] = (*fields_)[i]; + for (int i = start + num; i < fields_.size(); ++i) { + (fields_)[i - num] = (fields_)[i]; } // Pop off the # of deleted fields. for (int i = 0; i < num; ++i) { - fields_->pop_back(); - } - if (fields_ && fields_->size() == 0) { - // maintain invariant: never hold fields_ if empty. - delete fields_; - fields_ = NULL; + fields_.pop_back(); } } void UnknownFieldSet::DeleteByNumber(int number) { - if (fields_ == NULL) return; int left = 0; // The number of fields left after deletion. - for (int i = 0; i < fields_->size(); ++i) { - UnknownField* field = &(*fields_)[i]; + for (int i = 0; i < fields_.size(); ++i) { + UnknownField* field = &(fields_)[i]; if (field->number() == number) { field->Delete(); } else { if (i != left) { - (*fields_)[left] = (*fields_)[i]; + (fields_)[left] = (fields_)[i]; } ++left; } } - fields_->resize(left); - if (left == 0) { - // maintain invariant: never hold fields_ if empty. - delete fields_; - fields_ = NULL; - } + fields_.resize(left); } bool UnknownFieldSet::MergeFromCodedStream(io::CodedInputStream* input) { @@ -269,22 +249,6 @@ void UnknownField::Delete() { } } -// Reset all owned ptrs, a special function for performance, to avoid double -// owning the ptrs, when we merge from a temporary UnknownFieldSet objects. -void UnknownField::Reset() { - switch (type()) { - case UnknownField::TYPE_LENGTH_DELIMITED: - data_.length_delimited_.string_value_ = NULL; - break; - case UnknownField::TYPE_GROUP: { - data_.group_ = NULL; - break; - } - default: - break; - } -} - void UnknownField::DeepCopy(const UnknownField& other) { switch (type()) { case UnknownField::TYPE_LENGTH_DELIMITED: @@ -328,7 +292,7 @@ const char* PackedValidEnumParser(const char* begin, const char* end, auto ptr = begin; while (ptr < end) { uint64 varint; - ptr = Varint::Parse64(ptr, &varint); + ptr = io::Parse64(ptr, &varint); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); int val = varint; if (ctx->extra_parse_data().ValidateEnum(val)) @@ -343,7 +307,7 @@ const char* PackedValidEnumParserArg(const char* begin, const char* end, auto ptr = begin; while (ptr < end) { uint64 varint; - ptr = Varint::Parse64(ptr, &varint); + ptr = io::Parse64(ptr, &varint); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); int val = varint; if (ctx->extra_parse_data().ValidateEnumArg(val)) diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h index 0193b2723b..d8335cde16 100644 --- a/src/google/protobuf/unknown_field_set.h +++ b/src/google/protobuf/unknown_field_set.h @@ -176,17 +176,11 @@ class PROTOBUF_EXPORT UnknownFieldSet { // For InternalMergeFrom friend class UnknownField; // Merges from other UnknownFieldSet. This method assumes, that this object - // is newly created and has fields_ == NULL; + // is newly created and has no fields. void InternalMergeFrom(const UnknownFieldSet& other); void ClearFallback(); - // fields_ is either NULL, or a pointer to a vector that is *non-empty*. We - // never hold the empty vector because we want the 'do we have any unknown - // fields' check to be fast, and avoid a cache miss: the UFS instance gets - // embedded in the message object, so 'fields_ != NULL' tests a member - // variable hot in the cache, without the need to go touch a vector somewhere - // else in memory. - std::vector* fields_; + std::vector fields_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet); }; @@ -200,13 +194,16 @@ inline void WriteLengthDelimited(uint32 num, StringPiece val, unknown->AddLengthDelimited(num)->assign(val.data(), val.size()); } +PROTOBUF_EXPORT const char* PackedValidEnumParser(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT const char* PackedValidEnumParserArg(const char* begin, const char* end, void* object, ParseContext* ctx); - +PROTOBUF_EXPORT const char* UnknownGroupParse(const char* begin, const char* end, void* object, ParseContext* ctx); +PROTOBUF_EXPORT std::pair UnknownFieldParse(uint64 tag, ParseClosure parent, const char* begin, const char* end, @@ -262,10 +259,6 @@ class PROTOBUF_EXPORT UnknownField { // If this UnknownField contains a pointer, delete it. void Delete(); - // Reset all the underlying pointers to NULL. A special function to be only - // used while merging from a temporary UFS. - void Reset(); - // Make a deep copy of any pointers in this UnknownField. void DeepCopy(const UnknownField& other); @@ -291,36 +284,34 @@ class PROTOBUF_EXPORT UnknownField { // =================================================================== // inline implementations -inline UnknownFieldSet::UnknownFieldSet() : fields_(NULL) {} +inline UnknownFieldSet::UnknownFieldSet() {} inline UnknownFieldSet::~UnknownFieldSet() { Clear(); } inline void UnknownFieldSet::ClearAndFreeMemory() { Clear(); } inline void UnknownFieldSet::Clear() { - if (fields_ != NULL) { + if (!fields_.empty()) { ClearFallback(); } } inline bool UnknownFieldSet::empty() const { - // Invariant: fields_ is never empty if present. - return !fields_; + return fields_.empty(); } inline void UnknownFieldSet::Swap(UnknownFieldSet* x) { - std::swap(fields_, x->fields_); + fields_.swap(x->fields_); } inline int UnknownFieldSet::field_count() const { - return fields_ ? static_cast(fields_->size()) : 0; + return static_cast(fields_.size()); } inline const UnknownField& UnknownFieldSet::field(int index) const { - GOOGLE_DCHECK(fields_ != NULL); - return (*fields_)[static_cast(index)]; + return (fields_)[static_cast(index)]; } inline UnknownField* UnknownFieldSet::mutable_field(int index) { - return &(*fields_)[static_cast(index)]; + return &(fields_)[static_cast(index)]; } inline void UnknownFieldSet::AddLengthDelimited( diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index 30060fe617..40827cbc97 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -274,6 +274,7 @@ StatusOr DataPiece::ToBytes() const { StatusOr DataPiece::ToEnum(const google::protobuf::Enum* enum_type, bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, bool ignore_unknown_enum_values, bool* is_unknown_enum_value) const { if (type_ == TYPE_NULL) return google::protobuf::NULL_VALUE; @@ -295,11 +296,16 @@ StatusOr DataPiece::ToEnum(const google::protobuf::Enum* enum_type, } // Next try a normalized name. - for (string::iterator it = enum_name.begin(); it != enum_name.end(); ++it) { - *it = *it == '-' ? '_' : ascii_toupper(*it); + bool should_normalize_enum = + case_insensitive_enum_parsing || use_lower_camel_for_enums; + if (should_normalize_enum) { + for (string::iterator it = enum_name.begin(); it != enum_name.end(); + ++it) { + *it = *it == '-' ? '_' : ascii_toupper(*it); + } + value = FindEnumValueByNameOrNull(enum_type, enum_name); + if (value != nullptr) return value->number(); } - value = FindEnumValueByNameOrNull(enum_type, enum_name); - if (value != nullptr) return value->number(); // If use_lower_camel_for_enums is true try with enum name without // underscore. This will also accept camel case names as the enum_name has diff --git a/src/google/protobuf/util/internal/datapiece.h b/src/google/protobuf/util/internal/datapiece.h index 0551ff5ba8..f2628b81b8 100644 --- a/src/google/protobuf/util/internal/datapiece.h +++ b/src/google/protobuf/util/internal/datapiece.h @@ -169,7 +169,10 @@ class PROTOBUF_EXPORT DataPiece { // If none of these succeeds, returns a conversion error status. util::StatusOr ToEnum(const google::protobuf::Enum* enum_type, bool use_lower_camel_for_enums) const { - return ToEnum(enum_type, use_lower_camel_for_enums, false, nullptr); + return ToEnum(enum_type, use_lower_camel_for_enums, + /* ignore_unknown_enum_values */ false, + /* case_insensitive_enum_parsing */ true, + /* is_unknown_enum_value */ nullptr); } private: @@ -186,6 +189,7 @@ class PROTOBUF_EXPORT DataPiece { // unknown enum values. util::StatusOr ToEnum(const google::protobuf::Enum* enum_type, bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, bool ignore_unknown_enum_values, bool* is_unknown_enum_value) const; diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h index 89636dc527..7a8863ca7e 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.h +++ b/src/google/protobuf/util/internal/default_value_objectwriter.h @@ -119,7 +119,7 @@ class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { DefaultValueObjectWriter* RenderBytes(StringPiece name, StringPiece value) override; - DefaultValueObjectWriter* RenderNull(StringPiece name) override; + virtual DefaultValueObjectWriter* RenderNull(StringPiece name); // Register the callback for scrubbing of fields. Owership of // field_scrub_callback pointer is also transferred to this class diff --git a/src/google/protobuf/util/internal/json_objectwriter.h b/src/google/protobuf/util/internal/json_objectwriter.h index 2e19c9b349..ebfc7fbaa9 100644 --- a/src/google/protobuf/util/internal/json_objectwriter.h +++ b/src/google/protobuf/util/internal/json_objectwriter.h @@ -95,20 +95,21 @@ class PROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { virtual ~JsonObjectWriter(); // ObjectWriter methods. - JsonObjectWriter* StartObject(StringPiece name) override; - JsonObjectWriter* EndObject() override; - JsonObjectWriter* StartList(StringPiece name) override; - JsonObjectWriter* EndList() override; - JsonObjectWriter* RenderBool(StringPiece name, bool value) override; - JsonObjectWriter* RenderInt32(StringPiece name, int32 value) override; - JsonObjectWriter* RenderUint32(StringPiece name, uint32 value) override; - JsonObjectWriter* RenderInt64(StringPiece name, int64 value) override; - JsonObjectWriter* RenderUint64(StringPiece name, uint64 value) override; - JsonObjectWriter* RenderDouble(StringPiece name, double value) override; - JsonObjectWriter* RenderFloat(StringPiece name, float value) override; - JsonObjectWriter* RenderString(StringPiece name, StringPiece value) override; - JsonObjectWriter* RenderBytes(StringPiece name, StringPiece value) override; - JsonObjectWriter* RenderNull(StringPiece name) override; + virtual JsonObjectWriter* StartObject(StringPiece name); + virtual JsonObjectWriter* EndObject(); + virtual JsonObjectWriter* StartList(StringPiece name); + virtual JsonObjectWriter* EndList(); + virtual JsonObjectWriter* RenderBool(StringPiece name, bool value); + virtual JsonObjectWriter* RenderInt32(StringPiece name, int32 value); + virtual JsonObjectWriter* RenderUint32(StringPiece name, uint32 value); + virtual JsonObjectWriter* RenderInt64(StringPiece name, int64 value); + virtual JsonObjectWriter* RenderUint64(StringPiece name, uint64 value); + virtual JsonObjectWriter* RenderDouble(StringPiece name, double value); + virtual JsonObjectWriter* RenderFloat(StringPiece name, float value); + virtual JsonObjectWriter* RenderString(StringPiece name, + StringPiece value); + virtual JsonObjectWriter* RenderBytes(StringPiece name, StringPiece value); + virtual JsonObjectWriter* RenderNull(StringPiece name); virtual JsonObjectWriter* RenderNullAsEmpty(StringPiece name); void set_use_websafe_base64_for_bytes(bool value) { diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index 764c9f71d7..83a0c2d333 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -140,7 +140,7 @@ class JsonStreamParserTest : public ::testing::Test { bool allow_empty_null = false) { util::Status result = RunTest(json, split, coerce_utf8, allow_empty_null); - EXPECT_EQ(util::error::INVALID_ARGUMENT, result.error_code()); + EXPECT_EQ(util::error::INVALID_ARGUMENT, result.code()); StringPiece error_message(result.error_message()); EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); } diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc index 391c32ec1d..ec9ef19d15 100644 --- a/src/google/protobuf/util/internal/proto_writer.cc +++ b/src/google/protobuf/util/internal/proto_writer.cc @@ -69,6 +69,7 @@ ProtoWriter::ProtoWriter(TypeResolver* type_resolver, ignore_unknown_fields_(false), ignore_unknown_enum_values_(false), use_lower_camel_for_enums_(false), + case_insensitive_enum_parsing_(true), element_(nullptr), size_insert_(), output_(output), @@ -89,6 +90,7 @@ ProtoWriter::ProtoWriter(const TypeInfo* typeinfo, ignore_unknown_fields_(false), ignore_unknown_enum_values_(false), use_lower_camel_for_enums_(false), + case_insensitive_enum_parsing_(true), element_(nullptr), size_insert_(), output_(output), @@ -589,9 +591,11 @@ Status ProtoWriter::WriteEnum(int field_number, const DataPiece& data, const google::protobuf::Enum* enum_type, CodedOutputStream* stream, bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, bool ignore_unknown_values) { bool is_unknown_enum_value = false; StatusOr e = data.ToEnum(enum_type, use_lower_camel_for_enums, + case_insensitive_enum_parsing, ignore_unknown_values, &is_unknown_enum_value); if (e.ok() && !is_unknown_enum_value) { WireFormatLite::WriteEnum(field_number, e.ValueOrDie(), stream); @@ -689,10 +693,10 @@ ProtoWriter* ProtoWriter::RenderPrimitiveField( break; } case google::protobuf::Field_Kind_TYPE_ENUM: { - status = WriteEnum(field.number(), data, - typeinfo_->GetEnumByTypeUrl(field.type_url()), - stream_.get(), use_lower_camel_for_enums_, - ignore_unknown_enum_values_); + status = WriteEnum( + field.number(), data, typeinfo_->GetEnumByTypeUrl(field.type_url()), + stream_.get(), use_lower_camel_for_enums_, + case_insensitive_enum_parsing_, ignore_unknown_enum_values_); break; } default: // TYPE_GROUP or TYPE_MESSAGE diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h index 1a8df982c3..b67d76e76e 100644 --- a/src/google/protobuf/util/internal/proto_writer.h +++ b/src/google/protobuf/util/internal/proto_writer.h @@ -162,6 +162,10 @@ class PROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { use_lower_camel_for_enums_ = use_lower_camel_for_enums; } + void set_case_insensitive_enum_parsing(bool case_insensitive_enum_parsing) { + case_insensitive_enum_parsing_ = case_insensitive_enum_parsing; + } + protected: class PROTOBUF_EXPORT ProtoElement : public BaseElement, public LocationTrackerInterface { @@ -315,6 +319,7 @@ class PROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { const google::protobuf::Enum* enum_type, io::CodedOutputStream* stream, bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, bool ignore_unknown_values); // Variables for describing the structure of the input tree: @@ -338,6 +343,9 @@ class PROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { // field name. bool use_lower_camel_for_enums_; + // If true, check if enum name in UPPER_CASE matches the field name. + bool case_insensitive_enum_parsing_; + // Variable for internal state processing: // element_ : the current element. // size_insert_: sizes of nested messages. diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 55e8e4bfad..a11d983751 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -783,13 +783,14 @@ Status ProtoStreamObjectSource::RenderField( bool use_type_renderer = type_renderer != nullptr; + RETURN_IF_ERROR(IncrementRecursionDepth(type->name(), field_name)); if (use_type_renderer) { RETURN_IF_ERROR((*type_renderer)(this, *type, field_name, ow)); } else { - RETURN_IF_ERROR(IncrementRecursionDepth(type->name(), field_name)); RETURN_IF_ERROR(WriteMessage(*type, field_name, 0, true, ow)); - --recursion_depth_; } + --recursion_depth_; + if (!stream_->ConsumedEntireMessage()) { return Status(util::error::INVALID_ARGUMENT, "Nested protocol message not parsed in its entirety."); diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h index 5ff8327a48..124a36a1a5 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/src/google/protobuf/util/internal/protostream_objectsource.h @@ -155,9 +155,9 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { const google::protobuf::Type& type, uint32 tag) const; // Renders a field value to the ObjectWriter. - util::Status RenderField(const google::protobuf::Field* field, - StringPiece field_name, - ObjectWriter* ow) const; + virtual util::Status RenderField(const google::protobuf::Field* field, + StringPiece field_name, + ObjectWriter* ow) const; // Reads field value according to Field spec in 'field' and returns the read // value as string. This only works for primitive datatypes (no message diff --git a/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/src/google/protobuf/util/internal/protostream_objectsource_test.cc index 5e2f86f4da..8a8b0c45ac 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource_test.cc @@ -596,7 +596,7 @@ TEST_P(ProtostreamObjectSourceTest, CyclicMessageDepthTest) { } Status status = ExecuteTest(cyclic, Cyclic::descriptor()); - EXPECT_EQ(util::error::INVALID_ARGUMENT, status.error_code()); + EXPECT_EQ(util::error::INVALID_ARGUMENT, status.code()); } class ProtostreamObjectSourceMapsTest : public ProtostreamObjectSourceTest { @@ -941,7 +941,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, MissingTypeUrlError) { ow_.StartObject(""); Status status = ExecuteTest(out, AnyOut::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.error_code()); + EXPECT_EQ(util::error::INTERNAL, status.code()); } TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeServiceError) { @@ -957,7 +957,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeServiceError) { ow_.StartObject(""); Status status = ExecuteTest(out, AnyOut::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.error_code()); + EXPECT_EQ(util::error::INTERNAL, status.code()); } TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeError) { @@ -973,7 +973,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeError) { ow_.StartObject(""); Status status = ExecuteTest(out, AnyOut::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.error_code()); + EXPECT_EQ(util::error::INTERNAL, status.code()); } class ProtostreamObjectSourceStructTest : public ProtostreamObjectSourceTest { @@ -1106,7 +1106,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampBelowMinTest) { ow_.StartObject(""); Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.error_code()); + EXPECT_EQ(util::error::INTERNAL, status.code()); } TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampAboveMaxTest) { @@ -1117,7 +1117,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampAboveMaxTest) { ow_.StartObject(""); Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.error_code()); + EXPECT_EQ(util::error::INTERNAL, status.code()); } TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationBelowMinTest) { @@ -1128,7 +1128,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationBelowMinTest) { ow_.StartObject(""); Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.error_code()); + EXPECT_EQ(util::error::INTERNAL, status.code()); } TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationAboveMaxTest) { @@ -1139,7 +1139,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationAboveMaxTest) { ow_.StartObject(""); Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.error_code()); + EXPECT_EQ(util::error::INTERNAL, status.code()); } TEST_P(ProtostreamObjectSourceTimestampTest, TimestampDurationDefaultValue) { diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc index f2f0f3f08b..9f0e2089d6 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -73,6 +73,7 @@ ProtoStreamObjectWriter::ProtoStreamObjectWriter( set_ignore_unknown_fields(options_.ignore_unknown_fields); set_ignore_unknown_enum_values(options_.ignore_unknown_enum_values); set_use_lower_camel_for_enums(options_.use_lower_camel_for_enums); + set_case_insensitive_enum_parsing(options_.case_insensitive_enum_parsing); } ProtoStreamObjectWriter::ProtoStreamObjectWriter( @@ -85,6 +86,7 @@ ProtoStreamObjectWriter::ProtoStreamObjectWriter( options_(options) { set_ignore_unknown_fields(options_.ignore_unknown_fields); set_use_lower_camel_for_enums(options.use_lower_camel_for_enums); + set_case_insensitive_enum_parsing(options_.case_insensitive_enum_parsing); } ProtoStreamObjectWriter::ProtoStreamObjectWriter( diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.h b/src/google/protobuf/util/internal/protostream_objectwriter.h index bdb70c7027..8c1af58112 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.h +++ b/src/google/protobuf/util/internal/protostream_objectwriter.h @@ -104,6 +104,9 @@ class PROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { // the field name. bool use_lower_camel_for_enums; + // If true, check if enum name in UPPER_CASE matches the field name. + bool case_insensitive_enum_parsing; + // If true, skips rendering the map entry if map value is null unless the // value type is google.protobuf.NullType. bool ignore_null_value_map_entry; @@ -113,6 +116,8 @@ class PROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { ignore_unknown_fields(false), ignore_unknown_enum_values(false), use_lower_camel_for_enums(false), + // TODO(haon): Change this to false by default. + case_insensitive_enum_parsing(true), ignore_null_value_map_entry(false) {} // Default instance of Options with all options set to defaults. diff --git a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc index c4646965bc..da24dd5d47 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc @@ -301,6 +301,65 @@ TEST_P(ProtoStreamObjectWriterTest, IntEnumValuesAreAccepted) { CheckOutput(book); } +TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithDifferentCaseIsRejected) { + Book book; + book.set_title("Some Book"); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.case_insensitive_enum_parsing = false; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "action_and_adventure") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithSameCaseIsAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(google::protobuf::testing::Book_Type_ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.case_insensitive_enum_parsing = false; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "ACTION_AND_ADVENTURE") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithDifferentCaseIsAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(google::protobuf::testing::Book_Type_ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.case_insensitive_enum_parsing = true; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "action_AND_adventure") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithoutUnderscoreAreAccepted) { Book book; book.set_title("Some Book"); @@ -341,6 +400,28 @@ TEST_P(ProtoStreamObjectWriterTest, EnumValuesInCamelCaseAreAccepted) { CheckOutput(book); } +TEST_P(ProtoStreamObjectWriterTest, + EnumValuesInCamelCaseRemoveDashAndUnderscoreAreAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(google::protobuf::testing::Book_Type_ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.use_lower_camel_for_enums = true; + options_.case_insensitive_enum_parsing = false; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "action-And_Adventure") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + TEST_P(ProtoStreamObjectWriterTest, EnumValuesInCamelCaseWithNameNotUppercaseAreAccepted) { Book book; diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc index 8c0b4eb96a..1fcee6374e 100644 --- a/src/google/protobuf/util/json_util.cc +++ b/src/google/protobuf/util/json_util.cc @@ -129,9 +129,9 @@ class StatusErrorListener : public converter::ErrorListener { util::Status GetStatus() { return status_; } - void InvalidName(const converter::LocationTrackerInterface& loc, - StringPiece unknown_name, - StringPiece message) override { + virtual void InvalidName(const converter::LocationTrackerInterface& loc, + StringPiece unknown_name, + StringPiece message) { string loc_string = GetLocString(loc); if (!loc_string.empty()) { loc_string.append(" "); @@ -141,17 +141,17 @@ class StatusErrorListener : public converter::ErrorListener { StrCat(loc_string, unknown_name, ": ", message)); } - void InvalidValue(const converter::LocationTrackerInterface& loc, - StringPiece type_name, - StringPiece value) override { + virtual void InvalidValue(const converter::LocationTrackerInterface& loc, + StringPiece type_name, + StringPiece value) { status_ = util::Status( util::error::INVALID_ARGUMENT, StrCat(GetLocString(loc), ": invalid value ", string(value), " for type ", string(type_name))); } - void MissingField(const converter::LocationTrackerInterface& loc, - StringPiece missing_name) override { + virtual void MissingField(const converter::LocationTrackerInterface& loc, + StringPiece missing_name) { status_ = util::Status(util::error::INVALID_ARGUMENT, StrCat(GetLocString(loc), ": missing field ", string(missing_name))); @@ -186,6 +186,8 @@ util::Status JsonToBinaryStream(TypeResolver* resolver, proto_writer_options.ignore_unknown_fields = options.ignore_unknown_fields; proto_writer_options.ignore_unknown_enum_values = options.ignore_unknown_fields; + proto_writer_options.case_insensitive_enum_parsing = + options.case_insensitive_enum_parsing; converter::ProtoStreamObjectWriter proto_writer(resolver, type, &sink, &listener, proto_writer_options); diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h index 015ca58d10..2e4061540f 100644 --- a/src/google/protobuf/util/json_util.h +++ b/src/google/protobuf/util/json_util.h @@ -52,7 +52,17 @@ struct JsonParseOptions { // Whether to ignore unknown JSON fields during parsing bool ignore_unknown_fields; - JsonParseOptions() : ignore_unknown_fields(false) {} + // If true, when a lowercase enum value fails to parse, try convert it to + // UPPER_CASE and see if it matches a valid enum. + // WARNING: This option exists only to preserve legacy behavior. Avoid using + // this option. If your enum needs to support different casing, consider using + // allow_alias instead. + bool case_insensitive_enum_parsing; + + JsonParseOptions() + : ignore_unknown_fields(false), + // TODO(haon): Change this to false by default. + case_insensitive_enum_parsing(true) {} }; struct JsonPrintOptions { diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 23da45bc57..0f5b396ff1 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -454,6 +454,44 @@ TEST_F(JsonUtilTest, TestParsingUnknownEnumsProto3) { } } +TEST_F(JsonUtilTest, TestParsingEnumIgnoreCase) { + TestMessage m; + { + JsonParseOptions options; + string input = + "{\n" + " \"enum_value\":\"bar\"\n" + "}"; + m.set_enum_value(proto3::FOO); + EXPECT_TRUE(FromJson(input, &m, options)); + // Default behavior is case-insensitive. + // TODO(haon): Change the default behavior to case-sensitive. + ASSERT_EQ(proto3::BAR, m.enum_value()); + } + { + JsonParseOptions options; + options.case_insensitive_enum_parsing = false; + string input = + "{\n" + " \"enum_value\":\"bar\"\n" + "}"; + m.set_enum_value(proto3::FOO); + EXPECT_FALSE(FromJson(input, &m, options)); + ASSERT_EQ(proto3::FOO, m.enum_value()); // Keep previous value + } + { + JsonParseOptions options; + options.case_insensitive_enum_parsing = true; + string input = + "{\n" + " \"enum_value\":\"bar\"\n" + "}"; + m.set_enum_value(proto3::FOO); + EXPECT_TRUE(FromJson(input, &m, options)); + ASSERT_EQ(proto3::BAR, m.enum_value()); + } +} + typedef std::pair Segment; // A ZeroCopyOutputStream that writes to multiple buffers. class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream { @@ -594,7 +632,7 @@ TEST_F(JsonUtilTest, TestWrongJsonInput) { delete resolver; EXPECT_FALSE(result_status.ok()); - EXPECT_EQ(result_status.error_code(), + EXPECT_EQ(result_status.code(), util::error::INVALID_ARGUMENT); } diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index 3e00d07dab..d1183c0b9d 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -1603,10 +1603,10 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( success = success && (match_count == count1); } else { int start_offset = 0; + const bool is_treated_as_smart_set = IsTreatedAsSmartSet(repeated_field); // If the two repeated fields are treated as sets, optimize for the case // where both start with same items stored in the same order. - if (IsTreatedAsSet(repeated_field) || - IsTreatedAsSmartSet(repeated_field) || + if (IsTreatedAsSet(repeated_field) || is_treated_as_smart_set || IsTreatedAsSmartList(repeated_field)) { start_offset = std::min(count1, count2); for (int i = 0; i < count1 && i < count2; i++) { @@ -1623,16 +1623,16 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( for (int i = start_offset; i < count1; ++i) { // Indicates any matched elements for this repeated field. bool match = false; + int matched_j = -1; for (int j = start_offset; j < count2; j++) { if (match_list2->at(j) != -1) { - if (!IsTreatedAsSmartSet(repeated_field) || - num_diffs_list1[i] == 0) { + if (!is_treated_as_smart_set || num_diffs_list1[i] == 0) { continue; } } - if (IsTreatedAsSmartSet(repeated_field)) { + if (is_treated_as_smart_set) { num_diffs_reporter.Reset(); match = IsMatch(repeated_field, key_comparator, &message1, &message2, parent_fields, @@ -1643,7 +1643,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( nullptr, i, j); } - if (IsTreatedAsSmartSet(repeated_field)) { + if (is_treated_as_smart_set) { if (match) { num_diffs_list1[i] = 0; } else if (repeated_field->cpp_type() == @@ -1658,14 +1658,24 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( } if (match) { - match_list1->at(i) = j; - match_list2->at(j) = i; - if (!IsTreatedAsSmartSet(repeated_field) - || num_diffs_list1[i] == 0) { + matched_j = j; + if (!is_treated_as_smart_set || num_diffs_list1[i] == 0) { break; } } } + + match = (matched_j != -1); + if (match) { + if (is_treated_as_smart_set && + match_list2->at(matched_j) != -1) { + // This is to revert the previously matched index in list2. + match_list1->at(match_list2->at(matched_j)) = -1; + match = false; + } + match_list1->at(i) = matched_j; + match_list2->at(matched_j) = i; + } if (!match && reporter == NULL) return false; success = success && match; } diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index 96d0f0c724..f6d7bf1293 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -115,8 +115,9 @@ class PROTOBUF_EXPORT MessageDifferencer { // Determines whether the supplied messages are equal. Equality is defined as // all fields within the two messages being set to the same value. Primitive // fields and strings are compared by value while embedded messages/groups - // are compared as if via a recursive call. Use IgnoreField() and Compare() - // if some fields should be ignored in the comparison. + // are compared as if via a recursive call. Use Compare() with IgnoreField() + // if some fields should be ignored in the comparison. Use Compare() with + // TreatAsSet() if there are repeated fields where ordering does not matter. // // This method REQUIRES that the two messages have the same // Descriptor (message1.GetDescriptor() == message2.GetDescriptor()). diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index 24c05c6935..9ff9d24a77 100644 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -1155,6 +1155,67 @@ TEST(MessageDifferencerTest, RepeatedFieldSmartSetTest) { "modified: rm[2].b -> rm[0].b: 3 -> 0\n", diff_report); } +TEST(MessageDifferencerTest, RepeatedFieldSmartSet_MultipleMatches) { + // Create the testing protos + protobuf_unittest::TestDiffMessage msg1; + protobuf_unittest::TestDiffMessage msg2; + protobuf_unittest::TestField elem1_1, elem2_1, elem3_1; + protobuf_unittest::TestField elem2_2, elem3_2; + + // Only one field is different for each pair of elememts + elem1_1.set_a(1); + elem1_1.set_b(1); + elem1_1.set_c(1); + elem2_1.set_a(2); elem2_2.set_a(2); + elem2_1.set_b(2); elem2_2.set_b(0); + elem2_1.set_c(2); elem2_2.set_c(2); + elem3_1.set_a(3); elem3_2.set_a(3); + elem3_1.set_b(3); elem3_2.set_b(0); + elem3_1.set_c(3); elem3_2.set_c(3); + + + + // In this testcase, elem1_1 will match with elem2_2 first and then get + // reverted because elem2_1 matches with elem2_2 later. + *msg1.add_rm() = elem1_1; + *msg1.add_rm() = elem2_1; + *msg1.add_rm() = elem3_1; + *msg2.add_rm() = elem2_2; + *msg2.add_rm() = elem3_2; + + string diff_report; + util::MessageDifferencer differencer; + differencer.ReportDifferencesToString(&diff_report); + differencer.set_repeated_field_comparison( + util::MessageDifferencer::AS_SMART_SET); + EXPECT_FALSE(differencer.Compare(msg1, msg2)); + EXPECT_EQ("modified: rm[1].b -> rm[0].b: 2 -> 0\n" + "modified: rm[2].b -> rm[1].b: 3 -> 0\n" + "deleted: rm[0]: { c: 1 a: 1 b: 1 }\n", diff_report); +} + +TEST(MessageDifferencerTest, RepeatedFieldSmartSet_MultipleMatchesNoReporter) { + protobuf_unittest::TestDiffMessage msg1; + protobuf_unittest::TestDiffMessage msg2; + protobuf_unittest::TestField elem1, elem2, elem3, elem4; + elem1.set_a(1); + elem2.set_a(2); + elem3.set_a(3); + elem4.set_a(4); + + *msg1.add_rm() = elem1; + *msg1.add_rm() = elem2; + *msg1.add_rm() = elem3; + *msg2.add_rm() = elem2; + *msg2.add_rm() = elem3; + *msg2.add_rm() = elem4; + + util::MessageDifferencer differencer; + differencer.set_repeated_field_comparison( + util::MessageDifferencer::AS_SMART_SET); + EXPECT_FALSE(differencer.Compare(msg1, msg2)); +} + TEST(MessageDifferencerTest, RepeatedFieldSmartSet_NonMessageTypeTest) { // Create the testing protos protobuf_unittest::TestDiffMessage msg1; diff --git a/src/google/protobuf/wire_format.cc b/src/google/protobuf/wire_format.cc index 0342a101a8..1ddc1d51be 100644 --- a/src/google/protobuf/wire_format.cc +++ b/src/google/protobuf/wire_format.cc @@ -907,8 +907,8 @@ void WireFormat::SerializeFieldWithCachedSizes( // internal state and existing references that came from map reflection remain // valid for both reading and writing. if (field->is_map()) { - MapFieldBase* map_field = - message_reflection->MapData(const_cast(&message), field); + const MapFieldBase* map_field = + message_reflection->GetMapData(message, field); if (map_field->IsMapValid()) { if (output->IsSerializationDeterministic()) { std::vector sorted_key_list = @@ -1243,8 +1243,8 @@ size_t WireFormat::FieldDataOnlyByteSize( size_t data_size = 0; if (field->is_map()) { - MapFieldBase* map_field = - message_reflection->MapData(const_cast(&message), field); + const MapFieldBase* map_field = + message_reflection->GetMapData(message, field); if (map_field->IsMapValid()) { MapIterator iter(const_cast(&message), field); MapIterator end(const_cast(&message), field); diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index a393f36765..14ee5a35ef 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -550,19 +550,25 @@ void WireFormatLite::WriteMessage(int field_number, value.SerializeWithCachedSizes(output); } +void WireFormatLite::WriteSubMessageMaybeToArray( + int size, const MessageLite& value, io::CodedOutputStream* output) { + if (!output->IsSerializationDeterministic()) { + uint8* target = output->GetDirectBufferForNBytesAndAdvance(size); + if (target != nullptr) { + uint8* end = value.InternalSerializeWithCachedSizesToArray(target); + GOOGLE_DCHECK_EQ(end - target, size); + return; + } + } + value.SerializeWithCachedSizes(output); +} + void WireFormatLite::WriteGroupMaybeToArray(int field_number, const MessageLite& value, io::CodedOutputStream* output) { WriteTag(field_number, WIRETYPE_START_GROUP, output); const int size = value.GetCachedSize(); - uint8* target = output->GetDirectBufferForNBytesAndAdvance(size); - if (target != NULL) { - uint8* end = value.InternalSerializeWithCachedSizesToArray( - output->IsSerializationDeterministic(), target); - GOOGLE_DCHECK_EQ(end - target, size); - } else { - value.SerializeWithCachedSizes(output); - } + WriteSubMessageMaybeToArray(size, value, output); WriteTag(field_number, WIRETYPE_END_GROUP, output); } @@ -572,14 +578,7 @@ void WireFormatLite::WriteMessageMaybeToArray(int field_number, WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output); const int size = value.GetCachedSize(); output->WriteVarint32(size); - uint8* target = output->GetDirectBufferForNBytesAndAdvance(size); - if (target != NULL) { - uint8* end = value.InternalSerializeWithCachedSizesToArray( - output->IsSerializationDeterministic(), target); - GOOGLE_DCHECK_EQ(end - target, size); - } else { - value.SerializeWithCachedSizes(output); - } + WriteSubMessageMaybeToArray(size, value, output); } PROTOBUF_ALWAYS_INLINE static bool ReadBytesToString( diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index f5768756bc..ed1410ebd3 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -622,12 +622,10 @@ class PROTOBUF_EXPORT WireFormatLite { template INL static uint8* InternalWriteGroupToArray(int field_number, const MessageType& value, - bool deterministic, uint8* target); template INL static uint8* InternalWriteMessageToArray(int field_number, const MessageType& value, - bool deterministic, uint8* target); // Like above, but de-virtualize the call to SerializeWithCachedSizes(). The @@ -636,23 +634,21 @@ class PROTOBUF_EXPORT WireFormatLite { template INL static uint8* InternalWriteGroupNoVirtualToArray(int field_number, const MessageType& value, - bool deterministic, uint8* target); template INL static uint8* InternalWriteMessageNoVirtualToArray( - int field_number, const MessageType& value, bool deterministic, - uint8* target); + int field_number, const MessageType& value, uint8* target); // For backward-compatibility, the last four methods also have versions // that are non-deterministic always. INL static uint8* WriteGroupToArray(int field_number, const MessageLite& value, uint8* target) { - return InternalWriteGroupToArray(field_number, value, false, target); + return InternalWriteGroupToArray(field_number, value, target); } INL static uint8* WriteMessageToArray(int field_number, const MessageLite& value, uint8* target) { - return InternalWriteMessageToArray(field_number, value, false, target); + return InternalWriteMessageToArray(field_number, value, target); } template INL static uint8* WriteGroupNoVirtualToArray(int field_number, @@ -736,6 +732,8 @@ class PROTOBUF_EXPORT WireFormatLite { static const CppType kFieldTypeToCppTypeMap[]; static const WireFormatLite::WireType kWireTypeForFieldType[]; + static void WriteSubMessageMaybeToArray(int size, const MessageLite& value, + io::CodedOutputStream* output); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormatLite); }; diff --git a/src/google/protobuf/wire_format_lite_inl.h b/src/google/protobuf/wire_format_lite_inl.h index 44c4b5ca47..266b1e142c 100644 --- a/src/google/protobuf/wire_format_lite_inl.h +++ b/src/google/protobuf/wire_format_lite_inl.h @@ -889,46 +889,44 @@ inline uint8* WireFormatLite::WriteBytesToArray(int field_number, } -template +template inline uint8* WireFormatLite::InternalWriteGroupToArray( - int field_number, const MessageType& value, bool deterministic, - uint8* target) { + int field_number, const MessageType& value, uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); - target = value.InternalSerializeWithCachedSizesToArray(deterministic, target); + target = value.InternalSerializeWithCachedSizesToArray(target); return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); } -template +template inline uint8* WireFormatLite::InternalWriteMessageToArray( - int field_number, const MessageType& value, bool deterministic, - uint8* target) { + int field_number, const MessageType& value, uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); target = io::CodedOutputStream::WriteVarint32ToArray( static_cast(value.GetCachedSize()), target); - return value.InternalSerializeWithCachedSizesToArray(deterministic, target); + return value.InternalSerializeWithCachedSizesToArray(target); } // See comment on ReadGroupNoVirtual to understand the need for this template // parameter name. -template +template inline uint8* WireFormatLite::InternalWriteGroupNoVirtualToArray( int field_number, const MessageType_WorkAroundCppLookupDefect& value, - bool deterministic, uint8* target) { + uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); target = value.MessageType_WorkAroundCppLookupDefect:: - InternalSerializeWithCachedSizesToArray(deterministic, target); + InternalSerializeWithCachedSizesToArray(target); return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); } -template +template inline uint8* WireFormatLite::InternalWriteMessageNoVirtualToArray( int field_number, const MessageType_WorkAroundCppLookupDefect& value, - bool deterministic, uint8* target) { + uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); target = io::CodedOutputStream::WriteVarint32ToArray( static_cast( value.MessageType_WorkAroundCppLookupDefect::GetCachedSize()), target); return value.MessageType_WorkAroundCppLookupDefect:: - InternalSerializeWithCachedSizesToArray(deterministic, target); + InternalSerializeWithCachedSizesToArray(target); } // =================================================================== diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index fcfbc93761..0d6e413891 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -396,7 +396,7 @@ const char* DoubleValue::_InternalParse(const char* begin, const char* end, void ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // double value = 1; @@ -409,7 +409,7 @@ const char* DoubleValue::_InternalParse(const char* begin, const char* end, void break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -423,13 +423,6 @@ const char* DoubleValue::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool DoubleValue::MergePartialFromCodedStream( @@ -495,8 +488,7 @@ void DoubleValue::SerializeWithCachedSizes( } ::google::protobuf::uint8* DoubleValue::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DoubleValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -693,7 +685,7 @@ const char* FloatValue::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // float value = 1; @@ -706,7 +698,7 @@ const char* FloatValue::_InternalParse(const char* begin, const char* end, void* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -720,13 +712,6 @@ const char* FloatValue::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool FloatValue::MergePartialFromCodedStream( @@ -792,8 +777,7 @@ void FloatValue::SerializeWithCachedSizes( } ::google::protobuf::uint8* FloatValue::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FloatValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -990,21 +974,21 @@ const char* Int64Value::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // int64 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int64 value = val; msg->set_value(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1018,13 +1002,6 @@ const char* Int64Value::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Int64Value::MergePartialFromCodedStream( @@ -1090,8 +1067,7 @@ void Int64Value::SerializeWithCachedSizes( } ::google::protobuf::uint8* Int64Value::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int64Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1290,21 +1266,21 @@ const char* UInt64Value::_InternalParse(const char* begin, const char* end, void ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // uint64 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::uint64 value = val; msg->set_value(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1318,13 +1294,6 @@ const char* UInt64Value::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool UInt64Value::MergePartialFromCodedStream( @@ -1390,8 +1359,7 @@ void UInt64Value::SerializeWithCachedSizes( } ::google::protobuf::uint8* UInt64Value::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt64Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1590,21 +1558,21 @@ const char* Int32Value::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // int32 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_value(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1618,13 +1586,6 @@ const char* Int32Value::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Int32Value::MergePartialFromCodedStream( @@ -1690,8 +1651,7 @@ void Int32Value::SerializeWithCachedSizes( } ::google::protobuf::uint8* Int32Value::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int32Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1890,21 +1850,21 @@ const char* UInt32Value::_InternalParse(const char* begin, const char* end, void ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // uint32 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::uint32 value = val; msg->set_value(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -1918,13 +1878,6 @@ const char* UInt32Value::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool UInt32Value::MergePartialFromCodedStream( @@ -1990,8 +1943,7 @@ void UInt32Value::SerializeWithCachedSizes( } ::google::protobuf::uint8* UInt32Value::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt32Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2190,21 +2142,21 @@ const char* BoolValue::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // bool value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; - ptr = Varint::Parse64(ptr, &val); + ptr = ::google::protobuf::io::Parse64(ptr, &val); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); bool value = val; msg->set_value(value); break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -2218,13 +2170,6 @@ const char* BoolValue::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; - return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool BoolValue::MergePartialFromCodedStream( @@ -2290,8 +2235,7 @@ void BoolValue::SerializeWithCachedSizes( } ::google::protobuf::uint8* BoolValue::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BoolValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2495,13 +2439,13 @@ const char* StringValue::_InternalParse(const char* begin, const char* end, void ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // string value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.StringValue.value"); auto str = msg->mutable_value(); @@ -2518,7 +2462,7 @@ const char* StringValue::_InternalParse(const char* begin, const char* end, void break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -2532,13 +2476,9 @@ const char* StringValue::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool StringValue::MergePartialFromCodedStream( @@ -2611,8 +2551,7 @@ void StringValue::SerializeWithCachedSizes( } ::google::protobuf::uint8* StringValue::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.StringValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2825,13 +2764,13 @@ const char* BytesValue::_InternalParse(const char* begin, const char* end, void* ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; auto ptr = begin; while (ptr < end) { - ptr = Varint::Parse32Inline(ptr, &tag); + ptr = ::google::protobuf::io::Parse32(ptr, &tag); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { // bytes value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = Varint::Parse32Inline(ptr, &size); + ptr = ::google::protobuf::io::Parse32(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); auto str = msg->mutable_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { @@ -2847,7 +2786,7 @@ const char* BytesValue::_InternalParse(const char* begin, const char* end, void* break; } default: { - handle_unusual: (void)&&handle_unusual; + handle_unusual: if ((tag & 7) == 4 || tag == 0) { ctx->EndGroup(tag); return ptr; @@ -2861,13 +2800,9 @@ const char* BytesValue::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; -len_delim_till_end: (void)&&len_delim_till_end; +len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, - {parser_till_end, object}, size); -group_continues: (void)&&group_continues; - GOOGLE_DCHECK(ptr >= end); - GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->StoreGroup({_InternalParse, msg}, {parser_till_end, object}, depth, tag)); - return ptr; + {parser_till_end, object}, size); } #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool BytesValue::MergePartialFromCodedStream( @@ -2932,8 +2867,7 @@ void BytesValue::SerializeWithCachedSizes( } ::google::protobuf::uint8* BytesValue::InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const { - (void)deterministic; // Unused + ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BytesValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 19c248d918..48559c25ea 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -171,7 +171,7 @@ class PROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@prot void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -297,7 +297,7 @@ class PROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@proto void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -423,7 +423,7 @@ class PROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@proto void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -549,7 +549,7 @@ class PROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@prot void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -675,7 +675,7 @@ class PROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@proto void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -801,7 +801,7 @@ class PROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@prot void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -927,7 +927,7 @@ class PROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@protoc void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1053,7 +1053,7 @@ class PROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@prot void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1196,7 +1196,7 @@ class PROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@proto void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const final; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* target) const final; + ::google::protobuf::uint8* target) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: From f8fc10df1c0832cde3c183390fc1d4fea9d92508 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Thu, 20 Dec 2018 15:59:06 -0800 Subject: [PATCH 38/70] Revert change to map_lite_test.proto --- .../src/test/proto/com/google/protobuf/map_lite_test.proto | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto b/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto index 240600f2de..7324653f81 100644 --- a/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto @@ -30,9 +30,10 @@ syntax = "proto3"; -package map_test; +package map_lite_test; -option java_package = "map_test"; +option optimize_for = LITE_RUNTIME; +option java_package = "map_lite_test"; option java_outer_classname = "MapTestProto"; message TestMap { From 152c8301cf36c8e94bf7d7be0f775d49b85ff44d Mon Sep 17 00:00:00 2001 From: Yilun Chong Date: Thu, 20 Dec 2018 17:15:51 -0800 Subject: [PATCH 39/70] Fix python benchmark throughput; Change back to not using docker for benchmar (#5503) --- benchmarks/Makefile.am | 6 +++--- benchmarks/php/PhpBenchmark.php | 1 + benchmarks/python/py_benchmark.py | 2 +- kokoro/linux/benchmark/build.sh | 27 ++++++++++++++++++++++----- tests.sh | 4 ++-- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/benchmarks/Makefile.am b/benchmarks/Makefile.am index a9c69c79b1..6f63a4cc22 100644 --- a/benchmarks/Makefile.am +++ b/benchmarks/Makefile.am @@ -521,10 +521,10 @@ php-benchmark: proto3_middleman_php generate_proto3_data @chmod +x php-benchmark php: php-benchmark proto3_middleman_php - ./php-benchmark $(proto3_data) + ./php-benchmark --behavior_prefix="php" $(proto3_data) php_c_extension: - cd $(top_srcdir)/php/ext/google/protobuf && ./configure CFLAGS='-O3' && make -j8 + cd $(top_srcdir)/php/ext/google/protobuf && phpize && ./configure CFLAGS='-O3' && make -j8 php-c-benchmark: proto3_middleman_php generate_proto3_data php_c_extension php_c_extension mkdir -p "tmp/php/Google/Protobuf/Benchmark" && cp php/PhpBenchmark.php "tmp/php/Google/Protobuf/Benchmark" @@ -540,7 +540,7 @@ php-c-benchmark: proto3_middleman_php generate_proto3_data php_c_extension php_c @chmod +x php-c-benchmark php_c: php-c-benchmark proto3_middleman_php - ./php-c-benchmark $(proto3_data) + ./php-c-benchmark --behavior_prefix="php_c" $(proto3_data) ############ PHP RULES END ################# diff --git a/benchmarks/php/PhpBenchmark.php b/benchmarks/php/PhpBenchmark.php index 7220638762..2c5245d853 100644 --- a/benchmarks/php/PhpBenchmark.php +++ b/benchmarks/php/PhpBenchmark.php @@ -1,6 +1,7 @@ Date: Sat, 17 Nov 2018 16:50:24 -0600 Subject: [PATCH 40/70] Adds the ability to ignore unknown fields on parse This adds the ability for the MRI Ruby library to optionally pass in a ignore_unknown_fields option when decoding JSON. The functionality was added upstream in upb, this change exposes that option. --- conformance/failure_list_ruby.txt | 50 +- ruby/ext/google/protobuf_c/encode_decode.c | 30 +- ruby/ext/google/protobuf_c/message.c | 2 +- ruby/ext/google/protobuf_c/protobuf.h | 2 +- ruby/ext/google/protobuf_c/upb.c | 4118 ++++++++++++++------ ruby/ext/google/protobuf_c/upb.h | 1484 +++++-- ruby/lib/google/protobuf.rb | 4 +- ruby/tests/basic.rb | 13 + 8 files changed, 4058 insertions(+), 1645 deletions(-) diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt index 53b4970164..89270326c4 100644 --- a/conformance/failure_list_ruby.txt +++ b/conformance/failure_list_ruby.txt @@ -5,8 +5,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.DurationHas9FractionalDigits.Validator -Recommended.Proto3.JsonInput.DurationHasZeroFractionalDigit.Validator Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull @@ -17,9 +15,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.TimestampHas9FractionalDigits.Validator -Recommended.Proto3.JsonInput.TimestampHasZeroFractionalDigit.Validator -Recommended.Proto3.JsonInput.TimestampZeroNormalized.Validator Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput @@ -48,12 +43,8 @@ Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput -Required.Proto3.JsonInput.DurationMaxValue.JsonOutput -Required.Proto3.JsonInput.DurationMaxValue.ProtobufOutput Required.Proto3.JsonInput.DurationMinValue.JsonOutput -Required.Proto3.JsonInput.DurationMinValue.ProtobufOutput Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput -Required.Proto3.JsonInput.DurationRepeatedValue.ProtobufOutput Required.Proto3.JsonInput.FieldMask.JsonOutput Required.Proto3.JsonInput.FieldMask.ProtobufOutput Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput @@ -61,71 +52,32 @@ Required.Proto3.JsonInput.FloatFieldNan.JsonOutput Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput Required.Proto3.JsonInput.OneofFieldDuplicate Required.Proto3.JsonInput.OptionalBoolWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalBoolWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalBytesWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalBytesWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalDoubleWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalDoubleWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalFloatWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalFloatWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalInt32Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalInt32Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalInt64Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalInt64Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalStringWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalStringWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalUint32Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalUint32Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalUint64Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalUint64Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput Required.Proto3.JsonInput.RepeatedBoolWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedBoolWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedBytesWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedBytesWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedDoubleWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedDoubleWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedFloatWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedFloatWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedInt32Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedInt32Wrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedInt64Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedInt64Wrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedStringWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedStringWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedUint32Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedUint32Wrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedUint64Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedUint64Wrapper.ProtobufOutput Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput -Required.Proto3.JsonInput.Struct.JsonOutput -Required.Proto3.JsonInput.Struct.ProtobufOutput -Required.Proto3.JsonInput.TimestampMaxValue.JsonOutput -Required.Proto3.JsonInput.TimestampMaxValue.ProtobufOutput +Required.Proto3.JsonInput.TimestampJsonInputTooSmall Required.Proto3.JsonInput.TimestampMinValue.JsonOutput Required.Proto3.JsonInput.TimestampMinValue.ProtobufOutput Required.Proto3.JsonInput.TimestampRepeatedValue.JsonOutput Required.Proto3.JsonInput.TimestampRepeatedValue.ProtobufOutput -Required.Proto3.JsonInput.TimestampWithNegativeOffset.JsonOutput -Required.Proto3.JsonInput.TimestampWithNegativeOffset.ProtobufOutput -Required.Proto3.JsonInput.TimestampWithPositiveOffset.JsonOutput -Required.Proto3.JsonInput.TimestampWithPositiveOffset.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptBool.JsonOutput -Required.Proto3.JsonInput.ValueAcceptBool.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptFloat.JsonOutput -Required.Proto3.JsonInput.ValueAcceptFloat.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptInteger.JsonOutput -Required.Proto3.JsonInput.ValueAcceptInteger.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptList.JsonOutput -Required.Proto3.JsonInput.ValueAcceptList.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptNull.JsonOutput -Required.Proto3.JsonInput.ValueAcceptNull.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptObject.JsonOutput -Required.Proto3.JsonInput.ValueAcceptObject.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptString.JsonOutput -Required.Proto3.JsonInput.ValueAcceptString.ProtobufOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index 0c5a74abd1..a14f0bc80d 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -891,19 +891,38 @@ VALUE Message_decode(VALUE klass, VALUE data) { /* * call-seq: - * MessageClass.decode_json(data) => message + * MessageClass.decode_json(data, options = {}) => message * * Decodes the given data (as a string containing bytes in protocol buffers wire * format) under the interpretration given by this message class's definition * and returns a message object with the corresponding field values. + * + * @param options [Hash] options for the decoder + * ignore_unknown_fields: set true to ignore unknown fields (default is to raise an error) */ -VALUE Message_decode_json(VALUE klass, VALUE data) { +VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned); Descriptor* desc = ruby_to_Descriptor(descriptor); VALUE msgklass = Descriptor_msgclass(descriptor); VALUE msg_rb; + VALUE data = argv[0]; + VALUE ignore_unknown_fields = Qfalse; MessageHeader* msg; + if (argc < 1 || argc > 2) { + rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); + } + + if (argc == 2) { + VALUE hash_args = argv[1]; + if (TYPE(hash_args) != T_HASH) { + rb_raise(rb_eArgError, "Expected hash arguments."); + } + + ignore_unknown_fields = rb_hash_lookup2( + hash_args, ID2SYM(rb_intern("ignore_unknown_fields")), Qfalse); + } + if (TYPE(data) != T_STRING) { rb_raise(rb_eArgError, "Expected string for JSON data."); } @@ -922,7 +941,7 @@ VALUE Message_decode_json(VALUE klass, VALUE data) { stackenv_init(&se, "Error occurred during parsing: %s"); upb_sink_reset(&sink, get_fill_handlers(desc), msg); - parser = upb_json_parser_create(&se.env, method, &sink); + parser = upb_json_parser_create(&se.env, method, &sink, ignore_unknown_fields); upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data), upb_json_parser_input(parser)); @@ -1310,9 +1329,12 @@ VALUE Message_encode(VALUE klass, VALUE msg_rb) { /* * call-seq: - * MessageClass.encode_json(msg) => json_string + * MessageClass.encode_json(msg, options = {}) => json_string * * Encodes the given message object into its serialized JSON representation. + * @param options [Hash] options for the decoder + * preserve_proto_fieldnames: set true to use original fieldnames (default is to camelCase) + * emit_defaults: set true to emit 0/false values (default is to omit them) */ VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned); diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 81a782766f..61823c1de2 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -628,7 +628,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) { rb_define_method(klass, "[]=", Message_index_set, 2); rb_define_singleton_method(klass, "decode", Message_decode, 1); rb_define_singleton_method(klass, "encode", Message_encode, 1); - rb_define_singleton_method(klass, "decode_json", Message_decode_json, 1); + rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1); rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1); rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0); diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 0aa385a09f..616947c251 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -570,7 +570,7 @@ VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value); VALUE Message_descriptor(VALUE klass); VALUE Message_decode(VALUE klass, VALUE data); VALUE Message_encode(VALUE klass, VALUE msg_rb); -VALUE Message_decode_json(VALUE klass, VALUE data); +VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass); VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass); VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb); diff --git a/ruby/ext/google/protobuf_c/upb.c b/ruby/ext/google/protobuf_c/upb.c index c02a5ce4a4..049e2bb061 100644 --- a/ruby/ext/google/protobuf_c/upb.c +++ b/ruby/ext/google/protobuf_c/upb.c @@ -1,9 +1,506 @@ // Amalgamated source file #include "upb.h" +#if UINTPTR_MAX == 0xffffffff +#define UPB_SIZE(size32, size64) size32 +#else +#define UPB_SIZE(size32, size64) size64 +#endif + +#define UPB_FIELD_AT(msg, fieldtype, offset) \ + *(fieldtype*)((const char*)(msg) + offset) + +#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) \ + : 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; +/* 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. */ + +#include + + +static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = { + &google_protobuf_FileDescriptorProto_msginit, +}; + +static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_FileDescriptorSet_msginit = { + &google_protobuf_FileDescriptorSet_submsgs[0], + &google_protobuf_FileDescriptorSet__fields[0], + UPB_SIZE(4, 8), 1, false, +}; + +static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = { + &google_protobuf_DescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_msginit, + &google_protobuf_FieldDescriptorProto_msginit, + &google_protobuf_FileOptions_msginit, + &google_protobuf_ServiceDescriptorProto_msginit, + &google_protobuf_SourceCodeInfo_msginit, +}; + +static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(16, 32), 2, 0, 9, 1}, + {3, UPB_SIZE(40, 80), 0, 0, 9, 3}, + {4, UPB_SIZE(44, 88), 0, 0, 11, 3}, + {5, UPB_SIZE(48, 96), 0, 1, 11, 3}, + {6, UPB_SIZE(52, 104), 0, 4, 11, 3}, + {7, UPB_SIZE(56, 112), 0, 2, 11, 3}, + {8, UPB_SIZE(32, 64), 4, 3, 11, 1}, + {9, UPB_SIZE(36, 72), 5, 5, 11, 1}, + {10, UPB_SIZE(60, 120), 0, 0, 5, 3}, + {11, UPB_SIZE(64, 128), 0, 0, 5, 3}, + {12, UPB_SIZE(24, 48), 3, 0, 9, 1}, +}; + +const upb_msglayout google_protobuf_FileDescriptorProto_msginit = { + &google_protobuf_FileDescriptorProto_submsgs[0], + &google_protobuf_FileDescriptorProto__fields[0], + UPB_SIZE(72, 144), 12, false, +}; + +static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[8] = { + &google_protobuf_DescriptorProto_msginit, + &google_protobuf_DescriptorProto_ExtensionRange_msginit, + &google_protobuf_DescriptorProto_ReservedRange_msginit, + &google_protobuf_EnumDescriptorProto_msginit, + &google_protobuf_FieldDescriptorProto_msginit, + &google_protobuf_MessageOptions_msginit, + &google_protobuf_OneofDescriptorProto_msginit, +}; + +static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(20, 40), 0, 4, 11, 3}, + {3, UPB_SIZE(24, 48), 0, 0, 11, 3}, + {4, UPB_SIZE(28, 56), 0, 3, 11, 3}, + {5, UPB_SIZE(32, 64), 0, 1, 11, 3}, + {6, UPB_SIZE(36, 72), 0, 4, 11, 3}, + {7, UPB_SIZE(16, 32), 2, 5, 11, 1}, + {8, UPB_SIZE(40, 80), 0, 6, 11, 3}, + {9, UPB_SIZE(44, 88), 0, 2, 11, 3}, + {10, UPB_SIZE(48, 96), 0, 0, 9, 3}, +}; + +const upb_msglayout google_protobuf_DescriptorProto_msginit = { + &google_protobuf_DescriptorProto_submsgs[0], + &google_protobuf_DescriptorProto__fields[0], + UPB_SIZE(56, 112), 10, false, +}; + +static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { + &google_protobuf_ExtensionRangeOptions_msginit, +}; + +static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, + {3, UPB_SIZE(12, 16), 3, 0, 11, 1}, +}; + +const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = { + &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], + &google_protobuf_DescriptorProto_ExtensionRange__fields[0], + UPB_SIZE(16, 24), 3, false, +}; + +static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, +}; + +const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = { + NULL, + &google_protobuf_DescriptorProto_ReservedRange__fields[0], + UPB_SIZE(12, 12), 2, false, +}; + +static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = { + {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = { + &google_protobuf_ExtensionRangeOptions_submsgs[0], + &google_protobuf_ExtensionRangeOptions__fields[0], + UPB_SIZE(4, 8), 1, false, +}; + +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}, + {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}, + {9, UPB_SIZE(28, 28), 4, 0, 5, 1}, + {10, UPB_SIZE(64, 96), 9, 0, 9, 1}, +}; + +const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = { + &google_protobuf_FieldDescriptorProto_submsgs[0], + &google_protobuf_FieldDescriptorProto__fields[0], + UPB_SIZE(80, 128), 10, false, +}; + +static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = { + &google_protobuf_OneofOptions_msginit, +}; + +static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(16, 32), 2, 0, 11, 1}, +}; + +const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = { + &google_protobuf_OneofDescriptorProto_submsgs[0], + &google_protobuf_OneofDescriptorProto__fields[0], + UPB_SIZE(24, 48), 2, false, +}; + +static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = { + &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, + &google_protobuf_EnumOptions_msginit, + &google_protobuf_EnumValueDescriptorProto_msginit, +}; + +static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(20, 40), 0, 2, 11, 3}, + {3, UPB_SIZE(16, 32), 2, 1, 11, 1}, + {4, UPB_SIZE(24, 48), 0, 0, 11, 3}, + {5, UPB_SIZE(28, 56), 0, 0, 9, 3}, +}; + +const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = { + &google_protobuf_EnumDescriptorProto_submsgs[0], + &google_protobuf_EnumDescriptorProto__fields[0], + UPB_SIZE(32, 64), 5, false, +}; + +static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, +}; + +const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { + NULL, + &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], + UPB_SIZE(12, 12), 2, false, +}; + +static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { + &google_protobuf_EnumValueOptions_msginit, +}; + +static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = { + {1, UPB_SIZE(8, 16), 2, 0, 9, 1}, + {2, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {3, UPB_SIZE(16, 32), 3, 0, 11, 1}, +}; + +const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = { + &google_protobuf_EnumValueDescriptorProto_submsgs[0], + &google_protobuf_EnumValueDescriptorProto__fields[0], + UPB_SIZE(24, 48), 3, false, +}; + +static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { + &google_protobuf_MethodDescriptorProto_msginit, + &google_protobuf_ServiceOptions_msginit, +}; + +static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(20, 40), 0, 0, 11, 3}, + {3, UPB_SIZE(16, 32), 2, 1, 11, 1}, +}; + +const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = { + &google_protobuf_ServiceDescriptorProto_submsgs[0], + &google_protobuf_ServiceDescriptorProto__fields[0], + UPB_SIZE(24, 48), 3, false, +}; + +static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = { + &google_protobuf_MethodOptions_msginit, +}; + +static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = { + {1, UPB_SIZE(8, 16), 3, 0, 9, 1}, + {2, UPB_SIZE(16, 32), 4, 0, 9, 1}, + {3, UPB_SIZE(24, 48), 5, 0, 9, 1}, + {4, UPB_SIZE(32, 64), 6, 0, 11, 1}, + {5, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {6, UPB_SIZE(2, 2), 2, 0, 8, 1}, +}; + +const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = { + &google_protobuf_MethodDescriptorProto_submsgs[0], + &google_protobuf_MethodDescriptorProto__fields[0], + UPB_SIZE(40, 80), 6, false, +}; + +static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_FileOptions__fields[19] = { + {1, UPB_SIZE(32, 32), 11, 0, 9, 1}, + {8, UPB_SIZE(40, 48), 12, 0, 9, 1}, + {9, UPB_SIZE(8, 8), 1, 0, 14, 1}, + {10, UPB_SIZE(16, 16), 2, 0, 8, 1}, + {11, UPB_SIZE(48, 64), 13, 0, 9, 1}, + {16, UPB_SIZE(17, 17), 3, 0, 8, 1}, + {17, UPB_SIZE(18, 18), 4, 0, 8, 1}, + {18, UPB_SIZE(19, 19), 5, 0, 8, 1}, + {20, UPB_SIZE(20, 20), 6, 0, 8, 1}, + {23, UPB_SIZE(21, 21), 7, 0, 8, 1}, + {27, UPB_SIZE(22, 22), 8, 0, 8, 1}, + {31, UPB_SIZE(23, 23), 9, 0, 8, 1}, + {36, UPB_SIZE(56, 80), 14, 0, 9, 1}, + {37, UPB_SIZE(64, 96), 15, 0, 9, 1}, + {39, UPB_SIZE(72, 112), 16, 0, 9, 1}, + {40, UPB_SIZE(80, 128), 17, 0, 9, 1}, + {41, UPB_SIZE(88, 144), 18, 0, 9, 1}, + {42, UPB_SIZE(24, 24), 10, 0, 8, 1}, + {999, UPB_SIZE(96, 160), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_FileOptions_msginit = { + &google_protobuf_FileOptions_submsgs[0], + &google_protobuf_FileOptions__fields[0], + UPB_SIZE(104, 176), 19, false, +}; + +static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = { + {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {2, UPB_SIZE(2, 2), 2, 0, 8, 1}, + {3, UPB_SIZE(3, 3), 3, 0, 8, 1}, + {7, UPB_SIZE(4, 4), 4, 0, 8, 1}, + {999, UPB_SIZE(8, 8), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_MessageOptions_msginit = { + &google_protobuf_MessageOptions_submsgs[0], + &google_protobuf_MessageOptions__fields[0], + UPB_SIZE(12, 16), 5, false, +}; + +static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = { + {1, UPB_SIZE(8, 8), 1, 0, 14, 1}, + {2, UPB_SIZE(24, 24), 3, 0, 8, 1}, + {3, UPB_SIZE(25, 25), 4, 0, 8, 1}, + {5, UPB_SIZE(26, 26), 5, 0, 8, 1}, + {6, UPB_SIZE(16, 16), 2, 0, 14, 1}, + {10, UPB_SIZE(27, 27), 6, 0, 8, 1}, + {999, UPB_SIZE(28, 32), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_FieldOptions_msginit = { + &google_protobuf_FieldOptions_submsgs[0], + &google_protobuf_FieldOptions__fields[0], + UPB_SIZE(32, 40), 7, false, +}; + +static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = { + {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_OneofOptions_msginit = { + &google_protobuf_OneofOptions_submsgs[0], + &google_protobuf_OneofOptions__fields[0], + UPB_SIZE(4, 8), 1, false, +}; + +static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = { + {2, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {3, UPB_SIZE(2, 2), 2, 0, 8, 1}, + {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_EnumOptions_msginit = { + &google_protobuf_EnumOptions_submsgs[0], + &google_protobuf_EnumOptions__fields[0], + UPB_SIZE(8, 16), 3, false, +}; + +static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = { + {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_EnumValueOptions_msginit = { + &google_protobuf_EnumValueOptions_submsgs[0], + &google_protobuf_EnumValueOptions__fields[0], + UPB_SIZE(8, 16), 2, false, +}; + +static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = { + {33, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_ServiceOptions_msginit = { + &google_protobuf_ServiceOptions_submsgs[0], + &google_protobuf_ServiceOptions__fields[0], + UPB_SIZE(8, 16), 2, false, +}; + +static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = { + {33, UPB_SIZE(16, 16), 2, 0, 8, 1}, + {34, UPB_SIZE(8, 8), 1, 0, 14, 1}, + {999, UPB_SIZE(20, 24), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_MethodOptions_msginit = { + &google_protobuf_MethodOptions_submsgs[0], + &google_protobuf_MethodOptions__fields[0], + UPB_SIZE(24, 32), 3, false, +}; + +static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = { + &google_protobuf_UninterpretedOption_NamePart_msginit, +}; + +static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = { + {2, UPB_SIZE(56, 80), 0, 0, 11, 3}, + {3, UPB_SIZE(32, 32), 4, 0, 9, 1}, + {4, UPB_SIZE(8, 8), 1, 0, 4, 1}, + {5, UPB_SIZE(16, 16), 2, 0, 3, 1}, + {6, UPB_SIZE(24, 24), 3, 0, 1, 1}, + {7, UPB_SIZE(40, 48), 5, 0, 12, 1}, + {8, UPB_SIZE(48, 64), 6, 0, 9, 1}, +}; + +const upb_msglayout google_protobuf_UninterpretedOption_msginit = { + &google_protobuf_UninterpretedOption_submsgs[0], + &google_protobuf_UninterpretedOption__fields[0], + UPB_SIZE(64, 96), 7, false, +}; + +static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = { + {1, UPB_SIZE(8, 16), 2, 0, 9, 2}, + {2, UPB_SIZE(1, 1), 1, 0, 8, 2}, +}; + +const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = { + NULL, + &google_protobuf_UninterpretedOption_NamePart__fields[0], + UPB_SIZE(16, 32), 2, false, +}; + +static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { + &google_protobuf_SourceCodeInfo_Location_msginit, +}; + +static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_SourceCodeInfo_msginit = { + &google_protobuf_SourceCodeInfo_submsgs[0], + &google_protobuf_SourceCodeInfo__fields[0], + UPB_SIZE(4, 8), 1, false, +}; + +static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = { + {1, UPB_SIZE(24, 48), 0, 0, 5, 3}, + {2, UPB_SIZE(28, 56), 0, 0, 5, 3}, + {3, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {4, UPB_SIZE(16, 32), 2, 0, 9, 1}, + {6, UPB_SIZE(32, 64), 0, 0, 9, 3}, +}; + +const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = { + NULL, + &google_protobuf_SourceCodeInfo_Location__fields[0], + UPB_SIZE(40, 80), 5, false, +}; + +static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = { + &google_protobuf_GeneratedCodeInfo_Annotation_msginit, +}; + +static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, +}; + +const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = { + &google_protobuf_GeneratedCodeInfo_submsgs[0], + &google_protobuf_GeneratedCodeInfo__fields[0], + UPB_SIZE(4, 8), 1, false, +}; + +static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { + {1, UPB_SIZE(24, 32), 0, 0, 5, 3}, + {2, UPB_SIZE(16, 16), 3, 0, 9, 1}, + {3, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {4, UPB_SIZE(8, 8), 2, 0, 5, 1}, +}; + +const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = { + NULL, + &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], + UPB_SIZE(32, 48), 4, false, +}; + + + /* Maps descriptor type -> upb field type. */ -static const uint8_t upb_desctype_to_fieldtype[] = { +const uint8_t upb_desctype_to_fieldtype[] = { UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */ UPB_TYPE_DOUBLE, /* DOUBLE */ UPB_TYPE_FLOAT, /* FLOAT */ @@ -27,7 +524,6 @@ static const uint8_t upb_desctype_to_fieldtype[] = { /* Data pertaining to the parse. */ typedef struct { - upb_env *env; /* Current decoding pointer. Points to the beginning of a field until we * have finished decoding the whole field. */ const char *ptr; @@ -40,7 +536,7 @@ typedef struct { /* These members are unset for an unknown group frame. */ char *msg; - const upb_msglayout_msginit_v1 *m; + const upb_msglayout *m; } upb_decframe; #define CHK(x) if (!(x)) { return false; } @@ -49,7 +545,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number, const char *limit); static bool upb_decode_message(upb_decstate *d, const char *limit, int group_number, char *msg, - const upb_msglayout_msginit_v1 *l); + const upb_msglayout *l); static bool upb_decode_varint(const char **ptr, const char *limit, uint64_t *val) { @@ -130,9 +626,7 @@ static void upb_set32(void *msg, size_t ofs, uint32_t val) { static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame, const char *start) { - UPB_UNUSED(d); - UPB_UNUSED(frame); - UPB_UNUSED(start); + upb_msg_addunknown(frame->msg, start, d->ptr - start); return true; } @@ -171,6 +665,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) { size_t new_bytes; size_t old_bytes; void *new_data; + upb_alloc *alloc = upb_arena_alloc(arr->arena); while (new_size < needed) { new_size *= 2; @@ -178,7 +673,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) { old_bytes = arr->len * arr->element_size; new_bytes = new_size * arr->element_size; - new_data = upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes); + new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes); CHK(new_data); arr->data = new_data; @@ -200,23 +695,21 @@ static void *upb_array_add(upb_array *arr, size_t elements) { } static upb_array *upb_getarr(upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { UPB_ASSERT(field->label == UPB_LABEL_REPEATED); return *(upb_array**)&frame->msg[field->offset]; } -static upb_array *upb_getorcreatearr(upb_decstate *d, - upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { +static upb_array *upb_getorcreatearr(upb_decframe *frame, + const upb_msglayout_field *field) { upb_array *arr = upb_getarr(frame, field); if (!arr) { - arr = upb_env_malloc(d->env, sizeof(*arr)); + upb_fieldtype_t type = upb_desctype_to_fieldtype[field->descriptortype]; + arr = upb_array_new(type, upb_msg_arena(frame->msg)); if (!arr) { return NULL; } - upb_array_init(arr, upb_desctype_to_fieldtype[field->type], - upb_arena_alloc(upb_env_arena(d->env))); *(upb_array**)&frame->msg[field->offset] = arr; } @@ -224,26 +717,25 @@ static upb_array *upb_getorcreatearr(upb_decstate *d, } static void upb_sethasbit(upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { - UPB_ASSERT(field->hasbit != UPB_NO_HASBIT); - frame->msg[field->hasbit / 8] |= (1 << (field->hasbit % 8)); + 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_fieldinit_v1 *field) { - UPB_ASSERT(field->oneof_index != UPB_NOT_IN_ONEOF); - upb_set32(frame->msg, frame->m->oneofs[field->oneof_index].case_offset, - field->number); + const upb_msglayout_field *field) { + UPB_ASSERT(field->presence < 0); + upb_set32(frame->msg, ~field->presence, field->number); } -static char *upb_decode_prepareslot(upb_decstate *d, - upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { +static char *upb_decode_prepareslot(upb_decframe *frame, + const upb_msglayout_field *field) { char *field_mem = frame->msg + field->offset; upb_array *arr; if (field->label == UPB_LABEL_REPEATED) { - arr = upb_getorcreatearr(d, frame, field); + arr = upb_getorcreatearr(frame, field); field_mem = upb_array_reserve(arr, 1); } @@ -251,36 +743,33 @@ static char *upb_decode_prepareslot(upb_decstate *d, } static void upb_decode_setpresent(upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { + 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->oneof_index != UPB_NOT_IN_ONEOF) { + } else if (field->presence < 0) { upb_setoneofcase(frame, field); - } else if (field->hasbit != UPB_NO_HASBIT) { + } else if (field->presence > 0) { upb_sethasbit(frame, field); } } -static bool upb_decode_submsg(upb_decstate *d, - upb_decframe *frame, +static bool upb_decode_submsg(upb_decstate *d, upb_decframe *frame, const char *limit, - const upb_msglayout_fieldinit_v1 *field, + const upb_msglayout_field *field, int group_number) { - char *submsg = *(void**)&frame->msg[field->offset]; - const upb_msglayout_msginit_v1 *subm; + char *submsg_slot = upb_decode_prepareslot(frame, field); + char *submsg = *(void **)submsg_slot; + const upb_msglayout *subm; - UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG); subm = frame->m->submsgs[field->submsg_index]; UPB_ASSERT(subm); if (!submsg) { - submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm)); + submsg = upb_msg_new(subm, upb_msg_arena(frame->msg)); CHK(submsg); - submsg = upb_msg_init( - submsg, (upb_msglayout*)subm, upb_arena_alloc(upb_env_arena(d->env))); - *(void**)&frame->msg[field->offset] = submsg; + *(void**)submsg_slot = submsg; } upb_decode_message(d, limit, group_number, submsg, subm); @@ -290,15 +779,15 @@ static bool upb_decode_submsg(upb_decstate *d, static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { uint64_t val; void *field_mem; - field_mem = upb_decode_prepareslot(d, frame, field); + field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); CHK(upb_decode_varint(&d->ptr, frame->limit, &val)); - switch ((upb_descriptortype_t)field->type) { + switch ((upb_descriptortype_t)field->descriptortype) { case UPB_DESCRIPTOR_TYPE_INT64: case UPB_DESCRIPTOR_TYPE_UINT64: memcpy(field_mem, &val, sizeof(val)); @@ -335,15 +824,15 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { void *field_mem; uint64_t val; - field_mem = upb_decode_prepareslot(d, frame, field); + field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); CHK(upb_decode_64bit(&d->ptr, frame->limit, &val)); - switch ((upb_descriptortype_t)field->type) { + switch ((upb_descriptortype_t)field->descriptortype) { case UPB_DESCRIPTOR_TYPE_DOUBLE: case UPB_DESCRIPTOR_TYPE_FIXED64: case UPB_DESCRIPTOR_TYPE_SFIXED64: @@ -359,15 +848,15 @@ static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame, static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { void *field_mem; uint32_t val; - field_mem = upb_decode_prepareslot(d, frame, field); + field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); CHK(upb_decode_32bit(&d->ptr, frame->limit, &val)); - switch ((upb_descriptortype_t)field->type) { + switch ((upb_descriptortype_t)field->descriptortype) { case UPB_DESCRIPTOR_TYPE_FLOAT: case UPB_DESCRIPTOR_TYPE_FIXED32: case UPB_DESCRIPTOR_TYPE_SFIXED32: @@ -395,9 +884,9 @@ static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data, static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field, + const upb_msglayout_field *field, upb_stringview val) { - upb_array *arr = upb_getorcreatearr(d, frame, field); + upb_array *arr = upb_getorcreatearr(frame, field); #define VARINT_CASE(ctype, decode) { \ const char *ptr = val.data; \ @@ -415,7 +904,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, return true; \ } - switch ((upb_descriptortype_t)field->type) { + switch ((upb_descriptortype_t)field->descriptortype) { case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_BYTES: { void *field_mem = upb_array_add(arr, 1); @@ -445,9 +934,28 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, VARINT_CASE(int32_t, upb_zzdecode_32); case UPB_DESCRIPTOR_TYPE_SINT64: VARINT_CASE(int64_t, upb_zzdecode_64); - case UPB_DESCRIPTOR_TYPE_MESSAGE: + case UPB_DESCRIPTOR_TYPE_MESSAGE: { + const upb_msglayout *subm; + char *submsg; + void *field_mem; + CHK(val.size <= (size_t)(frame->limit - val.data)); - return upb_decode_submsg(d, frame, val.data + val.size, field, 0); + d->ptr -= val.size; + + /* Create elemente message. */ + subm = frame->m->submsgs[field->submsg_index]; + UPB_ASSERT(subm); + + submsg = upb_msg_new(subm, upb_msg_arena(frame->msg)); + CHK(submsg); + + field_mem = upb_array_add(arr, 1); + CHK(field_mem); + *(void**)field_mem = submsg; + + return upb_decode_message( + d, val.data + val.size, frame->group_number, submsg, subm); + } case UPB_DESCRIPTOR_TYPE_GROUP: return upb_append_unknown(d, frame, field_start); } @@ -457,7 +965,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { upb_stringview val; CHK(upb_decode_string(&d->ptr, frame->limit, &val)); @@ -465,16 +973,17 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, if (field->label == UPB_LABEL_REPEATED) { return upb_decode_toarray(d, frame, field_start, field, val); } else { - switch ((upb_descriptortype_t)field->type) { + switch ((upb_descriptortype_t)field->descriptortype) { case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_BYTES: { - void *field_mem = upb_decode_prepareslot(d, frame, field); + void *field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); memcpy(field_mem, &val, sizeof(val)); break; } case UPB_DESCRIPTOR_TYPE_MESSAGE: CHK(val.size <= (size_t)(frame->limit - val.data)); + d->ptr -= val.size; CHK(upb_decode_submsg(d, frame, val.data + val.size, field, 0)); break; default: @@ -486,8 +995,8 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, } } -static const upb_msglayout_fieldinit_v1 *upb_find_field( - const upb_msglayout_msginit_v1 *l, uint32_t field_number) { +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++) { @@ -503,7 +1012,7 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { int field_number; int wire_type; const char *field_start = d->ptr; - const upb_msglayout_fieldinit_v1 *field; + const upb_msglayout_field *field; CHK(upb_decode_tag(&d->ptr, frame->limit, &field_number, &wire_type)); field = upb_find_field(frame->m, field_number); @@ -519,7 +1028,7 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { case UPB_WIRE_TYPE_DELIMITED: return upb_decode_delimitedfield(d, frame, field_start, field); case UPB_WIRE_TYPE_START_GROUP: - CHK(field->type == UPB_DESCRIPTOR_TYPE_GROUP); + CHK(field->descriptortype == UPB_DESCRIPTOR_TYPE_GROUP); return upb_decode_submsg(d, frame, frame->limit, field, field_number); case UPB_WIRE_TYPE_END_GROUP: CHK(frame->group_number == field_number) @@ -530,7 +1039,9 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { } } else { CHK(field_number != 0); - return upb_skip_unknownfielddata(d, frame, field_number, wire_type); + CHK(upb_skip_unknownfielddata(d, frame, field_number, wire_type)); + CHK(upb_append_unknown(d, frame, field_start)); + return true; } } @@ -555,7 +1066,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number, static bool upb_decode_message(upb_decstate *d, const char *limit, int group_number, char *msg, - const upb_msglayout_msginit_v1 *l) { + const upb_msglayout *l) { upb_decframe frame; frame.group_number = group_number; frame.limit = limit; @@ -569,11 +1080,9 @@ static bool upb_decode_message(upb_decstate *d, const char *limit, return true; } -bool upb_decode(upb_stringview buf, void *msg, - const upb_msglayout_msginit_v1 *l, upb_env *env) { +bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l) { upb_decstate state; state.ptr = buf.data; - state.env = env; return upb_decode_message(&state, buf.data + buf.size, 0, msg, l); } @@ -943,6 +1452,45 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { return true; } +static void assign_msg_wellknowntype(upb_msgdef *m) { + const char *name = upb_msgdef_fullname(m); + if (name == NULL) { + m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; + return; + } + if (!strcmp(name, "google.protobuf.Duration")) { + m->well_known_type = UPB_WELLKNOWN_DURATION; + } else if (!strcmp(name, "google.protobuf.Timestamp")) { + m->well_known_type = UPB_WELLKNOWN_TIMESTAMP; + } else if (!strcmp(name, "google.protobuf.DoubleValue")) { + m->well_known_type = UPB_WELLKNOWN_DOUBLEVALUE; + } else if (!strcmp(name, "google.protobuf.FloatValue")) { + m->well_known_type = UPB_WELLKNOWN_FLOATVALUE; + } else if (!strcmp(name, "google.protobuf.Int64Value")) { + m->well_known_type = UPB_WELLKNOWN_INT64VALUE; + } else if (!strcmp(name, "google.protobuf.UInt64Value")) { + m->well_known_type = UPB_WELLKNOWN_UINT64VALUE; + } else if (!strcmp(name, "google.protobuf.Int32Value")) { + m->well_known_type = UPB_WELLKNOWN_INT32VALUE; + } else if (!strcmp(name, "google.protobuf.UInt32Value")) { + m->well_known_type = UPB_WELLKNOWN_UINT32VALUE; + } else if (!strcmp(name, "google.protobuf.BoolValue")) { + m->well_known_type = UPB_WELLKNOWN_BOOLVALUE; + } else if (!strcmp(name, "google.protobuf.StringValue")) { + m->well_known_type = UPB_WELLKNOWN_STRINGVALUE; + } else if (!strcmp(name, "google.protobuf.BytesValue")) { + m->well_known_type = UPB_WELLKNOWN_BYTESVALUE; + } else if (!strcmp(name, "google.protobuf.Value")) { + m->well_known_type = UPB_WELLKNOWN_VALUE; + } else if (!strcmp(name, "google.protobuf.ListValue")) { + m->well_known_type = UPB_WELLKNOWN_LISTVALUE; + } else if (!strcmp(name, "google.protobuf.Struct")) { + m->well_known_type = UPB_WELLKNOWN_STRUCT; + } else { + m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; + } +} + bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { size_t i; @@ -979,6 +1527,8 @@ bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { if (!assign_msg_indices(m, s)) { goto err; } + assign_msg_wellknowntype(m); + /* m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; */ } else if (e) { upb_inttable_compact(&e->iton); } @@ -2171,6 +2721,16 @@ bool upb_msgdef_mapentry(const upb_msgdef *m) { return m->map_entry; } +upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m) { + return m->well_known_type; +} + +bool upb_msgdef_isnumberwrapper(const upb_msgdef *m) { + upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); + return type >= UPB_WELLKNOWN_DOUBLEVALUE && + type <= UPB_WELLKNOWN_UINT32VALUE; +} + void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { upb_inttable_begin(iter, &m->itof); } @@ -2985,7 +3545,7 @@ static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); } static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); } typedef struct { - upb_env *env; + upb_alloc *alloc; char *buf, *ptr, *limit; } upb_encstate; @@ -3000,11 +3560,11 @@ static size_t upb_roundup_pow2(size_t bytes) { static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) { size_t old_size = e->limit - e->buf; size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char *new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size); + char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size); CHK(new_buf); /* We want previous data at the end, realloc() put it at the beginning. */ - memmove(e->limit - old_size, e->buf, old_size); + memmove(new_buf + new_size - old_size, e->buf, old_size); e->ptr = new_buf + new_size - (e->limit - e->ptr); e->limit = new_buf + new_size; @@ -3064,17 +3624,17 @@ static bool upb_put_float(upb_encstate *e, float d) { return upb_put_fixed32(e, u32); } -static uint32_t upb_readcase(const char *msg, const upb_msglayout_msginit_v1 *m, - int oneof_index) { +static uint32_t upb_readcase(const char *msg, const upb_msglayout_field *f) { uint32_t ret; - memcpy(&ret, msg + m->oneofs[oneof_index].case_offset, sizeof(ret)); + uint32_t offset = ~f->presence; + memcpy(&ret, msg + offset, sizeof(ret)); return ret; } -static bool upb_readhasbit(const char *msg, - const upb_msglayout_fieldinit_v1 *f) { - UPB_ASSERT(f->hasbit != UPB_NO_HASBIT); - return msg[f->hasbit / 8] & (1 << (f->hasbit % 8)); +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)); } static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) { @@ -3088,19 +3648,18 @@ static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr, } bool upb_encode_message(upb_encstate *e, const char *msg, - const upb_msglayout_msginit_v1 *m, - size_t *size); + const upb_msglayout *m, size_t *size); static bool upb_encode_array(upb_encstate *e, const char *field_mem, - const upb_msglayout_msginit_v1 *m, - const upb_msglayout_fieldinit_v1 *f) { + 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; } - UPB_ASSERT(arr->type == upb_desctype_to_fieldtype2[f->type]); + UPB_ASSERT(arr->type == upb_desctype_to_fieldtype2[f->descriptortype]); #define VARINT_CASE(ctype, encode) { \ ctype *start = arr->data; \ @@ -3115,7 +3674,7 @@ static bool upb_encode_array(upb_encstate *e, const char *field_mem, break; \ do { ; } while(0) - switch (f->type) { + switch (f->descriptortype) { case UPB_DESCRIPTOR_TYPE_DOUBLE: CHK(upb_put_fixedarray(e, arr, sizeof(double))); break; @@ -3134,9 +3693,10 @@ do { ; } while(0) 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(uint32_t, *ptr); + VARINT_CASE(int32_t, (int64_t)*ptr); case UPB_DESCRIPTOR_TYPE_BOOL: VARINT_CASE(bool, *ptr); case UPB_DESCRIPTOR_TYPE_SINT32: @@ -3158,7 +3718,7 @@ do { ; } while(0) case UPB_DESCRIPTOR_TYPE_GROUP: { void **start = arr->data; void **ptr = start + arr->len; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; do { size_t size; ptr--; @@ -3171,7 +3731,7 @@ do { ; } while(0) case UPB_DESCRIPTOR_TYPE_MESSAGE: { void **start = arr->data; void **ptr = start + arr->len; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; do { size_t size; ptr--; @@ -3191,11 +3751,9 @@ do { ; } while(0) } static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, - const upb_msglayout_msginit_v1 *m, - const upb_msglayout_fieldinit_v1 *f, - bool is_proto3) { - bool skip_zero_value = is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF; - + const upb_msglayout *m, + const upb_msglayout_field *f, + bool skip_zero_value) { #define CASE(ctype, type, wire_type, encodeval) do { \ ctype val = *(ctype*)field_mem; \ if (skip_zero_value && val == 0) { \ @@ -3205,7 +3763,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, upb_put_tag(e, f->number, wire_type); \ } while(0) - switch (f->type) { + switch (f->descriptortype) { case UPB_DESCRIPTOR_TYPE_DOUBLE: CASE(double, double, UPB_WIRE_TYPE_64BIT, val); case UPB_DESCRIPTOR_TYPE_FLOAT: @@ -3214,9 +3772,10 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, case UPB_DESCRIPTOR_TYPE_UINT64: CASE(uint64_t, varint, UPB_WIRE_TYPE_VARINT, val); case UPB_DESCRIPTOR_TYPE_UINT32: + CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); case UPB_DESCRIPTOR_TYPE_INT32: case UPB_DESCRIPTOR_TYPE_ENUM: - CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); + CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, (int64_t)val); case UPB_DESCRIPTOR_TYPE_SFIXED64: case UPB_DESCRIPTOR_TYPE_FIXED64: CASE(uint64_t, fixed64, UPB_WIRE_TYPE_64BIT, val); @@ -3241,9 +3800,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, } case UPB_DESCRIPTOR_TYPE_GROUP: { size_t size; - void *submsg = *(void**)field_mem; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; - if (skip_zero_value && submsg == NULL) { + 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) && @@ -3252,9 +3811,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, } case UPB_DESCRIPTOR_TYPE_MESSAGE: { size_t size; - void *submsg = *(void**)field_mem; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; - if (skip_zero_value && submsg == NULL) { + 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) && @@ -3266,49 +3825,52 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, UPB_UNREACHABLE(); } -bool upb_encode_hasscalarfield(const char *msg, - const upb_msglayout_msginit_v1 *m, - const upb_msglayout_fieldinit_v1 *f) { - if (f->oneof_index != UPB_NOT_IN_ONEOF) { - return upb_readcase(msg, m, f->oneof_index) == f->number; - } else if (m->is_proto2) { - return upb_readhasbit(msg, f); - } else { - /* For proto3, we'll test for the field being empty later. */ - return true; - } -} - -bool upb_encode_message(upb_encstate* e, const char *msg, - const upb_msglayout_msginit_v1 *m, - size_t *size) { +bool upb_encode_message(upb_encstate *e, const char *msg, + const upb_msglayout *m, size_t *size) { int i; - char *buf_end = e->ptr; - - if (msg == NULL) { - return true; - } + size_t pre_len = e->limit - e->ptr; + const char *unknown; + size_t unknown_size; for (i = m->field_count - 1; i >= 0; i--) { - const upb_msglayout_fieldinit_v1 *f = &m->fields[i]; + const upb_msglayout_field *f = &m->fields[i]; if (f->label == UPB_LABEL_REPEATED) { CHK(upb_encode_array(e, msg + f->offset, m, f)); } else { - if (upb_encode_hasscalarfield(msg, m, f)) { - CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, !m->is_proto2)); + bool skip_empty = false; + if (f->presence == 0) { + /* Proto3 presence. */ + skip_empty = true; + } else if (f->presence > 0) { + /* Proto2 presence: hasbit. */ + if (!upb_readhasbit(msg, f)) { + continue; + } + } else { + /* Field is in a oneof. */ + if (upb_readcase(msg, f) != f->number) { + continue; + } } + CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, skip_empty)); } } - *size = buf_end - e->ptr; + 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; } -char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *m, - upb_env *env, size_t *size) { +char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena, + size_t *size) { upb_encstate e; - e.env = env; + e.alloc = upb_arena_alloc(arena); e.buf = NULL; e.limit = NULL; e.ptr = NULL; @@ -4033,30 +4595,109 @@ bool upb_byteshandler_setendstr(upb_byteshandler *h, } -static bool is_power_of_two(size_t val) { - return (val & (val - 1)) == 0; -} +/** Handlers for upb_msg ******************************************************/ -/* 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); -} +typedef struct { + size_t offset; + int32_t hasbit; +} upb_msg_handlerdata; -static size_t div_round_up(size_t n, size_t d) { - return (n + d - 1) / d; -} +/* Fallback implementation if the handler is not specialized by the producer. */ +#define MSG_WRITER(type, ctype) \ + bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \ + uint8_t *m = c; \ + const upb_msg_handlerdata *d = hd; \ + if (d->hasbit > 0) \ + *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ + *(ctype*)&m[d->offset] = val; \ + return true; \ + } \ -bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) { - return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 || - type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 || - type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING; -} +MSG_WRITER(double, double) +MSG_WRITER(float, float) +MSG_WRITER(int32, int32_t) +MSG_WRITER(int64, int64_t) +MSG_WRITER(uint32, uint32_t) +MSG_WRITER(uint64, uint64_t) +MSG_WRITER(bool, bool) -void *upb_array_pack(const upb_array *arr, void *p, size_t *ofs, size_t size); -void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size); +bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f, + size_t offset, int32_t hasbit) { + upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; + bool ok; -#define PTR_AT(msg, ofs, type) (type*)((char*)msg + ofs) + upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d)); + if (!d) return false; + d->offset = offset; + d->hasbit = hasbit; + + upb_handlerattr_sethandlerdata(&attr, d); + upb_handlerattr_setalwaysok(&attr, true); + upb_handlers_addcleanup(h, d, upb_gfree); + +#define TYPE(u, l) \ + case UPB_TYPE_##u: \ + ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break; + + ok = false; + + switch (upb_fielddef_type(f)) { + TYPE(INT64, int64); + TYPE(INT32, int32); + TYPE(ENUM, int32); + TYPE(UINT64, uint64); + TYPE(UINT32, uint32); + TYPE(DOUBLE, double); + TYPE(FLOAT, float); + TYPE(BOOL, bool); + default: UPB_ASSERT(false); break; + } +#undef TYPE + + upb_handlerattr_uninit(&attr); + return ok; +} + +bool upb_msg_getscalarhandlerdata(const upb_handlers *h, + upb_selector_t s, + upb_fieldtype_t *type, + size_t *offset, + int32_t *hasbit) { + const upb_msg_handlerdata *d; + upb_func *f = upb_handlers_gethandler(h, s); + + if ((upb_int64_handlerfunc*)f == upb_msg_setint64) { + *type = UPB_TYPE_INT64; + } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) { + *type = UPB_TYPE_INT32; + } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) { + *type = UPB_TYPE_UINT64; + } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) { + *type = UPB_TYPE_UINT32; + } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) { + *type = UPB_TYPE_DOUBLE; + } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) { + *type = UPB_TYPE_FLOAT; + } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) { + *type = UPB_TYPE_BOOL; + } else { + return false; + } + + d = upb_handlers_gethandlerdata(h, s); + *offset = d->offset; + *hasbit = d->hasbit; + return true; +} + + +bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) { + return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 || + type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 || + type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING; +} + +#define PTR_AT(msg, ofs, type) (type*)((char*)msg + ofs) #define VOIDPTR_AT(msg, ofs) PTR_AT(msg, ofs, void) #define ENCODE_MAX_NESTING 64 #define CHECK_TRUE(x) if (!(x)) { return false; } @@ -4094,576 +4735,57 @@ static size_t upb_msgval_sizeof(upb_fieldtype_t type) { case UPB_TYPE_FLOAT: return 4; case UPB_TYPE_BOOL: - return 1; - case UPB_TYPE_BYTES: - case UPB_TYPE_MESSAGE: - return sizeof(void*); - case UPB_TYPE_STRING: - return sizeof(upb_stringview); - } - UPB_UNREACHABLE(); -} - -static uint8_t upb_msg_fieldsize(const upb_msglayout_fieldinit_v1 *field) { - if (field->label == UPB_LABEL_REPEATED) { - return sizeof(void*); - } else { - return upb_msgval_sizeof(field->type); - } -} - -static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { - if (upb_fielddef_isseq(f)) { - return sizeof(void*); - } else { - return upb_msgval_sizeof(upb_fielddef_type(f)); - } -} - -/* TODO(haberman): this is broken right now because upb_msgval can contain - * a char* / size_t pair, which is too big for a upb_value. To fix this - * we'll probably need to dynamically allocate a upb_msgval and store a - * pointer to that in the tables for extensions/maps. */ -static upb_value upb_toval(upb_msgval val) { - upb_value ret; - UPB_UNUSED(val); - memset(&ret, 0, sizeof(upb_value)); /* XXX */ - return ret; -} - -static upb_msgval upb_msgval_fromval(upb_value val) { - upb_msgval ret; - UPB_UNUSED(val); - memset(&ret, 0, sizeof(upb_msgval)); /* XXX */ - return ret; -} - -static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) { - switch (type) { - case UPB_TYPE_FLOAT: return UPB_CTYPE_FLOAT; - case UPB_TYPE_DOUBLE: return UPB_CTYPE_DOUBLE; - case UPB_TYPE_BOOL: return UPB_CTYPE_BOOL; - case UPB_TYPE_BYTES: - case UPB_TYPE_MESSAGE: - case UPB_TYPE_STRING: return UPB_CTYPE_CONSTPTR; - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: return UPB_CTYPE_INT32; - case UPB_TYPE_UINT32: return UPB_CTYPE_UINT32; - case UPB_TYPE_INT64: return UPB_CTYPE_INT64; - case UPB_TYPE_UINT64: return UPB_CTYPE_UINT64; - default: UPB_ASSERT(false); return 0; - } -} - -static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) { - switch (upb_fielddef_type(f)) { - case UPB_TYPE_FLOAT: - return upb_msgval_float(upb_fielddef_defaultfloat(f)); - case UPB_TYPE_DOUBLE: - return upb_msgval_double(upb_fielddef_defaultdouble(f)); - case UPB_TYPE_BOOL: - return upb_msgval_bool(upb_fielddef_defaultbool(f)); - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: { - size_t len; - const char *ptr = upb_fielddef_defaultstr(f, &len); - return upb_msgval_makestr(ptr, len); - } - case UPB_TYPE_MESSAGE: - return upb_msgval_msg(NULL); - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - return upb_msgval_int32(upb_fielddef_defaultint32(f)); - case UPB_TYPE_UINT32: - return upb_msgval_uint32(upb_fielddef_defaultuint32(f)); - case UPB_TYPE_INT64: - return upb_msgval_int64(upb_fielddef_defaultint64(f)); - case UPB_TYPE_UINT64: - return upb_msgval_uint64(upb_fielddef_defaultuint64(f)); - default: - UPB_ASSERT(false); - return upb_msgval_msg(NULL); - } -} - - -/** upb_msglayout *************************************************************/ - -struct upb_msglayout { - struct upb_msglayout_msginit_v1 data; -}; - -static void upb_msglayout_free(upb_msglayout *l) { - upb_gfree(l->data.default_msg); - upb_gfree(l); -} - -static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { - size_t ret; - - l->data.size = align_up(l->data.size, size); - ret = l->data.size; - l->data.size += size; - return ret; -} - -static uint32_t upb_msglayout_offset(const upb_msglayout *l, - const upb_fielddef *f) { - return l->data.fields[upb_fielddef_index(f)].offset; -} - -static uint32_t upb_msglayout_hasbit(const upb_msglayout *l, - const upb_fielddef *f) { - return l->data.fields[upb_fielddef_index(f)].hasbit; -} - -static bool upb_msglayout_initdefault(upb_msglayout *l, const upb_msgdef *m) { - upb_msg_field_iter it; - - if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->data.size) { - /* Allocate default message and set default values in it. */ - l->data.default_msg = upb_gmalloc(l->data.size); - if (!l->data.default_msg) { - return false; - } - - memset(l->data.default_msg, 0, l->data.size); - - 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_containingoneof(f)) { - continue; - } - - /* TODO(haberman): handle strings. */ - if (!upb_fielddef_isstring(f) && - !upb_fielddef_issubmsg(f) && - !upb_fielddef_isseq(f)) { - upb_msg_set(l->data.default_msg, - upb_fielddef_index(f), - upb_msgval_fromdefault(f), - l); - } - } - } - - return true; -} - -static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { - upb_msg_field_iter it; - upb_msg_oneof_iter oit; - upb_msglayout *l; - size_t hasbit; - size_t submsg_count = 0; - const upb_msglayout_msginit_v1 **submsgs; - upb_msglayout_fieldinit_v1 *fields; - upb_msglayout_oneofinit_v1 *oneofs; - - 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++; - } - } - - l = upb_gmalloc(sizeof(*l)); - if (!l) return NULL; - - memset(l, 0, sizeof(*l)); - - fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields)); - submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs)); - oneofs = upb_gmalloc(upb_msgdef_numoneofs(m) * sizeof(*oneofs)); - - if ((!fields && upb_msgdef_numfields(m)) || - (!submsgs && submsg_count) || - (!oneofs && upb_msgdef_numoneofs(m))) { - /* OOM. */ - upb_gfree(l); - upb_gfree(fields); - upb_gfree(submsgs); - upb_gfree(oneofs); - return NULL; - } - - l->data.field_count = upb_msgdef_numfields(m); - l->data.oneof_count = upb_msgdef_numoneofs(m); - l->data.fields = fields; - l->data.submsgs = submsgs; - l->data.oneofs = oneofs; - l->data.is_proto2 = (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2); - - /* 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. */ - 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_fieldinit_v1 *field = &fields[upb_fielddef_index(f)]; - - field->number = upb_fielddef_number(f); - field->type = upb_fielddef_type(f); - field->label = upb_fielddef_label(f); - - if (upb_fielddef_containingoneof(f)) { - field->oneof_index = upb_oneofdef_index(upb_fielddef_containingoneof(f)); - } else { - field->oneof_index = UPB_NOT_IN_ONEOF; - } - - if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { - field->hasbit = hasbit++; - } - } - - /* Account for space used by hasbits. */ - l->data.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_containingoneof(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. */ - upb_msglayout_oneofinit_v1 *oneof = &oneofs[upb_oneofdef_index(o)]; - size_t field_size = 0; - - /* 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. */ - oneof->case_offset = upb_msglayout_place(l, case_size); - oneof->data_offset = upb_msglayout_place(l, field_size); - } - - /* Size of the entire structure should be a multiple of its greatest - * alignment. TODO: track overall alignment for real? */ - l->data.size = align_up(l->data.size, 8); - - if (upb_msglayout_initdefault(l, m)) { - return l; - } else { - upb_msglayout_free(l); - return NULL; - } -} - - -/** upb_msgfactory ************************************************************/ - -struct upb_msgfactory { - const upb_symtab *symtab; /* We own a ref. */ - upb_inttable layouts; - upb_inttable mergehandlers; -}; - -upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) { - upb_msgfactory *ret = upb_gmalloc(sizeof(*ret)); - - ret->symtab = symtab; - upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR); - upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR); - - return ret; -} - -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); - } - - upb_inttable_begin(&i, &f->mergehandlers); - for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { - const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i)); - upb_handlers_unref(h, f); - } - - upb_inttable_uninit(&f->layouts); - upb_inttable_uninit(&f->mergehandlers); - upb_gfree(f); -} - -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) { - return f->symtab; -} - -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)); - - if (upb_inttable_lookupptr(&f->layouts, m, &v)) { - UPB_ASSERT(upb_value_getptr(v)); - return upb_value_getptr(v); - } else { - upb_msgfactory *mutable_f = (void*)f; - upb_msglayout *l = upb_msglayout_new(m); - upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l)); - UPB_ASSERT(l); - return l; - } -} - -/* Our handlers that we don't expose externally. */ - -void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) { - uint32_t ofs = (uintptr_t)hd; - upb_alloc *alloc = upb_msg_alloc(msg); - upb_msgval val; - UPB_UNUSED(size_hint); - - val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING)); - - upb_free(alloc, (void*)val.str.data); - val.str.data = NULL; - val.str.size = 0; - - upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING)); - return msg; -} - -size_t upb_msg_str(void *msg, const void *hd, const char *ptr, size_t size, - const upb_bufhandle *handle) { - uint32_t ofs = (uintptr_t)hd; - upb_alloc *alloc = upb_msg_alloc(msg); - upb_msgval val; - size_t newsize; - UPB_UNUSED(handle); - - val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING)); - - newsize = val.str.size + size; - val.str.data = upb_realloc(alloc, (void*)val.str.data, val.str.size, newsize); - - if (!val.str.data) { - return false; - } - - memcpy((char*)val.str.data + val.str.size, ptr, size); - val.str.size = newsize; - upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING)); - return size; -} - -static void callback(const void *closure, upb_handlers *h) { - upb_msgfactory *factory = (upb_msgfactory*)closure; - const upb_msgdef *md = upb_handlers_msgdef(h); - const upb_msglayout* layout = upb_msgfactory_getlayout(factory, md); - upb_msg_field_iter i; - UPB_UNUSED(factory); - - for(upb_msg_field_begin(&i, md); - !upb_msg_field_done(&i); - upb_msg_field_next(&i)) { - const upb_fielddef *f = upb_msg_iter_field(&i); - size_t offset = upb_msglayout_offset(layout, f); - upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; - upb_handlerattr_sethandlerdata(&attr, (void*)offset); - - if (upb_fielddef_isseq(f)) { - } else if (upb_fielddef_isstring(f)) { - upb_handlers_setstartstr(h, f, upb_msg_startstr, &attr); - upb_handlers_setstring(h, f, upb_msg_str, &attr); - } else { - upb_msg_setscalarhandler( - h, f, offset, upb_msglayout_hasbit(layout, f)); - } - } -} - -const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f, - const upb_msgdef *m) { - upb_msgfactory *mutable_f = (void*)f; - - /* TODO(haberman): properly cache these. */ - const upb_handlers *ret = upb_handlers_newfrozen(m, f, callback, f); - upb_inttable_push(&mutable_f->mergehandlers, upb_value_constptr(ret)); - - return ret; -} - -const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f, - const upb_handlers *h) { - const upb_msgdef *md = upb_handlers_msgdef(h); - return (const upb_visitorplan*)upb_msgfactory_getlayout(f, md); -} - - -/** upb_visitor ***************************************************************/ - -struct upb_visitor { - const upb_msglayout *layout; - upb_sink *sink; -}; - -static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) { - upb_selector_t ret; - bool ok = upb_handlers_getselector(f, type, &ret); - UPB_ASSERT(ok); - return ret; -} - -static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f, - const upb_msglayout *layout) { - int field_index = upb_fielddef_index(f); - if (upb_fielddef_isseq(f)) { - return upb_msgval_getarr(upb_msg_get(msg, field_index, layout)) != NULL; - } else if (upb_msgdef_syntax(upb_fielddef_containingtype(f)) == - UPB_SYNTAX_PROTO2) { - return upb_msg_has(msg, field_index, layout); - } else { - upb_msgval val = upb_msg_get(msg, field_index, layout); - switch (upb_fielddef_type(f)) { - case UPB_TYPE_FLOAT: - return upb_msgval_getfloat(val) != 0; - case UPB_TYPE_DOUBLE: - return upb_msgval_getdouble(val) != 0; - case UPB_TYPE_BOOL: - return upb_msgval_getbool(val); - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - return upb_msgval_getint32(val) != 0; - case UPB_TYPE_UINT32: - return upb_msgval_getuint32(val) != 0; - case UPB_TYPE_INT64: - return upb_msgval_getint64(val) != 0; - case UPB_TYPE_UINT64: - return upb_msgval_getuint64(val) != 0; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: - return upb_msgval_getstr(val).size > 0; - case UPB_TYPE_MESSAGE: - return upb_msgval_getmsg(val) != NULL; - } - UPB_UNREACHABLE(); + return 1; + case UPB_TYPE_MESSAGE: + return sizeof(void*); + case UPB_TYPE_BYTES: + case UPB_TYPE_STRING: + return sizeof(upb_stringview); } + UPB_UNREACHABLE(); } -static bool upb_visitor_visitmsg2(const upb_msg *msg, - const upb_msglayout *layout, upb_sink *sink, - int depth) { - const upb_msgdef *md = upb_handlers_msgdef(sink->handlers); - upb_msg_field_iter i; - upb_status status; - - upb_sink_startmsg(sink); - - /* Protect against cycles (possible because users may freely reassign message - * and repeated fields) by imposing a maximum recursion depth. */ - if (depth > ENCODE_MAX_NESTING) { - return false; - } - - for (upb_msg_field_begin(&i, md); - !upb_msg_field_done(&i); - upb_msg_field_next(&i)) { - upb_fielddef *f = upb_msg_iter_field(&i); - upb_msgval val; - - if (!upb_visitor_hasfield(msg, f, layout)) { - continue; - } - - val = upb_msg_get(msg, upb_fielddef_index(f), layout); - - if (upb_fielddef_isseq(f)) { - const upb_array *arr = upb_msgval_getarr(val); - UPB_ASSERT(arr); - /* TODO: putary(ary, f, sink, depth);*/ - } else if (upb_fielddef_issubmsg(f)) { - const upb_map *map = upb_msgval_getmap(val); - UPB_ASSERT(map); - /* TODO: putmap(map, f, sink, depth);*/ - } else if (upb_fielddef_isstring(f)) { - /* TODO putstr(); */ - } else { - upb_selector_t sel = getsel2(f, upb_handlers_getprimitivehandlertype(f)); - UPB_ASSERT(upb_fielddef_isprimitive(f)); - - switch (upb_fielddef_type(f)) { - case UPB_TYPE_FLOAT: - CHECK_TRUE(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val))); - break; - case UPB_TYPE_DOUBLE: - CHECK_TRUE(upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val))); - break; - case UPB_TYPE_BOOL: - CHECK_TRUE(upb_sink_putbool(sink, sel, upb_msgval_getbool(val))); - break; - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - CHECK_TRUE(upb_sink_putint32(sink, sel, upb_msgval_getint32(val))); - break; - case UPB_TYPE_UINT32: - CHECK_TRUE(upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val))); - break; - case UPB_TYPE_INT64: - CHECK_TRUE(upb_sink_putint64(sink, sel, upb_msgval_getint64(val))); - break; - case UPB_TYPE_UINT64: - CHECK_TRUE(upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val))); - break; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: - case UPB_TYPE_MESSAGE: - UPB_UNREACHABLE(); - } - } +static uint8_t upb_msg_fieldsize(const upb_msglayout_field *field) { + if (field->label == UPB_LABEL_REPEATED) { + return sizeof(void*); + } else { + return upb_msgval_sizeof(upb_desctype_to_fieldtype[field->descriptortype]); } +} - upb_sink_endmsg(sink, &status); - return true; +/* TODO(haberman): this is broken right now because upb_msgval can contain + * a char* / size_t pair, which is too big for a upb_value. To fix this + * we'll probably need to dynamically allocate a upb_msgval and store a + * pointer to that in the tables for extensions/maps. */ +static upb_value upb_toval(upb_msgval val) { + upb_value ret; + UPB_UNUSED(val); + memset(&ret, 0, sizeof(upb_value)); /* XXX */ + return ret; } -upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp, - upb_sink *output) { - upb_visitor *visitor = upb_env_malloc(e, sizeof(*visitor)); - visitor->layout = (const upb_msglayout*)vp; - visitor->sink = output; - return visitor; +static upb_msgval upb_msgval_fromval(upb_value val) { + upb_msgval ret; + UPB_UNUSED(val); + memset(&ret, 0, sizeof(upb_msgval)); /* XXX */ + return ret; } -bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) { - return upb_visitor_visitmsg2(msg, visitor->layout, visitor->sink, 0); +static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) { + switch (type) { + case UPB_TYPE_FLOAT: return UPB_CTYPE_FLOAT; + case UPB_TYPE_DOUBLE: return UPB_CTYPE_DOUBLE; + case UPB_TYPE_BOOL: return UPB_CTYPE_BOOL; + case UPB_TYPE_BYTES: + case UPB_TYPE_MESSAGE: + case UPB_TYPE_STRING: return UPB_CTYPE_CONSTPTR; + case UPB_TYPE_ENUM: + case UPB_TYPE_INT32: return UPB_CTYPE_INT32; + case UPB_TYPE_UINT32: return UPB_CTYPE_UINT32; + case UPB_TYPE_INT64: return UPB_CTYPE_INT64; + case UPB_TYPE_UINT64: return UPB_CTYPE_UINT64; + default: UPB_ASSERT(false); return 0; + } } @@ -4680,8 +4802,12 @@ bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) { /* Used when a message is not extendable. */ typedef struct { - /* TODO(haberman): add unknown fields. */ - upb_alloc *alloc; + /* TODO(haberman): use pointer tagging so we we are slim when known unknown + * fields are not present. */ + upb_arena *arena; + char *unknown; + size_t unknown_len; + size_t unknown_size; } upb_msg_internal; /* Used when a message is extendable. */ @@ -4691,7 +4817,7 @@ typedef struct { } upb_msg_internal_withext; static int upb_msg_internalsize(const upb_msglayout *l) { - return sizeof(upb_msg_internal) - l->data.extendable * sizeof(void*); + return sizeof(upb_msg_internal) - l->extendable * sizeof(void *); } static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) { @@ -4704,123 +4830,112 @@ static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) { static upb_msg_internal_withext *upb_msg_getinternalwithext( upb_msg *msg, const upb_msglayout *l) { - UPB_ASSERT(l->data.extendable); + UPB_ASSERT(l->extendable); return VOIDPTR_AT(msg, -sizeof(upb_msg_internal_withext)); } -static const upb_msglayout_fieldinit_v1 *upb_msg_checkfield( - int field_index, const upb_msglayout *l) { - UPB_ASSERT(field_index >= 0 && field_index < l->data.field_count); - return &l->data.fields[field_index]; +void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len) { + upb_msg_internal* in = upb_msg_getinternal(msg); + if (len > in->unknown_size - in->unknown_len) { + upb_alloc *alloc = upb_arena_alloc(in->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); + in->unknown_size = newsize; + } + memcpy(in->unknown + in->unknown_len, data, len); + in->unknown_len += len; +} + +const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { + const upb_msg_internal* in = upb_msg_getinternal_const(msg); + *len = in->unknown_len; + return in->unknown; +} + +static const upb_msglayout_field *upb_msg_checkfield(int field_index, + const upb_msglayout *l) { + UPB_ASSERT(field_index >= 0 && field_index < l->field_count); + return &l->fields[field_index]; } -static bool upb_msg_inoneof(const upb_msglayout_fieldinit_v1 *field) { - return field->oneof_index != UPB_NOT_IN_ONEOF; +static bool upb_msg_inoneof(const upb_msglayout_field *field) { + return field->presence < 0; } static uint32_t *upb_msg_oneofcase(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); UPB_ASSERT(upb_msg_inoneof(field)); - return PTR_AT(msg, l->data.oneofs[field->oneof_index].case_offset, uint32_t); + return PTR_AT(msg, ~field->presence, uint32_t); } -size_t upb_msg_sizeof(const upb_msglayout *l) { - return l->data.size + upb_msg_internalsize(l); +static size_t upb_msg_sizeof(const upb_msglayout *l) { + return l->size + upb_msg_internalsize(l); } -upb_msg *upb_msg_init(void *mem, const upb_msglayout *l, upb_alloc *a) { - upb_msg *msg = VOIDPTR_AT(mem, upb_msg_internalsize(l)); +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_internal *in; + upb_msg *msg; - /* Initialize normal members. */ - if (l->data.default_msg) { - memcpy(msg, l->data.default_msg, l->data.size); - } else { - memset(msg, 0, l->data.size); + if (!mem) { + return NULL; } + msg = VOIDPTR_AT(mem, upb_msg_internalsize(l)); + + /* Initialize normal members. */ + memset(msg, 0, l->size); + /* Initialize internal members. */ - upb_msg_getinternal(msg)->alloc = a; + in = upb_msg_getinternal(msg); + in->arena = a; + in->unknown = NULL; + in->unknown_len = 0; + in->unknown_size = 0; - if (l->data.extendable) { + if (l->extendable) { upb_msg_getinternalwithext(msg, l)->extdict = NULL; } return msg; } -void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) { - if (l->data.extendable) { - upb_inttable *ext_dict = upb_msg_getinternalwithext(msg, l)->extdict; - if (ext_dict) { - upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg)); - upb_free(upb_msg_alloc(msg), ext_dict); - } - } - - return VOIDPTR_AT(msg, -upb_msg_internalsize(l)); -} - -upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) { - void *mem = upb_malloc(a, upb_msg_sizeof(l)); - return mem ? upb_msg_init(mem, l, a) : NULL; -} - -void upb_msg_free(upb_msg *msg, const upb_msglayout *l) { - upb_free(upb_msg_alloc(msg), upb_msg_uninit(msg, l)); -} - -upb_alloc *upb_msg_alloc(const upb_msg *msg) { - return upb_msg_getinternal_const(msg)->alloc; +upb_arena *upb_msg_arena(const upb_msg *msg) { + return upb_msg_getinternal_const(msg)->arena; } bool upb_msg_has(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); - UPB_ASSERT(l->data.is_proto2); + UPB_ASSERT(field->presence); if (upb_msg_inoneof(field)) { /* Oneofs are set when the oneof number is set to this field. */ return *upb_msg_oneofcase(msg, field_index, l) == field->number; } else { /* Other fields are set when their hasbit is set. */ - uint32_t hasbit = l->data.fields[field_index].hasbit; + uint32_t hasbit = field->presence; return DEREF(msg, hasbit / 8, char) | (1 << (hasbit % 8)); } } upb_msgval upb_msg_get(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); int size = upb_msg_fieldsize(field); - - if (upb_msg_inoneof(field)) { - if (*upb_msg_oneofcase(msg, field_index, l) == field->number) { - size_t ofs = l->data.oneofs[field->oneof_index].data_offset; - return upb_msgval_read(msg, ofs, size); - } else { - /* Return default. */ - return upb_msgval_read(l->data.default_msg, field->offset, size); - } - } else { - return upb_msgval_read(msg, field->offset, size); - } + return upb_msgval_read(msg, field->offset, size); } void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); int size = upb_msg_fieldsize(field); - - if (upb_msg_inoneof(field)) { - size_t ofs = l->data.oneofs[field->oneof_index].data_offset; - *upb_msg_oneofcase(msg, field_index, l) = field->number; - upb_msgval_write(msg, ofs, val, size); - } else { - upb_msgval_write(msg, field->offset, val, size); - } + upb_msgval_write(msg, field->offset, val, size); } @@ -4828,37 +4943,22 @@ void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val, #define DEREF_ARR(arr, i, type) ((type*)arr->data)[i] -size_t upb_array_sizeof(upb_fieldtype_t type) { - UPB_UNUSED(type); - return sizeof(upb_array); -} - -void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *alloc) { - arr->type = type; - arr->data = NULL; - arr->len = 0; - arr->size = 0; - arr->element_size = upb_msgval_sizeof(type); - arr->alloc = alloc; -} - -void upb_array_uninit(upb_array *arr) { - upb_free(arr->alloc, arr->data); -} - -upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a) { - upb_array *ret = upb_malloc(a, upb_array_sizeof(type)); +upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a) { + upb_alloc *alloc = upb_arena_alloc(a); + upb_array *ret = upb_malloc(alloc, sizeof(upb_array)); - if (ret) { - upb_array_init(ret, type, a); + if (!ret) { + return NULL; } - return ret; -} + ret->type = type; + ret->data = NULL; + ret->len = 0; + ret->size = 0; + ret->element_size = upb_msgval_sizeof(type); + ret->arena = a; -void upb_array_free(upb_array *arr) { - upb_array_uninit(arr); - upb_free(arr->alloc, arr); + return ret; } size_t upb_array_size(const upb_array *arr) { @@ -4885,8 +4985,9 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val) { size_t new_size = UPB_MAX(arr->size * 2, 8); size_t new_bytes = new_size * arr->element_size; size_t old_bytes = arr->size * arr->element_size; + upb_alloc *alloc = upb_arena_alloc(arr->arena); upb_msgval *new_data = - upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes); + upb_realloc(alloc, arr->data, old_bytes, new_bytes); if (!new_data) { return false; @@ -4912,7 +5013,7 @@ struct upb_map { /* We may want to optimize this to use inttable where possible, for greater * efficiency and lower memory footprint. */ upb_strtable strtab; - upb_alloc *alloc; + upb_arena *arena; }; static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key, @@ -4963,52 +5064,28 @@ static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key, UPB_UNREACHABLE(); } -size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype) { - /* Size does not currently depend on key/value type. */ - UPB_UNUSED(ktype); - UPB_UNUSED(vtype); - return sizeof(upb_map); -} - -bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_alloc *a) { - upb_ctype_t vtabtype = upb_fieldtotabtype(vtype); - UPB_ASSERT(upb_fieldtype_mapkeyok(ktype)); - map->key_type = ktype; - map->val_type = vtype; - map->alloc = a; - - if (!upb_strtable_init2(&map->strtab, vtabtype, a)) { - return false; - } - - return true; -} - -void upb_map_uninit(upb_map *map) { - upb_strtable_uninit2(&map->strtab, map->alloc); -} - upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_alloc *a) { - upb_map *map = upb_malloc(a, upb_map_sizeof(ktype, vtype)); + upb_arena *a) { + upb_ctype_t vtabtype = upb_fieldtotabtype(vtype); + upb_alloc *alloc = upb_arena_alloc(a); + upb_map *map = upb_malloc(alloc, sizeof(upb_map)); if (!map) { return NULL; } - if (!upb_map_init(map, ktype, vtype, a)) { + UPB_ASSERT(upb_fieldtype_mapkeyok(ktype)); + map->key_type = ktype; + map->val_type = vtype; + map->arena = a; + + if (!upb_strtable_init2(&map->strtab, vtabtype, alloc)) { return NULL; } return map; } -void upb_map_free(upb_map *map) { - upb_map_uninit(map); - upb_free(map->alloc, map); -} - size_t upb_map_size(const upb_map *map) { return upb_strtable_count(&map->strtab); } @@ -5042,7 +5119,7 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, size_t key_len; upb_value tabval = upb_toval(val); upb_value removedtabval; - upb_alloc *a = map->alloc; + upb_alloc *a = upb_arena_alloc(map->arena); upb_map_tokey(map->key_type, &key, &key_str, &key_len); @@ -5058,163 +5135,321 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, bool upb_map_del(upb_map *map, upb_msgval key) { const char *key_str; size_t key_len; - upb_alloc *a = map->alloc; + upb_alloc *a = upb_arena_alloc(map->arena); + + upb_map_tokey(map->key_type, &key, &key_str, &key_len); + return upb_strtable_remove3(&map->strtab, key_str, key_len, NULL, a); +} + + +/** upb_mapiter ***************************************************************/ + +struct upb_mapiter { + upb_strtable_iter iter; + upb_fieldtype_t key_type; +}; + +size_t upb_mapiter_sizeof() { + return sizeof(upb_mapiter); +} + +void upb_mapiter_begin(upb_mapiter *i, const upb_map *map) { + upb_strtable_begin(&i->iter, &map->strtab); + i->key_type = map->key_type; +} + +upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a) { + upb_mapiter *ret = upb_malloc(a, upb_mapiter_sizeof()); + + if (!ret) { + return NULL; + } + + upb_mapiter_begin(ret, t); + return ret; +} + +void upb_mapiter_free(upb_mapiter *i, upb_alloc *a) { + upb_free(a, i); +} + +void upb_mapiter_next(upb_mapiter *i) { + upb_strtable_next(&i->iter); +} + +bool upb_mapiter_done(const upb_mapiter *i) { + return upb_strtable_done(&i->iter); +} + +upb_msgval upb_mapiter_key(const upb_mapiter *i) { + return upb_map_fromkey(i->key_type, upb_strtable_iter_key(&i->iter), + upb_strtable_iter_keylength(&i->iter)); +} + +upb_msgval upb_mapiter_value(const upb_mapiter *i) { + return upb_msgval_fromval(upb_strtable_iter_value(&i->iter)); +} + +void upb_mapiter_setdone(upb_mapiter *i) { + upb_strtable_iter_setdone(&i->iter); +} + +bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) { + return upb_strtable_iter_isequal(&i1->iter, &i2->iter); +} + + +static bool is_power_of_two(size_t val) { + return (val & (val - 1)) == 0; +} + +/* 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 size_t div_round_up(size_t n, size_t d) { + return (n + d - 1) / d; +} + +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_stringview); + } + UPB_UNREACHABLE(); +} + +static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { + if (upb_fielddef_isseq(f)) { + return sizeof(void*); + } else { + return upb_msgval_sizeof2(upb_fielddef_type(f)); + } +} + + +/** 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; +} + +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_map_tokey(map->key_type, &key, &key_str, &key_len); - return upb_strtable_remove3(&map->strtab, key_str, key_len, NULL, a); -} + memset(l, 0, sizeof(*l)); + fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields)); + submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs)); -/** upb_mapiter ***************************************************************/ + if ((!fields && upb_msgdef_numfields(m)) || + (!submsgs && submsg_count)) { + /* OOM. */ + upb_gfree(fields); + upb_gfree(submsgs); + return false; + } -struct upb_mapiter { - upb_strtable_iter iter; - upb_fieldtype_t key_type; -}; + l->field_count = upb_msgdef_numfields(m); + l->fields = fields; + l->submsgs = submsgs; -size_t upb_mapiter_sizeof() { - return sizeof(upb_mapiter); -} + /* 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. + */ -void upb_mapiter_begin(upb_mapiter *i, const upb_map *map) { - upb_strtable_begin(&i->iter, &map->strtab); - i->key_type = map->key_type; -} + /* 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_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a) { - upb_mapiter *ret = upb_malloc(a, upb_mapiter_sizeof()); + field->number = upb_fielddef_number(f); + field->descriptortype = upb_fielddef_descriptortype(f); + field->label = upb_fielddef_label(f); - if (!ret) { - return NULL; + 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 (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { + field->presence = (hasbit++); + } else { + field->presence = 0; + } } - upb_mapiter_begin(ret, t); - return ret; -} + /* Account for space used by hasbits. */ + l->size = div_round_up(hasbit, 8); -void upb_mapiter_free(upb_mapiter *i, upb_alloc *a) { - upb_free(a, i); -} + /* 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); -void upb_mapiter_next(upb_mapiter *i) { - upb_strtable_next(&i->iter); -} + if (upb_fielddef_containingoneof(f)) { + /* Oneofs are handled separately below. */ + continue; + } -bool upb_mapiter_done(const upb_mapiter *i) { - return upb_strtable_done(&i->iter); -} + fields[index].offset = upb_msglayout_place(l, field_size); + } -upb_msgval upb_mapiter_key(const upb_mapiter *i) { - return upb_map_fromkey(i->key_type, upb_strtable_iter_key(&i->iter), - upb_strtable_iter_keylength(&i->iter)); -} + /* 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; -upb_msgval upb_mapiter_value(const upb_mapiter *i) { - return upb_msgval_fromval(upb_strtable_iter_value(&i->iter)); -} + size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ + size_t field_size = 0; + uint32_t case_offset; + uint32_t data_offset; -void upb_mapiter_setdone(upb_mapiter *i) { - upb_strtable_iter_setdone(&i->iter); -} + /* 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)); + } -bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) { - return upb_strtable_iter_isequal(&i1->iter, &i2->iter); -} + /* 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; + } + } -/** Handlers for upb_msg ******************************************************/ + /* 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); -typedef struct { - size_t offset; - int32_t hasbit; -} upb_msg_handlerdata; + return true; +} -/* Fallback implementation if the handler is not specialized by the producer. */ -#define MSG_WRITER(type, ctype) \ - bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \ - uint8_t *m = c; \ - const upb_msg_handlerdata *d = hd; \ - if (d->hasbit > 0) \ - *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ - *(ctype*)&m[d->offset] = val; \ - return true; \ - } \ -MSG_WRITER(double, double) -MSG_WRITER(float, float) -MSG_WRITER(int32, int32_t) -MSG_WRITER(int64, int64_t) -MSG_WRITER(uint32, uint32_t) -MSG_WRITER(uint64, uint64_t) -MSG_WRITER(bool, bool) +/** upb_msgfactory ************************************************************/ -bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f, - size_t offset, int32_t hasbit) { - upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; - bool ok; +struct upb_msgfactory { + const upb_symtab *symtab; /* We own a ref. */ + upb_inttable layouts; + upb_inttable mergehandlers; +}; - upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d)); - if (!d) return false; - d->offset = offset; - d->hasbit = hasbit; +upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) { + upb_msgfactory *ret = upb_gmalloc(sizeof(*ret)); - upb_handlerattr_sethandlerdata(&attr, d); - upb_handlerattr_setalwaysok(&attr, true); - upb_handlers_addcleanup(h, d, upb_gfree); + ret->symtab = symtab; + upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR); + upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR); -#define TYPE(u, l) \ - case UPB_TYPE_##u: \ - ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break; + return ret; +} - ok = false; +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); + } - switch (upb_fielddef_type(f)) { - TYPE(INT64, int64); - TYPE(INT32, int32); - TYPE(ENUM, int32); - TYPE(UINT64, uint64); - TYPE(UINT32, uint32); - TYPE(DOUBLE, double); - TYPE(FLOAT, float); - TYPE(BOOL, bool); - default: UPB_ASSERT(false); break; + upb_inttable_begin(&i, &f->mergehandlers); + for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { + const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i)); + upb_handlers_unref(h, f); } -#undef TYPE - upb_handlerattr_uninit(&attr); - return ok; + upb_inttable_uninit(&f->layouts); + upb_inttable_uninit(&f->mergehandlers); + upb_gfree(f); } -bool upb_msg_getscalarhandlerdata(const upb_handlers *h, - upb_selector_t s, - upb_fieldtype_t *type, - size_t *offset, - int32_t *hasbit) { - const upb_msg_handlerdata *d; - upb_func *f = upb_handlers_gethandler(h, s); +const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) { + return f->symtab; +} - if ((upb_int64_handlerfunc*)f == upb_msg_setint64) { - *type = UPB_TYPE_INT64; - } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) { - *type = UPB_TYPE_INT32; - } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) { - *type = UPB_TYPE_UINT64; - } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) { - *type = UPB_TYPE_UINT32; - } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) { - *type = UPB_TYPE_DOUBLE; - } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) { - *type = UPB_TYPE_FLOAT; - } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) { - *type = UPB_TYPE_BOOL; +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)); + + if (upb_inttable_lookupptr(&f->layouts, m, &v)) { + UPB_ASSERT(upb_value_getptr(v)); + return upb_value_getptr(v); } else { - return false; + /* 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; } - - d = upb_handlers_gethandlerdata(h, s); - *offset = d->offset; - *hasbit = d->hasbit; - return true; } /* ** upb::RefCounted Implementation @@ -6425,9 +6660,10 @@ static size_t begin(const upb_table *t) { /* A simple "subclass" of upb_table that only adds a hash function for strings. */ static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) { + uint32_t len = (uint32_t) k2.str.len; char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1); if (str == NULL) return 0; - memcpy(str, &k2.str.len, sizeof(uint32_t)); + memcpy(str, &len, sizeof(uint32_t)); memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); return (uintptr_t)str; } @@ -7406,28 +7642,28 @@ static upb_inttable reftables[268]; #endif static const upb_msgdef msgs[22] = { - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftables[1]), - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2], &reftables[3]), - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4], &reftables[5]), - UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftables[7]), - UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &reftables[9]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &reftables[11]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]), - UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], &reftables[15]), - UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], &reftables[17]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &reftables[19]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftables[21]), - UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]), - UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]), - UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &reftables[27]), - UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]), - UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &reftables[31]), - UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], &reftables[33]), - UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables[37]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &reftables[41]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[0], &reftables[1]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[2], &reftables[3]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[4], &reftables[5]), + UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[6], &reftables[7]), + UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[8], &reftables[9]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[10], &reftables[11]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[12], &reftables[13]), + UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[14], &reftables[15]), + UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[16], &reftables[17]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[18], &reftables[19]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[20], &reftables[21]), + UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[22], &reftables[23]), + UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[24], &reftables[25]), + UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[26], &reftables[27]), + UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[28], &reftables[29]), + UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[30], &reftables[31]), + UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[32], &reftables[33]), + UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[34], &reftables[35]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[36], &reftables[37]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[38], &reftables[39]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[40], &reftables[41]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[42], &reftables[43]), }; static const upb_fielddef fields[107] = { @@ -8995,6 +9231,7 @@ static size_t msg_name(void *closure, const void *hd, const char *buf, upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); upb_descreader_setscopename(r, name); /* Passes ownership of name. */ + return n; } @@ -12309,7 +12546,7 @@ done: return r; } -#line 1 "upb/json/parser.rl" +//#line 1 "upb/json/parser.rl" /* ** upb::json::Parser (upb_json_parser) ** @@ -12335,12 +12572,66 @@ done: #include #include #include +#include #include #include +/* Need to define __USE_XOPEN before including time.h to make strptime work. */ +#ifndef __USE_XOPEN +#define __USE_XOPEN +#endif +#include + #define UPB_JSON_MAX_DEPTH 64 +/* Type of value message */ +enum { + VALUE_NULLVALUE = 0, + VALUE_NUMBERVALUE = 1, + VALUE_STRINGVALUE = 2, + VALUE_BOOLVALUE = 3, + VALUE_STRUCTVALUE = 4, + VALUE_LISTVALUE = 5 +}; + +/* Forward declare */ +static bool is_top_level(upb_json_parser *p); +static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type); +static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type); + +static bool is_number_wrapper_object(upb_json_parser *p); +static bool does_number_wrapper_start(upb_json_parser *p); +static bool does_number_wrapper_end(upb_json_parser *p); + +static bool is_string_wrapper_object(upb_json_parser *p); +static bool does_string_wrapper_start(upb_json_parser *p); +static bool does_string_wrapper_end(upb_json_parser *p); + +static void start_wrapper_object(upb_json_parser *p); +static void end_wrapper_object(upb_json_parser *p); + +static void start_value_object(upb_json_parser *p, int value_type); +static void end_value_object(upb_json_parser *p); + +static void start_listvalue_object(upb_json_parser *p); +static void end_listvalue_object(upb_json_parser *p); + +static void start_structvalue_object(upb_json_parser *p); +static void end_structvalue_object(upb_json_parser *p); + +static void start_object(upb_json_parser *p); +static void end_object(upb_json_parser *p); + +static bool start_subobject(upb_json_parser *p); +static void end_subobject(upb_json_parser *p); + +static void start_member(upb_json_parser *p); +static void end_member(upb_json_parser *p); +static bool end_membername(upb_json_parser *p); + +static const char eof_ch = 'e'; + typedef struct { upb_sink sink; @@ -12368,6 +12659,9 @@ typedef struct { * because |f| is the field in the *current* message (i.e., the map-entry * message itself), not the parent's field that leads to this map. */ const upb_fielddef *mapfield; + + /* True if the field to be parsed is unknown. */ + bool is_unknown_field; } upb_jsonparser_frame; struct upb_json_parser { @@ -12405,6 +12699,13 @@ struct upb_json_parser { /* Intermediate result of parsing a unicode escape sequence. */ uint32_t digit; + + /* Whether to proceed if unknown field is met. */ + bool ignore_json_unknown; + + /* Cache for parsing timestamp due to base and zone are handled in different + * handlers. */ + struct tm tm; }; struct upb_json_parsermethod { @@ -12913,21 +13214,71 @@ static bool end_text(upb_json_parser *p, const char *ptr) { return capture_end(p, ptr); } -static void start_number(upb_json_parser *p, const char *ptr) { +static bool start_number(upb_json_parser *p, const char *ptr) { + if (is_top_level(p)) { + if (is_number_wrapper_object(p)) { + start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_NUMBERVALUE); + } else { + return false; + } + } else if (does_number_wrapper_start(p)) { + if (!start_subobject(p)) { + return false; + } + start_wrapper_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_NUMBERVALUE); + } + multipart_startaccum(p); capture_begin(p, ptr); + return true; } static bool parse_number(upb_json_parser *p, bool is_quoted); -static bool end_number(upb_json_parser *p, const char *ptr) { +static bool end_number_nontop(upb_json_parser *p, const char *ptr) { if (!capture_end(p, ptr)) { return false; } + if (p->top->f == NULL) { + multipart_end(p); + return true; + } + return parse_number(p, false); } +static bool end_number(upb_json_parser *p, const char *ptr) { + if (!end_number_nontop(p, ptr)) { + return false; + } + + if (does_number_wrapper_end(p)) { + end_wrapper_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + return true; +} + /* |buf| is NULL-terminated. |buf| itself will never include quotes; * |is_quoted| tells us whether this text originally appeared inside quotes. */ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf, @@ -13077,6 +13428,10 @@ static bool parse_number(upb_json_parser *p, bool is_quoted) { static bool parser_putbool(upb_json_parser *p, bool val) { bool ok; + if (p->top->f == NULL) { + return true; + } + if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) { upb_status_seterrf(&p->status, "Boolean value specified for non-bool field: %s", @@ -13091,8 +13446,120 @@ static bool parser_putbool(upb_json_parser *p, bool val) { return true; } +static bool end_bool(upb_json_parser *p, bool val) { + if (is_top_level(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) { + start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_BOOLVALUE); + } else { + return false; + } + } else if (is_wellknown_field(p, UPB_WELLKNOWN_BOOLVALUE)) { + if (!start_subobject(p)) { + return false; + } + start_wrapper_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_BOOLVALUE); + } + + if (p->top->is_unknown_field) { + return true; + } + + if (!parser_putbool(p, val)) { + return false; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) { + end_wrapper_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + return true; +} + +static bool end_null(upb_json_parser *p) { + const char *zero_ptr = "0"; + + if (is_top_level(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_NULLVALUE); + } else { + return true; + } + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_NULLVALUE); + } else { + return true; + } + + /* Fill null_value field. */ + multipart_startaccum(p); + capture_begin(p, zero_ptr); + capture_end(p, zero_ptr + 1); + parse_number(p, false); + + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + + return true; +} + static bool start_stringval(upb_json_parser *p) { - UPB_ASSERT(p->top->f); + if (is_top_level(p)) { + if (is_string_wrapper_object(p)) { + start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + start_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_STRINGVALUE); + } else { + return false; + } + } else if (does_string_wrapper_start(p)) { + if (!start_subobject(p)) { + return false; + } + start_wrapper_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) { + if (!start_subobject(p)) { + return false; + } + start_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_STRINGVALUE); + } + + if (p->top->f == NULL) { + multipart_startaccum(p); + return true; + } if (upb_fielddef_isstring(p->top->f)) { upb_jsonparser_frame *inner; @@ -13110,6 +13577,7 @@ static bool start_stringval(upb_json_parser *p) { inner->name_table = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_unknown_field = false; p->top = inner; if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) { @@ -13133,73 +13601,369 @@ static bool start_stringval(upb_json_parser *p) { return true; } else { upb_status_seterrf(&p->status, - "String specified for bool or submessage field: %s", - upb_fielddef_name(p->top->f)); + "String specified for bool or submessage field: %s", + upb_fielddef_name(p->top->f)); + upb_env_reporterror(p->env, &p->status); + return false; + } +} + +static bool end_stringval_nontop(upb_json_parser *p) { + bool ok = true; + + if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + multipart_end(p); + return true; + } + + if (p->top->f == NULL) { + multipart_end(p); + return true; + } + + switch (upb_fielddef_type(p->top->f)) { + case UPB_TYPE_BYTES: + if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), + p->accumulated, p->accumulated_len)) { + return false; + } + /* Fall through. */ + + case UPB_TYPE_STRING: { + upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + p->top--; + upb_sink_endstr(&p->top->sink, sel); + break; + } + + case UPB_TYPE_ENUM: { + /* Resolve enum symbolic name to integer value. */ + const upb_enumdef *enumdef = + (const upb_enumdef*)upb_fielddef_subdef(p->top->f); + + size_t len; + const char *buf = accumulate_getptr(p, &len); + + int32_t int_val = 0; + ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); + + if (ok) { + 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); + upb_env_reporterror(p->env, &p->status); + } + + break; + } + + case UPB_TYPE_INT32: + case UPB_TYPE_INT64: + case UPB_TYPE_UINT32: + case UPB_TYPE_UINT64: + case UPB_TYPE_DOUBLE: + case UPB_TYPE_FLOAT: + ok = parse_number(p, true); + break; + + default: + UPB_ASSERT(false); + upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); + upb_env_reporterror(p->env, &p->status); + ok = false; + break; + } + + multipart_end(p); + + return ok; +} + +static bool end_stringval(upb_json_parser *p) { + if (!end_stringval_nontop(p)) { + return false; + } + + if (does_string_wrapper_end(p)) { + end_wrapper_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + end_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + return true; +} + +static void start_duration_base(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +static bool end_duration_base(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + char seconds_buf[14]; + char nanos_buf[12]; + char *end; + int64_t seconds = 0; + int32_t nanos = 0; + double val = 0.0; + const char *seconds_membername = "seconds"; + const char *nanos_membername = "nanos"; + size_t fraction_start; + + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + + memset(seconds_buf, 0, 14); + memset(nanos_buf, 0, 12); + + /* Find out base end. The maximus duration is 315576000000, which cannot be + * represented by double without losing precision. Thus, we need to handle + * fraction and base separately. */ + for (fraction_start = 0; fraction_start < len && buf[fraction_start] != '.'; + fraction_start++); + + /* Parse base */ + memcpy(seconds_buf, buf, fraction_start); + seconds = strtol(seconds_buf, &end, 10); + if (errno == ERANGE || end != seconds_buf + fraction_start) { + upb_status_seterrf(&p->status, "error parsing duration: %s", + seconds_buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + if (seconds > 315576000000) { + upb_status_seterrf(&p->status, "error parsing duration: " + "maximum acceptable value is " + "315576000000"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + if (seconds < -315576000000) { + upb_status_seterrf(&p->status, "error parsing duration: " + "minimum acceptable value is " + "-315576000000"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Parse fraction */ + nanos_buf[0] = '0'; + memcpy(nanos_buf + 1, buf + fraction_start, len - fraction_start); + val = strtod(nanos_buf, &end); + if (errno == ERANGE || end != nanos_buf + len - fraction_start + 1) { + upb_status_seterrf(&p->status, "error parsing duration: %s", + nanos_buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + nanos = val * 1000000000; + if (seconds < 0) nanos = -nanos; + + /* Clean up buffer */ + multipart_end(p); + + /* Set seconds */ + start_member(p); + capture_begin(p, seconds_membername); + capture_end(p, seconds_membername + 7); + end_membername(p); + upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds); + end_member(p); + + /* Set nanos */ + start_member(p); + capture_begin(p, nanos_membername); + capture_end(p, nanos_membername + 5); + end_membername(p); + upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos); + end_member(p); + + /* Continue previous environment */ + multipart_startaccum(p); + + return true; +} + +static void start_timestamp_base(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +#define UPB_TIMESTAMP_BASE_SIZE 19 + +static bool end_timestamp_base(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + /* 3 for GMT and 1 for ending 0 */ + char timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 4]; + + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + UPB_ASSERT(len == UPB_TIMESTAMP_BASE_SIZE); + memcpy(timestamp_buf, buf, UPB_TIMESTAMP_BASE_SIZE); + memcpy(timestamp_buf + UPB_TIMESTAMP_BASE_SIZE, "GMT", 3); + timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 3] = 0; + + /* Parse seconds */ + if (strptime(timestamp_buf, "%FT%H:%M:%S%Z", &p->tm) == NULL) { + upb_status_seterrf(&p->status, "error parsing timestamp: %s", buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Clean up buffer */ + multipart_end(p); + multipart_startaccum(p); + + return true; +} + +static void start_timestamp_fraction(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +static bool end_timestamp_fraction(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + char nanos_buf[12]; + char *end; + double val = 0.0; + int32_t nanos; + const char *nanos_membername = "nanos"; + + memset(nanos_buf, 0, 12); + + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + + if (len > 10) { + upb_status_seterrf(&p->status, + "error parsing timestamp: at most 9-digit fraction."); upb_env_reporterror(p->env, &p->status); return false; } -} -static bool end_stringval(upb_json_parser *p) { - bool ok = true; + /* Parse nanos */ + nanos_buf[0] = '0'; + memcpy(nanos_buf + 1, buf, len); + val = strtod(nanos_buf, &end); - switch (upb_fielddef_type(p->top->f)) { - case UPB_TYPE_BYTES: - if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), - p->accumulated, p->accumulated_len)) { - return false; - } - /* Fall through. */ + if (errno == ERANGE || end != nanos_buf + len + 1) { + upb_status_seterrf(&p->status, "error parsing timestamp nanos: %s", + nanos_buf); + upb_env_reporterror(p->env, &p->status); + return false; + } - case UPB_TYPE_STRING: { - upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); - p->top--; - upb_sink_endstr(&p->top->sink, sel); - break; - } + nanos = val * 1000000000; - case UPB_TYPE_ENUM: { - /* Resolve enum symbolic name to integer value. */ - const upb_enumdef *enumdef = - (const upb_enumdef*)upb_fielddef_subdef(p->top->f); + /* Clean up previous environment */ + multipart_end(p); - size_t len; - const char *buf = accumulate_getptr(p, &len); + /* Set nanos */ + start_member(p); + capture_begin(p, nanos_membername); + capture_end(p, nanos_membername + 5); + end_membername(p); + upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos); + end_member(p); - int32_t int_val = 0; - ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); + /* Continue previous environment */ + multipart_startaccum(p); - if (ok) { - 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); - upb_env_reporterror(p->env, &p->status); - } + return true; +} - break; - } +static void start_timestamp_zone(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} - case UPB_TYPE_INT32: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT32: - case UPB_TYPE_UINT64: - case UPB_TYPE_DOUBLE: - case UPB_TYPE_FLOAT: - ok = parse_number(p, true); - break; +static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + int hours; + int64_t seconds; + const char *seconds_membername = "seconds"; - default: - UPB_ASSERT(false); - upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + + if (buf[0] != 'Z') { + if (sscanf(buf + 1, "%2d:00", &hours) != 1) { + upb_status_seterrf(&p->status, "error parsing timestamp offset"); upb_env_reporterror(p->env, &p->status); - ok = false; - break; + return false; + } + + if (buf[0] == '+') { + hours = -hours; + } + + p->tm.tm_hour += hours; + } + + /* Normalize tm */ + seconds = mktime(&p->tm); + + /* Check timestamp boundary */ + if (seconds < -62135596800) { + upb_status_seterrf(&p->status, "error parsing timestamp: " + "minimum acceptable value is " + "0001-01-01T00:00:00Z"); + upb_env_reporterror(p->env, &p->status); + return false; } + /* Clean up previous environment */ multipart_end(p); - return ok; + /* Set seconds */ + start_member(p); + capture_begin(p, seconds_membername); + capture_end(p, seconds_membername + 7); + end_membername(p); + upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds); + end_member(p); + + /* Continue previous environment */ + multipart_startaccum(p); + + return true; } static void start_member(upb_json_parser *p) { @@ -13305,6 +14069,7 @@ static bool handle_mapentry(upb_json_parser *p) { inner->name_table = NULL; inner->mapfield = mapfield; inner->is_map = false; + inner->is_unknown_field = false; /* Don't set this to true *yet* -- we reuse parsing handlers below to push * the key field value to the sink, and these handlers will pop the frame @@ -13334,6 +14099,12 @@ static bool handle_mapentry(upb_json_parser *p) { static bool end_membername(upb_json_parser *p) { UPB_ASSERT(!p->top->f); + if (!p->top->m) { + p->top->is_unknown_field = true; + multipart_end(p); + return true; + } + if (p->top->is_map) { return handle_mapentry(p); } else { @@ -13345,10 +14116,12 @@ static bool end_membername(upb_json_parser *p) { p->top->f = upb_value_getconstptr(v); multipart_end(p); + return true; + } else if (p->ignore_json_unknown) { + p->top->is_unknown_field = true; + multipart_end(p); return true; } else { - /* TODO(haberman): Ignore unknown fields if requested/configured to do - * so. */ upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); upb_env_reporterror(p->env, &p->status); return false; @@ -13377,10 +14150,23 @@ static void end_member(upb_json_parser *p) { } p->top->f = NULL; + p->top->is_unknown_field = false; } static bool start_subobject(upb_json_parser *p) { - UPB_ASSERT(p->top->f); + if (p->top->is_unknown_field) { + upb_jsonparser_frame *inner; + if (!check_stack(p)) return false; + + inner = p->top + 1; + inner->m = NULL; + inner->f = NULL; + inner->is_map = false; + inner->is_mapentry = false; + inner->is_unknown_field = false; + p->top = inner; + return true; + } if (upb_fielddef_ismap(p->top->f)) { upb_jsonparser_frame *inner; @@ -13399,6 +14185,7 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = true; inner->is_mapentry = false; + inner->is_unknown_field = false; p->top = inner; return true; @@ -13419,6 +14206,7 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_unknown_field = false; p->top = inner; return true; @@ -13431,7 +14219,35 @@ static bool start_subobject(upb_json_parser *p) { } } +static bool start_subobject_full(upb_json_parser *p) { + if (is_top_level(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_STRUCTVALUE); + if (!start_subobject(p)) return false; + start_structvalue_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) { + start_structvalue_object(p); + } else { + return true; + } + } else if (is_wellknown_field(p, UPB_WELLKNOWN_STRUCT)) { + if (!start_subobject(p)) return false; + start_structvalue_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) return false; + start_value_object(p, VALUE_STRUCTVALUE); + if (!start_subobject(p)) return false; + start_structvalue_object(p); + } + + return start_subobject(p); +} + static void end_subobject(upb_json_parser *p) { + if (is_top_level(p)) { + return; + } + if (p->top->is_map) { upb_selector_t sel; p->top--; @@ -13439,9 +14255,30 @@ static void end_subobject(upb_json_parser *p) { upb_sink_endseq(&p->top->sink, sel); } else { upb_selector_t sel; + bool is_unknown = p->top->m == NULL; p->top--; - sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); - upb_sink_endsubmsg(&p->top->sink, sel); + if (!is_unknown) { + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); + upb_sink_endsubmsg(&p->top->sink, sel); + } + } +} + +static void end_subobject_full(upb_json_parser *p) { + end_subobject(p); + + if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) { + end_structvalue_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } } } @@ -13449,7 +14286,38 @@ static bool start_array(upb_json_parser *p) { upb_jsonparser_frame *inner; upb_selector_t sel; - UPB_ASSERT(p->top->f); + if (is_top_level(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_LISTVALUE); + if (!start_subobject(p)) return false; + start_listvalue_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) { + start_listvalue_object(p); + } else { + return false; + } + } else if (is_wellknown_field(p, UPB_WELLKNOWN_LISTVALUE)) { + if (!start_subobject(p)) return false; + start_listvalue_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) return false; + start_value_object(p, VALUE_LISTVALUE); + if (!start_subobject(p)) return false; + start_listvalue_object(p); + } + + if (p->top->is_unknown_field) { + inner = p->top + 1; + inner->m = NULL; + inner->name_table = NULL; + inner->f = NULL; + inner->is_map = false; + inner->is_mapentry = false; + inner->is_unknown_field = true; + p->top = inner; + + return true; + } if (!upb_fielddef_isseq(p->top->f)) { upb_status_seterrf(&p->status, @@ -13469,6 +14337,7 @@ static bool start_array(upb_json_parser *p) { inner->f = p->top->f; inner->is_map = false; inner->is_mapentry = false; + inner->is_unknown_field = false; p->top = inner; return true; @@ -13480,18 +14349,37 @@ static void end_array(upb_json_parser *p) { UPB_ASSERT(p->top > p->stack); p->top--; + + if (p->top->is_unknown_field) { + return; + } + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); upb_sink_endseq(&p->top->sink, sel); + + if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) { + end_listvalue_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + } } static void start_object(upb_json_parser *p) { - if (!p->top->is_map) { + if (!p->top->is_map && p->top->m != NULL) { upb_sink_startmsg(&p->top->sink); } } static void end_object(upb_json_parser *p) { - if (!p->top->is_map) { + if (!p->top->is_map && p->top->m != NULL) { upb_status status; upb_status_clear(&status); upb_sink_endmsg(&p->top->sink, &status); @@ -13501,6 +14389,149 @@ static void end_object(upb_json_parser *p) { } } +static bool is_string_wrapper(const upb_msgdef *m) { + upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); + return type == UPB_WELLKNOWN_STRINGVALUE || + type == UPB_WELLKNOWN_BYTESVALUE; +} + +static void start_wrapper_object(upb_json_parser *p) { + const char *membername = "value"; + + start_object(p); + + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + 5); + end_membername(p); +} + +static void end_wrapper_object(upb_json_parser *p) { + end_member(p); + end_object(p); +} + +static void start_value_object(upb_json_parser *p, int value_type) { + const char *nullmember = "null_value"; + const char *numbermember = "number_value"; + const char *stringmember = "string_value"; + const char *boolmember = "bool_value"; + const char *structmember = "struct_value"; + const char *listmember = "list_value"; + const char *membername = ""; + + switch (value_type) { + case VALUE_NULLVALUE: + membername = nullmember; + break; + case VALUE_NUMBERVALUE: + membername = numbermember; + break; + case VALUE_STRINGVALUE: + membername = stringmember; + break; + case VALUE_BOOLVALUE: + membername = boolmember; + break; + case VALUE_STRUCTVALUE: + membername = structmember; + break; + case VALUE_LISTVALUE: + membername = listmember; + break; + } + + start_object(p); + + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + strlen(membername)); + end_membername(p); +} + +static void end_value_object(upb_json_parser *p) { + end_member(p); + end_object(p); +} + +static void start_listvalue_object(upb_json_parser *p) { + const char *membername = "values"; + + start_object(p); + + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + strlen(membername)); + end_membername(p); +} + +static void end_listvalue_object(upb_json_parser *p) { + end_member(p); + end_object(p); +} + +static void start_structvalue_object(upb_json_parser *p) { + const char *membername = "fields"; + + start_object(p); + + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + strlen(membername)); + end_membername(p); +} + +static void end_structvalue_object(upb_json_parser *p) { + end_member(p); + end_object(p); +} + +static bool is_top_level(upb_json_parser *p) { + return p->top == p->stack && p->top->f == NULL && !p->top->is_unknown_field; +} + +static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type) { + return p->top->m != NULL && upb_msgdef_wellknowntype(p->top->m) == type; +} + +static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type) { + return p->top->f != NULL && + upb_fielddef_issubmsg(p->top->f) && + (upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(p->top->f)) + == type); +} + +static bool does_number_wrapper_start(upb_json_parser *p) { + return p->top->f != NULL && + upb_fielddef_issubmsg(p->top->f) && + upb_msgdef_isnumberwrapper(upb_fielddef_msgsubdef(p->top->f)); +} + +static bool does_number_wrapper_end(upb_json_parser *p) { + return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m); +} + +static bool is_number_wrapper_object(upb_json_parser *p) { + return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m); +} + +static bool does_string_wrapper_start(upb_json_parser *p) { + return p->top->f != NULL && + upb_fielddef_issubmsg(p->top->f) && + is_string_wrapper(upb_fielddef_msgsubdef(p->top->f)); +} + +static bool does_string_wrapper_end(upb_json_parser *p) { + return p->top->m != NULL && is_string_wrapper(p->top->m); +} + +static bool is_string_wrapper_object(upb_json_parser *p) { + return p->top->m != NULL && is_string_wrapper(p->top->m); +} #define CHECK_RETURN_TOP(x) if (!(x)) goto error @@ -13523,160 +14554,262 @@ static void end_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -#line 1310 "upb/json/parser.rl" +//#line 2147 "upb/json/parser.rl" -#line 1222 "upb/json/parser.c" +//#line 2016 "upb/json/parser.c" static const char _json_actions[] = { - 0, 1, 0, 1, 2, 1, 3, 1, - 5, 1, 6, 1, 7, 1, 8, 1, - 10, 1, 12, 1, 13, 1, 14, 1, - 15, 1, 16, 1, 17, 1, 21, 1, - 25, 1, 27, 2, 3, 8, 2, 4, - 5, 2, 6, 2, 2, 6, 8, 2, - 11, 9, 2, 13, 15, 2, 14, 15, - 2, 18, 1, 2, 19, 27, 2, 20, - 9, 2, 22, 27, 2, 23, 27, 2, - 24, 27, 2, 26, 27, 3, 14, 11, - 9 + 0, 1, 0, 1, 1, 1, 3, 1, + 4, 1, 6, 1, 7, 1, 8, 1, + 9, 1, 10, 1, 11, 1, 12, 1, + 13, 1, 21, 1, 23, 1, 24, 1, + 25, 1, 27, 1, 28, 1, 30, 1, + 32, 1, 33, 1, 34, 1, 35, 1, + 36, 1, 38, 2, 4, 9, 2, 5, + 6, 2, 7, 3, 2, 7, 9, 2, + 14, 15, 2, 16, 17, 2, 18, 19, + 2, 22, 20, 2, 26, 37, 2, 29, + 2, 2, 30, 38, 2, 31, 20, 2, + 33, 38, 2, 34, 38, 2, 35, 38, + 3, 25, 22, 20, 3, 26, 37, 38, + 4, 14, 15, 16, 17 }; -static const unsigned char _json_key_offsets[] = { - 0, 0, 4, 9, 14, 15, 19, 24, - 29, 34, 38, 42, 45, 48, 50, 54, - 58, 60, 62, 67, 69, 71, 80, 86, - 92, 98, 104, 106, 115, 116, 116, 116, - 121, 126, 131, 132, 133, 134, 135, 135, - 136, 137, 138, 138, 139, 140, 141, 141, - 146, 151, 152, 156, 161, 166, 171, 175, - 175, 178, 178, 178 +static const short _json_key_offsets[] = { + 0, 0, 12, 13, 18, 23, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, + 38, 43, 48, 49, 53, 58, 63, 68, + 72, 76, 79, 82, 84, 88, 92, 94, + 96, 101, 103, 105, 114, 120, 126, 132, + 138, 140, 144, 147, 149, 151, 154, 155, + 159, 161, 163, 165, 167, 168, 170, 172, + 173, 175, 177, 178, 180, 182, 183, 185, + 187, 188, 190, 192, 196, 198, 200, 201, + 202, 203, 204, 206, 211, 220, 221, 221, + 221, 226, 231, 236, 237, 238, 239, 240, + 240, 241, 242, 243, 243, 244, 245, 246, + 246, 251, 256, 257, 261, 266, 271, 276, + 280, 280, 283, 286, 289, 292, 295, 298, + 298, 298, 298, 298 }; static const char _json_trans_keys[] = { - 32, 123, 9, 13, 32, 34, 125, 9, - 13, 32, 34, 125, 9, 13, 34, 32, - 58, 9, 13, 32, 93, 125, 9, 13, - 32, 44, 125, 9, 13, 32, 44, 125, - 9, 13, 32, 34, 9, 13, 45, 48, - 49, 57, 48, 49, 57, 46, 69, 101, - 48, 57, 69, 101, 48, 57, 43, 45, - 48, 57, 48, 57, 48, 57, 46, 69, - 101, 48, 57, 34, 92, 34, 92, 34, - 47, 92, 98, 102, 110, 114, 116, 117, + 32, 34, 45, 91, 102, 110, 116, 123, + 9, 13, 48, 57, 34, 32, 93, 125, + 9, 13, 32, 44, 93, 9, 13, 32, + 93, 125, 9, 13, 97, 108, 115, 101, + 117, 108, 108, 114, 117, 101, 32, 34, + 125, 9, 13, 32, 34, 125, 9, 13, + 34, 32, 58, 9, 13, 32, 93, 125, + 9, 13, 32, 44, 125, 9, 13, 32, + 44, 125, 9, 13, 32, 34, 9, 13, + 45, 48, 49, 57, 48, 49, 57, 46, + 69, 101, 48, 57, 69, 101, 48, 57, + 43, 45, 48, 57, 48, 57, 48, 57, + 46, 69, 101, 48, 57, 34, 92, 34, + 92, 34, 47, 92, 98, 102, 110, 114, + 116, 117, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, - 97, 102, 48, 57, 65, 70, 97, 102, - 34, 92, 34, 45, 91, 102, 110, 116, - 123, 48, 57, 34, 32, 93, 125, 9, - 13, 32, 44, 93, 9, 13, 32, 93, - 125, 9, 13, 97, 108, 115, 101, 117, - 108, 108, 114, 117, 101, 32, 34, 125, - 9, 13, 32, 34, 125, 9, 13, 34, - 32, 58, 9, 13, 32, 93, 125, 9, - 13, 32, 44, 125, 9, 13, 32, 44, - 125, 9, 13, 32, 34, 9, 13, 32, + 97, 102, 34, 92, 45, 48, 49, 57, + 48, 49, 57, 46, 115, 48, 57, 115, + 48, 57, 34, 46, 115, 48, 57, 48, + 57, 48, 57, 48, 57, 48, 57, 45, + 48, 57, 48, 57, 45, 48, 57, 48, + 57, 84, 48, 57, 48, 57, 58, 48, + 57, 48, 57, 58, 48, 57, 48, 57, + 43, 45, 46, 90, 48, 57, 48, 57, + 58, 48, 48, 34, 48, 57, 43, 45, + 90, 48, 57, 34, 45, 91, 102, 110, + 116, 123, 48, 57, 34, 32, 93, 125, + 9, 13, 32, 44, 93, 9, 13, 32, + 93, 125, 9, 13, 97, 108, 115, 101, + 117, 108, 108, 114, 117, 101, 32, 34, + 125, 9, 13, 32, 34, 125, 9, 13, + 34, 32, 58, 9, 13, 32, 93, 125, + 9, 13, 32, 44, 125, 9, 13, 32, + 44, 125, 9, 13, 32, 34, 9, 13, + 32, 9, 13, 32, 9, 13, 32, 9, + 13, 32, 9, 13, 32, 9, 13, 32, 9, 13, 0 }; static const char _json_single_lengths[] = { - 0, 2, 3, 3, 1, 2, 3, 3, - 3, 2, 2, 1, 3, 0, 2, 2, - 0, 0, 3, 2, 2, 9, 0, 0, - 0, 0, 2, 7, 1, 0, 0, 3, - 3, 3, 1, 1, 1, 1, 0, 1, - 1, 1, 0, 1, 1, 1, 0, 3, - 3, 1, 2, 3, 3, 3, 2, 0, - 1, 0, 0, 0 + 0, 8, 1, 3, 3, 3, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 3, 3, 1, 2, 3, 3, 3, 2, + 2, 1, 3, 0, 2, 2, 0, 0, + 3, 2, 2, 9, 0, 0, 0, 0, + 2, 2, 1, 2, 0, 1, 1, 2, + 0, 0, 0, 0, 1, 0, 0, 1, + 0, 0, 1, 0, 0, 1, 0, 0, + 1, 0, 0, 4, 0, 0, 1, 1, + 1, 1, 0, 3, 7, 1, 0, 0, + 3, 3, 3, 1, 1, 1, 1, 0, + 1, 1, 1, 0, 1, 1, 1, 0, + 3, 3, 1, 2, 3, 3, 3, 2, + 0, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0 }; static const char _json_range_lengths[] = { - 0, 1, 1, 1, 0, 1, 1, 1, - 1, 1, 1, 1, 0, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 3, 3, - 3, 3, 0, 1, 0, 0, 0, 1, - 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 1, 1, 1, 1, 1, 0, - 1, 0, 0, 0 + 0, 2, 0, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 3, 3, 3, 3, + 0, 1, 1, 0, 1, 1, 0, 1, + 1, 1, 1, 1, 0, 1, 1, 0, + 1, 1, 0, 1, 1, 0, 1, 1, + 0, 1, 1, 0, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 0, 0, 0, + 1, 1, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 0, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0 }; static const short _json_index_offsets[] = { - 0, 0, 4, 9, 14, 16, 20, 25, - 30, 35, 39, 43, 46, 50, 52, 56, - 60, 62, 64, 69, 72, 75, 85, 89, - 93, 97, 101, 104, 113, 115, 116, 117, - 122, 127, 132, 134, 136, 138, 140, 141, - 143, 145, 147, 148, 150, 152, 154, 155, - 160, 165, 167, 171, 176, 181, 186, 190, - 191, 194, 195, 196 + 0, 0, 11, 13, 18, 23, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, + 48, 53, 58, 60, 64, 69, 74, 79, + 83, 87, 90, 94, 96, 100, 104, 106, + 108, 113, 116, 119, 129, 133, 137, 141, + 145, 148, 152, 155, 158, 160, 163, 165, + 169, 171, 173, 175, 177, 179, 181, 183, + 185, 187, 189, 191, 193, 195, 197, 199, + 201, 203, 205, 207, 212, 214, 216, 218, + 220, 222, 224, 226, 231, 240, 242, 243, + 244, 249, 254, 259, 261, 263, 265, 267, + 268, 270, 272, 274, 275, 277, 279, 281, + 282, 287, 292, 294, 298, 303, 308, 313, + 317, 318, 321, 324, 327, 330, 333, 336, + 337, 338, 339, 340 }; -static const char _json_indicies[] = { - 0, 2, 0, 1, 3, 4, 5, 3, - 1, 6, 7, 8, 6, 1, 9, 1, - 10, 11, 10, 1, 11, 1, 1, 11, - 12, 13, 14, 15, 13, 1, 16, 17, - 8, 16, 1, 17, 7, 17, 1, 18, - 19, 20, 1, 19, 20, 1, 22, 23, - 23, 21, 24, 1, 23, 23, 24, 21, - 25, 25, 26, 1, 26, 1, 26, 21, - 22, 23, 23, 20, 21, 28, 29, 27, - 31, 32, 30, 33, 33, 33, 33, 33, - 33, 33, 33, 34, 1, 35, 35, 35, - 1, 36, 36, 36, 1, 37, 37, 37, - 1, 38, 38, 38, 1, 40, 41, 39, - 42, 43, 44, 45, 46, 47, 48, 43, - 1, 49, 1, 50, 51, 53, 54, 1, - 53, 52, 55, 56, 54, 55, 1, 56, - 1, 1, 56, 52, 57, 1, 58, 1, - 59, 1, 60, 1, 61, 62, 1, 63, - 1, 64, 1, 65, 66, 1, 67, 1, - 68, 1, 69, 70, 71, 72, 70, 1, - 73, 74, 75, 73, 1, 76, 1, 77, - 78, 77, 1, 78, 1, 1, 78, 79, - 80, 81, 82, 80, 1, 83, 84, 75, - 83, 1, 84, 74, 84, 1, 85, 86, - 86, 1, 1, 1, 1, 0 +static const unsigned char _json_indicies[] = { + 0, 2, 3, 4, 5, 6, 7, 8, + 0, 3, 1, 9, 1, 11, 12, 1, + 11, 10, 13, 14, 12, 13, 1, 14, + 1, 1, 14, 10, 15, 1, 16, 1, + 17, 1, 18, 1, 19, 1, 20, 1, + 21, 1, 22, 1, 23, 1, 24, 1, + 25, 26, 27, 25, 1, 28, 29, 30, + 28, 1, 31, 1, 32, 33, 32, 1, + 33, 1, 1, 33, 34, 35, 36, 37, + 35, 1, 38, 39, 30, 38, 1, 39, + 29, 39, 1, 40, 41, 42, 1, 41, + 42, 1, 44, 45, 45, 43, 46, 1, + 45, 45, 46, 43, 47, 47, 48, 1, + 48, 1, 48, 43, 44, 45, 45, 42, + 43, 50, 51, 49, 53, 54, 52, 55, + 55, 55, 55, 55, 55, 55, 55, 56, + 1, 57, 57, 57, 1, 58, 58, 58, + 1, 59, 59, 59, 1, 60, 60, 60, + 1, 62, 63, 61, 64, 65, 66, 1, + 67, 68, 1, 69, 70, 1, 71, 1, + 70, 71, 1, 72, 1, 69, 70, 68, + 1, 73, 1, 74, 1, 75, 1, 76, + 1, 77, 1, 78, 1, 79, 1, 80, + 1, 81, 1, 82, 1, 83, 1, 84, + 1, 85, 1, 86, 1, 87, 1, 88, + 1, 89, 1, 90, 1, 91, 1, 92, + 92, 93, 94, 1, 95, 1, 96, 1, + 97, 1, 98, 1, 99, 1, 100, 1, + 101, 1, 102, 102, 103, 101, 1, 104, + 105, 106, 107, 108, 109, 110, 105, 1, + 111, 1, 112, 113, 115, 116, 1, 115, + 114, 117, 118, 116, 117, 1, 118, 1, + 1, 118, 114, 119, 1, 120, 1, 121, + 1, 122, 1, 123, 124, 1, 125, 1, + 126, 1, 127, 128, 1, 129, 1, 130, + 1, 131, 132, 133, 134, 132, 1, 135, + 136, 137, 135, 1, 138, 1, 139, 140, + 139, 1, 140, 1, 1, 140, 141, 142, + 143, 144, 142, 1, 145, 146, 137, 145, + 1, 146, 136, 146, 1, 147, 148, 148, + 1, 149, 149, 1, 150, 150, 1, 151, + 151, 1, 152, 152, 1, 153, 153, 1, + 1, 1, 1, 1, 1, 0 }; static const char _json_trans_targs[] = { - 1, 0, 2, 3, 4, 56, 3, 4, - 56, 5, 5, 6, 7, 8, 9, 56, - 8, 9, 11, 12, 18, 57, 13, 15, - 14, 16, 17, 20, 58, 21, 20, 58, - 21, 19, 22, 23, 24, 25, 26, 20, - 58, 21, 28, 30, 31, 34, 39, 43, - 47, 29, 59, 59, 32, 31, 29, 32, - 33, 35, 36, 37, 38, 59, 40, 41, - 42, 59, 44, 45, 46, 59, 48, 49, - 55, 48, 49, 55, 50, 50, 51, 52, - 53, 54, 55, 53, 54, 59, 56 + 1, 0, 2, 106, 3, 6, 10, 13, + 16, 105, 4, 3, 105, 4, 5, 7, + 8, 9, 107, 11, 12, 108, 14, 15, + 109, 17, 18, 110, 17, 18, 110, 19, + 19, 20, 21, 22, 23, 110, 22, 23, + 25, 26, 32, 111, 27, 29, 28, 30, + 31, 34, 112, 35, 34, 112, 35, 33, + 36, 37, 38, 39, 40, 34, 112, 35, + 42, 43, 47, 43, 47, 44, 46, 45, + 113, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 74, 73, 69, + 70, 71, 72, 73, 114, 75, 68, 73, + 77, 79, 80, 83, 88, 92, 96, 78, + 115, 115, 81, 80, 78, 81, 82, 84, + 85, 86, 87, 115, 89, 90, 91, 115, + 93, 94, 95, 115, 97, 98, 104, 97, + 98, 104, 99, 99, 100, 101, 102, 103, + 104, 102, 103, 115, 105, 105, 105, 105, + 105, 105 }; static const char _json_trans_actions[] = { - 0, 0, 0, 21, 77, 53, 0, 47, - 23, 17, 0, 0, 15, 19, 19, 50, - 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 3, 13, 0, 0, 35, - 5, 11, 0, 38, 7, 7, 7, 41, - 44, 9, 62, 56, 25, 0, 0, 0, - 31, 29, 33, 59, 15, 0, 27, 0, - 0, 0, 0, 0, 0, 68, 0, 0, - 0, 71, 0, 0, 0, 65, 21, 77, - 53, 0, 47, 23, 17, 0, 0, 15, - 19, 19, 50, 0, 0, 74, 0 + 0, 0, 84, 78, 33, 0, 0, 0, + 47, 39, 25, 0, 35, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 31, 96, 31, 0, 72, 0, 27, + 0, 0, 25, 29, 29, 29, 0, 0, + 0, 0, 0, 3, 0, 0, 0, 0, + 0, 5, 15, 0, 0, 51, 7, 13, + 0, 54, 9, 9, 9, 57, 60, 11, + 17, 17, 17, 0, 0, 0, 19, 0, + 21, 23, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 104, 63, 104, 0, + 0, 0, 0, 0, 69, 0, 66, 66, + 84, 78, 33, 0, 0, 0, 47, 39, + 49, 81, 25, 0, 35, 0, 0, 0, + 0, 0, 0, 90, 0, 0, 0, 93, + 0, 0, 0, 87, 31, 96, 31, 0, + 72, 0, 27, 0, 0, 25, 29, 29, + 29, 0, 0, 100, 0, 37, 43, 45, + 41, 75 +}; + +static const char _json_eof_actions[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 37, 43, 45, 41, 75, 0, + 0, 0, 0, 0 }; static const int json_start = 1; -static const int json_en_number_machine = 10; -static const int json_en_string_machine = 19; -static const int json_en_value_machine = 27; +static const int json_en_number_machine = 24; +static const int json_en_string_machine = 33; +static const int json_en_duration_machine = 41; +static const int json_en_timestamp_machine = 48; +static const int json_en_value_machine = 76; static const int json_en_main = 1; -#line 1313 "upb/json/parser.rl" +//#line 2150 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -13689,6 +14822,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, const char *p = buf; const char *pe = buf + size; + const char *eof = &eof_ch; parser->handle = handle; @@ -13698,7 +14832,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -#line 1393 "upb/json/parser.c" +//#line 2290 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -13772,119 +14906,167 @@ _match: { switch ( *_acts++ ) { - case 0: -#line 1225 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } - break; case 1: -#line 1226 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 10; goto _again;} } +//#line 2021 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; case 2: -#line 1230 "upb/json/parser.rl" - { start_text(parser, p); } +//#line 2023 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 24; goto _again;} } break; case 3: -#line 1231 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_text(parser, p)); } +//#line 2027 "upb/json/parser.rl" + { start_text(parser, p); } break; case 4: -#line 1237 "upb/json/parser.rl" - { start_hex(parser); } +//#line 2028 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 5: -#line 1238 "upb/json/parser.rl" - { hexdigit(parser, p); } +//#line 2034 "upb/json/parser.rl" + { start_hex(parser); } break; case 6: -#line 1239 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_hex(parser)); } +//#line 2035 "upb/json/parser.rl" + { hexdigit(parser, p); } break; case 7: -#line 1245 "upb/json/parser.rl" - { CHECK_RETURN_TOP(escape(parser, p)); } +//#line 2036 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_hex(parser)); } break; case 8: -#line 1251 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } +//#line 2042 "upb/json/parser.rl" + { CHECK_RETURN_TOP(escape(parser, p)); } break; case 9: -#line 1254 "upb/json/parser.rl" - { {stack[top++] = cs; cs = 19; goto _again;} } +//#line 2048 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; case 10: -#line 1256 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 27; goto _again;} } +//#line 2060 "upb/json/parser.rl" + { start_duration_base(parser, p); } break; case 11: -#line 1261 "upb/json/parser.rl" - { start_member(parser); } +//#line 2061 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_duration_base(parser, p)); } break; case 12: -#line 1262 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_membername(parser)); } +//#line 2063 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; case 13: -#line 1265 "upb/json/parser.rl" - { end_member(parser); } +//#line 2068 "upb/json/parser.rl" + { start_timestamp_base(parser, p); } break; case 14: -#line 1271 "upb/json/parser.rl" - { start_object(parser); } +//#line 2069 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } break; case 15: -#line 1274 "upb/json/parser.rl" - { end_object(parser); } +//#line 2071 "upb/json/parser.rl" + { start_timestamp_fraction(parser, p); } break; case 16: -#line 1280 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_array(parser)); } +//#line 2072 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } break; case 17: -#line 1284 "upb/json/parser.rl" +//#line 2074 "upb/json/parser.rl" + { start_timestamp_zone(parser, p); } + break; + case 18: +//#line 2075 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } + break; + case 19: +//#line 2077 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } + break; + case 20: +//#line 2082 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { + {stack[top++] = cs; cs = 48; goto _again;} + } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) { + {stack[top++] = cs; cs = 41; goto _again;} + } else { + {stack[top++] = cs; cs = 33; goto _again;} + } + } + break; + case 21: +//#line 2093 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 76; goto _again;} } + break; + case 22: +//#line 2098 "upb/json/parser.rl" + { start_member(parser); } + break; + case 23: +//#line 2099 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_membername(parser)); } + break; + case 24: +//#line 2102 "upb/json/parser.rl" + { end_member(parser); } + break; + case 25: +//#line 2108 "upb/json/parser.rl" + { start_object(parser); } + break; + case 26: +//#line 2111 "upb/json/parser.rl" + { end_object(parser); } + break; + case 27: +//#line 2117 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_array(parser)); } + break; + case 28: +//#line 2121 "upb/json/parser.rl" { end_array(parser); } break; - case 18: -#line 1289 "upb/json/parser.rl" - { start_number(parser, p); } + case 29: +//#line 2126 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_number(parser, p)); } break; - case 19: -#line 1290 "upb/json/parser.rl" + case 30: +//#line 2127 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; - case 20: -#line 1292 "upb/json/parser.rl" + case 31: +//#line 2129 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_stringval(parser)); } break; - case 21: -#line 1293 "upb/json/parser.rl" + case 32: +//#line 2130 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_stringval(parser)); } break; - case 22: -#line 1295 "upb/json/parser.rl" - { CHECK_RETURN_TOP(parser_putbool(parser, true)); } + case 33: +//#line 2132 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, true)); } break; - case 23: -#line 1297 "upb/json/parser.rl" - { CHECK_RETURN_TOP(parser_putbool(parser, false)); } + case 34: +//#line 2134 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, false)); } break; - case 24: -#line 1299 "upb/json/parser.rl" - { /* null value */ } + case 35: +//#line 2136 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_null(parser)); } break; - case 25: -#line 1301 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_subobject(parser)); } + case 36: +//#line 2138 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_subobject_full(parser)); } break; - case 26: -#line 1302 "upb/json/parser.rl" - { end_subobject(parser); } + case 37: +//#line 2139 "upb/json/parser.rl" + { end_subobject_full(parser); } break; - case 27: -#line 1307 "upb/json/parser.rl" + case 38: +//#line 2144 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -#line 1579 "upb/json/parser.c" +//#line 2524 "upb/json/parser.c" } } @@ -13894,10 +15076,49 @@ _again: if ( ++p != pe ) goto _resume; _test_eof: {} + if ( p == eof ) + { + const char *__acts = _json_actions + _json_eof_actions[cs]; + unsigned int __nacts = (unsigned int) *__acts++; + while ( __nacts-- > 0 ) { + switch ( *__acts++ ) { + case 0: +//#line 2019 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } + break; + case 26: +//#line 2111 "upb/json/parser.rl" + { end_object(parser); } + break; + case 30: +//#line 2127 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_number(parser, p)); } + break; + case 33: +//#line 2132 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, true)); } + break; + case 34: +//#line 2134 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, false)); } + break; + case 35: +//#line 2136 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_null(parser)); } + break; + case 37: +//#line 2139 "upb/json/parser.rl" + { end_subobject_full(parser); } + break; +//#line 2568 "upb/json/parser.c" + } + } + } + _out: {} } -#line 1334 "upb/json/parser.rl" +//#line 2172 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -13915,16 +15136,24 @@ error: } bool end(void *closure, const void *hd) { - UPB_UNUSED(closure); - UPB_UNUSED(hd); + upb_json_parser *parser = closure; /* Prevent compile warning on unused static constants. */ UPB_UNUSED(json_start); + UPB_UNUSED(json_en_duration_machine); UPB_UNUSED(json_en_number_machine); UPB_UNUSED(json_en_string_machine); + UPB_UNUSED(json_en_timestamp_machine); UPB_UNUSED(json_en_value_machine); UPB_UNUSED(json_en_main); - return true; + + parse(parser, hd, &eof_ch, 0, NULL); + + return parser->current_state >= +//#line 2608 "upb/json/parser.c" +105 +//#line 2202 "upb/json/parser.rl" +; } static void json_parser_reset(upb_json_parser *p) { @@ -13935,16 +15164,17 @@ static void json_parser_reset(upb_json_parser *p) { p->top->f = NULL; p->top->is_map = false; p->top->is_mapentry = false; + p->top->is_unknown_field = false; /* Emit Ragel initialization of the parser. */ -#line 1633 "upb/json/parser.c" +//#line 2626 "upb/json/parser.c" { cs = json_start; top = 0; } -#line 1374 "upb/json/parser.rl" +//#line 2217 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -14031,7 +15261,8 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { upb_json_parser *upb_json_parser_create(upb_env *env, const upb_json_parsermethod *method, - upb_sink *output) { + upb_sink *output, + bool ignore_json_unknown) { #ifndef NDEBUG const size_t size_before = upb_env_bytesallocated(env); #endif @@ -14050,6 +15281,8 @@ upb_json_parser *upb_json_parser_create(upb_env *env, p->top->m = upb_handlers_msgdef(output->handlers); set_name_table(p, p->top); + p->ignore_json_unknown = ignore_json_unknown; + /* If this fails, uncomment and increase the value in parser.h. */ /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <= @@ -14094,6 +15327,7 @@ const upb_byteshandler *upb_json_parsermethod_inputhandler( #include #include +#include struct upb_json_printer { upb_sink input_; @@ -14114,6 +15348,12 @@ struct upb_json_printer { * repeated fields and messages (maps), and the worst case is a * message->repeated field->submessage->repeated field->... nesting. */ bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; + + /* To print timestamp, printer needs to cache its seconds and nanos values + * and convert them when ending timestamp message. See comments of + * printer_sethandlers_timestamp for more detail. */ + int64_t seconds; + int32_t nanos; }; /* StringPiece; a pointer plus a length. */ @@ -14772,6 +16012,369 @@ void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames, upb_handlerattr_uninit(&empty_attr); } +static bool putseconds(void *closure, const void *handler_data, + int64_t seconds) { + upb_json_printer *p = closure; + p->seconds = seconds; + UPB_UNUSED(handler_data); + return true; +} + +static bool putnanos(void *closure, const void *handler_data, + int32_t nanos) { + upb_json_printer *p = closure; + p->nanos = nanos; + UPB_UNUSED(handler_data); + return true; +} + +static void *scalar_startstr_nokey(void *closure, const void *handler_data, + size_t size_hint) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(size_hint); + print_data(p, "\"", 1); + return p; +} + +static size_t putstr_nokey(void *closure, const void *handler_data, + const char *str, size_t len, + const upb_bufhandle *handle) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(handle); + print_data(p, "\"", 1); + putstring(p, str, len); + print_data(p, "\"", 1); + return len + 2; +} + +static void *startseq_nokey(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_++; + p->first_elem_[p->depth_] = true; + print_data(p, "[", 1); + return closure; +} + +static void *startmap_nokey(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_++; + p->first_elem_[p->depth_] = true; + print_data(p, "{", 1); + return closure; +} + +static bool putnull(void *closure, const void *handler_data, + int32_t null) { + upb_json_printer *p = closure; + print_data(p, "null", 4); + UPB_UNUSED(handler_data); + UPB_UNUSED(null); + return true; +} + +static bool printer_startdurationmsg(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + if (p->depth_ == 0) { + upb_bytessink_start(p->output_, 0, &p->subc_); + } + return true; +} + +#define UPB_DURATION_MAX_JSON_LEN 23 +#define UPB_DURATION_MAX_NANO_LEN 9 + +static bool printer_enddurationmsg(void *closure, const void *handler_data, + upb_status *s) { + upb_json_printer *p = closure; + char buffer[UPB_DURATION_MAX_JSON_LEN]; + size_t base_len; + size_t curr; + size_t i; + + memset(buffer, 0, UPB_DURATION_MAX_JSON_LEN); + + if (p->seconds < -315576000000) { + upb_status_seterrf(s, "error parsing duration: " + "minimum acceptable value is " + "-315576000000"); + return false; + } + + if (p->seconds > 315576000000) { + upb_status_seterrf(s, "error serializing duration: " + "maximum acceptable value is " + "315576000000"); + return false; + } + + _upb_snprintf(buffer, sizeof(buffer), "%ld", (long)p->seconds); + base_len = strlen(buffer); + + if (p->nanos != 0) { + char nanos_buffer[UPB_DURATION_MAX_NANO_LEN + 3]; + _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f", + p->nanos / 1000000000.0); + /* Remove trailing 0. */ + for (i = UPB_DURATION_MAX_NANO_LEN + 2; + nanos_buffer[i] == '0'; i--) { + nanos_buffer[i] = 0; + } + strcpy(buffer + base_len, nanos_buffer + 1); + } + + curr = strlen(buffer); + strcpy(buffer + curr, "s"); + + p->seconds = 0; + p->nanos = 0; + + print_data(p, "\"", 1); + print_data(p, buffer, strlen(buffer)); + print_data(p, "\"", 1); + + if (p->depth_ == 0) { + upb_bytessink_end(p->output_); + } + + UPB_UNUSED(handler_data); + return true; +} + +static bool printer_starttimestampmsg(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + if (p->depth_ == 0) { + upb_bytessink_start(p->output_, 0, &p->subc_); + } + return true; +} + +#define UPB_TIMESTAMP_MAX_JSON_LEN 31 +#define UPB_TIMESTAMP_BEFORE_NANO_LEN 19 +#define UPB_TIMESTAMP_MAX_NANO_LEN 9 + +static bool printer_endtimestampmsg(void *closure, const void *handler_data, + upb_status *s) { + upb_json_printer *p = closure; + char buffer[UPB_TIMESTAMP_MAX_JSON_LEN]; + time_t time = p->seconds; + size_t curr; + size_t i; + size_t year_length = + strftime(buffer, UPB_TIMESTAMP_MAX_JSON_LEN, "%Y", gmtime(&time)); + + if (p->seconds < -62135596800) { + upb_status_seterrf(s, "error parsing timestamp: " + "minimum acceptable value is " + "0001-01-01T00:00:00Z"); + return false; + } + + if (p->seconds > 253402300799) { + upb_status_seterrf(s, "error parsing timestamp: " + "maximum acceptable value is " + "9999-12-31T23:59:59Z"); + return false; + } + + /* strftime doesn't guarantee 4 digits for year. Prepend 0 by ourselves. */ + for (i = 0; i < 4 - year_length; i++) { + buffer[i] = '0'; + } + + strftime(buffer + (4 - year_length), UPB_TIMESTAMP_MAX_JSON_LEN, + "%Y-%m-%dT%H:%M:%S", gmtime(&time)); + if (p->nanos != 0) { + char nanos_buffer[UPB_TIMESTAMP_MAX_NANO_LEN + 3]; + _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f", + p->nanos / 1000000000.0); + /* Remove trailing 0. */ + for (i = UPB_TIMESTAMP_MAX_NANO_LEN + 2; + nanos_buffer[i] == '0'; i--) { + nanos_buffer[i] = 0; + } + strcpy(buffer + UPB_TIMESTAMP_BEFORE_NANO_LEN, nanos_buffer + 1); + } + + curr = strlen(buffer); + strcpy(buffer + curr, "Z"); + + p->seconds = 0; + p->nanos = 0; + + print_data(p, "\"", 1); + print_data(p, buffer, strlen(buffer)); + print_data(p, "\"", 1); + + if (p->depth_ == 0) { + upb_bytessink_end(p->output_); + } + + UPB_UNUSED(handler_data); + UPB_UNUSED(s); + return true; +} + +static bool printer_startmsg_noframe(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + if (p->depth_ == 0) { + upb_bytessink_start(p->output_, 0, &p->subc_); + } + return true; +} + +static bool printer_endmsg_noframe( + void *closure, const void *handler_data, upb_status *s) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(s); + if (p->depth_ == 0) { + upb_bytessink_end(p->output_); + } + return true; +} + +/* Set up handlers for a duration submessage. */ +void printer_sethandlers_duration(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + + const upb_fielddef* seconds_field = + upb_msgdef_itof(md, UPB_DURATION_SECONDS); + const upb_fielddef* nanos_field = + upb_msgdef_itof(md, UPB_DURATION_NANOS); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartmsg(h, printer_startdurationmsg, &empty_attr); + upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr); + upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr); + upb_handlers_setendmsg(h, printer_enddurationmsg, &empty_attr); + + UPB_UNUSED(closure); +} + +/* Set up handlers for a timestamp submessage. Instead of printing fields + * separately, the json representation of timestamp follows RFC 3339 */ +void printer_sethandlers_timestamp(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + + const upb_fielddef* seconds_field = + upb_msgdef_itof(md, UPB_TIMESTAMP_SECONDS); + const upb_fielddef* nanos_field = + upb_msgdef_itof(md, UPB_TIMESTAMP_NANOS); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartmsg(h, printer_starttimestampmsg, &empty_attr); + upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr); + upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr); + upb_handlers_setendmsg(h, printer_endtimestampmsg, &empty_attr); + + UPB_UNUSED(closure); +} + +void printer_sethandlers_value(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + upb_msg_field_iter i; + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_msg_field_begin(&i, md); + for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { + const upb_fielddef *f = upb_msg_iter_field(&i); + + switch (upb_fielddef_type(f)) { + case UPB_TYPE_ENUM: + upb_handlers_setint32(h, f, putnull, &empty_attr); + break; + case UPB_TYPE_DOUBLE: + upb_handlers_setdouble(h, f, putdouble, &empty_attr); + break; + case UPB_TYPE_STRING: + upb_handlers_setstartstr(h, f, scalar_startstr_nokey, &empty_attr); + upb_handlers_setstring(h, f, scalar_str, &empty_attr); + upb_handlers_setendstr(h, f, scalar_endstr, &empty_attr); + break; + case UPB_TYPE_BOOL: + upb_handlers_setbool(h, f, putbool, &empty_attr); + break; + case UPB_TYPE_MESSAGE: + break; + default: + UPB_ASSERT(false); + break; + } + } + + UPB_UNUSED(closure); +} + +#define WRAPPER_SETHANDLERS(wrapper, type, putmethod) \ +void printer_sethandlers_##wrapper(const void *closure, upb_handlers *h) { \ + const upb_msgdef *md = upb_handlers_msgdef(h); \ + const upb_fielddef* f = upb_msgdef_itof(md, 1); \ + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; \ + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); \ + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); \ + upb_handlers_set##type(h, f, putmethod, &empty_attr); \ + UPB_UNUSED(closure); \ +} + +WRAPPER_SETHANDLERS(doublevalue, double, putdouble) +WRAPPER_SETHANDLERS(floatvalue, float, putfloat) +WRAPPER_SETHANDLERS(int64value, int64, putint64_t) +WRAPPER_SETHANDLERS(uint64value, uint64, putuint64_t) +WRAPPER_SETHANDLERS(int32value, int32, putint32_t) +WRAPPER_SETHANDLERS(uint32value, uint32, putuint32_t) +WRAPPER_SETHANDLERS(boolvalue, bool, putbool) +WRAPPER_SETHANDLERS(stringvalue, string, putstr_nokey) +WRAPPER_SETHANDLERS(bytesvalue, string, putbytes) + +#undef WRAPPER_SETHANDLERS + +void printer_sethandlers_listvalue(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + const upb_fielddef* f = upb_msgdef_itof(md, 1); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartseq(h, f, startseq_nokey, &empty_attr); + upb_handlers_setendseq(h, f, endseq, &empty_attr); + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr); + + UPB_UNUSED(closure); +} + +void printer_sethandlers_structvalue(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + const upb_fielddef* f = upb_msgdef_itof(md, 1); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartseq(h, f, startmap_nokey, &empty_attr); + upb_handlers_setendseq(h, f, endmap, &empty_attr); + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr); + + UPB_UNUSED(closure); +} + void printer_sethandlers(const void *closure, upb_handlers *h) { const upb_msgdef *md = upb_handlers_msgdef(h); bool is_mapentry = upb_msgdef_mapentry(md); @@ -14787,6 +16390,42 @@ void printer_sethandlers(const void *closure, upb_handlers *h) { return; } + switch (upb_msgdef_wellknowntype(md)) { + case UPB_WELLKNOWN_UNSPECIFIED: + break; + case UPB_WELLKNOWN_DURATION: + printer_sethandlers_duration(closure, h); + return; + case UPB_WELLKNOWN_TIMESTAMP: + printer_sethandlers_timestamp(closure, h); + return; + case UPB_WELLKNOWN_VALUE: + printer_sethandlers_value(closure, h); + return; + case UPB_WELLKNOWN_LISTVALUE: + printer_sethandlers_listvalue(closure, h); + return; + case UPB_WELLKNOWN_STRUCT: + printer_sethandlers_structvalue(closure, h); + return; +#define WRAPPER(wellknowntype, name) \ + case wellknowntype: \ + printer_sethandlers_##name(closure, h); \ + return; \ + + WRAPPER(UPB_WELLKNOWN_DOUBLEVALUE, doublevalue); + WRAPPER(UPB_WELLKNOWN_FLOATVALUE, floatvalue); + WRAPPER(UPB_WELLKNOWN_INT64VALUE, int64value); + WRAPPER(UPB_WELLKNOWN_UINT64VALUE, uint64value); + WRAPPER(UPB_WELLKNOWN_INT32VALUE, int32value); + WRAPPER(UPB_WELLKNOWN_UINT32VALUE, uint32value); + WRAPPER(UPB_WELLKNOWN_BOOLVALUE, boolvalue); + WRAPPER(UPB_WELLKNOWN_STRINGVALUE, stringvalue); + WRAPPER(UPB_WELLKNOWN_BYTESVALUE, bytesvalue); + +#undef WRAPPER + } + upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); @@ -14894,6 +16533,8 @@ upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h, p->output_ = output; json_printer_reset(p); upb_sink_reset(&p->input_, h, p); + p->seconds = 0; + p->nanos = 0; /* If this fails, increase the value in printer.h. */ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= @@ -14911,3 +16552,8 @@ const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, return upb_handlers_newfrozen( md, owner, printer_sethandlers, &preserve_fieldnames); } + +#undef UPB_SIZE +#undef UPB_FIELD_AT +#undef UPB_READ_ONEOF +#undef UPB_WRITE_ONEOF diff --git a/ruby/ext/google/protobuf_c/upb.h b/ruby/ext/google/protobuf_c/upb.h index f441c89c83..0670a8123c 100644 --- a/ruby/ext/google/protobuf_c/upb.h +++ b/ruby/ext/google/protobuf_c/upb.h @@ -1,4 +1,116 @@ // Amalgamated source file + +// php.h intentionally defined NDEBUG. We have to define this macro in order to +// be used together with php.h +#ifndef NDEBUG +#define NDEBUG +#endif + +#if UINTPTR_MAX == 0xffffffff +#define UPB_SIZE(size32, size64) size32 +#else +#define UPB_SIZE(size32, size64) size64 +#endif + +#define UPB_FIELD_AT(msg, fieldtype, offset) \ + *(fieldtype*)((const char*)(msg) + offset) + +#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) \ + : 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::Message is a representation for protobuf messages. +** +** However it differs from other common representations like +** google::protobuf::Message in one key way: it does not prescribe any +** ownership between messages and submessages, and it relies on the +** client to ensure that each submessage/array/map outlives its parent. +** +** All messages, arrays, and maps live in an Arena. If the entire message +** tree is in the same arena, ensuring proper lifetimes is simple. However +** the client can mix arenas as long as they ensure that there are no +** dangling pointers. +** +** A client can access a upb::Message without knowing anything about +** ownership semantics, but to create or mutate a message a user needs +** to implement the memory management themselves. +** +** TODO: UTF-8 checking? +**/ + +#ifndef UPB_MSG_H_ +#define UPB_MSG_H_ + +/* +** Defs are upb's internal representation of the constructs that can appear +** in a .proto file: +** +** - upb::MessageDef (upb_msgdef): describes a "message" construct. +** - upb::FieldDef (upb_fielddef): describes a message field. +** - upb::FileDef (upb_filedef): describes a .proto file and its defs. +** - upb::EnumDef (upb_enumdef): describes an enum. +** - upb::OneofDef (upb_oneofdef): describes a oneof. +** - upb::Def (upb_def): base class of all the others. +** +** TODO: definitions of services. +** +** Like upb_refcounted objects, defs are mutable only until frozen, and are +** only thread-safe once frozen. +** +** 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_ + +/* +** upb::RefCounted (upb_refcounted) +** +** A refcounting scheme that supports circular refs. It accomplishes this by +** partitioning the set of objects into groups such that no cycle spans groups; +** we can then reference-count the group as a whole and ignore refs within the +** group. When objects are mutable, these groups are computed very +** conservatively; we group any objects that have ever had a link between them. +** When objects are frozen, we compute strongly-connected components which +** allows us to be precise and only group objects that are actually cyclic. +** +** 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_REFCOUNTED_H_ +#define UPB_REFCOUNTED_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 /* ** This file contains shared definitions that are widely used across upb. ** @@ -737,106 +849,6 @@ template class upb::InlinedEnvironment : public upb::Environment { #endif /* UPB_H_ */ -/* -** upb_decode: parsing into a upb_msg using a upb_msglayout. -*/ - -#ifndef UPB_DECODE_H_ -#define UPB_DECODE_H_ - -/* -** upb::Message is a representation for protobuf messages. -** -** However it differs from other common representations like -** google::protobuf::Message in one key way: it does not prescribe any -** ownership between messages and submessages, and it relies on the -** client to delete each message/submessage/array/map at the appropriate -** time. -** -** A client can access a upb::Message without knowing anything about -** ownership semantics, but to create or mutate a message a user needs -** to implement the memory management themselves. -** -** Currently all messages, arrays, and maps store a upb_alloc* internally. -** Mutating operations use this when they require dynamically-allocated -** memory. We could potentially eliminate this size overhead later by -** letting the user flip a bit on the factory that prevents this from -** being stored. The user would then need to use separate functions where -** the upb_alloc* is passed explicitly. However for handlers to populate -** such structures, they would need a place to store this upb_alloc* during -** parsing; upb_handlers don't currently have a good way to accommodate this. -** -** TODO: UTF-8 checking? -**/ - -#ifndef UPB_MSG_H_ -#define UPB_MSG_H_ - -/* -** Defs are upb's internal representation of the constructs that can appear -** in a .proto file: -** -** - upb::MessageDef (upb_msgdef): describes a "message" construct. -** - upb::FieldDef (upb_fielddef): describes a message field. -** - upb::FileDef (upb_filedef): describes a .proto file and its defs. -** - upb::EnumDef (upb_enumdef): describes an enum. -** - upb::OneofDef (upb_oneofdef): describes a oneof. -** - upb::Def (upb_def): base class of all the others. -** -** TODO: definitions of services. -** -** Like upb_refcounted objects, defs are mutable only until frozen, and are -** only thread-safe once frozen. -** -** 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_ - -/* -** upb::RefCounted (upb_refcounted) -** -** A refcounting scheme that supports circular refs. It accomplishes this by -** partitioning the set of objects into groups such that no cycle spans groups; -** we can then reference-count the group as a whole and ignore refs within the -** group. When objects are mutable, these groups are computed very -** conservatively; we group any objects that have ever had a link between them. -** When objects are frozen, we compute strongly-connected components which -** allows us to be precise and only group objects that are actually cyclic. -** -** 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_REFCOUNTED_H_ -#define UPB_REFCOUNTED_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" { @@ -1995,6 +2007,34 @@ typedef enum { UPB_SYNTAX_PROTO3 = 3 } upb_syntax_t; +/* All the different kind of well known type messages. For simplicity of check, + * number wrappers and string wrappers are grouped together. Make sure the + * order and merber of these groups are not changed. + */ +typedef enum { + UPB_WELLKNOWN_UNSPECIFIED, + UPB_WELLKNOWN_DURATION, + UPB_WELLKNOWN_TIMESTAMP, + /* number wrappers */ + UPB_WELLKNOWN_DOUBLEVALUE, + UPB_WELLKNOWN_FLOATVALUE, + UPB_WELLKNOWN_INT64VALUE, + UPB_WELLKNOWN_UINT64VALUE, + UPB_WELLKNOWN_INT32VALUE, + UPB_WELLKNOWN_UINT32VALUE, + /* string wrappers */ + UPB_WELLKNOWN_STRINGVALUE, + UPB_WELLKNOWN_BYTESVALUE, + UPB_WELLKNOWN_BOOLVALUE, + UPB_WELLKNOWN_VALUE, + UPB_WELLKNOWN_LISTVALUE, + UPB_WELLKNOWN_STRUCT +} upb_wellknowntype_t; + + +/* Maps descriptor type -> upb field type. */ +extern const uint8_t upb_desctype_to_fieldtype[]; + /* Maximum field number allowed for FieldDefs. This is an inherent limit of the * protobuf wire format. */ #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) @@ -2376,6 +2416,14 @@ typedef upb_strtable_iter upb_msg_oneof_iter; #define UPB_MAPENTRY_KEY 1 #define UPB_MAPENTRY_VALUE 2 +/* Well-known field tag numbers for timestamp messages. */ +#define UPB_DURATION_SECONDS 1 +#define UPB_DURATION_NANOS 2 + +/* Well-known field tag numbers for duration messages. */ +#define UPB_TIMESTAMP_SECONDS 1 +#define UPB_TIMESTAMP_NANOS 2 + #ifdef __cplusplus /* Structure that describes a single .proto message type. @@ -2490,6 +2538,13 @@ class upb::MessageDef { void setmapentry(bool map_entry); bool mapentry() const; + /* Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for + * non-well-known message. */ + upb_wellknowntype_t wellknowntype() const; + + /* Whether is a number wrapper. */ + bool isnumberwrapper() const; + /* Iteration over fields. The order is undefined. */ class field_iterator : public std::iterator { @@ -2631,6 +2686,8 @@ bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s); void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry); 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); /* Field lookup in a couple of different variations: @@ -3570,6 +3627,12 @@ inline void MessageDef::setmapentry(bool map_entry) { inline bool MessageDef::mapentry() const { return upb_msgdef_mapentry(this); } +inline upb_wellknowntype_t MessageDef::wellknowntype() const { + return upb_msgdef_wellknowntype(this); +} +inline bool MessageDef::isnumberwrapper() const { + return upb_msgdef_isnumberwrapper(this); +} inline MessageDef::field_iterator MessageDef::field_begin() { return field_iterator(this); } @@ -4697,6 +4760,34 @@ UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) { uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f); uint32_t upb_handlers_selectorcount(const upb_fielddef *f); + +/** Message handlers ******************************************************************/ + +/* These are the handlers used internally by upb_msgfactory_getmergehandlers(). + * They write scalar data to a known offset from the message pointer. + * + * These would be trivial for anyone to implement themselves, but it's better + * to use these because some JITs will recognize and specialize these instead + * of actually calling the function. */ + +/* Sets a handler for the given primitive field that will write the data at the + * given offset. If hasbit > 0, also sets a hasbit at the given bit offset + * (addressing each byte low to high). */ +bool upb_msg_setscalarhandler(upb_handlers *h, + const upb_fielddef *f, + size_t offset, + int32_t hasbit); + +/* If the given handler is a msghandlers_primitive field, returns true and sets + * *type, *offset and *hasbit. Otherwise returns false. */ +bool upb_msg_getscalarhandlerdata(const upb_handlers *h, + upb_selector_t s, + upb_fieldtype_t *type, + size_t *offset, + int32_t *hasbit); + + + UPB_END_EXTERN_C /* @@ -6381,21 +6472,14 @@ namespace upb { class Array; class Map; class MapIterator; -class MessageFactory; class MessageLayout; -class Visitor; -class VisitorPlan; } #endif -UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory) -UPB_DECLARE_TYPE(upb::MessageLayout, upb_msglayout) UPB_DECLARE_TYPE(upb::Array, upb_array) UPB_DECLARE_TYPE(upb::Map, upb_map) UPB_DECLARE_TYPE(upb::MapIterator, upb_mapiter) -UPB_DECLARE_TYPE(upb::Visitor, upb_visitor) -UPB_DECLARE_TYPE(upb::VisitorPlan, upb_visitorplan) /* TODO(haberman): C++ accessors */ @@ -6406,73 +6490,48 @@ typedef void upb_msg; /** upb_msglayout *************************************************************/ -/* upb_msglayout represents the memory layout of a given upb_msgdef. You get - * instances of this from a upb_msgfactory, and the factory always owns the - * msglayout. */ +/* 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. */ +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; -/** upb_visitor ***************************************************************/ +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_visitor will visit all the fields of a message and its submessages. It - * uses a upb_visitorplan which you can obtain from a upb_msgfactory. */ -upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp, - upb_sink *output); -bool upb_visitor_visitmsg(upb_visitor *v, const upb_msg *msg); +/** upb_stringview ************************************************************/ +typedef struct { + const char *data; + size_t size; +} upb_stringview; -/** upb_msgfactory ************************************************************/ +UPB_INLINE upb_stringview upb_stringview_make(const char *data, size_t size) { + upb_stringview ret; + ret.data = data; + ret.size = size; + return ret; +} -/* 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. - */ +#define UPB_STRINGVIEW_INIT(ptr, len) {ptr, 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); -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f); - -/* 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). - * - * The returned objects will live for as long as the msgfactory does. - * - * 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); -const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f, - const upb_msgdef *m); -const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f, - const upb_handlers *h); - - -/** upb_stringview ************************************************************/ - -typedef struct { - const char *data; - size_t size; -} upb_stringview; - -UPB_INLINE upb_stringview upb_stringview_make(const char *data, size_t size) { - upb_stringview ret; - ret.data = data; - ret.size = size; - return ret; -} - -#define UPB_STRINGVIEW_INIT(ptr, len) {ptr, len} - - -/** upb_msgval ****************************************************************/ +/** upb_msgval ****************************************************************/ /* A union representing all possible protobuf values. Used for generic get/set * operations. */ @@ -6528,52 +6587,16 @@ UPB_INLINE upb_msgval upb_msgval_makestr(const char *data, size_t size) { /** upb_msg *******************************************************************/ /* A upb_msg represents a protobuf message. It always corresponds to a specific - * upb_msglayout, which describes how it is laid out in memory. - * - * The message will have a fixed size, as returned by upb_msg_sizeof(), which - * will be used to store fixed-length fields. The upb_msg may also allocate - * dynamic memory internally to store data such as: - * - * - extensions - * - unknown fields - */ + * upb_msglayout, which describes how it is laid out in memory. */ -/* Returns the size of a message given this layout. */ -size_t upb_msg_sizeof(const upb_msglayout *l); +/* Creates a new message of the given type/layout in this arena. */ +upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a); -/* upb_msg_init() / upb_msg_uninit() allow the user to use a pre-allocated - * block of memory as a message. The block's size should be upb_msg_sizeof(). - * upb_msg_uninit() must be called to release internally-allocated memory - * unless the allocator is an arena that does not require freeing. - * - * Please note that upb_msg_init() may return a value that is different than - * |msg|, so you must assign the return value and not cast your memory block - * to upb_msg* directly! - * - * Please note that upb_msg_uninit() does *not* free any submessages, maps, - * or arrays referred to by this message's fields. You must free them manually - * yourself. - * - * upb_msg_uninit returns the original memory block, which may be useful if - * you dynamically allocated it (though upb_msg_new() would normally be more - * appropriate in this case). */ -upb_msg *upb_msg_init(void *msg, const upb_msglayout *l, upb_alloc *a); -void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l); - -/* Like upb_msg_init() / upb_msg_uninit(), except the message's memory is - * allocated / freed from the given upb_alloc. */ -upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a); -void upb_msg_free(upb_msg *msg, const upb_msglayout *l); - -/* Returns the upb_alloc for the given message. - * TODO(haberman): get rid of this? Not sure we want to be storing this - * for every message. */ -upb_alloc *upb_msg_alloc(const upb_msg *msg); - -/* Packs the tree of messages rooted at "msg" into a single hunk of memory, - * allocated from the given allocator. */ -void *upb_msg_pack(const upb_msg *msg, const upb_msglayout *l, - void *p, size_t *ofs, size_t size); +/* Returns the arena for the given message. */ +upb_arena *upb_msg_arena(const upb_msg *msg); + +void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len); +const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); /* Read-only message API. Can be safely called by anyone. */ @@ -6627,16 +6650,12 @@ bool upb_msg_clearfield(upb_msg *msg, * semantics are the same as upb_msg. A upb_array allocates dynamic * memory internally for the array elements. */ -size_t upb_array_sizeof(upb_fieldtype_t type); -void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *a); -void upb_array_uninit(upb_array *arr); -upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a); -void upb_array_free(upb_array *arr); +upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a); +upb_fieldtype_t upb_array_type(const upb_array *arr); /* Read-only interface. Safe for anyone to call. */ size_t upb_array_size(const upb_array *arr); -upb_fieldtype_t upb_array_type(const upb_array *arr); upb_msgval upb_array_get(const upb_array *arr, size_t i); /* Write interface. May only be called by the message's owner who can enforce @@ -6653,12 +6672,8 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val); * So you must ensure that any string or message values outlive the map, and you * must delete them manually when they are no longer required. */ -size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype); -bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_alloc *a); -void upb_map_uninit(upb_map *map); -upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, upb_alloc *a); -void upb_map_free(upb_map *map); +upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, + upb_arena *a); /* Read-only interface. Safe for anyone to call. */ @@ -6702,90 +6717,869 @@ upb_msgval upb_mapiter_value(const upb_mapiter *i); void upb_mapiter_setdone(upb_mapiter *i); bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2); +UPB_END_EXTERN_C -/** Handlers ******************************************************************/ - -/* These are the handlers used internally by upb_msgfactory_getmergehandlers(). - * They write scalar data to a known offset from the message pointer. +#endif /* UPB_MSG_H_ */ +/* This file was generated by upbc (the upb compiler) from the input + * file: * - * These would be trivial for anyone to implement themselves, but it's better - * to use these because some JITs will recognize and specialize these instead - * of actually calling the function. */ + * google/protobuf/descriptor.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ -/* Sets a handler for the given primitive field that will write the data at the - * given offset. If hasbit > 0, also sets a hasbit at the given bit offset - * (addressing each byte low to high). */ -bool upb_msg_setscalarhandler(upb_handlers *h, - const upb_fielddef *f, - size_t offset, - int32_t hasbit); +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ +#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -/* If the given handler is a msghandlers_primitive field, returns true and sets - * *type, *offset and *hasbit. Otherwise returns false. */ -bool upb_msg_getscalarhandlerdata(const upb_handlers *h, - upb_selector_t s, - upb_fieldtype_t *type, - size_t *offset, - int32_t *hasbit); +/* +** upb_decode: parsing into a upb_msg using a upb_msglayout. +*/ -/** Interfaces for generated code *********************************************/ +#ifndef UPB_DECODE_H_ +#define UPB_DECODE_H_ -#define UPB_NOT_IN_ONEOF UINT16_MAX -#define UPB_NO_HASBIT UINT16_MAX -#define UPB_NO_SUBMSG UINT16_MAX -typedef struct { - uint32_t number; - uint32_t offset; /* If in a oneof, offset of default in default_msg below. */ - uint16_t hasbit; /* UPB_NO_HASBIT if no hasbit. */ - uint16_t oneof_index; /* UPB_NOT_IN_ONEOF if not in a oneof. */ - uint16_t submsg_index; /* UPB_NO_SUBMSG if no submsg. */ - uint8_t type; - uint8_t label; -} upb_msglayout_fieldinit_v1; +UPB_BEGIN_EXTERN_C -typedef struct { - uint32_t data_offset; - uint32_t case_offset; -} upb_msglayout_oneofinit_v1; - -typedef struct upb_msglayout_msginit_v1 { - const struct upb_msglayout_msginit_v1 *const* submsgs; - const upb_msglayout_fieldinit_v1 *fields; - const upb_msglayout_oneofinit_v1 *oneofs; - void *default_msg; - /* Must be aligned to sizeof(void*). Doesn't include internal members like - * unknown fields, extension dict, pointer to msglayout, etc. */ - uint32_t size; - uint16_t field_count; - uint16_t oneof_count; - bool extendable; - bool is_proto2; -} upb_msglayout_msginit_v1; +bool upb_decode(upb_stringview buf, upb_msg *msg, const upb_msglayout *l); -#define UPB_ALIGN_UP_TO(val, align) ((val + (align - 1)) & -align) -#define UPB_ALIGNED_SIZEOF(type) UPB_ALIGN_UP_TO(sizeof(type), sizeof(void*)) +UPB_END_EXTERN_C -/* Initialize/uninitialize a msglayout from a msginit. If upb uses v1 - * internally, this will not allocate any memory. Should only be used by - * generated code. */ -upb_msglayout *upb_msglayout_frominit_v1( - const upb_msglayout_msginit_v1 *init, upb_alloc *a); -void upb_msglayout_uninit_v1(upb_msglayout *layout, upb_alloc *a); +#endif /* UPB_DECODE_H_ */ +/* +** upb_encode: parsing into a upb_msg using a upb_msglayout. +*/ -UPB_END_EXTERN_C +#ifndef UPB_ENCODE_H_ +#define UPB_ENCODE_H_ -#endif /* UPB_MSG_H_ */ UPB_BEGIN_EXTERN_C -bool upb_decode(upb_stringview buf, void *msg, - const upb_msglayout_msginit_v1 *l, upb_env *env); +char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena, + size_t *size); UPB_END_EXTERN_C -#endif /* UPB_DECODE_H_ */ +#endif /* UPB_ENCODE_H_ */ +UPB_BEGIN_EXTERN_C + +struct google_protobuf_FileDescriptorSet; +struct google_protobuf_FileDescriptorProto; +struct google_protobuf_DescriptorProto; +struct google_protobuf_DescriptorProto_ExtensionRange; +struct google_protobuf_DescriptorProto_ReservedRange; +struct google_protobuf_ExtensionRangeOptions; +struct google_protobuf_FieldDescriptorProto; +struct google_protobuf_OneofDescriptorProto; +struct google_protobuf_EnumDescriptorProto; +struct google_protobuf_EnumDescriptorProto_EnumReservedRange; +struct google_protobuf_EnumValueDescriptorProto; +struct google_protobuf_ServiceDescriptorProto; +struct google_protobuf_MethodDescriptorProto; +struct google_protobuf_FileOptions; +struct google_protobuf_MessageOptions; +struct google_protobuf_FieldOptions; +struct google_protobuf_OneofOptions; +struct google_protobuf_EnumOptions; +struct google_protobuf_EnumValueOptions; +struct google_protobuf_ServiceOptions; +struct google_protobuf_MethodOptions; +struct google_protobuf_UninterpretedOption; +struct google_protobuf_UninterpretedOption_NamePart; +struct google_protobuf_SourceCodeInfo; +struct google_protobuf_SourceCodeInfo_Location; +struct google_protobuf_GeneratedCodeInfo; +struct google_protobuf_GeneratedCodeInfo_Annotation; +typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; +typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; +typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; +typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; +typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; +typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; +typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; +typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; +typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; +typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; +typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; + +/* Enums */ + +typedef enum { + google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, + google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, + google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3 +} google_protobuf_FieldDescriptorProto_Label; + +typedef enum { + google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1, + google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2, + google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3, + google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4, + google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5, + google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6, + google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7, + google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8, + google_protobuf_FieldDescriptorProto_TYPE_STRING = 9, + google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10, + google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11, + google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12, + google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13, + google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14, + google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15, + google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16, + google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17, + google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18 +} google_protobuf_FieldDescriptorProto_Type; + +typedef enum { + google_protobuf_FieldOptions_STRING = 0, + google_protobuf_FieldOptions_CORD = 1, + google_protobuf_FieldOptions_STRING_PIECE = 2 +} google_protobuf_FieldOptions_CType; + +typedef enum { + google_protobuf_FieldOptions_JS_NORMAL = 0, + google_protobuf_FieldOptions_JS_STRING = 1, + google_protobuf_FieldOptions_JS_NUMBER = 2 +} google_protobuf_FieldOptions_JSType; + +typedef enum { + google_protobuf_FileOptions_SPEED = 1, + google_protobuf_FileOptions_CODE_SIZE = 2, + google_protobuf_FileOptions_LITE_RUNTIME = 3 +} google_protobuf_FileOptions_OptimizeMode; + +typedef enum { + google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0, + google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1, + google_protobuf_MethodOptions_IDEMPOTENT = 2 +} google_protobuf_MethodOptions_IdempotencyLevel; + +/* google.protobuf.FileDescriptorSet */ + +extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit; +UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena); +} +UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorSet_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileDescriptorSet *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.FileDescriptorProto */ + +extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit; +UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(40, 80)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(44, 88)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(48, 96)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(52, 104)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(56, 112)); } +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(32, 64)); } +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(36, 72)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(60, 120)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(64, 128)); } +UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)); } + +UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(40, 80)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_message_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(44, 88)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_enum_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(48, 96)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_service(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(52, 104)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_extension(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(56, 112)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { UPB_FIELD_AT(msg, google_protobuf_FileOptions*, UPB_SIZE(32, 64)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { UPB_FIELD_AT(msg, google_protobuf_SourceCodeInfo*, UPB_SIZE(36, 72)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_public_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(60, 120)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_weak_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(64, 128)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)) = value; } + + +/* google.protobuf.DescriptorProto */ + +extern const upb_msglayout google_protobuf_DescriptorProto_msginit; +UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(32, 64)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(36, 72)); } +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(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(40, 80)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(44, 88)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(48, 96)); } + +UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_field(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_nested_type(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_enum_type(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_extension_range(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(32, 64)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_extension(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(36, 72)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { UPB_FIELD_AT(msg, google_protobuf_MessageOptions*, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_oneof_decl(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(40, 80)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_range(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(44, 88)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_name(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(48, 96)) = value; } + + +/* google.protobuf.DescriptorProto.ExtensionRange */ + +extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit; +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); +} +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len); +} + +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_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +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 void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { UPB_FIELD_AT(msg, google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)) = value; } + + +/* google.protobuf.DescriptorProto.ReservedRange */ + +extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit; +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); +} +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len); +} + +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_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } + + +/* google.protobuf.ExtensionRangeOptions */ + +extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit; +UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); +} +UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_ExtensionRangeOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.FieldDescriptorProto */ + +extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit; +UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FieldDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } +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 google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)); } +UPB_INLINE google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)); } +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_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)); } + +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value) { UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value) { UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions*, UPB_SIZE(72, 112)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)) = value; } + + +/* google.protobuf.OneofDescriptorProto */ + +extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit; +UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_OneofDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +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(16, 32)); } + +UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { UPB_FIELD_AT(msg, google_protobuf_OneofOptions*, UPB_SIZE(16, 32)) = value; } + + +/* google.protobuf.EnumDescriptorProto */ + +extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit; +UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } +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(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } +UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } + +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_value(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { UPB_FIELD_AT(msg, google_protobuf_EnumOptions*, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } + + +/* google.protobuf.EnumDescriptorProto.EnumReservedRange */ + +extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); +} +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len); +} + +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_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } + + +/* google.protobuf.EnumValueDescriptorProto */ + +extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit; +UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +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 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, 32)); } + +UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { UPB_FIELD_AT(msg, google_protobuf_EnumValueOptions*, UPB_SIZE(16, 32)) = value; } + + +/* google.protobuf.ServiceDescriptorProto */ + +extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit; +UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_ServiceDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE const upb_array* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } +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(16, 32)); } + +UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_method(google_protobuf_ServiceDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } +UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { UPB_FIELD_AT(msg, google_protobuf_ServiceOptions*, UPB_SIZE(16, 32)) = value; } + + +/* google.protobuf.MethodDescriptorProto */ + +extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit; +UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_MethodDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } +UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)); } +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(32, 64)); } +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_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } + +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { UPB_FIELD_AT(msg, google_protobuf_MethodOptions*, UPB_SIZE(32, 64)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } + + +/* google.protobuf.FileOptions */ + +extern const upb_msglayout google_protobuf_FileOptions_msginit; +UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FileOptions_msginit, arena); +} +UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FileOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } +UPB_INLINE google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)); } +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 upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } +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_java_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)); } +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_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_deprecated(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)); } +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_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(72, 112)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(80, 128)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(88, 144)); } +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 const upb_array* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(96, 160)); } + +UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value) { UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(72, 112)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(80, 128)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(88, 144)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_uninterpreted_option(google_protobuf_FileOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(96, 160)) = value; } + + +/* google.protobuf.MessageOptions */ + +extern const upb_msglayout google_protobuf_MessageOptions_msginit; +UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); +} +UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_MessageOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len); +} + +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_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_deprecated(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)); } +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 const upb_array* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(8, 8)) = value; } + + +/* google.protobuf.FieldOptions */ + +extern const upb_msglayout google_protobuf_FieldOptions_msginit; +UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); +} +UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FieldOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len); +} + +UPB_INLINE google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)); } +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_deprecated(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)); } +UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)); } +UPB_INLINE google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)); } +UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)); } +UPB_INLINE const upb_array* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 32)); } + +UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 32)) = value; } + + +/* google.protobuf.OneofOptions */ + +extern const upb_msglayout google_protobuf_OneofOptions_msginit; +UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); +} +UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_OneofOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_OneofOptions_set_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.EnumOptions */ + +extern const upb_msglayout google_protobuf_EnumOptions_msginit; +UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); +} +UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len); +} + +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_deprecated(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } +UPB_INLINE const upb_array* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } + +UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } +UPB_INLINE void google_protobuf_EnumOptions_set_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } + + +/* google.protobuf.EnumValueOptions */ + +extern const upb_msglayout google_protobuf_EnumValueOptions_msginit; +UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); +} +UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE const upb_array* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } + +UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_EnumValueOptions_set_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } + + +/* google.protobuf.ServiceOptions */ + +extern const upb_msglayout google_protobuf_ServiceOptions_msginit; +UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); +} +UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_ServiceOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE const upb_array* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } + +UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_ServiceOptions_set_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } + + +/* google.protobuf.MethodOptions */ + +extern const upb_msglayout google_protobuf_MethodOptions_msginit; +UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); +} +UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_MethodOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); } +UPB_INLINE google_protobuf_MethodOptions_IdempotencyLevel google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)); } +UPB_INLINE const upb_array* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 24)); } + +UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, google_protobuf_MethodOptions_IdempotencyLevel value) { UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_MethodOptions_set_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 24)) = value; } + + +/* google.protobuf.UninterpretedOption */ + +extern const upb_msglayout google_protobuf_UninterpretedOption_msginit; +UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); +} +UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(56, 80)); } +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } +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 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 double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)); } +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } + +UPB_INLINE void google_protobuf_UninterpretedOption_set_name(google_protobuf_UninterpretedOption *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(56, 80)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } + + +/* google.protobuf.UninterpretedOption.NamePart */ + +extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit; +UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); +} +UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_NamePart_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +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 void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } + + +/* google.protobuf.SourceCodeInfo */ + +extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit; +UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); +} +UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_SourceCodeInfo_set_location(google_protobuf_SourceCodeInfo *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.SourceCodeInfo.Location */ + +extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit; +UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); +} +UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_Location_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } +UPB_INLINE upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(32, 64)); } + +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_path(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_span(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(32, 64)) = value; } + + +/* google.protobuf.GeneratedCodeInfo */ + +extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit; +UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena); +} +UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.GeneratedCodeInfo.Annotation */ + +extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit; +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); +} +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 32)); } +UPB_INLINE upb_stringview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 16)); } +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_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 32)) = value; } +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } + + +UPB_END_EXTERN_C + + +#endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */ /* ** structs.int.h: structures definitions that are internal to upb. */ @@ -6799,7 +7593,7 @@ struct upb_array { void *data; /* Each element is element_size. */ size_t len; /* Measured in elements. */ size_t size; /* Measured in elements. */ - upb_alloc *alloc; + upb_arena *arena; }; #endif /* UPB_STRUCTS_H_ */ @@ -6920,6 +7714,10 @@ struct upb_msgdef { /* Whether this message has proto2 or proto3 semantics. */ upb_syntax_t syntax; + /* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for + * non-well-known message. */ + upb_wellknowntype_t well_known_type; + /* TODO(haberman): proper extension ranges (there can be multiple). */ }; @@ -6928,10 +7726,11 @@ extern const struct upb_refcounted_vtbl upb_msgdef_vtbl; /* TODO: also support static initialization of the oneofs table. This will be * needed if we compile in descriptors that contain oneofs. */ #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ - map_entry, syntax, refs, ref2s) \ + map_entry, syntax, well_known_type, refs, ref2s) \ { \ UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \ - selector_count, submsg_field_count, itof, ntof, map_entry, syntax \ + selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \ + well_known_type \ } @@ -6994,22 +7793,44 @@ struct upb_filedef { extern const struct upb_refcounted_vtbl upb_filedef_vtbl; #endif /* UPB_STATICINIT_H_ */ -/* -** upb_encode: parsing into a upb_msg using a upb_msglayout. -*/ -#ifndef UPB_ENCODE_H_ -#define UPB_ENCODE_H_ +#ifndef UPB_MSGFACTORY_H_ +#define UPB_MSGFACTORY_H_ -UPB_BEGIN_EXTERN_C +UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory) -char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *l, - upb_env *env, size_t *size); +/** upb_msgfactory ************************************************************/ -UPB_END_EXTERN_C +/* 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. + */ -#endif /* UPB_ENCODE_H_ */ +/* 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); + +const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f); + +/* 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). + * + * The returned objects will live for as long as the msgfactory does. + * + * 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); + + +#endif /* UPB_MSGFACTORY_H_ */ /* ** upb::descriptor::Reader (upb_descreader) ** @@ -7112,53 +7933,6 @@ inline FileDef* Reader::file(size_t i) const { UPB_BEGIN_EXTERN_C -/* Enums */ - -typedef enum { - google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, - google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, - google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3 -} google_protobuf_FieldDescriptorProto_Label; - -typedef enum { - google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1, - google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2, - google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3, - google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4, - google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5, - google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6, - google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7, - google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8, - google_protobuf_FieldDescriptorProto_TYPE_STRING = 9, - google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10, - google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11, - google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12, - google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13, - google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16, - google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17, - google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18 -} google_protobuf_FieldDescriptorProto_Type; - -typedef enum { - google_protobuf_FieldOptions_STRING = 0, - google_protobuf_FieldOptions_CORD = 1, - google_protobuf_FieldOptions_STRING_PIECE = 2 -} google_protobuf_FieldOptions_CType; - -typedef enum { - google_protobuf_FieldOptions_JS_NORMAL = 0, - google_protobuf_FieldOptions_JS_STRING = 1, - google_protobuf_FieldOptions_JS_NUMBER = 2 -} google_protobuf_FieldOptions_JSType; - -typedef enum { - google_protobuf_FileOptions_SPEED = 1, - google_protobuf_FileOptions_CODE_SIZE = 2, - google_protobuf_FileOptions_LITE_RUNTIME = 3 -} google_protobuf_FileOptions_OptimizeMode; - /* MessageDefs: call these functions to get a ref to a msgdef. */ const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner); const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(const void *owner); @@ -8793,7 +9567,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, * constructed. This hint may be an overestimate for some build configurations. * But if the parser library is upgraded without recompiling the application, * it may be an underestimate. */ -#define UPB_JSON_PARSER_SIZE 4112 +#define UPB_JSON_PARSER_SIZE 4160 #ifdef __cplusplus @@ -8802,7 +9576,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, class upb::json::Parser { public: static Parser* Create(Environment* env, const ParserMethod* method, - Sink* output); + Sink* output, bool ignore_json_unknown); BytesSink* input(); @@ -8836,7 +9610,8 @@ UPB_BEGIN_EXTERN_C upb_json_parser* upb_json_parser_create(upb_env* e, const upb_json_parsermethod* m, - upb_sink* output); + upb_sink* output, + bool ignore_json_unknown); upb_bytessink *upb_json_parser_input(upb_json_parser *p); upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md, @@ -8856,8 +9631,8 @@ UPB_END_EXTERN_C namespace upb { namespace json { inline Parser* Parser::Create(Environment* env, const ParserMethod* method, - Sink* output) { - return upb_json_parser_create(env, method, output); + Sink* output, bool ignore_json_unknown) { + return upb_json_parser_create(env, method, output, ignore_json_unknown); } inline BytesSink* Parser::input() { return upb_json_parser_input(this); @@ -8906,7 +9681,7 @@ UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer) /* upb::json::Printer *********************************************************/ -#define UPB_JSON_PRINTER_SIZE 176 +#define UPB_JSON_PRINTER_SIZE 192 #ifdef __cplusplus @@ -8967,3 +9742,8 @@ inline reffed_ptr Printer::NewHandlers( #endif #endif /* UPB_JSON_TYPED_PRINTER_H_ */ + +#undef UPB_SIZE +#undef UPB_FIELD_AT +#undef UPB_READ_ONEOF +#undef UPB_WRITE_ONEOF diff --git a/ruby/lib/google/protobuf.rb b/ruby/lib/google/protobuf.rb index e20a584e80..464982e303 100644 --- a/ruby/lib/google/protobuf.rb +++ b/ruby/lib/google/protobuf.rb @@ -69,8 +69,8 @@ module Google klass.decode(proto) end - def self.decode_json(klass, json) - klass.decode_json(json) + def self.decode_json(klass, json, options = {}) + klass.decode_json(json, options) end end diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 77dfead404..5e17bef65b 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -254,6 +254,19 @@ module BasicTest "b" => TestMessage2.new(:foo => 2)} end + def test_protobuf_decode_json_ignore_unknown_fields + m = TestMessage.decode_json({ + optional_string: "foo", + not_in_message: "some_value" + }.to_json, { ignore_unknown_fields: true }) + + assert_equal m.optional_string, "foo" + e = assert_raise Google::Protobuf::ParseError do + TestMessage.decode_json({ not_in_message: "some_value" }.to_json) + end + assert_match(/No such field: not_in_message/, e.message) + end + def test_to_h m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)]) expected_result = { From 8faa778add7cc1a2bbb1139c633280753902830d Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 26 Dec 2018 10:36:09 -0800 Subject: [PATCH 41/70] Fix Any json encoding/decoding in php (#5496) * Fix Any json encoding/decoding in php * Fix comments --- conformance/failure_list_php_c.txt | 18 - php/ext/google/protobuf/encode_decode.c | 119 ++- php/ext/google/protobuf/upb.c | 985 ++++++++++++++++++------ php/ext/google/protobuf/upb.h | 69 +- php/tests/encode_decode_test.php | 141 ++++ php/tests/gdb_test.sh | 3 +- php/tests/memory_leak_test.php | 15 + php/tests/proto/test.proto | 5 + 8 files changed, 1057 insertions(+), 298 deletions(-) diff --git a/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index 8053d91ac4..dd69f5eafb 100644 --- a/conformance/failure_list_php_c.txt +++ b/conformance/failure_list_php_c.txt @@ -22,26 +22,8 @@ Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput Required.TimestampProtoInputTooLarge.JsonOutput Required.TimestampProtoInputTooSmall.JsonOutput -Required.Proto3.JsonInput.Any.JsonOutput -Required.Proto3.JsonInput.Any.ProtobufOutput -Required.Proto3.JsonInput.AnyNested.JsonOutput -Required.Proto3.JsonInput.AnyNested.ProtobufOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.JsonOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.ProtobufOutput -Required.Proto3.JsonInput.AnyWithDuration.JsonOutput -Required.Proto3.JsonInput.AnyWithDuration.ProtobufOutput Required.Proto3.JsonInput.AnyWithFieldMask.JsonOutput Required.Proto3.JsonInput.AnyWithFieldMask.ProtobufOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.JsonOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput -Required.Proto3.JsonInput.AnyWithStruct.JsonOutput -Required.Proto3.JsonInput.AnyWithStruct.ProtobufOutput -Required.Proto3.JsonInput.AnyWithTimestamp.JsonOutput -Required.Proto3.JsonInput.AnyWithTimestamp.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.ProtobufOutput Required.Proto3.JsonInput.BoolMapField.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 2bb5f52172..1313676620 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -1095,7 +1095,10 @@ static const upb_json_parsermethod *msgdef_jsonparsermethod(Descriptor* desc) { static void putmsg(zval* msg, const Descriptor* desc, upb_sink* sink, int depth, bool is_json TSRMLS_DC); static void putrawmsg(MessageHeader* msg, const Descriptor* desc, - upb_sink* sink, int depth, bool is_json TSRMLS_DC); + upb_sink* sink, int depth, bool is_json, + bool open_msg TSRMLS_DC); +static void putjsonany(MessageHeader* msg, const Descriptor* desc, + upb_sink* sink, int depth TSRMLS_DC); static void putstr(zval* str, const upb_fielddef* f, upb_sink* sink, bool force_default); @@ -1245,15 +1248,114 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, int depth, bool is_json TSRMLS_DC) { MessageHeader* msg = UNBOX(MessageHeader, msg_php); - putrawmsg(msg, desc, sink, depth, is_json TSRMLS_CC); + putrawmsg(msg, desc, sink, depth, is_json, true TSRMLS_CC); +} + +static const upb_handlers* msgdef_json_serialize_handlers( + Descriptor* desc, bool preserve_proto_fieldnames); + +static void putjsonany(MessageHeader* msg, const Descriptor* desc, + upb_sink* sink, int depth TSRMLS_DC) { + upb_status status; + const upb_fielddef* type_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_TYPE); + const upb_fielddef* value_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_VALUE); + + uint32_t type_url_offset; + zval* type_url_php_str; + const upb_msgdef *payload_type = NULL; + + upb_sink_startmsg(sink); + + /* Handle type url */ + type_url_offset = desc->layout->fields[upb_fielddef_index(type_field)].offset; + type_url_php_str = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), type_url_offset, CACHED_VALUE*)); + if (Z_STRLEN_P(type_url_php_str) > 0) { + putstr(type_url_php_str, type_field, sink, false); + } + + { + const char* type_url_str = Z_STRVAL_P(type_url_php_str); + size_t type_url_len = Z_STRLEN_P(type_url_php_str); + if (type_url_len <= 20 || + strncmp(type_url_str, "type.googleapis.com/", 20) != 0) { + zend_error(E_ERROR, "Invalid type url: %s", type_url_str); + } + + /* Resolve type url */ + type_url_str += 20; + type_url_len -= 20; + + payload_type = upb_symtab_lookupmsg2( + generated_pool->symtab, type_url_str, type_url_len); + if (payload_type == NULL) { + zend_error(E_ERROR, "Unknown type: %s", type_url_str); + return; + } + } + + { + uint32_t value_offset; + zval* value_php_str; + const char* value_str; + size_t value_len; + + value_offset = desc->layout->fields[upb_fielddef_index(value_field)].offset; + value_php_str = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), value_offset, CACHED_VALUE*)); + value_str = Z_STRVAL_P(value_php_str); + value_len = Z_STRLEN_P(value_php_str); + + if (value_len > 0) { + Descriptor* payload_desc = + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)payload_type)); + zend_class_entry* payload_klass = payload_desc->klass; + zval val; + upb_sink subsink; + bool is_wellknown; + + /* Create message of the payload type. */ + ZVAL_OBJ(&val, payload_klass->create_object(payload_klass TSRMLS_CC)); + MessageHeader* intern = UNBOX(MessageHeader, &val); + custom_data_init(payload_klass, intern PHP_PROTO_TSRMLS_CC); + + merge_from_string(value_str, value_len, payload_desc, intern); + + is_wellknown = + upb_msgdef_wellknowntype(payload_desc->msgdef) != + UPB_WELLKNOWN_UNSPECIFIED; + if (is_wellknown) { + upb_sink_startstr(sink, getsel(value_field, UPB_HANDLER_STARTSTR), 0, + &subsink); + } + + subsink.handlers = + msgdef_json_serialize_handlers(payload_desc, true); + subsink.closure = sink->closure; + putrawmsg(intern, payload_desc, &subsink, depth, true, + is_wellknown TSRMLS_CC); + + zval_dtor(&val); + } + } + + upb_sink_endmsg(sink, &status); } static void putrawmsg(MessageHeader* msg, const Descriptor* desc, - upb_sink* sink, int depth, bool is_json TSRMLS_DC) { + upb_sink* sink, int depth, bool is_json, + bool open_msg TSRMLS_DC) { upb_msg_field_iter i; upb_status status; - upb_sink_startmsg(sink); + if (is_json && upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) { + putjsonany(msg, desc, sink, depth TSRMLS_CC); + return; + } + + if (open_msg) { + upb_sink_startmsg(sink); + } // Protect against cycles (possible because users may freely reassign message // and repeated fields) by imposing a maximum recursion depth. @@ -1343,7 +1445,9 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, upb_sink_putunknown(sink, unknown->ptr, unknown->len); } - upb_sink_endmsg(sink, &status); + if (open_msg) { + upb_sink_endmsg(sink, &status); + } } static void putstr(zval* str, const upb_fielddef *f, @@ -1409,7 +1513,7 @@ static void putrawsubmsg(MessageHeader* submsg, const upb_fielddef* f, UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(upb_fielddef_msgsubdef(f))); upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink); - putrawmsg(submsg, subdesc, &subsink, depth + 1, is_json TSRMLS_CC); + putrawmsg(submsg, subdesc, &subsink, depth + 1, is_json, true TSRMLS_CC); upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG)); } @@ -1633,7 +1737,8 @@ PHP_METHOD(Message, mergeFromJsonString) { stackenv_init(&se, "Error occurred during parsing: %s"); upb_sink_reset(&sink, get_fill_handlers(desc), msg); - parser = upb_json_parser_create(&se.env, method, &sink, ignore_json_unknown); + parser = upb_json_parser_create(&se.env, method, generated_pool->symtab, + &sink, ignore_json_unknown); upb_bufsrc_putbuf(data, data_len, upb_json_parser_input(parser)); stackenv_uninit(&se); diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c index 049e2bb061..6b576d8566 100644 --- a/php/ext/google/protobuf/upb.c +++ b/php/ext/google/protobuf/upb.c @@ -1458,7 +1458,9 @@ static void assign_msg_wellknowntype(upb_msgdef *m) { m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; return; } - if (!strcmp(name, "google.protobuf.Duration")) { + if (!strcmp(name, "google.protobuf.Any")) { + m->well_known_type = UPB_WELLKNOWN_ANY; + } else if (!strcmp(name, "google.protobuf.Duration")) { m->well_known_type = UPB_WELLKNOWN_DURATION; } else if (!strcmp(name, "google.protobuf.Timestamp")) { m->well_known_type = UPB_WELLKNOWN_TIMESTAMP; @@ -3233,6 +3235,14 @@ const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { return def ? upb_dyncast_msgdef(def) : NULL; } +const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym, + size_t len) { + upb_value v; + upb_def *def = upb_strtable_lookup2(&s->symtab, sym, len, &v) ? + upb_value_getptr(v) : NULL; + return def ? upb_dyncast_msgdef(def) : NULL; +} + const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) { upb_value v; upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ? @@ -12546,7 +12556,7 @@ done: return r; } -//#line 1 "upb/json/parser.rl" +#line 1 "upb/json/parser.rl" /* ** upb::json::Parser (upb_json_parser) ** @@ -12623,6 +12633,9 @@ static void end_structvalue_object(upb_json_parser *p); static void start_object(upb_json_parser *p); static void end_object(upb_json_parser *p); +static void start_any_object(upb_json_parser *p, const char *ptr); +static bool end_any_object(upb_json_parser *p, const char *ptr); + static bool start_subobject(upb_json_parser *p); static void end_subobject(upb_json_parser *p); @@ -12630,8 +12643,89 @@ static void start_member(upb_json_parser *p); static void end_member(upb_json_parser *p); static bool end_membername(upb_json_parser *p); +static void start_any_member(upb_json_parser *p, const char *ptr); +static void end_any_member(upb_json_parser *p, const char *ptr); +static bool end_any_membername(upb_json_parser *p); + +size_t parse(void *closure, const void *hd, const char *buf, size_t size, + const upb_bufhandle *handle); +static bool end(void *closure, const void *hd); + static const char eof_ch = 'e'; +/* stringsink */ +typedef struct { + upb_byteshandler handler; + upb_bytessink sink; + char *ptr; + size_t len, size; +} upb_stringsink; + + +static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) { + upb_stringsink *sink = _sink; + sink->len = 0; + UPB_UNUSED(hd); + UPB_UNUSED(size_hint); + return sink; +} + +static size_t stringsink_string(void *_sink, const void *hd, const char *ptr, + size_t len, const upb_bufhandle *handle) { + upb_stringsink *sink = _sink; + size_t new_size = sink->size; + + UPB_UNUSED(hd); + UPB_UNUSED(handle); + + while (sink->len + len > new_size) { + new_size *= 2; + } + + if (new_size != sink->size) { + sink->ptr = realloc(sink->ptr, new_size); + sink->size = new_size; + } + + memcpy(sink->ptr + sink->len, ptr, len); + sink->len += len; + + return len; +} + +void upb_stringsink_init(upb_stringsink *sink) { + upb_byteshandler_init(&sink->handler); + upb_byteshandler_setstartstr(&sink->handler, stringsink_start, NULL); + upb_byteshandler_setstring(&sink->handler, stringsink_string, NULL); + + upb_bytessink_reset(&sink->sink, &sink->handler, sink); + + sink->size = 32; + sink->ptr = malloc(sink->size); + sink->len = 0; +} + +void upb_stringsink_uninit(upb_stringsink *sink) { free(sink->ptr); } + +typedef struct { + /* For encoding Any value field in binary format. */ + const upb_handlers *encoder_handlers; + upb_pb_encoder *encoder; + upb_stringsink stringsink; + + /* For decoding Any value field in json format. */ + upb_json_parsermethod *parser_method; + upb_json_parser* parser; + upb_sink sink; + + /* Mark the range of uninterpreted values in json input before type url. */ + const char *before_type_url_start; + const char *before_type_url_end; + + /* Mark the range of uninterpreted values in json input after type url. */ + const char *after_type_url_start; +} upb_jsonparser_any_frame; + typedef struct { upb_sink sink; @@ -12660,6 +12754,15 @@ typedef struct { * message itself), not the parent's field that leads to this map. */ const upb_fielddef *mapfield; + /* We are in an Any message context. This flag is set when parsing the Any + * message and indicates to all field parsers (subobjects, strings, numbers, + * and bools) that the parsed field should be serialized as binary data or + * cached (type url not found yet). */ + bool is_any; + + /* The type of packed message in Any. */ + upb_jsonparser_any_frame *any_frame; + /* True if the field to be parsed is unknown. */ bool is_unknown_field; } upb_jsonparser_frame; @@ -12700,6 +12803,9 @@ struct upb_json_parser { /* Intermediate result of parsing a unicode escape sequence. */ uint32_t digit; + /* For resolve type url in Any. */ + const upb_symtab *symtab; + /* Whether to proceed if unknown field is met. */ bool ignore_json_unknown; @@ -12723,6 +12829,84 @@ struct upb_json_parsermethod { #define PARSER_CHECK_RETURN(x) if (!(x)) return false +static void json_parser_any_frame_reset(upb_jsonparser_any_frame *frame) { + frame->encoder_handlers = NULL; + frame->encoder = NULL; + frame->parser_method = NULL; + frame->parser = NULL; + frame->before_type_url_start = NULL; + frame->before_type_url_end = NULL; + frame->after_type_url_start = NULL; +} + +static void json_parser_any_frame_set_payload_type( + upb_json_parser *p, + upb_jsonparser_any_frame *frame, + const upb_msgdef *payload_type) { + /* Initialize encoder. */ + frame->encoder_handlers = + upb_pb_encoder_newhandlers(payload_type, &frame->encoder_handlers); + upb_stringsink_init(&frame->stringsink); + frame->encoder = + upb_pb_encoder_create( + p->env, frame->encoder_handlers, + &frame->stringsink.sink); + + /* Initialize parser. */ + frame->parser_method = + upb_json_parsermethod_new(payload_type, &frame->parser_method); + upb_sink_reset(&frame->sink, frame->encoder_handlers, frame->encoder); + frame->parser = + upb_json_parser_create(p->env, frame->parser_method, p->symtab, + &frame->sink, p->ignore_json_unknown); +} + +static void json_parser_any_frame_free(upb_jsonparser_any_frame *frame) { + upb_handlers_unref(frame->encoder_handlers, + &frame->encoder_handlers); + upb_json_parsermethod_unref(frame->parser_method, + &frame->parser_method); + upb_stringsink_uninit(&frame->stringsink); +} + +static bool json_parser_any_frame_has_type_url( + upb_jsonparser_any_frame *frame) { + return frame->encoder != NULL; +} + +static bool json_parser_any_frame_has_value_before_type_url( + upb_jsonparser_any_frame *frame) { + return frame->before_type_url_start != frame->before_type_url_end; +} + +static bool json_parser_any_frame_has_value_after_type_url( + upb_jsonparser_any_frame *frame) { + return frame->after_type_url_start != NULL; +} + +static bool json_parser_any_frame_has_value( + upb_jsonparser_any_frame *frame) { + return json_parser_any_frame_has_value_before_type_url(frame) || + json_parser_any_frame_has_value_after_type_url(frame); +} + +static void json_parser_any_frame_set_before_type_url_end( + upb_jsonparser_any_frame *frame, + const char *ptr) { + if (frame->encoder == NULL) { + frame->before_type_url_end = ptr; + } +} + +static void json_parser_any_frame_set_after_type_url_start_once( + upb_jsonparser_any_frame *frame, + const char *ptr) { + if (json_parser_any_frame_has_type_url(frame) && + frame->after_type_url_start == NULL) { + frame->after_type_url_start = ptr; + } +} + /* Used to signal that a capture has been suspended. */ static char suspend_capture; @@ -13526,6 +13710,11 @@ static bool end_null(upb_json_parser *p) { return true; } +static bool start_any_stringval(upb_json_parser *p) { + multipart_startaccum(p); + return true; +} + static bool start_stringval(upb_json_parser *p) { if (is_top_level(p)) { if (is_string_wrapper_object(p)) { @@ -13561,6 +13750,10 @@ static bool start_stringval(upb_json_parser *p) { return true; } + if (p->top->is_any) { + return start_any_stringval(p); + } + if (upb_fielddef_isstring(p->top->f)) { upb_jsonparser_frame *inner; upb_selector_t sel; @@ -13577,6 +13770,8 @@ static bool start_stringval(upb_json_parser *p) { inner->name_table = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; @@ -13608,6 +13803,50 @@ static bool start_stringval(upb_json_parser *p) { } } +static bool end_any_stringval(upb_json_parser *p) { + size_t len; + const char *buf = accumulate_getptr(p, &len); + + /* Set type_url */ + upb_selector_t sel; + upb_jsonparser_frame *inner; + if (!check_stack(p)) return false; + inner = p->top + 1; + + sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); + upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); + sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); + upb_sink_putstring(&inner->sink, sel, buf, len, NULL); + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + upb_sink_endstr(&inner->sink, sel); + + multipart_end(p); + + /* Resolve type url */ + if (strncmp(buf, "type.googleapis.com/", 20) == 0 && len > 20) { + const upb_msgdef *payload_type = NULL; + buf += 20; + len -= 20; + + payload_type = upb_symtab_lookupmsg2(p->symtab, buf, len); + if (payload_type == NULL) { + upb_status_seterrf( + &p->status, "Cannot find packed type: %.*s\n", (int)len, buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + json_parser_any_frame_set_payload_type(p, p->top->any_frame, payload_type); + + return true; + } else { + upb_status_seterrf( + &p->status, "Invalid type url: %.*s\n", (int)len, buf); + upb_env_reporterror(p->env, &p->status); + return false; + } +} + static bool end_stringval_nontop(upb_json_parser *p) { bool ok = true; @@ -13622,6 +13861,10 @@ static bool end_stringval_nontop(upb_json_parser *p) { return true; } + if (p->top->is_any) { + return end_any_stringval(p); + } + switch (upb_fielddef_type(p->top->f)) { case UPB_TYPE_BYTES: if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), @@ -14069,6 +14312,8 @@ static bool handle_mapentry(upb_json_parser *p) { inner->name_table = NULL; inner->mapfield = mapfield; inner->is_map = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; /* Don't set this to true *yet* -- we reuse parsing handlers below to push @@ -14105,7 +14350,9 @@ static bool end_membername(upb_json_parser *p) { return true; } - if (p->top->is_map) { + if (p->top->is_any) { + return end_any_membername(p); + } else if (p->top->is_map) { return handle_mapentry(p); } else { size_t len; @@ -14129,6 +14376,23 @@ static bool end_membername(upb_json_parser *p) { } } +static bool end_any_membername(upb_json_parser *p) { + size_t len; + const char *buf = accumulate_getptr(p, &len); + upb_value v; + + if (len == 5 && strncmp(buf, "@type", len) == 0) { + upb_strtable_lookup2(p->top->name_table, "type_url", 8, &v); + p->top->f = upb_value_getconstptr(v); + multipart_end(p); + return true; + } else { + p->top->is_unknown_field = true; + multipart_end(p); + return true; + } +} + static void end_member(upb_json_parser *p) { /* If we just parsed a map-entry value, end that frame too. */ if (p->top->is_mapentry) { @@ -14153,6 +14417,16 @@ static void end_member(upb_json_parser *p) { p->top->is_unknown_field = false; } +static void start_any_member(upb_json_parser *p, const char *ptr) { + start_member(p); + json_parser_any_frame_set_after_type_url_start_once(p->top->any_frame, ptr); +} + +static void end_any_member(upb_json_parser *p, const char *ptr) { + json_parser_any_frame_set_before_type_url_end(p->top->any_frame, ptr); + end_member(p); +} + static bool start_subobject(upb_json_parser *p) { if (p->top->is_unknown_field) { upb_jsonparser_frame *inner; @@ -14163,6 +14437,8 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; return true; @@ -14185,6 +14461,8 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = true; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; @@ -14209,6 +14487,16 @@ static bool start_subobject(upb_json_parser *p) { inner->is_unknown_field = false; p->top = inner; + if (is_wellknown_msg(p, UPB_WELLKNOWN_ANY)) { + p->top->is_any = true; + p->top->any_frame = + upb_env_malloc(p->env, sizeof(upb_jsonparser_any_frame)); + json_parser_any_frame_reset(p->top->any_frame); + } else { + p->top->is_any = false; + p->top->any_frame = NULL; + } + return true; } else { upb_status_seterrf(&p->status, @@ -14313,6 +14601,8 @@ static bool start_array(upb_json_parser *p) { inner->f = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = true; p->top = inner; @@ -14337,6 +14627,8 @@ static bool start_array(upb_json_parser *p) { inner->f = p->top->f; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; @@ -14389,6 +14681,129 @@ static void end_object(upb_json_parser *p) { } } +static void start_any_object(upb_json_parser *p, const char *ptr) { + start_object(p); + p->top->any_frame->before_type_url_start = ptr; + p->top->any_frame->before_type_url_end = ptr; +} + +static bool end_any_object(upb_json_parser *p, const char *ptr) { + const char *value_membername = "value"; + bool is_well_known_packed = false; + const char *packed_end = ptr + 1; + upb_selector_t sel; + upb_jsonparser_frame *inner; + + if (json_parser_any_frame_has_value(p->top->any_frame) && + !json_parser_any_frame_has_type_url(p->top->any_frame)) { + upb_status_seterrmsg(&p->status, "No valid type url"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Well known types data is represented as value field. */ + if (upb_msgdef_wellknowntype(p->top->any_frame->parser->top->m) != + UPB_WELLKNOWN_UNSPECIFIED) { + is_well_known_packed = true; + + if (json_parser_any_frame_has_value_before_type_url(p->top->any_frame)) { + p->top->any_frame->before_type_url_start = + memchr(p->top->any_frame->before_type_url_start, ':', + p->top->any_frame->before_type_url_end - + p->top->any_frame->before_type_url_start); + if (p->top->any_frame->before_type_url_start == NULL) { + upb_status_seterrmsg(&p->status, "invalid data for well known type."); + upb_env_reporterror(p->env, &p->status); + return false; + } + p->top->any_frame->before_type_url_start++; + } + + if (json_parser_any_frame_has_value_after_type_url(p->top->any_frame)) { + p->top->any_frame->after_type_url_start = + memchr(p->top->any_frame->after_type_url_start, ':', + (ptr + 1) - + p->top->any_frame->after_type_url_start); + if (p->top->any_frame->after_type_url_start == NULL) { + upb_status_seterrmsg(&p->status, "Invalid data for well known type."); + upb_env_reporterror(p->env, &p->status); + return false; + } + p->top->any_frame->after_type_url_start++; + packed_end = ptr; + } + } + + if (json_parser_any_frame_has_value_before_type_url(p->top->any_frame)) { + if (!parse(p->top->any_frame->parser, NULL, + p->top->any_frame->before_type_url_start, + p->top->any_frame->before_type_url_end - + p->top->any_frame->before_type_url_start, NULL)) { + return false; + } + } else { + if (!is_well_known_packed) { + if (!parse(p->top->any_frame->parser, NULL, "{", 1, NULL)) { + return false; + } + } + } + + if (json_parser_any_frame_has_value_before_type_url(p->top->any_frame) && + json_parser_any_frame_has_value_after_type_url(p->top->any_frame)) { + if (!parse(p->top->any_frame->parser, NULL, ",", 1, NULL)) { + return false; + } + } + + if (json_parser_any_frame_has_value_after_type_url(p->top->any_frame)) { + if (!parse(p->top->any_frame->parser, NULL, + p->top->any_frame->after_type_url_start, + packed_end - p->top->any_frame->after_type_url_start, NULL)) { + return false; + } + } else { + if (!is_well_known_packed) { + if (!parse(p->top->any_frame->parser, NULL, "}", 1, NULL)) { + return false; + } + } + } + + if (!end(p->top->any_frame->parser, NULL)) { + return false; + } + + p->top->is_any = false; + + /* Set value */ + start_member(p); + capture_begin(p, value_membername); + capture_end(p, value_membername + 5); + end_membername(p); + + if (!check_stack(p)) return false; + inner = p->top + 1; + + sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); + upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); + sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); + upb_sink_putstring(&inner->sink, sel, p->top->any_frame->stringsink.ptr, + p->top->any_frame->stringsink.len, NULL); + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + upb_sink_endstr(&inner->sink, sel); + + end_member(p); + + end_object(p); + + /* Deallocate any parse frame. */ + json_parser_any_frame_free(p->top->any_frame); + upb_env_free(p->env, p->top->any_frame); + + return true; +} + static bool is_string_wrapper(const upb_msgdef *m) { upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); return type == UPB_WELLKNOWN_STRINGVALUE || @@ -14554,44 +14969,44 @@ static bool is_string_wrapper_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -//#line 2147 "upb/json/parser.rl" +#line 2576 "upb/json/parser.rl" -//#line 2016 "upb/json/parser.c" +#line 2422 "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, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 21, 1, 23, 1, 24, 1, - 25, 1, 27, 1, 28, 1, 30, 1, + 26, 1, 27, 1, 28, 1, 30, 1, 32, 1, 33, 1, 34, 1, 35, 1, - 36, 1, 38, 2, 4, 9, 2, 5, + 37, 1, 38, 2, 4, 9, 2, 5, 6, 2, 7, 3, 2, 7, 9, 2, 14, 15, 2, 16, 17, 2, 18, 19, - 2, 22, 20, 2, 26, 37, 2, 29, + 2, 22, 20, 2, 24, 26, 2, 29, 2, 2, 30, 38, 2, 31, 20, 2, 33, 38, 2, 34, 38, 2, 35, 38, - 3, 25, 22, 20, 3, 26, 37, 38, - 4, 14, 15, 16, 17 + 2, 36, 25, 2, 37, 38, 4, 14, + 15, 16, 17 }; static const short _json_key_offsets[] = { 0, 0, 12, 13, 18, 23, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, - 38, 43, 48, 49, 53, 58, 63, 68, - 72, 76, 79, 82, 84, 88, 92, 94, - 96, 101, 103, 105, 114, 120, 126, 132, - 138, 140, 144, 147, 149, 151, 154, 155, - 159, 161, 163, 165, 167, 168, 170, 172, - 173, 175, 177, 178, 180, 182, 183, 185, - 187, 188, 190, 192, 196, 198, 200, 201, - 202, 203, 204, 206, 211, 220, 221, 221, - 221, 226, 231, 236, 237, 238, 239, 240, - 240, 241, 242, 243, 243, 244, 245, 246, - 246, 251, 256, 257, 261, 266, 271, 276, - 280, 280, 283, 286, 289, 292, 295, 298, - 298, 298, 298, 298 + 38, 43, 44, 48, 53, 58, 63, 67, + 71, 74, 77, 79, 83, 87, 89, 91, + 96, 98, 100, 109, 115, 121, 127, 133, + 135, 139, 142, 144, 146, 149, 150, 154, + 156, 158, 160, 162, 163, 165, 167, 168, + 170, 172, 173, 175, 177, 178, 180, 182, + 183, 185, 187, 191, 193, 195, 196, 197, + 198, 199, 201, 206, 215, 216, 216, 216, + 221, 226, 231, 232, 233, 234, 235, 235, + 236, 237, 238, 238, 239, 240, 241, 241, + 246, 247, 251, 256, 261, 266, 270, 270, + 273, 276, 279, 282, 285, 288, 288, 288, + 288, 288 }; static const char _json_trans_keys[] = { @@ -14600,93 +15015,92 @@ static const char _json_trans_keys[] = { 9, 13, 32, 44, 93, 9, 13, 32, 93, 125, 9, 13, 97, 108, 115, 101, 117, 108, 108, 114, 117, 101, 32, 34, - 125, 9, 13, 32, 34, 125, 9, 13, - 34, 32, 58, 9, 13, 32, 93, 125, + 125, 9, 13, 34, 32, 58, 9, 13, + 32, 93, 125, 9, 13, 32, 44, 125, 9, 13, 32, 44, 125, 9, 13, 32, - 44, 125, 9, 13, 32, 34, 9, 13, - 45, 48, 49, 57, 48, 49, 57, 46, - 69, 101, 48, 57, 69, 101, 48, 57, - 43, 45, 48, 57, 48, 57, 48, 57, - 46, 69, 101, 48, 57, 34, 92, 34, - 92, 34, 47, 92, 98, 102, 110, 114, - 116, 117, 48, 57, 65, 70, 97, 102, - 48, 57, 65, 70, 97, 102, 48, 57, - 65, 70, 97, 102, 48, 57, 65, 70, - 97, 102, 34, 92, 45, 48, 49, 57, - 48, 49, 57, 46, 115, 48, 57, 115, - 48, 57, 34, 46, 115, 48, 57, 48, - 57, 48, 57, 48, 57, 48, 57, 45, - 48, 57, 48, 57, 45, 48, 57, 48, - 57, 84, 48, 57, 48, 57, 58, 48, - 57, 48, 57, 58, 48, 57, 48, 57, - 43, 45, 46, 90, 48, 57, 48, 57, - 58, 48, 48, 34, 48, 57, 43, 45, - 90, 48, 57, 34, 45, 91, 102, 110, - 116, 123, 48, 57, 34, 32, 93, 125, - 9, 13, 32, 44, 93, 9, 13, 32, - 93, 125, 9, 13, 97, 108, 115, 101, - 117, 108, 108, 114, 117, 101, 32, 34, - 125, 9, 13, 32, 34, 125, 9, 13, - 34, 32, 58, 9, 13, 32, 93, 125, - 9, 13, 32, 44, 125, 9, 13, 32, - 44, 125, 9, 13, 32, 34, 9, 13, - 32, 9, 13, 32, 9, 13, 32, 9, + 34, 9, 13, 45, 48, 49, 57, 48, + 49, 57, 46, 69, 101, 48, 57, 69, + 101, 48, 57, 43, 45, 48, 57, 48, + 57, 48, 57, 46, 69, 101, 48, 57, + 34, 92, 34, 92, 34, 47, 92, 98, + 102, 110, 114, 116, 117, 48, 57, 65, + 70, 97, 102, 48, 57, 65, 70, 97, + 102, 48, 57, 65, 70, 97, 102, 48, + 57, 65, 70, 97, 102, 34, 92, 45, + 48, 49, 57, 48, 49, 57, 46, 115, + 48, 57, 115, 48, 57, 34, 46, 115, + 48, 57, 48, 57, 48, 57, 48, 57, + 48, 57, 45, 48, 57, 48, 57, 45, + 48, 57, 48, 57, 84, 48, 57, 48, + 57, 58, 48, 57, 48, 57, 58, 48, + 57, 48, 57, 43, 45, 46, 90, 48, + 57, 48, 57, 58, 48, 48, 34, 48, + 57, 43, 45, 90, 48, 57, 34, 45, + 91, 102, 110, 116, 123, 48, 57, 34, + 32, 93, 125, 9, 13, 32, 44, 93, + 9, 13, 32, 93, 125, 9, 13, 97, + 108, 115, 101, 117, 108, 108, 114, 117, + 101, 32, 34, 125, 9, 13, 34, 32, + 58, 9, 13, 32, 93, 125, 9, 13, + 32, 44, 125, 9, 13, 32, 44, 125, + 9, 13, 32, 34, 9, 13, 32, 9, 13, 32, 9, 13, 32, 9, 13, 32, - 9, 13, 0 + 9, 13, 32, 9, 13, 32, 9, 13, + 0 }; static const char _json_single_lengths[] = { 0, 8, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 3, 3, 1, 2, 3, 3, 3, 2, - 2, 1, 3, 0, 2, 2, 0, 0, - 3, 2, 2, 9, 0, 0, 0, 0, - 2, 2, 1, 2, 0, 1, 1, 2, - 0, 0, 0, 0, 1, 0, 0, 1, - 0, 0, 1, 0, 0, 1, 0, 0, - 1, 0, 0, 4, 0, 0, 1, 1, - 1, 1, 0, 3, 7, 1, 0, 0, - 3, 3, 3, 1, 1, 1, 1, 0, - 1, 1, 1, 0, 1, 1, 1, 0, - 3, 3, 1, 2, 3, 3, 3, 2, - 0, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0 + 3, 1, 2, 3, 3, 3, 2, 2, + 1, 3, 0, 2, 2, 0, 0, 3, + 2, 2, 9, 0, 0, 0, 0, 2, + 2, 1, 2, 0, 1, 1, 2, 0, + 0, 0, 0, 1, 0, 0, 1, 0, + 0, 1, 0, 0, 1, 0, 0, 1, + 0, 0, 4, 0, 0, 1, 1, 1, + 1, 0, 3, 7, 1, 0, 0, 3, + 3, 3, 1, 1, 1, 1, 0, 1, + 1, 1, 0, 1, 1, 1, 0, 3, + 1, 2, 3, 3, 3, 2, 0, 1, + 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0 }; static const char _json_range_lengths[] = { 0, 2, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 3, 3, 3, 3, - 0, 1, 1, 0, 1, 1, 0, 1, - 1, 1, 1, 1, 0, 1, 1, 0, + 1, 0, 1, 1, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 0, 1, 1, 0, 1, 1, - 0, 1, 1, 0, 1, 1, 0, 0, - 0, 0, 1, 1, 1, 0, 0, 0, - 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0 + 1, 1, 1, 0, 1, 1, 0, 1, + 1, 0, 1, 1, 0, 1, 1, 0, + 1, 1, 0, 1, 1, 0, 0, 0, + 0, 1, 1, 1, 0, 0, 0, 1, + 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0 }; static const short _json_index_offsets[] = { 0, 0, 11, 13, 18, 23, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, - 48, 53, 58, 60, 64, 69, 74, 79, - 83, 87, 90, 94, 96, 100, 104, 106, - 108, 113, 116, 119, 129, 133, 137, 141, - 145, 148, 152, 155, 158, 160, 163, 165, - 169, 171, 173, 175, 177, 179, 181, 183, - 185, 187, 189, 191, 193, 195, 197, 199, - 201, 203, 205, 207, 212, 214, 216, 218, - 220, 222, 224, 226, 231, 240, 242, 243, - 244, 249, 254, 259, 261, 263, 265, 267, - 268, 270, 272, 274, 275, 277, 279, 281, - 282, 287, 292, 294, 298, 303, 308, 313, - 317, 318, 321, 324, 327, 330, 333, 336, - 337, 338, 339, 340 + 48, 53, 55, 59, 64, 69, 74, 78, + 82, 85, 89, 91, 95, 99, 101, 103, + 108, 111, 114, 124, 128, 132, 136, 140, + 143, 147, 150, 153, 155, 158, 160, 164, + 166, 168, 170, 172, 174, 176, 178, 180, + 182, 184, 186, 188, 190, 192, 194, 196, + 198, 200, 202, 207, 209, 211, 213, 215, + 217, 219, 221, 226, 235, 237, 238, 239, + 244, 249, 254, 256, 258, 260, 262, 263, + 265, 267, 269, 270, 272, 274, 276, 277, + 282, 284, 288, 293, 298, 303, 307, 308, + 311, 314, 317, 320, 323, 326, 327, 328, + 329, 330 }; static const unsigned char _json_indicies[] = { @@ -14696,97 +15110,93 @@ static const unsigned char _json_indicies[] = { 1, 1, 14, 10, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20, 1, 21, 1, 22, 1, 23, 1, 24, 1, - 25, 26, 27, 25, 1, 28, 29, 30, - 28, 1, 31, 1, 32, 33, 32, 1, - 33, 1, 1, 33, 34, 35, 36, 37, - 35, 1, 38, 39, 30, 38, 1, 39, - 29, 39, 1, 40, 41, 42, 1, 41, - 42, 1, 44, 45, 45, 43, 46, 1, - 45, 45, 46, 43, 47, 47, 48, 1, - 48, 1, 48, 43, 44, 45, 45, 42, - 43, 50, 51, 49, 53, 54, 52, 55, - 55, 55, 55, 55, 55, 55, 55, 56, - 1, 57, 57, 57, 1, 58, 58, 58, - 1, 59, 59, 59, 1, 60, 60, 60, - 1, 62, 63, 61, 64, 65, 66, 1, - 67, 68, 1, 69, 70, 1, 71, 1, - 70, 71, 1, 72, 1, 69, 70, 68, - 1, 73, 1, 74, 1, 75, 1, 76, - 1, 77, 1, 78, 1, 79, 1, 80, - 1, 81, 1, 82, 1, 83, 1, 84, - 1, 85, 1, 86, 1, 87, 1, 88, - 1, 89, 1, 90, 1, 91, 1, 92, - 92, 93, 94, 1, 95, 1, 96, 1, - 97, 1, 98, 1, 99, 1, 100, 1, - 101, 1, 102, 102, 103, 101, 1, 104, - 105, 106, 107, 108, 109, 110, 105, 1, - 111, 1, 112, 113, 115, 116, 1, 115, - 114, 117, 118, 116, 117, 1, 118, 1, - 1, 118, 114, 119, 1, 120, 1, 121, - 1, 122, 1, 123, 124, 1, 125, 1, - 126, 1, 127, 128, 1, 129, 1, 130, - 1, 131, 132, 133, 134, 132, 1, 135, - 136, 137, 135, 1, 138, 1, 139, 140, - 139, 1, 140, 1, 1, 140, 141, 142, - 143, 144, 142, 1, 145, 146, 137, 145, - 1, 146, 136, 146, 1, 147, 148, 148, - 1, 149, 149, 1, 150, 150, 1, 151, - 151, 1, 152, 152, 1, 153, 153, 1, - 1, 1, 1, 1, 1, 0 + 25, 26, 27, 25, 1, 28, 1, 29, + 30, 29, 1, 30, 1, 1, 30, 31, + 32, 33, 34, 32, 1, 35, 36, 27, + 35, 1, 36, 26, 36, 1, 37, 38, + 39, 1, 38, 39, 1, 41, 42, 42, + 40, 43, 1, 42, 42, 43, 40, 44, + 44, 45, 1, 45, 1, 45, 40, 41, + 42, 42, 39, 40, 47, 48, 46, 50, + 51, 49, 52, 52, 52, 52, 52, 52, + 52, 52, 53, 1, 54, 54, 54, 1, + 55, 55, 55, 1, 56, 56, 56, 1, + 57, 57, 57, 1, 59, 60, 58, 61, + 62, 63, 1, 64, 65, 1, 66, 67, + 1, 68, 1, 67, 68, 1, 69, 1, + 66, 67, 65, 1, 70, 1, 71, 1, + 72, 1, 73, 1, 74, 1, 75, 1, + 76, 1, 77, 1, 78, 1, 79, 1, + 80, 1, 81, 1, 82, 1, 83, 1, + 84, 1, 85, 1, 86, 1, 87, 1, + 88, 1, 89, 89, 90, 91, 1, 92, + 1, 93, 1, 94, 1, 95, 1, 96, + 1, 97, 1, 98, 1, 99, 99, 100, + 98, 1, 101, 102, 103, 104, 105, 106, + 107, 102, 1, 108, 1, 109, 110, 112, + 113, 1, 112, 111, 114, 115, 113, 114, + 1, 115, 1, 1, 115, 111, 116, 1, + 117, 1, 118, 1, 119, 1, 120, 121, + 1, 122, 1, 123, 1, 124, 125, 1, + 126, 1, 127, 1, 128, 129, 130, 131, + 129, 1, 132, 1, 133, 134, 133, 1, + 134, 1, 1, 134, 135, 136, 137, 138, + 136, 1, 139, 140, 131, 139, 1, 140, + 130, 140, 1, 141, 142, 142, 1, 143, + 143, 1, 144, 144, 1, 145, 145, 1, + 146, 146, 1, 147, 147, 1, 1, 1, + 1, 1, 1, 0 }; static const char _json_trans_targs[] = { - 1, 0, 2, 106, 3, 6, 10, 13, - 16, 105, 4, 3, 105, 4, 5, 7, - 8, 9, 107, 11, 12, 108, 14, 15, - 109, 17, 18, 110, 17, 18, 110, 19, - 19, 20, 21, 22, 23, 110, 22, 23, - 25, 26, 32, 111, 27, 29, 28, 30, - 31, 34, 112, 35, 34, 112, 35, 33, - 36, 37, 38, 39, 40, 34, 112, 35, - 42, 43, 47, 43, 47, 44, 46, 45, - 113, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 74, 73, 69, - 70, 71, 72, 73, 114, 75, 68, 73, - 77, 79, 80, 83, 88, 92, 96, 78, - 115, 115, 81, 80, 78, 81, 82, 84, - 85, 86, 87, 115, 89, 90, 91, 115, - 93, 94, 95, 115, 97, 98, 104, 97, - 98, 104, 99, 99, 100, 101, 102, 103, - 104, 102, 103, 115, 105, 105, 105, 105, - 105, 105 + 1, 0, 2, 104, 3, 6, 10, 13, + 16, 103, 4, 3, 103, 4, 5, 7, + 8, 9, 105, 11, 12, 106, 14, 15, + 107, 16, 17, 108, 18, 18, 19, 20, + 21, 22, 108, 21, 22, 24, 25, 31, + 109, 26, 28, 27, 29, 30, 33, 110, + 34, 33, 110, 34, 32, 35, 36, 37, + 38, 39, 33, 110, 34, 41, 42, 46, + 42, 46, 43, 45, 44, 111, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 73, 72, 68, 69, 70, 71, + 72, 112, 74, 67, 72, 76, 78, 79, + 82, 87, 91, 95, 77, 113, 113, 80, + 79, 77, 80, 81, 83, 84, 85, 86, + 113, 88, 89, 90, 113, 92, 93, 94, + 113, 95, 96, 102, 97, 97, 98, 99, + 100, 101, 102, 100, 101, 113, 103, 103, + 103, 103, 103, 103 }; static const char _json_trans_actions[] = { 0, 0, 84, 78, 33, 0, 0, 0, - 47, 39, 25, 0, 35, 0, 0, 0, + 96, 39, 25, 0, 35, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 72, 31, 27, 0, 0, 25, + 29, 29, 75, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 5, 15, + 0, 0, 51, 7, 13, 0, 54, 9, + 9, 9, 57, 60, 11, 17, 17, 17, + 0, 0, 0, 19, 0, 21, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 31, 96, 31, 0, 72, 0, 27, - 0, 0, 25, 29, 29, 29, 0, 0, - 0, 0, 0, 3, 0, 0, 0, 0, - 0, 5, 15, 0, 0, 51, 7, 13, - 0, 54, 9, 9, 9, 57, 60, 11, - 17, 17, 17, 0, 0, 0, 19, 0, - 21, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 104, 63, 104, 0, - 0, 0, 0, 0, 69, 0, 66, 66, - 84, 78, 33, 0, 0, 0, 47, 39, - 49, 81, 25, 0, 35, 0, 0, 0, - 0, 0, 0, 90, 0, 0, 0, 93, - 0, 0, 0, 87, 31, 96, 31, 0, - 72, 0, 27, 0, 0, 25, 29, 29, - 29, 0, 0, 100, 0, 37, 43, 45, - 41, 75 + 0, 102, 63, 102, 0, 0, 0, 0, + 0, 69, 0, 66, 66, 84, 78, 33, + 0, 0, 0, 96, 39, 49, 81, 25, + 0, 35, 0, 0, 0, 0, 0, 0, + 90, 0, 0, 0, 93, 0, 0, 0, + 87, 0, 72, 31, 27, 0, 0, 25, + 29, 29, 75, 0, 0, 99, 0, 37, + 43, 45, 41, 47 }; static const char _json_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -14795,21 +15205,22 @@ static const char _json_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 37, 43, 45, 41, 75, 0, - 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, + 37, 43, 45, 41, 47, 0, 0, 0, + 0, 0 }; static const int json_start = 1; -static const int json_en_number_machine = 24; -static const int json_en_string_machine = 33; -static const int json_en_duration_machine = 41; -static const int json_en_timestamp_machine = 48; -static const int json_en_value_machine = 76; +static const int json_en_number_machine = 23; +static const int json_en_string_machine = 32; +static const int json_en_duration_machine = 40; +static const int json_en_timestamp_machine = 47; +static const int json_en_value_machine = 75; static const int json_en_main = 1; -//#line 2150 "upb/json/parser.rl" +#line 2579 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -14832,7 +15243,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -//#line 2290 "upb/json/parser.c" +#line 2692 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -14907,166 +15318,190 @@ _match: switch ( *_acts++ ) { case 1: -//#line 2021 "upb/json/parser.rl" +#line 2427 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 2: -//#line 2023 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 24; goto _again;} } +#line 2429 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 23; goto _again;} } break; case 3: -//#line 2027 "upb/json/parser.rl" +#line 2433 "upb/json/parser.rl" { start_text(parser, p); } break; case 4: -//#line 2028 "upb/json/parser.rl" +#line 2434 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 5: -//#line 2034 "upb/json/parser.rl" +#line 2440 "upb/json/parser.rl" { start_hex(parser); } break; case 6: -//#line 2035 "upb/json/parser.rl" +#line 2441 "upb/json/parser.rl" { hexdigit(parser, p); } break; case 7: -//#line 2036 "upb/json/parser.rl" +#line 2442 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hex(parser)); } break; case 8: -//#line 2042 "upb/json/parser.rl" +#line 2448 "upb/json/parser.rl" { CHECK_RETURN_TOP(escape(parser, p)); } break; case 9: -//#line 2048 "upb/json/parser.rl" +#line 2454 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 10: -//#line 2060 "upb/json/parser.rl" +#line 2466 "upb/json/parser.rl" { start_duration_base(parser, p); } break; case 11: -//#line 2061 "upb/json/parser.rl" +#line 2467 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_duration_base(parser, p)); } break; case 12: -//#line 2063 "upb/json/parser.rl" +#line 2469 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 13: -//#line 2068 "upb/json/parser.rl" +#line 2474 "upb/json/parser.rl" { start_timestamp_base(parser, p); } break; case 14: -//#line 2069 "upb/json/parser.rl" +#line 2475 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } break; case 15: -//#line 2071 "upb/json/parser.rl" +#line 2477 "upb/json/parser.rl" { start_timestamp_fraction(parser, p); } break; case 16: -//#line 2072 "upb/json/parser.rl" +#line 2478 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } break; case 17: -//#line 2074 "upb/json/parser.rl" +#line 2480 "upb/json/parser.rl" { start_timestamp_zone(parser, p); } break; case 18: -//#line 2075 "upb/json/parser.rl" +#line 2481 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } break; case 19: -//#line 2077 "upb/json/parser.rl" +#line 2483 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 20: -//#line 2082 "upb/json/parser.rl" +#line 2488 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { - {stack[top++] = cs; cs = 48; goto _again;} + {stack[top++] = cs; cs = 47; goto _again;} } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) { - {stack[top++] = cs; cs = 41; goto _again;} + {stack[top++] = cs; cs = 40; goto _again;} } else { - {stack[top++] = cs; cs = 33; goto _again;} + {stack[top++] = cs; cs = 32; goto _again;} } } break; case 21: -//#line 2093 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 76; goto _again;} } +#line 2499 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 75; goto _again;} } break; case 22: -//#line 2098 "upb/json/parser.rl" - { start_member(parser); } +#line 2504 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + start_any_member(parser, p); + } else { + start_member(parser); + } + } break; case 23: -//#line 2099 "upb/json/parser.rl" +#line 2511 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_membername(parser)); } break; case 24: -//#line 2102 "upb/json/parser.rl" - { end_member(parser); } +#line 2514 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + end_any_member(parser, p); + } else { + end_member(parser); + } + } break; case 25: -//#line 2108 "upb/json/parser.rl" - { start_object(parser); } +#line 2525 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + start_any_object(parser, p); + } else { + start_object(parser); + } + } break; case 26: -//#line 2111 "upb/json/parser.rl" - { end_object(parser); } +#line 2534 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + CHECK_RETURN_TOP(end_any_object(parser, p)); + } else { + end_object(parser); + } + } break; case 27: -//#line 2117 "upb/json/parser.rl" +#line 2546 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_array(parser)); } break; case 28: -//#line 2121 "upb/json/parser.rl" +#line 2550 "upb/json/parser.rl" { end_array(parser); } break; case 29: -//#line 2126 "upb/json/parser.rl" +#line 2555 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_number(parser, p)); } break; case 30: -//#line 2127 "upb/json/parser.rl" +#line 2556 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; case 31: -//#line 2129 "upb/json/parser.rl" +#line 2558 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_stringval(parser)); } break; case 32: -//#line 2130 "upb/json/parser.rl" +#line 2559 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_stringval(parser)); } break; case 33: -//#line 2132 "upb/json/parser.rl" +#line 2561 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; case 34: -//#line 2134 "upb/json/parser.rl" +#line 2563 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; case 35: -//#line 2136 "upb/json/parser.rl" +#line 2565 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_null(parser)); } break; case 36: -//#line 2138 "upb/json/parser.rl" +#line 2567 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_subobject_full(parser)); } break; case 37: -//#line 2139 "upb/json/parser.rl" +#line 2568 "upb/json/parser.rl" { end_subobject_full(parser); } break; case 38: -//#line 2144 "upb/json/parser.rl" +#line 2573 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -//#line 2524 "upb/json/parser.c" +#line 2950 "upb/json/parser.c" } } @@ -15083,34 +15518,30 @@ _again: while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 0: -//#line 2019 "upb/json/parser.rl" +#line 2425 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; - case 26: -//#line 2111 "upb/json/parser.rl" - { end_object(parser); } - break; case 30: -//#line 2127 "upb/json/parser.rl" +#line 2556 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; case 33: -//#line 2132 "upb/json/parser.rl" +#line 2561 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; case 34: -//#line 2134 "upb/json/parser.rl" +#line 2563 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; case 35: -//#line 2136 "upb/json/parser.rl" +#line 2565 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_null(parser)); } break; case 37: -//#line 2139 "upb/json/parser.rl" +#line 2568 "upb/json/parser.rl" { end_subobject_full(parser); } break; -//#line 2568 "upb/json/parser.c" +#line 2990 "upb/json/parser.c" } } } @@ -15118,7 +15549,7 @@ _again: _out: {} } -//#line 2172 "upb/json/parser.rl" +#line 2601 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -15135,7 +15566,7 @@ error: return p - buf; } -bool end(void *closure, const void *hd) { +static bool end(void *closure, const void *hd) { upb_json_parser *parser = closure; /* Prevent compile warning on unused static constants. */ @@ -15150,9 +15581,9 @@ bool end(void *closure, const void *hd) { parse(parser, hd, &eof_ch, 0, NULL); return parser->current_state >= -//#line 2608 "upb/json/parser.c" -105 -//#line 2202 "upb/json/parser.rl" +#line 3030 "upb/json/parser.c" +103 +#line 2631 "upb/json/parser.rl" ; } @@ -15164,17 +15595,19 @@ static void json_parser_reset(upb_json_parser *p) { p->top->f = NULL; p->top->is_map = false; p->top->is_mapentry = false; + p->top->is_any = false; + p->top->any_frame = NULL; p->top->is_unknown_field = false; /* Emit Ragel initialization of the parser. */ -//#line 2626 "upb/json/parser.c" +#line 3050 "upb/json/parser.c" { cs = json_start; top = 0; } -//#line 2217 "upb/json/parser.rl" +#line 2648 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -15261,6 +15694,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { upb_json_parser *upb_json_parser_create(upb_env *env, const upb_json_parsermethod *method, + const upb_symtab* symtab, upb_sink *output, bool ignore_json_unknown) { #ifndef NDEBUG @@ -15279,7 +15713,17 @@ upb_json_parser *upb_json_parser_create(upb_env *env, json_parser_reset(p); upb_sink_reset(&p->top->sink, output->handlers, output->closure); p->top->m = upb_handlers_msgdef(output->handlers); + if (is_wellknown_msg(p, UPB_WELLKNOWN_ANY)) { + p->top->is_any = true; + p->top->any_frame = + upb_env_malloc(p->env, sizeof(upb_jsonparser_any_frame)); + json_parser_any_frame_reset(p->top->any_frame); + } else { + p->top->is_any = false; + p->top->any_frame = NULL; + } set_name_table(p, p->top); + p->symtab = symtab; p->ignore_json_unknown = ignore_json_unknown; @@ -15389,6 +15833,15 @@ strpc *newstrpc(upb_handlers *h, const upb_fielddef *f, return ret; } +/* Convert a null-terminated const char* to a string piece. */ +strpc *newstrpc_str(upb_handlers *h, const char * str) { + strpc * ret = upb_gmalloc(sizeof(*ret)); + ret->ptr = upb_gstrdup(str); + ret->len = strlen(str); + upb_handlers_addcleanup(h, ret, freestrpc); + return ret; +} + /* ------------ JSON string printing: values, maps, arrays ------------------ */ static void print_data( @@ -16240,6 +16693,49 @@ static bool printer_endmsg_noframe( return true; } +static void *scalar_startstr_onlykey( + void *closure, const void *handler_data, size_t size_hint) { + upb_json_printer *p = closure; + UPB_UNUSED(size_hint); + CHK(putkey(closure, handler_data)); + return p; +} + +/* Set up handlers for an Any submessage. */ +void printer_sethandlers_any(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + + const upb_fielddef* type_field = upb_msgdef_itof(md, UPB_ANY_TYPE); + const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_ANY_VALUE); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + /* type_url's json name is "@type" */ + upb_handlerattr type_name_attr = UPB_HANDLERATTR_INITIALIZER; + upb_handlerattr value_name_attr = UPB_HANDLERATTR_INITIALIZER; + strpc *type_url_json_name = newstrpc_str(h, "@type"); + strpc *value_json_name = newstrpc_str(h, "value"); + + upb_handlerattr_sethandlerdata(&type_name_attr, type_url_json_name); + upb_handlerattr_sethandlerdata(&value_name_attr, value_json_name); + + /* Set up handlers. */ + upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); + + upb_handlers_setstartstr(h, type_field, scalar_startstr, &type_name_attr); + upb_handlers_setstring(h, type_field, scalar_str, &empty_attr); + upb_handlers_setendstr(h, type_field, scalar_endstr, &empty_attr); + + /* This is not the full and correct JSON encoding for the Any value field. It + * requires further processing by the wrapper code based on the type URL. + */ + upb_handlers_setstartstr(h, value_field, scalar_startstr_onlykey, + &value_name_attr); + + UPB_UNUSED(closure); +} + /* Set up handlers for a duration submessage. */ void printer_sethandlers_duration(const void *closure, upb_handlers *h) { const upb_msgdef *md = upb_handlers_msgdef(h); @@ -16393,6 +16889,9 @@ void printer_sethandlers(const void *closure, upb_handlers *h) { switch (upb_msgdef_wellknowntype(md)) { case UPB_WELLKNOWN_UNSPECIFIED: break; + case UPB_WELLKNOWN_ANY: + printer_sethandlers_any(closure, h); + return; case UPB_WELLKNOWN_DURATION: printer_sethandlers_duration(closure, h); return; diff --git a/php/ext/google/protobuf/upb.h b/php/ext/google/protobuf/upb.h index 0670a8123c..f59fffb770 100644 --- a/php/ext/google/protobuf/upb.h +++ b/php/ext/google/protobuf/upb.h @@ -2013,6 +2013,7 @@ typedef enum { */ typedef enum { UPB_WELLKNOWN_UNSPECIFIED, + UPB_WELLKNOWN_ANY, UPB_WELLKNOWN_DURATION, UPB_WELLKNOWN_TIMESTAMP, /* number wrappers */ @@ -2416,6 +2417,10 @@ typedef upb_strtable_iter upb_msg_oneof_iter; #define UPB_MAPENTRY_KEY 1 #define UPB_MAPENTRY_VALUE 2 +/* Well-known field tag numbers for Any messages. */ +#define UPB_ANY_TYPE 1 +#define UPB_ANY_VALUE 2 + /* Well-known field tag numbers for timestamp messages. */ #define UPB_DURATION_SECONDS 1 #define UPB_DURATION_NANOS 2 @@ -3271,6 +3276,8 @@ const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, const char *sym); const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym); const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym); +const upb_msgdef *upb_symtab_lookupmsg2( + const upb_symtab *s, const char *sym, size_t len); const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym); bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, void *ref_donor, upb_status *status); @@ -6877,7 +6884,7 @@ typedef enum { extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit; UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); @@ -6896,7 +6903,7 @@ UPB_INLINE void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileD extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit; UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); @@ -6937,7 +6944,7 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_F extern const upb_msglayout google_protobuf_DescriptorProto_msginit; UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); @@ -6974,7 +6981,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_name(google_protobu extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit; UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); @@ -6997,7 +7004,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(googl extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit; UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); @@ -7018,7 +7025,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_pro extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit; UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); @@ -7037,7 +7044,7 @@ UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(g extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit; UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); @@ -7074,7 +7081,7 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protob extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit; UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); @@ -7095,7 +7102,7 @@ UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit; UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); @@ -7122,7 +7129,7 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_name(google_pro extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); @@ -7143,7 +7150,7 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(go extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit; UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); @@ -7166,7 +7173,7 @@ UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_prot extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit; UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); @@ -7189,7 +7196,7 @@ UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protob extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit; UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); @@ -7218,7 +7225,7 @@ UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(googl extern const upb_msglayout google_protobuf_FileOptions_msginit; UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); @@ -7273,7 +7280,7 @@ UPB_INLINE void google_protobuf_FileOptions_set_uninterpreted_option(google_prot extern const upb_msglayout google_protobuf_MessageOptions_msginit; UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); @@ -7300,7 +7307,7 @@ UPB_INLINE void google_protobuf_MessageOptions_set_uninterpreted_option(google_p extern const upb_msglayout google_protobuf_FieldOptions_msginit; UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); @@ -7331,7 +7338,7 @@ UPB_INLINE void google_protobuf_FieldOptions_set_uninterpreted_option(google_pro extern const upb_msglayout google_protobuf_OneofOptions_msginit; UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); @@ -7350,7 +7357,7 @@ UPB_INLINE void google_protobuf_OneofOptions_set_uninterpreted_option(google_pro extern const upb_msglayout google_protobuf_EnumOptions_msginit; UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); @@ -7373,7 +7380,7 @@ UPB_INLINE void google_protobuf_EnumOptions_set_uninterpreted_option(google_prot extern const upb_msglayout google_protobuf_EnumValueOptions_msginit; UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); @@ -7394,7 +7401,7 @@ UPB_INLINE void google_protobuf_EnumValueOptions_set_uninterpreted_option(google extern const upb_msglayout google_protobuf_ServiceOptions_msginit; UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); @@ -7415,7 +7422,7 @@ UPB_INLINE void google_protobuf_ServiceOptions_set_uninterpreted_option(google_p extern const upb_msglayout google_protobuf_MethodOptions_msginit; UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); @@ -7438,7 +7445,7 @@ UPB_INLINE void google_protobuf_MethodOptions_set_uninterpreted_option(google_pr extern const upb_msglayout google_protobuf_UninterpretedOption_msginit; UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); @@ -7469,7 +7476,7 @@ UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_p extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit; UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); @@ -7490,7 +7497,7 @@ UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(go extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit; UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); @@ -7509,7 +7516,7 @@ UPB_INLINE void google_protobuf_SourceCodeInfo_set_location(google_protobuf_Sour extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit; UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); @@ -7536,7 +7543,7 @@ UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_detached_com extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit; UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); @@ -7555,7 +7562,7 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit; UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); @@ -9567,7 +9574,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, * constructed. This hint may be an overestimate for some build configurations. * But if the parser library is upgraded without recompiling the application, * it may be an underestimate. */ -#define UPB_JSON_PARSER_SIZE 4160 +#define UPB_JSON_PARSER_SIZE 5712 #ifdef __cplusplus @@ -9576,6 +9583,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, class upb::json::Parser { public: static Parser* Create(Environment* env, const ParserMethod* method, + const SymbolTable* symtab, Sink* output, bool ignore_json_unknown); BytesSink* input(); @@ -9610,6 +9618,7 @@ UPB_BEGIN_EXTERN_C upb_json_parser* upb_json_parser_create(upb_env* e, const upb_json_parsermethod* m, + const upb_symtab* symtab, upb_sink* output, bool ignore_json_unknown); upb_bytessink *upb_json_parser_input(upb_json_parser *p); @@ -9631,8 +9640,10 @@ UPB_END_EXTERN_C namespace upb { namespace json { inline Parser* Parser::Create(Environment* env, const ParserMethod* method, + const SymbolTable* symtab, Sink* output, bool ignore_json_unknown) { - return upb_json_parser_create(env, method, output, ignore_json_unknown); + return upb_json_parser_create( + env, method, symtab, output, ignore_json_unknown); } inline BytesSink* Parser::input() { return upb_json_parser_input(this); diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 06f9a9006c..8018f9798b 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -5,12 +5,14 @@ require_once('test_util.php'); use Google\Protobuf\RepeatedField; use Google\Protobuf\GPBType; +use Foo\TestAny; use Foo\TestEnum; use Foo\TestMessage; use Foo\TestMessage\Sub; use Foo\TestPackedMessage; use Foo\TestRandomFieldOrder; use Foo\TestUnpackedMessage; +use Google\Protobuf\Any; use Google\Protobuf\DoubleValue; use Google\Protobuf\FloatValue; use Google\Protobuf\Int32Value; @@ -915,4 +917,143 @@ class EncodeDecodeTest extends TestBase $this->assertSame("{\"a\":1.5}", $m->serializeToJsonString()); } + public function testDecodeTopLevelAny() + { + // Make sure packed message has been created at least once. + $packed = new TestMessage(); + + $m1 = new Any(); + $m1->mergeFromJsonString( + "{\"optionalInt32\": 1, " . + "\"@type\":\"type.googleapis.com/foo.TestMessage\"}"); + $this->assertSame("type.googleapis.com/foo.TestMessage", + $m1->getTypeUrl()); + $this->assertSame("0801", bin2hex($m1->getValue())); + + $m2 = new Any(); + $m2->mergeFromJsonString( + "{\"@type\":\"type.googleapis.com/foo.TestMessage\", " . + "\"optionalInt32\": 1}"); + $this->assertSame("type.googleapis.com/foo.TestMessage", + $m2->getTypeUrl()); + $this->assertSame("0801", bin2hex($m2->getValue())); + + $m3 = new Any(); + $m3->mergeFromJsonString( + "{\"optionalInt32\": 1, " . + "\"@type\":\"type.googleapis.com/foo.TestMessage\", " . + "\"optionalInt64\": 2}"); + $this->assertSame("type.googleapis.com/foo.TestMessage", + $m3->getTypeUrl()); + $this->assertSame("08011002", bin2hex($m3->getValue())); + } + + public function testDecodeAny() + { + // Make sure packed message has been created at least once. + $packed = new TestMessage(); + + $m1 = new TestAny(); + $m1->mergeFromJsonString( + "{\"any\": {\"optionalInt32\": 1, " . + "\"@type\":\"type.googleapis.com/foo.TestMessage\"}}"); + $this->assertSame("type.googleapis.com/foo.TestMessage", + $m1->getAny()->getTypeUrl()); + $this->assertSame("0801", bin2hex($m1->getAny()->getValue())); + + $m2 = new TestAny(); + $m2->mergeFromJsonString( + "{\"any\":{\"@type\":\"type.googleapis.com/foo.TestMessage\", " . + "\"optionalInt32\": 1}}"); + $this->assertSame("type.googleapis.com/foo.TestMessage", + $m2->getAny()->getTypeUrl()); + $this->assertSame("0801", bin2hex($m2->getAny()->getValue())); + + $m3 = new TestAny(); + $m3->mergeFromJsonString( + "{\"any\":{\"optionalInt32\": 1, " . + "\"@type\":\"type.googleapis.com/foo.TestMessage\", " . + "\"optionalInt64\": 2}}"); + $this->assertSame("type.googleapis.com/foo.TestMessage", + $m3->getAny()->getTypeUrl()); + $this->assertSame("08011002", bin2hex($m3->getAny()->getValue())); + } + + public function testDecodeAnyWithWellKnownPacked() + { + // Make sure packed message has been created at least once. + $packed = new Int32Value(); + + $m1 = new TestAny(); + $m1->mergeFromJsonString( + "{\"any\":" . + " {\"@type\":\"type.googleapis.com/google.protobuf.Int32Value\"," . + " \"value\":1}}"); + $this->assertSame("type.googleapis.com/google.protobuf.Int32Value", + $m1->getAny()->getTypeUrl()); + $this->assertSame("0801", bin2hex($m1->getAny()->getValue())); + } + + /** + * @expectedException Exception + */ + public function testDecodeAnyWithUnknownPacked() + { + $m = new TestAny(); + $m->mergeFromJsonString( + "{\"any\":" . + " {\"@type\":\"type.googleapis.com/unknown\"," . + " \"value\":1}}"); + } + + public function testEncodeTopLevelAny() + { + // Test a normal message. + $packed = new TestMessage(); + $packed->setOptionalInt32(123); + $packed->setOptionalString("abc"); + + $m = new Any(); + $m->pack($packed); + $expected1 = + "{\"@type\":\"type.googleapis.com/foo.TestMessage\"," . + "\"optional_int32\":123,\"optional_string\":\"abc\"}"; + $expected2 = + "{\"@type\":\"type.googleapis.com/foo.TestMessage\"," . + "\"optionalInt32\":123,\"optionalString\":\"abc\"}"; + $result = $m->serializeToJsonString(); + $this->assertTrue($expected1 === $result || $expected2 === $result); + + // Test a well known message. + $packed = new Int32Value(); + $packed->setValue(123); + + $m = new Any(); + $m->pack($packed); + $this->assertSame( + "{\"@type\":\"type.googleapis.com/google.protobuf.Int32Value\"," . + "\"value\":123}", + $m->serializeToJsonString()); + + // Test an Any message. + $outer = new Any(); + $outer->pack($m); + $this->assertSame( + "{\"@type\":\"type.googleapis.com/google.protobuf.Any\"," . + "\"value\":{\"@type\":\"type.googleapis.com/google.protobuf.Int32Value\"," . + "\"value\":123}}", + $outer->serializeToJsonString()); + + // Test a Timestamp message. + $packed = new Google\Protobuf\Timestamp(); + $packed->setSeconds(946684800); + $packed->setNanos(123456789); + $m = new Any(); + $m->pack($packed); + $this->assertSame( + "{\"@type\":\"type.googleapis.com/google.protobuf.Timestamp\"," . + "\"value\":\"2000-01-01T00:00:00.123456789Z\"}", + $m->serializeToJsonString()); + } + } diff --git a/php/tests/gdb_test.sh b/php/tests/gdb_test.sh index 36fa31bbb2..da5f3f3ac1 100755 --- a/php/tests/gdb_test.sh +++ b/php/tests/gdb_test.sh @@ -11,7 +11,8 @@ php -i | grep "Configuration" # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which # phpunit` --bootstrap autoload.php tmp_test.php # -gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php generated_class_test.php +# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php generated_class_test.php +gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php # # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php # diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index f3bcb963f0..142f467669 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -19,6 +19,7 @@ require_once('generated/Bar/TestLegacyMessage/NestedEnum.php'); require_once('generated/Bar/TestLegacyMessage/NestedMessage.php'); require_once('generated/Foo/PBARRAY.php'); require_once('generated/Foo/PBEmpty.php'); +require_once('generated/Foo/TestAny.php'); require_once('generated/Foo/TestEnum.php'); require_once('generated/Foo/TestIncludeNamespaceMessage.php'); require_once('generated/Foo/TestIncludePrefixMessage.php'); @@ -49,6 +50,7 @@ require_once('test_util.php'); use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\GPBType; +use Foo\TestAny; use Foo\TestMessage; use Foo\TestMessage\Sub; @@ -191,3 +193,16 @@ $to = new TestMessage(); TestUtil::setTestMessage($from); $to->mergeFrom($from); TestUtil::assertTestMessage($to); + +// Test decode Any +// Make sure packed message has been created at least once. +$packed = new TestMessage(); + +$m = new TestAny(); +$m->mergeFromJsonString( + "{\"any\":" . + " {\"@type\":\"type.googleapis.com/foo.TestMessage\"," . + " \"optionalInt32\":1}}"); +assert("type.googleapis.com/foo.TestMessage" === + $m->getAny()->getTypeUrl()); +assert("0801" === bin2hex($m->getAny()->getValue())); diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto index d0109d83a5..e610c581b5 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -1,5 +1,6 @@ syntax = "proto3"; +import 'google/protobuf/any.proto'; import 'proto/test_include.proto'; import 'proto/test_no_namespace.proto'; import 'proto/test_php_namespace.proto'; @@ -201,3 +202,7 @@ message testLowerCaseMessage { enum testLowerCaseEnum { VALUE = 0; } + +message TestAny { + google.protobuf.Any any = 1; +} From be1716a6d0346de7a990b60f4afc9aebe2e06f36 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 26 Dec 2018 12:26:24 -0800 Subject: [PATCH 42/70] Revert "Enable the ignore_unknown_field option in the Ruby unmarshal options" (#5511) --- conformance/failure_list_ruby.txt | 50 +- ruby/ext/google/protobuf_c/encode_decode.c | 30 +- ruby/ext/google/protobuf_c/message.c | 2 +- ruby/ext/google/protobuf_c/protobuf.h | 2 +- ruby/ext/google/protobuf_c/upb.c | 4118 ++++++-------------- ruby/ext/google/protobuf_c/upb.h | 1494 ++----- ruby/lib/google/protobuf.rb | 4 +- ruby/tests/basic.rb | 13 - 8 files changed, 1650 insertions(+), 4063 deletions(-) diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt index 89270326c4..53b4970164 100644 --- a/conformance/failure_list_ruby.txt +++ b/conformance/failure_list_ruby.txt @@ -5,6 +5,8 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator +Recommended.Proto3.JsonInput.DurationHas9FractionalDigits.Validator +Recommended.Proto3.JsonInput.DurationHasZeroFractionalDigit.Validator Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull @@ -15,6 +17,9 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator +Recommended.Proto3.JsonInput.TimestampHas9FractionalDigits.Validator +Recommended.Proto3.JsonInput.TimestampHasZeroFractionalDigit.Validator +Recommended.Proto3.JsonInput.TimestampZeroNormalized.Validator Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput @@ -43,8 +48,12 @@ Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput +Required.Proto3.JsonInput.DurationMaxValue.JsonOutput +Required.Proto3.JsonInput.DurationMaxValue.ProtobufOutput Required.Proto3.JsonInput.DurationMinValue.JsonOutput +Required.Proto3.JsonInput.DurationMinValue.ProtobufOutput Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput +Required.Proto3.JsonInput.DurationRepeatedValue.ProtobufOutput Required.Proto3.JsonInput.FieldMask.JsonOutput Required.Proto3.JsonInput.FieldMask.ProtobufOutput Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput @@ -52,32 +61,71 @@ Required.Proto3.JsonInput.FloatFieldNan.JsonOutput Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput Required.Proto3.JsonInput.OneofFieldDuplicate Required.Proto3.JsonInput.OptionalBoolWrapper.JsonOutput +Required.Proto3.JsonInput.OptionalBoolWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalBytesWrapper.JsonOutput +Required.Proto3.JsonInput.OptionalBytesWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalDoubleWrapper.JsonOutput +Required.Proto3.JsonInput.OptionalDoubleWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalFloatWrapper.JsonOutput +Required.Proto3.JsonInput.OptionalFloatWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalInt32Wrapper.JsonOutput +Required.Proto3.JsonInput.OptionalInt32Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalInt64Wrapper.JsonOutput +Required.Proto3.JsonInput.OptionalInt64Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalStringWrapper.JsonOutput +Required.Proto3.JsonInput.OptionalStringWrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalUint32Wrapper.JsonOutput +Required.Proto3.JsonInput.OptionalUint32Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalUint64Wrapper.JsonOutput +Required.Proto3.JsonInput.OptionalUint64Wrapper.ProtobufOutput Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput Required.Proto3.JsonInput.RepeatedBoolWrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedBoolWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedBytesWrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedBytesWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedDoubleWrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedDoubleWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedFloatWrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedFloatWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedInt32Wrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedInt32Wrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedInt64Wrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedInt64Wrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedStringWrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedStringWrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedUint32Wrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedUint32Wrapper.ProtobufOutput Required.Proto3.JsonInput.RepeatedUint64Wrapper.JsonOutput +Required.Proto3.JsonInput.RepeatedUint64Wrapper.ProtobufOutput Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput -Required.Proto3.JsonInput.TimestampJsonInputTooSmall +Required.Proto3.JsonInput.Struct.JsonOutput +Required.Proto3.JsonInput.Struct.ProtobufOutput +Required.Proto3.JsonInput.TimestampMaxValue.JsonOutput +Required.Proto3.JsonInput.TimestampMaxValue.ProtobufOutput Required.Proto3.JsonInput.TimestampMinValue.JsonOutput Required.Proto3.JsonInput.TimestampMinValue.ProtobufOutput Required.Proto3.JsonInput.TimestampRepeatedValue.JsonOutput Required.Proto3.JsonInput.TimestampRepeatedValue.ProtobufOutput +Required.Proto3.JsonInput.TimestampWithNegativeOffset.JsonOutput +Required.Proto3.JsonInput.TimestampWithNegativeOffset.ProtobufOutput +Required.Proto3.JsonInput.TimestampWithPositiveOffset.JsonOutput +Required.Proto3.JsonInput.TimestampWithPositiveOffset.ProtobufOutput +Required.Proto3.JsonInput.ValueAcceptBool.JsonOutput +Required.Proto3.JsonInput.ValueAcceptBool.ProtobufOutput +Required.Proto3.JsonInput.ValueAcceptFloat.JsonOutput +Required.Proto3.JsonInput.ValueAcceptFloat.ProtobufOutput +Required.Proto3.JsonInput.ValueAcceptInteger.JsonOutput +Required.Proto3.JsonInput.ValueAcceptInteger.ProtobufOutput +Required.Proto3.JsonInput.ValueAcceptList.JsonOutput +Required.Proto3.JsonInput.ValueAcceptList.ProtobufOutput +Required.Proto3.JsonInput.ValueAcceptNull.JsonOutput +Required.Proto3.JsonInput.ValueAcceptNull.ProtobufOutput +Required.Proto3.JsonInput.ValueAcceptObject.JsonOutput +Required.Proto3.JsonInput.ValueAcceptObject.ProtobufOutput +Required.Proto3.JsonInput.ValueAcceptString.JsonOutput +Required.Proto3.JsonInput.ValueAcceptString.ProtobufOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index a14f0bc80d..0c5a74abd1 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -891,38 +891,19 @@ VALUE Message_decode(VALUE klass, VALUE data) { /* * call-seq: - * MessageClass.decode_json(data, options = {}) => message + * MessageClass.decode_json(data) => message * * Decodes the given data (as a string containing bytes in protocol buffers wire * format) under the interpretration given by this message class's definition * and returns a message object with the corresponding field values. - * - * @param options [Hash] options for the decoder - * ignore_unknown_fields: set true to ignore unknown fields (default is to raise an error) */ -VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { +VALUE Message_decode_json(VALUE klass, VALUE data) { VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned); Descriptor* desc = ruby_to_Descriptor(descriptor); VALUE msgklass = Descriptor_msgclass(descriptor); VALUE msg_rb; - VALUE data = argv[0]; - VALUE ignore_unknown_fields = Qfalse; MessageHeader* msg; - if (argc < 1 || argc > 2) { - rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); - } - - if (argc == 2) { - VALUE hash_args = argv[1]; - if (TYPE(hash_args) != T_HASH) { - rb_raise(rb_eArgError, "Expected hash arguments."); - } - - ignore_unknown_fields = rb_hash_lookup2( - hash_args, ID2SYM(rb_intern("ignore_unknown_fields")), Qfalse); - } - if (TYPE(data) != T_STRING) { rb_raise(rb_eArgError, "Expected string for JSON data."); } @@ -941,7 +922,7 @@ VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { stackenv_init(&se, "Error occurred during parsing: %s"); upb_sink_reset(&sink, get_fill_handlers(desc), msg); - parser = upb_json_parser_create(&se.env, method, &sink, ignore_unknown_fields); + parser = upb_json_parser_create(&se.env, method, &sink); upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data), upb_json_parser_input(parser)); @@ -1329,12 +1310,9 @@ VALUE Message_encode(VALUE klass, VALUE msg_rb) { /* * call-seq: - * MessageClass.encode_json(msg, options = {}) => json_string + * MessageClass.encode_json(msg) => json_string * * Encodes the given message object into its serialized JSON representation. - * @param options [Hash] options for the decoder - * preserve_proto_fieldnames: set true to use original fieldnames (default is to camelCase) - * emit_defaults: set true to emit 0/false values (default is to omit them) */ VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned); diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index fd123aebd0..b1d6a5e289 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -628,7 +628,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) { rb_define_method(klass, "[]=", Message_index_set, 2); rb_define_singleton_method(klass, "decode", Message_decode, 1); rb_define_singleton_method(klass, "encode", Message_encode, 1); - rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1); + rb_define_singleton_method(klass, "decode_json", Message_decode_json, 1); rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1); rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0); diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 616947c251..0aa385a09f 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -570,7 +570,7 @@ VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value); VALUE Message_descriptor(VALUE klass); VALUE Message_decode(VALUE klass, VALUE data); VALUE Message_encode(VALUE klass, VALUE msg_rb); -VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass); +VALUE Message_decode_json(VALUE klass, VALUE data); VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass); VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb); diff --git a/ruby/ext/google/protobuf_c/upb.c b/ruby/ext/google/protobuf_c/upb.c index 049e2bb061..c02a5ce4a4 100644 --- a/ruby/ext/google/protobuf_c/upb.c +++ b/ruby/ext/google/protobuf_c/upb.c @@ -1,506 +1,9 @@ // Amalgamated source file #include "upb.h" -#if UINTPTR_MAX == 0xffffffff -#define UPB_SIZE(size32, size64) size32 -#else -#define UPB_SIZE(size32, size64) size64 -#endif - -#define UPB_FIELD_AT(msg, fieldtype, offset) \ - *(fieldtype*)((const char*)(msg) + offset) - -#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) \ - : 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; -/* 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. */ - -#include - - -static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = { - &google_protobuf_FileDescriptorProto_msginit, -}; - -static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_FileDescriptorSet_msginit = { - &google_protobuf_FileDescriptorSet_submsgs[0], - &google_protobuf_FileDescriptorSet__fields[0], - UPB_SIZE(4, 8), 1, false, -}; - -static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = { - &google_protobuf_DescriptorProto_msginit, - &google_protobuf_EnumDescriptorProto_msginit, - &google_protobuf_FieldDescriptorProto_msginit, - &google_protobuf_FileOptions_msginit, - &google_protobuf_ServiceDescriptorProto_msginit, - &google_protobuf_SourceCodeInfo_msginit, -}; - -static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = { - {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, - {2, UPB_SIZE(16, 32), 2, 0, 9, 1}, - {3, UPB_SIZE(40, 80), 0, 0, 9, 3}, - {4, UPB_SIZE(44, 88), 0, 0, 11, 3}, - {5, UPB_SIZE(48, 96), 0, 1, 11, 3}, - {6, UPB_SIZE(52, 104), 0, 4, 11, 3}, - {7, UPB_SIZE(56, 112), 0, 2, 11, 3}, - {8, UPB_SIZE(32, 64), 4, 3, 11, 1}, - {9, UPB_SIZE(36, 72), 5, 5, 11, 1}, - {10, UPB_SIZE(60, 120), 0, 0, 5, 3}, - {11, UPB_SIZE(64, 128), 0, 0, 5, 3}, - {12, UPB_SIZE(24, 48), 3, 0, 9, 1}, -}; - -const upb_msglayout google_protobuf_FileDescriptorProto_msginit = { - &google_protobuf_FileDescriptorProto_submsgs[0], - &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(72, 144), 12, false, -}; - -static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[8] = { - &google_protobuf_DescriptorProto_msginit, - &google_protobuf_DescriptorProto_ExtensionRange_msginit, - &google_protobuf_DescriptorProto_ReservedRange_msginit, - &google_protobuf_EnumDescriptorProto_msginit, - &google_protobuf_FieldDescriptorProto_msginit, - &google_protobuf_MessageOptions_msginit, - &google_protobuf_OneofDescriptorProto_msginit, -}; - -static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = { - {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, - {2, UPB_SIZE(20, 40), 0, 4, 11, 3}, - {3, UPB_SIZE(24, 48), 0, 0, 11, 3}, - {4, UPB_SIZE(28, 56), 0, 3, 11, 3}, - {5, UPB_SIZE(32, 64), 0, 1, 11, 3}, - {6, UPB_SIZE(36, 72), 0, 4, 11, 3}, - {7, UPB_SIZE(16, 32), 2, 5, 11, 1}, - {8, UPB_SIZE(40, 80), 0, 6, 11, 3}, - {9, UPB_SIZE(44, 88), 0, 2, 11, 3}, - {10, UPB_SIZE(48, 96), 0, 0, 9, 3}, -}; - -const upb_msglayout google_protobuf_DescriptorProto_msginit = { - &google_protobuf_DescriptorProto_submsgs[0], - &google_protobuf_DescriptorProto__fields[0], - UPB_SIZE(56, 112), 10, false, -}; - -static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { - &google_protobuf_ExtensionRangeOptions_msginit, -}; - -static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, - {3, UPB_SIZE(12, 16), 3, 0, 11, 1}, -}; - -const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = { - &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], - &google_protobuf_DescriptorProto_ExtensionRange__fields[0], - UPB_SIZE(16, 24), 3, false, -}; - -static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, -}; - -const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = { - NULL, - &google_protobuf_DescriptorProto_ReservedRange__fields[0], - UPB_SIZE(12, 12), 2, false, -}; - -static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = { - &google_protobuf_ExtensionRangeOptions_submsgs[0], - &google_protobuf_ExtensionRangeOptions__fields[0], - UPB_SIZE(4, 8), 1, false, -}; - -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}, - {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}, - {9, UPB_SIZE(28, 28), 4, 0, 5, 1}, - {10, UPB_SIZE(64, 96), 9, 0, 9, 1}, -}; - -const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = { - &google_protobuf_FieldDescriptorProto_submsgs[0], - &google_protobuf_FieldDescriptorProto__fields[0], - UPB_SIZE(80, 128), 10, false, -}; - -static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = { - &google_protobuf_OneofOptions_msginit, -}; - -static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = { - {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, - {2, UPB_SIZE(16, 32), 2, 0, 11, 1}, -}; - -const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = { - &google_protobuf_OneofDescriptorProto_submsgs[0], - &google_protobuf_OneofDescriptorProto__fields[0], - UPB_SIZE(24, 48), 2, false, -}; - -static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = { - &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, - &google_protobuf_EnumOptions_msginit, - &google_protobuf_EnumValueDescriptorProto_msginit, -}; - -static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = { - {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, - {2, UPB_SIZE(20, 40), 0, 2, 11, 3}, - {3, UPB_SIZE(16, 32), 2, 1, 11, 1}, - {4, UPB_SIZE(24, 48), 0, 0, 11, 3}, - {5, UPB_SIZE(28, 56), 0, 0, 9, 3}, -}; - -const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = { - &google_protobuf_EnumDescriptorProto_submsgs[0], - &google_protobuf_EnumDescriptorProto__fields[0], - UPB_SIZE(32, 64), 5, false, -}; - -static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, -}; - -const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { - NULL, - &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], - UPB_SIZE(12, 12), 2, false, -}; - -static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { - &google_protobuf_EnumValueOptions_msginit, -}; - -static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = { - {1, UPB_SIZE(8, 16), 2, 0, 9, 1}, - {2, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {3, UPB_SIZE(16, 32), 3, 0, 11, 1}, -}; - -const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = { - &google_protobuf_EnumValueDescriptorProto_submsgs[0], - &google_protobuf_EnumValueDescriptorProto__fields[0], - UPB_SIZE(24, 48), 3, false, -}; - -static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { - &google_protobuf_MethodDescriptorProto_msginit, - &google_protobuf_ServiceOptions_msginit, -}; - -static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = { - {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, - {2, UPB_SIZE(20, 40), 0, 0, 11, 3}, - {3, UPB_SIZE(16, 32), 2, 1, 11, 1}, -}; - -const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = { - &google_protobuf_ServiceDescriptorProto_submsgs[0], - &google_protobuf_ServiceDescriptorProto__fields[0], - UPB_SIZE(24, 48), 3, false, -}; - -static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = { - &google_protobuf_MethodOptions_msginit, -}; - -static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = { - {1, UPB_SIZE(8, 16), 3, 0, 9, 1}, - {2, UPB_SIZE(16, 32), 4, 0, 9, 1}, - {3, UPB_SIZE(24, 48), 5, 0, 9, 1}, - {4, UPB_SIZE(32, 64), 6, 0, 11, 1}, - {5, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {6, UPB_SIZE(2, 2), 2, 0, 8, 1}, -}; - -const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = { - &google_protobuf_MethodDescriptorProto_submsgs[0], - &google_protobuf_MethodDescriptorProto__fields[0], - UPB_SIZE(40, 80), 6, false, -}; - -static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_FileOptions__fields[19] = { - {1, UPB_SIZE(32, 32), 11, 0, 9, 1}, - {8, UPB_SIZE(40, 48), 12, 0, 9, 1}, - {9, UPB_SIZE(8, 8), 1, 0, 14, 1}, - {10, UPB_SIZE(16, 16), 2, 0, 8, 1}, - {11, UPB_SIZE(48, 64), 13, 0, 9, 1}, - {16, UPB_SIZE(17, 17), 3, 0, 8, 1}, - {17, UPB_SIZE(18, 18), 4, 0, 8, 1}, - {18, UPB_SIZE(19, 19), 5, 0, 8, 1}, - {20, UPB_SIZE(20, 20), 6, 0, 8, 1}, - {23, UPB_SIZE(21, 21), 7, 0, 8, 1}, - {27, UPB_SIZE(22, 22), 8, 0, 8, 1}, - {31, UPB_SIZE(23, 23), 9, 0, 8, 1}, - {36, UPB_SIZE(56, 80), 14, 0, 9, 1}, - {37, UPB_SIZE(64, 96), 15, 0, 9, 1}, - {39, UPB_SIZE(72, 112), 16, 0, 9, 1}, - {40, UPB_SIZE(80, 128), 17, 0, 9, 1}, - {41, UPB_SIZE(88, 144), 18, 0, 9, 1}, - {42, UPB_SIZE(24, 24), 10, 0, 8, 1}, - {999, UPB_SIZE(96, 160), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_FileOptions_msginit = { - &google_protobuf_FileOptions_submsgs[0], - &google_protobuf_FileOptions__fields[0], - UPB_SIZE(104, 176), 19, false, -}; - -static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {2, UPB_SIZE(2, 2), 2, 0, 8, 1}, - {3, UPB_SIZE(3, 3), 3, 0, 8, 1}, - {7, UPB_SIZE(4, 4), 4, 0, 8, 1}, - {999, UPB_SIZE(8, 8), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_MessageOptions_msginit = { - &google_protobuf_MessageOptions_submsgs[0], - &google_protobuf_MessageOptions__fields[0], - UPB_SIZE(12, 16), 5, false, -}; - -static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = { - {1, UPB_SIZE(8, 8), 1, 0, 14, 1}, - {2, UPB_SIZE(24, 24), 3, 0, 8, 1}, - {3, UPB_SIZE(25, 25), 4, 0, 8, 1}, - {5, UPB_SIZE(26, 26), 5, 0, 8, 1}, - {6, UPB_SIZE(16, 16), 2, 0, 14, 1}, - {10, UPB_SIZE(27, 27), 6, 0, 8, 1}, - {999, UPB_SIZE(28, 32), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_FieldOptions_msginit = { - &google_protobuf_FieldOptions_submsgs[0], - &google_protobuf_FieldOptions__fields[0], - UPB_SIZE(32, 40), 7, false, -}; - -static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_OneofOptions_msginit = { - &google_protobuf_OneofOptions_submsgs[0], - &google_protobuf_OneofOptions__fields[0], - UPB_SIZE(4, 8), 1, false, -}; - -static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = { - {2, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {3, UPB_SIZE(2, 2), 2, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_EnumOptions_msginit = { - &google_protobuf_EnumOptions_submsgs[0], - &google_protobuf_EnumOptions__fields[0], - UPB_SIZE(8, 16), 3, false, -}; - -static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_EnumValueOptions_msginit = { - &google_protobuf_EnumValueOptions_submsgs[0], - &google_protobuf_EnumValueOptions__fields[0], - UPB_SIZE(8, 16), 2, false, -}; - -static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = { - {33, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_ServiceOptions_msginit = { - &google_protobuf_ServiceOptions_submsgs[0], - &google_protobuf_ServiceOptions__fields[0], - UPB_SIZE(8, 16), 2, false, -}; - -static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, -}; - -static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = { - {33, UPB_SIZE(16, 16), 2, 0, 8, 1}, - {34, UPB_SIZE(8, 8), 1, 0, 14, 1}, - {999, UPB_SIZE(20, 24), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_MethodOptions_msginit = { - &google_protobuf_MethodOptions_submsgs[0], - &google_protobuf_MethodOptions__fields[0], - UPB_SIZE(24, 32), 3, false, -}; - -static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = { - &google_protobuf_UninterpretedOption_NamePart_msginit, -}; - -static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = { - {2, UPB_SIZE(56, 80), 0, 0, 11, 3}, - {3, UPB_SIZE(32, 32), 4, 0, 9, 1}, - {4, UPB_SIZE(8, 8), 1, 0, 4, 1}, - {5, UPB_SIZE(16, 16), 2, 0, 3, 1}, - {6, UPB_SIZE(24, 24), 3, 0, 1, 1}, - {7, UPB_SIZE(40, 48), 5, 0, 12, 1}, - {8, UPB_SIZE(48, 64), 6, 0, 9, 1}, -}; - -const upb_msglayout google_protobuf_UninterpretedOption_msginit = { - &google_protobuf_UninterpretedOption_submsgs[0], - &google_protobuf_UninterpretedOption__fields[0], - UPB_SIZE(64, 96), 7, false, -}; - -static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = { - {1, UPB_SIZE(8, 16), 2, 0, 9, 2}, - {2, UPB_SIZE(1, 1), 1, 0, 8, 2}, -}; - -const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = { - NULL, - &google_protobuf_UninterpretedOption_NamePart__fields[0], - UPB_SIZE(16, 32), 2, false, -}; - -static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { - &google_protobuf_SourceCodeInfo_Location_msginit, -}; - -static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_SourceCodeInfo_msginit = { - &google_protobuf_SourceCodeInfo_submsgs[0], - &google_protobuf_SourceCodeInfo__fields[0], - UPB_SIZE(4, 8), 1, false, -}; - -static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, UPB_SIZE(24, 48), 0, 0, 5, 3}, - {2, UPB_SIZE(28, 56), 0, 0, 5, 3}, - {3, UPB_SIZE(8, 16), 1, 0, 9, 1}, - {4, UPB_SIZE(16, 32), 2, 0, 9, 1}, - {6, UPB_SIZE(32, 64), 0, 0, 9, 3}, -}; - -const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = { - NULL, - &google_protobuf_SourceCodeInfo_Location__fields[0], - UPB_SIZE(40, 80), 5, false, -}; - -static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = { - &google_protobuf_GeneratedCodeInfo_Annotation_msginit, -}; - -static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, -}; - -const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = { - &google_protobuf_GeneratedCodeInfo_submsgs[0], - &google_protobuf_GeneratedCodeInfo__fields[0], - UPB_SIZE(4, 8), 1, false, -}; - -static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { - {1, UPB_SIZE(24, 32), 0, 0, 5, 3}, - {2, UPB_SIZE(16, 16), 3, 0, 9, 1}, - {3, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {4, UPB_SIZE(8, 8), 2, 0, 5, 1}, -}; - -const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = { - NULL, - &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], - UPB_SIZE(32, 48), 4, false, -}; - - - /* Maps descriptor type -> upb field type. */ -const uint8_t upb_desctype_to_fieldtype[] = { +static const uint8_t upb_desctype_to_fieldtype[] = { UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */ UPB_TYPE_DOUBLE, /* DOUBLE */ UPB_TYPE_FLOAT, /* FLOAT */ @@ -524,6 +27,7 @@ const uint8_t upb_desctype_to_fieldtype[] = { /* Data pertaining to the parse. */ typedef struct { + upb_env *env; /* Current decoding pointer. Points to the beginning of a field until we * have finished decoding the whole field. */ const char *ptr; @@ -536,7 +40,7 @@ typedef struct { /* These members are unset for an unknown group frame. */ char *msg; - const upb_msglayout *m; + const upb_msglayout_msginit_v1 *m; } upb_decframe; #define CHK(x) if (!(x)) { return false; } @@ -545,7 +49,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number, const char *limit); static bool upb_decode_message(upb_decstate *d, const char *limit, int group_number, char *msg, - const upb_msglayout *l); + const upb_msglayout_msginit_v1 *l); static bool upb_decode_varint(const char **ptr, const char *limit, uint64_t *val) { @@ -626,7 +130,9 @@ static void upb_set32(void *msg, size_t ofs, uint32_t val) { static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame, const char *start) { - upb_msg_addunknown(frame->msg, start, d->ptr - start); + UPB_UNUSED(d); + UPB_UNUSED(frame); + UPB_UNUSED(start); return true; } @@ -665,7 +171,6 @@ static bool upb_array_grow(upb_array *arr, size_t elements) { size_t new_bytes; size_t old_bytes; void *new_data; - upb_alloc *alloc = upb_arena_alloc(arr->arena); while (new_size < needed) { new_size *= 2; @@ -673,7 +178,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) { old_bytes = arr->len * arr->element_size; new_bytes = new_size * arr->element_size; - new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes); + new_data = upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes); CHK(new_data); arr->data = new_data; @@ -695,21 +200,23 @@ static void *upb_array_add(upb_array *arr, size_t elements) { } static upb_array *upb_getarr(upb_decframe *frame, - const upb_msglayout_field *field) { + const upb_msglayout_fieldinit_v1 *field) { UPB_ASSERT(field->label == UPB_LABEL_REPEATED); return *(upb_array**)&frame->msg[field->offset]; } -static upb_array *upb_getorcreatearr(upb_decframe *frame, - const upb_msglayout_field *field) { +static upb_array *upb_getorcreatearr(upb_decstate *d, + upb_decframe *frame, + const upb_msglayout_fieldinit_v1 *field) { upb_array *arr = upb_getarr(frame, field); if (!arr) { - upb_fieldtype_t type = upb_desctype_to_fieldtype[field->descriptortype]; - arr = upb_array_new(type, upb_msg_arena(frame->msg)); + arr = upb_env_malloc(d->env, sizeof(*arr)); if (!arr) { return NULL; } + upb_array_init(arr, upb_desctype_to_fieldtype[field->type], + upb_arena_alloc(upb_env_arena(d->env))); *(upb_array**)&frame->msg[field->offset] = arr; } @@ -717,25 +224,26 @@ static upb_array *upb_getorcreatearr(upb_decframe *frame, } 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)); + const upb_msglayout_fieldinit_v1 *field) { + UPB_ASSERT(field->hasbit != UPB_NO_HASBIT); + frame->msg[field->hasbit / 8] |= (1 << (field->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); + const upb_msglayout_fieldinit_v1 *field) { + UPB_ASSERT(field->oneof_index != UPB_NOT_IN_ONEOF); + upb_set32(frame->msg, frame->m->oneofs[field->oneof_index].case_offset, + field->number); } -static char *upb_decode_prepareslot(upb_decframe *frame, - const upb_msglayout_field *field) { +static char *upb_decode_prepareslot(upb_decstate *d, + upb_decframe *frame, + const upb_msglayout_fieldinit_v1 *field) { char *field_mem = frame->msg + field->offset; upb_array *arr; if (field->label == UPB_LABEL_REPEATED) { - arr = upb_getorcreatearr(frame, field); + arr = upb_getorcreatearr(d, frame, field); field_mem = upb_array_reserve(arr, 1); } @@ -743,33 +251,36 @@ static char *upb_decode_prepareslot(upb_decframe *frame, } static void upb_decode_setpresent(upb_decframe *frame, - const upb_msglayout_field *field) { + const upb_msglayout_fieldinit_v1 *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) { + } else if (field->oneof_index != UPB_NOT_IN_ONEOF) { upb_setoneofcase(frame, field); - } else if (field->presence > 0) { + } else if (field->hasbit != UPB_NO_HASBIT) { upb_sethasbit(frame, field); } } -static bool upb_decode_submsg(upb_decstate *d, upb_decframe *frame, +static bool upb_decode_submsg(upb_decstate *d, + upb_decframe *frame, const char *limit, - const upb_msglayout_field *field, + const upb_msglayout_fieldinit_v1 *field, int group_number) { - char *submsg_slot = upb_decode_prepareslot(frame, field); - char *submsg = *(void **)submsg_slot; - const upb_msglayout *subm; + char *submsg = *(void**)&frame->msg[field->offset]; + const upb_msglayout_msginit_v1 *subm; + UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG); subm = frame->m->submsgs[field->submsg_index]; UPB_ASSERT(subm); if (!submsg) { - submsg = upb_msg_new(subm, upb_msg_arena(frame->msg)); + submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm)); CHK(submsg); - *(void**)submsg_slot = submsg; + submsg = upb_msg_init( + submsg, (upb_msglayout*)subm, upb_arena_alloc(upb_env_arena(d->env))); + *(void**)&frame->msg[field->offset] = submsg; } upb_decode_message(d, limit, group_number, submsg, subm); @@ -779,15 +290,15 @@ static bool upb_decode_submsg(upb_decstate *d, upb_decframe *frame, static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_field *field) { + const upb_msglayout_fieldinit_v1 *field) { uint64_t val; void *field_mem; - field_mem = upb_decode_prepareslot(frame, field); + field_mem = upb_decode_prepareslot(d, frame, field); CHK(field_mem); CHK(upb_decode_varint(&d->ptr, frame->limit, &val)); - switch ((upb_descriptortype_t)field->descriptortype) { + switch ((upb_descriptortype_t)field->type) { case UPB_DESCRIPTOR_TYPE_INT64: case UPB_DESCRIPTOR_TYPE_UINT64: memcpy(field_mem, &val, sizeof(val)); @@ -824,15 +335,15 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_field *field) { + const upb_msglayout_fieldinit_v1 *field) { void *field_mem; uint64_t val; - field_mem = upb_decode_prepareslot(frame, field); + field_mem = upb_decode_prepareslot(d, frame, field); CHK(field_mem); CHK(upb_decode_64bit(&d->ptr, frame->limit, &val)); - switch ((upb_descriptortype_t)field->descriptortype) { + switch ((upb_descriptortype_t)field->type) { case UPB_DESCRIPTOR_TYPE_DOUBLE: case UPB_DESCRIPTOR_TYPE_FIXED64: case UPB_DESCRIPTOR_TYPE_SFIXED64: @@ -848,15 +359,15 @@ static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame, static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_field *field) { + const upb_msglayout_fieldinit_v1 *field) { void *field_mem; uint32_t val; - field_mem = upb_decode_prepareslot(frame, field); + field_mem = upb_decode_prepareslot(d, frame, field); CHK(field_mem); CHK(upb_decode_32bit(&d->ptr, frame->limit, &val)); - switch ((upb_descriptortype_t)field->descriptortype) { + switch ((upb_descriptortype_t)field->type) { case UPB_DESCRIPTOR_TYPE_FLOAT: case UPB_DESCRIPTOR_TYPE_FIXED32: case UPB_DESCRIPTOR_TYPE_SFIXED32: @@ -884,9 +395,9 @@ static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data, static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_field *field, + const upb_msglayout_fieldinit_v1 *field, upb_stringview val) { - upb_array *arr = upb_getorcreatearr(frame, field); + upb_array *arr = upb_getorcreatearr(d, frame, field); #define VARINT_CASE(ctype, decode) { \ const char *ptr = val.data; \ @@ -904,7 +415,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, return true; \ } - switch ((upb_descriptortype_t)field->descriptortype) { + switch ((upb_descriptortype_t)field->type) { case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_BYTES: { void *field_mem = upb_array_add(arr, 1); @@ -934,28 +445,9 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, VARINT_CASE(int32_t, upb_zzdecode_32); case UPB_DESCRIPTOR_TYPE_SINT64: VARINT_CASE(int64_t, upb_zzdecode_64); - case UPB_DESCRIPTOR_TYPE_MESSAGE: { - const upb_msglayout *subm; - char *submsg; - void *field_mem; - + case UPB_DESCRIPTOR_TYPE_MESSAGE: CHK(val.size <= (size_t)(frame->limit - val.data)); - d->ptr -= val.size; - - /* Create elemente message. */ - subm = frame->m->submsgs[field->submsg_index]; - UPB_ASSERT(subm); - - submsg = upb_msg_new(subm, upb_msg_arena(frame->msg)); - CHK(submsg); - - field_mem = upb_array_add(arr, 1); - CHK(field_mem); - *(void**)field_mem = submsg; - - return upb_decode_message( - d, val.data + val.size, frame->group_number, submsg, subm); - } + return upb_decode_submsg(d, frame, val.data + val.size, field, 0); case UPB_DESCRIPTOR_TYPE_GROUP: return upb_append_unknown(d, frame, field_start); } @@ -965,7 +457,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_field *field) { + const upb_msglayout_fieldinit_v1 *field) { upb_stringview val; CHK(upb_decode_string(&d->ptr, frame->limit, &val)); @@ -973,17 +465,16 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, if (field->label == UPB_LABEL_REPEATED) { return upb_decode_toarray(d, frame, field_start, field, val); } else { - switch ((upb_descriptortype_t)field->descriptortype) { + switch ((upb_descriptortype_t)field->type) { case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_BYTES: { - void *field_mem = upb_decode_prepareslot(frame, field); + void *field_mem = upb_decode_prepareslot(d, frame, field); CHK(field_mem); memcpy(field_mem, &val, sizeof(val)); break; } case UPB_DESCRIPTOR_TYPE_MESSAGE: CHK(val.size <= (size_t)(frame->limit - val.data)); - d->ptr -= val.size; CHK(upb_decode_submsg(d, frame, val.data + val.size, field, 0)); break; default: @@ -995,8 +486,8 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, } } -static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, - uint32_t field_number) { +static const upb_msglayout_fieldinit_v1 *upb_find_field( + const upb_msglayout_msginit_v1 *l, uint32_t field_number) { /* Lots of optimization opportunities here. */ int i; for (i = 0; i < l->field_count; i++) { @@ -1012,7 +503,7 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { int field_number; int wire_type; const char *field_start = d->ptr; - const upb_msglayout_field *field; + const upb_msglayout_fieldinit_v1 *field; CHK(upb_decode_tag(&d->ptr, frame->limit, &field_number, &wire_type)); field = upb_find_field(frame->m, field_number); @@ -1028,7 +519,7 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { case UPB_WIRE_TYPE_DELIMITED: return upb_decode_delimitedfield(d, frame, field_start, field); case UPB_WIRE_TYPE_START_GROUP: - CHK(field->descriptortype == UPB_DESCRIPTOR_TYPE_GROUP); + CHK(field->type == UPB_DESCRIPTOR_TYPE_GROUP); return upb_decode_submsg(d, frame, frame->limit, field, field_number); case UPB_WIRE_TYPE_END_GROUP: CHK(frame->group_number == field_number) @@ -1039,9 +530,7 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { } } else { CHK(field_number != 0); - CHK(upb_skip_unknownfielddata(d, frame, field_number, wire_type)); - CHK(upb_append_unknown(d, frame, field_start)); - return true; + return upb_skip_unknownfielddata(d, frame, field_number, wire_type); } } @@ -1066,7 +555,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number, static bool upb_decode_message(upb_decstate *d, const char *limit, int group_number, char *msg, - const upb_msglayout *l) { + const upb_msglayout_msginit_v1 *l) { upb_decframe frame; frame.group_number = group_number; frame.limit = limit; @@ -1080,9 +569,11 @@ static bool upb_decode_message(upb_decstate *d, const char *limit, return true; } -bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l) { +bool upb_decode(upb_stringview buf, void *msg, + const upb_msglayout_msginit_v1 *l, upb_env *env) { upb_decstate state; state.ptr = buf.data; + state.env = env; return upb_decode_message(&state, buf.data + buf.size, 0, msg, l); } @@ -1452,45 +943,6 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { return true; } -static void assign_msg_wellknowntype(upb_msgdef *m) { - const char *name = upb_msgdef_fullname(m); - if (name == NULL) { - m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; - return; - } - if (!strcmp(name, "google.protobuf.Duration")) { - m->well_known_type = UPB_WELLKNOWN_DURATION; - } else if (!strcmp(name, "google.protobuf.Timestamp")) { - m->well_known_type = UPB_WELLKNOWN_TIMESTAMP; - } else if (!strcmp(name, "google.protobuf.DoubleValue")) { - m->well_known_type = UPB_WELLKNOWN_DOUBLEVALUE; - } else if (!strcmp(name, "google.protobuf.FloatValue")) { - m->well_known_type = UPB_WELLKNOWN_FLOATVALUE; - } else if (!strcmp(name, "google.protobuf.Int64Value")) { - m->well_known_type = UPB_WELLKNOWN_INT64VALUE; - } else if (!strcmp(name, "google.protobuf.UInt64Value")) { - m->well_known_type = UPB_WELLKNOWN_UINT64VALUE; - } else if (!strcmp(name, "google.protobuf.Int32Value")) { - m->well_known_type = UPB_WELLKNOWN_INT32VALUE; - } else if (!strcmp(name, "google.protobuf.UInt32Value")) { - m->well_known_type = UPB_WELLKNOWN_UINT32VALUE; - } else if (!strcmp(name, "google.protobuf.BoolValue")) { - m->well_known_type = UPB_WELLKNOWN_BOOLVALUE; - } else if (!strcmp(name, "google.protobuf.StringValue")) { - m->well_known_type = UPB_WELLKNOWN_STRINGVALUE; - } else if (!strcmp(name, "google.protobuf.BytesValue")) { - m->well_known_type = UPB_WELLKNOWN_BYTESVALUE; - } else if (!strcmp(name, "google.protobuf.Value")) { - m->well_known_type = UPB_WELLKNOWN_VALUE; - } else if (!strcmp(name, "google.protobuf.ListValue")) { - m->well_known_type = UPB_WELLKNOWN_LISTVALUE; - } else if (!strcmp(name, "google.protobuf.Struct")) { - m->well_known_type = UPB_WELLKNOWN_STRUCT; - } else { - m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; - } -} - bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { size_t i; @@ -1527,8 +979,6 @@ bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { if (!assign_msg_indices(m, s)) { goto err; } - assign_msg_wellknowntype(m); - /* m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; */ } else if (e) { upb_inttable_compact(&e->iton); } @@ -2721,16 +2171,6 @@ bool upb_msgdef_mapentry(const upb_msgdef *m) { return m->map_entry; } -upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m) { - return m->well_known_type; -} - -bool upb_msgdef_isnumberwrapper(const upb_msgdef *m) { - upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); - return type >= UPB_WELLKNOWN_DOUBLEVALUE && - type <= UPB_WELLKNOWN_UINT32VALUE; -} - void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { upb_inttable_begin(iter, &m->itof); } @@ -3545,7 +2985,7 @@ static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); } static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); } typedef struct { - upb_alloc *alloc; + upb_env *env; char *buf, *ptr, *limit; } upb_encstate; @@ -3560,11 +3000,11 @@ static size_t upb_roundup_pow2(size_t bytes) { static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) { size_t old_size = e->limit - e->buf; size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size); + char *new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size); CHK(new_buf); /* We want previous data at the end, realloc() put it at the beginning. */ - memmove(new_buf + new_size - old_size, e->buf, old_size); + memmove(e->limit - old_size, e->buf, old_size); e->ptr = new_buf + new_size - (e->limit - e->ptr); e->limit = new_buf + new_size; @@ -3624,17 +3064,17 @@ static bool upb_put_float(upb_encstate *e, float d) { return upb_put_fixed32(e, u32); } -static uint32_t upb_readcase(const char *msg, const upb_msglayout_field *f) { +static uint32_t upb_readcase(const char *msg, const upb_msglayout_msginit_v1 *m, + int oneof_index) { uint32_t ret; - uint32_t offset = ~f->presence; - memcpy(&ret, msg + offset, sizeof(ret)); + memcpy(&ret, msg + m->oneofs[oneof_index].case_offset, 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)); +static bool upb_readhasbit(const char *msg, + const upb_msglayout_fieldinit_v1 *f) { + UPB_ASSERT(f->hasbit != UPB_NO_HASBIT); + return msg[f->hasbit / 8] & (1 << (f->hasbit % 8)); } static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) { @@ -3648,18 +3088,19 @@ static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr, } bool upb_encode_message(upb_encstate *e, const char *msg, - const upb_msglayout *m, size_t *size); + const upb_msglayout_msginit_v1 *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_msglayout_msginit_v1 *m, + const upb_msglayout_fieldinit_v1 *f) { const upb_array *arr = *(const upb_array**)field_mem; if (arr == NULL || arr->len == 0) { return true; } - UPB_ASSERT(arr->type == upb_desctype_to_fieldtype2[f->descriptortype]); + UPB_ASSERT(arr->type == upb_desctype_to_fieldtype2[f->type]); #define VARINT_CASE(ctype, encode) { \ ctype *start = arr->data; \ @@ -3674,7 +3115,7 @@ static bool upb_encode_array(upb_encstate *e, const char *field_mem, break; \ do { ; } while(0) - switch (f->descriptortype) { + switch (f->type) { case UPB_DESCRIPTOR_TYPE_DOUBLE: CHK(upb_put_fixedarray(e, arr, sizeof(double))); break; @@ -3693,10 +3134,9 @@ do { ; } while(0) 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); + VARINT_CASE(uint32_t, *ptr); case UPB_DESCRIPTOR_TYPE_BOOL: VARINT_CASE(bool, *ptr); case UPB_DESCRIPTOR_TYPE_SINT32: @@ -3718,7 +3158,7 @@ do { ; } while(0) case UPB_DESCRIPTOR_TYPE_GROUP: { void **start = arr->data; void **ptr = start + arr->len; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; do { size_t size; ptr--; @@ -3731,7 +3171,7 @@ do { ; } while(0) case UPB_DESCRIPTOR_TYPE_MESSAGE: { void **start = arr->data; void **ptr = start + arr->len; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; do { size_t size; ptr--; @@ -3751,9 +3191,11 @@ do { ; } while(0) } static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, - const upb_msglayout *m, - const upb_msglayout_field *f, - bool skip_zero_value) { + const upb_msglayout_msginit_v1 *m, + const upb_msglayout_fieldinit_v1 *f, + bool is_proto3) { + bool skip_zero_value = is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF; + #define CASE(ctype, type, wire_type, encodeval) do { \ ctype val = *(ctype*)field_mem; \ if (skip_zero_value && val == 0) { \ @@ -3763,7 +3205,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, upb_put_tag(e, f->number, wire_type); \ } while(0) - switch (f->descriptortype) { + switch (f->type) { case UPB_DESCRIPTOR_TYPE_DOUBLE: CASE(double, double, UPB_WIRE_TYPE_64BIT, val); case UPB_DESCRIPTOR_TYPE_FLOAT: @@ -3772,10 +3214,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, case UPB_DESCRIPTOR_TYPE_UINT64: CASE(uint64_t, varint, UPB_WIRE_TYPE_VARINT, val); case UPB_DESCRIPTOR_TYPE_UINT32: - CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); case UPB_DESCRIPTOR_TYPE_INT32: case UPB_DESCRIPTOR_TYPE_ENUM: - CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, (int64_t)val); + CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); case UPB_DESCRIPTOR_TYPE_SFIXED64: case UPB_DESCRIPTOR_TYPE_FIXED64: CASE(uint64_t, fixed64, UPB_WIRE_TYPE_64BIT, val); @@ -3800,9 +3241,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, } case UPB_DESCRIPTOR_TYPE_GROUP: { size_t size; - void *submsg = *(void **)field_mem; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; - if (submsg == NULL) { + void *submsg = *(void**)field_mem; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + if (skip_zero_value && submsg == NULL) { return true; } return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && @@ -3811,9 +3252,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, } 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) { + void *submsg = *(void**)field_mem; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + if (skip_zero_value && submsg == NULL) { return true; } return upb_encode_message(e, submsg, subm, &size) && @@ -3825,52 +3266,49 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, UPB_UNREACHABLE(); } -bool upb_encode_message(upb_encstate *e, const char *msg, - const upb_msglayout *m, size_t *size) { +bool upb_encode_hasscalarfield(const char *msg, + const upb_msglayout_msginit_v1 *m, + const upb_msglayout_fieldinit_v1 *f) { + if (f->oneof_index != UPB_NOT_IN_ONEOF) { + return upb_readcase(msg, m, f->oneof_index) == f->number; + } else if (m->is_proto2) { + return upb_readhasbit(msg, f); + } else { + /* For proto3, we'll test for the field being empty later. */ + return true; + } +} + +bool upb_encode_message(upb_encstate* e, const char *msg, + const upb_msglayout_msginit_v1 *m, + size_t *size) { int i; - size_t pre_len = e->limit - e->ptr; - const char *unknown; - size_t unknown_size; + char *buf_end = e->ptr; + + if (msg == NULL) { + return true; + } for (i = m->field_count - 1; i >= 0; i--) { - const upb_msglayout_field *f = &m->fields[i]; + const upb_msglayout_fieldinit_v1 *f = &m->fields[i]; if (f->label == UPB_LABEL_REPEATED) { CHK(upb_encode_array(e, msg + f->offset, m, f)); } else { - bool skip_empty = false; - if (f->presence == 0) { - /* Proto3 presence. */ - skip_empty = true; - } else if (f->presence > 0) { - /* Proto2 presence: hasbit. */ - if (!upb_readhasbit(msg, f)) { - continue; - } - } else { - /* Field is in a oneof. */ - if (upb_readcase(msg, f) != f->number) { - continue; - } + if (upb_encode_hasscalarfield(msg, m, f)) { + CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, !m->is_proto2)); } - CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, skip_empty)); } } - unknown = upb_msg_getunknown(msg, &unknown_size); - - if (unknown) { - upb_put_bytes(e, unknown, unknown_size); - } - - *size = (e->limit - e->ptr) - pre_len; + *size = buf_end - e->ptr; return true; } -char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena, - size_t *size) { +char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *m, + upb_env *env, size_t *size) { upb_encstate e; - e.alloc = upb_arena_alloc(arena); + e.env = env; e.buf = NULL; e.limit = NULL; e.ptr = NULL; @@ -4595,107 +4033,28 @@ bool upb_byteshandler_setendstr(upb_byteshandler *h, } -/** Handlers for upb_msg ******************************************************/ +static bool is_power_of_two(size_t val) { + return (val & (val - 1)) == 0; +} -typedef struct { - size_t offset; - int32_t hasbit; -} upb_msg_handlerdata; +/* 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); +} -/* Fallback implementation if the handler is not specialized by the producer. */ -#define MSG_WRITER(type, ctype) \ - bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \ - uint8_t *m = c; \ - const upb_msg_handlerdata *d = hd; \ - if (d->hasbit > 0) \ - *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ - *(ctype*)&m[d->offset] = val; \ - return true; \ - } \ +static size_t div_round_up(size_t n, size_t d) { + return (n + d - 1) / d; +} -MSG_WRITER(double, double) -MSG_WRITER(float, float) -MSG_WRITER(int32, int32_t) -MSG_WRITER(int64, int64_t) -MSG_WRITER(uint32, uint32_t) -MSG_WRITER(uint64, uint64_t) -MSG_WRITER(bool, bool) +bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) { + return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 || + type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 || + type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING; +} -bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f, - size_t offset, int32_t hasbit) { - upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; - bool ok; - - upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d)); - if (!d) return false; - d->offset = offset; - d->hasbit = hasbit; - - upb_handlerattr_sethandlerdata(&attr, d); - upb_handlerattr_setalwaysok(&attr, true); - upb_handlers_addcleanup(h, d, upb_gfree); - -#define TYPE(u, l) \ - case UPB_TYPE_##u: \ - ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break; - - ok = false; - - switch (upb_fielddef_type(f)) { - TYPE(INT64, int64); - TYPE(INT32, int32); - TYPE(ENUM, int32); - TYPE(UINT64, uint64); - TYPE(UINT32, uint32); - TYPE(DOUBLE, double); - TYPE(FLOAT, float); - TYPE(BOOL, bool); - default: UPB_ASSERT(false); break; - } -#undef TYPE - - upb_handlerattr_uninit(&attr); - return ok; -} - -bool upb_msg_getscalarhandlerdata(const upb_handlers *h, - upb_selector_t s, - upb_fieldtype_t *type, - size_t *offset, - int32_t *hasbit) { - const upb_msg_handlerdata *d; - upb_func *f = upb_handlers_gethandler(h, s); - - if ((upb_int64_handlerfunc*)f == upb_msg_setint64) { - *type = UPB_TYPE_INT64; - } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) { - *type = UPB_TYPE_INT32; - } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) { - *type = UPB_TYPE_UINT64; - } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) { - *type = UPB_TYPE_UINT32; - } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) { - *type = UPB_TYPE_DOUBLE; - } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) { - *type = UPB_TYPE_FLOAT; - } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) { - *type = UPB_TYPE_BOOL; - } else { - return false; - } - - d = upb_handlers_gethandlerdata(h, s); - *offset = d->offset; - *hasbit = d->hasbit; - return true; -} - - -bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) { - return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 || - type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 || - type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING; -} +void *upb_array_pack(const upb_array *arr, void *p, size_t *ofs, size_t size); +void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size); #define PTR_AT(msg, ofs, type) (type*)((char*)msg + ofs) #define VOIDPTR_AT(msg, ofs) PTR_AT(msg, ofs, void) @@ -4736,56 +4095,575 @@ static size_t upb_msgval_sizeof(upb_fieldtype_t type) { return 4; case UPB_TYPE_BOOL: return 1; + case UPB_TYPE_BYTES: case UPB_TYPE_MESSAGE: return sizeof(void*); - case UPB_TYPE_BYTES: case UPB_TYPE_STRING: return sizeof(upb_stringview); } - UPB_UNREACHABLE(); -} + UPB_UNREACHABLE(); +} + +static uint8_t upb_msg_fieldsize(const upb_msglayout_fieldinit_v1 *field) { + if (field->label == UPB_LABEL_REPEATED) { + return sizeof(void*); + } else { + return upb_msgval_sizeof(field->type); + } +} + +static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { + if (upb_fielddef_isseq(f)) { + return sizeof(void*); + } else { + return upb_msgval_sizeof(upb_fielddef_type(f)); + } +} + +/* TODO(haberman): this is broken right now because upb_msgval can contain + * a char* / size_t pair, which is too big for a upb_value. To fix this + * we'll probably need to dynamically allocate a upb_msgval and store a + * pointer to that in the tables for extensions/maps. */ +static upb_value upb_toval(upb_msgval val) { + upb_value ret; + UPB_UNUSED(val); + memset(&ret, 0, sizeof(upb_value)); /* XXX */ + return ret; +} + +static upb_msgval upb_msgval_fromval(upb_value val) { + upb_msgval ret; + UPB_UNUSED(val); + memset(&ret, 0, sizeof(upb_msgval)); /* XXX */ + return ret; +} + +static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) { + switch (type) { + case UPB_TYPE_FLOAT: return UPB_CTYPE_FLOAT; + case UPB_TYPE_DOUBLE: return UPB_CTYPE_DOUBLE; + case UPB_TYPE_BOOL: return UPB_CTYPE_BOOL; + case UPB_TYPE_BYTES: + case UPB_TYPE_MESSAGE: + case UPB_TYPE_STRING: return UPB_CTYPE_CONSTPTR; + case UPB_TYPE_ENUM: + case UPB_TYPE_INT32: return UPB_CTYPE_INT32; + case UPB_TYPE_UINT32: return UPB_CTYPE_UINT32; + case UPB_TYPE_INT64: return UPB_CTYPE_INT64; + case UPB_TYPE_UINT64: return UPB_CTYPE_UINT64; + default: UPB_ASSERT(false); return 0; + } +} + +static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) { + switch (upb_fielddef_type(f)) { + case UPB_TYPE_FLOAT: + return upb_msgval_float(upb_fielddef_defaultfloat(f)); + case UPB_TYPE_DOUBLE: + return upb_msgval_double(upb_fielddef_defaultdouble(f)); + case UPB_TYPE_BOOL: + return upb_msgval_bool(upb_fielddef_defaultbool(f)); + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: { + size_t len; + const char *ptr = upb_fielddef_defaultstr(f, &len); + return upb_msgval_makestr(ptr, len); + } + case UPB_TYPE_MESSAGE: + return upb_msgval_msg(NULL); + case UPB_TYPE_ENUM: + case UPB_TYPE_INT32: + return upb_msgval_int32(upb_fielddef_defaultint32(f)); + case UPB_TYPE_UINT32: + return upb_msgval_uint32(upb_fielddef_defaultuint32(f)); + case UPB_TYPE_INT64: + return upb_msgval_int64(upb_fielddef_defaultint64(f)); + case UPB_TYPE_UINT64: + return upb_msgval_uint64(upb_fielddef_defaultuint64(f)); + default: + UPB_ASSERT(false); + return upb_msgval_msg(NULL); + } +} + + +/** upb_msglayout *************************************************************/ + +struct upb_msglayout { + struct upb_msglayout_msginit_v1 data; +}; + +static void upb_msglayout_free(upb_msglayout *l) { + upb_gfree(l->data.default_msg); + upb_gfree(l); +} + +static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { + size_t ret; + + l->data.size = align_up(l->data.size, size); + ret = l->data.size; + l->data.size += size; + return ret; +} + +static uint32_t upb_msglayout_offset(const upb_msglayout *l, + const upb_fielddef *f) { + return l->data.fields[upb_fielddef_index(f)].offset; +} + +static uint32_t upb_msglayout_hasbit(const upb_msglayout *l, + const upb_fielddef *f) { + return l->data.fields[upb_fielddef_index(f)].hasbit; +} + +static bool upb_msglayout_initdefault(upb_msglayout *l, const upb_msgdef *m) { + upb_msg_field_iter it; + + if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->data.size) { + /* Allocate default message and set default values in it. */ + l->data.default_msg = upb_gmalloc(l->data.size); + if (!l->data.default_msg) { + return false; + } + + memset(l->data.default_msg, 0, l->data.size); + + 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_containingoneof(f)) { + continue; + } + + /* TODO(haberman): handle strings. */ + if (!upb_fielddef_isstring(f) && + !upb_fielddef_issubmsg(f) && + !upb_fielddef_isseq(f)) { + upb_msg_set(l->data.default_msg, + upb_fielddef_index(f), + upb_msgval_fromdefault(f), + l); + } + } + } + + return true; +} + +static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { + upb_msg_field_iter it; + upb_msg_oneof_iter oit; + upb_msglayout *l; + size_t hasbit; + size_t submsg_count = 0; + const upb_msglayout_msginit_v1 **submsgs; + upb_msglayout_fieldinit_v1 *fields; + upb_msglayout_oneofinit_v1 *oneofs; + + 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++; + } + } + + l = upb_gmalloc(sizeof(*l)); + if (!l) return NULL; + + memset(l, 0, sizeof(*l)); + + fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields)); + submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs)); + oneofs = upb_gmalloc(upb_msgdef_numoneofs(m) * sizeof(*oneofs)); + + if ((!fields && upb_msgdef_numfields(m)) || + (!submsgs && submsg_count) || + (!oneofs && upb_msgdef_numoneofs(m))) { + /* OOM. */ + upb_gfree(l); + upb_gfree(fields); + upb_gfree(submsgs); + upb_gfree(oneofs); + return NULL; + } + + l->data.field_count = upb_msgdef_numfields(m); + l->data.oneof_count = upb_msgdef_numoneofs(m); + l->data.fields = fields; + l->data.submsgs = submsgs; + l->data.oneofs = oneofs; + l->data.is_proto2 = (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2); + + /* 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. */ + 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_fieldinit_v1 *field = &fields[upb_fielddef_index(f)]; + + field->number = upb_fielddef_number(f); + field->type = upb_fielddef_type(f); + field->label = upb_fielddef_label(f); + + if (upb_fielddef_containingoneof(f)) { + field->oneof_index = upb_oneofdef_index(upb_fielddef_containingoneof(f)); + } else { + field->oneof_index = UPB_NOT_IN_ONEOF; + } + + if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { + field->hasbit = hasbit++; + } + } + + /* Account for space used by hasbits. */ + l->data.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_containingoneof(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. */ + upb_msglayout_oneofinit_v1 *oneof = &oneofs[upb_oneofdef_index(o)]; + size_t field_size = 0; + + /* 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. */ + oneof->case_offset = upb_msglayout_place(l, case_size); + oneof->data_offset = upb_msglayout_place(l, field_size); + } + + /* Size of the entire structure should be a multiple of its greatest + * alignment. TODO: track overall alignment for real? */ + l->data.size = align_up(l->data.size, 8); + + if (upb_msglayout_initdefault(l, m)) { + return l; + } else { + upb_msglayout_free(l); + return NULL; + } +} + + +/** upb_msgfactory ************************************************************/ + +struct upb_msgfactory { + const upb_symtab *symtab; /* We own a ref. */ + upb_inttable layouts; + upb_inttable mergehandlers; +}; + +upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) { + upb_msgfactory *ret = upb_gmalloc(sizeof(*ret)); + + ret->symtab = symtab; + upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR); + upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR); + + return ret; +} + +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); + } + + upb_inttable_begin(&i, &f->mergehandlers); + for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { + const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i)); + upb_handlers_unref(h, f); + } + + upb_inttable_uninit(&f->layouts); + upb_inttable_uninit(&f->mergehandlers); + upb_gfree(f); +} + +const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) { + return f->symtab; +} + +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)); + + if (upb_inttable_lookupptr(&f->layouts, m, &v)) { + UPB_ASSERT(upb_value_getptr(v)); + return upb_value_getptr(v); + } else { + upb_msgfactory *mutable_f = (void*)f; + upb_msglayout *l = upb_msglayout_new(m); + upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l)); + UPB_ASSERT(l); + return l; + } +} + +/* Our handlers that we don't expose externally. */ + +void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) { + uint32_t ofs = (uintptr_t)hd; + upb_alloc *alloc = upb_msg_alloc(msg); + upb_msgval val; + UPB_UNUSED(size_hint); + + val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING)); + + upb_free(alloc, (void*)val.str.data); + val.str.data = NULL; + val.str.size = 0; + + upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING)); + return msg; +} + +size_t upb_msg_str(void *msg, const void *hd, const char *ptr, size_t size, + const upb_bufhandle *handle) { + uint32_t ofs = (uintptr_t)hd; + upb_alloc *alloc = upb_msg_alloc(msg); + upb_msgval val; + size_t newsize; + UPB_UNUSED(handle); + + val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING)); + + newsize = val.str.size + size; + val.str.data = upb_realloc(alloc, (void*)val.str.data, val.str.size, newsize); + + if (!val.str.data) { + return false; + } + + memcpy((char*)val.str.data + val.str.size, ptr, size); + val.str.size = newsize; + upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING)); + return size; +} + +static void callback(const void *closure, upb_handlers *h) { + upb_msgfactory *factory = (upb_msgfactory*)closure; + const upb_msgdef *md = upb_handlers_msgdef(h); + const upb_msglayout* layout = upb_msgfactory_getlayout(factory, md); + upb_msg_field_iter i; + UPB_UNUSED(factory); + + for(upb_msg_field_begin(&i, md); + !upb_msg_field_done(&i); + upb_msg_field_next(&i)) { + const upb_fielddef *f = upb_msg_iter_field(&i); + size_t offset = upb_msglayout_offset(layout, f); + upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; + upb_handlerattr_sethandlerdata(&attr, (void*)offset); + + if (upb_fielddef_isseq(f)) { + } else if (upb_fielddef_isstring(f)) { + upb_handlers_setstartstr(h, f, upb_msg_startstr, &attr); + upb_handlers_setstring(h, f, upb_msg_str, &attr); + } else { + upb_msg_setscalarhandler( + h, f, offset, upb_msglayout_hasbit(layout, f)); + } + } +} + +const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f, + const upb_msgdef *m) { + upb_msgfactory *mutable_f = (void*)f; + + /* TODO(haberman): properly cache these. */ + const upb_handlers *ret = upb_handlers_newfrozen(m, f, callback, f); + upb_inttable_push(&mutable_f->mergehandlers, upb_value_constptr(ret)); + + return ret; +} + +const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f, + const upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + return (const upb_visitorplan*)upb_msgfactory_getlayout(f, md); +} + + +/** upb_visitor ***************************************************************/ + +struct upb_visitor { + const upb_msglayout *layout; + upb_sink *sink; +}; + +static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) { + upb_selector_t ret; + bool ok = upb_handlers_getselector(f, type, &ret); + UPB_ASSERT(ok); + return ret; +} + +static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f, + const upb_msglayout *layout) { + int field_index = upb_fielddef_index(f); + if (upb_fielddef_isseq(f)) { + return upb_msgval_getarr(upb_msg_get(msg, field_index, layout)) != NULL; + } else if (upb_msgdef_syntax(upb_fielddef_containingtype(f)) == + UPB_SYNTAX_PROTO2) { + return upb_msg_has(msg, field_index, layout); + } else { + upb_msgval val = upb_msg_get(msg, field_index, layout); + switch (upb_fielddef_type(f)) { + case UPB_TYPE_FLOAT: + return upb_msgval_getfloat(val) != 0; + case UPB_TYPE_DOUBLE: + return upb_msgval_getdouble(val) != 0; + case UPB_TYPE_BOOL: + return upb_msgval_getbool(val); + case UPB_TYPE_ENUM: + case UPB_TYPE_INT32: + return upb_msgval_getint32(val) != 0; + case UPB_TYPE_UINT32: + return upb_msgval_getuint32(val) != 0; + case UPB_TYPE_INT64: + return upb_msgval_getint64(val) != 0; + case UPB_TYPE_UINT64: + return upb_msgval_getuint64(val) != 0; + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: + return upb_msgval_getstr(val).size > 0; + case UPB_TYPE_MESSAGE: + return upb_msgval_getmsg(val) != NULL; + } + UPB_UNREACHABLE(); + } +} + +static bool upb_visitor_visitmsg2(const upb_msg *msg, + const upb_msglayout *layout, upb_sink *sink, + int depth) { + const upb_msgdef *md = upb_handlers_msgdef(sink->handlers); + upb_msg_field_iter i; + upb_status status; + + upb_sink_startmsg(sink); + + /* Protect against cycles (possible because users may freely reassign message + * and repeated fields) by imposing a maximum recursion depth. */ + if (depth > ENCODE_MAX_NESTING) { + return false; + } -static uint8_t upb_msg_fieldsize(const upb_msglayout_field *field) { - if (field->label == UPB_LABEL_REPEATED) { - return sizeof(void*); - } else { - return upb_msgval_sizeof(upb_desctype_to_fieldtype[field->descriptortype]); + for (upb_msg_field_begin(&i, md); + !upb_msg_field_done(&i); + upb_msg_field_next(&i)) { + upb_fielddef *f = upb_msg_iter_field(&i); + upb_msgval val; + + if (!upb_visitor_hasfield(msg, f, layout)) { + continue; + } + + val = upb_msg_get(msg, upb_fielddef_index(f), layout); + + if (upb_fielddef_isseq(f)) { + const upb_array *arr = upb_msgval_getarr(val); + UPB_ASSERT(arr); + /* TODO: putary(ary, f, sink, depth);*/ + } else if (upb_fielddef_issubmsg(f)) { + const upb_map *map = upb_msgval_getmap(val); + UPB_ASSERT(map); + /* TODO: putmap(map, f, sink, depth);*/ + } else if (upb_fielddef_isstring(f)) { + /* TODO putstr(); */ + } else { + upb_selector_t sel = getsel2(f, upb_handlers_getprimitivehandlertype(f)); + UPB_ASSERT(upb_fielddef_isprimitive(f)); + + switch (upb_fielddef_type(f)) { + case UPB_TYPE_FLOAT: + CHECK_TRUE(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val))); + break; + case UPB_TYPE_DOUBLE: + CHECK_TRUE(upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val))); + break; + case UPB_TYPE_BOOL: + CHECK_TRUE(upb_sink_putbool(sink, sel, upb_msgval_getbool(val))); + break; + case UPB_TYPE_ENUM: + case UPB_TYPE_INT32: + CHECK_TRUE(upb_sink_putint32(sink, sel, upb_msgval_getint32(val))); + break; + case UPB_TYPE_UINT32: + CHECK_TRUE(upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val))); + break; + case UPB_TYPE_INT64: + CHECK_TRUE(upb_sink_putint64(sink, sel, upb_msgval_getint64(val))); + break; + case UPB_TYPE_UINT64: + CHECK_TRUE(upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val))); + break; + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: + case UPB_TYPE_MESSAGE: + UPB_UNREACHABLE(); + } + } } -} -/* TODO(haberman): this is broken right now because upb_msgval can contain - * a char* / size_t pair, which is too big for a upb_value. To fix this - * we'll probably need to dynamically allocate a upb_msgval and store a - * pointer to that in the tables for extensions/maps. */ -static upb_value upb_toval(upb_msgval val) { - upb_value ret; - UPB_UNUSED(val); - memset(&ret, 0, sizeof(upb_value)); /* XXX */ - return ret; + upb_sink_endmsg(sink, &status); + return true; } -static upb_msgval upb_msgval_fromval(upb_value val) { - upb_msgval ret; - UPB_UNUSED(val); - memset(&ret, 0, sizeof(upb_msgval)); /* XXX */ - return ret; +upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp, + upb_sink *output) { + upb_visitor *visitor = upb_env_malloc(e, sizeof(*visitor)); + visitor->layout = (const upb_msglayout*)vp; + visitor->sink = output; + return visitor; } -static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) { - switch (type) { - case UPB_TYPE_FLOAT: return UPB_CTYPE_FLOAT; - case UPB_TYPE_DOUBLE: return UPB_CTYPE_DOUBLE; - case UPB_TYPE_BOOL: return UPB_CTYPE_BOOL; - case UPB_TYPE_BYTES: - case UPB_TYPE_MESSAGE: - case UPB_TYPE_STRING: return UPB_CTYPE_CONSTPTR; - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: return UPB_CTYPE_INT32; - case UPB_TYPE_UINT32: return UPB_CTYPE_UINT32; - case UPB_TYPE_INT64: return UPB_CTYPE_INT64; - case UPB_TYPE_UINT64: return UPB_CTYPE_UINT64; - default: UPB_ASSERT(false); return 0; - } +bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) { + return upb_visitor_visitmsg2(msg, visitor->layout, visitor->sink, 0); } @@ -4802,12 +4680,8 @@ static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) { /* Used when a message is not extendable. */ typedef struct { - /* TODO(haberman): use pointer tagging so we we are slim when known unknown - * fields are not present. */ - upb_arena *arena; - char *unknown; - size_t unknown_len; - size_t unknown_size; + /* TODO(haberman): add unknown fields. */ + upb_alloc *alloc; } upb_msg_internal; /* Used when a message is extendable. */ @@ -4817,7 +4691,7 @@ typedef struct { } upb_msg_internal_withext; static int upb_msg_internalsize(const upb_msglayout *l) { - return sizeof(upb_msg_internal) - l->extendable * sizeof(void *); + return sizeof(upb_msg_internal) - l->data.extendable * sizeof(void*); } static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) { @@ -4830,112 +4704,123 @@ static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) { static upb_msg_internal_withext *upb_msg_getinternalwithext( upb_msg *msg, const upb_msglayout *l) { - UPB_ASSERT(l->extendable); + UPB_ASSERT(l->data.extendable); return VOIDPTR_AT(msg, -sizeof(upb_msg_internal_withext)); } -void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len) { - upb_msg_internal* in = upb_msg_getinternal(msg); - if (len > in->unknown_size - in->unknown_len) { - upb_alloc *alloc = upb_arena_alloc(in->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); - in->unknown_size = newsize; - } - memcpy(in->unknown + in->unknown_len, data, len); - in->unknown_len += len; -} - -const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { - const upb_msg_internal* in = upb_msg_getinternal_const(msg); - *len = in->unknown_len; - return in->unknown; -} - -static const upb_msglayout_field *upb_msg_checkfield(int field_index, - const upb_msglayout *l) { - UPB_ASSERT(field_index >= 0 && field_index < l->field_count); - return &l->fields[field_index]; +static const upb_msglayout_fieldinit_v1 *upb_msg_checkfield( + int field_index, const upb_msglayout *l) { + UPB_ASSERT(field_index >= 0 && field_index < l->data.field_count); + return &l->data.fields[field_index]; } -static bool upb_msg_inoneof(const upb_msglayout_field *field) { - return field->presence < 0; +static bool upb_msg_inoneof(const upb_msglayout_fieldinit_v1 *field) { + return field->oneof_index != UPB_NOT_IN_ONEOF; } static uint32_t *upb_msg_oneofcase(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); UPB_ASSERT(upb_msg_inoneof(field)); - return PTR_AT(msg, ~field->presence, uint32_t); + return PTR_AT(msg, l->data.oneofs[field->oneof_index].case_offset, uint32_t); } -static size_t upb_msg_sizeof(const upb_msglayout *l) { - return l->size + upb_msg_internalsize(l); +size_t upb_msg_sizeof(const upb_msglayout *l) { + return l->data.size + upb_msg_internalsize(l); } -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_internal *in; - upb_msg *msg; - - if (!mem) { - return NULL; - } - - msg = VOIDPTR_AT(mem, upb_msg_internalsize(l)); +upb_msg *upb_msg_init(void *mem, const upb_msglayout *l, upb_alloc *a) { + upb_msg *msg = VOIDPTR_AT(mem, upb_msg_internalsize(l)); /* Initialize normal members. */ - memset(msg, 0, l->size); + if (l->data.default_msg) { + memcpy(msg, l->data.default_msg, l->data.size); + } else { + memset(msg, 0, l->data.size); + } /* Initialize internal members. */ - in = upb_msg_getinternal(msg); - in->arena = a; - in->unknown = NULL; - in->unknown_len = 0; - in->unknown_size = 0; + upb_msg_getinternal(msg)->alloc = a; - if (l->extendable) { + if (l->data.extendable) { upb_msg_getinternalwithext(msg, l)->extdict = NULL; } return msg; } -upb_arena *upb_msg_arena(const upb_msg *msg) { - return upb_msg_getinternal_const(msg)->arena; +void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) { + if (l->data.extendable) { + upb_inttable *ext_dict = upb_msg_getinternalwithext(msg, l)->extdict; + if (ext_dict) { + upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg)); + upb_free(upb_msg_alloc(msg), ext_dict); + } + } + + return VOIDPTR_AT(msg, -upb_msg_internalsize(l)); +} + +upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) { + void *mem = upb_malloc(a, upb_msg_sizeof(l)); + return mem ? upb_msg_init(mem, l, a) : NULL; +} + +void upb_msg_free(upb_msg *msg, const upb_msglayout *l) { + upb_free(upb_msg_alloc(msg), upb_msg_uninit(msg, l)); +} + +upb_alloc *upb_msg_alloc(const upb_msg *msg) { + return upb_msg_getinternal_const(msg)->alloc; } bool upb_msg_has(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); - UPB_ASSERT(field->presence); + UPB_ASSERT(l->data.is_proto2); if (upb_msg_inoneof(field)) { /* Oneofs are set when the oneof number is set to this field. */ return *upb_msg_oneofcase(msg, field_index, l) == field->number; } else { /* Other fields are set when their hasbit is set. */ - uint32_t hasbit = field->presence; + uint32_t hasbit = l->data.fields[field_index].hasbit; return DEREF(msg, hasbit / 8, char) | (1 << (hasbit % 8)); } } upb_msgval upb_msg_get(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); int size = upb_msg_fieldsize(field); - return upb_msgval_read(msg, field->offset, size); + + if (upb_msg_inoneof(field)) { + if (*upb_msg_oneofcase(msg, field_index, l) == field->number) { + size_t ofs = l->data.oneofs[field->oneof_index].data_offset; + return upb_msgval_read(msg, ofs, size); + } else { + /* Return default. */ + return upb_msgval_read(l->data.default_msg, field->offset, size); + } + } else { + return upb_msgval_read(msg, field->offset, size); + } } void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val, const upb_msglayout *l) { - const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); int size = upb_msg_fieldsize(field); - upb_msgval_write(msg, field->offset, val, size); + + if (upb_msg_inoneof(field)) { + size_t ofs = l->data.oneofs[field->oneof_index].data_offset; + *upb_msg_oneofcase(msg, field_index, l) = field->number; + upb_msgval_write(msg, ofs, val, size); + } else { + upb_msgval_write(msg, field->offset, val, size); + } } @@ -4943,24 +4828,39 @@ void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val, #define DEREF_ARR(arr, i, type) ((type*)arr->data)[i] -upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a) { - upb_alloc *alloc = upb_arena_alloc(a); - upb_array *ret = upb_malloc(alloc, sizeof(upb_array)); +size_t upb_array_sizeof(upb_fieldtype_t type) { + UPB_UNUSED(type); + return sizeof(upb_array); +} + +void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *alloc) { + arr->type = type; + arr->data = NULL; + arr->len = 0; + arr->size = 0; + arr->element_size = upb_msgval_sizeof(type); + arr->alloc = alloc; +} - if (!ret) { - return NULL; - } +void upb_array_uninit(upb_array *arr) { + upb_free(arr->alloc, arr->data); +} + +upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a) { + upb_array *ret = upb_malloc(a, upb_array_sizeof(type)); - ret->type = type; - ret->data = NULL; - ret->len = 0; - ret->size = 0; - ret->element_size = upb_msgval_sizeof(type); - ret->arena = a; + if (ret) { + upb_array_init(ret, type, a); + } return ret; } +void upb_array_free(upb_array *arr) { + upb_array_uninit(arr); + upb_free(arr->alloc, arr); +} + size_t upb_array_size(const upb_array *arr) { return arr->len; } @@ -4985,9 +4885,8 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val) { size_t new_size = UPB_MAX(arr->size * 2, 8); size_t new_bytes = new_size * arr->element_size; size_t old_bytes = arr->size * arr->element_size; - upb_alloc *alloc = upb_arena_alloc(arr->arena); upb_msgval *new_data = - upb_realloc(alloc, arr->data, old_bytes, new_bytes); + upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes); if (!new_data) { return false; @@ -5013,7 +4912,7 @@ struct upb_map { /* We may want to optimize this to use inttable where possible, for greater * efficiency and lower memory footprint. */ upb_strtable strtab; - upb_arena *arena; + upb_alloc *alloc; }; static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key, @@ -5064,28 +4963,52 @@ static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key, UPB_UNREACHABLE(); } -upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_arena *a) { +size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype) { + /* Size does not currently depend on key/value type. */ + UPB_UNUSED(ktype); + UPB_UNUSED(vtype); + return sizeof(upb_map); +} + +bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype, + upb_alloc *a) { upb_ctype_t vtabtype = upb_fieldtotabtype(vtype); - upb_alloc *alloc = upb_arena_alloc(a); - upb_map *map = upb_malloc(alloc, sizeof(upb_map)); + UPB_ASSERT(upb_fieldtype_mapkeyok(ktype)); + map->key_type = ktype; + map->val_type = vtype; + map->alloc = a; + + if (!upb_strtable_init2(&map->strtab, vtabtype, a)) { + return false; + } + + return true; +} + +void upb_map_uninit(upb_map *map) { + upb_strtable_uninit2(&map->strtab, map->alloc); +} + +upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, + upb_alloc *a) { + upb_map *map = upb_malloc(a, upb_map_sizeof(ktype, vtype)); if (!map) { return NULL; } - UPB_ASSERT(upb_fieldtype_mapkeyok(ktype)); - map->key_type = ktype; - map->val_type = vtype; - map->arena = a; - - if (!upb_strtable_init2(&map->strtab, vtabtype, alloc)) { + if (!upb_map_init(map, ktype, vtype, a)) { return NULL; } return map; } +void upb_map_free(upb_map *map) { + upb_map_uninit(map); + upb_free(map->alloc, map); +} + size_t upb_map_size(const upb_map *map) { return upb_strtable_count(&map->strtab); } @@ -5119,7 +5042,7 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, size_t key_len; upb_value tabval = upb_toval(val); upb_value removedtabval; - upb_alloc *a = upb_arena_alloc(map->arena); + upb_alloc *a = map->alloc; upb_map_tokey(map->key_type, &key, &key_str, &key_len); @@ -5135,7 +5058,7 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, bool upb_map_del(upb_map *map, upb_msgval key) { const char *key_str; size_t key_len; - upb_alloc *a = upb_arena_alloc(map->arena); + upb_alloc *a = map->alloc; upb_map_tokey(map->key_type, &key, &key_str, &key_len); return upb_strtable_remove3(&map->strtab, key_str, key_len, NULL, a); @@ -5149,307 +5072,149 @@ struct upb_mapiter { upb_fieldtype_t key_type; }; -size_t upb_mapiter_sizeof() { - return sizeof(upb_mapiter); -} - -void upb_mapiter_begin(upb_mapiter *i, const upb_map *map) { - upb_strtable_begin(&i->iter, &map->strtab); - i->key_type = map->key_type; -} - -upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a) { - upb_mapiter *ret = upb_malloc(a, upb_mapiter_sizeof()); - - if (!ret) { - return NULL; - } - - upb_mapiter_begin(ret, t); - return ret; -} - -void upb_mapiter_free(upb_mapiter *i, upb_alloc *a) { - upb_free(a, i); -} - -void upb_mapiter_next(upb_mapiter *i) { - upb_strtable_next(&i->iter); -} - -bool upb_mapiter_done(const upb_mapiter *i) { - return upb_strtable_done(&i->iter); -} - -upb_msgval upb_mapiter_key(const upb_mapiter *i) { - return upb_map_fromkey(i->key_type, upb_strtable_iter_key(&i->iter), - upb_strtable_iter_keylength(&i->iter)); -} - -upb_msgval upb_mapiter_value(const upb_mapiter *i) { - return upb_msgval_fromval(upb_strtable_iter_value(&i->iter)); -} - -void upb_mapiter_setdone(upb_mapiter *i) { - upb_strtable_iter_setdone(&i->iter); -} - -bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) { - return upb_strtable_iter_isequal(&i1->iter, &i2->iter); -} - - -static bool is_power_of_two(size_t val) { - return (val & (val - 1)) == 0; -} - -/* 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 size_t div_round_up(size_t n, size_t d) { - return (n + d - 1) / d; -} - -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_stringview); - } - UPB_UNREACHABLE(); -} - -static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { - if (upb_fielddef_isseq(f)) { - return sizeof(void*); - } else { - return upb_msgval_sizeof2(upb_fielddef_type(f)); - } -} - - -/** 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; -} - -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++; - } - } - - 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)]; +size_t upb_mapiter_sizeof() { + return sizeof(upb_mapiter); +} - field->number = upb_fielddef_number(f); - field->descriptortype = upb_fielddef_descriptortype(f); - field->label = upb_fielddef_label(f); +void upb_mapiter_begin(upb_mapiter *i, const upb_map *map) { + upb_strtable_begin(&i->iter, &map->strtab); + i->key_type = map->key_type; +} - 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; - } +upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a) { + upb_mapiter *ret = upb_malloc(a, upb_mapiter_sizeof()); - if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { - field->presence = (hasbit++); - } else { - field->presence = 0; - } + if (!ret) { + return NULL; } - /* Account for space used by hasbits. */ - l->size = div_round_up(hasbit, 8); + upb_mapiter_begin(ret, t); + return ret; +} - /* 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); +void upb_mapiter_free(upb_mapiter *i, upb_alloc *a) { + upb_free(a, i); +} - if (upb_fielddef_containingoneof(f)) { - /* Oneofs are handled separately below. */ - continue; - } +void upb_mapiter_next(upb_mapiter *i) { + upb_strtable_next(&i->iter); +} - fields[index].offset = upb_msglayout_place(l, field_size); - } +bool upb_mapiter_done(const upb_mapiter *i) { + return upb_strtable_done(&i->iter); +} - /* 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; +upb_msgval upb_mapiter_key(const upb_mapiter *i) { + return upb_map_fromkey(i->key_type, upb_strtable_iter_key(&i->iter), + upb_strtable_iter_keylength(&i->iter)); +} - 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_msgval upb_mapiter_value(const upb_mapiter *i) { + return upb_msgval_fromval(upb_strtable_iter_value(&i->iter)); +} - /* 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)); - } +void upb_mapiter_setdone(upb_mapiter *i) { + upb_strtable_iter_setdone(&i->iter); +} - /* Align and allocate case offset. */ - case_offset = upb_msglayout_place(l, case_size); - data_offset = upb_msglayout_place(l, field_size); +bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) { + return upb_strtable_iter_isequal(&i1->iter, &i2->iter); +} - 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 = align_up(l->size, 8); +/** Handlers for upb_msg ******************************************************/ - return true; -} +typedef struct { + size_t offset; + int32_t hasbit; +} upb_msg_handlerdata; +/* Fallback implementation if the handler is not specialized by the producer. */ +#define MSG_WRITER(type, ctype) \ + bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \ + uint8_t *m = c; \ + const upb_msg_handlerdata *d = hd; \ + if (d->hasbit > 0) \ + *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ + *(ctype*)&m[d->offset] = val; \ + return true; \ + } \ -/** upb_msgfactory ************************************************************/ +MSG_WRITER(double, double) +MSG_WRITER(float, float) +MSG_WRITER(int32, int32_t) +MSG_WRITER(int64, int64_t) +MSG_WRITER(uint32, uint32_t) +MSG_WRITER(uint64, uint64_t) +MSG_WRITER(bool, bool) -struct upb_msgfactory { - const upb_symtab *symtab; /* We own a ref. */ - upb_inttable layouts; - upb_inttable mergehandlers; -}; +bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f, + size_t offset, int32_t hasbit) { + upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; + bool ok; -upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) { - upb_msgfactory *ret = upb_gmalloc(sizeof(*ret)); + upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d)); + if (!d) return false; + d->offset = offset; + d->hasbit = hasbit; - ret->symtab = symtab; - upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR); - upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR); + upb_handlerattr_sethandlerdata(&attr, d); + upb_handlerattr_setalwaysok(&attr, true); + upb_handlers_addcleanup(h, d, upb_gfree); - return ret; -} +#define TYPE(u, l) \ + case UPB_TYPE_##u: \ + ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break; -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); - } + ok = false; - upb_inttable_begin(&i, &f->mergehandlers); - for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { - const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i)); - upb_handlers_unref(h, f); + switch (upb_fielddef_type(f)) { + TYPE(INT64, int64); + TYPE(INT32, int32); + TYPE(ENUM, int32); + TYPE(UINT64, uint64); + TYPE(UINT32, uint32); + TYPE(DOUBLE, double); + TYPE(FLOAT, float); + TYPE(BOOL, bool); + default: UPB_ASSERT(false); break; } +#undef TYPE - upb_inttable_uninit(&f->layouts); - upb_inttable_uninit(&f->mergehandlers); - upb_gfree(f); -} - -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) { - return f->symtab; + upb_handlerattr_uninit(&attr); + return ok; } -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)); +bool upb_msg_getscalarhandlerdata(const upb_handlers *h, + upb_selector_t s, + upb_fieldtype_t *type, + size_t *offset, + int32_t *hasbit) { + const upb_msg_handlerdata *d; + upb_func *f = upb_handlers_gethandler(h, s); - if (upb_inttable_lookupptr(&f->layouts, m, &v)) { - UPB_ASSERT(upb_value_getptr(v)); - return upb_value_getptr(v); + if ((upb_int64_handlerfunc*)f == upb_msg_setint64) { + *type = UPB_TYPE_INT64; + } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) { + *type = UPB_TYPE_INT32; + } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) { + *type = UPB_TYPE_UINT64; + } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) { + *type = UPB_TYPE_UINT32; + } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) { + *type = UPB_TYPE_DOUBLE; + } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) { + *type = UPB_TYPE_FLOAT; + } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) { + *type = UPB_TYPE_BOOL; } 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; + return false; } + + d = upb_handlers_gethandlerdata(h, s); + *offset = d->offset; + *hasbit = d->hasbit; + return true; } /* ** upb::RefCounted Implementation @@ -6660,10 +6425,9 @@ static size_t begin(const upb_table *t) { /* A simple "subclass" of upb_table that only adds a hash function for strings. */ static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) { - uint32_t len = (uint32_t) k2.str.len; char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1); if (str == NULL) return 0; - memcpy(str, &len, sizeof(uint32_t)); + memcpy(str, &k2.str.len, sizeof(uint32_t)); memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); return (uintptr_t)str; } @@ -7642,28 +7406,28 @@ static upb_inttable reftables[268]; #endif static const upb_msgdef msgs[22] = { - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[0], &reftables[1]), - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[2], &reftables[3]), - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[4], &reftables[5]), - UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[6], &reftables[7]), - UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[8], &reftables[9]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[10], &reftables[11]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[12], &reftables[13]), - UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[14], &reftables[15]), - UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[16], &reftables[17]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[18], &reftables[19]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[20], &reftables[21]), - UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[22], &reftables[23]), - UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[24], &reftables[25]), - UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[26], &reftables[27]), - UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[28], &reftables[29]), - UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[30], &reftables[31]), - UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[32], &reftables[33]), - UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[34], &reftables[35]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[36], &reftables[37]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[38], &reftables[39]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[40], &reftables[41]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[42], &reftables[43]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftables[1]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2], &reftables[3]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4], &reftables[5]), + UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftables[7]), + UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &reftables[9]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &reftables[11]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]), + UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], &reftables[15]), + UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], &reftables[17]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &reftables[19]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftables[21]), + UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]), + UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]), + UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &reftables[27]), + UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]), + UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &reftables[31]), + UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], &reftables[33]), + UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables[37]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &reftables[41]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]), }; static const upb_fielddef fields[107] = { @@ -9231,7 +8995,6 @@ static size_t msg_name(void *closure, const void *hd, const char *buf, upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); upb_descreader_setscopename(r, name); /* Passes ownership of name. */ - return n; } @@ -12546,7 +12309,7 @@ done: return r; } -//#line 1 "upb/json/parser.rl" +#line 1 "upb/json/parser.rl" /* ** upb::json::Parser (upb_json_parser) ** @@ -12572,66 +12335,12 @@ done: #include #include #include -#include #include #include -/* Need to define __USE_XOPEN before including time.h to make strptime work. */ -#ifndef __USE_XOPEN -#define __USE_XOPEN -#endif -#include - #define UPB_JSON_MAX_DEPTH 64 -/* Type of value message */ -enum { - VALUE_NULLVALUE = 0, - VALUE_NUMBERVALUE = 1, - VALUE_STRINGVALUE = 2, - VALUE_BOOLVALUE = 3, - VALUE_STRUCTVALUE = 4, - VALUE_LISTVALUE = 5 -}; - -/* Forward declare */ -static bool is_top_level(upb_json_parser *p); -static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type); -static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type); - -static bool is_number_wrapper_object(upb_json_parser *p); -static bool does_number_wrapper_start(upb_json_parser *p); -static bool does_number_wrapper_end(upb_json_parser *p); - -static bool is_string_wrapper_object(upb_json_parser *p); -static bool does_string_wrapper_start(upb_json_parser *p); -static bool does_string_wrapper_end(upb_json_parser *p); - -static void start_wrapper_object(upb_json_parser *p); -static void end_wrapper_object(upb_json_parser *p); - -static void start_value_object(upb_json_parser *p, int value_type); -static void end_value_object(upb_json_parser *p); - -static void start_listvalue_object(upb_json_parser *p); -static void end_listvalue_object(upb_json_parser *p); - -static void start_structvalue_object(upb_json_parser *p); -static void end_structvalue_object(upb_json_parser *p); - -static void start_object(upb_json_parser *p); -static void end_object(upb_json_parser *p); - -static bool start_subobject(upb_json_parser *p); -static void end_subobject(upb_json_parser *p); - -static void start_member(upb_json_parser *p); -static void end_member(upb_json_parser *p); -static bool end_membername(upb_json_parser *p); - -static const char eof_ch = 'e'; - typedef struct { upb_sink sink; @@ -12659,9 +12368,6 @@ typedef struct { * because |f| is the field in the *current* message (i.e., the map-entry * message itself), not the parent's field that leads to this map. */ const upb_fielddef *mapfield; - - /* True if the field to be parsed is unknown. */ - bool is_unknown_field; } upb_jsonparser_frame; struct upb_json_parser { @@ -12699,13 +12405,6 @@ struct upb_json_parser { /* Intermediate result of parsing a unicode escape sequence. */ uint32_t digit; - - /* Whether to proceed if unknown field is met. */ - bool ignore_json_unknown; - - /* Cache for parsing timestamp due to base and zone are handled in different - * handlers. */ - struct tm tm; }; struct upb_json_parsermethod { @@ -13211,72 +12910,22 @@ static void start_text(upb_json_parser *p, const char *ptr) { } static bool end_text(upb_json_parser *p, const char *ptr) { - return capture_end(p, ptr); -} - -static bool start_number(upb_json_parser *p, const char *ptr) { - if (is_top_level(p)) { - if (is_number_wrapper_object(p)) { - start_wrapper_object(p); - } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - start_value_object(p, VALUE_NUMBERVALUE); - } else { - return false; - } - } else if (does_number_wrapper_start(p)) { - if (!start_subobject(p)) { - return false; - } - start_wrapper_object(p); - } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { - if (!start_subobject(p)) { - return false; - } - start_value_object(p, VALUE_NUMBERVALUE); - } - - multipart_startaccum(p); - capture_begin(p, ptr); - return true; -} - -static bool parse_number(upb_json_parser *p, bool is_quoted); - -static bool end_number_nontop(upb_json_parser *p, const char *ptr) { - if (!capture_end(p, ptr)) { - return false; - } - - if (p->top->f == NULL) { - multipart_end(p); - return true; - } + return capture_end(p, ptr); +} - return parse_number(p, false); +static void start_number(upb_json_parser *p, const char *ptr) { + multipart_startaccum(p); + capture_begin(p, ptr); } +static bool parse_number(upb_json_parser *p, bool is_quoted); + static bool end_number(upb_json_parser *p, const char *ptr) { - if (!end_number_nontop(p, ptr)) { + if (!capture_end(p, ptr)) { return false; } - if (does_number_wrapper_end(p)) { - end_wrapper_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - return true; - } - - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - end_value_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - return true; - } - - return true; + return parse_number(p, false); } /* |buf| is NULL-terminated. |buf| itself will never include quotes; @@ -13428,10 +13077,6 @@ static bool parse_number(upb_json_parser *p, bool is_quoted) { static bool parser_putbool(upb_json_parser *p, bool val) { bool ok; - if (p->top->f == NULL) { - return true; - } - if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) { upb_status_seterrf(&p->status, "Boolean value specified for non-bool field: %s", @@ -13446,120 +13091,8 @@ static bool parser_putbool(upb_json_parser *p, bool val) { return true; } -static bool end_bool(upb_json_parser *p, bool val) { - if (is_top_level(p)) { - if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) { - start_wrapper_object(p); - } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - start_value_object(p, VALUE_BOOLVALUE); - } else { - return false; - } - } else if (is_wellknown_field(p, UPB_WELLKNOWN_BOOLVALUE)) { - if (!start_subobject(p)) { - return false; - } - start_wrapper_object(p); - } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { - if (!start_subobject(p)) { - return false; - } - start_value_object(p, VALUE_BOOLVALUE); - } - - if (p->top->is_unknown_field) { - return true; - } - - if (!parser_putbool(p, val)) { - return false; - } - - if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) { - end_wrapper_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - return true; - } - - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - end_value_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - return true; - } - - return true; -} - -static bool end_null(upb_json_parser *p) { - const char *zero_ptr = "0"; - - if (is_top_level(p)) { - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - start_value_object(p, VALUE_NULLVALUE); - } else { - return true; - } - } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { - if (!start_subobject(p)) { - return false; - } - start_value_object(p, VALUE_NULLVALUE); - } else { - return true; - } - - /* Fill null_value field. */ - multipart_startaccum(p); - capture_begin(p, zero_ptr); - capture_end(p, zero_ptr + 1); - parse_number(p, false); - - end_value_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - - return true; -} - static bool start_stringval(upb_json_parser *p) { - if (is_top_level(p)) { - if (is_string_wrapper_object(p)) { - start_wrapper_object(p); - } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || - is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { - start_object(p); - } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - start_value_object(p, VALUE_STRINGVALUE); - } else { - return false; - } - } else if (does_string_wrapper_start(p)) { - if (!start_subobject(p)) { - return false; - } - start_wrapper_object(p); - } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) || - is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) { - if (!start_subobject(p)) { - return false; - } - start_object(p); - } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { - if (!start_subobject(p)) { - return false; - } - start_value_object(p, VALUE_STRINGVALUE); - } - - if (p->top->f == NULL) { - multipart_startaccum(p); - return true; - } + UPB_ASSERT(p->top->f); if (upb_fielddef_isstring(p->top->f)) { upb_jsonparser_frame *inner; @@ -13577,7 +13110,6 @@ static bool start_stringval(upb_json_parser *p) { inner->name_table = NULL; inner->is_map = false; inner->is_mapentry = false; - inner->is_unknown_field = false; p->top = inner; if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) { @@ -13594,376 +13126,80 @@ 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 accmulate so we can convert - * them all at once at the end. */ - multipart_startaccum(p); - return true; - } else { - upb_status_seterrf(&p->status, - "String specified for bool or submessage field: %s", - upb_fielddef_name(p->top->f)); - upb_env_reporterror(p->env, &p->status); - return false; - } -} - -static bool end_stringval_nontop(upb_json_parser *p) { - bool ok = true; - - if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || - is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { - multipart_end(p); - return true; - } - - if (p->top->f == NULL) { - multipart_end(p); - return true; - } - - switch (upb_fielddef_type(p->top->f)) { - case UPB_TYPE_BYTES: - if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), - p->accumulated, p->accumulated_len)) { - return false; - } - /* Fall through. */ - - case UPB_TYPE_STRING: { - upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); - p->top--; - upb_sink_endstr(&p->top->sink, sel); - break; - } - - case UPB_TYPE_ENUM: { - /* Resolve enum symbolic name to integer value. */ - const upb_enumdef *enumdef = - (const upb_enumdef*)upb_fielddef_subdef(p->top->f); - - size_t len; - const char *buf = accumulate_getptr(p, &len); - - int32_t int_val = 0; - ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); - - if (ok) { - 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); - upb_env_reporterror(p->env, &p->status); - } - - break; - } - - case UPB_TYPE_INT32: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT32: - case UPB_TYPE_UINT64: - case UPB_TYPE_DOUBLE: - case UPB_TYPE_FLOAT: - ok = parse_number(p, true); - break; - - default: - UPB_ASSERT(false); - upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); - upb_env_reporterror(p->env, &p->status); - ok = false; - break; - } - - multipart_end(p); - - return ok; -} - -static bool end_stringval(upb_json_parser *p) { - if (!end_stringval_nontop(p)) { - return false; - } - - if (does_string_wrapper_end(p)) { - end_wrapper_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - return true; - } - - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - end_value_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - return true; - } - - if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || - is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { - end_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - return true; - } - - return true; -} - -static void start_duration_base(upb_json_parser *p, const char *ptr) { - capture_begin(p, ptr); -} - -static bool end_duration_base(upb_json_parser *p, const char *ptr) { - size_t len; - const char *buf; - char seconds_buf[14]; - char nanos_buf[12]; - char *end; - int64_t seconds = 0; - int32_t nanos = 0; - double val = 0.0; - const char *seconds_membername = "seconds"; - const char *nanos_membername = "nanos"; - size_t fraction_start; - - if (!capture_end(p, ptr)) { - return false; - } - - buf = accumulate_getptr(p, &len); - - memset(seconds_buf, 0, 14); - memset(nanos_buf, 0, 12); - - /* Find out base end. The maximus duration is 315576000000, which cannot be - * represented by double without losing precision. Thus, we need to handle - * fraction and base separately. */ - for (fraction_start = 0; fraction_start < len && buf[fraction_start] != '.'; - fraction_start++); - - /* Parse base */ - memcpy(seconds_buf, buf, fraction_start); - seconds = strtol(seconds_buf, &end, 10); - if (errno == ERANGE || end != seconds_buf + fraction_start) { - upb_status_seterrf(&p->status, "error parsing duration: %s", - seconds_buf); - upb_env_reporterror(p->env, &p->status); - return false; - } - - if (seconds > 315576000000) { - upb_status_seterrf(&p->status, "error parsing duration: " - "maximum acceptable value is " - "315576000000"); - upb_env_reporterror(p->env, &p->status); - return false; - } - - if (seconds < -315576000000) { - upb_status_seterrf(&p->status, "error parsing duration: " - "minimum acceptable value is " - "-315576000000"); - upb_env_reporterror(p->env, &p->status); - return false; - } - - /* Parse fraction */ - nanos_buf[0] = '0'; - memcpy(nanos_buf + 1, buf + fraction_start, len - fraction_start); - val = strtod(nanos_buf, &end); - if (errno == ERANGE || end != nanos_buf + len - fraction_start + 1) { - upb_status_seterrf(&p->status, "error parsing duration: %s", - nanos_buf); - upb_env_reporterror(p->env, &p->status); - return false; - } - - nanos = val * 1000000000; - if (seconds < 0) nanos = -nanos; - - /* Clean up buffer */ - multipart_end(p); - - /* Set seconds */ - start_member(p); - capture_begin(p, seconds_membername); - capture_end(p, seconds_membername + 7); - end_membername(p); - upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds); - end_member(p); - - /* Set nanos */ - start_member(p); - capture_begin(p, nanos_membername); - capture_end(p, nanos_membername + 5); - end_membername(p); - upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos); - end_member(p); - - /* Continue previous environment */ - multipart_startaccum(p); - - return true; -} - -static void start_timestamp_base(upb_json_parser *p, const char *ptr) { - capture_begin(p, ptr); -} - -#define UPB_TIMESTAMP_BASE_SIZE 19 - -static bool end_timestamp_base(upb_json_parser *p, const char *ptr) { - size_t len; - const char *buf; - /* 3 for GMT and 1 for ending 0 */ - char timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 4]; - - if (!capture_end(p, ptr)) { - return false; - } - - buf = accumulate_getptr(p, &len); - UPB_ASSERT(len == UPB_TIMESTAMP_BASE_SIZE); - memcpy(timestamp_buf, buf, UPB_TIMESTAMP_BASE_SIZE); - memcpy(timestamp_buf + UPB_TIMESTAMP_BASE_SIZE, "GMT", 3); - timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 3] = 0; - - /* Parse seconds */ - if (strptime(timestamp_buf, "%FT%H:%M:%S%Z", &p->tm) == NULL) { - upb_status_seterrf(&p->status, "error parsing timestamp: %s", buf); - upb_env_reporterror(p->env, &p->status); - return false; - } - - /* Clean up buffer */ - multipart_end(p); - multipart_startaccum(p); - - return true; -} - -static void start_timestamp_fraction(upb_json_parser *p, const char *ptr) { - capture_begin(p, ptr); -} - -static bool end_timestamp_fraction(upb_json_parser *p, const char *ptr) { - size_t len; - const char *buf; - char nanos_buf[12]; - char *end; - double val = 0.0; - int32_t nanos; - const char *nanos_membername = "nanos"; - - memset(nanos_buf, 0, 12); - - if (!capture_end(p, ptr)) { - return false; - } - - buf = accumulate_getptr(p, &len); - - if (len > 10) { + /* No need to push a frame -- numeric values in quotes remain in the + * current parser frame. These values must accmulate so we can convert + * them all at once at the end. */ + multipart_startaccum(p); + return true; + } else { upb_status_seterrf(&p->status, - "error parsing timestamp: at most 9-digit fraction."); - upb_env_reporterror(p->env, &p->status); - return false; - } - - /* Parse nanos */ - nanos_buf[0] = '0'; - memcpy(nanos_buf + 1, buf, len); - val = strtod(nanos_buf, &end); - - if (errno == ERANGE || end != nanos_buf + len + 1) { - upb_status_seterrf(&p->status, "error parsing timestamp nanos: %s", - nanos_buf); + "String specified for bool or submessage field: %s", + upb_fielddef_name(p->top->f)); upb_env_reporterror(p->env, &p->status); return false; } +} - nanos = val * 1000000000; - - /* Clean up previous environment */ - multipart_end(p); - - /* Set nanos */ - start_member(p); - capture_begin(p, nanos_membername); - capture_end(p, nanos_membername + 5); - end_membername(p); - upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos); - end_member(p); - - /* Continue previous environment */ - multipart_startaccum(p); +static bool end_stringval(upb_json_parser *p) { + bool ok = true; - return true; -} + switch (upb_fielddef_type(p->top->f)) { + case UPB_TYPE_BYTES: + if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), + p->accumulated, p->accumulated_len)) { + return false; + } + /* Fall through. */ -static void start_timestamp_zone(upb_json_parser *p, const char *ptr) { - capture_begin(p, ptr); -} + case UPB_TYPE_STRING: { + upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + p->top--; + upb_sink_endstr(&p->top->sink, sel); + break; + } -static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) { - size_t len; - const char *buf; - int hours; - int64_t seconds; - const char *seconds_membername = "seconds"; + case UPB_TYPE_ENUM: { + /* Resolve enum symbolic name to integer value. */ + const upb_enumdef *enumdef = + (const upb_enumdef*)upb_fielddef_subdef(p->top->f); - if (!capture_end(p, ptr)) { - return false; - } + size_t len; + const char *buf = accumulate_getptr(p, &len); - buf = accumulate_getptr(p, &len); + int32_t int_val = 0; + ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); - if (buf[0] != 'Z') { - if (sscanf(buf + 1, "%2d:00", &hours) != 1) { - upb_status_seterrf(&p->status, "error parsing timestamp offset"); - upb_env_reporterror(p->env, &p->status); - return false; - } + if (ok) { + 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); + upb_env_reporterror(p->env, &p->status); + } - if (buf[0] == '+') { - hours = -hours; + break; } - p->tm.tm_hour += hours; - } - - /* Normalize tm */ - seconds = mktime(&p->tm); + case UPB_TYPE_INT32: + case UPB_TYPE_INT64: + case UPB_TYPE_UINT32: + case UPB_TYPE_UINT64: + case UPB_TYPE_DOUBLE: + case UPB_TYPE_FLOAT: + ok = parse_number(p, true); + break; - /* Check timestamp boundary */ - if (seconds < -62135596800) { - upb_status_seterrf(&p->status, "error parsing timestamp: " - "minimum acceptable value is " - "0001-01-01T00:00:00Z"); - upb_env_reporterror(p->env, &p->status); - return false; + default: + UPB_ASSERT(false); + upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); + upb_env_reporterror(p->env, &p->status); + ok = false; + break; } - /* Clean up previous environment */ multipart_end(p); - /* Set seconds */ - start_member(p); - capture_begin(p, seconds_membername); - capture_end(p, seconds_membername + 7); - end_membername(p); - upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds); - end_member(p); - - /* Continue previous environment */ - multipart_startaccum(p); - - return true; + return ok; } static void start_member(upb_json_parser *p) { @@ -14069,7 +13305,6 @@ static bool handle_mapentry(upb_json_parser *p) { inner->name_table = NULL; inner->mapfield = mapfield; inner->is_map = false; - inner->is_unknown_field = false; /* Don't set this to true *yet* -- we reuse parsing handlers below to push * the key field value to the sink, and these handlers will pop the frame @@ -14099,12 +13334,6 @@ static bool handle_mapentry(upb_json_parser *p) { static bool end_membername(upb_json_parser *p) { UPB_ASSERT(!p->top->f); - if (!p->top->m) { - p->top->is_unknown_field = true; - multipart_end(p); - return true; - } - if (p->top->is_map) { return handle_mapentry(p); } else { @@ -14116,12 +13345,10 @@ static bool end_membername(upb_json_parser *p) { p->top->f = upb_value_getconstptr(v); multipart_end(p); - return true; - } else if (p->ignore_json_unknown) { - p->top->is_unknown_field = true; - multipart_end(p); return true; } else { + /* TODO(haberman): Ignore unknown fields if requested/configured to do + * so. */ upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); upb_env_reporterror(p->env, &p->status); return false; @@ -14150,23 +13377,10 @@ static void end_member(upb_json_parser *p) { } p->top->f = NULL; - p->top->is_unknown_field = false; } static bool start_subobject(upb_json_parser *p) { - if (p->top->is_unknown_field) { - upb_jsonparser_frame *inner; - if (!check_stack(p)) return false; - - inner = p->top + 1; - inner->m = NULL; - inner->f = NULL; - inner->is_map = false; - inner->is_mapentry = false; - inner->is_unknown_field = false; - p->top = inner; - return true; - } + UPB_ASSERT(p->top->f); if (upb_fielddef_ismap(p->top->f)) { upb_jsonparser_frame *inner; @@ -14185,7 +13399,6 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = true; inner->is_mapentry = false; - inner->is_unknown_field = false; p->top = inner; return true; @@ -14206,7 +13419,6 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = false; inner->is_mapentry = false; - inner->is_unknown_field = false; p->top = inner; return true; @@ -14219,35 +13431,7 @@ static bool start_subobject(upb_json_parser *p) { } } -static bool start_subobject_full(upb_json_parser *p) { - if (is_top_level(p)) { - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - start_value_object(p, VALUE_STRUCTVALUE); - if (!start_subobject(p)) return false; - start_structvalue_object(p); - } else if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) { - start_structvalue_object(p); - } else { - return true; - } - } else if (is_wellknown_field(p, UPB_WELLKNOWN_STRUCT)) { - if (!start_subobject(p)) return false; - start_structvalue_object(p); - } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { - if (!start_subobject(p)) return false; - start_value_object(p, VALUE_STRUCTVALUE); - if (!start_subobject(p)) return false; - start_structvalue_object(p); - } - - return start_subobject(p); -} - static void end_subobject(upb_json_parser *p) { - if (is_top_level(p)) { - return; - } - if (p->top->is_map) { upb_selector_t sel; p->top--; @@ -14255,30 +13439,9 @@ static void end_subobject(upb_json_parser *p) { upb_sink_endseq(&p->top->sink, sel); } else { upb_selector_t sel; - bool is_unknown = p->top->m == NULL; p->top--; - if (!is_unknown) { - sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); - upb_sink_endsubmsg(&p->top->sink, sel); - } - } -} - -static void end_subobject_full(upb_json_parser *p) { - end_subobject(p); - - if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) { - end_structvalue_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - } - - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - end_value_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); + upb_sink_endsubmsg(&p->top->sink, sel); } } @@ -14286,38 +13449,7 @@ static bool start_array(upb_json_parser *p) { upb_jsonparser_frame *inner; upb_selector_t sel; - if (is_top_level(p)) { - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - start_value_object(p, VALUE_LISTVALUE); - if (!start_subobject(p)) return false; - start_listvalue_object(p); - } else if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) { - start_listvalue_object(p); - } else { - return false; - } - } else if (is_wellknown_field(p, UPB_WELLKNOWN_LISTVALUE)) { - if (!start_subobject(p)) return false; - start_listvalue_object(p); - } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { - if (!start_subobject(p)) return false; - start_value_object(p, VALUE_LISTVALUE); - if (!start_subobject(p)) return false; - start_listvalue_object(p); - } - - if (p->top->is_unknown_field) { - inner = p->top + 1; - inner->m = NULL; - inner->name_table = NULL; - inner->f = NULL; - inner->is_map = false; - inner->is_mapentry = false; - inner->is_unknown_field = true; - p->top = inner; - - return true; - } + UPB_ASSERT(p->top->f); if (!upb_fielddef_isseq(p->top->f)) { upb_status_seterrf(&p->status, @@ -14337,7 +13469,6 @@ static bool start_array(upb_json_parser *p) { inner->f = p->top->f; inner->is_map = false; inner->is_mapentry = false; - inner->is_unknown_field = false; p->top = inner; return true; @@ -14349,37 +13480,18 @@ static void end_array(upb_json_parser *p) { UPB_ASSERT(p->top > p->stack); p->top--; - - if (p->top->is_unknown_field) { - return; - } - sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); upb_sink_endseq(&p->top->sink, sel); - - if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) { - end_listvalue_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - } - - if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { - end_value_object(p); - if (!is_top_level(p)) { - end_subobject(p); - } - } } static void start_object(upb_json_parser *p) { - if (!p->top->is_map && p->top->m != NULL) { + if (!p->top->is_map) { upb_sink_startmsg(&p->top->sink); } } static void end_object(upb_json_parser *p) { - if (!p->top->is_map && p->top->m != NULL) { + if (!p->top->is_map) { upb_status status; upb_status_clear(&status); upb_sink_endmsg(&p->top->sink, &status); @@ -14389,149 +13501,6 @@ static void end_object(upb_json_parser *p) { } } -static bool is_string_wrapper(const upb_msgdef *m) { - upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); - return type == UPB_WELLKNOWN_STRINGVALUE || - type == UPB_WELLKNOWN_BYTESVALUE; -} - -static void start_wrapper_object(upb_json_parser *p) { - const char *membername = "value"; - - start_object(p); - - /* Set up context for parsing value */ - start_member(p); - capture_begin(p, membername); - capture_end(p, membername + 5); - end_membername(p); -} - -static void end_wrapper_object(upb_json_parser *p) { - end_member(p); - end_object(p); -} - -static void start_value_object(upb_json_parser *p, int value_type) { - const char *nullmember = "null_value"; - const char *numbermember = "number_value"; - const char *stringmember = "string_value"; - const char *boolmember = "bool_value"; - const char *structmember = "struct_value"; - const char *listmember = "list_value"; - const char *membername = ""; - - switch (value_type) { - case VALUE_NULLVALUE: - membername = nullmember; - break; - case VALUE_NUMBERVALUE: - membername = numbermember; - break; - case VALUE_STRINGVALUE: - membername = stringmember; - break; - case VALUE_BOOLVALUE: - membername = boolmember; - break; - case VALUE_STRUCTVALUE: - membername = structmember; - break; - case VALUE_LISTVALUE: - membername = listmember; - break; - } - - start_object(p); - - /* Set up context for parsing value */ - start_member(p); - capture_begin(p, membername); - capture_end(p, membername + strlen(membername)); - end_membername(p); -} - -static void end_value_object(upb_json_parser *p) { - end_member(p); - end_object(p); -} - -static void start_listvalue_object(upb_json_parser *p) { - const char *membername = "values"; - - start_object(p); - - /* Set up context for parsing value */ - start_member(p); - capture_begin(p, membername); - capture_end(p, membername + strlen(membername)); - end_membername(p); -} - -static void end_listvalue_object(upb_json_parser *p) { - end_member(p); - end_object(p); -} - -static void start_structvalue_object(upb_json_parser *p) { - const char *membername = "fields"; - - start_object(p); - - /* Set up context for parsing value */ - start_member(p); - capture_begin(p, membername); - capture_end(p, membername + strlen(membername)); - end_membername(p); -} - -static void end_structvalue_object(upb_json_parser *p) { - end_member(p); - end_object(p); -} - -static bool is_top_level(upb_json_parser *p) { - return p->top == p->stack && p->top->f == NULL && !p->top->is_unknown_field; -} - -static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type) { - return p->top->m != NULL && upb_msgdef_wellknowntype(p->top->m) == type; -} - -static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type) { - return p->top->f != NULL && - upb_fielddef_issubmsg(p->top->f) && - (upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(p->top->f)) - == type); -} - -static bool does_number_wrapper_start(upb_json_parser *p) { - return p->top->f != NULL && - upb_fielddef_issubmsg(p->top->f) && - upb_msgdef_isnumberwrapper(upb_fielddef_msgsubdef(p->top->f)); -} - -static bool does_number_wrapper_end(upb_json_parser *p) { - return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m); -} - -static bool is_number_wrapper_object(upb_json_parser *p) { - return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m); -} - -static bool does_string_wrapper_start(upb_json_parser *p) { - return p->top->f != NULL && - upb_fielddef_issubmsg(p->top->f) && - is_string_wrapper(upb_fielddef_msgsubdef(p->top->f)); -} - -static bool does_string_wrapper_end(upb_json_parser *p) { - return p->top->m != NULL && is_string_wrapper(p->top->m); -} - -static bool is_string_wrapper_object(upb_json_parser *p) { - return p->top->m != NULL && is_string_wrapper(p->top->m); -} #define CHECK_RETURN_TOP(x) if (!(x)) goto error @@ -14554,262 +13523,160 @@ static bool is_string_wrapper_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -//#line 2147 "upb/json/parser.rl" +#line 1310 "upb/json/parser.rl" -//#line 2016 "upb/json/parser.c" +#line 1222 "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, - 9, 1, 10, 1, 11, 1, 12, 1, - 13, 1, 21, 1, 23, 1, 24, 1, - 25, 1, 27, 1, 28, 1, 30, 1, - 32, 1, 33, 1, 34, 1, 35, 1, - 36, 1, 38, 2, 4, 9, 2, 5, - 6, 2, 7, 3, 2, 7, 9, 2, - 14, 15, 2, 16, 17, 2, 18, 19, - 2, 22, 20, 2, 26, 37, 2, 29, - 2, 2, 30, 38, 2, 31, 20, 2, - 33, 38, 2, 34, 38, 2, 35, 38, - 3, 25, 22, 20, 3, 26, 37, 38, - 4, 14, 15, 16, 17 + 0, 1, 0, 1, 2, 1, 3, 1, + 5, 1, 6, 1, 7, 1, 8, 1, + 10, 1, 12, 1, 13, 1, 14, 1, + 15, 1, 16, 1, 17, 1, 21, 1, + 25, 1, 27, 2, 3, 8, 2, 4, + 5, 2, 6, 2, 2, 6, 8, 2, + 11, 9, 2, 13, 15, 2, 14, 15, + 2, 18, 1, 2, 19, 27, 2, 20, + 9, 2, 22, 27, 2, 23, 27, 2, + 24, 27, 2, 26, 27, 3, 14, 11, + 9 }; -static const short _json_key_offsets[] = { - 0, 0, 12, 13, 18, 23, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, - 38, 43, 48, 49, 53, 58, 63, 68, - 72, 76, 79, 82, 84, 88, 92, 94, - 96, 101, 103, 105, 114, 120, 126, 132, - 138, 140, 144, 147, 149, 151, 154, 155, - 159, 161, 163, 165, 167, 168, 170, 172, - 173, 175, 177, 178, 180, 182, 183, 185, - 187, 188, 190, 192, 196, 198, 200, 201, - 202, 203, 204, 206, 211, 220, 221, 221, - 221, 226, 231, 236, 237, 238, 239, 240, - 240, 241, 242, 243, 243, 244, 245, 246, - 246, 251, 256, 257, 261, 266, 271, 276, - 280, 280, 283, 286, 289, 292, 295, 298, - 298, 298, 298, 298 +static const unsigned char _json_key_offsets[] = { + 0, 0, 4, 9, 14, 15, 19, 24, + 29, 34, 38, 42, 45, 48, 50, 54, + 58, 60, 62, 67, 69, 71, 80, 86, + 92, 98, 104, 106, 115, 116, 116, 116, + 121, 126, 131, 132, 133, 134, 135, 135, + 136, 137, 138, 138, 139, 140, 141, 141, + 146, 151, 152, 156, 161, 166, 171, 175, + 175, 178, 178, 178 }; static const char _json_trans_keys[] = { - 32, 34, 45, 91, 102, 110, 116, 123, - 9, 13, 48, 57, 34, 32, 93, 125, - 9, 13, 32, 44, 93, 9, 13, 32, - 93, 125, 9, 13, 97, 108, 115, 101, - 117, 108, 108, 114, 117, 101, 32, 34, - 125, 9, 13, 32, 34, 125, 9, 13, - 34, 32, 58, 9, 13, 32, 93, 125, - 9, 13, 32, 44, 125, 9, 13, 32, - 44, 125, 9, 13, 32, 34, 9, 13, - 45, 48, 49, 57, 48, 49, 57, 46, - 69, 101, 48, 57, 69, 101, 48, 57, - 43, 45, 48, 57, 48, 57, 48, 57, - 46, 69, 101, 48, 57, 34, 92, 34, - 92, 34, 47, 92, 98, 102, 110, 114, - 116, 117, 48, 57, 65, 70, 97, 102, + 32, 123, 9, 13, 32, 34, 125, 9, + 13, 32, 34, 125, 9, 13, 34, 32, + 58, 9, 13, 32, 93, 125, 9, 13, + 32, 44, 125, 9, 13, 32, 44, 125, + 9, 13, 32, 34, 9, 13, 45, 48, + 49, 57, 48, 49, 57, 46, 69, 101, + 48, 57, 69, 101, 48, 57, 43, 45, + 48, 57, 48, 57, 48, 57, 46, 69, + 101, 48, 57, 34, 92, 34, 92, 34, + 47, 92, 98, 102, 110, 114, 116, 117, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, - 97, 102, 34, 92, 45, 48, 49, 57, - 48, 49, 57, 46, 115, 48, 57, 115, - 48, 57, 34, 46, 115, 48, 57, 48, - 57, 48, 57, 48, 57, 48, 57, 45, - 48, 57, 48, 57, 45, 48, 57, 48, - 57, 84, 48, 57, 48, 57, 58, 48, - 57, 48, 57, 58, 48, 57, 48, 57, - 43, 45, 46, 90, 48, 57, 48, 57, - 58, 48, 48, 34, 48, 57, 43, 45, - 90, 48, 57, 34, 45, 91, 102, 110, - 116, 123, 48, 57, 34, 32, 93, 125, - 9, 13, 32, 44, 93, 9, 13, 32, - 93, 125, 9, 13, 97, 108, 115, 101, - 117, 108, 108, 114, 117, 101, 32, 34, - 125, 9, 13, 32, 34, 125, 9, 13, - 34, 32, 58, 9, 13, 32, 93, 125, - 9, 13, 32, 44, 125, 9, 13, 32, - 44, 125, 9, 13, 32, 34, 9, 13, - 32, 9, 13, 32, 9, 13, 32, 9, - 13, 32, 9, 13, 32, 9, 13, 32, + 97, 102, 48, 57, 65, 70, 97, 102, + 34, 92, 34, 45, 91, 102, 110, 116, + 123, 48, 57, 34, 32, 93, 125, 9, + 13, 32, 44, 93, 9, 13, 32, 93, + 125, 9, 13, 97, 108, 115, 101, 117, + 108, 108, 114, 117, 101, 32, 34, 125, + 9, 13, 32, 34, 125, 9, 13, 34, + 32, 58, 9, 13, 32, 93, 125, 9, + 13, 32, 44, 125, 9, 13, 32, 44, + 125, 9, 13, 32, 34, 9, 13, 32, 9, 13, 0 }; static const char _json_single_lengths[] = { - 0, 8, 1, 3, 3, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 3, 3, 1, 2, 3, 3, 3, 2, - 2, 1, 3, 0, 2, 2, 0, 0, - 3, 2, 2, 9, 0, 0, 0, 0, - 2, 2, 1, 2, 0, 1, 1, 2, - 0, 0, 0, 0, 1, 0, 0, 1, - 0, 0, 1, 0, 0, 1, 0, 0, - 1, 0, 0, 4, 0, 0, 1, 1, - 1, 1, 0, 3, 7, 1, 0, 0, - 3, 3, 3, 1, 1, 1, 1, 0, - 1, 1, 1, 0, 1, 1, 1, 0, - 3, 3, 1, 2, 3, 3, 3, 2, - 0, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0 + 0, 2, 3, 3, 1, 2, 3, 3, + 3, 2, 2, 1, 3, 0, 2, 2, + 0, 0, 3, 2, 2, 9, 0, 0, + 0, 0, 2, 7, 1, 0, 0, 3, + 3, 3, 1, 1, 1, 1, 0, 1, + 1, 1, 0, 1, 1, 1, 0, 3, + 3, 1, 2, 3, 3, 3, 2, 0, + 1, 0, 0, 0 }; static const char _json_range_lengths[] = { - 0, 2, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 3, 3, 3, 3, - 0, 1, 1, 0, 1, 1, 0, 1, - 1, 1, 1, 1, 0, 1, 1, 0, - 1, 1, 0, 1, 1, 0, 1, 1, - 0, 1, 1, 0, 1, 1, 0, 0, - 0, 0, 1, 1, 1, 0, 0, 0, - 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0 + 0, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 3, 3, + 3, 3, 0, 1, 0, 0, 0, 1, + 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 1, 1, 1, 1, 1, 0, + 1, 0, 0, 0 }; static const short _json_index_offsets[] = { - 0, 0, 11, 13, 18, 23, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, - 48, 53, 58, 60, 64, 69, 74, 79, - 83, 87, 90, 94, 96, 100, 104, 106, - 108, 113, 116, 119, 129, 133, 137, 141, - 145, 148, 152, 155, 158, 160, 163, 165, - 169, 171, 173, 175, 177, 179, 181, 183, - 185, 187, 189, 191, 193, 195, 197, 199, - 201, 203, 205, 207, 212, 214, 216, 218, - 220, 222, 224, 226, 231, 240, 242, 243, - 244, 249, 254, 259, 261, 263, 265, 267, - 268, 270, 272, 274, 275, 277, 279, 281, - 282, 287, 292, 294, 298, 303, 308, 313, - 317, 318, 321, 324, 327, 330, 333, 336, - 337, 338, 339, 340 + 0, 0, 4, 9, 14, 16, 20, 25, + 30, 35, 39, 43, 46, 50, 52, 56, + 60, 62, 64, 69, 72, 75, 85, 89, + 93, 97, 101, 104, 113, 115, 116, 117, + 122, 127, 132, 134, 136, 138, 140, 141, + 143, 145, 147, 148, 150, 152, 154, 155, + 160, 165, 167, 171, 176, 181, 186, 190, + 191, 194, 195, 196 }; -static const unsigned char _json_indicies[] = { - 0, 2, 3, 4, 5, 6, 7, 8, - 0, 3, 1, 9, 1, 11, 12, 1, - 11, 10, 13, 14, 12, 13, 1, 14, - 1, 1, 14, 10, 15, 1, 16, 1, - 17, 1, 18, 1, 19, 1, 20, 1, - 21, 1, 22, 1, 23, 1, 24, 1, - 25, 26, 27, 25, 1, 28, 29, 30, - 28, 1, 31, 1, 32, 33, 32, 1, - 33, 1, 1, 33, 34, 35, 36, 37, - 35, 1, 38, 39, 30, 38, 1, 39, - 29, 39, 1, 40, 41, 42, 1, 41, - 42, 1, 44, 45, 45, 43, 46, 1, - 45, 45, 46, 43, 47, 47, 48, 1, - 48, 1, 48, 43, 44, 45, 45, 42, - 43, 50, 51, 49, 53, 54, 52, 55, - 55, 55, 55, 55, 55, 55, 55, 56, - 1, 57, 57, 57, 1, 58, 58, 58, - 1, 59, 59, 59, 1, 60, 60, 60, - 1, 62, 63, 61, 64, 65, 66, 1, - 67, 68, 1, 69, 70, 1, 71, 1, - 70, 71, 1, 72, 1, 69, 70, 68, - 1, 73, 1, 74, 1, 75, 1, 76, - 1, 77, 1, 78, 1, 79, 1, 80, - 1, 81, 1, 82, 1, 83, 1, 84, - 1, 85, 1, 86, 1, 87, 1, 88, - 1, 89, 1, 90, 1, 91, 1, 92, - 92, 93, 94, 1, 95, 1, 96, 1, - 97, 1, 98, 1, 99, 1, 100, 1, - 101, 1, 102, 102, 103, 101, 1, 104, - 105, 106, 107, 108, 109, 110, 105, 1, - 111, 1, 112, 113, 115, 116, 1, 115, - 114, 117, 118, 116, 117, 1, 118, 1, - 1, 118, 114, 119, 1, 120, 1, 121, - 1, 122, 1, 123, 124, 1, 125, 1, - 126, 1, 127, 128, 1, 129, 1, 130, - 1, 131, 132, 133, 134, 132, 1, 135, - 136, 137, 135, 1, 138, 1, 139, 140, - 139, 1, 140, 1, 1, 140, 141, 142, - 143, 144, 142, 1, 145, 146, 137, 145, - 1, 146, 136, 146, 1, 147, 148, 148, - 1, 149, 149, 1, 150, 150, 1, 151, - 151, 1, 152, 152, 1, 153, 153, 1, - 1, 1, 1, 1, 1, 0 +static const char _json_indicies[] = { + 0, 2, 0, 1, 3, 4, 5, 3, + 1, 6, 7, 8, 6, 1, 9, 1, + 10, 11, 10, 1, 11, 1, 1, 11, + 12, 13, 14, 15, 13, 1, 16, 17, + 8, 16, 1, 17, 7, 17, 1, 18, + 19, 20, 1, 19, 20, 1, 22, 23, + 23, 21, 24, 1, 23, 23, 24, 21, + 25, 25, 26, 1, 26, 1, 26, 21, + 22, 23, 23, 20, 21, 28, 29, 27, + 31, 32, 30, 33, 33, 33, 33, 33, + 33, 33, 33, 34, 1, 35, 35, 35, + 1, 36, 36, 36, 1, 37, 37, 37, + 1, 38, 38, 38, 1, 40, 41, 39, + 42, 43, 44, 45, 46, 47, 48, 43, + 1, 49, 1, 50, 51, 53, 54, 1, + 53, 52, 55, 56, 54, 55, 1, 56, + 1, 1, 56, 52, 57, 1, 58, 1, + 59, 1, 60, 1, 61, 62, 1, 63, + 1, 64, 1, 65, 66, 1, 67, 1, + 68, 1, 69, 70, 71, 72, 70, 1, + 73, 74, 75, 73, 1, 76, 1, 77, + 78, 77, 1, 78, 1, 1, 78, 79, + 80, 81, 82, 80, 1, 83, 84, 75, + 83, 1, 84, 74, 84, 1, 85, 86, + 86, 1, 1, 1, 1, 0 }; static const char _json_trans_targs[] = { - 1, 0, 2, 106, 3, 6, 10, 13, - 16, 105, 4, 3, 105, 4, 5, 7, - 8, 9, 107, 11, 12, 108, 14, 15, - 109, 17, 18, 110, 17, 18, 110, 19, - 19, 20, 21, 22, 23, 110, 22, 23, - 25, 26, 32, 111, 27, 29, 28, 30, - 31, 34, 112, 35, 34, 112, 35, 33, - 36, 37, 38, 39, 40, 34, 112, 35, - 42, 43, 47, 43, 47, 44, 46, 45, - 113, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 74, 73, 69, - 70, 71, 72, 73, 114, 75, 68, 73, - 77, 79, 80, 83, 88, 92, 96, 78, - 115, 115, 81, 80, 78, 81, 82, 84, - 85, 86, 87, 115, 89, 90, 91, 115, - 93, 94, 95, 115, 97, 98, 104, 97, - 98, 104, 99, 99, 100, 101, 102, 103, - 104, 102, 103, 115, 105, 105, 105, 105, - 105, 105 + 1, 0, 2, 3, 4, 56, 3, 4, + 56, 5, 5, 6, 7, 8, 9, 56, + 8, 9, 11, 12, 18, 57, 13, 15, + 14, 16, 17, 20, 58, 21, 20, 58, + 21, 19, 22, 23, 24, 25, 26, 20, + 58, 21, 28, 30, 31, 34, 39, 43, + 47, 29, 59, 59, 32, 31, 29, 32, + 33, 35, 36, 37, 38, 59, 40, 41, + 42, 59, 44, 45, 46, 59, 48, 49, + 55, 48, 49, 55, 50, 50, 51, 52, + 53, 54, 55, 53, 54, 59, 56 }; static const char _json_trans_actions[] = { - 0, 0, 84, 78, 33, 0, 0, 0, - 47, 39, 25, 0, 35, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 31, 96, 31, 0, 72, 0, 27, - 0, 0, 25, 29, 29, 29, 0, 0, - 0, 0, 0, 3, 0, 0, 0, 0, - 0, 5, 15, 0, 0, 51, 7, 13, - 0, 54, 9, 9, 9, 57, 60, 11, - 17, 17, 17, 0, 0, 0, 19, 0, - 21, 23, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 104, 63, 104, 0, - 0, 0, 0, 0, 69, 0, 66, 66, - 84, 78, 33, 0, 0, 0, 47, 39, - 49, 81, 25, 0, 35, 0, 0, 0, - 0, 0, 0, 90, 0, 0, 0, 93, - 0, 0, 0, 87, 31, 96, 31, 0, - 72, 0, 27, 0, 0, 25, 29, 29, - 29, 0, 0, 100, 0, 37, 43, 45, - 41, 75 -}; - -static const char _json_eof_actions[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 37, 43, 45, 41, 75, 0, - 0, 0, 0, 0 + 0, 0, 0, 21, 77, 53, 0, 47, + 23, 17, 0, 0, 15, 19, 19, 50, + 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 3, 13, 0, 0, 35, + 5, 11, 0, 38, 7, 7, 7, 41, + 44, 9, 62, 56, 25, 0, 0, 0, + 31, 29, 33, 59, 15, 0, 27, 0, + 0, 0, 0, 0, 0, 68, 0, 0, + 0, 71, 0, 0, 0, 65, 21, 77, + 53, 0, 47, 23, 17, 0, 0, 15, + 19, 19, 50, 0, 0, 74, 0 }; static const int json_start = 1; -static const int json_en_number_machine = 24; -static const int json_en_string_machine = 33; -static const int json_en_duration_machine = 41; -static const int json_en_timestamp_machine = 48; -static const int json_en_value_machine = 76; +static const int json_en_number_machine = 10; +static const int json_en_string_machine = 19; +static const int json_en_value_machine = 27; static const int json_en_main = 1; -//#line 2150 "upb/json/parser.rl" +#line 1313 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -14822,7 +13689,6 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, const char *p = buf; const char *pe = buf + size; - const char *eof = &eof_ch; parser->handle = handle; @@ -14832,7 +13698,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -//#line 2290 "upb/json/parser.c" +#line 1393 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -14906,167 +13772,119 @@ _match: { switch ( *_acts++ ) { - case 1: -//#line 2021 "upb/json/parser.rl" + case 0: +#line 1225 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; + case 1: +#line 1226 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 10; goto _again;} } + break; case 2: -//#line 2023 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 24; goto _again;} } +#line 1230 "upb/json/parser.rl" + { start_text(parser, p); } break; case 3: -//#line 2027 "upb/json/parser.rl" - { start_text(parser, p); } +#line 1231 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 4: -//#line 2028 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_text(parser, p)); } +#line 1237 "upb/json/parser.rl" + { start_hex(parser); } break; case 5: -//#line 2034 "upb/json/parser.rl" - { start_hex(parser); } +#line 1238 "upb/json/parser.rl" + { hexdigit(parser, p); } break; case 6: -//#line 2035 "upb/json/parser.rl" - { hexdigit(parser, p); } +#line 1239 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_hex(parser)); } break; case 7: -//#line 2036 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_hex(parser)); } +#line 1245 "upb/json/parser.rl" + { CHECK_RETURN_TOP(escape(parser, p)); } break; case 8: -//#line 2042 "upb/json/parser.rl" - { CHECK_RETURN_TOP(escape(parser, p)); } +#line 1251 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; case 9: -//#line 2048 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } +#line 1254 "upb/json/parser.rl" + { {stack[top++] = cs; cs = 19; goto _again;} } break; case 10: -//#line 2060 "upb/json/parser.rl" - { start_duration_base(parser, p); } +#line 1256 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 27; goto _again;} } break; case 11: -//#line 2061 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_duration_base(parser, p)); } - break; - case 12: -//#line 2063 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } - break; - case 13: -//#line 2068 "upb/json/parser.rl" - { start_timestamp_base(parser, p); } - break; - case 14: -//#line 2069 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } - break; - case 15: -//#line 2071 "upb/json/parser.rl" - { start_timestamp_fraction(parser, p); } - break; - case 16: -//#line 2072 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } - break; - case 17: -//#line 2074 "upb/json/parser.rl" - { start_timestamp_zone(parser, p); } - break; - case 18: -//#line 2075 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } - break; - case 19: -//#line 2077 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } - break; - case 20: -//#line 2082 "upb/json/parser.rl" - { - if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { - {stack[top++] = cs; cs = 48; goto _again;} - } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) { - {stack[top++] = cs; cs = 41; goto _again;} - } else { - {stack[top++] = cs; cs = 33; goto _again;} - } - } - break; - case 21: -//#line 2093 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 76; goto _again;} } - break; - case 22: -//#line 2098 "upb/json/parser.rl" +#line 1261 "upb/json/parser.rl" { start_member(parser); } break; - case 23: -//#line 2099 "upb/json/parser.rl" + case 12: +#line 1262 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_membername(parser)); } break; - case 24: -//#line 2102 "upb/json/parser.rl" + case 13: +#line 1265 "upb/json/parser.rl" { end_member(parser); } break; - case 25: -//#line 2108 "upb/json/parser.rl" + case 14: +#line 1271 "upb/json/parser.rl" { start_object(parser); } break; - case 26: -//#line 2111 "upb/json/parser.rl" + case 15: +#line 1274 "upb/json/parser.rl" { end_object(parser); } break; - case 27: -//#line 2117 "upb/json/parser.rl" + case 16: +#line 1280 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_array(parser)); } break; - case 28: -//#line 2121 "upb/json/parser.rl" + case 17: +#line 1284 "upb/json/parser.rl" { end_array(parser); } break; - case 29: -//#line 2126 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_number(parser, p)); } + case 18: +#line 1289 "upb/json/parser.rl" + { start_number(parser, p); } break; - case 30: -//#line 2127 "upb/json/parser.rl" + case 19: +#line 1290 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; - case 31: -//#line 2129 "upb/json/parser.rl" + case 20: +#line 1292 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_stringval(parser)); } break; - case 32: -//#line 2130 "upb/json/parser.rl" + case 21: +#line 1293 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_stringval(parser)); } break; - case 33: -//#line 2132 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, true)); } + case 22: +#line 1295 "upb/json/parser.rl" + { CHECK_RETURN_TOP(parser_putbool(parser, true)); } break; - case 34: -//#line 2134 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, false)); } + case 23: +#line 1297 "upb/json/parser.rl" + { CHECK_RETURN_TOP(parser_putbool(parser, false)); } break; - case 35: -//#line 2136 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_null(parser)); } + case 24: +#line 1299 "upb/json/parser.rl" + { /* null value */ } break; - case 36: -//#line 2138 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_subobject_full(parser)); } + case 25: +#line 1301 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_subobject(parser)); } break; - case 37: -//#line 2139 "upb/json/parser.rl" - { end_subobject_full(parser); } + case 26: +#line 1302 "upb/json/parser.rl" + { end_subobject(parser); } break; - case 38: -//#line 2144 "upb/json/parser.rl" + case 27: +#line 1307 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -//#line 2524 "upb/json/parser.c" +#line 1579 "upb/json/parser.c" } } @@ -15076,49 +13894,10 @@ _again: if ( ++p != pe ) goto _resume; _test_eof: {} - if ( p == eof ) - { - const char *__acts = _json_actions + _json_eof_actions[cs]; - unsigned int __nacts = (unsigned int) *__acts++; - while ( __nacts-- > 0 ) { - switch ( *__acts++ ) { - case 0: -//#line 2019 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } - break; - case 26: -//#line 2111 "upb/json/parser.rl" - { end_object(parser); } - break; - case 30: -//#line 2127 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_number(parser, p)); } - break; - case 33: -//#line 2132 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, true)); } - break; - case 34: -//#line 2134 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, false)); } - break; - case 35: -//#line 2136 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_null(parser)); } - break; - case 37: -//#line 2139 "upb/json/parser.rl" - { end_subobject_full(parser); } - break; -//#line 2568 "upb/json/parser.c" - } - } - } - _out: {} } -//#line 2172 "upb/json/parser.rl" +#line 1334 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -15136,24 +13915,16 @@ error: } bool end(void *closure, const void *hd) { - upb_json_parser *parser = closure; + UPB_UNUSED(closure); + UPB_UNUSED(hd); /* Prevent compile warning on unused static constants. */ UPB_UNUSED(json_start); - UPB_UNUSED(json_en_duration_machine); UPB_UNUSED(json_en_number_machine); UPB_UNUSED(json_en_string_machine); - UPB_UNUSED(json_en_timestamp_machine); UPB_UNUSED(json_en_value_machine); UPB_UNUSED(json_en_main); - - parse(parser, hd, &eof_ch, 0, NULL); - - return parser->current_state >= -//#line 2608 "upb/json/parser.c" -105 -//#line 2202 "upb/json/parser.rl" -; + return true; } static void json_parser_reset(upb_json_parser *p) { @@ -15164,17 +13935,16 @@ static void json_parser_reset(upb_json_parser *p) { p->top->f = NULL; p->top->is_map = false; p->top->is_mapentry = false; - p->top->is_unknown_field = false; /* Emit Ragel initialization of the parser. */ -//#line 2626 "upb/json/parser.c" +#line 1633 "upb/json/parser.c" { cs = json_start; top = 0; } -//#line 2217 "upb/json/parser.rl" +#line 1374 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -15261,8 +14031,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { upb_json_parser *upb_json_parser_create(upb_env *env, const upb_json_parsermethod *method, - upb_sink *output, - bool ignore_json_unknown) { + upb_sink *output) { #ifndef NDEBUG const size_t size_before = upb_env_bytesallocated(env); #endif @@ -15281,8 +14050,6 @@ upb_json_parser *upb_json_parser_create(upb_env *env, p->top->m = upb_handlers_msgdef(output->handlers); set_name_table(p, p->top); - p->ignore_json_unknown = ignore_json_unknown; - /* If this fails, uncomment and increase the value in parser.h. */ /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <= @@ -15327,7 +14094,6 @@ const upb_byteshandler *upb_json_parsermethod_inputhandler( #include #include -#include struct upb_json_printer { upb_sink input_; @@ -15348,12 +14114,6 @@ struct upb_json_printer { * repeated fields and messages (maps), and the worst case is a * message->repeated field->submessage->repeated field->... nesting. */ bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; - - /* To print timestamp, printer needs to cache its seconds and nanos values - * and convert them when ending timestamp message. See comments of - * printer_sethandlers_timestamp for more detail. */ - int64_t seconds; - int32_t nanos; }; /* StringPiece; a pointer plus a length. */ @@ -16012,369 +14772,6 @@ void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames, upb_handlerattr_uninit(&empty_attr); } -static bool putseconds(void *closure, const void *handler_data, - int64_t seconds) { - upb_json_printer *p = closure; - p->seconds = seconds; - UPB_UNUSED(handler_data); - return true; -} - -static bool putnanos(void *closure, const void *handler_data, - int32_t nanos) { - upb_json_printer *p = closure; - p->nanos = nanos; - UPB_UNUSED(handler_data); - return true; -} - -static void *scalar_startstr_nokey(void *closure, const void *handler_data, - size_t size_hint) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - UPB_UNUSED(size_hint); - print_data(p, "\"", 1); - return p; -} - -static size_t putstr_nokey(void *closure, const void *handler_data, - const char *str, size_t len, - const upb_bufhandle *handle) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - UPB_UNUSED(handle); - print_data(p, "\"", 1); - putstring(p, str, len); - print_data(p, "\"", 1); - return len + 2; -} - -static void *startseq_nokey(void *closure, const void *handler_data) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - p->depth_++; - p->first_elem_[p->depth_] = true; - print_data(p, "[", 1); - return closure; -} - -static void *startmap_nokey(void *closure, const void *handler_data) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - p->depth_++; - p->first_elem_[p->depth_] = true; - print_data(p, "{", 1); - return closure; -} - -static bool putnull(void *closure, const void *handler_data, - int32_t null) { - upb_json_printer *p = closure; - print_data(p, "null", 4); - UPB_UNUSED(handler_data); - UPB_UNUSED(null); - return true; -} - -static bool printer_startdurationmsg(void *closure, const void *handler_data) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - if (p->depth_ == 0) { - upb_bytessink_start(p->output_, 0, &p->subc_); - } - return true; -} - -#define UPB_DURATION_MAX_JSON_LEN 23 -#define UPB_DURATION_MAX_NANO_LEN 9 - -static bool printer_enddurationmsg(void *closure, const void *handler_data, - upb_status *s) { - upb_json_printer *p = closure; - char buffer[UPB_DURATION_MAX_JSON_LEN]; - size_t base_len; - size_t curr; - size_t i; - - memset(buffer, 0, UPB_DURATION_MAX_JSON_LEN); - - if (p->seconds < -315576000000) { - upb_status_seterrf(s, "error parsing duration: " - "minimum acceptable value is " - "-315576000000"); - return false; - } - - if (p->seconds > 315576000000) { - upb_status_seterrf(s, "error serializing duration: " - "maximum acceptable value is " - "315576000000"); - return false; - } - - _upb_snprintf(buffer, sizeof(buffer), "%ld", (long)p->seconds); - base_len = strlen(buffer); - - if (p->nanos != 0) { - char nanos_buffer[UPB_DURATION_MAX_NANO_LEN + 3]; - _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f", - p->nanos / 1000000000.0); - /* Remove trailing 0. */ - for (i = UPB_DURATION_MAX_NANO_LEN + 2; - nanos_buffer[i] == '0'; i--) { - nanos_buffer[i] = 0; - } - strcpy(buffer + base_len, nanos_buffer + 1); - } - - curr = strlen(buffer); - strcpy(buffer + curr, "s"); - - p->seconds = 0; - p->nanos = 0; - - print_data(p, "\"", 1); - print_data(p, buffer, strlen(buffer)); - print_data(p, "\"", 1); - - if (p->depth_ == 0) { - upb_bytessink_end(p->output_); - } - - UPB_UNUSED(handler_data); - return true; -} - -static bool printer_starttimestampmsg(void *closure, const void *handler_data) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - if (p->depth_ == 0) { - upb_bytessink_start(p->output_, 0, &p->subc_); - } - return true; -} - -#define UPB_TIMESTAMP_MAX_JSON_LEN 31 -#define UPB_TIMESTAMP_BEFORE_NANO_LEN 19 -#define UPB_TIMESTAMP_MAX_NANO_LEN 9 - -static bool printer_endtimestampmsg(void *closure, const void *handler_data, - upb_status *s) { - upb_json_printer *p = closure; - char buffer[UPB_TIMESTAMP_MAX_JSON_LEN]; - time_t time = p->seconds; - size_t curr; - size_t i; - size_t year_length = - strftime(buffer, UPB_TIMESTAMP_MAX_JSON_LEN, "%Y", gmtime(&time)); - - if (p->seconds < -62135596800) { - upb_status_seterrf(s, "error parsing timestamp: " - "minimum acceptable value is " - "0001-01-01T00:00:00Z"); - return false; - } - - if (p->seconds > 253402300799) { - upb_status_seterrf(s, "error parsing timestamp: " - "maximum acceptable value is " - "9999-12-31T23:59:59Z"); - return false; - } - - /* strftime doesn't guarantee 4 digits for year. Prepend 0 by ourselves. */ - for (i = 0; i < 4 - year_length; i++) { - buffer[i] = '0'; - } - - strftime(buffer + (4 - year_length), UPB_TIMESTAMP_MAX_JSON_LEN, - "%Y-%m-%dT%H:%M:%S", gmtime(&time)); - if (p->nanos != 0) { - char nanos_buffer[UPB_TIMESTAMP_MAX_NANO_LEN + 3]; - _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f", - p->nanos / 1000000000.0); - /* Remove trailing 0. */ - for (i = UPB_TIMESTAMP_MAX_NANO_LEN + 2; - nanos_buffer[i] == '0'; i--) { - nanos_buffer[i] = 0; - } - strcpy(buffer + UPB_TIMESTAMP_BEFORE_NANO_LEN, nanos_buffer + 1); - } - - curr = strlen(buffer); - strcpy(buffer + curr, "Z"); - - p->seconds = 0; - p->nanos = 0; - - print_data(p, "\"", 1); - print_data(p, buffer, strlen(buffer)); - print_data(p, "\"", 1); - - if (p->depth_ == 0) { - upb_bytessink_end(p->output_); - } - - UPB_UNUSED(handler_data); - UPB_UNUSED(s); - return true; -} - -static bool printer_startmsg_noframe(void *closure, const void *handler_data) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - if (p->depth_ == 0) { - upb_bytessink_start(p->output_, 0, &p->subc_); - } - return true; -} - -static bool printer_endmsg_noframe( - void *closure, const void *handler_data, upb_status *s) { - upb_json_printer *p = closure; - UPB_UNUSED(handler_data); - UPB_UNUSED(s); - if (p->depth_ == 0) { - upb_bytessink_end(p->output_); - } - return true; -} - -/* Set up handlers for a duration submessage. */ -void printer_sethandlers_duration(const void *closure, upb_handlers *h) { - const upb_msgdef *md = upb_handlers_msgdef(h); - - const upb_fielddef* seconds_field = - upb_msgdef_itof(md, UPB_DURATION_SECONDS); - const upb_fielddef* nanos_field = - upb_msgdef_itof(md, UPB_DURATION_NANOS); - - upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; - - upb_handlers_setstartmsg(h, printer_startdurationmsg, &empty_attr); - upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr); - upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr); - upb_handlers_setendmsg(h, printer_enddurationmsg, &empty_attr); - - UPB_UNUSED(closure); -} - -/* Set up handlers for a timestamp submessage. Instead of printing fields - * separately, the json representation of timestamp follows RFC 3339 */ -void printer_sethandlers_timestamp(const void *closure, upb_handlers *h) { - const upb_msgdef *md = upb_handlers_msgdef(h); - - const upb_fielddef* seconds_field = - upb_msgdef_itof(md, UPB_TIMESTAMP_SECONDS); - const upb_fielddef* nanos_field = - upb_msgdef_itof(md, UPB_TIMESTAMP_NANOS); - - upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; - - upb_handlers_setstartmsg(h, printer_starttimestampmsg, &empty_attr); - upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr); - upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr); - upb_handlers_setendmsg(h, printer_endtimestampmsg, &empty_attr); - - UPB_UNUSED(closure); -} - -void printer_sethandlers_value(const void *closure, upb_handlers *h) { - const upb_msgdef *md = upb_handlers_msgdef(h); - upb_msg_field_iter i; - - upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; - - upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); - upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); - - upb_msg_field_begin(&i, md); - for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { - const upb_fielddef *f = upb_msg_iter_field(&i); - - switch (upb_fielddef_type(f)) { - case UPB_TYPE_ENUM: - upb_handlers_setint32(h, f, putnull, &empty_attr); - break; - case UPB_TYPE_DOUBLE: - upb_handlers_setdouble(h, f, putdouble, &empty_attr); - break; - case UPB_TYPE_STRING: - upb_handlers_setstartstr(h, f, scalar_startstr_nokey, &empty_attr); - upb_handlers_setstring(h, f, scalar_str, &empty_attr); - upb_handlers_setendstr(h, f, scalar_endstr, &empty_attr); - break; - case UPB_TYPE_BOOL: - upb_handlers_setbool(h, f, putbool, &empty_attr); - break; - case UPB_TYPE_MESSAGE: - break; - default: - UPB_ASSERT(false); - break; - } - } - - UPB_UNUSED(closure); -} - -#define WRAPPER_SETHANDLERS(wrapper, type, putmethod) \ -void printer_sethandlers_##wrapper(const void *closure, upb_handlers *h) { \ - const upb_msgdef *md = upb_handlers_msgdef(h); \ - const upb_fielddef* f = upb_msgdef_itof(md, 1); \ - upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; \ - upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); \ - upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); \ - upb_handlers_set##type(h, f, putmethod, &empty_attr); \ - UPB_UNUSED(closure); \ -} - -WRAPPER_SETHANDLERS(doublevalue, double, putdouble) -WRAPPER_SETHANDLERS(floatvalue, float, putfloat) -WRAPPER_SETHANDLERS(int64value, int64, putint64_t) -WRAPPER_SETHANDLERS(uint64value, uint64, putuint64_t) -WRAPPER_SETHANDLERS(int32value, int32, putint32_t) -WRAPPER_SETHANDLERS(uint32value, uint32, putuint32_t) -WRAPPER_SETHANDLERS(boolvalue, bool, putbool) -WRAPPER_SETHANDLERS(stringvalue, string, putstr_nokey) -WRAPPER_SETHANDLERS(bytesvalue, string, putbytes) - -#undef WRAPPER_SETHANDLERS - -void printer_sethandlers_listvalue(const void *closure, upb_handlers *h) { - const upb_msgdef *md = upb_handlers_msgdef(h); - const upb_fielddef* f = upb_msgdef_itof(md, 1); - - upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; - - upb_handlers_setstartseq(h, f, startseq_nokey, &empty_attr); - upb_handlers_setendseq(h, f, endseq, &empty_attr); - - upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); - upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); - - upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr); - - UPB_UNUSED(closure); -} - -void printer_sethandlers_structvalue(const void *closure, upb_handlers *h) { - const upb_msgdef *md = upb_handlers_msgdef(h); - const upb_fielddef* f = upb_msgdef_itof(md, 1); - - upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; - - upb_handlers_setstartseq(h, f, startmap_nokey, &empty_attr); - upb_handlers_setendseq(h, f, endmap, &empty_attr); - - upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); - upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); - - upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr); - - UPB_UNUSED(closure); -} - void printer_sethandlers(const void *closure, upb_handlers *h) { const upb_msgdef *md = upb_handlers_msgdef(h); bool is_mapentry = upb_msgdef_mapentry(md); @@ -16390,42 +14787,6 @@ void printer_sethandlers(const void *closure, upb_handlers *h) { return; } - switch (upb_msgdef_wellknowntype(md)) { - case UPB_WELLKNOWN_UNSPECIFIED: - break; - case UPB_WELLKNOWN_DURATION: - printer_sethandlers_duration(closure, h); - return; - case UPB_WELLKNOWN_TIMESTAMP: - printer_sethandlers_timestamp(closure, h); - return; - case UPB_WELLKNOWN_VALUE: - printer_sethandlers_value(closure, h); - return; - case UPB_WELLKNOWN_LISTVALUE: - printer_sethandlers_listvalue(closure, h); - return; - case UPB_WELLKNOWN_STRUCT: - printer_sethandlers_structvalue(closure, h); - return; -#define WRAPPER(wellknowntype, name) \ - case wellknowntype: \ - printer_sethandlers_##name(closure, h); \ - return; \ - - WRAPPER(UPB_WELLKNOWN_DOUBLEVALUE, doublevalue); - WRAPPER(UPB_WELLKNOWN_FLOATVALUE, floatvalue); - WRAPPER(UPB_WELLKNOWN_INT64VALUE, int64value); - WRAPPER(UPB_WELLKNOWN_UINT64VALUE, uint64value); - WRAPPER(UPB_WELLKNOWN_INT32VALUE, int32value); - WRAPPER(UPB_WELLKNOWN_UINT32VALUE, uint32value); - WRAPPER(UPB_WELLKNOWN_BOOLVALUE, boolvalue); - WRAPPER(UPB_WELLKNOWN_STRINGVALUE, stringvalue); - WRAPPER(UPB_WELLKNOWN_BYTESVALUE, bytesvalue); - -#undef WRAPPER - } - upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); @@ -16533,8 +14894,6 @@ upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h, p->output_ = output; json_printer_reset(p); upb_sink_reset(&p->input_, h, p); - p->seconds = 0; - p->nanos = 0; /* If this fails, increase the value in printer.h. */ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= @@ -16552,8 +14911,3 @@ const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, return upb_handlers_newfrozen( md, owner, printer_sethandlers, &preserve_fieldnames); } - -#undef UPB_SIZE -#undef UPB_FIELD_AT -#undef UPB_READ_ONEOF -#undef UPB_WRITE_ONEOF diff --git a/ruby/ext/google/protobuf_c/upb.h b/ruby/ext/google/protobuf_c/upb.h index 0670a8123c..f441c89c83 100644 --- a/ruby/ext/google/protobuf_c/upb.h +++ b/ruby/ext/google/protobuf_c/upb.h @@ -1,116 +1,4 @@ // Amalgamated source file - -// php.h intentionally defined NDEBUG. We have to define this macro in order to -// be used together with php.h -#ifndef NDEBUG -#define NDEBUG -#endif - -#if UINTPTR_MAX == 0xffffffff -#define UPB_SIZE(size32, size64) size32 -#else -#define UPB_SIZE(size32, size64) size64 -#endif - -#define UPB_FIELD_AT(msg, fieldtype, offset) \ - *(fieldtype*)((const char*)(msg) + offset) - -#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) \ - : 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::Message is a representation for protobuf messages. -** -** However it differs from other common representations like -** google::protobuf::Message in one key way: it does not prescribe any -** ownership between messages and submessages, and it relies on the -** client to ensure that each submessage/array/map outlives its parent. -** -** All messages, arrays, and maps live in an Arena. If the entire message -** tree is in the same arena, ensuring proper lifetimes is simple. However -** the client can mix arenas as long as they ensure that there are no -** dangling pointers. -** -** A client can access a upb::Message without knowing anything about -** ownership semantics, but to create or mutate a message a user needs -** to implement the memory management themselves. -** -** TODO: UTF-8 checking? -**/ - -#ifndef UPB_MSG_H_ -#define UPB_MSG_H_ - -/* -** Defs are upb's internal representation of the constructs that can appear -** in a .proto file: -** -** - upb::MessageDef (upb_msgdef): describes a "message" construct. -** - upb::FieldDef (upb_fielddef): describes a message field. -** - upb::FileDef (upb_filedef): describes a .proto file and its defs. -** - upb::EnumDef (upb_enumdef): describes an enum. -** - upb::OneofDef (upb_oneofdef): describes a oneof. -** - upb::Def (upb_def): base class of all the others. -** -** TODO: definitions of services. -** -** Like upb_refcounted objects, defs are mutable only until frozen, and are -** only thread-safe once frozen. -** -** 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_ - -/* -** upb::RefCounted (upb_refcounted) -** -** A refcounting scheme that supports circular refs. It accomplishes this by -** partitioning the set of objects into groups such that no cycle spans groups; -** we can then reference-count the group as a whole and ignore refs within the -** group. When objects are mutable, these groups are computed very -** conservatively; we group any objects that have ever had a link between them. -** When objects are frozen, we compute strongly-connected components which -** allows us to be precise and only group objects that are actually cyclic. -** -** 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_REFCOUNTED_H_ -#define UPB_REFCOUNTED_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 /* ** This file contains shared definitions that are widely used across upb. ** @@ -849,6 +737,106 @@ template class upb::InlinedEnvironment : public upb::Environment { #endif /* UPB_H_ */ +/* +** upb_decode: parsing into a upb_msg using a upb_msglayout. +*/ + +#ifndef UPB_DECODE_H_ +#define UPB_DECODE_H_ + +/* +** upb::Message is a representation for protobuf messages. +** +** However it differs from other common representations like +** google::protobuf::Message in one key way: it does not prescribe any +** ownership between messages and submessages, and it relies on the +** client to delete each message/submessage/array/map at the appropriate +** time. +** +** A client can access a upb::Message without knowing anything about +** ownership semantics, but to create or mutate a message a user needs +** to implement the memory management themselves. +** +** Currently all messages, arrays, and maps store a upb_alloc* internally. +** Mutating operations use this when they require dynamically-allocated +** memory. We could potentially eliminate this size overhead later by +** letting the user flip a bit on the factory that prevents this from +** being stored. The user would then need to use separate functions where +** the upb_alloc* is passed explicitly. However for handlers to populate +** such structures, they would need a place to store this upb_alloc* during +** parsing; upb_handlers don't currently have a good way to accommodate this. +** +** TODO: UTF-8 checking? +**/ + +#ifndef UPB_MSG_H_ +#define UPB_MSG_H_ + +/* +** Defs are upb's internal representation of the constructs that can appear +** in a .proto file: +** +** - upb::MessageDef (upb_msgdef): describes a "message" construct. +** - upb::FieldDef (upb_fielddef): describes a message field. +** - upb::FileDef (upb_filedef): describes a .proto file and its defs. +** - upb::EnumDef (upb_enumdef): describes an enum. +** - upb::OneofDef (upb_oneofdef): describes a oneof. +** - upb::Def (upb_def): base class of all the others. +** +** TODO: definitions of services. +** +** Like upb_refcounted objects, defs are mutable only until frozen, and are +** only thread-safe once frozen. +** +** 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_ + +/* +** upb::RefCounted (upb_refcounted) +** +** A refcounting scheme that supports circular refs. It accomplishes this by +** partitioning the set of objects into groups such that no cycle spans groups; +** we can then reference-count the group as a whole and ignore refs within the +** group. When objects are mutable, these groups are computed very +** conservatively; we group any objects that have ever had a link between them. +** When objects are frozen, we compute strongly-connected components which +** allows us to be precise and only group objects that are actually cyclic. +** +** 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_REFCOUNTED_H_ +#define UPB_REFCOUNTED_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" { @@ -2007,34 +1995,6 @@ typedef enum { UPB_SYNTAX_PROTO3 = 3 } upb_syntax_t; -/* All the different kind of well known type messages. For simplicity of check, - * number wrappers and string wrappers are grouped together. Make sure the - * order and merber of these groups are not changed. - */ -typedef enum { - UPB_WELLKNOWN_UNSPECIFIED, - UPB_WELLKNOWN_DURATION, - UPB_WELLKNOWN_TIMESTAMP, - /* number wrappers */ - UPB_WELLKNOWN_DOUBLEVALUE, - UPB_WELLKNOWN_FLOATVALUE, - UPB_WELLKNOWN_INT64VALUE, - UPB_WELLKNOWN_UINT64VALUE, - UPB_WELLKNOWN_INT32VALUE, - UPB_WELLKNOWN_UINT32VALUE, - /* string wrappers */ - UPB_WELLKNOWN_STRINGVALUE, - UPB_WELLKNOWN_BYTESVALUE, - UPB_WELLKNOWN_BOOLVALUE, - UPB_WELLKNOWN_VALUE, - UPB_WELLKNOWN_LISTVALUE, - UPB_WELLKNOWN_STRUCT -} upb_wellknowntype_t; - - -/* Maps descriptor type -> upb field type. */ -extern const uint8_t upb_desctype_to_fieldtype[]; - /* Maximum field number allowed for FieldDefs. This is an inherent limit of the * protobuf wire format. */ #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) @@ -2416,14 +2376,6 @@ typedef upb_strtable_iter upb_msg_oneof_iter; #define UPB_MAPENTRY_KEY 1 #define UPB_MAPENTRY_VALUE 2 -/* Well-known field tag numbers for timestamp messages. */ -#define UPB_DURATION_SECONDS 1 -#define UPB_DURATION_NANOS 2 - -/* Well-known field tag numbers for duration messages. */ -#define UPB_TIMESTAMP_SECONDS 1 -#define UPB_TIMESTAMP_NANOS 2 - #ifdef __cplusplus /* Structure that describes a single .proto message type. @@ -2538,13 +2490,6 @@ class upb::MessageDef { void setmapentry(bool map_entry); bool mapentry() const; - /* Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for - * non-well-known message. */ - upb_wellknowntype_t wellknowntype() const; - - /* Whether is a number wrapper. */ - bool isnumberwrapper() const; - /* Iteration over fields. The order is undefined. */ class field_iterator : public std::iterator { @@ -2686,8 +2631,6 @@ bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s); void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry); 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); /* Field lookup in a couple of different variations: @@ -3627,12 +3570,6 @@ inline void MessageDef::setmapentry(bool map_entry) { inline bool MessageDef::mapentry() const { return upb_msgdef_mapentry(this); } -inline upb_wellknowntype_t MessageDef::wellknowntype() const { - return upb_msgdef_wellknowntype(this); -} -inline bool MessageDef::isnumberwrapper() const { - return upb_msgdef_isnumberwrapper(this); -} inline MessageDef::field_iterator MessageDef::field_begin() { return field_iterator(this); } @@ -4760,34 +4697,6 @@ UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) { uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f); uint32_t upb_handlers_selectorcount(const upb_fielddef *f); - -/** Message handlers ******************************************************************/ - -/* These are the handlers used internally by upb_msgfactory_getmergehandlers(). - * They write scalar data to a known offset from the message pointer. - * - * These would be trivial for anyone to implement themselves, but it's better - * to use these because some JITs will recognize and specialize these instead - * of actually calling the function. */ - -/* Sets a handler for the given primitive field that will write the data at the - * given offset. If hasbit > 0, also sets a hasbit at the given bit offset - * (addressing each byte low to high). */ -bool upb_msg_setscalarhandler(upb_handlers *h, - const upb_fielddef *f, - size_t offset, - int32_t hasbit); - -/* If the given handler is a msghandlers_primitive field, returns true and sets - * *type, *offset and *hasbit. Otherwise returns false. */ -bool upb_msg_getscalarhandlerdata(const upb_handlers *h, - upb_selector_t s, - upb_fieldtype_t *type, - size_t *offset, - int32_t *hasbit); - - - UPB_END_EXTERN_C /* @@ -6472,14 +6381,21 @@ namespace upb { class Array; class Map; class MapIterator; +class MessageFactory; class MessageLayout; +class Visitor; +class VisitorPlan; } #endif +UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory) +UPB_DECLARE_TYPE(upb::MessageLayout, upb_msglayout) UPB_DECLARE_TYPE(upb::Array, upb_array) UPB_DECLARE_TYPE(upb::Map, upb_map) UPB_DECLARE_TYPE(upb::MapIterator, upb_mapiter) +UPB_DECLARE_TYPE(upb::Visitor, upb_visitor) +UPB_DECLARE_TYPE(upb::VisitorPlan, upb_visitorplan) /* TODO(haberman): C++ accessors */ @@ -6490,54 +6406,79 @@ typedef void upb_msg; /** upb_msglayout *************************************************************/ -/* 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. */ - -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; +/* upb_msglayout represents the memory layout of a given upb_msgdef. You get + * instances of this from a upb_msgfactory, and the factory always owns the + * msglayout. */ -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_visitor ***************************************************************/ -/** upb_stringview ************************************************************/ +/* upb_visitor will visit all the fields of a message and its submessages. It + * uses a upb_visitorplan which you can obtain from a upb_msgfactory. */ -typedef struct { - const char *data; - size_t size; -} upb_stringview; +upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp, + upb_sink *output); +bool upb_visitor_visitmsg(upb_visitor *v, const upb_msg *msg); -UPB_INLINE upb_stringview upb_stringview_make(const char *data, size_t size) { - upb_stringview ret; - ret.data = data; - ret.size = size; - return ret; -} -#define UPB_STRINGVIEW_INIT(ptr, len) {ptr, len} +/** upb_msgfactory ************************************************************/ +/* 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. + */ -/** upb_msgval ****************************************************************/ +/* 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); -/* A union representing all possible protobuf values. Used for generic get/set - * operations. */ +const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f); -typedef union { - bool b; +/* 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). + * + * The returned objects will live for as long as the msgfactory does. + * + * 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); +const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f, + const upb_msgdef *m); +const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f, + const upb_handlers *h); + + +/** upb_stringview ************************************************************/ + +typedef struct { + const char *data; + size_t size; +} upb_stringview; + +UPB_INLINE upb_stringview upb_stringview_make(const char *data, size_t size) { + upb_stringview ret; + ret.data = data; + ret.size = size; + return ret; +} + +#define UPB_STRINGVIEW_INIT(ptr, len) {ptr, len} + + +/** upb_msgval ****************************************************************/ + +/* A union representing all possible protobuf values. Used for generic get/set + * operations. */ + +typedef union { + bool b; float flt; double dbl; int32_t i32; @@ -6587,16 +6528,52 @@ UPB_INLINE upb_msgval upb_msgval_makestr(const char *data, size_t size) { /** upb_msg *******************************************************************/ /* A upb_msg represents a protobuf message. It always corresponds to a specific - * upb_msglayout, which describes how it is laid out in memory. */ - -/* Creates a new message of the given type/layout in this arena. */ -upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a); + * upb_msglayout, which describes how it is laid out in memory. + * + * The message will have a fixed size, as returned by upb_msg_sizeof(), which + * will be used to store fixed-length fields. The upb_msg may also allocate + * dynamic memory internally to store data such as: + * + * - extensions + * - unknown fields + */ -/* Returns the arena for the given message. */ -upb_arena *upb_msg_arena(const upb_msg *msg); +/* Returns the size of a message given this layout. */ +size_t upb_msg_sizeof(const upb_msglayout *l); -void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len); -const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); +/* upb_msg_init() / upb_msg_uninit() allow the user to use a pre-allocated + * block of memory as a message. The block's size should be upb_msg_sizeof(). + * upb_msg_uninit() must be called to release internally-allocated memory + * unless the allocator is an arena that does not require freeing. + * + * Please note that upb_msg_init() may return a value that is different than + * |msg|, so you must assign the return value and not cast your memory block + * to upb_msg* directly! + * + * Please note that upb_msg_uninit() does *not* free any submessages, maps, + * or arrays referred to by this message's fields. You must free them manually + * yourself. + * + * upb_msg_uninit returns the original memory block, which may be useful if + * you dynamically allocated it (though upb_msg_new() would normally be more + * appropriate in this case). */ +upb_msg *upb_msg_init(void *msg, const upb_msglayout *l, upb_alloc *a); +void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l); + +/* Like upb_msg_init() / upb_msg_uninit(), except the message's memory is + * allocated / freed from the given upb_alloc. */ +upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a); +void upb_msg_free(upb_msg *msg, const upb_msglayout *l); + +/* Returns the upb_alloc for the given message. + * TODO(haberman): get rid of this? Not sure we want to be storing this + * for every message. */ +upb_alloc *upb_msg_alloc(const upb_msg *msg); + +/* Packs the tree of messages rooted at "msg" into a single hunk of memory, + * allocated from the given allocator. */ +void *upb_msg_pack(const upb_msg *msg, const upb_msglayout *l, + void *p, size_t *ofs, size_t size); /* Read-only message API. Can be safely called by anyone. */ @@ -6650,12 +6627,16 @@ bool upb_msg_clearfield(upb_msg *msg, * semantics are the same as upb_msg. A upb_array allocates dynamic * memory internally for the array elements. */ -upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a); -upb_fieldtype_t upb_array_type(const upb_array *arr); +size_t upb_array_sizeof(upb_fieldtype_t type); +void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *a); +void upb_array_uninit(upb_array *arr); +upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a); +void upb_array_free(upb_array *arr); /* Read-only interface. Safe for anyone to call. */ size_t upb_array_size(const upb_array *arr); +upb_fieldtype_t upb_array_type(const upb_array *arr); upb_msgval upb_array_get(const upb_array *arr, size_t i); /* Write interface. May only be called by the message's owner who can enforce @@ -6672,8 +6653,12 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val); * So you must ensure that any string or message values outlive the map, and you * must delete them manually when they are no longer required. */ -upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_arena *a); +size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype); +bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype, + upb_alloc *a); +void upb_map_uninit(upb_map *map); +upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, upb_alloc *a); +void upb_map_free(upb_map *map); /* Read-only interface. Safe for anyone to call. */ @@ -6717,869 +6702,90 @@ upb_msgval upb_mapiter_value(const upb_mapiter *i); void upb_mapiter_setdone(upb_mapiter *i); bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2); -UPB_END_EXTERN_C - -#endif /* UPB_MSG_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_ +/** Handlers ******************************************************************/ -/* -** upb_decode: parsing into a upb_msg using a upb_msglayout. -*/ +/* These are the handlers used internally by upb_msgfactory_getmergehandlers(). + * They write scalar data to a known offset from the message pointer. + * + * These would be trivial for anyone to implement themselves, but it's better + * to use these because some JITs will recognize and specialize these instead + * of actually calling the function. */ -#ifndef UPB_DECODE_H_ -#define UPB_DECODE_H_ +/* Sets a handler for the given primitive field that will write the data at the + * given offset. If hasbit > 0, also sets a hasbit at the given bit offset + * (addressing each byte low to high). */ +bool upb_msg_setscalarhandler(upb_handlers *h, + const upb_fielddef *f, + size_t offset, + int32_t hasbit); +/* If the given handler is a msghandlers_primitive field, returns true and sets + * *type, *offset and *hasbit. Otherwise returns false. */ +bool upb_msg_getscalarhandlerdata(const upb_handlers *h, + upb_selector_t s, + upb_fieldtype_t *type, + size_t *offset, + int32_t *hasbit); -UPB_BEGIN_EXTERN_C -bool upb_decode(upb_stringview buf, upb_msg *msg, const upb_msglayout *l); +/** Interfaces for generated code *********************************************/ -UPB_END_EXTERN_C +#define UPB_NOT_IN_ONEOF UINT16_MAX +#define UPB_NO_HASBIT UINT16_MAX +#define UPB_NO_SUBMSG UINT16_MAX -#endif /* UPB_DECODE_H_ */ -/* -** upb_encode: parsing into a upb_msg using a upb_msglayout. -*/ - -#ifndef UPB_ENCODE_H_ -#define UPB_ENCODE_H_ +typedef struct { + uint32_t number; + uint32_t offset; /* If in a oneof, offset of default in default_msg below. */ + uint16_t hasbit; /* UPB_NO_HASBIT if no hasbit. */ + uint16_t oneof_index; /* UPB_NOT_IN_ONEOF if not in a oneof. */ + uint16_t submsg_index; /* UPB_NO_SUBMSG if no submsg. */ + uint8_t type; + uint8_t label; +} upb_msglayout_fieldinit_v1; +typedef struct { + uint32_t data_offset; + uint32_t case_offset; +} upb_msglayout_oneofinit_v1; + +typedef struct upb_msglayout_msginit_v1 { + const struct upb_msglayout_msginit_v1 *const* submsgs; + const upb_msglayout_fieldinit_v1 *fields; + const upb_msglayout_oneofinit_v1 *oneofs; + void *default_msg; + /* Must be aligned to sizeof(void*). Doesn't include internal members like + * unknown fields, extension dict, pointer to msglayout, etc. */ + uint32_t size; + uint16_t field_count; + uint16_t oneof_count; + bool extendable; + bool is_proto2; +} upb_msglayout_msginit_v1; -UPB_BEGIN_EXTERN_C +#define UPB_ALIGN_UP_TO(val, align) ((val + (align - 1)) & -align) +#define UPB_ALIGNED_SIZEOF(type) UPB_ALIGN_UP_TO(sizeof(type), sizeof(void*)) -char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena, - size_t *size); +/* Initialize/uninitialize a msglayout from a msginit. If upb uses v1 + * internally, this will not allocate any memory. Should only be used by + * generated code. */ +upb_msglayout *upb_msglayout_frominit_v1( + const upb_msglayout_msginit_v1 *init, upb_alloc *a); +void upb_msglayout_uninit_v1(upb_msglayout *layout, upb_alloc *a); UPB_END_EXTERN_C -#endif /* UPB_ENCODE_H_ */ -UPB_BEGIN_EXTERN_C - -struct google_protobuf_FileDescriptorSet; -struct google_protobuf_FileDescriptorProto; -struct google_protobuf_DescriptorProto; -struct google_protobuf_DescriptorProto_ExtensionRange; -struct google_protobuf_DescriptorProto_ReservedRange; -struct google_protobuf_ExtensionRangeOptions; -struct google_protobuf_FieldDescriptorProto; -struct google_protobuf_OneofDescriptorProto; -struct google_protobuf_EnumDescriptorProto; -struct google_protobuf_EnumDescriptorProto_EnumReservedRange; -struct google_protobuf_EnumValueDescriptorProto; -struct google_protobuf_ServiceDescriptorProto; -struct google_protobuf_MethodDescriptorProto; -struct google_protobuf_FileOptions; -struct google_protobuf_MessageOptions; -struct google_protobuf_FieldOptions; -struct google_protobuf_OneofOptions; -struct google_protobuf_EnumOptions; -struct google_protobuf_EnumValueOptions; -struct google_protobuf_ServiceOptions; -struct google_protobuf_MethodOptions; -struct google_protobuf_UninterpretedOption; -struct google_protobuf_UninterpretedOption_NamePart; -struct google_protobuf_SourceCodeInfo; -struct google_protobuf_SourceCodeInfo_Location; -struct google_protobuf_GeneratedCodeInfo; -struct google_protobuf_GeneratedCodeInfo_Annotation; -typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; -typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; -typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; -typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; -typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; -typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; -typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; -typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; -typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; -typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; -typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; -typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; -typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; -typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; -typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; -typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; -typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; -typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; -typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; -typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; -typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; -typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; -typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; -typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; -typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; - -/* Enums */ - -typedef enum { - google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, - google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, - google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3 -} google_protobuf_FieldDescriptorProto_Label; - -typedef enum { - google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1, - google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2, - google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3, - google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4, - google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5, - google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6, - google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7, - google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8, - google_protobuf_FieldDescriptorProto_TYPE_STRING = 9, - google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10, - google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11, - google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12, - google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13, - google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15, - google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16, - google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17, - google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18 -} google_protobuf_FieldDescriptorProto_Type; - -typedef enum { - google_protobuf_FieldOptions_STRING = 0, - google_protobuf_FieldOptions_CORD = 1, - google_protobuf_FieldOptions_STRING_PIECE = 2 -} google_protobuf_FieldOptions_CType; - -typedef enum { - google_protobuf_FieldOptions_JS_NORMAL = 0, - google_protobuf_FieldOptions_JS_STRING = 1, - google_protobuf_FieldOptions_JS_NUMBER = 2 -} google_protobuf_FieldOptions_JSType; - -typedef enum { - google_protobuf_FileOptions_SPEED = 1, - google_protobuf_FileOptions_CODE_SIZE = 2, - google_protobuf_FileOptions_LITE_RUNTIME = 3 -} google_protobuf_FileOptions_OptimizeMode; - -typedef enum { - google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0, - google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1, - google_protobuf_MethodOptions_IDEMPOTENT = 2 -} google_protobuf_MethodOptions_IdempotencyLevel; - -/* google.protobuf.FileDescriptorSet */ - -extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit; -UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena); -} -UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorSet_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } - -UPB_INLINE void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileDescriptorSet *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } - - -/* google.protobuf.FileDescriptorProto */ - -extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit; -UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } -UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(40, 80)); } -UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(44, 88)); } -UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(48, 96)); } -UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(52, 104)); } -UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(56, 112)); } -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(32, 64)); } -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(36, 72)); } -UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(60, 120)); } -UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(64, 128)); } -UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)); } - -UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(40, 80)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_message_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(44, 88)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_enum_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(48, 96)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_service(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(52, 104)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_extension(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(56, 112)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { UPB_FIELD_AT(msg, google_protobuf_FileOptions*, UPB_SIZE(32, 64)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { UPB_FIELD_AT(msg, google_protobuf_SourceCodeInfo*, UPB_SIZE(36, 72)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_public_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(60, 120)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_weak_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(64, 128)) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)) = value; } - - -/* google.protobuf.DescriptorProto */ - -extern const upb_msglayout google_protobuf_DescriptorProto_msginit; -UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(32, 64)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(36, 72)); } -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(16, 32)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(40, 80)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(44, 88)); } -UPB_INLINE const upb_array* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(48, 96)); } - -UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_field(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_nested_type(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_enum_type(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_extension_range(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(32, 64)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_extension(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(36, 72)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { UPB_FIELD_AT(msg, google_protobuf_MessageOptions*, UPB_SIZE(16, 32)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_oneof_decl(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(40, 80)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_range(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(44, 88)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_name(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(48, 96)) = value; } - - -/* google.protobuf.DescriptorProto.ExtensionRange */ - -extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit; -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); -} -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len); -} - -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_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } -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 void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { UPB_FIELD_AT(msg, google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)) = value; } - - -/* google.protobuf.DescriptorProto.ReservedRange */ - -extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit; -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); -} -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len); -} - -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_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } - -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } -UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } - - -/* google.protobuf.ExtensionRangeOptions */ - -extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit; -UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); -} -UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_ExtensionRangeOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } - -UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } - - -/* google.protobuf.FieldDescriptorProto */ - -extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit; -UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_FieldDescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } -UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } -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 google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)); } -UPB_INLINE google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)); } -UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } -UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)); } -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_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)); } -UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)); } - -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value) { UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value) { UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions*, UPB_SIZE(72, 112)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)) = value; } - - -/* google.protobuf.OneofDescriptorProto */ - -extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit; -UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_OneofDescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -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(16, 32)); } - -UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { UPB_FIELD_AT(msg, google_protobuf_OneofOptions*, UPB_SIZE(16, 32)) = value; } - - -/* google.protobuf.EnumDescriptorProto */ - -extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit; -UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } -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(16, 32)); } -UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } -UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } - -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_value(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { UPB_FIELD_AT(msg, google_protobuf_EnumOptions*, UPB_SIZE(16, 32)) = value; } -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } - - -/* google.protobuf.EnumDescriptorProto.EnumReservedRange */ - -extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); -} -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len); -} - -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_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } - -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } -UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } - - -/* google.protobuf.EnumValueDescriptorProto */ - -extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit; -UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueDescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -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 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, 32)); } - -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { UPB_FIELD_AT(msg, google_protobuf_EnumValueOptions*, UPB_SIZE(16, 32)) = value; } - - -/* google.protobuf.ServiceDescriptorProto */ - -extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit; -UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_ServiceDescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -UPB_INLINE const upb_array* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } -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(16, 32)); } - -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_method(google_protobuf_ServiceDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { UPB_FIELD_AT(msg, google_protobuf_ServiceOptions*, UPB_SIZE(16, 32)) = value; } - - -/* google.protobuf.MethodDescriptorProto */ - -extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit; -UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); -} -UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_MethodDescriptorProto_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } -UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)); } -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(32, 64)); } -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_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } - -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)) = value; } -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { UPB_FIELD_AT(msg, google_protobuf_MethodOptions*, UPB_SIZE(32, 64)) = value; } -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } - - -/* google.protobuf.FileOptions */ - -extern const upb_msglayout google_protobuf_FileOptions_msginit; -UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_FileOptions_msginit, arena); -} -UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_FileOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } -UPB_INLINE upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } -UPB_INLINE google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)); } -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 upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } -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_java_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)); } -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_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_deprecated(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)); } -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_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)); } -UPB_INLINE upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)); } -UPB_INLINE upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)); } -UPB_INLINE upb_stringview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(72, 112)); } -UPB_INLINE upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(80, 128)); } -UPB_INLINE upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(88, 144)); } -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 const upb_array* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(96, 160)); } - -UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value) { UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(72, 112)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(80, 128)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(88, 144)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_uninterpreted_option(google_protobuf_FileOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(96, 160)) = value; } - - -/* google.protobuf.MessageOptions */ - -extern const upb_msglayout google_protobuf_MessageOptions_msginit; -UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); -} -UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_MessageOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len); -} - -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_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_deprecated(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)); } -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 const upb_array* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(8, 8)); } - -UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } -UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } -UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)) = value; } -UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)) = value; } -UPB_INLINE void google_protobuf_MessageOptions_set_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(8, 8)) = value; } - - -/* google.protobuf.FieldOptions */ - -extern const upb_msglayout google_protobuf_FieldOptions_msginit; -UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); -} -UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_FieldOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len); -} - -UPB_INLINE google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)); } -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_deprecated(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)); } -UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)); } -UPB_INLINE google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)); } -UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)); } -UPB_INLINE const upb_array* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 32)); } - -UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)) = value; } -UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; } -UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)) = value; } -UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)) = value; } -UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)) = value; } -UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)) = value; } -UPB_INLINE void google_protobuf_FieldOptions_set_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 32)) = value; } - - -/* google.protobuf.OneofOptions */ - -extern const upb_msglayout google_protobuf_OneofOptions_msginit; -UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); -} -UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_OneofOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } - -UPB_INLINE void google_protobuf_OneofOptions_set_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } - - -/* google.protobuf.EnumOptions */ - -extern const upb_msglayout google_protobuf_EnumOptions_msginit; -UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); -} -UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_EnumOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len); -} - -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_deprecated(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } -UPB_INLINE const upb_array* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } - -UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } -UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } -UPB_INLINE void google_protobuf_EnumOptions_set_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } - - -/* google.protobuf.EnumValueOptions */ - -extern const upb_msglayout google_protobuf_EnumValueOptions_msginit; -UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); -} -UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len); -} - -UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } -UPB_INLINE const upb_array* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } - -UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } -UPB_INLINE void google_protobuf_EnumValueOptions_set_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } - - -/* google.protobuf.ServiceOptions */ - -extern const upb_msglayout google_protobuf_ServiceOptions_msginit; -UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); -} -UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_ServiceOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len); -} - -UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } -UPB_INLINE const upb_array* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } - -UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } -UPB_INLINE void google_protobuf_ServiceOptions_set_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } - - -/* google.protobuf.MethodOptions */ - -extern const upb_msglayout google_protobuf_MethodOptions_msginit; -UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); -} -UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_MethodOptions_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len); -} - -UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); } -UPB_INLINE google_protobuf_MethodOptions_IdempotencyLevel google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)); } -UPB_INLINE const upb_array* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 24)); } - -UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; } -UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, google_protobuf_MethodOptions_IdempotencyLevel value) { UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)) = value; } -UPB_INLINE void google_protobuf_MethodOptions_set_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 24)) = value; } - - -/* google.protobuf.UninterpretedOption */ - -extern const upb_msglayout google_protobuf_UninterpretedOption_msginit; -UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); -} -UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(56, 80)); } -UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } -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 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 double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)); } -UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } -UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } - -UPB_INLINE void google_protobuf_UninterpretedOption_set_name(google_protobuf_UninterpretedOption *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(56, 80)) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } - - -/* google.protobuf.UninterpretedOption.NamePart */ - -extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit; -UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); -} -UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_NamePart_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len); -} - -UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -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 void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } - - -/* google.protobuf.SourceCodeInfo */ - -extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit; -UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); -} -UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } - -UPB_INLINE void google_protobuf_SourceCodeInfo_set_location(google_protobuf_SourceCodeInfo *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } - - -/* google.protobuf.SourceCodeInfo.Location */ - -extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit; -UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); -} -UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_Location_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } -UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } -UPB_INLINE upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } -UPB_INLINE upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } -UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(32, 64)); } - -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_path(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_span(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(32, 64)) = value; } - - -/* google.protobuf.GeneratedCodeInfo */ - -extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit; -UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena); -} -UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } - -UPB_INLINE void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } - - -/* google.protobuf.GeneratedCodeInfo.Annotation */ - -extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit; -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { - return upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); -} -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parsenew(upb_stringview buf, upb_arena *arena) { - google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit)) ? ret : NULL; -} -UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len); -} - -UPB_INLINE const upb_array* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 32)); } -UPB_INLINE upb_stringview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 16)); } -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_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +#endif /* UPB_MSG_H_ */ -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 32)) = value; } -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 16)) = value; } -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } +UPB_BEGIN_EXTERN_C +bool upb_decode(upb_stringview buf, void *msg, + const upb_msglayout_msginit_v1 *l, upb_env *env); UPB_END_EXTERN_C - -#endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */ +#endif /* UPB_DECODE_H_ */ /* ** structs.int.h: structures definitions that are internal to upb. */ @@ -7593,7 +6799,7 @@ struct upb_array { void *data; /* Each element is element_size. */ size_t len; /* Measured in elements. */ size_t size; /* Measured in elements. */ - upb_arena *arena; + upb_alloc *alloc; }; #endif /* UPB_STRUCTS_H_ */ @@ -7714,10 +6920,6 @@ struct upb_msgdef { /* Whether this message has proto2 or proto3 semantics. */ upb_syntax_t syntax; - /* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for - * non-well-known message. */ - upb_wellknowntype_t well_known_type; - /* TODO(haberman): proper extension ranges (there can be multiple). */ }; @@ -7726,11 +6928,10 @@ extern const struct upb_refcounted_vtbl upb_msgdef_vtbl; /* TODO: also support static initialization of the oneofs table. This will be * needed if we compile in descriptors that contain oneofs. */ #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ - map_entry, syntax, well_known_type, refs, ref2s) \ + map_entry, syntax, refs, ref2s) \ { \ UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \ - selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \ - well_known_type \ + selector_count, submsg_field_count, itof, ntof, map_entry, syntax \ } @@ -7793,44 +6994,22 @@ struct upb_filedef { extern const struct upb_refcounted_vtbl upb_filedef_vtbl; #endif /* UPB_STATICINIT_H_ */ +/* +** upb_encode: parsing into a upb_msg using a upb_msglayout. +*/ +#ifndef UPB_ENCODE_H_ +#define UPB_ENCODE_H_ -#ifndef UPB_MSGFACTORY_H_ -#define UPB_MSGFACTORY_H_ - -UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory) - -/** upb_msgfactory ************************************************************/ - -/* 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. - */ - -/* 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); -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f); +UPB_BEGIN_EXTERN_C -/* 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). - * - * The returned objects will live for as long as the msgfactory does. - * - * 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); +char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *l, + upb_env *env, size_t *size); +UPB_END_EXTERN_C -#endif /* UPB_MSGFACTORY_H_ */ +#endif /* UPB_ENCODE_H_ */ /* ** upb::descriptor::Reader (upb_descreader) ** @@ -7933,6 +7112,53 @@ inline FileDef* Reader::file(size_t i) const { UPB_BEGIN_EXTERN_C +/* Enums */ + +typedef enum { + google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, + google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, + google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3 +} google_protobuf_FieldDescriptorProto_Label; + +typedef enum { + google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1, + google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2, + google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3, + google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4, + google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5, + google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6, + google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7, + google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8, + google_protobuf_FieldDescriptorProto_TYPE_STRING = 9, + google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10, + google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11, + google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12, + google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13, + google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14, + google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15, + google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16, + google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17, + google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18 +} google_protobuf_FieldDescriptorProto_Type; + +typedef enum { + google_protobuf_FieldOptions_STRING = 0, + google_protobuf_FieldOptions_CORD = 1, + google_protobuf_FieldOptions_STRING_PIECE = 2 +} google_protobuf_FieldOptions_CType; + +typedef enum { + google_protobuf_FieldOptions_JS_NORMAL = 0, + google_protobuf_FieldOptions_JS_STRING = 1, + google_protobuf_FieldOptions_JS_NUMBER = 2 +} google_protobuf_FieldOptions_JSType; + +typedef enum { + google_protobuf_FileOptions_SPEED = 1, + google_protobuf_FileOptions_CODE_SIZE = 2, + google_protobuf_FileOptions_LITE_RUNTIME = 3 +} google_protobuf_FileOptions_OptimizeMode; + /* MessageDefs: call these functions to get a ref to a msgdef. */ const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner); const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(const void *owner); @@ -9567,7 +8793,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, * constructed. This hint may be an overestimate for some build configurations. * But if the parser library is upgraded without recompiling the application, * it may be an underestimate. */ -#define UPB_JSON_PARSER_SIZE 4160 +#define UPB_JSON_PARSER_SIZE 4112 #ifdef __cplusplus @@ -9576,7 +8802,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, class upb::json::Parser { public: static Parser* Create(Environment* env, const ParserMethod* method, - Sink* output, bool ignore_json_unknown); + Sink* output); BytesSink* input(); @@ -9610,8 +8836,7 @@ UPB_BEGIN_EXTERN_C upb_json_parser* upb_json_parser_create(upb_env* e, const upb_json_parsermethod* m, - upb_sink* output, - bool ignore_json_unknown); + upb_sink* output); upb_bytessink *upb_json_parser_input(upb_json_parser *p); upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md, @@ -9631,8 +8856,8 @@ UPB_END_EXTERN_C namespace upb { namespace json { inline Parser* Parser::Create(Environment* env, const ParserMethod* method, - Sink* output, bool ignore_json_unknown) { - return upb_json_parser_create(env, method, output, ignore_json_unknown); + Sink* output) { + return upb_json_parser_create(env, method, output); } inline BytesSink* Parser::input() { return upb_json_parser_input(this); @@ -9681,7 +8906,7 @@ UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer) /* upb::json::Printer *********************************************************/ -#define UPB_JSON_PRINTER_SIZE 192 +#define UPB_JSON_PRINTER_SIZE 176 #ifdef __cplusplus @@ -9742,8 +8967,3 @@ inline reffed_ptr Printer::NewHandlers( #endif #endif /* UPB_JSON_TYPED_PRINTER_H_ */ - -#undef UPB_SIZE -#undef UPB_FIELD_AT -#undef UPB_READ_ONEOF -#undef UPB_WRITE_ONEOF diff --git a/ruby/lib/google/protobuf.rb b/ruby/lib/google/protobuf.rb index 464982e303..e20a584e80 100644 --- a/ruby/lib/google/protobuf.rb +++ b/ruby/lib/google/protobuf.rb @@ -69,8 +69,8 @@ module Google klass.decode(proto) end - def self.decode_json(klass, json, options = {}) - klass.decode_json(json, options) + def self.decode_json(klass, json) + klass.decode_json(json) end end diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 5e17bef65b..77dfead404 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -254,19 +254,6 @@ module BasicTest "b" => TestMessage2.new(:foo => 2)} end - def test_protobuf_decode_json_ignore_unknown_fields - m = TestMessage.decode_json({ - optional_string: "foo", - not_in_message: "some_value" - }.to_json, { ignore_unknown_fields: true }) - - assert_equal m.optional_string, "foo" - e = assert_raise Google::Protobuf::ParseError do - TestMessage.decode_json({ not_in_message: "some_value" }.to_json) - end - assert_match(/No such field: not_in_message/, e.message) - end - def test_to_h m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)]) expected_result = { From 595cb359c0317885ec05d88a85ae5e4287f6eac4 Mon Sep 17 00:00:00 2001 From: Keith Moyer Date: Thu, 27 Dec 2018 13:42:08 -0800 Subject: [PATCH 43/70] Rely on no-writable-strings synonym The -Wno-writable-strings warning flag is Clang-specific. GCC's equivalent is -Wno-write-strings, which Clang also supports as a synonym. So, -Wno-write strings is more compatible and there is no need to specify both. https://clang.llvm.org/docs/DiagnosticsReference.html#wwrite-strings https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html --- BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/BUILD b/BUILD index 253bc3edb2..1664621e95 100644 --- a/BUILD +++ b/BUILD @@ -54,7 +54,6 @@ COPTS = select({ "-Wno-sign-compare", "-Wno-unused-function", # Prevents ISO C++ const string assignment warnings for pyext sources. - "-Wno-writable-strings", "-Wno-write-strings", ], }) From b5f9a35b165a44ea9ca1bcfe91d887b378b6441d Mon Sep 17 00:00:00 2001 From: Hao Nguyen <45579440+haon4@users.noreply.github.com> Date: Wed, 2 Jan 2019 15:10:38 -0800 Subject: [PATCH 44/70] Down-integrate internal changes to github. (#5527) --- .../protobuf/compiler/js/js_generator.cc | 39 ++++++----- .../protobuf/generated_message_reflection.cc | 4 +- src/google/protobuf/map_field.cc | 58 ++++++++++++++--- src/google/protobuf/map_field.h | 8 ++- src/google/protobuf/map_field_inl.h | 10 ++- src/google/protobuf/map_field_test.cc | 13 ++-- src/google/protobuf/map_test_util.cc | 4 ++ .../util/internal/protostream_objectsource.cc | 19 +++--- .../util/internal/protostream_objectsource.h | 9 ++- .../protobuf/util/type_resolver_util.cc | 41 +++++++++--- .../protobuf/util/type_resolver_util_test.cc | 65 +++++++++++++++++-- 11 files changed, 203 insertions(+), 67 deletions(-) diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index db19ff58dd..06383936de 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2848,44 +2848,50 @@ void Generator::GenerateClassField(const GeneratorOptions& options, // fields with presence. if (field->is_map()) { printer->Print( + "/** Clears values from the map. The map will be non-null. */\n" "$class$.prototype.$clearername$ = function() {\n" " this.$gettername$().clear();$returnvalue$\n" "};\n" "\n" "\n", "class", GetMessagePath(options, field->containing_type()), - "clearername", "clear" + JSGetterName(options, field), - "gettername", "get" + JSGetterName(options, field), - "returnvalue", JSReturnClause(field)); + "clearername", "clear" + JSGetterName(options, field), "gettername", + "get" + JSGetterName(options, field), "returnvalue", + JSReturnClause(field)); printer->Annotate("clearername", field); } else if (field->is_repeated() || (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !field->is_required())) { // Fields where we can delegate to the regular setter. printer->Print( + "/** $jsdoc$ */\n" "$class$.prototype.$clearername$ = function() {\n" " this.$settername$($clearedvalue$);$returnvalue$\n" "};\n" "\n" "\n", + "jsdoc", + field->is_repeated() ? "Clears the list making it empty but non-null." + : "Clears the message field making it undefined.", "class", GetMessagePath(options, field->containing_type()), - "clearername", "clear" + JSGetterName(options, field), - "settername", "set" + JSGetterName(options, field), - "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), - "returnvalue", JSReturnClause(field)); + "clearername", "clear" + JSGetterName(options, field), "settername", + "set" + JSGetterName(options, field), "clearedvalue", + (field->is_repeated() ? "[]" : "undefined"), "returnvalue", + JSReturnClause(field)); printer->Annotate("clearername", field); } else if (HasFieldPresence(options, field)) { // Fields where we can't delegate to the regular setter because it doesn't // accept "undefined" as an argument. printer->Print( + "/** Clears the field making it undefined. */\n" "$class$.prototype.$clearername$ = function() {\n" " jspb.Message.set$maybeoneof$Field(this, " "$index$$maybeoneofgroup$, ", "class", GetMessagePath(options, field->containing_type()), - "clearername", "clear" + JSGetterName(options, field), - "maybeoneof", (field->containing_oneof() ? "Oneof" : ""), - "maybeoneofgroup", (field->containing_oneof() ? - (", " + JSOneofArray(options, field)) : ""), + "clearername", "clear" + JSGetterName(options, field), "maybeoneof", + (field->containing_oneof() ? "Oneof" : ""), "maybeoneofgroup", + (field->containing_oneof() ? (", " + JSOneofArray(options, field)) + : ""), "index", JSFieldIndex(field)); printer->Annotate("clearername", field); printer->Print( @@ -2963,14 +2969,15 @@ void Generator::GenerateRepeatedMessageHelperMethods( " * @param {number=} opt_index\n" " * @return {!$optionaltype$}\n" " */\n" - "$class$.prototype.add$name$ = function(opt_value, opt_index) {\n" + "$class$.prototype.$addername$ = function(opt_value, opt_index) {\n" " return jspb.Message.addTo$repeatedtag$WrapperField(", - "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), - "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field, BYTES_DEFAULT, - /* drop_list = */ true), + "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "class", + GetMessagePath(options, field->containing_type()), "addername", + "add" + JSGetterName(options, field, BYTES_DEFAULT, + /* drop_list = */ true), "repeatedtag", (field->is_repeated() ? "Repeated" : "")); + printer->Annotate("addername", field); printer->Print( "this, $index$$oneofgroup$, opt_value, $ctor$, opt_index);\n" "};\n" diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 96852ea7c8..e77026c782 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -867,9 +867,7 @@ void GeneratedMessageReflection::ClearField( case FieldDescriptor::CPPTYPE_MESSAGE: { if (IsMapFieldInApi(field)) { - MutableRaw(message, field) - ->MutableRepeatedField() - ->Clear >(); + MutableRaw(message, field)->Clear(); } else { // We don't know which subclass of RepeatedPtrFieldBase the type is, // so we use RepeatedPtrFieldBase directly. diff --git a/src/google/protobuf/map_field.cc b/src/google/protobuf/map_field.cc index 7c10d67f4c..9b27a32e7e 100644 --- a/src/google/protobuf/map_field.cc +++ b/src/google/protobuf/map_field.cc @@ -91,21 +91,47 @@ void MapFieldBase::SetRepeatedDirty() { state_.store(STATE_MODIFIED_REPEATED, std::memory_order_relaxed); } +void MapFieldBase::SetClean() { + // These are called by (non-const) mutator functions. So by our API it's the + // callers responsibility to have these calls properly ordered. + state_.store(CLEAN, std::memory_order_relaxed); +} + void* MapFieldBase::MutableRepeatedPtrField() const { return repeated_field_; } void MapFieldBase::SyncRepeatedFieldWithMap() const { // acquire here matches with release below to ensure that we can only see a // value of CLEAN after all previous changes have been synced. - if (state_.load(std::memory_order_acquire) == STATE_MODIFIED_MAP) { - mutex_.Lock(); - // Double check state, because another thread may have seen the same state - // and done the synchronization before the current thread. - if (state_.load(std::memory_order_relaxed) == STATE_MODIFIED_MAP) { - SyncRepeatedFieldWithMapNoLock(); - state_.store(CLEAN, std::memory_order_release); + switch (state_.load(std::memory_order_acquire)) { + case STATE_MODIFIED_MAP: + mutex_.Lock(); + // Double check state, because another thread may have seen the same + // state and done the synchronization before the current thread. + if (state_.load(std::memory_order_relaxed) == STATE_MODIFIED_MAP) { + SyncRepeatedFieldWithMapNoLock(); + state_.store(CLEAN, std::memory_order_release); + } + mutex_.Unlock(); + break; + case CLEAN: + mutex_.Lock(); + // Double check state + if (state_.load(std::memory_order_relaxed) == CLEAN) { + if (repeated_field_ == nullptr) { + if (arena_ == nullptr) { + repeated_field_ = new RepeatedPtrField(); + } else { + repeated_field_ = + Arena::CreateMessage >(arena_); + } + } + state_.store(CLEAN, std::memory_order_release); + } + mutex_.Unlock(); + break; + default: + break; } - mutex_.Unlock(); - } } void MapFieldBase::SyncRepeatedFieldWithMapNoLock() const { @@ -155,6 +181,20 @@ int DynamicMapField::size() const { return GetMap().size(); } +void DynamicMapField::Clear() { + Map* map = &const_cast(this)->map_; + for (Map::iterator iter = map->begin(); + iter != map->end(); ++iter) { + iter->second.DeleteData(); + } + map->clear(); + + if (MapFieldBase::repeated_field_ != nullptr) { + MapFieldBase::repeated_field_->Clear(); + } + MapFieldBase::SetClean(); +} + bool DynamicMapField::ContainsMapKey( const MapKey& map_key) const { const Map& map = GetMap(); diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index 5e598b8e0d..0bb559804f 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -107,6 +107,7 @@ class PROTOBUF_EXPORT MapFieldBase { virtual void Swap(MapFieldBase* other) = 0; // Sync Map with repeated field and returns the size of map. virtual int size() const = 0; + virtual void Clear() = 0; // Returns the number of bytes used by the repeated field, excluding // sizeof(*this) @@ -136,6 +137,9 @@ class PROTOBUF_EXPORT MapFieldBase { // Tells MapFieldBase that there is new change to RepeatedPTrField. void SetRepeatedDirty(); + // Tells MapFieldBase that map and repeated are the same. + void SetClean(); + // Provides derived class the access to repeated field. void* MutableRepeatedPtrField() const; @@ -268,9 +272,8 @@ class MapField : public TypeDefinedMapFieldBase { return result; } - // Convenient methods for generated message implementation. int size() const override; - void Clear(); + void Clear() override; void MergeFrom(const MapFieldBase& other) override; void Swap(MapFieldBase* other) override; @@ -334,6 +337,7 @@ class PROTOBUF_EXPORT DynamicMapField Map* MutableMap() override; int size() const override; + void Clear() override; private: Map map_; diff --git a/src/google/protobuf/map_field_inl.h b/src/google/protobuf/map_field_inl.h index 73c16ed4ee..40ceb50499 100644 --- a/src/google/protobuf/map_field_inl.h +++ b/src/google/protobuf/map_field_inl.h @@ -178,9 +178,15 @@ template void MapField::Clear() { - MapFieldBase::SyncMapWithRepeatedField(); + if (this->MapFieldBase::repeated_field_ != nullptr) { + RepeatedPtrField* repeated_field = + reinterpret_cast*>( + this->MapFieldBase::repeated_field_); + repeated_field->Clear(); + } + impl_.MutableMap()->clear(); - MapFieldBase::SetMapDirty(); + MapFieldBase::SetClean(); } template size()); + if (repeated_field == nullptr) { + EXPECT_EQ(repeated_size, 0); + } else { + EXPECT_EQ(repeated_size, repeated_field->size()); + } } } @@ -442,11 +447,7 @@ TEST_P(MapFieldStateTest, SwapRepeatedDirty) { TEST_P(MapFieldStateTest, Clear) { map_field_->Clear(); - if (state_ != MAP_DIRTY) { - Expect(map_field_.get(), MAP_DIRTY, 0, 1, false); - } else { - Expect(map_field_.get(), MAP_DIRTY, 0, 0, true); - } + Expect(map_field_.get(), CLEAN, 0, 0, false); } TEST_P(MapFieldStateTest, SpaceUsedExcludingSelf) { diff --git a/src/google/protobuf/map_test_util.cc b/src/google/protobuf/map_test_util.cc index 31ac173633..25f027f305 100644 --- a/src/google/protobuf/map_test_util.cc +++ b/src/google/protobuf/map_test_util.cc @@ -1582,6 +1582,10 @@ void MapReflectionTester::ExpectClearViaReflection( EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_bytes"))); EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_enum"))); EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_foreign_message"))); + EXPECT_TRUE(reflection->GetMapData( + message, F("map_int32_foreign_message"))->IsMapValid()); + EXPECT_TRUE(reflection->GetMapData( + message, F("map_int32_foreign_message"))->IsRepeatedFieldValid()); } void MapReflectionTester::ExpectClearViaReflectionIterator( diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index a11d983751..2c1a739300 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -188,10 +188,10 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type, bool include_start_and_end, ObjectWriter* ow) const { - const TypeRenderer* type_renderer = FindTypeRenderer(type.name()); - if (type_renderer != nullptr) { - return (*type_renderer)(this, type, name, ow); - } + const TypeRenderer* type_renderer = FindTypeRenderer(type.name()); + if (type_renderer != nullptr) { + return (*type_renderer)(this, type, name, ow); + } const google::protobuf::Field* field = nullptr; string field_name; @@ -229,9 +229,7 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type, if (field->cardinality() == google::protobuf::Field_Cardinality_CARDINALITY_REPEATED) { - bool check_maps = true; - - if (check_maps && IsMap(*field)) { + if (IsMap(*field)) { ow->StartObject(field_name); ASSIGN_OR_RETURN(tag, RenderMap(field, field_name, tag, ow)); ow->EndObject(); @@ -332,6 +330,7 @@ Status ProtoStreamObjectSource::RenderPacked( return util::Status(); } + Status ProtoStreamObjectSource::RenderTimestamp( const ProtoStreamObjectSource* os, const google::protobuf::Type& type, StringPiece field_name, ObjectWriter* ow) { @@ -708,6 +707,7 @@ std::unordered_map* ProtoStreamObjectSource::renderers_ = NULL; PROTOBUF_NAMESPACE_ID::internal::once_flag source_renderers_init_; + void ProtoStreamObjectSource::InitRendererMap() { renderers_ = new std::unordered_map(); @@ -745,6 +745,7 @@ void ProtoStreamObjectSource::InitRendererMap() { ::google::protobuf::internal::OnShutdown(&DeleteRendererMap); } + void ProtoStreamObjectSource::DeleteRendererMap() { delete ProtoStreamObjectSource::renderers_; renderers_ = NULL; @@ -781,10 +782,8 @@ Status ProtoStreamObjectSource::RenderField( // Short-circuit any special type rendering to save call-stack space. const TypeRenderer* type_renderer = FindTypeRenderer(type->name()); - bool use_type_renderer = type_renderer != nullptr; - RETURN_IF_ERROR(IncrementRecursionDepth(type->name(), field_name)); - if (use_type_renderer) { + if (type_renderer != nullptr) { RETURN_IF_ERROR((*type_renderer)(this, *type, field_name, ow)); } else { RETURN_IF_ERROR(WriteMessage(*type, field_name, 0, true, ow)); diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h index 124a36a1a5..ac94b038ff 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/src/google/protobuf/util/internal/protostream_objectsource.h @@ -46,6 +46,7 @@ #include #include + #include namespace google { @@ -181,9 +182,10 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { // Renders a NWP map. // Returns the next tag after reading all map entries. The caller should use // this tag before reading more tags from the stream. - util::StatusOr RenderMap(const google::protobuf::Field* field, - StringPiece name, uint32 list_tag, - ObjectWriter* ow) const; + util::StatusOr + RenderMap(const google::protobuf::Field* field, + StringPiece name, uint32 list_tag, + ObjectWriter* ow) const; // Renders a packed repeating field. A packed field is stored as: // {tag length item1 item2 item3} instead of the less efficient @@ -191,6 +193,7 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { util::Status RenderPacked(const google::protobuf::Field* field, ObjectWriter* ow) const; + // Renders a google.protobuf.Timestamp value to ObjectWriter static util::Status RenderTimestamp(const ProtoStreamObjectSource* os, const google::protobuf::Type& type, diff --git a/src/google/protobuf/util/type_resolver_util.cc b/src/google/protobuf/util/type_resolver_util.cc index f40ce941e9..4d7a3c0753 100644 --- a/src/google/protobuf/util/type_resolver_util.cc +++ b/src/google/protobuf/util/type_resolver_util.cc @@ -118,6 +118,27 @@ class DescriptorPoolTypeResolver : public TypeResolver { void ConvertMessageOptions(const MessageOptions& options, RepeatedPtrField

Field number for the "failure" field. + public const int FailureFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_failure_codec + = pb::FieldCodec.ForString(10); + private readonly pbc::RepeatedField failure_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Failure { + get { return failure_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as FailureSet); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(FailureSet other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!failure_.Equals(other.failure_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= failure_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + failure_.WriteTo(output, _repeated_failure_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += failure_.CalculateSize(_repeated_failure_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(FailureSet other) { + if (other == null) { + return; + } + failure_.Add(other.failure_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { + return; + } + break; + case 10: { + failure_.AddEntriesFrom(input, _repeated_failure_codec); + break; + } + } + } + } + + } + /// /// Represents a single test case's input. The testee should: /// @@ -107,7 +232,7 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[0]; } + get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[1]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -468,7 +593,7 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[1]; } + get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[2]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -850,7 +975,7 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[2]; } + get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[3]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs index 683dc41d0e..b59075bc10 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs @@ -29,7 +29,7 @@ namespace ProtobufTestMessages.Proto3 { "dWYvYW55LnByb3RvGh5nb29nbGUvcHJvdG9idWYvZHVyYXRpb24ucHJvdG8a", "IGdvb2dsZS9wcm90b2J1Zi9maWVsZF9tYXNrLnByb3RvGhxnb29nbGUvcHJv", "dG9idWYvc3RydWN0LnByb3RvGh9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1w", - "LnByb3RvGh5nb29nbGUvcHJvdG9idWYvd3JhcHBlcnMucHJvdG8itDsKElRl", + "LnByb3RvGh5nb29nbGUvcHJvdG9idWYvd3JhcHBlcnMucHJvdG8i7TwKElRl", "c3RBbGxUeXBlc1Byb3RvMxIWCg5vcHRpb25hbF9pbnQzMhgBIAEoBRIWCg5v", "cHRpb25hbF9pbnQ2NBgCIAEoAxIXCg9vcHRpb25hbF91aW50MzIYAyABKA0S", "FwoPb3B0aW9uYWxfdWludDY0GAQgASgEEhcKD29wdGlvbmFsX3NpbnQzMhgF", @@ -46,167 +46,171 @@ namespace ProtobufTestMessages.Proto3 { "c3RlZF9lbnVtGBUgASgOMjwucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90", "bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk5lc3RlZEVudW0SSQoVb3B0aW9uYWxf", "Zm9yZWlnbl9lbnVtGBYgASgOMioucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5w", - "cm90bzMuRm9yZWlnbkVudW0SIQoVb3B0aW9uYWxfc3RyaW5nX3BpZWNlGBgg", - "ASgJQgIIAhIZCg1vcHRpb25hbF9jb3JkGBkgASgJQgIIARJMChFyZWN1cnNp", - "dmVfbWVzc2FnZRgbIAEoCzIxLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJv", - "dG8zLlRlc3RBbGxUeXBlc1Byb3RvMxIWCg5yZXBlYXRlZF9pbnQzMhgfIAMo", - "BRIWCg5yZXBlYXRlZF9pbnQ2NBggIAMoAxIXCg9yZXBlYXRlZF91aW50MzIY", - "ISADKA0SFwoPcmVwZWF0ZWRfdWludDY0GCIgAygEEhcKD3JlcGVhdGVkX3Np", - "bnQzMhgjIAMoERIXCg9yZXBlYXRlZF9zaW50NjQYJCADKBISGAoQcmVwZWF0", - "ZWRfZml4ZWQzMhglIAMoBxIYChByZXBlYXRlZF9maXhlZDY0GCYgAygGEhkK", - "EXJlcGVhdGVkX3NmaXhlZDMyGCcgAygPEhkKEXJlcGVhdGVkX3NmaXhlZDY0", - "GCggAygQEhYKDnJlcGVhdGVkX2Zsb2F0GCkgAygCEhcKD3JlcGVhdGVkX2Rv", - "dWJsZRgqIAMoARIVCg1yZXBlYXRlZF9ib29sGCsgAygIEhcKD3JlcGVhdGVk", - "X3N0cmluZxgsIAMoCRIWCg5yZXBlYXRlZF9ieXRlcxgtIAMoDBJgChdyZXBl", - "YXRlZF9uZXN0ZWRfbWVzc2FnZRgwIAMoCzI/LnByb3RvYnVmX3Rlc3RfbWVz", - "c2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlc1Byb3RvMy5OZXN0ZWRNZXNzYWdl", - "Ek8KGHJlcGVhdGVkX2ZvcmVpZ25fbWVzc2FnZRgxIAMoCzItLnByb3RvYnVm", - "X3Rlc3RfbWVzc2FnZXMucHJvdG8zLkZvcmVpZ25NZXNzYWdlEloKFHJlcGVh", - "dGVkX25lc3RlZF9lbnVtGDMgAygOMjwucHJvdG9idWZfdGVzdF9tZXNzYWdl", - "cy5wcm90bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk5lc3RlZEVudW0SSQoVcmVw", - "ZWF0ZWRfZm9yZWlnbl9lbnVtGDQgAygOMioucHJvdG9idWZfdGVzdF9tZXNz", - "YWdlcy5wcm90bzMuRm9yZWlnbkVudW0SIQoVcmVwZWF0ZWRfc3RyaW5nX3Bp", - "ZWNlGDYgAygJQgIIAhIZCg1yZXBlYXRlZF9jb3JkGDcgAygJQgIIARJdCg9t", - "YXBfaW50MzJfaW50MzIYOCADKAsyRC5wcm90b2J1Zl90ZXN0X21lc3NhZ2Vz", - "LnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMuTWFwSW50MzJJbnQzMkVudHJ5", - "El0KD21hcF9pbnQ2NF9pbnQ2NBg5IAMoCzJELnByb3RvYnVmX3Rlc3RfbWVz", - "c2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlc1Byb3RvMy5NYXBJbnQ2NEludDY0", - "RW50cnkSYQoRbWFwX3VpbnQzMl91aW50MzIYOiADKAsyRi5wcm90b2J1Zl90", - "ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMuTWFwVWlu", - "dDMyVWludDMyRW50cnkSYQoRbWFwX3VpbnQ2NF91aW50NjQYOyADKAsyRi5w", - "cm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90", - "bzMuTWFwVWludDY0VWludDY0RW50cnkSYQoRbWFwX3NpbnQzMl9zaW50MzIY", - "PCADKAsyRi5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxs", - "VHlwZXNQcm90bzMuTWFwU2ludDMyU2ludDMyRW50cnkSYQoRbWFwX3NpbnQ2", - "NF9zaW50NjQYPSADKAsyRi5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3Rv", - "My5UZXN0QWxsVHlwZXNQcm90bzMuTWFwU2ludDY0U2ludDY0RW50cnkSZQoT", - "bWFwX2ZpeGVkMzJfZml4ZWQzMhg+IAMoCzJILnByb3RvYnVmX3Rlc3RfbWVz", - "c2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlc1Byb3RvMy5NYXBGaXhlZDMyRml4", - "ZWQzMkVudHJ5EmUKE21hcF9maXhlZDY0X2ZpeGVkNjQYPyADKAsySC5wcm90", - "b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMu", - "TWFwRml4ZWQ2NEZpeGVkNjRFbnRyeRJpChVtYXBfc2ZpeGVkMzJfc2ZpeGVk", - "MzIYQCADKAsySi5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0", - "QWxsVHlwZXNQcm90bzMuTWFwU2ZpeGVkMzJTZml4ZWQzMkVudHJ5EmkKFW1h", - "cF9zZml4ZWQ2NF9zZml4ZWQ2NBhBIAMoCzJKLnByb3RvYnVmX3Rlc3RfbWVz", - "c2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlc1Byb3RvMy5NYXBTZml4ZWQ2NFNm", - "aXhlZDY0RW50cnkSXQoPbWFwX2ludDMyX2Zsb2F0GEIgAygLMkQucHJvdG9i", + "cm90bzMuRm9yZWlnbkVudW0SXAoVb3B0aW9uYWxfYWxpYXNlZF9lbnVtGBcg", + "ASgOMj0ucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5", + "cGVzUHJvdG8zLkFsaWFzZWRFbnVtEiEKFW9wdGlvbmFsX3N0cmluZ19waWVj", + "ZRgYIAEoCUICCAISGQoNb3B0aW9uYWxfY29yZBgZIAEoCUICCAESTAoRcmVj", + "dXJzaXZlX21lc3NhZ2UYGyABKAsyMS5wcm90b2J1Zl90ZXN0X21lc3NhZ2Vz", + "LnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMSFgoOcmVwZWF0ZWRfaW50MzIY", + "HyADKAUSFgoOcmVwZWF0ZWRfaW50NjQYICADKAMSFwoPcmVwZWF0ZWRfdWlu", + "dDMyGCEgAygNEhcKD3JlcGVhdGVkX3VpbnQ2NBgiIAMoBBIXCg9yZXBlYXRl", + "ZF9zaW50MzIYIyADKBESFwoPcmVwZWF0ZWRfc2ludDY0GCQgAygSEhgKEHJl", + "cGVhdGVkX2ZpeGVkMzIYJSADKAcSGAoQcmVwZWF0ZWRfZml4ZWQ2NBgmIAMo", + "BhIZChFyZXBlYXRlZF9zZml4ZWQzMhgnIAMoDxIZChFyZXBlYXRlZF9zZml4", + "ZWQ2NBgoIAMoEBIWCg5yZXBlYXRlZF9mbG9hdBgpIAMoAhIXCg9yZXBlYXRl", + "ZF9kb3VibGUYKiADKAESFQoNcmVwZWF0ZWRfYm9vbBgrIAMoCBIXCg9yZXBl", + "YXRlZF9zdHJpbmcYLCADKAkSFgoOcmVwZWF0ZWRfYnl0ZXMYLSADKAwSYAoX", + "cmVwZWF0ZWRfbmVzdGVkX21lc3NhZ2UYMCADKAsyPy5wcm90b2J1Zl90ZXN0", + "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMuTmVzdGVkTWVz", + "c2FnZRJPChhyZXBlYXRlZF9mb3JlaWduX21lc3NhZ2UYMSADKAsyLS5wcm90", + "b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5Gb3JlaWduTWVzc2FnZRJaChRy", + "ZXBlYXRlZF9uZXN0ZWRfZW51bRgzIAMoDjI8LnByb3RvYnVmX3Rlc3RfbWVz", + "c2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlc1Byb3RvMy5OZXN0ZWRFbnVtEkkK", + "FXJlcGVhdGVkX2ZvcmVpZ25fZW51bRg0IAMoDjIqLnByb3RvYnVmX3Rlc3Rf", + "bWVzc2FnZXMucHJvdG8zLkZvcmVpZ25FbnVtEiEKFXJlcGVhdGVkX3N0cmlu", + "Z19waWVjZRg2IAMoCUICCAISGQoNcmVwZWF0ZWRfY29yZBg3IAMoCUICCAES", + "XQoPbWFwX2ludDMyX2ludDMyGDggAygLMkQucHJvdG9idWZfdGVzdF9tZXNz", + "YWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk1hcEludDMySW50MzJF", + "bnRyeRJdCg9tYXBfaW50NjRfaW50NjQYOSADKAsyRC5wcm90b2J1Zl90ZXN0", + "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMuTWFwSW50NjRJ", + "bnQ2NEVudHJ5EmEKEW1hcF91aW50MzJfdWludDMyGDogAygLMkYucHJvdG9i", "dWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk1h", - "cEludDMyRmxvYXRFbnRyeRJfChBtYXBfaW50MzJfZG91YmxlGEMgAygLMkUu", + "cFVpbnQzMlVpbnQzMkVudHJ5EmEKEW1hcF91aW50NjRfdWludDY0GDsgAygL", + "MkYucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVz", + "UHJvdG8zLk1hcFVpbnQ2NFVpbnQ2NEVudHJ5EmEKEW1hcF9zaW50MzJfc2lu", + "dDMyGDwgAygLMkYucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVz", + "dEFsbFR5cGVzUHJvdG8zLk1hcFNpbnQzMlNpbnQzMkVudHJ5EmEKEW1hcF9z", + "aW50NjRfc2ludDY0GD0gAygLMkYucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5w", + "cm90bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk1hcFNpbnQ2NFNpbnQ2NEVudHJ5", + "EmUKE21hcF9maXhlZDMyX2ZpeGVkMzIYPiADKAsySC5wcm90b2J1Zl90ZXN0", + "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMuTWFwRml4ZWQz", + "MkZpeGVkMzJFbnRyeRJlChNtYXBfZml4ZWQ2NF9maXhlZDY0GD8gAygLMkgu", "cHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzUHJv", - "dG8zLk1hcEludDMyRG91YmxlRW50cnkSWQoNbWFwX2Jvb2xfYm9vbBhEIAMo", - "CzJCLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBl", - "c1Byb3RvMy5NYXBCb29sQm9vbEVudHJ5EmEKEW1hcF9zdHJpbmdfc3RyaW5n", - "GEUgAygLMkYucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFs", - "bFR5cGVzUHJvdG8zLk1hcFN0cmluZ1N0cmluZ0VudHJ5El8KEG1hcF9zdHJp", - "bmdfYnl0ZXMYRiADKAsyRS5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3Rv", - "My5UZXN0QWxsVHlwZXNQcm90bzMuTWFwU3RyaW5nQnl0ZXNFbnRyeRJwChlt", - "YXBfc3RyaW5nX25lc3RlZF9tZXNzYWdlGEcgAygLMk0ucHJvdG9idWZfdGVz", - "dF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk1hcFN0cmlu", - "Z05lc3RlZE1lc3NhZ2VFbnRyeRJyChptYXBfc3RyaW5nX2ZvcmVpZ25fbWVz", - "c2FnZRhIIAMoCzJOLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRl", - "c3RBbGxUeXBlc1Byb3RvMy5NYXBTdHJpbmdGb3JlaWduTWVzc2FnZUVudHJ5", - "EmoKFm1hcF9zdHJpbmdfbmVzdGVkX2VudW0YSSADKAsySi5wcm90b2J1Zl90", - "ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMuTWFwU3Ry", - "aW5nTmVzdGVkRW51bUVudHJ5EmwKF21hcF9zdHJpbmdfZm9yZWlnbl9lbnVt", - "GEogAygLMksucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFs", - "bFR5cGVzUHJvdG8zLk1hcFN0cmluZ0ZvcmVpZ25FbnVtRW50cnkSFgoMb25l", - "b2ZfdWludDMyGG8gASgNSAASXwoUb25lb2ZfbmVzdGVkX21lc3NhZ2UYcCAB", - "KAsyPy5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlw", - "ZXNQcm90bzMuTmVzdGVkTWVzc2FnZUgAEhYKDG9uZW9mX3N0cmluZxhxIAEo", - "CUgAEhUKC29uZW9mX2J5dGVzGHIgASgMSAASFAoKb25lb2ZfYm9vbBhzIAEo", - "CEgAEhYKDG9uZW9mX3VpbnQ2NBh0IAEoBEgAEhUKC29uZW9mX2Zsb2F0GHUg", - "ASgCSAASFgoMb25lb2ZfZG91YmxlGHYgASgBSAASUgoKb25lb2ZfZW51bRh3", - "IAEoDjI8LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxU", - "eXBlc1Byb3RvMy5OZXN0ZWRFbnVtSAASOgoVb3B0aW9uYWxfYm9vbF93cmFw", - "cGVyGMkBIAEoCzIaLmdvb2dsZS5wcm90b2J1Zi5Cb29sVmFsdWUSPAoWb3B0", - "aW9uYWxfaW50MzJfd3JhcHBlchjKASABKAsyGy5nb29nbGUucHJvdG9idWYu", - "SW50MzJWYWx1ZRI8ChZvcHRpb25hbF9pbnQ2NF93cmFwcGVyGMsBIAEoCzIb", - "Lmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVlEj4KF29wdGlvbmFsX3VpbnQz", - "Ml93cmFwcGVyGMwBIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5VSW50MzJWYWx1", - "ZRI+ChdvcHRpb25hbF91aW50NjRfd3JhcHBlchjNASABKAsyHC5nb29nbGUu", - "cHJvdG9idWYuVUludDY0VmFsdWUSPAoWb3B0aW9uYWxfZmxvYXRfd3JhcHBl", - "chjOASABKAsyGy5nb29nbGUucHJvdG9idWYuRmxvYXRWYWx1ZRI+ChdvcHRp", - "b25hbF9kb3VibGVfd3JhcHBlchjPASABKAsyHC5nb29nbGUucHJvdG9idWYu", - "RG91YmxlVmFsdWUSPgoXb3B0aW9uYWxfc3RyaW5nX3dyYXBwZXIY0AEgASgL", - "MhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEjwKFm9wdGlvbmFsX2J5", - "dGVzX3dyYXBwZXIY0QEgASgLMhsuZ29vZ2xlLnByb3RvYnVmLkJ5dGVzVmFs", - "dWUSOgoVcmVwZWF0ZWRfYm9vbF93cmFwcGVyGNMBIAMoCzIaLmdvb2dsZS5w", - "cm90b2J1Zi5Cb29sVmFsdWUSPAoWcmVwZWF0ZWRfaW50MzJfd3JhcHBlchjU", - "ASADKAsyGy5nb29nbGUucHJvdG9idWYuSW50MzJWYWx1ZRI8ChZyZXBlYXRl", - "ZF9pbnQ2NF93cmFwcGVyGNUBIAMoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2", - "NFZhbHVlEj4KF3JlcGVhdGVkX3VpbnQzMl93cmFwcGVyGNYBIAMoCzIcLmdv", - "b2dsZS5wcm90b2J1Zi5VSW50MzJWYWx1ZRI+ChdyZXBlYXRlZF91aW50NjRf", - "d3JhcHBlchjXASADKAsyHC5nb29nbGUucHJvdG9idWYuVUludDY0VmFsdWUS", - "PAoWcmVwZWF0ZWRfZmxvYXRfd3JhcHBlchjYASADKAsyGy5nb29nbGUucHJv", - "dG9idWYuRmxvYXRWYWx1ZRI+ChdyZXBlYXRlZF9kb3VibGVfd3JhcHBlchjZ", - "ASADKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSPgoXcmVwZWF0", - "ZWRfc3RyaW5nX3dyYXBwZXIY2gEgAygLMhwuZ29vZ2xlLnByb3RvYnVmLlN0", - "cmluZ1ZhbHVlEjwKFnJlcGVhdGVkX2J5dGVzX3dyYXBwZXIY2wEgAygLMhsu", - "Z29vZ2xlLnByb3RvYnVmLkJ5dGVzVmFsdWUSNQoRb3B0aW9uYWxfZHVyYXRp", - "b24YrQIgASgLMhkuZ29vZ2xlLnByb3RvYnVmLkR1cmF0aW9uEjcKEm9wdGlv", - "bmFsX3RpbWVzdGFtcBiuAiABKAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0", - "YW1wEjgKE29wdGlvbmFsX2ZpZWxkX21hc2sYrwIgASgLMhouZ29vZ2xlLnBy", - "b3RvYnVmLkZpZWxkTWFzaxIxCg9vcHRpb25hbF9zdHJ1Y3QYsAIgASgLMhcu", - "Z29vZ2xlLnByb3RvYnVmLlN0cnVjdBIrCgxvcHRpb25hbF9hbnkYsQIgASgL", - "MhQuZ29vZ2xlLnByb3RvYnVmLkFueRIvCg5vcHRpb25hbF92YWx1ZRiyAiAB", - "KAsyFi5nb29nbGUucHJvdG9idWYuVmFsdWUSNQoRcmVwZWF0ZWRfZHVyYXRp", - "b24YtwIgAygLMhkuZ29vZ2xlLnByb3RvYnVmLkR1cmF0aW9uEjcKEnJlcGVh", - "dGVkX3RpbWVzdGFtcBi4AiADKAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0", - "YW1wEjcKEnJlcGVhdGVkX2ZpZWxkbWFzaxi5AiADKAsyGi5nb29nbGUucHJv", - "dG9idWYuRmllbGRNYXNrEjEKD3JlcGVhdGVkX3N0cnVjdBjEAiADKAsyFy5n", - "b29nbGUucHJvdG9idWYuU3RydWN0EisKDHJlcGVhdGVkX2FueRi7AiADKAsy", - "FC5nb29nbGUucHJvdG9idWYuQW55Ei8KDnJlcGVhdGVkX3ZhbHVlGLwCIAMo", - "CzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZRITCgpmaWVsZG5hbWUxGJEDIAEo", - "BRIUCgtmaWVsZF9uYW1lMhiSAyABKAUSFQoMX2ZpZWxkX25hbWUzGJMDIAEo", - "BRIWCg1maWVsZF9fbmFtZTRfGJQDIAEoBRIUCgtmaWVsZDBuYW1lNRiVAyAB", - "KAUSFgoNZmllbGRfMF9uYW1lNhiWAyABKAUSEwoKZmllbGROYW1lNxiXAyAB", - "KAUSEwoKRmllbGROYW1lOBiYAyABKAUSFAoLZmllbGRfTmFtZTkYmQMgASgF", - "EhUKDEZpZWxkX05hbWUxMBiaAyABKAUSFQoMRklFTERfTkFNRTExGJsDIAEo", - "BRIVCgxGSUVMRF9uYW1lMTIYnAMgASgFEhcKDl9fZmllbGRfbmFtZTEzGJ0D", - "IAEoBRIXCg5fX0ZpZWxkX25hbWUxNBieAyABKAUSFgoNZmllbGRfX25hbWUx", - "NRifAyABKAUSFgoNZmllbGRfX05hbWUxNhigAyABKAUSFwoOZmllbGRfbmFt", - "ZTE3X18YoQMgASgFEhcKDkZpZWxkX25hbWUxOF9fGKIDIAEoBRpiCg1OZXN0", - "ZWRNZXNzYWdlEgkKAWEYASABKAUSRgoLY29yZWN1cnNpdmUYAiABKAsyMS5w", - "cm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90", - "bzMaNAoSTWFwSW50MzJJbnQzMkVudHJ5EgsKA2tleRgBIAEoBRINCgV2YWx1", - "ZRgCIAEoBToCOAEaNAoSTWFwSW50NjRJbnQ2NEVudHJ5EgsKA2tleRgBIAEo", - "AxINCgV2YWx1ZRgCIAEoAzoCOAEaNgoUTWFwVWludDMyVWludDMyRW50cnkS", - "CwoDa2V5GAEgASgNEg0KBXZhbHVlGAIgASgNOgI4ARo2ChRNYXBVaW50NjRV", - "aW50NjRFbnRyeRILCgNrZXkYASABKAQSDQoFdmFsdWUYAiABKAQ6AjgBGjYK", - "FE1hcFNpbnQzMlNpbnQzMkVudHJ5EgsKA2tleRgBIAEoERINCgV2YWx1ZRgC", - "IAEoEToCOAEaNgoUTWFwU2ludDY0U2ludDY0RW50cnkSCwoDa2V5GAEgASgS", - "Eg0KBXZhbHVlGAIgASgSOgI4ARo4ChZNYXBGaXhlZDMyRml4ZWQzMkVudHJ5", - "EgsKA2tleRgBIAEoBxINCgV2YWx1ZRgCIAEoBzoCOAEaOAoWTWFwRml4ZWQ2", - "NEZpeGVkNjRFbnRyeRILCgNrZXkYASABKAYSDQoFdmFsdWUYAiABKAY6AjgB", - "GjoKGE1hcFNmaXhlZDMyU2ZpeGVkMzJFbnRyeRILCgNrZXkYASABKA8SDQoF", - "dmFsdWUYAiABKA86AjgBGjoKGE1hcFNmaXhlZDY0U2ZpeGVkNjRFbnRyeRIL", - "CgNrZXkYASABKBASDQoFdmFsdWUYAiABKBA6AjgBGjQKEk1hcEludDMyRmxv", - "YXRFbnRyeRILCgNrZXkYASABKAUSDQoFdmFsdWUYAiABKAI6AjgBGjUKE01h", - "cEludDMyRG91YmxlRW50cnkSCwoDa2V5GAEgASgFEg0KBXZhbHVlGAIgASgB", - "OgI4ARoyChBNYXBCb29sQm9vbEVudHJ5EgsKA2tleRgBIAEoCBINCgV2YWx1", - "ZRgCIAEoCDoCOAEaNgoUTWFwU3RyaW5nU3RyaW5nRW50cnkSCwoDa2V5GAEg", - "ASgJEg0KBXZhbHVlGAIgASgJOgI4ARo1ChNNYXBTdHJpbmdCeXRlc0VudHJ5", - "EgsKA2tleRgBIAEoCRINCgV2YWx1ZRgCIAEoDDoCOAEafgobTWFwU3RyaW5n", - "TmVzdGVkTWVzc2FnZUVudHJ5EgsKA2tleRgBIAEoCRJOCgV2YWx1ZRgCIAEo", - "CzI/LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBl", - "c1Byb3RvMy5OZXN0ZWRNZXNzYWdlOgI4ARptChxNYXBTdHJpbmdGb3JlaWdu", - "TWVzc2FnZUVudHJ5EgsKA2tleRgBIAEoCRI8CgV2YWx1ZRgCIAEoCzItLnBy", - "b3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLkZvcmVpZ25NZXNzYWdlOgI4", - "ARp4ChhNYXBTdHJpbmdOZXN0ZWRFbnVtRW50cnkSCwoDa2V5GAEgASgJEksK", - "BXZhbHVlGAIgASgOMjwucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMu", - "VGVzdEFsbFR5cGVzUHJvdG8zLk5lc3RlZEVudW06AjgBGmcKGU1hcFN0cmlu", - "Z0ZvcmVpZ25FbnVtRW50cnkSCwoDa2V5GAEgASgJEjkKBXZhbHVlGAIgASgO", - "MioucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuRm9yZWlnbkVudW06", - "AjgBIjkKCk5lc3RlZEVudW0SBwoDRk9PEAASBwoDQkFSEAESBwoDQkFaEAIS", - "EAoDTkVHEP///////////wFCDQoLb25lb2ZfZmllbGRKBgj1AxD/AyIbCg5G", - "b3JlaWduTWVzc2FnZRIJCgFjGAEgASgFKkAKC0ZvcmVpZ25FbnVtEg8KC0ZP", - "UkVJR05fRk9PEAASDwoLRk9SRUlHTl9CQVIQARIPCgtGT1JFSUdOX0JBWhAC", - "QjgKKGNvbS5nb29nbGUucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzNI", - "AfgBAaICBlByb3RvM2IGcHJvdG8z")); + "dG8zLk1hcEZpeGVkNjRGaXhlZDY0RW50cnkSaQoVbWFwX3NmaXhlZDMyX3Nm", + "aXhlZDMyGEAgAygLMkoucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMu", + "VGVzdEFsbFR5cGVzUHJvdG8zLk1hcFNmaXhlZDMyU2ZpeGVkMzJFbnRyeRJp", + "ChVtYXBfc2ZpeGVkNjRfc2ZpeGVkNjQYQSADKAsySi5wcm90b2J1Zl90ZXN0", + "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXNQcm90bzMuTWFwU2ZpeGVk", + "NjRTZml4ZWQ2NEVudHJ5El0KD21hcF9pbnQzMl9mbG9hdBhCIAMoCzJELnBy", + "b3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlc1Byb3Rv", + "My5NYXBJbnQzMkZsb2F0RW50cnkSXwoQbWFwX2ludDMyX2RvdWJsZRhDIAMo", + "CzJFLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBl", + "c1Byb3RvMy5NYXBJbnQzMkRvdWJsZUVudHJ5ElkKDW1hcF9ib29sX2Jvb2wY", + "RCADKAsyQi5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxs", + "VHlwZXNQcm90bzMuTWFwQm9vbEJvb2xFbnRyeRJhChFtYXBfc3RyaW5nX3N0", + "cmluZxhFIAMoCzJGLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRl", + "c3RBbGxUeXBlc1Byb3RvMy5NYXBTdHJpbmdTdHJpbmdFbnRyeRJfChBtYXBf", + "c3RyaW5nX2J5dGVzGEYgAygLMkUucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5w", + "cm90bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk1hcFN0cmluZ0J5dGVzRW50cnkS", + "cAoZbWFwX3N0cmluZ19uZXN0ZWRfbWVzc2FnZRhHIAMoCzJNLnByb3RvYnVm", + "X3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlc1Byb3RvMy5NYXBT", + "dHJpbmdOZXN0ZWRNZXNzYWdlRW50cnkScgoabWFwX3N0cmluZ19mb3JlaWdu", + "X21lc3NhZ2UYSCADKAsyTi5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3Rv", + "My5UZXN0QWxsVHlwZXNQcm90bzMuTWFwU3RyaW5nRm9yZWlnbk1lc3NhZ2VF", + "bnRyeRJqChZtYXBfc3RyaW5nX25lc3RlZF9lbnVtGEkgAygLMkoucHJvdG9i", + "dWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzUHJvdG8zLk1h", + "cFN0cmluZ05lc3RlZEVudW1FbnRyeRJsChdtYXBfc3RyaW5nX2ZvcmVpZ25f", + "ZW51bRhKIAMoCzJLLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRl", + "c3RBbGxUeXBlc1Byb3RvMy5NYXBTdHJpbmdGb3JlaWduRW51bUVudHJ5EhYK", + "DG9uZW9mX3VpbnQzMhhvIAEoDUgAEl8KFG9uZW9mX25lc3RlZF9tZXNzYWdl", + "GHAgASgLMj8ucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFs", + "bFR5cGVzUHJvdG8zLk5lc3RlZE1lc3NhZ2VIABIWCgxvbmVvZl9zdHJpbmcY", + "cSABKAlIABIVCgtvbmVvZl9ieXRlcxhyIAEoDEgAEhQKCm9uZW9mX2Jvb2wY", + "cyABKAhIABIWCgxvbmVvZl91aW50NjQYdCABKARIABIVCgtvbmVvZl9mbG9h", + "dBh1IAEoAkgAEhYKDG9uZW9mX2RvdWJsZRh2IAEoAUgAElIKCm9uZW9mX2Vu", + "dW0YdyABKA4yPC5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0", + "QWxsVHlwZXNQcm90bzMuTmVzdGVkRW51bUgAEjoKFW9wdGlvbmFsX2Jvb2xf", + "d3JhcHBlchjJASABKAsyGi5nb29nbGUucHJvdG9idWYuQm9vbFZhbHVlEjwK", + "Fm9wdGlvbmFsX2ludDMyX3dyYXBwZXIYygEgASgLMhsuZ29vZ2xlLnByb3Rv", + "YnVmLkludDMyVmFsdWUSPAoWb3B0aW9uYWxfaW50NjRfd3JhcHBlchjLASAB", + "KAsyGy5nb29nbGUucHJvdG9idWYuSW50NjRWYWx1ZRI+ChdvcHRpb25hbF91", + "aW50MzJfd3JhcHBlchjMASABKAsyHC5nb29nbGUucHJvdG9idWYuVUludDMy", + "VmFsdWUSPgoXb3B0aW9uYWxfdWludDY0X3dyYXBwZXIYzQEgASgLMhwuZ29v", + "Z2xlLnByb3RvYnVmLlVJbnQ2NFZhbHVlEjwKFm9wdGlvbmFsX2Zsb2F0X3dy", + "YXBwZXIYzgEgASgLMhsuZ29vZ2xlLnByb3RvYnVmLkZsb2F0VmFsdWUSPgoX", + "b3B0aW9uYWxfZG91YmxlX3dyYXBwZXIYzwEgASgLMhwuZ29vZ2xlLnByb3Rv", + "YnVmLkRvdWJsZVZhbHVlEj4KF29wdGlvbmFsX3N0cmluZ193cmFwcGVyGNAB", + "IAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5TdHJpbmdWYWx1ZRI8ChZvcHRpb25h", + "bF9ieXRlc193cmFwcGVyGNEBIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5CeXRl", + "c1ZhbHVlEjoKFXJlcGVhdGVkX2Jvb2xfd3JhcHBlchjTASADKAsyGi5nb29n", + "bGUucHJvdG9idWYuQm9vbFZhbHVlEjwKFnJlcGVhdGVkX2ludDMyX3dyYXBw", + "ZXIY1AEgAygLMhsuZ29vZ2xlLnByb3RvYnVmLkludDMyVmFsdWUSPAoWcmVw", + "ZWF0ZWRfaW50NjRfd3JhcHBlchjVASADKAsyGy5nb29nbGUucHJvdG9idWYu", + "SW50NjRWYWx1ZRI+ChdyZXBlYXRlZF91aW50MzJfd3JhcHBlchjWASADKAsy", + "HC5nb29nbGUucHJvdG9idWYuVUludDMyVmFsdWUSPgoXcmVwZWF0ZWRfdWlu", + "dDY0X3dyYXBwZXIY1wEgAygLMhwuZ29vZ2xlLnByb3RvYnVmLlVJbnQ2NFZh", + "bHVlEjwKFnJlcGVhdGVkX2Zsb2F0X3dyYXBwZXIY2AEgAygLMhsuZ29vZ2xl", + "LnByb3RvYnVmLkZsb2F0VmFsdWUSPgoXcmVwZWF0ZWRfZG91YmxlX3dyYXBw", + "ZXIY2QEgAygLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEj4KF3Jl", + "cGVhdGVkX3N0cmluZ193cmFwcGVyGNoBIAMoCzIcLmdvb2dsZS5wcm90b2J1", + "Zi5TdHJpbmdWYWx1ZRI8ChZyZXBlYXRlZF9ieXRlc193cmFwcGVyGNsBIAMo", + "CzIbLmdvb2dsZS5wcm90b2J1Zi5CeXRlc1ZhbHVlEjUKEW9wdGlvbmFsX2R1", + "cmF0aW9uGK0CIAEoCzIZLmdvb2dsZS5wcm90b2J1Zi5EdXJhdGlvbhI3ChJv", + "cHRpb25hbF90aW1lc3RhbXAYrgIgASgLMhouZ29vZ2xlLnByb3RvYnVmLlRp", + "bWVzdGFtcBI4ChNvcHRpb25hbF9maWVsZF9tYXNrGK8CIAEoCzIaLmdvb2ds", + "ZS5wcm90b2J1Zi5GaWVsZE1hc2sSMQoPb3B0aW9uYWxfc3RydWN0GLACIAEo", + "CzIXLmdvb2dsZS5wcm90b2J1Zi5TdHJ1Y3QSKwoMb3B0aW9uYWxfYW55GLEC", + "IAEoCzIULmdvb2dsZS5wcm90b2J1Zi5BbnkSLwoOb3B0aW9uYWxfdmFsdWUY", + "sgIgASgLMhYuZ29vZ2xlLnByb3RvYnVmLlZhbHVlEjUKEXJlcGVhdGVkX2R1", + "cmF0aW9uGLcCIAMoCzIZLmdvb2dsZS5wcm90b2J1Zi5EdXJhdGlvbhI3ChJy", + "ZXBlYXRlZF90aW1lc3RhbXAYuAIgAygLMhouZ29vZ2xlLnByb3RvYnVmLlRp", + "bWVzdGFtcBI3ChJyZXBlYXRlZF9maWVsZG1hc2sYuQIgAygLMhouZ29vZ2xl", + "LnByb3RvYnVmLkZpZWxkTWFzaxIxCg9yZXBlYXRlZF9zdHJ1Y3QYxAIgAygL", + "MhcuZ29vZ2xlLnByb3RvYnVmLlN0cnVjdBIrCgxyZXBlYXRlZF9hbnkYuwIg", + "AygLMhQuZ29vZ2xlLnByb3RvYnVmLkFueRIvCg5yZXBlYXRlZF92YWx1ZRi8", + "AiADKAsyFi5nb29nbGUucHJvdG9idWYuVmFsdWUSEwoKZmllbGRuYW1lMRiR", + "AyABKAUSFAoLZmllbGRfbmFtZTIYkgMgASgFEhUKDF9maWVsZF9uYW1lMxiT", + "AyABKAUSFgoNZmllbGRfX25hbWU0XxiUAyABKAUSFAoLZmllbGQwbmFtZTUY", + "lQMgASgFEhYKDWZpZWxkXzBfbmFtZTYYlgMgASgFEhMKCmZpZWxkTmFtZTcY", + "lwMgASgFEhMKCkZpZWxkTmFtZTgYmAMgASgFEhQKC2ZpZWxkX05hbWU5GJkD", + "IAEoBRIVCgxGaWVsZF9OYW1lMTAYmgMgASgFEhUKDEZJRUxEX05BTUUxMRib", + "AyABKAUSFQoMRklFTERfbmFtZTEyGJwDIAEoBRIXCg5fX2ZpZWxkX25hbWUx", + "MxidAyABKAUSFwoOX19GaWVsZF9uYW1lMTQYngMgASgFEhYKDWZpZWxkX19u", + "YW1lMTUYnwMgASgFEhYKDWZpZWxkX19OYW1lMTYYoAMgASgFEhcKDmZpZWxk", + "X25hbWUxN19fGKEDIAEoBRIXCg5GaWVsZF9uYW1lMThfXxiiAyABKAUaYgoN", + "TmVzdGVkTWVzc2FnZRIJCgFhGAEgASgFEkYKC2NvcmVjdXJzaXZlGAIgASgL", + "MjEucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVz", + "UHJvdG8zGjQKEk1hcEludDMySW50MzJFbnRyeRILCgNrZXkYASABKAUSDQoF", + "dmFsdWUYAiABKAU6AjgBGjQKEk1hcEludDY0SW50NjRFbnRyeRILCgNrZXkY", + "ASABKAMSDQoFdmFsdWUYAiABKAM6AjgBGjYKFE1hcFVpbnQzMlVpbnQzMkVu", + "dHJ5EgsKA2tleRgBIAEoDRINCgV2YWx1ZRgCIAEoDToCOAEaNgoUTWFwVWlu", + "dDY0VWludDY0RW50cnkSCwoDa2V5GAEgASgEEg0KBXZhbHVlGAIgASgEOgI4", + "ARo2ChRNYXBTaW50MzJTaW50MzJFbnRyeRILCgNrZXkYASABKBESDQoFdmFs", + "dWUYAiABKBE6AjgBGjYKFE1hcFNpbnQ2NFNpbnQ2NEVudHJ5EgsKA2tleRgB", + "IAEoEhINCgV2YWx1ZRgCIAEoEjoCOAEaOAoWTWFwRml4ZWQzMkZpeGVkMzJF", + "bnRyeRILCgNrZXkYASABKAcSDQoFdmFsdWUYAiABKAc6AjgBGjgKFk1hcEZp", + "eGVkNjRGaXhlZDY0RW50cnkSCwoDa2V5GAEgASgGEg0KBXZhbHVlGAIgASgG", + "OgI4ARo6ChhNYXBTZml4ZWQzMlNmaXhlZDMyRW50cnkSCwoDa2V5GAEgASgP", + "Eg0KBXZhbHVlGAIgASgPOgI4ARo6ChhNYXBTZml4ZWQ2NFNmaXhlZDY0RW50", + "cnkSCwoDa2V5GAEgASgQEg0KBXZhbHVlGAIgASgQOgI4ARo0ChJNYXBJbnQz", + "MkZsb2F0RW50cnkSCwoDa2V5GAEgASgFEg0KBXZhbHVlGAIgASgCOgI4ARo1", + "ChNNYXBJbnQzMkRvdWJsZUVudHJ5EgsKA2tleRgBIAEoBRINCgV2YWx1ZRgC", + "IAEoAToCOAEaMgoQTWFwQm9vbEJvb2xFbnRyeRILCgNrZXkYASABKAgSDQoF", + "dmFsdWUYAiABKAg6AjgBGjYKFE1hcFN0cmluZ1N0cmluZ0VudHJ5EgsKA2tl", + "eRgBIAEoCRINCgV2YWx1ZRgCIAEoCToCOAEaNQoTTWFwU3RyaW5nQnl0ZXNF", + "bnRyeRILCgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAw6AjgBGn4KG01hcFN0", + "cmluZ05lc3RlZE1lc3NhZ2VFbnRyeRILCgNrZXkYASABKAkSTgoFdmFsdWUY", + "AiABKAsyPy5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxs", + "VHlwZXNQcm90bzMuTmVzdGVkTWVzc2FnZToCOAEabQocTWFwU3RyaW5nRm9y", + "ZWlnbk1lc3NhZ2VFbnRyeRILCgNrZXkYASABKAkSPAoFdmFsdWUYAiABKAsy", + "LS5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5Gb3JlaWduTWVzc2Fn", + "ZToCOAEaeAoYTWFwU3RyaW5nTmVzdGVkRW51bUVudHJ5EgsKA2tleRgBIAEo", + "CRJLCgV2YWx1ZRgCIAEoDjI8LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJv", + "dG8zLlRlc3RBbGxUeXBlc1Byb3RvMy5OZXN0ZWRFbnVtOgI4ARpnChlNYXBT", + "dHJpbmdGb3JlaWduRW51bUVudHJ5EgsKA2tleRgBIAEoCRI5CgV2YWx1ZRgC", + "IAEoDjIqLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLkZvcmVpZ25F", + "bnVtOgI4ASI5CgpOZXN0ZWRFbnVtEgcKA0ZPTxAAEgcKA0JBUhABEgcKA0JB", + "WhACEhAKA05FRxD///////////8BIlkKC0FsaWFzZWRFbnVtEg0KCUFMSUFT", + "X0ZPTxAAEg0KCUFMSUFTX0JBUhABEg0KCUFMSUFTX0JBWhACEgcKA1FVWBAC", + "EgcKA3F1eBACEgcKA2JBehACGgIQAUINCgtvbmVvZl9maWVsZEoGCPUDEP8D", + "IhsKDkZvcmVpZ25NZXNzYWdlEgkKAWMYASABKAUqQAoLRm9yZWlnbkVudW0S", + "DwoLRk9SRUlHTl9GT08QABIPCgtGT1JFSUdOX0JBUhABEg8KC0ZPUkVJR05f", + "QkFaEAJCOAooY29tLmdvb2dsZS5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnBy", + "b3RvM0gB+AEBogIGUHJvdG8zYgZwcm90bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.DurationReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.FieldMaskReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ProtobufTestMessages.Proto3.ForeignEnum), }, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.TestAllTypesProto3), global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalNestedMessage", "OptionalForeignMessage", "OptionalNestedEnum", "OptionalForeignEnum", "OptionalStringPiece", "OptionalCord", "RecursiveMessage", "RepeatedInt32", "RepeatedInt64", "RepeatedUint32", "RepeatedUint64", "RepeatedSint32", "RepeatedSint64", "RepeatedFixed32", "RepeatedFixed64", "RepeatedSfixed32", "RepeatedSfixed64", "RepeatedFloat", "RepeatedDouble", "RepeatedBool", "RepeatedString", "RepeatedBytes", "RepeatedNestedMessage", "RepeatedForeignMessage", "RepeatedNestedEnum", "RepeatedForeignEnum", "RepeatedStringPiece", "RepeatedCord", "MapInt32Int32", "MapInt64Int64", "MapUint32Uint32", "MapUint64Uint64", "MapSint32Sint32", "MapSint64Sint64", "MapFixed32Fixed32", "MapFixed64Fixed64", "MapSfixed32Sfixed32", "MapSfixed64Sfixed64", "MapInt32Float", "MapInt32Double", "MapBoolBool", "MapStringString", "MapStringBytes", "MapStringNestedMessage", "MapStringForeignMessage", "MapStringNestedEnum", "MapStringForeignEnum", "OneofUint32", "OneofNestedMessage", "OneofString", "OneofBytes", "OneofBool", "OneofUint64", "OneofFloat", "OneofDouble", "OneofEnum", "OptionalBoolWrapper", "OptionalInt32Wrapper", "OptionalInt64Wrapper", "OptionalUint32Wrapper", "OptionalUint64Wrapper", "OptionalFloatWrapper", "OptionalDoubleWrapper", "OptionalStringWrapper", "OptionalBytesWrapper", "RepeatedBoolWrapper", "RepeatedInt32Wrapper", "RepeatedInt64Wrapper", "RepeatedUint32Wrapper", "RepeatedUint64Wrapper", "RepeatedFloatWrapper", "RepeatedDoubleWrapper", "RepeatedStringWrapper", "RepeatedBytesWrapper", "OptionalDuration", "OptionalTimestamp", "OptionalFieldMask", "OptionalStruct", "OptionalAny", "OptionalValue", "RepeatedDuration", "RepeatedTimestamp", "RepeatedFieldmask", "RepeatedStruct", "RepeatedAny", "RepeatedValue", "Fieldname1", "FieldName2", "FieldName3", "FieldName4", "Field0Name5", "Field0Name6", "FieldName7", "FieldName8", "FieldName9", "FieldName10", "FIELDNAME11", "FIELDName12", "FieldName13", "FieldName14", "FieldName15", "FieldName16", "FieldName17", "FieldName18" }, new[]{ "OneofField" }, new[]{ typeof(global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage), global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage.Parser, new[]{ "A", "Corecursive" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.TestAllTypesProto3), global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalNestedMessage", "OptionalForeignMessage", "OptionalNestedEnum", "OptionalForeignEnum", "OptionalAliasedEnum", "OptionalStringPiece", "OptionalCord", "RecursiveMessage", "RepeatedInt32", "RepeatedInt64", "RepeatedUint32", "RepeatedUint64", "RepeatedSint32", "RepeatedSint64", "RepeatedFixed32", "RepeatedFixed64", "RepeatedSfixed32", "RepeatedSfixed64", "RepeatedFloat", "RepeatedDouble", "RepeatedBool", "RepeatedString", "RepeatedBytes", "RepeatedNestedMessage", "RepeatedForeignMessage", "RepeatedNestedEnum", "RepeatedForeignEnum", "RepeatedStringPiece", "RepeatedCord", "MapInt32Int32", "MapInt64Int64", "MapUint32Uint32", "MapUint64Uint64", "MapSint32Sint32", "MapSint64Sint64", "MapFixed32Fixed32", "MapFixed64Fixed64", "MapSfixed32Sfixed32", "MapSfixed64Sfixed64", "MapInt32Float", "MapInt32Double", "MapBoolBool", "MapStringString", "MapStringBytes", "MapStringNestedMessage", "MapStringForeignMessage", "MapStringNestedEnum", "MapStringForeignEnum", "OneofUint32", "OneofNestedMessage", "OneofString", "OneofBytes", "OneofBool", "OneofUint64", "OneofFloat", "OneofDouble", "OneofEnum", "OptionalBoolWrapper", "OptionalInt32Wrapper", "OptionalInt64Wrapper", "OptionalUint32Wrapper", "OptionalUint64Wrapper", "OptionalFloatWrapper", "OptionalDoubleWrapper", "OptionalStringWrapper", "OptionalBytesWrapper", "RepeatedBoolWrapper", "RepeatedInt32Wrapper", "RepeatedInt64Wrapper", "RepeatedUint32Wrapper", "RepeatedUint64Wrapper", "RepeatedFloatWrapper", "RepeatedDoubleWrapper", "RepeatedStringWrapper", "RepeatedBytesWrapper", "OptionalDuration", "OptionalTimestamp", "OptionalFieldMask", "OptionalStruct", "OptionalAny", "OptionalValue", "RepeatedDuration", "RepeatedTimestamp", "RepeatedFieldmask", "RepeatedStruct", "RepeatedAny", "RepeatedValue", "Fieldname1", "FieldName2", "FieldName3", "FieldName4", "Field0Name5", "Field0Name6", "FieldName7", "FieldName8", "FieldName9", "FieldName10", "FIELDNAME11", "FIELDName12", "FieldName13", "FieldName14", "FieldName15", "FieldName16", "FieldName17", "FieldName18" }, new[]{ "OneofField" }, new[]{ typeof(global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum), typeof(global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.AliasedEnum) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage), global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage.Parser, new[]{ "A", "Corecursive" }, null, null, null), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, }), new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.ForeignMessage), global::ProtobufTestMessages.Proto3.ForeignMessage.Parser, new[]{ "C" }, null, null, null) })); @@ -277,6 +281,7 @@ namespace ProtobufTestMessages.Proto3 { optionalForeignMessage_ = other.optionalForeignMessage_ != null ? other.optionalForeignMessage_.Clone() : null; optionalNestedEnum_ = other.optionalNestedEnum_; optionalForeignEnum_ = other.optionalForeignEnum_; + optionalAliasedEnum_ = other.optionalAliasedEnum_; optionalStringPiece_ = other.optionalStringPiece_; optionalCord_ = other.optionalCord_; recursiveMessage_ = other.recursiveMessage_ != null ? other.recursiveMessage_.Clone() : null; @@ -618,6 +623,17 @@ namespace ProtobufTestMessages.Proto3 { } } + /// Field number for the "optional_aliased_enum" field. + public const int OptionalAliasedEnumFieldNumber = 23; + private global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.AliasedEnum optionalAliasedEnum_ = 0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.AliasedEnum OptionalAliasedEnum { + get { return optionalAliasedEnum_; } + set { + optionalAliasedEnum_ = value; + } + } + /// Field number for the "optional_string_piece" field. public const int OptionalStringPieceFieldNumber = 24; private string optionalStringPiece_ = ""; @@ -1752,6 +1768,7 @@ namespace ProtobufTestMessages.Proto3 { if (!object.Equals(OptionalForeignMessage, other.OptionalForeignMessage)) return false; if (OptionalNestedEnum != other.OptionalNestedEnum) return false; if (OptionalForeignEnum != other.OptionalForeignEnum) return false; + if (OptionalAliasedEnum != other.OptionalAliasedEnum) return false; if (OptionalStringPiece != other.OptionalStringPiece) return false; if (OptionalCord != other.OptionalCord) return false; if (!object.Equals(RecursiveMessage, other.RecursiveMessage)) return false; @@ -1878,6 +1895,7 @@ namespace ProtobufTestMessages.Proto3 { if (optionalForeignMessage_ != null) hash ^= OptionalForeignMessage.GetHashCode(); if (OptionalNestedEnum != 0) hash ^= OptionalNestedEnum.GetHashCode(); if (OptionalForeignEnum != 0) hash ^= OptionalForeignEnum.GetHashCode(); + if (OptionalAliasedEnum != 0) hash ^= OptionalAliasedEnum.GetHashCode(); if (OptionalStringPiece.Length != 0) hash ^= OptionalStringPiece.GetHashCode(); if (OptionalCord.Length != 0) hash ^= OptionalCord.GetHashCode(); if (recursiveMessage_ != null) hash ^= RecursiveMessage.GetHashCode(); @@ -2068,6 +2086,10 @@ namespace ProtobufTestMessages.Proto3 { output.WriteRawTag(176, 1); output.WriteEnum((int) OptionalForeignEnum); } + if (OptionalAliasedEnum != 0) { + output.WriteRawTag(184, 1); + output.WriteEnum((int) OptionalAliasedEnum); + } if (OptionalStringPiece.Length != 0) { output.WriteRawTag(194, 1); output.WriteString(OptionalStringPiece); @@ -2359,6 +2381,9 @@ namespace ProtobufTestMessages.Proto3 { if (OptionalForeignEnum != 0) { size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalForeignEnum); } + if (OptionalAliasedEnum != 0) { + size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalAliasedEnum); + } if (OptionalStringPiece.Length != 0) { size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalStringPiece); } @@ -2623,6 +2648,9 @@ namespace ProtobufTestMessages.Proto3 { if (other.OptionalForeignEnum != 0) { OptionalForeignEnum = other.OptionalForeignEnum; } + if (other.OptionalAliasedEnum != 0) { + OptionalAliasedEnum = other.OptionalAliasedEnum; + } if (other.OptionalStringPiece.Length != 0) { OptionalStringPiece = other.OptionalStringPiece; } @@ -2953,6 +2981,10 @@ namespace ProtobufTestMessages.Proto3 { OptionalForeignEnum = (global::ProtobufTestMessages.Proto3.ForeignEnum) input.ReadEnum(); break; } + case 184: { + OptionalAliasedEnum = (global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.AliasedEnum) input.ReadEnum(); + break; + } case 194: { OptionalStringPiece = input.ReadString(); break; @@ -3440,6 +3472,15 @@ namespace ProtobufTestMessages.Proto3 { [pbr::OriginalName("NEG")] Neg = -1, } + public enum AliasedEnum { + [pbr::OriginalName("ALIAS_FOO")] AliasFoo = 0, + [pbr::OriginalName("ALIAS_BAR")] AliasBar = 1, + [pbr::OriginalName("ALIAS_BAZ")] AliasBaz = 2, + [pbr::OriginalName("QUX", PreferredAlias = false)] Qux = 2, + [pbr::OriginalName("qux", PreferredAlias = false)] Qux_ = 2, + [pbr::OriginalName("bAz", PreferredAlias = false)] BAz = 2, + } + public sealed partial class NestedMessage : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index cf1a89a8ca041d034694df980457a50040ccb7ed..23d927275659dba733c51fba0c7dababc0bbdf7e 100644 GIT binary patch delta 9792 zcmY+~cW_rly9e+*dp7O&OF~!@(yN33AwBdOdWR4oy(cClAt8`L^{AtxBQrKc>^gSk z-a!RqR4j}XM^Ww!_TFaRJHB`HzV9FRzdP^!Zhrgh=Khyw&+ccR-Lq#;`Q_Awm`fL9 zZoPxfivPVLE}c35uPY*Py24}2twWcE-Xad7YO?!ke!{+71>-EI53I$OF1M)o8p zWz&qfvLz?m{zH_dSB8$P#)0iqxV|YoUw%z=Loi+;8(5UIlR!v1-_`Y&-R zlK%7jzy3$Wd45bl$}mYvZWKGbKujQ9N2I)sk%}Wvd7ETrAT|)8k9p$%g(6IOTcira z1tRrP5r(!~WUPx(eM|ggZY^+l>xAmQ?rZCW`h@yhC)7u{Z9;wBe%plVLLZ+{9l2J? z7~8vt>Qyq*#i(8t2-<99oAS0#sE>(2?CML@-#(#!xbmteR1Zh>>Iv1uQN0?~lk}wO znW+(3$Nzmnl3!ydSA@Z+5s{(E9iOh6sHq$w{hEwS2)aG+T9JiZaZUtDC2K`ZmZ?cl zYOSItvDPXCrPeA)sm>SKh7n-uL@hG{Or3}_sP3^YI+-Idb(vWv83grK@u1X;x@=R^ zgHmr5J?HgS@pMDqGE#XBmXTl@L_ISSOoL_gsc5i_1k+#@RBW_LIFv@wz)JY|K^~Gm zLygfsk0~5Xqh%tL*CcYx%tU}`5{=A6fN2uZW`q%7ngXdDL21g$HZv2cyk@IJLTMIF zIi_YLlx7j_a|ou{GLc}KEfb}@7LjX`i2~Cinwg0L(;@;!iGtD+Oy>wnOLmS)CR%x| zR*8nvDq3;_xXSe!iU!kanP@PrmWc+_n#D{&d2M#-1;Dh4)?CwJ07{!(dI2bHcIgG6 zw59U`4l1vG{51Kx_aK;d(Z)+J2&Ubh?I4(Td$xmM+B10R#VD^s=>114F;F^0JD;W) zC>?1Tm>FMRPO-}Cw2LMdOsD9`G*x54blPNM!F1YWV!?FUWa5<9 zWoIT1N|)&5Wa6N7*_nxh(iNH+AKk}+>9SKZNqOC3wHebSFx{eyXJ!)CWw)4QQkw*( zJAWxhP`X#FGG{wpc|BH%hteauSDTvgPfuir9L z!1RkgPG$;}eydD@(r=Y1Q2MQspu7RGz|3!g4`x90Gn0VxG+@tm0+@klUI__c26ApP zsU_g59GEsA4(@#-L0@?TdGpNdCn|4H%rt!@qKiQ>u)s7-L>Gg$3qKJJ2cvnLPedPs zDQR34eGI10FnuKIJ_a-LO&?R0Hza18KBl6NAu%}9G@Odr7!thNr=s0Z;&eWSE{0|n zm^+b7Qr_^1HZRdn!UjBSw}2#MIUF~|v`K<6oWPfP5`^IyvrHbz${P^{reZRX5sM@P z8L>z*kP(X{0~xVMit@cttE4~~wMq(<(O6C;1>phePw9JEL}kb@RU2XYXI z*@)Aj9JES?@(x)g1Ii(*WI#C-!?ThBxbNH&n87V)#89JNX| zl%rP3hH}&@Im)}mDmhSYu}Th*TkML<0dk97aXCP4u}H4+e2e5ttUuo>xlnw2hH|0! z_B7{0(Q9S==~&#PeFqq6oLES+mYdM5;2W{MJW-4FFJDrpd2_Z}Q5z0p#OfhZqLET9u z>o^2;r=w;ld6%PRfI`UB3?y|I1rtrv8IbOxl2sf+y30v3mAubR$ zSyB3MVI|&8^u1*k_I<=f%gsy{D0z%TnQ2^ro)B_R1?cIR>!|=ukCEb6g#z?+jB=-O zTXb}c@=A3_di({tr(-m|Brs+CHDk7t_mU_{4bR@(wl@%%G@krysUlE%j5veYm?jh? z8FV&`dns)ehv@QNDl9h17bLwLU(Wic=mFjfrg0f!X> zd%$5ONp|aPCBPnZSgDf79aahq;e!?{1%?8~N`W1BRw=CG z&MH&#Arcj4#>!wJJgzN&{N$DaLkVApWxyVyv?4R1WxyVy(sDCpqxhAs;U|sjdGhG4fVJe?v5}Tvs zNoUQ0h45jTYZ}jig#xzbz&c63#pVDz>9DyH{I!i{o~l24LYZbrEX7{Vv) zC>H@k0dH`NfIUe$3(Y7O!FrOG=yx0ap0`-Zr$|&9YcVW@PttN-Tkn61fuV%Ih%5&7 z6y+>3*kWK$(Nf-qmniu(i6sVG0u13(RB382frWx}4q-h_IrBJ#^)xNi?>RcLrAqqG zkXUN4rN9tAO-oGmrNB^-!6C3`C}%#0z@DK+OR$XtiwaW_&yx5z@(VNqn%y{%W%Iy7~uVP87e1_tPt{DZ8@4g zPii_JMbqbL=4{inQpp!wx0UD?A>Xws3G43#*KH-*zTmoDq2!Asc`8?+Ey8Hi&kA(= zA_e${zXDBPq-6aHrANC`$(Km-rM?nP5k{G&E79~NiXML!(&v9A+P*|nQ%u`cO1|t; zUWK*@IptMo`?AY;6`H>6GG49ZD=y>JXo`?CUX7-&xQth$=_};hl-DTvs_S+Q+9Kp` z*P!jIuG=+e`>N}9t&*om^7>ti^Mf$XjCL)Wo}x*-AFoBzQY}FPu~V5Uw7CBUjALjhwOfW7Xp4ZvP^)*R8b?778->O4tbO4a%HjGTR934Vte%aOlJ~DS5_Wn}8vFgBF|Gn}DH!FW616 z&NyomtTWEqtmIiY$j$g95rO!O#Wn*&0grMsu(NKIn}MBmquiq8IhPo|zegZEYe%^S z7794AEwIkH#J0dX=ex|dD*2|v@O3@{;W?YwR$wS#Y%8!g9kvzNo6g#%MR&6hfA& zA-&_IYDn)msT$HdM$$Xc4ka&;{noVu6hfwUfVx0I-e`A#xX&fuVr!^3A}m(p3IYq#4*%%9~-Z79~F- zQD_otfraoY@dw!!SSa9UoEBIgQ8HgnEk3Z1+=EN2k{|0mFm!dbVpSmIRnZFSV+!(z zm{w39(=?vWR!ASa9k5NwPxM1xNNR(Gkfkq5ZE7)F*^5%BD7`PiWy1Gs1Qy zuQ{q66hfxjL0xnEUpu60PHKmA%}E_feoBJx&K;0^#7uR7`jmqF&8h>`rMm{C6pNU9Zy+)ddP6 zQ(d60Q;;8Xx^z5dNu2RBGuw+r-UJX)b3()4mO zoEsFSID~V967}zc`i9@FIL5PnX)A@l%40b@PDzM!ZCgY^LWf|B%4jykd3N`9&Dn;~mAEQDVW?+3eK zp&*jCwcWtJq$s|Sb_4s;Judeu`IQ@GFEE5(5?E&_!!}b9C)>#8ee&=Rv02ab;tu+7(1+YSw^#HK% z+>{Lf`_4_-ppxIabukDG;dge%27#e~6B~r}y;~Q9u)cTeVy}`vIBT!;RRrSi?ZVg# z38Hlfx!eZ~ z;g1&E2Mh&_?F04`;n&j8rL+&&Pn4p62x;$Q5F9RY>{ z#zuhs>aY=DzdCGG$=}>4N0Au9U#&F?3k7VA!urh(aun8Ylv2Y}Hm2n74jTi8@Hack zF<>ZQYz)}%4jTjZyPmPKfG5MEmHgYutLa{a|2O-|Jz9TnKxke&qr-#_RU%H9kfb91 zps@cU!jFfZ{%<1rhqm>(#6Jir`F9d= z$n5VFqkl*i;rIsfCx!hp)K9q1=uZmQzj(`V{ogn8FZ?r+UQjy1L4>g!BHh0T|2Gt> ui-Z5|>gt3Ma$OuisOy%E!wCQ3D&v1X&H>lO z*;|EiqMYr*sT{YibByDWcpN5=BI1 zvs3x$_WV?@%Tp86&6KgGUhge;H5E#|S5#8fD+;CFE80d4v9558hH23C!f2QVo$F8y z(~vhyBAABRif!o##fF z1Jjr)mI$S>yu!`Q1RFJZWdcf*Zme`QC!jRxyjVh*CeKWOY4S|2jhc0pOC}elSvLuj z3)8GqPRT`S&M%b+rMaTgC6i~P7O&)?wCLulRGis*c`z-W$%AR}Odd>2xiBdkwfe1> zf@#$)Rj$JnN~_;`DU?>f^-?IUrLuwZZPb=tra0O7`7mv|RkmI}Oq*Zre3&-B+W9bT zWwP}OY}Br2yO}9KY1eJCOa&)6}fYLspP$HD}k}_r{PAF~)+vQej>nMo*}xIImGW)ViPj;zIhUuEWSt69KE4R7To?@eJuS`Md)?M3O%_%6|dP+Kqv-A|0 z?)g{9k1*YynQEg$o|y`BNOub}73PpGaP6j|9GbsDB9ud3u{P@Qibd(shnx~?3)7<~ zx`q~}XZ}WsV0t_=%|^X?otv3yFul4*l9|Q?_xfd;hSHlSOE?Xsw{ng%r*S#;&Rq+W z!`#Qyl53{7dX1a6LL2qzg|3f6`smZW>s-r1`snk06wBkQayqlouVtT3r(yr}dGZ^5^e>uerJl=mqZUQs7lOFZg@(hwbI%%3CW&j>7l zQI2_KCdx6d%tSfnm6@b<%p%tjgUO1X_rdZirXq({m@ zPI{yqUUfP%BbIQ6)2-#skG6UM=C+aJW>fV<`<|E zWXvy6CCJ!+ADKWPWxGzi*nk}%3P4s9;vp`^}4~WT{Xz{9;xOY zbA5j1;KTl_M!CLjhg3zmeowu-CCszY8L!MkIpdXiC};AET(fx~XXmk8zTq9qb>dp}#V)!p6~Cb##qwOibjEdtfc zUCl*F7ruu@^bq?V7SSw@tvuTo(M4P(7ycr;h^v>mE*2$S#PjM>)6&QP#n${u>AK?V ziu%JNsnn$OJ#4YD*_6i1-IHZ;PP*1i2~`r7ERrxv!kVQqi6%#&CDz;onVOuomKd8u z_$O88sxJYfK(HlXHwA17*iB&0s`q>u&c1{PH)&aJ^ib#xku?`Zj`IR2=Deg zb~P9UvX-mC?olO+UD~U`?oqXMZj@`RxmW30XRW~^yhkOMa`LXT28)6jE{xZJ-K$EH zvts&ZuzS_w8i%d5=Dx7W)`Ah9uet;M=8Y_hdj_k|6+&YJtfAlG3L#`pP6 zwhoLEnX+|Y_lHrg1G_(ra=kSVD80pvay=N~{eG0|u_%yF6zj1bP?hW5AlG9(pf)A1 z9O?J34c0uU^j3#$03&=rZE@8%fKebHDmH*Us46$euV4?V&0E}zZM5c`(wm&M5sUCa zmE5e8`Q3;`L8*i>*f~|XMq;pYYJKwlkzAIWta(W3%?{fHMtDwba8LvF4G`?H0Nvly0}s z_L0!-7TP`%y4`BcqsqusZlx(*rPN+=m$MbpPa##hnw@sRO0Yn})hZ=-2U zEGciJ?Gqv8ZM1zNq`cjlCquW}X-g>GZl~#!q1){=eKK@=wKY#EBm4Ji)`xIXdUQPh zuBPo%YO>tiucqx&s+ksj?1Yc43gw%As*^$!l#3=9qb(@@3unUVgnl-rg&*p^iB zJ4^4N0}4vq^zFdEpi1Qiv;+TwTDc}Oo3Y+$&C^P+ci2ua!V5}v@lG%bWR-VW=n~rvMtIR< zyTK@si*GmBGivrKm)LHsXVlu{dqk4h9&4Tr)*dXvXVk`2oVhLR0i#5)Jz&oUY!BG8 z0o!ZMb77Qw!3duP%UFA{D3DR^#dcI$~^P{W>qd*d?2YWsw zRuA@kNUXt{7lPG*Mfki=tO1Jxu^O;mhy&ID_Cmn+S#v3javvDs3m)4CMuCiSAK0ZZ z%6(Xu!YKD!^I~#?&rHyMK6wzPubt%k*M6uMRsLN08R|t=Cwx=M*60AEfX7w(4AB90IUKV(z%Hw$ z$tz#7fSuO7rSvLibz%`-R&vMe#G*iM&T%K$TdGt}be&*tsbwo2c8xV}ha>YfV1#ce zxyxMxMuA}0V7;wMm%2Q!!FpRQm*aPrHSZ|B)Fsx1MHs*BkIY?Ql*nPS3+x?LBnQ(j zuy@qrT9;V2HSa1ulxE)Xy1@wFQPOoc76tP3@5Xvp&5*xgbYs1%suy6T&wmH4c~9vY zhaChXd{@b5*n?mc$l>Q8*n4W0Tu%qV-U|nsL)N^X+ygU9b%og-{Nbt>=_6GoPySw{kNlHg z_gV8X_dj`)?t}U`P<>Dzt9&_+_CbBD%H^G>59(u8D=+CstobC_rkTMXK_Zl-jv#%a z^5yt*1nCo1>2^w?J_7YgvP(zPmruVnpPs)^6ph6F?1N90{={$4e$HGJOmN-w1AVG; zt%NwAs_DsRt>iMi)|$_fOE$AXuf-z#RLLppS}Y30x)$p*#aTQvf@`tj&%%-OI%_^p zF0%}F9T?$fN^S_(fl(mXbzq;X+(L(42lly|nf!?`N$jXKUnI}XjCB-?@N*^C@KG!Z zCdkR;DA*S&SFWU^U|)no=`m}*45K^-M)-x2r}8l{3M8>(SYL)w9>e-F4Dz@&Uxmbu z^JO@P_)9;^<6smBb{y=hkl1msuR>x2)_k3OWXOzi0E_S|pV$Bv1!4_geI1r^0PE{G ztmU9J-vn$BjPPr}mV;mv2sQ}zO~3}hz6sU|YrYLLb^?p=8*iP!q5v!NW^w}T+c0G( zz`hMrHe}6rVP6b^5q|4uYzT}3No)w~yRa{Yu)YiXV%VDRgEh>PF^Bj&zcGfvC=hHI z?E8QXgMA;c5o>-3*a(Rce($XjEDFRL!TKRsBUnGE*zeer*8G?p8#8Np5{&Q%kDUag zK(LcwKPvvZnYolsg8it9lD|nOyMNT0pMo`tMfjtVGwCQ61&NjZ%kU`JPXQYR`zc^! z*8CiH>=+o~PaYcsqd*cH!}>XF*fFf1!-gHV=9gfN8yn{k|Lk|{I2Z+jjf4FXuyL?o z0(Q!pU&AO*kr?4G-a3Uvfmo-oehq^>h4rf{YLh8DZOv~1I}Jwos~_cQFbV`a4fb2W zPJ{iH%-Hf&WU}(C`Rn%pXcmO79CI5+nRwWeyM&kQfD-#0Y8phsw>oY{$f8_J=A+ z{_v}_`8e`7mGzHIKiNsuzp3oxFVrSG`EMEXccs(!`6S{;!ih=tNl3bXS5uPD_DNlS r{EtvKNtjUT@&jQ~cX_%p;eUq8Nn1jxtkb_vncAB(GCDjyyyE`>Bk+#- diff --git a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java index 3c168e6929..2a41cf1ef0 100644 --- a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java @@ -45,7 +45,8 @@ import java.util.RandomAccess; final class BooleanArrayList extends AbstractProtobufList implements BooleanList, RandomAccess, PrimitiveNonBoxingCollection { - private static final BooleanArrayList EMPTY_LIST = new BooleanArrayList(); + private static final BooleanArrayList EMPTY_LIST = new BooleanArrayList(new boolean[0], 0); + static { EMPTY_LIST.makeImmutable(); } diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index 161a1b64fa..ec48796164 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -377,7 +377,7 @@ public abstract class CodedInputStream { /** * Set the maximum message recursion depth. In order to prevent malicious messages from causing * stack overflows, {@code CodedInputStream} limits how deeply messages may be nested. The default - * limit is 64. + * limit is 100. * * @return the old limit. */ diff --git a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java index d0fa9b7e68..d4f63d6b91 100644 --- a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java @@ -45,7 +45,8 @@ import java.util.RandomAccess; final class DoubleArrayList extends AbstractProtobufList implements DoubleList, RandomAccess, PrimitiveNonBoxingCollection { - private static final DoubleArrayList EMPTY_LIST = new DoubleArrayList(); + private static final DoubleArrayList EMPTY_LIST = new DoubleArrayList(new double[0], 0); + static { EMPTY_LIST.makeImmutable(); } diff --git a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java index 62330c3aa0..ac20de865b 100644 --- a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java @@ -45,7 +45,8 @@ import java.util.RandomAccess; final class FloatArrayList extends AbstractProtobufList implements FloatList, RandomAccess, PrimitiveNonBoxingCollection { - private static final FloatArrayList EMPTY_LIST = new FloatArrayList(); + private static final FloatArrayList EMPTY_LIST = new FloatArrayList(new float[0], 0); + static { EMPTY_LIST.makeImmutable(); } diff --git a/java/core/src/main/java/com/google/protobuf/IntArrayList.java b/java/core/src/main/java/com/google/protobuf/IntArrayList.java index ad128b59d8..54a378b001 100644 --- a/java/core/src/main/java/com/google/protobuf/IntArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/IntArrayList.java @@ -45,7 +45,8 @@ import java.util.RandomAccess; final class IntArrayList extends AbstractProtobufList implements IntList, RandomAccess, PrimitiveNonBoxingCollection { - private static final IntArrayList EMPTY_LIST = new IntArrayList(); + private static final IntArrayList EMPTY_LIST = new IntArrayList(new int[0], 0); + static { EMPTY_LIST.makeImmutable(); } diff --git a/java/core/src/main/java/com/google/protobuf/LongArrayList.java b/java/core/src/main/java/com/google/protobuf/LongArrayList.java index 99f7fdbc5c..1a0943cee0 100644 --- a/java/core/src/main/java/com/google/protobuf/LongArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/LongArrayList.java @@ -45,7 +45,8 @@ import java.util.RandomAccess; final class LongArrayList extends AbstractProtobufList implements LongList, RandomAccess, PrimitiveNonBoxingCollection { - private static final LongArrayList EMPTY_LIST = new LongArrayList(); + private static final LongArrayList EMPTY_LIST = new LongArrayList(new long[0], 0); + static { EMPTY_LIST.makeImmutable(); } diff --git a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java index 9834161382..f9a9c85942 100644 --- a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java @@ -37,7 +37,8 @@ import java.util.List; /** Implements {@link ProtobufList} for non-primitive and {@link String} types. */ final class ProtobufArrayList extends AbstractProtobufList { - private static final ProtobufArrayList EMPTY_LIST = new ProtobufArrayList(); + private static final ProtobufArrayList EMPTY_LIST = + new ProtobufArrayList(new ArrayList(0)); static { EMPTY_LIST.makeImmutable(); diff --git a/js/binary/proto_test.js b/js/binary/proto_test.js index 161821068f..ae31c8d1ce 100644 --- a/js/binary/proto_test.js +++ b/js/binary/proto_test.js @@ -661,4 +661,5 @@ describe('protoBinaryTest', function() { checkAllFields(msg, msg2); }); + }); diff --git a/js/message.js b/js/message.js index 17b562e16e..1ca9fac0f5 100644 --- a/js/message.js +++ b/js/message.js @@ -41,6 +41,8 @@ goog.provide('jspb.Message'); goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.crypt.base64'); +goog.require('jspb.BinaryConstants'); +goog.require('jspb.BinaryReader'); goog.require('jspb.Map'); // Not needed in compilation units that have no protos with xids. @@ -622,10 +624,7 @@ jspb.Message.serializeBinaryExtensions = function(proto, writer, extensions, * Reads an extension field from the given reader and, if a valid extension, * sets the extension value. * @param {!jspb.Message} msg A jspb proto. - * @param {{ - * skipField:function(this:jspb.BinaryReader), - * getFieldNumber:function(this:jspb.BinaryReader):number - * }} reader + * @param {!jspb.BinaryReader} reader * @param {!Object} extensions The extensions object. * @param {function(this:jspb.Message,!jspb.ExtensionFieldInfo)} getExtensionFn * @param {function(this:jspb.Message,!jspb.ExtensionFieldInfo, ?)} setExtensionFn diff --git a/js/testbinary.proto b/js/testbinary.proto index ed5bdfc68f..ee4d2dfac4 100644 --- a/js/testbinary.proto +++ b/js/testbinary.proto @@ -242,3 +242,4 @@ enum MapValueEnum { message MapValueMessage { optional int32 foo = 1; } + diff --git a/python/google/protobuf/message.py b/python/google/protobuf/message.py index 2f89857c85..8854c86529 100755 --- a/python/google/protobuf/message.py +++ b/python/google/protobuf/message.py @@ -172,6 +172,9 @@ class Message(object): we *do* stop because of an END_GROUP tag, the number of bytes returned does not include the bytes for the END_GROUP tag information. + + Raises: + message.DecodeError if the input cannot be parsed. """ raise NotImplementedError diff --git a/src/Makefile.am b/src/Makefile.am index 16cbe0ce31..13a5a149a8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -201,7 +201,6 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/stubs/time.cc \ google/protobuf/stubs/time.h \ google/protobuf/arena.cc \ - google/protobuf/arenastring.cc \ google/protobuf/extension_set.cc \ google/protobuf/generated_message_util.cc \ google/protobuf/generated_message_table_driven_lite.h \ diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 1c95380d27..4e994a8075 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -195,7 +195,7 @@ void Any::Clear() { const char* Any::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -207,7 +207,7 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object // string type_url = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Any.type_url"); auto str = msg->mutable_type_url(); @@ -226,7 +226,7 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object // bytes value = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); auto str = msg->mutable_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index ba93762273..5858b1208c 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -62,7 +62,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ { +class PROTOBUF_EXPORT Any final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ { public: Any(); virtual ~Any(); diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 2a5c466efb..63695f78a0 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -301,7 +301,7 @@ void Api::Clear() { const char* Api::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -313,7 +313,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Api.name"); auto str = msg->mutable_name(); @@ -333,7 +333,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Method::_InternalParse; object = msg->add_methods(); @@ -351,7 +351,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -368,7 +368,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object // string version = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Api.version"); auto str = msg->mutable_version(); @@ -387,7 +387,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object // .google.protobuf.SourceContext source_context = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); @@ -403,7 +403,7 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Mixin::_InternalParse; object = msg->add_mixins(); @@ -972,7 +972,7 @@ void Method::Clear() { const char* Method::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -984,7 +984,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.name"); auto str = msg->mutable_name(); @@ -1003,7 +1003,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj // string request_type_url = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.request_type_url"); auto str = msg->mutable_request_type_url(); @@ -1032,7 +1032,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj // string response_type_url = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.response_type_url"); auto str = msg->mutable_response_type_url(); @@ -1062,7 +1062,7 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -1601,7 +1601,7 @@ void Mixin::Clear() { const char* Mixin::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1613,7 +1613,7 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Mixin.name"); auto str = msg->mutable_name(); @@ -1632,7 +1632,7 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje // string root = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Mixin.root"); auto str = msg->mutable_root(); diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 518c6be844..11e819610e 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -71,7 +71,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ { +class PROTOBUF_EXPORT Api final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ { public: Api(); virtual ~Api(); @@ -261,7 +262,8 @@ class PROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_inser }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ { +class PROTOBUF_EXPORT Method final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ { public: Method(); virtual ~Method(); @@ -444,7 +446,8 @@ class PROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc_in }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ { +class PROTOBUF_EXPORT Mixin final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ { public: Mixin(); virtual ~Mixin(); diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index dc540cfa27..8e35a0e0a9 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -1323,7 +1323,7 @@ class ParseLoopGenerator { "end, void* object,\n" " ::$proto_ns$::internal::ParseContext* ctx) {\n" " auto msg = static_cast<$classname$*>(object);\n" - " $uint32$ size; (void)size;\n" + " $int32$ size; (void)size;\n" " int depth; (void)depth;\n" " $uint32$ tag;\n" " ::$proto_ns$::internal::ParseFunc parser_till_end; " @@ -1548,7 +1548,7 @@ class ParseLoopGenerator { void GenerateLengthDelim(const FieldDescriptor* field) { format_( - "ptr = ::$proto_ns$::io::Parse32(ptr, &size);\n" + "ptr = ::$proto_ns$::io::ReadSize(ptr, &size);\n" "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); if (!IsProto1(field->file(), options_) && field->is_packable()) { if (!HasPreservingUnknownEnumSemantics(field->file()) && diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index a729282080..10aef2db16 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -244,6 +244,12 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) { // TODO(ckennelly): Cull these exclusions if/when these protos do not have // their methods overriden by subclasses. +bool ShouldMarkClassAsFinal(const Descriptor* descriptor, + const Options& options) { + const string name = ClassName(descriptor, true); + return HasPrefixString(name, "::google::protobuf"); +} + bool ShouldMarkClearAsFinal(const Descriptor* descriptor, const Options& options) { static std::set exclusions{ @@ -926,6 +932,9 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) { void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { Formatter format(printer, variables_); + format.Set("class_final", + ShouldMarkClassAsFinal(descriptor_, options_) ? "final": ""); + if (IsMapEntryMessage(descriptor_)) { std::map vars; CollectMapInfo(options_, descriptor_, &vars); @@ -967,9 +976,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { } format( - "class $dllexport_decl $${1$$classname$$}$ : public $superclass$ " - "/* @@protoc_insertion_point(class_definition:$full_name$) */ " - "{\n", + "class $dllexport_decl $${1$$classname$$}$$ class_final$ :\n" + " public $superclass$ /* @@protoc_insertion_point(" + "class_definition:$full_name$) */ {\n", descriptor_); format(" public:\n"); format.Indent(); diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 06383936de..c85cb7993b 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -3064,38 +3064,42 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options, " * @return {!$class$}\n" " */\n" "$class$.deserializeBinaryFromReader = function(msg, reader) {\n" - " while (reader.nextField()) {\n" - " if (reader.isEndGroup()) {\n" - " break;\n" - " }\n" - " var field = reader.getFieldNumber();\n" - " switch (field) {\n", + " while (reader.nextField()) {\n", "class", GetMessagePath(options, desc)); + printer->Print( + " if (reader.isEndGroup()) {\n" + " break;\n" + " }\n" + " var field = reader.getFieldNumber();\n" + " switch (field) {\n"); - for (int i = 0; i < desc->field_count(); i++) { - if (!IgnoreField(desc->field(i))) { - GenerateClassDeserializeBinaryField(options, printer, desc->field(i)); + + for (int i = 0; i < desc->field_count(); i++) { + if (!IgnoreField(desc->field(i))) { + GenerateClassDeserializeBinaryField(options, printer, desc->field(i)); + } } - } - printer->Print( - " default:\n"); - if (IsExtendable(desc)) { printer->Print( - " jspb.Message.readBinaryExtension(msg, reader, $extobj$Binary,\n" - " $class$.prototype.getExtension,\n" - " $class$.prototype.setExtension);\n" - " break;\n", - "extobj", JSExtensionsObjectName(options, desc->file(), desc), - "class", GetMessagePath(options, desc)); - } else { - printer->Print( - " reader.skipField();\n" - " break;\n"); - } + " default:\n"); + if (IsExtendable(desc)) { + printer->Print( + " jspb.Message.readBinaryExtension(msg, reader,\n" + " $extobj$Binary,\n" + " $class$.prototype.getExtension,\n" + " $class$.prototype.setExtension);\n" + " break;\n" + " }\n", + "extobj", JSExtensionsObjectName(options, desc->file(), desc), + "class", GetMessagePath(options, desc)); + } else { + printer->Print( + " reader.skipField();\n" + " break;\n" + " }\n"); + } printer->Print( - " }\n" " }\n" " return msg;\n" "};\n" diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 9b34152949..857eec7eae 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -314,7 +314,7 @@ void Version::Clear() { const char* Version::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -356,7 +356,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob // optional string suffix = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.Version.suffix"); auto str = msg->mutable_suffix(); @@ -793,7 +793,7 @@ void CodeGeneratorRequest::Clear() { const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -806,7 +806,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.file_to_generate"); auto str = msg->add_file_to_generate(); @@ -827,7 +827,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* // optional string parameter = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.parameter"); auto str = msg->mutable_parameter(); @@ -846,7 +846,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* // optional .google.protobuf.compiler.Version compiler_version = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::compiler::Version::_InternalParse; object = msg->mutable_compiler_version(); @@ -862,7 +862,7 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* case 15: { if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FileDescriptorProto::_InternalParse; object = msg->add_proto_file(); @@ -1312,7 +1312,7 @@ void CodeGeneratorResponse_File::Clear() { const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1324,7 +1324,7 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.name"); auto str = msg->mutable_name(); @@ -1343,7 +1343,7 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const // optional string insertion_point = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point"); auto str = msg->mutable_insertion_point(); @@ -1362,7 +1362,7 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const // optional string content = 15; case 15: { if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.content"); auto str = msg->mutable_content(); @@ -1764,7 +1764,7 @@ void CodeGeneratorResponse::Clear() { const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1776,7 +1776,7 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* // optional string error = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.error"); auto str = msg->mutable_error(); @@ -1796,7 +1796,7 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* case 15: { if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::compiler::CodeGeneratorResponse_File::_InternalParse; object = msg->add_file(); diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index a8e4479fb4..c84da10231 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -83,7 +83,8 @@ namespace compiler { // =================================================================== -class PROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ { +class PROTOC_EXPORT Version final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ { public: Version(); virtual ~Version(); @@ -235,7 +236,8 @@ class PROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_ins }; // ------------------------------------------------------------------- -class PROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { +class PROTOC_EXPORT CodeGeneratorRequest final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { public: CodeGeneratorRequest(); virtual ~CodeGeneratorRequest(); @@ -409,7 +411,8 @@ class PROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* }; // ------------------------------------------------------------------- -class PROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse.File) */ { +class PROTOC_EXPORT CodeGeneratorResponse_File final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse.File) */ { public: CodeGeneratorResponse_File(); virtual ~CodeGeneratorResponse_File(); @@ -569,7 +572,8 @@ class PROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Mess }; // ------------------------------------------------------------------- -class PROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse) */ { +class PROTOC_EXPORT CodeGeneratorResponse final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse) */ { public: CodeGeneratorResponse(); virtual ~CodeGeneratorResponse(); diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 198bcca7f0..bba219b48d 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1468,7 +1468,7 @@ void FileDescriptorSet::Clear() { const char* FileDescriptorSet::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1481,7 +1481,7 @@ const char* FileDescriptorSet::_InternalParse(const char* begin, const char* end case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FileDescriptorProto::_InternalParse; object = msg->add_file(); @@ -1924,7 +1924,7 @@ void FileDescriptorProto::Clear() { const char* FileDescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1936,7 +1936,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.name"); auto str = msg->mutable_name(); @@ -1955,7 +1955,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional string package = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.package"); auto str = msg->mutable_package(); @@ -1975,7 +1975,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.dependency"); auto str = msg->add_dependency(); @@ -1997,7 +1997,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto::_InternalParse; object = msg->add_message_type(); @@ -2015,7 +2015,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumDescriptorProto::_InternalParse; object = msg->add_enum_type(); @@ -2033,7 +2033,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ServiceDescriptorProto::_InternalParse; object = msg->add_service(); @@ -2051,7 +2051,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_extension(); @@ -2068,7 +2068,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional .google.protobuf.FileOptions options = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FileOptions::_InternalParse; object = msg->mutable_options(); @@ -2083,7 +2083,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional .google.protobuf.SourceCodeInfo source_code_info = 9; case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceCodeInfo::_InternalParse; object = msg->mutable_source_code_info(); @@ -2108,7 +2108,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 80 && (ptr += 1)); break; } else if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_public_dependency(); @@ -2131,7 +2131,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 88 && (ptr += 1)); break; } else if (static_cast<::google::protobuf::uint8>(tag) != 90) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_weak_dependency(); @@ -2144,7 +2144,7 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e // optional string syntax = 12; case 12: { if (static_cast<::google::protobuf::uint8>(tag) != 98) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.syntax"); auto str = msg->mutable_syntax(); @@ -2970,7 +2970,7 @@ void DescriptorProto_ExtensionRange::Clear() { const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -3002,7 +3002,7 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co // optional .google.protobuf.ExtensionRangeOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ExtensionRangeOptions::_InternalParse; object = msg->mutable_options(); @@ -3390,7 +3390,7 @@ void DescriptorProto_ReservedRange::Clear() { const char* DescriptorProto_ReservedRange::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -3820,7 +3820,7 @@ void DescriptorProto::Clear() { const char* DescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -3832,7 +3832,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.DescriptorProto.name"); auto str = msg->mutable_name(); @@ -3852,7 +3852,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_field(); @@ -3870,7 +3870,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto::_InternalParse; object = msg->add_nested_type(); @@ -3888,7 +3888,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumDescriptorProto::_InternalParse; object = msg->add_enum_type(); @@ -3906,7 +3906,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto_ExtensionRange::_InternalParse; object = msg->add_extension_range(); @@ -3924,7 +3924,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_extension(); @@ -3941,7 +3941,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, // optional .google.protobuf.MessageOptions options = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::MessageOptions::_InternalParse; object = msg->mutable_options(); @@ -3957,7 +3957,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::OneofDescriptorProto::_InternalParse; object = msg->add_oneof_decl(); @@ -3975,7 +3975,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::DescriptorProto_ReservedRange::_InternalParse; object = msg->add_reserved_range(); @@ -3993,7 +3993,7 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.DescriptorProto.reserved_name"); auto str = msg->add_reserved_name(); @@ -4694,7 +4694,7 @@ void ExtensionRangeOptions::Clear() { const char* ExtensionRangeOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -4707,7 +4707,7 @@ const char* ExtensionRangeOptions::_InternalParse(const char* begin, const char* case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -5175,7 +5175,7 @@ void FieldDescriptorProto::Clear() { const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -5187,7 +5187,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.name"); auto str = msg->mutable_name(); @@ -5206,7 +5206,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string extendee = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.extendee"); auto str = msg->mutable_extendee(); @@ -5263,7 +5263,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string type_name = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.type_name"); auto str = msg->mutable_type_name(); @@ -5282,7 +5282,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string default_value = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.default_value"); auto str = msg->mutable_default_value(); @@ -5301,7 +5301,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional .google.protobuf.FieldOptions options = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FieldOptions::_InternalParse; object = msg->mutable_options(); @@ -5326,7 +5326,7 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* // optional string json_name = 10; case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.json_name"); auto str = msg->mutable_json_name(); @@ -6079,7 +6079,7 @@ void OneofDescriptorProto::Clear() { const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -6091,7 +6091,7 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.OneofDescriptorProto.name"); auto str = msg->mutable_name(); @@ -6110,7 +6110,7 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* // optional .google.protobuf.OneofOptions options = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::OneofOptions::_InternalParse; object = msg->mutable_options(); @@ -6477,7 +6477,7 @@ void EnumDescriptorProto_EnumReservedRange::Clear() { const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -6887,7 +6887,7 @@ void EnumDescriptorProto::Clear() { const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -6899,7 +6899,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumDescriptorProto.name"); auto str = msg->mutable_name(); @@ -6919,7 +6919,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumValueDescriptorProto::_InternalParse; object = msg->add_value(); @@ -6936,7 +6936,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e // optional .google.protobuf.EnumOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumOptions::_InternalParse; object = msg->mutable_options(); @@ -6952,7 +6952,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumDescriptorProto_EnumReservedRange::_InternalParse; object = msg->add_reserved_range(); @@ -6970,7 +6970,7 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumDescriptorProto.reserved_name"); auto str = msg->add_reserved_name(); @@ -7514,7 +7514,7 @@ void EnumValueDescriptorProto::Clear() { const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -7526,7 +7526,7 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumValueDescriptorProto.name"); auto str = msg->mutable_name(); @@ -7555,7 +7555,7 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch // optional .google.protobuf.EnumValueOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumValueOptions::_InternalParse; object = msg->mutable_options(); @@ -7995,7 +7995,7 @@ void ServiceDescriptorProto::Clear() { const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -8007,7 +8007,7 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.ServiceDescriptorProto.name"); auto str = msg->mutable_name(); @@ -8027,7 +8027,7 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::MethodDescriptorProto::_InternalParse; object = msg->add_method(); @@ -8044,7 +8044,7 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char // optional .google.protobuf.ServiceOptions options = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ServiceOptions::_InternalParse; object = msg->mutable_options(); @@ -8531,7 +8531,7 @@ void MethodDescriptorProto::Clear() { const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -8543,7 +8543,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.name"); auto str = msg->mutable_name(); @@ -8562,7 +8562,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* // optional string input_type = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.input_type"); auto str = msg->mutable_input_type(); @@ -8581,7 +8581,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* // optional string output_type = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.output_type"); auto str = msg->mutable_output_type(); @@ -8600,7 +8600,7 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* // optional .google.protobuf.MethodOptions options = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::MethodOptions::_InternalParse; object = msg->mutable_options(); @@ -9340,7 +9340,7 @@ void FileOptions::Clear() { const char* FileOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -9352,7 +9352,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string java_package = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.java_package"); auto str = msg->mutable_java_package(); @@ -9371,7 +9371,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string java_outer_classname = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.java_outer_classname"); auto str = msg->mutable_java_outer_classname(); @@ -9414,7 +9414,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string go_package = 11; case 11: { if (static_cast<::google::protobuf::uint8>(tag) != 90) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.go_package"); auto str = msg->mutable_go_package(); @@ -9503,7 +9503,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string objc_class_prefix = 36; case 36: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.objc_class_prefix"); auto str = msg->mutable_objc_class_prefix(); @@ -9522,7 +9522,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string csharp_namespace = 37; case 37: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.csharp_namespace"); auto str = msg->mutable_csharp_namespace(); @@ -9541,7 +9541,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string swift_prefix = 39; case 39: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.swift_prefix"); auto str = msg->mutable_swift_prefix(); @@ -9560,7 +9560,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string php_class_prefix = 40; case 40: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_class_prefix"); auto str = msg->mutable_php_class_prefix(); @@ -9579,7 +9579,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string php_namespace = 41; case 41: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_namespace"); auto str = msg->mutable_php_namespace(); @@ -9608,7 +9608,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string php_metadata_namespace = 44; case 44: { if (static_cast<::google::protobuf::uint8>(tag) != 98) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_metadata_namespace"); auto str = msg->mutable_php_metadata_namespace(); @@ -9627,7 +9627,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void // optional string ruby_package = 45; case 45: { if (static_cast<::google::protobuf::uint8>(tag) != 106) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.ruby_package"); auto str = msg->mutable_ruby_package(); @@ -9647,7 +9647,7 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -10834,7 +10834,7 @@ void MessageOptions::Clear() { const char* MessageOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -10887,7 +10887,7 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -11395,7 +11395,7 @@ void FieldOptions::Clear() { const char* FieldOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -11476,7 +11476,7 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -12030,7 +12030,7 @@ void OneofOptions::Clear() { const char* OneofOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -12043,7 +12043,7 @@ const char* OneofOptions::_InternalParse(const char* begin, const char* end, voi case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -12395,7 +12395,7 @@ void EnumOptions::Clear() { const char* EnumOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -12428,7 +12428,7 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -12843,7 +12843,7 @@ void EnumValueOptions::Clear() { const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -12866,7 +12866,7 @@ const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -13243,7 +13243,7 @@ void ServiceOptions::Clear() { const char* ServiceOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -13266,7 +13266,7 @@ const char* ServiceOptions::_InternalParse(const char* begin, const char* end, v case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -13656,7 +13656,7 @@ void MethodOptions::Clear() { const char* MethodOptions::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -13693,7 +13693,7 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo case 999: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); @@ -14125,7 +14125,7 @@ void UninterpretedOption_NamePart::Clear() { const char* UninterpretedOption_NamePart::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -14137,7 +14137,7 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* begin, cons // required string name_part = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.NamePart.name_part"); auto str = msg->mutable_name_part(); @@ -14583,7 +14583,7 @@ void UninterpretedOption::Clear() { const char* UninterpretedOption::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -14596,7 +14596,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::UninterpretedOption_NamePart::_InternalParse; object = msg->add_name(); @@ -14613,7 +14613,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e // optional string identifier_value = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.identifier_value"); auto str = msg->mutable_identifier_value(); @@ -14661,7 +14661,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e // optional bytes string_value = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); auto str = msg->mutable_string_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { @@ -14679,7 +14679,7 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e // optional string aggregate_value = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 66) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.aggregate_value"); auto str = msg->mutable_aggregate_value(); @@ -15264,7 +15264,7 @@ void SourceCodeInfo_Location::Clear() { const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -15276,7 +15276,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha // repeated int32 path = 1 [packed = true]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) == 10) { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_path(); @@ -15299,7 +15299,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha // repeated int32 span = 2 [packed = true]; case 2: { if (static_cast<::google::protobuf::uint8>(tag) == 18) { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_span(); @@ -15322,7 +15322,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha // optional string leading_comments = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.leading_comments"); auto str = msg->mutable_leading_comments(); @@ -15341,7 +15341,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha // optional string trailing_comments = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.trailing_comments"); auto str = msg->mutable_trailing_comments(); @@ -15361,7 +15361,7 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.leading_detached_comments"); auto str = msg->add_leading_detached_comments(); @@ -15890,7 +15890,7 @@ void SourceCodeInfo::Clear() { const char* SourceCodeInfo::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -15903,7 +15903,7 @@ const char* SourceCodeInfo::_InternalParse(const char* begin, const char* end, v case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceCodeInfo_Location::_InternalParse; object = msg->add_location(); @@ -16239,7 +16239,7 @@ void GeneratedCodeInfo_Annotation::Clear() { const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -16251,7 +16251,7 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons // repeated int32 path = 1 [packed = true]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) == 10) { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::PackedInt32Parser; object = msg->mutable_path(); @@ -16274,7 +16274,7 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons // optional string source_file = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.GeneratedCodeInfo.Annotation.source_file"); auto str = msg->mutable_source_file(); @@ -16739,7 +16739,7 @@ void GeneratedCodeInfo::Clear() { const char* GeneratedCodeInfo::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -16752,7 +16752,7 @@ const char* GeneratedCodeInfo::_InternalParse(const char* begin, const char* end case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::GeneratedCodeInfo_Annotation::_InternalParse; object = msg->add_annotation(); diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 5ec9398fd5..1860184627 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -301,7 +301,8 @@ inline bool MethodOptions_IdempotencyLevel_Parse( } // =================================================================== -class PROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorSet) */ { +class PROTOBUF_EXPORT FileDescriptorSet final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorSet) */ { public: FileDescriptorSet(); virtual ~FileDescriptorSet(); @@ -441,7 +442,8 @@ class PROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message /* }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorProto) */ { +class PROTOBUF_EXPORT FileDescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorProto) */ { public: FileDescriptorProto(); virtual ~FileDescriptorProto(); @@ -770,7 +772,8 @@ class PROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Message / }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ExtensionRange) */ { +class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ExtensionRange) */ { public: DescriptorProto_ExtensionRange(); virtual ~DescriptorProto_ExtensionRange(); @@ -926,7 +929,8 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::protobuf }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ReservedRange) */ { +class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ReservedRange) */ { public: DescriptorProto_ReservedRange(); virtual ~DescriptorProto_ReservedRange(); @@ -1069,7 +1073,8 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protobuf: }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto) */ { +class PROTOBUF_EXPORT DescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto) */ { public: DescriptorProto(); virtual ~DescriptorProto(); @@ -1351,7 +1356,8 @@ class PROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* @@ }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT ExtensionRangeOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ExtensionRangeOptions) */ { +class PROTOBUF_EXPORT ExtensionRangeOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ExtensionRangeOptions) */ { public: ExtensionRangeOptions(); virtual ~ExtensionRangeOptions(); @@ -1494,7 +1500,8 @@ class PROTOBUF_EXPORT ExtensionRangeOptions : public ::google::protobuf::Message }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldDescriptorProto) */ { +class PROTOBUF_EXPORT FieldDescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldDescriptorProto) */ { public: FieldDescriptorProto(); virtual ~FieldDescriptorProto(); @@ -1877,7 +1884,8 @@ class PROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Message }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofDescriptorProto) */ { +class PROTOBUF_EXPORT OneofDescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofDescriptorProto) */ { public: OneofDescriptorProto(); virtual ~OneofDescriptorProto(); @@ -2042,7 +2050,8 @@ class PROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Message }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto.EnumReservedRange) */ { +class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto.EnumReservedRange) */ { public: EnumDescriptorProto_EnumReservedRange(); virtual ~EnumDescriptorProto_EnumReservedRange(); @@ -2185,7 +2194,8 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange : public ::google::p }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto) */ { +class PROTOBUF_EXPORT EnumDescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto) */ { public: EnumDescriptorProto(); virtual ~EnumDescriptorProto(); @@ -2401,7 +2411,8 @@ class PROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Message / }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueDescriptorProto) */ { +class PROTOBUF_EXPORT EnumValueDescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueDescriptorProto) */ { public: EnumValueDescriptorProto(); virtual ~EnumValueDescriptorProto(); @@ -2574,7 +2585,8 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::Mess }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceDescriptorProto) */ { +class PROTOBUF_EXPORT ServiceDescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceDescriptorProto) */ { public: ServiceDescriptorProto(); virtual ~ServiceDescriptorProto(); @@ -2752,7 +2764,8 @@ class PROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Messag }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodDescriptorProto) */ { +class PROTOBUF_EXPORT MethodDescriptorProto final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodDescriptorProto) */ { public: MethodDescriptorProto(); virtual ~MethodDescriptorProto(); @@ -2983,7 +2996,8 @@ class PROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Message }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileOptions) */ { +class PROTOBUF_EXPORT FileOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileOptions) */ { public: FileOptions(); virtual ~FileOptions(); @@ -3484,7 +3498,8 @@ class PROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@prot }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MessageOptions) */ { +class PROTOBUF_EXPORT MessageOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MessageOptions) */ { public: MessageOptions(); virtual ~MessageOptions(); @@ -3659,7 +3674,8 @@ class PROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* @@p }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldOptions) */ { +class PROTOBUF_EXPORT FieldOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldOptions) */ { public: FieldOptions(); virtual ~FieldOptions(); @@ -3906,7 +3922,8 @@ class PROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@pro }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofOptions) */ { +class PROTOBUF_EXPORT OneofOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofOptions) */ { public: OneofOptions(); virtual ~OneofOptions(); @@ -4049,7 +4066,8 @@ class PROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@pro }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumOptions) */ { +class PROTOBUF_EXPORT EnumOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumOptions) */ { public: EnumOptions(); virtual ~EnumOptions(); @@ -4208,7 +4226,8 @@ class PROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@prot }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueOptions) */ { +class PROTOBUF_EXPORT EnumValueOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueOptions) */ { public: EnumValueOptions(); virtual ~EnumValueOptions(); @@ -4359,7 +4378,8 @@ class PROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message /* @ }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceOptions) */ { +class PROTOBUF_EXPORT ServiceOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceOptions) */ { public: ServiceOptions(); virtual ~ServiceOptions(); @@ -4510,7 +4530,8 @@ class PROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* @@p }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodOptions) */ { +class PROTOBUF_EXPORT MethodOptions final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodOptions) */ { public: MethodOptions(); virtual ~MethodOptions(); @@ -4697,7 +4718,8 @@ class PROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @@pr }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption.NamePart) */ { +class PROTOBUF_EXPORT UninterpretedOption_NamePart final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption.NamePart) */ { public: UninterpretedOption_NamePart(); virtual ~UninterpretedOption_NamePart(); @@ -4860,7 +4882,8 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobuf:: }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption) */ { +class PROTOBUF_EXPORT UninterpretedOption final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption) */ { public: UninterpretedOption(); virtual ~UninterpretedOption(); @@ -5101,7 +5124,8 @@ class PROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Message / }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo.Location) */ { +class PROTOBUF_EXPORT SourceCodeInfo_Location final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo.Location) */ { public: SourceCodeInfo_Location(); virtual ~SourceCodeInfo_Location(); @@ -5329,7 +5353,8 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Messa }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo) */ { +class PROTOBUF_EXPORT SourceCodeInfo final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo) */ { public: SourceCodeInfo(); virtual ~SourceCodeInfo(); @@ -5471,7 +5496,8 @@ class PROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* @@p }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo.Annotation) */ { +class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo.Annotation) */ { public: GeneratedCodeInfo_Annotation(); virtual ~GeneratedCodeInfo_Annotation(); @@ -5653,7 +5679,8 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobuf:: }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo) */ { +class PROTOBUF_EXPORT GeneratedCodeInfo final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo) */ { public: GeneratedCodeInfo(); virtual ~GeneratedCodeInfo(); diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 41fdbec664..d4a0cb1172 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -176,7 +176,7 @@ void Duration::Clear() { const char* Duration::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index a3b55d3afc..86c6b5b72c 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -61,7 +61,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Duration) */ { +class PROTOBUF_EXPORT Duration final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Duration) */ { public: Duration(); virtual ~Duration(); diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 7f401fe032..a8d1d0171e 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -162,7 +162,7 @@ void Empty::Clear() { const char* Empty::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 2e64a6f24b..f9014394fd 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -61,7 +61,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Empty) */ { +class PROTOBUF_EXPORT Empty final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Empty) */ { public: Empty(); virtual ~Empty(); diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index af398546d3..41278ef035 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -59,6 +60,8 @@ namespace protobuf { namespace internal { namespace { +using TestUtil::EqualsToSerialized; + // This test closely mirrors net/proto2/compiler/cpp/internal/unittest.cc // except that it uses extensions rather than regular fields. @@ -660,7 +663,10 @@ TEST(ExtensionSetTest, PackedToUnpackedParsing) { // Reserialize unittest::TestUnpackedTypes unpacked; TestUtil::SetUnpackedFields(&unpacked); - EXPECT_TRUE(unpacked.SerializeAsString() == destination.SerializeAsString()); + // Serialized proto has to be the same size and parsed to the same message. + EXPECT_EQ(unpacked.SerializeAsString().size(), + destination.SerializeAsString().size()); + EXPECT_TRUE(EqualsToSerialized(unpacked, destination.SerializeAsString())); // Make sure we can add extensions. destination.AddExtension(unittest::unpacked_int32_extension, 1); @@ -681,7 +687,10 @@ TEST(ExtensionSetTest, UnpackedToPackedParsing) { // Reserialize unittest::TestPackedTypes packed; TestUtil::SetPackedFields(&packed); - EXPECT_TRUE(packed.SerializeAsString() == destination.SerializeAsString()); + // Serialized proto has to be the same size and parsed to the same message. + EXPECT_EQ(packed.SerializeAsString().size(), + destination.SerializeAsString().size()); + EXPECT_TRUE(EqualsToSerialized(packed, destination.SerializeAsString())); // Make sure we can add extensions. destination.AddExtension(unittest::packed_int32_extension, 1); @@ -1193,6 +1202,7 @@ TEST(ExtensionSetTest, DynamicExtensions) { // Since the extensions were based off of the fields of TestDynamicExtensions, // we can use that message to create this test message. string data; + unittest::TestDynamicExtensions dynamic_extension; { unittest::TestDynamicExtensions message; message.set_scalar_extension(123); @@ -1218,6 +1228,7 @@ TEST(ExtensionSetTest, DynamicExtensions) { message.mutable_unknown_fields()->AddLengthDelimited(54321, "unknown"); message.SerializeToString(&data); + dynamic_extension = message; } // Now we can parse this using our dynamic extension definitions... @@ -1252,9 +1263,8 @@ TEST(ExtensionSetTest, DynamicExtensions) { message.DebugString()); // Can we serialize it? - // (Don't use EXPECT_EQ because we don't want to dump raw binary data to the - // terminal on failure.) - EXPECT_TRUE(message.SerializeAsString() == data); + EXPECT_TRUE( + EqualsToSerialized(dynamic_extension, message.SerializeAsString())); // What if we parse using the reflection-based parser? { diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index f266ca2da1..b865a50c66 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -170,7 +170,7 @@ void FieldMask::Clear() { const char* FieldMask::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -183,7 +183,7 @@ const char* FieldMask::_InternalParse(const char* begin, const char* end, void* case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldMask.paths"); auto str = msg->add_paths(); diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 8ad3f6b9f5..a74e3b4b46 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -61,7 +61,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldMask) */ { +class PROTOBUF_EXPORT FieldMask final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldMask) */ { public: FieldMask(); virtual ~FieldMask(); diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 9bafafbccb..8d80d19f17 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -178,8 +178,8 @@ const char* VarintParse(const char* p, T* out) { res += byte << (i * 7); int j = i + 1; if (PROTOBUF_PREDICT_TRUE(byte < 128)) { - *out = res - extra; - return p + j; + *out = res - extra; + return p + j; } extra += 128ull << (i * 7); } @@ -193,6 +193,27 @@ inline const char* Parse64(const char* p, uint64* out) { return VarintParse<10>(p, out); } +inline const char* ReadSize(const char* p, int32* out) { + int32 res = 0; + int32 extra = 0; + for (int i = 0; i < 4; i++) { + uint32 byte = static_cast(p[i]); + res += byte << (i * 7); + int j = i + 1; + if (PROTOBUF_PREDICT_TRUE(byte < 128)) { + *out = res - extra; + return p + j; + } + extra += 128ull << (i * 7); + } + uint32 byte = static_cast(p[4]); + // size may not be negative, so only the lowest 3 bits can be set. + if (byte >= 8) return nullptr; + res += byte << (4 * 7); + *out = res - extra; + return p + 5; +} + // Class which reads and decodes binary data which is composed of varint- // encoded integers and fixed-width pieces. Wraps a ZeroCopyInputStream. // Most users will not need to deal with CodedInputStream. diff --git a/src/google/protobuf/map_field.cc b/src/google/protobuf/map_field.cc index 9b27a32e7e..8c86a6b0c0 100644 --- a/src/google/protobuf/map_field.cc +++ b/src/google/protobuf/map_field.cc @@ -91,12 +91,6 @@ void MapFieldBase::SetRepeatedDirty() { state_.store(STATE_MODIFIED_REPEATED, std::memory_order_relaxed); } -void MapFieldBase::SetClean() { - // These are called by (non-const) mutator functions. So by our API it's the - // callers responsibility to have these calls properly ordered. - state_.store(CLEAN, std::memory_order_relaxed); -} - void* MapFieldBase::MutableRepeatedPtrField() const { return repeated_field_; } void MapFieldBase::SyncRepeatedFieldWithMap() const { @@ -192,7 +186,9 @@ void DynamicMapField::Clear() { if (MapFieldBase::repeated_field_ != nullptr) { MapFieldBase::repeated_field_->Clear(); } - MapFieldBase::SetClean(); + // Data in map and repeated field are both empty, but we can't set status + // CLEAN which will invalidate previous reference to map. + MapFieldBase::SetMapDirty(); } bool DynamicMapField::ContainsMapKey( diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index 0bb559804f..ef1804b3cf 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -137,9 +137,6 @@ class PROTOBUF_EXPORT MapFieldBase { // Tells MapFieldBase that there is new change to RepeatedPTrField. void SetRepeatedDirty(); - // Tells MapFieldBase that map and repeated are the same. - void SetClean(); - // Provides derived class the access to repeated field. void* MutableRepeatedPtrField() const; diff --git a/src/google/protobuf/map_field_inl.h b/src/google/protobuf/map_field_inl.h index 40ceb50499..1e2fa496eb 100644 --- a/src/google/protobuf/map_field_inl.h +++ b/src/google/protobuf/map_field_inl.h @@ -186,7 +186,10 @@ void MapFieldclear(); - MapFieldBase::SetClean(); + // Data in map and repeated field are both empty, but we can't set status + // CLEAN. Because clear is a generated API, we cannot invalidate previous + // reference to map. + MapFieldBase::SetMapDirty(); } template Clear(); - Expect(map_field_.get(), CLEAN, 0, 0, false); + Expect(map_field_.get(), MAP_DIRTY, 0, 0, false); } TEST_P(MapFieldStateTest, SpaceUsedExcludingSelf) { diff --git a/src/google/protobuf/map_test_util.cc b/src/google/protobuf/map_test_util.cc index 25f027f305..7061946129 100644 --- a/src/google/protobuf/map_test_util.cc +++ b/src/google/protobuf/map_test_util.cc @@ -1584,8 +1584,6 @@ void MapReflectionTester::ExpectClearViaReflection( EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_foreign_message"))); EXPECT_TRUE(reflection->GetMapData( message, F("map_int32_foreign_message"))->IsMapValid()); - EXPECT_TRUE(reflection->GetMapData( - message, F("map_int32_foreign_message"))->IsRepeatedFieldValid()); } void MapReflectionTester::ExpectClearViaReflectionIterator( diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index fb1da49e54..2f1261ccdd 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -353,6 +353,10 @@ bool MessageLite::ParsePartialFromArray(const void* data, int size) { return ParseFrom(as_string_view(data, size)); } +bool MessageLite::MergeFromString(const string& data) { + return ParseFrom(data); +} + // =================================================================== diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 4de3908114..20195bdc0d 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -347,8 +347,6 @@ class PROTOBUF_EXPORT ParseContext { const char* StoreAndTailCall(const char* ptr, const char* end, ParseClosure current_parser, ParseClosure child_parser, int32 size) { - // if size was bigger than 2GB we should fail - if (size < 0) return nullptr; // At this point ptr could be past end. Hence a malicious size could // overflow. int64 safe_new_limit = size - static_cast(end - ptr); @@ -650,8 +648,8 @@ std::pair FieldParser(uint64 tag, ParseClosure parent, break; } case WireType::WIRETYPE_LENGTH_DELIMITED: { - uint32 size; - ptr = io::Parse32(ptr, &size); + int32 size; + ptr = io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_ASSERT_RETURN(ptr != nullptr, {}); ParseClosure child = field_parser.AddLengthDelimited(number, size); if (size > end - ptr) { diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index ff0668be6b..e779fc961a 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -161,7 +161,7 @@ void SourceContext::Clear() { const char* SourceContext::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -173,7 +173,7 @@ const char* SourceContext::_InternalParse(const char* begin, const char* end, vo // string file_name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceContext.file_name"); auto str = msg->mutable_file_name(); diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index b3d7834ce2..4ed899729d 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -61,7 +61,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceContext) */ { +class PROTOBUF_EXPORT SourceContext final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceContext) */ { public: SourceContext(); virtual ~SourceContext(); diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 317d5dc156..9e1740c23a 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -300,7 +300,7 @@ void Struct::Clear() { const char* Struct::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -313,7 +313,7 @@ const char* Struct::_InternalParse(const char* begin, const char* end, void* obj case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::internal::SlowMapEntryParser; auto parse_map = ::google::protobuf::Struct_FieldsEntry_DoNotUse::_ParseMap; @@ -844,7 +844,7 @@ void Value::Clear() { const char* Value::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -875,7 +875,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje // string string_value = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Value.string_value"); auto str = msg->mutable_string_value(); @@ -904,7 +904,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje // .google.protobuf.Struct struct_value = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Struct::_InternalParse; object = msg->mutable_struct_value(); @@ -919,7 +919,7 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje // .google.protobuf.ListValue list_value = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::ListValue::_InternalParse; object = msg->mutable_list_value(); @@ -1406,7 +1406,7 @@ void ListValue::Clear() { const char* ListValue::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1419,7 +1419,7 @@ const char* ListValue::_InternalParse(const char* begin, const char* end, void* case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Value::_InternalParse; object = msg->add_values(); diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index e44bcbd5ed..7d8040d7a4 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -121,7 +121,8 @@ static bool _ParseMap(const char* begin, const char* end, void* object, ::google // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Struct) */ { +class PROTOBUF_EXPORT Struct final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Struct) */ { public: Struct(); virtual ~Struct(); @@ -256,7 +257,8 @@ class PROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc_in }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Value) */ { +class PROTOBUF_EXPORT Value final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Value) */ { public: Value(); virtual ~Value(); @@ -484,7 +486,8 @@ class PROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ins }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ListValue) */ { +class PROTOBUF_EXPORT ListValue final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ListValue) */ { public: ListValue(); virtual ~ListValue(); diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index e567ba7f0d..a9599cfe2e 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -620,16 +620,26 @@ struct PROTOBUF_EXPORT AlphaNum { // No bool ctor -- bools convert to an integral type. // A bool ctor would also convert incoming pointers (bletch). - AlphaNum(int32 i32) + AlphaNum(int i32) : piece_data_(digits), piece_size_(FastInt32ToBufferLeft(i32, digits) - &digits[0]) {} - AlphaNum(uint32 u32) + AlphaNum(unsigned int u32) : piece_data_(digits), piece_size_(FastUInt32ToBufferLeft(u32, digits) - &digits[0]) {} - AlphaNum(int64 i64) + AlphaNum(long long i64) : piece_data_(digits), piece_size_(FastInt64ToBufferLeft(i64, digits) - &digits[0]) {} - AlphaNum(uint64 u64) + AlphaNum(unsigned long long u64) + : piece_data_(digits), + piece_size_(FastUInt64ToBufferLeft(u64, digits) - &digits[0]) {} + + // Note: on some architectures, "long" is only 32 bits, not 64, but the + // performance hit of using FastInt64ToBufferLeft to handle 32-bit values + // is quite minor. + AlphaNum(long i64) + : piece_data_(digits), + piece_size_(FastInt64ToBufferLeft(i64, digits) - &digits[0]) {} + AlphaNum(unsigned long u64) : piece_data_(digits), piece_size_(FastUInt64ToBufferLeft(u64, digits) - &digits[0]) {} diff --git a/src/google/protobuf/stubs/strutil_unittest.cc b/src/google/protobuf/stubs/strutil_unittest.cc index 9460a66582..f830e37704 100644 --- a/src/google/protobuf/stubs/strutil_unittest.cc +++ b/src/google/protobuf/stubs/strutil_unittest.cc @@ -805,6 +805,37 @@ TEST(Base64, EscapeAndUnescape) { } } +// Test StrCat of ints and longs of various sizes and signdedness. +TEST(StrCat, Ints) { + const short s = -1; // NOLINT(runtime/int) + const uint16_t us = 2; + const int i = -3; + const unsigned int ui = 4; + const long l = -5; // NOLINT(runtime/int) + const unsigned long ul = 6; // NOLINT(runtime/int) + const long long ll = -7; // NOLINT(runtime/int) + const unsigned long long ull = 8; // NOLINT(runtime/int) + const ptrdiff_t ptrdiff = -9; + const size_t size = 10; + const intptr_t intptr = -12; + const uintptr_t uintptr = 13; + string answer; + answer = StrCat(s, us); + EXPECT_EQ(answer, "-12"); + answer = StrCat(i, ui); + EXPECT_EQ(answer, "-34"); + answer = StrCat(l, ul); + EXPECT_EQ(answer, "-56"); + answer = StrCat(ll, ull); + EXPECT_EQ(answer, "-78"); + answer = StrCat(ptrdiff, size); + EXPECT_EQ(answer, "-910"); + answer = StrCat(ptrdiff, intptr); + EXPECT_EQ(answer, "-9-12"); + answer = StrCat(uintptr, 0); + EXPECT_EQ(answer, "130"); +} + } // anonymous namespace } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/test_util2.h b/src/google/protobuf/test_util2.h index d729808d5b..299311dc6f 100644 --- a/src/google/protobuf/test_util2.h +++ b/src/google/protobuf/test_util2.h @@ -33,6 +33,7 @@ #include +#include #include @@ -66,6 +67,15 @@ inline ::std::string GetTestDataPath(const ::std::string& google3_path) { return TestSourceDir() + "/" + MaybeTranslatePath(google3_path); } +// Checks the equality of "message" and serialized proto of type "ProtoType". +// Do not directly compare two serialized protos. +template +bool EqualsToSerialized(const ProtoType& message, const std::string& data) { + ProtoType other; + other.ParsePartialFromString(data); + return util::MessageDifferencer::Equals(message, other); +} + } // namespace TestUtil } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index bf30404af1..acc7b9b8dd 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -176,7 +176,7 @@ void Timestamp::Clear() { const char* Timestamp::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index ccb2890a81..f49ca7a260 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -61,7 +61,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Timestamp) */ { +class PROTOBUF_EXPORT Timestamp final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Timestamp) */ { public: Timestamp(); virtual ~Timestamp(); diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 1696bfa965..c187394719 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -503,7 +503,7 @@ void Type::Clear() { const char* Type::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -515,7 +515,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Type.name"); auto str = msg->mutable_name(); @@ -535,7 +535,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Field::_InternalParse; object = msg->add_fields(); @@ -553,7 +553,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Type.oneofs"); auto str = msg->add_oneofs(); @@ -575,7 +575,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -592,7 +592,7 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec // .google.protobuf.SourceContext source_context = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 42) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); @@ -1155,7 +1155,7 @@ void Field::Clear() { const char* Field::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1197,7 +1197,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string name = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.name"); auto str = msg->mutable_name(); @@ -1216,7 +1216,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string type_url = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 50) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.type_url"); auto str = msg->mutable_type_url(); @@ -1256,7 +1256,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 74) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -1273,7 +1273,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string json_name = 10; case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 82) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.json_name"); auto str = msg->mutable_json_name(); @@ -1292,7 +1292,7 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // string default_value = 11; case 11: { if (static_cast<::google::protobuf::uint8>(tag) != 90) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.default_value"); auto str = msg->mutable_default_value(); @@ -2013,7 +2013,7 @@ void Enum::Clear() { const char* Enum::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -2025,7 +2025,7 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Enum.name"); auto str = msg->mutable_name(); @@ -2045,7 +2045,7 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::EnumValue::_InternalParse; object = msg->add_enumvalue(); @@ -2063,7 +2063,7 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -2080,7 +2080,7 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec // .google.protobuf.SourceContext source_context = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); @@ -2560,7 +2560,7 @@ void EnumValue::Clear() { const char* EnumValue::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -2572,7 +2572,7 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumValue.name"); auto str = msg->mutable_name(); @@ -2602,7 +2602,7 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; do { - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); @@ -3026,7 +3026,7 @@ void Option::Clear() { const char* Option::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -3038,7 +3038,7 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj // string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Option.name"); auto str = msg->mutable_name(); @@ -3057,7 +3057,7 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj // .google.protobuf.Any value = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::Any::_InternalParse; object = msg->mutable_value(); diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index fe39afb4a1..ce345ba9df 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -162,7 +162,8 @@ inline bool Syntax_Parse( } // =================================================================== -class PROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Type) */ { +class PROTOBUF_EXPORT Type final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Type) */ { public: Type(); virtual ~Type(); @@ -374,7 +375,8 @@ class PROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_inse }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Field) */ { +class PROTOBUF_EXPORT Field final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Field) */ { public: Field(); virtual ~Field(); @@ -727,7 +729,8 @@ class PROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ins }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Enum) */ { +class PROTOBUF_EXPORT Enum final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Enum) */ { public: Enum(); virtual ~Enum(); @@ -916,7 +919,8 @@ class PROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_inse }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValue) */ { +class PROTOBUF_EXPORT EnumValue final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValue) */ { public: EnumValue(); virtual ~EnumValue(); @@ -1079,7 +1083,8 @@ class PROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@protoc }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Option) */ { +class PROTOBUF_EXPORT Option final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Option) */ { public: Option(); virtual ~Option(); diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index 0d6e413891..202c9f3ddc 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -390,7 +390,7 @@ void DoubleValue::Clear() { const char* DoubleValue::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -679,7 +679,7 @@ void FloatValue::Clear() { const char* FloatValue::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -968,7 +968,7 @@ void Int64Value::Clear() { const char* Int64Value::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1260,7 +1260,7 @@ void UInt64Value::Clear() { const char* UInt64Value::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1552,7 +1552,7 @@ void Int32Value::Clear() { const char* Int32Value::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -1844,7 +1844,7 @@ void UInt32Value::Clear() { const char* UInt32Value::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -2136,7 +2136,7 @@ void BoolValue::Clear() { const char* BoolValue::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -2433,7 +2433,7 @@ void StringValue::Clear() { const char* StringValue::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -2445,7 +2445,7 @@ const char* StringValue::_InternalParse(const char* begin, const char* end, void // string value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.StringValue.value"); auto str = msg->mutable_value(); @@ -2758,7 +2758,7 @@ void BytesValue::Clear() { const char* BytesValue::_InternalParse(const char* begin, const char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) { auto msg = static_cast(object); - ::google::protobuf::uint32 size; (void)size; + ::google::protobuf::int32 size; (void)size; int depth; (void)depth; ::google::protobuf::uint32 tag; ::google::protobuf::internal::ParseFunc parser_till_end; (void)parser_till_end; @@ -2770,7 +2770,7 @@ const char* BytesValue::_InternalParse(const char* begin, const char* end, void* // bytes value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; - ptr = ::google::protobuf::io::Parse32(ptr, &size); + ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); auto str = msg->mutable_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 48559c25ea..11a76625e5 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -93,7 +93,8 @@ namespace protobuf { // =================================================================== -class PROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DoubleValue) */ { +class PROTOBUF_EXPORT DoubleValue final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DoubleValue) */ { public: DoubleValue(); virtual ~DoubleValue(); @@ -219,7 +220,8 @@ class PROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@prot }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FloatValue) */ { +class PROTOBUF_EXPORT FloatValue final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FloatValue) */ { public: FloatValue(); virtual ~FloatValue(); @@ -345,7 +347,8 @@ class PROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@proto }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int64Value) */ { +class PROTOBUF_EXPORT Int64Value final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int64Value) */ { public: Int64Value(); virtual ~Int64Value(); @@ -471,7 +474,8 @@ class PROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@proto }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt64Value) */ { +class PROTOBUF_EXPORT UInt64Value final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt64Value) */ { public: UInt64Value(); virtual ~UInt64Value(); @@ -597,7 +601,8 @@ class PROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@prot }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int32Value) */ { +class PROTOBUF_EXPORT Int32Value final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int32Value) */ { public: Int32Value(); virtual ~Int32Value(); @@ -723,7 +728,8 @@ class PROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@proto }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt32Value) */ { +class PROTOBUF_EXPORT UInt32Value final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt32Value) */ { public: UInt32Value(); virtual ~UInt32Value(); @@ -849,7 +855,8 @@ class PROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@prot }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BoolValue) */ { +class PROTOBUF_EXPORT BoolValue final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BoolValue) */ { public: BoolValue(); virtual ~BoolValue(); @@ -975,7 +982,8 @@ class PROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@protoc }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.StringValue) */ { +class PROTOBUF_EXPORT StringValue final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.StringValue) */ { public: StringValue(); virtual ~StringValue(); @@ -1118,7 +1126,8 @@ class PROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@prot }; // ------------------------------------------------------------------- -class PROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BytesValue) */ { +class PROTOBUF_EXPORT BytesValue final : + public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BytesValue) */ { public: BytesValue(); virtual ~BytesValue(); From b1b9eaa6c7630c8588a47d9f0cc2ec0823c173ba Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 10 Jan 2019 09:37:20 -0500 Subject: [PATCH 53/70] Comments on the next line will go to the next field. Even though the comments were indented to appear to go with the jspb case/field, protoc doesn't collect comments like that, so these "hanging" comments actually "attach" to the next thing added to each. Looking at https://github.com/protocolbuffers/protobuf/pull/5566 you see where the generated code picked up the comment on the wrong field. --- conformance/conformance.proto | 8 ++++---- csharp/src/Google.Protobuf.Conformance/Conformance.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/conformance/conformance.proto b/conformance/conformance.proto index 91e2ad37ba..0e86d11bf4 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto @@ -68,8 +68,8 @@ enum TestCategory { // https://developers.google.com/protocol-buffers/docs/proto3#json_options // for more detail. JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; - JSPB_TEST = 4; // Test jspb wire format. Google internal only. - // Opensource testees just skip it. + // Test jspb wire format. Google internal only. Opensource testees just skip it. + JSPB_TEST = 4; } message FailureSet { @@ -92,8 +92,8 @@ message ConformanceRequest { oneof payload { bytes protobuf_payload = 1; string json_payload = 2; - string jspb_payload = 7; // Google internal only. - // Opensource testees just skip it. + // Google internal only. Opensource testees just skip it. + string jspb_payload = 7; } // Which format should the testee serialize its message to? diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index de570f8279..220b33b1ee 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -86,7 +86,7 @@ namespace Conformance { /// [pbr::OriginalName("JSON_IGNORE_UNKNOWN_PARSING_TEST")] JsonIgnoreUnknownParsingTest = 3, /// - /// Test jspb wire format. Google internal only. + /// Test jspb wire format. Google internal only. Opensource testees just skip it. /// [pbr::OriginalName("JSPB_TEST")] JspbTest = 4, } @@ -298,7 +298,7 @@ namespace Conformance { /// Field number for the "jspb_payload" field. public const int JspbPayloadFieldNumber = 7; /// - /// Google internal only. + /// Google internal only. Opensource testees just skip it. /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public string JspbPayload { From cb95a7f6a8b66315969b74fa00b439f8f259fc8c Mon Sep 17 00:00:00 2001 From: Yilun Chong Date: Fri, 11 Jan 2019 11:40:52 -0800 Subject: [PATCH 54/70] Down-integrate internal changes to github. (#5566) * Down-integrate internal changes to github. * fix csharp conformance test * add comments in conformance.proto for text format * fix comments * fix comments, re-generated csharp file * fix comments, re-generated csharp file --- conformance/ConformanceJava.java | 32 +++-- conformance/conformance.proto | 12 ++ conformance/conformance_cpp.cc | 18 ++- conformance/conformance_python.py | 11 ++ conformance/conformance_test.cc | 11 ++ .../Conformance.cs | 119 +++++++++++++++--- js/test.proto | 23 ++-- .../protobuf/compiler/js/js_generator.cc | 51 +++++--- 8 files changed, 220 insertions(+), 57 deletions(-) diff --git a/conformance/ConformanceJava.java b/conformance/ConformanceJava.java index d1ce4059f6..008f3bc7ae 100644 --- a/conformance/ConformanceJava.java +++ b/conformance/ConformanceJava.java @@ -1,16 +1,17 @@ -import com.google.protobuf.ByteString; import com.google.protobuf.AbstractMessage; -import com.google.protobuf.Parser; +import com.google.protobuf.ByteString; import com.google.protobuf.CodedInputStream; -import com.google.protobuf.conformance.Conformance; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf_test_messages.proto3.TestMessagesProto3; -import com.google.protobuf_test_messages.proto3.TestMessagesProto3.TestAllTypesProto3; -import com.google.protobuf_test_messages.proto2.TestMessagesProto2; -import com.google.protobuf_test_messages.proto2.TestMessagesProto2.TestAllTypesProto2; import com.google.protobuf.ExtensionRegistry; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.Parser; +import com.google.protobuf.TextFormat; +import com.google.protobuf.conformance.Conformance; import com.google.protobuf.util.JsonFormat; import com.google.protobuf.util.JsonFormat.TypeRegistry; +import com.google.protobuf_test_messages.proto2.TestMessagesProto2; +import com.google.protobuf_test_messages.proto2.TestMessagesProto2.TestAllTypesProto2; +import com.google.protobuf_test_messages.proto3.TestMessagesProto3; +import com.google.protobuf_test_messages.proto3.TestMessagesProto3.TestAllTypesProto3; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -247,6 +248,17 @@ class ConformanceJava { } break; } + case TEXT_PAYLOAD: { + try { + TestMessagesProto3.TestAllTypesProto3.Builder builder = + TestMessagesProto3.TestAllTypesProto3.newBuilder(); + TextFormat.merge(request.getTextPayload(), builder); + testMessage = builder.build(); + } catch (TextFormat.ParseException e) { + return Conformance.ConformanceResponse.newBuilder().setParseError(e.getMessage()).build(); + } + break; + } case PAYLOAD_NOT_SET: { throw new RuntimeException("Request didn't have payload."); } @@ -274,6 +286,10 @@ class ConformanceJava { e.getMessage()).build(); } + case TEXT_FORMAT: + return Conformance.ConformanceResponse.newBuilder().setTextPayload( + TextFormat.printToString(testMessage)).build(); + default: { throw new RuntimeException("Unexpected request output."); } diff --git a/conformance/conformance.proto b/conformance/conformance.proto index 0e86d11bf4..b61f3569d4 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto @@ -56,6 +56,7 @@ enum WireFormat { PROTOBUF = 1; JSON = 2; JSPB = 3; // Google internal only. Opensource testees just skip it. + TEXT_FORMAT = 4; } enum TestCategory { @@ -70,8 +71,14 @@ enum TestCategory { JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; // Test jspb wire format. Google internal only. Opensource testees just skip it. JSPB_TEST = 4; + // Test text format. For cpp, java and python, testees can already deal with + // this type. Testees of other languages can simply skip it. + TEXT_FORMAT_TEST = 5; } +// The conformance runner will request a list of failures as the first request. +// This will be known by message_type == "conformance.FailureSet", a conformance +// test should return a serialized FailureSet in protobuf_payload. message FailureSet { repeated string failure = 1; } @@ -94,6 +101,7 @@ message ConformanceRequest { string json_payload = 2; // Google internal only. Opensource testees just skip it. string jspb_payload = 7; + string text_payload = 8; } // Which format should the testee serialize its message to? @@ -149,6 +157,10 @@ message ConformanceResponse { // serialize to JSPB and set it in this field. JSPB is google internal only // format. Opensource testees can just skip it. string jspb_payload = 7; + + // If the input was successfully parsed and the requested output was + // TEXT_FORMAT, serialize to TEXT_FORMAT and set it in this field. + string text_payload = 8; } } diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc index a451ab0ad5..ff70d5d9b9 100644 --- a/conformance/conformance_cpp.cc +++ b/conformance/conformance_cpp.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -45,14 +46,15 @@ using google::protobuf::Descriptor; using google::protobuf::DescriptorPool; using google::protobuf::Message; using google::protobuf::MessageFactory; +using google::protobuf::TextFormat; using google::protobuf::util::BinaryToJsonString; using google::protobuf::util::JsonParseOptions; using google::protobuf::util::JsonToBinaryString; using google::protobuf::util::NewTypeResolverForDescriptorPool; using google::protobuf::util::Status; using google::protobuf::util::TypeResolver; -using protobuf_test_messages::proto3::TestAllTypesProto3; using protobuf_test_messages::proto2::TestAllTypesProto2; +using protobuf_test_messages::proto3::TestAllTypesProto3; using std::string; static const char kTypeUrlPrefix[] = "type.googleapis.com"; @@ -163,6 +165,14 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { break; } + case ConformanceRequest::kTextPayload: { + if (!TextFormat::ParseFromString(request.text_payload(), test_message)) { + response->set_parse_error("Parse error"); + return; + } + break; + } + case ConformanceRequest::PAYLOAD_NOT_SET: GOOGLE_LOG(FATAL) << "Request didn't have payload."; break; @@ -203,6 +213,12 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { break; } + case conformance::TEXT_FORMAT: { + GOOGLE_CHECK(TextFormat::PrintToString(*test_message, + response->mutable_text_payload())); + break; + } + default: GOOGLE_LOG(FATAL) << "Unknown output format: " << request.requested_output_format(); diff --git a/conformance/conformance_python.py b/conformance/conformance_python.py index f1975e04b7..623f8f5cc8 100755 --- a/conformance/conformance_python.py +++ b/conformance/conformance_python.py @@ -44,6 +44,7 @@ from google.protobuf import json_format from google.protobuf import message from google.protobuf import test_messages_proto3_pb2 from google.protobuf import test_messages_proto2_pb2 +from google.protobuf import text_format import conformance_pb2 sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0) @@ -136,6 +137,13 @@ def do_test(request): response.parse_error = str(e) return response + elif request.WhichOneof('payload') == 'text_payload': + try: + text_format.Parse(request.text_payload, test_message) + except Exception as e: + response.parse_error = str(e) + return response + else: raise ProtocolError("Request didn't have payload.") @@ -152,6 +160,9 @@ def do_test(request): response.serialize_error = str(e) return response + elif request.requested_output_format == conformance_pb2.TEXT_FORMAT: + response.text_payload = text_format.MessageToString(test_message) + except Exception as e: response.runtime_error = str(e) diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index 265a05382d..b743e8e2a2 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -85,6 +85,11 @@ ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting( break; } + case conformance::TEXT_FORMAT: { + request_.set_text_payload(input); + break; + } + default: GOOGLE_LOG(FATAL) << "Unspecified input format"; } @@ -131,6 +136,8 @@ string ConformanceTestSuite::ConformanceRequestSetting:: return "ProtobufInput"; case conformance::JSON: return "JsonInput"; + case conformance::TEXT_FORMAT: + return "TextFormatInput"; default: GOOGLE_LOG(FATAL) << "Unspecified output format"; } @@ -144,6 +151,8 @@ string ConformanceTestSuite::ConformanceRequestSetting:: return "ProtobufOutput"; case conformance::JSON: return "JsonOutput"; + case conformance::TEXT_FORMAT: + return "TextFormatOutput"; default: GOOGLE_LOG(FATAL) << "Unspecified output format"; } @@ -341,6 +350,8 @@ string ConformanceTestSuite::WireFormatToString( return "JSON"; case conformance::JSPB: return "JSPB"; + case conformance::TEXT_FORMAT: + return "TEXT_FORMAT"; case conformance::UNSPECIFIED: return "UNSPECIFIED"; default: diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 220b33b1ee..3b2bb0311a 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -25,31 +25,33 @@ namespace Conformance { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2UiHQoKRmFpbHVyZVNl", - "dBIPCgdmYWlsdXJlGAEgAygJIq0CChJDb25mb3JtYW5jZVJlcXVlc3QSGgoQ", + "dBIPCgdmYWlsdXJlGAEgAygJIsUCChJDb25mb3JtYW5jZVJlcXVlc3QSGgoQ", "cHJvdG9idWZfcGF5bG9hZBgBIAEoDEgAEhYKDGpzb25fcGF5bG9hZBgCIAEo", - "CUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgAEjgKF3JlcXVlc3RlZF9vdXRw", - "dXRfZm9ybWF0GAMgASgOMhcuY29uZm9ybWFuY2UuV2lyZUZvcm1hdBIUCgxt", - "ZXNzYWdlX3R5cGUYBCABKAkSMAoNdGVzdF9jYXRlZ29yeRgFIAEoDjIZLmNv", - "bmZvcm1hbmNlLlRlc3RDYXRlZ29yeRI+ChVqc3BiX2VuY29kaW5nX29wdGlv", - "bnMYBiABKAsyHy5jb25mb3JtYW5jZS5Kc3BiRW5jb2RpbmdDb25maWdCCQoH", - "cGF5bG9hZCLJAQoTQ29uZm9ybWFuY2VSZXNwb25zZRIVCgtwYXJzZV9lcnJv", - "chgBIAEoCUgAEhkKD3NlcmlhbGl6ZV9lcnJvchgGIAEoCUgAEhcKDXJ1bnRp", - "bWVfZXJyb3IYAiABKAlIABIaChBwcm90b2J1Zl9wYXlsb2FkGAMgASgMSAAS", - "FgoManNvbl9wYXlsb2FkGAQgASgJSAASEQoHc2tpcHBlZBgFIAEoCUgAEhYK", - "DGpzcGJfcGF5bG9hZBgHIAEoCUgAQggKBnJlc3VsdCI3ChJKc3BiRW5jb2Rp", - "bmdDb25maWcSIQoZdXNlX2pzcGJfYXJyYXlfYW55X2Zvcm1hdBgBIAEoCCo/", - "CgpXaXJlRm9ybWF0Eg8KC1VOU1BFQ0lGSUVEEAASDAoIUFJPVE9CVUYQARII", - "CgRKU09OEAISCAoESlNQQhADKnkKDFRlc3RDYXRlZ29yeRIUChBVTlNQRUNJ", - "RklFRF9URVNUEAASDwoLQklOQVJZX1RFU1QQARINCglKU09OX1RFU1QQAhIk", - "CiBKU09OX0lHTk9SRV9VTktOT1dOX1BBUlNJTkdfVEVTVBADEg0KCUpTUEJf", - "VEVTVBAEQiEKH2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFuY2ViBnBy", - "b3RvMw==")); + "CUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgAEhYKDHRleHRfcGF5bG9hZBgI", + "IAEoCUgAEjgKF3JlcXVlc3RlZF9vdXRwdXRfZm9ybWF0GAMgASgOMhcuY29u", + "Zm9ybWFuY2UuV2lyZUZvcm1hdBIUCgxtZXNzYWdlX3R5cGUYBCABKAkSMAoN", + "dGVzdF9jYXRlZ29yeRgFIAEoDjIZLmNvbmZvcm1hbmNlLlRlc3RDYXRlZ29y", + "eRI+ChVqc3BiX2VuY29kaW5nX29wdGlvbnMYBiABKAsyHy5jb25mb3JtYW5j", + "ZS5Kc3BiRW5jb2RpbmdDb25maWdCCQoHcGF5bG9hZCLhAQoTQ29uZm9ybWFu", + "Y2VSZXNwb25zZRIVCgtwYXJzZV9lcnJvchgBIAEoCUgAEhkKD3NlcmlhbGl6", + "ZV9lcnJvchgGIAEoCUgAEhcKDXJ1bnRpbWVfZXJyb3IYAiABKAlIABIaChBw", + "cm90b2J1Zl9wYXlsb2FkGAMgASgMSAASFgoManNvbl9wYXlsb2FkGAQgASgJ", + "SAASEQoHc2tpcHBlZBgFIAEoCUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgA", + "EhYKDHRleHRfcGF5bG9hZBgIIAEoCUgAQggKBnJlc3VsdCI3ChJKc3BiRW5j", + "b2RpbmdDb25maWcSIQoZdXNlX2pzcGJfYXJyYXlfYW55X2Zvcm1hdBgBIAEo", + "CCpQCgpXaXJlRm9ybWF0Eg8KC1VOU1BFQ0lGSUVEEAASDAoIUFJPVE9CVUYQ", + "ARIICgRKU09OEAISCAoESlNQQhADEg8KC1RFWFRfRk9STUFUEAQqjwEKDFRl", + "c3RDYXRlZ29yeRIUChBVTlNQRUNJRklFRF9URVNUEAASDwoLQklOQVJZX1RF", + "U1QQARINCglKU09OX1RFU1QQAhIkCiBKU09OX0lHTk9SRV9VTktOT1dOX1BB", + "UlNJTkdfVEVTVBADEg0KCUpTUEJfVEVTVBAEEhQKEFRFWFRfRk9STUFUX1RF", + "U1QQBUIhCh9jb20uZ29vZ2xlLnByb3RvYnVmLmNvbmZvcm1hbmNlYgZwcm90", + "bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.FailureSet), global::Conformance.FailureSet.Parser, new[]{ "Failure" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions" }, new[]{ "Payload" }, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload" }, new[]{ "Result" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions" }, new[]{ "Payload" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload", "TextPayload" }, new[]{ "Result" }, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null) })); } @@ -65,6 +67,7 @@ namespace Conformance { /// Google internal only. Opensource testees just skip it. /// [pbr::OriginalName("JSPB")] Jspb = 3, + [pbr::OriginalName("TEXT_FORMAT")] TextFormat = 4, } public enum TestCategory { @@ -89,11 +92,21 @@ namespace Conformance { /// Test jspb wire format. Google internal only. Opensource testees just skip it. /// [pbr::OriginalName("JSPB_TEST")] JspbTest = 4, + /// + /// Test text format. For cpp, java and python, testees can already deal with + /// this type. Testees of other languages can simply skip it. + /// + [pbr::OriginalName("TEXT_FORMAT_TEST")] TextFormatTest = 5, } #endregion #region Messages + /// + /// The conformance runner will request a list of failures as the first request. + /// This will be known by message_type == "conformance.FailureSet", a conformance + /// test should return a serialized FailureSet in protobuf_payload. + /// public sealed partial class FailureSet : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FailureSet()); private pb::UnknownFieldSet _unknownFields; @@ -263,6 +276,9 @@ namespace Conformance { case PayloadOneofCase.JspbPayload: JspbPayload = other.JspbPayload; break; + case PayloadOneofCase.TextPayload: + TextPayload = other.TextPayload; + break; } _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -309,6 +325,17 @@ namespace Conformance { } } + /// Field number for the "text_payload" field. + public const int TextPayloadFieldNumber = 8; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TextPayload { + get { return payloadCase_ == PayloadOneofCase.TextPayload ? (string) payload_ : ""; } + set { + payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + payloadCase_ = PayloadOneofCase.TextPayload; + } + } + /// Field number for the "requested_output_format" field. public const int RequestedOutputFormatFieldNumber = 3; private global::Conformance.WireFormat requestedOutputFormat_ = 0; @@ -376,6 +403,7 @@ namespace Conformance { ProtobufPayload = 1, JsonPayload = 2, JspbPayload = 7, + TextPayload = 8, } private PayloadOneofCase payloadCase_ = PayloadOneofCase.None; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -405,6 +433,7 @@ namespace Conformance { if (ProtobufPayload != other.ProtobufPayload) return false; if (JsonPayload != other.JsonPayload) return false; if (JspbPayload != other.JspbPayload) return false; + if (TextPayload != other.TextPayload) return false; if (RequestedOutputFormat != other.RequestedOutputFormat) return false; if (MessageType != other.MessageType) return false; if (TestCategory != other.TestCategory) return false; @@ -419,6 +448,7 @@ namespace Conformance { if (payloadCase_ == PayloadOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); if (payloadCase_ == PayloadOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); + if (payloadCase_ == PayloadOneofCase.TextPayload) hash ^= TextPayload.GetHashCode(); if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode(); if (MessageType.Length != 0) hash ^= MessageType.GetHashCode(); if (TestCategory != 0) hash ^= TestCategory.GetHashCode(); @@ -465,6 +495,10 @@ namespace Conformance { output.WriteRawTag(58); output.WriteString(JspbPayload); } + if (payloadCase_ == PayloadOneofCase.TextPayload) { + output.WriteRawTag(66); + output.WriteString(TextPayload); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -482,6 +516,9 @@ namespace Conformance { if (payloadCase_ == PayloadOneofCase.JspbPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); } + if (payloadCase_ == PayloadOneofCase.TextPayload) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); + } if (RequestedOutputFormat != 0) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) RequestedOutputFormat); } @@ -530,6 +567,9 @@ namespace Conformance { case PayloadOneofCase.JspbPayload: JspbPayload = other.JspbPayload; break; + case PayloadOneofCase.TextPayload: + TextPayload = other.TextPayload; + break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); @@ -576,6 +616,10 @@ namespace Conformance { JspbPayload = input.ReadString(); break; } + case 66: { + TextPayload = input.ReadString(); + break; + } } } } @@ -632,6 +676,9 @@ namespace Conformance { case ResultOneofCase.JspbPayload: JspbPayload = other.JspbPayload; break; + case ResultOneofCase.TextPayload: + TextPayload = other.TextPayload; + break; } _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -753,6 +800,21 @@ namespace Conformance { } } + /// Field number for the "text_payload" field. + public const int TextPayloadFieldNumber = 8; + /// + /// If the input was successfully parsed and the requested output was + /// TEXT_FORMAT, serialize to TEXT_FORMAT and set it in this field. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TextPayload { + get { return resultCase_ == ResultOneofCase.TextPayload ? (string) result_ : ""; } + set { + result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + resultCase_ = ResultOneofCase.TextPayload; + } + } + private object result_; /// Enum of possible cases for the "result" oneof. public enum ResultOneofCase { @@ -764,6 +826,7 @@ namespace Conformance { JsonPayload = 4, Skipped = 5, JspbPayload = 7, + TextPayload = 8, } private ResultOneofCase resultCase_ = ResultOneofCase.None; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -797,6 +860,7 @@ namespace Conformance { if (JsonPayload != other.JsonPayload) return false; if (Skipped != other.Skipped) return false; if (JspbPayload != other.JspbPayload) return false; + if (TextPayload != other.TextPayload) return false; if (ResultCase != other.ResultCase) return false; return Equals(_unknownFields, other._unknownFields); } @@ -811,6 +875,7 @@ namespace Conformance { if (resultCase_ == ResultOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); if (resultCase_ == ResultOneofCase.Skipped) hash ^= Skipped.GetHashCode(); if (resultCase_ == ResultOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); + if (resultCase_ == ResultOneofCase.TextPayload) hash ^= TextPayload.GetHashCode(); hash ^= (int) resultCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -853,6 +918,10 @@ namespace Conformance { output.WriteRawTag(58); output.WriteString(JspbPayload); } + if (resultCase_ == ResultOneofCase.TextPayload) { + output.WriteRawTag(66); + output.WriteString(TextPayload); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -882,6 +951,9 @@ namespace Conformance { if (resultCase_ == ResultOneofCase.JspbPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); } + if (resultCase_ == ResultOneofCase.TextPayload) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -915,6 +987,9 @@ namespace Conformance { case ResultOneofCase.JspbPayload: JspbPayload = other.JspbPayload; break; + case ResultOneofCase.TextPayload: + TextPayload = other.TextPayload; + break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); @@ -958,6 +1033,10 @@ namespace Conformance { JspbPayload = input.ReadString(); break; } + case 66: { + TextPayload = input.ReadString(); + break; + } } } } diff --git a/js/test.proto b/js/test.proto index 454fd8396f..bc1a9b64cc 100644 --- a/js/test.proto +++ b/js/test.proto @@ -39,8 +39,7 @@ import "google/protobuf/descriptor.proto"; package jspb.test; -message Empty { -} +message Empty {} enum OuterEnum { FOO = 1; @@ -137,12 +136,13 @@ message DefaultValues { E1 = 13; E2 = 77; } - optional string string_field = 1 [default="default<>\'\"abc"]; - optional bool bool_field = 2 [default=true]; - optional int64 int_field = 3 [default=11]; - optional Enum enum_field = 4 [default=E1]; - optional string empty_field = 6 [default=""]; - optional bytes bytes_field = 8 [default="moo"]; // Base64 encoding is "bW9v" + optional string string_field = 1 [default = "default<>\'\"abc"]; + optional bool bool_field = 2 [default = true]; + optional int64 int_field = 3 [default = 11]; + optional Enum enum_field = 4 [default = E1]; + optional string empty_field = 6 [default = ""]; + optional bytes bytes_field = 8 + [default = "moo"]; // Base64 encoding is "bW9v" } message FloatingPointFields { @@ -254,9 +254,9 @@ extend TestLastFieldBeforePivot { message Int64Types { - optional int64 int64_normal = 1 [jstype=JS_NORMAL]; - optional sint64 int64_string = 2 [jstype=JS_STRING]; - optional uint64 int64_number = 3 [jstype=JS_NUMBER]; + optional int64 int64_normal = 1 [jstype = JS_NORMAL]; + optional sint64 int64_string = 2 [jstype = JS_STRING]; + optional uint64 int64_number = 3 [jstype = JS_NUMBER]; } @@ -297,3 +297,4 @@ message Deeply { } } + diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index c85cb7993b..26645080d1 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2847,52 +2847,69 @@ void Generator::GenerateClassField(const GeneratorOptions& options, // Generate clearFoo() method for map fields, repeated fields, and other // fields with presence. if (field->is_map()) { + // clang-format off printer->Print( - "/** Clears values from the map. The map will be non-null. */\n" + "/**\n" + " * Clears values from the map. The map will be non-null." + "$returndoc$\n" + " */\n" "$class$.prototype.$clearername$ = function() {\n" " this.$gettername$().clear();$returnvalue$\n" "};\n" "\n" "\n", + "returndoc", JSReturnDoc(options, field), "class", GetMessagePath(options, field->containing_type()), - "clearername", "clear" + JSGetterName(options, field), "gettername", - "get" + JSGetterName(options, field), "returnvalue", - JSReturnClause(field)); + "clearername", "clear" + JSGetterName(options, field), + "gettername", "get" + JSGetterName(options, field), + "returnvalue", JSReturnClause(field)); + // clang-format on printer->Annotate("clearername", field); } else if (field->is_repeated() || (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !field->is_required())) { // Fields where we can delegate to the regular setter. + // clang-format off printer->Print( - "/** $jsdoc$ */\n" + "/**\n" + " * $jsdoc$$returndoc$\n" + " */\n" "$class$.prototype.$clearername$ = function() {\n" " this.$settername$($clearedvalue$);$returnvalue$\n" "};\n" "\n" "\n", - "jsdoc", - field->is_repeated() ? "Clears the list making it empty but non-null." - : "Clears the message field making it undefined.", + "jsdoc", field->is_repeated() + ? "Clears the list making it empty but non-null." + : "Clears the message field making it undefined.", + "returndoc", JSReturnDoc(options, field), "class", GetMessagePath(options, field->containing_type()), - "clearername", "clear" + JSGetterName(options, field), "settername", - "set" + JSGetterName(options, field), "clearedvalue", - (field->is_repeated() ? "[]" : "undefined"), "returnvalue", - JSReturnClause(field)); + "clearername", "clear" + JSGetterName(options, field), + "settername", "set" + JSGetterName(options, field), + "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), + "returnvalue", JSReturnClause(field)); + // clang-format on printer->Annotate("clearername", field); } else if (HasFieldPresence(options, field)) { // Fields where we can't delegate to the regular setter because it doesn't // accept "undefined" as an argument. + // clang-format off printer->Print( - "/** Clears the field making it undefined. */\n" + "/**\n" + " * Clears the field making it undefined.$returndoc$\n" + " */\n" "$class$.prototype.$clearername$ = function() {\n" " jspb.Message.set$maybeoneof$Field(this, " "$index$$maybeoneofgroup$, ", + "returndoc", JSReturnDoc(options, field), "class", GetMessagePath(options, field->containing_type()), - "clearername", "clear" + JSGetterName(options, field), "maybeoneof", - (field->containing_oneof() ? "Oneof" : ""), "maybeoneofgroup", - (field->containing_oneof() ? (", " + JSOneofArray(options, field)) - : ""), + "clearername", "clear" + JSGetterName(options, field), + "maybeoneof", (field->containing_oneof() ? "Oneof" : ""), + "maybeoneofgroup", (field->containing_oneof() + ? (", " + JSOneofArray(options, field)) + : ""), "index", JSFieldIndex(field)); + // clang-format on printer->Annotate("clearername", field); printer->Print( "$clearedvalue$);$returnvalue$\n" From 54683e607b96bc66ae95e7a4e37e0e97532b383d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Elliott?= Date: Sat, 12 Jan 2019 15:25:07 -0300 Subject: [PATCH 55/70] Fix Issue #5345 (#5381) Added a few \ on the comments to match the exceptions scope when is referenced while in a namespace. So the IDEs can be happy. --- php/src/Google/Protobuf/Any.php | 6 +++--- .../Protobuf/Internal/CodedInputStream.php | 2 +- php/src/Google/Protobuf/Internal/MapField.php | 14 +++++++------- php/src/Google/Protobuf/Internal/Message.php | 4 ++-- .../Google/Protobuf/Internal/RepeatedField.php | 16 ++++++++-------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/php/src/Google/Protobuf/Any.php b/php/src/Google/Protobuf/Any.php index a992854957..cdbaa255a1 100644 --- a/php/src/Google/Protobuf/Any.php +++ b/php/src/Google/Protobuf/Any.php @@ -252,9 +252,9 @@ class Any extends \Google\Protobuf\Internal\Message * the method will create a message of the targeted type and fill it with * the decoded value in Any. * @return unpacked message - * @throws Exception Type url needs to be type.googleapis.com/fully-qulified. - * @throws Exception Class hasn't been added to descriptor pool. - * @throws Exception cannot decode data in value field. + * @throws \Exception Type url needs to be type.googleapis.com/fully-qulified. + * @throws \Exception Class hasn't been added to descriptor pool. + * @throws \Exception cannot decode data in value field. */ public function unpack() { diff --git a/php/src/Google/Protobuf/Internal/CodedInputStream.php b/php/src/Google/Protobuf/Internal/CodedInputStream.php index b612da5b7b..33f4a456af 100644 --- a/php/src/Google/Protobuf/Internal/CodedInputStream.php +++ b/php/src/Google/Protobuf/Internal/CodedInputStream.php @@ -317,7 +317,7 @@ class CodedInputStream * passed unchanged to the corresponding call to popLimit(). * * @param integer $byte_limit - * @throws Exception Fail to push limit. + * @throws \Exception Fail to push limit. */ public function pushLimit($byte_limit) { diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index 1b2b0cf0ac..2c66aa0c19 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -131,8 +131,8 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * * @param object $key The key of the element to be fetched. * @return object The stored element at given key. - * @throws ErrorException Invalid type for index. - * @throws ErrorException Non-existing index. + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. */ public function offsetGet($key) { @@ -147,9 +147,9 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @param object $key The key of the element to be fetched. * @param object $value The element to be assigned. * @return void - * @throws ErrorException Invalid type for key. - * @throws ErrorException Invalid type for value. - * @throws ErrorException Non-existing key. + * @throws \ErrorException Invalid type for key. + * @throws \ErrorException Invalid type for value. + * @throws \ErrorException Non-existing key. */ public function offsetSet($key, $value) { @@ -207,7 +207,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * * @param object $key The key of the element to be removed. * @return void - * @throws ErrorException Invalid type for key. + * @throws \ErrorException Invalid type for key. */ public function offsetUnset($key) { @@ -222,7 +222,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * * @param object $key The key of the element to be removed. * @return bool True if the element at the given key exists. - * @throws ErrorException Invalid type for key. + * @throws \ErrorException Invalid type for key. */ public function offsetExists($key) { diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 92d6df7e49..d304a12b47 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -716,7 +716,7 @@ class Message * * @param string $data Binary protobuf data. * @return null. - * @throws Exception Invalid data. + * @throws \Exception Invalid data. */ public function mergeFromString($data) { @@ -734,7 +734,7 @@ class Message * * @param string $data Json protobuf data. * @return null. - * @throws Exception Invalid data. + * @throws \Exception Invalid data. */ public function mergeFromJsonString($data) { diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index e9b92d8d29..ec7a3a6d07 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -118,8 +118,8 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * @param long $offset The index of the element to be fetched. * @return object The stored element at given index. - * @throws ErrorException Invalid type for index. - * @throws ErrorException Non-existing index. + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. */ public function offsetGet($offset) { @@ -134,9 +134,9 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @param long $offset The index of the element to be assigned. * @param object $value The element to be assigned. * @return void - * @throws ErrorException Invalid type for index. - * @throws ErrorException Non-existing index. - * @throws ErrorException Incorrect type of the element. + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. + * @throws \ErrorException Incorrect type of the element. */ public function offsetSet($offset, $value) { @@ -206,8 +206,8 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * @param long $offset The index of the element to be removed. * @return void - * @throws ErrorException Invalid type for index. - * @throws ErrorException The element to be removed is not at the end of the + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException The element to be removed is not at the end of the * RepeatedField. */ public function offsetUnset($offset) @@ -229,7 +229,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * @param long $offset The index of the element to be removed. * @return bool True if the element at the given offset exists. - * @throws ErrorException Invalid type for index. + * @throws \ErrorException Invalid type for index. */ public function offsetExists($offset) { From a2a0afb5468dc423782344a2047abc041e75323e Mon Sep 17 00:00:00 2001 From: Yilun Chong Date: Sun, 13 Jan 2019 17:40:58 -0800 Subject: [PATCH 56/70] Down-integrate internal changes to github. (#5575) * Down-integrate internal changes to github. * Fix BUILD file and regenerate csharp descritpor --- BUILD | 1 - conformance/conformance.proto | 3 +- .../Conformance.cs | 2 +- src/google/protobuf/any.pb.cc | 22 +- src/google/protobuf/api.pb.cc | 137 +-- src/google/protobuf/arenastring.cc | 43 - .../protobuf/compiler/cpp/cpp_extension.cc | 5 +- src/google/protobuf/compiler/cpp/cpp_field.cc | 6 +- src/google/protobuf/compiler/cpp/cpp_file.cc | 8 +- .../protobuf/compiler/cpp/cpp_generator.cc | 4 +- .../protobuf/compiler/cpp/cpp_helpers.cc | 160 ++- .../protobuf/compiler/cpp/cpp_helpers.h | 3 +- .../protobuf/compiler/cpp/cpp_map_field.cc | 5 +- .../protobuf/compiler/cpp/cpp_message.cc | 43 +- .../compiler/cpp/cpp_primitive_field.cc | 6 +- .../protobuf/compiler/cpp/cpp_string_field.cc | 3 +- .../protobuf/compiler/java/java_context.cc | 5 +- .../protobuf/compiler/java/java_enum.cc | 13 +- .../protobuf/compiler/java/java_enum_field.cc | 19 +- .../compiler/java/java_enum_field_lite.cc | 7 +- .../protobuf/compiler/java/java_enum_lite.cc | 7 +- .../protobuf/compiler/java/java_extension.cc | 7 +- .../protobuf/compiler/java/java_field.cc | 9 +- .../protobuf/compiler/java/java_file.cc | 12 +- .../protobuf/compiler/java/java_helpers.cc | 15 +- .../protobuf/compiler/java/java_map_field.cc | 4 +- .../protobuf/compiler/java/java_message.cc | 45 +- .../compiler/java/java_message_builder.cc | 10 +- .../java/java_message_builder_lite.cc | 4 +- .../compiler/java/java_message_field.cc | 8 +- .../compiler/java/java_message_field_lite.cc | 3 +- .../compiler/java/java_message_lite.cc | 18 +- .../compiler/java/java_primitive_field.cc | 33 +- .../java/java_primitive_field_lite.cc | 7 +- .../protobuf/compiler/java/java_service.cc | 13 +- .../compiler/java/java_string_field.cc | 13 +- .../compiler/java/java_string_field_lite.cc | 5 +- .../protobuf/compiler/js/js_generator.cc | 59 +- src/google/protobuf/compiler/parser.cc | 5 +- src/google/protobuf/compiler/plugin.pb.cc | 118 +-- .../compiler/python/python_generator.cc | 44 +- src/google/protobuf/descriptor.cc | 9 +- src/google/protobuf/descriptor.h | 6 +- src/google/protobuf/descriptor.pb.cc | 950 +++++++----------- src/google/protobuf/duration.pb.cc | 10 +- src/google/protobuf/field_mask.pb.cc | 13 +- src/google/protobuf/generated_message_util.h | 8 +- src/google/protobuf/io/coded_stream.h | 1 + src/google/protobuf/map.h | 2 + src/google/protobuf/map_test.cc | 9 + src/google/protobuf/parse_context.h | 4 +- src/google/protobuf/reflection_ops.cc | 3 +- .../protobuf/repeated_field_unittest.cc | 9 +- src/google/protobuf/source_context.pb.cc | 13 +- src/google/protobuf/struct.pb.cc | 54 +- src/google/protobuf/text_format.cc | 16 +- src/google/protobuf/text_format_unittest.cc | 9 +- src/google/protobuf/timestamp.pb.cc | 10 +- src/google/protobuf/type.pb.cc | 217 ++-- .../protobuf/util/internal/datapiece.cc | 9 +- .../util/internal/json_objectwriter.cc | 9 +- .../util/internal/protostream_objectsource.cc | 21 +- .../util/internal/protostream_objectwriter.cc | 5 +- src/google/protobuf/util/internal/utility.h | 5 +- .../protobuf/util/message_differencer.cc | 10 +- src/google/protobuf/util/time_util.cc | 3 +- .../protobuf/util/type_resolver_util.cc | 8 +- src/google/protobuf/wire_format_lite.h | 23 + src/google/protobuf/wrappers.pb.cc | 63 +- 69 files changed, 1012 insertions(+), 1421 deletions(-) delete mode 100644 src/google/protobuf/arenastring.cc diff --git a/BUILD b/BUILD index 1664621e95..e9e108377a 100644 --- a/BUILD +++ b/BUILD @@ -93,7 +93,6 @@ cc_library( srcs = [ # AUTOGEN(protobuf_lite_srcs) "src/google/protobuf/arena.cc", - "src/google/protobuf/arenastring.cc", "src/google/protobuf/extension_set.cc", "src/google/protobuf/generated_message_table_driven_lite.cc", "src/google/protobuf/generated_message_util.cc", diff --git a/conformance/conformance.proto b/conformance/conformance.proto index b61f3569d4..271476dc5e 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto @@ -71,7 +71,7 @@ enum TestCategory { JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; // Test jspb wire format. Google internal only. Opensource testees just skip it. JSPB_TEST = 4; - // Test text format. For cpp, java and python, testees can already deal with + // Test text format. For cpp, java and python, testees can already deal with // this type. Testees of other languages can simply skip it. TEXT_FORMAT_TEST = 5; } @@ -169,3 +169,4 @@ message JspbEncodingConfig { // Encode the value field of Any as jspb array if ture, otherwise binary. bool use_jspb_array_any_format = 1; } + diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 3b2bb0311a..73a140d3d1 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -93,7 +93,7 @@ namespace Conformance { /// [pbr::OriginalName("JSPB_TEST")] JspbTest = 4, /// - /// Test text format. For cpp, java and python, testees can already deal with + /// Test text format. For cpp, java and python, testees can already deal with /// this type. Testees of other languages can simply skip it. /// [pbr::OriginalName("TEXT_FORMAT_TEST")] TextFormatTest = 5, diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 4e994a8075..0b68e1d445 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -210,16 +210,13 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Any.type_url"); - auto str = msg->mutable_type_url(); + object = msg->mutable_type_url(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -228,16 +225,13 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - auto str = msg->mutable_value(); + object = msg->mutable_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParser; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheck(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -256,6 +250,10 @@ const char* Any::_InternalParse(const char* begin, const char* end, void* object } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 63695f78a0..2a6ca2bf82 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -316,16 +316,13 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Api.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -338,11 +335,9 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object parser_till_end = ::google::protobuf::Method::_InternalParse; object = msg->add_methods(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 18 && (ptr += 1)); break; @@ -356,11 +351,9 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 26 && (ptr += 1)); break; @@ -371,16 +364,13 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Api.version"); - auto str = msg->mutable_version(); + object = msg->mutable_version(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -392,11 +382,9 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // repeated .google.protobuf.Mixin mixins = 6; @@ -408,11 +396,9 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object parser_till_end = ::google::protobuf::Mixin::_InternalParse; object = msg->add_mixins(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 50 && (ptr += 1)); break; @@ -420,11 +406,9 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object // .google.protobuf.Syntax syntax = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); + msg->set_syntax(static_cast<::google::protobuf::Syntax>(val)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); - msg->set_syntax(value); break; } default: { @@ -442,6 +426,10 @@ const char* Api::_InternalParse(const char* begin, const char* end, void* object } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -987,16 +975,13 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1006,27 +991,21 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.request_type_url"); - auto str = msg->mutable_request_type_url(); + object = msg->mutable_request_type_url(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // bool request_streaming = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_request_streaming(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_request_streaming(value); break; } // string response_type_url = 4; @@ -1035,27 +1014,21 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Method.response_type_url"); - auto str = msg->mutable_response_type_url(); + object = msg->mutable_response_type_url(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // bool response_streaming = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_response_streaming(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_response_streaming(value); break; } // repeated .google.protobuf.Option options = 6; @@ -1067,11 +1040,9 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 50 && (ptr += 1)); break; @@ -1079,11 +1050,9 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj // .google.protobuf.Syntax syntax = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); + msg->set_syntax(static_cast<::google::protobuf::Syntax>(val)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); - msg->set_syntax(value); break; } default: { @@ -1101,6 +1070,10 @@ const char* Method::_InternalParse(const char* begin, const char* end, void* obj } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -1616,16 +1589,13 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Mixin.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1635,16 +1605,13 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Mixin.root"); - auto str = msg->mutable_root(); + object = msg->mutable_root(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1663,6 +1630,10 @@ const char* Mixin::_InternalParse(const char* begin, const char* end, void* obje } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc deleted file mode 100644 index 7f33a0c865..0000000000 --- a/src/google/protobuf/arenastring.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// The ArenaString implementation is not included in the open-source release. Do -// not include this file in the distribution. - -#include - -namespace google { -namespace protobuf { -namespace internal { - - -} // namespace internal -} // namespace protobuf -} // namespace google diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc index f866eb6e0b..9b25797647 100644 --- a/src/google/protobuf/compiler/cpp/cpp_extension.cc +++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc @@ -40,6 +40,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -95,7 +96,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, variables_["name"] = name; variables_["constant_name"] = FieldConstantName(descriptor_); variables_["field_type"] = - SimpleItoa(static_cast(descriptor_->type())); + StrCat(static_cast(descriptor_->type())); variables_["packed"] = descriptor_->options().packed() ? "true" : "false"; string scope = @@ -103,7 +104,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, variables_["scope"] = scope; string scoped_name = scope + name; variables_["scoped_name"] = scoped_name; - variables_["number"] = SimpleItoa(descriptor_->number()); + variables_["number"] = StrCat(descriptor_->number()); } ExtensionGenerator::~ExtensionGenerator() {} diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc index 582da4ae09..fe20d4bb12 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_field.cc @@ -62,13 +62,13 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, SetCommonVars(options, variables); (*variables)["ns"] = Namespace(descriptor); (*variables)["name"] = FieldName(descriptor); - (*variables)["index"] = SimpleItoa(descriptor->index()); - (*variables)["number"] = SimpleItoa(descriptor->number()); + (*variables)["index"] = StrCat(descriptor->index()); + (*variables)["number"] = StrCat(descriptor->number()); (*variables)["classname"] = ClassName(FieldScope(descriptor), false); (*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type()); (*variables)["field_member"] = FieldName(descriptor) + "_"; - (*variables)["tag_size"] = SimpleItoa( + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), descriptor->type())); (*variables)["deprecated_attr"] = DeprecatedAttribute(options, descriptor->options().deprecated()); diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index 5df9e8004b..e9abeff8aa 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -50,6 +50,7 @@ #include + #include namespace google { @@ -477,10 +478,9 @@ void FileGenerator::GenerateInternalForwardDeclarations( auto scc = scc_analyzer->GetSCC(msg); string repr = UniqueName(ClassName(scc->GetRepresentative()), msg, options_); - global_namespace_decls.insert( - "extern " + dllexport + weak_attr + " ::" + ProtobufNamespace(options) + - "::internal::SCCInfo<" + SimpleItoa(scc->children.size()) + - "> scc_info_" + repr); + global_namespace_decls.insert(StrCat( + "extern ", dllexport, weak_attr, " ::", ProtobufNamespace(options), + "::internal::SCCInfo<", scc->children.size(), "> scc_info_", repr)); } format("\n"); diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc index ba631d303f..e4ec690a03 100644 --- a/src/google/protobuf/compiler/cpp/cpp_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc @@ -46,6 +46,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -203,8 +204,7 @@ bool CppGenerator::Generate(const FileDescriptor* file, } for (int i = 0; i < num_cc_files; i++) { std::unique_ptr output( - generator_context->Open(basename + ".out/" + - SimpleItoa(i) + ".cc")); + generator_context->Open(StrCat(basename, ".out/", i, ".cc"))); io::Printer printer(output.get(), '$'); if (i < file_generator.NumMessages()) { file_generator.GenerateSourceForMessage(i, &printer); diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 8e35a0e0a9..e6cbdf4668 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -41,6 +41,7 @@ #include #include #include + #include #include #include @@ -420,7 +421,7 @@ string FieldConstantName(const FieldDescriptor* field) { // This field's camelcase name is not unique. As a hack, add the field // number to the constant name. This makes the constant rather useless, // but what can we do? - result += "_" + SimpleItoa(field->number()); + result += "_" + StrCat(field->number()); } return result; @@ -555,9 +556,9 @@ string Int32ToString(int number) { if (number == kint32min) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 - return SimpleItoa(number + 1) + " - 1"; + return StrCat(number + 1, " - 1"); } else { - return SimpleItoa(number); + return StrCat(number); } } @@ -565,14 +566,13 @@ string Int64ToString(const string& macro_prefix, int64 number) { if (number == kint64min) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 - return macro_prefix + "_LONGLONG(" + SimpleItoa(number + 1) + - ") - 1"; + return StrCat(macro_prefix, "_LONGLONG(", number + 1, ") - 1"); } - return macro_prefix + "_LONGLONG(" + SimpleItoa(number) + ")"; + return StrCat(macro_prefix, "_LONGLONG(", number, ")"); } string UInt64ToString(const string& macro_prefix, uint64 number) { - return macro_prefix + "_ULONGLONG(" + SimpleItoa(number) + ")"; + return StrCat(macro_prefix, "_ULONGLONG(", number, ")"); } string DefaultValue(const FieldDescriptor* field) { @@ -591,7 +591,7 @@ string DefaultValue(const Options& options, const FieldDescriptor* field) { case FieldDescriptor::CPPTYPE_INT32: return Int32ToString(field->default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: - return SimpleItoa(field->default_value_uint32()) + "u"; + return StrCat(field->default_value_uint32()) + "u"; case FieldDescriptor::CPPTYPE_INT64: return Int64ToString("PROTOBUF", field->default_value_int64()); case FieldDescriptor::CPPTYPE_UINT64: @@ -1422,6 +1422,26 @@ class ParseLoopGenerator { " } // switch\n" " } // while\n" " return ptr;\n"); + if (use_string_) { + format_( + "string_till_end:\n" + " static_cast<$string$*>(object)->clear();\n" + // TODO(gerbens) evaluate security + " static_cast<$string$*>(object)->reserve(size);\n" + " goto len_delim_till_end;\n"); + } + if (use_arena_string_) { + format_( + "arena_string_till_end:\n" + " object = " + "static_cast<::$proto_ns$::internal::ArenaStringPtr*>(object)->" + "Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), " + "msg->GetArenaNoVirtual());\n" + " static_cast<$string$*>(object)->clear();\n" + // TODO(gerbens) evaluate security + " static_cast<$string$*>(object)->reserve(size);\n" + " goto len_delim_till_end;\n"); + } if (use_length_delimited_) { format_( "len_delim_till_end:\n" @@ -1447,33 +1467,30 @@ class ParseLoopGenerator { Formatter format_; bool use_length_delimited_ = false; bool use_group_ = false; + bool use_string_ = false; + bool use_arena_string_ = false; using WireFormat = internal::WireFormat; using WireFormatLite = internal::WireFormatLite; void GenerateArenaString(const FieldDescriptor* field, const string& utf8) { + use_arena_string_ = true; + if (HasFieldPresence(field->file())) { + format_("HasBitSetters::set_has_$1$(msg);\n", FieldName(field)); + } format_( "if (size > end - ptr + " "::$proto_ns$::internal::ParseContext::kSlopBytes) {\n" - " auto str = msg->mutable_$1$();\n" - " str->clear();\n" - // TODO(gerbens) evaluate security - " str->reserve(size);\n" - " object = str;\n" + " object = &msg->$1$_;\n" " parser_till_end = ::$proto_ns$::internal::GreedyStringParser$2$;\n" - " goto len_delim_till_end;\n" + " goto arena_string_till_end;\n" "}\n" "$GOOGLE_PROTOBUF$_PARSER_ASSERT(::$proto_ns$::internal::StringCheck$2$" - "(ptr, size, ctx));\n", - FieldName(field), utf8); - if (HasFieldPresence(field->file())) { - format_("HasBitSetters::set_has_$1$(msg);\n", FieldName(field)); - } - format_( + "(ptr, size, ctx));\n" "::$proto_ns$::internal::CopyIntoArenaString(ptr, size, &msg->$1$_, " "msg->GetArenaNoVirtual());\n" "ptr += size;\n", - FieldName(field)); + FieldName(field), utf8); } void GenerateStrings(const FieldDescriptor* field, bool check_utf8) { @@ -1510,40 +1527,40 @@ class ParseLoopGenerator { return; } format_( - "auto str = msg->$1$_$2$();\n" + "object = msg->$1$_$2$();\n" "if (size > end - ptr + " - "::$proto_ns$::internal::ParseContext::kSlopBytes) {\n" - " object = str;\n", + "::$proto_ns$::internal::ParseContext::kSlopBytes) {\n", field->is_repeated() && !field->is_packable() ? "add" : "mutable", FieldName(field)); string name; + string label = "len_delim_till_end"; switch (ctype) { case FieldOptions::STRING: name = "GreedyStringParser"; - format_( - " str->clear();\n" - // TODO(gerbens) evaluate security - " str->reserve(size);\n"); + use_string_ = true; + label = "string_till_end"; break; case FieldOptions::CORD: name = "CordParser"; - format_(" str->Clear();\n"); + format_(" static_cast<::Cord*>(object)->Clear();\n"); break; case FieldOptions::STRING_PIECE: name = "StringPieceParser"; - format_(" str->Clear();\n"); + format_( + " " + "static_cast<::$proto_ns$::internal::StringPieceField*>(object)->" + "Clear();\n"); break; } format_( " parser_till_end = ::$proto_ns$::internal::$1$$2$;\n" - " goto len_delim_till_end;\n" + " goto $3$;\n" "}\n" "$GOOGLE_PROTOBUF$_PARSER_ASSERT(::$proto_ns$::internal::StringCheck$2$" - "(" - "ptr, size, ctx));\n" - "::$proto_ns$::internal::Inline$1$(str, ptr, size, ctx);\n" + "(ptr, size, ctx));\n" + "::$proto_ns$::internal::Inline$1$(object, ptr, size, ctx);\n" "ptr += size;\n", - name, utf8); + name, utf8, label); } void GenerateLengthDelim(const FieldDescriptor* field) { @@ -1690,11 +1707,9 @@ class ParseLoopGenerator { } format_( "if (size > end - ptr) goto len_delim_till_end;\n" - "auto newend = ptr + size;\n" - "bool ok = ctx->ParseExactRange({parser_till_end, object},\n" - " ptr, newend);\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ok);\n" - "ptr = newend;\n"); + "ptr += size;\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ctx->ParseExactRange(\n" + " {parser_till_end, object}, ptr - size, ptr));\n"); break; } default: @@ -1712,21 +1727,11 @@ class ParseLoopGenerator { } switch (wiretype) { case WireFormatLite::WIRETYPE_VARINT: { - format_( - "$uint64$ val;\n" - "ptr = ::$proto_ns$::io::Parse64(ptr, &val);\n" - "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); string type = PrimitiveTypeName(options_, field->cpp_type()); - if ((field->type() == FieldDescriptor::TYPE_SINT32 || - field->type() == FieldDescriptor::TYPE_SINT64) && + string prefix = field->is_repeated() ? "add" : "set"; + if (field->type() == FieldDescriptor::TYPE_ENUM && !IsProto1(field->file(), options_)) { - int size = field->type() == FieldDescriptor::TYPE_SINT32 ? 32 : 64; - format_( - "$1$ value = " - "::$proto_ns$::internal::WireFormatLite::ZigZagDecode$2$(val);\n", - type, size); - } else if (field->type() == FieldDescriptor::TYPE_ENUM && - !IsProto1(field->file(), options_)) { + format_("$uint64$ val = ::$proto_ns$::internal::ReadVarint(&ptr);\n"); if (!HasPreservingUnknownEnumSemantics(field->file())) { format_( "if (!$1$_IsValid(val)) {\n" @@ -1736,30 +1741,31 @@ class ParseLoopGenerator { "}\n", QualifiedClassName(field->enum_type()), field->number()); } - format_("$1$ value = static_cast<$1$>(val);\n", - QualifiedClassName(field->enum_type())); + format_("msg->$1$_$2$(static_cast<$3$>(val));\n", prefix, + FieldName(field), QualifiedClassName(field->enum_type())); } else { - format_("$1$ value = val;\n", type); - } - if (field->is_repeated()) { - format_("msg->add_$1$(value);\n", FieldName(field)); - } else { - format_("msg->set_$1$(value);\n", FieldName(field)); + string zigzag; + if ((field->type() == FieldDescriptor::TYPE_SINT32 || + field->type() == FieldDescriptor::TYPE_SINT64) && + !IsProto1(field->file(), options_)) { + int size = field->type() == FieldDescriptor::TYPE_SINT32 ? 32 : 64; + zigzag = StrCat("ZigZag", size); + } + format_( + "msg->$1$_$2$(::$proto_ns$::internal::ReadVarint$3$(&ptr));\n", + prefix, FieldName(field), zigzag); } + format_("$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); break; } + case WireFormatLite::WIRETYPE_FIXED32: case WireFormatLite::WIRETYPE_FIXED64: { + string prefix = field->is_repeated() ? "add" : "set"; string type = PrimitiveTypeName(options_, field->cpp_type()); format_( - "$1$ val;\n" - "::std::memcpy(&val, ptr, 8);\n" - "ptr += 8;\n", - type); - if (field->is_repeated()) { - format_("msg->add_$1$(val);\n", FieldName(field)); - } else { - format_("msg->set_$1$(val);\n", FieldName(field)); - } + "msg->$1$_$2$(::$proto_ns$::io::UnalignedLoad<$3$>(ptr));\n" + "ptr += sizeof($3$);\n", + prefix, FieldName(field), type); break; } case WireFormatLite::WIRETYPE_LENGTH_DELIMITED: { @@ -1786,20 +1792,6 @@ class ParseLoopGenerator { GOOGLE_LOG(FATAL) << "Can't have end group field\n"; break; } - case WireFormatLite::WIRETYPE_FIXED32: { - string type = PrimitiveTypeName(options_, field->cpp_type()); - format_( - "$1$ val;\n" - "std::memcpy(&val, ptr, 4);\n" - "ptr += 4;\n", - type); - if (field->is_repeated()) { - format_("msg->add_$1$(val);\n", FieldName(field)); - } else { - format_("msg->set_$1$(val);\n", FieldName(field)); - } - break; - } } // switch (wire_type) if (ShouldRepeat(field, wiretype)) { diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index a055702c00..21521f8a91 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -51,6 +51,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -593,7 +594,7 @@ class PROTOC_EXPORT Formatter { template ::value>::type> static std::string ToString(I x) { - return SimpleItoa(x); + return StrCat(x); } static std::string ToString(strings::Hex x) { return StrCat(x); } static std::string ToString(const FieldDescriptor* d) { return Payload(d); } diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc index b44677f5e6..86e4df3387 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -80,9 +80,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, (*variables)["val_wire_type"] = "TYPE_" + ToUpper(DeclaredTypeMethodName(val->type())); (*variables)["map_classname"] = ClassName(descriptor->message_type(), false); - (*variables)["number"] = SimpleItoa(descriptor->number()); - (*variables)["tag"] = - SimpleItoa(internal::WireFormat::MakeTag(descriptor)); + (*variables)["number"] = StrCat(descriptor->number()); + (*variables)["tag"] = StrCat(internal::WireFormat::MakeTag(descriptor)); if (HasDescriptorMethods(descriptor->file(), options)) { (*variables)["lite"] = ""; diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 10aef2db16..ed20edd47c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -246,8 +246,7 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) { bool ShouldMarkClassAsFinal(const Descriptor* descriptor, const Options& options) { - const string name = ClassName(descriptor, true); - return HasPrefixString(name, "::google::protobuf"); + return true; } bool ShouldMarkClearAsFinal(const Descriptor* descriptor, @@ -909,7 +908,7 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) { format.Set("field_name", UnderscoresToCamelCase(field->name(), true)); format.Set("oneof_name", field->containing_oneof()->name()); format.Set("oneof_index", - SimpleItoa(field->containing_oneof()->index())); + StrCat(field->containing_oneof()->index())); GenerateOneofMemberHasBits(field, format); } else { // Singular field. @@ -1342,8 +1341,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { const string has_bits_decl = sizeof_has_bits == 0 ? "" - : "::$proto_ns$::internal::HasBits<" + - SimpleItoa(sizeof_has_bits / 4) + "> _has_bits_;\n"; + : StrCat("::$proto_ns$::internal::HasBits<", + sizeof_has_bits / 4, "> _has_bits_;\n"); // To minimize padding, data members are divided into three sections: // (1) members assumed to align to 8 bytes @@ -1634,10 +1633,9 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { std::map vars; vars["classtype"] = QualifiedClassName(descriptor_); vars["field_name"] = FieldName(field); - vars["tag"] = SimpleItoa(tag); - vars["hasbit"] = SimpleItoa(i); - vars["type"] = - SimpleItoa(CalcFieldNum(generator, field, options_)); + vars["tag"] = StrCat(tag); + vars["hasbit"] = StrCat(i); + vars["type"] = StrCat(CalcFieldNum(generator, field, options_)); vars["ptr"] = "nullptr"; if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { GOOGLE_CHECK(!IsMapEntryMessage(field->message_type())); @@ -1646,8 +1644,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { "::" + UniqueName("TableStruct", field->message_type(), options_) + "::serialization_table + " + - SimpleItoa( - FindMessageIndexInFile(field->message_type())); + StrCat(FindMessageIndexInFile(field->message_type())); } } Formatter::SaveState saver(&format); @@ -1724,7 +1721,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { ptr = "::" + UniqueName("TableStruct", field->message_type(), options_) + "::serialization_table + " + - SimpleItoa(FindMessageIndexInFile(field->message_type())); + StrCat(FindMessageIndexInFile(field->message_type())); } } @@ -2172,16 +2169,15 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) { std::map vars; if (field->containing_oneof() != NULL) { vars["name"] = field->containing_oneof()->name(); - vars["presence"] = - SimpleItoa(field->containing_oneof()->index()); + vars["presence"] = StrCat(field->containing_oneof()->index()); } else { vars["name"] = FieldName(field); - vars["presence"] = SimpleItoa(has_bit_indices_[field->index()]); + vars["presence"] = StrCat(has_bit_indices_[field->index()]); } - vars["nwtype"] = SimpleItoa(normal_wiretype); - vars["pwtype"] = SimpleItoa(packed_wiretype); - vars["ptype"] = SimpleItoa(processing_type); - vars["tag_size"] = SimpleItoa(tag_size); + vars["nwtype"] = StrCat(normal_wiretype); + vars["pwtype"] = StrCat(packed_wiretype); + vars["ptype"] = StrCat(processing_type); + vars["tag_size"] = StrCat(tag_size); format.AddMap(vars); @@ -2336,9 +2332,8 @@ std::pair MessageGenerator::GenerateOffsets( } else if (HasFieldPresence(descriptor_->file())) { entries += has_bit_indices_.size(); for (int i = 0; i < has_bit_indices_.size(); i++) { - const string index = has_bit_indices_[i] >= 0 - ? SimpleItoa(has_bit_indices_[i]) - : "~0u"; + const string index = + has_bit_indices_[i] >= 0 ? StrCat(has_bit_indices_[i]) : "~0u"; format("$1$,\n", index); } } @@ -3775,8 +3770,8 @@ void MessageGenerator::GenerateSerializeOneExtensionRange( io::Printer* printer, const Descriptor::ExtensionRange* range, bool to_array) { std::map vars; - vars["start"] = SimpleItoa(range->start); - vars["end"] = SimpleItoa(range->end); + vars["start"] = StrCat(range->start); + vars["end"] = StrCat(range->end); Formatter format(printer, vars); format("// Extension range [$start$, $end$)\n"); if (to_array) { diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index 2f6a050455..a009a14ed7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -38,6 +38,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -85,11 +86,10 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = PrimitiveTypeName(options, descriptor->cpp_type()); (*variables)["default"] = DefaultValue(options, descriptor); - (*variables)["tag"] = - SimpleItoa(internal::WireFormat::MakeTag(descriptor)); + (*variables)["tag"] = StrCat(internal::WireFormat::MakeTag(descriptor)); int fixed_size = FixedSize(descriptor->type()); if (fixed_size != -1) { - (*variables)["fixed_size"] = SimpleItoa(fixed_size); + (*variables)["fixed_size"] = StrCat(fixed_size); } (*variables)["wire_format_field_type"] = FieldDescriptorProto_Type_Name( static_cast(descriptor->type())); diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 74a3f34baa..3972ed25e3 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc @@ -39,6 +39,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -52,7 +53,7 @@ void SetStringVariables(const FieldDescriptor* descriptor, SetCommonFieldVariables(descriptor, variables, options); (*variables)["default"] = DefaultValue(options, descriptor); (*variables)["default_length"] = - SimpleItoa(descriptor->default_value_string().length()); + StrCat(descriptor->default_value_string().length()); string default_variable_string = MakeDefaultName(descriptor); (*variables)["default_variable_name"] = default_variable_string; (*variables)["default_variable"] = diff --git a/src/google/protobuf/compiler/java/java_context.cc b/src/google/protobuf/compiler/java/java_context.cc index 2528c2d13f..db795ed198 100644 --- a/src/google/protobuf/compiler/java/java_context.cc +++ b/src/google/protobuf/compiler/java/java_context.cc @@ -35,6 +35,7 @@ #include #include #include + #include namespace google { @@ -159,8 +160,8 @@ void Context::InitializeFieldGeneratorInfoForFields( // For fields conflicting with some other fields, we append the field // number to their field names in generated code to avoid conflicts. if (is_conflict[i]) { - info.name += SimpleItoa(field->number()); - info.capitalized_name += SimpleItoa(field->number()); + info.name += StrCat(field->number()); + info.capitalized_name += StrCat(field->number()); info.disambiguated_reason = conflict_reason[i]; } field_generator_info_map_[field] = info; diff --git a/src/google/protobuf/compiler/java/java_enum.cc b/src/google/protobuf/compiler/java/java_enum.cc index 1ca7ba958b..9436aa6633 100644 --- a/src/google/protobuf/compiler/java/java_enum.cc +++ b/src/google/protobuf/compiler/java/java_enum.cc @@ -44,6 +44,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -96,8 +97,8 @@ void EnumGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { std::map vars; vars["name"] = canonical_values_[i]->name(); - vars["index"] = SimpleItoa(canonical_values_[i]->index()); - vars["number"] = SimpleItoa(canonical_values_[i]->number()); + vars["index"] = StrCat(canonical_values_[i]->index()); + vars["number"] = StrCat(canonical_values_[i]->number()); WriteEnumValueDocComment(printer, canonical_values_[i]); if (canonical_values_[i]->options().deprecated()) { printer->Print("@java.lang.Deprecated\n"); @@ -141,7 +142,7 @@ void EnumGenerator::Generate(io::Printer* printer) { for (int i = 0; i < descriptor_->value_count(); i++) { std::map vars; vars["name"] = descriptor_->value(i)->name(); - vars["number"] = SimpleItoa(descriptor_->value(i)->number()); + vars["number"] = StrCat(descriptor_->value(i)->number()); vars["{"] = ""; vars["}"] = ""; WriteEnumValueDocComment(printer, descriptor_->value(i)); @@ -192,7 +193,7 @@ void EnumGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { printer->Print("case $number$: return $name$;\n", "name", canonical_values_[i]->name(), "number", - SimpleItoa(canonical_values_[i]->number())); + StrCat(canonical_values_[i]->number())); } printer->Outdent(); @@ -244,7 +245,7 @@ void EnumGenerator::Generate(io::Printer* printer) { " return $file$.getDescriptor().getEnumTypes().get($index$);\n", "file", name_resolver_->GetClassName(descriptor_->file(), immutable_api_), - "index", SimpleItoa(descriptor_->index())); + "index", StrCat(descriptor_->index())); } else { printer->Print( " return $parent$.$descriptor$.getEnumTypes().get($index$);\n", @@ -257,7 +258,7 @@ void EnumGenerator::Generate(io::Printer* printer) { .no_standard_descriptor_accessor() ? "getDefaultInstance().getDescriptorForType()" : "getDescriptor()", - "index", SimpleItoa(descriptor_->index())); + "index", StrCat(descriptor_->index())); } printer->Print( diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc index 9d0bcd2cec..35c9a316d0 100644 --- a/src/google/protobuf/compiler/java/java_enum_field.cc +++ b/src/google/protobuf/compiler/java/java_enum_field.cc @@ -46,6 +46,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -67,10 +68,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, name_resolver->GetMutableClassName(descriptor->enum_type()); (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_number"] = - SimpleItoa(descriptor->default_value_enum()->number()); - (*variables)["tag"] = SimpleItoa( + StrCat(descriptor->default_value_enum()->number()); + (*variables)["tag"] = StrCat( static_cast(internal::WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = SimpleItoa( + (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler @@ -358,7 +359,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { void ImmutableEnumFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print(variables_, - "result = result && $name$_ == other.$name$_;\n"); + "if ($name$_ != other.$name$_) return false;\n"); } void ImmutableEnumFieldGenerator:: @@ -554,12 +555,12 @@ void ImmutableEnumOneofFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print(variables_, - "result = result && get$capitalized_name$Value()\n" - " == other.get$capitalized_name$Value();\n"); + "if (get$capitalized_name$Value()\n" + " != other.get$capitalized_name$Value()) return false;\n"); } else { printer->Print(variables_, - "result = result && get$capitalized_name$()\n" - " .equals(other.get$capitalized_name$());\n"); + "if (!get$capitalized_name$()\n" + " .equals(other.get$capitalized_name$())) return false;\n"); } } @@ -983,7 +984,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { void RepeatedImmutableEnumFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print(variables_, - "result = result && $name$_.equals(other.$name$_);\n"); + "if (!$name$_.equals(other.$name$_)) return false;\n"); } void RepeatedImmutableEnumFieldGenerator:: diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/src/google/protobuf/compiler/java/java_enum_field_lite.cc index 353a2f6e57..2b0ec2928a 100644 --- a/src/google/protobuf/compiler/java/java_enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_enum_field_lite.cc @@ -46,6 +46,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -67,10 +68,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, name_resolver->GetMutableClassName(descriptor->enum_type()); (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_number"] = - SimpleItoa(descriptor->default_value_enum()->number()); - (*variables)["tag"] = SimpleItoa( + StrCat(descriptor->default_value_enum()->number()); + (*variables)["tag"] = StrCat( static_cast(internal::WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = SimpleItoa( + (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler diff --git a/src/google/protobuf/compiler/java/java_enum_lite.cc b/src/google/protobuf/compiler/java/java_enum_lite.cc index deebe523c6..9db138373f 100644 --- a/src/google/protobuf/compiler/java/java_enum_lite.cc +++ b/src/google/protobuf/compiler/java/java_enum_lite.cc @@ -43,6 +43,7 @@ #include #include #include + #include namespace google { @@ -87,7 +88,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { std::map vars; vars["name"] = canonical_values_[i]->name(); - vars["number"] = SimpleItoa(canonical_values_[i]->number()); + vars["number"] = StrCat(canonical_values_[i]->number()); WriteEnumValueDocComment(printer, canonical_values_[i]); if (canonical_values_[i]->options().deprecated()) { printer->Print("@java.lang.Deprecated\n"); @@ -122,7 +123,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { for (int i = 0; i < descriptor_->value_count(); i++) { std::map vars; vars["name"] = descriptor_->value(i)->name(); - vars["number"] = SimpleItoa(descriptor_->value(i)->number()); + vars["number"] = StrCat(descriptor_->value(i)->number()); vars["{"] = ""; vars["}"] = ""; WriteEnumValueDocComment(printer, descriptor_->value(i)); @@ -166,7 +167,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { printer->Print("case $number$: return $name$;\n", "name", canonical_values_[i]->name(), "number", - SimpleItoa(canonical_values_[i]->number())); + StrCat(canonical_values_[i]->number())); } printer->Outdent(); diff --git a/src/google/protobuf/compiler/java/java_extension.cc b/src/google/protobuf/compiler/java/java_extension.cc index 1ee9771046..cc1921d5a4 100644 --- a/src/google/protobuf/compiler/java/java_extension.cc +++ b/src/google/protobuf/compiler/java/java_extension.cc @@ -41,6 +41,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -69,9 +70,9 @@ void ExtensionGenerator::InitTemplateVars( vars["name"] = UnderscoresToCamelCase(descriptor); vars["containing_type"] = name_resolver->GetClassName(descriptor->containing_type(), immutable); - vars["number"] = SimpleItoa(descriptor->number()); + vars["number"] = StrCat(descriptor->number()); vars["constant_name"] = FieldConstantName(descriptor); - vars["index"] = SimpleItoa(descriptor->index()); + vars["index"] = StrCat(descriptor->index()); vars["default"] = descriptor->is_repeated() ? "" : DefaultValue(descriptor, immutable, name_resolver); vars["type_constant"] = FieldTypeName(GetType(descriptor)); @@ -152,7 +153,7 @@ int ImmutableExtensionGenerator::GenerateNonNestedInitializationCode( printer->Print( "$name$.internalInit(descriptor.getExtensions().get($index$));\n", "name", UnderscoresToCamelCase(descriptor_), "index", - SimpleItoa(descriptor_->index())); + StrCat(descriptor_->index())); bytecode_estimate += 21; } return bytecode_estimate; diff --git a/src/google/protobuf/compiler/java/java_field.cc b/src/google/protobuf/compiler/java/java_field.cc index fec20a7f35..9574c151a2 100644 --- a/src/google/protobuf/compiler/java/java_field.cc +++ b/src/google/protobuf/compiler/java/java_field.cc @@ -55,6 +55,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -254,7 +255,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_name"] = info->capitalized_name; (*variables)["disambiguated_reason"] = info->disambiguated_reason; (*variables)["constant_name"] = FieldConstantName(descriptor); - (*variables)["number"] = SimpleItoa(descriptor->number()); + (*variables)["number"] = StrCat(descriptor->number()); // These variables are placeholders to pick out the beginning and ends of // identifiers for annotations (when doing so with existing variables would // be ambiguous or impossible). They should never be set to anything but the @@ -269,13 +270,13 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor, (*variables)["oneof_name"] = info->name; (*variables)["oneof_capitalized_name"] = info->capitalized_name; (*variables)["oneof_index"] = - SimpleItoa(descriptor->containing_oneof()->index()); + StrCat(descriptor->containing_oneof()->index()); (*variables)["set_oneof_case_message"] = - info->name + "Case_ = " + SimpleItoa(descriptor->number()); + info->name + "Case_ = " + StrCat(descriptor->number()); (*variables)["clear_oneof_case_message"] = info->name + "Case_ = 0"; (*variables)["has_oneof_case_message"] = - info->name + "Case_ == " + SimpleItoa(descriptor->number()); + info->name + "Case_ == " + StrCat(descriptor->number()); } void PrintExtraFieldInfo(const std::map& variables, diff --git a/src/google/protobuf/compiler/java/java_file.cc b/src/google/protobuf/compiler/java/java_file.cc index 5356512ced..d345ca9041 100644 --- a/src/google/protobuf/compiler/java/java_file.cc +++ b/src/google/protobuf/compiler/java/java_file.cc @@ -54,6 +54,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -172,11 +173,10 @@ void MaybeRestartJavaMethod(io::Printer* printer, if ((*bytecode_estimate) > bytesPerMethod) { ++(*method_num); - printer->Print(chain_statement, "method_num", - SimpleItoa(*method_num)); + printer->Print(chain_statement, "method_num", StrCat(*method_num)); printer->Outdent(); printer->Print("}\n"); - printer->Print(method_decl, "method_num", SimpleItoa(*method_num)); + printer->Print(method_decl, "method_num", StrCat(*method_num)); printer->Indent(); *bytecode_estimate = 0; } @@ -548,13 +548,11 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(io::Printer* " $scope$.getExtensions().get($index$),\n" " (com.google.protobuf.Message) defaultExtensionInstance);\n" "}\n", - "scope", scope, "index", SimpleItoa(field->index()), - "class", + "scope", scope, "index", StrCat(field->index()), "class", name_resolver_->GetImmutableClassName(field->message_type())); } else { printer->Print("registry.add($scope$.getExtensions().get($index$));\n", - "scope", scope, "index", - SimpleItoa(field->index())); + "scope", scope, "index", StrCat(field->index())); } } printer->Print( diff --git a/src/google/protobuf/compiler/java/java_helpers.cc b/src/google/protobuf/compiler/java/java_helpers.cc index dbd1604a60..97ad0533e7 100644 --- a/src/google/protobuf/compiler/java/java_helpers.cc +++ b/src/google/protobuf/compiler/java/java_helpers.cc @@ -46,6 +46,7 @@ #include + #include // for hash namespace google { @@ -473,16 +474,14 @@ string DefaultValue(const FieldDescriptor* field, bool immutable, // of FieldDescriptor to call. switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return SimpleItoa(field->default_value_int32()); + return StrCat(field->default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: // Need to print as a signed int since Java has no unsigned. - return SimpleItoa( - static_cast(field->default_value_uint32())); + return StrCat(static_cast(field->default_value_uint32())); case FieldDescriptor::CPPTYPE_INT64: - return SimpleItoa(field->default_value_int64()) + "L"; + return StrCat(field->default_value_int64()) + "L"; case FieldDescriptor::CPPTYPE_UINT64: - return SimpleItoa( - static_cast(field->default_value_uint64())) + + return StrCat(static_cast(field->default_value_uint64())) + "L"; case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field->default_value_double(); @@ -625,7 +624,7 @@ const char* bit_masks[] = { string GetBitFieldName(int index) { string varName = "bitField"; - varName += SimpleItoa(index); + varName += StrCat(index); varName += "_"; return varName; } @@ -641,7 +640,7 @@ string GenerateGetBitInternal(const string& prefix, int bitIndex) { int bitInVarIndex = bitIndex % 32; string mask = bit_masks[bitInVarIndex]; - string result = "((" + varName + " & " + mask + ") == " + mask + ")"; + string result = "((" + varName + " & " + mask + ") != 0)"; return result; } diff --git a/src/google/protobuf/compiler/java/java_map_field.cc b/src/google/protobuf/compiler/java/java_map_field.cc index b22a21993f..cfcb918d1a 100644 --- a/src/google/protobuf/compiler/java/java_map_field.cc +++ b/src/google/protobuf/compiler/java/java_map_field.cc @@ -773,8 +773,8 @@ void ImmutableMapFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print( variables_, - "result = result && internalGet$capitalized_name$().equals(\n" - " other.internalGet$capitalized_name$());\n"); + "if (!internalGet$capitalized_name$().equals(\n" + " other.internalGet$capitalized_name$())) return false;\n"); } void ImmutableMapFieldGenerator:: diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index 151422310a..9aabd62a47 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -56,6 +56,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -109,7 +110,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( std::map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); - vars["index"] = SimpleItoa(descriptor_->index()); + vars["index"] = StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); if (descriptor_->containing_type() != NULL) { vars["parent"] = UniqueFileScopeIdentifier( @@ -153,7 +154,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers( int bytecode_estimate = 0; std::map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); - vars["index"] = SimpleItoa(descriptor_->index()); + vars["index"] = StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); if (descriptor_->containing_type() != NULL) { vars["parent"] = UniqueFileScopeIdentifier( @@ -417,8 +418,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { descriptor_->oneof_decl(i))->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( descriptor_->oneof_decl(i))->capitalized_name; - vars["oneof_index"] = - SimpleItoa(descriptor_->oneof_decl(i)->index()); + vars["oneof_index"] = StrCat(descriptor_->oneof_decl(i)->index()); // oneofCase_ and oneof_ printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" @@ -434,7 +434,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { "$deprecation$$field_name$($field_number$),\n", "deprecation", field->options().deprecated() ? "@java.lang.Deprecated " : "", "field_name", ToUpper(field->name()), "field_number", - SimpleItoa(field->number())); + StrCat(field->number())); } printer->Print( "$cap_oneof_name$_NOT_SET(0);\n", @@ -459,7 +459,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); printer->Print(" case $field_number$: return $field_name$;\n", - "field_number", SimpleItoa(field->number()), + "field_number", StrCat(field->number()), "field_name", ToUpper(field->name())); } printer->Print( @@ -491,8 +491,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { for (int i = 0; i < descriptor_->field_count(); i++) { printer->Print("public static final int $constant_name$ = $number$;\n", "constant_name", FieldConstantName(descriptor_->field(i)), - "number", - SimpleItoa(descriptor_->field(i)->number())); + "number", StrCat(descriptor_->field(i)->number())); field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); printer->Print("\n"); } @@ -764,7 +763,7 @@ void ImmutableMessageGenerator::GenerateSerializeOneField( void ImmutableMessageGenerator::GenerateSerializeOneExtensionRange( io::Printer* printer, const Descriptor::ExtensionRange* range) { printer->Print("extensionWriter.writeUntil($end$, output);\n", "end", - SimpleItoa(range->end)); + StrCat(range->end)); } // =================================================================== @@ -838,7 +837,7 @@ GenerateDescriptorMethods(io::Printer* printer) { printer->Print( "case $number$:\n" " return internalGet$capitalized_name$();\n", - "number", SimpleItoa(field->number()), "capitalized_name", + "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); } printer->Print( @@ -929,7 +928,7 @@ void ImmutableMessageGenerator::GenerateIsInitialized( context_->GetOneofGeneratorInfo(oneof); printer->Print("if ($oneof_name$Case_ == $field_number$) {\n", "oneof_name", oneof_info->name, "field_number", - SimpleItoa(field->number())); + StrCat(field->number())); } else { printer->Print( "if (has$name$()) {\n", @@ -1023,7 +1022,6 @@ GenerateEqualsAndHashCode(io::Printer* printer) { "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - printer->Print("boolean result = true;\n"); for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); if (field->containing_oneof() == NULL) { @@ -1031,7 +1029,7 @@ GenerateEqualsAndHashCode(io::Printer* printer) { bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field); if (check_has_bits) { printer->Print( - "result = result && (has$name$() == other.has$name$());\n" + "if (has$name$() != other.has$name$()) return false;\n" "if (has$name$()) {\n", "name", info->capitalized_name); printer->Indent(); @@ -1048,13 +1046,12 @@ GenerateEqualsAndHashCode(io::Printer* printer) { // Compare oneofs. for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { printer->Print( - "result = result && get$oneof_capitalized_name$Case().equals(\n" - " other.get$oneof_capitalized_name$Case());\n", + "if (!get$oneof_capitalized_name$Case().equals(" + "other.get$oneof_capitalized_name$Case())) return false;\n", "oneof_capitalized_name", context_->GetOneofGeneratorInfo( descriptor_->oneof_decl(i))->capitalized_name); printer->Print( - "if (!result) return false;\n" "switch ($oneof_name$Case_) {\n", "oneof_name", context_->GetOneofGeneratorInfo( @@ -1063,7 +1060,7 @@ GenerateEqualsAndHashCode(io::Printer* printer) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); printer->Print("case $field_number$:\n", "field_number", - SimpleItoa(field->number())); + StrCat(field->number())); printer->Indent(); field_generators_.get(field).GenerateEqualsCode(printer); printer->Print("break;\n"); @@ -1080,14 +1077,14 @@ GenerateEqualsAndHashCode(io::Printer* printer) { // false for non-canonical ordering when running in LITE_RUNTIME but it's // the best we can do. printer->Print( - "result = result && unknownFields.equals(other.unknownFields);\n"); + "if (!unknownFields.equals(other.unknownFields)) return false;\n"); if (descriptor_->extension_range_count() > 0) { printer->Print( - "result = result &&\n" - " getExtensionFields().equals(other.getExtensionFields());\n"); + "if (!getExtensionFields().equals(other.getExtensionFields()))\n" + " return false;\n"); } printer->Print( - "return result;\n"); + "return true;\n"); printer->Outdent(); printer->Print( "}\n" @@ -1145,7 +1142,7 @@ GenerateEqualsAndHashCode(io::Printer* printer) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); printer->Print("case $field_number$:\n", "field_number", - SimpleItoa(field->number())); + StrCat(field->number())); printer->Indent(); field_generators_.get(field).GenerateHashCode(printer); printer->Print("break;\n"); @@ -1252,7 +1249,7 @@ GenerateParsingConstructor(io::Printer* printer) { WireFormat::WireTypeForFieldType(field->type())); printer->Print("case $tag$: {\n", "tag", - SimpleItoa(static_cast(tag))); + StrCat(static_cast(tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCode(printer); @@ -1268,7 +1265,7 @@ GenerateParsingConstructor(io::Printer* printer) { uint32 packed_tag = WireFormatLite::MakeTag(field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED); printer->Print("case $tag$: {\n", "tag", - SimpleItoa(static_cast(packed_tag))); + StrCat(static_cast(packed_tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCodeFromPacked(printer); diff --git a/src/google/protobuf/compiler/java/java_message_builder.cc b/src/google/protobuf/compiler/java/java_message_builder.cc index f2f6d0b28e..761be791c5 100644 --- a/src/google/protobuf/compiler/java/java_message_builder.cc +++ b/src/google/protobuf/compiler/java/java_message_builder.cc @@ -54,6 +54,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -125,8 +126,7 @@ Generate(io::Printer* printer) { descriptor_->oneof_decl(i))->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( descriptor_->oneof_decl(i))->capitalized_name; - vars["oneof_index"] = - SimpleItoa(descriptor_->oneof_decl(i)->index()); + vars["oneof_index"] = StrCat(descriptor_->oneof_decl(i)->index()); // oneofCase_ and oneof_ printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" @@ -233,7 +233,7 @@ GenerateDescriptorMethods(io::Printer* printer) { printer->Print( "case $number$:\n" " return internalGet$capitalized_name$();\n", - "number", SimpleItoa(field->number()), "capitalized_name", + "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); } printer->Print( @@ -259,7 +259,7 @@ GenerateDescriptorMethods(io::Printer* printer) { printer->Print( "case $number$:\n" " return internalGetMutable$capitalized_name$();\n", - "number", SimpleItoa(field->number()), "capitalized_name", + "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); } printer->Print( @@ -685,7 +685,7 @@ void MessageBuilderGenerator::GenerateIsInitialized( context_->GetOneofGeneratorInfo(oneof); printer->Print("if ($oneof_name$Case_ == $field_number$) {\n", "oneof_name", oneof_info->name, "field_number", - SimpleItoa(field->number())); + StrCat(field->number())); } else { printer->Print( "if (has$name$()) {\n", diff --git a/src/google/protobuf/compiler/java/java_message_builder_lite.cc b/src/google/protobuf/compiler/java/java_message_builder_lite.cc index b9a12d4ad9..8987fa43de 100644 --- a/src/google/protobuf/compiler/java/java_message_builder_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_builder_lite.cc @@ -53,6 +53,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -101,8 +102,7 @@ Generate(io::Printer* printer) { descriptor_->oneof_decl(i))->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( descriptor_->oneof_decl(i))->capitalized_name; - vars["oneof_index"] = - SimpleItoa(descriptor_->oneof_decl(i)->index()); + vars["oneof_index"] = StrCat(descriptor_->oneof_decl(i)->index()); // oneofCase() and clearOneof() printer->Print(vars, diff --git a/src/google/protobuf/compiler/java/java_message_field.cc b/src/google/protobuf/compiler/java/java_message_field.cc index 92425d064e..5b6de09ac1 100644 --- a/src/google/protobuf/compiler/java/java_message_field.cc +++ b/src/google/protobuf/compiler/java/java_message_field.cc @@ -506,8 +506,8 @@ GenerateSerializedSizeCode(io::Printer* printer) const { void ImmutableMessageFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print(variables_, - "result = result && get$capitalized_name$()\n" - " .equals(other.get$capitalized_name$());\n"); + "if (!get$capitalized_name$()\n" + " .equals(other.get$capitalized_name$())) return false;\n"); } void ImmutableMessageFieldGenerator:: @@ -1307,8 +1307,8 @@ GenerateSerializedSizeCode(io::Printer* printer) const { void RepeatedImmutableMessageFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print(variables_, - "result = result && get$capitalized_name$List()\n" - " .equals(other.get$capitalized_name$List());\n"); + "if (!get$capitalized_name$List()\n" + " .equals(other.get$capitalized_name$List())) return false;\n"); } void RepeatedImmutableMessageFieldGenerator:: diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.cc b/src/google/protobuf/compiler/java/java_message_field_lite.cc index 7bf6426e81..58fbf15693 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_field_lite.cc @@ -36,14 +36,15 @@ #include #include -#include #include #include +#include #include #include #include #include + namespace google { namespace protobuf { namespace compiler { diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index a131e8cca4..3f907e2210 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -56,6 +56,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -253,7 +254,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( oneof)->capitalized_name; - vars["oneof_index"] = SimpleItoa(oneof->index()); + vars["oneof_index"] = StrCat(oneof->index()); // oneofCase_ and oneof_ printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" @@ -267,7 +268,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { const FieldDescriptor* field = oneof->field(j); printer->Print("$field_name$($field_number$),\n", "field_name", ToUpper(field->name()), "field_number", - SimpleItoa(field->number())); + StrCat(field->number())); } printer->Print( "$cap_oneof_name$_NOT_SET(0);\n", @@ -292,7 +293,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { for (int j = 0; j < oneof->field_count(); j++) { const FieldDescriptor* field = oneof->field(j); printer->Print(" case $field_number$: return $field_name$;\n", - "field_number", SimpleItoa(field->number()), + "field_number", StrCat(field->number()), "field_name", ToUpper(field->name())); } printer->Print( @@ -327,8 +328,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { for (int i = 0; i < descriptor_->field_count(); i++) { printer->Print("public static final int $constant_name$ = $number$;\n", "constant_name", FieldConstantName(descriptor_->field(i)), - "number", - SimpleItoa(descriptor_->field(i)->number())); + "number", StrCat(descriptor_->field(i)->number())); field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); printer->Print("\n"); } @@ -729,7 +729,7 @@ void ImmutableMessageLiteGenerator::GenerateSerializeOneField( void ImmutableMessageLiteGenerator::GenerateSerializeOneExtensionRange( io::Printer* printer, const Descriptor::ExtensionRange* range) { printer->Print("extensionWriter.writeUntil($end$, output);\n", "end", - SimpleItoa(range->end)); + StrCat(range->end)); } // =================================================================== @@ -810,7 +810,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodIsInitialized( context_->GetOneofGeneratorInfo(oneof); printer->Print("if ($oneof_name$Case_ == $field_number$) {\n", "oneof_name", oneof_info->name, "field_number", - SimpleItoa(field->number())); + StrCat(field->number())); } else { printer->Print( "if (has$name$()) {\n", @@ -1014,7 +1014,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream( field->number(), WireFormat::WireTypeForFieldType(field->type())); printer->Print("case $tag$: {\n", "tag", - SimpleItoa(static_cast(tag))); + StrCat(static_cast(tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCode(printer); @@ -1031,7 +1031,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream( uint32 packed_tag = WireFormatLite::MakeTag( field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED); printer->Print("case $tag$: {\n", "tag", - SimpleItoa(static_cast(packed_tag))); + StrCat(static_cast(packed_tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCodeFromPacked(printer); diff --git a/src/google/protobuf/compiler/java/java_primitive_field.cc b/src/google/protobuf/compiler/java/java_primitive_field.cc index a170a91006..b3ab52908d 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field.cc @@ -46,6 +46,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -113,8 +114,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_type"] = GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - SimpleItoa(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = SimpleItoa( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); if (IsReferenceType(GetJavaType(descriptor))) { (*variables)["null_check"] = @@ -130,7 +131,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, ? "@java.lang.Deprecated " : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { - (*variables)["fixed_size"] = SimpleItoa(fixed_size); + (*variables)["fixed_size"] = StrCat(fixed_size); } (*variables)["on_changed"] = "onChanged();"; @@ -385,31 +386,29 @@ GenerateEqualsCode(io::Printer* printer) const { case JAVATYPE_LONG: case JAVATYPE_BOOLEAN: printer->Print(variables_, - "result = result && (get$capitalized_name$()\n" - " == other.get$capitalized_name$());\n"); + "if (get$capitalized_name$()\n" + " != other.get$capitalized_name$()) return false;\n"); break; case JAVATYPE_FLOAT: printer->Print(variables_, - "result = result && (\n" - " java.lang.Float.floatToIntBits(get$capitalized_name$())\n" - " == java.lang.Float.floatToIntBits(\n" - " other.get$capitalized_name$()));\n"); + "if (java.lang.Float.floatToIntBits(get$capitalized_name$())\n" + " != java.lang.Float.floatToIntBits(\n" + " other.get$capitalized_name$())) return false;\n"); break; case JAVATYPE_DOUBLE: printer->Print(variables_, - "result = result && (\n" - " java.lang.Double.doubleToLongBits(get$capitalized_name$())\n" - " == java.lang.Double.doubleToLongBits(\n" - " other.get$capitalized_name$()));\n"); + "if (java.lang.Double.doubleToLongBits(get$capitalized_name$())\n" + " != java.lang.Double.doubleToLongBits(\n" + " other.get$capitalized_name$())) return false;\n"); break; case JAVATYPE_STRING: case JAVATYPE_BYTES: printer->Print(variables_, - "result = result && get$capitalized_name$()\n" - " .equals(other.get$capitalized_name$());\n"); + "if (!get$capitalized_name$()\n" + " .equals(other.get$capitalized_name$())) return false;\n"); break; case JAVATYPE_ENUM: @@ -926,8 +925,8 @@ GenerateSerializedSizeCode(io::Printer* printer) const { void RepeatedImmutablePrimitiveFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print(variables_, - "result = result && get$capitalized_name$List()\n" - " .equals(other.get$capitalized_name$List());\n"); + "if (!get$capitalized_name$List()\n" + " .equals(other.get$capitalized_name$List())) return false;\n"); } void RepeatedImmutablePrimitiveFieldGenerator:: diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc index 034a0865b0..ce3488212b 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc @@ -46,6 +46,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -71,8 +72,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_type"] = GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - SimpleItoa(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = SimpleItoa( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; @@ -131,7 +132,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, ? "@java.lang.Deprecated " : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { - (*variables)["fixed_size"] = SimpleItoa(fixed_size); + (*variables)["fixed_size"] = StrCat(fixed_size); } if (SupportFieldPresence(descriptor->file())) { diff --git a/src/google/protobuf/compiler/java/java_service.cc b/src/google/protobuf/compiler/java/java_service.cc index 53a9017de4..36676f904f 100644 --- a/src/google/protobuf/compiler/java/java_service.cc +++ b/src/google/protobuf/compiler/java/java_service.cc @@ -41,6 +41,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -90,7 +91,7 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) { " return $file$.getDescriptor().getServices().get($index$);\n" "}\n", "file", name_resolver_->GetImmutableClassName(descriptor_->file()), - "index", SimpleItoa(descriptor_->index())); + "index", StrCat(descriptor_->index())); GenerateGetDescriptorForType(printer); // Generate more stuff. @@ -209,7 +210,7 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); std::map vars; - vars["index"] = SimpleItoa(i); + vars["index"] = StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName( method->input_type()); @@ -256,7 +257,7 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod( for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); std::map vars; - vars["index"] = SimpleItoa(i); + vars["index"] = StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName( method->input_type()); @@ -302,7 +303,7 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); std::map vars; - vars["index"] = SimpleItoa(i); + vars["index"] = StrCat(i); vars["type"] = name_resolver_->GetImmutableClassName( (which == REQUEST) ? method->input_type() : method->output_type()); printer->Print(vars, @@ -354,7 +355,7 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { printer->Indent(); std::map vars; - vars["index"] = SimpleItoa(i); + vars["index"] = StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, "channel.callMethod(\n" @@ -418,7 +419,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { printer->Indent(); std::map vars; - vars["index"] = SimpleItoa(i); + vars["index"] = StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, "return ($output$) channel.callBlockingMethod(\n" diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index 2b6e938180..0184297b4c 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -47,6 +47,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -72,8 +73,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "String"; (*variables)["tag"] = - SimpleItoa(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = SimpleItoa( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["null_check"] = " if (value == null) {\n" @@ -451,8 +452,8 @@ GenerateSerializedSizeCode(io::Printer* printer) const { void ImmutableStringFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print(variables_, - "result = result && get$capitalized_name$()\n" - " .equals(other.get$capitalized_name$());\n"); + "if (!get$capitalized_name$()\n" + " .equals(other.get$capitalized_name$())) return false;\n"); } void ImmutableStringFieldGenerator:: @@ -1016,8 +1017,8 @@ GenerateSerializedSizeCode(io::Printer* printer) const { void RepeatedImmutableStringFieldGenerator:: GenerateEqualsCode(io::Printer* printer) const { printer->Print(variables_, - "result = result && get$capitalized_name$List()\n" - " .equals(other.get$capitalized_name$List());\n"); + "if (!get$capitalized_name$List()\n" + " .equals(other.get$capitalized_name$List())) return false;\n"); } void RepeatedImmutableStringFieldGenerator:: diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc index 5ce3151791..29f5d05a61 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -47,6 +47,7 @@ #include #include + namespace google { namespace protobuf { namespace compiler { @@ -73,8 +74,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "java.lang.String"; (*variables)["tag"] = - SimpleItoa(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = SimpleItoa( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["null_check"] = " if (value == null) {\n" diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 26645080d1..fd0367bc12 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -43,6 +43,7 @@ #include #include #include + #include #include #include @@ -615,12 +616,11 @@ string JSFieldIndex(const FieldDescriptor* field) { for (int i = 0; i < parent_type->field_count(); i++) { if (parent_type->field(i)->type() == FieldDescriptor::TYPE_GROUP && parent_type->field(i)->message_type() == containing_type) { - return SimpleItoa(field->number() - - parent_type->field(i)->number()); + return StrCat(field->number() - parent_type->field(i)->number()); } } } - return SimpleItoa(field->number()); + return StrCat(field->number()); } string JSOneofIndex(const OneofDescriptor* oneof) { @@ -639,7 +639,7 @@ string JSOneofIndex(const OneofDescriptor* oneof) { break; } } - return SimpleItoa(index); + return StrCat(index); } // Decodes a codepoint in \x0000 -- \xFFFF. @@ -845,23 +845,25 @@ string JSFieldDefault(const FieldDescriptor* field) { switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return MaybeNumberString( - field, SimpleItoa(field->default_value_int32())); + return MaybeNumberString(field, + StrCat(field->default_value_int32())); case FieldDescriptor::CPPTYPE_UINT32: // The original codegen is in Java, and Java protobufs store unsigned // integer values as signed integer values. In order to exactly match the // output, we need to reinterpret as base-2 signed. Ugh. - return MaybeNumberString(field, SimpleItoa(static_cast( - field->default_value_uint32()))); - case FieldDescriptor::CPPTYPE_INT64: return MaybeNumberString( - field, SimpleItoa(field->default_value_int64())); + field, + StrCat(static_cast(field->default_value_uint32()))); + case FieldDescriptor::CPPTYPE_INT64: + return MaybeNumberString(field, + StrCat(field->default_value_int64())); case FieldDescriptor::CPPTYPE_UINT64: // See above note for uint32 -- reinterpreting as signed. - return MaybeNumberString(field, SimpleItoa(static_cast( - field->default_value_uint64()))); + return MaybeNumberString( + field, + StrCat(static_cast(field->default_value_uint64()))); case FieldDescriptor::CPPTYPE_ENUM: - return SimpleItoa(field->default_value_enum()->number()); + return StrCat(field->default_value_enum()->number()); case FieldDescriptor::CPPTYPE_BOOL: return field->default_value_bool() ? "true" : "false"; case FieldDescriptor::CPPTYPE_FLOAT: @@ -1444,7 +1446,7 @@ string GetPivot(const Descriptor* desc) { (max_field_number + 1) : kDefaultPivot; } - return SimpleItoa(pivot); + return StrCat(pivot); } // Whether this field represents presence. For fields with presence, we @@ -2104,6 +2106,12 @@ void Generator::GenerateClassConstructor(const GeneratorOptions& options, "};\n" "goog.inherits($classname$, jspb.Message);\n" "if (goog.DEBUG && !COMPILED) {\n" + // displayName overrides Function.prototype.displayName + // http://google3/javascript/externs/es3.js?l=511 + " /**\n" + " * @public\n" + " * @override\n" + " */\n" " $classname$.displayName = '$classname$';\n" "}\n", "classname", GetMessagePath(options, desc)); @@ -3128,8 +3136,7 @@ void Generator::GenerateClassDeserializeBinaryField( const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field) const { - printer->Print(" case $num$:\n", "num", - SimpleItoa(field->number())); + printer->Print(" case $num$:\n", "num", StrCat(field->number())); if (field->is_map()) { const FieldDescriptor* key_field = MapFieldKey(field); @@ -3165,7 +3172,7 @@ void Generator::GenerateClassDeserializeBinaryField( (field->type() == FieldDescriptor::TYPE_GROUP) ? "Group" : "Message", "grpfield", (field->type() == FieldDescriptor::TYPE_GROUP) - ? (SimpleItoa(field->number()) + ", ") + ? (StrCat(field->number()) + ", ") : ""); } else { printer->Print( @@ -3328,7 +3335,7 @@ void Generator::GenerateClassSerializeBinaryField( printer->Print( " f.serializeBinary($index$, writer, " "$keyWriterFn$, $valueWriterFn$", - "index", SimpleItoa(field->number()), "keyWriterFn", + "index", StrCat(field->number()), "keyWriterFn", JSBinaryWriterMethodName(options, key_field), "valueWriterFn", JSBinaryWriterMethodName(options, value_field)); @@ -3344,7 +3351,7 @@ void Generator::GenerateClassSerializeBinaryField( " $index$,\n" " f", "method", JSBinaryReadWriteMethodName(field, /* is_writer = */ true), - "index", SimpleItoa(field->number())); + "index", StrCat(field->number())); if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !field->is_map()) { @@ -3381,7 +3388,7 @@ void Generator::GenerateEnum(const GeneratorOptions& options, const EnumValueDescriptor* value = enumdesc->value(i); printer->Print(" $name$: $value$$comma$\n", "name", ToEnumCase(value->name()), "value", - SimpleItoa(value->number()), "comma", + StrCat(value->number()), "comma", (i == enumdesc->value_count() - 1) ? "" : ","); printer->Annotate("name", value); } @@ -3425,8 +3432,8 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "!Object} */ (\n" " $toObject$),\n" " $repeated$);\n", - "index", SimpleItoa(field->number()), "name", - extension_object_name, "ctor", + "index", StrCat(field->number()), "name", extension_object_name, + "ctor", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ? SubmessageTypeRef(options, field) : string("null")), @@ -3446,8 +3453,8 @@ void Generator::GenerateExtension(const GeneratorOptions& options, " $binaryMessageDeserializeFn$,\n", "extendName", JSExtensionsObjectName(options, field->file(), field->containing_type()), - "index", SimpleItoa(field->number()), "class", extension_scope, - "name", extension_object_name, "binaryReaderFn", + "index", StrCat(field->number()), "class", extension_scope, "name", + extension_object_name, "binaryReaderFn", JSBinaryReaderMethodName(options, field), "binaryWriterFn", JSBinaryWriterMethodName(options, field), "binaryMessageSerializeFn", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) @@ -3468,8 +3475,8 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "\n", "extendName", JSExtensionsObjectName(options, field->file(), field->containing_type()), - "index", SimpleItoa(field->number()), "class", extension_scope, - "name", extension_object_name); + "index", StrCat(field->number()), "class", extension_scope, "name", + extension_object_name); } bool GeneratorOptions::ParseFromOptions( diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index 1a3171a802..3f9fe2a436 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -38,6 +38,7 @@ #include #include + #include #include @@ -1154,7 +1155,7 @@ bool Parser::ParseDefaultAssignment( DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. - default_value->append(SimpleItoa(value)); + default_value->append(StrCat(value)); break; } @@ -1177,7 +1178,7 @@ bool Parser::ParseDefaultAssignment( DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. - default_value->append(SimpleItoa(value)); + default_value->append(StrCat(value)); break; } diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 857eec7eae..745271be17 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -326,31 +326,22 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob // optional int32 major = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_major(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_major(value); break; } // optional int32 minor = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_minor(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_minor(value); break; } // optional int32 patch = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_patch(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_patch(value); break; } // optional string suffix = 4; @@ -359,16 +350,13 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.Version.suffix"); - auto str = msg->mutable_suffix(); + object = msg->mutable_suffix(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -387,6 +375,10 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -809,16 +801,13 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.file_to_generate"); - auto str = msg->add_file_to_generate(); + object = msg->add_file_to_generate(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 10 && (ptr += 1)); @@ -830,16 +819,13 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.parameter"); - auto str = msg->mutable_parameter(); + object = msg->mutable_parameter(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -851,11 +837,9 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* parser_till_end = ::google::protobuf::compiler::Version::_InternalParse; object = msg->mutable_compiler_version(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // repeated .google.protobuf.FileDescriptorProto proto_file = 15; @@ -867,11 +851,9 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* parser_till_end = ::google::protobuf::FileDescriptorProto::_InternalParse; object = msg->add_proto_file(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 122 && (ptr += 1)); break; @@ -891,6 +873,10 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -1327,16 +1313,13 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1346,16 +1329,13 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point"); - auto str = msg->mutable_insertion_point(); + object = msg->mutable_insertion_point(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1365,16 +1345,13 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.content"); - auto str = msg->mutable_content(); + object = msg->mutable_content(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1393,6 +1370,10 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -1779,16 +1760,13 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.error"); - auto str = msg->mutable_error(); + object = msg->mutable_error(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1801,11 +1779,9 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* parser_till_end = ::google::protobuf::compiler::CodeGeneratorResponse_File::_InternalParse; object = msg->add_file(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 122 && (ptr += 1)); break; @@ -1825,6 +1801,10 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index bbe83525e0..6b1e4d2898 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -65,6 +65,7 @@ #include + namespace google { namespace protobuf { namespace compiler { @@ -218,13 +219,13 @@ string StringifyDefaultValue(const FieldDescriptor& field) { switch (field.cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return SimpleItoa(field.default_value_int32()); + return StrCat(field.default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: - return SimpleItoa(field.default_value_uint32()); + return StrCat(field.default_value_uint32()); case FieldDescriptor::CPPTYPE_INT64: - return SimpleItoa(field.default_value_int64()); + return StrCat(field.default_value_int64()); case FieldDescriptor::CPPTYPE_UINT64: - return SimpleItoa(field.default_value_uint64()); + return StrCat(field.default_value_uint64()); case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field.default_value_double(); if (value == std::numeric_limits::infinity()) { @@ -260,7 +261,7 @@ string StringifyDefaultValue(const FieldDescriptor& field) { case FieldDescriptor::CPPTYPE_BOOL: return field.default_value_bool() ? "True" : "False"; case FieldDescriptor::CPPTYPE_ENUM: - return SimpleItoa(field.default_value_enum()->number()); + return StrCat(field.default_value_enum()->number()); case FieldDescriptor::CPPTYPE_STRING: //##!PY25 return "b\"" + CEscape(field.default_value_string()) + //##!PY25 (field.type() != FieldDescriptor::TYPE_STRING ? "\"" : @@ -495,7 +496,7 @@ void Generator::PrintTopLevelEnums() const { for (int i = 0; i < top_level_enum_values.size(); ++i) { printer_->Print("$name$ = $value$\n", "name", top_level_enum_values[i].first, "value", - SimpleItoa(top_level_enum_values[i].second)); + StrCat(top_level_enum_values[i].second)); } printer_->Print("\n"); } @@ -569,7 +570,7 @@ void Generator::PrintTopLevelExtensions() const { UpperString(&constant_name); printer_->Print("$constant_name$ = $number$\n", "constant_name", constant_name, "number", - SimpleItoa(extension_field.number())); + StrCat(extension_field.number())); printer_->Print("$name$ = ", "name", extension_field.name()); PrintFieldDescriptor(extension_field, is_extension); printer_->Print("\n"); @@ -616,7 +617,7 @@ void Generator::PrintServiceDescriptor( m["name"] = descriptor.name(); m["full_name"] = descriptor.full_name(); m["file"] = kDescriptorKey; - m["index"] = SimpleItoa(descriptor.index()); + m["index"] = StrCat(descriptor.index()); m["options_value"] = OptionsValue(options_string); const char required_function_arguments[] = "name='$name$',\n" @@ -637,7 +638,7 @@ void Generator::PrintServiceDescriptor( m.clear(); m["name"] = method->name(); m["full_name"] = method->full_name(); - m["index"] = SimpleItoa(method->index()); + m["index"] = StrCat(method->index()); m["serialized_options"] = CEscape(options_string); m["input_type"] = ModuleLevelDescriptorName(*(method->input_type())); m["output_type"] = ModuleLevelDescriptorName(*(method->output_type())); @@ -762,9 +763,8 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { for (int i = 0; i < message_descriptor.extension_range_count(); ++i) { const Descriptor::ExtensionRange* range = message_descriptor.extension_range(i); - printer_->Print("($start$, $end$), ", "start", - SimpleItoa(range->start), "end", - SimpleItoa(range->end)); + printer_->Print("($start$, $end$), ", "start", StrCat(range->start), + "end", StrCat(range->end)); } printer_->Print("],\n"); printer_->Print("oneofs=[\n"); @@ -774,7 +774,7 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { std::map m; m["name"] = desc->name(); m["full_name"] = desc->full_name(); - m["index"] = SimpleItoa(desc->index()); + m["index"] = StrCat(desc->index()); string options_string = OptionsValue(desc->options().SerializeAsString()); if (options_string == "None") { @@ -1108,8 +1108,8 @@ void Generator::PrintEnumValueDescriptor( descriptor.options().SerializeToString(&options_string); std::map m; m["name"] = descriptor.name(); - m["index"] = SimpleItoa(descriptor.index()); - m["number"] = SimpleItoa(descriptor.number()); + m["index"] = StrCat(descriptor.index()); + m["number"] = StrCat(descriptor.number()); m["options"] = OptionsValue(options_string); printer_->Print( m, @@ -1137,11 +1137,11 @@ void Generator::PrintFieldDescriptor( std::map m; m["name"] = field.name(); m["full_name"] = field.full_name(); - m["index"] = SimpleItoa(field.index()); - m["number"] = SimpleItoa(field.number()); - m["type"] = SimpleItoa(field.type()); - m["cpp_type"] = SimpleItoa(field.cpp_type()); - m["label"] = SimpleItoa(field.label()); + m["index"] = StrCat(field.index()); + m["number"] = StrCat(field.number()); + m["type"] = StrCat(field.type()); + m["cpp_type"] = StrCat(field.cpp_type()); + m["label"] = StrCat(field.label()); m["has_default_value"] = field.has_default_value() ? "True" : "False"; m["default_value"] = StringifyDefaultValue(field); m["is_extension"] = is_extension ? "True" : "False"; @@ -1281,8 +1281,8 @@ void Generator::PrintSerializedPbInterval( printer_->Print( "serialized_start=$serialized_start$,\n" "serialized_end=$serialized_end$,\n", - "serialized_start", SimpleItoa(offset), "serialized_end", - SimpleItoa(offset + sp.size())); + "serialized_start", StrCat(offset), "serialized_end", + StrCat(offset + sp.size())); } namespace { diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index caed8a94bd..606f8aca81 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -63,6 +63,7 @@ #include + #include #include #include @@ -1926,16 +1927,16 @@ string FieldDescriptor::DefaultValueAsString(bool quote_string_type) const { GOOGLE_CHECK(has_default_value()) << "No default value"; switch (cpp_type()) { case CPPTYPE_INT32: - return SimpleItoa(default_value_int32()); + return StrCat(default_value_int32()); break; case CPPTYPE_INT64: - return SimpleItoa(default_value_int64()); + return StrCat(default_value_int64()); break; case CPPTYPE_UINT32: - return SimpleItoa(default_value_uint32()); + return StrCat(default_value_uint32()); break; case CPPTYPE_UINT64: - return SimpleItoa(default_value_uint64()); + return StrCat(default_value_uint64()); break; case CPPTYPE_FLOAT: return SimpleFtoa(default_value_float()); diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index ac4d8b23eb..7da7546d9d 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -1135,10 +1135,8 @@ class PROTOBUF_EXPORT EnumValueDescriptor { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor); }; -// Describes an RPC service. To get the ServiceDescriptor for a service, -// call Service::GetDescriptor(). Generated service classes also have a -// static method called descriptor() which returns the type's -// ServiceDescriptor. Use DescriptorPool to construct your own descriptors. +// Describes an RPC service. Use DescriptorPool to construct your own +// descriptors. class PROTOBUF_EXPORT ServiceDescriptor { public: typedef ServiceDescriptorProto Proto; diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index bba219b48d..b999c1ccb0 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1486,11 +1486,9 @@ const char* FileDescriptorSet::_InternalParse(const char* begin, const char* end parser_till_end = ::google::protobuf::FileDescriptorProto::_InternalParse; object = msg->add_file(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 10 && (ptr += 1)); break; @@ -1939,16 +1937,13 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1958,16 +1953,13 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.package"); - auto str = msg->mutable_package(); + object = msg->mutable_package(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1978,16 +1970,13 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.dependency"); - auto str = msg->add_dependency(); + object = msg->add_dependency(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 26 && (ptr += 1)); @@ -2002,11 +1991,9 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::DescriptorProto::_InternalParse; object = msg->add_message_type(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 34 && (ptr += 1)); break; @@ -2020,11 +2007,9 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::EnumDescriptorProto::_InternalParse; object = msg->add_enum_type(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 42 && (ptr += 1)); break; @@ -2038,11 +2023,9 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::ServiceDescriptorProto::_InternalParse; object = msg->add_service(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 50 && (ptr += 1)); break; @@ -2056,11 +2039,9 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_extension(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 58 && (ptr += 1)); break; @@ -2073,11 +2054,9 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::FileOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; @@ -2088,22 +2067,17 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::SourceCodeInfo::_InternalParse; object = msg->mutable_source_code_info(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // repeated int32 public_dependency = 10; case 10: { if (static_cast<::google::protobuf::uint8>(tag) == 80) { do { - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->add_public_dependency(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->add_public_dependency(value); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 80 && (ptr += 1)); break; @@ -2122,11 +2096,8 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e case 11: { if (static_cast<::google::protobuf::uint8>(tag) == 88) { do { - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->add_weak_dependency(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->add_weak_dependency(value); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 88 && (ptr += 1)); break; @@ -2147,16 +2118,13 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileDescriptorProto.syntax"); - auto str = msg->mutable_syntax(); + object = msg->mutable_syntax(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -2175,6 +2143,10 @@ const char* FileDescriptorProto::_InternalParse(const char* begin, const char* e } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -2982,21 +2954,15 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co // optional int32 start = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_start(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_start(value); break; } // optional int32 end = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_end(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_end(value); break; } // optional .google.protobuf.ExtensionRangeOptions options = 3; @@ -3007,11 +2973,9 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* begin, co parser_till_end = ::google::protobuf::ExtensionRangeOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } default: { @@ -3402,21 +3366,15 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* begin, con // optional int32 start = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_start(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_start(value); break; } // optional int32 end = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_end(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_end(value); break; } default: { @@ -3835,16 +3793,13 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.DescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -3857,11 +3812,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_field(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 18 && (ptr += 1)); break; @@ -3875,11 +3828,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::DescriptorProto::_InternalParse; object = msg->add_nested_type(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 26 && (ptr += 1)); break; @@ -3893,11 +3844,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::EnumDescriptorProto::_InternalParse; object = msg->add_enum_type(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 34 && (ptr += 1)); break; @@ -3911,11 +3860,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::DescriptorProto_ExtensionRange::_InternalParse; object = msg->add_extension_range(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 42 && (ptr += 1)); break; @@ -3929,11 +3876,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::FieldDescriptorProto::_InternalParse; object = msg->add_extension(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 50 && (ptr += 1)); break; @@ -3946,11 +3891,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::MessageOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; @@ -3962,11 +3905,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::OneofDescriptorProto::_InternalParse; object = msg->add_oneof_decl(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 66 && (ptr += 1)); break; @@ -3980,11 +3921,9 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::DescriptorProto_ReservedRange::_InternalParse; object = msg->add_reserved_range(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 74 && (ptr += 1)); break; @@ -3996,16 +3935,13 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.DescriptorProto.reserved_name"); - auto str = msg->add_reserved_name(); + object = msg->add_reserved_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 82 && (ptr += 1)); @@ -4026,6 +3962,10 @@ const char* DescriptorProto::_InternalParse(const char* begin, const char* end, } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -4712,11 +4652,9 @@ const char* ExtensionRangeOptions::_InternalParse(const char* begin, const char* parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -5190,16 +5128,13 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -5209,55 +5144,45 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.extendee"); - auto str = msg->mutable_extendee(); + object = msg->mutable_extendee(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // optional int32 number = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_number(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_number(value); break; } // optional .google.protobuf.FieldDescriptorProto.Label label = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); - GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); if (!::google::protobuf::FieldDescriptorProto_Label_IsValid(val)) { ::google::protobuf::internal::WriteVarint(4, val, msg->mutable_unknown_fields()); break; } - ::google::protobuf::FieldDescriptorProto_Label value = static_cast<::google::protobuf::FieldDescriptorProto_Label>(val); - msg->set_label(value); + msg->set_label(static_cast<::google::protobuf::FieldDescriptorProto_Label>(val)); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); break; } // optional .google.protobuf.FieldDescriptorProto.Type type = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); - GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); if (!::google::protobuf::FieldDescriptorProto_Type_IsValid(val)) { ::google::protobuf::internal::WriteVarint(5, val, msg->mutable_unknown_fields()); break; } - ::google::protobuf::FieldDescriptorProto_Type value = static_cast<::google::protobuf::FieldDescriptorProto_Type>(val); - msg->set_type(value); + msg->set_type(static_cast<::google::protobuf::FieldDescriptorProto_Type>(val)); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); break; } // optional string type_name = 6; @@ -5266,16 +5191,13 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.type_name"); - auto str = msg->mutable_type_name(); + object = msg->mutable_type_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -5285,16 +5207,13 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.default_value"); - auto str = msg->mutable_default_value(); + object = msg->mutable_default_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -5306,21 +5225,16 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* parser_till_end = ::google::protobuf::FieldOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // optional int32 oneof_index = 9; case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 72) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_oneof_index(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_oneof_index(value); break; } // optional string json_name = 10; @@ -5329,16 +5243,13 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldDescriptorProto.json_name"); - auto str = msg->mutable_json_name(); + object = msg->mutable_json_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -5357,6 +5268,10 @@ const char* FieldDescriptorProto::_InternalParse(const char* begin, const char* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -6094,16 +6009,13 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.OneofDescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -6115,11 +6027,9 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* parser_till_end = ::google::protobuf::OneofOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } default: { @@ -6137,6 +6047,10 @@ const char* OneofDescriptorProto::_InternalParse(const char* begin, const char* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -6489,21 +6403,15 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* be // optional int32 start = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_start(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_start(value); break; } // optional int32 end = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_end(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_end(value); break; } default: { @@ -6902,16 +6810,13 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumDescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -6924,11 +6829,9 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::EnumValueDescriptorProto::_InternalParse; object = msg->add_value(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 18 && (ptr += 1)); break; @@ -6941,11 +6844,9 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::EnumOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; @@ -6957,11 +6858,9 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::EnumDescriptorProto_EnumReservedRange::_InternalParse; object = msg->add_reserved_range(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 34 && (ptr += 1)); break; @@ -6973,16 +6872,13 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumDescriptorProto.reserved_name"); - auto str = msg->add_reserved_name(); + object = msg->add_reserved_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 42 && (ptr += 1)); @@ -7003,6 +6899,10 @@ const char* EnumDescriptorProto::_InternalParse(const char* begin, const char* e } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -7529,27 +7429,21 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumValueDescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // optional int32 number = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_number(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_number(value); break; } // optional .google.protobuf.EnumValueOptions options = 3; @@ -7560,11 +7454,9 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch parser_till_end = ::google::protobuf::EnumValueOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } default: { @@ -7582,6 +7474,10 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* begin, const ch } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -8010,16 +7906,13 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.ServiceDescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -8032,11 +7925,9 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char parser_till_end = ::google::protobuf::MethodDescriptorProto::_InternalParse; object = msg->add_method(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 18 && (ptr += 1)); break; @@ -8049,11 +7940,9 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char parser_till_end = ::google::protobuf::ServiceOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } default: { @@ -8071,6 +7960,10 @@ const char* ServiceDescriptorProto::_InternalParse(const char* begin, const char } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -8546,16 +8439,13 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -8565,16 +8455,13 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.input_type"); - auto str = msg->mutable_input_type(); + object = msg->mutable_input_type(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -8584,16 +8471,13 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.MethodDescriptorProto.output_type"); - auto str = msg->mutable_output_type(); + object = msg->mutable_output_type(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -8605,31 +8489,23 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* parser_till_end = ::google::protobuf::MethodOptions::_InternalParse; object = msg->mutable_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // optional bool client_streaming = 5 [default = false]; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_client_streaming(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_client_streaming(value); break; } // optional bool server_streaming = 6 [default = false]; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 48) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_server_streaming(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_server_streaming(value); break; } default: { @@ -8647,6 +8523,10 @@ const char* MethodDescriptorProto::_InternalParse(const char* begin, const char* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -9355,16 +9235,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.java_package"); - auto str = msg->mutable_java_package(); + object = msg->mutable_java_package(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -9374,41 +9251,33 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.java_outer_classname"); - auto str = msg->mutable_java_outer_classname(); + object = msg->mutable_java_outer_classname(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; case 9: { if (static_cast<::google::protobuf::uint8>(tag) != 72) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); - GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); if (!::google::protobuf::FileOptions_OptimizeMode_IsValid(val)) { ::google::protobuf::internal::WriteVarint(9, val, msg->mutable_unknown_fields()); break; } - ::google::protobuf::FileOptions_OptimizeMode value = static_cast<::google::protobuf::FileOptions_OptimizeMode>(val); - msg->set_optimize_for(value); + msg->set_optimize_for(static_cast<::google::protobuf::FileOptions_OptimizeMode>(val)); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); break; } // optional bool java_multiple_files = 10 [default = false]; case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 80) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_java_multiple_files(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_java_multiple_files(value); break; } // optional string go_package = 11; @@ -9417,87 +9286,63 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.go_package"); - auto str = msg->mutable_go_package(); + object = msg->mutable_go_package(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // optional bool cc_generic_services = 16 [default = false]; case 16: { if (static_cast<::google::protobuf::uint8>(tag) != 128) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_cc_generic_services(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_cc_generic_services(value); break; } // optional bool java_generic_services = 17 [default = false]; case 17: { if (static_cast<::google::protobuf::uint8>(tag) != 136) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_java_generic_services(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_java_generic_services(value); break; } // optional bool py_generic_services = 18 [default = false]; case 18: { if (static_cast<::google::protobuf::uint8>(tag) != 144) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_py_generic_services(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_py_generic_services(value); break; } // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; case 20: { if (static_cast<::google::protobuf::uint8>(tag) != 160) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_java_generate_equals_and_hash(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_java_generate_equals_and_hash(value); break; } // optional bool deprecated = 23 [default = false]; case 23: { if (static_cast<::google::protobuf::uint8>(tag) != 184) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_deprecated(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_deprecated(value); break; } // optional bool java_string_check_utf8 = 27 [default = false]; case 27: { if (static_cast<::google::protobuf::uint8>(tag) != 216) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_java_string_check_utf8(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_java_string_check_utf8(value); break; } // optional bool cc_enable_arenas = 31 [default = false]; case 31: { if (static_cast<::google::protobuf::uint8>(tag) != 248) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_cc_enable_arenas(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_cc_enable_arenas(value); break; } // optional string objc_class_prefix = 36; @@ -9506,16 +9351,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.objc_class_prefix"); - auto str = msg->mutable_objc_class_prefix(); + object = msg->mutable_objc_class_prefix(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -9525,16 +9367,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.csharp_namespace"); - auto str = msg->mutable_csharp_namespace(); + object = msg->mutable_csharp_namespace(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -9544,16 +9383,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.swift_prefix"); - auto str = msg->mutable_swift_prefix(); + object = msg->mutable_swift_prefix(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -9563,16 +9399,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_class_prefix"); - auto str = msg->mutable_php_class_prefix(); + object = msg->mutable_php_class_prefix(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -9582,27 +9415,21 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_namespace"); - auto str = msg->mutable_php_namespace(); + object = msg->mutable_php_namespace(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // optional bool php_generic_services = 42 [default = false]; case 42: { if (static_cast<::google::protobuf::uint8>(tag) != 80) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_php_generic_services(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_php_generic_services(value); break; } // optional string php_metadata_namespace = 44; @@ -9611,16 +9438,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.php_metadata_namespace"); - auto str = msg->mutable_php_metadata_namespace(); + object = msg->mutable_php_metadata_namespace(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -9630,16 +9454,13 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FileOptions.ruby_package"); - auto str = msg->mutable_ruby_package(); + object = msg->mutable_ruby_package(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -9652,11 +9473,9 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -9684,6 +9503,10 @@ const char* FileOptions::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -10846,41 +10669,29 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v // optional bool message_set_wire_format = 1 [default = false]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_message_set_wire_format(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_message_set_wire_format(value); break; } // optional bool no_standard_descriptor_accessor = 2 [default = false]; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_no_standard_descriptor_accessor(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_no_standard_descriptor_accessor(value); break; } // optional bool deprecated = 3 [default = false]; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_deprecated(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_deprecated(value); break; } // optional bool map_entry = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_map_entry(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_map_entry(value); break; } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; @@ -10892,11 +10703,9 @@ const char* MessageOptions::_InternalParse(const char* begin, const char* end, v parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -11407,69 +11216,53 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); - GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); if (!::google::protobuf::FieldOptions_CType_IsValid(val)) { ::google::protobuf::internal::WriteVarint(1, val, msg->mutable_unknown_fields()); break; } - ::google::protobuf::FieldOptions_CType value = static_cast<::google::protobuf::FieldOptions_CType>(val); - msg->set_ctype(value); + msg->set_ctype(static_cast<::google::protobuf::FieldOptions_CType>(val)); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); break; } // optional bool packed = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_packed(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_packed(value); break; } // optional bool deprecated = 3 [default = false]; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_deprecated(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_deprecated(value); break; } // optional bool lazy = 5 [default = false]; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_lazy(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_lazy(value); break; } // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 48) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); - GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); if (!::google::protobuf::FieldOptions_JSType_IsValid(val)) { ::google::protobuf::internal::WriteVarint(6, val, msg->mutable_unknown_fields()); break; } - ::google::protobuf::FieldOptions_JSType value = static_cast<::google::protobuf::FieldOptions_JSType>(val); - msg->set_jstype(value); + msg->set_jstype(static_cast<::google::protobuf::FieldOptions_JSType>(val)); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); break; } // optional bool weak = 10 [default = false]; case 10: { if (static_cast<::google::protobuf::uint8>(tag) != 80) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_weak(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_weak(value); break; } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; @@ -11481,11 +11274,9 @@ const char* FieldOptions::_InternalParse(const char* begin, const char* end, voi parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -12048,11 +11839,9 @@ const char* OneofOptions::_InternalParse(const char* begin, const char* end, voi parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -12407,21 +12196,15 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void // optional bool allow_alias = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_allow_alias(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_allow_alias(value); break; } // optional bool deprecated = 3 [default = false]; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_deprecated(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_deprecated(value); break; } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; @@ -12433,11 +12216,9 @@ const char* EnumOptions::_InternalParse(const char* begin, const char* end, void parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -12855,11 +12636,8 @@ const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, // optional bool deprecated = 1 [default = false]; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_deprecated(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_deprecated(value); break; } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; @@ -12871,11 +12649,9 @@ const char* EnumValueOptions::_InternalParse(const char* begin, const char* end, parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -13255,11 +13031,8 @@ const char* ServiceOptions::_InternalParse(const char* begin, const char* end, v // optional bool deprecated = 33 [default = false]; case 33: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_deprecated(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_deprecated(value); break; } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; @@ -13271,11 +13044,9 @@ const char* ServiceOptions::_InternalParse(const char* begin, const char* end, v parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -13668,25 +13439,20 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo // optional bool deprecated = 33 [default = false]; case 33: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_deprecated(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_deprecated(value); break; } // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; case 34: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); - GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); if (!::google::protobuf::MethodOptions_IdempotencyLevel_IsValid(val)) { ::google::protobuf::internal::WriteVarint(34, val, msg->mutable_unknown_fields()); break; } - ::google::protobuf::MethodOptions_IdempotencyLevel value = static_cast<::google::protobuf::MethodOptions_IdempotencyLevel>(val); - msg->set_idempotency_level(value); + msg->set_idempotency_level(static_cast<::google::protobuf::MethodOptions_IdempotencyLevel>(val)); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); break; } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; @@ -13698,11 +13464,9 @@ const char* MethodOptions::_InternalParse(const char* begin, const char* end, vo parser_till_end = ::google::protobuf::UninterpretedOption::_InternalParse; object = msg->add_uninterpreted_option(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 65535) == 16058 && (ptr += 2)); break; @@ -14140,27 +13904,21 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* begin, cons ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.NamePart.name_part"); - auto str = msg->mutable_name_part(); + object = msg->mutable_name_part(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // required bool is_extension = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_is_extension(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_is_extension(value); break; } default: { @@ -14178,6 +13936,10 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* begin, cons } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -14601,11 +14363,9 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e parser_till_end = ::google::protobuf::UninterpretedOption_NamePart::_InternalParse; object = msg->add_name(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 18 && (ptr += 1)); break; @@ -14616,46 +14376,35 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.identifier_value"); - auto str = msg->mutable_identifier_value(); + object = msg->mutable_identifier_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // optional uint64 positive_int_value = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_positive_int_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::uint64 value = val; - msg->set_positive_int_value(value); break; } // optional int64 negative_int_value = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_negative_int_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int64 value = val; - msg->set_negative_int_value(value); break; } // optional double double_value = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 49) goto handle_unusual; - double val; - ::std::memcpy(&val, ptr, 8); - ptr += 8; - msg->set_double_value(val); + msg->set_double_value(::google::protobuf::io::UnalignedLoad(ptr)); + ptr += sizeof(double); break; } // optional bytes string_value = 7; @@ -14663,16 +14412,13 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e if (static_cast<::google::protobuf::uint8>(tag) != 58) goto handle_unusual; ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - auto str = msg->mutable_string_value(); + object = msg->mutable_string_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParser; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheck(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -14682,16 +14428,13 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.UninterpretedOption.aggregate_value"); - auto str = msg->mutable_aggregate_value(); + object = msg->mutable_aggregate_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -14710,6 +14453,10 @@ const char* UninterpretedOption::_InternalParse(const char* begin, const char* e } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -15287,11 +15034,8 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha break; } else if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; do { - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->add_path(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->add_path(value); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 8 && (ptr += 1)); break; @@ -15310,11 +15054,8 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha break; } else if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; do { - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->add_span(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->add_span(value); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 16 && (ptr += 1)); break; @@ -15325,16 +15066,13 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.leading_comments"); - auto str = msg->mutable_leading_comments(); + object = msg->mutable_leading_comments(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -15344,16 +15082,13 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.trailing_comments"); - auto str = msg->mutable_trailing_comments(); + object = msg->mutable_trailing_comments(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -15364,16 +15099,13 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceCodeInfo.Location.leading_detached_comments"); - auto str = msg->add_leading_detached_comments(); + object = msg->add_leading_detached_comments(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 50 && (ptr += 1)); @@ -15394,6 +15126,10 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* begin, const cha } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -15908,11 +15644,9 @@ const char* SourceCodeInfo::_InternalParse(const char* begin, const char* end, v parser_till_end = ::google::protobuf::SourceCodeInfo_Location::_InternalParse; object = msg->add_location(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 10 && (ptr += 1)); break; @@ -16262,11 +15996,8 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons break; } else if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; do { - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->add_path(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->add_path(value); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 8 && (ptr += 1)); break; @@ -16277,37 +16008,28 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.GeneratedCodeInfo.Annotation.source_file"); - auto str = msg->mutable_source_file(); + object = msg->mutable_source_file(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8Verify; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8Verify(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // optional int32 begin = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_begin(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_begin(value); break; } // optional int32 end = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_end(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_end(value); break; } default: { @@ -16325,6 +16047,10 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* begin, cons } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -16757,11 +16483,9 @@ const char* GeneratedCodeInfo::_InternalParse(const char* begin, const char* end parser_till_end = ::google::protobuf::GeneratedCodeInfo_Annotation::_InternalParse; object = msg->add_annotation(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 10 && (ptr += 1)); break; diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index d4a0cb1172..1e29f3c164 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -188,21 +188,15 @@ const char* Duration::_InternalParse(const char* begin, const char* end, void* o // int64 seconds = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_seconds(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int64 value = val; - msg->set_seconds(value); break; } // int32 nanos = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_nanos(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_nanos(value); break; } default: { diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index b865a50c66..e5a8fe6f59 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -186,16 +186,13 @@ const char* FieldMask::_InternalParse(const char* begin, const char* end, void* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.FieldMask.paths"); - auto str = msg->add_paths(); + object = msg->add_paths(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 10 && (ptr += 1)); @@ -216,6 +213,10 @@ const char* FieldMask::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 2e29fd3842..6230153a21 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -219,10 +219,10 @@ inline void OnShutdownDestroyString(const ::std::string* ptr) { } #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -inline void InlineGreedyStringParser(std::string* str, const char* begin, int size, - ParseContext*) { - str->assign(begin, size); +// To simplify generation of the parse loop code we take objects by void ptr. +inline void InlineGreedyStringParser(void* str, const char* begin, int size, + ParseContext*) { + static_cast(str)->assign(begin, size); } diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 8d80d19f17..d75095d9ff 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -183,6 +183,7 @@ const char* VarintParse(const char* p, T* out) { } extra += 128ull << (i * 7); } + *out = 0; return nullptr; } diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index a7126c1639..624f84d13f 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -559,6 +559,7 @@ class Map { iterator find(const Key& k) { return iterator(FindHelper(k).first); } const_iterator find(const Key& k) const { return find(k, NULL); } + bool contains(const Key& k) const { return find(k) != end(); } // In traditional C++ style, this performs "insert if not present." std::pair insert(const KeyValuePair& kv) { @@ -1079,6 +1080,7 @@ class Map { return const_iterator(iterator(elements_->find(key))); } iterator find(const key_type& key) { return iterator(elements_->find(key)); } + bool contains(const Key& key) const { return elements_->contains(key); } std::pair equal_range( const key_type& key) const { const_iterator it = find(key); diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index 06ebf5d3f8..1cb133829b 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -126,6 +126,7 @@ class MapImplTest : public ::testing::Test { // Test map size is correct. EXPECT_EQ(value, map_[key]); EXPECT_EQ(1, map_.count(key)); + EXPECT_TRUE(map_.contains(key)); // Check mutable at and find work correctly. EXPECT_EQ(value, map_.at(key)); @@ -248,6 +249,14 @@ TEST_F(MapImplTest, CountNonExist) { EXPECT_EQ(0, map_.count(0)); } +TEST_F(MapImplTest, ContainNotExist) { + EXPECT_FALSE(map_.contains(0)); +} + +TEST_F(MapImplTest, ImmutableContainNotExist) { + EXPECT_FALSE(const_map_.contains(0)); +} + TEST_F(MapImplTest, MutableFindNonExist) { EXPECT_TRUE(map_.end() == map_.find(0)); } diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 20195bdc0d..43e4144c97 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -137,7 +137,9 @@ struct ParseClosure { // (end <= retval < end + kSlopBytes). // All tag/value pairs between in [begin, retval) are parsed and retval // points to start of a tag. - const char* operator()(const char* ptr, const char* end, ParseContext* ctx) { + PROTOBUF_ALWAYS_INLINE // Don't pay for extra stack frame in debug mode + const char* + operator()(const char* ptr, const char* end, ParseContext* ctx) { GOOGLE_DCHECK(ptr < end); return func(ptr, end, object, ctx); } diff --git a/src/google/protobuf/reflection_ops.cc b/src/google/protobuf/reflection_ops.cc index 541fee943c..058f58f3ee 100644 --- a/src/google/protobuf/reflection_ops.cc +++ b/src/google/protobuf/reflection_ops.cc @@ -45,6 +45,7 @@ #include #include + namespace google { namespace protobuf { namespace internal { @@ -288,7 +289,7 @@ static string SubMessagePrefix(const string& prefix, } if (index != -1) { result.append("["); - result.append(SimpleItoa(index)); + result.append(StrCat(index)); result.append("]"); } result.append("."); diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index fa86c593b3..033e3436f7 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -49,6 +49,7 @@ #include #include #include + #include namespace google { @@ -1786,11 +1787,11 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, TestAllTypes goldenproto; for (int i = 0; i < 10; ++i) { string* new_data = new string; - *new_data = "name-" + SimpleItoa(i); + *new_data = "name-" + StrCat(i); data.push_back(new_data); new_data = goldenproto.add_repeated_string(); - *new_data = "name-" + SimpleItoa(i); + *new_data = "name-" + StrCat(i); } TestAllTypes testproto; std::copy(data.begin(), data.end(), AllocatedRepeatedPtrFieldBackInserter( @@ -1823,11 +1824,11 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, TestAllTypes goldenproto; for (int i = 0; i < 10; ++i) { string* new_data = new string; - *new_data = "name-" + SimpleItoa(i); + *new_data = "name-" + StrCat(i); data.push_back(new_data); new_data = goldenproto.add_repeated_string(); - *new_data = "name-" + SimpleItoa(i); + *new_data = "name-" + StrCat(i); } TestAllTypes testproto; std::copy(data.begin(), data.end(), diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index e779fc961a..89faa46613 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -176,16 +176,13 @@ const char* SourceContext::_InternalParse(const char* begin, const char* end, vo ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.SourceContext.file_name"); - auto str = msg->mutable_file_name(); + object = msg->mutable_file_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -204,6 +201,10 @@ const char* SourceContext::_InternalParse(const char* begin, const char* end, vo } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 9e1740c23a..c0fd3f3690 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -856,20 +856,16 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje // .google.protobuf.NullValue null_value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); + msg->set_null_value(static_cast<::google::protobuf::NullValue>(val)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::NullValue value = static_cast<::google::protobuf::NullValue>(val); - msg->set_null_value(value); break; } // double number_value = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 17) goto handle_unusual; - double val; - ::std::memcpy(&val, ptr, 8); - ptr += 8; - msg->set_number_value(val); + msg->set_number_value(::google::protobuf::io::UnalignedLoad(ptr)); + ptr += sizeof(double); break; } // string string_value = 3; @@ -878,27 +874,21 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Value.string_value"); - auto str = msg->mutable_string_value(); + object = msg->mutable_string_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // bool bool_value = 4; case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 32) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_bool_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_bool_value(value); break; } // .google.protobuf.Struct struct_value = 5; @@ -909,11 +899,9 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje parser_till_end = ::google::protobuf::Struct::_InternalParse; object = msg->mutable_struct_value(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // .google.protobuf.ListValue list_value = 6; @@ -924,11 +912,9 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje parser_till_end = ::google::protobuf::ListValue::_InternalParse; object = msg->mutable_list_value(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } default: { @@ -946,6 +932,10 @@ const char* Value::_InternalParse(const char* begin, const char* end, void* obje } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -1424,11 +1414,9 @@ const char* ListValue::_InternalParse(const char* begin, const char* end, void* parser_till_end = ::google::protobuf::Value::_InternalParse; object = msg->add_values(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 10 && (ptr += 1)); break; diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 50e2b1cb3c..e4b9b455e2 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -764,7 +764,7 @@ label_skip_parsing: LookingAtType(io::Tokenizer::TYPE_INTEGER)) { int64 int_value; DO(ConsumeSignedInteger(&int_value, kint32max)); - value = SimpleItoa(int_value); // for error reporting + value = StrCat(int_value); // for error reporting enum_value = enum_type->FindValueByNumber(int_value); } else { ReportError("Expected integer or identifier, got: " + @@ -1575,19 +1575,19 @@ void TextFormat::FastFieldValuePrinter::PrintBool( } void TextFormat::FastFieldValuePrinter::PrintInt32( int32 val, BaseTextGenerator* generator) const { - generator->PrintString(SimpleItoa(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintUInt32( uint32 val, BaseTextGenerator* generator) const { - generator->PrintString(SimpleItoa(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintInt64( int64 val, BaseTextGenerator* generator) const { - generator->PrintString(SimpleItoa(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintUInt64( uint64 val, BaseTextGenerator* generator) const { - generator->PrintString(SimpleItoa(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintFloat( float val, BaseTextGenerator* generator) const { @@ -2251,7 +2251,7 @@ void TextFormat::Printer::PrintFieldName(const Message& message, // if use_field_number_ is true, prints field number instead // of field name. if (use_field_number_) { - generator->PrintString(SimpleItoa(field->number())); + generator->PrintString(StrCat(field->number())); return; } @@ -2396,13 +2396,13 @@ void TextFormat::Printer::PrintUnknownFields( const UnknownFieldSet& unknown_fields, TextGenerator* generator) const { for (int i = 0; i < unknown_fields.field_count(); i++) { const UnknownField& field = unknown_fields.field(i); - string field_number = SimpleItoa(field.number()); + string field_number = StrCat(field.number()); switch (field.type()) { case UnknownField::TYPE_VARINT: generator->PrintString(field_number); generator->PrintLiteral(": "); - generator->PrintString(SimpleItoa(field.varint())); + generator->PrintString(StrCat(field.varint())); if (single_line_mode_) { generator->PrintLiteral(" "); } else { diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index d64cd2ebec..883875a79b 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -54,6 +54,7 @@ #include #include + #include #include #include @@ -1284,9 +1285,9 @@ class TextFormatParserTest : public testing::Test { parser.RecordErrorsTo(&error_collector); EXPECT_EQ(expected_result, parser.ParseFromString(input, proto)) << input << " -> " << proto->DebugString(); - EXPECT_EQ(SimpleItoa(line) + ":" + SimpleItoa(col) + - ": " + message + "\n", - error_collector.text_); + EXPECT_EQ( + StrCat(line) + ":" + StrCat(col) + ": " + message + "\n", + error_collector.text_); } void ExpectSuccessAndTree(const string& input, Message* proto, @@ -1509,7 +1510,7 @@ TEST_F(TextFormatParserTest, ParseFieldValueFromString) { // enum EXPECT_FIELD(nested_enum, unittest::TestAllTypes::BAR, "BAR"); EXPECT_FIELD(nested_enum, unittest::TestAllTypes::BAZ, - SimpleItoa(unittest::TestAllTypes::BAZ)); + StrCat(unittest::TestAllTypes::BAZ)); EXPECT_INVALID(nested_enum, "FOOBAR"); // message diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index acc7b9b8dd..6cc150baf9 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -188,21 +188,15 @@ const char* Timestamp::_InternalParse(const char* begin, const char* end, void* // int64 seconds = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_seconds(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int64 value = val; - msg->set_seconds(value); break; } // int32 nanos = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_nanos(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_nanos(value); break; } default: { diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index c187394719..bc31823a17 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -518,16 +518,13 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Type.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -540,11 +537,9 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec parser_till_end = ::google::protobuf::Field::_InternalParse; object = msg->add_fields(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 18 && (ptr += 1)); break; @@ -556,16 +551,13 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Type.oneofs"); - auto str = msg->add_oneofs(); + object = msg->add_oneofs(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 26 && (ptr += 1)); @@ -580,11 +572,9 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 34 && (ptr += 1)); break; @@ -597,21 +587,17 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // .google.protobuf.Syntax syntax = 6; case 6: { if (static_cast<::google::protobuf::uint8>(tag) != 48) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); + msg->set_syntax(static_cast<::google::protobuf::Syntax>(val)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); - msg->set_syntax(value); break; } default: { @@ -629,6 +615,10 @@ const char* Type::_InternalParse(const char* begin, const char* end, void* objec } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -1167,31 +1157,24 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje // .google.protobuf.Field.Kind kind = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); + msg->set_kind(static_cast<::google::protobuf::Field_Kind>(val)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::Field_Kind value = static_cast<::google::protobuf::Field_Kind>(val); - msg->set_kind(value); break; } // .google.protobuf.Field.Cardinality cardinality = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); + msg->set_cardinality(static_cast<::google::protobuf::Field_Cardinality>(val)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::Field_Cardinality value = static_cast<::google::protobuf::Field_Cardinality>(val); - msg->set_cardinality(value); break; } // int32 number = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_number(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_number(value); break; } // string name = 4; @@ -1200,16 +1183,13 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1219,37 +1199,28 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.type_url"); - auto str = msg->mutable_type_url(); + object = msg->mutable_type_url(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // int32 oneof_index = 7; case 7: { if (static_cast<::google::protobuf::uint8>(tag) != 56) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_oneof_index(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_oneof_index(value); break; } // bool packed = 8; case 8: { if (static_cast<::google::protobuf::uint8>(tag) != 64) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_packed(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_packed(value); break; } // repeated .google.protobuf.Option options = 9; @@ -1261,11 +1232,9 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 74 && (ptr += 1)); break; @@ -1276,16 +1245,13 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.json_name"); - auto str = msg->mutable_json_name(); + object = msg->mutable_json_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1295,16 +1261,13 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Field.default_value"); - auto str = msg->mutable_default_value(); + object = msg->mutable_default_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -1323,6 +1286,10 @@ const char* Field::_InternalParse(const char* begin, const char* end, void* obje } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -2028,16 +1995,13 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Enum.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -2050,11 +2014,9 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec parser_till_end = ::google::protobuf::EnumValue::_InternalParse; object = msg->add_enumvalue(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 18 && (ptr += 1)); break; @@ -2068,11 +2030,9 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 26 && (ptr += 1)); break; @@ -2085,21 +2045,17 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec parser_till_end = ::google::protobuf::SourceContext::_InternalParse; object = msg->mutable_source_context(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } // .google.protobuf.Syntax syntax = 5; case 5: { if (static_cast<::google::protobuf::uint8>(tag) != 40) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + ::google::protobuf::uint64 val = ::google::protobuf::internal::ReadVarint(&ptr); + msg->set_syntax(static_cast<::google::protobuf::Syntax>(val)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::Syntax value = static_cast<::google::protobuf::Syntax>(val); - msg->set_syntax(value); break; } default: { @@ -2117,6 +2073,10 @@ const char* Enum::_InternalParse(const char* begin, const char* end, void* objec } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -2575,27 +2535,21 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.EnumValue.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } // int32 number = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_number(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_number(value); break; } // repeated .google.protobuf.Option options = 3; @@ -2607,11 +2561,9 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* parser_till_end = ::google::protobuf::Option::_InternalParse; object = msg->add_options(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); if (ptr >= end) break; } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 26 && (ptr += 1)); break; @@ -2631,6 +2583,10 @@ const char* EnumValue::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -3041,16 +2997,13 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.Option.name"); - auto str = msg->mutable_name(); + object = msg->mutable_name(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -3062,11 +3015,9 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj parser_till_end = ::google::protobuf::Any::_InternalParse; object = msg->mutable_value(); if (size > end - ptr) goto len_delim_till_end; - auto newend = ptr + size; - bool ok = ctx->ParseExactRange({parser_till_end, object}, - ptr, newend); - GOOGLE_PROTOBUF_PARSER_ASSERT(ok); - ptr = newend; + ptr += size; + GOOGLE_PROTOBUF_PARSER_ASSERT(ctx->ParseExactRange( + {parser_till_end, object}, ptr - size, ptr)); break; } default: { @@ -3084,6 +3035,10 @@ const char* Option::_InternalParse(const char* begin, const char* end, void* obj } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index 40827cbc97..2ae447feef 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -34,6 +34,7 @@ #include #include #include + #include #include #include @@ -231,13 +232,13 @@ string DataPiece::ValueAsStringOrDefault( StringPiece default_string) const { switch (type_) { case TYPE_INT32: - return SimpleItoa(i32_); + return StrCat(i32_); case TYPE_INT64: - return SimpleItoa(i64_); + return StrCat(i64_); case TYPE_UINT32: - return SimpleItoa(u32_); + return StrCat(u32_); case TYPE_UINT64: - return SimpleItoa(u64_); + return StrCat(u64_); case TYPE_DOUBLE: return DoubleAsString(double_); case TYPE_FLOAT: diff --git a/src/google/protobuf/util/internal/json_objectwriter.cc b/src/google/protobuf/util/internal/json_objectwriter.cc index c2d3292eb1..74c9e74128 100644 --- a/src/google/protobuf/util/internal/json_objectwriter.cc +++ b/src/google/protobuf/util/internal/json_objectwriter.cc @@ -36,6 +36,7 @@ #include #include #include + #include #include #include @@ -89,19 +90,19 @@ JsonObjectWriter* JsonObjectWriter::RenderBool(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderInt32(StringPiece name, int32 value) { - return RenderSimple(name, SimpleItoa(value)); + return RenderSimple(name, StrCat(value)); } JsonObjectWriter* JsonObjectWriter::RenderUint32(StringPiece name, uint32 value) { - return RenderSimple(name, SimpleItoa(value)); + return RenderSimple(name, StrCat(value)); } JsonObjectWriter* JsonObjectWriter::RenderInt64(StringPiece name, int64 value) { WritePrefix(name); WriteChar('"'); - stream_->WriteString(SimpleItoa(value)); + stream_->WriteString(StrCat(value)); WriteChar('"'); return this; } @@ -110,7 +111,7 @@ JsonObjectWriter* JsonObjectWriter::RenderUint64(StringPiece name, uint64 value) { WritePrefix(name); WriteChar('"'); - stream_->WriteString(SimpleItoa(value)); + stream_->WriteString(StrCat(value)); WriteChar('"'); return this; } diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 2c1a739300..a37d0eb976 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -49,6 +49,7 @@ #include #include + #include #include @@ -943,61 +944,61 @@ const string ProtoStreamObjectSource::ReadFieldValueAsString( case google::protobuf::Field_Kind_TYPE_INT32: { uint32 buffer32; stream_->ReadVarint32(&buffer32); - result = SimpleItoa(::google::protobuf::bit_cast(buffer32)); + result = StrCat(::google::protobuf::bit_cast(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_INT64: { uint64 buffer64; stream_->ReadVarint64(&buffer64); - result = SimpleItoa(::google::protobuf::bit_cast(buffer64)); + result = StrCat(::google::protobuf::bit_cast(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_UINT32: { uint32 buffer32; stream_->ReadVarint32(&buffer32); - result = SimpleItoa(::google::protobuf::bit_cast(buffer32)); + result = StrCat(::google::protobuf::bit_cast(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_UINT64: { uint64 buffer64; stream_->ReadVarint64(&buffer64); - result = SimpleItoa(::google::protobuf::bit_cast(buffer64)); + result = StrCat(::google::protobuf::bit_cast(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_SINT32: { uint32 buffer32; stream_->ReadVarint32(&buffer32); - result = SimpleItoa(WireFormatLite::ZigZagDecode32(buffer32)); + result = StrCat(WireFormatLite::ZigZagDecode32(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_SINT64: { uint64 buffer64; stream_->ReadVarint64(&buffer64); - result = SimpleItoa(WireFormatLite::ZigZagDecode64(buffer64)); + result = StrCat(WireFormatLite::ZigZagDecode64(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_SFIXED32: { uint32 buffer32; stream_->ReadLittleEndian32(&buffer32); - result = SimpleItoa(::google::protobuf::bit_cast(buffer32)); + result = StrCat(::google::protobuf::bit_cast(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_SFIXED64: { uint64 buffer64; stream_->ReadLittleEndian64(&buffer64); - result = SimpleItoa(::google::protobuf::bit_cast(buffer64)); + result = StrCat(::google::protobuf::bit_cast(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_FIXED32: { uint32 buffer32; stream_->ReadLittleEndian32(&buffer32); - result = SimpleItoa(::google::protobuf::bit_cast(buffer32)); + result = StrCat(::google::protobuf::bit_cast(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_FIXED64: { uint64 buffer64; stream_->ReadLittleEndian64(&buffer64); - result = SimpleItoa(::google::protobuf::bit_cast(buffer64)); + result = StrCat(::google::protobuf::bit_cast(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_FLOAT: { diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc index 9f0e2089d6..65115133cf 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -44,6 +44,7 @@ #include #include + #include #include @@ -887,7 +888,7 @@ Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow, if (int_value.ok()) { ow->ProtoWriter::RenderDataPiece( "string_value", - DataPiece(SimpleItoa(int_value.ValueOrDie()), true)); + DataPiece(StrCat(int_value.ValueOrDie()), true)); return Status(); } } @@ -902,7 +903,7 @@ Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow, if (int_value.ok()) { ow->ProtoWriter::RenderDataPiece( "string_value", - DataPiece(SimpleItoa(int_value.ValueOrDie()), true)); + DataPiece(StrCat(int_value.ValueOrDie()), true)); return Status(); } } diff --git a/src/google/protobuf/util/internal/utility.h b/src/google/protobuf/util/internal/utility.h index 29935d6f70..8cd695f2ee 100644 --- a/src/google/protobuf/util/internal/utility.h +++ b/src/google/protobuf/util/internal/utility.h @@ -39,8 +39,9 @@ #include #include #include -#include #include +#include + #include #include @@ -187,7 +188,7 @@ PROTOBUF_EXPORT std::string FloatAsString(float value); // Convert from int32, int64, uint32, uint64, double or float to string. template std::string ValueAsString(T value) { - return SimpleItoa(value); + return StrCat(value); } template <> diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index d1183c0b9d..e2239fc490 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -1761,16 +1761,14 @@ void MessageDifferencer::StreamReporter::PrintPath( continue; } } else { - printer_->PrintRaw( - SimpleItoa(specific_field.unknown_field_number)); + printer_->PrintRaw(StrCat(specific_field.unknown_field_number)); } if (left_side && specific_field.index >= 0) { - printer_->Print("[$name$]", "name", - SimpleItoa(specific_field.index)); + printer_->Print("[$name$]", "name", StrCat(specific_field.index)); } if (!left_side && specific_field.new_index >= 0) { printer_->Print("[$name$]", "name", - SimpleItoa(specific_field.new_index)); + StrCat(specific_field.new_index)); } } } @@ -1825,7 +1823,7 @@ StreamReporter::PrintUnknownFieldValue(const UnknownField* unknown_field) { string output; switch (unknown_field->type()) { case UnknownField::TYPE_VARINT: - output = SimpleItoa(unknown_field->varint()); + output = StrCat(unknown_field->varint()); break; case UnknownField::TYPE_FIXED32: output = StrCat( diff --git a/src/google/protobuf/util/time_util.cc b/src/google/protobuf/util/time_util.cc index a7cba004e3..fbcc27fb6c 100644 --- a/src/google/protobuf/util/time_util.cc +++ b/src/google/protobuf/util/time_util.cc @@ -38,6 +38,7 @@ #include + #include namespace google { @@ -184,7 +185,7 @@ string TimeUtil::ToString(const Duration& duration) { seconds = -seconds; nanos = -nanos; } - result += SimpleItoa(seconds); + result += StrCat(seconds); if (nanos != 0) { result += "." + FormatNanos(nanos); } diff --git a/src/google/protobuf/util/type_resolver_util.cc b/src/google/protobuf/util/type_resolver_util.cc index 4d7a3c0753..a363e18e53 100644 --- a/src/google/protobuf/util/type_resolver_util.cc +++ b/src/google/protobuf/util/type_resolver_util.cc @@ -315,16 +315,16 @@ class DescriptorPoolTypeResolver : public TypeResolver { string DefaultValueAsString(const FieldDescriptor* descriptor) { switch (descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return SimpleItoa(descriptor->default_value_int32()); + return StrCat(descriptor->default_value_int32()); break; case FieldDescriptor::CPPTYPE_INT64: - return SimpleItoa(descriptor->default_value_int64()); + return StrCat(descriptor->default_value_int64()); break; case FieldDescriptor::CPPTYPE_UINT32: - return SimpleItoa(descriptor->default_value_uint32()); + return StrCat(descriptor->default_value_uint32()); break; case FieldDescriptor::CPPTYPE_UINT64: - return SimpleItoa(descriptor->default_value_uint64()); + return StrCat(descriptor->default_value_uint64()); break; case FieldDescriptor::CPPTYPE_FLOAT: return SimpleFtoa(descriptor->default_value_float()); diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index ed1410ebd3..0f1a03bc39 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -912,6 +912,29 @@ inline size_t ComputeUnknownMessageSetItemsSize(const std::string& unknown_field return unknown_fields.size(); } +// Some convenience functions to simplify the generated parse loop code. +// Returning the value and updating the buffer pointer allows for nicer +// function composition. We rely on the compiler to inline this. +// Also in debug compiles having local scoped variables tend to generated +// stack frames that scale as O(num fields). +inline uint64 ReadVarint(const char** p) { + uint64 tmp; + *p = io::Parse64(*p, &tmp); + return tmp; +} + +inline int64 ReadVarintZigZag64(const char** p) { + uint64 tmp; + *p = io::Parse64(*p, &tmp); + return WireFormatLite::ZigZagDecode64(tmp); +} + +inline int32 ReadVarintZigZag32(const char** p) { + uint64 tmp; + *p = io::Parse64(*p, &tmp); + return WireFormatLite::ZigZagDecode32(tmp); +} + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index 202c9f3ddc..12fd3179c7 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -402,10 +402,8 @@ const char* DoubleValue::_InternalParse(const char* begin, const char* end, void // double value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 9) goto handle_unusual; - double val; - ::std::memcpy(&val, ptr, 8); - ptr += 8; - msg->set_value(val); + msg->set_value(::google::protobuf::io::UnalignedLoad(ptr)); + ptr += sizeof(double); break; } default: { @@ -691,10 +689,8 @@ const char* FloatValue::_InternalParse(const char* begin, const char* end, void* // float value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 13) goto handle_unusual; - float val; - std::memcpy(&val, ptr, 4); - ptr += 4; - msg->set_value(val); + msg->set_value(::google::protobuf::io::UnalignedLoad(ptr)); + ptr += sizeof(float); break; } default: { @@ -980,11 +976,8 @@ const char* Int64Value::_InternalParse(const char* begin, const char* end, void* // int64 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int64 value = val; - msg->set_value(value); break; } default: { @@ -1272,11 +1265,8 @@ const char* UInt64Value::_InternalParse(const char* begin, const char* end, void // uint64 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::uint64 value = val; - msg->set_value(value); break; } default: { @@ -1564,11 +1554,8 @@ const char* Int32Value::_InternalParse(const char* begin, const char* end, void* // int32 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::int32 value = val; - msg->set_value(value); break; } default: { @@ -1856,11 +1843,8 @@ const char* UInt32Value::_InternalParse(const char* begin, const char* end, void // uint32 value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ::google::protobuf::uint32 value = val; - msg->set_value(value); break; } default: { @@ -2148,11 +2132,8 @@ const char* BoolValue::_InternalParse(const char* begin, const char* end, void* // bool value = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; - ::google::protobuf::uint64 val; - ptr = ::google::protobuf::io::Parse64(ptr, &val); + msg->set_value(::google::protobuf::internal::ReadVarint(&ptr)); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - bool value = val; - msg->set_value(value); break; } default: { @@ -2448,16 +2429,13 @@ const char* StringValue::_InternalParse(const char* begin, const char* end, void ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.StringValue.value"); - auto str = msg->mutable_value(); + object = msg->mutable_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParserUTF8; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheckUTF8(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -2476,6 +2454,10 @@ const char* StringValue::_InternalParse(const char* begin, const char* end, void } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -2772,16 +2754,13 @@ const char* BytesValue::_InternalParse(const char* begin, const char* end, void* if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; ptr = ::google::protobuf::io::ReadSize(ptr, &size); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - auto str = msg->mutable_value(); + object = msg->mutable_value(); if (size > end - ptr + ::google::protobuf::internal::ParseContext::kSlopBytes) { - object = str; - str->clear(); - str->reserve(size); parser_till_end = ::google::protobuf::internal::GreedyStringParser; - goto len_delim_till_end; + goto string_till_end; } GOOGLE_PROTOBUF_PARSER_ASSERT(::google::protobuf::internal::StringCheck(ptr, size, ctx)); - ::google::protobuf::internal::InlineGreedyStringParser(str, ptr, size, ctx); + ::google::protobuf::internal::InlineGreedyStringParser(object, ptr, size, ctx); ptr += size; break; } @@ -2800,6 +2779,10 @@ const char* BytesValue::_InternalParse(const char* begin, const char* end, void* } // switch } // while return ptr; +string_till_end: + static_cast<::std::string*>(object)->clear(); + static_cast<::std::string*>(object)->reserve(size); + goto len_delim_till_end; len_delim_till_end: return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); From 94a1819c7ae8509ab6ad37d867d3ea60a5809aaa Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Sun, 13 Jan 2019 18:25:16 -0800 Subject: [PATCH 57/70] Remove unused f expression from jscode gen. (#5573) Varadic assignment in javascript where the right hand expression is an object yields a single set assignment with the right most lefthand variable, while leaving the other left side expressions undefined. For example: var a,b = {} will only initialize a to undefined. But will set b to the {} value. -- For this code since f is never used, it is a safe operation to remove it. --- src/google/protobuf/compiler/js/js_generator.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index fd0367bc12..71e9ba8889 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2272,7 +2272,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options, " * @suppress {unusedLocalVariables} f is only used for nested messages\n" " */\n" "$classname$.toObject = function(includeInstance, msg) {\n" - " var f, obj = {", + " var obj = {", "classname", GetMessagePath(options, desc)); bool first = true; From 0c95791509ec0fe4e6973ccf885ad0055eb35b82 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 14 Jan 2019 10:28:21 -0500 Subject: [PATCH 58/70] [ObjC] add support for the TextFormat constants. ObjC doesn't support them, but this ensure when tests are added they will be handled correctly. The conformance.proto was updated in PR #5566 --- conformance/conformance_objc.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/conformance/conformance_objc.m b/conformance/conformance_objc.m index 42b17bce30..60b2ac59ed 100644 --- a/conformance/conformance_objc.m +++ b/conformance/conformance_objc.m @@ -98,6 +98,10 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { @"ConformanceRequest had a jspb_payload ConformanceRequest.payload;" " those aren't supposed to happen with opensource."; break; + + case ConformanceRequest_Payload_OneOfCase_TextPayload: + response.skipped = @"ObjC doesn't support parsing TextFormat"; + break; } if (testMessage) { @@ -124,6 +128,12 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { @"ConformanceRequest had a requested_output_format of JSPB WireFormat; that" " isn't supposed to happen with opensource."; break; + + case WireFormat_TextFormat: + // ObjC only has partial objc generation, so don't attempt any tests that need + // support. + response.skipped = @"ObjC doesn't support generating TextFormat"; + break; } } From dda7ab0363c4255aed5eae7aa84a4a7816f29bab Mon Sep 17 00:00:00 2001 From: toc007 Date: Tue, 15 Jan 2019 20:01:41 -0800 Subject: [PATCH 59/70] Ruby nested msg caps (#5564) * Ruby nested msg caps * nested types tests added * test cases added for RubifyConstant * extracted NestedMessage to TestNestedMessage * removed nested tests with leading underscore * extracted testLowercase to toplevel testLowercaseNested --- ruby/tests/generated_code.proto | 5 +++++ ruby/tests/generated_code_test.rb | 2 ++ src/google/protobuf/compiler/ruby/ruby_generator.cc | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ruby/tests/generated_code.proto b/ruby/tests/generated_code.proto index 3b934bd691..e8116697d7 100644 --- a/ruby/tests/generated_code.proto +++ b/ruby/tests/generated_code.proto @@ -69,6 +69,11 @@ enum TestEnum { C = 3; } +message testLowercaseNested { + message lowercase{} +} + + message TestUnknown { TestUnknown optional_unknown = 11; repeated TestUnknown repeated_unknown = 31; diff --git a/ruby/tests/generated_code_test.rb b/ruby/tests/generated_code_test.rb index 6e6f915ade..aed1cf8ebc 100644 --- a/ruby/tests/generated_code_test.rb +++ b/ruby/tests/generated_code_test.rb @@ -15,6 +15,8 @@ class GeneratedCodeTest < Test::Unit::TestCase # successfully creates message definitions and classes, not to test every # aspect of the extension (basic.rb is for that). A::B::C::TestMessage.new + A::B::C::TestMessage::NestedMessage.new + A::B::C::TestLowercaseNested::Lowercase.new FooBar::TestImportedMessage.new A::B::TestRubyPackageMessage.new end diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index 6b9ea82264..d6aa1f0081 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -389,7 +389,7 @@ void GenerateMessageAssignment( "lookup(\"$full_name$\").msgclass\n", "full_name", message->full_name()); - std::string nested_prefix = prefix + message->name() + "::"; + std::string nested_prefix = prefix + RubifyConstant(message->name()) + "::"; for (int i = 0; i < message->nested_type_count(); i++) { GenerateMessageAssignment(nested_prefix, message->nested_type(i), printer); } From 7181b1c090e6f1565f72a09dbc971382be72a410 Mon Sep 17 00:00:00 2001 From: i9 Date: Wed, 16 Jan 2019 19:47:12 -0800 Subject: [PATCH 60/70] Add proto3 to solidity link pb3-gen-sol is a proto3 to solidity library generator that supports proto3 native types and uses field option for solidity native types. Both the message and generated code are more efficient than other solutions. It also includes a library to decode protobuf wireformat. --- docs/third_party.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/third_party.md b/docs/third_party.md index a2bb0342be..94ce0ec066 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -89,6 +89,7 @@ These are projects we know about implementing Protocol Buffers for other program * Scala: http://code.google.com/p/protobuf-scala * Scala: https://github.com/SandroGrzicic/ScalaBuff * Scala: https://scalapb.github.io +* Solidity: https://github.com/celer-network/pb3-gen-sol * Swift: https://github.com/alexeyxo/protobuf-swift * Swift: https://github.com/apple/swift-protobuf/ * Vala: https://launchpad.net/protobuf-vala From c4f2a92c5566b6d8781d88ea031e0f9715206bac Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 17 Jan 2019 10:18:43 -0800 Subject: [PATCH 61/70] Fix field mask for php in json (#5591) * Fix field mask for php in json * Update byte size --- conformance/failure_list_php_c.txt | 11 +- php/ext/google/protobuf/encode_decode.c | 201 +-- php/ext/google/protobuf/upb.c | 1601 +++++++++++++++++------ php/ext/google/protobuf/upb.h | 1 + php/tests/encode_decode_test.php | 58 + php/tests/generated_class_test.php | 6 +- php/tests/php_implementation_test.php | 2 +- php/tests/test_base.php | 12 +- php/tests/test_util.php | 24 +- 9 files changed, 1424 insertions(+), 492 deletions(-) diff --git a/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index dd69f5eafb..28ba83b011 100644 --- a/conformance/failure_list_php_c.txt +++ b/conformance/failure_list_php_c.txt @@ -5,6 +5,7 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator +Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.OneofZeroBytes.JsonOutput @@ -22,8 +23,6 @@ Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput Required.TimestampProtoInputTooLarge.JsonOutput Required.TimestampProtoInputTooSmall.JsonOutput -Required.Proto3.JsonInput.AnyWithFieldMask.JsonOutput -Required.Proto3.JsonInput.AnyWithFieldMask.ProtobufOutput Required.Proto3.JsonInput.BoolMapField.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput @@ -32,22 +31,14 @@ Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput Required.Proto3.JsonInput.DurationMinValue.JsonOutput Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput -Required.Proto3.JsonInput.FieldMask.JsonOutput -Required.Proto3.JsonInput.FieldMask.ProtobufOutput Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput Required.Proto3.JsonInput.FloatFieldNan.JsonOutput Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput Required.Proto3.JsonInput.OneofFieldDuplicate Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput -Required.Proto3.JsonInput.StringFieldEscape.JsonOutput -Required.Proto3.JsonInput.StringFieldEscape.ProtobufOutput Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput -Required.Proto3.JsonInput.StringFieldUnicodeEscape.JsonOutput -Required.Proto3.JsonInput.StringFieldUnicodeEscape.ProtobufOutput -Required.Proto3.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.JsonOutput -Required.Proto3.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.ProtobufOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 3d2bb7c203..801b44d53c 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -148,6 +148,11 @@ static const void* newhandlerdata(upb_handlers* h, uint32_t ofs) { return hd_ofs; } +typedef struct { + void* closure; + stringsink sink; +} stringfields_parseframe_t; + typedef size_t (*encodeunknown_handlerfunc)(void* _sink, const void* hd, const char* ptr, size_t len, const upb_bufhandle* handle); @@ -245,46 +250,41 @@ DEFINE_APPEND_HANDLER(int64, int64_t) DEFINE_APPEND_HANDLER(uint64, uint64_t) DEFINE_APPEND_HANDLER(double, double) -// Appends a string to a repeated field. +// Appends a string or 'bytes' string to a repeated field. static void* appendstr_handler(void *closure, const void *hd, size_t size_hint) { - zval* array = (zval*)closure; - TSRMLS_FETCH(); - RepeatedField* intern = UNBOX(RepeatedField, array); + UPB_UNUSED(hd); -#if PHP_MAJOR_VERSION < 7 - zval* str; - MAKE_STD_ZVAL(str); - PHP_PROTO_ZVAL_STRING(str, "", 1); - repeated_field_push_native(intern, &str); - return (void*)str; -#else - zend_string* str = zend_string_init("", 0, 1); - repeated_field_push_native(intern, &str); - return intern; -#endif + stringfields_parseframe_t* frame = + (stringfields_parseframe_t*)malloc(sizeof(stringfields_parseframe_t)); + frame->closure = closure; + stringsink_init(&frame->sink); + + return frame; } -// Appends a 'bytes' string to a repeated field. -static void* appendbytes_handler(void *closure, - const void *hd, - size_t size_hint) { - zval* array = (zval*)closure; +static bool appendstr_end_handler(void *closure, const void *hd) { + stringfields_parseframe_t* frame = closure; + + zval* array = (zval*)frame->closure; TSRMLS_FETCH(); RepeatedField* intern = UNBOX(RepeatedField, array); #if PHP_MAJOR_VERSION < 7 zval* str; MAKE_STD_ZVAL(str); - PHP_PROTO_ZVAL_STRING(str, "", 1); + PHP_PROTO_ZVAL_STRINGL(str, frame->sink.ptr, frame->sink.len, 1); repeated_field_push_native(intern, &str); - return (void*)str; #else - zend_string* str = zend_string_init("", 0, 1); + zend_string* str = zend_string_init(frame->sink.ptr, frame->sink.len, 1); repeated_field_push_native(intern, &str); - return intern; #endif + + stringsink_uninit(&frame->sink); + free(frame); + + return true; } // Handlers that append primitive values to a repeated field. @@ -326,64 +326,76 @@ static void *empty_php_string(zval* value_ptr) { return value_ptr; } #endif +#if PHP_MAJOR_VERSION < 7 +static void *empty_php_string2(zval** value_ptr) { + SEPARATE_ZVAL_IF_NOT_REF(value_ptr); + if (Z_TYPE_PP(value_ptr) == IS_STRING && + !IS_INTERNED(Z_STRVAL_PP(value_ptr))) { + FREE(Z_STRVAL_PP(value_ptr)); + } + ZVAL_EMPTY_STRING(*value_ptr); + return (void*)(*value_ptr); +} +static void new_php_string(zval** value_ptr, const char* str, size_t len) { + SEPARATE_ZVAL_IF_NOT_REF(value_ptr); + if (Z_TYPE_PP(value_ptr) == IS_STRING && + !IS_INTERNED(Z_STRVAL_PP(value_ptr))) { + FREE(Z_STRVAL_PP(value_ptr)); + } + ZVAL_EMPTY_STRING(*value_ptr); + ZVAL_STRINGL(*value_ptr, str, len, 1); +} +#else +static void *empty_php_string2(zval* value_ptr) { + if (Z_TYPE_P(value_ptr) == IS_STRING) { + zend_string_release(Z_STR_P(value_ptr)); + } + ZVAL_EMPTY_STRING(value_ptr); + return value_ptr; +} +static void new_php_string(zval* value_ptr, const char* str, size_t len) { + if (Z_TYPE_P(value_ptr) == IS_STRING) { + zend_string_release(Z_STR_P(value_ptr)); + } + ZVAL_NEW_STR(value_ptr, zend_string_init(str, len, 0)); +} +#endif -// Sets a non-repeated string field in a message. +// Sets a non-repeated string/bytes field in a message. static void* str_handler(void *closure, const void *hd, size_t size_hint) { - MessageHeader* msg = closure; - const size_t *ofs = hd; - return empty_php_string(DEREF(message_data(msg), *ofs, CACHED_VALUE*)); + UPB_UNUSED(hd); + + stringfields_parseframe_t* frame = + (stringfields_parseframe_t*)malloc(sizeof(stringfields_parseframe_t)); + frame->closure = closure; + stringsink_init(&frame->sink); + + return frame; } -// Sets a non-repeated 'bytes' field in a message. -static void* bytes_handler(void *closure, - const void *hd, - size_t size_hint) { - MessageHeader* msg = closure; +static bool str_end_handler(void *closure, const void *hd) { + stringfields_parseframe_t* frame = closure; const size_t *ofs = hd; - return empty_php_string(DEREF(message_data(msg), *ofs, CACHED_VALUE*)); + MessageHeader* msg = (MessageHeader*)frame->closure; + + new_php_string(DEREF(message_data(msg), *ofs, CACHED_VALUE*), + frame->sink.ptr, frame->sink.len); + + stringsink_uninit(&frame->sink); + free(frame); + + return true; } static size_t stringdata_handler(void* closure, const void* hd, const char* str, size_t len, const upb_bufhandle* handle) { - zval* php_str = (zval*)closure; -#if PHP_MAJOR_VERSION < 7 - // Oneof string/bytes fields may have NULL initial value, which doesn't need - // to be freed. - if (Z_TYPE_P(php_str) == IS_STRING && !IS_INTERNED(Z_STRVAL_P(php_str))) { - FREE(Z_STRVAL_P(php_str)); - } - ZVAL_STRINGL(php_str, str, len, 1); -#else - if (Z_TYPE_P(php_str) == IS_STRING) { - zend_string_release(Z_STR_P(php_str)); - } - ZVAL_NEW_STR(php_str, zend_string_init(str, len, 0)); -#endif - return len; + stringfields_parseframe_t* frame = closure; + return stringsink_string(&frame->sink, hd, str, len, handle); } -#if PHP_MAJOR_VERSION >= 7 -static size_t zendstringdata_handler(void* closure, const void* hd, - const char* str, size_t len, - const upb_bufhandle* handle) { - RepeatedField* intern = (RepeatedField*)closure; - - unsigned char memory[NATIVE_SLOT_MAX_SIZE]; - memset(memory, 0, NATIVE_SLOT_MAX_SIZE); - *(zend_string**)memory = zend_string_init(str, len, 0); - - HashTable *ht = PHP_PROTO_HASH_OF(intern->array); - int index = zend_hash_num_elements(ht) - 1; - php_proto_zend_hash_index_update_mem( - ht, index, memory, sizeof(zend_string*), NULL); - - return len; -} -#endif - // Appends a submessage to a repeated field. static void *appendsubmsg_handler(void *closure, const void *hd) { zval* array = (zval*)closure; @@ -744,13 +756,38 @@ static void *oneofbytes_handler(void *closure, return empty_php_string(DEREF( message_data(msg), oneofdata->ofs, CACHED_VALUE*)); } +static bool oneofstr_end_handler(void *closure, const void *hd) { + stringfields_parseframe_t* frame = closure; + MessageHeader* msg = (MessageHeader*)frame->closure; + const oneof_handlerdata_t *oneofdata = hd; + + oneof_cleanup(msg, oneofdata); + + DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) = + oneofdata->oneof_case_num; + DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) = + OBJ_PROP(&msg->std, oneofdata->property_ofs); + + new_php_string(DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*), + frame->sink.ptr, frame->sink.len); + + stringsink_uninit(&frame->sink); + free(frame); + + return true; +} static void *oneofstr_handler(void *closure, const void *hd, size_t size_hint) { - // TODO(teboring): Add it back. - // rb_enc_associate(str, kRubyString8bitEncoding); - return oneofbytes_handler(closure, hd, size_hint); + UPB_UNUSED(hd); + + stringfields_parseframe_t* frame = + (stringfields_parseframe_t*)malloc(sizeof(stringfields_parseframe_t)); + frame->closure = closure; + stringsink_init(&frame->sink); + + return frame; } // Handler for a submessage field in a oneof. @@ -822,15 +859,9 @@ static void add_handlers_for_repeated_field(upb_handlers *h, case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { - bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES; - upb_handlers_setstartstr(h, f, is_bytes ? - appendbytes_handler : appendstr_handler, - NULL); -#if PHP_MAJOR_VERSION < 7 + upb_handlers_setstartstr(h, f, appendstr_handler, NULL); upb_handlers_setstring(h, f, stringdata_handler, NULL); -#else - upb_handlers_setstring(h, f, zendstringdata_handler, NULL); -#endif + upb_handlers_setendstr(h, f, appendstr_end_handler, &attr); break; } case UPB_TYPE_MESSAGE: { @@ -870,13 +901,11 @@ static void add_handlers_for_singular_field(upb_handlers *h, case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { - bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES; upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; upb_handlerattr_sethandlerdata(&attr, newhandlerdata(h, offset)); - upb_handlers_setstartstr(h, f, - is_bytes ? bytes_handler : str_handler, - &attr); + upb_handlers_setstartstr(h, f, str_handler, &attr); upb_handlers_setstring(h, f, stringdata_handler, &attr); + upb_handlers_setendstr(h, f, str_end_handler, &attr); upb_handlerattr_uninit(&attr); break; } @@ -958,11 +987,9 @@ static void add_handlers_for_oneof_field(upb_handlers *h, case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { - bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES; - upb_handlers_setstartstr(h, f, is_bytes ? - oneofbytes_handler : oneofstr_handler, - &attr); + upb_handlers_setstartstr(h, f, oneofstr_handler, &attr); upb_handlers_setstring(h, f, stringdata_handler, NULL); + upb_handlers_setendstr(h, f, oneofstr_end_handler, &attr); break; } case UPB_TYPE_MESSAGE: { diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c index 6b576d8566..a2634ce493 100644 --- a/php/ext/google/protobuf/upb.c +++ b/php/ext/google/protobuf/upb.c @@ -1460,6 +1460,8 @@ static void assign_msg_wellknowntype(upb_msgdef *m) { } if (!strcmp(name, "google.protobuf.Any")) { m->well_known_type = UPB_WELLKNOWN_ANY; + } else if (!strcmp(name, "google.protobuf.FieldMask")) { + m->well_known_type = UPB_WELLKNOWN_FIELDMASK; } else if (!strcmp(name, "google.protobuf.Duration")) { m->well_known_type = UPB_WELLKNOWN_DURATION; } else if (!strcmp(name, "google.protobuf.Timestamp")) { @@ -5461,6 +5463,29 @@ const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, return l; } } + +#if UINTPTR_MAX == 0xffffffff +#define UPB_SIZE(size32, size64) size32 +#else +#define UPB_SIZE(size32, size64) size64 +#endif + +#define UPB_FIELD_AT(msg, fieldtype, offset) \ + *(fieldtype*)((const char*)(msg) + offset) + +#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) \ + : 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; + +#undef UPB_SIZE +#undef UPB_FIELD_AT +#undef UPB_READ_ONEOF +#undef UPB_WRITE_ONEOF /* ** upb::RefCounted Implementation ** @@ -10119,8 +10144,8 @@ static void generate_delimfield(compiler *c, const upb_fielddef *f, putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR)); /* Need to emit even if no handler to skip past the string. */ putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING)); - putop(c, OP_POP); maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR); + putop(c, OP_POP); putop(c, OP_SETDELIM); putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK); putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_LOOPBREAK); @@ -10135,8 +10160,8 @@ static void generate_delimfield(compiler *c, const upb_fielddef *f, putop(c, OP_PUSHLENDELIM); putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR)); putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING)); - putop(c, OP_POP); maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR); + putop(c, OP_POP); putop(c, OP_SETDELIM); } } @@ -12618,6 +12643,12 @@ static bool is_string_wrapper_object(upb_json_parser *p); static bool does_string_wrapper_start(upb_json_parser *p); static bool does_string_wrapper_end(upb_json_parser *p); +static bool is_fieldmask_object(upb_json_parser *p); +static bool does_fieldmask_start(upb_json_parser *p); +static bool does_fieldmask_end(upb_json_parser *p); +static void start_fieldmask_object(upb_json_parser *p); +static void end_fieldmask_object(upb_json_parser *p); + static void start_wrapper_object(upb_json_parser *p); static void end_wrapper_object(upb_json_parser *p); @@ -13719,6 +13750,9 @@ static bool start_stringval(upb_json_parser *p) { if (is_top_level(p)) { if (is_string_wrapper_object(p)) { start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_FIELDMASK)) { + start_fieldmask_object(p); + return true; } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { start_object(p); @@ -13732,6 +13766,12 @@ static bool start_stringval(upb_json_parser *p) { return false; } start_wrapper_object(p); + } else if (does_fieldmask_start(p)) { + if (!start_subobject(p)) { + return false; + } + start_fieldmask_object(p); + return true; } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) || is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) { if (!start_subobject(p)) { @@ -13875,8 +13915,8 @@ static bool end_stringval_nontop(upb_json_parser *p) { case UPB_TYPE_STRING: { upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); - p->top--; upb_sink_endstr(&p->top->sink, sel); + p->top--; break; } @@ -13925,6 +13965,16 @@ static bool end_stringval_nontop(upb_json_parser *p) { } static bool end_stringval(upb_json_parser *p) { + /* FieldMask's stringvals have been ended when handling them. Only need to + * close FieldMask here.*/ + if (does_fieldmask_end(p)) { + end_fieldmask_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + if (!end_stringval_nontop(p)) { return false; } @@ -13946,7 +13996,8 @@ static bool end_stringval(upb_json_parser *p) { } if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || - is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION) || + is_wellknown_msg(p, UPB_WELLKNOWN_FIELDMASK)) { end_object(p); if (!is_top_level(p)) { end_subobject(p); @@ -14209,6 +14260,75 @@ static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) { return true; } +static void start_fieldmask_path_text(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +static bool end_fieldmask_path_text(upb_json_parser *p, const char *ptr) { + if (!capture_end(p, ptr)) { + return false; + } +} + +static bool start_fieldmask_path(upb_json_parser *p) { + upb_jsonparser_frame *inner; + upb_selector_t sel; + + if (!check_stack(p)) return false; + + /* Start a new parser frame: parser frames correspond one-to-one with + * handler frames, and string events occur in a sub-frame. */ + inner = p->top + 1; + sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); + upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); + inner->m = p->top->m; + inner->f = p->top->f; + inner->name_table = NULL; + inner->is_map = false; + inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; + inner->is_unknown_field = false; + p->top = inner; + + multipart_startaccum(p); + return true; +} + +static bool lower_camel_push( + upb_json_parser *p, upb_selector_t sel, const char *ptr, size_t len) { + const char *limit = ptr + len; + bool first = true; + for (;ptr < limit; ptr++) { + if (*ptr >= 'A' && *ptr <= 'Z' && !first) { + char lower = tolower(*ptr); + upb_sink_putstring(&p->top->sink, sel, "_", 1, NULL); + upb_sink_putstring(&p->top->sink, sel, &lower, 1, NULL); + } else { + upb_sink_putstring(&p->top->sink, sel, ptr, 1, NULL); + } + first = false; + } + return true; +} + +static bool end_fieldmask_path(upb_json_parser *p) { + upb_selector_t sel; + + if (!lower_camel_push( + p, getsel_for_handlertype(p, UPB_HANDLER_STRING), + p->accumulated, p->accumulated_len)) { + return false; + } + + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + upb_sink_endstr(&p->top->sink, sel); + p->top--; + + multipart_end(p); + return true; +} + static void start_member(upb_json_parser *p) { UPB_ASSERT(!p->top->f); multipart_startaccum(p); @@ -14268,7 +14388,7 @@ static bool parse_mapentry_key(upb_json_parser *p) { sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); upb_sink_putstring(&subsink, sel, buf, len, NULL); sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); - upb_sink_endstr(&p->top->sink, sel); + upb_sink_endstr(&subsink, sel); multipart_end(p); break; } @@ -14810,6 +14930,31 @@ static bool is_string_wrapper(const upb_msgdef *m) { type == UPB_WELLKNOWN_BYTESVALUE; } +static bool is_fieldmask(const upb_msgdef *m) { + upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); + return type == UPB_WELLKNOWN_FIELDMASK; +} + +static void start_fieldmask_object(upb_json_parser *p) { + const char *membername = "paths"; + + start_object(p); + + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + 5); + end_membername(p); + + start_array(p); +} + +static void end_fieldmask_object(upb_json_parser *p) { + end_array(p); + end_member(p); + end_object(p); +} + static void start_wrapper_object(upb_json_parser *p) { const char *membername = "value"; @@ -14948,6 +15093,20 @@ static bool is_string_wrapper_object(upb_json_parser *p) { return p->top->m != NULL && is_string_wrapper(p->top->m); } +static bool does_fieldmask_start(upb_json_parser *p) { + return p->top->f != NULL && + upb_fielddef_issubmsg(p->top->f) && + is_fieldmask(upb_fielddef_msgsubdef(p->top->f)); +} + +static bool does_fieldmask_end(upb_json_parser *p) { + return p->top->m != NULL && is_fieldmask(p->top->m); +} + +static bool is_fieldmask_object(upb_json_parser *p) { + return p->top->m != NULL && is_fieldmask(p->top->m); +} + #define CHECK_RETURN_TOP(x) if (!(x)) goto error @@ -14969,227 +15128,27 @@ static bool is_string_wrapper_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -#line 2576 "upb/json/parser.rl" +#line 2730 "upb/json/parser.rl" -#line 2422 "upb/json/parser.c" +#line 2556 "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, 9, 1, 10, 1, 11, 1, 12, 1, - 13, 1, 21, 1, 23, 1, 24, 1, - 26, 1, 27, 1, 28, 1, 30, 1, - 32, 1, 33, 1, 34, 1, 35, 1, - 37, 1, 38, 2, 4, 9, 2, 5, - 6, 2, 7, 3, 2, 7, 9, 2, - 14, 15, 2, 16, 17, 2, 18, 19, - 2, 22, 20, 2, 24, 26, 2, 29, - 2, 2, 30, 38, 2, 31, 20, 2, - 33, 38, 2, 34, 38, 2, 35, 38, - 2, 36, 25, 2, 37, 38, 4, 14, - 15, 16, 17 -}; - -static const short _json_key_offsets[] = { - 0, 0, 12, 13, 18, 23, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, - 38, 43, 44, 48, 53, 58, 63, 67, - 71, 74, 77, 79, 83, 87, 89, 91, - 96, 98, 100, 109, 115, 121, 127, 133, - 135, 139, 142, 144, 146, 149, 150, 154, - 156, 158, 160, 162, 163, 165, 167, 168, - 170, 172, 173, 175, 177, 178, 180, 182, - 183, 185, 187, 191, 193, 195, 196, 197, - 198, 199, 201, 206, 215, 216, 216, 216, - 221, 226, 231, 232, 233, 234, 235, 235, - 236, 237, 238, 238, 239, 240, 241, 241, - 246, 247, 251, 256, 261, 266, 270, 270, - 273, 276, 279, 282, 285, 288, 288, 288, - 288, 288 -}; - -static const char _json_trans_keys[] = { - 32, 34, 45, 91, 102, 110, 116, 123, - 9, 13, 48, 57, 34, 32, 93, 125, - 9, 13, 32, 44, 93, 9, 13, 32, - 93, 125, 9, 13, 97, 108, 115, 101, - 117, 108, 108, 114, 117, 101, 32, 34, - 125, 9, 13, 34, 32, 58, 9, 13, - 32, 93, 125, 9, 13, 32, 44, 125, - 9, 13, 32, 44, 125, 9, 13, 32, - 34, 9, 13, 45, 48, 49, 57, 48, - 49, 57, 46, 69, 101, 48, 57, 69, - 101, 48, 57, 43, 45, 48, 57, 48, - 57, 48, 57, 46, 69, 101, 48, 57, - 34, 92, 34, 92, 34, 47, 92, 98, - 102, 110, 114, 116, 117, 48, 57, 65, - 70, 97, 102, 48, 57, 65, 70, 97, - 102, 48, 57, 65, 70, 97, 102, 48, - 57, 65, 70, 97, 102, 34, 92, 45, - 48, 49, 57, 48, 49, 57, 46, 115, - 48, 57, 115, 48, 57, 34, 46, 115, - 48, 57, 48, 57, 48, 57, 48, 57, - 48, 57, 45, 48, 57, 48, 57, 45, - 48, 57, 48, 57, 84, 48, 57, 48, - 57, 58, 48, 57, 48, 57, 58, 48, - 57, 48, 57, 43, 45, 46, 90, 48, - 57, 48, 57, 58, 48, 48, 34, 48, - 57, 43, 45, 90, 48, 57, 34, 45, - 91, 102, 110, 116, 123, 48, 57, 34, - 32, 93, 125, 9, 13, 32, 44, 93, - 9, 13, 32, 93, 125, 9, 13, 97, - 108, 115, 101, 117, 108, 108, 114, 117, - 101, 32, 34, 125, 9, 13, 34, 32, - 58, 9, 13, 32, 93, 125, 9, 13, - 32, 44, 125, 9, 13, 32, 44, 125, - 9, 13, 32, 34, 9, 13, 32, 9, - 13, 32, 9, 13, 32, 9, 13, 32, - 9, 13, 32, 9, 13, 32, 9, 13, - 0 -}; - -static const char _json_single_lengths[] = { - 0, 8, 1, 3, 3, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 3, 1, 2, 3, 3, 3, 2, 2, - 1, 3, 0, 2, 2, 0, 0, 3, - 2, 2, 9, 0, 0, 0, 0, 2, - 2, 1, 2, 0, 1, 1, 2, 0, - 0, 0, 0, 1, 0, 0, 1, 0, - 0, 1, 0, 0, 1, 0, 0, 1, - 0, 0, 4, 0, 0, 1, 1, 1, - 1, 0, 3, 7, 1, 0, 0, 3, - 3, 3, 1, 1, 1, 1, 0, 1, - 1, 1, 0, 1, 1, 1, 0, 3, - 1, 2, 3, 3, 3, 2, 0, 1, - 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0 -}; - -static const char _json_range_lengths[] = { - 0, 2, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 1, 1, 1, 1, 1, 1, - 1, 0, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 3, 3, 3, 3, 0, - 1, 1, 0, 1, 1, 0, 1, 1, - 1, 1, 1, 0, 1, 1, 0, 1, - 1, 0, 1, 1, 0, 1, 1, 0, - 1, 1, 0, 1, 1, 0, 0, 0, - 0, 1, 1, 1, 0, 0, 0, 1, - 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 1, 1, 1, 1, 1, 0, 1, - 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0 -}; - -static const short _json_index_offsets[] = { - 0, 0, 11, 13, 18, 23, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, - 48, 53, 55, 59, 64, 69, 74, 78, - 82, 85, 89, 91, 95, 99, 101, 103, - 108, 111, 114, 124, 128, 132, 136, 140, - 143, 147, 150, 153, 155, 158, 160, 164, - 166, 168, 170, 172, 174, 176, 178, 180, - 182, 184, 186, 188, 190, 192, 194, 196, - 198, 200, 202, 207, 209, 211, 213, 215, - 217, 219, 221, 226, 235, 237, 238, 239, - 244, 249, 254, 256, 258, 260, 262, 263, - 265, 267, 269, 270, 272, 274, 276, 277, - 282, 284, 288, 293, 298, 303, 307, 308, - 311, 314, 317, 320, 323, 326, 327, 328, - 329, 330 -}; - -static const unsigned char _json_indicies[] = { - 0, 2, 3, 4, 5, 6, 7, 8, - 0, 3, 1, 9, 1, 11, 12, 1, - 11, 10, 13, 14, 12, 13, 1, 14, - 1, 1, 14, 10, 15, 1, 16, 1, - 17, 1, 18, 1, 19, 1, 20, 1, - 21, 1, 22, 1, 23, 1, 24, 1, - 25, 26, 27, 25, 1, 28, 1, 29, - 30, 29, 1, 30, 1, 1, 30, 31, - 32, 33, 34, 32, 1, 35, 36, 27, - 35, 1, 36, 26, 36, 1, 37, 38, - 39, 1, 38, 39, 1, 41, 42, 42, - 40, 43, 1, 42, 42, 43, 40, 44, - 44, 45, 1, 45, 1, 45, 40, 41, - 42, 42, 39, 40, 47, 48, 46, 50, - 51, 49, 52, 52, 52, 52, 52, 52, - 52, 52, 53, 1, 54, 54, 54, 1, - 55, 55, 55, 1, 56, 56, 56, 1, - 57, 57, 57, 1, 59, 60, 58, 61, - 62, 63, 1, 64, 65, 1, 66, 67, - 1, 68, 1, 67, 68, 1, 69, 1, - 66, 67, 65, 1, 70, 1, 71, 1, - 72, 1, 73, 1, 74, 1, 75, 1, - 76, 1, 77, 1, 78, 1, 79, 1, - 80, 1, 81, 1, 82, 1, 83, 1, - 84, 1, 85, 1, 86, 1, 87, 1, - 88, 1, 89, 89, 90, 91, 1, 92, - 1, 93, 1, 94, 1, 95, 1, 96, - 1, 97, 1, 98, 1, 99, 99, 100, - 98, 1, 101, 102, 103, 104, 105, 106, - 107, 102, 1, 108, 1, 109, 110, 112, - 113, 1, 112, 111, 114, 115, 113, 114, - 1, 115, 1, 1, 115, 111, 116, 1, - 117, 1, 118, 1, 119, 1, 120, 121, - 1, 122, 1, 123, 1, 124, 125, 1, - 126, 1, 127, 1, 128, 129, 130, 131, - 129, 1, 132, 1, 133, 134, 133, 1, - 134, 1, 1, 134, 135, 136, 137, 138, - 136, 1, 139, 140, 131, 139, 1, 140, - 130, 140, 1, 141, 142, 142, 1, 143, - 143, 1, 144, 144, 1, 145, 145, 1, - 146, 146, 1, 147, 147, 1, 1, 1, - 1, 1, 1, 0 -}; - -static const char _json_trans_targs[] = { - 1, 0, 2, 104, 3, 6, 10, 13, - 16, 103, 4, 3, 103, 4, 5, 7, - 8, 9, 105, 11, 12, 106, 14, 15, - 107, 16, 17, 108, 18, 18, 19, 20, - 21, 22, 108, 21, 22, 24, 25, 31, - 109, 26, 28, 27, 29, 30, 33, 110, - 34, 33, 110, 34, 32, 35, 36, 37, - 38, 39, 33, 110, 34, 41, 42, 46, - 42, 46, 43, 45, 44, 111, 48, 49, - 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, - 66, 67, 73, 72, 68, 69, 70, 71, - 72, 112, 74, 67, 72, 76, 78, 79, - 82, 87, 91, 95, 77, 113, 113, 80, - 79, 77, 80, 81, 83, 84, 85, 86, - 113, 88, 89, 90, 113, 92, 93, 94, - 113, 95, 96, 102, 97, 97, 98, 99, - 100, 101, 102, 100, 101, 113, 103, 103, - 103, 103, 103, 103 -}; - -static const char _json_trans_actions[] = { - 0, 0, 84, 78, 33, 0, 0, 0, - 96, 39, 25, 0, 35, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 72, 31, 27, 0, 0, 25, - 29, 29, 75, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 5, 15, - 0, 0, 51, 7, 13, 0, 54, 9, - 9, 9, 57, 60, 11, 17, 17, 17, - 0, 0, 0, 19, 0, 21, 23, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 102, 63, 102, 0, 0, 0, 0, - 0, 69, 0, 66, 66, 84, 78, 33, - 0, 0, 0, 96, 39, 49, 81, 25, - 0, 35, 0, 0, 0, 0, 0, 0, - 90, 0, 0, 0, 93, 0, 0, 0, - 87, 0, 72, 31, 27, 0, 0, 25, - 29, 29, 75, 0, 0, 99, 0, 37, - 43, 45, 41, 47 + 13, 1, 24, 1, 26, 1, 28, 1, + 29, 1, 31, 1, 32, 1, 33, 1, + 35, 1, 37, 1, 38, 1, 39, 1, + 40, 1, 42, 1, 43, 2, 4, 9, + 2, 5, 6, 2, 7, 3, 2, 7, + 9, 2, 14, 15, 2, 16, 17, 2, + 18, 19, 2, 21, 23, 2, 22, 20, + 2, 27, 25, 2, 29, 31, 2, 34, + 2, 2, 35, 43, 2, 36, 25, 2, + 38, 43, 2, 39, 43, 2, 40, 43, + 2, 41, 30, 2, 42, 43, 3, 21, + 23, 24, 4, 14, 15, 16, 17 }; static const char _json_eof_actions[] = { @@ -15206,8 +15165,8 @@ static const char _json_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 37, 43, 45, 41, 47, 0, 0, 0, - 0, 0 + 0, 0, 0, 39, 45, 47, 43, 49, + 0, 0, 0, 0, 0, 0 }; static const int json_start = 1; @@ -15216,11 +15175,12 @@ static const int json_en_number_machine = 23; static const int json_en_string_machine = 32; static const int json_en_duration_machine = 40; static const int json_en_timestamp_machine = 47; -static const int json_en_value_machine = 75; +static const int json_en_fieldmask_machine = 75; +static const int json_en_value_machine = 78; static const int json_en_main = 1; -#line 2579 "upb/json/parser.rl" +#line 2733 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -15243,174 +15203,996 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -#line 2692 "upb/json/parser.c" +#line 2627 "upb/json/parser.c" { - int _klen; - unsigned int _trans; const char *_acts; unsigned int _nacts; - const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: - _keys = _json_trans_keys + _json_key_offsets[cs]; - _trans = _json_index_offsets[cs]; - - _klen = _json_single_lengths[cs]; - if ( _klen > 0 ) { - const char *_lower = _keys; - const char *_mid; - const char *_upper = _keys + _klen - 1; - while (1) { - if ( _upper < _lower ) - break; - - _mid = _lower + ((_upper-_lower) >> 1); - if ( (*p) < *_mid ) - _upper = _mid - 1; - else if ( (*p) > *_mid ) - _lower = _mid + 1; - else { - _trans += (unsigned int)(_mid - _keys); - goto _match; - } - } - _keys += _klen; - _trans += _klen; + switch ( cs ) { +case 1: + switch( (*p) ) { + case 32: goto tr0; + case 34: goto tr2; + case 45: goto tr3; + case 91: goto tr4; + case 102: goto tr5; + case 110: goto tr6; + case 116: goto tr7; + case 123: goto tr8; } - - _klen = _json_range_lengths[cs]; - if ( _klen > 0 ) { - const char *_lower = _keys; - const char *_mid; - const char *_upper = _keys + (_klen<<1) - 2; - while (1) { - if ( _upper < _lower ) - break; - - _mid = _lower + (((_upper-_lower) >> 1) & ~1); - if ( (*p) < _mid[0] ) - _upper = _mid - 2; - else if ( (*p) > _mid[1] ) - _lower = _mid + 2; - else { - _trans += (unsigned int)((_mid - _keys)>>1); - goto _match; - } - } - _trans += _klen; + if ( (*p) > 13 ) { + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr3; + } else if ( (*p) >= 9 ) + goto tr0; + goto tr1; +case 0: + goto _out; +case 2: + if ( (*p) == 34 ) + goto tr9; + goto tr1; +case 106: + if ( (*p) == 32 ) + goto tr147; + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr147; + goto tr1; +case 107: + if ( (*p) == 32 ) + goto tr148; + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr148; + goto tr1; +case 3: + switch( (*p) ) { + case 32: goto tr11; + case 93: goto tr12; + case 125: goto tr1; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr11; + goto tr10; +case 4: + switch( (*p) ) { + case 32: goto tr13; + case 44: goto tr14; + case 93: goto tr12; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr13; + goto tr1; +case 5: + switch( (*p) ) { + case 32: goto tr14; + case 93: goto tr1; + case 125: goto tr1; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr14; + goto tr10; +case 6: + if ( (*p) == 97 ) + goto tr15; + goto tr1; +case 7: + if ( (*p) == 108 ) + goto tr16; + goto tr1; +case 8: + if ( (*p) == 115 ) + goto tr17; + goto tr1; +case 9: + if ( (*p) == 101 ) + goto tr18; + goto tr1; +case 108: + if ( (*p) == 32 ) + goto tr149; + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr149; + goto tr1; +case 10: + if ( (*p) == 117 ) + goto tr19; + goto tr1; +case 11: + if ( (*p) == 108 ) + goto tr20; + goto tr1; +case 12: + if ( (*p) == 108 ) + goto tr21; + goto tr1; +case 109: + if ( (*p) == 32 ) + goto tr150; + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr150; + goto tr1; +case 13: + if ( (*p) == 114 ) + goto tr22; + goto tr1; +case 14: + if ( (*p) == 117 ) + goto tr23; + goto tr1; +case 15: + if ( (*p) == 101 ) + goto tr24; + goto tr1; +case 110: + if ( (*p) == 32 ) + goto tr151; + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr151; + goto tr1; +case 16: + switch( (*p) ) { + case 32: goto tr25; + case 34: goto tr26; + case 125: goto tr27; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr25; + goto tr1; +case 17: + if ( (*p) == 34 ) + goto tr28; + goto tr1; +case 18: + switch( (*p) ) { + case 32: goto tr29; + case 58: goto tr30; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr29; + goto tr1; +case 19: + switch( (*p) ) { + case 32: goto tr30; + case 93: goto tr1; + case 125: goto tr1; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr30; + goto tr31; +case 20: + switch( (*p) ) { + case 32: goto tr32; + case 44: goto tr33; + case 125: goto tr34; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr32; + goto tr1; +case 21: + switch( (*p) ) { + case 32: goto tr35; + case 44: goto tr36; + case 125: goto tr27; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr35; + goto tr1; +case 22: + switch( (*p) ) { + case 32: goto tr36; + case 34: goto tr26; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr36; + goto tr1; +case 111: + if ( (*p) == 32 ) + goto tr152; + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr152; + goto tr1; +case 23: + switch( (*p) ) { + case 45: goto tr37; + case 48: goto tr38; + } + if ( 49 <= (*p) && (*p) <= 57 ) + goto tr39; + goto tr1; +case 24: + if ( (*p) == 48 ) + goto tr38; + if ( 49 <= (*p) && (*p) <= 57 ) + goto tr39; + goto tr1; +case 25: + switch( (*p) ) { + case 46: goto tr41; + case 69: goto tr42; + case 101: goto tr42; + } + goto tr40; +case 112: + goto tr1; +case 26: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr43; + goto tr1; +case 27: + switch( (*p) ) { + case 69: goto tr42; + case 101: goto tr42; + } + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr43; + goto tr40; +case 28: + switch( (*p) ) { + case 43: goto tr44; + case 45: goto tr44; + } + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr45; + goto tr1; +case 29: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr45; + goto tr1; +case 30: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr45; + goto tr40; +case 31: + switch( (*p) ) { + case 46: goto tr41; + case 69: goto tr42; + case 101: goto tr42; + } + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr39; + goto tr40; +case 32: + switch( (*p) ) { + case 34: goto tr47; + case 92: goto tr48; + } + goto tr46; +case 33: + switch( (*p) ) { + case 34: goto tr50; + case 92: goto tr51; + } + goto tr49; +case 113: + goto tr1; +case 34: + switch( (*p) ) { + case 34: goto tr52; + case 47: goto tr52; + case 92: goto tr52; + case 98: goto tr52; + case 102: goto tr52; + case 110: goto tr52; + case 114: goto tr52; + case 116: goto tr52; + case 117: goto tr53; + } + goto tr1; +case 35: + if ( (*p) < 65 ) { + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr54; + } else if ( (*p) > 70 ) { + if ( 97 <= (*p) && (*p) <= 102 ) + goto tr54; + } else + goto tr54; + goto tr1; +case 36: + if ( (*p) < 65 ) { + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr55; + } else if ( (*p) > 70 ) { + if ( 97 <= (*p) && (*p) <= 102 ) + goto tr55; + } else + goto tr55; + goto tr1; +case 37: + if ( (*p) < 65 ) { + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr56; + } else if ( (*p) > 70 ) { + if ( 97 <= (*p) && (*p) <= 102 ) + goto tr56; + } else + goto tr56; + goto tr1; +case 38: + if ( (*p) < 65 ) { + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr57; + } else if ( (*p) > 70 ) { + if ( 97 <= (*p) && (*p) <= 102 ) + goto tr57; + } else + goto tr57; + goto tr1; +case 39: + switch( (*p) ) { + case 34: goto tr59; + case 92: goto tr60; + } + goto tr58; +case 40: + switch( (*p) ) { + case 45: goto tr61; + case 48: goto tr62; + } + if ( 49 <= (*p) && (*p) <= 57 ) + goto tr63; + goto tr1; +case 41: + if ( (*p) == 48 ) + goto tr64; + if ( 49 <= (*p) && (*p) <= 57 ) + goto tr65; + goto tr1; +case 42: + switch( (*p) ) { + case 46: goto tr66; + case 115: goto tr67; + } + goto tr1; +case 43: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr68; + goto tr1; +case 44: + if ( (*p) == 115 ) + goto tr67; + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr68; + goto tr1; +case 45: + if ( (*p) == 34 ) + goto tr69; + goto tr1; +case 114: + goto tr1; +case 46: + switch( (*p) ) { + case 46: goto tr66; + case 115: goto tr67; + } + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr65; + goto tr1; +case 47: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr70; + goto tr1; +case 48: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr71; + goto tr1; +case 49: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr72; + goto tr1; +case 50: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr73; + goto tr1; +case 51: + if ( (*p) == 45 ) + goto tr74; + goto tr1; +case 52: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr75; + goto tr1; +case 53: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr76; + goto tr1; +case 54: + if ( (*p) == 45 ) + goto tr77; + goto tr1; +case 55: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr78; + goto tr1; +case 56: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr79; + goto tr1; +case 57: + if ( (*p) == 84 ) + goto tr80; + goto tr1; +case 58: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr81; + goto tr1; +case 59: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr82; + goto tr1; +case 60: + if ( (*p) == 58 ) + goto tr83; + goto tr1; +case 61: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr84; + goto tr1; +case 62: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr85; + goto tr1; +case 63: + if ( (*p) == 58 ) + goto tr86; + goto tr1; +case 64: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr87; + goto tr1; +case 65: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr88; + goto tr1; +case 66: + switch( (*p) ) { + case 43: goto tr89; + case 45: goto tr89; + case 46: goto tr90; + case 90: goto tr91; + } + goto tr1; +case 67: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr92; + goto tr1; +case 68: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr93; + goto tr1; +case 69: + if ( (*p) == 58 ) + goto tr94; + goto tr1; +case 70: + if ( (*p) == 48 ) + goto tr95; + goto tr1; +case 71: + if ( (*p) == 48 ) + goto tr96; + goto tr1; +case 72: + if ( (*p) == 34 ) + goto tr97; + goto tr1; +case 115: + goto tr1; +case 73: + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr98; + goto tr1; +case 74: + switch( (*p) ) { + case 43: goto tr99; + case 45: goto tr99; + case 90: goto tr100; + } + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr98; + goto tr1; +case 75: + switch( (*p) ) { + case 34: goto tr102; + case 44: goto tr1; + } + goto tr101; +case 76: + switch( (*p) ) { + case 34: goto tr104; + case 44: goto tr105; + } + goto tr103; +case 116: + goto tr1; +case 77: + switch( (*p) ) { + case 34: goto tr1; + case 44: goto tr1; + } + goto tr101; +case 78: + switch( (*p) ) { + case 34: goto tr106; + case 45: goto tr107; + case 91: goto tr108; + case 102: goto tr109; + case 110: goto tr110; + case 116: goto tr111; + case 123: goto tr112; + } + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr107; + goto tr1; +case 79: + if ( (*p) == 34 ) + goto tr113; + goto tr1; +case 80: + goto tr114; +case 117: + goto tr1; +case 81: + goto tr115; +case 82: + switch( (*p) ) { + case 32: goto tr117; + case 93: goto tr118; + case 125: goto tr1; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr117; + goto tr116; +case 83: + switch( (*p) ) { + case 32: goto tr119; + case 44: goto tr120; + case 93: goto tr118; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr119; + goto tr1; +case 84: + switch( (*p) ) { + case 32: goto tr120; + case 93: goto tr1; + case 125: goto tr1; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr120; + goto tr116; +case 85: + if ( (*p) == 97 ) + goto tr121; + goto tr1; +case 86: + if ( (*p) == 108 ) + goto tr122; + goto tr1; +case 87: + if ( (*p) == 115 ) + goto tr123; + goto tr1; +case 88: + if ( (*p) == 101 ) + goto tr124; + goto tr1; +case 89: + goto tr125; +case 90: + if ( (*p) == 117 ) + goto tr126; + goto tr1; +case 91: + if ( (*p) == 108 ) + goto tr127; + goto tr1; +case 92: + if ( (*p) == 108 ) + goto tr128; + goto tr1; +case 93: + goto tr129; +case 94: + if ( (*p) == 114 ) + goto tr130; + goto tr1; +case 95: + if ( (*p) == 117 ) + goto tr131; + goto tr1; +case 96: + if ( (*p) == 101 ) + goto tr132; + goto tr1; +case 97: + goto tr133; +case 98: + switch( (*p) ) { + case 32: goto tr134; + case 34: goto tr135; + case 125: goto tr136; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr134; + goto tr1; +case 99: + if ( (*p) == 34 ) + goto tr137; + goto tr1; +case 100: + switch( (*p) ) { + case 32: goto tr138; + case 58: goto tr139; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr138; + goto tr1; +case 101: + switch( (*p) ) { + case 32: goto tr139; + case 93: goto tr1; + case 125: goto tr1; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr139; + goto tr140; +case 102: + switch( (*p) ) { + case 32: goto tr141; + case 44: goto tr142; + case 125: goto tr143; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr141; + goto tr1; +case 103: + switch( (*p) ) { + case 32: goto tr144; + case 44: goto tr145; + case 125: goto tr136; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr144; + goto tr1; +case 104: + switch( (*p) ) { + case 32: goto tr145; + case 34: goto tr135; + } + if ( 9 <= (*p) && (*p) <= 13 ) + goto tr145; + goto tr1; +case 105: + goto tr146; } -_match: - _trans = _json_indicies[_trans]; - cs = _json_trans_targs[_trans]; - - if ( _json_trans_actions[_trans] == 0 ) - goto _again; - - _acts = _json_actions + _json_trans_actions[_trans]; - _nacts = (unsigned int) *_acts++; - while ( _nacts-- > 0 ) - { - switch ( *_acts++ ) - { + tr1: cs = 0; goto _again; + tr0: cs = 1; goto _again; + tr2: cs = 2; goto f0; + tr11: cs = 3; goto _again; + tr4: cs = 3; goto f2; + tr13: cs = 4; goto _again; + tr10: cs = 4; goto f5; + tr14: cs = 5; goto _again; + tr5: cs = 6; goto _again; + tr15: cs = 7; goto _again; + tr16: cs = 8; goto _again; + tr17: cs = 9; goto _again; + tr6: cs = 10; goto _again; + tr19: cs = 11; goto _again; + tr20: cs = 12; goto _again; + tr7: cs = 13; goto _again; + tr22: cs = 14; goto _again; + tr23: cs = 15; goto _again; + tr25: cs = 16; goto _again; + tr8: cs = 16; goto f3; + tr26: cs = 17; goto f7; + tr29: cs = 18; goto _again; + tr28: cs = 18; goto f9; + tr30: cs = 19; goto _again; + tr31: cs = 20; goto f5; + tr35: cs = 21; goto _again; + tr32: cs = 21; goto f10; + tr36: cs = 22; goto _again; + tr33: cs = 22; goto f10; + tr37: cs = 24; goto _again; + tr38: cs = 25; goto _again; + tr41: cs = 26; goto _again; + tr43: cs = 27; goto _again; + tr42: cs = 28; goto _again; + tr44: cs = 29; goto _again; + tr45: cs = 30; goto _again; + tr39: cs = 31; goto _again; + tr52: cs = 32; goto f18; + tr49: cs = 33; goto _again; + tr46: cs = 33; goto f14; + tr58: cs = 33; goto f21; + tr48: cs = 34; goto _again; + tr51: cs = 34; goto f17; + tr60: cs = 34; goto f23; + tr53: cs = 35; goto _again; + tr54: cs = 36; goto f19; + tr55: cs = 37; goto f20; + tr56: cs = 38; goto f20; + tr57: cs = 39; goto f20; + tr61: cs = 41; goto f24; + tr64: cs = 42; goto _again; + tr62: cs = 42; goto f24; + tr66: cs = 43; goto _again; + tr68: cs = 44; goto _again; + tr67: cs = 45; goto f25; + tr65: cs = 46; goto _again; + tr63: cs = 46; goto f24; + tr70: cs = 48; goto f27; + tr71: cs = 49; goto _again; + tr72: cs = 50; goto _again; + tr73: cs = 51; goto _again; + tr74: cs = 52; goto _again; + tr75: cs = 53; goto _again; + tr76: cs = 54; goto _again; + tr77: cs = 55; goto _again; + tr78: cs = 56; goto _again; + tr79: cs = 57; goto _again; + tr80: cs = 58; goto _again; + tr81: cs = 59; goto _again; + tr82: cs = 60; goto _again; + tr83: cs = 61; goto _again; + tr84: cs = 62; goto _again; + tr85: cs = 63; goto _again; + tr86: cs = 64; goto _again; + tr87: cs = 65; goto _again; + tr88: cs = 66; goto _again; + tr89: cs = 67; goto f28; + tr99: cs = 67; goto f31; + tr92: cs = 68; goto _again; + tr93: cs = 69; goto _again; + tr94: cs = 70; goto _again; + tr95: cs = 71; goto _again; + tr96: cs = 72; goto _again; + tr91: cs = 72; goto f28; + tr100: cs = 72; goto f31; + tr90: cs = 73; goto f29; + tr98: cs = 74; goto _again; + tr103: cs = 76; goto _again; + tr101: cs = 76; goto f32; + tr105: cs = 77; goto f35; + tr106: cs = 79; goto f0; + tr113: cs = 80; goto f4; + tr118: cs = 80; goto f6; + tr107: cs = 81; goto f1; + tr117: cs = 82; goto _again; + tr108: cs = 82; goto f2; + tr119: cs = 83; goto _again; + tr116: cs = 83; goto f5; + tr120: cs = 84; goto _again; + tr109: cs = 85; goto _again; + tr121: cs = 86; goto _again; + tr122: cs = 87; goto _again; + tr123: cs = 88; goto _again; + tr124: cs = 89; goto _again; + tr110: cs = 90; goto _again; + tr126: cs = 91; goto _again; + tr127: cs = 92; goto _again; + tr128: cs = 93; goto _again; + tr111: cs = 94; goto _again; + tr130: cs = 95; goto _again; + tr131: cs = 96; goto _again; + tr132: cs = 97; goto _again; + tr134: cs = 98; goto _again; + tr112: cs = 98; goto f3; + tr135: cs = 99; goto f7; + tr138: cs = 100; goto _again; + tr137: cs = 100; goto f9; + tr139: cs = 101; goto _again; + tr140: cs = 102; goto f5; + tr144: cs = 103; goto _again; + tr141: cs = 103; goto f10; + tr145: cs = 104; goto _again; + tr142: cs = 104; goto f10; + tr136: cs = 105; goto f8; + tr143: cs = 105; goto f11; + tr147: cs = 106; goto _again; + tr9: cs = 106; goto f4; + tr12: cs = 106; goto f6; + tr148: cs = 106; goto f42; + tr149: cs = 106; goto f43; + tr150: cs = 106; goto f44; + tr151: cs = 106; goto f45; + tr152: cs = 106; goto f46; + tr3: cs = 107; goto f1; + tr18: cs = 108; goto _again; + tr21: cs = 109; goto _again; + tr24: cs = 110; goto _again; + tr27: cs = 111; goto f8; + tr34: cs = 111; goto f11; + tr40: cs = 112; goto f13; + tr47: cs = 113; goto f15; + tr50: cs = 113; goto f16; + tr59: cs = 113; goto f22; + tr69: cs = 114; goto f26; + tr97: cs = 115; goto f30; + tr102: cs = 116; goto f33; + tr104: cs = 116; goto f34; + tr114: cs = 117; goto f36; + tr115: cs = 117; goto f37; + tr125: cs = 117; goto f38; + tr129: cs = 117; goto f39; + tr133: cs = 117; goto f40; + tr146: cs = 117; goto f41; + + f13: _acts = _json_actions + 3; goto execFuncs; + f14: _acts = _json_actions + 5; goto execFuncs; + f17: _acts = _json_actions + 7; goto execFuncs; + f20: _acts = _json_actions + 9; goto execFuncs; + f23: _acts = _json_actions + 11; goto execFuncs; + f18: _acts = _json_actions + 13; goto execFuncs; + f15: _acts = _json_actions + 15; goto execFuncs; + f24: _acts = _json_actions + 17; goto execFuncs; + f25: _acts = _json_actions + 19; goto execFuncs; + f26: _acts = _json_actions + 21; goto execFuncs; + f27: _acts = _json_actions + 23; goto execFuncs; + f33: _acts = _json_actions + 25; goto execFuncs; + f5: _acts = _json_actions + 27; goto execFuncs; + f9: _acts = _json_actions + 29; goto execFuncs; + f10: _acts = _json_actions + 31; goto execFuncs; + f8: _acts = _json_actions + 33; goto execFuncs; + f2: _acts = _json_actions + 35; goto execFuncs; + f6: _acts = _json_actions + 37; goto execFuncs; + f42: _acts = _json_actions + 39; goto execFuncs; + f4: _acts = _json_actions + 41; goto execFuncs; + f45: _acts = _json_actions + 43; goto execFuncs; + f43: _acts = _json_actions + 45; goto execFuncs; + f44: _acts = _json_actions + 47; goto execFuncs; + f46: _acts = _json_actions + 49; goto execFuncs; + f36: _acts = _json_actions + 51; goto execFuncs; + f16: _acts = _json_actions + 53; goto execFuncs; + f19: _acts = _json_actions + 56; goto execFuncs; + f21: _acts = _json_actions + 59; goto execFuncs; + f22: _acts = _json_actions + 62; goto execFuncs; + f29: _acts = _json_actions + 65; goto execFuncs; + f31: _acts = _json_actions + 68; goto execFuncs; + f30: _acts = _json_actions + 71; goto execFuncs; + f35: _acts = _json_actions + 74; goto execFuncs; + f32: _acts = _json_actions + 77; goto execFuncs; + f7: _acts = _json_actions + 80; goto execFuncs; + f11: _acts = _json_actions + 83; goto execFuncs; + f1: _acts = _json_actions + 86; goto execFuncs; + f37: _acts = _json_actions + 89; goto execFuncs; + f0: _acts = _json_actions + 92; goto execFuncs; + f40: _acts = _json_actions + 95; goto execFuncs; + f38: _acts = _json_actions + 98; goto execFuncs; + f39: _acts = _json_actions + 101; goto execFuncs; + f3: _acts = _json_actions + 104; goto execFuncs; + f41: _acts = _json_actions + 107; goto execFuncs; + f34: _acts = _json_actions + 110; goto execFuncs; + f28: _acts = _json_actions + 114; goto execFuncs; + +execFuncs: + _nacts = *_acts++; + while ( _nacts-- > 0 ) { + switch ( *_acts++ ) { case 1: -#line 2427 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } +#line 2561 "upb/json/parser.rl" + { p--; {cs = stack[--top];goto _again;} } break; case 2: -#line 2429 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 23; goto _again;} } +#line 2563 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 23;goto _again;} } break; case 3: -#line 2433 "upb/json/parser.rl" +#line 2567 "upb/json/parser.rl" { start_text(parser, p); } break; case 4: -#line 2434 "upb/json/parser.rl" +#line 2568 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 5: -#line 2440 "upb/json/parser.rl" +#line 2574 "upb/json/parser.rl" { start_hex(parser); } break; case 6: -#line 2441 "upb/json/parser.rl" +#line 2575 "upb/json/parser.rl" { hexdigit(parser, p); } break; case 7: -#line 2442 "upb/json/parser.rl" +#line 2576 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hex(parser)); } break; case 8: -#line 2448 "upb/json/parser.rl" +#line 2582 "upb/json/parser.rl" { CHECK_RETURN_TOP(escape(parser, p)); } break; case 9: -#line 2454 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } +#line 2588 "upb/json/parser.rl" + { p--; {cs = stack[--top];goto _again;} } break; case 10: -#line 2466 "upb/json/parser.rl" +#line 2600 "upb/json/parser.rl" { start_duration_base(parser, p); } break; case 11: -#line 2467 "upb/json/parser.rl" +#line 2601 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_duration_base(parser, p)); } break; case 12: -#line 2469 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } +#line 2603 "upb/json/parser.rl" + { p--; {cs = stack[--top];goto _again;} } break; case 13: -#line 2474 "upb/json/parser.rl" +#line 2608 "upb/json/parser.rl" { start_timestamp_base(parser, p); } break; case 14: -#line 2475 "upb/json/parser.rl" +#line 2609 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } break; case 15: -#line 2477 "upb/json/parser.rl" +#line 2611 "upb/json/parser.rl" { start_timestamp_fraction(parser, p); } break; case 16: -#line 2478 "upb/json/parser.rl" +#line 2612 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } break; case 17: -#line 2480 "upb/json/parser.rl" +#line 2614 "upb/json/parser.rl" { start_timestamp_zone(parser, p); } break; case 18: -#line 2481 "upb/json/parser.rl" +#line 2615 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } break; case 19: -#line 2483 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } +#line 2617 "upb/json/parser.rl" + { p--; {cs = stack[--top];goto _again;} } break; case 20: -#line 2488 "upb/json/parser.rl" +#line 2622 "upb/json/parser.rl" + { start_fieldmask_path_text(parser, p); } + break; + case 21: +#line 2623 "upb/json/parser.rl" + { end_fieldmask_path_text(parser, p); } + break; + case 22: +#line 2628 "upb/json/parser.rl" + { start_fieldmask_path(parser); } + break; + case 23: +#line 2629 "upb/json/parser.rl" + { end_fieldmask_path(parser); } + break; + case 24: +#line 2635 "upb/json/parser.rl" + { p--; {cs = stack[--top];goto _again;} } + break; + case 25: +#line 2640 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { - {stack[top++] = cs; cs = 47; goto _again;} + {stack[top++] = cs; cs = 47;goto _again;} } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) { - {stack[top++] = cs; cs = 40; goto _again;} + {stack[top++] = cs; cs = 40;goto _again;} + } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_FIELDMASK)) { + {stack[top++] = cs; cs = 75;goto _again;} } else { - {stack[top++] = cs; cs = 32; goto _again;} + {stack[top++] = cs; cs = 32;goto _again;} } } break; - case 21: -#line 2499 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 75; goto _again;} } + case 26: +#line 2653 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 78;goto _again;} } break; - case 22: -#line 2504 "upb/json/parser.rl" + case 27: +#line 2658 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { start_any_member(parser, p); @@ -15419,12 +16201,12 @@ _match: } } break; - case 23: -#line 2511 "upb/json/parser.rl" + case 28: +#line 2665 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_membername(parser)); } break; - case 24: -#line 2514 "upb/json/parser.rl" + case 29: +#line 2668 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { end_any_member(parser, p); @@ -15433,8 +16215,8 @@ _match: } } break; - case 25: -#line 2525 "upb/json/parser.rl" + case 30: +#line 2679 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { start_any_object(parser, p); @@ -15443,8 +16225,8 @@ _match: } } break; - case 26: -#line 2534 "upb/json/parser.rl" + case 31: +#line 2688 "upb/json/parser.rl" { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { CHECK_RETURN_TOP(end_any_object(parser, p)); @@ -15453,57 +16235,58 @@ _match: } } break; - case 27: -#line 2546 "upb/json/parser.rl" + case 32: +#line 2700 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_array(parser)); } break; - case 28: -#line 2550 "upb/json/parser.rl" + case 33: +#line 2704 "upb/json/parser.rl" { end_array(parser); } break; - case 29: -#line 2555 "upb/json/parser.rl" + case 34: +#line 2709 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_number(parser, p)); } break; - case 30: -#line 2556 "upb/json/parser.rl" + case 35: +#line 2710 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; - case 31: -#line 2558 "upb/json/parser.rl" + case 36: +#line 2712 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_stringval(parser)); } break; - case 32: -#line 2559 "upb/json/parser.rl" + case 37: +#line 2713 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_stringval(parser)); } break; - case 33: -#line 2561 "upb/json/parser.rl" + case 38: +#line 2715 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; - case 34: -#line 2563 "upb/json/parser.rl" + case 39: +#line 2717 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; - case 35: -#line 2565 "upb/json/parser.rl" + case 40: +#line 2719 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_null(parser)); } break; - case 36: -#line 2567 "upb/json/parser.rl" + case 41: +#line 2721 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_subobject_full(parser)); } break; - case 37: -#line 2568 "upb/json/parser.rl" + case 42: +#line 2722 "upb/json/parser.rl" { end_subobject_full(parser); } break; - case 38: -#line 2573 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } + case 43: +#line 2727 "upb/json/parser.rl" + { p--; {cs = stack[--top];goto _again;} } break; -#line 2950 "upb/json/parser.c" +#line 3707 "upb/json/parser.c" } } + goto _again; _again: if ( cs == 0 ) @@ -15518,30 +16301,32 @@ _again: while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 0: -#line 2425 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } +#line 2559 "upb/json/parser.rl" + { p--; {cs = stack[--top]; if ( p == pe ) + goto _test_eof; +goto _again;} } break; - case 30: -#line 2556 "upb/json/parser.rl" + case 35: +#line 2710 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; - case 33: -#line 2561 "upb/json/parser.rl" + case 38: +#line 2715 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; - case 34: -#line 2563 "upb/json/parser.rl" + case 39: +#line 2717 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; - case 35: -#line 2565 "upb/json/parser.rl" + case 40: +#line 2719 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_null(parser)); } break; - case 37: -#line 2568 "upb/json/parser.rl" + case 42: +#line 2722 "upb/json/parser.rl" { end_subobject_full(parser); } break; -#line 2990 "upb/json/parser.c" +#line 3750 "upb/json/parser.c" } } } @@ -15549,7 +16334,7 @@ _again: _out: {} } -#line 2601 "upb/json/parser.rl" +#line 2755 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -15572,6 +16357,7 @@ static bool end(void *closure, const void *hd) { /* Prevent compile warning on unused static constants. */ UPB_UNUSED(json_start); UPB_UNUSED(json_en_duration_machine); + UPB_UNUSED(json_en_fieldmask_machine); UPB_UNUSED(json_en_number_machine); UPB_UNUSED(json_en_string_machine); UPB_UNUSED(json_en_timestamp_machine); @@ -15580,11 +16366,7 @@ static bool end(void *closure, const void *hd) { parse(parser, hd, &eof_ch, 0, NULL); - return parser->current_state >= -#line 3030 "upb/json/parser.c" -103 -#line 2631 "upb/json/parser.rl" -; + return parser->current_state >= 106; } static void json_parser_reset(upb_json_parser *p) { @@ -15601,13 +16383,13 @@ static void json_parser_reset(upb_json_parser *p) { /* Emit Ragel initialization of the parser. */ -#line 3050 "upb/json/parser.c" +#line 3807 "upb/json/parser.c" { cs = json_start; top = 0; } -#line 2648 "upb/json/parser.rl" +#line 2803 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -16511,6 +17293,57 @@ static void *startseq_nokey(void *closure, const void *handler_data) { return closure; } +static void *startseq_fieldmask(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_++; + p->first_elem_[p->depth_] = true; + print_data(p, "\"", 1); + return closure; +} + +static bool endseq_fieldmask(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_--; + print_data(p, "\"", 1); + return true; +} + +static void *repeated_startstr_fieldmask( + void *closure, const void *handler_data, + size_t size_hint) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(size_hint); + print_comma(p); + return p; +} + +static size_t repeated_str_fieldmask( + void *closure, const void *handler_data, + const char *str, size_t len, + const upb_bufhandle *handle) { + const char* limit = str + len; + bool upper = false; + size_t result_len = 0; + for (; str < limit; str++) { + if (*str == '_') { + upper = true; + continue; + } + if (upper && *str >= 'a' && *str <= 'z') { + char upper_char = toupper(*str); + CHK(putstr(closure, handler_data, &upper_char, 1, handle)); + } else { + CHK(putstr(closure, handler_data, str, 1, handle)); + } + upper = false; + result_len++; + } + return result_len; +} + static void *startmap_nokey(void *closure, const void *handler_data) { upb_json_printer *p = closure; UPB_UNUSED(handler_data); @@ -16736,6 +17569,25 @@ void printer_sethandlers_any(const void *closure, upb_handlers *h) { UPB_UNUSED(closure); } +/* Set up handlers for a fieldmask submessage. */ +void printer_sethandlers_fieldmask(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + const upb_fielddef* f = upb_msgdef_itof(md, 1); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartseq(h, f, startseq_fieldmask, &empty_attr); + upb_handlers_setendseq(h, f, endseq_fieldmask, &empty_attr); + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_handlers_setstartstr(h, f, repeated_startstr_fieldmask, &empty_attr); + upb_handlers_setstring(h, f, repeated_str_fieldmask, &empty_attr); + + UPB_UNUSED(closure); +} + /* Set up handlers for a duration submessage. */ void printer_sethandlers_duration(const void *closure, upb_handlers *h) { const upb_msgdef *md = upb_handlers_msgdef(h); @@ -16892,6 +17744,9 @@ void printer_sethandlers(const void *closure, upb_handlers *h) { case UPB_WELLKNOWN_ANY: printer_sethandlers_any(closure, h); return; + case UPB_WELLKNOWN_FIELDMASK: + printer_sethandlers_fieldmask(closure, h); + return; case UPB_WELLKNOWN_DURATION: printer_sethandlers_duration(closure, h); return; diff --git a/php/ext/google/protobuf/upb.h b/php/ext/google/protobuf/upb.h index f59fffb770..86393c6fa4 100644 --- a/php/ext/google/protobuf/upb.h +++ b/php/ext/google/protobuf/upb.h @@ -2014,6 +2014,7 @@ typedef enum { typedef enum { UPB_WELLKNOWN_UNSPECIFIED, UPB_WELLKNOWN_ANY, + UPB_WELLKNOWN_FIELDMASK, UPB_WELLKNOWN_DURATION, UPB_WELLKNOWN_TIMESTAMP, /* number wrappers */ diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 6aaca840cc..61527e899a 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -14,6 +14,7 @@ use Foo\TestRandomFieldOrder; use Foo\TestUnpackedMessage; use Google\Protobuf\Any; use Google\Protobuf\DoubleValue; +use Google\Protobuf\FieldMask; use Google\Protobuf\FloatValue; use Google\Protobuf\Int32Value; use Google\Protobuf\UInt32Value; @@ -266,6 +267,40 @@ class EncodeDecodeTest extends TestBase } + public function testJsonEncodeDecodeOneof() + { + $m = new TestMessage(); + + $m->setOneofEnum(TestEnum::ONE); + $data = $m->serializeToJsonString(); + $n = new TestMessage(); + $n->mergeFromJsonString($data); + $this->assertSame("oneof_enum", $n->getMyOneof()); + $this->assertSame(TestEnum::ONE, $n->getOneofEnum()); + + $m->setOneofString("a"); + $data = $m->serializeToJsonString(); + $n = new TestMessage(); + $n->mergeFromJsonString($data); + $this->assertSame("oneof_string", $n->getMyOneof()); + $this->assertSame("a", $n->getOneofString()); + + $m->setOneofBytes("bbbb"); + $data = $m->serializeToJsonString(); + $n = new TestMessage(); + $n->mergeFromJsonString($data); + $this->assertSame("oneof_bytes", $n->getMyOneof()); + $this->assertSame("bbbb", $n->getOneofBytes()); + + $sub_m = new Sub(); + $m->setOneofMessage($sub_m); + $data = $m->serializeToJsonString(); + $n = new TestMessage(); + $n->mergeFromJsonString($data); + $this->assertSame("oneof_message", $n->getMyOneof()); + $this->assertFalse(is_null($n->getOneofMessage())); + } + public function testPackedEncode() { $from = new TestPackedMessage(); @@ -1070,4 +1105,27 @@ class EncodeDecodeTest extends TestBase $m->serializeToJsonString()); } + public function testDecodeTopLevelFieldMask() + { + $m = new TestMessage(); + $m->setMapStringString(['a'=>'abcdefg']); + $data1 = $m->serializeToJsonString(); + $n = new TestMessage(); + $n->mergeFromJsonString($data1); + $data2 = $n->serializeToJsonString(); + $this->assertSame($data1, $data2); + + $m = new FieldMask(); + $m->mergeFromJsonString("\"foo.barBaz,qux\""); + $this->assertSame("foo.bar_baz", $m->getPaths()[0]); + $this->assertSame("qux", $m->getPaths()[1]); + } + + public function testEncodeTopLevelFieldMask() + { + $m = new FieldMask(); + $m->setPaths(["foo.bar_baz", "qux"]); + $this->assertSame("\"foo.barBaz,qux\"", $m->serializeToJsonString()); + } + } diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 38c380969c..83deaba163 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -1329,7 +1329,7 @@ class GeneratedClassTest extends TestBase 'optional_double' => 1.6, 'optional_bool' => true, 'optional_string' => 'a', - 'optional_bytes' => 'b', + 'optional_bytes' => 'bbbb', 'optional_enum' => TestEnum::ONE, 'optional_message' => new Sub([ 'a' => 33 @@ -1348,7 +1348,7 @@ class GeneratedClassTest extends TestBase 'repeated_double' => [1.6, 2.6], 'repeated_bool' => [true, false], 'repeated_string' => ['a', 'c'], - 'repeated_bytes' => ['b', 'd'], + 'repeated_bytes' => ['bbbb', 'dddd'], 'repeated_enum' => [TestEnum::ZERO, TestEnum::ONE], 'repeated_message' => [new Sub(['a' => 34]), new Sub(['a' => 35])], @@ -1366,7 +1366,7 @@ class GeneratedClassTest extends TestBase 'map_int32_double' => [1 => 3.6], 'map_bool_bool' => [true => true], 'map_string_string' => ['e' => 'e'], - 'map_int32_bytes' => [1 => 'f'], + 'map_int32_bytes' => [1 => 'ffff'], 'map_int32_enum' => [1 => TestEnum::ONE], 'map_int32_message' => [1 => new Sub(['a' => 36])], ]); diff --git a/php/tests/php_implementation_test.php b/php/tests/php_implementation_test.php index 323a36ff09..8d27d19f0d 100644 --- a/php/tests/php_implementation_test.php +++ b/php/tests/php_implementation_test.php @@ -504,7 +504,7 @@ class ImplementationTest extends TestBase { $m = new TestMessage(); TestUtil::setTestMessage($m); - $this->assertSame(506, $m->byteSize()); + $this->assertSame(518, $m->byteSize()); } public function testPackedByteSize() diff --git a/php/tests/test_base.php b/php/tests/test_base.php index 27efc87a9e..a4d951bdc5 100644 --- a/php/tests/test_base.php +++ b/php/tests/test_base.php @@ -28,7 +28,7 @@ class TestBase extends \PHPUnit\Framework\TestCase $this->assertSame(1.6, $m->getOptionalDouble()); $this->assertSame(true, $m->getOptionalBool()); $this->assertSame('a', $m->getOptionalString()); - $this->assertSame('b', $m->getOptionalBytes()); + $this->assertSame('bbbb', $m->getOptionalBytes()); $this->assertSame(TestEnum::ONE, $m->getOptionalEnum()); $this->assertSame(33, $m->getOptionalMessage()->getA()); if (PHP_INT_SIZE == 4) { @@ -59,7 +59,7 @@ class TestBase extends \PHPUnit\Framework\TestCase $this->assertEquals(1.6, $m->getRepeatedDouble()[0]); $this->assertEquals(true, $m->getRepeatedBool()[0]); $this->assertEquals('a', $m->getRepeatedString()[0]); - $this->assertEquals('b', $m->getRepeatedBytes()[0]); + $this->assertEquals('bbbb', $m->getRepeatedBytes()[0]); $this->assertEquals(34, $m->getRepeatedMessage()[0]->GetA()); $this->assertEquals(-52, $m->getRepeatedInt32()[1]); @@ -76,7 +76,7 @@ class TestBase extends \PHPUnit\Framework\TestCase $this->assertEquals(2.6, $m->getRepeatedDouble()[1]); $this->assertEquals(false, $m->getRepeatedBool()[1]); $this->assertEquals('c', $m->getRepeatedString()[1]); - $this->assertEquals('d', $m->getRepeatedBytes()[1]); + $this->assertEquals('dddd', $m->getRepeatedBytes()[1]); $this->assertEquals(35, $m->getRepeatedMessage()[1]->GetA()); if (PHP_INT_SIZE == 4) { @@ -101,7 +101,7 @@ class TestBase extends \PHPUnit\Framework\TestCase $this->assertEquals(3.6, $m->getMapInt32Double()[1]); $this->assertEquals(true , $m->getMapBoolBool()[true]); $this->assertEquals('e', $m->getMapStringString()['e']); - $this->assertEquals('f', $m->getMapInt32Bytes()[1]); + $this->assertEquals('ffff', $m->getMapInt32Bytes()[1]); $this->assertEquals(TestEnum::ONE, $m->getMapInt32Enum()[1]); $this->assertEquals(36, $m->getMapInt32Message()[1]->GetA()); } @@ -146,7 +146,7 @@ class TestBase extends \PHPUnit\Framework\TestCase $this->assertEquals(1.6, $m->getRepeatedDouble()[0]); $this->assertEquals(true, $m->getRepeatedBool()[0]); $this->assertEquals('a', $m->getRepeatedString()[0]); - $this->assertEquals('b', $m->getRepeatedBytes()[0]); + $this->assertEquals('bbbb', $m->getRepeatedBytes()[0]); $this->assertEquals(TestEnum::ZERO, $m->getRepeatedEnum()[0]); $this->assertEquals(34, $m->getRepeatedMessage()[0]->GetA()); @@ -164,7 +164,7 @@ class TestBase extends \PHPUnit\Framework\TestCase $this->assertEquals(2.6, $m->getRepeatedDouble()[1]); $this->assertEquals(false, $m->getRepeatedBool()[1]); $this->assertEquals('c', $m->getRepeatedString()[1]); - $this->assertEquals('d', $m->getRepeatedBytes()[1]); + $this->assertEquals('dddd', $m->getRepeatedBytes()[1]); $this->assertEquals(TestEnum::ONE, $m->getRepeatedEnum()[1]); $this->assertEquals(35, $m->getRepeatedMessage()[1]->GetA()); diff --git a/php/tests/test_util.php b/php/tests/test_util.php index a676d097ed..2c5b59541c 100644 --- a/php/tests/test_util.php +++ b/php/tests/test_util.php @@ -65,7 +65,7 @@ class TestUtil $m->setOptionalDouble(1.6); $m->setOptionalBool(true); $m->setOptionalString('a'); - $m->setOptionalBytes('b'); + $m->setOptionalBytes('bbbb'); $m->setOptionalEnum(TestEnum::ONE); $sub = new Sub(); $m->setOptionalMessage($sub); @@ -85,7 +85,7 @@ class TestUtil self::appendHelper($m, 'RepeatedDouble', 1.6); self::appendHelper($m, 'RepeatedBool', true); self::appendHelper($m, 'RepeatedString', 'a'); - self::appendHelper($m, 'RepeatedBytes', 'b'); + self::appendHelper($m, 'RepeatedBytes', 'bbbb'); self::appendHelper($m, 'RepeatedEnum', TestEnum::ZERO); self::appendHelper($m, 'RepeatedMessage', new Sub()); $m->getRepeatedMessage()[0]->setA(34); @@ -104,7 +104,7 @@ class TestUtil self::appendHelper($m, 'RepeatedDouble', 2.6); self::appendHelper($m, 'RepeatedBool', false); self::appendHelper($m, 'RepeatedString', 'c'); - self::appendHelper($m, 'RepeatedBytes', 'd'); + self::appendHelper($m, 'RepeatedBytes', 'dddd'); self::appendHelper($m, 'RepeatedEnum', TestEnum::ONE); self::appendHelper($m, 'RepeatedMessage', new Sub()); $m->getRepeatedMessage()[1]->SetA(35); @@ -123,7 +123,7 @@ class TestUtil self::kvUpdateHelper($m, 'MapInt32Double', 1, 3.6); self::kvUpdateHelper($m, 'MapBoolBool', true, true); self::kvUpdateHelper($m, 'MapStringString', 'e', 'e'); - self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'f'); + self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'ffff'); self::kvUpdateHelper($m, 'MapInt32Enum', 1, TestEnum::ONE); self::kvUpdateHelper($m, 'MapInt32Message', 1, new Sub()); $m->getMapInt32Message()[1]->SetA(36); @@ -234,7 +234,7 @@ class TestUtil assert(1.6 === $m->getOptionalDouble()); assert(true=== $m->getOptionalBool()); assert('a' === $m->getOptionalString()); - assert('b' === $m->getOptionalBytes()); + assert('bbbb' === $m->getOptionalBytes()); assert(TestEnum::ONE === $m->getOptionalEnum()); assert(33 === $m->getOptionalMessage()->getA()); @@ -260,7 +260,7 @@ class TestUtil assert(1.6 === $m->getRepeatedDouble()[0]); assert(true=== $m->getRepeatedBool()[0]); assert('a' === $m->getRepeatedString()[0]); - assert('b' === $m->getRepeatedBytes()[0]); + assert('bbbb' === $m->getRepeatedBytes()[0]); assert(TestEnum::ZERO === $m->getRepeatedEnum()[0]); assert(34 === $m->getRepeatedMessage()[0]->getA()); @@ -286,7 +286,7 @@ class TestUtil assert(2.6 === $m->getRepeatedDouble()[1]); assert(false === $m->getRepeatedBool()[1]); assert('c' === $m->getRepeatedString()[1]); - assert('d' === $m->getRepeatedBytes()[1]); + assert('dddd' === $m->getRepeatedBytes()[1]); assert(TestEnum::ONE === $m->getRepeatedEnum()[1]); assert(35 === $m->getRepeatedMessage()[1]->getA()); @@ -312,7 +312,7 @@ class TestUtil assert(3.6 === $m->getMapInt32Double()[1]); assert(true === $m->getMapBoolBool()[true]); assert('e' === $m->getMapStringString()['e']); - assert('f' === $m->getMapInt32Bytes()[1]); + assert('ffff' === $m->getMapInt32Bytes()[1]); assert(TestEnum::ONE === $m->getMapInt32Enum()[1]); assert(36 === $m->getMapInt32Message()[1]->GetA()); } @@ -334,7 +334,7 @@ class TestUtil "619A9999999999F93F" . "6801" . "720161" . - "7A0162" . + "7A0462626262" . "800101" . "8A01020821" . @@ -366,8 +366,8 @@ class TestUtil "D80200" . "E2020161" . "E2020163" . - "EA020162" . - "EA020164" . + "EA020462626262" . + "EA020464646464" . "F00200" . "F00201" . "FA02020822" . @@ -387,7 +387,7 @@ class TestUtil "92050B080111CDCCCCCCCCCC0C40" . "9A050408011001" . "A205060a0165120165" . - "AA05050801120166" . + "AA05080801120466666666" . "B2050408011001" . "Ba0506080112020824" ); From 37a0ab7d83f1a8fb577d405c1201ad42f24f9448 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 17 Jan 2019 10:24:41 -0800 Subject: [PATCH 62/70] Fix Any json encoding/decoding for ruby. (#5592) * Fix Any json encoding/decoding for ruby. * Revert unnecessary changes --- conformance/failure_list_ruby.txt | 23 +- ruby/ext/google/protobuf_c/encode_decode.c | 157 ++- ruby/ext/google/protobuf_c/protobuf.h | 2 + ruby/ext/google/protobuf_c/upb.c | 1315 +++++++++++++++----- ruby/ext/google/protobuf_c/upb.h | 76 +- ruby/tests/encode_decode_test.rb | 16 +- 6 files changed, 1216 insertions(+), 373 deletions(-) diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt index 44f67a9256..651cb55f57 100644 --- a/conformance/failure_list_ruby.txt +++ b/conformance/failure_list_ruby.txt @@ -5,6 +5,7 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator +Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull @@ -18,26 +19,6 @@ Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput -Required.Proto3.JsonInput.Any.JsonOutput -Required.Proto3.JsonInput.Any.ProtobufOutput -Required.Proto3.JsonInput.AnyNested.JsonOutput -Required.Proto3.JsonInput.AnyNested.ProtobufOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.JsonOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.ProtobufOutput -Required.Proto3.JsonInput.AnyWithDuration.JsonOutput -Required.Proto3.JsonInput.AnyWithDuration.ProtobufOutput -Required.Proto3.JsonInput.AnyWithFieldMask.JsonOutput -Required.Proto3.JsonInput.AnyWithFieldMask.ProtobufOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.JsonOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput -Required.Proto3.JsonInput.AnyWithStruct.JsonOutput -Required.Proto3.JsonInput.AnyWithStruct.ProtobufOutput -Required.Proto3.JsonInput.AnyWithTimestamp.JsonOutput -Required.Proto3.JsonInput.AnyWithTimestamp.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput @@ -45,8 +26,6 @@ Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput Required.Proto3.JsonInput.DurationMinValue.JsonOutput Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput -Required.Proto3.JsonInput.FieldMask.JsonOutput -Required.Proto3.JsonInput.FieldMask.ProtobufOutput Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput Required.Proto3.JsonInput.FloatFieldNan.JsonOutput Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index a14f0bc80d..c5078bcb73 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -254,18 +254,13 @@ static size_t stringdata_handler(void* closure, const void* hd, } static bool stringdata_end_handler(void* closure, const void* hd) { - MessageHeader* msg = closure; - const size_t *ofs = hd; - VALUE rb_str = DEREF(msg, *ofs, VALUE); + VALUE rb_str = closure; rb_obj_freeze(rb_str); return true; } static bool appendstring_end_handler(void* closure, const void* hd) { - VALUE ary = (VALUE)closure; - int size = RepeatedField_size(ary); - VALUE* last = RepeatedField_index_native(ary, size - 1); - VALUE rb_str = *last; + VALUE rb_str = closure; rb_obj_freeze(rb_str); return true; } @@ -481,9 +476,8 @@ static void *oneofbytes_handler(void *closure, } static bool oneofstring_end_handler(void* closure, const void* hd) { - MessageHeader* msg = closure; - const oneof_handlerdata_t *oneofdata = hd; - rb_obj_freeze(DEREF(msg, oneofdata->ofs, VALUE)); + VALUE rb_str = rb_str_new2(""); + rb_obj_freeze(rb_str); return true; } @@ -938,10 +932,12 @@ VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { stackenv se; upb_sink sink; upb_json_parser* parser; + DescriptorPool* pool = ruby_to_DescriptorPool(generated_pool); stackenv_init(&se, "Error occurred during parsing: %s"); upb_sink_reset(&sink, get_fill_handlers(desc), msg); - parser = upb_json_parser_create(&se.env, method, &sink, ignore_unknown_fields); + parser = upb_json_parser_create(&se.env, method, pool->symtab, + &sink, ignore_unknown_fields); upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data), upb_json_parser_input(parser)); @@ -958,7 +954,8 @@ VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { /* msgvisitor *****************************************************************/ static void putmsg(VALUE msg, const Descriptor* desc, - upb_sink *sink, int depth, bool emit_defaults); + upb_sink *sink, int depth, bool emit_defaults, + bool is_json, bool open_msg); static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) { upb_selector_t ret; @@ -990,7 +987,7 @@ static void putstr(VALUE str, const upb_fielddef *f, upb_sink *sink) { } static void putsubmsg(VALUE submsg, const upb_fielddef *f, upb_sink *sink, - int depth, bool emit_defaults) { + int depth, bool emit_defaults, bool is_json) { upb_sink subsink; VALUE descriptor; Descriptor* subdesc; @@ -1001,12 +998,12 @@ static void putsubmsg(VALUE submsg, const upb_fielddef *f, upb_sink *sink, subdesc = ruby_to_Descriptor(descriptor); upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink); - putmsg(submsg, subdesc, &subsink, depth + 1, emit_defaults); + putmsg(submsg, subdesc, &subsink, depth + 1, emit_defaults, is_json, true); upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG)); } static void putary(VALUE ary, const upb_fielddef *f, upb_sink *sink, - int depth, bool emit_defaults) { + int depth, bool emit_defaults, bool is_json) { upb_sink subsink; upb_fieldtype_t type = upb_fielddef_type(f); upb_selector_t sel = 0; @@ -1046,7 +1043,8 @@ static void putary(VALUE ary, const upb_fielddef *f, upb_sink *sink, putstr(*((VALUE *)memory), f, &subsink); break; case UPB_TYPE_MESSAGE: - putsubmsg(*((VALUE *)memory), f, &subsink, depth, emit_defaults); + putsubmsg(*((VALUE *)memory), f, &subsink, depth, + emit_defaults, is_json); break; #undef T @@ -1061,7 +1059,8 @@ static void put_ruby_value(VALUE value, VALUE type_class, int depth, upb_sink *sink, - bool emit_defaults) { + bool emit_defaults, + bool is_json) { upb_selector_t sel = 0; if (upb_fielddef_isprimitive(f)) { sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); @@ -1101,12 +1100,12 @@ static void put_ruby_value(VALUE value, putstr(value, f, sink); break; case UPB_TYPE_MESSAGE: - putsubmsg(value, f, sink, depth, emit_defaults); + putsubmsg(value, f, sink, depth, emit_defaults, is_json); } } static void putmap(VALUE map, const upb_fielddef *f, upb_sink *sink, - int depth, bool emit_defaults) { + int depth, bool emit_defaults, bool is_json) { Map* self; upb_sink subsink; const upb_fielddef* key_field; @@ -1134,9 +1133,10 @@ static void putmap(VALUE map, const upb_fielddef *f, upb_sink *sink, &entry_sink); upb_sink_startmsg(&entry_sink); - put_ruby_value(key, key_field, Qnil, depth + 1, &entry_sink, emit_defaults); + put_ruby_value(key, key_field, Qnil, depth + 1, &entry_sink, + emit_defaults, is_json); put_ruby_value(value, value_field, self->value_type_class, depth + 1, - &entry_sink, emit_defaults); + &entry_sink, emit_defaults, is_json); upb_sink_endmsg(&entry_sink, &status); upb_sink_endsubmsg(&subsink, getsel(f, UPB_HANDLER_ENDSUBMSG)); @@ -1145,13 +1145,108 @@ static void putmap(VALUE map, const upb_fielddef *f, upb_sink *sink, upb_sink_endseq(sink, getsel(f, UPB_HANDLER_ENDSEQ)); } +static const upb_handlers* msgdef_json_serialize_handlers( + Descriptor* desc, bool preserve_proto_fieldnames); + +static void putjsonany(VALUE msg_rb, const Descriptor* desc, + upb_sink* sink, int depth, bool emit_defaults) { + upb_status status; + MessageHeader* msg = NULL; + const upb_fielddef* type_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_TYPE); + const upb_fielddef* value_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_VALUE); + + size_t type_url_offset; + VALUE type_url_str_rb; + const upb_msgdef *payload_type = NULL; + + TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); + + upb_sink_startmsg(sink); + + /* Handle type url */ + type_url_offset = desc->layout->fields[upb_fielddef_index(type_field)].offset; + type_url_str_rb = DEREF(Message_data(msg), type_url_offset, VALUE); + if (RSTRING_LEN(type_url_str_rb) > 0) { + putstr(type_url_str_rb, type_field, sink); + } + + { + const char* type_url_str = RSTRING_PTR(type_url_str_rb); + size_t type_url_len = RSTRING_LEN(type_url_str_rb); + DescriptorPool* pool = ruby_to_DescriptorPool(generated_pool); + + if (type_url_len <= 20 || + strncmp(type_url_str, "type.googleapis.com/", 20) != 0) { + rb_raise(rb_eRuntimeError, "Invalid type url: %s", type_url_str); + return; + } + + /* Resolve type url */ + type_url_str += 20; + type_url_len -= 20; + + payload_type = upb_symtab_lookupmsg2( + pool->symtab, type_url_str, type_url_len); + if (payload_type == NULL) { + rb_raise(rb_eRuntimeError, "Unknown type: %s", type_url_str); + return; + } + } + + { + uint32_t value_offset; + VALUE value_str_rb; + const char* value_str; + size_t value_len; + + value_offset = desc->layout->fields[upb_fielddef_index(value_field)].offset; + value_str_rb = DEREF(Message_data(msg), value_offset, VALUE); + value_str = RSTRING_PTR(value_str_rb); + value_len = RSTRING_LEN(value_str_rb); + + if (value_len > 0) { + VALUE payload_desc_rb = get_def_obj(payload_type); + Descriptor* payload_desc = ruby_to_Descriptor(payload_desc_rb); + VALUE payload_class = Descriptor_msgclass(payload_desc_rb); + upb_sink subsink; + bool is_wellknown; + + VALUE payload_msg_rb = Message_decode(payload_class, value_str_rb); + + is_wellknown = + upb_msgdef_wellknowntype(payload_desc->msgdef) != + UPB_WELLKNOWN_UNSPECIFIED; + if (is_wellknown) { + upb_sink_startstr(sink, getsel(value_field, UPB_HANDLER_STARTSTR), 0, + &subsink); + } + + subsink.handlers = + msgdef_json_serialize_handlers(payload_desc, true); + subsink.closure = sink->closure; + putmsg(payload_msg_rb, payload_desc, &subsink, depth, emit_defaults, true, + is_wellknown); + } + } + + upb_sink_endmsg(sink, &status); +} + static void putmsg(VALUE msg_rb, const Descriptor* desc, - upb_sink *sink, int depth, bool emit_defaults) { + upb_sink *sink, int depth, bool emit_defaults, + bool is_json, bool open_msg) { MessageHeader* msg; upb_msg_field_iter i; upb_status status; - upb_sink_startmsg(sink); + if (is_json && upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) { + putjsonany(msg_rb, desc, sink, depth, emit_defaults); + return; + } + + if (open_msg) { + upb_sink_startmsg(sink); + } // Protect against cycles (possible because users may freely reassign message // and repeated fields) by imposing a maximum recursion depth. @@ -1196,12 +1291,12 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, if (is_map_field(f)) { VALUE map = DEREF(msg, offset, VALUE); if (map != Qnil || emit_defaults) { - putmap(map, f, sink, depth, emit_defaults); + putmap(map, f, sink, depth, emit_defaults, is_json); } } else if (upb_fielddef_isseq(f)) { VALUE ary = DEREF(msg, offset, VALUE); if (ary != Qnil) { - putary(ary, f, sink, depth, emit_defaults); + putary(ary, f, sink, depth, emit_defaults, is_json); } } else if (upb_fielddef_isstring(f)) { VALUE str = DEREF(msg, offset, VALUE); @@ -1217,7 +1312,8 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, putstr(str, f, sink); } } else if (upb_fielddef_issubmsg(f)) { - putsubmsg(DEREF(msg, offset, VALUE), f, sink, depth, emit_defaults); + putsubmsg(DEREF(msg, offset, VALUE), f, sink, depth, + emit_defaults, is_json); } else { upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); @@ -1261,7 +1357,9 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, upb_sink_putunknown(sink, unknown->ptr, unknown->len); } - upb_sink_endmsg(sink, &status); + if (open_msg) { + upb_sink_endmsg(sink, &status); + } } static const upb_handlers* msgdef_pb_serialize_handlers(Descriptor* desc) { @@ -1316,7 +1414,7 @@ VALUE Message_encode(VALUE klass, VALUE msg_rb) { stackenv_init(&se, "Error occurred during encoding: %s"); encoder = upb_pb_encoder_create(&se.env, serialize_handlers, &sink.sink); - putmsg(msg_rb, desc, upb_pb_encoder_input(encoder), 0, false); + putmsg(msg_rb, desc, upb_pb_encoder_input(encoder), 0, false, false, true); ret = rb_str_new(sink.ptr, sink.len); @@ -1374,7 +1472,8 @@ VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { stackenv_init(&se, "Error occurred during encoding: %s"); printer = upb_json_printer_create(&se.env, serialize_handlers, &sink.sink); - putmsg(msg_rb, desc, upb_json_printer_input(printer), 0, RTEST(emit_defaults)); + putmsg(msg_rb, desc, upb_json_printer_input(printer), 0, + RTEST(emit_defaults), true, true); ret = rb_enc_str_new(sink.ptr, sink.len, rb_utf8_encoding()); diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 616947c251..eff212e1a7 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -196,6 +196,8 @@ VALUE DescriptorPool_build(int argc, VALUE* argv, VALUE _self); VALUE DescriptorPool_lookup(VALUE _self, VALUE name); VALUE DescriptorPool_generated_pool(VALUE _self); +extern VALUE generated_pool; + void Descriptor_mark(void* _self); void Descriptor_free(void* _self); VALUE Descriptor_alloc(VALUE klass); diff --git a/ruby/ext/google/protobuf_c/upb.c b/ruby/ext/google/protobuf_c/upb.c index 049e2bb061..b001d7a591 100644 --- a/ruby/ext/google/protobuf_c/upb.c +++ b/ruby/ext/google/protobuf_c/upb.c @@ -1458,7 +1458,11 @@ static void assign_msg_wellknowntype(upb_msgdef *m) { m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; return; } - if (!strcmp(name, "google.protobuf.Duration")) { + if (!strcmp(name, "google.protobuf.Any")) { + m->well_known_type = UPB_WELLKNOWN_ANY; + } else if (!strcmp(name, "google.protobuf.FieldMask")) { + m->well_known_type = UPB_WELLKNOWN_FIELDMASK; + } else if (!strcmp(name, "google.protobuf.Duration")) { m->well_known_type = UPB_WELLKNOWN_DURATION; } else if (!strcmp(name, "google.protobuf.Timestamp")) { m->well_known_type = UPB_WELLKNOWN_TIMESTAMP; @@ -3233,6 +3237,14 @@ const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { return def ? upb_dyncast_msgdef(def) : NULL; } +const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym, + size_t len) { + upb_value v; + upb_def *def = upb_strtable_lookup2(&s->symtab, sym, len, &v) ? + upb_value_getptr(v) : NULL; + return def ? upb_dyncast_msgdef(def) : NULL; +} + const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) { upb_value v; upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ? @@ -5451,6 +5463,29 @@ const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, return l; } } + +#if UINTPTR_MAX == 0xffffffff +#define UPB_SIZE(size32, size64) size32 +#else +#define UPB_SIZE(size32, size64) size64 +#endif + +#define UPB_FIELD_AT(msg, fieldtype, offset) \ + *(fieldtype*)((const char*)(msg) + offset) + +#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) \ + : 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; + +#undef UPB_SIZE +#undef UPB_FIELD_AT +#undef UPB_READ_ONEOF +#undef UPB_WRITE_ONEOF /* ** upb::RefCounted Implementation ** @@ -10109,8 +10144,8 @@ static void generate_delimfield(compiler *c, const upb_fielddef *f, putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR)); /* Need to emit even if no handler to skip past the string. */ putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING)); - putop(c, OP_POP); maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR); + putop(c, OP_POP); putop(c, OP_SETDELIM); putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK); putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_LOOPBREAK); @@ -10125,8 +10160,8 @@ static void generate_delimfield(compiler *c, const upb_fielddef *f, putop(c, OP_PUSHLENDELIM); putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR)); putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING)); - putop(c, OP_POP); maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR); + putop(c, OP_POP); putop(c, OP_SETDELIM); } } @@ -12546,7 +12581,7 @@ done: return r; } -//#line 1 "upb/json/parser.rl" +#line 1 "upb/json/parser.rl" /* ** upb::json::Parser (upb_json_parser) ** @@ -12608,6 +12643,12 @@ static bool is_string_wrapper_object(upb_json_parser *p); static bool does_string_wrapper_start(upb_json_parser *p); static bool does_string_wrapper_end(upb_json_parser *p); +static bool is_fieldmask_object(upb_json_parser *p); +static bool does_fieldmask_start(upb_json_parser *p); +static bool does_fieldmask_end(upb_json_parser *p); +static void start_fieldmask_object(upb_json_parser *p); +static void end_fieldmask_object(upb_json_parser *p); + static void start_wrapper_object(upb_json_parser *p); static void end_wrapper_object(upb_json_parser *p); @@ -12623,6 +12664,9 @@ static void end_structvalue_object(upb_json_parser *p); static void start_object(upb_json_parser *p); static void end_object(upb_json_parser *p); +static void start_any_object(upb_json_parser *p, const char *ptr); +static bool end_any_object(upb_json_parser *p, const char *ptr); + static bool start_subobject(upb_json_parser *p); static void end_subobject(upb_json_parser *p); @@ -12630,8 +12674,89 @@ static void start_member(upb_json_parser *p); static void end_member(upb_json_parser *p); static bool end_membername(upb_json_parser *p); +static void start_any_member(upb_json_parser *p, const char *ptr); +static void end_any_member(upb_json_parser *p, const char *ptr); +static bool end_any_membername(upb_json_parser *p); + +size_t parse(void *closure, const void *hd, const char *buf, size_t size, + const upb_bufhandle *handle); +static bool end(void *closure, const void *hd); + static const char eof_ch = 'e'; +/* stringsink */ +typedef struct { + upb_byteshandler handler; + upb_bytessink sink; + char *ptr; + size_t len, size; +} upb_stringsink; + + +static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) { + upb_stringsink *sink = _sink; + sink->len = 0; + UPB_UNUSED(hd); + UPB_UNUSED(size_hint); + return sink; +} + +static size_t stringsink_string(void *_sink, const void *hd, const char *ptr, + size_t len, const upb_bufhandle *handle) { + upb_stringsink *sink = _sink; + size_t new_size = sink->size; + + UPB_UNUSED(hd); + UPB_UNUSED(handle); + + while (sink->len + len > new_size) { + new_size *= 2; + } + + if (new_size != sink->size) { + sink->ptr = realloc(sink->ptr, new_size); + sink->size = new_size; + } + + memcpy(sink->ptr + sink->len, ptr, len); + sink->len += len; + + return len; +} + +void upb_stringsink_init(upb_stringsink *sink) { + upb_byteshandler_init(&sink->handler); + upb_byteshandler_setstartstr(&sink->handler, stringsink_start, NULL); + upb_byteshandler_setstring(&sink->handler, stringsink_string, NULL); + + upb_bytessink_reset(&sink->sink, &sink->handler, sink); + + sink->size = 32; + sink->ptr = malloc(sink->size); + sink->len = 0; +} + +void upb_stringsink_uninit(upb_stringsink *sink) { free(sink->ptr); } + +typedef struct { + /* For encoding Any value field in binary format. */ + const upb_handlers *encoder_handlers; + upb_pb_encoder *encoder; + upb_stringsink stringsink; + + /* For decoding Any value field in json format. */ + upb_json_parsermethod *parser_method; + upb_json_parser* parser; + upb_sink sink; + + /* Mark the range of uninterpreted values in json input before type url. */ + const char *before_type_url_start; + const char *before_type_url_end; + + /* Mark the range of uninterpreted values in json input after type url. */ + const char *after_type_url_start; +} upb_jsonparser_any_frame; + typedef struct { upb_sink sink; @@ -12660,6 +12785,15 @@ typedef struct { * message itself), not the parent's field that leads to this map. */ const upb_fielddef *mapfield; + /* We are in an Any message context. This flag is set when parsing the Any + * message and indicates to all field parsers (subobjects, strings, numbers, + * and bools) that the parsed field should be serialized as binary data or + * cached (type url not found yet). */ + bool is_any; + + /* The type of packed message in Any. */ + upb_jsonparser_any_frame *any_frame; + /* True if the field to be parsed is unknown. */ bool is_unknown_field; } upb_jsonparser_frame; @@ -12700,6 +12834,9 @@ struct upb_json_parser { /* Intermediate result of parsing a unicode escape sequence. */ uint32_t digit; + /* For resolve type url in Any. */ + const upb_symtab *symtab; + /* Whether to proceed if unknown field is met. */ bool ignore_json_unknown; @@ -12723,6 +12860,84 @@ struct upb_json_parsermethod { #define PARSER_CHECK_RETURN(x) if (!(x)) return false +static void json_parser_any_frame_reset(upb_jsonparser_any_frame *frame) { + frame->encoder_handlers = NULL; + frame->encoder = NULL; + frame->parser_method = NULL; + frame->parser = NULL; + frame->before_type_url_start = NULL; + frame->before_type_url_end = NULL; + frame->after_type_url_start = NULL; +} + +static void json_parser_any_frame_set_payload_type( + upb_json_parser *p, + upb_jsonparser_any_frame *frame, + const upb_msgdef *payload_type) { + /* Initialize encoder. */ + frame->encoder_handlers = + upb_pb_encoder_newhandlers(payload_type, &frame->encoder_handlers); + upb_stringsink_init(&frame->stringsink); + frame->encoder = + upb_pb_encoder_create( + p->env, frame->encoder_handlers, + &frame->stringsink.sink); + + /* Initialize parser. */ + frame->parser_method = + upb_json_parsermethod_new(payload_type, &frame->parser_method); + upb_sink_reset(&frame->sink, frame->encoder_handlers, frame->encoder); + frame->parser = + upb_json_parser_create(p->env, frame->parser_method, p->symtab, + &frame->sink, p->ignore_json_unknown); +} + +static void json_parser_any_frame_free(upb_jsonparser_any_frame *frame) { + upb_handlers_unref(frame->encoder_handlers, + &frame->encoder_handlers); + upb_json_parsermethod_unref(frame->parser_method, + &frame->parser_method); + upb_stringsink_uninit(&frame->stringsink); +} + +static bool json_parser_any_frame_has_type_url( + upb_jsonparser_any_frame *frame) { + return frame->encoder != NULL; +} + +static bool json_parser_any_frame_has_value_before_type_url( + upb_jsonparser_any_frame *frame) { + return frame->before_type_url_start != frame->before_type_url_end; +} + +static bool json_parser_any_frame_has_value_after_type_url( + upb_jsonparser_any_frame *frame) { + return frame->after_type_url_start != NULL; +} + +static bool json_parser_any_frame_has_value( + upb_jsonparser_any_frame *frame) { + return json_parser_any_frame_has_value_before_type_url(frame) || + json_parser_any_frame_has_value_after_type_url(frame); +} + +static void json_parser_any_frame_set_before_type_url_end( + upb_jsonparser_any_frame *frame, + const char *ptr) { + if (frame->encoder == NULL) { + frame->before_type_url_end = ptr; + } +} + +static void json_parser_any_frame_set_after_type_url_start_once( + upb_jsonparser_any_frame *frame, + const char *ptr) { + if (json_parser_any_frame_has_type_url(frame) && + frame->after_type_url_start == NULL) { + frame->after_type_url_start = ptr; + } +} + /* Used to signal that a capture has been suspended. */ static char suspend_capture; @@ -13526,10 +13741,18 @@ static bool end_null(upb_json_parser *p) { return true; } +static bool start_any_stringval(upb_json_parser *p) { + multipart_startaccum(p); + return true; +} + static bool start_stringval(upb_json_parser *p) { if (is_top_level(p)) { if (is_string_wrapper_object(p)) { start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_FIELDMASK)) { + start_fieldmask_object(p); + return true; } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { start_object(p); @@ -13543,6 +13766,12 @@ static bool start_stringval(upb_json_parser *p) { return false; } start_wrapper_object(p); + } else if (does_fieldmask_start(p)) { + if (!start_subobject(p)) { + return false; + } + start_fieldmask_object(p); + return true; } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) || is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) { if (!start_subobject(p)) { @@ -13561,6 +13790,10 @@ static bool start_stringval(upb_json_parser *p) { return true; } + if (p->top->is_any) { + return start_any_stringval(p); + } + if (upb_fielddef_isstring(p->top->f)) { upb_jsonparser_frame *inner; upb_selector_t sel; @@ -13577,6 +13810,8 @@ static bool start_stringval(upb_json_parser *p) { inner->name_table = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; @@ -13608,6 +13843,50 @@ static bool start_stringval(upb_json_parser *p) { } } +static bool end_any_stringval(upb_json_parser *p) { + size_t len; + const char *buf = accumulate_getptr(p, &len); + + /* Set type_url */ + upb_selector_t sel; + upb_jsonparser_frame *inner; + if (!check_stack(p)) return false; + inner = p->top + 1; + + sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); + upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); + sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); + upb_sink_putstring(&inner->sink, sel, buf, len, NULL); + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + upb_sink_endstr(&inner->sink, sel); + + multipart_end(p); + + /* Resolve type url */ + if (strncmp(buf, "type.googleapis.com/", 20) == 0 && len > 20) { + const upb_msgdef *payload_type = NULL; + buf += 20; + len -= 20; + + payload_type = upb_symtab_lookupmsg2(p->symtab, buf, len); + if (payload_type == NULL) { + upb_status_seterrf( + &p->status, "Cannot find packed type: %.*s\n", (int)len, buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + json_parser_any_frame_set_payload_type(p, p->top->any_frame, payload_type); + + return true; + } else { + upb_status_seterrf( + &p->status, "Invalid type url: %.*s\n", (int)len, buf); + upb_env_reporterror(p->env, &p->status); + return false; + } +} + static bool end_stringval_nontop(upb_json_parser *p) { bool ok = true; @@ -13622,6 +13901,10 @@ static bool end_stringval_nontop(upb_json_parser *p) { return true; } + if (p->top->is_any) { + return end_any_stringval(p); + } + switch (upb_fielddef_type(p->top->f)) { case UPB_TYPE_BYTES: if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), @@ -13632,8 +13915,8 @@ static bool end_stringval_nontop(upb_json_parser *p) { case UPB_TYPE_STRING: { upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); - p->top--; upb_sink_endstr(&p->top->sink, sel); + p->top--; break; } @@ -13682,6 +13965,16 @@ static bool end_stringval_nontop(upb_json_parser *p) { } static bool end_stringval(upb_json_parser *p) { + /* FieldMask's stringvals have been ended when handling them. Only need to + * close FieldMask here.*/ + if (does_fieldmask_end(p)) { + end_fieldmask_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + if (!end_stringval_nontop(p)) { return false; } @@ -13703,7 +13996,8 @@ static bool end_stringval(upb_json_parser *p) { } if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || - is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION) || + is_wellknown_msg(p, UPB_WELLKNOWN_FIELDMASK)) { end_object(p); if (!is_top_level(p)) { end_subobject(p); @@ -13966,6 +14260,75 @@ static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) { return true; } +static void start_fieldmask_path_text(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +static bool end_fieldmask_path_text(upb_json_parser *p, const char *ptr) { + if (!capture_end(p, ptr)) { + return false; + } +} + +static bool start_fieldmask_path(upb_json_parser *p) { + upb_jsonparser_frame *inner; + upb_selector_t sel; + + if (!check_stack(p)) return false; + + /* Start a new parser frame: parser frames correspond one-to-one with + * handler frames, and string events occur in a sub-frame. */ + inner = p->top + 1; + sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); + upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); + inner->m = p->top->m; + inner->f = p->top->f; + inner->name_table = NULL; + inner->is_map = false; + inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; + inner->is_unknown_field = false; + p->top = inner; + + multipart_startaccum(p); + return true; +} + +static bool lower_camel_push( + upb_json_parser *p, upb_selector_t sel, const char *ptr, size_t len) { + const char *limit = ptr + len; + bool first = true; + for (;ptr < limit; ptr++) { + if (*ptr >= 'A' && *ptr <= 'Z' && !first) { + char lower = tolower(*ptr); + upb_sink_putstring(&p->top->sink, sel, "_", 1, NULL); + upb_sink_putstring(&p->top->sink, sel, &lower, 1, NULL); + } else { + upb_sink_putstring(&p->top->sink, sel, ptr, 1, NULL); + } + first = false; + } + return true; +} + +static bool end_fieldmask_path(upb_json_parser *p) { + upb_selector_t sel; + + if (!lower_camel_push( + p, getsel_for_handlertype(p, UPB_HANDLER_STRING), + p->accumulated, p->accumulated_len)) { + return false; + } + + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + upb_sink_endstr(&p->top->sink, sel); + p->top--; + + multipart_end(p); + return true; +} + static void start_member(upb_json_parser *p) { UPB_ASSERT(!p->top->f); multipart_startaccum(p); @@ -14025,7 +14388,7 @@ static bool parse_mapentry_key(upb_json_parser *p) { sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); upb_sink_putstring(&subsink, sel, buf, len, NULL); sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); - upb_sink_endstr(&p->top->sink, sel); + upb_sink_endstr(&subsink, sel); multipart_end(p); break; } @@ -14069,6 +14432,8 @@ static bool handle_mapentry(upb_json_parser *p) { inner->name_table = NULL; inner->mapfield = mapfield; inner->is_map = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; /* Don't set this to true *yet* -- we reuse parsing handlers below to push @@ -14105,7 +14470,9 @@ static bool end_membername(upb_json_parser *p) { return true; } - if (p->top->is_map) { + if (p->top->is_any) { + return end_any_membername(p); + } else if (p->top->is_map) { return handle_mapentry(p); } else { size_t len; @@ -14129,6 +14496,23 @@ static bool end_membername(upb_json_parser *p) { } } +static bool end_any_membername(upb_json_parser *p) { + size_t len; + const char *buf = accumulate_getptr(p, &len); + upb_value v; + + if (len == 5 && strncmp(buf, "@type", len) == 0) { + upb_strtable_lookup2(p->top->name_table, "type_url", 8, &v); + p->top->f = upb_value_getconstptr(v); + multipart_end(p); + return true; + } else { + p->top->is_unknown_field = true; + multipart_end(p); + return true; + } +} + static void end_member(upb_json_parser *p) { /* If we just parsed a map-entry value, end that frame too. */ if (p->top->is_mapentry) { @@ -14153,6 +14537,16 @@ static void end_member(upb_json_parser *p) { p->top->is_unknown_field = false; } +static void start_any_member(upb_json_parser *p, const char *ptr) { + start_member(p); + json_parser_any_frame_set_after_type_url_start_once(p->top->any_frame, ptr); +} + +static void end_any_member(upb_json_parser *p, const char *ptr) { + json_parser_any_frame_set_before_type_url_end(p->top->any_frame, ptr); + end_member(p); +} + static bool start_subobject(upb_json_parser *p) { if (p->top->is_unknown_field) { upb_jsonparser_frame *inner; @@ -14163,6 +14557,8 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; return true; @@ -14185,6 +14581,8 @@ static bool start_subobject(upb_json_parser *p) { inner->f = NULL; inner->is_map = true; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; @@ -14209,6 +14607,16 @@ static bool start_subobject(upb_json_parser *p) { inner->is_unknown_field = false; p->top = inner; + if (is_wellknown_msg(p, UPB_WELLKNOWN_ANY)) { + p->top->is_any = true; + p->top->any_frame = + upb_env_malloc(p->env, sizeof(upb_jsonparser_any_frame)); + json_parser_any_frame_reset(p->top->any_frame); + } else { + p->top->is_any = false; + p->top->any_frame = NULL; + } + return true; } else { upb_status_seterrf(&p->status, @@ -14313,6 +14721,8 @@ static bool start_array(upb_json_parser *p) { inner->f = NULL; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = true; p->top = inner; @@ -14337,6 +14747,8 @@ static bool start_array(upb_json_parser *p) { inner->f = p->top->f; inner->is_map = false; inner->is_mapentry = false; + inner->is_any = false; + inner->any_frame = NULL; inner->is_unknown_field = false; p->top = inner; @@ -14389,12 +14801,160 @@ static void end_object(upb_json_parser *p) { } } +static void start_any_object(upb_json_parser *p, const char *ptr) { + start_object(p); + p->top->any_frame->before_type_url_start = ptr; + p->top->any_frame->before_type_url_end = ptr; +} + +static bool end_any_object(upb_json_parser *p, const char *ptr) { + const char *value_membername = "value"; + bool is_well_known_packed = false; + const char *packed_end = ptr + 1; + upb_selector_t sel; + upb_jsonparser_frame *inner; + + if (json_parser_any_frame_has_value(p->top->any_frame) && + !json_parser_any_frame_has_type_url(p->top->any_frame)) { + upb_status_seterrmsg(&p->status, "No valid type url"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Well known types data is represented as value field. */ + if (upb_msgdef_wellknowntype(p->top->any_frame->parser->top->m) != + UPB_WELLKNOWN_UNSPECIFIED) { + is_well_known_packed = true; + + if (json_parser_any_frame_has_value_before_type_url(p->top->any_frame)) { + p->top->any_frame->before_type_url_start = + memchr(p->top->any_frame->before_type_url_start, ':', + p->top->any_frame->before_type_url_end - + p->top->any_frame->before_type_url_start); + if (p->top->any_frame->before_type_url_start == NULL) { + upb_status_seterrmsg(&p->status, "invalid data for well known type."); + upb_env_reporterror(p->env, &p->status); + return false; + } + p->top->any_frame->before_type_url_start++; + } + + if (json_parser_any_frame_has_value_after_type_url(p->top->any_frame)) { + p->top->any_frame->after_type_url_start = + memchr(p->top->any_frame->after_type_url_start, ':', + (ptr + 1) - + p->top->any_frame->after_type_url_start); + if (p->top->any_frame->after_type_url_start == NULL) { + upb_status_seterrmsg(&p->status, "Invalid data for well known type."); + upb_env_reporterror(p->env, &p->status); + return false; + } + p->top->any_frame->after_type_url_start++; + packed_end = ptr; + } + } + + if (json_parser_any_frame_has_value_before_type_url(p->top->any_frame)) { + if (!parse(p->top->any_frame->parser, NULL, + p->top->any_frame->before_type_url_start, + p->top->any_frame->before_type_url_end - + p->top->any_frame->before_type_url_start, NULL)) { + return false; + } + } else { + if (!is_well_known_packed) { + if (!parse(p->top->any_frame->parser, NULL, "{", 1, NULL)) { + return false; + } + } + } + + if (json_parser_any_frame_has_value_before_type_url(p->top->any_frame) && + json_parser_any_frame_has_value_after_type_url(p->top->any_frame)) { + if (!parse(p->top->any_frame->parser, NULL, ",", 1, NULL)) { + return false; + } + } + + if (json_parser_any_frame_has_value_after_type_url(p->top->any_frame)) { + if (!parse(p->top->any_frame->parser, NULL, + p->top->any_frame->after_type_url_start, + packed_end - p->top->any_frame->after_type_url_start, NULL)) { + return false; + } + } else { + if (!is_well_known_packed) { + if (!parse(p->top->any_frame->parser, NULL, "}", 1, NULL)) { + return false; + } + } + } + + if (!end(p->top->any_frame->parser, NULL)) { + return false; + } + + p->top->is_any = false; + + /* Set value */ + start_member(p); + capture_begin(p, value_membername); + capture_end(p, value_membername + 5); + end_membername(p); + + if (!check_stack(p)) return false; + inner = p->top + 1; + + sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); + upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); + sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); + upb_sink_putstring(&inner->sink, sel, p->top->any_frame->stringsink.ptr, + p->top->any_frame->stringsink.len, NULL); + sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); + upb_sink_endstr(&inner->sink, sel); + + end_member(p); + + end_object(p); + + /* Deallocate any parse frame. */ + json_parser_any_frame_free(p->top->any_frame); + upb_env_free(p->env, p->top->any_frame); + + return true; +} + static bool is_string_wrapper(const upb_msgdef *m) { upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); return type == UPB_WELLKNOWN_STRINGVALUE || type == UPB_WELLKNOWN_BYTESVALUE; } +static bool is_fieldmask(const upb_msgdef *m) { + upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); + return type == UPB_WELLKNOWN_FIELDMASK; +} + +static void start_fieldmask_object(upb_json_parser *p) { + const char *membername = "paths"; + + start_object(p); + + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + 5); + end_membername(p); + + start_array(p); +} + +static void end_fieldmask_object(upb_json_parser *p) { + end_array(p); + end_member(p); + end_object(p); +} + static void start_wrapper_object(upb_json_parser *p) { const char *membername = "value"; @@ -14533,6 +15093,20 @@ static bool is_string_wrapper_object(upb_json_parser *p) { return p->top->m != NULL && is_string_wrapper(p->top->m); } +static bool does_fieldmask_start(upb_json_parser *p) { + return p->top->f != NULL && + upb_fielddef_issubmsg(p->top->f) && + is_fieldmask(upb_fielddef_msgsubdef(p->top->f)); +} + +static bool does_fieldmask_end(upb_json_parser *p) { + return p->top->m != NULL && is_fieldmask(p->top->m); +} + +static bool is_fieldmask_object(upb_json_parser *p) { + return p->top->m != NULL && is_fieldmask(p->top->m); +} + #define CHECK_RETURN_TOP(x) if (!(x)) goto error @@ -14554,44 +15128,45 @@ static bool is_string_wrapper_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -//#line 2147 "upb/json/parser.rl" +#line 2730 "upb/json/parser.rl" -//#line 2016 "upb/json/parser.c" +#line 2556 "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, 9, 1, 10, 1, 11, 1, 12, 1, - 13, 1, 21, 1, 23, 1, 24, 1, - 25, 1, 27, 1, 28, 1, 30, 1, - 32, 1, 33, 1, 34, 1, 35, 1, - 36, 1, 38, 2, 4, 9, 2, 5, - 6, 2, 7, 3, 2, 7, 9, 2, - 14, 15, 2, 16, 17, 2, 18, 19, - 2, 22, 20, 2, 26, 37, 2, 29, - 2, 2, 30, 38, 2, 31, 20, 2, - 33, 38, 2, 34, 38, 2, 35, 38, - 3, 25, 22, 20, 3, 26, 37, 38, - 4, 14, 15, 16, 17 + 13, 1, 24, 1, 26, 1, 28, 1, + 29, 1, 31, 1, 32, 1, 33, 1, + 35, 1, 37, 1, 38, 1, 39, 1, + 40, 1, 42, 1, 43, 2, 4, 9, + 2, 5, 6, 2, 7, 3, 2, 7, + 9, 2, 14, 15, 2, 16, 17, 2, + 18, 19, 2, 21, 23, 2, 22, 20, + 2, 27, 25, 2, 29, 31, 2, 34, + 2, 2, 35, 43, 2, 36, 25, 2, + 38, 43, 2, 39, 43, 2, 40, 43, + 2, 41, 30, 2, 42, 43, 3, 21, + 23, 24, 4, 14, 15, 16, 17 }; static const short _json_key_offsets[] = { 0, 0, 12, 13, 18, 23, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, - 38, 43, 48, 49, 53, 58, 63, 68, - 72, 76, 79, 82, 84, 88, 92, 94, - 96, 101, 103, 105, 114, 120, 126, 132, - 138, 140, 144, 147, 149, 151, 154, 155, - 159, 161, 163, 165, 167, 168, 170, 172, - 173, 175, 177, 178, 180, 182, 183, 185, - 187, 188, 190, 192, 196, 198, 200, 201, - 202, 203, 204, 206, 211, 220, 221, 221, - 221, 226, 231, 236, 237, 238, 239, 240, - 240, 241, 242, 243, 243, 244, 245, 246, - 246, 251, 256, 257, 261, 266, 271, 276, - 280, 280, 283, 286, 289, 292, 295, 298, - 298, 298, 298, 298 + 38, 43, 44, 48, 53, 58, 63, 67, + 71, 74, 77, 79, 83, 87, 89, 91, + 96, 98, 100, 109, 115, 121, 127, 133, + 135, 139, 142, 144, 146, 149, 150, 154, + 156, 158, 160, 162, 163, 165, 167, 168, + 170, 172, 173, 175, 177, 178, 180, 182, + 183, 185, 187, 191, 193, 195, 196, 197, + 198, 199, 201, 206, 208, 210, 212, 221, + 222, 222, 222, 227, 232, 237, 238, 239, + 240, 241, 241, 242, 243, 244, 244, 245, + 246, 247, 247, 252, 253, 257, 262, 267, + 272, 276, 276, 279, 282, 285, 288, 291, + 294, 294, 294, 294, 294, 294 }; static const char _json_trans_keys[] = { @@ -14600,93 +15175,92 @@ static const char _json_trans_keys[] = { 9, 13, 32, 44, 93, 9, 13, 32, 93, 125, 9, 13, 97, 108, 115, 101, 117, 108, 108, 114, 117, 101, 32, 34, - 125, 9, 13, 32, 34, 125, 9, 13, - 34, 32, 58, 9, 13, 32, 93, 125, + 125, 9, 13, 34, 32, 58, 9, 13, + 32, 93, 125, 9, 13, 32, 44, 125, 9, 13, 32, 44, 125, 9, 13, 32, - 44, 125, 9, 13, 32, 34, 9, 13, - 45, 48, 49, 57, 48, 49, 57, 46, - 69, 101, 48, 57, 69, 101, 48, 57, - 43, 45, 48, 57, 48, 57, 48, 57, - 46, 69, 101, 48, 57, 34, 92, 34, - 92, 34, 47, 92, 98, 102, 110, 114, - 116, 117, 48, 57, 65, 70, 97, 102, - 48, 57, 65, 70, 97, 102, 48, 57, - 65, 70, 97, 102, 48, 57, 65, 70, - 97, 102, 34, 92, 45, 48, 49, 57, - 48, 49, 57, 46, 115, 48, 57, 115, - 48, 57, 34, 46, 115, 48, 57, 48, - 57, 48, 57, 48, 57, 48, 57, 45, - 48, 57, 48, 57, 45, 48, 57, 48, - 57, 84, 48, 57, 48, 57, 58, 48, - 57, 48, 57, 58, 48, 57, 48, 57, - 43, 45, 46, 90, 48, 57, 48, 57, - 58, 48, 48, 34, 48, 57, 43, 45, - 90, 48, 57, 34, 45, 91, 102, 110, - 116, 123, 48, 57, 34, 32, 93, 125, - 9, 13, 32, 44, 93, 9, 13, 32, - 93, 125, 9, 13, 97, 108, 115, 101, - 117, 108, 108, 114, 117, 101, 32, 34, - 125, 9, 13, 32, 34, 125, 9, 13, - 34, 32, 58, 9, 13, 32, 93, 125, - 9, 13, 32, 44, 125, 9, 13, 32, - 44, 125, 9, 13, 32, 34, 9, 13, - 32, 9, 13, 32, 9, 13, 32, 9, - 13, 32, 9, 13, 32, 9, 13, 32, - 9, 13, 0 + 34, 9, 13, 45, 48, 49, 57, 48, + 49, 57, 46, 69, 101, 48, 57, 69, + 101, 48, 57, 43, 45, 48, 57, 48, + 57, 48, 57, 46, 69, 101, 48, 57, + 34, 92, 34, 92, 34, 47, 92, 98, + 102, 110, 114, 116, 117, 48, 57, 65, + 70, 97, 102, 48, 57, 65, 70, 97, + 102, 48, 57, 65, 70, 97, 102, 48, + 57, 65, 70, 97, 102, 34, 92, 45, + 48, 49, 57, 48, 49, 57, 46, 115, + 48, 57, 115, 48, 57, 34, 46, 115, + 48, 57, 48, 57, 48, 57, 48, 57, + 48, 57, 45, 48, 57, 48, 57, 45, + 48, 57, 48, 57, 84, 48, 57, 48, + 57, 58, 48, 57, 48, 57, 58, 48, + 57, 48, 57, 43, 45, 46, 90, 48, + 57, 48, 57, 58, 48, 48, 34, 48, + 57, 43, 45, 90, 48, 57, 34, 44, + 34, 44, 34, 44, 34, 45, 91, 102, + 110, 116, 123, 48, 57, 34, 32, 93, + 125, 9, 13, 32, 44, 93, 9, 13, + 32, 93, 125, 9, 13, 97, 108, 115, + 101, 117, 108, 108, 114, 117, 101, 32, + 34, 125, 9, 13, 34, 32, 58, 9, + 13, 32, 93, 125, 9, 13, 32, 44, + 125, 9, 13, 32, 44, 125, 9, 13, + 32, 34, 9, 13, 32, 9, 13, 32, + 9, 13, 32, 9, 13, 32, 9, 13, + 32, 9, 13, 32, 9, 13, 0 }; static const char _json_single_lengths[] = { 0, 8, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 3, 3, 1, 2, 3, 3, 3, 2, - 2, 1, 3, 0, 2, 2, 0, 0, - 3, 2, 2, 9, 0, 0, 0, 0, - 2, 2, 1, 2, 0, 1, 1, 2, - 0, 0, 0, 0, 1, 0, 0, 1, - 0, 0, 1, 0, 0, 1, 0, 0, - 1, 0, 0, 4, 0, 0, 1, 1, - 1, 1, 0, 3, 7, 1, 0, 0, - 3, 3, 3, 1, 1, 1, 1, 0, - 1, 1, 1, 0, 1, 1, 1, 0, - 3, 3, 1, 2, 3, 3, 3, 2, - 0, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0 + 3, 1, 2, 3, 3, 3, 2, 2, + 1, 3, 0, 2, 2, 0, 0, 3, + 2, 2, 9, 0, 0, 0, 0, 2, + 2, 1, 2, 0, 1, 1, 2, 0, + 0, 0, 0, 1, 0, 0, 1, 0, + 0, 1, 0, 0, 1, 0, 0, 1, + 0, 0, 4, 0, 0, 1, 1, 1, + 1, 0, 3, 2, 2, 2, 7, 1, + 0, 0, 3, 3, 3, 1, 1, 1, + 1, 0, 1, 1, 1, 0, 1, 1, + 1, 0, 3, 1, 2, 3, 3, 3, + 2, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0 }; static const char _json_range_lengths[] = { 0, 2, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 3, 3, 3, 3, - 0, 1, 1, 0, 1, 1, 0, 1, - 1, 1, 1, 1, 0, 1, 1, 0, + 1, 0, 1, 1, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 0, 1, 1, 0, 1, 1, - 0, 1, 1, 0, 1, 1, 0, 0, + 1, 1, 1, 0, 1, 1, 0, 1, + 1, 0, 1, 1, 0, 1, 1, 0, + 1, 1, 0, 1, 1, 0, 0, 0, + 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, - 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0 + 0, 0, 1, 0, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0 }; static const short _json_index_offsets[] = { 0, 0, 11, 13, 18, 23, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, - 48, 53, 58, 60, 64, 69, 74, 79, - 83, 87, 90, 94, 96, 100, 104, 106, - 108, 113, 116, 119, 129, 133, 137, 141, - 145, 148, 152, 155, 158, 160, 163, 165, - 169, 171, 173, 175, 177, 179, 181, 183, - 185, 187, 189, 191, 193, 195, 197, 199, - 201, 203, 205, 207, 212, 214, 216, 218, - 220, 222, 224, 226, 231, 240, 242, 243, - 244, 249, 254, 259, 261, 263, 265, 267, - 268, 270, 272, 274, 275, 277, 279, 281, - 282, 287, 292, 294, 298, 303, 308, 313, - 317, 318, 321, 324, 327, 330, 333, 336, - 337, 338, 339, 340 + 48, 53, 55, 59, 64, 69, 74, 78, + 82, 85, 89, 91, 95, 99, 101, 103, + 108, 111, 114, 124, 128, 132, 136, 140, + 143, 147, 150, 153, 155, 158, 160, 164, + 166, 168, 170, 172, 174, 176, 178, 180, + 182, 184, 186, 188, 190, 192, 194, 196, + 198, 200, 202, 207, 209, 211, 213, 215, + 217, 219, 221, 226, 229, 232, 235, 244, + 246, 247, 248, 253, 258, 263, 265, 267, + 269, 271, 272, 274, 276, 278, 279, 281, + 283, 285, 286, 291, 293, 297, 302, 307, + 312, 316, 317, 320, 323, 326, 329, 332, + 335, 336, 337, 338, 339, 340 }; static const unsigned char _json_indicies[] = { @@ -14696,97 +15270,96 @@ static const unsigned char _json_indicies[] = { 1, 1, 14, 10, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20, 1, 21, 1, 22, 1, 23, 1, 24, 1, - 25, 26, 27, 25, 1, 28, 29, 30, - 28, 1, 31, 1, 32, 33, 32, 1, - 33, 1, 1, 33, 34, 35, 36, 37, - 35, 1, 38, 39, 30, 38, 1, 39, - 29, 39, 1, 40, 41, 42, 1, 41, - 42, 1, 44, 45, 45, 43, 46, 1, - 45, 45, 46, 43, 47, 47, 48, 1, - 48, 1, 48, 43, 44, 45, 45, 42, - 43, 50, 51, 49, 53, 54, 52, 55, - 55, 55, 55, 55, 55, 55, 55, 56, - 1, 57, 57, 57, 1, 58, 58, 58, - 1, 59, 59, 59, 1, 60, 60, 60, - 1, 62, 63, 61, 64, 65, 66, 1, - 67, 68, 1, 69, 70, 1, 71, 1, - 70, 71, 1, 72, 1, 69, 70, 68, - 1, 73, 1, 74, 1, 75, 1, 76, - 1, 77, 1, 78, 1, 79, 1, 80, - 1, 81, 1, 82, 1, 83, 1, 84, - 1, 85, 1, 86, 1, 87, 1, 88, - 1, 89, 1, 90, 1, 91, 1, 92, - 92, 93, 94, 1, 95, 1, 96, 1, - 97, 1, 98, 1, 99, 1, 100, 1, - 101, 1, 102, 102, 103, 101, 1, 104, - 105, 106, 107, 108, 109, 110, 105, 1, - 111, 1, 112, 113, 115, 116, 1, 115, - 114, 117, 118, 116, 117, 1, 118, 1, - 1, 118, 114, 119, 1, 120, 1, 121, - 1, 122, 1, 123, 124, 1, 125, 1, - 126, 1, 127, 128, 1, 129, 1, 130, - 1, 131, 132, 133, 134, 132, 1, 135, - 136, 137, 135, 1, 138, 1, 139, 140, - 139, 1, 140, 1, 1, 140, 141, 142, - 143, 144, 142, 1, 145, 146, 137, 145, - 1, 146, 136, 146, 1, 147, 148, 148, - 1, 149, 149, 1, 150, 150, 1, 151, - 151, 1, 152, 152, 1, 153, 153, 1, + 25, 26, 27, 25, 1, 28, 1, 29, + 30, 29, 1, 30, 1, 1, 30, 31, + 32, 33, 34, 32, 1, 35, 36, 27, + 35, 1, 36, 26, 36, 1, 37, 38, + 39, 1, 38, 39, 1, 41, 42, 42, + 40, 43, 1, 42, 42, 43, 40, 44, + 44, 45, 1, 45, 1, 45, 40, 41, + 42, 42, 39, 40, 47, 48, 46, 50, + 51, 49, 52, 52, 52, 52, 52, 52, + 52, 52, 53, 1, 54, 54, 54, 1, + 55, 55, 55, 1, 56, 56, 56, 1, + 57, 57, 57, 1, 59, 60, 58, 61, + 62, 63, 1, 64, 65, 1, 66, 67, + 1, 68, 1, 67, 68, 1, 69, 1, + 66, 67, 65, 1, 70, 1, 71, 1, + 72, 1, 73, 1, 74, 1, 75, 1, + 76, 1, 77, 1, 78, 1, 79, 1, + 80, 1, 81, 1, 82, 1, 83, 1, + 84, 1, 85, 1, 86, 1, 87, 1, + 88, 1, 89, 89, 90, 91, 1, 92, + 1, 93, 1, 94, 1, 95, 1, 96, + 1, 97, 1, 98, 1, 99, 99, 100, + 98, 1, 102, 1, 101, 104, 105, 103, + 1, 1, 101, 106, 107, 108, 109, 110, + 111, 112, 107, 1, 113, 1, 114, 115, + 117, 118, 1, 117, 116, 119, 120, 118, + 119, 1, 120, 1, 1, 120, 116, 121, + 1, 122, 1, 123, 1, 124, 1, 125, + 126, 1, 127, 1, 128, 1, 129, 130, + 1, 131, 1, 132, 1, 133, 134, 135, + 136, 134, 1, 137, 1, 138, 139, 138, + 1, 139, 1, 1, 139, 140, 141, 142, + 143, 141, 1, 144, 145, 136, 144, 1, + 145, 135, 145, 1, 146, 147, 147, 1, + 148, 148, 1, 149, 149, 1, 150, 150, + 1, 151, 151, 1, 152, 152, 1, 1, 1, 1, 1, 1, 1, 0 }; static const char _json_trans_targs[] = { - 1, 0, 2, 106, 3, 6, 10, 13, - 16, 105, 4, 3, 105, 4, 5, 7, - 8, 9, 107, 11, 12, 108, 14, 15, - 109, 17, 18, 110, 17, 18, 110, 19, - 19, 20, 21, 22, 23, 110, 22, 23, - 25, 26, 32, 111, 27, 29, 28, 30, - 31, 34, 112, 35, 34, 112, 35, 33, - 36, 37, 38, 39, 40, 34, 112, 35, - 42, 43, 47, 43, 47, 44, 46, 45, - 113, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 74, 73, 69, - 70, 71, 72, 73, 114, 75, 68, 73, - 77, 79, 80, 83, 88, 92, 96, 78, - 115, 115, 81, 80, 78, 81, 82, 84, - 85, 86, 87, 115, 89, 90, 91, 115, - 93, 94, 95, 115, 97, 98, 104, 97, - 98, 104, 99, 99, 100, 101, 102, 103, - 104, 102, 103, 115, 105, 105, 105, 105, - 105, 105 + 1, 0, 2, 107, 3, 6, 10, 13, + 16, 106, 4, 3, 106, 4, 5, 7, + 8, 9, 108, 11, 12, 109, 14, 15, + 110, 16, 17, 111, 18, 18, 19, 20, + 21, 22, 111, 21, 22, 24, 25, 31, + 112, 26, 28, 27, 29, 30, 33, 113, + 34, 33, 113, 34, 32, 35, 36, 37, + 38, 39, 33, 113, 34, 41, 42, 46, + 42, 46, 43, 45, 44, 114, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 73, 72, 68, 69, 70, 71, + 72, 115, 74, 67, 72, 76, 116, 76, + 116, 77, 79, 81, 82, 85, 90, 94, + 98, 80, 117, 117, 83, 82, 80, 83, + 84, 86, 87, 88, 89, 117, 91, 92, + 93, 117, 95, 96, 97, 117, 98, 99, + 105, 100, 100, 101, 102, 103, 104, 105, + 103, 104, 117, 106, 106, 106, 106, 106, + 106 }; static const char _json_trans_actions[] = { - 0, 0, 84, 78, 33, 0, 0, 0, - 47, 39, 25, 0, 35, 0, 0, 0, + 0, 0, 92, 86, 35, 0, 0, 0, + 104, 41, 27, 0, 37, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 80, 33, 29, 0, 0, 27, + 31, 31, 83, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 5, 15, + 0, 0, 53, 7, 13, 0, 56, 9, + 9, 9, 59, 62, 11, 17, 17, 17, + 0, 0, 0, 19, 0, 21, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 31, 96, 31, 0, 72, 0, 27, - 0, 0, 25, 29, 29, 29, 0, 0, - 0, 0, 0, 3, 0, 0, 0, 0, - 0, 5, 15, 0, 0, 51, 7, 13, - 0, 54, 9, 9, 9, 57, 60, 11, - 17, 17, 17, 0, 0, 0, 19, 0, - 21, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 104, 63, 104, 0, - 0, 0, 0, 0, 69, 0, 66, 66, - 84, 78, 33, 0, 0, 0, 47, 39, - 49, 81, 25, 0, 35, 0, 0, 0, - 0, 0, 0, 90, 0, 0, 0, 93, - 0, 0, 0, 87, 31, 96, 31, 0, - 72, 0, 27, 0, 0, 25, 29, 29, - 29, 0, 0, 100, 0, 37, 43, 45, - 41, 75 + 0, 114, 65, 114, 0, 0, 0, 0, + 0, 71, 0, 68, 68, 77, 25, 0, + 110, 74, 92, 86, 35, 0, 0, 0, + 104, 41, 51, 89, 27, 0, 37, 0, + 0, 0, 0, 0, 0, 98, 0, 0, + 0, 101, 0, 0, 0, 95, 0, 80, + 33, 29, 0, 0, 27, 31, 31, 83, + 0, 0, 107, 0, 39, 45, 47, 43, + 49 }; static const char _json_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -14795,21 +15368,23 @@ static const char _json_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 37, 43, 45, 41, 75, 0, - 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 39, 45, 47, 43, 49, + 0, 0, 0, 0, 0, 0 }; static const int json_start = 1; -static const int json_en_number_machine = 24; -static const int json_en_string_machine = 33; -static const int json_en_duration_machine = 41; -static const int json_en_timestamp_machine = 48; -static const int json_en_value_machine = 76; +static const int json_en_number_machine = 23; +static const int json_en_string_machine = 32; +static const int json_en_duration_machine = 40; +static const int json_en_timestamp_machine = 47; +static const int json_en_fieldmask_machine = 75; +static const int json_en_value_machine = 78; static const int json_en_main = 1; -//#line 2150 "upb/json/parser.rl" +#line 2733 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -14832,7 +15407,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -//#line 2290 "upb/json/parser.c" +#line 2831 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -14907,166 +15482,212 @@ _match: switch ( *_acts++ ) { case 1: -//#line 2021 "upb/json/parser.rl" +#line 2561 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 2: -//#line 2023 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 24; goto _again;} } +#line 2563 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 23;goto _again;} } break; case 3: -//#line 2027 "upb/json/parser.rl" +#line 2567 "upb/json/parser.rl" { start_text(parser, p); } break; case 4: -//#line 2028 "upb/json/parser.rl" +#line 2568 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 5: -//#line 2034 "upb/json/parser.rl" +#line 2574 "upb/json/parser.rl" { start_hex(parser); } break; case 6: -//#line 2035 "upb/json/parser.rl" +#line 2575 "upb/json/parser.rl" { hexdigit(parser, p); } break; case 7: -//#line 2036 "upb/json/parser.rl" +#line 2576 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hex(parser)); } break; case 8: -//#line 2042 "upb/json/parser.rl" +#line 2582 "upb/json/parser.rl" { CHECK_RETURN_TOP(escape(parser, p)); } break; case 9: -//#line 2048 "upb/json/parser.rl" +#line 2588 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 10: -//#line 2060 "upb/json/parser.rl" +#line 2600 "upb/json/parser.rl" { start_duration_base(parser, p); } break; case 11: -//#line 2061 "upb/json/parser.rl" +#line 2601 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_duration_base(parser, p)); } break; case 12: -//#line 2063 "upb/json/parser.rl" +#line 2603 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 13: -//#line 2068 "upb/json/parser.rl" +#line 2608 "upb/json/parser.rl" { start_timestamp_base(parser, p); } break; case 14: -//#line 2069 "upb/json/parser.rl" +#line 2609 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } break; case 15: -//#line 2071 "upb/json/parser.rl" +#line 2611 "upb/json/parser.rl" { start_timestamp_fraction(parser, p); } break; case 16: -//#line 2072 "upb/json/parser.rl" +#line 2612 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } break; case 17: -//#line 2074 "upb/json/parser.rl" +#line 2614 "upb/json/parser.rl" { start_timestamp_zone(parser, p); } break; case 18: -//#line 2075 "upb/json/parser.rl" +#line 2615 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } break; case 19: -//#line 2077 "upb/json/parser.rl" +#line 2617 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 20: -//#line 2082 "upb/json/parser.rl" - { - if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { - {stack[top++] = cs; cs = 48; goto _again;} - } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) { - {stack[top++] = cs; cs = 41; goto _again;} - } else { - {stack[top++] = cs; cs = 33; goto _again;} - } - } +#line 2622 "upb/json/parser.rl" + { start_fieldmask_path_text(parser, p); } break; case 21: -//#line 2093 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 76; goto _again;} } +#line 2623 "upb/json/parser.rl" + { end_fieldmask_path_text(parser, p); } break; case 22: -//#line 2098 "upb/json/parser.rl" - { start_member(parser); } +#line 2628 "upb/json/parser.rl" + { start_fieldmask_path(parser); } break; case 23: -//#line 2099 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_membername(parser)); } +#line 2629 "upb/json/parser.rl" + { end_fieldmask_path(parser); } break; case 24: -//#line 2102 "upb/json/parser.rl" - { end_member(parser); } +#line 2635 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; case 25: -//#line 2108 "upb/json/parser.rl" - { start_object(parser); } +#line 2640 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { + {stack[top++] = cs; cs = 47;goto _again;} + } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) { + {stack[top++] = cs; cs = 40;goto _again;} + } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_FIELDMASK)) { + {stack[top++] = cs; cs = 75;goto _again;} + } else { + {stack[top++] = cs; cs = 32;goto _again;} + } + } break; case 26: -//#line 2111 "upb/json/parser.rl" - { end_object(parser); } +#line 2653 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 78;goto _again;} } break; case 27: -//#line 2117 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_array(parser)); } +#line 2658 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + start_any_member(parser, p); + } else { + start_member(parser); + } + } break; case 28: -//#line 2121 "upb/json/parser.rl" - { end_array(parser); } +#line 2665 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_membername(parser)); } break; case 29: -//#line 2126 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_number(parser, p)); } +#line 2668 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + end_any_member(parser, p); + } else { + end_member(parser); + } + } break; case 30: -//#line 2127 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_number(parser, p)); } +#line 2679 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + start_any_object(parser, p); + } else { + start_object(parser); + } + } break; case 31: -//#line 2129 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_stringval(parser)); } +#line 2688 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { + CHECK_RETURN_TOP(end_any_object(parser, p)); + } else { + end_object(parser); + } + } break; case 32: -//#line 2130 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_stringval(parser)); } +#line 2700 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_array(parser)); } break; case 33: -//#line 2132 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, true)); } +#line 2704 "upb/json/parser.rl" + { end_array(parser); } break; case 34: -//#line 2134 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, false)); } +#line 2709 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_number(parser, p)); } break; case 35: -//#line 2136 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_null(parser)); } +#line 2710 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_number(parser, p)); } break; case 36: -//#line 2138 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_subobject_full(parser)); } +#line 2712 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_stringval(parser)); } break; case 37: -//#line 2139 "upb/json/parser.rl" - { end_subobject_full(parser); } +#line 2713 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_stringval(parser)); } break; case 38: -//#line 2144 "upb/json/parser.rl" +#line 2715 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, true)); } + break; + case 39: +#line 2717 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, false)); } + break; + case 40: +#line 2719 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_null(parser)); } + break; + case 41: +#line 2721 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_subobject_full(parser)); } + break; + case 42: +#line 2722 "upb/json/parser.rl" + { end_subobject_full(parser); } + break; + case 43: +#line 2727 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -//#line 2524 "upb/json/parser.c" +#line 3111 "upb/json/parser.c" } } @@ -15083,34 +15704,32 @@ _again: while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 0: -//#line 2019 "upb/json/parser.rl" - { p--; {cs = stack[--top]; goto _again;} } - break; - case 26: -//#line 2111 "upb/json/parser.rl" - { end_object(parser); } +#line 2559 "upb/json/parser.rl" + { p--; {cs = stack[--top]; if ( p == pe ) + goto _test_eof; +goto _again;} } break; - case 30: -//#line 2127 "upb/json/parser.rl" + case 35: +#line 2710 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; - case 33: -//#line 2132 "upb/json/parser.rl" + case 38: +#line 2715 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; - case 34: -//#line 2134 "upb/json/parser.rl" + case 39: +#line 2717 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; - case 35: -//#line 2136 "upb/json/parser.rl" + case 40: +#line 2719 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_null(parser)); } break; - case 37: -//#line 2139 "upb/json/parser.rl" + case 42: +#line 2722 "upb/json/parser.rl" { end_subobject_full(parser); } break; -//#line 2568 "upb/json/parser.c" +#line 3153 "upb/json/parser.c" } } } @@ -15118,7 +15737,7 @@ _again: _out: {} } -//#line 2172 "upb/json/parser.rl" +#line 2755 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -15135,12 +15754,13 @@ error: return p - buf; } -bool end(void *closure, const void *hd) { +static bool end(void *closure, const void *hd) { upb_json_parser *parser = closure; /* Prevent compile warning on unused static constants. */ UPB_UNUSED(json_start); UPB_UNUSED(json_en_duration_machine); + UPB_UNUSED(json_en_fieldmask_machine); UPB_UNUSED(json_en_number_machine); UPB_UNUSED(json_en_string_machine); UPB_UNUSED(json_en_timestamp_machine); @@ -15149,11 +15769,7 @@ bool end(void *closure, const void *hd) { parse(parser, hd, &eof_ch, 0, NULL); - return parser->current_state >= -//#line 2608 "upb/json/parser.c" -105 -//#line 2202 "upb/json/parser.rl" -; + return parser->current_state >= 106; } static void json_parser_reset(upb_json_parser *p) { @@ -15164,17 +15780,19 @@ static void json_parser_reset(upb_json_parser *p) { p->top->f = NULL; p->top->is_map = false; p->top->is_mapentry = false; + p->top->is_any = false; + p->top->any_frame = NULL; p->top->is_unknown_field = false; /* Emit Ragel initialization of the parser. */ -//#line 2626 "upb/json/parser.c" +#line 3210 "upb/json/parser.c" { cs = json_start; top = 0; } -//#line 2217 "upb/json/parser.rl" +#line 2803 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -15261,6 +15879,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { upb_json_parser *upb_json_parser_create(upb_env *env, const upb_json_parsermethod *method, + const upb_symtab* symtab, upb_sink *output, bool ignore_json_unknown) { #ifndef NDEBUG @@ -15279,7 +15898,17 @@ upb_json_parser *upb_json_parser_create(upb_env *env, json_parser_reset(p); upb_sink_reset(&p->top->sink, output->handlers, output->closure); p->top->m = upb_handlers_msgdef(output->handlers); + if (is_wellknown_msg(p, UPB_WELLKNOWN_ANY)) { + p->top->is_any = true; + p->top->any_frame = + upb_env_malloc(p->env, sizeof(upb_jsonparser_any_frame)); + json_parser_any_frame_reset(p->top->any_frame); + } else { + p->top->is_any = false; + p->top->any_frame = NULL; + } set_name_table(p, p->top); + p->symtab = symtab; p->ignore_json_unknown = ignore_json_unknown; @@ -15389,6 +16018,15 @@ strpc *newstrpc(upb_handlers *h, const upb_fielddef *f, return ret; } +/* Convert a null-terminated const char* to a string piece. */ +strpc *newstrpc_str(upb_handlers *h, const char * str) { + strpc * ret = upb_gmalloc(sizeof(*ret)); + ret->ptr = upb_gstrdup(str); + ret->len = strlen(str); + upb_handlers_addcleanup(h, ret, freestrpc); + return ret; +} + /* ------------ JSON string printing: values, maps, arrays ------------------ */ static void print_data( @@ -16058,6 +16696,57 @@ static void *startseq_nokey(void *closure, const void *handler_data) { return closure; } +static void *startseq_fieldmask(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_++; + p->first_elem_[p->depth_] = true; + print_data(p, "\"", 1); + return closure; +} + +static bool endseq_fieldmask(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_--; + print_data(p, "\"", 1); + return true; +} + +static void *repeated_startstr_fieldmask( + void *closure, const void *handler_data, + size_t size_hint) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(size_hint); + print_comma(p); + return p; +} + +static size_t repeated_str_fieldmask( + void *closure, const void *handler_data, + const char *str, size_t len, + const upb_bufhandle *handle) { + const char* limit = str + len; + bool upper = false; + size_t result_len = 0; + for (; str < limit; str++) { + if (*str == '_') { + upper = true; + continue; + } + if (upper && *str >= 'a' && *str <= 'z') { + char upper_char = toupper(*str); + CHK(putstr(closure, handler_data, &upper_char, 1, handle)); + } else { + CHK(putstr(closure, handler_data, str, 1, handle)); + } + upper = false; + result_len++; + } + return result_len; +} + static void *startmap_nokey(void *closure, const void *handler_data) { upb_json_printer *p = closure; UPB_UNUSED(handler_data); @@ -16240,6 +16929,68 @@ static bool printer_endmsg_noframe( return true; } +static void *scalar_startstr_onlykey( + void *closure, const void *handler_data, size_t size_hint) { + upb_json_printer *p = closure; + UPB_UNUSED(size_hint); + CHK(putkey(closure, handler_data)); + return p; +} + +/* Set up handlers for an Any submessage. */ +void printer_sethandlers_any(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + + const upb_fielddef* type_field = upb_msgdef_itof(md, UPB_ANY_TYPE); + const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_ANY_VALUE); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + /* type_url's json name is "@type" */ + upb_handlerattr type_name_attr = UPB_HANDLERATTR_INITIALIZER; + upb_handlerattr value_name_attr = UPB_HANDLERATTR_INITIALIZER; + strpc *type_url_json_name = newstrpc_str(h, "@type"); + strpc *value_json_name = newstrpc_str(h, "value"); + + upb_handlerattr_sethandlerdata(&type_name_attr, type_url_json_name); + upb_handlerattr_sethandlerdata(&value_name_attr, value_json_name); + + /* Set up handlers. */ + upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); + + upb_handlers_setstartstr(h, type_field, scalar_startstr, &type_name_attr); + upb_handlers_setstring(h, type_field, scalar_str, &empty_attr); + upb_handlers_setendstr(h, type_field, scalar_endstr, &empty_attr); + + /* This is not the full and correct JSON encoding for the Any value field. It + * requires further processing by the wrapper code based on the type URL. + */ + upb_handlers_setstartstr(h, value_field, scalar_startstr_onlykey, + &value_name_attr); + + UPB_UNUSED(closure); +} + +/* Set up handlers for a fieldmask submessage. */ +void printer_sethandlers_fieldmask(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + const upb_fielddef* f = upb_msgdef_itof(md, 1); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartseq(h, f, startseq_fieldmask, &empty_attr); + upb_handlers_setendseq(h, f, endseq_fieldmask, &empty_attr); + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_handlers_setstartstr(h, f, repeated_startstr_fieldmask, &empty_attr); + upb_handlers_setstring(h, f, repeated_str_fieldmask, &empty_attr); + + UPB_UNUSED(closure); +} + /* Set up handlers for a duration submessage. */ void printer_sethandlers_duration(const void *closure, upb_handlers *h) { const upb_msgdef *md = upb_handlers_msgdef(h); @@ -16393,6 +17144,12 @@ void printer_sethandlers(const void *closure, upb_handlers *h) { switch (upb_msgdef_wellknowntype(md)) { case UPB_WELLKNOWN_UNSPECIFIED: break; + case UPB_WELLKNOWN_ANY: + printer_sethandlers_any(closure, h); + return; + case UPB_WELLKNOWN_FIELDMASK: + printer_sethandlers_fieldmask(closure, h); + return; case UPB_WELLKNOWN_DURATION: printer_sethandlers_duration(closure, h); return; diff --git a/ruby/ext/google/protobuf_c/upb.h b/ruby/ext/google/protobuf_c/upb.h index 0670a8123c..7b3981b3b3 100644 --- a/ruby/ext/google/protobuf_c/upb.h +++ b/ruby/ext/google/protobuf_c/upb.h @@ -1,11 +1,5 @@ // Amalgamated source file -// php.h intentionally defined NDEBUG. We have to define this macro in order to -// be used together with php.h -#ifndef NDEBUG -#define NDEBUG -#endif - #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 #else @@ -2013,6 +2007,8 @@ typedef enum { */ typedef enum { UPB_WELLKNOWN_UNSPECIFIED, + UPB_WELLKNOWN_ANY, + UPB_WELLKNOWN_FIELDMASK, UPB_WELLKNOWN_DURATION, UPB_WELLKNOWN_TIMESTAMP, /* number wrappers */ @@ -2416,6 +2412,10 @@ typedef upb_strtable_iter upb_msg_oneof_iter; #define UPB_MAPENTRY_KEY 1 #define UPB_MAPENTRY_VALUE 2 +/* Well-known field tag numbers for Any messages. */ +#define UPB_ANY_TYPE 1 +#define UPB_ANY_VALUE 2 + /* Well-known field tag numbers for timestamp messages. */ #define UPB_DURATION_SECONDS 1 #define UPB_DURATION_NANOS 2 @@ -3271,6 +3271,8 @@ const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, const char *sym); const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym); const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym); +const upb_msgdef *upb_symtab_lookupmsg2( + const upb_symtab *s, const char *sym, size_t len); const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym); bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, void *ref_donor, upb_status *status); @@ -6877,7 +6879,7 @@ typedef enum { extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit; UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); @@ -6896,7 +6898,7 @@ UPB_INLINE void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileD extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit; UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); @@ -6937,7 +6939,7 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_F extern const upb_msglayout google_protobuf_DescriptorProto_msginit; UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); @@ -6974,7 +6976,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_name(google_protobu extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit; UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); @@ -6997,7 +6999,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(googl extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit; UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); @@ -7018,7 +7020,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_pro extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit; UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); @@ -7037,7 +7039,7 @@ UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(g extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit; UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); @@ -7074,7 +7076,7 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protob extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit; UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); @@ -7095,7 +7097,7 @@ UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit; UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); @@ -7122,7 +7124,7 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_name(google_pro extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); @@ -7143,7 +7145,7 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(go extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit; UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); @@ -7166,7 +7168,7 @@ UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_prot extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit; UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); @@ -7189,7 +7191,7 @@ UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protob extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit; UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); @@ -7218,7 +7220,7 @@ UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(googl extern const upb_msglayout google_protobuf_FileOptions_msginit; UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); @@ -7273,7 +7275,7 @@ UPB_INLINE void google_protobuf_FileOptions_set_uninterpreted_option(google_prot extern const upb_msglayout google_protobuf_MessageOptions_msginit; UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); @@ -7300,7 +7302,7 @@ UPB_INLINE void google_protobuf_MessageOptions_set_uninterpreted_option(google_p extern const upb_msglayout google_protobuf_FieldOptions_msginit; UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); @@ -7331,7 +7333,7 @@ UPB_INLINE void google_protobuf_FieldOptions_set_uninterpreted_option(google_pro extern const upb_msglayout google_protobuf_OneofOptions_msginit; UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); @@ -7350,7 +7352,7 @@ UPB_INLINE void google_protobuf_OneofOptions_set_uninterpreted_option(google_pro extern const upb_msglayout google_protobuf_EnumOptions_msginit; UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); @@ -7373,7 +7375,7 @@ UPB_INLINE void google_protobuf_EnumOptions_set_uninterpreted_option(google_prot extern const upb_msglayout google_protobuf_EnumValueOptions_msginit; UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); @@ -7394,7 +7396,7 @@ UPB_INLINE void google_protobuf_EnumValueOptions_set_uninterpreted_option(google extern const upb_msglayout google_protobuf_ServiceOptions_msginit; UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); @@ -7415,7 +7417,7 @@ UPB_INLINE void google_protobuf_ServiceOptions_set_uninterpreted_option(google_p extern const upb_msglayout google_protobuf_MethodOptions_msginit; UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); @@ -7438,7 +7440,7 @@ UPB_INLINE void google_protobuf_MethodOptions_set_uninterpreted_option(google_pr extern const upb_msglayout google_protobuf_UninterpretedOption_msginit; UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); @@ -7469,7 +7471,7 @@ UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_p extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit; UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); @@ -7490,7 +7492,7 @@ UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(go extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit; UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); @@ -7509,7 +7511,7 @@ UPB_INLINE void google_protobuf_SourceCodeInfo_set_location(google_protobuf_Sour extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit; UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); @@ -7536,7 +7538,7 @@ UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_detached_com extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit; UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); @@ -7555,7 +7557,7 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit; UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { - return 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_parsenew(upb_stringview buf, upb_arena *arena) { google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); @@ -9567,7 +9569,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, * constructed. This hint may be an overestimate for some build configurations. * But if the parser library is upgraded without recompiling the application, * it may be an underestimate. */ -#define UPB_JSON_PARSER_SIZE 4160 +#define UPB_JSON_PARSER_SIZE 5712 #ifdef __cplusplus @@ -9576,6 +9578,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, class upb::json::Parser { public: static Parser* Create(Environment* env, const ParserMethod* method, + const SymbolTable* symtab, Sink* output, bool ignore_json_unknown); BytesSink* input(); @@ -9610,6 +9613,7 @@ UPB_BEGIN_EXTERN_C upb_json_parser* upb_json_parser_create(upb_env* e, const upb_json_parsermethod* m, + const upb_symtab* symtab, upb_sink* output, bool ignore_json_unknown); upb_bytessink *upb_json_parser_input(upb_json_parser *p); @@ -9631,8 +9635,10 @@ UPB_END_EXTERN_C namespace upb { namespace json { inline Parser* Parser::Create(Environment* env, const ParserMethod* method, + const SymbolTable* symtab, Sink* output, bool ignore_json_unknown) { - return upb_json_parser_create(env, method, output, ignore_json_unknown); + return upb_json_parser_create( + env, method, symtab, output, ignore_json_unknown); } inline BytesSink* Parser::input() { return upb_json_parser_input(this); diff --git a/ruby/tests/encode_decode_test.rb b/ruby/tests/encode_decode_test.rb index d2b25fdcae..d3cebab215 100644 --- a/ruby/tests/encode_decode_test.rb +++ b/ruby/tests/encode_decode_test.rb @@ -22,8 +22,8 @@ class EncodeDecodeTest < Test::Unit::TestCase # Test discard unknown for singular message field. unknown_msg = A::B::C::TestUnknown.new( - :optional_unknown => - A::B::C::TestUnknown.new(:unknown_field => 1)) + :optional_unknown => + A::B::C::TestUnknown.new(:unknown_field => 1)) from = A::B::C::TestUnknown.encode(unknown_msg) m = A::B::C::TestMessage.decode(from) Google::Protobuf.discard_unknown(m) @@ -32,8 +32,8 @@ class EncodeDecodeTest < Test::Unit::TestCase # Test discard unknown for repeated message field. unknown_msg = A::B::C::TestUnknown.new( - :repeated_unknown => - [A::B::C::TestUnknown.new(:unknown_field => 1)]) + :repeated_unknown => + [A::B::C::TestUnknown.new(:unknown_field => 1)]) from = A::B::C::TestUnknown.encode(unknown_msg) m = A::B::C::TestMessage.decode(from) Google::Protobuf.discard_unknown(m) @@ -42,8 +42,8 @@ class EncodeDecodeTest < Test::Unit::TestCase # Test discard unknown for map value message field. unknown_msg = A::B::C::TestUnknown.new( - :map_unknown => - {"" => A::B::C::TestUnknown.new(:unknown_field => 1)}) + :map_unknown => + {"" => A::B::C::TestUnknown.new(:unknown_field => 1)}) from = A::B::C::TestUnknown.encode(unknown_msg) m = A::B::C::TestMessage.decode(from) Google::Protobuf.discard_unknown(m) @@ -52,8 +52,8 @@ class EncodeDecodeTest < Test::Unit::TestCase # Test discard unknown for oneof message field. unknown_msg = A::B::C::TestUnknown.new( - :oneof_unknown => - A::B::C::TestUnknown.new(:unknown_field => 1)) + :oneof_unknown => + A::B::C::TestUnknown.new(:unknown_field => 1)) from = A::B::C::TestUnknown.encode(unknown_msg) m = A::B::C::TestMessage.decode(from) Google::Protobuf.discard_unknown(m) From b3367aee14843037a73d84b4602f4454f1d30fec Mon Sep 17 00:00:00 2001 From: bitspill Date: Thu, 17 Jan 2019 17:13:31 -0800 Subject: [PATCH 63/70] doc: apply consistent indentation to Any examples (#5597) --- src/google/protobuf/any.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/any.proto b/src/google/protobuf/any.proto index c9be854167..deb9de24fb 100644 --- a/src/google/protobuf/any.proto +++ b/src/google/protobuf/any.proto @@ -64,7 +64,7 @@ option objc_class_prefix = "GPB"; // foo = any.unpack(Foo.class); // } // -// Example 3: Pack and unpack a message in Python. +// Example 3: Pack and unpack a message in Python. // // foo = Foo(...) // any = Any() @@ -74,7 +74,7 @@ option objc_class_prefix = "GPB"; // any.Unpack(foo) // ... // -// Example 4: Pack and unpack a message in Go +// Example 4: Pack and unpack a message in Go // // foo := &pb.Foo{...} // any, err := ptypes.MarshalAny(foo) From 4e929031b08a8352c4a03bb99cc2b8b066114725 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 18 Jan 2019 12:54:23 -0800 Subject: [PATCH 64/70] Revert "doc: apply consistent indentation to Any examples (#5597)" This reverts commit b3367aee14843037a73d84b4602f4454f1d30fec. --- src/google/protobuf/any.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/any.proto b/src/google/protobuf/any.proto index deb9de24fb..c9be854167 100644 --- a/src/google/protobuf/any.proto +++ b/src/google/protobuf/any.proto @@ -64,7 +64,7 @@ option objc_class_prefix = "GPB"; // foo = any.unpack(Foo.class); // } // -// Example 3: Pack and unpack a message in Python. +// Example 3: Pack and unpack a message in Python. // // foo = Foo(...) // any = Any() @@ -74,7 +74,7 @@ option objc_class_prefix = "GPB"; // any.Unpack(foo) // ... // -// Example 4: Pack and unpack a message in Go +// Example 4: Pack and unpack a message in Go // // foo := &pb.Foo{...} // any, err := ptypes.MarshalAny(foo) From dd7127d23da52c5f227f9d617a9dcbb447740225 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 18 Jan 2019 15:05:57 -0800 Subject: [PATCH 65/70] Fixed compile warnings for PHP extension. (#5589) * Fixed compile warnings for PHP extension. * Fixed some compile errors on PHP <7 and with TSR enabled. * One more fix for TSRM builds. --- php/ext/google/protobuf/def.c | 3 + php/ext/google/protobuf/encode_decode.c | 9 ++- php/ext/google/protobuf/map.c | 5 +- php/ext/google/protobuf/message.c | 83 +++++++++++-------------- php/ext/google/protobuf/protobuf.h | 12 ++-- php/ext/google/protobuf/type_check.c | 46 ++++++-------- 6 files changed, 79 insertions(+), 79 deletions(-) diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 238a924789..db6aec7014 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -28,6 +28,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include +#include + #include "protobuf.h" // Forward declare. diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 801b44d53c..836b2f9818 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -27,6 +27,9 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +#include +#include #include "protobuf.h" #include "utf8.h" @@ -84,6 +87,8 @@ void stringsink_init(stringsink *sink) { void stringsink_uninit(stringsink *sink) { free(sink->ptr); } +void stringsink_uninit_opaque(void *sink) { stringsink_uninit(sink); } + /* stackenv *****************************************************************/ // Stack-allocated context during an encode/decode operation. Contains the upb @@ -1748,7 +1753,7 @@ PHP_METHOD(Message, serializeToString) { serialize_to_string(getThis(), return_value TSRMLS_CC); } -void merge_from_string(const char* data, int data_len, const Descriptor* desc, +void merge_from_string(const char* data, int data_len, Descriptor* desc, MessageHeader* msg) { const upb_pbdecodermethod* method = msgdef_decodermethod(desc); const upb_handlers* h = upb_pbdecodermethod_desthandlers(method); @@ -1900,7 +1905,7 @@ static void discard_unknown_fields(MessageHeader* msg) { for (map_begin(map_php, &map_it TSRMLS_CC); !map_done(&map_it); map_next(&map_it)) { upb_value value = map_iter_value(&map_it, &len); - void* memory = raw_value(upb_value_memory(&value), value_field); + const void* memory = raw_value(upb_value_memory(&value), value_field); #if PHP_MAJOR_VERSION < 7 MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory); #else diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index c5b500b53e..0ce10190e6 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -167,7 +167,8 @@ static void map_begin_internal(Map *map, MapIter *iter) { upb_strtable_begin(&iter->it, &map->table); } -static HashTable *map_field_get_gc(zval *object, CACHED_VALUE **table, int *n) { +static HashTable *map_field_get_gc(zval *object, CACHED_VALUE **table, + int *n TSRMLS_DC) { // TODO(teboring): Unfortunately, zend engine does not support garbage // collection for custom array. We have to use zend engine's native array // instead. @@ -294,7 +295,7 @@ static bool map_field_read_dimension(zval *object, zval *key, int type, } } -static bool map_index_unset(Map *intern, const char* keyval, int length) { +static void map_index_unset(Map *intern, const char* keyval, int length) { upb_value old_value; if (upb_strtable_remove2(&intern->table, keyval, length, &old_value)) { switch (intern->value_type) { diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 08a4793ff7..d883340f06 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -29,9 +29,16 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include #include #include +#if PHP_MAJOR_VERSION < 7 +#include +#else +#include +#endif + #include "protobuf.h" #include "utf8.h" @@ -83,7 +90,7 @@ static HashTable* message_get_properties(zval* object TSRMLS_DC); // Define object free method. PHP_PROTO_OBJECT_FREE_START(MessageHeader, message) if (*(void**)intern->data != NULL) { - stringsink_uninit(*(void**)intern->data); + stringsink_uninit_opaque(*(void**)intern->data); FREE(*(void**)intern->data); } FREE(intern->data); @@ -904,12 +911,11 @@ PHP_METHOD(Field_Cardinality, name) { case 3: PHP_PROTO_RETURN_STRING("CARDINALITY_REPEATED", 1); default: - zend_throw_exception( - NULL, + zend_throw_exception_ex( + NULL, 0 TSRMLS_CC, "Enum Google\\Protobuf\\Field_Cardinality has no name " "defined for value %d.", - value, - 0 TSRMLS_CC); + value); } } @@ -927,12 +933,11 @@ PHP_METHOD(Field_Cardinality, value) { if (strncmp(name, "CARDINALITY_REQUIRED", name_len) == 0) RETURN_LONG(2); if (strncmp(name, "CARDINALITY_REPEATED", name_len) == 0) RETURN_LONG(3); - zend_throw_exception( - NULL, + zend_throw_exception_ex( + NULL, 0 TSRMLS_CC, "Enum Google\\Protobuf\\Field_Cardinality has no value " "defined for name %s.", - name, - 0 TSRMLS_CC); + name); } // ----------------------------------------------------------------------------- @@ -1042,12 +1047,10 @@ PHP_METHOD(Field_Kind, name) { case 18: PHP_PROTO_RETURN_STRING("TYPE_SINT64", 1); default: - zend_throw_exception( - NULL, - "Enum Google\\Protobuf\\Field_Kind has no name " - "defined for value %d.", - value, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Enum Google\\Protobuf\\Field_Kind has no name " + "defined for value %d.", + value); } } @@ -1080,12 +1083,10 @@ PHP_METHOD(Field_Kind, value) { if (strncmp(name, "TYPE_SINT32", name_len) == 0) RETURN_LONG(17); if (strncmp(name, "TYPE_SINT64", name_len) == 0) RETURN_LONG(18); - zend_throw_exception( - NULL, - "Enum Google\\Protobuf\\Field_Kind has no value " - "defined for name %s.", - name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Enum Google\\Protobuf\\Field_Kind has no value " + "defined for name %s.", + name); } // ----------------------------------------------------------------------------- @@ -1117,12 +1118,10 @@ PHP_METHOD(NullValue, name) { case 0: PHP_PROTO_RETURN_STRING("NULL_VALUE", 1); default: - zend_throw_exception( - NULL, - "Enum Google\\Protobuf\\NullValue has no name " - "defined for value %d.", - value, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Enum Google\\Protobuf\\NullValue has no name " + "defined for value %d.", + value); } } @@ -1137,12 +1136,10 @@ PHP_METHOD(NullValue, value) { if (strncmp(name, "NULL_VALUE", name_len) == 0) RETURN_LONG(0); - zend_throw_exception( - NULL, - "Enum Google\\Protobuf\\NullValue has no value " - "defined for name %s.", - name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Enum Google\\Protobuf\\NullValue has no value " + "defined for name %s.", + name); } // ----------------------------------------------------------------------------- @@ -1178,12 +1175,10 @@ PHP_METHOD(Syntax, name) { case 1: PHP_PROTO_RETURN_STRING("SYNTAX_PROTO3", 1); default: - zend_throw_exception( - NULL, - "Enum Google\\Protobuf\\Syntax has no name " - "defined for value %d.", - value, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Enum Google\\Protobuf\\Syntax has no name " + "defined for value %d.", + value); } } @@ -1199,12 +1194,10 @@ PHP_METHOD(Syntax, value) { if (strncmp(name, "SYNTAX_PROTO2", name_len) == 0) RETURN_LONG(0); if (strncmp(name, "SYNTAX_PROTO3", name_len) == 0) RETURN_LONG(1); - zend_throw_exception( - NULL, - "Enum Google\\Protobuf\\Syntax has no value " - "defined for name %s.", - name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Enum Google\\Protobuf\\Syntax has no value " + "defined for name %s.", + name); } // ----------------------------------------------------------------------------- diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 5cbf348b02..c4ab8860d1 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -310,8 +310,10 @@ static inline int php_proto_zend_hash_index_update_mem(HashTable* ht, ulong h, static inline int php_proto_zend_hash_update_zval(HashTable* ht, const char* key, uint key_len, zval* pData) { + void* result = NULL; zend_string* internal_key = zend_string_init(key, key_len, 0); - zend_hash_update(ht, internal_key, pData); + result = zend_hash_update(ht, internal_key, pData); + return result != NULL ? SUCCESS : FAILURE; } static inline int php_proto_zend_hash_update_mem(HashTable* ht, const char* key, @@ -682,6 +684,7 @@ void double_value_init(TSRMLS_D); void duration_init(TSRMLS_D); void empty_init(TSRMLS_D); void enum_descriptor_init(TSRMLS_D); +void enum_value_descriptor_init(TSRMLS_D); void enum_init(TSRMLS_D); void enum_value_init(TSRMLS_D); void field_cardinality_init(TSRMLS_D); @@ -711,8 +714,8 @@ void struct_init(TSRMLS_D); void syntax_init(TSRMLS_D); void timestamp_init(TSRMLS_D); void type_init(TSRMLS_D); -void uint32_value_init(TSRMLS_D); -void uint64_value_init(TSRMLS_D); +void u_int32_value_init(TSRMLS_D); +void u_int64_value_init(TSRMLS_D); void util_init(TSRMLS_D); void value_init(TSRMLS_D); @@ -966,7 +969,7 @@ PHP_METHOD(Message, __construct); const upb_pbdecodermethod *new_fillmsg_decodermethod(Descriptor *desc, const void *owner); void serialize_to_string(zval* val, zval* return_value TSRMLS_DC); -void merge_from_string(const char* data, int data_len, const Descriptor* desc, +void merge_from_string(const char* data, int data_len, Descriptor* desc, MessageHeader* msg); PHP_METHOD(Message, serializeToString); @@ -1448,6 +1451,7 @@ extern zend_class_entry* value_type; upb_fieldtype_t to_fieldtype(upb_descriptortype_t type); const zend_class_entry* field_type_class( const upb_fielddef* field PHP_PROTO_TSRMLS_DC); +void stringsink_uninit_opaque(void *sink); // ----------------------------------------------------------------------------- // Utilities. diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index 3fb9c51108..31dc44493d 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -29,6 +29,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include #include "protobuf.h" #include "utf8.h" @@ -434,9 +435,9 @@ PHP_METHOD(Util, checkMessage) { RETURN_NULL(); } if (!instanceof_function(Z_OBJCE_P(val), klass TSRMLS_CC)) { - zend_throw_exception( - NULL, "Given value is not an instance of %s.", klass->name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Given value is not an instance of %s.", + klass->name); return; } RETURN_ZVAL(val, 1, 0); @@ -479,32 +480,27 @@ void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type, } else if (Z_TYPE_P(val) == IS_OBJECT) { if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) { - zend_throw_exception( - NULL, "Given value is not an instance of %s.", - repeated_field_type->name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Given value is not an instance of %s.", + repeated_field_type->name); return; } RepeatedField* intern = UNBOX(RepeatedField, val); if (to_fieldtype(type) != intern->type) { - zend_throw_exception( - NULL, "Incorrect repeated field type.", - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Incorrect repeated field type."); return; } if (klass != NULL && intern->msg_ce != klass) { - zend_throw_exception( - NULL, "Expect a repeated field of %s, but %s is given.", - klass->name, - intern->msg_ce->name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Expect a repeated field of %s, but %s is given.", + klass->name, intern->msg_ce->name); return; } RETURN_ZVAL(val, 1, 0); } else { - zend_throw_exception( - NULL, "Incorrect repeated field type.", - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Incorrect repeated field type."); return; } } @@ -560,10 +556,9 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type, RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 1); } else if (Z_TYPE_P(val) == IS_OBJECT) { if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) { - zend_throw_exception( - NULL, "Given value is not an instance of %s.", - map_field_type->name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Given value is not an instance of %s.", + map_field_type->name); return; } Map* intern = UNBOX(Map, val); @@ -580,10 +575,9 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type, return; } if (klass != NULL && intern->msg_ce != klass) { - zend_throw_exception( - NULL, "Expect a map field of %s, but %s is given.", - klass->name, intern->msg_ce->name, - 0 TSRMLS_CC); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, + "Expect a map field of %s, but %s is given.", + klass->name, intern->msg_ce->name); return; } RETURN_ZVAL(val, 1, 0); From 1069565a68654fa016cb454c87eca8372b3b8d3f Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 22 Jan 2019 14:02:44 -0800 Subject: [PATCH 66/70] Fix c extension doesn' allow message reference in array (#5599) * Fix c extension doesn' allow message reference in array * Fix array constructor handling reference of array. * Change test name --- php/ext/google/protobuf/message.c | 5 +++++ php/ext/google/protobuf/storage.c | 6 ++++++ php/tests/array_test.php | 31 +++++++++++++++++++++++++++++++ php/tests/proto/test.proto | 1 + 4 files changed, 43 insertions(+) diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index d883340f06..079bd1dd45 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -319,6 +319,11 @@ void Message_construct(zval* msg, zval* array_wrapper) { zend_hash_move_forward_ex(array, &pointer)) { zend_hash_get_current_key_zval_ex(array, &key, &pointer); field = upb_msgdef_ntofz(intern->descriptor->msgdef, Z_STRVAL_P(&key)); +#if PHP_MAJOR_VERSION >= 7 + if (Z_ISREF_P((CACHED_VALUE*)value)) { + value = Z_REFVAL_P((CACHED_VALUE*)value); + } +#endif if (field == NULL) { zend_error(E_USER_ERROR, "Unknown field: %s", Z_STRVAL_P(&key)); } diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index 93a16ddab4..610d3eb75e 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -186,6 +186,12 @@ bool native_slot_set_by_array(upb_fieldtype_t type, break; } case UPB_TYPE_MESSAGE: { +#if PHP_MAJOR_VERSION >= 7 + if (Z_ISREF_P(value)) { + ZVAL_DEREF(value); + } +#endif + if (Z_TYPE_P(value) != IS_OBJECT) { zend_error(E_USER_ERROR, "Given value is not message."); return false; diff --git a/php/tests/array_test.php b/php/tests/array_test.php index b0084332c9..d47a107765 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -529,6 +529,37 @@ class RepeatedFieldTest extends \PHPUnit\Framework\TestCase $this->assertSame(3, $arr[2]); } + ######################################################### + # Test reference in array + ######################################################### + + public function testArrayElementIsReference() + { + $m = new TestMessage(); + $subs = [1, 2]; + + foreach ($subs as &$sub) { + $sub = new Sub(['a' => $sub]); + } + + $m->setRepeatedMessage($subs); + } + + public function testArrayIsReference() + { + $keys = [['repeated_message' => [['a' => 1]]]]; + + foreach ($keys as &$key) { + foreach ($key['repeated_message'] as &$element) { + $element = new Sub($element); + } + $key = new TestMessage($key); + } + + $m = new TestMessage(); + $m->setRepeatedDeep($keys); + } + ######################################################### # Test memory leak ######################################################### diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto index e610c581b5..ca39ea46a4 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -31,6 +31,7 @@ message TestMessage { Sub optional_message = 17; bar.TestInclude optional_included_message = 18; TestMessage recursive = 19; + repeated TestMessage repeated_deep = 20; // Repeated repeated int32 repeated_int32 = 31; From 7f42d6d0bcadb286aa5120bc60441d4b56bacd93 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 22 Jan 2019 15:35:12 -0800 Subject: [PATCH 67/70] Fix empty FieldMask json encoding/decoding (#5605) * Fix empty FieldMask json encoding/decoding * Add failed test to python's conformance failure list --- conformance/binary_json_conformance_suite.cc | 4 + conformance/failure_list_python.txt | 1 + conformance/failure_list_python_cpp.txt | 1 + php/ext/google/protobuf/upb.c | 1178 +++++------------- php/src/Google/Protobuf/Internal/GPBUtil.php | 5 +- php/tests/encode_decode_test.php | 7 + 6 files changed, 318 insertions(+), 878 deletions(-) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index bdc3691239..45d9c1678d 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -2042,6 +2042,10 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { "FieldMask", REQUIRED, R"({"optionalFieldMask": "foo,barBaz"})", R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})"); + RunValidJsonTest( + "EmptyFieldMask", REQUIRED, + R"({"optionalFieldMask": ""})", + R"(optional_field_mask: {})"); ExpectParseFailureForJson( "FieldMaskInvalidCharacter", RECOMMENDED, R"({"optionalFieldMask": "foo,bar_bar"})"); diff --git a/conformance/failure_list_python.txt b/conformance/failure_list_python.txt index e3ce7af759..ce7cdec29a 100644 --- a/conformance/failure_list_python.txt +++ b/conformance/failure_list_python.txt @@ -19,3 +19,4 @@ Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0 Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1 Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_2 Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_3 +Required.Proto3.JsonInput.EmptyFieldMask.ProtobufOutput diff --git a/conformance/failure_list_python_cpp.txt b/conformance/failure_list_python_cpp.txt index 59a969d2f5..45319464a1 100644 --- a/conformance/failure_list_python_cpp.txt +++ b/conformance/failure_list_python_cpp.txt @@ -20,3 +20,4 @@ Required.Proto3.JsonInput.FloatFieldTooLarge Required.Proto3.JsonInput.FloatFieldTooSmall Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool Required.Proto3.JsonInput.TimestampJsonInputLowercaseT +Required.Proto3.JsonInput.EmptyFieldMask.ProtobufOutput diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c index a2634ce493..8452334ddf 100644 --- a/php/ext/google/protobuf/upb.c +++ b/php/ext/google/protobuf/upb.c @@ -15151,6 +15151,210 @@ static const char _json_actions[] = { 23, 24, 4, 14, 15, 16, 17 }; +static const short _json_key_offsets[] = { + 0, 0, 12, 13, 18, 23, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, + 38, 43, 44, 48, 53, 58, 63, 67, + 71, 74, 77, 79, 83, 87, 89, 91, + 96, 98, 100, 109, 115, 121, 127, 133, + 135, 139, 142, 144, 146, 149, 150, 154, + 156, 158, 160, 162, 163, 165, 167, 168, + 170, 172, 173, 175, 177, 178, 180, 182, + 183, 185, 187, 191, 193, 195, 196, 197, + 198, 199, 201, 206, 208, 210, 212, 221, + 222, 222, 222, 227, 232, 237, 238, 239, + 240, 241, 241, 242, 243, 244, 244, 245, + 246, 247, 247, 252, 253, 257, 262, 267, + 272, 276, 276, 279, 282, 285, 288, 291, + 294, 294, 294, 294, 294, 294 +}; + +static const char _json_trans_keys[] = { + 32, 34, 45, 91, 102, 110, 116, 123, + 9, 13, 48, 57, 34, 32, 93, 125, + 9, 13, 32, 44, 93, 9, 13, 32, + 93, 125, 9, 13, 97, 108, 115, 101, + 117, 108, 108, 114, 117, 101, 32, 34, + 125, 9, 13, 34, 32, 58, 9, 13, + 32, 93, 125, 9, 13, 32, 44, 125, + 9, 13, 32, 44, 125, 9, 13, 32, + 34, 9, 13, 45, 48, 49, 57, 48, + 49, 57, 46, 69, 101, 48, 57, 69, + 101, 48, 57, 43, 45, 48, 57, 48, + 57, 48, 57, 46, 69, 101, 48, 57, + 34, 92, 34, 92, 34, 47, 92, 98, + 102, 110, 114, 116, 117, 48, 57, 65, + 70, 97, 102, 48, 57, 65, 70, 97, + 102, 48, 57, 65, 70, 97, 102, 48, + 57, 65, 70, 97, 102, 34, 92, 45, + 48, 49, 57, 48, 49, 57, 46, 115, + 48, 57, 115, 48, 57, 34, 46, 115, + 48, 57, 48, 57, 48, 57, 48, 57, + 48, 57, 45, 48, 57, 48, 57, 45, + 48, 57, 48, 57, 84, 48, 57, 48, + 57, 58, 48, 57, 48, 57, 58, 48, + 57, 48, 57, 43, 45, 46, 90, 48, + 57, 48, 57, 58, 48, 48, 34, 48, + 57, 43, 45, 90, 48, 57, 34, 44, + 34, 44, 34, 44, 34, 45, 91, 102, + 110, 116, 123, 48, 57, 34, 32, 93, + 125, 9, 13, 32, 44, 93, 9, 13, + 32, 93, 125, 9, 13, 97, 108, 115, + 101, 117, 108, 108, 114, 117, 101, 32, + 34, 125, 9, 13, 34, 32, 58, 9, + 13, 32, 93, 125, 9, 13, 32, 44, + 125, 9, 13, 32, 44, 125, 9, 13, + 32, 34, 9, 13, 32, 9, 13, 32, + 9, 13, 32, 9, 13, 32, 9, 13, + 32, 9, 13, 32, 9, 13, 0 +}; + +static const char _json_single_lengths[] = { + 0, 8, 1, 3, 3, 3, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 3, 1, 2, 3, 3, 3, 2, 2, + 1, 3, 0, 2, 2, 0, 0, 3, + 2, 2, 9, 0, 0, 0, 0, 2, + 2, 1, 2, 0, 1, 1, 2, 0, + 0, 0, 0, 1, 0, 0, 1, 0, + 0, 1, 0, 0, 1, 0, 0, 1, + 0, 0, 4, 0, 0, 1, 1, 1, + 1, 0, 3, 2, 2, 2, 7, 1, + 0, 0, 3, 3, 3, 1, 1, 1, + 1, 0, 1, 1, 1, 0, 1, 1, + 1, 0, 3, 1, 2, 3, 3, 3, + 2, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0 +}; + +static const char _json_range_lengths[] = { + 0, 2, 0, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 1, 1, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 3, 3, 3, 3, 0, + 1, 1, 0, 1, 1, 0, 1, 1, + 1, 1, 1, 0, 1, 1, 0, 1, + 1, 0, 1, 1, 0, 1, 1, 0, + 1, 1, 0, 1, 1, 0, 0, 0, + 0, 1, 1, 0, 0, 0, 1, 0, + 0, 0, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0 +}; + +static const short _json_index_offsets[] = { + 0, 0, 11, 13, 18, 23, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, + 48, 53, 55, 59, 64, 69, 74, 78, + 82, 85, 89, 91, 95, 99, 101, 103, + 108, 111, 114, 124, 128, 132, 136, 140, + 143, 147, 150, 153, 155, 158, 160, 164, + 166, 168, 170, 172, 174, 176, 178, 180, + 182, 184, 186, 188, 190, 192, 194, 196, + 198, 200, 202, 207, 209, 211, 213, 215, + 217, 219, 221, 226, 229, 232, 235, 244, + 246, 247, 248, 253, 258, 263, 265, 267, + 269, 271, 272, 274, 276, 278, 279, 281, + 283, 285, 286, 291, 293, 297, 302, 307, + 312, 316, 317, 320, 323, 326, 329, 332, + 335, 336, 337, 338, 339, 340 +}; + +static const unsigned char _json_indicies[] = { + 0, 2, 3, 4, 5, 6, 7, 8, + 0, 3, 1, 9, 1, 11, 12, 1, + 11, 10, 13, 14, 12, 13, 1, 14, + 1, 1, 14, 10, 15, 1, 16, 1, + 17, 1, 18, 1, 19, 1, 20, 1, + 21, 1, 22, 1, 23, 1, 24, 1, + 25, 26, 27, 25, 1, 28, 1, 29, + 30, 29, 1, 30, 1, 1, 30, 31, + 32, 33, 34, 32, 1, 35, 36, 27, + 35, 1, 36, 26, 36, 1, 37, 38, + 39, 1, 38, 39, 1, 41, 42, 42, + 40, 43, 1, 42, 42, 43, 40, 44, + 44, 45, 1, 45, 1, 45, 40, 41, + 42, 42, 39, 40, 47, 48, 46, 50, + 51, 49, 52, 52, 52, 52, 52, 52, + 52, 52, 53, 1, 54, 54, 54, 1, + 55, 55, 55, 1, 56, 56, 56, 1, + 57, 57, 57, 1, 59, 60, 58, 61, + 62, 63, 1, 64, 65, 1, 66, 67, + 1, 68, 1, 67, 68, 1, 69, 1, + 66, 67, 65, 1, 70, 1, 71, 1, + 72, 1, 73, 1, 74, 1, 75, 1, + 76, 1, 77, 1, 78, 1, 79, 1, + 80, 1, 81, 1, 82, 1, 83, 1, + 84, 1, 85, 1, 86, 1, 87, 1, + 88, 1, 89, 89, 90, 91, 1, 92, + 1, 93, 1, 94, 1, 95, 1, 96, + 1, 97, 1, 98, 1, 99, 99, 100, + 98, 1, 102, 1, 101, 104, 105, 103, + 1, 1, 101, 106, 107, 108, 109, 110, + 111, 112, 107, 1, 113, 1, 114, 115, + 117, 118, 1, 117, 116, 119, 120, 118, + 119, 1, 120, 1, 1, 120, 116, 121, + 1, 122, 1, 123, 1, 124, 1, 125, + 126, 1, 127, 1, 128, 1, 129, 130, + 1, 131, 1, 132, 1, 133, 134, 135, + 136, 134, 1, 137, 1, 138, 139, 138, + 1, 139, 1, 1, 139, 140, 141, 142, + 143, 141, 1, 144, 145, 136, 144, 1, + 145, 135, 145, 1, 146, 147, 147, 1, + 148, 148, 1, 149, 149, 1, 150, 150, + 1, 151, 151, 1, 152, 152, 1, 1, + 1, 1, 1, 1, 1, 0 +}; + +static const char _json_trans_targs[] = { + 1, 0, 2, 107, 3, 6, 10, 13, + 16, 106, 4, 3, 106, 4, 5, 7, + 8, 9, 108, 11, 12, 109, 14, 15, + 110, 16, 17, 111, 18, 18, 19, 20, + 21, 22, 111, 21, 22, 24, 25, 31, + 112, 26, 28, 27, 29, 30, 33, 113, + 34, 33, 113, 34, 32, 35, 36, 37, + 38, 39, 33, 113, 34, 41, 42, 46, + 42, 46, 43, 45, 44, 114, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 73, 72, 68, 69, 70, 71, + 72, 115, 74, 67, 72, 76, 116, 76, + 116, 77, 79, 81, 82, 85, 90, 94, + 98, 80, 117, 117, 83, 82, 80, 83, + 84, 86, 87, 88, 89, 117, 91, 92, + 93, 117, 95, 96, 97, 117, 98, 99, + 105, 100, 100, 101, 102, 103, 104, 105, + 103, 104, 117, 106, 106, 106, 106, 106, + 106 +}; + +static const char _json_trans_actions[] = { + 0, 0, 92, 86, 35, 0, 0, 0, + 104, 41, 27, 0, 37, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 80, 33, 29, 0, 0, 27, + 31, 31, 83, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 5, 15, + 0, 0, 53, 7, 13, 0, 56, 9, + 9, 9, 59, 62, 11, 17, 17, 17, + 0, 0, 0, 19, 0, 21, 23, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 114, 65, 114, 0, 0, 0, 0, + 0, 71, 0, 68, 68, 77, 25, 0, + 110, 74, 92, 86, 35, 0, 0, 0, + 104, 41, 51, 89, 27, 0, 37, 0, + 0, 0, 0, 0, 0, 98, 0, 0, + 0, 101, 0, 0, 0, 95, 0, 80, + 33, 29, 0, 0, 27, 31, 31, 83, + 0, 0, 107, 0, 39, 45, 47, 43, + 49 +}; + static const char _json_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -15203,883 +15407,83 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -#line 2627 "upb/json/parser.c" +#line 2831 "upb/json/parser.c" { + int _klen; + unsigned int _trans; const char *_acts; unsigned int _nacts; + const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: - switch ( cs ) { -case 1: - switch( (*p) ) { - case 32: goto tr0; - case 34: goto tr2; - case 45: goto tr3; - case 91: goto tr4; - case 102: goto tr5; - case 110: goto tr6; - case 116: goto tr7; - case 123: goto tr8; - } - if ( (*p) > 13 ) { - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr3; - } else if ( (*p) >= 9 ) - goto tr0; - goto tr1; -case 0: - goto _out; -case 2: - if ( (*p) == 34 ) - goto tr9; - goto tr1; -case 106: - if ( (*p) == 32 ) - goto tr147; - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr147; - goto tr1; -case 107: - if ( (*p) == 32 ) - goto tr148; - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr148; - goto tr1; -case 3: - switch( (*p) ) { - case 32: goto tr11; - case 93: goto tr12; - case 125: goto tr1; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr11; - goto tr10; -case 4: - switch( (*p) ) { - case 32: goto tr13; - case 44: goto tr14; - case 93: goto tr12; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr13; - goto tr1; -case 5: - switch( (*p) ) { - case 32: goto tr14; - case 93: goto tr1; - case 125: goto tr1; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr14; - goto tr10; -case 6: - if ( (*p) == 97 ) - goto tr15; - goto tr1; -case 7: - if ( (*p) == 108 ) - goto tr16; - goto tr1; -case 8: - if ( (*p) == 115 ) - goto tr17; - goto tr1; -case 9: - if ( (*p) == 101 ) - goto tr18; - goto tr1; -case 108: - if ( (*p) == 32 ) - goto tr149; - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr149; - goto tr1; -case 10: - if ( (*p) == 117 ) - goto tr19; - goto tr1; -case 11: - if ( (*p) == 108 ) - goto tr20; - goto tr1; -case 12: - if ( (*p) == 108 ) - goto tr21; - goto tr1; -case 109: - if ( (*p) == 32 ) - goto tr150; - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr150; - goto tr1; -case 13: - if ( (*p) == 114 ) - goto tr22; - goto tr1; -case 14: - if ( (*p) == 117 ) - goto tr23; - goto tr1; -case 15: - if ( (*p) == 101 ) - goto tr24; - goto tr1; -case 110: - if ( (*p) == 32 ) - goto tr151; - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr151; - goto tr1; -case 16: - switch( (*p) ) { - case 32: goto tr25; - case 34: goto tr26; - case 125: goto tr27; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr25; - goto tr1; -case 17: - if ( (*p) == 34 ) - goto tr28; - goto tr1; -case 18: - switch( (*p) ) { - case 32: goto tr29; - case 58: goto tr30; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr29; - goto tr1; -case 19: - switch( (*p) ) { - case 32: goto tr30; - case 93: goto tr1; - case 125: goto tr1; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr30; - goto tr31; -case 20: - switch( (*p) ) { - case 32: goto tr32; - case 44: goto tr33; - case 125: goto tr34; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr32; - goto tr1; -case 21: - switch( (*p) ) { - case 32: goto tr35; - case 44: goto tr36; - case 125: goto tr27; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr35; - goto tr1; -case 22: - switch( (*p) ) { - case 32: goto tr36; - case 34: goto tr26; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr36; - goto tr1; -case 111: - if ( (*p) == 32 ) - goto tr152; - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr152; - goto tr1; -case 23: - switch( (*p) ) { - case 45: goto tr37; - case 48: goto tr38; - } - if ( 49 <= (*p) && (*p) <= 57 ) - goto tr39; - goto tr1; -case 24: - if ( (*p) == 48 ) - goto tr38; - if ( 49 <= (*p) && (*p) <= 57 ) - goto tr39; - goto tr1; -case 25: - switch( (*p) ) { - case 46: goto tr41; - case 69: goto tr42; - case 101: goto tr42; - } - goto tr40; -case 112: - goto tr1; -case 26: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr43; - goto tr1; -case 27: - switch( (*p) ) { - case 69: goto tr42; - case 101: goto tr42; - } - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr43; - goto tr40; -case 28: - switch( (*p) ) { - case 43: goto tr44; - case 45: goto tr44; - } - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr45; - goto tr1; -case 29: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr45; - goto tr1; -case 30: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr45; - goto tr40; -case 31: - switch( (*p) ) { - case 46: goto tr41; - case 69: goto tr42; - case 101: goto tr42; - } - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr39; - goto tr40; -case 32: - switch( (*p) ) { - case 34: goto tr47; - case 92: goto tr48; - } - goto tr46; -case 33: - switch( (*p) ) { - case 34: goto tr50; - case 92: goto tr51; - } - goto tr49; -case 113: - goto tr1; -case 34: - switch( (*p) ) { - case 34: goto tr52; - case 47: goto tr52; - case 92: goto tr52; - case 98: goto tr52; - case 102: goto tr52; - case 110: goto tr52; - case 114: goto tr52; - case 116: goto tr52; - case 117: goto tr53; - } - goto tr1; -case 35: - if ( (*p) < 65 ) { - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr54; - } else if ( (*p) > 70 ) { - if ( 97 <= (*p) && (*p) <= 102 ) - goto tr54; - } else - goto tr54; - goto tr1; -case 36: - if ( (*p) < 65 ) { - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr55; - } else if ( (*p) > 70 ) { - if ( 97 <= (*p) && (*p) <= 102 ) - goto tr55; - } else - goto tr55; - goto tr1; -case 37: - if ( (*p) < 65 ) { - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr56; - } else if ( (*p) > 70 ) { - if ( 97 <= (*p) && (*p) <= 102 ) - goto tr56; - } else - goto tr56; - goto tr1; -case 38: - if ( (*p) < 65 ) { - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr57; - } else if ( (*p) > 70 ) { - if ( 97 <= (*p) && (*p) <= 102 ) - goto tr57; - } else - goto tr57; - goto tr1; -case 39: - switch( (*p) ) { - case 34: goto tr59; - case 92: goto tr60; - } - goto tr58; -case 40: - switch( (*p) ) { - case 45: goto tr61; - case 48: goto tr62; - } - if ( 49 <= (*p) && (*p) <= 57 ) - goto tr63; - goto tr1; -case 41: - if ( (*p) == 48 ) - goto tr64; - if ( 49 <= (*p) && (*p) <= 57 ) - goto tr65; - goto tr1; -case 42: - switch( (*p) ) { - case 46: goto tr66; - case 115: goto tr67; - } - goto tr1; -case 43: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr68; - goto tr1; -case 44: - if ( (*p) == 115 ) - goto tr67; - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr68; - goto tr1; -case 45: - if ( (*p) == 34 ) - goto tr69; - goto tr1; -case 114: - goto tr1; -case 46: - switch( (*p) ) { - case 46: goto tr66; - case 115: goto tr67; - } - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr65; - goto tr1; -case 47: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr70; - goto tr1; -case 48: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr71; - goto tr1; -case 49: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr72; - goto tr1; -case 50: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr73; - goto tr1; -case 51: - if ( (*p) == 45 ) - goto tr74; - goto tr1; -case 52: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr75; - goto tr1; -case 53: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr76; - goto tr1; -case 54: - if ( (*p) == 45 ) - goto tr77; - goto tr1; -case 55: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr78; - goto tr1; -case 56: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr79; - goto tr1; -case 57: - if ( (*p) == 84 ) - goto tr80; - goto tr1; -case 58: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr81; - goto tr1; -case 59: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr82; - goto tr1; -case 60: - if ( (*p) == 58 ) - goto tr83; - goto tr1; -case 61: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr84; - goto tr1; -case 62: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr85; - goto tr1; -case 63: - if ( (*p) == 58 ) - goto tr86; - goto tr1; -case 64: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr87; - goto tr1; -case 65: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr88; - goto tr1; -case 66: - switch( (*p) ) { - case 43: goto tr89; - case 45: goto tr89; - case 46: goto tr90; - case 90: goto tr91; - } - goto tr1; -case 67: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr92; - goto tr1; -case 68: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr93; - goto tr1; -case 69: - if ( (*p) == 58 ) - goto tr94; - goto tr1; -case 70: - if ( (*p) == 48 ) - goto tr95; - goto tr1; -case 71: - if ( (*p) == 48 ) - goto tr96; - goto tr1; -case 72: - if ( (*p) == 34 ) - goto tr97; - goto tr1; -case 115: - goto tr1; -case 73: - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr98; - goto tr1; -case 74: - switch( (*p) ) { - case 43: goto tr99; - case 45: goto tr99; - case 90: goto tr100; - } - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr98; - goto tr1; -case 75: - switch( (*p) ) { - case 34: goto tr102; - case 44: goto tr1; - } - goto tr101; -case 76: - switch( (*p) ) { - case 34: goto tr104; - case 44: goto tr105; - } - goto tr103; -case 116: - goto tr1; -case 77: - switch( (*p) ) { - case 34: goto tr1; - case 44: goto tr1; - } - goto tr101; -case 78: - switch( (*p) ) { - case 34: goto tr106; - case 45: goto tr107; - case 91: goto tr108; - case 102: goto tr109; - case 110: goto tr110; - case 116: goto tr111; - case 123: goto tr112; - } - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr107; - goto tr1; -case 79: - if ( (*p) == 34 ) - goto tr113; - goto tr1; -case 80: - goto tr114; -case 117: - goto tr1; -case 81: - goto tr115; -case 82: - switch( (*p) ) { - case 32: goto tr117; - case 93: goto tr118; - case 125: goto tr1; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr117; - goto tr116; -case 83: - switch( (*p) ) { - case 32: goto tr119; - case 44: goto tr120; - case 93: goto tr118; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr119; - goto tr1; -case 84: - switch( (*p) ) { - case 32: goto tr120; - case 93: goto tr1; - case 125: goto tr1; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr120; - goto tr116; -case 85: - if ( (*p) == 97 ) - goto tr121; - goto tr1; -case 86: - if ( (*p) == 108 ) - goto tr122; - goto tr1; -case 87: - if ( (*p) == 115 ) - goto tr123; - goto tr1; -case 88: - if ( (*p) == 101 ) - goto tr124; - goto tr1; -case 89: - goto tr125; -case 90: - if ( (*p) == 117 ) - goto tr126; - goto tr1; -case 91: - if ( (*p) == 108 ) - goto tr127; - goto tr1; -case 92: - if ( (*p) == 108 ) - goto tr128; - goto tr1; -case 93: - goto tr129; -case 94: - if ( (*p) == 114 ) - goto tr130; - goto tr1; -case 95: - if ( (*p) == 117 ) - goto tr131; - goto tr1; -case 96: - if ( (*p) == 101 ) - goto tr132; - goto tr1; -case 97: - goto tr133; -case 98: - switch( (*p) ) { - case 32: goto tr134; - case 34: goto tr135; - case 125: goto tr136; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr134; - goto tr1; -case 99: - if ( (*p) == 34 ) - goto tr137; - goto tr1; -case 100: - switch( (*p) ) { - case 32: goto tr138; - case 58: goto tr139; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr138; - goto tr1; -case 101: - switch( (*p) ) { - case 32: goto tr139; - case 93: goto tr1; - case 125: goto tr1; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr139; - goto tr140; -case 102: - switch( (*p) ) { - case 32: goto tr141; - case 44: goto tr142; - case 125: goto tr143; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr141; - goto tr1; -case 103: - switch( (*p) ) { - case 32: goto tr144; - case 44: goto tr145; - case 125: goto tr136; - } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr144; - goto tr1; -case 104: - switch( (*p) ) { - case 32: goto tr145; - case 34: goto tr135; + _keys = _json_trans_keys + _json_key_offsets[cs]; + _trans = _json_index_offsets[cs]; + + _klen = _json_single_lengths[cs]; + if ( _klen > 0 ) { + const char *_lower = _keys; + const char *_mid; + const char *_upper = _keys + _klen - 1; + while (1) { + if ( _upper < _lower ) + break; + + _mid = _lower + ((_upper-_lower) >> 1); + if ( (*p) < *_mid ) + _upper = _mid - 1; + else if ( (*p) > *_mid ) + _lower = _mid + 1; + else { + _trans += (unsigned int)(_mid - _keys); + goto _match; + } + } + _keys += _klen; + _trans += _klen; } - if ( 9 <= (*p) && (*p) <= 13 ) - goto tr145; - goto tr1; -case 105: - goto tr146; + + _klen = _json_range_lengths[cs]; + if ( _klen > 0 ) { + const char *_lower = _keys; + const char *_mid; + const char *_upper = _keys + (_klen<<1) - 2; + while (1) { + if ( _upper < _lower ) + break; + + _mid = _lower + (((_upper-_lower) >> 1) & ~1); + if ( (*p) < _mid[0] ) + _upper = _mid - 2; + else if ( (*p) > _mid[1] ) + _lower = _mid + 2; + else { + _trans += (unsigned int)((_mid - _keys)>>1); + goto _match; + } + } + _trans += _klen; } - tr1: cs = 0; goto _again; - tr0: cs = 1; goto _again; - tr2: cs = 2; goto f0; - tr11: cs = 3; goto _again; - tr4: cs = 3; goto f2; - tr13: cs = 4; goto _again; - tr10: cs = 4; goto f5; - tr14: cs = 5; goto _again; - tr5: cs = 6; goto _again; - tr15: cs = 7; goto _again; - tr16: cs = 8; goto _again; - tr17: cs = 9; goto _again; - tr6: cs = 10; goto _again; - tr19: cs = 11; goto _again; - tr20: cs = 12; goto _again; - tr7: cs = 13; goto _again; - tr22: cs = 14; goto _again; - tr23: cs = 15; goto _again; - tr25: cs = 16; goto _again; - tr8: cs = 16; goto f3; - tr26: cs = 17; goto f7; - tr29: cs = 18; goto _again; - tr28: cs = 18; goto f9; - tr30: cs = 19; goto _again; - tr31: cs = 20; goto f5; - tr35: cs = 21; goto _again; - tr32: cs = 21; goto f10; - tr36: cs = 22; goto _again; - tr33: cs = 22; goto f10; - tr37: cs = 24; goto _again; - tr38: cs = 25; goto _again; - tr41: cs = 26; goto _again; - tr43: cs = 27; goto _again; - tr42: cs = 28; goto _again; - tr44: cs = 29; goto _again; - tr45: cs = 30; goto _again; - tr39: cs = 31; goto _again; - tr52: cs = 32; goto f18; - tr49: cs = 33; goto _again; - tr46: cs = 33; goto f14; - tr58: cs = 33; goto f21; - tr48: cs = 34; goto _again; - tr51: cs = 34; goto f17; - tr60: cs = 34; goto f23; - tr53: cs = 35; goto _again; - tr54: cs = 36; goto f19; - tr55: cs = 37; goto f20; - tr56: cs = 38; goto f20; - tr57: cs = 39; goto f20; - tr61: cs = 41; goto f24; - tr64: cs = 42; goto _again; - tr62: cs = 42; goto f24; - tr66: cs = 43; goto _again; - tr68: cs = 44; goto _again; - tr67: cs = 45; goto f25; - tr65: cs = 46; goto _again; - tr63: cs = 46; goto f24; - tr70: cs = 48; goto f27; - tr71: cs = 49; goto _again; - tr72: cs = 50; goto _again; - tr73: cs = 51; goto _again; - tr74: cs = 52; goto _again; - tr75: cs = 53; goto _again; - tr76: cs = 54; goto _again; - tr77: cs = 55; goto _again; - tr78: cs = 56; goto _again; - tr79: cs = 57; goto _again; - tr80: cs = 58; goto _again; - tr81: cs = 59; goto _again; - tr82: cs = 60; goto _again; - tr83: cs = 61; goto _again; - tr84: cs = 62; goto _again; - tr85: cs = 63; goto _again; - tr86: cs = 64; goto _again; - tr87: cs = 65; goto _again; - tr88: cs = 66; goto _again; - tr89: cs = 67; goto f28; - tr99: cs = 67; goto f31; - tr92: cs = 68; goto _again; - tr93: cs = 69; goto _again; - tr94: cs = 70; goto _again; - tr95: cs = 71; goto _again; - tr96: cs = 72; goto _again; - tr91: cs = 72; goto f28; - tr100: cs = 72; goto f31; - tr90: cs = 73; goto f29; - tr98: cs = 74; goto _again; - tr103: cs = 76; goto _again; - tr101: cs = 76; goto f32; - tr105: cs = 77; goto f35; - tr106: cs = 79; goto f0; - tr113: cs = 80; goto f4; - tr118: cs = 80; goto f6; - tr107: cs = 81; goto f1; - tr117: cs = 82; goto _again; - tr108: cs = 82; goto f2; - tr119: cs = 83; goto _again; - tr116: cs = 83; goto f5; - tr120: cs = 84; goto _again; - tr109: cs = 85; goto _again; - tr121: cs = 86; goto _again; - tr122: cs = 87; goto _again; - tr123: cs = 88; goto _again; - tr124: cs = 89; goto _again; - tr110: cs = 90; goto _again; - tr126: cs = 91; goto _again; - tr127: cs = 92; goto _again; - tr128: cs = 93; goto _again; - tr111: cs = 94; goto _again; - tr130: cs = 95; goto _again; - tr131: cs = 96; goto _again; - tr132: cs = 97; goto _again; - tr134: cs = 98; goto _again; - tr112: cs = 98; goto f3; - tr135: cs = 99; goto f7; - tr138: cs = 100; goto _again; - tr137: cs = 100; goto f9; - tr139: cs = 101; goto _again; - tr140: cs = 102; goto f5; - tr144: cs = 103; goto _again; - tr141: cs = 103; goto f10; - tr145: cs = 104; goto _again; - tr142: cs = 104; goto f10; - tr136: cs = 105; goto f8; - tr143: cs = 105; goto f11; - tr147: cs = 106; goto _again; - tr9: cs = 106; goto f4; - tr12: cs = 106; goto f6; - tr148: cs = 106; goto f42; - tr149: cs = 106; goto f43; - tr150: cs = 106; goto f44; - tr151: cs = 106; goto f45; - tr152: cs = 106; goto f46; - tr3: cs = 107; goto f1; - tr18: cs = 108; goto _again; - tr21: cs = 109; goto _again; - tr24: cs = 110; goto _again; - tr27: cs = 111; goto f8; - tr34: cs = 111; goto f11; - tr40: cs = 112; goto f13; - tr47: cs = 113; goto f15; - tr50: cs = 113; goto f16; - tr59: cs = 113; goto f22; - tr69: cs = 114; goto f26; - tr97: cs = 115; goto f30; - tr102: cs = 116; goto f33; - tr104: cs = 116; goto f34; - tr114: cs = 117; goto f36; - tr115: cs = 117; goto f37; - tr125: cs = 117; goto f38; - tr129: cs = 117; goto f39; - tr133: cs = 117; goto f40; - tr146: cs = 117; goto f41; - - f13: _acts = _json_actions + 3; goto execFuncs; - f14: _acts = _json_actions + 5; goto execFuncs; - f17: _acts = _json_actions + 7; goto execFuncs; - f20: _acts = _json_actions + 9; goto execFuncs; - f23: _acts = _json_actions + 11; goto execFuncs; - f18: _acts = _json_actions + 13; goto execFuncs; - f15: _acts = _json_actions + 15; goto execFuncs; - f24: _acts = _json_actions + 17; goto execFuncs; - f25: _acts = _json_actions + 19; goto execFuncs; - f26: _acts = _json_actions + 21; goto execFuncs; - f27: _acts = _json_actions + 23; goto execFuncs; - f33: _acts = _json_actions + 25; goto execFuncs; - f5: _acts = _json_actions + 27; goto execFuncs; - f9: _acts = _json_actions + 29; goto execFuncs; - f10: _acts = _json_actions + 31; goto execFuncs; - f8: _acts = _json_actions + 33; goto execFuncs; - f2: _acts = _json_actions + 35; goto execFuncs; - f6: _acts = _json_actions + 37; goto execFuncs; - f42: _acts = _json_actions + 39; goto execFuncs; - f4: _acts = _json_actions + 41; goto execFuncs; - f45: _acts = _json_actions + 43; goto execFuncs; - f43: _acts = _json_actions + 45; goto execFuncs; - f44: _acts = _json_actions + 47; goto execFuncs; - f46: _acts = _json_actions + 49; goto execFuncs; - f36: _acts = _json_actions + 51; goto execFuncs; - f16: _acts = _json_actions + 53; goto execFuncs; - f19: _acts = _json_actions + 56; goto execFuncs; - f21: _acts = _json_actions + 59; goto execFuncs; - f22: _acts = _json_actions + 62; goto execFuncs; - f29: _acts = _json_actions + 65; goto execFuncs; - f31: _acts = _json_actions + 68; goto execFuncs; - f30: _acts = _json_actions + 71; goto execFuncs; - f35: _acts = _json_actions + 74; goto execFuncs; - f32: _acts = _json_actions + 77; goto execFuncs; - f7: _acts = _json_actions + 80; goto execFuncs; - f11: _acts = _json_actions + 83; goto execFuncs; - f1: _acts = _json_actions + 86; goto execFuncs; - f37: _acts = _json_actions + 89; goto execFuncs; - f0: _acts = _json_actions + 92; goto execFuncs; - f40: _acts = _json_actions + 95; goto execFuncs; - f38: _acts = _json_actions + 98; goto execFuncs; - f39: _acts = _json_actions + 101; goto execFuncs; - f3: _acts = _json_actions + 104; goto execFuncs; - f41: _acts = _json_actions + 107; goto execFuncs; - f34: _acts = _json_actions + 110; goto execFuncs; - f28: _acts = _json_actions + 114; goto execFuncs; - -execFuncs: - _nacts = *_acts++; - while ( _nacts-- > 0 ) { - switch ( *_acts++ ) { +_match: + _trans = _json_indicies[_trans]; + cs = _json_trans_targs[_trans]; + + if ( _json_trans_actions[_trans] == 0 ) + goto _again; + + _acts = _json_actions + _json_trans_actions[_trans]; + _nacts = (unsigned int) *_acts++; + while ( _nacts-- > 0 ) + { + switch ( *_acts++ ) + { case 1: #line 2561 "upb/json/parser.rl" - { p--; {cs = stack[--top];goto _again;} } + { p--; {cs = stack[--top]; goto _again;} } break; case 2: #line 2563 "upb/json/parser.rl" @@ -16111,7 +15515,7 @@ execFuncs: break; case 9: #line 2588 "upb/json/parser.rl" - { p--; {cs = stack[--top];goto _again;} } + { p--; {cs = stack[--top]; goto _again;} } break; case 10: #line 2600 "upb/json/parser.rl" @@ -16123,7 +15527,7 @@ execFuncs: break; case 12: #line 2603 "upb/json/parser.rl" - { p--; {cs = stack[--top];goto _again;} } + { p--; {cs = stack[--top]; goto _again;} } break; case 13: #line 2608 "upb/json/parser.rl" @@ -16151,7 +15555,7 @@ execFuncs: break; case 19: #line 2617 "upb/json/parser.rl" - { p--; {cs = stack[--top];goto _again;} } + { p--; {cs = stack[--top]; goto _again;} } break; case 20: #line 2622 "upb/json/parser.rl" @@ -16171,7 +15575,7 @@ execFuncs: break; case 24: #line 2635 "upb/json/parser.rl" - { p--; {cs = stack[--top];goto _again;} } + { p--; {cs = stack[--top]; goto _again;} } break; case 25: #line 2640 "upb/json/parser.rl" @@ -16281,12 +15685,11 @@ execFuncs: break; case 43: #line 2727 "upb/json/parser.rl" - { p--; {cs = stack[--top];goto _again;} } + { p--; {cs = stack[--top]; goto _again;} } break; -#line 3707 "upb/json/parser.c" +#line 3111 "upb/json/parser.c" } } - goto _again; _again: if ( cs == 0 ) @@ -16302,7 +15705,7 @@ _again: switch ( *__acts++ ) { case 0: #line 2559 "upb/json/parser.rl" - { p--; {cs = stack[--top]; if ( p == pe ) + { p--; {cs = stack[--top]; if ( p == pe ) goto _test_eof; goto _again;} } break; @@ -16326,7 +15729,7 @@ goto _again;} } #line 2722 "upb/json/parser.rl" { end_subobject_full(parser); } break; -#line 3750 "upb/json/parser.c" +#line 3153 "upb/json/parser.c" } } } @@ -16383,7 +15786,7 @@ static void json_parser_reset(upb_json_parser *p) { /* Emit Ragel initialization of the parser. */ -#line 3807 "upb/json/parser.c" +#line 3210 "upb/json/parser.c" { cs = json_start; top = 0; @@ -17298,7 +16701,6 @@ static void *startseq_fieldmask(void *closure, const void *handler_data) { UPB_UNUSED(handler_data); p->depth_++; p->first_elem_[p->depth_] = true; - print_data(p, "\"", 1); return closure; } @@ -17306,7 +16708,6 @@ static bool endseq_fieldmask(void *closure, const void *handler_data) { upb_json_printer *p = closure; UPB_UNUSED(handler_data); p->depth_--; - print_data(p, "\"", 1); return true; } @@ -17526,6 +16927,29 @@ static bool printer_endmsg_noframe( return true; } +static bool printer_startmsg_fieldmask( + void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + if (p->depth_ == 0) { + upb_bytessink_start(p->output_, 0, &p->subc_); + } + print_data(p, "\"", 1); + return true; +} + +static bool printer_endmsg_fieldmask( + void *closure, const void *handler_data, upb_status *s) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(s); + print_data(p, "\"", 1); + if (p->depth_ == 0) { + upb_bytessink_end(p->output_); + } + return true; +} + static void *scalar_startstr_onlykey( void *closure, const void *handler_data, size_t size_hint) { upb_json_printer *p = closure; @@ -17579,8 +17003,8 @@ void printer_sethandlers_fieldmask(const void *closure, upb_handlers *h) { upb_handlers_setstartseq(h, f, startseq_fieldmask, &empty_attr); upb_handlers_setendseq(h, f, endseq_fieldmask, &empty_attr); - upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); - upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + upb_handlers_setstartmsg(h, printer_startmsg_fieldmask, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_fieldmask, &empty_attr); upb_handlers_setstartstr(h, f, repeated_startstr_fieldmask, &empty_attr); upb_handlers_setstring(h, f, repeated_str_fieldmask, &empty_attr); diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 7b5cc7d1f3..0beedba333 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -518,8 +518,11 @@ class GPBUtil public static function parseFieldMask($paths_string) { - $path_strings = explode(",", $paths_string); $field_mask = new FieldMask(); + if (strlen($paths_string) === 0) { + return $field_mask; + } + $path_strings = explode(",", $paths_string); $paths = $field_mask->getPaths(); foreach($path_strings as &$path_string) { $field_strings = explode(".", $path_string); diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 61527e899a..4107d65bb6 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -1128,4 +1128,11 @@ class EncodeDecodeTest extends TestBase $this->assertSame("\"foo.barBaz,qux\"", $m->serializeToJsonString()); } + public function testDecodeEmptyFieldMask() + { + $m = new FieldMask(); + $m->mergeFromJsonString("\"\""); + $this->assertEquals("", $m->serializeToString()); + } + } From 4f8a635679c43c546764b4af9cc7132e1854e080 Mon Sep 17 00:00:00 2001 From: Hao Nguyen <45579440+haon4@users.noreply.github.com> Date: Wed, 23 Jan 2019 10:02:51 -0800 Subject: [PATCH 68/70] Create test for protoc with tcmalloc (#5612) * Add TC malloc kokoro test * Update tcmalloc test --- kokoro/linux/cpp_tcmalloc/build.sh | 13 +++++++++ kokoro/linux/cpp_tcmalloc/continuous.cfg | 5 ++++ kokoro/linux/cpp_tcmalloc/presubmit.cfg | 5 ++++ .../dockerfile/test/cpp_tcmalloc/Dockerfile | 29 +++++++++++++++++++ tests.sh | 9 ++++++ 5 files changed, 61 insertions(+) create mode 100755 kokoro/linux/cpp_tcmalloc/build.sh create mode 100644 kokoro/linux/cpp_tcmalloc/continuous.cfg create mode 100644 kokoro/linux/cpp_tcmalloc/presubmit.cfg create mode 100644 kokoro/linux/dockerfile/test/cpp_tcmalloc/Dockerfile diff --git a/kokoro/linux/cpp_tcmalloc/build.sh b/kokoro/linux/cpp_tcmalloc/build.sh new file mode 100755 index 0000000000..3c77b11e70 --- /dev/null +++ b/kokoro/linux/cpp_tcmalloc/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Build file to set up and run tests + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/cpp_tcmalloc +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="cpp_tcmalloc" +./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/cpp_tcmalloc/continuous.cfg b/kokoro/linux/cpp_tcmalloc/continuous.cfg new file mode 100644 index 0000000000..46312a9be2 --- /dev/null +++ b/kokoro/linux/cpp_tcmalloc/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cpp_tcmalloc/build.sh" +timeout_mins: 1440 diff --git a/kokoro/linux/cpp_tcmalloc/presubmit.cfg b/kokoro/linux/cpp_tcmalloc/presubmit.cfg new file mode 100644 index 0000000000..46312a9be2 --- /dev/null +++ b/kokoro/linux/cpp_tcmalloc/presubmit.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cpp_tcmalloc/build.sh" +timeout_mins: 1440 diff --git a/kokoro/linux/dockerfile/test/cpp_tcmalloc/Dockerfile b/kokoro/linux/dockerfile/test/cpp_tcmalloc/Dockerfile new file mode 100644 index 0000000000..0ce9982ad4 --- /dev/null +++ b/kokoro/linux/dockerfile/test/cpp_tcmalloc/Dockerfile @@ -0,0 +1,29 @@ +FROM debian:jessie + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean + +# Install dependencies for TC malloc +RUN apt-get install -y \ + google-perftools \ + libgoogle-perftools4 \ + libgoogle-perftools-dev diff --git a/tests.sh b/tests.sh index 5b369485e2..2f453bdc80 100755 --- a/tests.sh +++ b/tests.sh @@ -38,6 +38,15 @@ build_cpp() { fi } +build_cpp_tcmalloc() { + internal_build_cpp + ./configure LIBS=-ltcmalloc && make clean && make \ + PTHREAD_CFLAGS='-pthread -DGOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN' \ + check + cd src + PPROF_PATH=/usr/bin/google-pprof HEAPCHECK=draconian ./protobuf-test +} + build_cpp_distcheck() { # Initialize any submodules. git submodule update --init --recursive From 30851ca2662c5a3e8323432bc660e37345f8fae1 Mon Sep 17 00:00:00 2001 From: Hao Nguyen <45579440+haon4@users.noreply.github.com> Date: Wed, 23 Jan 2019 10:55:36 -0800 Subject: [PATCH 69/70] Fix protoc release (#5615) * Fix protoc release * Update Dockerfile to include libatomic --- protoc-artifacts/Dockerfile | 17 ++++++++++++++--- protoc-artifacts/build-protoc.sh | 10 +++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/protoc-artifacts/Dockerfile b/protoc-artifacts/Dockerfile index 95086eae7e..278bc7452d 100644 --- a/protoc-artifacts/Dockerfile +++ b/protoc-artifacts/Dockerfile @@ -33,9 +33,20 @@ RUN wget http://people.centos.org/tru/devtools-2/devtools-2.repo -P /etc/yum.rep bash -c 'echo "enabled=1" >> /etc/yum.repos.d/devtools-2.repo' && \ bash -c "sed -e 's/\$basearch/i386/g' /etc/yum.repos.d/devtools-2.repo > /etc/yum.repos.d/devtools-i386-2.repo" && \ sed -e 's/testing-/testing-i386-/g' -i /etc/yum.repos.d/devtools-i386-2.repo && \ - rpm --rebuilddb && \ - yum install -y devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils devtoolset-2-libstdc++-devel \ - devtoolset-2-gcc.i686 devtoolset-2-gcc-c++.i686 devtoolset-2-binutils.i686 devtoolset-2-libstdc++-devel.i686 && \ + rpm --rebuilddb + +RUN yum install -y devtoolset-2-gcc \ + devtoolset-2-gcc-c++ \ + devtoolset-2-binutils \ + devtoolset-2-libstdc++-devel \ + devtoolset-2-libatomic-devel \ + libatomic \ + devtoolset-2-gcc.i686 \ + devtoolset-2-gcc-c++.i686 \ + devtoolset-2-binutils.i686 \ + devtoolset-2-libstdc++-devel.i686 \ + devtoolset-2-libatomic-devel.i686 \ + libatomic.i686 && \ yum clean all COPY scl-enable-devtoolset.sh /var/local/ diff --git a/protoc-artifacts/build-protoc.sh b/protoc-artifacts/build-protoc.sh index b8d2eb8762..305cf21ade 100755 --- a/protoc-artifacts/build-protoc.sh +++ b/protoc-artifacts/build-protoc.sh @@ -95,8 +95,8 @@ checkArch () assertEq $format "elf64-little" $LINENO elif [[ "$ARCH" == ppcle_64 ]]; then if [[ $host_machine == ppc64le ]];then - assertEq $format "elf64-powerpcle" $LINENO - else + assertEq $format "elf64-powerpcle" $LINENO + else assertEq $format "elf64-little" $LINENO fi else @@ -140,11 +140,11 @@ checkDependencies () host_machine="$(uname -m)"; dump_cmd='ldd '"$1" if [[ "$ARCH" == x86_32 ]]; then - white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2" + white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2\|libatomic\.so\.1" elif [[ "$ARCH" == x86_64 ]]; then - white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2" + white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2\|libatomic\.so\.1" elif [[ "$ARCH" == ppcle_64 ]]; then - if [[ $host_machine != ppc64le ]];then + if [[ $host_machine != ppc64le ]];then dump_cmd='objdump -p '"$1"' | grep NEEDED' fi white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libz\.so\.1\|ld64\.so\.2" From d750fbf648256c7c631f51ffdbf67d7c18b0114e Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 23 Jan 2019 12:44:20 -0800 Subject: [PATCH 70/70] Fix more issues for reference values (#5613) * Fix more issues for reference values * Revert change in gdb test * Add more tests --- php/ext/google/protobuf/storage.c | 16 +++-- php/ext/google/protobuf/type_check.c | 5 ++ php/tests/array_test.php | 44 +++++++----- php/tests/generated_class_test.php | 103 +++++++++++++++++++++++++++ php/tests/map_field_test.php | 37 ++++++++++ php/tests/proto/test.proto | 1 - 6 files changed, 181 insertions(+), 25 deletions(-) diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index 610d3eb75e..0c5b68c578 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -161,6 +161,11 @@ bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, bool native_slot_set_by_array(upb_fieldtype_t type, const zend_class_entry* klass, void* memory, zval* value TSRMLS_DC) { +#if PHP_MAJOR_VERSION >= 7 + if (Z_ISREF_P(value)) { + ZVAL_DEREF(value); + } +#endif switch (type) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { @@ -186,12 +191,6 @@ bool native_slot_set_by_array(upb_fieldtype_t type, break; } case UPB_TYPE_MESSAGE: { -#if PHP_MAJOR_VERSION >= 7 - if (Z_ISREF_P(value)) { - ZVAL_DEREF(value); - } -#endif - if (Z_TYPE_P(value) != IS_OBJECT) { zend_error(E_USER_ERROR, "Given value is not message."); return false; @@ -219,6 +218,11 @@ bool native_slot_set_by_array(upb_fieldtype_t type, bool native_slot_set_by_map(upb_fieldtype_t type, const zend_class_entry* klass, void* memory, zval* value TSRMLS_DC) { +#if PHP_MAJOR_VERSION >= 7 + if (Z_ISREF_P(value)) { + ZVAL_DEREF(value); + } +#endif switch (type) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index 31dc44493d..d8a9245603 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -373,6 +373,11 @@ bool protobuf_convert_to_bool(zval* from, int8_t* to) { } bool protobuf_convert_to_string(zval* from) { +#if PHP_MAJOR_VERSION >= 7 + if (Z_ISREF_P(from)) { + ZVAL_DEREF(from); + } +#endif TSRMLS_FETCH(); switch (Z_TYPE_P(from)) { case IS_STRING: { diff --git a/php/tests/array_test.php b/php/tests/array_test.php index d47a107765..b251404083 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -533,31 +533,39 @@ class RepeatedFieldTest extends \PHPUnit\Framework\TestCase # Test reference in array ######################################################### - public function testArrayElementIsReference() + public function testArrayElementIsReferenceInSetters() { + // Bool elements + $values = [true]; + array_walk($values, function (&$value) {}); $m = new TestMessage(); - $subs = [1, 2]; - - foreach ($subs as &$sub) { - $sub = new Sub(['a' => $sub]); - } + $m->setRepeatedBool($values); - $m->setRepeatedMessage($subs); - } + // Int32 elements + $values = [1]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setRepeatedInt32($values); - public function testArrayIsReference() - { - $keys = [['repeated_message' => [['a' => 1]]]]; + // Double elements + $values = [1.0]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setRepeatedDouble($values); - foreach ($keys as &$key) { - foreach ($key['repeated_message'] as &$element) { - $element = new Sub($element); - } - $key = new TestMessage($key); - } + // String elements + $values = ['a']; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setRepeatedString($values); + // Message elements $m = new TestMessage(); - $m->setRepeatedDeep($keys); + $subs = [1, 2]; + foreach ($subs as &$sub) { + $sub = new Sub(['a' => $sub]); + } + $m->setRepeatedMessage($subs); } ######################################################### diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 83deaba163..93b7b29bb4 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -1375,6 +1375,78 @@ class GeneratedClassTest extends TestBase $this->assertTrue(true); } + public function testReferenceInArrayConstructor() + { + $keys = [[ + 'optional_bool' => true, + 'repeated_bool' => [true], + 'map_bool_bool' => [true => true], + 'optional_double' => 1.0, + 'repeated_double' => [1.0], + 'map_int32_double' => [1 => 1.0], + 'optional_int32' => 1, + 'repeated_int32' => [1], + 'map_int32_int32' => [1 => 1], + 'optional_string' => 'a', + 'repeated_string' => ['a'], + 'map_string_string' => ['a' => 'a'], + 'optional_message' => ['a' => 1], + 'repeated_message' => [['a' => 1]], + 'map_int32_message' => [1 => ['a' => 1]], + ]]; + + foreach ($keys as &$key) { + foreach ($key as $id => &$value) { + if ($id === 'repeated_bool') { + foreach ($value as &$element) { + } + } + if ($id === 'map_bool_bool') { + foreach ($value as $mapKey => &$element) { + } + } + if ($id === 'repeated_double') { + foreach ($value as &$element) { + } + } + if ($id === 'map_int32_double') { + foreach ($value as $mapKey => &$element) { + } + } + if ($id === 'repeated_int32') { + foreach ($value as &$element) { + } + } + if ($id === 'map_int32_int32') { + foreach ($value as $mapKey => &$element) { + } + } + if ($id === 'repeated_string') { + foreach ($value as &$element) { + } + } + if ($id === 'map_string_string') { + foreach ($value as $mapKey => &$element) { + } + } + if ($id === 'optional_message') { + $value = new Sub($value); + } + if ($id === 'repeated_message') { + foreach ($value as &$element) { + $element = new Sub($element); + } + } + if ($id === 'map_int32_message') { + foreach ($value as $mapKey => &$element) { + $element = new Sub($element); + } + } + } + $key = new TestMessage($key); + } + } + ######################################################### # Test message equals. ######################################################### @@ -1387,4 +1459,35 @@ class GeneratedClassTest extends TestBase TestUtil::setTestMessage($n); $this->assertEquals($m, $n); } + + ######################################################### + # Test reference of value + ######################################################### + + public function testValueIsReference() + { + // Bool element + $values = [true]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setOptionalBool($values[0]); + + // Int32 element + $values = [1]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setOptionalInt32($values[0]); + + // Double element + $values = [1.0]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setOptionalDouble($values[0]); + + // String element + $values = ['a']; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setOptionalString($values[0]); + } } diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php index 0260879328..577be681bf 100644 --- a/php/tests/map_field_test.php +++ b/php/tests/map_field_test.php @@ -442,6 +442,43 @@ class MapFieldTest extends \PHPUnit\Framework\TestCase { $this->assertSame(3, $i); } + ######################################################### + # Test reference in map + ######################################################### + + public function testMapElementIsReference() + { + // Bool elements + $values = [true => true]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setMapBoolBool($values); + + // Int32 elements + $values = [1 => 1]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setMapInt32Int32($values); + + // Double elements + $values = [1 => 1.0]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setMapInt32Double($values); + + // String elements + $values = ['a' => 'a']; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setMapStringString($values); + + // Message elements + $values = [1 => new Sub()]; + array_walk($values, function (&$value) {}); + $m = new TestMessage(); + $m->setMapInt32Message($values); + } + ######################################################### # Test memory leak ######################################################### diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto index ca39ea46a4..e610c581b5 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -31,7 +31,6 @@ message TestMessage { Sub optional_message = 17; bar.TestInclude optional_included_message = 18; TestMessage recursive = 19; - repeated TestMessage repeated_deep = 20; // Repeated repeated int32 repeated_int32 = 31;