本文整理匯總了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;
}