当前位置: 首页>>代码示例>>Java>>正文


Java MessagePackable类代码示例

本文整理汇总了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);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:12,代码来源:MessagePackableTemplate.java

示例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).");
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:80,代码来源:TemplateRegistry.java


注:本文中的org.msgpack.MessagePackable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。