當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。