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


Java RuntimeSchema.createFrom方法代码示例

本文整理汇总了Java中io.protostuff.runtime.RuntimeSchema.createFrom方法的典型用法代码示例。如果您正苦于以下问题:Java RuntimeSchema.createFrom方法的具体用法?Java RuntimeSchema.createFrom怎么用?Java RuntimeSchema.createFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.protostuff.runtime.RuntimeSchema的用法示例。


在下文中一共展示了RuntimeSchema.createFrom方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
/**
 * 序列化对象
 *
 * @param obj
 * @param <T>
 * @return
 */
public static <T> byte[] serialize(T obj) {
    if (obj == null) {
        throw new RuntimeException("序列化对象(" + obj + ")为空!");
    }
    RuntimeSchema<T> schema = RuntimeSchema.createFrom((Class<T>) obj.getClass());
    LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
    byte[] protoStuff = null;
    try {
        protoStuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } catch (Exception e) {
        throw new RuntimeException("序列化(" + obj.getClass() + ")对象(" + obj + ")发生异常!", e);
    } finally {
        buffer.clear();
    }
    return protoStuff;
}
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:24,代码来源:ProtoStuffUtil.java

示例2: getSchema

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Schema<T> getSchema(Class<T> clazz) {
	Schema<T> schema = (Schema<T>) schemaCache.get(clazz);
	
	if (schema != null) {
		return schema;
	}
	
	schema = RuntimeSchema.createFrom(clazz);
	schemaCache.put(clazz, schema);
	return schema;
}
 
开发者ID:DanceFirstThinkLater,项目名称:PetiteRPC,代码行数:13,代码来源:ProtostuffSerializer.java

示例3: getSchema

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Schema<T> getSchema(Class<T> cls) {
    Schema<T> schema = (Schema<T>) cachedSchema.get(cls);
    if (schema == null) {
        schema = RuntimeSchema.createFrom(cls);
        cachedSchema.put(cls, schema);
    }
    return schema;
}
 
开发者ID:TwoDragonLake,项目名称:tdl-seckill,代码行数:10,代码来源:ConvertUtil.java

示例4: deserializeList

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
/**
 * 反序列花列表对象
 *
 * @param dataArray
 * @param targetClass
 * @param <T>
 * @return
 */
public static <T> List<T> deserializeList(byte[] dataArray, Class<T> targetClass) {
    if (dataArray == null || dataArray.length == 0) {
        throw new RuntimeException("反序列化对象发生异常,Byte序列为空!");
    }
    RuntimeSchema<T> schema = RuntimeSchema.createFrom(targetClass);
    List<T> result = null;
    try {
        result = ProtostuffIOUtil.parseListFrom(new ByteArrayInputStream(dataArray), schema);
    } catch (IOException e) {
        throw new RuntimeException("反序列化对象列表发生IO异常!", e);
    }
    return result;
}
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:22,代码来源:ProtoStuffUtil.java

示例5: getSchema

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Schema<T> getSchema(final Class<T> clasz) {
    Schema<T> schema = (Schema<T>) cachedSchema.get(clasz);
    if (schema == null) {
        schema = RuntimeSchema.createFrom(clasz);
        if (schema != null) {
            cachedSchema.put(clasz, schema);
        }
    }
    return schema;
}
 
开发者ID:bobxwang,项目名称:springboot-scala-withswagger,代码行数:12,代码来源:ProtostuffHttpMessageConverter.java

示例6: getSchema

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Schema<T> getSchema(Class<T> clasz) {
    Schema<T> schema = (Schema<T>) cachedSchema.get(clasz);
    if (schema == null) {
        schema = RuntimeSchema.createFrom(clasz);
        if (schema != null) {
            cachedSchema.put(clasz, schema);
        }
    }
    return schema;
}
 
开发者ID:bobxwang,项目名称:springboot-scala-withswagger,代码行数:12,代码来源:ProtostufUtils.java

示例7: getSchema

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Schema<T> getSchema(Class<T> cls) {
    Schema<T> schema = (Schema<T>) cachedSchema.get(cls);
    if (schema == null) {
        schema = RuntimeSchema.createFrom(cls);
        if (schema != null) {
            cachedSchema.put(cls, schema);
        }
    }
    return schema;
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:12,代码来源:ProtobuffSerializer.java

示例8: serialize

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
public static <T> byte[] serialize(T obj) {
    Class<T> cls = (Class<T>) obj.getClass();
    LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
    try {
        Schema<T> schema = RuntimeSchema.createFrom(cls);
        return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
}
 
开发者ID:zyy,项目名称:java.study,代码行数:13,代码来源:SerializationUtils.java

示例9: deserialize

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
public static <T> T deserialize(byte[] data, Class<T> cls) {
    try {
        T message = objenesis.newInstance(cls);
        Schema<T> schema = RuntimeSchema.createFrom(cls);
        ProtostuffIOUtil.mergeFrom(data, message, schema);
        return message;
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:zyy,项目名称:java.study,代码行数:11,代码来源:SerializationUtils.java

示例10: getSchema

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
public static <T> Schema<T> getSchema(Class<T> clazz) {
    @SuppressWarnings("unchecked")
    Schema<T> schema = (Schema<T>) cachedSchema.get(clazz);
    if (schema == null) {
        schema = RuntimeSchema.createFrom(clazz);
        cachedSchema.put(clazz, schema);
    }
    return schema;
}
 
开发者ID:srid99,项目名称:protostuff-example,代码行数:10,代码来源:SchemaUtils.java

示例11: createWrapSchema

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
private static WrapSchema createWrapSchema(WrapClassConfig config) throws Exception {
  Class<?> cls = JavassistUtils.createClass(config);
  Schema<?> schema = RuntimeSchema.createFrom(cls);
  return WrapSchemaFactory.createSchema(schema, config.getType());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:6,代码来源:ProtobufSchemaUtils.java

示例12: deserialize

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
/**
 * 反序列对象
 *
 * @param dataArray
 * @param targetClass
 * @param <T>
 * @return
 */
public static <T> T deserialize(byte[] dataArray, Class<T> targetClass) {
    if (dataArray == null || dataArray.length == 0) {
        throw new RuntimeException("反序列化对象发生异常,Byte序列为空!");
    }
    T instance = null;
    try {
        instance = targetClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException("反序列化过程中依据类型创建对象失败!", e);
    }
    RuntimeSchema<T> schema = RuntimeSchema.createFrom(targetClass);
    ProtostuffIOUtil.mergeFrom(dataArray, instance, schema);
    return instance;
}
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:23,代码来源:ProtoStuffUtil.java

示例13: prepare

import io.protostuff.runtime.RuntimeSchema; //导入方法依赖的package包/类
@Setup
public void prepare() throws IOException
{
    int1RuntimeSchema = RuntimeSchema.createFrom(Int1.class);
    int10RuntimeSchema = RuntimeSchema.createFrom(Int10.class);
    sparseInt1RuntimeSchema = RuntimeSchema.createFrom(SparseInt1.class);
    sparseInt10RuntimeSchema = RuntimeSchema.createFrom(SparseInt10.class);
    generatedInt1Schema = GeneratedInt1.getSchema();
    generatedInt10Schema = GeneratedInt10.getSchema();
    int1 = new Int1();
    int1.a0 = 1;
    int10 = new Int10();
    int10.a0 = 1;
    int10.a1 = 2;
    int10.a2 = 3;
    int10.a3 = 4;
    int10.a4 = 5;
    int10.a5 = 6;
    int10.a6 = 7;
    int10.a7 = 8;
    int10.a8 = 9;
    int10.a9 = 10;
    sparseInt1 = new SparseInt1();
    sparseInt1.a0 = 1;
    sparseInt10 = new SparseInt10();
    sparseInt10.a0 = 1;
    sparseInt10.a1 = 2;
    sparseInt10.a2 = 3;
    sparseInt10.a3 = 4;
    sparseInt10.a4 = 5;
    sparseInt10.a5 = 6;
    sparseInt10.a6 = 7;
    sparseInt10.a7 = 8;
    sparseInt10.a8 = 9;
    sparseInt10.a9 = 10;
    generatedInt1 = new GeneratedInt1();
    generatedInt1.setA0(1);
    generatedInt10 = new GeneratedInt10();
    generatedInt10.setA0(1);
    generatedInt10.setA1(2);
    generatedInt10.setA2(3);
    generatedInt10.setA3(4);
    generatedInt10.setA4(5);
    generatedInt10.setA5(6);
    generatedInt10.setA6(7);
    generatedInt10.setA7(8);
    generatedInt10.setA8(9);
    generatedInt10.setA9(10);
    buffer = LinkedBuffer.allocate();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ProtobufIOUtil.writeTo(outputStream, int1, int1RuntimeSchema, buffer);
    data_1_int = outputStream.toByteArray();
    outputStream.reset();
    buffer.clear();

    ProtobufIOUtil.writeTo(outputStream, int10, int10RuntimeSchema, buffer);
    data_10_int = outputStream.toByteArray();
    outputStream.reset();
    buffer.clear();
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:62,代码来源:RuntimeSchemaBenchmark.java


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