mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-21 06:11:18 +01:00
add DateTemplate and BigDecimalTemplate
This commit is contained in:
parent
324f215316
commit
24a8ee436f
@ -0,0 +1,40 @@
|
|||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import org.msgpack.MessagePackObject;
|
||||||
|
import org.msgpack.MessageTypeException;
|
||||||
|
import org.msgpack.Packer;
|
||||||
|
import org.msgpack.Template;
|
||||||
|
import org.msgpack.Unpacker;
|
||||||
|
|
||||||
|
public class BigDecimalTemplate implements Template {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pack(Packer pk, Object target) throws IOException {
|
||||||
|
BigDecimal temp = (BigDecimal) target;
|
||||||
|
pk.packString(temp.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {
|
||||||
|
String temp = pac.unpackString();
|
||||||
|
return new BigDecimal(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object convert(MessagePackObject from, Object to) throws MessageTypeException {
|
||||||
|
String temp = from.asString();
|
||||||
|
return new BigDecimal(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public BigDecimalTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final BigDecimalTemplate instance = new BigDecimalTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
TemplateRegistry.register(BigDecimal.class, instance);
|
||||||
|
}
|
||||||
|
}
|
40
java/src/main/java/org/msgpack/template/DateTemplate.java
Normal file
40
java/src/main/java/org/msgpack/template/DateTemplate.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package org.msgpack.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.msgpack.MessagePackObject;
|
||||||
|
import org.msgpack.MessageTypeException;
|
||||||
|
import org.msgpack.Packer;
|
||||||
|
import org.msgpack.Template;
|
||||||
|
import org.msgpack.Unpacker;
|
||||||
|
|
||||||
|
public class DateTemplate implements Template {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pack(Packer pk, Object target) throws IOException {
|
||||||
|
Date temp = (Date) target;
|
||||||
|
pk.packLong(temp.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {
|
||||||
|
Long temp = pac.unpackLong();
|
||||||
|
return new Date(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object convert(MessagePackObject from, Object to) throws MessageTypeException {
|
||||||
|
Long temp = from.asLong();
|
||||||
|
return new Date(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public DateTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final DateTemplate instance = new DateTemplate();
|
||||||
|
|
||||||
|
static {
|
||||||
|
TemplateRegistry.register(Date.class, instance);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user