本文整理汇总了Java中org.msgpack.type.ValueFactory类的典型用法代码示例。如果您正苦于以下问题:Java ValueFactory类的具体用法?Java ValueFactory怎么用?Java ValueFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValueFactory类属于org.msgpack.type包,在下文中一共展示了ValueFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: objectToValue
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private Value objectToValue(Object obj) {
if (obj instanceof String) {
return ValueFactory.createRawValue((String) obj);
} else if (obj instanceof Integer) {
return ValueFactory.createIntegerValue((Integer) obj);
} else if (obj instanceof Long) {
return ValueFactory.createIntegerValue((Long) obj);
} else if (obj instanceof Map) {
return mapToValue((Map) obj);
} else if (obj instanceof List) {
return listToValue((List) obj);
} else if (obj instanceof Boolean) {
return ValueFactory.createBooleanValue((Boolean) obj);
} else if (obj instanceof Double) {
return ValueFactory.createFloatValue((Double) obj);
} else {
return ValueFactory.createNilValue();
}
}
示例2: join
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
void join(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
long end_time = System.currentTimeMillis() + unit.toMillis(timeout);
boolean run_callback = false;
synchronized (lock) {
while (done == false) {
long timeout_remaining = end_time - System.currentTimeMillis();
if (timeout_remaining <= 0) break;
lock.wait(timeout_remaining);
}
if (!done) {
this.error = ValueFactory.createRawValue("timedout");
done = true;
lock.notifyAll();
run_callback = true;
}
}
if (run_callback && callback != null) {
// FIXME #SF submit?
// session.getEventLoop().getWorkerExecutor().submit(callback);
callback.run();
}
}
示例3: writeArrayBegin
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Override
public Packer writeArrayBegin(int size) throws IOException {
if (size == 0) {
// Value[] array = new Value[size];
putContainer(ValueFactory.createArrayValue());
stack.pushArray(0);
values[stack.getDepth()] = null;
} else {
Value[] array = new Value[size];
putContainer(ValueFactory.createArrayValue(array, true));
stack.pushArray(size);
values[stack.getDepth()] = array;
}
return this;
}
示例4: writeMapBegin
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Override
public Packer writeMapBegin(int size) throws IOException {
stack.checkCount();
if (size == 0) {
putContainer(ValueFactory.createMapValue());
stack.pushMap(0);
values[stack.getDepth()] = null;
} else {
Value[] array = new Value[size * 2];
putContainer(ValueFactory.createMapValue(array, true));
stack.pushMap(size);
values[stack.getDepth()] = array;
}
return this;
}
示例5: acceptUnsignedInteger
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Override
void acceptUnsignedInteger(int v) throws IOException {
if (v < 0) {
long value = (long) (v & 0x7fffffff) + 0x80000000L;
uc.write(ValueFactory.createIntegerValue(value));
} else {
uc.write(ValueFactory.createIntegerValue(v));
}
}
示例6: refer
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Override
public void refer(ByteBuffer bb, boolean gift) throws IOException {
// TODO gift
byte[] raw = new byte[bb.remaining()];
bb.get(raw);
uc.write(ValueFactory.createRawValue(raw, true));
}
示例7: listToValue
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private Value listToValue(List list) {
Value[] array = new Value[list.size()];
for (int i = 0; i < array.length; i++) {
array[i] = objectToValue(list.get(i));
}
return ValueFactory.createArrayValue(array, true);
}
示例8: 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);
}
示例9: testPackValue
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Test
public void testPackValue() throws IOException {
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
String text = "This is Value";
Value value = ValueFactory.createRawValue(text);
packer.write(value);
byte[] bytes = out.toByteArray();
Assert.assertEquals(text.length() + 1,bytes.length);
Assert.assertEquals(0xa0 + text.length(), 0xff & bytes[0]);
}
示例10: testPackValuePassedAsObject
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Test
public void testPackValuePassedAsObject() throws IOException{
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
String text = "This is Value";
Object value = ValueFactory.createRawValue(text);
packer.write(value); // passed as object
byte[] bytes = out.toByteArray();
Assert.assertEquals(text.length() + 1,bytes.length);
Assert.assertEquals(0xa0 + text.length(), 0xff & bytes[0]);
}
示例11: testValuePassedAsObject
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Test
public void testValuePassedAsObject() throws IOException {
MessagePack msgpack = new MessagePack();
String text = "This class is Value but...";
Object value = ValueFactory.createRawValue("This class is Value but...");
byte[] strValue = msgpack.write(value);
// should be raw type
assertEquals(0xa0 + text.length(),0xff & strValue[0]);
}
示例12: testRawValueGetString
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Test
public void testRawValueGetString() throws Exception {
for (byte[] malform : malforms) {
RawValue r = ValueFactory.createRawValue(malform);
try {
r.getString();
fail("no exception");
} catch (MessageTypeException expected) {
}
byte[] a = r.getByteArray();
assertArrayEquals(malform, a);
}
}
示例13: testConverterUnpackString
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Test
public void testConverterUnpackString() throws Exception {
for (byte[] malform : malforms) {
MessagePack msgpack = new MessagePack();
RawValue r = ValueFactory.createRawValue(malform);
Converter u = new Converter(msgpack, r);
try {
u.readString();
fail("no exception");
} catch (MessageTypeException expected) {
}
byte[] a = u.readByteArray();
assertArrayEquals(malform, a);
}
}
示例14: testValueToString
import org.msgpack.type.ValueFactory; //导入依赖的package包/类
@Test
public void testValueToString() throws Exception {
for (byte[] malform : malforms) {
RawValue r = ValueFactory.createRawValue(malform);
String str = r.toString();
// malformed bytes will be ignored
assertEquals("\"\"", str);
}
}
示例15: 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;
}