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


Java FieldDescriptor.isOptional方法代碼示例

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


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

示例1: add

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private void add(final ExtensionInfo extension) {
  if (!extension.descriptor.isExtension()) {
    throw new IllegalArgumentException(
      "ExtensionRegistry.add() was given a FieldDescriptor for a regular " +
      "(non-extension) field.");
  }

  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);
  }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:25,代碼來源:ExtensionRegistry.java

示例2: printSingleField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private void printSingleField(FieldDescriptor field, Object value, 
        XMLStreamWriter generator) throws XMLStreamException, IOException {
    
    if (field.isExtension()) {
        generator.writeStartElement(EXTENSION_ELEMENT);
        // 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.writeAttribute(EXTENSION_TYPE, field.getMessageType().getFullName());
        } else {
        	// extensions will have '.' in them, while normal fields wont..
        	generator.writeAttribute(EXTENSION_TYPE, field.getFullName());
        }
    } else {
        if (field.getType() == FieldDescriptor.Type.GROUP) {
            // Groups must be serialized with their original capitalization.
            generator.writeStartElement(field.getMessageType().getName());
        } else {
            generator.writeStartElement(field.getName());
        }
    }

    
    // Done with the name, on to the value
    printFieldValue(field, value, generator);
    
    generator.writeEndElement();
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:32,代碼來源:XmlJavaxFormat.java

示例3: 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

示例4: 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,項目名稱:sstore-soft,代碼行數:42,代碼來源:TextFormat.java

示例5: printSingleField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private void printSingleField(FieldDescriptor field, Object value, XmlGenerator generator) throws IOException {
    if (field.isExtension()) {
        generator.print("<extension type=\"");
        // 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(">");
    }

    printFieldValue(field, value, generator);

    if (!field.isExtension()) {
        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(">");
    } else {
        generator.print("</extension>");
    }

}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:42,代碼來源:XmlFormat.java

示例6: printSingleField

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
private void printSingleField(FieldDescriptor field,
                                     Object value,
                                     HtmlGenerator generator) throws IOException {
    if (field.isExtension()) {
        generator.print("[<span style=\"");
        generator.print(FIELD_NAME_STYLE);
        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("</span>]");
    } else {
        generator.print("<span style=\"");
        generator.print(FIELD_NAME_STYLE);
        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("</span>");
    }

    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        generator.print(" <span style=\"color: red;\">{</span><br/>");
        generator.indent();
    } else {
        generator.print(": ");
    }

    printFieldValue(field, value, generator);

    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        generator.outdent();
        generator.print("<span style=\"color: red;\">}</span>");
    }
    generator.print("<br/>");
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:46,代碼來源:HtmlFormat.java

示例7: 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


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