Package org.msgpack.packer

Examples of org.msgpack.packer.Packer


    @Test @Override
    public void testNil() throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  packer.writeNil();
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  unpacker.readNil();
    }
View Full Code Here


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

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

    @Override
    public void testByteArray(byte[] v) throws Exception {
        // FIXME JSONPacker doesn't support bytes
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  //packer.writeByteArray(v);
        String str = new String(v);
  packer.writeString(str);
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  //byte[] ret = unpacker.readByteArray();
  String ret = unpacker.readString();
  assertEquals(str, ret);
View Full Code Here

    @Override
    public <E> void testList(List<E> v, Class<E> elementClass) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  if (v == null) {
      packer.writeNil();
  } else {
      packer.writeArrayBegin(v.size());
      for (Object o : v) {
    packer.write(o);
      }
      packer.writeArrayEnd();
  }
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
        if (unpacker.trySkipNil()) {
            assertEquals(null, v);
View Full Code Here

    @Override
    public <K, V> void testMap(Map<K, V> v, Class<K> keyElementClass, Class<V> valueElementClass) throws Exception {
  MessagePack msgpack = new JSON();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Packer packer = msgpack.createPacker(out);
  if (v == null) {
      packer.writeNil();
  } else {
      packer.writeMapBegin(v.size());
      for (Map.Entry<Object, Object> e : ((Map<Object, Object>) v).entrySet()) {
    if (!(e.getKey() instanceof String)) {
        try {
      packer.write(e.getKey());
      fail("JSONPacker should reject non-String value for the map key");
        } catch (IOException ex) {
      assertTrue(ex instanceof IOException);
        }
        return;
    }
    packer.write(e.getKey());
    packer.write(e.getValue());
      }
      packer.writeMapEnd();
  }
  byte[] bytes = out.toByteArray();
  Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
  if (unpacker.trySkipNil()) {
      assertEquals(null, v);
View Full Code Here

    public void write(OutputStream out, Object v) throws IOException {
        write(out, v, registry.lookup(v.getClass()));
    }

    public <T> void write(OutputStream out, T v, Template<T> tmpl) throws IOException {
        Packer pk = createPacker(out);
        tmpl.write(pk, v);
    }
View Full Code Here

  @Override
  public void testShortArray(short[] v) throws Exception {
      MessagePack msgpack = new MessagePack();
      Template<short[]> tmpl = ShortArrayTemplate.instance;
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      Packer packer = msgpack.createPacker(out);
      tmpl.write(packer, v);
      byte[] bytes = out.toByteArray();
      Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
      short[] ret0;
      switch (index) {
View Full Code Here

  @Override
  public void testShortArray(short[] v) throws Exception {
      MessagePack msgpack = new MessagePack();
      Template<short[]> tmpl = ShortArrayTemplate.instance;
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      Packer packer = msgpack.createPacker(out);
      tmpl.write(packer, v);
      byte[] bytes = out.toByteArray();
      BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
      short[] ret0;
      switch (index) {
View Full Code Here

  @Override
  public void testLongArray(long[] v) throws Exception {
      MessagePack msgpack = new MessagePack();
      Template<long[]> tmpl = LongArrayTemplate.instance;
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      Packer packer = msgpack.createPacker(out);
      tmpl.write(packer, v);
      byte[] bytes = out.toByteArray();
      Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
      long[] ret0;
      switch (index) {
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.