Skip to content

Commit b6d97e1

Browse files
committed
added read(Template) in AbstractUnpacker and Unpacker classes
1 parent 647487f commit b6d97e1

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/org/msgpack/unpacker/AbstractUnpacker.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,20 @@ public <T> T read(T to) throws IOException {
8787
Template<? super T> tmpl = msgpack.lookup((Class<T>) to.getClass());
8888
return (T) tmpl.read(this, to);
8989
}
90-
}
9190

91+
@Override
92+
public <T> T read(Template<T> tmpl) throws IOException {
93+
if (tryReadNil()) {
94+
return null;
95+
}
96+
return (T) tmpl.read(this, null);
97+
}
98+
99+
@Override
100+
public <T> T read(T to, Template<T> tmpl) throws IOException {
101+
if(tryReadNil()) {
102+
return null;
103+
}
104+
return (T) tmpl.read(this, to);
105+
}
106+
}

src/main/java/org/msgpack/unpacker/Unpacker.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.nio.ByteBuffer;
2323
import java.math.BigInteger;
2424
import java.lang.Iterable;
25+
26+
import org.msgpack.template.Template;
2527
import org.msgpack.type.Value;
2628

2729
/**
@@ -34,6 +36,10 @@ public interface Unpacker extends Iterable<Value>, Closeable {
3436

3537
public <T> T read(T to) throws IOException;
3638

39+
public <T> T read(Template<T> tmpl) throws IOException;
40+
41+
public <T> T read(T to, Template<T> tmpl) throws IOException;
42+
3743
public void skip() throws IOException;
3844

3945

0 commit comments

Comments
 (0)