当前位置: 首页>>代码示例>>Java>>正文


Java FieldDescriptor.getMessageType方法代码示例

本文整理汇总了Java中com.google.protobuf.Descriptors.FieldDescriptor.getMessageType方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptor.getMessageType方法的具体用法?Java FieldDescriptor.getMessageType怎么用?Java FieldDescriptor.getMessageType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.Descriptors.FieldDescriptor的用法示例。


在下文中一共展示了FieldDescriptor.getMessageType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mergeMapField

import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
private void mergeMapField(FieldDescriptor field, JsonElement json, Message.Builder builder)
    throws InvalidProtocolBufferException {
  if (!(json instanceof JsonObject)) {
    throw new InvalidProtocolBufferException("Expect a map object but found: " + json);
  }
  Descriptor type = field.getMessageType();
  FieldDescriptor keyField = type.findFieldByName("key");
  FieldDescriptor valueField = type.findFieldByName("value");
  if (keyField == null || valueField == null) {
    throw new InvalidProtocolBufferException("Invalid map field: " + field.getFullName());
  }
  JsonObject object = (JsonObject) json;
  for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
    Message.Builder entryBuilder = builder.newBuilderForField(field);
    Object key = parseFieldValue(keyField, new JsonPrimitive(entry.getKey()), entryBuilder);
    Object value = parseFieldValue(valueField, entry.getValue(), entryBuilder);
    if (value == null) {
      throw new InvalidProtocolBufferException("Map value cannot be null.");
    }
    entryBuilder.setField(keyField, key);
    entryBuilder.setField(valueField, value);
    builder.addRepeatedField(field, entryBuilder.build());
  }
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:25,代码来源:JsonFormat.java

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

示例3: ProtoFieldInfo

import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
ProtoFieldInfo(FieldDescriptor field, Message containingPrototype) {
  this.field = checkNotNull(field, "field");
  this.containingPrototype = checkNotNull(containingPrototype, "containingPrototype");
  builderClass = containingPrototype.newBuilderForType().getClass();

  camelCaseName = underscoresToUpperCamelCase(field.getName());

  if (field.isMapField()) {
    Descriptor mapType = field.getMessageType();
    mapKeyField = new ProtoFieldInfo(mapType.findFieldByName("key"), containingPrototype);
    mapValueField = new ProtoFieldInfo(mapType.findFieldByName("value"), containingPrototype);
  } else {
    mapKeyField = null;
    mapValueField = null;
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:17,代码来源:ProtoFieldInfo.java

示例4: newBuilderForField

import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
public Builder newBuilderForField(FieldDescriptor field) {
  verifyContainingType(field);

  if (field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) {
    throw new IllegalArgumentException(
      "newBuilderForField is only valid for fields with message type.");
  }

  return new Builder(field.getMessageType());
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:11,代码来源:DynamicMessage.java

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

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

示例7: printMapFieldValue

import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private void printMapFieldValue(FieldDescriptor field, Object value) throws IOException {
  Descriptor type = field.getMessageType();
  FieldDescriptor keyField = type.findFieldByName("key");
  FieldDescriptor valueField = type.findFieldByName("value");
  if (keyField == null || valueField == null) {
    throw new InvalidProtocolBufferException("Invalid map field.");
  }
  generator.print("{" + blankOrNewLine);
  generator.indent();
  boolean printedElement = false;
  for (Object element : (List) value) {
    Message entry = (Message) element;
    Object entryKey = entry.getField(keyField);
    Object entryValue = entry.getField(valueField);
    if (printedElement) {
      generator.print("," + blankOrNewLine);
    } else {
      printedElement = true;
    }
    // Key fields are always double-quoted.
    printSingleFieldValue(keyField, entryKey, true);
    generator.print(":" + blankOrSpace);
    printSingleFieldValue(valueField, entryValue);
  }
  if (printedElement) {
    generator.print(blankOrNewLine);
  }
  generator.outdent();
  generator.print("}");
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:32,代码来源:JsonFormat.java

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

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

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

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

示例12: mustSkipNull

import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
/**
 * Determines whether we skip processing of the field if it is null. We usually skip null values
 * in the JSON to treat them as default, but must actually process the null for {@link Value} and
 * {@link NullValue} because it means their value must be set.
 */
private boolean mustSkipNull(FieldDescriptor field) {
  if (field.isRepeated()) {
    return true;
  }
  if (field.getJavaType() == JavaType.MESSAGE
      && field.getMessageType() == Value.getDescriptor()) {
    return false;
  }
  if (field.getJavaType() == JavaType.ENUM && field.getEnumType() == NullValue.getDescriptor()) {
    return false;
  }
  return true;
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:19,代码来源:DoParse.java


注:本文中的com.google.protobuf.Descriptors.FieldDescriptor.getMessageType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。