本文整理汇总了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());
}
示例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);
}
}
}
示例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);
}
示例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();
}
}
}
示例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());
}
示例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());
}
示例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));
}
示例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());
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}