Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Protocol Buffers - Google's data interchange format
// Copyright 2013 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf.nano;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
/**
* Represents an extension.
*
* @author [email protected] (Brian Duff)
* @author [email protected] (Max Cai)
* @param the type of the extendable message this extension is for.
* @param the Java type of the extension; see {@link #clazz}.
*/
public class Extension, T> {
/*
* Because we typically only define message-typed extensions, the Extension class hierarchy is
* designed as follows, to allow a big amount of code in this file to be removed by ProGuard:
*
* Extension // ready to use for message/group typed extensions
* Δ
* |
* PrimitiveExtension // for primitive/enum typed extensions
*/
public static final int TYPE_DOUBLE = InternalNano.TYPE_DOUBLE;
public static final int TYPE_FLOAT = InternalNano.TYPE_FLOAT;
public static final int TYPE_INT64 = InternalNano.TYPE_INT64;
public static final int TYPE_UINT64 = InternalNano.TYPE_UINT64;
public static final int TYPE_INT32 = InternalNano.TYPE_INT32;
public static final int TYPE_FIXED64 = InternalNano.TYPE_FIXED64;
public static final int TYPE_FIXED32 = InternalNano.TYPE_FIXED32;
public static final int TYPE_BOOL = InternalNano.TYPE_BOOL;
public static final int TYPE_STRING = InternalNano.TYPE_STRING;
public static final int TYPE_GROUP = InternalNano.TYPE_GROUP;
public static final int TYPE_MESSAGE = InternalNano.TYPE_MESSAGE;
public static final int TYPE_BYTES = InternalNano.TYPE_BYTES;
public static final int TYPE_UINT32 = InternalNano.TYPE_UINT32;
public static final int TYPE_ENUM = InternalNano.TYPE_ENUM;
public static final int TYPE_SFIXED32 = InternalNano.TYPE_SFIXED32;
public static final int TYPE_SFIXED64 = InternalNano.TYPE_SFIXED64;
public static final int TYPE_SINT32 = InternalNano.TYPE_SINT32;
public static final int TYPE_SINT64 = InternalNano.TYPE_SINT64;
/**
* Creates an {@code Extension} of the given message type and tag number.
* Should be used by the generated code only.
*
* @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
* @deprecated use {@link #createMessageTyped(int, Class, long)} instead.
*/
@Deprecated
public static , T extends MessageNano>
Extension createMessageTyped(int type, Class clazz, int tag) {
return new Extension(type, clazz, tag, false);
}
// Note: these create...() methods take a long for the tag parameter,
// because tags are represented as unsigned ints, and these values exist
// in generated code as long values. However, they can fit in 32-bits, so
// it's safe to cast them to int without loss of precision.
/**
* Creates an {@code Extension} of the given message type and tag number.
* Should be used by the generated code only.
*
* @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
*/
public static , T extends MessageNano>
Extension createMessageTyped(int type, Class clazz, long tag) {
return new Extension(type, clazz, (int) tag, false);
}
/**
* Creates a repeated {@code Extension} of the given message type and tag number.
* Should be used by the generated code only.
*
* @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
*/
public static , T extends MessageNano>
Extension createRepeatedMessageTyped(int type, Class clazz, long tag) {
return new Extension(type, clazz, (int) tag, true);
}
/**
* Creates an {@code Extension} of the given primitive type and tag number.
* Should be used by the generated code only.
*
* @param type one of {@code TYPE_*}, except {@link #TYPE_MESSAGE} and {@link #TYPE_GROUP}
* @param clazz the boxed Java type of this extension
*/
public static , T>
Extension createPrimitiveTyped(int type, Class clazz, long tag) {
return new PrimitiveExtension(type, clazz, (int) tag, false, 0, 0);
}
/**
* Creates a repeated {@code Extension} of the given primitive type and tag number.
* Should be used by the generated code only.
*
* @param type one of {@code TYPE_*}, except {@link #TYPE_MESSAGE} and {@link #TYPE_GROUP}
* @param clazz the Java array type of this extension, with an unboxed component type
*/
public static , T>
Extension createRepeatedPrimitiveTyped(
int type, Class clazz, long tag, long nonPackedTag, long packedTag) {
return new PrimitiveExtension(type, clazz, (int) tag, true,
(int) nonPackedTag, (int) packedTag);
}
/**
* Protocol Buffer type of this extension; one of the {@code TYPE_} constants.
*/
protected final int type;
/**
* Java type of this extension. For a singular extension, this is the boxed Java type for the
* Protocol Buffer {@link #type}; for a repeated extension, this is an array type whose
* component type is the unboxed Java type for {@link #type}. For example, for a singular
* {@code int32}/{@link #TYPE_INT32} extension, this equals {@code Integer.class}; for a
* repeated {@code int32} extension, this equals {@code int[].class}.
*/
protected final Class clazz;
/**
* Tag number of this extension. The data should be viewed as an unsigned 32-bit value.
*/
public final int tag;
/**
* Whether this extension is repeated.
*/
protected final boolean repeated;
private Extension(int type, Class clazz, int tag, boolean repeated) {
this.type = type;
this.clazz = clazz;
this.tag = tag;
this.repeated = repeated;
}
/**
* Returns the value of this extension stored in the given list of unknown fields, or
* {@code null} if no unknown fields matches this extension.
*
* @param unknownFields a list of {@link UnknownFieldData}. All of the elements must have a tag
* that matches this Extension's tag.
*
*/
final T getValueFrom(List unknownFields) {
if (unknownFields == null) {
return null;
}
return repeated ? getRepeatedValueFrom(unknownFields) : getSingularValueFrom(unknownFields);
}
private T getRepeatedValueFrom(List unknownFields) {
// For repeated extensions, read all matching unknown fields in their original order.
List