本文整理汇总了Java中org.msgpack.MessagePack.createUnpacker方法的典型用法代码示例。如果您正苦于以下问题:Java MessagePack.createUnpacker方法的具体用法?Java MessagePack.createUnpacker怎么用?Java MessagePack.createUnpacker使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.msgpack.MessagePack
的用法示例。
在下文中一共展示了MessagePack.createUnpacker方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInheritanceClassNotNullable
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
Template<InheritanceClassNotNullable> tmpl = builder.buildTemplate(InheritanceClassNotNullable.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();
InheritanceClassNotNullable ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例2: testOptional0202
import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage03 testOptional0202(MyMessage02 src) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
Template<MyMessage02> tmpl02 = builder.buildTemplate(MyMessage02.class);
Template<MyMessage03> tmpl03 = builder.buildTemplate(MyMessage03.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl02.write(packer, src);
byte[] bytes = packer.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Unpacker unpacker = msgpack.createUnpacker(in);
unpacker.resetReadByteCount();
MyMessage03 dst = tmpl03.read(unpacker, null);
assertEquals(bytes.length, unpacker.getReadByteCount());
return dst;
}
示例3: testMessagePackableTypeFieldsClass
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry);
Template<MessagePackableTypeFieldsClass> tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.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();
MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例4: testOptional0103
import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage03 testOptional0103(MyMessage01 src) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
Template<MyMessage01> tmpl01 = builder.buildTemplate(MyMessage01.class);
Template<MyMessage03> tmpl03 = builder.buildTemplate(MyMessage03.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
tmpl01.write(packer, src);
byte[] bytes = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Unpacker unpacker = msgpack.createUnpacker(in);
unpacker.resetReadByteCount();
MyMessage03 dst = tmpl03.read(unpacker, null);
assertEquals(bytes.length, unpacker.getReadByteCount());
return dst;
}
示例5: testMessagePackableTypeFieldsClass
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
Template<MessagePackableTypeFieldsClass> tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.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();
MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例6: testPrimitiveTypeFieldsClass
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
Template<PrimitiveTypeFieldsClass> tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.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();
PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例7: SocketTransport
import org.msgpack.MessagePack; //导入方法依赖的package包/类
public SocketTransport(Socket socket) throws IOException {
this.socket = socket;
MessagePack msgpack = new MessagePack();
msgpack.register(ReplResponse.ResponseStatus.class);
msgpack.register(ReplResponse.class);
packer = msgpack.createPacker(socket.getOutputStream());
unpacker = msgpack.createUnpacker(socket.getInputStream());
}
示例8: run
import org.msgpack.MessagePack; //导入方法依赖的package包/类
public void run() {
while (isRunning) {
try {
if (sock == null || !sock.isBound()) {
System.out.println("Creating new server socket...");
sock = new ServerSocket(mainPort);
}
Socket s = sock.accept();
InputStream is = new FastBufferedInputStream(s.getInputStream());
//ObjectInputStream ois = new ObjectInputStream(is);
//Kryo k = new Kryo(); Input i = new Input(is);
MessagePack mp = new MessagePack(); Unpacker up = mp.createUnpacker(is);
while(isRunning) {
Transaction t = up.read(Transaction.class);
//Transaction t = k.readObject(i, Transaction.class);
//Transaction t = (Transaction) ois.readObject();
t.id = log.getNextId();
//System.out.println("Received " + t);
log.append(t);
}
} catch(Exception e) {
System.err.println(e);
}
}
}
示例9: run
import org.msgpack.MessagePack; //导入方法依赖的package包/类
public void run() {
while (isRunning) {
try {
if (sock == null || !sock.isBound()) {
System.out.println("Creating new server socket...");
sock = new Socket("127.0.0.1", mainPort);
}
InputStream is = new FastBufferedInputStream(sock.getInputStream());
//ObjectInputStream ois = new ObjectInputStream(is);
//Kryo k = new Kryo(); Input i = new Input(is);
MessagePack mp = new MessagePack(); Unpacker up = mp.createUnpacker(is);
while(isRunning) {
Transaction t = up.read(Transaction.class);
//Transaction t = k.readObject(i, Transaction.class);
//Transaction t = (Transaction) ois.readObject();
t.id = log.getNextId();
//System.out.println("Received " + t);
log.append(t);
}
} catch(Exception e) {
System.err.println(e);
}
}
}
示例10: main
import org.msgpack.MessagePack; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Order order = new Order();
order.id = 1L;
order.name = "ss";
Order order1 = new Order();
order1.id = 2L;
order1.name = "ss";
MessagePack messagePack = new MessagePack();
//序列化
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Packer packer = messagePack.createPacker(byteArrayOutputStream);
packer.write(order);
packer.write(order1);
byte[] raw = byteArrayOutputStream.toByteArray();
// System.out.println("ss:" + raw.length);
//反序列化
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(raw);
Unpacker unpacker = messagePack.createUnpacker(byteArrayInputStream);
Order destOrder = unpacker.read(Order.class);
Order destOrder2 = unpacker.read(Order.class);
System.out.println(destOrder.id + ":" + destOrder.name);
System.out.println(destOrder2.id + ":" + destOrder2.name);
}
示例11: testPrimitiveTypeFieldsClass
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry);
Template<PrimitiveTypeFieldsClass> tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl.write(packer, v);
byte[] bytes = packer.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
unpacker.resetReadByteCount();
PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例12: testByte
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testByte(byte v) throws Exception {
MessagePack msgpack = new JSON();
BufferPacker packer = msgpack.createBufferPacker();
packer.write(v);
byte[] bytes = packer.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(
new ByteArrayInputStream(bytes));
byte ret = unpacker.readByte();
assertEquals(v, ret);
}
示例13: testLong
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testLong(long v) throws Exception {
MessagePack msgpack = new JSON();
BufferPacker packer = msgpack.createBufferPacker();
packer.write(v);
byte[] bytes = packer.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(
new ByteArrayInputStream(bytes));
long ret = unpacker.readLong();
assertEquals(v, ret);
}
示例14: testReferenceTypeFieldsClass
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry);
Template<ReferenceTypeFieldsClass> tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl.write(packer, v);
byte[] bytes = packer.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
unpacker.resetReadByteCount();
ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例15: testModifiersFieldsClassNotNullable
import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Override
public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception {
MessagePack msgpack = new MessagePack();
TemplateRegistry registry = new TemplateRegistry(null);
JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
Template<ModifiersFieldsClassNotNullable> tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class);
BufferPacker packer = msgpack.createBufferPacker();
tmpl.write(packer, v);
byte[] bytes = packer.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
unpacker.resetReadByteCount();
ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}