本文整理汇总了Java中org.msgpack.template.Templates类的典型用法代码示例。如果您正苦于以下问题:Java Templates类的具体用法?Java Templates怎么用?Java Templates使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Templates类属于org.msgpack.template包,在下文中一共展示了Templates类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: read
import org.msgpack.template.Templates; //导入依赖的package包/类
@Override
public Object read(Unpacker u, Object to, boolean required) throws IOException {
if (!required && u.trySkipNil()) {
return null;
}
switch (u.getNextType()) {
case BOOLEAN:
return Templates.TBoolean.read(u, (Boolean) to, required);
case INTEGER:
return Templates.TInteger.read(u, (Integer) to, required);
case FLOAT:
return Templates.TFloat.read(u, (Float) to, required);
case RAW:
return Templates.TString.read(u, (String) to, required);
default:
throw new MessageTypeException("convert into unknown type is invalid");
}
}
开发者ID:pippo1980,项目名称:upns,代码行数:21,代码来源:MSGPackMarshaller.java
示例2: decode
import org.msgpack.template.Templates; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes", "resource"})
public <E> E decode(byte[] data, Class<E> messageType) throws IOException {
MessagePack msgpack = new MessagePack();
msgpack.register(Map.class, new MapTemplate(Templates.TString, new ObjectTemplate()));
msgpack.register(List.class, new ListTemplate(new ObjectTemplate()));
Value dynamic = msgpack.read(data);
Converter converter = new Converter(msgpack, dynamic);
return converter.read(messageType);
}
开发者ID:weibocom,项目名称:yar-java,代码行数:10,代码来源:MsgpackPackager.java
示例3: main
import org.msgpack.template.Templates; //导入依赖的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));
}
开发者ID:whyDK37,项目名称:pinenut,代码行数:28,代码来源:MsgPackTest.java
示例4: test
import org.msgpack.template.Templates; //导入依赖的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));
}
开发者ID:chenleijava,项目名称:springJredisCache,代码行数:28,代码来源:TestMessagePack.java
示例5: testReadTemplateNull
import org.msgpack.template.Templates; //导入依赖的package包/类
@Test
public void testReadTemplateNull() throws IOException {
Byte tbyte = u().read(Templates.TByte);
assertNull(tbyte);
Short tshort = u().read(Templates.TShort);
assertNull(tshort);
Integer tinteger = u().read(Templates.TInteger);
assertNull(tinteger);
Long tlong = u().read(Templates.TLong);
assertNull(tlong);
Character tcharacter = u().read(Templates.TCharacter);
assertNull(tcharacter);
BigInteger tbiginteger = u().read(Templates.TBigInteger);
assertNull(tbiginteger);
BigDecimal tbigdecimail = u().read(Templates.TBigDecimal);
assertNull(tbigdecimail);
Float tfloat = u().read(Templates.TFloat);
assertNull(tfloat);
Double tdouble = u().read(Templates.TDouble);
assertNull(tdouble);
Boolean tboolean = u().read(Templates.TBoolean);
assertNull(tboolean);
String tstring = u().read(Templates.TString);
assertNull(tstring);
byte[] tbytearray = u().read(Templates.TByteArray);
assertNull(tbytearray);
ByteBuffer tbytebuffer = u().read(Templates.TByteBuffer);
assertNull(tbytebuffer);
Date tdate = u().read(Templates.TDate);
assertNull(tdate);
List<String> tlist = u().read(Templates.tList(Templates.TString));
assertNull(tlist);
Map<String, Integer> tmap = u().read(
Templates.tMap(Templates.TString, Templates.TInteger));
assertNull(tmap);
Collection<Long> tcollection = u().read(
Templates.tCollection(Templates.TLong));
assertNull(tcollection);
MyEnum tordinalenum = u().read(Templates.tOrdinalEnum(MyEnum.class));
assertNull(tordinalenum);
}
开发者ID:nict-wisdom,项目名称:rasc,代码行数:59,代码来源:TestReadTemplate.java
注:本文中的org.msgpack.template.Templates类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论