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


Java MessagePack类代码示例

本文整理汇总了Java中org.msgpack.MessagePack的典型用法代码示例。如果您正苦于以下问题:Java MessagePack类的具体用法?Java MessagePack怎么用?Java MessagePack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: simpleTest

import org.msgpack.MessagePack; //导入依赖的package包/类
/**
 * Map<String, Object>がシリアライズ可能で、
 * それ以外のフィールド名はシリアライズされないことを確認する
 * @throws IOException MessagePackのException
 */
@Test
public void simpleTest() throws IOException {
	MessagePack msgpack = new MessagePack();
	msgpack.register(Object.class, ObjectTemplate.getInstance());
	msgpack.register(TestObj.class);

	TestObj t = new TestObj();
	t.mapObj = new LinkedHashMap<>();

	t.mapObj.put("a", "aval");
	t.mapObj.put("b", 1);

	t.longFieldNameValue = "c";

	byte[] bytes = msgpack.write(t);

	Value value = msgpack.read(bytes);

	assertEquals("[{\"a\":\"aval\",\"b\":1},\"c\"]", value.toString());
}
 
开发者ID:ksgwr,项目名称:MessagePackTemplate,代码行数:26,代码来源:ObjectTemplateTest.java

示例2: run

import org.msgpack.MessagePack; //导入依赖的package包/类
public void run() {

        MessagePack mp = new MessagePack();
        //Packer p = mp.createBufferPacker();

        while(isRunning) {
            try {
                Transaction t = log.take();
                byte[] bytes = mp.write(t);

                ServiceMessage csm = new ServiceMessage(t.id, bytes);

                for (SenderConnector sc : senders) {
                    sc.pushToSlave(csm);
                }
            } catch (Exception e) {
                System.err.println(e);
            }
        }
    }
 
开发者ID:kriskalish,项目名称:hologram,代码行数:21,代码来源:FanOut.java

示例3: testMap

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
public <K, V> void testMap(Map<K, V> v, Class<K> keyElementClass, Class<V> valueElementClass) throws Exception {
    MessagePack msgpack = new MessagePack();
    Template<K> keyElementTemplate = msgpack.lookup(keyElementClass);
    Template<V> valueElementTemplate = msgpack.lookup(valueElementClass);
    Template<Map<K, V>> tmpl = new MapTemplate<K, V>(keyElementTemplate, valueElementTemplate);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Packer packer = msgpack.createPacker(out);
    tmpl.write(packer, v);
    byte[] bytes = out.toByteArray();
    Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
    unpacker.resetReadByteCount();
    Map<K, V> ret = tmpl.read(unpacker, null);
    assertEquals(v, ret);
    assertEquals(bytes.length, unpacker.getReadByteCount());
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:17,代码来源:TestMapTemplate.java

示例4: testPrimitiveTypeFieldsClass

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
Template<PrimitiveTypeFieldsClass> tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl.write(packer, v);
byte[] bytes = packer.toByteArray();
BufferUnpacker unpacker = msgpack.createBufferUnpacker();
unpacker.resetReadByteCount();
unpacker.wrap(bytes);
PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:17,代码来源:TestJavassistBufferPackBufferUnpack.java

示例5: testUserDefinedTypeFieldsClassNotNullable

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
Template<UserDefinedTypeFieldsClassNotNullable> tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl.write(packer, v);
byte[] bytes = packer.toByteArray();
BufferUnpacker u = msgpack.createBufferUnpacker();
u.resetReadByteCount();
u.wrap(bytes);
Value value = u.readValue();
Converter unpacker = new Converter(value);
UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, u.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:19,代码来源:TestJavassistBufferPackConvert.java

示例6: testUserDefinedTypeFieldsClass

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
Template<UserDefinedTypeFieldsClass> tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl.write(packer, v);
byte[] bytes = out.toByteArray();
BufferUnpacker u = msgpack.createBufferUnpacker();
u.resetReadByteCount();
u.wrap(bytes);
Value value = u.readValue();
Converter unpacker = new Converter(value);
UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:19,代码来源:TestJavassistPackConvert.java

示例7: testFinalClass

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testFinalClass(FinalClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
Template<FinalClass> tmpl = builder.buildTemplate(FinalClass.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl.write(packer, v);
byte[] bytes = out.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
unpacker.resetReadByteCount();
FinalClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:17,代码来源:TestJavassistPackUnpack.java

示例8: testModifiersFieldsClassNotNullable

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry);
Template<ModifiersFieldsClassNotNullable> tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl.write(packer, v);
byte[] bytes = out.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
unpacker.resetReadByteCount();
ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:17,代码来源:TestReflectionBeansPackUnpack.java

示例9: testPrimitiveTypeFieldsClassNotNullable

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
Template<PrimitiveTypeFieldsClassNotNullable> tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl.write(packer, v);
byte[] bytes = out.toByteArray();
BufferUnpacker u = msgpack.createBufferUnpacker();
u.resetReadByteCount();
u.wrap(bytes);
Value value = u.readValue();
Converter unpacker = new Converter(value);
PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, u.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:20,代码来源:TestReflectionPackConvert.java

示例10: testInheritanceClass

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testInheritanceClass(InheritanceClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
Template<InheritanceClass> tmpl = builder.buildTemplate(InheritanceClass.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl.write(packer, v);
byte[] bytes = out.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
unpacker.resetReadByteCount();
InheritanceClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:17,代码来源:TestReflectionPackUnpack.java

示例11: testModifiersFieldsClass

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry);
Template<ModifiersFieldsClass> tmpl = builder.buildTemplate(ModifiersFieldsClass.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl.write(packer, v);
byte[] bytes = packer.toByteArray();
BufferUnpacker unpacker = msgpack.createBufferUnpacker();
unpacker.resetReadByteCount();
unpacker.wrap(bytes);
ModifiersFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:17,代码来源:TestReflectionBeansBufferPackBufferUnpack.java

示例12: testListTypeFieldsClassNotNullable

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry);
Template<ListTypeFieldsClassNotNullable> tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl.write(packer, v);
byte[] bytes = out.toByteArray();
BufferUnpacker u = msgpack.createBufferUnpacker();
u.resetReadByteCount();
u.wrap(bytes);
Value value = u.readValue();
Converter unpacker = new Converter(value);
ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, u.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:20,代码来源:TestReflectionBeansPackConvert.java

示例13: getClient

import org.msgpack.MessagePack; //导入依赖的package包/类
/**
 * Msgpackクライアントをコネクションプールから取得する.<BR>
 * 存在しない場合には、新規に作成する.
 * @param addr  接続先アドレス
 * @param timeOut タイムアウト
 * @return ClientEx 
 */
public ClientEx getClient(InetSocketAddress addr, int timeOut) {
	ClientEx ce = null;

	synchronized (poolClient) {
		if (poolClient.containsKey(addr)) {
			//既に生成済み
			ce = poolClient.get(addr);
		} else {
			ce = new ClientEx(addr, new NettyEventLoopEx(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), Executors.newScheduledThreadPool(2), new MessagePack()));
			poolClient.put(addr, ce);
			ce.setRequestTimeout(timeOut);
		}
		ce.joinClient();
	}
	return ce;
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:24,代码来源:MsgPackClientPool.java

示例14: testFinalClass

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testFinalClass(FinalClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
Template<FinalClass> tmpl = builder.buildTemplate(FinalClass.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl.write(packer, v);
byte[] bytes = out.toByteArray();
BufferUnpacker u = msgpack.createBufferUnpacker();
u.resetReadByteCount();
u.wrap(bytes);
Value value = u.readValue();
Converter unpacker = new Converter(value);
FinalClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:19,代码来源:TestJavassistPackConvert.java

示例15: testReferenceTypeFieldsClassNotNullable

import org.msgpack.MessagePack; //导入依赖的package包/类
@Override
   public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry);
Template<ReferenceTypeFieldsClassNotNullable> tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl.write(packer, v);
byte[] bytes = packer.toByteArray();
BufferUnpacker u = msgpack.createBufferUnpacker();
u.resetReadByteCount();
u.wrap(bytes);
Value value = u.readValue();
Converter unpacker = new Converter(value);
ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, u.getReadByteCount());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:19,代码来源:TestReflectionBeansBufferPackConvert.java


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