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


Java Packer.writeNil方法代码示例

本文整理汇总了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();
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:20,代码来源:SetTemplate.java

示例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);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:17,代码来源:OrdinalEnumTemplate.java

示例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();
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:23,代码来源:ArrayTemplateBuilder.java

示例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();
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:21,代码来源:MapTemplate.java

示例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);
}
 
开发者ID:weibocom,项目名称:yar-java,代码行数:11,代码来源:MsgpackPackager.java

示例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);
}
 
开发者ID:vongosling,项目名称:jvm-serializer,代码行数:12,代码来源:ObjectTemplate.java

示例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);
	}

}
 
开发者ID:ksgwr,项目名称:MessagePackTemplate,代码行数:15,代码来源:ObjectTemplate.java

示例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);
	}
}
 
开发者ID:ksgwr,项目名称:MessagePackTemplate,代码行数:33,代码来源:MapObjectTemplate.java

示例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);
    }
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:21,代码来源:MessagePack.java

示例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);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:12,代码来源:IntegerTemplate.java

示例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);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:12,代码来源:BigIntegerTemplate.java

示例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();
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:16,代码来源:DoubleArrayTemplate.java

示例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);
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:12,代码来源:StringTemplate.java

示例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();
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:16,代码来源:IntegerArrayTemplate.java

示例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());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:15,代码来源:TestPackConvert.java


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