本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}