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


Java Converter.read方法代码示例

本文整理汇总了Java中org.msgpack.unpacker.Converter.read方法的典型用法代码示例。如果您正苦于以下问题:Java Converter.read方法的具体用法?Java Converter.read怎么用?Java Converter.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.msgpack.unpacker.Converter的用法示例。


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

示例1: decode

import org.msgpack.unpacker.Converter; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes", "resource"})
public <E> E decode(byte[] data, Class<E> messageType) throws IOException {
    MessagePack msgpack = new MessagePack();
    msgpack.register(Map.class, new MapTemplate(Templates.TString, new ObjectTemplate()));
    msgpack.register(List.class, new ListTemplate(new ObjectTemplate()));
    Value dynamic = msgpack.read(data);
    Converter converter = new Converter(msgpack, dynamic);
    return converter.read(messageType);
}
 
开发者ID:weibocom,项目名称:yar-java,代码行数:10,代码来源:MsgpackPackager.java

示例2: testBigInteger

import org.msgpack.unpacker.Converter; //导入方法依赖的package包/类
@Override
   public void testBigInteger(BigInteger v) throws Exception {
MessagePack msgpack = new MessagePack();
       Unconverter packer = new Unconverter(msgpack);
       packer.write(v);
       Value r = packer.getResult();
       Converter unpacker = new Converter(msgpack, r);
       BigInteger ret = unpacker.read(BigInteger.class);
       assertEquals(v, ret);
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:11,代码来源:TestUnconvertConvert.java

示例3: testString

import org.msgpack.unpacker.Converter; //导入方法依赖的package包/类
@Override
   public void testString(String v) throws Exception {
MessagePack msgpack = new MessagePack();
       Unconverter packer = new Unconverter(msgpack);
       packer.write(v);
       Value r = packer.getResult();
       Converter unpacker = new Converter(msgpack, r);
       String ret = unpacker.read(String.class);
       assertEquals(v, ret);
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:11,代码来源:TestUnconvertConvert.java

示例4: testByteArray

import org.msgpack.unpacker.Converter; //导入方法依赖的package包/类
@Override
   public void testByteArray(byte[] v) throws Exception {
MessagePack msgpack = new MessagePack();
       Unconverter packer = new Unconverter(msgpack);
       packer.write(v);
       Value r = packer.getResult();
       Converter unpacker = new Converter(msgpack, r);
       byte[] ret = unpacker.read(byte[].class);
assertArrayEquals(v, ret);
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:11,代码来源:TestUnconvertConvert.java

示例5: testPrimitive

import org.msgpack.unpacker.Converter; //导入方法依赖的package包/类
@Test
public void testPrimitive() throws Exception {
    MessagePack msgpack = new MessagePack();

    PrimitiveTest t = new PrimitiveTest();
    t.b = new boolean[] { true, false };
    t.s = new short[] { 0, 1 };
    t.i = new int[] { 2, 3 };
    // t.l = new long[] {4, 5};
    t.f = new float[] { 2.0f, 4.0f };
    // t.d = new double[] {8.0, 16.0};

    BufferPacker packer = msgpack.createBufferPacker();
    packer.write(t);
    byte[] raw = packer.toByteArray();
    BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw);
    PrimitiveTest u = unpacker.read(PrimitiveTest.class);
    assertEquals(t.b.length, u.b.length);
    for (int i = 0; i < t.b.length; i++) {
        assertEquals(t.b[i], u.b[i]);
    }
    assertEquals(t.s.length, u.s.length);
    for (int i = 0; i < t.s.length; i++) {
        assertEquals(t.s[i], u.s[i]);
    }
    assertEquals(t.i.length, u.i.length);
    for (int i = 0; i < t.i.length; i++) {
        assertEquals(t.i[i], u.i[i]);
    }
    // assertEquals(t.l.length, u.l.length);
    // for(int i=0; i < t.l.length; i++) { assertEquals(t.l[i], u.l[i]); }
    assertEquals(t.f.length, u.f.length);
    for (int i = 0; i < t.f.length; i++) {
        assertEquals(t.f[i], u.f[i], 10e-10);
    }
    // assertEquals(t.d.length, u.d.length);
    // for(int i=0; i < t.d.length; i++) { assertEquals(t.d[i], u.d[i]); }

    Unconverter unconverter = new Unconverter(msgpack);
    unconverter.write(t);
    Value value = unconverter.getResult();
    Converter converter = new Converter(msgpack, value);
    PrimitiveTest c = converter.read(PrimitiveTest.class);
    assertEquals(t.b.length, c.b.length);
    for (int i = 0; i < t.b.length; i++) {
        assertEquals(t.b[i], c.b[i]);
    }
    assertEquals(t.s.length, c.s.length);
    for (int i = 0; i < t.s.length; i++) {
        assertEquals(t.s[i], c.s[i]);
    }
    assertEquals(t.i.length, c.i.length);
    for (int i = 0; i < t.i.length; i++) {
        assertEquals(t.i[i], c.i[i]);
    }
    // assertEquals(t.l.length, c.l.length);
    // for(int i=0; i < t.l.length; i++) { assertEquals(t.l[i], c.l[i]); }
    assertEquals(t.f.length, c.f.length);
    for (int i = 0; i < t.f.length; i++) {
        assertEquals(t.f[i], c.f[i], 10e-10);
    }
    // assertEquals(t.d.length, c.d.length);
    // for(int i=0; i < t.d.length; i++) { assertEquals(t.d[i], c.d[i]); }
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:65,代码来源:TestSimpleArrays.java

示例6: testReference

import org.msgpack.unpacker.Converter; //导入方法依赖的package包/类
@Test
public void testReference() throws Exception {
    MessagePack msgpack = new MessagePack();

    ReferenceTest t = new ReferenceTest();
    t.b = new Boolean[] { true, false };
    t.s = new Short[] { 0, 1 };
    t.i = new Integer[] { 2, 3 };
    t.l = new Long[] { 4l, 5l };
    t.f = new Float[] { 2.0f, 4.0f };
    t.d = new Double[] { 8.0, 16.0 };
    t.str = new String[] { "furuhashi", "java" };

    BufferPacker packer = msgpack.createBufferPacker();
    packer.write(t);
    byte[] raw = packer.toByteArray();
    BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw);
    ReferenceTest u = unpacker.read(ReferenceTest.class);
    assertEquals(t.b.length, u.b.length);
    for (int i = 0; i < t.b.length; i++) {
        assertEquals(t.b[i], u.b[i]);
    }
    assertEquals(t.s.length, u.s.length);
    for (int i = 0; i < t.s.length; i++) {
        assertEquals(t.s[i], u.s[i]);
    }
    assertEquals(t.i.length, u.i.length);
    for (int i = 0; i < t.i.length; i++) {
        assertEquals(t.i[i], u.i[i]);
    }
    assertEquals(t.l.length, u.l.length);
    for (int i = 0; i < t.l.length; i++) {
        assertEquals(t.l[i], u.l[i]);
    }
    assertEquals(t.f.length, u.f.length);
    for (int i = 0; i < t.f.length; i++) {
        assertEquals(t.f[i], u.f[i]);
    }
    assertEquals(t.d.length, u.d.length);
    for (int i = 0; i < t.d.length; i++) {
        assertEquals(t.d[i], u.d[i]);
    }
    assertEquals(t.str.length, u.str.length);
    for (int i = 0; i < t.str.length; i++) {
        assertEquals(t.str[i], u.str[i]);
    }

    Unconverter unconverter = new Unconverter(msgpack);
    unconverter.write(t);
    Value value = unconverter.getResult();
    Converter converter = new Converter(msgpack, value);
    ReferenceTest c = converter.read(ReferenceTest.class);
    assertEquals(t.b.length, c.b.length);
    for (int i = 0; i < t.b.length; i++) {
        assertEquals(t.b[i], c.b[i]);
    }
    assertEquals(t.s.length, c.s.length);
    for (int i = 0; i < t.s.length; i++) {
        assertEquals(t.s[i], c.s[i]);
    }
    assertEquals(t.i.length, c.i.length);
    for (int i = 0; i < t.i.length; i++) {
        assertEquals(t.i[i], c.i[i]);
    }
    assertEquals(t.l.length, c.l.length);
    for (int i = 0; i < t.l.length; i++) {
        assertEquals(t.l[i], c.l[i]);
    }
    assertEquals(t.f.length, c.f.length);
    for (int i = 0; i < t.f.length; i++) {
        assertEquals(t.f[i], c.f[i]);
    }
    assertEquals(t.d.length, c.d.length);
    for (int i = 0; i < t.d.length; i++) {
        assertEquals(t.d[i], c.d[i]);
    }
    assertEquals(t.str.length, c.str.length);
    for (int i = 0; i < t.str.length; i++) {
        assertEquals(t.str[i], c.str[i]);
    }
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:82,代码来源:TestSimpleArrays.java

示例7: testLocal

import org.msgpack.unpacker.Converter; //导入方法依赖的package包/类
@Test
public void testLocal() throws IOException {
    MessagePack msgpack = new MessagePack();

    int[][][] src = new int[10][20][30];
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 20; ++j) {
            for (int k = 0; k < 30; ++k) {
                src[i][j][k] = (int) (Math.random() * 100);
            }
        }
    }

    BufferPacker packer = msgpack.createBufferPacker();
    packer.write(src);
    byte[] raw = packer.toByteArray();
    BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw);
    int[][][] u = unpacker.read(int[][][].class);
    assertEquals(src.length, u.length);
    for (int i = 0; i < src.length; ++i) {
        assertEquals(src[i].length, u[i].length);
        for (int j = 0; j < src[i].length; ++j) {
            assertEquals(src[i][j].length, u[i][j].length);
            for (int k = 0; k < src[i][j].length; ++k) {
                assertEquals(src[i][j][k], u[i][j][k]);
            }
        }
    }

    Unconverter unconverter = new Unconverter(msgpack);
    unconverter.write(src);
    Value value = unconverter.getResult();
    Converter converter = new Converter(msgpack, value);
    int[][][] c = converter.read(int[][][].class);
    assertEquals(src.length, c.length);
    for (int i = 0; i < src.length; ++i) {
        assertEquals(src[i].length, c[i].length);
        for (int j = 0; j < src[i].length; ++j) {
            assertEquals(src[i][j].length, c[i][j].length);
            for (int k = 0; k < src[i][j].length; ++k) {
                assertEquals(src[i][j][k], c[i][j][k]);
            }
        }
    }
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:46,代码来源:TestSimpleArrays.java


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