Package org.msgpack.packer

Examples of org.msgpack.packer.Packer


  MessagePack msgpack = new MessagePack();
  TemplateRegistry registry = new TemplateRegistry();
  JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry);
  Template<MessagePackableTypeFieldsClassNotNullable> tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  tmpl.write(packer, v);
  byte[] bytes = out.toByteArray();
  BufferUnpacker u = msgpack.createBufferUnpacker();
  u.wrap(bytes);
  Value value = u.readValue();
View Full Code Here


  registry.register(EnumTypeFieldsClass.SampleEnum.class,
    new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClass.SampleEnum.class));
  ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
  Template<EnumTypeFieldsClass> tmpl = builder.buildTemplate(EnumTypeFieldsClass.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));
  EnumTypeFieldsClass ret = tmpl.read(unpacker, null);
  assertEquals(v, ret);
View Full Code Here

  registry.register(EnumTypeFieldsClassNotNullable.SampleEnum.class,
    new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClassNotNullable.SampleEnum.class));
  ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
  Template<EnumTypeFieldsClassNotNullable> tmpl = builder.buildTemplate(EnumTypeFieldsClassNotNullable.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));
  EnumTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null);
  assertEquals(v, ret);
View Full Code Here

    @Override
    public void testBoolean(boolean v) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  packer.writeBoolean(v);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  boolean ret = unpacker.readBoolean();
  assertEquals(v, ret);
    }
View Full Code Here

    @Override
    public void testByte(byte v) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  packer.writeByte(v);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  byte ret = unpacker.readByte();
  assertEquals(v, ret);
    }
View Full Code Here

    @Override
    public void testShort(short v) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  packer.writeShort(v);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  short ret = unpacker.readShort();
  assertEquals(v, ret);
    }
View Full Code Here

    @Override
    public void testInteger(int v) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  packer.writeInt(v);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  int ret = unpacker.readInt();
  assertEquals(v, ret);
    }
View Full Code Here

    @Override
    public void testLong(long v) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  packer.writeLong(v);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  long ret = unpacker.readLong();
  assertEquals(v, ret);
    }
View Full Code Here

    @Override
    public void testFloat(float v) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
        if(((Float)v).isInfinite() || ((Float)v).isNaN()) {
            try {
                packer.writeFloat(v);
                fail("JSONPacker should reject infinite and NaN value");
            } catch (IOException ex) {
                assertTrue(ex instanceof IOException);
            }
            return;
        }
  packer.writeFloat(v);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  float ret = unpacker.readFloat();
  assertEquals(v, ret, 10e-10);
    }
View Full Code Here

    @Override
    public void testDouble(double v) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
        if(((Double)v).isInfinite() || ((Double)v).isNaN()) {
            try {
                packer.writeDouble(v);
                fail("JSONPacker should reject infinite and NaN value");
            } catch (IOException ex) {
                assertTrue(ex instanceof IOException);
            }
            return;
        }
  packer.writeDouble(v);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  double ret = unpacker.readDouble();
  assertEquals(v, ret, 10e-10);
    }
View Full Code Here

TOP

Related Classes of org.msgpack.packer.Packer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.