本文整理汇总了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());
}
示例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);
}
}
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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;
}
示例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);
}
示例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());
}