本文整理汇总了Java中org.msgpack.type.ValueFactory.createMapValue方法的典型用法代码示例。如果您正苦于以下问题:Java ValueFactory.createMapValue方法的具体用法?Java ValueFactory.createMapValue怎么用?Java ValueFactory.createMapValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.msgpack.type.ValueFactory
的用法示例。
在下文中一共展示了ValueFactory.createMapValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToValue
import org.msgpack.type.ValueFactory; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Value mapToValue(Map map) {
Value[] kvs = new Value[map.size() * 2];
Iterator<Map.Entry> it = map.entrySet().iterator();
for (int i = 0; i < kvs.length; i += 2) {
Map.Entry pair = it.next();
kvs[i] = objectToValue(pair.getKey());
kvs[i + 1] = objectToValue(pair.getValue());
}
return ValueFactory.createMapValue(kvs, true);
}
示例2: createComplexType
import org.msgpack.type.ValueFactory; //导入方法依赖的package包/类
public Value createComplexType() throws Exception {
Random rand = new Random(System.currentTimeMillis());
byte[] b0 = new byte[0];
byte[] b1 = new byte[10];
rand.nextBytes(b1);
byte[] b2 = new byte[1024];
rand.nextBytes(b2);
Value list = ValueFactory.createArrayValue(new Value[] {
ValueFactory.createRawValue(b0),
ValueFactory.createRawValue(b1),
ValueFactory.createRawValue(b2), });
Value map = ValueFactory.createMapValue(new Value[] {
ValueFactory.createIntegerValue(0),
ValueFactory.createIntegerValue(Integer.MIN_VALUE),
ValueFactory.createIntegerValue(rand.nextInt()),
ValueFactory.createIntegerValue(Integer.MAX_VALUE),
ValueFactory.createFloatValue(rand.nextFloat()),
ValueFactory.createBooleanValue(true),
ValueFactory.createFloatValue(rand.nextDouble()),
ValueFactory.createNilValue(), });
List<Value> values = new ArrayList<Value>();
for (int i = 0; i < 2; i++) {
values.add(list);
for (int j = 0; j < 100; j++) {
values.add(map);
}
}
Value complex = ValueFactory.createArrayValue(values
.toArray(new Value[values.size()]));
return complex;
}
示例3: testSimplePackUnpack
import org.msgpack.type.ValueFactory; //导入方法依赖的package包/类
@Test
public void testSimplePackUnpack() throws IOException {
MessagePack msgpack = new MessagePack();
Value v = ValueFactory.createMapValue(new Value[] {
ValueFactory.createRawValue("k1"),
ValueFactory.createIntegerValue(1),
ValueFactory.createRawValue("k2"),
ValueFactory.createArrayValue(new Value[] {
ValueFactory.createNilValue(),
ValueFactory.createBooleanValue(true),
ValueFactory.createBooleanValue(false)
}),
ValueFactory.createRawValue("k3"),
ValueFactory.createFloatValue(0.1)
});
JSONBufferPacker pk = new JSONBufferPacker(msgpack);
pk.write(v);
byte[] raw = pk.toByteArray();
String str = new String(raw);
assertEquals("{\"k1\":1,\"k2\":[null,true,false],\"k3\":0.1}", str);
JSONBufferUnpacker u = new JSONBufferUnpacker(msgpack).wrap(raw);
Value v2 = u.readValue();
assertEquals(v, v2);
}