http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValue.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValue.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValue.java new file mode 100644 index 0000000..83771f5 --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValue.java @@ -0,0 +1,1044 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +/** + * <pre> + * Enum value definition. + * </pre> + * + * Protobuf type {@code google.protobuf.EnumValue} + */ +public final class EnumValue extends + org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:google.protobuf.EnumValue) + EnumValueOrBuilder { + // Use EnumValue.newBuilder() to construct. + private EnumValue(org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.Builder<?> builder) { + super(builder); + } + private EnumValue() { + name_ = ""; + number_ = 0; + options_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + public final org.apache.hadoop.hbase.shaded.com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private EnumValue( + org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedInputStream input, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + name_ = s; + break; + } + case 16: { + + number_ = input.readInt32(); + break; + } + case 26: { + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + options_ = new java.util.ArrayList<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option>(); + mutable_bitField0_ |= 0x00000004; + } + options_.add( + input.readMessage(org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.parser(), extensionRegistry)); + break; + } + } + } + } catch (org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + options_ = java.util.Collections.unmodifiableList(options_); + } + makeExtensionsImmutable(); + } + } + public static final org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_descriptor; + } + + protected org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue.class, org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue.Builder.class); + } + + private int bitField0_; + public static final int NAME_FIELD_NUMBER = 1; + private volatile java.lang.Object name_; + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString bs = + (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString b = + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ref; + } + } + + public static final int NUMBER_FIELD_NUMBER = 2; + private int number_; + /** + * <pre> + * Enum value number. + * </pre> + * + * <code>optional int32 number = 2;</code> + */ + public int getNumber() { + return number_; + } + + public static final int OPTIONS_FIELD_NUMBER = 3; + private java.util.List<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option> options_; + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public java.util.List<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option> getOptionsList() { + return options_; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public java.util.List<? extends org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder> + getOptionsOrBuilderList() { + return options_; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public int getOptionsCount() { + return options_.size(); + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.Option getOptions(int index) { + return options_.get(index); + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index) { + return options_.get(index); + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getNameBytes().isEmpty()) { + org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + if (number_ != 0) { + output.writeInt32(2, number_); + } + for (int i = 0; i < options_.size(); i++) { + output.writeMessage(3, options_.get(i)); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getNameBytes().isEmpty()) { + size += org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + if (number_ != 0) { + size += org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedOutputStream + .computeInt32Size(2, number_); + } + for (int i = 0; i < options_.size(); i++) { + size += org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedOutputStream + .computeMessageSize(3, options_.get(i)); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue)) { + return super.equals(obj); + } + org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue other = (org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue) obj; + + boolean result = true; + result = result && getName() + .equals(other.getName()); + result = result && (getNumber() + == other.getNumber()); + result = result && getOptionsList() + .equals(other.getOptionsList()); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (37 * hash) + NUMBER_FIELD_NUMBER; + hash = (53 * hash) + getNumber(); + if (getOptionsCount() > 0) { + hash = (37 * hash) + OPTIONS_FIELD_NUMBER; + hash = (53 * hash) + getOptionsList().hashCode(); + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom( + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString data) + throws org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom( + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString data, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom(byte[] data) + throws org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom( + byte[] data, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom(java.io.InputStream input) + throws java.io.IOException { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom( + java.io.InputStream input, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseDelimitedFrom( + java.io.InputStream input, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom( + org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parseFrom( + org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedInputStream input, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * <pre> + * Enum value definition. + * </pre> + * + * Protobuf type {@code google.protobuf.EnumValue} + */ + public static final class Builder extends + org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements + // @@protoc_insertion_point(builder_implements:google.protobuf.EnumValue) + org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValueOrBuilder { + public static final org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_descriptor; + } + + protected org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue.class, org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue.Builder.class); + } + + // Construct using org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + getOptionsFieldBuilder(); + } + } + public Builder clear() { + super.clear(); + name_ = ""; + + number_ = 0; + + if (optionsBuilder_ == null) { + options_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + } else { + optionsBuilder_.clear(); + } + return this; + } + + public org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.TypeProto.internal_static_google_protobuf_EnumValue_descriptor; + } + + public org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue getDefaultInstanceForType() { + return org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue.getDefaultInstance(); + } + + public org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue build() { + org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue buildPartial() { + org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue result = new org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + result.name_ = name_; + result.number_ = number_; + if (optionsBuilder_ == null) { + if (((bitField0_ & 0x00000004) == 0x00000004)) { + options_ = java.util.Collections.unmodifiableList(options_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.options_ = options_; + } else { + result.options_ = optionsBuilder_.build(); + } + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor field, + int index, Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(org.apache.hadoop.hbase.shaded.com.google.protobuf.Message other) { + if (other instanceof org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue) { + return mergeFrom((org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue other) { + if (other == org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + onChanged(); + } + if (other.getNumber() != 0) { + setNumber(other.getNumber()); + } + if (optionsBuilder_ == null) { + if (!other.options_.isEmpty()) { + if (options_.isEmpty()) { + options_ = other.options_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureOptionsIsMutable(); + options_.addAll(other.options_); + } + onChanged(); + } + } else { + if (!other.options_.isEmpty()) { + if (optionsBuilder_.isEmpty()) { + optionsBuilder_.dispose(); + optionsBuilder_ = null; + options_ = other.options_; + bitField0_ = (bitField0_ & ~0x00000004); + optionsBuilder_ = + org.apache.hadoop.hbase.shaded.com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + getOptionsFieldBuilder() : null; + } else { + optionsBuilder_.addAllMessages(other.options_); + } + } + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedInputStream input, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString bs = + (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString b = + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ref; + } + } + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + public Builder setName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + name_ = value; + onChanged(); + return this; + } + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + public Builder clearName() { + + name_ = getDefaultInstance().getName(); + onChanged(); + return this; + } + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + public Builder setNameBytes( + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + name_ = value; + onChanged(); + return this; + } + + private int number_ ; + /** + * <pre> + * Enum value number. + * </pre> + * + * <code>optional int32 number = 2;</code> + */ + public int getNumber() { + return number_; + } + /** + * <pre> + * Enum value number. + * </pre> + * + * <code>optional int32 number = 2;</code> + */ + public Builder setNumber(int value) { + + number_ = value; + onChanged(); + return this; + } + /** + * <pre> + * Enum value number. + * </pre> + * + * <code>optional int32 number = 2;</code> + */ + public Builder clearNumber() { + + number_ = 0; + onChanged(); + return this; + } + + private java.util.List<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option> options_ = + java.util.Collections.emptyList(); + private void ensureOptionsIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + options_ = new java.util.ArrayList<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option>(options_); + bitField0_ |= 0x00000004; + } + } + + private org.apache.hadoop.hbase.shaded.com.google.protobuf.RepeatedFieldBuilderV3< + org.apache.hadoop.hbase.shaded.com.google.protobuf.Option, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder, org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder> optionsBuilder_; + + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public java.util.List<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option> getOptionsList() { + if (optionsBuilder_ == null) { + return java.util.Collections.unmodifiableList(options_); + } else { + return optionsBuilder_.getMessageList(); + } + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public int getOptionsCount() { + if (optionsBuilder_ == null) { + return options_.size(); + } else { + return optionsBuilder_.getCount(); + } + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.Option getOptions(int index) { + if (optionsBuilder_ == null) { + return options_.get(index); + } else { + return optionsBuilder_.getMessage(index); + } + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder setOptions( + int index, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option value) { + if (optionsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureOptionsIsMutable(); + options_.set(index, value); + onChanged(); + } else { + optionsBuilder_.setMessage(index, value); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder setOptions( + int index, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder builderForValue) { + if (optionsBuilder_ == null) { + ensureOptionsIsMutable(); + options_.set(index, builderForValue.build()); + onChanged(); + } else { + optionsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder addOptions(org.apache.hadoop.hbase.shaded.com.google.protobuf.Option value) { + if (optionsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureOptionsIsMutable(); + options_.add(value); + onChanged(); + } else { + optionsBuilder_.addMessage(value); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder addOptions( + int index, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option value) { + if (optionsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureOptionsIsMutable(); + options_.add(index, value); + onChanged(); + } else { + optionsBuilder_.addMessage(index, value); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder addOptions( + org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder builderForValue) { + if (optionsBuilder_ == null) { + ensureOptionsIsMutable(); + options_.add(builderForValue.build()); + onChanged(); + } else { + optionsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder addOptions( + int index, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder builderForValue) { + if (optionsBuilder_ == null) { + ensureOptionsIsMutable(); + options_.add(index, builderForValue.build()); + onChanged(); + } else { + optionsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder addAllOptions( + java.lang.Iterable<? extends org.apache.hadoop.hbase.shaded.com.google.protobuf.Option> values) { + if (optionsBuilder_ == null) { + ensureOptionsIsMutable(); + org.apache.hadoop.hbase.shaded.com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, options_); + onChanged(); + } else { + optionsBuilder_.addAllMessages(values); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder clearOptions() { + if (optionsBuilder_ == null) { + options_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + } else { + optionsBuilder_.clear(); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public Builder removeOptions(int index) { + if (optionsBuilder_ == null) { + ensureOptionsIsMutable(); + options_.remove(index); + onChanged(); + } else { + optionsBuilder_.remove(index); + } + return this; + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder getOptionsBuilder( + int index) { + return getOptionsFieldBuilder().getBuilder(index); + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index) { + if (optionsBuilder_ == null) { + return options_.get(index); } else { + return optionsBuilder_.getMessageOrBuilder(index); + } + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public java.util.List<? extends org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder> + getOptionsOrBuilderList() { + if (optionsBuilder_ != null) { + return optionsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(options_); + } + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder addOptionsBuilder() { + return getOptionsFieldBuilder().addBuilder( + org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.getDefaultInstance()); + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder addOptionsBuilder( + int index) { + return getOptionsFieldBuilder().addBuilder( + index, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.getDefaultInstance()); + } + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + public java.util.List<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder> + getOptionsBuilderList() { + return getOptionsFieldBuilder().getBuilderList(); + } + private org.apache.hadoop.hbase.shaded.com.google.protobuf.RepeatedFieldBuilderV3< + org.apache.hadoop.hbase.shaded.com.google.protobuf.Option, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder, org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder> + getOptionsFieldBuilder() { + if (optionsBuilder_ == null) { + optionsBuilder_ = new org.apache.hadoop.hbase.shaded.com.google.protobuf.RepeatedFieldBuilderV3< + org.apache.hadoop.hbase.shaded.com.google.protobuf.Option, org.apache.hadoop.hbase.shaded.com.google.protobuf.Option.Builder, org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder>( + options_, + ((bitField0_ & 0x00000004) == 0x00000004), + getParentForChildren(), + isClean()); + options_ = null; + } + return optionsBuilder_; + } + public final Builder setUnknownFields( + final org.apache.hadoop.hbase.shaded.com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final org.apache.hadoop.hbase.shaded.com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:google.protobuf.EnumValue) + } + + // @@protoc_insertion_point(class_scope:google.protobuf.EnumValue) + private static final org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue(); + } + + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final org.apache.hadoop.hbase.shaded.com.google.protobuf.Parser<EnumValue> + PARSER = new org.apache.hadoop.hbase.shaded.com.google.protobuf.AbstractParser<EnumValue>() { + public EnumValue parsePartialFrom( + org.apache.hadoop.hbase.shaded.com.google.protobuf.CodedInputStream input, + org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException { + return new EnumValue(input, extensionRegistry); + } + }; + + public static org.apache.hadoop.hbase.shaded.com.google.protobuf.Parser<EnumValue> parser() { + return PARSER; + } + + @java.lang.Override + public org.apache.hadoop.hbase.shaded.com.google.protobuf.Parser<EnumValue> getParserForType() { + return PARSER; + } + + public org.apache.hadoop.hbase.shaded.com.google.protobuf.EnumValue getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} +
http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValueOrBuilder.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValueOrBuilder.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValueOrBuilder.java new file mode 100644 index 0000000..a6b9e7a --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/EnumValueOrBuilder.java @@ -0,0 +1,80 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +public interface EnumValueOrBuilder extends + // @@protoc_insertion_point(interface_extends:google.protobuf.EnumValue) + org.apache.hadoop.hbase.shaded.com.google.protobuf.MessageOrBuilder { + + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + java.lang.String getName(); + /** + * <pre> + * Enum value name. + * </pre> + * + * <code>optional string name = 1;</code> + */ + org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString + getNameBytes(); + + /** + * <pre> + * Enum value number. + * </pre> + * + * <code>optional int32 number = 2;</code> + */ + int getNumber(); + + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + java.util.List<org.apache.hadoop.hbase.shaded.com.google.protobuf.Option> + getOptionsList(); + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + org.apache.hadoop.hbase.shaded.com.google.protobuf.Option getOptions(int index); + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + int getOptionsCount(); + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + java.util.List<? extends org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder> + getOptionsOrBuilderList(); + /** + * <pre> + * Protocol buffer options. + * </pre> + * + * <code>repeated .google.protobuf.Option options = 3;</code> + */ + org.apache.hadoop.hbase.shaded.com.google.protobuf.OptionOrBuilder getOptionsOrBuilder( + int index); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExperimentalApi.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExperimentalApi.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExperimentalApi.java new file mode 100644 index 0000000..3bfee9d --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExperimentalApi.java @@ -0,0 +1,66 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates a public API that can change at any time, and has no guarantee of API stability and + * backward-compatibility. + * + * <p>Usage guidelines: + * <ol> + * <li>This annotation is used only on public API. Internal interfaces should not use it.</li> + * <li>This annotation should only be added to new APIs. Adding it to an existing API is + * considered API-breaking.</li> + * <li>Removing this annotation from an API gives it stable status.</li> + * </ol> + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ + 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. + */ + String value() default ""; +} + http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/Extension.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/Extension.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/Extension.java new file mode 100644 index 0000000..e5aa7d3 --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/Extension.java @@ -0,0 +1,86 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +/** + * Interface that generated extensions implement. + * + * @author [email protected] (Jisi Liu) + */ +public abstract class Extension<ContainingType extends MessageLite, Type> + extends ExtensionLite<ContainingType, Type> { + + /** Returns the descriptor of the extension. */ + public abstract Descriptors.FieldDescriptor getDescriptor(); + + /** Returns whether or not this extension is a Lite Extension. */ + @Override + final boolean isLite() { + return false; + } + + // All the methods below are extension implementation details. + + /** + * The API type that the extension is used for. + */ + protected enum ExtensionType { + IMMUTABLE, + MUTABLE, + PROTO1, + } + + protected ExtensionType getExtensionType() { + // TODO(liujisi): make this abstract after we fix proto1. + return ExtensionType.IMMUTABLE; + } + + /** + * Type of a message extension. + */ + public enum MessageType { + PROTO1, + PROTO2, + } + + /** + * If the extension is a message extension (i.e., getLiteType() == MESSAGE), + * returns the type of the message, otherwise undefined. + */ + public MessageType getMessageType() { + return MessageType.PROTO2; + } + + protected abstract Object fromReflectionType(Object value); + protected abstract Object singularFromReflectionType(Object value); + protected abstract Object toReflectionType(Object value); + protected abstract Object singularToReflectionType(Object value); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionLite.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionLite.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionLite.java new file mode 100644 index 0000000..cb47243 --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionLite.java @@ -0,0 +1,63 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +/** + * Lite interface that generated extensions implement. + * <p> + * Methods are for use by generated code only. You can hold a reference to + * extensions using this type name. + */ +public abstract class ExtensionLite<ContainingType extends MessageLite, Type> { + + /** Returns the field number of the extension. */ + public abstract int getNumber(); + + /** Returns the type of the field. */ + public abstract WireFormat.FieldType getLiteType(); + + /** Returns whether it is a repeated field. */ + public abstract boolean isRepeated(); + + /** Returns the default value of the extension field. */ + public abstract Type getDefaultValue(); + + /** + * Returns the default instance of the extension field, if it's a message + * extension. + */ + public abstract MessageLite getMessageDefaultInstance(); + + /** Returns whether or not this extension is a Lite Extension. */ + boolean isLite() { + return true; + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistry.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistry.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistry.java new file mode 100644 index 0000000..3bc5977 --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistry.java @@ -0,0 +1,397 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +import org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.Descriptor; +import org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * A table of known extensions, searchable by name or field number. When + * parsing a protocol message that might have extensions, you must provide + * an {@code ExtensionRegistry} in which you have registered any extensions + * that you want to be able to parse. Otherwise, those extensions will just + * be treated like unknown fields. + * + * <p>For example, if you had the {@code .proto} file: + * + * <pre> + * option java_class = "MyProto"; + * + * message Foo { + * extensions 1000 to max; + * } + * + * extend Foo { + * optional int32 bar; + * } + * </pre> + * + * Then you might write code like: + * + * <pre> + * ExtensionRegistry registry = ExtensionRegistry.newInstance(); + * registry.add(MyProto.bar); + * MyProto.Foo message = MyProto.Foo.parseFrom(input, registry); + * </pre> + * + * <p>Background: + * + * <p>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. + * + * <p>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 [email protected] Kenton Varda + */ +public class ExtensionRegistry extends ExtensionRegistryLite { + /** Construct a new, empty instance. */ + public static ExtensionRegistry newInstance() { + return new ExtensionRegistry(); + } + + /** Get the unmodifiable singleton empty instance. */ + public static ExtensionRegistry getEmptyRegistry() { + return EMPTY_REGISTRY; + } + + + /** Returns an unmodifiable view of the registry. */ + @Override + public ExtensionRegistry getUnmodifiable() { + return new ExtensionRegistry(this); + } + + /** A (Descriptor, Message) pair, returned by lookup methods. */ + public static final class ExtensionInfo { + /** The extension's descriptor. */ + public final FieldDescriptor descriptor; + + /** + * A default instance of the extension's type, if it has a message type. + * Otherwise, {@code null}. + */ + public final Message defaultInstance; + + private ExtensionInfo(final FieldDescriptor descriptor) { + this.descriptor = descriptor; + defaultInstance = null; + } + private ExtensionInfo(final FieldDescriptor descriptor, + final Message defaultInstance) { + this.descriptor = descriptor; + this.defaultInstance = defaultInstance; + } + } + + /** + * Deprecated. Use {@link #findImmutableExtensionByName(String)} instead. + */ + 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. + * + * @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. + * + * @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)} + */ + public ExtensionInfo findExtensionByNumber( + final Descriptor containingType, final int fieldNumber) { + return findImmutableExtensionByNumber(containingType, fieldNumber); + } + + /** + * Find an extension by containing type and field number for immutable APIs. + * + * @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)); + } + + /** + * Find an extension by containing type and field number for mutable APIs. + * + * @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)); + } + + /** + * 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. + */ + public Set<ExtensionInfo> getAllMutableExtensionsByExtendedType(final String fullName) { + HashSet<ExtensionInfo> extensions = new HashSet<ExtensionInfo>(); + for (DescriptorIntPair pair : mutableExtensionsByNumber.keySet()) { + if (pair.descriptor.getFullName().equals(fullName)) { + extensions.add(mutableExtensionsByNumber.get(pair)); + } + } + return extensions; + } + + /** + * Find all extensions for immutable 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. + */ + public Set<ExtensionInfo> getAllImmutableExtensionsByExtendedType(final String fullName) { + HashSet<ExtensionInfo> extensions = new HashSet<ExtensionInfo>(); + for (DescriptorIntPair pair : immutableExtensionsByNumber.keySet()) { + if (pair.descriptor.getFullName().equals(fullName)) { + extensions.add(immutableExtensionsByNumber.get(pair)); + } + } + return extensions; + } + + /** Add an extension from a generated file to the registry. */ + public void add(final Extension<?, ?> extension) { + if (extension.getExtensionType() != Extension.ExtensionType.IMMUTABLE && + extension.getExtensionType() != Extension.ExtensionType.MUTABLE) { + // do not support other extension types. ignore + return; + } + add(newExtensionInfo(extension), extension.getExtensionType()); + } + + /** Add an extension from a generated file to the registry. */ + public void add(final GeneratedMessage.GeneratedExtension<?, ?> extension) { + add((Extension<?, ?>) extension); + } + + static ExtensionInfo newExtensionInfo(final Extension<?, ?> extension) { + if (extension.getDescriptor().getJavaType() == + FieldDescriptor.JavaType.MESSAGE) { + if (extension.getMessageDefaultInstance() == null) { + throw new IllegalStateException( + "Registered message-type extension had null default instance: " + + extension.getDescriptor().getFullName()); + } + return new ExtensionInfo(extension.getDescriptor(), + (Message) extension.getMessageDefaultInstance()); + } else { + return new ExtensionInfo(extension.getDescriptor(), null); + } + } + + /** Add a non-message-type extension to the registry by descriptor. */ + public void add(final FieldDescriptor type) { + if (type.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + throw new IllegalArgumentException( + "ExtensionRegistry.add() must be provided a default instance when " + + "adding an embedded message extension."); + } + ExtensionInfo info = new ExtensionInfo(type, null); + add(info, Extension.ExtensionType.IMMUTABLE); + add(info, Extension.ExtensionType.MUTABLE); + } + + /** Add a message-type extension to the registry by descriptor. */ + public void add(final FieldDescriptor type, final Message defaultInstance) { + if (type.getJavaType() != FieldDescriptor.JavaType.MESSAGE) { + throw new IllegalArgumentException( + "ExtensionRegistry.add() provided a default instance for a " + + "non-message extension."); + } + add(new ExtensionInfo(type, defaultInstance), + Extension.ExtensionType.IMMUTABLE); + } + + // ================================================================= + // Private stuff. + + private ExtensionRegistry() { + this.immutableExtensionsByName = new HashMap<String, ExtensionInfo>(); + this.mutableExtensionsByName = new HashMap<String, ExtensionInfo>(); + this.immutableExtensionsByNumber = + new HashMap<DescriptorIntPair, ExtensionInfo>(); + this.mutableExtensionsByNumber = + new HashMap<DescriptorIntPair, ExtensionInfo>(); + } + + private ExtensionRegistry(ExtensionRegistry other) { + super(other); + this.immutableExtensionsByName = + Collections.unmodifiableMap(other.immutableExtensionsByName); + this.mutableExtensionsByName = + Collections.unmodifiableMap(other.mutableExtensionsByName); + this.immutableExtensionsByNumber = + Collections.unmodifiableMap(other.immutableExtensionsByNumber); + this.mutableExtensionsByNumber = + Collections.unmodifiableMap(other.mutableExtensionsByNumber); + } + + private final Map<String, ExtensionInfo> immutableExtensionsByName; + private final Map<String, ExtensionInfo> mutableExtensionsByName; + private final Map<DescriptorIntPair, ExtensionInfo> immutableExtensionsByNumber; + private final Map<DescriptorIntPair, ExtensionInfo> mutableExtensionsByNumber; + + ExtensionRegistry(boolean empty) { + super(EMPTY_REGISTRY_LITE); + this.immutableExtensionsByName = + Collections.<String, ExtensionInfo>emptyMap(); + this.mutableExtensionsByName = + Collections.<String, ExtensionInfo>emptyMap(); + this.immutableExtensionsByNumber = + Collections.<DescriptorIntPair, ExtensionInfo>emptyMap(); + this.mutableExtensionsByNumber = + Collections.<DescriptorIntPair, ExtensionInfo>emptyMap(); + } + static final ExtensionRegistry EMPTY_REGISTRY = new ExtensionRegistry(true); + + private void add( + final ExtensionInfo extension, + final Extension.ExtensionType extensionType) { + if (!extension.descriptor.isExtension()) { + throw new IllegalArgumentException( + "ExtensionRegistry.add() was given a FieldDescriptor for a regular " + + "(non-extension) field."); + } + + Map<String, ExtensionInfo> extensionsByName; + Map<DescriptorIntPair, ExtensionInfo> extensionsByNumber; + switch (extensionType) { + case IMMUTABLE: + extensionsByName = immutableExtensionsByName; + extensionsByNumber = immutableExtensionsByNumber; + break; + case MUTABLE: + extensionsByName = mutableExtensionsByName; + extensionsByNumber = mutableExtensionsByNumber; + break; + default: + // Ignore the unknown supported type. + return; + } + + extensionsByName.put(extension.descriptor.getFullName(), extension); + extensionsByNumber.put( + new DescriptorIntPair(extension.descriptor.getContainingType(), + extension.descriptor.getNumber()), + extension); + + final FieldDescriptor field = extension.descriptor; + if (field.getContainingType().getOptions().getMessageSetWireFormat() && + field.getType() == FieldDescriptor.Type.MESSAGE && + field.isOptional() && + field.getExtensionScope() == field.getMessageType()) { + // This is an extension of a MessageSet type defined within the extension + // type's own scope. For backwards-compatibility, allow it to be looked + // up by type name. + extensionsByName.put(field.getMessageType().getFullName(), extension); + } + } + + /** A (GenericDescriptor, int) pair, used as a map key. */ + private static final class DescriptorIntPair { + private final Descriptor descriptor; + private final int number; + + DescriptorIntPair(final Descriptor descriptor, final int number) { + this.descriptor = descriptor; + this.number = number; + } + + @Override + public int hashCode() { + return descriptor.hashCode() * ((1 << 16) - 1) + number; + } + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof DescriptorIntPair)) { + return false; + } + final DescriptorIntPair other = (DescriptorIntPair)obj; + return descriptor == other.descriptor && number == other.number; + } + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryFactory.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryFactory.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryFactory.java new file mode 100644 index 0000000..85e6668 --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryFactory.java @@ -0,0 +1,95 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +import static org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistryLite.EMPTY_REGISTRY_LITE; + +/** + * A factory object to create instances of {@link ExtensionRegistryLite}. + * + * <p> + * 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 = "org.apache.hadoop.hbase.shaded.com.google.protobuf.ExtensionRegistry"; + + /* Visible for Testing + @Nullable */ + static final Class<?> EXTENSION_REGISTRY_CLASS = reflectExtensionRegistry(); + + /* @Nullable */ + static Class<?> reflectExtensionRegistry() { + try { + return Class.forName(FULL_REGISTRY_CLASS_NAME); + } catch (ClassNotFoundException e) { + // The exception allocation is potentially expensive on Android (where it can be triggered + // many times at start up). Is there a way to ameliorate this? + return null; + } + } + + /** Construct a new, empty instance. */ + public static ExtensionRegistryLite create() { + if (EXTENSION_REGISTRY_CLASS != null) { + try { + return invokeSubclassFactory("newInstance"); + } catch (Exception e) { + // return a Lite registry. + } + } + return new ExtensionRegistryLite(); + } + + /** Get the unmodifiable singleton empty instance. */ + public static ExtensionRegistryLite createEmpty() { + if (EXTENSION_REGISTRY_CLASS != null) { + try { + return invokeSubclassFactory("getEmptyRegistry"); + } catch (Exception e) { + // return a Lite registry. + } + } + return EMPTY_REGISTRY_LITE; + } + + static boolean isFullRegistry(ExtensionRegistryLite registry) { + return EXTENSION_REGISTRY_CLASS != null + && EXTENSION_REGISTRY_CLASS.isAssignableFrom(registry.getClass()); + } + + private static final ExtensionRegistryLite invokeSubclassFactory(String methodName) + throws Exception { + return (ExtensionRegistryLite) EXTENSION_REGISTRY_CLASS + .getMethod(methodName).invoke(null); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/401aa064/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryLite.java ---------------------------------------------------------------------- diff --git a/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryLite.java b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryLite.java new file mode 100644 index 0000000..878e46a --- /dev/null +++ b/hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/shaded/com/google/protobuf/ExtensionRegistryLite.java @@ -0,0 +1,226 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package org.apache.hadoop.hbase.shaded.com.google.protobuf; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Equivalent to {@link ExtensionRegistry} but supports only "lite" types. + * <p> + * 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. + * <p> + * 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: + * <pre> + * Extended type Inner type Extension Use registry + * ======================================================================= + * lite lite lite ExtensionRegistryLite + * lite regular lite ExtensionRegistry + * regular regular regular ExtensionRegistry + * all other combinations not supported + * </pre> + * <p> + * 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 [email protected] Kenton Varda + */ +public class ExtensionRegistryLite { + + // Set true to enable lazy parsing feature for MessageSet. + // + // TODO(xiangl): Now we use a global flag to control whether enable lazy + // parsing feature for MessageSet, which may be too crude for some + // applications. Need to support this feature on smaller granularity. + private static volatile boolean eagerlyParseMessageSets = false; + + // Visible for testing. + static final String EXTENSION_CLASS_NAME = "org.apache.hadoop.hbase.shaded.com.google.protobuf.Extension"; + + /* @Nullable */ + static Class<?> resolveExtensionClass() { + try { + return Class.forName(EXTENSION_CLASS_NAME); + } catch (ClassNotFoundException e) { + // See comment in ExtensionRegistryFactory on the potential expense of this. + return null; + } + } + + /* @Nullable */ + private static final Class<?> extensionClass = resolveExtensionClass(); + + public static boolean isEagerlyParseMessageSets() { + return eagerlyParseMessageSets; + } + + public static void setEagerlyParseMessageSets(boolean isEagerlyParse) { + eagerlyParseMessageSets = isEagerlyParse; + } + + /** + * Construct a new, empty instance. + * + * <p> + * This may be an {@code ExtensionRegistry} if the full (non-Lite) proto libraries are available. + */ + public static ExtensionRegistryLite newInstance() { + return ExtensionRegistryFactory.create(); + } + + /** + * 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(); + } + + /** Returns an unmodifiable view of the registry. */ + public ExtensionRegistryLite getUnmodifiable() { + return new ExtensionRegistryLite(this); + } + + /** + * Find an extension by containing type and field number. + * + * @return Information about the extension if found, or {@code null} + * otherwise. + */ + @SuppressWarnings("unchecked") + public <ContainingType extends MessageLite> + GeneratedMessageLite.GeneratedExtension<ContainingType, ?> + findLiteExtensionByNumber( + final ContainingType containingTypeDefaultInstance, + final int fieldNumber) { + return (GeneratedMessageLite.GeneratedExtension<ContainingType, ?>) + extensionsByNumber.get( + new ObjectIntPair(containingTypeDefaultInstance, fieldNumber)); + } + + /** Add an extension from a lite generated file to the registry. */ + public final void add( + final GeneratedMessageLite.GeneratedExtension<?, ?> extension) { + extensionsByNumber.put( + new ObjectIntPair(extension.getContainingTypeDefaultInstance(), + extension.getNumber()), + extension); + } + + /** + * Add an extension from a lite generated file to the registry only if it is + * a non-lite extension i.e. {@link GeneratedMessageLite.GeneratedExtension}. */ + public final void add(ExtensionLite<?, ?> extension) { + if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) { + add((GeneratedMessageLite.GeneratedExtension<?, ?>) extension); + } + if (ExtensionRegistryFactory.isFullRegistry(this)) { + try { + this.getClass().getMethod("add", extensionClass).invoke(this, extension); + } catch (Exception e) { + throw new IllegalArgumentException( + String.format("Could not invoke ExtensionRegistry#add for %s", extension), e); + } + } + } + + // ================================================================= + // Private stuff. + + // Constructors are package-private so that ExtensionRegistry can subclass + // this. + + ExtensionRegistryLite() { + this.extensionsByNumber = + new HashMap<ObjectIntPair, + GeneratedMessageLite.GeneratedExtension<?, ?>>(); + } + static final ExtensionRegistryLite EMPTY_REGISTRY_LITE = + new ExtensionRegistryLite(true); + + ExtensionRegistryLite(ExtensionRegistryLite other) { + if (other == EMPTY_REGISTRY_LITE) { + this.extensionsByNumber = Collections.emptyMap(); + } else { + this.extensionsByNumber = + Collections.unmodifiableMap(other.extensionsByNumber); + } + } + + private final Map<ObjectIntPair, + GeneratedMessageLite.GeneratedExtension<?, ?>> + extensionsByNumber; + + ExtensionRegistryLite(boolean empty) { + this.extensionsByNumber = Collections.emptyMap(); + } + + /** A (Object, int) pair, used as a map key. */ + private static final class ObjectIntPair { + private final Object object; + private final int number; + + ObjectIntPair(final Object object, final int number) { + this.object = object; + this.number = number; + } + + @Override + public int hashCode() { + return System.identityHashCode(object) * ((1 << 16) - 1) + number; + } + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof ObjectIntPair)) { + return false; + } + final ObjectIntPair other = (ObjectIntPair)obj; + return object == other.object && number == other.number; + } + } +}
