diff options
47 files changed, 577 insertions, 103 deletions
diff --git a/cmake/examples.cmake b/cmake/examples.cmake index 83d0e988..0a651051 100644 --- a/cmake/examples.cmake +++ b/cmake/examples.cmake @@ -37,7 +37,7 @@ mark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST) if(protobuf_BUILD_EXAMPLES_MULTITEST)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
- #Build using the legacy compatiblity module.
+ #Build using the legacy compatibility module.
add_examples_build(examples-legacy
"-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}"
"-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
@@ -49,7 +49,7 @@ if(protobuf_BUILD_EXAMPLES_MULTITEST) "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
)
- #Build using the installed library in legacy compatiblity mode.
+ #Build using the installed library in legacy compatibility mode.
add_examples_build(examples-installed-legacy
"-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
"-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
diff --git a/conformance/ConformanceJavaLite.java b/conformance/ConformanceJavaLite.java index 121dc7d1..016f7932 100644 --- a/conformance/ConformanceJavaLite.java +++ b/conformance/ConformanceJavaLite.java @@ -58,7 +58,7 @@ class ConformanceJavaLite { } case JSON_PAYLOAD: { return Conformance.ConformanceResponse.newBuilder().setSkipped( - "Lite runtime does not suport Json Formant.").build(); + "Lite runtime does not support JSON format.").build(); } case PAYLOAD_NOT_SET: { throw new RuntimeException("Request didn't have payload."); @@ -78,7 +78,7 @@ class ConformanceJavaLite { case JSON: return Conformance.ConformanceResponse.newBuilder().setSkipped( - "Lite runtime does not suport Json Formant.").build(); + "Lite runtime does not support JSON format.").build(); default: { throw new RuntimeException("Unexpected request output."); diff --git a/java/README.md b/java/README.md index 83f91e18..0e0fba64 100644 --- a/java/README.md +++ b/java/README.md @@ -88,7 +88,7 @@ Compatibility Notice * Protobuf minor version releases are backwards-compatible. If your code can build/run against the old version, it's expected to build/run against - the new version as well. Both binary compatibility and source compatbility + the new version as well. Both binary compatibility and source compatibility are guaranteed for minor version releases if the user follows the guideline described in this section. @@ -98,7 +98,7 @@ Compatibility Notice * APIs marked with the @ExperimentalApi annotation are subject to change. They can be modified in any way, or even removed, at any time. Don't use them if - compatiblity is needed. If your code is a library itself (i.e. it is used on + compatibility is needed. If your code is a library itself (i.e. it is used on the CLASSPATH of users outside your own control), you should not use experimental APIs, unless you repackage them (e.g. using ProGuard). diff --git a/java/compatibility_tests/README.md b/java/compatibility_tests/README.md index 2465941e..72c6034c 100644 --- a/java/compatibility_tests/README.md +++ b/java/compatibility_tests/README.md @@ -5,7 +5,7 @@ previously released versions. ## Directory Layout -For each released protobuf version we are testing compatiblity with, there +For each released protobuf version we are testing compatibility with, there is a sub-directory with the following layout (take v2.5.0 as an example): * v2.5.0 @@ -47,4 +47,4 @@ For each version, the test script will test: * only upgrading more_protos to the new version and see whether everything builds/runs fine. Both source compatibility and -binary compatiblity will be tested. +binary compatibility will be tested. diff --git a/java/compatibility_tests/v2.5.0/test.sh b/java/compatibility_tests/v2.5.0/test.sh index 05503bb1..b7922b1a 100755 --- a/java/compatibility_tests/v2.5.0/test.sh +++ b/java/compatibility_tests/v2.5.0/test.sh @@ -11,7 +11,7 @@ TEST_VERSION=`grep "^ <version>.*</version>" pom.xml | sed "s| <version>\(.*\) # The old version of protobuf that we are testing compatibility against. This # is usually the same as TEST_VERSION (i.e., we use the tests extracted from -# that version to test compatibilty of the newest runtime against it), but it +# that version to test compatibility of the newest runtime against it), but it # is also possible to use this same test set to test the compatibiilty of the # latest version against other versions. case "$1" in @@ -40,7 +40,7 @@ esac # Extract the latest protobuf version number. VERSION_NUMBER=`grep "^ <version>.*</version>" ../../pom.xml | sed "s| <version>\(.*\)</version>|\1|"` -echo "Running compatibilty tests between $VERSION_NUMBER and $OLD_VERSION" +echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION" # Check protoc [ -f ../../../src/protoc ] || { @@ -55,7 +55,7 @@ echo "Running compatibilty tests between $VERSION_NUMBER and $OLD_VERSION" popd } -# Download old version source for the compatiblity test +# Download old version source for the compatibility test [ -d protobuf ] || { git clone https://github.com/google/protobuf.git cd protobuf @@ -92,7 +92,7 @@ mvn clean test \ # jar against the new runtime directly without recompile. # Collect all test dependencies in a single jar file (except for protobuf) to -# make it easier to run binary compatibilty test (where we will need to run +# make it easier to run binary compatibility test (where we will need to run # the jar files directly). cd deps mvn assembly:single diff --git a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java index b8fdb2b2..46ddbf48 100644 --- a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java @@ -498,7 +498,7 @@ public abstract class AbstractMessage * override this method. */ void markClean() { - throw new IllegalStateException("Should be overriden by subclasses."); + throw new IllegalStateException("Should be overridden by subclasses."); } /** @@ -510,7 +510,7 @@ public abstract class AbstractMessage * override this method. */ void dispose() { - throw new IllegalStateException("Should be overriden by subclasses."); + throw new IllegalStateException("Should be overridden by subclasses."); } // =============================================================== @@ -605,7 +605,7 @@ public abstract class AbstractMessage } /** - * @deprecated from v3.0.0-beta-3+, for compatiblity with v2.5.0 and v2.6.1 + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 * generated code. */ @Deprecated @@ -614,7 +614,7 @@ public abstract class AbstractMessage } // /** - * @deprecated from v3.0.0-beta-3+, for compatiblity with v2.5.0 and v2.6.1 + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 * generated code. */ @Deprecated @@ -623,7 +623,7 @@ public abstract class AbstractMessage } // /** - * @deprecated from v3.0.0-beta-3+, for compatiblity with v2.5.0 and v2.6.1 + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 * generated code. */ @Deprecated @@ -632,7 +632,7 @@ public abstract class AbstractMessage } // /** - * @deprecated from v3.0.0-beta-3+, for compatiblity with v2.5.0 and v2.6.1 + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 * generated code. */ @Deprecated diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 62c94508..49653899 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -87,17 +87,17 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { * Empty {@code ByteString}. */ public static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY); - - /** + + /** * An interface to efficiently copy {@code byte[]}. - * - * <p>One of the noticable costs of copying a byte[] into a new array using - * {@code System.arraycopy} is nullification of a new buffer before the copy. It has been shown + * + * <p>One of the noticeable costs of copying a byte[] into a new array using + * {@code System.arraycopy} is nullification of a new buffer before the copy. It has been shown * the Hotspot VM is capable to intrisicfy {@code Arrays.copyOfRange} operation to avoid this * expensive nullification and provide substantial performance gain. Unfortunately this does not * hold on Android runtimes and could make the copy slightly slower due to additional code in * the {@code Arrays.copyOfRange}. Thus we provide two different implementation for array copier - * for Hotspot and Android runtimes. + * for Hotspot and Android runtimes. */ private interface ByteArrayCopier { /** @@ -105,7 +105,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { */ byte[] copyFrom(byte[] bytes, int offset, int size); } - + /** Implementation of {@code ByteArrayCopier} which uses {@link System#arraycopy}. */ private static final class SystemByteArrayCopier implements ByteArrayCopier { @Override @@ -115,7 +115,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { return copy; } } - + /** Implementation of {@code ByteArrayCopier} which uses {@link Arrays#copyOfRange}. */ private static final class ArraysByteArrayCopier implements ByteArrayCopier { @Override @@ -123,7 +123,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { return Arrays.copyOfRange(bytes, offset, offset + size); } } - + private static final ByteArrayCopier byteArrayCopier; static { boolean isAndroid = true; @@ -132,7 +132,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { } catch (ClassNotFoundException e) { isAndroid = false; } - + byteArrayCopier = isAndroid ? new SystemByteArrayCopier() : new ArraysByteArrayCopier(); } @@ -309,7 +309,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { public static ByteString copyFrom(byte[] bytes) { return copyFrom(bytes, 0, bytes.length); } - + /** * Wraps the given bytes into a {@code ByteString}. Intended for internal only * usage to force a classload of ByteString before LiteralByteString. @@ -402,7 +402,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { * immutable tree of byte arrays ("chunks") of the stream data. The * first chunk is small, with subsequent chunks each being double * the size, up to 8K. - * + * * <p>Each byte read from the input stream will be copied twice to ensure * that the resulting ByteString is truly immutable. * @@ -1226,7 +1226,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { return String.format("<ByteString@%s size=%d>", Integer.toHexString(System.identityHashCode(this)), size()); } - + /** * This class implements a {@link com.google.protobuf.ByteString} backed by a * single array of bytes, contiguous in memory. It supports substring by @@ -1450,7 +1450,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { return 0; } } - + /** * This class is used to represent the substring of a {@link ByteString} over a * single byte array. In terms of the public API of {@link ByteString}, you end diff --git a/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java b/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java index 29e8d875..4764ca1b 100644 --- a/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java @@ -55,7 +55,7 @@ public class LiteEqualsAndHashTest extends TestCase { // correctly when linked only against the lite library. // We do however do some basic testing to make sure that equals is actually - // overriden to test for value equality rather than simple object equality. + // overridden to test for value equality rather than simple object equality. // Check that two identical objs are equal. Foo foo1a = Foo.newBuilder() diff --git a/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java b/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java index d9500bb9..5f329f02 100644 --- a/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java +++ b/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java @@ -156,7 +156,7 @@ public final class MessageNanoPrinter { } catch (NoSuchMethodException e) { continue; } - // If hazzer does't exist or returns false, no need to continue + // If hazzer doesn't exist or returns false, no need to continue if (!(Boolean) hazzer.invoke(object)) { continue; } diff --git a/js/map.js b/js/map.js new file mode 100644 index 00000000..821765ec --- /dev/null +++ b/js/map.js @@ -0,0 +1,482 @@ +// 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. + +goog.provide('jspb.Map'); + +goog.require('goog.asserts'); + +goog.forwardDeclare('jspb.BinaryReader'); +goog.forwardDeclare('jspb.BinaryWriter'); + + + +/** + * Constructs a new Map. A Map is a container that is used to implement map + * fields on message objects. It closely follows the ES6 Map API; however, + * it is distinct because we do not want to depend on external polyfills or + * on ES6 itself. + * + * This constructor should only be called from generated message code. It is not + * intended for general use by library consumers. The callback function + * arguments are references to methods in `BinaryReader` and `BinaryWriter`, as + * well as constructors and reader/writer methods in submessage types if + * appropriate, that are used for binary serialization and parsing. + * + * @template K, V + * + * @param {!Array<!Array<!Object>>} arr + * + * @param {function(this:jspb.BinaryWriter,number,K)=} opt_keyWriterFn + * The method on BinaryWriter that writes type K to the stream. + * + * @param {function(this:jspb.BinaryReader):K=} opt_keyReaderFn + * The method on BinaryReader that reads type K from the stream. + * + * @param {function(this:jspb.BinaryWriter,number,V)| + * function(this:jspb.BinaryReader,V,?)=} opt_valueWriterFn + * The method on BinaryWriter that writes type V to the stream. May be + * writeMessage, in which case the second callback arg form is used. + * + * @param {function(this:jspb.BinaryReader):V| + * function(this:jspb.BinaryReader,V, + * function(V,!jspb.BinaryReader))=} opt_valueReaderFn + * The method on BinaryReader that reads type V from the stream. May be + * readMessage, in which case the second callback arg form is used. + * + * @param {?function(new:V)|function(new:V,?)=} opt_valueCtor + * The constructor for type V, if type V is a message type. + * + * @param {?function(V,!jspb.BinaryWriter)=} opt_valueWriterCallback + * The BinaryWriter serialization callback for type V, if V is a message + * type. + * + * @param {?function(V,!jspb.BinaryReader)=} opt_valueReaderCallback + * The BinaryReader parsing callback for type V, if V is a message type. + * + * @constructor + * @struct + */ +jspb.Map = function( + arr, opt_keyWriterFn, opt_keyReaderFn, opt_valueWriterFn, opt_valueReaderFn, + opt_valueCtor, opt_valueWriterCallback, opt_valueReaderCallback) { + + /** @const @private */ + this.arr_ = arr; + /** @const @private */ + this.keyWriterFn_ = opt_keyWriterFn; + /** @const @private */ + this.keyReaderFn_ = opt_keyReaderFn; + /** @const @private */ + this.valueWriterFn_ = opt_valueWriterFn; + /** @const @private */ + this.valueReaderFn_ = opt_valueReaderFn; + /** @const @private */ + this.valueCtor_ = opt_valueCtor; + /** @const @private */ + this.valueWriterCallback_ = opt_valueWriterCallback; + /** @const @private */ + this.valueReaderCallback_ = opt_valueReaderCallback; + + /** @type {!Object<string, !jspb.Map.Entry_<K,V>>} @private */ + this.map_ = {}; + + /** + * Is `this.arr_ updated with respect to `this.map_`? + * @type {boolean} + */ + this.arrClean = true; + + if (this.arr_.length > 0) { + this.loadFromArray_(); + } +}; + + +/** + * Load initial content from underlying array. + * @private + */ +jspb.Map.prototype.loadFromArray_ = function() { + for (var i = 0; i < this.arr_.length; i++) { + var record = this.arr_[i]; + var key = record[0]; + var value = record[1]; + this.map_[key.toString()] = new jspb.Map.Entry_(key, value); + } + this.arrClean = true; +}; + + +/** + * Synchronize content to underlying array, if needed, and return it. + * @return {!Array<!Array<!Object>>} + */ +jspb.Map.prototype.toArray = function() { + if (this.arrClean) { + if (this.valueCtor_) { + // We need to recursively sync maps in submessages to their arrays. + var m = this.map_; + for (var p in m) { + if (Object.prototype.hasOwnProperty.call(m, p)) { + m[p].valueWrapper.toArray(); + } + } + } + } else { + // Delete all elements. + this.arr_.length = 0; + var strKeys = this.stringKeys_(); + // Output keys in deterministic (sorted) order. + strKeys.sort(); + for (var i = 0; i < strKeys.length; i++) { + var entry = this.map_[strKeys[i]]; + var valueWrapper = /** @type {!Object} */ (entry.valueWrapper); + if (valueWrapper) { + valueWrapper.toArray(); + } + this.arr_.push([entry.key, entry.value]); + } + this.arrClean = true; + } + return this.arr_; +}; + + +/** + * Helper: return an iterator over an array. + * @template T + * @param {!Array<T>} arr the array + * @return {!Iterator<T>} an iterator + * @private + */ +jspb.Map.arrayIterator_ = function(arr) { + var idx = 0; + return /** @type {!Iterator} */ ({ + next: function() { + if (idx < arr.length) { + return { done: false, value: arr[idx++] }; + } else { + return { done: true }; + } + } + }); +}; + + +/** + * Returns the map's length (number of key/value pairs). + * @return {number} + */ +jspb.Map.prototype.getLength = function() { + return this.stringKeys_().length; +}; + + +/** + * Clears the map. + */ +jspb.Map.prototype.clear = function() { + this.map_ = {}; + this.arrClean = false; +}; + + +/** + * Deletes a particular key from the map. + * N.B.: differs in name from ES6 Map's `delete` because IE8 does not support + * reserved words as property names. + * @this {jspb.Map} + * @param {K} key + * @return {boolean} Whether any entry with this key was deleted. + */ +jspb.Map.prototype.del = function(key) { + var keyValue = key.toString(); + var hadKey = this.map_.hasOwnProperty(keyValue); + delete this.map_[keyValue]; + this.arrClean = false; + return hadKey; +}; + + +/** + * Returns an array of [key, value] pairs in the map. + * + * This is redundant compared to the plain entries() method, but we provide this + * to help out Angular 1.x users. Still evaluating whether this is the best + * option. + * + * @return {!Array<K|V>} + */ +jspb.Map.prototype.getEntryList = function() { + var entries = []; + var strKeys = this.stringKeys_(); + strKeys.sort(); + for (var i = 0; i < strKeys.length; i++) { + var entry = this.map_[strKeys[i]]; + entries.push([entry.key, entry.value]); + } + return entries; +}; + + +/** + * Returns an iterator over [key, value] pairs in the map. + * Closure compiler sadly doesn't support tuples, ie. Iterator<[K,V]>. + * @return {!Iterator<!Array<K|V>>} + * The iterator + */ +jspb.Map.prototype.entries = function() { + var entries = []; + var strKeys = this.stringKeys_(); + strKeys.sort(); + for (var i = 0; i < strKeys.length; i++) { + var entry = this.map_[strKeys[i]]; + entries.push([entry.key, this.wrapEntry_(entry)]); + } + return jspb.Map.arrayIterator_(entries); +}; + + +/** + * Returns an iterator over keys in the map. + * @return {!Iterator<K>} The iterator + */ +jspb.Map.prototype.keys = function() { + var keys = []; + var strKeys = this.stringKeys_(); + strKeys.sort(); + for (var i = 0; i < strKeys.length; i++) { + var entry = this.map_[strKeys[i]]; + keys.push(entry.key); + } + return jspb.Map.arrayIterator_(keys); +}; + + +/** + * Returns an iterator over values in the map. + * @return {!Iterator<V>} The iterator + */ +jspb.Map.prototype.values = function() { + var values = []; + var strKeys = this.stringKeys_(); + strKeys.sort(); + for (var i = 0; i < strKeys.length; i++) { + var entry = this.map_[strKeys[i]]; + values.push(this.wrapEntry_(entry)); + } + return jspb.Map.arrayIterator_(values); +}; + + +/** + * Iterates over entries in the map, calling a function on each. + * @template T + * @param {function(this:T, V, K, ?jspb.Map<K, V>)} cb + * @param {T=} opt_thisArg + */ +jspb.Map.prototype.forEach = function(cb, opt_thisArg) { + var strKeys = this.stringKeys_(); + strKeys.sort(); + for (var i = 0; i < strKeys.length; i++) { + var entry = this.map_[strKeys[i]]; + cb.call(opt_thisArg, this.wrapEntry_(entry), entry.key, this); + } +}; + + +/** + * Sets a key in the map to the given value. + * @param {K} key The key + * @param {V} value The value + * @return {!jspb.Map<K,V>} + */ +jspb.Map.prototype.set = function(key, value) { + var entry = new jspb.Map.Entry_(key); + if (this.valueCtor_) { + entry.valueWrapper = value; + // .toArray() on a message returns a reference to the underlying array + // rather than a copy. + entry.value = value.toArray(); + } else { + entry.value = value; + } + this.map_[key.toString()] = entry; + this.arrClean = false; + return this; +}; + + +/** + * Helper: lazily construct a wrapper around an entry, if needed, and return the + * user-visible type. + * @param {!jspb.Map.Entry_<K,V>} entry + * @return {V} + * @private + */ +jspb.Map.prototype.wrapEntry_ = function(entry) { + if (this.valueCtor_) { + if (!entry.valueWrapper) { + entry.valueWrapper = new this.valueCtor_(entry.value); + } + return /** @type {V} */ (entry.valueWrapper); + } else { + return entry.value; + } +}; + + +/** + * Gets the value corresponding to a key in the map. + * @param {K} key + * @return {V|undefined} The value, or `undefined` if key not present + */ +jspb.Map.prototype.get = function(key) { + var keyValue = key.toString(); + var entry = this.map_[keyValue]; + if (entry) { + return this.wrapEntry_(entry); + } else { + return undefined; + } +}; + + +/** + * Determines whether the given key is present in the map. + * @param {K} key + * @return {boolean} `true` if the key is present + */ +jspb.Map.prototype.has = function(key) { + var keyValue = key.toString(); + return (keyValue in this.map_); +}; + + +/** + * Write this Map field in wire format to a BinaryWriter, using the given field + * number. + * @param {number} fieldNumber + * @param {!jspb.BinaryWriter} writer + */ +jspb.Map.prototype.serializeBinary = function(fieldNumber, writer) { + var strKeys = this.stringKeys_(); + strKeys.sort(); + for (var i = 0; i < strKeys.length; i++) { + var entry = this.map_[strKeys[i]]; + writer.beginSubMessage(fieldNumber); + this.keyWriterFn_.call(writer, 1, entry.key); + if (this.valueCtor_) { + this.valueWriterFn_.call(writer, 2, this.wrapEntry_(entry), + this.valueWriterCallback_); + } else { + this.valueWriterFn_.call(writer, 2, entry.value); + } + writer.endSubMessage(); + } +}; + + +/** + * Read one key/value message from the given BinaryReader. Compatible as the + * `reader` callback parameter to jspb.BinaryReader.readMessage, to be called + * when a key/value pair submessage is encountered. + * @param {!jspb.Map} map + * @param {!jspb.BinaryReader} reader + */ +jspb.Map.deserializeBinary = function(map, reader) { + var key = undefined; + var value = undefined; + + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + if (field == 1) { + // Key. + key = map.keyReaderFn_.call(reader); + } else if (field == 2) { + // Value. + if (map.valueCtor_) { + value = new map.valueCtor_(); + map.valueReaderFn_.call(reader, value, map.valueReaderCallback_); + } else { + value = map.valueReaderFn_.call(reader); + } + } + } + + goog.asserts.assert(key != undefined); + goog.asserts.assert(value != undefined); + map.set(key, value); +}; + + +/** + * Helper: compute the list of all stringified keys in the underlying Object + * map. + * @return {!Array<string>} + * @private + */ +jspb.Map.prototype.stringKeys_ = function() { + var m = this.map_; + var ret = []; + for (var p in m) { + if (Object.prototype.hasOwnProperty.call(m, p)) { + ret.push(p); + } + } + return ret; +}; + + + +/** + * @param {!K} key The entry's key. + * @param {V=} opt_value The entry's value wrapper. + * @constructor + * @struct + * @template K, V + * @private + */ +jspb.Map.Entry_ = function(key, opt_value) { + /** @const {K} */ + this.key = key; + + // The JSPB-serializable value. For primitive types this will be of type V. + // For message types it will be an array. + /** @type {V} */ + this.value = opt_value; + + // Only used for submessage values. + /** @type {V} */ + this.valueWrapper = undefined; +}; diff --git a/js/test.proto b/js/test.proto index 06eb79af..cf2eafef 100644 --- a/js/test.proto +++ b/js/test.proto @@ -229,3 +229,7 @@ message TestMessageWithOneof { } } +message TestEndsWithBytes { + optional int32 value = 1; + optional bytes data = 2; +} diff --git a/js/testbinary.proto b/js/testbinary.proto index a3fcb5f1..116f17fb 100644 --- a/js/testbinary.proto +++ b/js/testbinary.proto @@ -185,8 +185,6 @@ extend TestExtendable { } message TestMapFields { - option (jspb.generate_from_object) = true; - map<string, string> map_string_string = 1; map<string, int32> map_string_int32 = 2; map<string, int64> map_string_int64 = 3; diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h index b3b07793..9608cdb0 100644 --- a/objectivec/GPBMessage.h +++ b/objectivec/GPBMessage.h @@ -97,7 +97,7 @@ CF_EXTERN_C_END /// the data can not be parsed. /// /// @return A new instance of the class messaged. -+ (instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr; ++ (nullable instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr; /// Creates a new instance by parsing the data. This method should be sent to /// the generated message class that the data should be interpreted as. If @@ -116,9 +116,9 @@ CF_EXTERN_C_END /// reason if the data can not be parsed. /// /// @return A new instance of the class messaged. -+ (instancetype)parseFromData:(NSData *)data - extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry - error:(NSError **)errorPtr; ++ (nullable instancetype)parseFromData:(NSData *)data + extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry + error:(NSError **)errorPtr; /// Creates a new instance by parsing the data from the given input stream. This /// method should be sent to the generated message class that the data should @@ -137,10 +137,10 @@ CF_EXTERN_C_END /// reason if the data can not be parsed. /// /// @return A new instance of the class messaged. -+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry: - (nullable GPBExtensionRegistry *)extensionRegistry - error:(NSError **)errorPtr; ++ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input + extensionRegistry: + (nullable GPBExtensionRegistry *)extensionRegistry + error:(NSError **)errorPtr; /// Creates a new instance by parsing the data from the given input stream. This /// method should be sent to the generated message class that the data should @@ -160,10 +160,10 @@ CF_EXTERN_C_END /// reason if the data can not be parsed. /// /// @return A new instance of the class messaged. -+ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry: - (nullable GPBExtensionRegistry *)extensionRegistry - error:(NSError **)errorPtr; ++ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input + extensionRegistry: + (nullable GPBExtensionRegistry *)extensionRegistry + error:(NSError **)errorPtr; /// Initializes an instance by parsing the data. This method should be sent to /// the generated message class that the data should be interpreted as. If @@ -179,7 +179,7 @@ CF_EXTERN_C_END /// @param data The data to parse. /// @param errorPtr An optional error pointer to fill in with a failure reason if /// the data can not be parsed. -- (instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr; +- (nullable instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr; /// Initializes an instance by parsing the data. This method should be sent to /// the generated message class that the data should be interpreted as. If @@ -196,9 +196,9 @@ CF_EXTERN_C_END /// @param extensionRegistry The extension registry to use to look up extensions. /// @param errorPtr An optional error pointer to fill in with a failure /// reason if the data can not be parsed. -- (instancetype)initWithData:(NSData *)data - extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry - error:(NSError **)errorPtr; +- (nullable instancetype)initWithData:(NSData *)data + extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry + error:(NSError **)errorPtr; /// Initializes an instance by parsing the data from the given input stream. This /// method should be sent to the generated message class that the data should @@ -216,10 +216,10 @@ CF_EXTERN_C_END /// @param extensionRegistry The extension registry to use to look up extensions. /// @param errorPtr An optional error pointer to fill in with a failure /// reason if the data can not be parsed. -- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry: - (nullable GPBExtensionRegistry *)extensionRegistry - error:(NSError **)errorPtr; +- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input + extensionRegistry: + (nullable GPBExtensionRegistry *)extensionRegistry + error:(NSError **)errorPtr; /// Writes out the message to the given output stream. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output; diff --git a/objectivec/Tests/GPBSwiftTests.swift b/objectivec/Tests/GPBSwiftTests.swift index 474fde38..b5999c21 100644 --- a/objectivec/Tests/GPBSwiftTests.swift +++ b/objectivec/Tests/GPBSwiftTests.swift @@ -446,7 +446,7 @@ class GPBBridgeTests: XCTestCase { let data = msg.data() - let msg2 = Message2(data: data!, error:nil) + let msg2 = try! Message2(data: data!) XCTAssertTrue(msg2 !== msg) // New instance XCTAssertEqual(msg.optionalInt32, Int32(100)) XCTAssertEqual(msg.optionalInt64, Int64(101)) diff --git a/php/ext/google/protobuf/upb.h b/php/ext/google/protobuf/upb.h index 078e2a28..073faf41 100644 --- a/php/ext/google/protobuf/upb.h +++ b/php/ext/google/protobuf/upb.h @@ -54,7 +54,7 @@ ** store pointers or integers of at least 32 bits (upb isn't really useful on ** systems where sizeof(void*) < 4). ** -** The table must be homogenous (all values of the same type). In debug +** The table must be homogeneous (all values of the same type). In debug ** mode, we check this on insert and lookup. */ diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 2eba1232..873af306 100755 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -349,7 +349,7 @@ class Descriptor(_NestedDescriptorBase): Args: proto: An empty descriptor_pb2.DescriptorProto. """ - # This function is overriden to give a better doc comment. + # This function is overridden to give a better doc comment. super(Descriptor, self).CopyToProto(proto) @@ -626,7 +626,7 @@ class EnumDescriptor(_NestedDescriptorBase): Args: proto: An empty descriptor_pb2.EnumDescriptorProto. """ - # This function is overriden to give a better doc comment. + # This function is overridden to give a better doc comment. super(EnumDescriptor, self).CopyToProto(proto) @@ -747,7 +747,7 @@ class ServiceDescriptor(_NestedDescriptorBase): Args: proto: An empty descriptor_pb2.ServiceDescriptorProto. """ - # This function is overriden to give a better doc comment. + # This function is overridden to give a better doc comment. super(ServiceDescriptor, self).CopyToProto(proto) diff --git a/python/google/protobuf/internal/_parameterized.py b/python/google/protobuf/internal/_parameterized.py index dea3f199..23a78f03 100755 --- a/python/google/protobuf/internal/_parameterized.py +++ b/python/google/protobuf/internal/_parameterized.py @@ -347,7 +347,7 @@ class TestGeneratorMetaclass(type): iterable conforms to the test pattern, the injected methods will be picked up as tests by the unittest framework. - In general, it is supposed to be used in conjuction with the + In general, it is supposed to be used in conjunction with the Parameters decorator. """ diff --git a/ruby/ext/google/protobuf_c/upb.h b/ruby/ext/google/protobuf_c/upb.h index 2faf74e5..e8b683bd 100644 --- a/ruby/ext/google/protobuf_c/upb.h +++ b/ruby/ext/google/protobuf_c/upb.h @@ -55,7 +55,7 @@ ** store pointers or integers of at least 32 bits (upb isn't really useful on ** systems where sizeof(void*) < 4). ** -** The table must be homogenous (all values of the same type). In debug +** The table must be homogeneous (all values of the same type). In debug ** mode, we check this on insert and lookup. */ diff --git a/ruby/lib/google/protobuf/repeated_field.rb b/ruby/lib/google/protobuf/repeated_field.rb index 0ad2060d..831e0320 100644 --- a/ruby/lib/google/protobuf/repeated_field.rb +++ b/ruby/lib/google/protobuf/repeated_field.rb @@ -173,7 +173,7 @@ module Google external_enumerator.each_with_index do |val, i| result = yield(val) results << result - #nil means no change occured from yield; usually occurs when #to_a is called + #nil means no change occurred from yield; usually occurs when #to_a is called if result repeated_field[i] = result if result != val end diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index df6f8afc..bb781b0a 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -50,9 +50,7 @@ #include <iostream> #include <ctype.h> -#ifdef GOOGLE_PROTOBUF_ARCH_SPARC #include <limits.h> //For PATH_MAX -#endif #include <memory> #ifndef _SHARED_PTR_H @@ -614,7 +612,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { } else { // This was an OpenForInsert(). - // If the data doens't end with a clean line break, add one. + // If the data doesn't end with a clean line break, add one. if (!data_.empty() && data_[data_.size() - 1] != '\n') { data_.push_back('\n'); } diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h index 31223e13..b1e3fe21 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/src/google/protobuf/compiler/cpp/cpp_message.h @@ -66,7 +66,7 @@ class MessageGenerator { // Header stuff. - // Return names for foward declarations of this class and all its nested + // Return names for forward declarations of this class and all its nested // types. A given key in {class,enum}_names will map from a class name to the // descriptor that was responsible for its inclusion in the map. This can be // used to associate the descriptor with the code generated for it. diff --git a/src/google/protobuf/compiler/java/java_helpers.h b/src/google/protobuf/compiler/java/java_helpers.h index 5316d2f9..829ec3d7 100644 --- a/src/google/protobuf/compiler/java/java_helpers.h +++ b/src/google/protobuf/compiler/java/java_helpers.h @@ -243,7 +243,7 @@ inline bool HasGenericServices(const FileDescriptor *file, bool enforce_lite) { } inline bool IsLazy(const FieldDescriptor* descriptor, bool enforce_lite) { - // Currently, the proto-lite version suports lazy field. + // Currently, the proto-lite version supports lazy field. // TODO(niwasaki): Support lazy fields also for other proto runtimes. if (HasDescriptorMethods(descriptor->file(), enforce_lite)) { return false; diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index b74c7447..e1e5496a 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -715,7 +715,7 @@ GenerateInterfaceMembers(io::Printer* printer) const { // NOTE: the same method in the implementation class actually returns // com.google.protobuf.ProtocolStringList (a subclass of List). It's // changed between protobuf 2.5.0 release and protobuf 2.6.1 release. - // To retain binary compatibilty with both 2.5.0 and 2.6.1 generated + // To retain binary compatibility with both 2.5.0 and 2.6.1 generated // code, we make this interface method return List so both methods // with different return types exist in the compiled byte code. "$deprecation$java.util.List<java.lang.String>\n" diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index f5185ab1..8a2633d7 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -151,7 +151,7 @@ string StripProto(const string& filename) { return StripSuffixString(filename, suffix); } -// Given a filename like foo/bar/baz.proto, returns the correspoding JavaScript +// Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript // file foo/bar/baz.js. string GetJSFilename(const string& filename) { return StripProto(filename) + "_pb.js"; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index 66cb4a16..812b4a1c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -228,7 +228,7 @@ int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const { void FieldGenerator::SetExtraRuntimeHasBitsBase(int index_base) { // 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. - cerr << "Error: should have overriden SetExtraRuntimeHasBitsBase()." << endl; + cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." << endl; cerr.flush(); abort(); } diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index 2c561c23..0f80e78b 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -71,7 +71,7 @@ class LIBPROTOBUF_EXPORT Parser { // it. Returns true if no errors occurred, false otherwise. bool Parse(io::Tokenizer* input, FileDescriptorProto* file); - // Optional fetaures: + // Optional features: // DEPRECATED: New code should use the SourceCodeInfo embedded in the // FileDescriptorProto. diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 347bac5a..d1f7b5ca 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -2126,7 +2126,7 @@ inline void GeneratedMessageReflection::ClearOneofField( inline void GeneratedMessageReflection::ClearOneof( Message* message, const OneofDescriptor* oneof_descriptor) const { // TODO(jieluo): Consider to cache the unused object instead of deleting - // it. It will be much faster if an aplication switches a lot from + // it. It will be much faster if an application switches a lot from // a few oneof fields. Time/space tradeoff uint32 oneof_case = GetOneofCase(*message, oneof_descriptor); if (oneof_case > 0) { diff --git a/src/google/protobuf/io/tokenizer.h b/src/google/protobuf/io/tokenizer.h index 64ee7d84..77a873bc 100644 --- a/src/google/protobuf/io/tokenizer.h +++ b/src/google/protobuf/io/tokenizer.h @@ -329,7 +329,7 @@ class LIBPROTOBUF_EXPORT Tokenizer { // depending on what was read. This needs to know if the first // character was a zero in order to correctly recognize hex and octal // numbers. - // It also needs to know if the first characted was a . to parse floating + // It also needs to know if the first character was a . to parse floating // point correctly. TokenType ConsumeNumber(bool started_with_zero, bool started_with_dot); diff --git a/src/google/protobuf/map_entry.h b/src/google/protobuf/map_entry.h index 801e7522..e87eda64 100644 --- a/src/google/protobuf/map_entry.h +++ b/src/google/protobuf/map_entry.h @@ -83,7 +83,7 @@ class LIBPROTOBUF_EXPORT MapEntryBase : public Message { // reflection, its in-memory type is the same as generated message with the same // fields. However, in order to decide the in-memory type of key/value, we need // to know both their cpp type in generated api and proto type. In -// implmentation, all in-memory types have related wire format functions to +// implementation, all in-memory types have related wire format functions to // support except ArenaStringPtr. Therefore, we need to define another type with // supporting wire format functions. Since this type is only used as return type // of MapEntry accessors, it's named MapEntry accessor type. diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index 4b46f3aa..d6af8532 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -54,7 +54,7 @@ class ContendedMapCleanTest; class GeneratedMessageReflection; class MapFieldAccessor; -// This class provides accesss to map field using reflection, which is the same +// This class provides access to map field using reflection, which is the same // as those provided for RepeatedPtrField<Message>. It is used for internal // reflection implentation only. Users should never use this directly. class LIBPROTOBUF_EXPORT MapFieldBase { @@ -208,7 +208,7 @@ class TypeDefinedMapFieldBase : public MapFieldBase { virtual void SetMapIteratorValue(MapIterator* map_iter) const = 0; }; -// This class provides accesss to map field using generated api. It is used for +// This class provides access to map field using generated api. It is used for // internal generated message implentation only. Users should never use this // directly. template <typename Key, typename T, diff --git a/src/google/protobuf/map_field_lite.h b/src/google/protobuf/map_field_lite.h index 860dae55..a9f30f59 100644 --- a/src/google/protobuf/map_field_lite.h +++ b/src/google/protobuf/map_field_lite.h @@ -38,7 +38,7 @@ namespace google { namespace protobuf { namespace internal { -// This class provides accesss to map field using generated api. It is used for +// This class provides access to map field using generated api. It is used for // internal generated message implentation only. Users should never use this // directly. template <typename Key, typename T, diff --git a/src/google/protobuf/map_lite_unittest.proto b/src/google/protobuf/map_lite_unittest.proto index 0592dd7a..0135fff3 100644 --- a/src/google/protobuf/map_lite_unittest.proto +++ b/src/google/protobuf/map_lite_unittest.proto @@ -81,7 +81,7 @@ message TestArenaMapLite { map_int32_foreign_message_no_arena = 18; } -// Test embeded message with required fields +// Test embedded message with required fields message TestRequiredMessageMapLite { map<int32, TestRequiredLite> map_field = 1; } diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index dccb31ca..cdd1ccd5 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -502,7 +502,7 @@ static void StressTestIterators(int n, bool test_old_style_proto2_maps) { // Test old iterator vs new iterator, with table modification in between. TestOldVersusNewIterator<Map<int, int>::const_iterator>(n % 3, &m); TestOldVersusNewIterator<Map<int, int>::iterator>(n % (1 + (n / 40)), &m); - // Finally, ensure erase(iterator) doesn't reorder anything, becuase that is + // Finally, ensure erase(iterator) doesn't reorder anything, because that is // what its documentation says. m[last_key] = m[last_key ^ 999] = 0; vector<Map<int, int>::iterator> v; diff --git a/src/google/protobuf/map_unittest.proto b/src/google/protobuf/map_unittest.proto index aea1e8ce..c6154f04 100644 --- a/src/google/protobuf/map_unittest.proto +++ b/src/google/protobuf/map_unittest.proto @@ -83,7 +83,7 @@ enum MapEnum { MAP_ENUM_BAZ = 2; } -// Test embeded message with required fields +// Test embedded message with required fields message TestRequiredMessageMap { map<int32, TestRequired> map_field = 1; } diff --git a/src/google/protobuf/reflection.h b/src/google/protobuf/reflection.h index 671aafdc..2391f453 100755 --- a/src/google/protobuf/reflection.h +++ b/src/google/protobuf/reflection.h @@ -356,7 +356,7 @@ class LIBPROTOBUF_EXPORT RepeatedFieldAccessor { virtual void Swap(Field* data, const RepeatedFieldAccessor* other_mutator, Field* other_data) const = 0; - // Create an iterator that points at the begining of the repeated field. + // Create an iterator that points at the beginning of the repeated field. virtual Iterator* BeginIterator(const Field* data) const = 0; // Create an iterator that points at the end of the repeated field. virtual Iterator* EndIterator(const Field* data) const = 0; diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 38358dbb..bc567555 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -2363,7 +2363,7 @@ template<typename T> class RepeatedPtrFieldBackInsertIterator RepeatedPtrField<T>* field_; }; -// A back inserter for RepeatedPtrFields that inserts by transfering ownership +// A back inserter for RepeatedPtrFields that inserts by transferring ownership // of a pointer. template<typename T> class AllocatedRepeatedPtrFieldBackInsertIterator : public std::iterator<std::output_iterator_tag, T> { diff --git a/src/google/protobuf/repeated_field_reflection.h b/src/google/protobuf/repeated_field_reflection.h index 44d14d5b..512c0f1d 100644 --- a/src/google/protobuf/repeated_field_reflection.h +++ b/src/google/protobuf/repeated_field_reflection.h @@ -94,7 +94,7 @@ class LIBPROTOBUF_EXPORT RepeatedFieldAccessor { virtual void Swap(Field* data, const RepeatedFieldAccessor* other_mutator, Field* other_data) const = 0; - // Create an iterator that points at the begining of the repeated field. + // Create an iterator that points at the beginning of the repeated field. virtual Iterator* BeginIterator(const Field* data) const = 0; // Create an iterator that points at the end of the repeated field. virtual Iterator* EndIterator(const Field* data) const = 0; diff --git a/src/google/protobuf/stubs/bytestream.h b/src/google/protobuf/stubs/bytestream.h index de8e0204..07604e17 100644 --- a/src/google/protobuf/stubs/bytestream.h +++ b/src/google/protobuf/stubs/bytestream.h @@ -208,7 +208,7 @@ class LIBPROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { }; // Implementation of ByteSink that allocates an internal buffer (a char array) -// and expands it as needed to accomodate appended data (similar to a string), +// and expands it as needed to accommodate appended data (similar to a string), // and allows the caller to take ownership of the internal buffer via the // GetBuffer() method. The buffer returned from GetBuffer() must be deleted by // the caller with delete[]. GetBuffer() also sets the internal buffer to be diff --git a/src/google/protobuf/stubs/stringpiece.h b/src/google/protobuf/stubs/stringpiece.h index 91671659..8910688b 100644 --- a/src/google/protobuf/stubs/stringpiece.h +++ b/src/google/protobuf/stubs/stringpiece.h @@ -222,14 +222,6 @@ class LIBPROTOBUF_EXPORT StringPiece { : ptr_(str.data()), length_(0) { length_ = CheckedSsizeTFromSizeT(str.size()); } -#if defined(HAS_GLOBAL_STRING) - template <class Allocator> - StringPiece( // NOLINT(runtime/explicit) - const basic_string<char, std::char_traits<char>, Allocator>& str) - : ptr_(str.data()), length_(0) { - length_ = CheckedSsizeTFromSizeT(str.size()); - } -#endif StringPiece(const char* offset, stringpiece_ssize_type len) : ptr_(offset), length_(len) { diff --git a/src/google/protobuf/stubs/time.h b/src/google/protobuf/stubs/time.h index 20a6b56d..45607ca9 100644 --- a/src/google/protobuf/stubs/time.h +++ b/src/google/protobuf/stubs/time.h @@ -66,7 +66,7 @@ void LIBPROTOBUF_EXPORT GetCurrentTime(int64* seconds, int32* nanos); string LIBPROTOBUF_EXPORT FormatTime(int64 seconds, int32 nanos); // Parses a time string. This method accepts RFC3339 date/time string with UTC // offset. For example, "2015-05-20T13:29:35.120-08:00". -bool LIBPROTOBUF_EXPORT ParseTime(const string& vaule, int64* seconds, int32* nanos); +bool LIBPROTOBUF_EXPORT ParseTime(const string& value, int64* seconds, int32* nanos); } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/util/field_comparator.cc b/src/google/protobuf/util/field_comparator.cc index 60b8b8a5..a1a56ee6 100644 --- a/src/google/protobuf/util/field_comparator.cc +++ b/src/google/protobuf/util/field_comparator.cc @@ -189,7 +189,7 @@ bool DefaultFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, return MathUtil::AlmostEquals(value_1, value_2); } else { // Use user-provided fraction and margin. Since they are stored as - // doubles, we explicitely cast them to types of values provided. This + // doubles, we explicitly cast them to types of values provided. This // is very likely to fail if provided values are not numeric. return MathUtil::WithinFractionOrMargin( value_1, value_2, static_cast<T>(tolerance->fraction), diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc index 3e09c9bb..7a1a6cbd 100644 --- a/src/google/protobuf/util/internal/proto_writer.cc +++ b/src/google/protobuf/util/internal/proto_writer.cc @@ -64,6 +64,7 @@ ProtoWriter::ProtoWriter(TypeResolver* type_resolver, typeinfo_(TypeInfo::NewTypeInfo(type_resolver)), own_typeinfo_(true), done_(false), + ignore_unknown_fields_(false), element_(NULL), size_insert_(), output_(output), @@ -71,7 +72,6 @@ ProtoWriter::ProtoWriter(TypeResolver* type_resolver, adapter_(&buffer_), stream_(new CodedOutputStream(&adapter_)), listener_(listener), - ignore_unknown_fields_(false), invalid_depth_(0), tracker_(new ObjectLocationTracker()) {} @@ -82,6 +82,7 @@ ProtoWriter::ProtoWriter(const TypeInfo* typeinfo, typeinfo_(typeinfo), own_typeinfo_(false), done_(false), + ignore_unknown_fields_(false), element_(NULL), size_insert_(), output_(output), @@ -89,7 +90,6 @@ ProtoWriter::ProtoWriter(const TypeInfo* typeinfo, adapter_(&buffer_), stream_(new CodedOutputStream(&adapter_)), listener_(listener), - ignore_unknown_fields_(false), invalid_depth_(0), tracker_(new ObjectLocationTracker()) {} diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h index da121809..8b7c6c34 100644 --- a/src/google/protobuf/util/internal/proto_writer.h +++ b/src/google/protobuf/util/internal/proto_writer.h @@ -184,7 +184,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { return static_cast<ProtoElement*>(BaseElement::parent()); } - // Returns true if the index is already taken by a preceeding oneof input. + // Returns true if the index is already taken by a preceding oneof input. bool IsOneofIndexTaken(int32 index); // Marks the oneof 'index' as taken. Future inputs to this oneof will diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index fc55c2b9..a6d0cb07 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -1386,7 +1386,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( if (key_comparator != NULL || IsTreatedAsSet(repeated_field)) { if (scope_ == PARTIAL) { // When partial matching is enabled, Compare(a, b) && Compare(a, c) - // doesn't neccessarily imply Compare(b, c). Therefore a naive greedy + // doesn't necessarily imply Compare(b, c). Therefore a naive greedy // algorithm will fail to find a maximum matching. // Here we use the argumenting path algorithm. MaximumMatcher::NodeMatchCallback* callback = diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index 1abbfcba..654d1a67 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -278,7 +278,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { const Message& message2, const vector<SpecificField>& field_path) { } - // Report that an unkown field is ignored. (see comment above). + // Report that an unknown field is ignored. (see comment above). // Note this is a different function since the last SpecificField in field // path has a null field. This could break existing Reporter. virtual void ReportUnknownFieldIgnored( diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index a867c881..ed43c512 100755 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -2349,7 +2349,7 @@ TEST_F(ComparisonTest, RepeatedMapFieldTest_RepeatedMessageKey) { } TEST_F(ComparisonTest, RepeatedSetOptionTest_Unknown) { - // Currently, as_set option doens't have affects on unknown field. + // Currently, as_set option doesn't have affects on unknown field. // If needed, this feature will be added by request. repeated_field_as_set(); unknown1_->AddGroup(245)->AddFixed32(248, 1); diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h index 941be75b..aaee21f0 100644 --- a/src/google/protobuf/wire_format.h +++ b/src/google/protobuf/wire_format.h @@ -315,7 +315,7 @@ inline void WireFormat::VerifyUTF8String(const char* data, int size, WireFormatLite::VerifyUtf8String( data, size, static_cast<WireFormatLite::Operation>(op), NULL); #else - // Avoid the compiler warning about unsued variables. + // Avoid the compiler warning about unused variables. (void)data; (void)size; (void)op; #endif } |