本文整理汇总了Java中org.msgpack.MessagePackable类的典型用法代码示例。如果您正苦于以下问题:Java MessagePackable类的具体用法?Java MessagePackable怎么用?Java MessagePackable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessagePackable类属于org.msgpack包,在下文中一共展示了MessagePackable类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.msgpack.MessagePackable; //导入依赖的package包/类
public void write(Packer pk, MessagePackable target, boolean required)
throws IOException {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
target.writeTo(pk);
}
示例2: lookup
import org.msgpack.MessagePackable; //导入依赖的package包/类
public synchronized Template lookup(Type targetType) {
Template tmpl;
if (targetType instanceof ParameterizedType) {
// ParameterizedType is not a Class<?>
ParameterizedType paramedType = (ParameterizedType) targetType;
tmpl = lookupGenericType(paramedType);
if (tmpl != null) {
return tmpl;
}
targetType = paramedType.getRawType();
}
tmpl = lookupGenericArrayType(targetType);
if (tmpl != null) {
return tmpl;
}
tmpl = lookupCache(targetType);
if (tmpl != null) {
return tmpl;
}
if (targetType instanceof WildcardType ||
targetType instanceof TypeVariable) {
// WildcardType is not a Class<?>
tmpl = new AnyTemplate<Object>(this);
register(targetType, tmpl);
return tmpl;
}
Class<?> targetClass = (Class<?>) targetType;
// MessagePackable interface is implemented
if (MessagePackable.class.isAssignableFrom(targetClass)) {
// FIXME #MN
// following processing should be merged into lookAfterBuilding
// or lookupInterfaceTypes method in next version
tmpl = new MessagePackableTemplate(targetClass);
register(targetClass, tmpl);
return tmpl;
}
if (targetClass.isInterface()) {
// writing interfaces will succeed
// reading into interfaces will fail
tmpl = new AnyTemplate<Object>(this);
register(targetType, tmpl);
return tmpl;
}
// find matched template builder and build template
tmpl = lookupAfterBuilding(targetClass);
if (tmpl != null) {
return tmpl;
}
// lookup template of interface type
tmpl = lookupInterfaceTypes(targetClass);
if (tmpl != null) {
return tmpl;
}
// lookup template of superclass type
tmpl = lookupSuperclasses(targetClass);
if (tmpl != null) {
return tmpl;
}
// lookup template of interface type of superclasss
tmpl = lookupSuperclassInterfaceTypes(targetClass);
if (tmpl != null) {
return tmpl;
}
throw new MessageTypeException(
"Cannot find template for " + targetClass + " class. " +
"Try to add @Message annotation to the class or call MessagePack.register(Type).");
}