Skip to content

Commit e9ed366

Browse files
committed
added class JSON
1 parent d88ed52 commit e9ed366

3 files changed

Lines changed: 94 additions & 7 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// MessagePack for Java
3+
//
4+
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
package org.msgpack;
19+
20+
import java.io.InputStream;
21+
import java.io.OutputStream;
22+
import java.io.IOException;
23+
import java.nio.ByteBuffer;
24+
import org.msgpack.template.Template;
25+
import org.msgpack.template.TemplateRegistry;
26+
import org.msgpack.packer.Packer;
27+
import org.msgpack.packer.BufferPacker;
28+
import org.msgpack.packer.JSONPacker;
29+
import org.msgpack.packer.JSONBufferPacker;
30+
import org.msgpack.unpacker.Unpacker;
31+
import org.msgpack.unpacker.BufferUnpacker;
32+
import org.msgpack.unpacker.JSONUnpacker;
33+
import org.msgpack.unpacker.JSONBufferUnpacker;
34+
import org.msgpack.type.Value;
35+
36+
37+
public class JSON extends MessagePack {
38+
public JSON() {
39+
super();
40+
}
41+
42+
public JSON(MessagePack msgpack) {
43+
super(msgpack);
44+
}
45+
46+
47+
@Override
48+
public Packer createPacker(OutputStream stream) {
49+
return new JSONPacker(this, stream);
50+
}
51+
52+
@Override
53+
public BufferPacker createBufferPacker() {
54+
return new JSONBufferPacker(this);
55+
}
56+
57+
@Override
58+
public BufferPacker createBufferPacker(int bufferSize) {
59+
return new JSONBufferPacker(this, bufferSize);
60+
}
61+
62+
@Override
63+
public Unpacker createUnpacker(InputStream stream) {
64+
return new JSONUnpacker(this, stream);
65+
}
66+
67+
@Override
68+
public BufferUnpacker createBufferUnpacker() {
69+
return new JSONBufferUnpacker();
70+
}
71+
72+
@Override
73+
public BufferUnpacker createBufferUnpacker(byte[] b) {
74+
return createBufferUnpacker().wrap(b);
75+
}
76+
77+
@Override
78+
public BufferUnpacker createBufferUnpacker(byte[] b, int off, int len) {
79+
return createBufferUnpacker().wrap(b, off, len);
80+
}
81+
82+
@Override
83+
public BufferUnpacker createBufferUnpacker(ByteBuffer bb) {
84+
return createBufferUnpacker().wrap(bb);
85+
}
86+
}
87+

src/main/java/org/msgpack/MessagePack.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public class MessagePack {
4040
private TemplateRegistry registry;
4141

4242
public MessagePack() {
43-
registry = new TemplateRegistry();
43+
registry = new TemplateRegistry();
4444
}
4545

4646
public MessagePack(MessagePack msgpack) {
47-
registry = new TemplateRegistry(msgpack.registry);
47+
registry = new TemplateRegistry(msgpack.registry);
4848
}
4949

5050

@@ -177,7 +177,7 @@ public <T> Value unconvert(T v) throws IOException {
177177

178178

179179
public void register(Class<?> type) {
180-
registry.register(type);
180+
registry.register(type);
181181
}
182182

183183
// TODO #MN
@@ -188,7 +188,7 @@ public <T> void register(Class<T> type, Template<T> tmpl) {
188188
}
189189

190190
public <T> Template<T> lookup(Class<T> type) {
191-
return registry.lookup(type);
191+
return registry.lookup(type);
192192
}
193193

194194

@@ -206,12 +206,12 @@ public static void pack(OutputStream out, Object obj) throws IOException {
206206

207207
@Deprecated
208208
public static <T> byte[] pack(T obj, Template<T> tmpl) throws IOException { // TODO IOException
209-
return globalMessagePack.write(obj, tmpl);
209+
return globalMessagePack.write(obj, tmpl);
210210
}
211211

212212
@Deprecated
213213
public static <T> void pack(OutputStream out, T obj, Template<T> tmpl) throws IOException {
214-
globalMessagePack.write(out, obj, tmpl);
214+
globalMessagePack.write(out, obj, tmpl);
215215
}
216216

217217
@Deprecated

src/main/java/org/msgpack/packer/JSONBufferPacker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.msgpack.io.LinkedBufferOutput;
2323

2424

25-
public class JSONBufferPacker extends JSONPacker {
25+
public class JSONBufferPacker extends JSONPacker implements BufferPacker {
2626
private static final int DEFAULT_BUFFER_SIZE = 512; // TODO default buffer size
2727

2828
public JSONBufferPacker() {

0 commit comments

Comments
 (0)