Skip to content

Commit 13a33df

Browse files
committed
creating default instances for packer & unpacker config objects.
this will reduce also the amount of created objects in application lifecycle, as they don't share state.
1 parent 61d341d commit 13a33df

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public class MessagePack
3737
{
3838
public static final Charset UTF8 = Charset.forName("UTF-8");
3939

40+
/**
41+
* Default packer/unpacker configurations
42+
*/
43+
public static final PackerConfig DEFAULT_PACKER_CONFIG = new PackerConfig();
44+
public static final UnpackerConfig DEFAULT_UNPACKER_CONFIG = new UnpackerConfig();
45+
4046
/**
4147
* The prefix code set of MessagePack. See also https://github.com/msgpack/msgpack/blob/master/spec.md for details.
4248
*/
@@ -138,7 +144,7 @@ private MessagePack()
138144
*/
139145
public static MessagePacker newDefaultPacker(MessageBufferOutput out)
140146
{
141-
return new PackerConfig().newPacker(out);
147+
return DEFAULT_PACKER_CONFIG.newPacker(out);
142148
}
143149

144150
/**
@@ -149,7 +155,7 @@ public static MessagePacker newDefaultPacker(MessageBufferOutput out)
149155
*/
150156
public static MessagePacker newDefaultPacker(OutputStream out)
151157
{
152-
return new PackerConfig().newPacker(out);
158+
return DEFAULT_PACKER_CONFIG.newPacker(out);
153159
}
154160

155161
/**
@@ -160,7 +166,7 @@ public static MessagePacker newDefaultPacker(OutputStream out)
160166
*/
161167
public static MessagePacker newDefaultPacker(WritableByteChannel channel)
162168
{
163-
return new PackerConfig().newPacker(channel);
169+
return DEFAULT_PACKER_CONFIG.newPacker(channel);
164170
}
165171

166172
/**
@@ -170,7 +176,7 @@ public static MessagePacker newDefaultPacker(WritableByteChannel channel)
170176
*/
171177
public static MessageBufferPacker newDefaultBufferPacker()
172178
{
173-
return new PackerConfig().newBufferPacker();
179+
return DEFAULT_PACKER_CONFIG.newBufferPacker();
174180
}
175181

176182
/**
@@ -181,7 +187,7 @@ public static MessageBufferPacker newDefaultBufferPacker()
181187
*/
182188
public static MessageUnpacker newDefaultUnpacker(MessageBufferInput in)
183189
{
184-
return new UnpackerConfig().newUnpacker(in);
190+
return DEFAULT_UNPACKER_CONFIG.newUnpacker(in);
185191
}
186192

187193
/**
@@ -192,7 +198,7 @@ public static MessageUnpacker newDefaultUnpacker(MessageBufferInput in)
192198
*/
193199
public static MessageUnpacker newDefaultUnpacker(InputStream in)
194200
{
195-
return new UnpackerConfig().newUnpacker(in);
201+
return DEFAULT_UNPACKER_CONFIG.newUnpacker(in);
196202
}
197203

198204
/**
@@ -203,7 +209,7 @@ public static MessageUnpacker newDefaultUnpacker(InputStream in)
203209
*/
204210
public static MessageUnpacker newDefaultUnpacker(ReadableByteChannel channel)
205211
{
206-
return new UnpackerConfig().newUnpacker(channel);
212+
return DEFAULT_UNPACKER_CONFIG.newUnpacker(channel);
207213
}
208214

209215
/**
@@ -214,7 +220,7 @@ public static MessageUnpacker newDefaultUnpacker(ReadableByteChannel channel)
214220
*/
215221
public static MessageUnpacker newDefaultUnpacker(byte[] contents)
216222
{
217-
return new UnpackerConfig().newUnpacker(contents);
223+
return DEFAULT_UNPACKER_CONFIG.newUnpacker(contents);
218224
}
219225

220226
/**
@@ -227,7 +233,7 @@ public static MessageUnpacker newDefaultUnpacker(byte[] contents)
227233
*/
228234
public static MessageUnpacker newDefaultUnpacker(byte[] contents, int offset, int length)
229235
{
230-
return new UnpackerConfig().newUnpacker(contents, offset, length);
236+
return DEFAULT_UNPACKER_CONFIG.newUnpacker(contents, offset, length);
231237
}
232238

233239
/**

0 commit comments

Comments
 (0)