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


Java Message.getDescriptorForType方法代码示例

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


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

示例1: findForPrototype

import com.google.protobuf.Message; //导入方法依赖的package包/类
/**
 * Returns the {@link TypeSpecificMarshaller} that can marshall protobufs with the same type as
 * {@code prototype}.
 */
TypeSpecificMarshaller<?> findForPrototype(Message prototype) {
  TypeSpecificMarshaller<?> marshaller = descriptorRegistry.get(prototype.getDescriptorForType());
  if (marshaller == null) {
    throw new IllegalArgumentException(
        "Could not find marshaller for type: "
            + prototype.getDescriptorForType()
            + ". Has it been registered?");
  }
  return marshaller;
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:15,代码来源:MarshallerRegistry.java

示例2: getProtobufClassFieldDescriptions

import com.google.protobuf.Message; //导入方法依赖的package包/类
protected String getProtobufClassFieldDescriptions(Class<? extends Message> messageClass)
        throws Exception {
    StringBuilder sb = new StringBuilder();
    Constructor<?> constructor = null;
    try {
        constructor = messageClass.getDeclaredConstructor();
    } catch (NoSuchMethodException nsmex) {
        //Issue #35
        logger.info("Unsupported protobuf field: {}", messageClass.getName());
        return sb.toString();
    }
    constructor.setAccessible(true);
    Object instance = constructor.newInstance();
    Message.Builder builder = ((Message)instance).newBuilderForType();
    Message message = builder.build();

    Descriptors.Descriptor requestDesc = message.getDescriptorForType();
    List<Descriptors.FieldDescriptor> requestFields = requestDesc.getFields();
    Iterator<Descriptors.FieldDescriptor> iter = requestFields.iterator();
    while (iter.hasNext()) {
        Descriptors.FieldDescriptor fd = iter.next();
        //TODO: deal with repeated fields
        sb.append("{\"name\":\"");
        sb.append(fd.getName());
        sb.append("\",\"type\":\"");
        if (fd.getType().toString().equalsIgnoreCase("message")) {
            sb.append(getLastComponent(fd.getMessageType().getFullName()));
            sb.append("\",\"values\":[");
            Descriptors.FieldDescriptor childDescriptor = requestDesc.findFieldByName(fd.getName());
            Message.Builder subMessageBuilder = builder.newBuilderForField(childDescriptor);
            Message subMessage = subMessageBuilder.build();
            sb.append(getProtobufClassFieldDescriptions(subMessage.getClass()));
            sb.append("]}");
        } else {
            sb.append(fd.getType().toString().toLowerCase());
            sb.append("\",\"values\":null}");
        }
        if (iter.hasNext()) {
            sb.append(",");
        }
    }
    return sb.toString();
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:44,代码来源:RegistrationManager.java

示例3: DoWrite

import com.google.protobuf.Message; //导入方法依赖的package包/类
DoWrite(Message prototype, boolean includeDefaults) {
  this.prototype = prototype;
  this.messageClass = prototype.getClass();
  this.descriptor = prototype.getDescriptorForType();
  this.includeDefaults = includeDefaults;
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:7,代码来源:DoWrite.java

示例4: DoParse

import com.google.protobuf.Message; //导入方法依赖的package包/类
DoParse(Message prototype, boolean ignoringUnknownFields) {
  this.prototype = prototype;
  builderClass = prototype.newBuilderForType().getClass();
  descriptor = prototype.getDescriptorForType();
  this.ignoringUnknownFields = ignoringUnknownFields;
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:7,代码来源:DoParse.java


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