本文整理汇总了Java中com.google.protobuf.Message.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getClass方法的具体用法?Java Message.getClass怎么用?Java Message.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.Message
的用法示例。
在下文中一共展示了Message.getClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromProtobuf
import com.google.protobuf.Message; //导入方法依赖的package包/类
/**
* @see com.quancheng.saluki.serializer.IProtobufSerializer#fromProtobuf(com.google.protobuf.Message,
* java.lang.Class)
*/
@Override
public Object fromProtobuf(Message protobuf, Class<?> pojoClazz) throws ProtobufException {
try {
final Class<? extends Message> protoClazz =
ProtobufSerializerUtils.getProtobufClassFromPojoAnno(pojoClazz);
if (protoClazz == null) {
throw new ProtobufAnnotationException(
"Doesn't seem like " + pojoClazz + " is ProtobufEntity");
}
final Map<Field, ProtobufAttribute> protobufFields =
ProtobufSerializerUtils.getAllProtbufFields(pojoClazz);
if (protobufFields.isEmpty()) {
throw new ProtobufException("No protoBuf fields have been annotated on the class "
+ pojoClazz + ", thus cannot continue.");
}
Object pojo = pojoClazz.newInstance();
for (Entry<Field, ProtobufAttribute> entry : protobufFields.entrySet()) {
final Field field = entry.getKey();
final ProtobufAttribute protobufAttribute = entry.getValue();
final String setter = ProtobufSerializerUtils.getPojoSetter(protobufAttribute, field);
Object protobufValue =
Protobuf2PojoHelp.getProtobufFieldValue(protobuf, protobufAttribute, field);
if (protobufValue == null) {
continue;
}
Protobuf2PojoHelp.setPojoFieldValue(pojo, setter, protobufValue, protobufAttribute, field);
}
return pojo;
} catch (Exception e) {
throw new ProtobufException("Could not generate POJO of type " + pojoClazz
+ " from Protobuf object " + protobuf.getClass() + ": " + e, e);
}
}
示例2: 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;
}