當前位置: 首頁>>代碼示例>>Java>>正文


Java FieldDescriptor.isExtension方法代碼示例

本文整理匯總了Java中com.google.protobuf.Descriptors.FieldDescriptor.isExtension方法的典型用法代碼示例。如果您正苦於以下問題:Java FieldDescriptor.isExtension方法的具體用法?Java FieldDescriptor.isExtension怎麽用?Java FieldDescriptor.isExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.protobuf.Descriptors.FieldDescriptor的用法示例。


在下文中一共展示了FieldDescriptor.isExtension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeTo

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
public void writeTo(final CodedOutputStream output) throws IOException {
  final boolean isMessageSet =
      getDescriptorForType().getOptions().getMessageSetWireFormat();

  for (final Map.Entry<FieldDescriptor, Object> entry :
      getAllFields().entrySet()) {
    final FieldDescriptor field = entry.getKey();
    final Object value = entry.getValue();
    if (isMessageSet && field.isExtension() &&
        field.getType() == FieldDescriptor.Type.MESSAGE &&
        !field.isRepeated()) {
      output.writeMessageSetExtension(field.getNumber(), (Message) value);
    } else {
      FieldSet.writeField(field, value, output);
    }
  }

  final UnknownFieldSet unknownFields = getUnknownFields();
  if (isMessageSet) {
    unknownFields.writeAsMessageSetTo(output);
  } else {
    unknownFields.writeTo(output);
  }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:25,代碼來源:AbstractMessage.java

示例2: getField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:21,代碼來源:GeneratedMessage.java

示例3: subMessagePrefix

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private static String subMessagePrefix(final String prefix,
                                       final FieldDescriptor field,
                                       final int index) {
  final StringBuilder result = new StringBuilder(prefix);
  if (field.isExtension()) {
    result.append('(')
          .append(field.getFullName())
          .append(')');
  } else {
    result.append(field.getName());
  }
  if (index != -1) {
    result.append('[')
          .append(index)
          .append(']');
  }
  result.append('.');
  return result.toString();
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:20,代碼來源:AbstractMessage.java

示例4: hasField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
@Override
public boolean hasField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    return extensions.hasField(field);
  } else {
    return super.hasField(field);
  }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:10,代碼來源:GeneratedMessage.java

示例5: getRepeatedFieldCount

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
@Override
public int getRepeatedFieldCount(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    return extensions.getRepeatedFieldCount(field);
  } else {
    return super.getRepeatedFieldCount(field);
  }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:10,代碼來源:GeneratedMessage.java

示例6: setField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
@Override
public BuilderType setField(final FieldDescriptor field,
                            final Object value) {
  if (field.isExtension()) {
    final ExtendableMessage<MessageType> message = internalGetResult();
    message.verifyContainingType(field);
    message.extensions.setField(field, value);
    return (BuilderType) this;
  } else {
    return super.setField(field, value);
  }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:13,代碼來源:GeneratedMessage.java

示例7: clearField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
@Override
public BuilderType clearField(final FieldDescriptor field) {
  if (field.isExtension()) {
    final ExtendableMessage<MessageType> message = internalGetResult();
    message.verifyContainingType(field);
    message.extensions.clearField(field);
    return (BuilderType) this;
  } else {
    return super.clearField(field);
  }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:12,代碼來源:GeneratedMessage.java

示例8: getField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
/** Get the FieldAccessor for a particular field. */
private FieldAccessor getField(final FieldDescriptor field) {
  if (field.getContainingType() != descriptor) {
    throw new IllegalArgumentException(
      "FieldDescriptor does not match message type.");
  } else if (field.isExtension()) {
    // If this type had extensions, it would subclass ExtendableMessage,
    // which overrides the reflection interface to handle extensions.
    throw new IllegalArgumentException(
      "This type does not have extensions.");
  }
  return fields[field.getIndex()];
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:14,代碼來源:GeneratedMessage.java

示例9: addRepeatedField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
@Override
public BuilderType addRepeatedField(final FieldDescriptor field,
                                    final Object value) {
  if (field.isExtension()) {
    final ExtendableMessage<MessageType> message = internalGetResult();
    message.verifyContainingType(field);
    message.extensions.addRepeatedField(field, value);
    return (BuilderType) this;
  } else {
    return super.addRepeatedField(field, value);
  }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:13,代碼來源:GeneratedMessage.java

示例10: internalInit

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
/** For use by generated code only. */
public void internalInit(final FieldDescriptor descriptor,
                         final Class type) {
  if (this.descriptor != null) {
    throw new IllegalStateException("Already initialized.");
  }

  if (!descriptor.isExtension()) {
    throw new IllegalArgumentException(
      "GeneratedExtension given a regular (non-extension) field.");
  }

  this.descriptor = descriptor;
  this.type = type;

  switch (descriptor.getJavaType()) {
    case MESSAGE:
      enumValueOf = null;
      enumGetValueDescriptor = null;
      messageDefaultInstance =
        (Message) invokeOrDie(getMethodOrDie(type, "getDefaultInstance"),
                              null);
      if (messageDefaultInstance == null) {
        throw new IllegalStateException(
            type.getName() + ".getDefaultInstance() returned null.");
      }
      break;
    case ENUM:
      enumValueOf = getMethodOrDie(type, "valueOf",
                                   EnumValueDescriptor.class);
      enumGetValueDescriptor = getMethodOrDie(type, "getValueDescriptor");
      messageDefaultInstance = null;
      break;
    default:
      enumValueOf = null;
      enumGetValueDescriptor = null;
      messageDefaultInstance = null;
      break;
  }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:41,代碼來源:GeneratedMessage.java

示例11: getSerializedSize

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
public int getSerializedSize() {
  int size = memoizedSize;
  if (size != -1) {
    return size;
  }

  size = 0;
  final boolean isMessageSet =
      getDescriptorForType().getOptions().getMessageSetWireFormat();

  for (final Map.Entry<FieldDescriptor, Object> entry :
      getAllFields().entrySet()) {
    final FieldDescriptor field = entry.getKey();
    final Object value = entry.getValue();
    if (isMessageSet && field.isExtension() &&
        field.getType() == FieldDescriptor.Type.MESSAGE &&
        !field.isRepeated()) {
      size += CodedOutputStream.computeMessageSetExtensionSize(
          field.getNumber(), (Message) value);
    } else {
      size += FieldSet.computeFieldSize(field, value);
    }
  }

  final UnknownFieldSet unknownFields = getUnknownFields();
  if (isMessageSet) {
    size += unknownFields.getSerializedSizeAsMessageSet();
  } else {
    size += unknownFields.getSerializedSize();
  }

  memoizedSize = size;
  return size;
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:35,代碼來源:AbstractMessage.java

示例12: printSingleField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private void printSingleField(FieldDescriptor field,
                                     Object value,
                                     JsonGenerator generator) throws IOException {
    if (field.isExtension()) {
        // We special-case MessageSet elements for compatibility with proto1.
        if (field.getContainingType().getOptions().getMessageSetWireFormat()
            && (field.getType() == FieldDescriptor.Type.MESSAGE) && (field.isOptional())
            // object equality
            && (field.getExtensionScope() == field.getMessageType())) {
            generator.writeFieldName(field.getMessageType().getFullName());
        } else {
        	// extensions will have '.' in them, while normal fields wont..
        	generator.writeFieldName(field.getFullName());
        }
    } else {
        if (field.getType() == FieldDescriptor.Type.GROUP) {
            // Groups must be serialized with their original capitalization.
            generator.writeFieldName(field.getMessageType().getName());
        } else {
            generator.writeFieldName(field.getName());
        }
    }

    // Done with the name, on to the value
    if (field.isRepeated()) {
        // Repeated field. Print each element.
        generator.writeStartArray();
        for (Iterator<?> iter = ((List<?>) value).iterator(); iter.hasNext();) {
            printFieldValue(field, iter.next(), generator);
        }
        generator.writeEndArray();
    } else {
        printFieldValue(field, value, generator);
    }
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:36,代碼來源:JsonJacksonFormat.java

示例13: getRepeatedField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
@Override
public Object getRepeatedField(final FieldDescriptor field,
                               final int index) {
  if (field.isExtension()) {
    verifyContainingType(field);
    return extensions.getRepeatedField(field, index);
  } else {
    return super.getRepeatedField(field, index);
  }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:11,代碼來源:GeneratedMessage.java

示例14: printSingleField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private void printSingleField(FieldDescriptor field,
                                     Object value,
                                     JsonGenerator generator) throws IOException {
    if (field.isExtension()) {
        generator.print("\"");
        // We special-case MessageSet elements for compatibility with proto1.
        if (field.getContainingType().getOptions().getMessageSetWireFormat()
            && (field.getType() == FieldDescriptor.Type.MESSAGE) && (field.isOptional())
            // object equality
            && (field.getExtensionScope() == field.getMessageType())) {
            generator.print(field.getMessageType().getFullName());
        } else {
            generator.print(field.getFullName());
        }
        generator.print("\"");
    } else {
        generator.print("\"");
        if (field.getType() == FieldDescriptor.Type.GROUP) {
            // Groups must be serialized with their original capitalization.
            generator.print(field.getMessageType().getName());
        } else {
            generator.print(field.getName());
        }
        generator.print("\"");
    }

    // Done with the name, on to the value

    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        generator.print(": ");
        generator.indent();
    } else {
        generator.print(": ");
    }


    if (field.isRepeated()) {
        // Repeated field. Print each element.
        generator.print("[");
        for (Iterator<?> iter = ((List<?>) value).iterator(); iter.hasNext();) {
            printFieldValue(field, iter.next(), generator);
            if (iter.hasNext()) {
                generator.print(",");
            }
        }
        generator.print("]");
    } else {
        printFieldValue(field, value, generator);
        if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
            generator.outdent();
        }
    }
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:54,代碼來源:JsonFormat.java

示例15: printSingleField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private static void printSingleField(final FieldDescriptor field,
                                     final Object value,
                                     final TextGenerator generator)
                                     throws IOException {
  if (field.isExtension()) {
    generator.print("[");
    // We special-case MessageSet elements for compatibility with proto1.
    if (field.getContainingType().getOptions().getMessageSetWireFormat()
        && (field.getType() == FieldDescriptor.Type.MESSAGE)
        && (field.isOptional())
        // object equality
        && (field.getExtensionScope() == field.getMessageType())) {
      generator.print(field.getMessageType().getFullName());
    } else {
      generator.print(field.getFullName());
    }
    generator.print("]");
  } else {
    if (field.getType() == FieldDescriptor.Type.GROUP) {
      // Groups must be serialized with their original capitalization.
      generator.print(field.getMessageType().getName());
    } else {
      generator.print(field.getName());
    }
  }

  if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
    generator.print(" {\n");
    generator.indent();
  } else {
    generator.print(": ");
  }

  printFieldValue(field, value, generator);

  if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
    generator.outdent();
    generator.print("}");
  }
  generator.print("\n");
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:42,代碼來源:TextFormat.java


注:本文中的com.google.protobuf.Descriptors.FieldDescriptor.isExtension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。