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