本文整理汇总了Java中org.msgpack.packer.Packer.writeNil方法的典型用法代码示例。如果您正苦于以下问题:Java Packer.writeNil方法的具体用法?Java Packer.writeNil怎么用?Java Packer.writeNil使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.msgpack.packer.Packer
的用法示例。
在下文中一共展示了Packer.writeNil方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, Set<E> target, boolean required)
throws IOException {
if (!(target instanceof Set)) {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
throw new MessageTypeException("Target is not a List but "
+ target.getClass());
}
pk.writeArrayBegin(target.size());
for (E e : target) {
elementTemplate.write(pk, e);
}
pk.writeArrayEnd();
}
示例2: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer pk, T target, boolean required) throws IOException {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
Integer ordinal = reverse.get(target);
if (ordinal == null) {
throw new MessageTypeException(
new IllegalArgumentException("ordinal: " + ordinal));
}
pk.write((int) ordinal);
}
示例3: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer packer, Object v, boolean required) throws IOException {
if (v == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
packer.writeNil();
return;
}
if (!(v instanceof Object[])
|| !componentClass.isAssignableFrom(v.getClass().getComponentType())) {
throw new MessageTypeException();
}
Object[] array = (Object[]) v;
int length = array.length;
packer.writeArrayBegin(length);
for (int i = 0; i < length; i++) {
componentTemplate.write(packer, array[i], required);
}
packer.writeArrayEnd();
}
示例4: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, Map<K, V> target, boolean required)
throws IOException {
if (!(target instanceof Map)) {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
throw new MessageTypeException("Target is not a Map but " + target.getClass());
}
Map<K, V> map = (Map<K, V>) target;
pk.writeMapBegin(map.size());
for (Map.Entry<K, V> pair : map.entrySet()) {
keyTemplate.write(pk, pair.getKey());
valueTemplate.write(pk, pair.getValue());
}
pk.writeMapEnd();
}
示例5: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, Object v, boolean required) throws IOException {
if (v == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.write(v);
}
示例6: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer pk, Object v, boolean required) throws IOException {
if (v == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.write(v);
}
示例7: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer paramPacker, Object paramT, boolean paramBoolean)
throws IOException {
if(paramT==null) {
if(paramBoolean) {
throw new MessageTypeException("Attempted to write null");
}
paramPacker.writeNil();
return;
} else {
paramPacker.write(paramT);
}
}
示例8: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer paramPacker, T paramT, boolean paramBoolean)
throws IOException {
if(paramT==null) {
if(paramBoolean) {
throw new MessageTypeException("Attempted to write null");
}
paramPacker.writeNil();
return;
} else {
Field[] fields = paramT.getClass().getFields();
paramPacker.writeMapBegin(fields.length);
for(Field field:fields) {
int mod = field.getModifiers();
if(Modifier.isPublic(mod) && !Modifier.isStatic(mod) && !Modifier.isTransient(mod)) {
try {
CompressField cfield;
if (isCompress && (cfield = field.getAnnotation(CompressField.class)) != null) {
// if compress option is true, serialize field name to integer
paramPacker.write(cfield.value());
} else {
paramPacker.write(field.getName());
}
paramPacker.write(field.get(paramT));
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new MessageTypeException("Illegal Exception");
}
}
}
paramPacker.writeMapEnd(paramBoolean);
}
}
示例9: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
/**
* Serializes specified object to output stream.
*
* @since 0.6.0
* @param out
* output stream
* @param v
* serialized object
* @throws IOException
*/
public <T> void write(OutputStream out, T v) throws IOException {
Packer pk = createPacker(out);
if (v == null) {
pk.writeNil();
} else {
@SuppressWarnings("unchecked")
Template<T> tmpl = registry.lookup(v.getClass());
tmpl.write(pk, v);
}
}
示例10: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, Integer target, boolean required)
throws IOException {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.write((int) target);
}
示例11: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, BigInteger target, boolean required)
throws IOException {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.write((BigInteger) target);
}
示例12: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, double[] target, boolean required)
throws IOException {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.writeArrayBegin(target.length);
for (double a : target) {
pk.write(a);
}
pk.writeArrayEnd();
}
示例13: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, String target, boolean required)
throws IOException {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.write(target);
}
示例14: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, int[] target, boolean required)
throws IOException {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.writeArrayBegin(target.length);
for (int a : target) {
pk.write(a);
}
pk.writeArrayEnd();
}
示例15: testNil
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Test @Override
public void testNil() throws Exception {
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
packer.writeNil();
byte[] bytes = out.toByteArray();
BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
unpacker.resetReadByteCount();
Value value = unpacker.readValue();
assertTrue(value.isNilValue());
new Converter(value).readNil();
assertEquals(bytes.length, unpacker.getReadByteCount());
}