@@ -43,6 +43,31 @@ public MessagePack(MessagePack parent) {
4343 registry = new TemplateRegistry (parent .registry );
4444 }
4545
46+ public byte [] pack (Object v ) throws IOException {
47+ return pack (v , getTemplate (v .getClass ()));
48+ }
49+
50+ public byte [] pack (Object v , Template tmpl ) throws IOException { // TODO IOException
51+ BufferPacker pk = new BufferPacker ();
52+ tmpl .write (pk , v );
53+ return pk .toByteArray ();
54+ }
55+
56+ public void pack (OutputStream out , Object v ) throws IOException {
57+ pack (out , v , getTemplate (v .getClass ()));
58+ }
59+
60+ public void pack (OutputStream out , Object v , Template tmpl ) throws IOException {
61+ tmpl .write (new StreamPacker (out ), v );
62+ }
63+
64+ public byte [] pack (Value v ) throws IOException { // TODO IOException
65+ // FIXME ValueTemplate should do this
66+ BufferPacker pk = new BufferPacker ();
67+ pk .write (v );
68+ return pk .toByteArray ();
69+ }
70+
4671 public <T > T unpack (InputStream in , T v ) throws IOException {
4772 // TODO
4873 Template tmpl = getTemplate (v .getClass ());
@@ -55,6 +80,18 @@ public <T> T unpack(InputStream in, Class<T> c) throws IOException {
5580 return (T )tmpl .read (new StreamUnpacker (in ), null );
5681 }
5782
83+ public Value unpack (byte [] b ) throws IOException { // TODO IOException
84+ return unpack (b , 0 , b .length );
85+ }
86+
87+ public Value unpack (byte [] b , int off , int len ) throws IOException { // TODO IOException
88+ return new BufferUnpacker ().wrap (b , off , len ).readValue ();
89+ }
90+
91+ public Value unpack (ByteBuffer buf ) throws IOException { // TODO IOException
92+ return new BufferUnpacker ().wrap (buf ).readValue ();
93+ }
94+
5895 public <T > T unpack (byte [] b , T v ) throws IOException { // TODO IOException
5996 // TODO
6097 Template tmpl = getTemplate (v .getClass ());
@@ -87,37 +124,6 @@ public <T> T unpack(ByteBuffer b, Class<T> c) { // TODO IOException
87124 return null ;
88125 }
89126
90- public Value unpack (byte [] b ) throws IOException { // TODO IOException
91- return unpack (b , 0 , b .length );
92- }
93-
94- public Value unpack (byte [] b , int off , int len ) throws IOException { // TODO IOException
95- return new BufferUnpacker ().wrap (b , off , len ).readValue ();
96- }
97-
98- public Value unpack (ByteBuffer buf ) throws IOException { // TODO IOException
99- return new BufferUnpacker ().wrap (buf ).readValue ();
100- }
101-
102- public void pack (OutputStream out , Object v ) throws IOException {
103- Template tmpl = getTemplate (v .getClass ());
104- tmpl .write (new StreamPacker (out ), v );
105- }
106-
107- public byte [] pack (Value v ) throws IOException { // TODO IOException
108- // FIXME ValueTemplate should do this
109- BufferPacker pk = new BufferPacker ();
110- pk .write (v );
111- return pk .toByteArray ();
112- }
113-
114- public byte [] pack (Object v ) throws IOException { // TODO IOException
115- Template tmpl = getTemplate (v .getClass ());
116- BufferPacker pk = new BufferPacker ();
117- tmpl .write (pk , v );
118- return pk .toByteArray ();
119- }
120-
121127 protected Template getTemplate (Class <?> c ) {
122128 Template tmpl = registry .lookup (c );
123129 if (tmpl == null ) {
0 commit comments