Merge pull request #10758 from mkruskal-google/utf8_range
Declare a dependency on utf8_range repo
diff --git a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl
index 278d0ee..a1d10aa 100644
--- a/build_defs/cpp_opts.bzl
+++ b/build_defs/cpp_opts.bzl
@@ -2,18 +2,19 @@
COPTS = select({
"//build_defs:config_msvc": [
- "/wd4065", # switch statement contains 'default' but no 'case' labels
- "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
- "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
- "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
- "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
- "/wd4307", # 'operator' : integral constant overflow
- "/wd4309", # 'conversion' : truncation of constant value
- "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
- "/wd4355", # 'this' : used in base member initializer list
- "/wd4506", # no definition for inline function 'function'
- "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
- "/wd4996", # The compiler encountered a deprecated declaration.
+ "/wd4065", # switch statement contains 'default' but no 'case' labels
+ "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
+ "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
+ "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
+ "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
+ "/wd4307", # 'operator' : integral constant overflow
+ "/wd4309", # 'conversion' : truncation of constant value
+ "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
+ "/wd4355", # 'this' : used in base member initializer list
+ "/wd4506", # no definition for inline function 'function'
+ "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
+ "/wd4996", # The compiler encountered a deprecated declaration.
+ "/std:c++14", # Use C++14
],
"//conditions:default": [
"-DHAVE_ZLIB",
diff --git a/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java b/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java
index 9e84432..d31f1ed 100644
--- a/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java
+++ b/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java
@@ -31,7 +31,6 @@
package com.google.protobuf;
import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
import java.lang.annotation.Documented;
@@ -45,6 +44,6 @@
* annotated with {@code @CheckReturnValue} to exempt specific methods from the default.
*/
@Documented
-@Target({METHOD, TYPE})
+@Target(METHOD) // TODO(kak): consider adding CONSTRUCTOR later if necessary
@Retention(CLASS)
@interface CanIgnoreReturnValue {}
diff --git a/java/core/src/test/proto/com/google/protobuf/proto2_message.proto b/java/core/src/test/proto/com/google/protobuf/proto2_message.proto
index 86c48b0..dad00ed 100644
--- a/java/core/src/test/proto/com/google/protobuf/proto2_message.proto
+++ b/java/core/src/test/proto/com/google/protobuf/proto2_message.proto
@@ -36,7 +36,6 @@
option java_package = "com.google.protobuf.testing";
option java_outer_classname = "Proto2Testing";
-
message Proto2SpecialFieldName {
optional double regular_name = 1;
optional int32 cached_size = 2;
diff --git a/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto b/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto
index 7dfd40e..57efc17 100644
--- a/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto
+++ b/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto
@@ -36,7 +36,6 @@
option java_package = "com.google.protobuf.testing";
option java_outer_classname = "Proto2TestingLite";
-
message Proto2MessageLite {
enum TestEnum {
diff --git a/objectivec/GPBAny.pbobjc.h b/objectivec/GPBAny.pbobjc.h
index 3f40181..3edf349 100644
--- a/objectivec/GPBAny.pbobjc.h
+++ b/objectivec/GPBAny.pbobjc.h
@@ -99,7 +99,6 @@
* in the type URL, for example "foo.bar.com/x/y.z" will yield type
* name "y.z".
*
- *
* JSON
*
* The JSON representation of an `Any` value uses the regular
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index 528149f..1d26392 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -32,6 +32,7 @@
#import <objc/message.h>
#import <objc/runtime.h>
+#import <os/lock.h>
#import <stdatomic.h>
#import "GPBArray_PackagePrivate.h"
@@ -70,8 +71,7 @@
@package
GPBUnknownFieldSet *unknownFields_;
NSMutableDictionary *extensionMap_;
- // Readonly access to autocreatedExtensionMap_ is protected via
- // readOnlySemaphore_.
+ // Readonly access to autocreatedExtensionMap_ is protected via readOnlyLock_.
NSMutableDictionary *autocreatedExtensionMap_;
// If the object was autocreated, we remember the creator so that if we get
@@ -80,19 +80,21 @@
GPBFieldDescriptor *autocreatorField_;
GPBExtensionDescriptor *autocreatorExtension_;
- // Message can only be mutated from one thread. But some *readonly* operations
- // modify internal state because they autocreate things. The
- // autocreatedExtensionMap_ is one such structure. Access during readonly
- // operations is protected via this semaphore.
- // NOTE: OSSpinLock may seem like a good fit here but Apple engineers have
- // pointed out that they are vulnerable to live locking on iOS in cases of
- // priority inversion:
+ // Messages can only be mutated from one thread. But some *readonly* operations modify internal
+ // state because they autocreate things. The autocreatedExtensionMap_ is one such structure.
+ // Access during readonly operations is protected via this lock.
+ //
+ // Long ago, this was an OSSpinLock, but then it came to light that there were issues for that on
+ // iOS:
// http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/
// https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html
- // Use of readOnlySemaphore_ must be prefaced by a call to
- // GPBPrepareReadOnlySemaphore to ensure it has been created. This allows
- // readOnlySemaphore_ to be only created when actually needed.
- _Atomic(dispatch_semaphore_t) readOnlySemaphore_;
+ // It was changed to a dispatch_semaphore_t, but that has potential for priority inversion issues.
+ // The minOS versions are now high enough that os_unfair_lock can be used, and should provide
+ // all the support we need. For more information in the concurrency/locking space see:
+ // https://gist.github.com/tclementdev/6af616354912b0347cdf6db159c37057
+ // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html
+ // https://developer.apple.com/videos/play/wwdc2017/706/
+ os_unfair_lock readOnlyLock_;
}
@end
@@ -746,33 +748,6 @@
self->autocreatorExtension_ = nil;
}
-// Call this before using the readOnlySemaphore_. This ensures it is created only once.
-void GPBPrepareReadOnlySemaphore(GPBMessage *self) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdirect-ivar-access"
-
- // Create the semaphore on demand (rather than init) as developers might not cause them
- // to be needed, and the heap usage can add up. The atomic swap is used to avoid needing
- // another lock around creating it.
- if (self->readOnlySemaphore_ == nil) {
- dispatch_semaphore_t worker = dispatch_semaphore_create(1);
- dispatch_semaphore_t expected = nil;
- if (!atomic_compare_exchange_strong(&self->readOnlySemaphore_, &expected, worker)) {
- dispatch_release(worker);
- }
-#if defined(__clang_analyzer__)
- // The static analyzer thinks worker is leaked (doesn't seem to know about
- // atomic_compare_exchange_strong); so just for the analyzer, let it think
- // worker is also released in this case.
- else {
- dispatch_release(worker);
- }
-#endif
- }
-
-#pragma clang diagnostic pop
-}
-
static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
if (!self->unknownFields_) {
self->unknownFields_ = [[GPBUnknownFieldSet alloc] init];
@@ -845,6 +820,7 @@
if ((self = [super init])) {
messageStorage_ =
(GPBMessage_StoragePtr)(((uint8_t *)self) + class_getInstanceSize([self class]));
+ readOnlyLock_ = OS_UNFAIR_LOCK_INIT;
}
return self;
@@ -915,9 +891,6 @@
- (void)dealloc {
[self internalClear:NO];
NSCAssert(!autocreator_, @"Autocreator was not cleared before dealloc.");
- if (readOnlySemaphore_) {
- dispatch_release(readOnlySemaphore_);
- }
[super dealloc];
}
@@ -1741,8 +1714,7 @@
}
// Check for an autocreated value.
- GPBPrepareReadOnlySemaphore(self);
- dispatch_semaphore_wait(readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ os_unfair_lock_lock(&readOnlyLock_);
value = [autocreatedExtensionMap_ objectForKey:extension];
if (!value) {
// Auto create the message extensions to match normal fields.
@@ -1759,7 +1731,7 @@
[value release];
}
- dispatch_semaphore_signal(readOnlySemaphore_);
+ os_unfair_lock_unlock(&readOnlyLock_);
return value;
}
diff --git a/objectivec/GPBRootObject.m b/objectivec/GPBRootObject.m
index 08adfcf..b546959 100644
--- a/objectivec/GPBRootObject.m
+++ b/objectivec/GPBRootObject.m
@@ -31,6 +31,7 @@
#import "GPBRootObject_PackagePrivate.h"
#import <objc/runtime.h>
+#import <os/lock.h>
#import <CoreFoundation/CoreFoundation.h>
@@ -96,19 +97,23 @@
return jenkins_one_at_a_time_hash(key);
}
-// NOTE: OSSpinLock may seem like a good fit here but Apple engineers have
-// pointed out that they are vulnerable to live locking on iOS in cases of
-// priority inversion:
+// Long ago, this was an OSSpinLock, but then it came to light that there were issues for that on
+// iOS:
// http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/
// https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html
-static dispatch_semaphore_t gExtensionSingletonDictionarySemaphore;
+// It was changed to a dispatch_semaphore_t, but that has potential for priority inversion issues.
+// The minOS versions are now high enough that os_unfair_lock can be used, and should provide
+// all the support we need. For more information in the concurrency/locking space see:
+// https://gist.github.com/tclementdev/6af616354912b0347cdf6db159c37057
+// https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html
+// https://developer.apple.com/videos/play/wwdc2017/706/
+static os_unfair_lock gExtensionSingletonDictionaryLock = OS_UNFAIR_LOCK_INIT;
static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL;
static GPBExtensionRegistry *gDefaultExtensionRegistry = NULL;
+ (void)initialize {
// Ensure the global is started up.
if (!gExtensionSingletonDictionary) {
- gExtensionSingletonDictionarySemaphore = dispatch_semaphore_create(1);
CFDictionaryKeyCallBacks keyCallBacks = {
// See description above for reason for using custom dictionary.
0,
@@ -139,9 +144,9 @@
+ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field {
const char *key = [field singletonNameC];
- dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore, DISPATCH_TIME_FOREVER);
+ os_unfair_lock_lock(&gExtensionSingletonDictionaryLock);
CFDictionarySetValue(gExtensionSingletonDictionary, key, field);
- dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore);
+ os_unfair_lock_unlock(&gExtensionSingletonDictionaryLock);
}
static id ExtensionForName(id self, SEL _cmd) {
@@ -173,20 +178,20 @@
key[classNameLen + 1 + selNameLen] = '\0';
// NOTE: Even though this method is called from another C function,
- // gExtensionSingletonDictionarySemaphore and gExtensionSingletonDictionary
+ // gExtensionSingletonDictionaryLock and gExtensionSingletonDictionary
// will always be initialized. This is because this call flow is just to
// lookup the Extension, meaning the code is calling an Extension class
// message on a Message or Root class. This guarantees that the class was
// initialized and Message classes ensure their Root was also initialized.
NSAssert(gExtensionSingletonDictionary, @"Startup order broken!");
- dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore, DISPATCH_TIME_FOREVER);
+ os_unfair_lock_lock(&gExtensionSingletonDictionaryLock);
id extension = (id)CFDictionaryGetValue(gExtensionSingletonDictionary, key);
// We can't remove the key from the dictionary here (as an optimization),
// two threads could have gone into +resolveClassMethod: for the same method,
// and ended up here; there's no way to ensure both return YES without letting
// both try to wire in the method.
- dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore);
+ os_unfair_lock_unlock(&gExtensionSingletonDictionaryLock);
return extension;
}
diff --git a/objectivec/GPBTimestamp.pbobjc.h b/objectivec/GPBTimestamp.pbobjc.h
index 0f1acdd..ebed8c8 100644
--- a/objectivec/GPBTimestamp.pbobjc.h
+++ b/objectivec/GPBTimestamp.pbobjc.h
@@ -95,7 +95,6 @@
* Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
* .setNanos((int) ((millis % 1000) * 1000000)).build();
*
- *
* Example 5: Compute Timestamp from Java `Instant.now()`.
*
* Instant now = Instant.now();
@@ -104,7 +103,6 @@
* Timestamp.newBuilder().setSeconds(now.getEpochSecond())
* .setNanos(now.getNano()).build();
*
- *
* Example 6: Compute Timestamp from current time in Python.
*
* timestamp = Timestamp()
diff --git a/protobuf.bzl b/protobuf.bzl
index 7c4a13f..f638f39 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -40,13 +40,14 @@
def _ObjcBase(srcs):
return [
"".join([token.capitalize() for token in src[:-len(".proto")].split("_")])
- for src in srcs]
+ for src in srcs
+ ]
def _ObjcHdrs(srcs):
- return[src + ".pbobjc.h" for src in _ObjcBase(srcs)]
+ return [src + ".pbobjc.h" for src in _ObjcBase(srcs)]
def _ObjcSrcs(srcs):
- return[src + ".pbobjc.m" for src in _ObjcBase(srcs)]
+ return [src + ".pbobjc.m" for src in _ObjcBase(srcs)]
def _ObjcOuts(srcs, out_type):
if out_type == "hdrs":
@@ -67,7 +68,8 @@
def _CsharpOuts(srcs):
return [
"".join([token.capitalize() for token in src[:-len(".proto")].split("_")]) + ".cs"
- for src in srcs]
+ for src in srcs
+ ]
ProtoGenInfo = provider(
fields = ["srcs", "import_flags", "deps"],
@@ -96,7 +98,7 @@
if ctx.attr.includes:
for include in ctx.attr.includes:
- import_flags += ["-I"+_GetPath(ctx,include)]
+ import_flags += ["-I" + _GetPath(ctx, include)]
import_flags = depset(direct = import_flags)
@@ -149,6 +151,7 @@
outs.extend(_PyOuts([src.basename], use_grpc_plugin = use_grpc_plugin))
elif lang == "ruby":
outs.extend(_RubyOuts([src.basename]))
+
# Otherwise, rely on user-supplied outs.
args += [("--%s_out=" + path_tpl) % (lang, gen_dir)]
@@ -261,7 +264,7 @@
"langs": attr.string_list(),
"outs": attr.string_list(),
"out_type": attr.string(
- default = "all"
+ default = "all",
),
},
output_to_genfiles = True,
@@ -641,7 +644,7 @@
native.filegroup(
name = name,
- srcs = [":%s_genproto"%name],
+ srcs = [":%s_genproto" % name],
testonly = testonly,
visibility = visibility,
**kwargs
diff --git a/python/BUILD.bazel b/python/BUILD.bazel
index b78b070..56d8c8a 100644
--- a/python/BUILD.bazel
+++ b/python/BUILD.bazel
@@ -276,6 +276,13 @@
)
py_test(
+ name = "field_mask_test",
+ srcs = ["google/protobuf/internal/field_mask_test.py"],
+ imports = ["."],
+ deps = [":python_test_lib"],
+)
+
+py_test(
name = "generator_test",
srcs = ["google/protobuf/internal/generator_test.py"],
imports = ["."],
diff --git a/python/google/protobuf/internal/field_mask.py b/python/google/protobuf/internal/field_mask.py
new file mode 100644
index 0000000..4897699
--- /dev/null
+++ b/python/google/protobuf/internal/field_mask.py
@@ -0,0 +1,333 @@
+# 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.
+
+"""Contains FieldMask class."""
+
+from google.protobuf.descriptor import FieldDescriptor
+
+
+class FieldMask(object):
+ """Class for FieldMask message type."""
+
+ __slots__ = ()
+
+ def ToJsonString(self):
+ """Converts FieldMask to string according to proto3 JSON spec."""
+ camelcase_paths = []
+ for path in self.paths:
+ camelcase_paths.append(_SnakeCaseToCamelCase(path))
+ return ','.join(camelcase_paths)
+
+ def FromJsonString(self, value):
+ """Converts string to FieldMask according to proto3 JSON spec."""
+ if not isinstance(value, str):
+ raise ValueError('FieldMask JSON value not a string: {!r}'.format(value))
+ self.Clear()
+ if value:
+ for path in value.split(','):
+ self.paths.append(_CamelCaseToSnakeCase(path))
+
+ def IsValidForDescriptor(self, message_descriptor):
+ """Checks whether the FieldMask is valid for Message Descriptor."""
+ for path in self.paths:
+ if not _IsValidPath(message_descriptor, path):
+ return False
+ return True
+
+ def AllFieldsFromDescriptor(self, message_descriptor):
+ """Gets all direct fields of Message Descriptor to FieldMask."""
+ self.Clear()
+ for field in message_descriptor.fields:
+ self.paths.append(field.name)
+
+ def CanonicalFormFromMask(self, mask):
+ """Converts a FieldMask to the canonical form.
+
+ Removes paths that are covered by another path. For example,
+ "foo.bar" is covered by "foo" and will be removed if "foo"
+ is also in the FieldMask. Then sorts all paths in alphabetical order.
+
+ Args:
+ mask: The original FieldMask to be converted.
+ """
+ tree = _FieldMaskTree(mask)
+ tree.ToFieldMask(self)
+
+ def Union(self, mask1, mask2):
+ """Merges mask1 and mask2 into this FieldMask."""
+ _CheckFieldMaskMessage(mask1)
+ _CheckFieldMaskMessage(mask2)
+ tree = _FieldMaskTree(mask1)
+ tree.MergeFromFieldMask(mask2)
+ tree.ToFieldMask(self)
+
+ def Intersect(self, mask1, mask2):
+ """Intersects mask1 and mask2 into this FieldMask."""
+ _CheckFieldMaskMessage(mask1)
+ _CheckFieldMaskMessage(mask2)
+ tree = _FieldMaskTree(mask1)
+ intersection = _FieldMaskTree()
+ for path in mask2.paths:
+ tree.IntersectPath(path, intersection)
+ intersection.ToFieldMask(self)
+
+ def MergeMessage(
+ self, source, destination,
+ replace_message_field=False, replace_repeated_field=False):
+ """Merges fields specified in FieldMask from source to destination.
+
+ Args:
+ source: Source message.
+ destination: The destination message to be merged into.
+ replace_message_field: Replace message field if True. Merge message
+ field if False.
+ replace_repeated_field: Replace repeated field if True. Append
+ elements of repeated field if False.
+ """
+ tree = _FieldMaskTree(self)
+ tree.MergeMessage(
+ source, destination, replace_message_field, replace_repeated_field)
+
+
+def _IsValidPath(message_descriptor, path):
+ """Checks whether the path is valid for Message Descriptor."""
+ parts = path.split('.')
+ last = parts.pop()
+ for name in parts:
+ field = message_descriptor.fields_by_name.get(name)
+ if (field is None or
+ field.label == FieldDescriptor.LABEL_REPEATED or
+ field.type != FieldDescriptor.TYPE_MESSAGE):
+ return False
+ message_descriptor = field.message_type
+ return last in message_descriptor.fields_by_name
+
+
+def _CheckFieldMaskMessage(message):
+ """Raises ValueError if message is not a FieldMask."""
+ message_descriptor = message.DESCRIPTOR
+ if (message_descriptor.name != 'FieldMask' or
+ message_descriptor.file.name != 'google/protobuf/field_mask.proto'):
+ raise ValueError('Message {0} is not a FieldMask.'.format(
+ message_descriptor.full_name))
+
+
+def _SnakeCaseToCamelCase(path_name):
+ """Converts a path name from snake_case to camelCase."""
+ result = []
+ after_underscore = False
+ for c in path_name:
+ if c.isupper():
+ raise ValueError(
+ 'Fail to print FieldMask to Json string: Path name '
+ '{0} must not contain uppercase letters.'.format(path_name))
+ if after_underscore:
+ if c.islower():
+ result.append(c.upper())
+ after_underscore = False
+ else:
+ raise ValueError(
+ 'Fail to print FieldMask to Json string: The '
+ 'character after a "_" must be a lowercase letter '
+ 'in path name {0}.'.format(path_name))
+ elif c == '_':
+ after_underscore = True
+ else:
+ result += c
+
+ if after_underscore:
+ raise ValueError('Fail to print FieldMask to Json string: Trailing "_" '
+ 'in path name {0}.'.format(path_name))
+ return ''.join(result)
+
+
+def _CamelCaseToSnakeCase(path_name):
+ """Converts a field name from camelCase to snake_case."""
+ result = []
+ for c in path_name:
+ if c == '_':
+ raise ValueError('Fail to parse FieldMask: Path name '
+ '{0} must not contain "_"s.'.format(path_name))
+ if c.isupper():
+ result += '_'
+ result += c.lower()
+ else:
+ result += c
+ return ''.join(result)
+
+
+class _FieldMaskTree(object):
+ """Represents a FieldMask in a tree structure.
+
+ For example, given a FieldMask "foo.bar,foo.baz,bar.baz",
+ the FieldMaskTree will be:
+ [_root] -+- foo -+- bar
+ | |
+ | +- baz
+ |
+ +- bar --- baz
+ In the tree, each leaf node represents a field path.
+ """
+
+ __slots__ = ('_root',)
+
+ def __init__(self, field_mask=None):
+ """Initializes the tree by FieldMask."""
+ self._root = {}
+ if field_mask:
+ self.MergeFromFieldMask(field_mask)
+
+ def MergeFromFieldMask(self, field_mask):
+ """Merges a FieldMask to the tree."""
+ for path in field_mask.paths:
+ self.AddPath(path)
+
+ def AddPath(self, path):
+ """Adds a field path into the tree.
+
+ If the field path to add is a sub-path of an existing field path
+ in the tree (i.e., a leaf node), it means the tree already matches
+ the given path so nothing will be added to the tree. If the path
+ matches an existing non-leaf node in the tree, that non-leaf node
+ will be turned into a leaf node with all its children removed because
+ the path matches all the node's children. Otherwise, a new path will
+ be added.
+
+ Args:
+ path: The field path to add.
+ """
+ node = self._root
+ for name in path.split('.'):
+ if name not in node:
+ node[name] = {}
+ elif not node[name]:
+ # Pre-existing empty node implies we already have this entire tree.
+ return
+ node = node[name]
+ # Remove any sub-trees we might have had.
+ node.clear()
+
+ def ToFieldMask(self, field_mask):
+ """Converts the tree to a FieldMask."""
+ field_mask.Clear()
+ _AddFieldPaths(self._root, '', field_mask)
+
+ def IntersectPath(self, path, intersection):
+ """Calculates the intersection part of a field path with this tree.
+
+ Args:
+ path: The field path to calculates.
+ intersection: The out tree to record the intersection part.
+ """
+ node = self._root
+ for name in path.split('.'):
+ if name not in node:
+ return
+ elif not node[name]:
+ intersection.AddPath(path)
+ return
+ node = node[name]
+ intersection.AddLeafNodes(path, node)
+
+ def AddLeafNodes(self, prefix, node):
+ """Adds leaf nodes begin with prefix to this tree."""
+ if not node:
+ self.AddPath(prefix)
+ for name in node:
+ child_path = prefix + '.' + name
+ self.AddLeafNodes(child_path, node[name])
+
+ def MergeMessage(
+ self, source, destination,
+ replace_message, replace_repeated):
+ """Merge all fields specified by this tree from source to destination."""
+ _MergeMessage(
+ self._root, source, destination, replace_message, replace_repeated)
+
+
+def _StrConvert(value):
+ """Converts value to str if it is not."""
+ # This file is imported by c extension and some methods like ClearField
+ # requires string for the field name. py2/py3 has different text
+ # type and may use unicode.
+ if not isinstance(value, str):
+ return value.encode('utf-8')
+ return value
+
+
+def _MergeMessage(
+ node, source, destination, replace_message, replace_repeated):
+ """Merge all fields specified by a sub-tree from source to destination."""
+ source_descriptor = source.DESCRIPTOR
+ for name in node:
+ child = node[name]
+ field = source_descriptor.fields_by_name[name]
+ if field is None:
+ raise ValueError('Error: Can\'t find field {0} in message {1}.'.format(
+ name, source_descriptor.full_name))
+ if child:
+ # Sub-paths are only allowed for singular message fields.
+ if (field.label == FieldDescriptor.LABEL_REPEATED or
+ field.cpp_type != FieldDescriptor.CPPTYPE_MESSAGE):
+ raise ValueError('Error: Field {0} in message {1} is not a singular '
+ 'message field and cannot have sub-fields.'.format(
+ name, source_descriptor.full_name))
+ if source.HasField(name):
+ _MergeMessage(
+ child, getattr(source, name), getattr(destination, name),
+ replace_message, replace_repeated)
+ continue
+ if field.label == FieldDescriptor.LABEL_REPEATED:
+ if replace_repeated:
+ destination.ClearField(_StrConvert(name))
+ repeated_source = getattr(source, name)
+ repeated_destination = getattr(destination, name)
+ repeated_destination.MergeFrom(repeated_source)
+ else:
+ if field.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
+ if replace_message:
+ destination.ClearField(_StrConvert(name))
+ if source.HasField(name):
+ getattr(destination, name).MergeFrom(getattr(source, name))
+ else:
+ setattr(destination, name, getattr(source, name))
+
+
+def _AddFieldPaths(node, prefix, field_mask):
+ """Adds the field paths descended from node to field_mask."""
+ if not node and prefix:
+ field_mask.paths.append(prefix)
+ return
+ for name in sorted(node):
+ if prefix:
+ child_path = prefix + '.' + name
+ else:
+ child_path = name
+ _AddFieldPaths(node[name], child_path, field_mask)
diff --git a/python/google/protobuf/internal/field_mask_test.py b/python/google/protobuf/internal/field_mask_test.py
new file mode 100644
index 0000000..8266418
--- /dev/null
+++ b/python/google/protobuf/internal/field_mask_test.py
@@ -0,0 +1,400 @@
+# 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.
+
+"""Test for google.protobuf.internal.well_known_types."""
+
+import unittest
+
+from google.protobuf import field_mask_pb2
+from google.protobuf import map_unittest_pb2
+from google.protobuf import unittest_pb2
+from google.protobuf.internal import field_mask
+from google.protobuf.internal import test_util
+from google.protobuf import descriptor
+
+
+class FieldMaskTest(unittest.TestCase):
+
+ def testStringFormat(self):
+ mask = field_mask_pb2.FieldMask()
+ self.assertEqual('', mask.ToJsonString())
+ mask.paths.append('foo')
+ self.assertEqual('foo', mask.ToJsonString())
+ mask.paths.append('bar')
+ self.assertEqual('foo,bar', mask.ToJsonString())
+
+ mask.FromJsonString('')
+ self.assertEqual('', mask.ToJsonString())
+ mask.FromJsonString('foo')
+ self.assertEqual(['foo'], mask.paths)
+ mask.FromJsonString('foo,bar')
+ self.assertEqual(['foo', 'bar'], mask.paths)
+
+ # Test camel case
+ mask.Clear()
+ mask.paths.append('foo_bar')
+ self.assertEqual('fooBar', mask.ToJsonString())
+ mask.paths.append('bar_quz')
+ self.assertEqual('fooBar,barQuz', mask.ToJsonString())
+
+ mask.FromJsonString('')
+ self.assertEqual('', mask.ToJsonString())
+ self.assertEqual([], mask.paths)
+ mask.FromJsonString('fooBar')
+ self.assertEqual(['foo_bar'], mask.paths)
+ mask.FromJsonString('fooBar,barQuz')
+ self.assertEqual(['foo_bar', 'bar_quz'], mask.paths)
+
+ def testDescriptorToFieldMask(self):
+ mask = field_mask_pb2.FieldMask()
+ msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
+ mask.AllFieldsFromDescriptor(msg_descriptor)
+ self.assertEqual(76, len(mask.paths))
+ self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
+ for field in msg_descriptor.fields:
+ self.assertTrue(field.name in mask.paths)
+
+ def testIsValidForDescriptor(self):
+ msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
+ # Empty mask
+ mask = field_mask_pb2.FieldMask()
+ self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
+ # All fields from descriptor
+ mask.AllFieldsFromDescriptor(msg_descriptor)
+ self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
+ # Child under optional message
+ mask.paths.append('optional_nested_message.bb')
+ self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
+ # Repeated field is only allowed in the last position of path
+ mask.paths.append('repeated_nested_message.bb')
+ self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
+ # Invalid top level field
+ mask = field_mask_pb2.FieldMask()
+ mask.paths.append('xxx')
+ self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
+ # Invalid field in root
+ mask = field_mask_pb2.FieldMask()
+ mask.paths.append('xxx.zzz')
+ self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
+ # Invalid field in internal node
+ mask = field_mask_pb2.FieldMask()
+ mask.paths.append('optional_nested_message.xxx.zzz')
+ self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
+ # Invalid field in leaf
+ mask = field_mask_pb2.FieldMask()
+ mask.paths.append('optional_nested_message.xxx')
+ self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
+
+ def testCanonicalFrom(self):
+ mask = field_mask_pb2.FieldMask()
+ out_mask = field_mask_pb2.FieldMask()
+ # Paths will be sorted.
+ mask.FromJsonString('baz.quz,bar,foo')
+ out_mask.CanonicalFormFromMask(mask)
+ self.assertEqual('bar,baz.quz,foo', out_mask.ToJsonString())
+ # Duplicated paths will be removed.
+ mask.FromJsonString('foo,bar,foo')
+ out_mask.CanonicalFormFromMask(mask)
+ self.assertEqual('bar,foo', out_mask.ToJsonString())
+ # Sub-paths of other paths will be removed.
+ mask.FromJsonString('foo.b1,bar.b1,foo.b2,bar')
+ out_mask.CanonicalFormFromMask(mask)
+ self.assertEqual('bar,foo.b1,foo.b2', out_mask.ToJsonString())
+
+ # Test more deeply nested cases.
+ mask.FromJsonString(
+ 'foo.bar.baz1,foo.bar.baz2.quz,foo.bar.baz2')
+ out_mask.CanonicalFormFromMask(mask)
+ self.assertEqual('foo.bar.baz1,foo.bar.baz2',
+ out_mask.ToJsonString())
+ mask.FromJsonString(
+ 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz')
+ out_mask.CanonicalFormFromMask(mask)
+ self.assertEqual('foo.bar.baz1,foo.bar.baz2',
+ out_mask.ToJsonString())
+ mask.FromJsonString(
+ 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo.bar')
+ out_mask.CanonicalFormFromMask(mask)
+ self.assertEqual('foo.bar', out_mask.ToJsonString())
+ mask.FromJsonString(
+ 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo')
+ out_mask.CanonicalFormFromMask(mask)
+ self.assertEqual('foo', out_mask.ToJsonString())
+
+ def testUnion(self):
+ mask1 = field_mask_pb2.FieldMask()
+ mask2 = field_mask_pb2.FieldMask()
+ out_mask = field_mask_pb2.FieldMask()
+ mask1.FromJsonString('foo,baz')
+ mask2.FromJsonString('bar,quz')
+ out_mask.Union(mask1, mask2)
+ self.assertEqual('bar,baz,foo,quz', out_mask.ToJsonString())
+ # Overlap with duplicated paths.
+ mask1.FromJsonString('foo,baz.bb')
+ mask2.FromJsonString('baz.bb,quz')
+ out_mask.Union(mask1, mask2)
+ self.assertEqual('baz.bb,foo,quz', out_mask.ToJsonString())
+ # Overlap with paths covering some other paths.
+ mask1.FromJsonString('foo.bar.baz,quz')
+ mask2.FromJsonString('foo.bar,bar')
+ out_mask.Union(mask1, mask2)
+ self.assertEqual('bar,foo.bar,quz', out_mask.ToJsonString())
+ src = unittest_pb2.TestAllTypes()
+ with self.assertRaises(ValueError):
+ out_mask.Union(src, mask2)
+
+ def testIntersect(self):
+ mask1 = field_mask_pb2.FieldMask()
+ mask2 = field_mask_pb2.FieldMask()
+ out_mask = field_mask_pb2.FieldMask()
+ # Test cases without overlapping.
+ mask1.FromJsonString('foo,baz')
+ mask2.FromJsonString('bar,quz')
+ out_mask.Intersect(mask1, mask2)
+ self.assertEqual('', out_mask.ToJsonString())
+ self.assertEqual(len(out_mask.paths), 0)
+ self.assertEqual(out_mask.paths, [])
+ # Overlap with duplicated paths.
+ mask1.FromJsonString('foo,baz.bb')
+ mask2.FromJsonString('baz.bb,quz')
+ out_mask.Intersect(mask1, mask2)
+ self.assertEqual('baz.bb', out_mask.ToJsonString())
+ # Overlap with paths covering some other paths.
+ mask1.FromJsonString('foo.bar.baz,quz')
+ mask2.FromJsonString('foo.bar,bar')
+ out_mask.Intersect(mask1, mask2)
+ self.assertEqual('foo.bar.baz', out_mask.ToJsonString())
+ mask1.FromJsonString('foo.bar,bar')
+ mask2.FromJsonString('foo.bar.baz,quz')
+ out_mask.Intersect(mask1, mask2)
+ self.assertEqual('foo.bar.baz', out_mask.ToJsonString())
+ # Intersect '' with ''
+ mask1.Clear()
+ mask2.Clear()
+ mask1.paths.append('')
+ mask2.paths.append('')
+ self.assertEqual(mask1.paths, [''])
+ self.assertEqual('', mask1.ToJsonString())
+ out_mask.Intersect(mask1, mask2)
+ self.assertEqual(out_mask.paths, [])
+
+ def testMergeMessageWithoutMapFields(self):
+ # Test merge one field.
+ src = unittest_pb2.TestAllTypes()
+ test_util.SetAllFields(src)
+ for field in src.DESCRIPTOR.fields:
+ if field.containing_oneof:
+ continue
+ field_name = field.name
+ dst = unittest_pb2.TestAllTypes()
+ # Only set one path to mask.
+ mask = field_mask_pb2.FieldMask()
+ mask.paths.append(field_name)
+ mask.MergeMessage(src, dst)
+ # The expected result message.
+ msg = unittest_pb2.TestAllTypes()
+ if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
+ repeated_src = getattr(src, field_name)
+ repeated_msg = getattr(msg, field_name)
+ if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
+ for item in repeated_src:
+ repeated_msg.add().CopyFrom(item)
+ else:
+ repeated_msg.extend(repeated_src)
+ elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
+ getattr(msg, field_name).CopyFrom(getattr(src, field_name))
+ else:
+ setattr(msg, field_name, getattr(src, field_name))
+ # Only field specified in mask is merged.
+ self.assertEqual(msg, dst)
+
+ # Test merge nested fields.
+ nested_src = unittest_pb2.NestedTestAllTypes()
+ nested_dst = unittest_pb2.NestedTestAllTypes()
+ nested_src.child.payload.optional_int32 = 1234
+ nested_src.child.child.payload.optional_int32 = 5678
+ mask = field_mask_pb2.FieldMask()
+ mask.FromJsonString('child.payload')
+ mask.MergeMessage(nested_src, nested_dst)
+ self.assertEqual(1234, nested_dst.child.payload.optional_int32)
+ self.assertEqual(0, nested_dst.child.child.payload.optional_int32)
+
+ mask.FromJsonString('child.child.payload')
+ mask.MergeMessage(nested_src, nested_dst)
+ self.assertEqual(1234, nested_dst.child.payload.optional_int32)
+ self.assertEqual(5678, nested_dst.child.child.payload.optional_int32)
+
+ nested_dst.Clear()
+ mask.FromJsonString('child.child.payload')
+ mask.MergeMessage(nested_src, nested_dst)
+ self.assertEqual(0, nested_dst.child.payload.optional_int32)
+ self.assertEqual(5678, nested_dst.child.child.payload.optional_int32)
+
+ nested_dst.Clear()
+ mask.FromJsonString('child')
+ mask.MergeMessage(nested_src, nested_dst)
+ self.assertEqual(1234, nested_dst.child.payload.optional_int32)
+ self.assertEqual(5678, nested_dst.child.child.payload.optional_int32)
+
+ # Test MergeOptions.
+ nested_dst.Clear()
+ nested_dst.child.payload.optional_int64 = 4321
+ # Message fields will be merged by default.
+ mask.FromJsonString('child.payload')
+ mask.MergeMessage(nested_src, nested_dst)
+ self.assertEqual(1234, nested_dst.child.payload.optional_int32)
+ self.assertEqual(4321, nested_dst.child.payload.optional_int64)
+ # Change the behavior to replace message fields.
+ mask.FromJsonString('child.payload')
+ mask.MergeMessage(nested_src, nested_dst, True, False)
+ self.assertEqual(1234, nested_dst.child.payload.optional_int32)
+ self.assertEqual(0, nested_dst.child.payload.optional_int64)
+
+ # By default, fields missing in source are not cleared in destination.
+ nested_dst.payload.optional_int32 = 1234
+ self.assertTrue(nested_dst.HasField('payload'))
+ mask.FromJsonString('payload')
+ mask.MergeMessage(nested_src, nested_dst)
+ self.assertTrue(nested_dst.HasField('payload'))
+ # But they are cleared when replacing message fields.
+ nested_dst.Clear()
+ nested_dst.payload.optional_int32 = 1234
+ mask.FromJsonString('payload')
+ mask.MergeMessage(nested_src, nested_dst, True, False)
+ self.assertFalse(nested_dst.HasField('payload'))
+
+ nested_src.payload.repeated_int32.append(1234)
+ nested_dst.payload.repeated_int32.append(5678)
+ # Repeated fields will be appended by default.
+ mask.FromJsonString('payload.repeatedInt32')
+ mask.MergeMessage(nested_src, nested_dst)
+ self.assertEqual(2, len(nested_dst.payload.repeated_int32))
+ self.assertEqual(5678, nested_dst.payload.repeated_int32[0])
+ self.assertEqual(1234, nested_dst.payload.repeated_int32[1])
+ # Change the behavior to replace repeated fields.
+ mask.FromJsonString('payload.repeatedInt32')
+ mask.MergeMessage(nested_src, nested_dst, False, True)
+ self.assertEqual(1, len(nested_dst.payload.repeated_int32))
+ self.assertEqual(1234, nested_dst.payload.repeated_int32[0])
+
+ # Test Merge oneof field.
+ new_msg = unittest_pb2.TestOneof2()
+ dst = unittest_pb2.TestOneof2()
+ dst.foo_message.moo_int = 1
+ mask = field_mask_pb2.FieldMask()
+ mask.FromJsonString('fooMessage,fooLazyMessage.mooInt')
+ mask.MergeMessage(new_msg, dst)
+ self.assertTrue(dst.HasField('foo_message'))
+ self.assertFalse(dst.HasField('foo_lazy_message'))
+
+ def testMergeMessageWithMapField(self):
+ empty_map = map_unittest_pb2.TestRecursiveMapMessage()
+ src_level_2 = map_unittest_pb2.TestRecursiveMapMessage()
+ src_level_2.a['src level 2'].CopyFrom(empty_map)
+ src = map_unittest_pb2.TestRecursiveMapMessage()
+ src.a['common key'].CopyFrom(src_level_2)
+ src.a['src level 1'].CopyFrom(src_level_2)
+
+ dst_level_2 = map_unittest_pb2.TestRecursiveMapMessage()
+ dst_level_2.a['dst level 2'].CopyFrom(empty_map)
+ dst = map_unittest_pb2.TestRecursiveMapMessage()
+ dst.a['common key'].CopyFrom(dst_level_2)
+ dst.a['dst level 1'].CopyFrom(empty_map)
+
+ mask = field_mask_pb2.FieldMask()
+ mask.FromJsonString('a')
+ mask.MergeMessage(src, dst)
+
+ # map from dst is replaced with map from src.
+ self.assertEqual(dst.a['common key'], src_level_2)
+ self.assertEqual(dst.a['src level 1'], src_level_2)
+ self.assertEqual(dst.a['dst level 1'], empty_map)
+
+ def testMergeErrors(self):
+ src = unittest_pb2.TestAllTypes()
+ dst = unittest_pb2.TestAllTypes()
+ mask = field_mask_pb2.FieldMask()
+ test_util.SetAllFields(src)
+ mask.FromJsonString('optionalInt32.field')
+ with self.assertRaises(ValueError) as e:
+ mask.MergeMessage(src, dst)
+ self.assertEqual('Error: Field optional_int32 in message '
+ 'protobuf_unittest.TestAllTypes is not a singular '
+ 'message field and cannot have sub-fields.',
+ str(e.exception))
+
+ def testSnakeCaseToCamelCase(self):
+ self.assertEqual('fooBar',
+ field_mask._SnakeCaseToCamelCase('foo_bar'))
+ self.assertEqual('FooBar',
+ field_mask._SnakeCaseToCamelCase('_foo_bar'))
+ self.assertEqual('foo3Bar',
+ field_mask._SnakeCaseToCamelCase('foo3_bar'))
+
+ # No uppercase letter is allowed.
+ self.assertRaisesRegex(
+ ValueError,
+ 'Fail to print FieldMask to Json string: Path name Foo must '
+ 'not contain uppercase letters.',
+ field_mask._SnakeCaseToCamelCase, 'Foo')
+ # Any character after a "_" must be a lowercase letter.
+ # 1. "_" cannot be followed by another "_".
+ # 2. "_" cannot be followed by a digit.
+ # 3. "_" cannot appear as the last character.
+ self.assertRaisesRegex(
+ ValueError,
+ 'Fail to print FieldMask to Json string: The character after a '
+ '"_" must be a lowercase letter in path name foo__bar.',
+ field_mask._SnakeCaseToCamelCase, 'foo__bar')
+ self.assertRaisesRegex(
+ ValueError,
+ 'Fail to print FieldMask to Json string: The character after a '
+ '"_" must be a lowercase letter in path name foo_3bar.',
+ field_mask._SnakeCaseToCamelCase, 'foo_3bar')
+ self.assertRaisesRegex(
+ ValueError,
+ 'Fail to print FieldMask to Json string: Trailing "_" in path '
+ 'name foo_bar_.', field_mask._SnakeCaseToCamelCase, 'foo_bar_')
+
+ def testCamelCaseToSnakeCase(self):
+ self.assertEqual('foo_bar',
+ field_mask._CamelCaseToSnakeCase('fooBar'))
+ self.assertEqual('_foo_bar',
+ field_mask._CamelCaseToSnakeCase('FooBar'))
+ self.assertEqual('foo3_bar',
+ field_mask._CamelCaseToSnakeCase('foo3Bar'))
+ self.assertRaisesRegex(
+ ValueError,
+ 'Fail to parse FieldMask: Path name foo_bar must not contain "_"s.',
+ field_mask._CamelCaseToSnakeCase, 'foo_bar')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/python/google/protobuf/internal/missing_enum_values.proto b/python/google/protobuf/internal/missing_enum_values.proto
index 37baca7..96de1e4 100644
--- a/python/google/protobuf/internal/missing_enum_values.proto
+++ b/python/google/protobuf/internal/missing_enum_values.proto
@@ -30,7 +30,6 @@
syntax = "proto2";
-
package google.protobuf.python.internal;
message TestEnumValues {
@@ -53,4 +52,3 @@
message JustString {
required string dummy = 1;
}
-
diff --git a/python/google/protobuf/internal/well_known_types.py b/python/google/protobuf/internal/well_known_types.py
index 8881d75..e340f90 100644
--- a/python/google/protobuf/internal/well_known_types.py
+++ b/python/google/protobuf/internal/well_known_types.py
@@ -44,7 +44,9 @@
import collections.abc
import datetime
-from google.protobuf.descriptor import FieldDescriptor
+from google.protobuf.internal import field_mask
+
+FieldMask = field_mask.FieldMask
_TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S'
_NANOS_PER_SECOND = 1000000000
@@ -430,306 +432,6 @@
return result
-class FieldMask(object):
- """Class for FieldMask message type."""
-
- __slots__ = ()
-
- def ToJsonString(self):
- """Converts FieldMask to string according to proto3 JSON spec."""
- camelcase_paths = []
- for path in self.paths:
- camelcase_paths.append(_SnakeCaseToCamelCase(path))
- return ','.join(camelcase_paths)
-
- def FromJsonString(self, value):
- """Converts string to FieldMask according to proto3 JSON spec."""
- if not isinstance(value, str):
- raise ValueError('FieldMask JSON value not a string: {!r}'.format(value))
- self.Clear()
- if value:
- for path in value.split(','):
- self.paths.append(_CamelCaseToSnakeCase(path))
-
- def IsValidForDescriptor(self, message_descriptor):
- """Checks whether the FieldMask is valid for Message Descriptor."""
- for path in self.paths:
- if not _IsValidPath(message_descriptor, path):
- return False
- return True
-
- def AllFieldsFromDescriptor(self, message_descriptor):
- """Gets all direct fields of Message Descriptor to FieldMask."""
- self.Clear()
- for field in message_descriptor.fields:
- self.paths.append(field.name)
-
- def CanonicalFormFromMask(self, mask):
- """Converts a FieldMask to the canonical form.
-
- Removes paths that are covered by another path. For example,
- "foo.bar" is covered by "foo" and will be removed if "foo"
- is also in the FieldMask. Then sorts all paths in alphabetical order.
-
- Args:
- mask: The original FieldMask to be converted.
- """
- tree = _FieldMaskTree(mask)
- tree.ToFieldMask(self)
-
- def Union(self, mask1, mask2):
- """Merges mask1 and mask2 into this FieldMask."""
- _CheckFieldMaskMessage(mask1)
- _CheckFieldMaskMessage(mask2)
- tree = _FieldMaskTree(mask1)
- tree.MergeFromFieldMask(mask2)
- tree.ToFieldMask(self)
-
- def Intersect(self, mask1, mask2):
- """Intersects mask1 and mask2 into this FieldMask."""
- _CheckFieldMaskMessage(mask1)
- _CheckFieldMaskMessage(mask2)
- tree = _FieldMaskTree(mask1)
- intersection = _FieldMaskTree()
- for path in mask2.paths:
- tree.IntersectPath(path, intersection)
- intersection.ToFieldMask(self)
-
- def MergeMessage(
- self, source, destination,
- replace_message_field=False, replace_repeated_field=False):
- """Merges fields specified in FieldMask from source to destination.
-
- Args:
- source: Source message.
- destination: The destination message to be merged into.
- replace_message_field: Replace message field if True. Merge message
- field if False.
- replace_repeated_field: Replace repeated field if True. Append
- elements of repeated field if False.
- """
- tree = _FieldMaskTree(self)
- tree.MergeMessage(
- source, destination, replace_message_field, replace_repeated_field)
-
-
-def _IsValidPath(message_descriptor, path):
- """Checks whether the path is valid for Message Descriptor."""
- parts = path.split('.')
- last = parts.pop()
- for name in parts:
- field = message_descriptor.fields_by_name.get(name)
- if (field is None or
- field.label == FieldDescriptor.LABEL_REPEATED or
- field.type != FieldDescriptor.TYPE_MESSAGE):
- return False
- message_descriptor = field.message_type
- return last in message_descriptor.fields_by_name
-
-
-def _CheckFieldMaskMessage(message):
- """Raises ValueError if message is not a FieldMask."""
- message_descriptor = message.DESCRIPTOR
- if (message_descriptor.name != 'FieldMask' or
- message_descriptor.file.name != 'google/protobuf/field_mask.proto'):
- raise ValueError('Message {0} is not a FieldMask.'.format(
- message_descriptor.full_name))
-
-
-def _SnakeCaseToCamelCase(path_name):
- """Converts a path name from snake_case to camelCase."""
- result = []
- after_underscore = False
- for c in path_name:
- if c.isupper():
- raise ValueError(
- 'Fail to print FieldMask to Json string: Path name '
- '{0} must not contain uppercase letters.'.format(path_name))
- if after_underscore:
- if c.islower():
- result.append(c.upper())
- after_underscore = False
- else:
- raise ValueError(
- 'Fail to print FieldMask to Json string: The '
- 'character after a "_" must be a lowercase letter '
- 'in path name {0}.'.format(path_name))
- elif c == '_':
- after_underscore = True
- else:
- result += c
-
- if after_underscore:
- raise ValueError('Fail to print FieldMask to Json string: Trailing "_" '
- 'in path name {0}.'.format(path_name))
- return ''.join(result)
-
-
-def _CamelCaseToSnakeCase(path_name):
- """Converts a field name from camelCase to snake_case."""
- result = []
- for c in path_name:
- if c == '_':
- raise ValueError('Fail to parse FieldMask: Path name '
- '{0} must not contain "_"s.'.format(path_name))
- if c.isupper():
- result += '_'
- result += c.lower()
- else:
- result += c
- return ''.join(result)
-
-
-class _FieldMaskTree(object):
- """Represents a FieldMask in a tree structure.
-
- For example, given a FieldMask "foo.bar,foo.baz,bar.baz",
- the FieldMaskTree will be:
- [_root] -+- foo -+- bar
- | |
- | +- baz
- |
- +- bar --- baz
- In the tree, each leaf node represents a field path.
- """
-
- __slots__ = ('_root',)
-
- def __init__(self, field_mask=None):
- """Initializes the tree by FieldMask."""
- self._root = {}
- if field_mask:
- self.MergeFromFieldMask(field_mask)
-
- def MergeFromFieldMask(self, field_mask):
- """Merges a FieldMask to the tree."""
- for path in field_mask.paths:
- self.AddPath(path)
-
- def AddPath(self, path):
- """Adds a field path into the tree.
-
- If the field path to add is a sub-path of an existing field path
- in the tree (i.e., a leaf node), it means the tree already matches
- the given path so nothing will be added to the tree. If the path
- matches an existing non-leaf node in the tree, that non-leaf node
- will be turned into a leaf node with all its children removed because
- the path matches all the node's children. Otherwise, a new path will
- be added.
-
- Args:
- path: The field path to add.
- """
- node = self._root
- for name in path.split('.'):
- if name not in node:
- node[name] = {}
- elif not node[name]:
- # Pre-existing empty node implies we already have this entire tree.
- return
- node = node[name]
- # Remove any sub-trees we might have had.
- node.clear()
-
- def ToFieldMask(self, field_mask):
- """Converts the tree to a FieldMask."""
- field_mask.Clear()
- _AddFieldPaths(self._root, '', field_mask)
-
- def IntersectPath(self, path, intersection):
- """Calculates the intersection part of a field path with this tree.
-
- Args:
- path: The field path to calculates.
- intersection: The out tree to record the intersection part.
- """
- node = self._root
- for name in path.split('.'):
- if name not in node:
- return
- elif not node[name]:
- intersection.AddPath(path)
- return
- node = node[name]
- intersection.AddLeafNodes(path, node)
-
- def AddLeafNodes(self, prefix, node):
- """Adds leaf nodes begin with prefix to this tree."""
- if not node:
- self.AddPath(prefix)
- for name in node:
- child_path = prefix + '.' + name
- self.AddLeafNodes(child_path, node[name])
-
- def MergeMessage(
- self, source, destination,
- replace_message, replace_repeated):
- """Merge all fields specified by this tree from source to destination."""
- _MergeMessage(
- self._root, source, destination, replace_message, replace_repeated)
-
-
-def _StrConvert(value):
- """Converts value to str if it is not."""
- # This file is imported by c extension and some methods like ClearField
- # requires string for the field name. py2/py3 has different text
- # type and may use unicode.
- if not isinstance(value, str):
- return value.encode('utf-8')
- return value
-
-
-def _MergeMessage(
- node, source, destination, replace_message, replace_repeated):
- """Merge all fields specified by a sub-tree from source to destination."""
- source_descriptor = source.DESCRIPTOR
- for name in node:
- child = node[name]
- field = source_descriptor.fields_by_name[name]
- if field is None:
- raise ValueError('Error: Can\'t find field {0} in message {1}.'.format(
- name, source_descriptor.full_name))
- if child:
- # Sub-paths are only allowed for singular message fields.
- if (field.label == FieldDescriptor.LABEL_REPEATED or
- field.cpp_type != FieldDescriptor.CPPTYPE_MESSAGE):
- raise ValueError('Error: Field {0} in message {1} is not a singular '
- 'message field and cannot have sub-fields.'.format(
- name, source_descriptor.full_name))
- if source.HasField(name):
- _MergeMessage(
- child, getattr(source, name), getattr(destination, name),
- replace_message, replace_repeated)
- continue
- if field.label == FieldDescriptor.LABEL_REPEATED:
- if replace_repeated:
- destination.ClearField(_StrConvert(name))
- repeated_source = getattr(source, name)
- repeated_destination = getattr(destination, name)
- repeated_destination.MergeFrom(repeated_source)
- else:
- if field.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
- if replace_message:
- destination.ClearField(_StrConvert(name))
- if source.HasField(name):
- getattr(destination, name).MergeFrom(getattr(source, name))
- else:
- setattr(destination, name, getattr(source, name))
-
-
-def _AddFieldPaths(node, prefix, field_mask):
- """Adds the field paths descended from node to field_mask."""
- if not node and prefix:
- field_mask.paths.append(prefix)
- return
- for name in sorted(node):
- if prefix:
- child_path = prefix + '.' + name
- else:
- child_path = name
- _AddFieldPaths(node[name], child_path, field_mask)
-
-
def _SetStructValue(struct_value, value):
if value is None:
struct_value.null_value = 0
diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py
index a32459a..601ae41 100644
--- a/python/google/protobuf/internal/well_known_types_test.py
+++ b/python/google/protobuf/internal/well_known_types_test.py
@@ -38,15 +38,11 @@
from google.protobuf import any_pb2
from google.protobuf import duration_pb2
-from google.protobuf import field_mask_pb2
from google.protobuf import struct_pb2
from google.protobuf import timestamp_pb2
-from google.protobuf import map_unittest_pb2
from google.protobuf import unittest_pb2
from google.protobuf.internal import any_test_pb2
-from google.protobuf.internal import test_util
from google.protobuf.internal import well_known_types
-from google.protobuf import descriptor
from google.protobuf import text_format
from google.protobuf.internal import _parameterized
@@ -390,362 +386,6 @@
message.ToJsonString)
-class FieldMaskTest(unittest.TestCase):
-
- def testStringFormat(self):
- mask = field_mask_pb2.FieldMask()
- self.assertEqual('', mask.ToJsonString())
- mask.paths.append('foo')
- self.assertEqual('foo', mask.ToJsonString())
- mask.paths.append('bar')
- self.assertEqual('foo,bar', mask.ToJsonString())
-
- mask.FromJsonString('')
- self.assertEqual('', mask.ToJsonString())
- mask.FromJsonString('foo')
- self.assertEqual(['foo'], mask.paths)
- mask.FromJsonString('foo,bar')
- self.assertEqual(['foo', 'bar'], mask.paths)
-
- # Test camel case
- mask.Clear()
- mask.paths.append('foo_bar')
- self.assertEqual('fooBar', mask.ToJsonString())
- mask.paths.append('bar_quz')
- self.assertEqual('fooBar,barQuz', mask.ToJsonString())
-
- mask.FromJsonString('')
- self.assertEqual('', mask.ToJsonString())
- self.assertEqual([], mask.paths)
- mask.FromJsonString('fooBar')
- self.assertEqual(['foo_bar'], mask.paths)
- mask.FromJsonString('fooBar,barQuz')
- self.assertEqual(['foo_bar', 'bar_quz'], mask.paths)
-
- def testDescriptorToFieldMask(self):
- mask = field_mask_pb2.FieldMask()
- msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
- mask.AllFieldsFromDescriptor(msg_descriptor)
- self.assertEqual(76, len(mask.paths))
- self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
- for field in msg_descriptor.fields:
- self.assertTrue(field.name in mask.paths)
-
- def testIsValidForDescriptor(self):
- msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
- # Empty mask
- mask = field_mask_pb2.FieldMask()
- self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
- # All fields from descriptor
- mask.AllFieldsFromDescriptor(msg_descriptor)
- self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
- # Child under optional message
- mask.paths.append('optional_nested_message.bb')
- self.assertTrue(mask.IsValidForDescriptor(msg_descriptor))
- # Repeated field is only allowed in the last position of path
- mask.paths.append('repeated_nested_message.bb')
- self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
- # Invalid top level field
- mask = field_mask_pb2.FieldMask()
- mask.paths.append('xxx')
- self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
- # Invalid field in root
- mask = field_mask_pb2.FieldMask()
- mask.paths.append('xxx.zzz')
- self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
- # Invalid field in internal node
- mask = field_mask_pb2.FieldMask()
- mask.paths.append('optional_nested_message.xxx.zzz')
- self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
- # Invalid field in leaf
- mask = field_mask_pb2.FieldMask()
- mask.paths.append('optional_nested_message.xxx')
- self.assertFalse(mask.IsValidForDescriptor(msg_descriptor))
-
- def testCanonicalFrom(self):
- mask = field_mask_pb2.FieldMask()
- out_mask = field_mask_pb2.FieldMask()
- # Paths will be sorted.
- mask.FromJsonString('baz.quz,bar,foo')
- out_mask.CanonicalFormFromMask(mask)
- self.assertEqual('bar,baz.quz,foo', out_mask.ToJsonString())
- # Duplicated paths will be removed.
- mask.FromJsonString('foo,bar,foo')
- out_mask.CanonicalFormFromMask(mask)
- self.assertEqual('bar,foo', out_mask.ToJsonString())
- # Sub-paths of other paths will be removed.
- mask.FromJsonString('foo.b1,bar.b1,foo.b2,bar')
- out_mask.CanonicalFormFromMask(mask)
- self.assertEqual('bar,foo.b1,foo.b2', out_mask.ToJsonString())
-
- # Test more deeply nested cases.
- mask.FromJsonString(
- 'foo.bar.baz1,foo.bar.baz2.quz,foo.bar.baz2')
- out_mask.CanonicalFormFromMask(mask)
- self.assertEqual('foo.bar.baz1,foo.bar.baz2',
- out_mask.ToJsonString())
- mask.FromJsonString(
- 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz')
- out_mask.CanonicalFormFromMask(mask)
- self.assertEqual('foo.bar.baz1,foo.bar.baz2',
- out_mask.ToJsonString())
- mask.FromJsonString(
- 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo.bar')
- out_mask.CanonicalFormFromMask(mask)
- self.assertEqual('foo.bar', out_mask.ToJsonString())
- mask.FromJsonString(
- 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo')
- out_mask.CanonicalFormFromMask(mask)
- self.assertEqual('foo', out_mask.ToJsonString())
-
- def testUnion(self):
- mask1 = field_mask_pb2.FieldMask()
- mask2 = field_mask_pb2.FieldMask()
- out_mask = field_mask_pb2.FieldMask()
- mask1.FromJsonString('foo,baz')
- mask2.FromJsonString('bar,quz')
- out_mask.Union(mask1, mask2)
- self.assertEqual('bar,baz,foo,quz', out_mask.ToJsonString())
- # Overlap with duplicated paths.
- mask1.FromJsonString('foo,baz.bb')
- mask2.FromJsonString('baz.bb,quz')
- out_mask.Union(mask1, mask2)
- self.assertEqual('baz.bb,foo,quz', out_mask.ToJsonString())
- # Overlap with paths covering some other paths.
- mask1.FromJsonString('foo.bar.baz,quz')
- mask2.FromJsonString('foo.bar,bar')
- out_mask.Union(mask1, mask2)
- self.assertEqual('bar,foo.bar,quz', out_mask.ToJsonString())
- src = unittest_pb2.TestAllTypes()
- with self.assertRaises(ValueError):
- out_mask.Union(src, mask2)
-
- def testIntersect(self):
- mask1 = field_mask_pb2.FieldMask()
- mask2 = field_mask_pb2.FieldMask()
- out_mask = field_mask_pb2.FieldMask()
- # Test cases without overlapping.
- mask1.FromJsonString('foo,baz')
- mask2.FromJsonString('bar,quz')
- out_mask.Intersect(mask1, mask2)
- self.assertEqual('', out_mask.ToJsonString())
- self.assertEqual(len(out_mask.paths), 0)
- self.assertEqual(out_mask.paths, [])
- # Overlap with duplicated paths.
- mask1.FromJsonString('foo,baz.bb')
- mask2.FromJsonString('baz.bb,quz')
- out_mask.Intersect(mask1, mask2)
- self.assertEqual('baz.bb', out_mask.ToJsonString())
- # Overlap with paths covering some other paths.
- mask1.FromJsonString('foo.bar.baz,quz')
- mask2.FromJsonString('foo.bar,bar')
- out_mask.Intersect(mask1, mask2)
- self.assertEqual('foo.bar.baz', out_mask.ToJsonString())
- mask1.FromJsonString('foo.bar,bar')
- mask2.FromJsonString('foo.bar.baz,quz')
- out_mask.Intersect(mask1, mask2)
- self.assertEqual('foo.bar.baz', out_mask.ToJsonString())
- # Intersect '' with ''
- mask1.Clear()
- mask2.Clear()
- mask1.paths.append('')
- mask2.paths.append('')
- self.assertEqual(mask1.paths, [''])
- self.assertEqual('', mask1.ToJsonString())
- out_mask.Intersect(mask1, mask2)
- self.assertEqual(out_mask.paths, [])
-
- def testMergeMessageWithoutMapFields(self):
- # Test merge one field.
- src = unittest_pb2.TestAllTypes()
- test_util.SetAllFields(src)
- for field in src.DESCRIPTOR.fields:
- if field.containing_oneof:
- continue
- field_name = field.name
- dst = unittest_pb2.TestAllTypes()
- # Only set one path to mask.
- mask = field_mask_pb2.FieldMask()
- mask.paths.append(field_name)
- mask.MergeMessage(src, dst)
- # The expected result message.
- msg = unittest_pb2.TestAllTypes()
- if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
- repeated_src = getattr(src, field_name)
- repeated_msg = getattr(msg, field_name)
- if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
- for item in repeated_src:
- repeated_msg.add().CopyFrom(item)
- else:
- repeated_msg.extend(repeated_src)
- elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
- getattr(msg, field_name).CopyFrom(getattr(src, field_name))
- else:
- setattr(msg, field_name, getattr(src, field_name))
- # Only field specified in mask is merged.
- self.assertEqual(msg, dst)
-
- # Test merge nested fields.
- nested_src = unittest_pb2.NestedTestAllTypes()
- nested_dst = unittest_pb2.NestedTestAllTypes()
- nested_src.child.payload.optional_int32 = 1234
- nested_src.child.child.payload.optional_int32 = 5678
- mask = field_mask_pb2.FieldMask()
- mask.FromJsonString('child.payload')
- mask.MergeMessage(nested_src, nested_dst)
- self.assertEqual(1234, nested_dst.child.payload.optional_int32)
- self.assertEqual(0, nested_dst.child.child.payload.optional_int32)
-
- mask.FromJsonString('child.child.payload')
- mask.MergeMessage(nested_src, nested_dst)
- self.assertEqual(1234, nested_dst.child.payload.optional_int32)
- self.assertEqual(5678, nested_dst.child.child.payload.optional_int32)
-
- nested_dst.Clear()
- mask.FromJsonString('child.child.payload')
- mask.MergeMessage(nested_src, nested_dst)
- self.assertEqual(0, nested_dst.child.payload.optional_int32)
- self.assertEqual(5678, nested_dst.child.child.payload.optional_int32)
-
- nested_dst.Clear()
- mask.FromJsonString('child')
- mask.MergeMessage(nested_src, nested_dst)
- self.assertEqual(1234, nested_dst.child.payload.optional_int32)
- self.assertEqual(5678, nested_dst.child.child.payload.optional_int32)
-
- # Test MergeOptions.
- nested_dst.Clear()
- nested_dst.child.payload.optional_int64 = 4321
- # Message fields will be merged by default.
- mask.FromJsonString('child.payload')
- mask.MergeMessage(nested_src, nested_dst)
- self.assertEqual(1234, nested_dst.child.payload.optional_int32)
- self.assertEqual(4321, nested_dst.child.payload.optional_int64)
- # Change the behavior to replace message fields.
- mask.FromJsonString('child.payload')
- mask.MergeMessage(nested_src, nested_dst, True, False)
- self.assertEqual(1234, nested_dst.child.payload.optional_int32)
- self.assertEqual(0, nested_dst.child.payload.optional_int64)
-
- # By default, fields missing in source are not cleared in destination.
- nested_dst.payload.optional_int32 = 1234
- self.assertTrue(nested_dst.HasField('payload'))
- mask.FromJsonString('payload')
- mask.MergeMessage(nested_src, nested_dst)
- self.assertTrue(nested_dst.HasField('payload'))
- # But they are cleared when replacing message fields.
- nested_dst.Clear()
- nested_dst.payload.optional_int32 = 1234
- mask.FromJsonString('payload')
- mask.MergeMessage(nested_src, nested_dst, True, False)
- self.assertFalse(nested_dst.HasField('payload'))
-
- nested_src.payload.repeated_int32.append(1234)
- nested_dst.payload.repeated_int32.append(5678)
- # Repeated fields will be appended by default.
- mask.FromJsonString('payload.repeatedInt32')
- mask.MergeMessage(nested_src, nested_dst)
- self.assertEqual(2, len(nested_dst.payload.repeated_int32))
- self.assertEqual(5678, nested_dst.payload.repeated_int32[0])
- self.assertEqual(1234, nested_dst.payload.repeated_int32[1])
- # Change the behavior to replace repeated fields.
- mask.FromJsonString('payload.repeatedInt32')
- mask.MergeMessage(nested_src, nested_dst, False, True)
- self.assertEqual(1, len(nested_dst.payload.repeated_int32))
- self.assertEqual(1234, nested_dst.payload.repeated_int32[0])
-
- # Test Merge oneof field.
- new_msg = unittest_pb2.TestOneof2()
- dst = unittest_pb2.TestOneof2()
- dst.foo_message.moo_int = 1
- mask = field_mask_pb2.FieldMask()
- mask.FromJsonString('fooMessage,fooLazyMessage.mooInt')
- mask.MergeMessage(new_msg, dst)
- self.assertTrue(dst.HasField('foo_message'))
- self.assertFalse(dst.HasField('foo_lazy_message'))
-
- def testMergeMessageWithMapField(self):
- empty_map = map_unittest_pb2.TestRecursiveMapMessage()
- src_level_2 = map_unittest_pb2.TestRecursiveMapMessage()
- src_level_2.a['src level 2'].CopyFrom(empty_map)
- src = map_unittest_pb2.TestRecursiveMapMessage()
- src.a['common key'].CopyFrom(src_level_2)
- src.a['src level 1'].CopyFrom(src_level_2)
-
- dst_level_2 = map_unittest_pb2.TestRecursiveMapMessage()
- dst_level_2.a['dst level 2'].CopyFrom(empty_map)
- dst = map_unittest_pb2.TestRecursiveMapMessage()
- dst.a['common key'].CopyFrom(dst_level_2)
- dst.a['dst level 1'].CopyFrom(empty_map)
-
- mask = field_mask_pb2.FieldMask()
- mask.FromJsonString('a')
- mask.MergeMessage(src, dst)
-
- # map from dst is replaced with map from src.
- self.assertEqual(dst.a['common key'], src_level_2)
- self.assertEqual(dst.a['src level 1'], src_level_2)
- self.assertEqual(dst.a['dst level 1'], empty_map)
-
- def testMergeErrors(self):
- src = unittest_pb2.TestAllTypes()
- dst = unittest_pb2.TestAllTypes()
- mask = field_mask_pb2.FieldMask()
- test_util.SetAllFields(src)
- mask.FromJsonString('optionalInt32.field')
- with self.assertRaises(ValueError) as e:
- mask.MergeMessage(src, dst)
- self.assertEqual('Error: Field optional_int32 in message '
- 'protobuf_unittest.TestAllTypes is not a singular '
- 'message field and cannot have sub-fields.',
- str(e.exception))
-
- def testSnakeCaseToCamelCase(self):
- self.assertEqual('fooBar',
- well_known_types._SnakeCaseToCamelCase('foo_bar'))
- self.assertEqual('FooBar',
- well_known_types._SnakeCaseToCamelCase('_foo_bar'))
- self.assertEqual('foo3Bar',
- well_known_types._SnakeCaseToCamelCase('foo3_bar'))
-
- # No uppercase letter is allowed.
- self.assertRaisesRegex(
- ValueError,
- 'Fail to print FieldMask to Json string: Path name Foo must '
- 'not contain uppercase letters.',
- well_known_types._SnakeCaseToCamelCase, 'Foo')
- # Any character after a "_" must be a lowercase letter.
- # 1. "_" cannot be followed by another "_".
- # 2. "_" cannot be followed by a digit.
- # 3. "_" cannot appear as the last character.
- self.assertRaisesRegex(
- ValueError,
- 'Fail to print FieldMask to Json string: The character after a '
- '"_" must be a lowercase letter in path name foo__bar.',
- well_known_types._SnakeCaseToCamelCase, 'foo__bar')
- self.assertRaisesRegex(
- ValueError,
- 'Fail to print FieldMask to Json string: The character after a '
- '"_" must be a lowercase letter in path name foo_3bar.',
- well_known_types._SnakeCaseToCamelCase, 'foo_3bar')
- self.assertRaisesRegex(
- ValueError,
- 'Fail to print FieldMask to Json string: Trailing "_" in path '
- 'name foo_bar_.', well_known_types._SnakeCaseToCamelCase, 'foo_bar_')
-
- def testCamelCaseToSnakeCase(self):
- self.assertEqual('foo_bar',
- well_known_types._CamelCaseToSnakeCase('fooBar'))
- self.assertEqual('_foo_bar',
- well_known_types._CamelCaseToSnakeCase('FooBar'))
- self.assertEqual('foo3_bar',
- well_known_types._CamelCaseToSnakeCase('foo3Bar'))
- self.assertRaisesRegex(
- ValueError,
- 'Fail to parse FieldMask: Path name foo_bar must not contain "_"s.',
- well_known_types._CamelCaseToSnakeCase, 'foo_bar')
-
-
class StructTest(unittest.TestCase):
def testStruct(self):
diff --git a/src/file_lists.cmake b/src/file_lists.cmake
index c9e111d..1626c92 100644
--- a/src/file_lists.cmake
+++ b/src/file_lists.cmake
@@ -181,7 +181,6 @@
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_macros.h
- ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stl_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.h
${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.h
@@ -273,7 +272,6 @@
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_macros.h
- ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stl_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h
)
diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc
index 514da71..9649411 100644
--- a/src/google/protobuf/any.pb.cc
+++ b/src/google/protobuf/any.pb.cc
@@ -218,6 +218,7 @@
}
const char* Any::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -267,6 +268,7 @@
uint8_t* Any::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -296,6 +298,7 @@
}
size_t Any::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Any)
size_t total_size = 0;
@@ -330,6 +333,7 @@
void Any::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Any*>(&to_msg);
auto& from = static_cast<const Any&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -371,6 +375,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Any::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fany_2eproto_getter, &descriptor_table_google_2fprotobuf_2fany_2eproto_once,
file_level_metadata_google_2fprotobuf_2fany_2eproto[0]);
diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h
index 01ca595..3d1e46f 100644
--- a/src/google/protobuf/any.pb.h
+++ b/src/google/protobuf/any.pb.h
@@ -320,11 +320,6 @@
return _impl_.type_url_.Release();
}
inline void Any::set_allocated_type_url(std::string* type_url) {
- if (type_url != nullptr) {
-
- } else {
-
- }
_impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.type_url_.IsDefault()) {
@@ -370,11 +365,6 @@
return _impl_.value_.Release();
}
inline void Any::set_allocated_value(std::string* value) {
- if (value != nullptr) {
-
- } else {
-
- }
_impl_.value_.SetAllocated(value, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.value_.IsDefault()) {
diff --git a/src/google/protobuf/any.proto b/src/google/protobuf/any.proto
index e2c2042..8bd9801 100644
--- a/src/google/protobuf/any.proto
+++ b/src/google/protobuf/any.proto
@@ -93,7 +93,6 @@
// in the type URL, for example "foo.bar.com/x/y.z" will yield type
// name "y.z".
//
-//
// JSON
//
// The JSON representation of an `Any` value uses the regular
diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc
index 865bf59..da04763 100644
--- a/src/google/protobuf/api.pb.cc
+++ b/src/google/protobuf/api.pb.cc
@@ -329,6 +329,7 @@
}
const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -435,6 +436,7 @@
uint8_t* Api::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Api)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -506,6 +508,7 @@
}
size_t Api::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Api)
size_t total_size = 0;
@@ -574,6 +577,7 @@
void Api::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Api*>(&to_msg);
auto& from = static_cast<const Api&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -634,6 +638,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Api::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fapi_2eproto_getter, &descriptor_table_google_2fprotobuf_2fapi_2eproto_once,
file_level_metadata_google_2fprotobuf_2fapi_2eproto[0]);
@@ -763,6 +768,7 @@
}
const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -861,6 +867,7 @@
uint8_t* Method::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Method)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -931,6 +938,7 @@
}
size_t Method::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Method)
size_t total_size = 0;
@@ -995,6 +1003,7 @@
void Method::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Method*>(&to_msg);
auto& from = static_cast<const Method&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1060,6 +1069,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Method::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fapi_2eproto_getter, &descriptor_table_google_2fprotobuf_2fapi_2eproto_once,
file_level_metadata_google_2fprotobuf_2fapi_2eproto[1]);
@@ -1154,6 +1164,7 @@
}
const char* Mixin::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1204,6 +1215,7 @@
uint8_t* Mixin::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Mixin)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1237,6 +1249,7 @@
}
size_t Mixin::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Mixin)
size_t total_size = 0;
@@ -1271,6 +1284,7 @@
void Mixin::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Mixin*>(&to_msg);
auto& from = static_cast<const Mixin&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1312,6 +1326,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Mixin::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fapi_2eproto_getter, &descriptor_table_google_2fprotobuf_2fapi_2eproto_once,
file_level_metadata_google_2fprotobuf_2fapi_2eproto[2]);
diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h
index 20c1f5a..2f9a865 100644
--- a/src/google/protobuf/api.pb.h
+++ b/src/google/protobuf/api.pb.h
@@ -792,11 +792,6 @@
return _impl_.name_.Release();
}
inline void Api::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -919,11 +914,6 @@
return _impl_.version_.Release();
}
inline void Api::set_allocated_version(std::string* version) {
- if (version != nullptr) {
-
- } else {
-
- }
_impl_.version_.SetAllocated(version, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.version_.IsDefault()) {
@@ -955,11 +945,6 @@
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_);
}
_impl_.source_context_ = source_context;
- if (source_context) {
-
- } else {
-
- }
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.source_context)
}
inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
@@ -1118,11 +1103,6 @@
return _impl_.name_.Release();
}
inline void Method::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -1168,11 +1148,6 @@
return _impl_.request_type_url_.Release();
}
inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
- if (request_type_url != nullptr) {
-
- } else {
-
- }
_impl_.request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.request_type_url_.IsDefault()) {
@@ -1238,11 +1213,6 @@
return _impl_.response_type_url_.Release();
}
inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
- if (response_type_url != nullptr) {
-
- } else {
-
- }
_impl_.response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.response_type_url_.IsDefault()) {
@@ -1369,11 +1339,6 @@
return _impl_.name_.Release();
}
inline void Mixin::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -1419,11 +1384,6 @@
return _impl_.root_.Release();
}
inline void Mixin::set_allocated_root(std::string* root) {
- if (root != nullptr) {
-
- } else {
-
- }
_impl_.root_.SetAllocated(root, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.root_.IsDefault()) {
diff --git a/src/google/protobuf/api.proto b/src/google/protobuf/api.proto
index 3d598fc..426c240 100644
--- a/src/google/protobuf/api.proto
+++ b/src/google/protobuf/api.proto
@@ -82,7 +82,6 @@
// be omitted. Zero major versions must only be used for
// experimental, non-GA interfaces.
//
- //
string version = 4;
// Source context for the protocol buffer service represented by this
diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc
index 2a183d3..f033d67 100644
--- a/src/google/protobuf/arenastring.cc
+++ b/src/google/protobuf/arenastring.cc
@@ -39,7 +39,6 @@
#include "absl/synchronization/mutex.h"
#include "google/protobuf/message_lite.h"
#include "google/protobuf/parse_context.h"
-#include "google/protobuf/stubs/stl_util.h"
// clang-format off
#include "google/protobuf/port_def.inc"
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index cc80987..84e096a 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -89,7 +89,6 @@
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/text_format.h"
-#include "google/protobuf/stubs/stl_util.h"
// Must be included last.
@@ -872,7 +871,7 @@
// Now copy in the data.
std::string::size_type data_pos = 0;
- char* target_ptr = ::google::protobuf::string_as_array(target) + pos;
+ char* target_ptr = &(*target)[pos];
while (data_pos < data_.size()) {
// Copy indent.
memcpy(target_ptr, indent_.data(), indent_.size());
@@ -889,8 +888,7 @@
}
UpdateMetadata(data_, pos, data_.size() + indent_size, indent_.size());
- GOOGLE_CHECK_EQ(target_ptr,
- ::google::protobuf::string_as_array(target) + pos + data_.size() + indent_size);
+ GOOGLE_CHECK_EQ(target_ptr, &(*target)[pos] + data_.size() + indent_size);
}
}
}
diff --git a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc
index 4685c0a..3ea5d73 100644
--- a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc
@@ -56,7 +56,6 @@
#include "absl/container/flat_hash_map.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/compiler/cpp/helpers.h"
-#include "google/protobuf/stubs/stl_util.h"
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.h b/src/google/protobuf/compiler/cpp/cpp_generator.h
index b336453..599b4ab 100644
--- a/src/google/protobuf/compiler/cpp/cpp_generator.h
+++ b/src/google/protobuf/compiler/cpp/cpp_generator.h
@@ -1,3 +1,33 @@
+// 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 GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_
#define GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_
diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc
index 70ff98f..64edf64 100644
--- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc
+++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc
@@ -271,6 +271,12 @@
static NumToEntryTable MakeNumToEntryTable(
const std::vector<const FieldDescriptor*>& field_descriptors);
+static int FieldNameDataSize(const std::vector<uint8_t>& data) {
+ // We add a +1 here to allow for a NUL termination character. It makes the
+ // codegen nicer.
+ return data.empty() ? 0 : data.size() + 1;
+}
+
void ParseFunctionGenerator::GenerateDataDecls(io::Printer* printer) {
if (!should_generate_tctable()) {
return;
@@ -288,9 +294,7 @@
"TcParseTable<$1$, $2$, $3$, $4$, $5$> _table_;\n",
tc_table_info_->table_size_log2, ordered_fields_.size(),
tc_table_info_->aux_entries.size(),
- // We add a +1 here to allow for a NUL termination character. It makes the
- // codegen nicer.
- tc_table_info_->field_name_data.size() + 1,
+ FieldNameDataSize(tc_table_info_->field_name_data),
field_num_to_entry_table.size16());
if (should_generate_guarded_tctable()) {
format.Outdent();
@@ -450,7 +454,7 @@
"{\n",
tc_table_info_->table_size_log2, ordered_fields_.size(),
tc_table_info_->aux_entries.size(),
- tc_table_info_->field_name_data.size() + 1, // See above for why +1
+ FieldNameDataSize(tc_table_info_->field_name_data),
field_num_to_entry_table.size16());
{
auto table_scope = format.ScopedIndent();
@@ -608,12 +612,12 @@
format("}}, {{\n");
}
} // ordered_fields_.empty()
- {
- // field_names[]
- auto field_name_scope = format.ScopedIndent();
- GenerateFieldNames(format);
- }
- format("}},\n");
+ {
+ // field_names[]
+ auto field_name_scope = format.ScopedIndent();
+ GenerateFieldNames(format);
+ }
+ format("}},\n");
}
format("};\n\n"); // _table_
}
@@ -832,6 +836,11 @@
}
void ParseFunctionGenerator::GenerateFieldNames(Formatter& format) {
+ if (tc_table_info_->field_name_data.empty()) {
+ // No names to output.
+ return;
+ }
+
// We could just output the bytes directly, but we want it to look better than
// that in the source code. Also, it is more efficient for compilation time to
// have a literal string than an initializer list of chars.
@@ -854,8 +863,8 @@
format("\"\n");
// Then print each name in a line of its own
- for (; sizes < sizes_end && sizes[0] != 0; p += *sizes++) {
- format("\"$1$\"\n", std::string(p, p + *sizes));
+ for (; sizes < sizes_end; p += *sizes++) {
+ if (*sizes != 0) format("\"$1$\"\n", std::string(p, p + *sizes));
}
}
diff --git a/src/google/protobuf/compiler/cpp/unittest.inc b/src/google/protobuf/compiler/cpp/unittest.inc
index f1c4986..1f65a90 100644
--- a/src/google/protobuf/compiler/cpp/unittest.inc
+++ b/src/google/protobuf/compiler/cpp/unittest.inc
@@ -76,7 +76,6 @@
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/test_util2.h"
-#include "google/protobuf/stubs/stl_util.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
@@ -664,7 +663,7 @@
TestUtil::SetAllFields(&message1);
int size = message1.ByteSizeLong();
data.resize(size);
- uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -678,8 +677,7 @@
TestUtil::SetPackedFields(&packed_message1);
int packed_size = packed_message1.ByteSizeLong();
packed_data.resize(packed_size);
- uint8_t* start =
- reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&packed_data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&packed_data[0]);
uint8_t* end = packed_message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(packed_size, end - start);
EXPECT_TRUE(packed_message2.ParseFromString(packed_data));
@@ -696,7 +694,7 @@
data.resize(size);
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
io::CodedOutputStream output_stream(&array_stream);
message1.SerializeWithCachedSizes(&output_stream);
EXPECT_FALSE(output_stream.HadError());
@@ -715,7 +713,7 @@
data.resize(size);
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
io::CodedOutputStream output_stream(&array_stream);
message1.SerializeWithCachedSizes(&output_stream);
EXPECT_FALSE(output_stream.HadError());
@@ -1841,7 +1839,7 @@
message1.set_foo_int(123);
int size = message1.ByteSizeLong();
data.resize(size);
-uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1855,7 +1853,7 @@
message1.set_foo_string("foo");
int size = message1.ByteSizeLong();
data.resize(size);
- uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1870,7 +1868,7 @@
message1.set_foo_bytes("moo");
int size = message1.ByteSizeLong();
data.resize(size);
- uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1884,7 +1882,7 @@
message1.set_foo_enum(UNITTEST::TestOneof2::FOO);
int size = message1.ByteSizeLong();
data.resize(size);
- uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1898,7 +1896,7 @@
message1.mutable_foo_message()->set_moo_int(234);
int size = message1.ByteSizeLong();
data.resize(size);
- uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1912,7 +1910,7 @@
message1.mutable_foogroup()->set_a(345);
int size = message1.ByteSizeLong();
data.resize(size);
- uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1937,11 +1935,11 @@
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
- io::CodedOutputStream output_stream(&array_stream);
- message1.SerializeWithCachedSizes(&output_stream);
- EXPECT_FALSE(output_stream.HadError());
- EXPECT_EQ(size, output_stream.ByteCount());
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
+ io::CodedOutputStream output_stream(&array_stream);
+ message1.SerializeWithCachedSizes(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
}
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1958,11 +1956,11 @@
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
- io::CodedOutputStream output_stream(&array_stream);
- message1.SerializeWithCachedSizes(&output_stream);
- EXPECT_FALSE(output_stream.HadError());
- EXPECT_EQ(size, output_stream.ByteCount());
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
+ io::CodedOutputStream output_stream(&array_stream);
+ message1.SerializeWithCachedSizes(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
}
EXPECT_TRUE(message2.ParseFromString(data));
@@ -1980,11 +1978,11 @@
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
- io::CodedOutputStream output_stream(&array_stream);
- message1.SerializeWithCachedSizes(&output_stream);
- EXPECT_FALSE(output_stream.HadError());
- EXPECT_EQ(size, output_stream.ByteCount());
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
+ io::CodedOutputStream output_stream(&array_stream);
+ message1.SerializeWithCachedSizes(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
}
EXPECT_TRUE(message2.ParseFromString(data));
@@ -2001,11 +1999,11 @@
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
- io::CodedOutputStream output_stream(&array_stream);
- message1.SerializeWithCachedSizes(&output_stream);
- EXPECT_FALSE(output_stream.HadError());
- EXPECT_EQ(size, output_stream.ByteCount());
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
+ io::CodedOutputStream output_stream(&array_stream);
+ message1.SerializeWithCachedSizes(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
}
EXPECT_TRUE(message2.ParseFromString(data));
@@ -2022,11 +2020,11 @@
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
- io::CodedOutputStream output_stream(&array_stream);
- message1.SerializeWithCachedSizes(&output_stream);
- EXPECT_FALSE(output_stream.HadError());
- EXPECT_EQ(size, output_stream.ByteCount());
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
+ io::CodedOutputStream output_stream(&array_stream);
+ message1.SerializeWithCachedSizes(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
}
EXPECT_TRUE(message2.ParseFromString(data));
@@ -2043,11 +2041,11 @@
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
- io::CodedOutputStream output_stream(&array_stream);
- message1.SerializeWithCachedSizes(&output_stream);
- EXPECT_FALSE(output_stream.HadError());
- EXPECT_EQ(size, output_stream.ByteCount());
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
+ io::CodedOutputStream output_stream(&array_stream);
+ message1.SerializeWithCachedSizes(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
}
EXPECT_TRUE(message2.ParseFromString(data));
diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
index 798cab5..a477a81 100644
--- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
@@ -51,7 +51,6 @@
#include "google/protobuf/compiler/importer.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
-#include "google/protobuf/stubs/stl_util.h"
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/java/java_generator.h b/src/google/protobuf/compiler/java/java_generator.h
index 2058371..45d30a5 100644
--- a/src/google/protobuf/compiler/java/java_generator.h
+++ b/src/google/protobuf/compiler/java/java_generator.h
@@ -1,3 +1,33 @@
+// 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 GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_
#define GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_
diff --git a/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc b/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc
index fc8ab23..3bc4eef 100644
--- a/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc
+++ b/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc
@@ -32,14 +32,13 @@
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
-#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
+#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
-#include "google/protobuf/stubs/strutil.h"
// 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.
diff --git a/src/google/protobuf/compiler/plugin.proto b/src/google/protobuf/compiler/plugin.proto
index 0f46a45..b233bce 100644
--- a/src/google/protobuf/compiler/plugin.proto
+++ b/src/google/protobuf/compiler/plugin.proto
@@ -89,7 +89,6 @@
// The version number of protocol compiler.
optional Version compiler_version = 3;
-
}
// The plugin writes an encoded CodeGeneratorResponse to stdout.
diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h
index bb31797..a46cf5e 100644
--- a/src/google/protobuf/compiler/python/python_generator.h
+++ b/src/google/protobuf/compiler/python/python_generator.h
@@ -1,3 +1,33 @@
+// 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 GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_
#define GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_
diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto
index f264b13..0636a87 100644
--- a/src/google/protobuf/descriptor.proto
+++ b/src/google/protobuf/descriptor.proto
@@ -36,7 +36,6 @@
// A valid .proto file can be translated directly to a FileDescriptorProto
// without any other information (e.g. without reading its imports).
-
syntax = "proto2";
package google.protobuf;
@@ -134,7 +133,6 @@
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
-
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
@@ -310,7 +308,6 @@
optional bool server_streaming = 6 [default = false];
}
-
// ===================================================================
// Options
@@ -351,7 +348,6 @@
// domain names.
optional string java_package = 1;
-
// Controls the name of the wrapper Java class generated for the .proto file.
// That class will always contain the .proto file's getDescriptor() method as
// well as any top-level extensions defined in the .proto file.
@@ -378,7 +374,6 @@
// This option has no effect on when used with the lite runtime.
optional bool java_string_check_utf8 = 27 [default = false];
-
// Generated classes can be optimized for speed or code size.
enum OptimizeMode {
SPEED = 1; // Generate complete code for parsing, serialization,
@@ -395,9 +390,6 @@
// - Otherwise, the basename of the .proto file, without extension.
optional string go_package = 11;
-
-
-
// Should generic services be generated in each language? "Generic" services
// are not specific to any particular RPC system. They are generated by the
// main code generators in each language (without additional plugins).
@@ -423,7 +415,6 @@
// only to generated classes for C++.
optional bool cc_enable_arenas = 31 [default = true];
-
// Sets the objective c class prefix which is prepended to all objective c
// generated classes from this .proto. There is no default.
optional string objc_class_prefix = 36;
@@ -456,7 +447,6 @@
// determining the ruby package.
optional string ruby_package = 45;
-
// The parser stores options it doesn't recognize here.
// See the documentation for the "Options" section above.
repeated UninterpretedOption uninterpreted_option = 999;
@@ -528,7 +518,6 @@
reserved 8; // javalite_serializable
reserved 9; // javanano_as_lite
-
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
@@ -597,7 +586,6 @@
// call from multiple threads concurrently, while non-const methods continue
// to require exclusive access.
//
- //
// Note that implementations may choose not to check required fields within
// a lazy sub-message. That is, calling IsInitialized() on the outer message
// may return true even if the inner message has missing required fields.
@@ -627,7 +615,6 @@
// For Google-internal migration only. Do not use.
optional bool weak = 10 [default = false];
-
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
@@ -731,7 +718,6 @@
extensions 1000 to max;
}
-
// A message representing a option the parser does not recognize. This only
// appears in options protos created by the compiler::Parser class.
// DescriptorPool resolves these when building Descriptor objects. Therefore,
diff --git a/src/google/protobuf/descriptor_database.cc b/src/google/protobuf/descriptor_database.cc
index c024a77..5e0d6c3 100644
--- a/src/google/protobuf/descriptor_database.cc
+++ b/src/google/protobuf/descriptor_database.cc
@@ -42,7 +42,6 @@
#include "absl/strings/match.h"
#include "absl/strings/str_replace.h"
#include "google/protobuf/descriptor.pb.h"
-#include "google/protobuf/stubs/stl_util.h"
namespace google {
diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc
index 726592b..ab187ae 100644
--- a/src/google/protobuf/descriptor_unittest.cc
+++ b/src/google/protobuf/descriptor_unittest.cc
@@ -2775,15 +2775,19 @@
->set_default_value("hello");
AddField(message_proto, "data", 9, label, FD::TYPE_BYTES)
->set_default_value("\\001\\002\\003");
+ AddField(message_proto, "data2", 10, label, FD::TYPE_BYTES)
+ ->set_default_value("\\X01\\X2\\X3");
+ AddField(message_proto, "data3", 11, label, FD::TYPE_BYTES)
+ ->set_default_value("\\x01\\x2\\x3");
FieldDescriptorProto* enum_field =
- AddField(message_proto, "enum", 10, label, FD::TYPE_ENUM);
+ AddField(message_proto, "enum", 12, label, FD::TYPE_ENUM);
enum_field->set_type_name("DummyEnum");
enum_field->set_default_value("B");
// Strings are allowed to have empty defaults. (At one point, due to
// a bug, empty defaults for strings were rejected. Oops.)
- AddField(message_proto, "empty_string", 11, label, FD::TYPE_STRING)
+ AddField(message_proto, "empty_string", 13, label, FD::TYPE_STRING)
->set_default_value("");
// Add a second set of fields with implicit default values.
@@ -2813,7 +2817,7 @@
ASSERT_EQ(1, file->message_type_count());
const Descriptor* message = file->message_type(0);
- ASSERT_EQ(21, message->field_count());
+ ASSERT_EQ(23, message->field_count());
// Check the default values.
ASSERT_TRUE(message->field(0)->has_default_value());
@@ -2827,6 +2831,8 @@
ASSERT_TRUE(message->field(8)->has_default_value());
ASSERT_TRUE(message->field(9)->has_default_value());
ASSERT_TRUE(message->field(10)->has_default_value());
+ ASSERT_TRUE(message->field(11)->has_default_value());
+ ASSERT_TRUE(message->field(12)->has_default_value());
EXPECT_EQ(-1, message->field(0)->default_value_int32());
EXPECT_EQ(int64_t{-1000000000000}, message->field(1)->default_value_int64());
@@ -2837,11 +2843,11 @@
EXPECT_TRUE(message->field(6)->default_value_bool());
EXPECT_EQ("hello", message->field(7)->default_value_string());
EXPECT_EQ("\001\002\003", message->field(8)->default_value_string());
- EXPECT_EQ(enum_value_b, message->field(9)->default_value_enum());
- EXPECT_EQ("", message->field(10)->default_value_string());
+ EXPECT_EQ("\001\002\003", message->field(9)->default_value_string());
+ EXPECT_EQ("\001\002\003", message->field(10)->default_value_string());
+ EXPECT_EQ(enum_value_b, message->field(11)->default_value_enum());
+ EXPECT_EQ("", message->field(12)->default_value_string());
- ASSERT_FALSE(message->field(11)->has_default_value());
- ASSERT_FALSE(message->field(12)->has_default_value());
ASSERT_FALSE(message->field(13)->has_default_value());
ASSERT_FALSE(message->field(14)->has_default_value());
ASSERT_FALSE(message->field(15)->has_default_value());
@@ -2850,17 +2856,19 @@
ASSERT_FALSE(message->field(18)->has_default_value());
ASSERT_FALSE(message->field(19)->has_default_value());
ASSERT_FALSE(message->field(20)->has_default_value());
+ ASSERT_FALSE(message->field(21)->has_default_value());
+ ASSERT_FALSE(message->field(22)->has_default_value());
- EXPECT_EQ(0, message->field(11)->default_value_int32());
- EXPECT_EQ(0, message->field(12)->default_value_int64());
- EXPECT_EQ(0, message->field(13)->default_value_uint32());
- EXPECT_EQ(0, message->field(14)->default_value_uint64());
- EXPECT_EQ(0.0f, message->field(15)->default_value_float());
- EXPECT_EQ(0.0, message->field(16)->default_value_double());
- EXPECT_FALSE(message->field(17)->default_value_bool());
- EXPECT_EQ("", message->field(18)->default_value_string());
- EXPECT_EQ("", message->field(19)->default_value_string());
- EXPECT_EQ(enum_value_a, message->field(20)->default_value_enum());
+ EXPECT_EQ(0, message->field(13)->default_value_int32());
+ EXPECT_EQ(0, message->field(14)->default_value_int64());
+ EXPECT_EQ(0, message->field(15)->default_value_uint32());
+ EXPECT_EQ(0, message->field(16)->default_value_uint64());
+ EXPECT_EQ(0.0f, message->field(17)->default_value_float());
+ EXPECT_EQ(0.0, message->field(18)->default_value_double());
+ EXPECT_FALSE(message->field(19)->default_value_bool());
+ EXPECT_EQ("", message->field(20)->default_value_string());
+ EXPECT_EQ("", message->field(21)->default_value_string());
+ EXPECT_EQ(enum_value_a, message->field(22)->default_value_enum());
}
TEST_F(MiscTest, FieldOptions) {
diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc
index 18d3e42..7c60f7f 100644
--- a/src/google/protobuf/duration.pb.cc
+++ b/src/google/protobuf/duration.pb.cc
@@ -120,17 +120,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.Duration)
}
Duration::Duration(const Duration& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- Duration* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.seconds_){}
- , decltype(_impl_.nanos_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- ::memcpy(&_impl_.seconds_, &from._impl_.seconds_,
- static_cast<size_t>(reinterpret_cast<char*>(&_impl_.nanos_) -
- reinterpret_cast<char*>(&_impl_.seconds_)) + sizeof(_impl_.nanos_));
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Duration)
}
@@ -175,6 +167,7 @@
}
const char* Duration::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -221,6 +214,7 @@
uint8_t* Duration::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -246,6 +240,7 @@
}
size_t Duration::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Duration)
size_t total_size = 0;
@@ -276,6 +271,7 @@
void Duration::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Duration*>(&to_msg);
auto& from = static_cast<const Duration&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -313,6 +309,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Duration::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fduration_2eproto_getter, &descriptor_table_google_2fprotobuf_2fduration_2eproto_once,
file_level_metadata_google_2fprotobuf_2fduration_2eproto[0]);
diff --git a/src/google/protobuf/duration.proto b/src/google/protobuf/duration.proto
index 81c3e36..a0d91df 100644
--- a/src/google/protobuf/duration.proto
+++ b/src/google/protobuf/duration.proto
@@ -99,7 +99,6 @@
// be expressed in JSON format as "3.000000001s", and 3 seconds and 1
// microsecond should be expressed in JSON format as "3.000001s".
//
-//
message Duration {
// Signed seconds of the span of time. Must be from -315,576,000,000
// to +315,576,000,000 inclusive. Note: these bounds are computed from:
diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc
index 91ba9f2..c04ad78 100644
--- a/src/google/protobuf/empty.pb.cc
+++ b/src/google/protobuf/empty.pb.cc
@@ -136,6 +136,7 @@
::PROTOBUF_NAMESPACE_ID::Metadata Empty::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fempty_2eproto_getter, &descriptor_table_google_2fprotobuf_2fempty_2eproto_once,
file_level_metadata_google_2fprotobuf_2fempty_2eproto[0]);
diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc
index 8ef2d2b..5d07a98 100644
--- a/src/google/protobuf/extension_set_unittest.cc
+++ b/src/google/protobuf/extension_set_unittest.cc
@@ -53,7 +53,6 @@
#include "absl/strings/match.h"
#include "google/protobuf/test_util.h"
#include "google/protobuf/test_util2.h"
-#include "google/protobuf/stubs/stl_util.h"
#include "google/protobuf/stubs/strutil.h"
@@ -552,7 +551,7 @@
size_t size = source.ByteSizeLong();
std::string data;
data.resize(size);
- uint8_t* target = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* target = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = source.SerializeWithCachedSizesToArray(target);
EXPECT_EQ(size, end - target);
EXPECT_TRUE(destination.ParseFromString(data));
@@ -574,7 +573,7 @@
std::string data;
data.resize(size);
{
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
io::CodedOutputStream output_stream(&array_stream);
source.SerializeWithCachedSizes(&output_stream);
ASSERT_FALSE(output_stream.HadError());
@@ -596,7 +595,7 @@
size_t size = source.ByteSizeLong();
std::string data;
data.resize(size);
- uint8_t* target = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* target = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = source.SerializeWithCachedSizesToArray(target);
EXPECT_EQ(size, end - target);
EXPECT_TRUE(destination.ParseFromString(data));
@@ -618,7 +617,7 @@
std::string data;
data.resize(size);
{
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
io::CodedOutputStream output_stream(&array_stream);
source.SerializeWithCachedSizes(&output_stream);
ASSERT_FALSE(output_stream.HadError());
diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc
index 42dbbd5..de87758 100644
--- a/src/google/protobuf/field_mask.pb.cc
+++ b/src/google/protobuf/field_mask.pb.cc
@@ -167,6 +167,7 @@
}
const char* FieldMask::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -212,6 +213,7 @@
uint8_t* FieldMask::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -235,6 +237,7 @@
}
size_t FieldMask::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldMask)
size_t total_size = 0;
@@ -263,6 +266,7 @@
void FieldMask::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<FieldMask*>(&to_msg);
auto& from = static_cast<const FieldMask&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -290,6 +294,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata FieldMask::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_getter, &descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_once,
file_level_metadata_google_2fprotobuf_2ffield_5fmask_2eproto[0]);
diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc
index bacb9b8..43d0c10 100644
--- a/src/google/protobuf/generated_message_reflection.cc
+++ b/src/google/protobuf/generated_message_reflection.cc
@@ -3095,7 +3095,7 @@
// Create a dummy table that only exists to make TcParser::ParseLoop jump
// into the reflective parse loop.
- using Table = internal::TcParseTable<0, 0, 0, 1, 1>;
+ using Table = internal::TcParseTable<0, 0, 0, 0, 1>;
// We use `operator new` here because the destruction will be done with
// `operator delete` unconditionally.
void* p = ::operator new(sizeof(Table));
@@ -3320,8 +3320,10 @@
PopulateTcParseFieldAux(table_info, res->field_aux(0u));
// Copy the name data.
- memcpy(res->name_data(), table_info.field_name_data.data(),
- table_info.field_name_data.size());
+ if (!table_info.field_name_data.empty()) {
+ memcpy(res->name_data(), table_info.field_name_data.data(),
+ table_info.field_name_data.size());
+ }
// Validation to make sure we used all the bytes correctly.
GOOGLE_CHECK_EQ(res->name_data() + table_info.field_name_data.size() -
reinterpret_cast<char*>(res),
diff --git a/src/google/protobuf/generated_message_tctable_decl.h b/src/google/protobuf/generated_message_tctable_decl.h
index 58bf277..dd4845b 100644
--- a/src/google/protobuf/generated_message_tctable_decl.h
+++ b/src/google/protobuf/generated_message_tctable_decl.h
@@ -347,7 +347,7 @@
// Entries for all fields:
std::array<TcParseTableBase::FieldEntry, kNumFieldEntries> field_entries;
std::array<TcParseTableBase::FieldAux, kNumFieldAux> aux_entries;
- std::array<char, kNameTableSize> field_names;
+ std::array<char, kNameTableSize == 0 ? 1 : kNameTableSize> field_names;
};
// Partial specialization: if there are no aux entries, there will be no array.
@@ -363,7 +363,7 @@
fast_entries;
std::array<uint16_t, kFieldLookupSize> field_lookup_table;
std::array<TcParseTableBase::FieldEntry, kNumFieldEntries> field_entries;
- std::array<char, kNameTableSize> field_names;
+ std::array<char, kNameTableSize == 0 ? 1 : kNameTableSize> field_names;
};
// Partial specialization: if there are no fields at all, then we can save space
@@ -375,7 +375,7 @@
// The fast parsing loop will always use this entry, so it must be present.
std::array<TcParseTableBase::FastFieldEntry, 1> fast_entries;
std::array<uint16_t, kFieldLookupSize> field_lookup_table;
- std::array<char, kNameTableSize> field_names;
+ std::array<char, kNameTableSize == 0 ? 1 : kNameTableSize> field_names;
};
static_assert(std::is_standard_layout<TcParseTable<1>>::value,
diff --git a/src/google/protobuf/generated_message_tctable_gen.cc b/src/google/protobuf/generated_message_tctable_gen.cc
index 4189180..e31d191 100644
--- a/src/google/protobuf/generated_message_tctable_gen.cc
+++ b/src/google/protobuf/generated_message_tctable_gen.cc
@@ -420,10 +420,9 @@
case field_layout::kTvUtf8:
case field_layout::kTvUtf8Debug:
return field->name();
- break;
}
}
- return "?";
+ return "";
}
std::vector<uint8_t> GenerateFieldNames(
@@ -431,6 +430,20 @@
const std::vector<TailCallTableInfo::FieldEntryInfo>& entries) {
static constexpr int kMaxNameLength = 255;
std::vector<uint8_t> out;
+
+ bool found_needed_name = false;
+ for (const auto& entry : entries) {
+ if (!FieldNameForTable(entry).empty()) {
+ found_needed_name = true;
+ break;
+ }
+ }
+
+ // No names needed. Omit the whole table.
+ if (!found_needed_name) {
+ return out;
+ }
+
// First, we output the size of each string, as an unsigned byte. The first
// string is the message name.
int count = 1;
diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h
index 25263d5..f51be94 100644
--- a/src/google/protobuf/generated_message_tctable_impl.h
+++ b/src/google/protobuf/generated_message_tctable_impl.h
@@ -610,6 +610,7 @@
// For FindFieldEntry tests:
friend class FindFieldEntryTest;
+ friend struct ParseFunctionGeneratorTestPeer;
static constexpr const uint32_t kMtSmallScanSize = 4;
// Mini parsing:
diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc
index 4d7f56c..88bbc89 100644
--- a/src/google/protobuf/io/tokenizer.cc
+++ b/src/google/protobuf/io/tokenizer.cc
@@ -96,7 +96,6 @@
#include "absl/strings/str_format.h"
#include "google/protobuf/io/strtod.h"
#include "google/protobuf/io/zero_copy_stream.h"
-#include "google/protobuf/stubs/stl_util.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
@@ -422,7 +421,7 @@
// Possibly followed by two more octal digits, but these will
// just be consumed by the main loop anyway so we don't need
// to do so explicitly here.
- } else if (TryConsume('x')) {
+ } else if (TryConsume('x') || TryConsume('X')) {
if (!TryConsumeOne<HexDigit>()) {
AddError("Expected hex digits for escape sequence.");
}
@@ -1216,7 +1215,7 @@
}
output->push_back(static_cast<char>(code));
- } else if (*ptr == 'x') {
+ } else if (*ptr == 'x' || *ptr == 'X') {
// A hex escape. May zero, one, or two digits. (The zero case
// will have been caught as an error earlier.)
int code = 0;
diff --git a/src/google/protobuf/io/tokenizer_unittest.cc b/src/google/protobuf/io/tokenizer_unittest.cc
index f4d70f0..3d59f63 100644
--- a/src/google/protobuf/io/tokenizer_unittest.cc
+++ b/src/google/protobuf/io/tokenizer_unittest.cc
@@ -1045,6 +1045,8 @@
EXPECT_EQ("\1x\1\123\739\52\334n\3", output);
Tokenizer::ParseString("'\\x20\\x4'", &output);
EXPECT_EQ("\x20\x4", output);
+ Tokenizer::ParseString("'\\X20\\X4'", &output);
+ EXPECT_EQ("\x20\x4", output);
// Test invalid strings that may still be tokenized as strings.
Tokenizer::ParseString("\"\\a\\l\\v\\t", &output); // \l is invalid
@@ -1110,7 +1112,7 @@
ErrorCase kErrorCases[] = {
// String errors.
{"'\\l' foo", true, "0:2: Invalid escape sequence in string literal.\n"},
- {"'\\X' foo", true, "0:2: Invalid escape sequence in string literal.\n"},
+ {"'\\X' foo", true, "0:3: Expected hex digits for escape sequence.\n"},
{"'\\x' foo", true, "0:3: Expected hex digits for escape sequence.\n"},
{"'foo", false, "0:4: Unexpected end of string.\n"},
{"'bar\nfoo", true,
diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc
index 2955c7b..041930e 100644
--- a/src/google/protobuf/io/zero_copy_stream_impl.cc
+++ b/src/google/protobuf/io/zero_copy_stream_impl.cc
@@ -47,7 +47,6 @@
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/io/io_win32.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
-#include "google/protobuf/stubs/stl_util.h"
namespace google {
diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/src/google/protobuf/io/zero_copy_stream_impl_lite.h
index 28ad9d6..a23713c 100644
--- a/src/google/protobuf/io/zero_copy_stream_impl_lite.h
+++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.h
@@ -53,7 +53,6 @@
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/port.h"
-#include "google/protobuf/stubs/stl_util.h"
// Must be included last.
@@ -387,24 +386,10 @@
// ===================================================================
-// mutable_string_data() and as_string_data() are workarounds to improve
-// the performance of writing new data to an existing string. Unfortunately
-// the methods provided by the string class are suboptimal, and using memcpy()
-// is mildly annoying because it requires its pointer args to be non-NULL even
-// if we ask it to copy 0 bytes. Furthermore, string_as_array() has the
-// property that it always returns NULL if its arg is the empty string, exactly
-// what we want to avoid if we're using it in conjunction with memcpy()!
-// With C++11, the desired memcpy() boils down to memcpy(..., &(*s)[0], size),
-// where s is a string*. Without C++11, &(*s)[0] is not guaranteed to be safe,
-// so we use string_as_array(), and live with the extra logic that tests whether
-// *s is empty.
-
// Return a pointer to mutable characters underlying the given string. The
// return value is valid until the next time the string is resized. We
// trust the caller to treat the return value as an array of length s->size().
inline char* mutable_string_data(std::string* s) {
- // This should be simpler & faster than string_as_array() because the latter
- // is guaranteed to return NULL when *s is empty, so it has to check for that.
return &(*s)[0];
}
diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc
index 3b615b7..1a03171 100644
--- a/src/google/protobuf/lite_unittest.cc
+++ b/src/google/protobuf/lite_unittest.cc
@@ -675,8 +675,7 @@
MapLiteTestUtil::SetMapFields(&message1);
size_t size = message1.ByteSizeLong();
data.resize(size);
- ::uint8_t* start =
- reinterpret_cast<::uint8_t*>(::google::protobuf::string_as_array(&data));
+ ::uint8_t* start = reinterpret_cast<::uint8_t*>(&data[0]);
::uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -696,7 +695,7 @@
data.resize(size);
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
io::CodedOutputStream output_stream(&array_stream);
message1.SerializeWithCachedSizes(&output_stream);
EXPECT_FALSE(output_stream.HadError());
diff --git a/src/google/protobuf/map_test.inc b/src/google/protobuf/map_test.inc
index baf3c82..9b839ae 100644
--- a/src/google/protobuf/map_test.inc
+++ b/src/google/protobuf/map_test.inc
@@ -2692,7 +2692,7 @@
MapTestUtil::SetMapFields(&message1);
size_t size = message1.ByteSizeLong();
data.resize(size);
- uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
+ uint8_t* start = reinterpret_cast<uint8_t*>(&data[0]);
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
@@ -2708,7 +2708,7 @@
data.resize(size);
{
// Allow the output stream to buffer only one byte at a time.
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1);
+ io::ArrayOutputStream array_stream(&data[0], size, 1);
io::CodedOutputStream output_stream(&array_stream);
message1.SerializeWithCachedSizes(&output_stream);
EXPECT_FALSE(output_stream.HadError());
@@ -3739,7 +3739,7 @@
const T& t) {
const size_t size = t.ByteSizeLong();
std::string result(size, '\0');
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&result), size);
+ io::ArrayOutputStream array_stream(&result[0], size);
io::CodedOutputStream output_stream(&array_stream);
output_stream.SetSerializationDeterministic(true);
t.SerializePartialToCodedStream(&output_stream);
@@ -3753,7 +3753,7 @@
const T& t) {
const size_t size = t.ByteSizeLong();
std::string result(size, '\0');
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&result), size);
+ io::ArrayOutputStream array_stream(&result[0], size);
io::CodedOutputStream output_stream(&array_stream);
output_stream.SetSerializationDeterministic(true);
t.SerializeToCodedStream(&output_stream);
@@ -3766,7 +3766,7 @@
static std::string DeterministicSerialization(const T& t) {
const size_t size = t.ByteSizeLong();
std::string result(size, '\0');
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&result), size);
+ io::ArrayOutputStream array_stream(&result[0], size);
{
io::CodedOutputStream output_stream(&array_stream);
output_stream.SetSerializationDeterministic(true);
diff --git a/src/google/protobuf/map_unittest.proto b/src/google/protobuf/map_unittest.proto
index 263ef61..7c88c55 100644
--- a/src/google/protobuf/map_unittest.proto
+++ b/src/google/protobuf/map_unittest.proto
@@ -76,7 +76,6 @@
map<int32, int32> map2 = 2;
}
-
enum MapEnum {
MAP_ENUM_FOO = 0;
MAP_ENUM_BAR = 1;
diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc
index 4cad7af..e43d93a 100644
--- a/src/google/protobuf/message.cc
+++ b/src/google/protobuf/message.cc
@@ -61,7 +61,6 @@
#include "google/protobuf/unknown_field_set.h"
#include "google/protobuf/wire_format.h"
#include "google/protobuf/wire_format_lite.h"
-#include "google/protobuf/stubs/stl_util.h"
// Must be included last.
diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc
index eeecf07..6f91b16 100644
--- a/src/google/protobuf/repeated_field_unittest.cc
+++ b/src/google/protobuf/repeated_field_unittest.cc
@@ -56,7 +56,6 @@
#include "absl/strings/cord.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/stubs/strutil.h"
-#include "google/protobuf/stubs/stl_util.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc
index 1959701..ce0f339 100644
--- a/src/google/protobuf/source_context.pb.cc
+++ b/src/google/protobuf/source_context.pb.cc
@@ -179,6 +179,7 @@
}
const char* SourceContext::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -219,6 +220,7 @@
uint8_t* SourceContext::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -242,6 +244,7 @@
}
size_t SourceContext::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceContext)
size_t total_size = 0;
@@ -269,6 +272,7 @@
void SourceContext::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<SourceContext*>(&to_msg);
auto& from = static_cast<const SourceContext&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -303,6 +307,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata SourceContext::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_getter, &descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_once,
file_level_metadata_google_2fprotobuf_2fsource_5fcontext_2eproto[0]);
diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h
index 8f1aeff..21d2fc2 100644
--- a/src/google/protobuf/source_context.pb.h
+++ b/src/google/protobuf/source_context.pb.h
@@ -268,11 +268,6 @@
return _impl_.file_name_.Release();
}
inline void SourceContext::set_allocated_file_name(std::string* file_name) {
- if (file_name != nullptr) {
-
- } else {
-
- }
_impl_.file_name_.SetAllocated(file_name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.file_name_.IsDefault()) {
diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc
index aa53b79..eb92db0 100644
--- a/src/google/protobuf/struct.pb.cc
+++ b/src/google/protobuf/struct.pb.cc
@@ -209,7 +209,6 @@
return false;
}
}
-
// ===================================================================
Struct_FieldsEntry_DoNotUse::Struct_FieldsEntry_DoNotUse() {}
@@ -295,6 +294,7 @@
}
const char* Struct::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -338,6 +338,7 @@
uint8_t* Struct::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -377,6 +378,7 @@
}
size_t Struct::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Struct)
size_t total_size = 0;
@@ -406,6 +408,7 @@
void Struct::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Struct*>(&to_msg);
auto& from = static_cast<const Struct&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -433,6 +436,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Struct::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter, &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once,
file_level_metadata_google_2fprotobuf_2fstruct_2eproto[1]);
@@ -617,6 +621,7 @@
}
const char* Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -698,6 +703,7 @@
uint8_t* Value::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Value)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -754,6 +760,7 @@
}
size_t Value::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Value)
size_t total_size = 0;
@@ -816,6 +823,7 @@
void Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Value*>(&to_msg);
auto& from = static_cast<const Value&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -874,6 +882,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Value::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter, &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once,
file_level_metadata_google_2fprotobuf_2fstruct_2eproto[2]);
@@ -940,6 +949,7 @@
}
const char* ListValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -983,6 +993,7 @@
uint8_t* ListValue::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ListValue)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1004,6 +1015,7 @@
}
size_t ListValue::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.ListValue)
size_t total_size = 0;
@@ -1031,6 +1043,7 @@
void ListValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<ListValue*>(&to_msg);
auto& from = static_cast<const ListValue&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1058,6 +1071,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata ListValue::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter, &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once,
file_level_metadata_google_2fprotobuf_2fstruct_2eproto[3]);
diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h
index 36ae0b8..b31f206 100644
--- a/src/google/protobuf/struct.pb.h
+++ b/src/google/protobuf/struct.pb.h
@@ -80,31 +80,34 @@
PROTOBUF_NAMESPACE_OPEN
enum NullValue : int {
NULL_VALUE = 0,
- NullValue_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::min(),
- NullValue_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::max()
+ NullValue_INT_MIN_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::min(),
+ NullValue_INT_MAX_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::max(),
};
-PROTOBUF_EXPORT bool NullValue_IsValid(int value);
-constexpr NullValue NullValue_MIN = NULL_VALUE;
-constexpr NullValue NullValue_MAX = NULL_VALUE;
-constexpr int NullValue_ARRAYSIZE = NullValue_MAX + 1;
-PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* NullValue_descriptor();
-template<typename T>
-inline const std::string& NullValue_Name(T enum_t_value) {
- static_assert(::std::is_same<T, NullValue>::value ||
- ::std::is_integral<T>::value,
- "Incorrect type passed to function NullValue_Name.");
- return NullValue_Name(static_cast<NullValue>(enum_t_value));
+PROTOBUF_EXPORT bool NullValue_IsValid(int value);
+constexpr NullValue NullValue_MIN = static_cast<NullValue>(0);
+constexpr NullValue NullValue_MAX = static_cast<NullValue>(0);
+constexpr int NullValue_ARRAYSIZE = 0 + 1;
+PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor*
+NullValue_descriptor();
+template <typename T>
+const std::string& NullValue_Name(T value) {
+ static_assert(std::is_same<T, NullValue>::value ||
+ std::is_integral<T>::value,
+ "Incorrect type passed to NullValue_Name().");
+ return NullValue_Name(static_cast<NullValue>(value));
}
-template<>
+template <>
inline const std::string& NullValue_Name(NullValue value) {
- return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum
- <NullValue_descriptor, 0, 0>(static_cast<int>(value));
+ return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum<NullValue_descriptor,
+ 0, 0>(
+ static_cast<int>(value));
}
-inline bool NullValue_Parse(
- ::absl::string_view name, NullValue* value) {
+inline bool NullValue_Parse(absl::string_view name, NullValue* value) {
return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum<NullValue>(
- NullValue_descriptor(), name, value);
+ NullValue_descriptor(), name, value);
}
// ===================================================================
@@ -1175,9 +1178,10 @@
PROTOBUF_NAMESPACE_OPEN
-template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::NullValue> : ::std::true_type {};
template <>
-inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::NullValue>() {
+struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::NullValue> : std::true_type {};
+template <>
+inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::NullValue>() {
return ::PROTOBUF_NAMESPACE_ID::NullValue_descriptor();
}
diff --git a/src/google/protobuf/stubs/BUILD.bazel b/src/google/protobuf/stubs/BUILD.bazel
index 98f497e..9cc3e75 100644
--- a/src/google/protobuf/stubs/BUILD.bazel
+++ b/src/google/protobuf/stubs/BUILD.bazel
@@ -26,7 +26,6 @@
"platform_macros.h",
"port.h",
"status_macros.h",
- "stl_util.h",
"strutil.h",
],
copts = COPTS,
@@ -56,7 +55,6 @@
"platform_macros.h",
"port.h",
"status_macros.h",
- "stl_util.h",
"strutil.h",
],
deps = [
diff --git a/src/google/protobuf/stubs/callback.h b/src/google/protobuf/stubs/callback.h
index 691eda4..ed4b9f7 100644
--- a/src/google/protobuf/stubs/callback.h
+++ b/src/google/protobuf/stubs/callback.h
@@ -1,3 +1,33 @@
+// 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 GOOGLE_PROTOBUF_STUBS_CALLBACK_H_
#define GOOGLE_PROTOBUF_STUBS_CALLBACK_H_
diff --git a/src/google/protobuf/stubs/stl_util.h b/src/google/protobuf/stubs/stl_util.h
deleted file mode 100644
index cd10c4b..0000000
--- a/src/google/protobuf/stubs/stl_util.h
+++ /dev/null
@@ -1,68 +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.
-
-// from google3/util/gtl/stl_util.h
-
-#ifndef GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__
-#define GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__
-
-#include <algorithm>
-
-#include "google/protobuf/stubs/common.h"
-
-// Must be last.
-#include "google/protobuf/port_def.inc" // NOLINT
-
-namespace google {
-namespace protobuf {
-
-// Return a mutable char* pointing to a string's internal buffer,
-// which may not be null-terminated. Writing through this pointer will
-// modify the string.
-//
-// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the
-// next call to a string method that invalidates iterators.
-//
-// As of 2006-04, there is no standard-blessed way of getting a
-// mutable reference to a string's internal buffer. However, issue 530
-// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530)
-// proposes this as the method. According to Matt Austern, this should
-// already work on all current implementations.
-inline char* string_as_array(std::string* str) {
- // DO NOT USE const_cast<char*>(str->data())! See the unittest for why.
- return str->empty() ? nullptr : &*str->begin();
-}
-
-} // namespace protobuf
-} // namespace google
-
-#include "google/protobuf/port_undef.inc" // NOLINT
-
-#endif // GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__
diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc
index 720c6fc..7d088a8 100644
--- a/src/google/protobuf/stubs/strutil.cc
+++ b/src/google/protobuf/stubs/strutil.cc
@@ -44,7 +44,6 @@
#include "absl/strings/ascii.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/stubs/logging.h"
-#include "google/protobuf/stubs/stl_util.h"
#ifdef _WIN32
// MSVC has only _snprintf, not snprintf.
@@ -671,9 +670,8 @@
const absl::string_view base64_chars) {
const int calc_escaped_size = CalculateBase64EscapedLen(szsrc, do_padding);
dest->resize(calc_escaped_size);
- const int escaped_len =
- Base64EscapeInternal(src, szsrc, string_as_array(dest), dest->size(),
- base64_chars, do_padding);
+ const int escaped_len = Base64EscapeInternal(
+ src, szsrc, &(*dest)[0], dest->size(), base64_chars, do_padding);
GOOGLE_DCHECK_EQ(calc_escaped_size, escaped_len);
dest->erase(escaped_len);
}
diff --git a/src/google/protobuf/stubs/strutil_unittest.cc b/src/google/protobuf/stubs/strutil_unittest.cc
index 71e60e6..ea15b1d 100644
--- a/src/google/protobuf/stubs/strutil_unittest.cc
+++ b/src/google/protobuf/stubs/strutil_unittest.cc
@@ -35,7 +35,6 @@
#include <gtest/gtest.h>
#include <locale.h>
-#include "google/protobuf/stubs/stl_util.h"
#include "google/protobuf/testing/googletest.h"
#ifdef _WIN32
diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc
index 560d413..30132a1 100644
--- a/src/google/protobuf/text_format.cc
+++ b/src/google/protobuf/text_format.cc
@@ -67,7 +67,6 @@
#include "google/protobuf/repeated_field.h"
#include "google/protobuf/unknown_field_set.h"
#include "google/protobuf/wire_format_lite.h"
-#include "google/protobuf/stubs/stl_util.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc
index a62cdcf..a26f164 100644
--- a/src/google/protobuf/timestamp.pb.cc
+++ b/src/google/protobuf/timestamp.pb.cc
@@ -120,17 +120,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.Timestamp)
}
Timestamp::Timestamp(const Timestamp& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- Timestamp* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.seconds_){}
- , decltype(_impl_.nanos_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- ::memcpy(&_impl_.seconds_, &from._impl_.seconds_,
- static_cast<size_t>(reinterpret_cast<char*>(&_impl_.nanos_) -
- reinterpret_cast<char*>(&_impl_.seconds_)) + sizeof(_impl_.nanos_));
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Timestamp)
}
@@ -175,6 +167,7 @@
}
const char* Timestamp::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -221,6 +214,7 @@
uint8_t* Timestamp::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Timestamp)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -246,6 +240,7 @@
}
size_t Timestamp::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Timestamp)
size_t total_size = 0;
@@ -276,6 +271,7 @@
void Timestamp::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Timestamp*>(&to_msg);
auto& from = static_cast<const Timestamp&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -313,6 +309,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Timestamp::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_once,
file_level_metadata_google_2fprotobuf_2ftimestamp_2eproto[0]);
diff --git a/src/google/protobuf/timestamp.proto b/src/google/protobuf/timestamp.proto
index 3b2df6d..184a18f 100644
--- a/src/google/protobuf/timestamp.proto
+++ b/src/google/protobuf/timestamp.proto
@@ -90,7 +90,6 @@
// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
// .setNanos((int) ((millis % 1000) * 1000000)).build();
//
-//
// Example 5: Compute Timestamp from Java `Instant.now()`.
//
// Instant now = Instant.now();
@@ -99,7 +98,6 @@
// Timestamp.newBuilder().setSeconds(now.getEpochSecond())
// .setNanos(now.getNano()).build();
//
-//
// Example 6: Compute Timestamp from current time in Python.
//
// timestamp = Timestamp()
@@ -132,7 +130,6 @@
// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
// ) to obtain a formatter capable of generating timestamps in this format.
//
-//
message Timestamp {
// Represents seconds of UTC time since Unix epoch
// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc
index cdebb41..096d52e 100644
--- a/src/google/protobuf/type.pb.cc
+++ b/src/google/protobuf/type.pb.cc
@@ -315,8 +315,9 @@
return false;
}
}
+#if (__cplusplus < 201703) && \
+ (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
-#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
constexpr Field_Kind Field::TYPE_UNKNOWN;
constexpr Field_Kind Field::TYPE_DOUBLE;
constexpr Field_Kind Field::TYPE_FLOAT;
@@ -339,7 +340,9 @@
constexpr Field_Kind Field::Kind_MIN;
constexpr Field_Kind Field::Kind_MAX;
constexpr int Field::Kind_ARRAYSIZE;
-#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
+
+#endif // (__cplusplus < 201703) &&
+ // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Field_Cardinality_descriptor() {
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2ftype_2eproto);
return file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto[1];
@@ -355,8 +358,9 @@
return false;
}
}
+#if (__cplusplus < 201703) && \
+ (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
-#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
constexpr Field_Cardinality Field::CARDINALITY_UNKNOWN;
constexpr Field_Cardinality Field::CARDINALITY_OPTIONAL;
constexpr Field_Cardinality Field::CARDINALITY_REQUIRED;
@@ -364,7 +368,9 @@
constexpr Field_Cardinality Field::Cardinality_MIN;
constexpr Field_Cardinality Field::Cardinality_MAX;
constexpr int Field::Cardinality_ARRAYSIZE;
-#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
+
+#endif // (__cplusplus < 201703) &&
+ // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Syntax_descriptor() {
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2ftype_2eproto);
return file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto[2];
@@ -378,7 +384,6 @@
return false;
}
}
-
// ===================================================================
class Type::_Internal {
@@ -490,6 +495,7 @@
}
const char* Type::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -588,6 +594,7 @@
uint8_t* Type::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Type)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -651,6 +658,7 @@
}
size_t Type::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Type)
size_t total_size = 0;
@@ -713,6 +721,7 @@
void Type::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Type*>(&to_msg);
auto& from = static_cast<const Type&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -766,6 +775,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Type::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once,
file_level_metadata_google_2fprotobuf_2ftype_2eproto[0]);
@@ -912,6 +922,7 @@
}
const char* Field::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1037,6 +1048,7 @@
uint8_t* Field::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Field)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1130,6 +1142,7 @@
}
size_t Field::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Field)
size_t total_size = 0;
@@ -1212,6 +1225,7 @@
void Field::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Field*>(&to_msg);
auto& from = static_cast<const Field&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1290,6 +1304,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Field::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once,
file_level_metadata_google_2fprotobuf_2ftype_2eproto[1]);
@@ -1401,6 +1416,7 @@
}
const char* Enum::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1484,6 +1500,7 @@
uint8_t* Enum::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Enum)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1537,6 +1554,7 @@
}
size_t Enum::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Enum)
size_t total_size = 0;
@@ -1591,6 +1609,7 @@
void Enum::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Enum*>(&to_msg);
auto& from = static_cast<const Enum&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1642,6 +1661,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Enum::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once,
file_level_metadata_google_2fprotobuf_2ftype_2eproto[2]);
@@ -1728,6 +1748,7 @@
}
const char* EnumValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1789,6 +1810,7 @@
uint8_t* EnumValue::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValue)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1826,6 +1848,7 @@
}
size_t EnumValue::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValue)
size_t total_size = 0;
@@ -1865,6 +1888,7 @@
void EnumValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<EnumValue*>(&to_msg);
auto& from = static_cast<const EnumValue&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1905,6 +1929,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata EnumValue::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once,
file_level_metadata_google_2fprotobuf_2ftype_2eproto[3]);
@@ -2004,6 +2029,7 @@
}
const char* Option::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -2052,6 +2078,7 @@
uint8_t* Option::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Option)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -2082,6 +2109,7 @@
}
size_t Option::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Option)
size_t total_size = 0;
@@ -2116,6 +2144,7 @@
void Option::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Option*>(&to_msg);
auto& from = static_cast<const Option&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Option)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -2155,6 +2184,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Option::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once,
file_level_metadata_google_2fprotobuf_2ftype_2eproto[4]);
diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h
index 18bf4cb..a630ba6 100644
--- a/src/google/protobuf/type.pb.h
+++ b/src/google/protobuf/type.pb.h
@@ -102,91 +102,100 @@
Field_Kind_TYPE_SFIXED64 = 16,
Field_Kind_TYPE_SINT32 = 17,
Field_Kind_TYPE_SINT64 = 18,
- Field_Kind_Field_Kind_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::min(),
- Field_Kind_Field_Kind_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::max()
+ Field_Kind_Field_Kind_INT_MIN_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::min(),
+ Field_Kind_Field_Kind_INT_MAX_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::max(),
};
-PROTOBUF_EXPORT bool Field_Kind_IsValid(int value);
-constexpr Field_Kind Field_Kind_Kind_MIN = Field_Kind_TYPE_UNKNOWN;
-constexpr Field_Kind Field_Kind_Kind_MAX = Field_Kind_TYPE_SINT64;
-constexpr int Field_Kind_Kind_ARRAYSIZE = Field_Kind_Kind_MAX + 1;
-PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Field_Kind_descriptor();
-template<typename T>
-inline const std::string& Field_Kind_Name(T enum_t_value) {
- static_assert(::std::is_same<T, Field_Kind>::value ||
- ::std::is_integral<T>::value,
- "Incorrect type passed to function Field_Kind_Name.");
- return Field_Kind_Name(static_cast<Field_Kind>(enum_t_value));
+PROTOBUF_EXPORT bool Field_Kind_IsValid(int value);
+constexpr Field_Kind Field_Kind_Kind_MIN = static_cast<Field_Kind>(0);
+constexpr Field_Kind Field_Kind_Kind_MAX = static_cast<Field_Kind>(18);
+constexpr int Field_Kind_Kind_ARRAYSIZE = 18 + 1;
+PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor*
+Field_Kind_descriptor();
+template <typename T>
+const std::string& Field_Kind_Name(T value) {
+ static_assert(std::is_same<T, Field_Kind>::value ||
+ std::is_integral<T>::value,
+ "Incorrect type passed to Kind_Name().");
+ return Field_Kind_Name(static_cast<Field_Kind>(value));
}
-template<>
+template <>
inline const std::string& Field_Kind_Name(Field_Kind value) {
- return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum
- <Field_Kind_descriptor, 0, 18>(static_cast<int>(value));
+ return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum<Field_Kind_descriptor,
+ 0, 18>(
+ static_cast<int>(value));
}
-inline bool Field_Kind_Parse(
- ::absl::string_view name, Field_Kind* value) {
+inline bool Field_Kind_Parse(absl::string_view name, Field_Kind* value) {
return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum<Field_Kind>(
- Field_Kind_descriptor(), name, value);
+ Field_Kind_descriptor(), name, value);
}
enum Field_Cardinality : int {
Field_Cardinality_CARDINALITY_UNKNOWN = 0,
Field_Cardinality_CARDINALITY_OPTIONAL = 1,
Field_Cardinality_CARDINALITY_REQUIRED = 2,
Field_Cardinality_CARDINALITY_REPEATED = 3,
- Field_Cardinality_Field_Cardinality_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::min(),
- Field_Cardinality_Field_Cardinality_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::max()
+ Field_Cardinality_Field_Cardinality_INT_MIN_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::min(),
+ Field_Cardinality_Field_Cardinality_INT_MAX_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::max(),
};
-PROTOBUF_EXPORT bool Field_Cardinality_IsValid(int value);
-constexpr Field_Cardinality Field_Cardinality_Cardinality_MIN = Field_Cardinality_CARDINALITY_UNKNOWN;
-constexpr Field_Cardinality Field_Cardinality_Cardinality_MAX = Field_Cardinality_CARDINALITY_REPEATED;
-constexpr int Field_Cardinality_Cardinality_ARRAYSIZE = Field_Cardinality_Cardinality_MAX + 1;
-PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Field_Cardinality_descriptor();
-template<typename T>
-inline const std::string& Field_Cardinality_Name(T enum_t_value) {
- static_assert(::std::is_same<T, Field_Cardinality>::value ||
- ::std::is_integral<T>::value,
- "Incorrect type passed to function Field_Cardinality_Name.");
- return Field_Cardinality_Name(static_cast<Field_Cardinality>(enum_t_value));
+PROTOBUF_EXPORT bool Field_Cardinality_IsValid(int value);
+constexpr Field_Cardinality Field_Cardinality_Cardinality_MIN = static_cast<Field_Cardinality>(0);
+constexpr Field_Cardinality Field_Cardinality_Cardinality_MAX = static_cast<Field_Cardinality>(3);
+constexpr int Field_Cardinality_Cardinality_ARRAYSIZE = 3 + 1;
+PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor*
+Field_Cardinality_descriptor();
+template <typename T>
+const std::string& Field_Cardinality_Name(T value) {
+ static_assert(std::is_same<T, Field_Cardinality>::value ||
+ std::is_integral<T>::value,
+ "Incorrect type passed to Cardinality_Name().");
+ return Field_Cardinality_Name(static_cast<Field_Cardinality>(value));
}
-template<>
+template <>
inline const std::string& Field_Cardinality_Name(Field_Cardinality value) {
- return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum
- <Field_Cardinality_descriptor, 0, 3>(static_cast<int>(value));
+ return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum<Field_Cardinality_descriptor,
+ 0, 3>(
+ static_cast<int>(value));
}
-inline bool Field_Cardinality_Parse(
- ::absl::string_view name, Field_Cardinality* value) {
+inline bool Field_Cardinality_Parse(absl::string_view name, Field_Cardinality* value) {
return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum<Field_Cardinality>(
- Field_Cardinality_descriptor(), name, value);
+ Field_Cardinality_descriptor(), name, value);
}
enum Syntax : int {
SYNTAX_PROTO2 = 0,
SYNTAX_PROTO3 = 1,
- Syntax_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::min(),
- Syntax_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::max()
+ Syntax_INT_MIN_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::min(),
+ Syntax_INT_MAX_SENTINEL_DO_NOT_USE_ =
+ std::numeric_limits<int32_t>::max(),
};
-PROTOBUF_EXPORT bool Syntax_IsValid(int value);
-constexpr Syntax Syntax_MIN = SYNTAX_PROTO2;
-constexpr Syntax Syntax_MAX = SYNTAX_PROTO3;
-constexpr int Syntax_ARRAYSIZE = Syntax_MAX + 1;
-PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Syntax_descriptor();
-template<typename T>
-inline const std::string& Syntax_Name(T enum_t_value) {
- static_assert(::std::is_same<T, Syntax>::value ||
- ::std::is_integral<T>::value,
- "Incorrect type passed to function Syntax_Name.");
- return Syntax_Name(static_cast<Syntax>(enum_t_value));
+PROTOBUF_EXPORT bool Syntax_IsValid(int value);
+constexpr Syntax Syntax_MIN = static_cast<Syntax>(0);
+constexpr Syntax Syntax_MAX = static_cast<Syntax>(1);
+constexpr int Syntax_ARRAYSIZE = 1 + 1;
+PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor*
+Syntax_descriptor();
+template <typename T>
+const std::string& Syntax_Name(T value) {
+ static_assert(std::is_same<T, Syntax>::value ||
+ std::is_integral<T>::value,
+ "Incorrect type passed to Syntax_Name().");
+ return Syntax_Name(static_cast<Syntax>(value));
}
-template<>
+template <>
inline const std::string& Syntax_Name(Syntax value) {
- return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum
- <Syntax_descriptor, 0, 1>(static_cast<int>(value));
+ return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum<Syntax_descriptor,
+ 0, 1>(
+ static_cast<int>(value));
}
-inline bool Syntax_Parse(
- ::absl::string_view name, Syntax* value) {
+inline bool Syntax_Parse(absl::string_view name, Syntax* value) {
return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum<Syntax>(
- Syntax_descriptor(), name, value);
+ Syntax_descriptor(), name, value);
}
// ===================================================================
@@ -561,101 +570,62 @@
// nested types ----------------------------------------------------
- typedef Field_Kind Kind;
- static constexpr Kind TYPE_UNKNOWN =
- Field_Kind_TYPE_UNKNOWN;
- static constexpr Kind TYPE_DOUBLE =
- Field_Kind_TYPE_DOUBLE;
- static constexpr Kind TYPE_FLOAT =
- Field_Kind_TYPE_FLOAT;
- static constexpr Kind TYPE_INT64 =
- Field_Kind_TYPE_INT64;
- static constexpr Kind TYPE_UINT64 =
- Field_Kind_TYPE_UINT64;
- static constexpr Kind TYPE_INT32 =
- Field_Kind_TYPE_INT32;
- static constexpr Kind TYPE_FIXED64 =
- Field_Kind_TYPE_FIXED64;
- static constexpr Kind TYPE_FIXED32 =
- Field_Kind_TYPE_FIXED32;
- static constexpr Kind TYPE_BOOL =
- Field_Kind_TYPE_BOOL;
- static constexpr Kind TYPE_STRING =
- Field_Kind_TYPE_STRING;
- static constexpr Kind TYPE_GROUP =
- Field_Kind_TYPE_GROUP;
- static constexpr Kind TYPE_MESSAGE =
- Field_Kind_TYPE_MESSAGE;
- static constexpr Kind TYPE_BYTES =
- Field_Kind_TYPE_BYTES;
- static constexpr Kind TYPE_UINT32 =
- Field_Kind_TYPE_UINT32;
- static constexpr Kind TYPE_ENUM =
- Field_Kind_TYPE_ENUM;
- static constexpr Kind TYPE_SFIXED32 =
- Field_Kind_TYPE_SFIXED32;
- static constexpr Kind TYPE_SFIXED64 =
- Field_Kind_TYPE_SFIXED64;
- static constexpr Kind TYPE_SINT32 =
- Field_Kind_TYPE_SINT32;
- static constexpr Kind TYPE_SINT64 =
- Field_Kind_TYPE_SINT64;
+ using Kind = Field_Kind;
+ static constexpr Kind TYPE_UNKNOWN = Field_Kind_TYPE_UNKNOWN;
+ static constexpr Kind TYPE_DOUBLE = Field_Kind_TYPE_DOUBLE;
+ static constexpr Kind TYPE_FLOAT = Field_Kind_TYPE_FLOAT;
+ static constexpr Kind TYPE_INT64 = Field_Kind_TYPE_INT64;
+ static constexpr Kind TYPE_UINT64 = Field_Kind_TYPE_UINT64;
+ static constexpr Kind TYPE_INT32 = Field_Kind_TYPE_INT32;
+ static constexpr Kind TYPE_FIXED64 = Field_Kind_TYPE_FIXED64;
+ static constexpr Kind TYPE_FIXED32 = Field_Kind_TYPE_FIXED32;
+ static constexpr Kind TYPE_BOOL = Field_Kind_TYPE_BOOL;
+ static constexpr Kind TYPE_STRING = Field_Kind_TYPE_STRING;
+ static constexpr Kind TYPE_GROUP = Field_Kind_TYPE_GROUP;
+ static constexpr Kind TYPE_MESSAGE = Field_Kind_TYPE_MESSAGE;
+ static constexpr Kind TYPE_BYTES = Field_Kind_TYPE_BYTES;
+ static constexpr Kind TYPE_UINT32 = Field_Kind_TYPE_UINT32;
+ static constexpr Kind TYPE_ENUM = Field_Kind_TYPE_ENUM;
+ static constexpr Kind TYPE_SFIXED32 = Field_Kind_TYPE_SFIXED32;
+ static constexpr Kind TYPE_SFIXED64 = Field_Kind_TYPE_SFIXED64;
+ static constexpr Kind TYPE_SINT32 = Field_Kind_TYPE_SINT32;
+ static constexpr Kind TYPE_SINT64 = Field_Kind_TYPE_SINT64;
static inline bool Kind_IsValid(int value) {
return Field_Kind_IsValid(value);
}
- static constexpr Kind Kind_MIN =
- Field_Kind_Kind_MIN;
- static constexpr Kind Kind_MAX =
- Field_Kind_Kind_MAX;
- static constexpr int Kind_ARRAYSIZE =
- Field_Kind_Kind_ARRAYSIZE;
- static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor*
- Kind_descriptor() {
+ static constexpr Kind Kind_MIN = Field_Kind_Kind_MIN;
+ static constexpr Kind Kind_MAX = Field_Kind_Kind_MAX;
+ static constexpr int Kind_ARRAYSIZE = Field_Kind_Kind_ARRAYSIZE;
+ static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Kind_descriptor() {
return Field_Kind_descriptor();
}
- template<typename T>
- static inline const std::string& Kind_Name(T enum_t_value) {
- static_assert(::std::is_same<T, Kind>::value ||
- ::std::is_integral<T>::value,
- "Incorrect type passed to function Kind_Name.");
- return Field_Kind_Name(enum_t_value);
+ template <typename T>
+ static inline const std::string& Kind_Name(T value) {
+ return Field_Kind_Name(value);
}
- static inline bool Kind_Parse(::absl::string_view name,
- Kind* value) {
+ static inline bool Kind_Parse(absl::string_view name, Kind* value) {
return Field_Kind_Parse(name, value);
}
- typedef Field_Cardinality Cardinality;
- static constexpr Cardinality CARDINALITY_UNKNOWN =
- Field_Cardinality_CARDINALITY_UNKNOWN;
- static constexpr Cardinality CARDINALITY_OPTIONAL =
- Field_Cardinality_CARDINALITY_OPTIONAL;
- static constexpr Cardinality CARDINALITY_REQUIRED =
- Field_Cardinality_CARDINALITY_REQUIRED;
- static constexpr Cardinality CARDINALITY_REPEATED =
- Field_Cardinality_CARDINALITY_REPEATED;
+ using Cardinality = Field_Cardinality;
+ static constexpr Cardinality CARDINALITY_UNKNOWN = Field_Cardinality_CARDINALITY_UNKNOWN;
+ static constexpr Cardinality CARDINALITY_OPTIONAL = Field_Cardinality_CARDINALITY_OPTIONAL;
+ static constexpr Cardinality CARDINALITY_REQUIRED = Field_Cardinality_CARDINALITY_REQUIRED;
+ static constexpr Cardinality CARDINALITY_REPEATED = Field_Cardinality_CARDINALITY_REPEATED;
static inline bool Cardinality_IsValid(int value) {
return Field_Cardinality_IsValid(value);
}
- static constexpr Cardinality Cardinality_MIN =
- Field_Cardinality_Cardinality_MIN;
- static constexpr Cardinality Cardinality_MAX =
- Field_Cardinality_Cardinality_MAX;
- static constexpr int Cardinality_ARRAYSIZE =
- Field_Cardinality_Cardinality_ARRAYSIZE;
- static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor*
- Cardinality_descriptor() {
+ static constexpr Cardinality Cardinality_MIN = Field_Cardinality_Cardinality_MIN;
+ static constexpr Cardinality Cardinality_MAX = Field_Cardinality_Cardinality_MAX;
+ static constexpr int Cardinality_ARRAYSIZE = Field_Cardinality_Cardinality_ARRAYSIZE;
+ static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Cardinality_descriptor() {
return Field_Cardinality_descriptor();
}
- template<typename T>
- static inline const std::string& Cardinality_Name(T enum_t_value) {
- static_assert(::std::is_same<T, Cardinality>::value ||
- ::std::is_integral<T>::value,
- "Incorrect type passed to function Cardinality_Name.");
- return Field_Cardinality_Name(enum_t_value);
+ template <typename T>
+ static inline const std::string& Cardinality_Name(T value) {
+ return Field_Cardinality_Name(value);
}
- static inline bool Cardinality_Parse(::absl::string_view name,
- Cardinality* value) {
+ static inline bool Cardinality_Parse(absl::string_view name, Cardinality* value) {
return Field_Cardinality_Parse(name, value);
}
@@ -1445,11 +1415,6 @@
return _impl_.name_.Release();
}
inline void Type::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -1634,11 +1599,6 @@
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_);
}
_impl_.source_context_ = source_context;
- if (source_context) {
-
- } else {
-
- }
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Type.source_context)
}
inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Type::release_source_context() {
@@ -1817,11 +1777,6 @@
return _impl_.name_.Release();
}
inline void Field::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -1867,11 +1822,6 @@
return _impl_.type_url_.Release();
}
inline void Field::set_allocated_type_url(std::string* type_url) {
- if (type_url != nullptr) {
-
- } else {
-
- }
_impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.type_url_.IsDefault()) {
@@ -1997,11 +1947,6 @@
return _impl_.json_name_.Release();
}
inline void Field::set_allocated_json_name(std::string* json_name) {
- if (json_name != nullptr) {
-
- } else {
-
- }
_impl_.json_name_.SetAllocated(json_name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.json_name_.IsDefault()) {
@@ -2047,11 +1992,6 @@
return _impl_.default_value_.Release();
}
inline void Field::set_allocated_default_value(std::string* default_value) {
- if (default_value != nullptr) {
-
- } else {
-
- }
_impl_.default_value_.SetAllocated(default_value, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.default_value_.IsDefault()) {
@@ -2101,11 +2041,6 @@
return _impl_.name_.Release();
}
inline void Enum::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -2217,11 +2152,6 @@
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_);
}
_impl_.source_context_ = source_context;
- if (source_context) {
-
- } else {
-
- }
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Enum.source_context)
}
inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Enum::release_source_context() {
@@ -2340,11 +2270,6 @@
return _impl_.name_.Release();
}
inline void EnumValue::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -2454,11 +2379,6 @@
return _impl_.name_.Release();
}
inline void Option::set_allocated_name(std::string* name) {
- if (name != nullptr) {
-
- } else {
-
- }
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.name_.IsDefault()) {
@@ -2490,11 +2410,6 @@
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.value_);
}
_impl_.value_ = value;
- if (value) {
-
- } else {
-
- }
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Option.value)
}
inline ::PROTOBUF_NAMESPACE_ID::Any* Option::release_value() {
@@ -2563,19 +2478,22 @@
PROTOBUF_NAMESPACE_OPEN
-template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::Field_Kind> : ::std::true_type {};
template <>
-inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::Field_Kind>() {
+struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::Field_Kind> : std::true_type {};
+template <>
+inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::Field_Kind>() {
return ::PROTOBUF_NAMESPACE_ID::Field_Kind_descriptor();
}
-template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::Field_Cardinality> : ::std::true_type {};
template <>
-inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::Field_Cardinality>() {
+struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::Field_Cardinality> : std::true_type {};
+template <>
+inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::Field_Cardinality>() {
return ::PROTOBUF_NAMESPACE_ID::Field_Cardinality_descriptor();
}
-template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::Syntax> : ::std::true_type {};
template <>
-inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::Syntax>() {
+struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::Syntax> : std::true_type {};
+template <>
+inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::Syntax>() {
return ::PROTOBUF_NAMESPACE_ID::Syntax_descriptor();
}
diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto
index a807815..440a6f0 100644
--- a/src/google/protobuf/unittest.proto
+++ b/src/google/protobuf/unittest.proto
@@ -889,7 +889,6 @@
}
}
-
// Test messages for packed fields
message TestPackedTypes {
@@ -1070,7 +1069,6 @@
optional int64 m6 = 6;
}
-
// Test that RPC services work.
message FooRequest {}
message FooResponse {}
@@ -1083,7 +1081,6 @@
rpc Bar(BarRequest) returns (BarResponse);
}
-
message BarRequest {}
message BarResponse {}
@@ -1437,7 +1434,6 @@
optional Nested optional_nested = 1;
}
-
// This message contains different kind of enums to exercise the different
// parsers in table-driven.
message EnumParseTester {
@@ -1565,4 +1561,3 @@
repeated string repeated_string_midfield = 1002;
repeated string repeated_string_hifield = 1000002;
};
-
diff --git a/src/google/protobuf/unittest_import.proto b/src/google/protobuf/unittest_import.proto
index 8d03e38..4fc0ebb 100644
--- a/src/google/protobuf/unittest_import.proto
+++ b/src/google/protobuf/unittest_import.proto
@@ -64,7 +64,6 @@
IMPORT_BAZ = 9;
}
-
// To use an enum in a map, it must has the first value as 0.
enum ImportEnumForMap {
UNKNOWN = 0;
diff --git a/src/google/protobuf/unknown_field_set_unittest.cc b/src/google/protobuf/unknown_field_set_unittest.cc
index 7093f3d..38337a4 100644
--- a/src/google/protobuf/unknown_field_set_unittest.cc
+++ b/src/google/protobuf/unknown_field_set_unittest.cc
@@ -59,7 +59,6 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "google/protobuf/test_util.h"
-#include "google/protobuf/stubs/stl_util.h"
namespace google {
@@ -207,15 +206,13 @@
slow_buffer.resize(size);
fast_buffer.resize(size);
- uint8_t* target =
- reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&fast_buffer));
+ uint8_t* target = reinterpret_cast<uint8_t*>(&fast_buffer[0]);
uint8_t* result = WireFormat::SerializeUnknownFieldsToArray(
empty_message_.unknown_fields(), target);
EXPECT_EQ(size, result - target);
{
- io::ArrayOutputStream raw_stream(::google::protobuf::string_as_array(&slow_buffer), size,
- 1);
+ io::ArrayOutputStream raw_stream(&slow_buffer[0], size, 1);
io::CodedOutputStream output_stream(&raw_stream);
WireFormat::SerializeUnknownFields(empty_message_.unknown_fields(),
&output_stream);
diff --git a/src/google/protobuf/util/json_format.proto b/src/google/protobuf/util/json_format.proto
index 6199f09..a2703ce 100644
--- a/src/google/protobuf/util/json_format.proto
+++ b/src/google/protobuf/util/json_format.proto
@@ -41,7 +41,6 @@
import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";
-
message TestFlagsAndStrings {
required int32 A = 1;
repeated group RepeatedGroup = 2 {
@@ -96,7 +95,6 @@
optional uint32 f = 6;
}
-
message TestCamelCase {
optional string normal_field = 1;
optional int32 CAPITAL_FIELD = 2;
diff --git a/src/google/protobuf/well_known_types_unittest.cc b/src/google/protobuf/well_known_types_unittest.cc
index 2cc25b5..4d7a0ff 100644
--- a/src/google/protobuf/well_known_types_unittest.cc
+++ b/src/google/protobuf/well_known_types_unittest.cc
@@ -30,7 +30,6 @@
#include <gtest/gtest.h>
#include "google/protobuf/stubs/common.h"
-#include "google/protobuf/stubs/stl_util.h"
#include "google/protobuf/testing/googletest.h"
#include "google/protobuf/unittest_well_known_types.pb.h"
diff --git a/src/google/protobuf/wire_format_unittest.inc b/src/google/protobuf/wire_format_unittest.inc
index 6a3c5bb..81a577e 100644
--- a/src/google/protobuf/wire_format_unittest.inc
+++ b/src/google/protobuf/wire_format_unittest.inc
@@ -49,7 +49,6 @@
#include "absl/strings/match.h"
#include "google/protobuf/dynamic_message.h"
#include "google/protobuf/test_util2.h"
-#include "google/protobuf/stubs/stl_util.h"
// clang-format off
#include "google/protobuf/port_def.inc"
@@ -494,16 +493,14 @@
// Serialize to flat array
{
- uint8_t* target =
- reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&flat_data));
+ uint8_t* target = reinterpret_cast<uint8_t*>(&flat_data[0]);
uint8_t* end = message_set.SerializeWithCachedSizesToArray(target);
EXPECT_EQ(size, end - target);
}
// Serialize to buffer
{
- io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&stream_data), size,
- 1);
+ io::ArrayOutputStream array_stream(&stream_data[0], size, 1);
io::CodedOutputStream output_stream(&array_stream);
message_set.SerializeWithCachedSizes(&output_stream);
ASSERT_FALSE(output_stream.HadError());
diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc
index 60846db..9bc7397 100644
--- a/src/google/protobuf/wrappers.pb.cc
+++ b/src/google/protobuf/wrappers.pb.cc
@@ -324,14 +324,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.DoubleValue)
}
DoubleValue::DoubleValue(const DoubleValue& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- DoubleValue* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.value_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- _this->_impl_.value_ = from._impl_.value_;
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.DoubleValue)
}
@@ -373,6 +368,7 @@
}
const char* DoubleValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -411,6 +407,7 @@
uint8_t* DoubleValue::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DoubleValue)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -434,6 +431,7 @@
}
size_t DoubleValue::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.DoubleValue)
size_t total_size = 0;
@@ -463,6 +461,7 @@
void DoubleValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<DoubleValue*>(&to_msg);
auto& from = static_cast<const DoubleValue&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DoubleValue)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -496,6 +495,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata DoubleValue::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[0]);
@@ -513,14 +513,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.FloatValue)
}
FloatValue::FloatValue(const FloatValue& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- FloatValue* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.value_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- _this->_impl_.value_ = from._impl_.value_;
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.FloatValue)
}
@@ -562,6 +557,7 @@
}
const char* FloatValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -600,6 +596,7 @@
uint8_t* FloatValue::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FloatValue)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -623,6 +620,7 @@
}
size_t FloatValue::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.FloatValue)
size_t total_size = 0;
@@ -652,6 +650,7 @@
void FloatValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<FloatValue*>(&to_msg);
auto& from = static_cast<const FloatValue&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FloatValue)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -685,6 +684,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata FloatValue::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[1]);
@@ -702,14 +702,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.Int64Value)
}
Int64Value::Int64Value(const Int64Value& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- Int64Value* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.value_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- _this->_impl_.value_ = from._impl_.value_;
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Int64Value)
}
@@ -751,6 +746,7 @@
}
const char* Int64Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -789,6 +785,7 @@
uint8_t* Int64Value::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int64Value)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -808,6 +805,7 @@
}
size_t Int64Value::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int64Value)
size_t total_size = 0;
@@ -833,6 +831,7 @@
void Int64Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Int64Value*>(&to_msg);
auto& from = static_cast<const Int64Value&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int64Value)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -862,6 +861,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Int64Value::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[2]);
@@ -879,14 +879,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.UInt64Value)
}
UInt64Value::UInt64Value(const UInt64Value& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- UInt64Value* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.value_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- _this->_impl_.value_ = from._impl_.value_;
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.UInt64Value)
}
@@ -928,6 +923,7 @@
}
const char* UInt64Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -966,6 +962,7 @@
uint8_t* UInt64Value::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt64Value)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -985,6 +982,7 @@
}
size_t UInt64Value::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt64Value)
size_t total_size = 0;
@@ -1010,6 +1008,7 @@
void UInt64Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<UInt64Value*>(&to_msg);
auto& from = static_cast<const UInt64Value&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt64Value)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1039,6 +1038,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata UInt64Value::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[3]);
@@ -1056,14 +1056,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.Int32Value)
}
Int32Value::Int32Value(const Int32Value& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- Int32Value* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.value_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- _this->_impl_.value_ = from._impl_.value_;
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Int32Value)
}
@@ -1105,6 +1100,7 @@
}
const char* Int32Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1143,6 +1139,7 @@
uint8_t* Int32Value::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int32Value)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1162,6 +1159,7 @@
}
size_t Int32Value::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int32Value)
size_t total_size = 0;
@@ -1187,6 +1185,7 @@
void Int32Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<Int32Value*>(&to_msg);
auto& from = static_cast<const Int32Value&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int32Value)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1216,6 +1215,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata Int32Value::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[4]);
@@ -1233,14 +1233,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.UInt32Value)
}
UInt32Value::UInt32Value(const UInt32Value& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- UInt32Value* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.value_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- _this->_impl_.value_ = from._impl_.value_;
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.UInt32Value)
}
@@ -1282,6 +1277,7 @@
}
const char* UInt32Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1320,6 +1316,7 @@
uint8_t* UInt32Value::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt32Value)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1339,6 +1336,7 @@
}
size_t UInt32Value::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt32Value)
size_t total_size = 0;
@@ -1364,6 +1362,7 @@
void UInt32Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<UInt32Value*>(&to_msg);
auto& from = static_cast<const UInt32Value&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt32Value)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1393,6 +1392,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata UInt32Value::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[5]);
@@ -1410,14 +1410,9 @@
// @@protoc_insertion_point(arena_constructor:google.protobuf.BoolValue)
}
BoolValue::BoolValue(const BoolValue& from)
- : ::PROTOBUF_NAMESPACE_ID::Message() {
- BoolValue* const _this = this; (void)_this;
- new (&_impl_) Impl_{
- decltype(_impl_.value_){}
- , /*decltype(_impl_._cached_size_)*/{}};
-
- _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
- _this->_impl_.value_ = from._impl_.value_;
+ : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(
+ from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.BoolValue)
}
@@ -1459,6 +1454,7 @@
}
const char* BoolValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1497,6 +1493,7 @@
uint8_t* BoolValue::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BoolValue)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1516,6 +1513,7 @@
}
size_t BoolValue::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.BoolValue)
size_t total_size = 0;
@@ -1541,6 +1539,7 @@
void BoolValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<BoolValue*>(&to_msg);
auto& from = static_cast<const BoolValue&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BoolValue)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1570,6 +1569,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata BoolValue::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[6]);
@@ -1648,6 +1648,7 @@
}
const char* StringValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1688,6 +1689,7 @@
uint8_t* StringValue::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.StringValue)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1711,6 +1713,7 @@
}
size_t StringValue::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.StringValue)
size_t total_size = 0;
@@ -1738,6 +1741,7 @@
void StringValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<StringValue*>(&to_msg);
auto& from = static_cast<const StringValue&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.StringValue)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1772,6 +1776,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata StringValue::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[7]);
@@ -1850,6 +1855,7 @@
}
const char* BytesValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
+
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
uint32_t tag;
@@ -1889,6 +1895,7 @@
uint8_t* BytesValue::_InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
+
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BytesValue)
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
@@ -1908,6 +1915,7 @@
}
size_t BytesValue::ByteSizeLong() const {
+
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.BytesValue)
size_t total_size = 0;
@@ -1935,6 +1943,7 @@
void BytesValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) {
auto* const _this = static_cast<BytesValue*>(&to_msg);
auto& from = static_cast<const BytesValue&>(from_msg);
+
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BytesValue)
GOOGLE_DCHECK_NE(&from, _this);
uint32_t cached_has_bits = 0;
@@ -1969,6 +1978,7 @@
}
::PROTOBUF_NAMESPACE_ID::Metadata BytesValue::GetMetadata() const {
+
return ::_pbi::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once,
file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[8]);
diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h
index 4f56846..48f4496 100644
--- a/src/google/protobuf/wrappers.pb.h
+++ b/src/google/protobuf/wrappers.pb.h
@@ -1657,11 +1657,6 @@
return _impl_.value_.Release();
}
inline void StringValue::set_allocated_value(std::string* value) {
- if (value != nullptr) {
-
- } else {
-
- }
_impl_.value_.SetAllocated(value, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.value_.IsDefault()) {
@@ -1711,11 +1706,6 @@
return _impl_.value_.Release();
}
inline void BytesValue::set_allocated_value(std::string* value) {
- if (value != nullptr) {
-
- } else {
-
- }
_impl_.value_.SetAllocated(value, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (_impl_.value_.IsDefault()) {