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


Java MessagePack.read方法代码示例

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


在下文中一共展示了MessagePack.read方法的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());
}
 
开发者ID:ksgwr,项目名称:MessagePackTemplate,代码行数:26,代码来源:ObjectTemplateTest.java

示例2: testSimplePackUnpack

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

    // serialize
    byte[] raw = msgpack.write(new int[] {1,2,3});

    // deserialize to static type
    int[] a = msgpack.read(raw, new int[3]);
    assertArrayEquals(new int[] {1,2,3}, a);

    // deserialize to dynamic type (see TestSimpleDynamicTyping.java)
    Value v = msgpack.read(raw);

    // ByteBuffer is also supported
    int[] ab = msgpack.read(ByteBuffer.wrap(raw), new int[3]);
    assertArrayEquals(new int[] {1,2,3}, ab);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:20,代码来源:TestSimplePackUnpack.java

示例3: decode

import org.msgpack.MessagePack; //导入方法依赖的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

示例4: simpleTest

import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Test
public void simpleTest() throws IOException {
	MessagePack msgpack = new MessagePack();
	msgpack.register(TestObj.class, new MapObjectTemplate<TestObj>(TestObj.class));

	TestObj t = new TestObj();
	t.a = "aval";
	t.b = 1;

	byte[] bytes = msgpack.write(t);

	Value value = msgpack.read(bytes);

	assertEquals("{\"a\":\"aval\",\"b\":1}", value.toString());
}
 
开发者ID:ksgwr,项目名称:MessagePackTemplate,代码行数:16,代码来源:MapObjectTemplateTest.java

示例5: main

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
        List<String> lifeStyle = new ArrayList<String>();
        lifeStyle.add("dance");
        lifeStyle.add("sing");
        lifeStyle.add("quite");

        BigHouse bigHouse = new BigHouse();
        bigHouse.setLocate("北京");
        bigHouse.setPrice(121321.3);
        MessagePack messagePack = new MessagePack();

        //序列化
//        byte[] raw = messagePack.write(lifeStyle);
        byte[] raw2 = messagePack.write(bigHouse);

        //反序列化
//        List<String> dest = messagePack.read(raw, Templates.tList(Templates.TString));
//        messagePack.register(BigHouse.class);
        Value value = messagePack.read(raw2);
        BigHouse bigHouse1 = new Converter(value).read(BigHouse.class);

//        for (String str : dest)
//            System.out.println(str);

        System.out.println(bigHouse1.getLocate());

    }
 
开发者ID:krisjin,项目名称:bscl,代码行数:28,代码来源:MsgpackDemo.java

示例6: main

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    // Create serialize objects.
    List<String> src = new ArrayList<String>();
    src.add("msgpack");
    src.add("kumofs");
    src.add("viver");

    MessagePack msgpack = new MessagePack();
// Serialize
    byte[] raw = msgpack.write(src);
    System.out.println(raw.length);
    System.out.println(new String(raw));

// Deserialize directly using a template
    List<String> dst1 = msgpack.read(raw, Templates.tList(Templates.TString));
    System.out.println(dst1.get(0));
    System.out.println(dst1.get(1));
    System.out.println(dst1.get(2));

// Or, Deserialze to Value then convert type.
    Value dynamic = msgpack.read(raw);
    List<String> dst2 = new Converter(dynamic)
            .read(Templates.tList(Templates.TString));
    System.out.println(dst2.get(0));
    System.out.println(dst2.get(1));
    System.out.println(dst2.get(2));
  }
 
开发者ID:whyDK37,项目名称:pinenut,代码行数:28,代码来源:MsgPackTest.java

示例7: testSimpleConvert

import org.msgpack.MessagePack; //导入方法依赖的package包/类
@Test
public void testSimpleConvert() throws IOException {
    MessagePack msgpack = new MessagePack();
    byte[] raw = msgpack.write(new int[] {1,2,3});

    Value v = msgpack.read(raw);

    int[] array = msgpack.convert(v, new int[3]);
    assertArrayEquals(new int[] {1,2,3}, array);

    Value v2 = msgpack.unconvert(array);
    assertEquals(v, v2);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:14,代码来源:TestSimpleConvertUnconvert.java

示例8: testOptional0101

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage01 testOptional0101(MyMessage01 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    return msgpack.read(bytes, MyMessage01.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:8,代码来源:TestOptionalBufferPackBufferUnpack.java

示例9: testOptional0102

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage02 testOptional0102(MyMessage01 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    return msgpack.read(bytes, MyMessage02.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:8,代码来源:TestOptionalBufferPackBufferUnpack.java

示例10: testOptional0103

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage03 testOptional0103(MyMessage01 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    return msgpack.read(bytes, MyMessage03.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:8,代码来源:TestOptionalBufferPackBufferUnpack.java

示例11: testOptional0202

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage03 testOptional0202(MyMessage02 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    return msgpack.read(bytes, MyMessage03.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:8,代码来源:TestOptionalBufferPackBufferUnpack.java

示例12: testOptional0101

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage01 testOptional0101(MyMessage01 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    return msgpack.read(in, MyMessage01.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:9,代码来源:TestOptionalPackUnpack.java

示例13: testOptional0102

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage02 testOptional0102(MyMessage01 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    return msgpack.read(in, MyMessage02.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:9,代码来源:TestOptionalPackUnpack.java

示例14: testOptional0103

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage03 testOptional0103(MyMessage01 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    return msgpack.read(in, MyMessage03.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:9,代码来源:TestOptionalPackUnpack.java

示例15: testOptional0202

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public MyMessage03 testOptional0202(MyMessage02 src) throws Exception {
    MessagePack msgpack = new MessagePack();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msgpack.write(out, src);
    byte[] bytes = out.toByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    return msgpack.read(in, MyMessage03.class);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:9,代码来源:TestOptionalPackUnpack.java


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