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


Java MessagePack.write方法代码示例

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


在下文中一共展示了MessagePack.write方法的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: run

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public void run() {

        MessagePack mp = new MessagePack();
        //Packer p = mp.createBufferPacker();

        while(isRunning) {
            try {
                Transaction t = log.take();
                byte[] bytes = mp.write(t);

                ServiceMessage csm = new ServiceMessage(t.id, bytes);

                for (SenderConnector sc : senders) {
                    sc.pushToSlave(csm);
                }
            } catch (Exception e) {
                System.err.println(e);
            }
        }
    }
 
开发者ID:kriskalish,项目名称:hologram,代码行数:21,代码来源:FanOut.java

示例3: 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

示例4: testMsgpackDynamicArray

import org.msgpack.MessagePack; //导入方法依赖的package包/类
private void testMsgpackDynamicArray() throws IOException {
    List<String> src = list;

    MessagePack msgpack = new MessagePack();
    byte[] raw;
    raw = msgpack.write(src);

    List<String> dst = new LinkedList<String>();
    ArrayValue arrayValue = msgpack.read(raw).asArrayValue();
    for (Value v : arrayValue) {
        dst.add(v.asRawValue().getString());

        if (!v.asRawValue().getString().equals(EXAMPLE_STRING)) {
            throw new AssertionError();
        }
    }
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:18,代码来源:TestThreadSafety.java

示例5: 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

示例6: 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

示例7: 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

示例8: main

import org.msgpack.MessagePack; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    // Create serialize objects.
    Son2 son2 = new Son2();
    son2.setName("name");
    son2.setAge(11);
    son2.setHeight(1.2);
    son2.setId(1);

    MessagePack msgpack = new MessagePack();
    msgpack.register(Son.class);
    msgpack.register(Son2.class);

// Serialize
    byte[] raw = msgpack.write(son2);

// Deserialize directly using a template
    System.out.println(msgpack.read(raw, Son2.class).getName());
    System.out.println(msgpack.read(raw, Son2.class).getAge());

    System.out.println(msgpack.read(raw, Son.class).getName());
    System.out.println(msgpack.read(raw, Son.class).getId());

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
    System.out.println("test 2  ////////////////////////////////////////////////////////////////////////////");
    Son son = new Son();
    son.setName("name");
    son.setHeight(1.2);
    son.setId(1);

    raw = msgpack.write(son);
    System.out.println(msgpack.read(raw, Son2.class).getName());
    System.out.println(msgpack.read(raw, Son2.class).getAge());

    System.out.println(msgpack.read(raw, Son.class).getName());
    System.out.println(msgpack.read(raw, Son.class).getId());
  }
 
开发者ID:whyDK37,项目名称:pinenut,代码行数:38,代码来源:MsgPackTest2.java

示例9: test

import org.msgpack.MessagePack; //导入方法依赖的package包/类
@org.junit.Test
    public void test() 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);

// 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:chenleijava,项目名称:springJredisCache,代码行数:28,代码来源:TestMessagePack.java

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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