To this end, a builder calls markDirty() on its parent whenever it transitions from clean
+ * to dirty. The parent must propagate this call to its own parent, unless it was already dirty,
+ * in which case the grandparent must necessarily already be dirty as well. The parent can only
+ * transition back to "clean" after calling build() on all children.
*/
void markDirty();
}
@@ -107,8 +103,7 @@ public abstract class AbstractMessage
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
@Override
public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
- throw new UnsupportedOperationException(
- "getOneofFieldDescriptor() is not implemented.");
+ throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented.");
}
@Override
@@ -156,8 +151,8 @@ public abstract class AbstractMessage
if (getDescriptorForType() != otherMessage.getDescriptorForType()) {
return false;
}
- return compareFields(getAllFields(), otherMessage.getAllFields()) &&
- getUnknownFields().equals(otherMessage.getUnknownFields());
+ return compareFields(getAllFields(), otherMessage.getAllFields())
+ && getUnknownFields().equals(otherMessage.getUnknownFields());
}
@Override
@@ -182,20 +177,17 @@ public abstract class AbstractMessage
}
/**
- * Compares two bytes fields. The parameters must be either a byte array or a
- * ByteString object. They can be of different type though.
+ * Compares two bytes fields. The parameters must be either a byte array or a ByteString object.
+ * They can be of different type though.
*/
private static boolean compareBytes(Object a, Object b) {
if (a instanceof byte[] && b instanceof byte[]) {
- return Arrays.equals((byte[])a, (byte[])b);
+ return Arrays.equals((byte[]) a, (byte[]) b);
}
return toByteString(a).equals(toByteString(b));
}
- /**
- * Converts a list of MapEntry messages into a Map used for equals() and
- * hashCode().
- */
+ /** Converts a list of MapEntry messages into a Map used for equals() and hashCode(). */
@SuppressWarnings({"rawtypes", "unchecked"})
private static Map convertMapEntryListToMap(List list) {
if (list.isEmpty()) {
@@ -223,10 +215,7 @@ public abstract class AbstractMessage
return result;
}
- /**
- * Compares two map fields. The parameters must be a list of MapEntry
- * messages.
- */
+ /** Compares two map fields. The parameters must be a list of MapEntry messages. */
@SuppressWarnings({"rawtypes", "unchecked"})
private static boolean compareMapField(Object a, Object b) {
Map ma = convertMapEntryListToMap((List) a);
@@ -235,16 +224,13 @@ public abstract class AbstractMessage
}
/**
- * Compares two set of fields.
- * This method is used to implement {@link AbstractMessage#equals(Object)}
- * and {@link AbstractMutableMessage#equals(Object)}. It takes special care
- * of bytes fields because immutable messages and mutable messages use
- * different Java type to represent a bytes field and this method should be
- * able to compare immutable messages, mutable messages and also an immutable
- * message to a mutable message.
+ * Compares two set of fields. This method is used to implement {@link
+ * AbstractMessage#equals(Object)} and {@link AbstractMutableMessage#equals(Object)}. It takes
+ * special care of bytes fields because immutable messages and mutable messages use different Java
+ * type to represent a bytes field and this method should be able to compare immutable messages,
+ * mutable messages and also an immutable message to a mutable message.
*/
- static boolean compareFields(Map NOTE: Implementations that don't support nested builders don't need to override this
+ * method.
*/
void markClean() {
throw new IllegalStateException("Should be overridden by subclasses.");
}
/**
- * Used to support nested builders and called when this nested builder is
- * no longer used by its parent builder and should release the reference
- * to its parent builder.
+ * Used to support nested builders and called when this nested builder is no longer used by its
+ * parent builder and should release the reference to its parent builder.
*
- * NOTE: Implementations that don't support nested builders don't need to
- * override this method.
+ * NOTE: Implementations that don't support nested builders don't need to override this
+ * method.
*/
void dispose() {
throw new IllegalStateException("Should be overridden by subclasses.");
@@ -552,73 +520,63 @@ public abstract class AbstractMessage
// bug.
@Override
- public BuilderType mergeFrom(final ByteString data)
- throws InvalidProtocolBufferException {
+ public BuilderType mergeFrom(final ByteString data) throws InvalidProtocolBufferException {
return (BuilderType) super.mergeFrom(data);
}
@Override
public BuilderType mergeFrom(
- final ByteString data,
- final ExtensionRegistryLite extensionRegistry)
+ final ByteString data, final ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException {
return (BuilderType) super.mergeFrom(data, extensionRegistry);
}
@Override
- public BuilderType mergeFrom(final byte[] data)
- throws InvalidProtocolBufferException {
+ public BuilderType mergeFrom(final byte[] data) throws InvalidProtocolBufferException {
return (BuilderType) super.mergeFrom(data);
}
@Override
- public BuilderType mergeFrom(
- final byte[] data, final int off, final int len)
+ public BuilderType mergeFrom(final byte[] data, final int off, final int len)
throws InvalidProtocolBufferException {
return (BuilderType) super.mergeFrom(data, off, len);
}
@Override
- public BuilderType mergeFrom(
- final byte[] data,
- final ExtensionRegistryLite extensionRegistry)
+ public BuilderType mergeFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException {
return (BuilderType) super.mergeFrom(data, extensionRegistry);
}
@Override
public BuilderType mergeFrom(
- final byte[] data, final int off, final int len,
+ final byte[] data,
+ final int off,
+ final int len,
final ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException {
return (BuilderType) super.mergeFrom(data, off, len, extensionRegistry);
}
@Override
- public BuilderType mergeFrom(final InputStream input)
- throws IOException {
+ public BuilderType mergeFrom(final InputStream input) throws IOException {
return (BuilderType) super.mergeFrom(input);
}
@Override
public BuilderType mergeFrom(
- final InputStream input,
- final ExtensionRegistryLite extensionRegistry)
- throws IOException {
+ final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException {
return (BuilderType) super.mergeFrom(input, extensionRegistry);
}
@Override
- public boolean mergeDelimitedFrom(final InputStream input)
- throws IOException {
+ public boolean mergeDelimitedFrom(final InputStream input) throws IOException {
return super.mergeDelimitedFrom(input);
}
@Override
public boolean mergeDelimitedFrom(
- final InputStream input,
- final ExtensionRegistryLite extensionRegistry)
- throws IOException {
+ final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException {
return super.mergeDelimitedFrom(input, extensionRegistry);
}
}
diff --git a/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java b/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
index b22bbaab62..1720575099 100644
--- a/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
+++ b/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
@@ -41,22 +41,20 @@ import java.util.Collection;
import java.util.List;
/**
- * A partial implementation of the {@link MessageLite} interface which
- * implements as many methods of that interface as possible in terms of other
- * methods.
+ * A partial implementation of the {@link MessageLite} interface which implements as many methods of
+ * that interface as possible in terms of other methods.
*
* @author kenton@google.com Kenton Varda
*/
public abstract class AbstractMessageLite<
- MessageType extends AbstractMessageLite Note: This class implements all the convenience methods in the {@link Parser} interface. See
+ * {@link Parser} for related javadocs. Subclasses need to implement {@link
+ * Parser#parsePartialFrom(CodedInputStream, ExtensionRegistryLite)}
*
* @author liujisi@google.com (Pherl Liu)
*/
public abstract class AbstractParser
- * This implementation assumes all subclasses are array based, supporting random access.
+ * methods must check if the list is mutable before proceeding. Subclasses must invoke {@link
+ * #ensureIsMutable()} manually when overriding those methods.
+ *
+ * This implementation assumes all subclasses are array based, supporting random access.
*/
abstract class AbstractProtobufList Abstract interface for a blocking RPC channel. {@code BlockingRpcChannel}
- * is the blocking equivalent to {@link RpcChannel}.
+ * Abstract interface for a blocking RPC channel. {@code BlockingRpcChannel} is the blocking
+ * equivalent to {@link RpcChannel}.
*
* @author kenton@google.com Kenton Varda
* @author cpovirk@google.com Chris Povirk
*/
public interface BlockingRpcChannel {
/**
- * Call the given method of the remote service and blocks until it returns.
- * {@code callBlockingMethod()} is the blocking equivalent to
- * {@link RpcChannel#callMethod}.
+ * Call the given method of the remote service and blocks until it returns. {@code
+ * callBlockingMethod()} is the blocking equivalent to {@link RpcChannel#callMethod}.
*/
Message callBlockingMethod(
Descriptors.MethodDescriptor method,
RpcController controller,
Message request,
- Message responsePrototype) throws ServiceException;
+ Message responsePrototype)
+ throws ServiceException;
}
diff --git a/java/core/src/main/java/com/google/protobuf/BlockingService.java b/java/core/src/main/java/com/google/protobuf/BlockingService.java
index d01f0b8ff0..e2b99c96c3 100644
--- a/java/core/src/main/java/com/google/protobuf/BlockingService.java
+++ b/java/core/src/main/java/com/google/protobuf/BlockingService.java
@@ -37,28 +37,21 @@ package com.google.protobuf;
* @author cpovirk@google.com Chris Povirk
*/
public interface BlockingService {
- /**
- * Equivalent to {@link Service#getDescriptorForType}.
- */
+ /** Equivalent to {@link Service#getDescriptorForType}. */
Descriptors.ServiceDescriptor getDescriptorForType();
/**
- * Equivalent to {@link Service#callMethod}, except that
- * {@code callBlockingMethod()} returns the result of the RPC or throws a
- * {@link ServiceException} if there is a failure, rather than passing the
- * information to a callback.
+ * Equivalent to {@link Service#callMethod}, except that {@code callBlockingMethod()} returns the
+ * result of the RPC or throws a {@link ServiceException} if there is a failure, rather than
+ * passing the information to a callback.
*/
- Message callBlockingMethod(Descriptors.MethodDescriptor method,
- RpcController controller,
- Message request) throws ServiceException;
+ Message callBlockingMethod(
+ Descriptors.MethodDescriptor method, RpcController controller, Message request)
+ throws ServiceException;
- /**
- * Equivalent to {@link Service#getRequestPrototype}.
- */
+ /** Equivalent to {@link Service#getRequestPrototype}. */
Message getRequestPrototype(Descriptors.MethodDescriptor method);
- /**
- * Equivalent to {@link Service#getResponsePrototype}.
- */
+ /** Equivalent to {@link Service#getResponsePrototype}. */
Message getResponsePrototype(Descriptors.MethodDescriptor method);
}
diff --git a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java
index 0dedb173c9..2c8929e5e4 100644
--- a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java
+++ b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java
@@ -42,11 +42,11 @@ import java.util.RandomAccess;
*
* @author dweis@google.com (Daniel Weis)
*/
-final class BooleanArrayList
- extends AbstractProtobufList Traditional write operations:
- * (as defined by {@link java.io.OutputStream}) where the target method is responsible for either
- * copying the data or completing the write before returning from the method call.
+ * Traditional write operations: (as defined by {@link java.io.OutputStream}) where the
+ * target method is responsible for either copying the data or completing the write before returning
+ * from the method call.
*
* Lazy write operations: where the caller guarantees that it will never modify the
* provided buffer and it can therefore be considered immutable. The target method is free to
@@ -57,9 +57,9 @@ public abstract class ByteOutput {
public abstract void write(byte value) throws IOException;
/**
- * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will
- * not be processed prior to the return of this method call, since {@code value} may be
- * reused/altered by the caller.
+ * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will not be
+ * processed prior to the return of this method call, since {@code value} may be reused/altered by
+ * the caller.
*
* NOTE: This method MUST NOT modify the {@code value}. Doing so is a
* programming error and will lead to data corruption which will be difficult to debug.
@@ -87,15 +87,15 @@ public abstract class ByteOutput {
public abstract void writeLazy(byte[] value, int offset, int length) throws IOException;
/**
- * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will
- * not be processed prior to the return of this method call, since {@code value} may be
- * reused/altered by the caller.
+ * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will not be
+ * processed prior to the return of this method call, since {@code value} may be reused/altered by
+ * the caller.
*
* NOTE: This method MUST NOT modify the {@code value}. Doing so is a
* programming error and will lead to data corruption which will be difficult to debug.
*
* @param value the bytes to be written. Upon returning from this call, the {@code position} of
- * this buffer will be set to the {@code limit}
+ * this buffer will be set to the {@code limit}
* @throws IOException thrown if an error occurred while writing
*/
public abstract void write(ByteBuffer value) throws IOException;
@@ -109,7 +109,7 @@ public abstract class ByteOutput {
* programming error and will lead to data corruption which will be difficult to debug.
*
* @param value the bytes to be written. Upon returning from this call, the {@code position} of
- * this buffer will be set to the {@code limit}
+ * this buffer will be set to the {@code limit}
* @throws IOException thrown if an error occurred while writing
*/
public abstract void writeLazy(ByteBuffer value) throws IOException;
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 ddda0f263d..844d8a5317 100644
--- a/java/core/src/main/java/com/google/protobuf/ByteString.java
+++ b/java/core/src/main/java/com/google/protobuf/ByteString.java
@@ -67,41 +67,36 @@ import java.util.NoSuchElementException;
public abstract class ByteString implements Iterable 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
+ * 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.
+ * 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.
*/
private interface ByteArrayCopier {
- /**
- * Copies the specified range of the specified array into a new array
- */
+ /** Copies the specified range of the specified array into a new array */
byte[] copyFrom(byte[] bytes, int offset, int size);
}
@@ -124,15 +119,16 @@ public abstract class ByteString implements Iterable For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because
- * it is interpreted as an unsigned value, {@code 255}.
+ * For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because it
+ * is interpreted as an unsigned value, {@code 255}.
*/
private static final Comparator For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because
- * it is interpreted as an unsigned value, {@code 255}:
+ * For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because it
+ * is interpreted as an unsigned value, {@code 255}:
*
* Each byte read from the input stream will be copied twice to ensure
- * that the resulting ByteString is truly immutable.
- *
- * @param streamToDrain The source stream, which is read completely
- * but not closed.
- * @return A new {@code ByteString} which is made up of chunks of
- * various sizes, depending on the behavior of the underlying
- * stream.
- * @throws IOException IOException is thrown if there is a problem
- * reading the underlying stream.
+ * Completely reads the given stream's bytes into a {@code ByteString}, blocking if necessary
+ * until all bytes are read through to the end of the stream.
+ *
+ * Performance notes: The returned {@code ByteString} is an 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.
+ *
+ * Each byte read from the input stream will be copied twice to ensure that the resulting
+ * ByteString is truly immutable.
+ *
+ * @param streamToDrain The source stream, which is read completely but not closed.
+ * @return A new {@code ByteString} which is made up of chunks of various sizes, depending on the
+ * behavior of the underlying stream.
+ * @throws IOException IOException is thrown if there is a problem reading the underlying stream.
*/
- public static ByteString readFrom(InputStream streamToDrain)
- throws IOException {
+ public static ByteString readFrom(InputStream streamToDrain) throws IOException {
return readFrom(streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE);
}
/**
- * Completely reads the given stream's bytes into a
- * {@code ByteString}, blocking if necessary until all bytes are
- * read through to the end of the stream.
- *
- * Performance notes: The returned {@code ByteString} is an
- * immutable tree of byte arrays ("chunks") of the stream data. The
- * chunkSize parameter sets the size of these byte arrays.
- *
- * Each byte read from the input stream will be copied twice to ensure
- * that the resulting ByteString is truly immutable.
- *
- * @param streamToDrain The source stream, which is read completely
- * but not closed.
- * @param chunkSize The size of the chunks in which to read the
- * stream.
- * @return A new {@code ByteString} which is made up of chunks of
- * the given size.
- * @throws IOException IOException is thrown if there is a problem
- * reading the underlying stream.
+ * Completely reads the given stream's bytes into a {@code ByteString}, blocking if necessary
+ * until all bytes are read through to the end of the stream.
+ *
+ * Performance notes: The returned {@code ByteString} is an immutable tree of byte
+ * arrays ("chunks") of the stream data. The chunkSize parameter sets the size of these byte
+ * arrays.
+ *
+ * Each byte read from the input stream will be copied twice to ensure that the resulting
+ * ByteString is truly immutable.
+ *
+ * @param streamToDrain The source stream, which is read completely but not closed.
+ * @param chunkSize The size of the chunks in which to read the stream.
+ * @return A new {@code ByteString} which is made up of chunks of the given size.
+ * @throws IOException IOException is thrown if there is a problem reading the underlying stream.
*/
- public static ByteString readFrom(InputStream streamToDrain, int chunkSize)
- throws IOException {
+ public static ByteString readFrom(InputStream streamToDrain, int chunkSize) throws IOException {
return readFrom(streamToDrain, chunkSize, chunkSize);
}
// Helper method that takes the chunk size range as a parameter.
- public static ByteString readFrom(InputStream streamToDrain, int minChunkSize,
- int maxChunkSize) throws IOException {
+ public static ByteString readFrom(InputStream streamToDrain, int minChunkSize, int maxChunkSize)
+ throws IOException {
Collection The returned {@code ByteString} is not necessarily a unique object.
- * If the list is empty, the returned object is the singleton empty
- * {@code ByteString}. If the list has only one element, that
- * {@code ByteString} will be returned without copying.
+ * The returned {@code ByteString} is not necessarily a unique object. If the list is empty,
+ * the returned object is the singleton empty {@code ByteString}. If the list has only one
+ * element, that {@code ByteString} will be returned without copying.
*
* @param byteStrings strings to be concatenated
* @return new {@code ByteString}
@@ -604,9 +569,9 @@ public abstract class ByteString implements Iterable This method may expose internal backing buffers of the {@link ByteString} to the {@link
* ByteOutput} in order to avoid additional copying overhead. It would be possible for a malicious
* {@link ByteOutput} to corrupt the {@link ByteString}. Use with caution!
*
- * @param byteOutput the output target to receive the bytes
- * @throws IOException if an I/O error occurs
+ * @param byteOutput the output target to receive the bytes
+ * @throws IOException if an I/O error occurs
* @see UnsafeByteOperations#unsafeWriteTo(ByteString, ByteOutput)
*/
abstract void writeTo(ByteOutput byteOutput) throws IOException;
/**
- * Constructs a read-only {@code java.nio.ByteBuffer} whose content
- * is equal to the contents of this byte string.
- * The result uses the same backing array as the byte string, if possible.
+ * Constructs a read-only {@code java.nio.ByteBuffer} whose content is equal to the contents of
+ * this byte string. The result uses the same backing array as the byte string, if possible.
*
* @return wrapped bytes
*/
public abstract ByteBuffer asReadOnlyByteBuffer();
/**
- * Constructs a list of read-only {@code java.nio.ByteBuffer} objects
- * such that the concatenation of their contents is equal to the contents
- * of this byte string. The result uses the same backing arrays as the
- * byte string.
- *
- * By returning a list, implementations of this method may be able to avoid
- * copying even when there are multiple backing arrays.
+ * Constructs a list of read-only {@code java.nio.ByteBuffer} objects such that the concatenation
+ * of their contents is equal to the contents of this byte string. The result uses the same
+ * backing arrays as the byte string.
+ *
+ * By returning a list, implementations of this method may be able to avoid copying even when
+ * there are multiple backing arrays.
*
* @return a list of wrapped bytes
*/
public abstract List More precisely, returns {@code true} whenever: More precisely, returns {@code true} whenever:
+ *
+ * This method returns {@code false} for "overlong" byte sequences,
- * as well as for 3-byte sequences that would map to a surrogate
- * character, in accordance with the restricted definition of UTF-8
- * introduced in Unicode 3.1. Note that the UTF-8 decoder included in
- * Oracle's JDK has been modified to also reject "overlong" byte
- * sequences, but (as of 2011) still accepts 3-byte surrogate
- * character byte sequences.
+ * This method returns {@code false} for "overlong" byte sequences, as well as for 3-byte
+ * sequences that would map to a surrogate character, in accordance with the restricted definition
+ * of UTF-8 introduced in Unicode 3.1. Note that the UTF-8 decoder included in Oracle's JDK has
+ * been modified to also reject "overlong" byte sequences, but (as of 2011) still accepts 3-byte
+ * surrogate character byte sequences.
*
* See the Unicode Standard,
- * The {@link InputStream} returned by this method is guaranteed to be
- * completely non-blocking. The method {@link InputStream#available()}
- * returns the number of bytes remaining in the stream. The methods
- * {@link InputStream#read(byte[])}, {@link InputStream#read(byte[],int,int)}
- * and {@link InputStream#skip(long)} will read/skip as many bytes as are
- * available. The method {@link InputStream#markSupported()} returns
- * {@code true}.
- *
- * The methods in the returned {@link InputStream} might not be
- * thread safe.
+ *
+ * The {@link InputStream} returned by this method is guaranteed to be completely non-blocking.
+ * The method {@link InputStream#available()} returns the number of bytes remaining in the stream.
+ * The methods {@link InputStream#read(byte[])}, {@link InputStream#read(byte[],int,int)} and
+ * {@link InputStream#skip(long)} will read/skip as many bytes as are available. The method {@link
+ * InputStream#markSupported()} returns {@code true}.
+ *
+ * The methods in the returned {@link InputStream} might not be thread safe.
*
* @return an input stream that returns the bytes of this byte string.
*/
public abstract InputStream newInput();
/**
- * Creates a {@link CodedInputStream} which can be used to read the bytes.
- * Using this is often more efficient than creating a {@link CodedInputStream}
- * that wraps the result of {@link #newInput()}.
+ * Creates a {@link CodedInputStream} which can be used to read the bytes. Using this is often
+ * more efficient than creating a {@link CodedInputStream} that wraps the result of {@link
+ * #newInput()}.
*
* @return stream based on wrapped data
*/
@@ -970,10 +916,10 @@ public abstract class ByteString implements Iterable
- * A {@link ByteString.Output} offers the same functionality as a
- * {@link ByteArrayOutputStream}, except that it returns a {@link ByteString}
- * rather than a {@code byte} array.
+ *
+ * A {@link ByteString.Output} offers the same functionality as a {@link
+ * ByteArrayOutputStream}, except that it returns a {@link ByteString} rather than a {@code byte}
+ * array.
*
* @param initialCapacity estimate of number of bytes to be written
* @return {@code OutputStream} for building a {@code ByteString}
@@ -983,12 +929,12 @@ public abstract class ByteString implements Iterable
- * A {@link ByteString.Output} offers the same functionality as a
- * {@link ByteArrayOutputStream}, except that it returns a {@link ByteString}
- * rather than a {@code byte array}.
+ * Creates a new {@link Output}. Call {@link Output#toByteString()} to create the {@code
+ * ByteString} instance.
+ *
+ * A {@link ByteString.Output} offers the same functionality as a {@link
+ * ByteArrayOutputStream}, except that it returns a {@link ByteString} rather than a {@code byte
+ * array}.
*
* @return {@code OutputStream} for building a {@code ByteString}
*/
@@ -997,8 +943,8 @@ public abstract class ByteString implements Iterable This is package-private because it's a somewhat confusing interface.
- * Users can call {@link Message#toByteString()} instead of calling this
- * directly.
+ * This is package-private because it's a somewhat confusing interface. Users can call {@link
+ * Message#toByteString()} instead of calling this directly.
*
- * @param size The target byte size of the {@code ByteString}. You must write
- * exactly this many bytes before building the result.
+ * @param size The target byte size of the {@code ByteString}. You must write exactly this many
+ * bytes before building the result.
* @return the builder
*/
static CodedBuilder newCodedBuilder(int size) {
@@ -1224,16 +1162,16 @@ public abstract class ByteString implements Iterable This class contains most of the overhead involved in creating a substring
- * from a {@link LiteralByteString}. The overhead involves some range-checking
- * and two extra fields.
+ * This class contains most of the overhead involved in creating a substring from a {@link
+ * LiteralByteString}. The overhead involves some range-checking and two extra fields.
*
* @author carlanton@google.com (Carl Haverl)
*/
@@ -1555,15 +1488,13 @@ public abstract class ByteString implements Iterable This class contains two kinds of methods: methods that write specific
- * protocol message constructs and field types (e.g. {@link #writeTag} and
- * {@link #writeInt32}) and methods that write low-level values (e.g.
- * {@link #writeRawVarint32} and {@link #writeRawBytes}). If you are
- * writing encoded protocol messages, you should use the former methods, but if
- * you are writing some other format of your own design, use the latter.
+ * This class contains two kinds of methods: methods that write specific protocol message
+ * constructs and field types (e.g. {@link #writeTag} and {@link #writeInt32}) and methods that
+ * write low-level values (e.g. {@link #writeRawVarint32} and {@link #writeRawBytes}). If you are
+ * writing encoded protocol messages, you should use the former methods, but if you are writing some
+ * other format of your own design, use the latter.
*
* This class is totally unsynchronized.
*/
@@ -60,23 +59,17 @@ public abstract class CodedOutputStream extends ByteOutput {
private static final Logger logger = Logger.getLogger(CodedOutputStream.class.getName());
private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations();
- /**
- * @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead.
- */
- @Deprecated
- public static final int LITTLE_ENDIAN_32_SIZE = FIXED32_SIZE;
+ /** @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead. */
+ @Deprecated public static final int LITTLE_ENDIAN_32_SIZE = FIXED32_SIZE;
- /**
- * The buffer size used in {@link #newInstance(OutputStream)}.
- */
+ /** The buffer size used in {@link #newInstance(OutputStream)}. */
public static final int DEFAULT_BUFFER_SIZE = 4096;
/**
- * Returns the buffer size to efficiently write dataLength bytes to this
- * CodedOutputStream. Used by AbstractMessageLite.
+ * Returns the buffer size to efficiently write dataLength bytes to this CodedOutputStream. Used
+ * by AbstractMessageLite.
*
- * @return the buffer size to efficiently write dataLength bytes to this
- * CodedOutputStream.
+ * @return the buffer size to efficiently write dataLength bytes to this CodedOutputStream.
*/
static int computePreferredBufferSize(int dataLength) {
if (dataLength > DEFAULT_BUFFER_SIZE) {
@@ -88,9 +81,9 @@ public abstract class CodedOutputStream extends ByteOutput {
/**
* Create a new {@code CodedOutputStream} wrapping the given {@code OutputStream}.
*
- * NOTE: The provided {@link OutputStream} MUST NOT retain access or
- * modify the provided byte arrays. Doing so may result in corrupted data, which would be
- * difficult to debug.
+ * NOTE: The provided {@link OutputStream} MUST NOT retain access or modify
+ * the provided byte arrays. Doing so may result in corrupted data, which would be difficult to
+ * debug.
*/
public static CodedOutputStream newInstance(final OutputStream output) {
return newInstance(output, DEFAULT_BUFFER_SIZE);
@@ -100,30 +93,28 @@ public abstract class CodedOutputStream extends ByteOutput {
* Create a new {@code CodedOutputStream} wrapping the given {@code OutputStream} with a given
* buffer size.
*
- * NOTE: The provided {@link OutputStream} MUST NOT retain access or
- * modify the provided byte arrays. Doing so may result in corrupted data, which would be
- * difficult to debug.
+ * NOTE: The provided {@link OutputStream} MUST NOT retain access or modify
+ * the provided byte arrays. Doing so may result in corrupted data, which would be difficult to
+ * debug.
*/
public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) {
return new OutputStreamEncoder(output, bufferSize);
}
/**
- * Create a new {@code CodedOutputStream} that writes directly to the given
- * byte array. If more bytes are written than fit in the array,
- * {@link OutOfSpaceException} will be thrown. Writing directly to a flat
- * array is faster than writing to an {@code OutputStream}. See also
- * {@link ByteString#newCodedBuilder}.
+ * Create a new {@code CodedOutputStream} that writes directly to the given byte array. If more
+ * bytes are written than fit in the array, {@link OutOfSpaceException} will be thrown. Writing
+ * directly to a flat array is faster than writing to an {@code OutputStream}. See also {@link
+ * ByteString#newCodedBuilder}.
*/
public static CodedOutputStream newInstance(final byte[] flatArray) {
return newInstance(flatArray, 0, flatArray.length);
}
/**
- * Create a new {@code CodedOutputStream} that writes directly to the given
- * byte array slice. If more bytes are written than fit in the slice,
- * {@link OutOfSpaceException} will be thrown. Writing directly to a flat
- * array is faster than writing to an {@code OutputStream}. See also
+ * Create a new {@code CodedOutputStream} that writes directly to the given byte array slice. If
+ * more bytes are written than fit in the slice, {@link OutOfSpaceException} will be thrown.
+ * Writing directly to a flat array is faster than writing to an {@code OutputStream}. See also
* {@link ByteString#newCodedBuilder}.
*/
public static CodedOutputStream newInstance(
@@ -162,9 +153,9 @@ public abstract class CodedOutputStream extends ByteOutput {
* implies:
*
* Note the deterministic serialization is NOT canonical across languages; it is also unstable
@@ -173,14 +164,14 @@ public abstract class CodedOutputStream extends ByteOutput {
* their own canonicalization specification and implement the serializer using reflection APIs
* rather than relying on this API.
*
- * Once set, the serializer will: (Note this is an implementation detail and may subject to
+ * Once set, the serializer will: (Note this is an implementation detail and may subject to
* change in the future)
*
* NOTE: The {@link ByteOutput} MUST NOT modify the provided buffers. Doing
- * so may result in corrupted data, which would be difficult to debug.
+ * NOTE: The {@link ByteOutput} MUST NOT modify the provided buffers. Doing so
+ * may result in corrupted data, which would be difficult to debug.
*
* @param byteOutput the output target for encoded bytes.
* @param bufferSize the size of the internal scratch buffer to be used for string encoding.
- * Setting this to {@code 0} will disable buffering, requiring an allocation for each encoded
- * string.
+ * Setting this to {@code 0} will disable buffering, requiring an allocation for each encoded
+ * string.
*/
static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) {
if (bufferSize < 0) {
@@ -225,8 +217,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
// Disallow construction outside of this class.
- private CodedOutputStream() {
- }
+ private CodedOutputStream() {}
// -----------------------------------------------------------------
@@ -294,8 +285,8 @@ public abstract class CodedOutputStream extends ByteOutput {
public abstract void writeBool(int fieldNumber, boolean value) throws IOException;
/**
- * Write an enum field, including tag, to the stream. The provided value is the numeric
- * value used to represent the enum value on the wire (not the enum ordinal value).
+ * Write an enum field, including tag, to the stream. The provided value is the numeric value used
+ * to represent the enum value on the wire (not the enum ordinal value).
*/
public final void writeEnum(final int fieldNumber, final int value) throws IOException {
writeInt32(fieldNumber, value);
@@ -319,21 +310,17 @@ public abstract class CodedOutputStream extends ByteOutput {
throws IOException;
/**
- * Write a {@code bytes} field, including tag, to the stream.
- * This method will write all content of the ByteBuffer regardless of the
- * current position and limit (i.e., the number of bytes to be written is
- * value.capacity(), not value.remaining()). Furthermore, this method doesn't
- * alter the state of the passed-in ByteBuffer. Its position, limit, mark,
- * etc. will remain unchanged. If you only want to write the remaining bytes
- * of a ByteBuffer, you can call
- * {@code writeByteBuffer(fieldNumber, byteBuffer.slice())}.
+ * Write a {@code bytes} field, including tag, to the stream. This method will write all content
+ * of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be
+ * written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the
+ * state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If
+ * you only want to write the remaining bytes of a ByteBuffer, you can call {@code
+ * writeByteBuffer(fieldNumber, byteBuffer.slice())}.
*/
// Abstract to avoid overhead of additional virtual method calls.
public abstract void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException;
- /**
- * Write a single byte.
- */
+ /** Write a single byte. */
public final void writeRawByte(final byte value) throws IOException {
write(value);
}
@@ -348,9 +335,7 @@ public abstract class CodedOutputStream extends ByteOutput {
write(value, 0, value.length);
}
- /**
- * Write part of an array of bytes.
- */
+ /** Write part of an array of bytes. */
public final void writeRawBytes(final byte[] value, int offset, int length) throws IOException {
write(value, offset, length);
}
@@ -361,13 +346,11 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Write a ByteBuffer. This method will write all content of the ByteBuffer
- * regardless of the current position and limit (i.e., the number of bytes
- * to be written is value.capacity(), not value.remaining()). Furthermore,
- * this method doesn't alter the state of the passed-in ByteBuffer. Its
- * position, limit, mark, etc. will remain unchanged. If you only want to
- * write the remaining bytes of a ByteBuffer, you can call
- * {@code writeRawBytes(byteBuffer.slice())}.
+ * Write a ByteBuffer. This method will write all content of the ByteBuffer regardless of the
+ * current position and limit (i.e., the number of bytes to be written is value.capacity(), not
+ * value.remaining()). Furthermore, this method doesn't alter the state of the passed-in
+ * ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write
+ * the remaining bytes of a ByteBuffer, you can call {@code writeRawBytes(byteBuffer.slice())}.
*/
// Abstract to avoid overhead of additional virtual method calls.
public abstract void writeRawBytes(final ByteBuffer value) throws IOException;
@@ -379,16 +362,16 @@ public abstract class CodedOutputStream extends ByteOutput {
/**
- * Write a MessageSet extension field to the stream. For historical reasons,
- * the wire format differs from normal fields.
+ * Write a MessageSet extension field to the stream. For historical reasons, the wire format
+ * differs from normal fields.
*/
// Abstract to avoid overhead of additional virtual method calls.
public abstract void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
throws IOException;
/**
- * Write an unparsed MessageSet extension field to the stream. For
- * historical reasons, the wire format differs from normal fields.
+ * Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire
+ * format differs from normal fields.
*/
// Abstract to avoid overhead of additional virtual method calls.
public abstract void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
@@ -457,8 +440,8 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Write an enum field to the stream. The provided value is the numeric
- * value used to represent the enum value on the wire (not the enum ordinal value).
+ * Write an enum field to the stream. The provided value is the numeric value used to represent
+ * the enum value on the wire (not the enum ordinal value).
*/
public final void writeEnumNoTag(final int value) throws IOException {
writeInt32NoTag(value);
@@ -483,7 +466,7 @@ public abstract class CodedOutputStream extends ByteOutput {
public abstract void writeMessageNoTag(final MessageLite value) throws IOException;
- //=================================================================
+ // =================================================================
@ExperimentalApi
@Override
@@ -508,161 +491,160 @@ public abstract class CodedOutputStream extends ByteOutput {
// =================================================================
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code int32} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code int32} field, including
+ * tag.
*/
public static int computeInt32Size(final int fieldNumber, final int value) {
return computeTagSize(fieldNumber) + computeInt32SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code uint32} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code uint32} field, including
+ * tag.
*/
public static int computeUInt32Size(final int fieldNumber, final int value) {
return computeTagSize(fieldNumber) + computeUInt32SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code sint32} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code sint32} field, including
+ * tag.
*/
public static int computeSInt32Size(final int fieldNumber, final int value) {
return computeTagSize(fieldNumber) + computeSInt32SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code fixed32} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code fixed32} field, including
+ * tag.
*/
public static int computeFixed32Size(final int fieldNumber, final int value) {
return computeTagSize(fieldNumber) + computeFixed32SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code sfixed32} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code sfixed32} field, including
+ * tag.
*/
public static int computeSFixed32Size(final int fieldNumber, final int value) {
return computeTagSize(fieldNumber) + computeSFixed32SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code int64} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code int64} field, including
+ * tag.
*/
public static int computeInt64Size(final int fieldNumber, final long value) {
return computeTagSize(fieldNumber) + computeInt64SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code uint64} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code uint64} field, including
+ * tag.
*/
public static int computeUInt64Size(final int fieldNumber, final long value) {
return computeTagSize(fieldNumber) + computeUInt64SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code sint64} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code sint64} field, including
+ * tag.
*/
public static int computeSInt64Size(final int fieldNumber, final long value) {
return computeTagSize(fieldNumber) + computeSInt64SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code fixed64} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code fixed64} field, including
+ * tag.
*/
public static int computeFixed64Size(final int fieldNumber, final long value) {
return computeTagSize(fieldNumber) + computeFixed64SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code sfixed64} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code sfixed64} field, including
+ * tag.
*/
public static int computeSFixed64Size(final int fieldNumber, final long value) {
return computeTagSize(fieldNumber) + computeSFixed64SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code float} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code float} field, including
+ * tag.
*/
public static int computeFloatSize(final int fieldNumber, final float value) {
return computeTagSize(fieldNumber) + computeFloatSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code double} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code double} field, including
+ * tag.
*/
public static int computeDoubleSize(final int fieldNumber, final double value) {
return computeTagSize(fieldNumber) + computeDoubleSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code bool} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code bool} field, including tag.
*/
public static int computeBoolSize(final int fieldNumber, final boolean value) {
return computeTagSize(fieldNumber) + computeBoolSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * enum field, including tag. The provided value is the numeric
- * value used to represent the enum value on the wire (not the enum ordinal value).
+ * Compute the number of bytes that would be needed to encode an enum field, including tag. The
+ * provided value is the numeric value used to represent the enum value on the wire (not the enum
+ * ordinal value).
*/
public static int computeEnumSize(final int fieldNumber, final int value) {
return computeTagSize(fieldNumber) + computeEnumSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code string} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code string} field, including
+ * tag.
*/
public static int computeStringSize(final int fieldNumber, final String value) {
return computeTagSize(fieldNumber) + computeStringSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code bytes} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code bytes} field, including
+ * tag.
*/
public static int computeBytesSize(final int fieldNumber, final ByteString value) {
return computeTagSize(fieldNumber) + computeBytesSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code bytes} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code bytes} field, including
+ * tag.
*/
public static int computeByteArraySize(final int fieldNumber, final byte[] value) {
return computeTagSize(fieldNumber) + computeByteArraySizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code bytes} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code bytes} field, including
+ * tag.
*/
public static int computeByteBufferSize(final int fieldNumber, final ByteBuffer value) {
return computeTagSize(fieldNumber) + computeByteBufferSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * embedded message in lazy field, including tag.
+ * Compute the number of bytes that would be needed to encode an embedded message in lazy field,
+ * including tag.
*/
public static int computeLazyFieldSize(final int fieldNumber, final LazyFieldLite value) {
return computeTagSize(fieldNumber) + computeLazyFieldSizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode an
- * embedded message field, including tag.
+ * Compute the number of bytes that would be needed to encode an embedded message field, including
+ * tag.
*/
public static int computeMessageSize(final int fieldNumber, final MessageLite value) {
return computeTagSize(fieldNumber) + computeMessageSizeNoTag(value);
@@ -670,9 +652,8 @@ public abstract class CodedOutputStream extends ByteOutput {
/**
- * Compute the number of bytes that would be needed to encode a
- * MessageSet extension to the stream. For historical reasons,
- * the wire format differs from normal fields.
+ * Compute the number of bytes that would be needed to encode a MessageSet extension to the
+ * stream. For historical reasons, the wire format differs from normal fields.
*/
public static int computeMessageSetExtensionSize(final int fieldNumber, final MessageLite value) {
return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2
@@ -681,9 +662,8 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Compute the number of bytes that would be needed to encode an
- * unparsed MessageSet extension field to the stream. For
- * historical reasons, the wire format differs from normal fields.
+ * Compute the number of bytes that would be needed to encode an unparsed MessageSet extension
+ * field to the stream. For historical reasons, the wire format differs from normal fields.
*/
public static int computeRawMessageSetExtensionSize(
final int fieldNumber, final ByteString value) {
@@ -693,9 +673,9 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Compute the number of bytes that would be needed to encode an
- * lazily parsed MessageSet extension field to the stream. For
- * historical reasons, the wire format differs from normal fields.
+ * Compute the number of bytes that would be needed to encode an lazily parsed MessageSet
+ * extension field to the stream. For historical reasons, the wire format differs from normal
+ * fields.
*/
public static int computeLazyFieldMessageSetExtensionSize(
final int fieldNumber, final LazyFieldLite value) {
@@ -712,8 +692,8 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code int32} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code int32} field, including
+ * tag.
*/
public static int computeInt32SizeNoTag(final int value) {
if (value >= 0) {
@@ -724,12 +704,9 @@ public abstract class CodedOutputStream extends ByteOutput {
}
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code uint32} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code uint32} field. */
public static int computeUInt32SizeNoTag(final int value) {
- if ((value & (~0 << 7)) == 0) {
+ if ((value & (~0 << 7)) == 0) {
return 1;
}
if ((value & (~0 << 14)) == 0) {
@@ -744,41 +721,32 @@ public abstract class CodedOutputStream extends ByteOutput {
return 5;
}
- /**
- * Compute the number of bytes that would be needed to encode an
- * {@code sint32} field.
- */
+ /** Compute the number of bytes that would be needed to encode an {@code sint32} field. */
public static int computeSInt32SizeNoTag(final int value) {
return computeUInt32SizeNoTag(encodeZigZag32(value));
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code fixed32} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code fixed32} field. */
public static int computeFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) {
return FIXED32_SIZE;
}
- /**
- * Compute the number of bytes that would be needed to encode an
- * {@code sfixed32} field.
- */
+ /** Compute the number of bytes that would be needed to encode an {@code sfixed32} field. */
public static int computeSFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) {
return FIXED32_SIZE;
}
/**
- * Compute the number of bytes that would be needed to encode an
- * {@code int64} field, including tag.
+ * Compute the number of bytes that would be needed to encode an {@code int64} field, including
+ * tag.
*/
public static int computeInt64SizeNoTag(final long value) {
return computeUInt64SizeNoTag(value);
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code uint64} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code uint64} field, including
+ * tag.
*/
public static int computeUInt64SizeNoTag(long value) {
// handle two popular special cases up front ...
@@ -791,10 +759,12 @@ public abstract class CodedOutputStream extends ByteOutput {
// ... leaving us with 8 remaining, which we can divide and conquer
int n = 2;
if ((value & (~0L << 35)) != 0L) {
- n += 4; value >>>= 28;
+ n += 4;
+ value >>>= 28;
}
if ((value & (~0L << 21)) != 0L) {
- n += 2; value >>>= 14;
+ n += 2;
+ value >>>= 14;
}
if ((value & (~0L << 14)) != 0L) {
n += 1;
@@ -802,67 +772,51 @@ public abstract class CodedOutputStream extends ByteOutput {
return n;
}
- /**
- * Compute the number of bytes that would be needed to encode an
- * {@code sint64} field.
- */
+ /** Compute the number of bytes that would be needed to encode an {@code sint64} field. */
public static int computeSInt64SizeNoTag(final long value) {
return computeUInt64SizeNoTag(encodeZigZag64(value));
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code fixed64} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code fixed64} field. */
public static int computeFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) {
return FIXED64_SIZE;
}
- /**
- * Compute the number of bytes that would be needed to encode an
- * {@code sfixed64} field.
- */
+ /** Compute the number of bytes that would be needed to encode an {@code sfixed64} field. */
public static int computeSFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) {
return FIXED64_SIZE;
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code float} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code float} field, including
+ * tag.
*/
public static int computeFloatSizeNoTag(@SuppressWarnings("unused") final float unused) {
return FIXED32_SIZE;
}
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code double} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code double} field, including
+ * tag.
*/
public static int computeDoubleSizeNoTag(@SuppressWarnings("unused") final double unused) {
return FIXED64_SIZE;
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code bool} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code bool} field. */
public static int computeBoolSizeNoTag(@SuppressWarnings("unused") final boolean unused) {
return 1;
}
/**
- * Compute the number of bytes that would be needed to encode an enum field.
- * The provided value is the numeric value used to represent the enum value on the wire
- * (not the enum ordinal value).
+ * Compute the number of bytes that would be needed to encode an enum field. The provided value is
+ * the numeric value used to represent the enum value on the wire (not the enum ordinal value).
*/
public static int computeEnumSizeNoTag(final int value) {
return computeInt32SizeNoTag(value);
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code string} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code string} field. */
public static int computeStringSizeNoTag(final String value) {
int length;
try {
@@ -877,41 +831,29 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Compute the number of bytes that would be needed to encode an embedded
- * message stored in lazy field.
+ * Compute the number of bytes that would be needed to encode an embedded message stored in lazy
+ * field.
*/
public static int computeLazyFieldSizeNoTag(final LazyFieldLite value) {
return computeLengthDelimitedFieldSize(value.getSerializedSize());
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code bytes} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code bytes} field. */
public static int computeBytesSizeNoTag(final ByteString value) {
return computeLengthDelimitedFieldSize(value.size());
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code bytes} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code bytes} field. */
public static int computeByteArraySizeNoTag(final byte[] value) {
return computeLengthDelimitedFieldSize(value.length);
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code bytes} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code bytes} field. */
public static int computeByteBufferSizeNoTag(final ByteBuffer value) {
return computeLengthDelimitedFieldSize(value.capacity());
}
- /**
- * Compute the number of bytes that would be needed to encode an embedded
- * message field.
- */
+ /** Compute the number of bytes that would be needed to encode an embedded message field. */
public static int computeMessageSizeNoTag(final MessageLite value) {
return computeLengthDelimitedFieldSize(value.getSerializedSize());
}
@@ -922,14 +864,13 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers
- * into values that can be efficiently encoded with varint. (Otherwise,
- * negative values must be sign-extended to 64 bits to be varint encoded,
- * thus always taking 10 bytes on the wire.)
+ * Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be
+ * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits
+ * to be varint encoded, thus always taking 10 bytes on the wire.)
*
* @param n A signed 32-bit integer.
- * @return An unsigned 32-bit integer, stored in a signed int because
- * Java has no explicit unsigned support.
+ * @return An unsigned 32-bit integer, stored in a signed int because Java has no explicit
+ * unsigned support.
*/
public static int encodeZigZag32(final int n) {
// Note: the right-shift must be arithmetic
@@ -937,14 +878,13 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers
- * into values that can be efficiently encoded with varint. (Otherwise,
- * negative values must be sign-extended to 64 bits to be varint encoded,
- * thus always taking 10 bytes on the wire.)
+ * Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be
+ * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits
+ * to be varint encoded, thus always taking 10 bytes on the wire.)
*
* @param n A signed 64-bit integer.
- * @return An unsigned 64-bit integer, stored in a signed int because
- * Java has no explicit unsigned support.
+ * @return An unsigned 64-bit integer, stored in a signed int because Java has no explicit
+ * unsigned support.
*/
public static long encodeZigZag64(final long n) {
// Note: the right-shift must be arithmetic
@@ -954,23 +894,22 @@ public abstract class CodedOutputStream extends ByteOutput {
// =================================================================
/**
- * Flushes the stream and forces any buffered bytes to be written. This
- * does not flush the underlying OutputStream.
+ * Flushes the stream and forces any buffered bytes to be written. This does not flush the
+ * underlying OutputStream.
*/
public abstract void flush() throws IOException;
/**
- * If writing to a flat array, return the space left in the array.
- * Otherwise, throws {@code UnsupportedOperationException}.
+ * If writing to a flat array, return the space left in the array. Otherwise, throws {@code
+ * UnsupportedOperationException}.
*/
public abstract int spaceLeft();
/**
- * Verifies that {@link #spaceLeft()} returns zero. It's common to create
- * a byte array that is exactly big enough to hold a message, then write to
- * it with a {@code CodedOutputStream}. Calling {@code checkNoSpaceLeft()}
- * after writing verifies that the message was actually as big as expected,
- * which can help catch bugs.
+ * Verifies that {@link #spaceLeft()} returns zero. It's common to create a byte array that is
+ * exactly big enough to hold a message, then write to it with a {@code CodedOutputStream}.
+ * Calling {@code checkNoSpaceLeft()} after writing verifies that the message was actually as big
+ * as expected, which can help catch bugs.
*/
public final void checkNoSpaceLeft() {
if (spaceLeft() != 0) {
@@ -979,9 +918,8 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * If you create a CodedOutputStream around a simple flat array, you must
- * not attempt to write more bytes than the array has space. Otherwise,
- * this exception will be thrown.
+ * If you create a CodedOutputStream around a simple flat array, you must not attempt to write
+ * more bytes than the array has space. Otherwise, this exception will be thrown.
*/
public static class OutOfSpaceException extends IOException {
private static final long serialVersionUID = -6947486886997889499L;
@@ -1007,9 +945,8 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Get the total number of bytes successfully written to this stream. The
- * returned value is not guaranteed to be accurate if exceptions have been
- * found in the middle of writing.
+ * Get the total number of bytes successfully written to this stream. The returned value is not
+ * guaranteed to be accurate if exceptions have been found in the middle of writing.
*/
public abstract int getTotalBytesWritten();
@@ -1021,8 +958,10 @@ public abstract class CodedOutputStream extends ByteOutput {
final void inefficientWriteStringNoTag(String value, UnpairedSurrogateException cause)
throws IOException {
- logger.log(Level.WARNING,
- "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!", cause);
+ logger.log(
+ Level.WARNING,
+ "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!",
+ cause);
// Unfortunately there does not appear to be any way to tell Java to encode
// UTF-8 directly into our buffer, so we have to let it create its own byte
@@ -1066,8 +1005,8 @@ public abstract class CodedOutputStream extends ByteOutput {
/**
- * Compute the number of bytes that would be needed to encode a
- * {@code group} field, including tag.
+ * Compute the number of bytes that would be needed to encode a {@code group} field, including
+ * tag.
*
* @deprecated groups are deprecated.
*/
@@ -1077,10 +1016,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
- /**
- * Compute the number of bytes that would be needed to encode a
- * {@code group} field.
- */
+ /** Compute the number of bytes that would be needed to encode a {@code group} field. */
@Deprecated
public static int computeGroupSizeNoTag(final MessageLite value) {
return value.getSerializedSize();
@@ -1088,8 +1024,8 @@ public abstract class CodedOutputStream extends ByteOutput {
/**
- * Encode and write a varint. {@code value} is treated as
- * unsigned, so it won't be sign-extended if negative.
+ * Encode and write a varint. {@code value} is treated as unsigned, so it won't be sign-extended
+ * if negative.
*
* @deprecated use {@link #writeUInt32NoTag} instead.
*/
@@ -1109,9 +1045,8 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * Compute the number of bytes that would be needed to encode a varint.
- * {@code value} is treated as unsigned, so it won't be sign-extended if
- * negative.
+ * Compute the number of bytes that would be needed to encode a varint. {@code value} is treated
+ * as unsigned, so it won't be sign-extended if negative.
*
* @deprecated use {@link #computeUInt32SizeNoTag(int)} instead.
*/
@@ -1152,9 +1087,7 @@ public abstract class CodedOutputStream extends ByteOutput {
// =================================================================
- /**
- * A {@link CodedOutputStream} that writes directly to a byte array.
- */
+ /** A {@link CodedOutputStream} that writes directly to a byte array. */
private static class ArrayEncoder extends CodedOutputStream {
private final byte[] buffer;
private final int offset;
@@ -1166,9 +1099,10 @@ public abstract class CodedOutputStream extends ByteOutput {
throw new NullPointerException("buffer");
}
if ((offset | length | (buffer.length - (offset + length))) < 0) {
- throw new IllegalArgumentException(String.format(
- "Array range is invalid. Buffer.length=%d, offset=%d, length=%d",
- buffer.length, offset, length));
+ throw new IllegalArgumentException(
+ String.format(
+ "Array range is invalid. Buffer.length=%d, offset=%d, length=%d",
+ buffer.length, offset, length));
}
this.buffer = buffer;
this.offset = offset;
@@ -1501,15 +1435,17 @@ public abstract class CodedOutputStream extends ByteOutput {
}
/**
- * A {@link CodedOutputStream} that writes directly to a heap {@link ByteBuffer}. Writes are
- * done directly to the underlying array. The buffer position is only updated after a flush.
+ * A {@link CodedOutputStream} that writes directly to a heap {@link ByteBuffer}. Writes are done
+ * directly to the underlying array. The buffer position is only updated after a flush.
*/
private static final class HeapNioEncoder extends ArrayEncoder {
private final ByteBuffer byteBuffer;
private int initialPosition;
HeapNioEncoder(ByteBuffer byteBuffer) {
- super(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(),
+ super(
+ byteBuffer.array(),
+ byteBuffer.arrayOffset() + byteBuffer.position(),
byteBuffer.remaining());
this.byteBuffer = byteBuffer;
this.initialPosition = byteBuffer.position();
@@ -1604,16 +1540,14 @@ public abstract class CodedOutputStream extends ByteOutput {
}
@Override
- public void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
- throws IOException {
+ public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException {
writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
writeUInt32NoTag(value.capacity());
writeRawBytes(value);
}
@Override
- public void writeMessage(final int fieldNumber, final MessageLite value)
- throws IOException {
+ public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException {
writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
writeMessageNoTag(value);
}
@@ -2186,9 +2120,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
}
- /**
- * Abstract base class for buffered encoders.
- */
+ /** Abstract base class for buffered encoders. */
private abstract static class AbstractBufferedEncoder extends CodedOutputStream {
final byte[] buffer;
final int limit;
@@ -2346,8 +2278,8 @@ public abstract class CodedOutputStream extends ByteOutput {
/**
* A {@link CodedOutputStream} that decorates a {@link ByteOutput}. It internal buffer only to
- * support string encoding operations. All other writes are just passed through to the
- * {@link ByteOutput}.
+ * support string encoding operations. All other writes are just passed through to the {@link
+ * ByteOutput}.
*/
private static final class ByteOutputEncoder extends AbstractBufferedEncoder {
private final ByteOutput out;
@@ -2433,8 +2365,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
@Override
- public void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
- throws IOException {
+ public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException {
writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
writeUInt32NoTag(value.capacity());
writeRawBytes(value);
@@ -2464,8 +2395,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
@Override
- public void writeMessage(final int fieldNumber, final MessageLite value)
- throws IOException {
+ public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException {
writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
writeMessageNoTag(value);
}
@@ -2738,8 +2668,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
@Override
- public void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
- throws IOException {
+ public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException {
writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
writeUInt32NoTag(value.capacity());
writeRawBytes(value);
@@ -2769,8 +2698,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
@Override
- public void writeMessage(final int fieldNumber, final MessageLite value)
- throws IOException {
+ public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException {
writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
writeMessageNoTag(value);
}
@@ -2916,8 +2844,7 @@ public abstract class CodedOutputStream extends ByteOutput {
}
@Override
- public void write(byte[] value, int offset, int length)
- throws IOException {
+ public void write(byte[] value, int offset, int length) throws IOException {
if (limit - position >= length) {
// We have room in the current buffer.
System.arraycopy(value, offset, buffer, position, length);
diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java
index 75b16fe30e..8f751925c4 100644
--- a/java/core/src/main/java/com/google/protobuf/Descriptors.java
+++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java
@@ -49,29 +49,25 @@ import java.util.logging.Logger;
/**
* Contains a collection of classes which describe protocol message types.
*
- * Every message type has a {@link Descriptor}, which lists all
- * its fields and other information about a type. You can get a message
- * type's descriptor by calling {@code MessageType.getDescriptor()}, or
- * (given a message object of the type) {@code message.getDescriptorForType()}.
- * Furthermore, each message is associated with a {@link FileDescriptor} for
- * a relevant {@code .proto} file. You can obtain it by calling
- * {@code Descriptor.getFile()}. A {@link FileDescriptor} contains descriptors
- * for all the messages defined in that file, and file descriptors for all the
- * imported {@code .proto} files.
+ * Every message type has a {@link Descriptor}, which lists all its fields and other information
+ * about a type. You can get a message type's descriptor by calling {@code
+ * MessageType.getDescriptor()}, or (given a message object of the type) {@code
+ * message.getDescriptorForType()}. Furthermore, each message is associated with a {@link
+ * FileDescriptor} for a relevant {@code .proto} file. You can obtain it by calling {@code
+ * Descriptor.getFile()}. A {@link FileDescriptor} contains descriptors for all the messages defined
+ * in that file, and file descriptors for all the imported {@code .proto} files.
*
- * Descriptors are built from DescriptorProtos, as defined in
- * {@code google/protobuf/descriptor.proto}.
+ * Descriptors are built from DescriptorProtos, as defined in {@code
+ * google/protobuf/descriptor.proto}.
*
* @author kenton@google.com Kenton Varda
*/
public final class Descriptors {
- private static final Logger logger =
- Logger.getLogger(Descriptors.class.getName());
+ private static final Logger logger = Logger.getLogger(Descriptors.class.getName());
/**
- * Describes a {@code .proto} file, including everything defined within.
- * That includes, in particular, descriptors for all the messages and
- * file descriptors for all other imported {@code .proto} files
- * (dependencies).
+ * Describes a {@code .proto} file, including everything defined within. That includes, in
+ * particular, descriptors for all the messages and file descriptors for all other imported {@code
+ * .proto} files (dependencies).
*/
public static final class FileDescriptor extends GenericDescriptor {
/** Convert the descriptor to its protocol message representation. */
@@ -99,14 +95,17 @@ public final class Descriptors {
}
/**
- * Get the proto package name. This is the package name given by the
- * {@code package} statement in the {@code .proto} file, which differs
- * from the Java package.
+ * Get the proto package name. This is the package name given by the {@code package} statement
+ * in the {@code .proto} file, which differs from the Java package.
*/
- public String getPackage() { return proto.getPackage(); }
+ public String getPackage() {
+ return proto.getPackage();
+ }
/** Get the {@code FileOptions}, defined in {@code descriptor.proto}. */
- public FileOptions getOptions() { return proto.getOptions(); }
+ public FileOptions getOptions() {
+ return proto.getOptions();
+ }
/** Get a list of top-level message types declared in this file. */
public List
+ * All descriptors implement this to make it easier to implement tools like {@code
+ * DescriptorPool}.
*
- * This class is public so that the methods it exposes can be called from
- * outside of this package. However, it should only be subclassed from
- * nested classes of Descriptors.
+ * This class is public so that the methods it exposes can be called from outside of this
+ * package. However, it should only be subclassed from nested classes of Descriptors.
*/
public abstract static class GenericDescriptor {
public abstract Message toProto();
+
public abstract String getName();
+
public abstract String getFullName();
+
public abstract FileDescriptor getFile();
}
- /**
- * Thrown when building descriptors fails because the source DescriptorProtos
- * are not valid.
- */
+ /** Thrown when building descriptors fails because the source DescriptorProtos are not valid. */
public static class DescriptorValidationException extends Exception {
private static final long serialVersionUID = 5750205775490483148L;
/** Gets the full name of the descriptor where the error occurred. */
- public String getProblemSymbolName() { return name; }
+ public String getProblemSymbolName() {
+ return name;
+ }
- /**
- * Gets the protocol message representation of the invalid descriptor.
- */
- public Message getProblemProto() { return proto; }
+ /** Gets the protocol message representation of the invalid descriptor. */
+ public Message getProblemProto() {
+ return proto;
+ }
- /**
- * Gets a human-readable description of the error.
- */
- public String getDescription() { return description; }
+ /** Gets a human-readable description of the error. */
+ public String getDescription() {
+ return description;
+ }
private final String name;
private final Message proto;
private final String description;
private DescriptorValidationException(
- final GenericDescriptor problemDescriptor,
- final String description) {
+ final GenericDescriptor problemDescriptor, final String description) {
super(problemDescriptor.getFullName() + ": " + description);
// Note that problemDescriptor may be partially uninitialized, so we
@@ -2078,8 +2084,7 @@ public final class Descriptors {
}
private DescriptorValidationException(
- final FileDescriptor problemDescriptor,
- final String description) {
+ final FileDescriptor problemDescriptor, final String description) {
super(problemDescriptor.getName() + ": " + description);
// Note that problemDescriptor may be partially uninitialized, so we
@@ -2094,19 +2099,19 @@ public final class Descriptors {
// =================================================================
/**
- * A private helper class which contains lookup tables containing all the
- * descriptors defined in a particular file.
+ * A private helper class which contains lookup tables containing all the descriptors defined in a
+ * particular file.
*/
private static final class DescriptorPool {
- /** Defines what subclass of descriptors to search in the descriptor pool.
- */
+ /** Defines what subclass of descriptors to search in the descriptor pool. */
enum SearchFilter {
- TYPES_ONLY, AGGREGATES_ONLY, ALL_SYMBOLS
+ TYPES_ONLY,
+ AGGREGATES_ONLY,
+ ALL_SYMBOLS
}
- DescriptorPool(final FileDescriptor[] dependencies,
- boolean allowUnknownDependencies) {
+ DescriptorPool(final FileDescriptor[] dependencies, boolean allowUnknownDependencies) {
this.dependencies = new HashSet Usage example:
+ *
* Like all other implementations of {@code Parser}, this parser is stateless and thread-safe.
diff --git a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
index 8d987b2e33..e7b8fa8335 100644
--- a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
+++ b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
@@ -42,11 +42,11 @@ import java.util.RandomAccess;
*
* @author dweis@google.com (Daniel Weis)
*/
-final class DoubleArrayList
- extends AbstractProtobufList This constructor is package private and will be used in {@code DynamicMutableMessage} to
+ * convert a mutable message to an immutable message.
*/
- DynamicMessage(Descriptor type, FieldSet Usage guidelines:
+ *
*
- * Methods are for use by generated code only. You can hold a reference to
- * extensions using this type name.
+ *
+ * Methods are for use by generated code only. You can hold a reference to extensions using this
+ * type name.
*/
public abstract class ExtensionLite For example, if you had the {@code .proto} file:
*
@@ -70,25 +69,22 @@ import java.util.Set;
*
* Background:
*
- * You might wonder why this is necessary. Two alternatives might come to
- * mind. First, you might imagine a system where generated extensions are
- * automatically registered when their containing classes are loaded. This
- * is a popular technique, but is bad design; among other things, it creates a
- * situation where behavior can change depending on what classes happen to be
- * loaded. It also introduces a security vulnerability, because an
- * unprivileged class could cause its code to be called unexpectedly from a
- * privileged class by registering itself as an extension of the right type.
+ * You might wonder why this is necessary. Two alternatives might come to mind. First, you might
+ * imagine a system where generated extensions are automatically registered when their containing
+ * classes are loaded. This is a popular technique, but is bad design; among other things, it
+ * creates a situation where behavior can change depending on what classes happen to be loaded. It
+ * also introduces a security vulnerability, because an unprivileged class could cause its code to
+ * be called unexpectedly from a privileged class by registering itself as an extension of the right
+ * type.
*
- * Another option you might consider is lazy parsing: do not parse an
- * extension until it is first requested, at which point the caller must
- * provide a type to use. This introduces a different set of problems. First,
- * it would require a mutex lock any time an extension was accessed, which
- * would be slow. Second, corrupt data would not be detected until first
- * access, at which point it would be much harder to deal with it. Third, it
- * could violate the expectation that message objects are immutable, since the
- * type provided could be any arbitrary message class. An unprivileged user
- * could take advantage of this to inject a mutable object into a message
- * belonging to privileged code and create mischief.
+ * Another option you might consider is lazy parsing: do not parse an extension until it is first
+ * requested, at which point the caller must provide a type to use. This introduces a different set
+ * of problems. First, it would require a mutex lock any time an extension was accessed, which would
+ * be slow. Second, corrupt data would not be detected until first access, at which point it would
+ * be much harder to deal with it. Third, it could violate the expectation that message objects are
+ * immutable, since the type provided could be any arbitrary message class. An unprivileged user
+ * could take advantage of this to inject a mutable object into a message belonging to privileged
+ * code and create mischief.
*
* @author kenton@google.com Kenton Varda
*/
@@ -116,8 +112,8 @@ public class ExtensionRegistry extends ExtensionRegistryLite {
public final FieldDescriptor descriptor;
/**
- * A default instance of the extension's type, if it has a message type.
- * Otherwise, {@code null}.
+ * A default instance of the extension's type, if it has a message type. Otherwise, {@code
+ * null}.
*/
public final Message defaultInstance;
@@ -125,48 +121,41 @@ public class ExtensionRegistry extends ExtensionRegistryLite {
this.descriptor = descriptor;
defaultInstance = null;
}
- private ExtensionInfo(final FieldDescriptor descriptor,
- final Message defaultInstance) {
+
+ private ExtensionInfo(final FieldDescriptor descriptor, final Message defaultInstance) {
this.descriptor = descriptor;
this.defaultInstance = defaultInstance;
}
}
- /**
- * Deprecated. Use {@link #findImmutableExtensionByName(String)} instead.
- */
+ /** Deprecated. Use {@link #findImmutableExtensionByName(String)} instead. */
+ @Deprecated
public ExtensionInfo findExtensionByName(final String fullName) {
return findImmutableExtensionByName(fullName);
}
/**
- * Find an extension for immutable APIs by fully-qualified field name,
- * in the proto namespace. i.e. {@code result.descriptor.fullName()} will
- * match {@code fullName} if a match is found.
+ * Find an extension for immutable APIs by fully-qualified field name, in the proto namespace.
+ * i.e. {@code result.descriptor.fullName()} will match {@code fullName} if a match is found.
*
- * @return Information about the extension if found, or {@code null}
- * otherwise.
+ * @return Information about the extension if found, or {@code null} otherwise.
*/
public ExtensionInfo findImmutableExtensionByName(final String fullName) {
return immutableExtensionsByName.get(fullName);
}
/**
- * Find an extension for mutable APIs by fully-qualified field name,
- * in the proto namespace. i.e. {@code result.descriptor.fullName()} will
- * match {@code fullName} if a match is found.
+ * Find an extension for mutable APIs by fully-qualified field name, in the proto namespace. i.e.
+ * {@code result.descriptor.fullName()} will match {@code fullName} if a match is found.
*
- * @return Information about the extension if found, or {@code null}
- * otherwise.
+ * @return Information about the extension if found, or {@code null} otherwise.
*/
public ExtensionInfo findMutableExtensionByName(final String fullName) {
return mutableExtensionsByName.get(fullName);
}
- /**
- * Deprecated. Use {@link #findImmutableExtensionByNumber(
- * Descriptors.Descriptor, int)}
- */
+ /** Deprecated. Use {@link #findImmutableExtensionByNumber( Descriptors.Descriptor, int)} */
+ @Deprecated
public ExtensionInfo findExtensionByNumber(
final Descriptor containingType, final int fieldNumber) {
return findImmutableExtensionByNumber(containingType, fieldNumber);
@@ -175,34 +164,28 @@ public class ExtensionRegistry extends ExtensionRegistryLite {
/**
* Find an extension by containing type and field number for immutable APIs.
*
- * @return Information about the extension if found, or {@code null}
- * otherwise.
+ * @return Information about the extension if found, or {@code null} otherwise.
*/
public ExtensionInfo findImmutableExtensionByNumber(
final Descriptor containingType, final int fieldNumber) {
- return immutableExtensionsByNumber.get(
- new DescriptorIntPair(containingType, fieldNumber));
+ return immutableExtensionsByNumber.get(new DescriptorIntPair(containingType, fieldNumber));
}
/**
* Find an extension by containing type and field number for mutable APIs.
*
- * @return Information about the extension if found, or {@code null}
- * otherwise.
+ * @return Information about the extension if found, or {@code null} otherwise.
*/
public ExtensionInfo findMutableExtensionByNumber(
final Descriptor containingType, final int fieldNumber) {
- return mutableExtensionsByNumber.get(
- new DescriptorIntPair(containingType, fieldNumber));
+ return mutableExtensionsByNumber.get(new DescriptorIntPair(containingType, fieldNumber));
}
/**
- * Find all extensions for mutable APIs by fully-qualified name of
- * extended class. Note that this method is more computationally expensive
- * than getting a single extension by name or number.
+ * Find all extensions for mutable APIs by fully-qualified name of extended class. Note that this
+ * method is more computationally expensive than getting a single extension by name or number.
*
- * @return Information about the extensions found, or {@code null} if there
- * are none.
+ * @return Information about the extensions found, or {@code null} if there are none.
*/
public Set
- * This factory detects (via reflection) if the full (non-Lite) protocol buffer libraries
- * are available, and if so, the instances returned are actually {@link ExtensionRegistry}.
+ * This factory detects (via reflection) if the full (non-Lite) protocol buffer libraries are
+ * available, and if so, the instances returned are actually {@link ExtensionRegistry}.
*/
final class ExtensionRegistryFactory {
static final String FULL_REGISTRY_CLASS_NAME = "com.google.protobuf.ExtensionRegistry";
/* Visible for Testing
- @Nullable */
+ @Nullable */
static final Class> EXTENSION_REGISTRY_CLASS = reflectExtensionRegistry();
/* @Nullable */
@@ -90,7 +89,7 @@ final class ExtensionRegistryFactory {
private static final ExtensionRegistryLite invokeSubclassFactory(String methodName)
throws Exception {
- return (ExtensionRegistryLite) EXTENSION_REGISTRY_CLASS
- .getDeclaredMethod(methodName).invoke(null);
+ return (ExtensionRegistryLite)
+ EXTENSION_REGISTRY_CLASS.getDeclaredMethod(methodName).invoke(null);
}
}
diff --git a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java
index f3d48d3af3..0ce5f5493f 100644
--- a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java
+++ b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java
@@ -36,22 +36,20 @@ import java.util.Map;
/**
* Equivalent to {@link ExtensionRegistry} but supports only "lite" types.
- *
- * If all of your types are lite types, then you only need to use
- * {@code ExtensionRegistryLite}. Similarly, if all your types are regular
- * types, then you only need {@link ExtensionRegistry}. Typically it does not
- * make sense to mix the two, since if you have any regular types in your
- * program, you then require the full runtime and lose all the benefits of
- * the lite runtime, so you might as well make all your types be regular types.
- * However, in some cases (e.g. when depending on multiple third-party libraries
- * where one uses lite types and one uses regular), you may find yourself
- * wanting to mix the two. In this case things get more complicated.
- *
- * There are three factors to consider: Whether the type being extended is
- * lite, whether the embedded type (in the case of a message-typed extension)
- * is lite, and whether the extension itself is lite. Since all three are
- * declared in different files, they could all be different. Here are all
- * the combinations and which type of registry to use:
+ *
+ * If all of your types are lite types, then you only need to use {@code ExtensionRegistryLite}.
+ * Similarly, if all your types are regular types, then you only need {@link ExtensionRegistry}.
+ * Typically it does not make sense to mix the two, since if you have any regular types in your
+ * program, you then require the full runtime and lose all the benefits of the lite runtime, so you
+ * might as well make all your types be regular types. However, in some cases (e.g. when depending
+ * on multiple third-party libraries where one uses lite types and one uses regular), you may find
+ * yourself wanting to mix the two. In this case things get more complicated.
+ *
+ * There are three factors to consider: Whether the type being extended is lite, whether the
+ * embedded type (in the case of a message-typed extension) is lite, and whether the extension
+ * itself is lite. Since all three are declared in different files, they could all be different.
+ * Here are all the combinations and which type of registry to use:
+ *
*
- * Note that just as regular types are not allowed to contain lite-type fields,
- * they are also not allowed to contain lite-type extensions. This is because
- * regular types must be fully accessible via reflection, which in turn means
- * that all the inner messages must also support reflection. On the other hand,
- * since regular types implement the entire lite interface, there is no problem
- * with embedding regular types inside lite types.
+ *
+ * Note that just as regular types are not allowed to contain lite-type fields, they are also not
+ * allowed to contain lite-type extensions. This is because regular types must be fully accessible
+ * via reflection, which in turn means that all the inner messages must also support reflection. On
+ * the other hand, since regular types implement the entire lite interface, there is no problem with
+ * embedding regular types inside lite types.
*
* @author kenton@google.com Kenton Varda
*/
@@ -114,8 +111,8 @@ public class ExtensionRegistryLite {
}
/**
- * Get the unmodifiable singleton empty instance of either ExtensionRegistryLite or
- * {@code ExtensionRegistry} (if the full (non-Lite) proto libraries are available).
+ * Get the unmodifiable singleton empty instance of either ExtensionRegistryLite or {@code
+ * ExtensionRegistry} (if the full (non-Lite) proto libraries are available).
*/
public static ExtensionRegistryLite getEmptyRegistry() {
return ExtensionRegistryFactory.createEmpty();
@@ -130,32 +127,27 @@ public class ExtensionRegistryLite {
/**
* Find an extension by containing type and field number.
*
- * @return Information about the extension if found, or {@code null}
- * otherwise.
+ * @return Information about the extension if found, or {@code null} otherwise.
*/
@SuppressWarnings("unchecked")
public
- *
*/
public static Comparatortrue
if the byte sequence represented by the
- * argument is a prefix of the byte sequence represented by
- * this string; false
otherwise.
+ * @return true
if the byte sequence represented by the argument is a prefix of the
+ * byte sequence represented by this string; false
otherwise.
*/
public final boolean startsWith(ByteString prefix) {
- return size() >= prefix.size() &&
- substring(0, prefix.size()).equals(prefix);
+ return size() >= prefix.size() && substring(0, prefix.size()).equals(prefix);
}
/**
- * Tests if this bytestring ends with the specified suffix.
- * Similar to {@link String#endsWith(String)}
+ * Tests if this bytestring ends with the specified suffix. Similar to {@link
+ * String#endsWith(String)}
*
* @param suffix the suffix.
- * @return true
if the byte sequence represented by the
- * argument is a suffix of the byte sequence represented by
- * this string; false
otherwise.
+ * @return true
if the byte sequence represented by the argument is a suffix of the
+ * byte sequence represented by this string; false
otherwise.
*/
public final boolean endsWith(ByteString suffix) {
- return size() >= suffix.size() &&
- substring(size() - suffix.size()).equals(suffix);
+ return size() >= suffix.size() && substring(size() - suffix.size()).equals(suffix);
}
// =================================================================
@@ -366,9 +351,7 @@ public abstract class ByteString implements Iterable {@code
+ *
{@code
* Arrays.equals(byteString.toByteArray(),
* new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))
* }
*
- *
* Table 3-6. UTF-8 Bit Distribution,
* Table 3-7. Well Formed UTF-8 Byte Sequences.
*
- * @return whether the bytes in this {@code ByteString} are a
- * well-formed UTF-8 byte sequence
+ * @return whether the bytes in this {@code ByteString} are a well-formed UTF-8 byte sequence
*/
public abstract boolean isValidUtf8();
/**
- * Tells whether the given byte sequence is a well-formed, malformed, or
- * incomplete UTF-8 byte sequence. This method accepts and returns a partial
- * state result, allowing the bytes for a complete UTF-8 byte sequence to be
- * composed from multiple {@code ByteString} segments.
- *
- * @param state either {@code 0} (if this is the initial decoding operation)
- * or the value returned from a call to a partial decoding method for the
- * previous bytes
+ * Tells whether the given byte sequence is a well-formed, malformed, or incomplete UTF-8 byte
+ * sequence. This method accepts and returns a partial state result, allowing the bytes for a
+ * complete UTF-8 byte sequence to be composed from multiple {@code ByteString} segments.
+ *
+ * @param state either {@code 0} (if this is the initial decoding operation) or the value returned
+ * from a call to a partial decoding method for the previous bytes
* @param offset offset of the first byte to check
* @param length number of bytes to check
- *
- * @return {@code -1} if the partial byte sequence is definitely malformed,
- * {@code 0} if it is well-formed (no additional input needed), or, if the
- * byte sequence is "incomplete", i.e. apparently terminated in the middle of
- * a character, an opaque integer "state" value containing enough information
- * to decode the character when passed to a subsequent invocation of a
- * partial decoding method.
+ * @return {@code -1} if the partial byte sequence is definitely malformed, {@code 0} if it is
+ * well-formed (no additional input needed), or, if the byte sequence is "incomplete", i.e.
+ * apparently terminated in the middle of a character, an opaque integer "state" value
+ * containing enough information to decode the character when passed to a subsequent
+ * invocation of a partial decoding method.
*/
protected abstract int partialIsValidUtf8(int state, int offset, int length);
@@ -886,9 +838,7 @@ public abstract class ByteString implements Iterable
- *
*
*
- *
*/
public void useDeterministicSerialization() {
@@ -190,31 +181,32 @@ public abstract class CodedOutputStream extends ByteOutput {
boolean isSerializationDeterministic() {
return serializationDeterministic;
}
+
private boolean serializationDeterministic;
/**
* Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}.
*
* @deprecated the size parameter is no longer used since use of an internal buffer is useless
- * (and wasteful) when writing to a {@link ByteBuffer}. Use {@link #newInstance(ByteBuffer)}
- * instead.
+ * (and wasteful) when writing to a {@link ByteBuffer}. Use {@link #newInstance(ByteBuffer)}
+ * instead.
*/
@Deprecated
- public static CodedOutputStream newInstance(ByteBuffer byteBuffer,
- @SuppressWarnings("unused") int unused) {
+ public static CodedOutputStream newInstance(
+ ByteBuffer byteBuffer, @SuppressWarnings("unused") int unused) {
return newInstance(byteBuffer);
}
/**
* Create a new {@code CodedOutputStream} that writes to the provided {@link ByteOutput}.
*
- *
* for all i in [0, file.getMessageTypeCount()):
* file.getMessageType(i).getIndex() == i
*
+ *
* Similarly, for a {@link Descriptor} {@code messageType}:
+ *
*
* for all i in [0, messageType.getNestedTypeCount()):
* messageType.getNestedType(i).getIndex() == i
*
*/
- public int getIndex() { return index; }
+ public int getIndex() {
+ return index;
+ }
/** Convert the descriptor to its protocol message representation. */
@Override
@@ -607,14 +584,15 @@ public final class Descriptors {
}
/**
- * Get the type's fully-qualified name, within the proto language's
- * namespace. This differs from the Java name. For example, given this
- * {@code .proto}:
+ * Get the type's fully-qualified name, within the proto language's namespace. This differs from
+ * the Java name. For example, given this {@code .proto}:
+ *
*
* package foo.bar;
* option java_package = "com.example.protos"
* message Baz {}
*
+ *
* {@code Baz}'s full name is "foo.bar.Baz".
*/
@Override
@@ -629,10 +607,14 @@ public final class Descriptors {
}
/** If this is a nested type, get the outer descriptor, otherwise null. */
- public Descriptor getContainingType() { return containingType; }
+ public Descriptor getContainingType() {
+ return containingType;
+ }
/** Get the {@code MessageOptions}, defined in {@code descriptor.proto}. */
- public MessageOptions getOptions() { return proto.getOptions(); }
+ public MessageOptions getOptions() {
+ return proto.getOptions();
+ }
/** Get a list of this message type's fields. */
public List
* message Foo {
* extensions 1000 to max;
@@ -1072,14 +1066,14 @@ public final class Descriptors {
* }
* }
*
- * Both {@code baz}'s and {@code qux}'s containing type is {@code Foo}.
- * However, {@code baz}'s extension scope is {@code null} while
- * {@code qux}'s extension scope is {@code Bar}.
+ *
+ * Both {@code baz}'s and {@code qux}'s containing type is {@code Foo}. However, {@code baz}'s
+ * extension scope is {@code null} while {@code qux}'s extension scope is {@code Bar}.
*/
public Descriptor getExtensionScope() {
if (!isExtension()) {
throw new UnsupportedOperationException(
- "This field is not an extension.");
+ String.format("This field is not an extension. (%s)", fullName));
}
return extensionScope;
}
@@ -1088,7 +1082,7 @@ public final class Descriptors {
public Descriptor getMessageType() {
if (getJavaType() != JavaType.MESSAGE) {
throw new UnsupportedOperationException(
- "This field is not of message type.");
+ String.format("This field is not of message type. (%s)", fullName));
}
return messageType;
}
@@ -1098,27 +1092,25 @@ public final class Descriptors {
public EnumDescriptor getEnumType() {
if (getJavaType() != JavaType.ENUM) {
throw new UnsupportedOperationException(
- "This field is not of enum type.");
+ String.format("This field is not of enum type. (%s)", fullName));
}
return enumType;
}
/**
- * Compare with another {@code FieldDescriptor}. This orders fields in
- * "canonical" order, which simply means ascending order by field number.
- * {@code other} must be a field of the same type -- i.e.
- * {@code getContainingType()} must return the same {@code Descriptor} for
- * both fields.
+ * Compare with another {@code FieldDescriptor}. This orders fields in "canonical" order, which
+ * simply means ascending order by field number. {@code other} must be a field of the same type
+ * -- i.e. {@code getContainingType()} must return the same {@code Descriptor} for both fields.
*
- * @return negative, zero, or positive if {@code this} is less than,
- * equal to, or greater than {@code other}, respectively.
+ * @return negative, zero, or positive if {@code this} is less than, equal to, or greater than
+ * {@code other}, respectively.
*/
@Override
public int compareTo(final FieldDescriptor other) {
if (other.containingType != containingType) {
throw new IllegalArgumentException(
- "FieldDescriptors can only be compared to other FieldDescriptors " +
- "for fields of the same message type.");
+ "FieldDescriptors can only be compared to other FieldDescriptors "
+ + "for fields of the same message type.");
}
return getNumber() - other.getNumber();
}
@@ -1145,24 +1137,24 @@ public final class Descriptors {
private Object defaultValue;
public enum Type {
- DOUBLE (JavaType.DOUBLE ),
- FLOAT (JavaType.FLOAT ),
- INT64 (JavaType.LONG ),
- UINT64 (JavaType.LONG ),
- INT32 (JavaType.INT ),
- FIXED64 (JavaType.LONG ),
- FIXED32 (JavaType.INT ),
- BOOL (JavaType.BOOLEAN ),
- STRING (JavaType.STRING ),
- GROUP (JavaType.MESSAGE ),
- MESSAGE (JavaType.MESSAGE ),
- BYTES (JavaType.BYTE_STRING),
- UINT32 (JavaType.INT ),
- ENUM (JavaType.ENUM ),
- SFIXED32(JavaType.INT ),
- SFIXED64(JavaType.LONG ),
- SINT32 (JavaType.INT ),
- SINT64 (JavaType.LONG );
+ DOUBLE(JavaType.DOUBLE),
+ FLOAT(JavaType.FLOAT),
+ INT64(JavaType.LONG),
+ UINT64(JavaType.LONG),
+ INT32(JavaType.INT),
+ FIXED64(JavaType.LONG),
+ FIXED32(JavaType.INT),
+ BOOL(JavaType.BOOLEAN),
+ STRING(JavaType.STRING),
+ GROUP(JavaType.MESSAGE),
+ MESSAGE(JavaType.MESSAGE),
+ BYTES(JavaType.BYTE_STRING),
+ UINT32(JavaType.INT),
+ ENUM(JavaType.ENUM),
+ SFIXED32(JavaType.INT),
+ SFIXED64(JavaType.LONG),
+ SINT32(JavaType.INT),
+ SINT64(JavaType.LONG);
Type(final JavaType javaType) {
this.javaType = javaType;
@@ -1173,7 +1165,10 @@ public final class Descriptors {
public FieldDescriptorProto.Type toProto() {
return FieldDescriptorProto.Type.forNumber(ordinal() + 1);
}
- public JavaType getJavaType() { return javaType; }
+
+ public JavaType getJavaType() {
+ return javaType;
+ }
public static Type valueOf(final FieldDescriptorProto.Type type) {
return values()[type.getNumber() - 1];
@@ -1183,9 +1178,8 @@ public final class Descriptors {
static {
// Refuse to init if someone added a new declared type.
if (Type.values().length != FieldDescriptorProto.Type.values().length) {
- throw new RuntimeException(""
- + "descriptor.proto has a new declared type but Descriptors.java "
- + "wasn't updated.");
+ throw new RuntimeException(
+ "descriptor.proto has a new declared type but Descriptors.java wasn't updated.");
}
}
@@ -1205,8 +1199,8 @@ public final class Descriptors {
}
/**
- * The default default value for fields of this type, if it's a primitive
- * type. This is meant for use inside this file only, hence is private.
+ * The default default value for fields of this type, if it's a primitive type. This is meant
+ * for use inside this file only, hence is private.
*/
private final Object defaultDefault;
}
@@ -1230,12 +1224,13 @@ public final class Descriptors {
return result.toString();
}
- private FieldDescriptor(final FieldDescriptorProto proto,
- final FileDescriptor file,
- final Descriptor parent,
- final int index,
- final boolean isExtension)
- throws DescriptorValidationException {
+ private FieldDescriptor(
+ final FieldDescriptorProto proto,
+ final FileDescriptor file,
+ final Descriptor parent,
+ final int index,
+ final boolean isExtension)
+ throws DescriptorValidationException {
this.index = index;
this.proto = proto;
fullName = computeFullName(file, parent, proto.getName());
@@ -1251,16 +1246,15 @@ public final class Descriptors {
}
if (getNumber() <= 0) {
- throw new DescriptorValidationException(this,
- "Field numbers must be positive integers.");
+ throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
}
if (isExtension) {
if (!proto.hasExtendee()) {
- throw new DescriptorValidationException(this,
- "FieldDescriptorProto.extendee not set for extension field.");
+ throw new DescriptorValidationException(
+ this, "FieldDescriptorProto.extendee not set for extension field.");
}
- containingType = null; // Will be filled in when cross-linking
+ containingType = null; // Will be filled in when cross-linking
if (parent != null) {
extensionScope = parent;
} else {
@@ -1268,23 +1262,23 @@ public final class Descriptors {
}
if (proto.hasOneofIndex()) {
- throw new DescriptorValidationException(this,
- "FieldDescriptorProto.oneof_index set for extension field.");
+ throw new DescriptorValidationException(
+ this, "FieldDescriptorProto.oneof_index set for extension field.");
}
containingOneof = null;
} else {
if (proto.hasExtendee()) {
- throw new DescriptorValidationException(this,
- "FieldDescriptorProto.extendee set for non-extension field.");
+ throw new DescriptorValidationException(
+ this, "FieldDescriptorProto.extendee set for non-extension field.");
}
containingType = parent;
if (proto.hasOneofIndex()) {
- if (proto.getOneofIndex() < 0 ||
- proto.getOneofIndex() >= parent.toProto().getOneofDeclCount()) {
- throw new DescriptorValidationException(this,
- "FieldDescriptorProto.oneof_index is out of range for type "
- + parent.getName());
+ if (proto.getOneofIndex() < 0
+ || proto.getOneofIndex() >= parent.toProto().getOneofDeclCount()) {
+ throw new DescriptorValidationException(
+ this,
+ "FieldDescriptorProto.oneof_index is out of range for type " + parent.getName());
}
containingOneof = parent.getOneofs().get(proto.getOneofIndex());
containingOneof.fieldCount++;
@@ -1301,26 +1295,29 @@ public final class Descriptors {
private void crossLink() throws DescriptorValidationException {
if (proto.hasExtendee()) {
final GenericDescriptor extendee =
- file.pool.lookupSymbol(proto.getExtendee(), this,
- DescriptorPool.SearchFilter.TYPES_ONLY);
+ file.pool.lookupSymbol(
+ proto.getExtendee(), this, DescriptorPool.SearchFilter.TYPES_ONLY);
if (!(extendee instanceof Descriptor)) {
- throw new DescriptorValidationException(this,
- '\"' + proto.getExtendee() + "\" is not a message type.");
+ throw new DescriptorValidationException(
+ this, '\"' + proto.getExtendee() + "\" is not a message type.");
}
- containingType = (Descriptor)extendee;
+ containingType = (Descriptor) extendee;
if (!getContainingType().isExtensionNumber(getNumber())) {
- throw new DescriptorValidationException(this,
- '\"' + getContainingType().getFullName() +
- "\" does not declare " + getNumber() +
- " as an extension number.");
+ throw new DescriptorValidationException(
+ this,
+ '\"'
+ + getContainingType().getFullName()
+ + "\" does not declare "
+ + getNumber()
+ + " as an extension number.");
}
}
if (proto.hasTypeName()) {
final GenericDescriptor typeDescriptor =
- file.pool.lookupSymbol(proto.getTypeName(), this,
- DescriptorPool.SearchFilter.TYPES_ONLY);
+ file.pool.lookupSymbol(
+ proto.getTypeName(), this, DescriptorPool.SearchFilter.TYPES_ONLY);
if (!proto.hasType()) {
// Choose field type based on symbol.
@@ -1329,53 +1326,49 @@ public final class Descriptors {
} else if (typeDescriptor instanceof EnumDescriptor) {
type = Type.ENUM;
} else {
- throw new DescriptorValidationException(this,
- '\"' + proto.getTypeName() + "\" is not a type.");
+ throw new DescriptorValidationException(
+ this, '\"' + proto.getTypeName() + "\" is not a type.");
}
}
if (getJavaType() == JavaType.MESSAGE) {
if (!(typeDescriptor instanceof Descriptor)) {
- throw new DescriptorValidationException(this,
- '\"' + proto.getTypeName() + "\" is not a message type.");
+ throw new DescriptorValidationException(
+ this, '\"' + proto.getTypeName() + "\" is not a message type.");
}
- messageType = (Descriptor)typeDescriptor;
+ messageType = (Descriptor) typeDescriptor;
if (proto.hasDefaultValue()) {
- throw new DescriptorValidationException(this,
- "Messages can't have default values.");
+ throw new DescriptorValidationException(this, "Messages can't have default values.");
}
} else if (getJavaType() == JavaType.ENUM) {
if (!(typeDescriptor instanceof EnumDescriptor)) {
- throw new DescriptorValidationException(this,
- '\"' + proto.getTypeName() + "\" is not an enum type.");
+ throw new DescriptorValidationException(
+ this, '\"' + proto.getTypeName() + "\" is not an enum type.");
}
- enumType = (EnumDescriptor)typeDescriptor;
+ enumType = (EnumDescriptor) typeDescriptor;
} else {
- throw new DescriptorValidationException(this,
- "Field with primitive type has type_name.");
+ throw new DescriptorValidationException(this, "Field with primitive type has type_name.");
}
} else {
- if (getJavaType() == JavaType.MESSAGE ||
- getJavaType() == JavaType.ENUM) {
- throw new DescriptorValidationException(this,
- "Field with message or enum type missing type_name.");
+ if (getJavaType() == JavaType.MESSAGE || getJavaType() == JavaType.ENUM) {
+ throw new DescriptorValidationException(
+ this, "Field with message or enum type missing type_name.");
}
}
// Only repeated primitive fields may be packed.
if (proto.getOptions().getPacked() && !isPackable()) {
- throw new DescriptorValidationException(this,
- "[packed = true] can only be specified for repeated primitive " +
- "fields.");
+ throw new DescriptorValidationException(
+ this, "[packed = true] can only be specified for repeated primitive fields.");
}
// We don't attempt to parse the default value until here because for
// enums we need the enum type's descriptor.
if (proto.hasDefaultValue()) {
if (isRepeated()) {
- throw new DescriptorValidationException(this,
- "Repeated fields cannot have default values.");
+ throw new DescriptorValidationException(
+ this, "Repeated fields cannot have default values.");
}
try {
@@ -1428,30 +1421,26 @@ public final class Descriptors {
break;
case BYTES:
try {
- defaultValue =
- TextFormat.unescapeBytes(proto.getDefaultValue());
+ defaultValue = TextFormat.unescapeBytes(proto.getDefaultValue());
} catch (TextFormat.InvalidEscapeSequenceException e) {
- throw new DescriptorValidationException(this,
- "Couldn't parse default value: " + e.getMessage(), e);
+ throw new DescriptorValidationException(
+ this, "Couldn't parse default value: " + e.getMessage(), e);
}
break;
case ENUM:
defaultValue = enumType.findValueByName(proto.getDefaultValue());
if (defaultValue == null) {
- throw new DescriptorValidationException(this,
- "Unknown enum default value: \"" +
- proto.getDefaultValue() + '\"');
+ throw new DescriptorValidationException(
+ this, "Unknown enum default value: \"" + proto.getDefaultValue() + '\"');
}
break;
case MESSAGE:
case GROUP:
- throw new DescriptorValidationException(this,
- "Message type had default value.");
+ throw new DescriptorValidationException(this, "Message type had default value.");
}
} catch (NumberFormatException e) {
- throw new DescriptorValidationException(this,
- "Could not parse default value: \"" +
- proto.getDefaultValue() + '\"', e);
+ throw new DescriptorValidationException(
+ this, "Could not parse default value: \"" + proto.getDefaultValue() + '\"', e);
}
} else {
// Determine the default default for this field.
@@ -1478,16 +1467,15 @@ public final class Descriptors {
file.pool.addFieldByNumber(this);
}
- if (containingType != null &&
- containingType.getOptions().getMessageSetWireFormat()) {
+ if (containingType != null && containingType.getOptions().getMessageSetWireFormat()) {
if (isExtension()) {
if (!isOptional() || getType() != Type.MESSAGE) {
- throw new DescriptorValidationException(this,
- "Extensions of MessageSets must be optional messages.");
+ throw new DescriptorValidationException(
+ this, "Extensions of MessageSets must be optional messages.");
}
} else {
- throw new DescriptorValidationException(this,
- "MessageSets cannot have fields, only extensions.");
+ throw new DescriptorValidationException(
+ this, "MessageSets cannot have fields, only extensions.");
}
}
}
@@ -1497,10 +1485,7 @@ public final class Descriptors {
this.proto = proto;
}
- /**
- * For internal use only. This is to satisfy the FieldDescriptorLite
- * interface.
- */
+ /** For internal use only. This is to satisfy the FieldDescriptorLite interface. */
@Override
public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from) {
// FieldDescriptors are only used with non-lite messages so we can just
@@ -1517,9 +1502,12 @@ public final class Descriptors {
implements Internal.EnumLiteMap{@code
- * private final static Parser
*
*
- *
*/
@Retention(RetentionPolicy.SOURCE)
@Target({
- ElementType.ANNOTATION_TYPE,
- ElementType.CONSTRUCTOR,
- ElementType.FIELD,
- ElementType.METHOD,
- ElementType.PACKAGE,
- ElementType.TYPE})
+ ElementType.ANNOTATION_TYPE,
+ ElementType.CONSTRUCTOR,
+ ElementType.FIELD,
+ ElementType.METHOD,
+ ElementType.PACKAGE,
+ ElementType.TYPE
+})
@Documented
public @interface ExperimentalApi {
- /**
- * Context information such as links to discussion thread, tracking issue etc.
- */
+ /** Context information such as links to discussion thread, tracking issue etc. */
String value() default "";
}
-
diff --git a/java/core/src/main/java/com/google/protobuf/Extension.java b/java/core/src/main/java/com/google/protobuf/Extension.java
index 5df12e6422..e5da634f1c 100644
--- a/java/core/src/main/java/com/google/protobuf/Extension.java
+++ b/java/core/src/main/java/com/google/protobuf/Extension.java
@@ -49,9 +49,7 @@ public abstract class Extension
* Extended type Inner type Extension Use registry
* =======================================================================
@@ -60,13 +58,12 @@ import java.util.Map;
* regular regular regular ExtensionRegistry
* all other combinations not supported
*
- *