Skip to content

Commit d29276f

Browse files
committed
Revert the removed configuration comments and use more redable configuration names
1 parent 1fab3f7 commit d29276f

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

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

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ public static MessageUnpacker newDefaultUnpacker(byte[] contents, int offset, in
147147
*/
148148
public static class PackerConfig
149149
{
150+
/**
151+
* Use String.getBytes() for converting Java Strings that are smaller than this threshold into UTF8.
152+
* Note that this parameter is subject to change.
153+
*/
150154
public int smallStringOptimizationThreshold = 512;
151155

152156
/**
@@ -155,7 +159,8 @@ public static class PackerConfig
155159
* @param out
156160
* @return
157161
*/
158-
public MessagePacker newPacker(MessageBufferOutput out) {
162+
public MessagePacker newPacker(MessageBufferOutput out)
163+
{
159164
return new MessagePacker(out, this);
160165
}
161166

@@ -165,7 +170,8 @@ public MessagePacker newPacker(MessageBufferOutput out) {
165170
* @param out
166171
* @return
167172
*/
168-
public MessagePacker newPacker(OutputStream out) {
173+
public MessagePacker newPacker(OutputStream out)
174+
{
169175
return newPacker(new OutputStreamBufferOutput(out));
170176
}
171177

@@ -175,7 +181,8 @@ public MessagePacker newPacker(OutputStream out) {
175181
* @param channel
176182
* @return
177183
*/
178-
public MessagePacker newPacker(WritableByteChannel channel) {
184+
public MessagePacker newPacker(WritableByteChannel channel)
185+
{
179186
return newPacker(new ChannelBufferOutput(channel));
180187
}
181188

@@ -184,7 +191,8 @@ public MessagePacker newPacker(WritableByteChannel channel) {
184191
*
185192
* @return
186193
*/
187-
public MessageBufferPacker newBufferPacker() {
194+
public MessageBufferPacker newBufferPacker()
195+
{
188196
return new MessageBufferPacker(this);
189197
}
190198
}
@@ -194,11 +202,34 @@ public MessageBufferPacker newBufferPacker() {
194202
*/
195203
public static class UnpackerConfig
196204
{
197-
public boolean allowStringAsBinary = true;
198-
public boolean allowBinaryAsString = true;
205+
/**
206+
* Allow unpackBinaryHeader to read str format family (default:true)
207+
*/
208+
public boolean allowReadingStringAsBinary = true;
209+
210+
/**
211+
* Allow unpackRawStringHeader and unpackString to read bin format family (default: true)
212+
*/
213+
public boolean allowReadingBinaryAsString = true;
214+
215+
/**
216+
* Action when encountered a malformed input
217+
*/
199218
public CodingErrorAction actionOnMalformedString = CodingErrorAction.REPLACE;
219+
220+
/**
221+
* Action when an unmappable character is found
222+
*/
200223
public CodingErrorAction actionOnUnmappableString = CodingErrorAction.REPLACE;
224+
225+
/**
226+
* unpackString size limit. (default: Integer.MAX_VALUE)
227+
*/
201228
public int stringSizeLimit = Integer.MAX_VALUE;
229+
230+
/**
231+
*
232+
*/
202233
public int stringDecoderBufferSize = 8192;
203234

204235
/**
@@ -207,7 +238,8 @@ public static class UnpackerConfig
207238
* @param in
208239
* @return
209240
*/
210-
public MessageUnpacker newUnpacker(MessageBufferInput in) {
241+
public MessageUnpacker newUnpacker(MessageBufferInput in)
242+
{
211243
return new MessageUnpacker(in, this);
212244
}
213245

@@ -217,7 +249,8 @@ public MessageUnpacker newUnpacker(MessageBufferInput in) {
217249
* @param in
218250
* @return
219251
*/
220-
public MessageUnpacker newUnpacker(InputStream in) {
252+
public MessageUnpacker newUnpacker(InputStream in)
253+
{
221254
return newUnpacker(new InputStreamBufferInput(in));
222255
}
223256

@@ -227,7 +260,8 @@ public MessageUnpacker newUnpacker(InputStream in) {
227260
* @param channel
228261
* @return
229262
*/
230-
public MessageUnpacker newUnpacker(ReadableByteChannel channel) {
263+
public MessageUnpacker newUnpacker(ReadableByteChannel channel)
264+
{
231265
return newUnpacker(new ChannelBufferInput(channel));
232266
}
233267

@@ -237,7 +271,8 @@ public MessageUnpacker newUnpacker(ReadableByteChannel channel) {
237271
* @param contents
238272
* @return
239273
*/
240-
public MessageUnpacker newUnpacker(byte[] contents) {
274+
public MessageUnpacker newUnpacker(byte[] contents)
275+
{
241276
return newUnpacker(new ArrayBufferInput(contents));
242277
}
243278

@@ -247,9 +282,9 @@ public MessageUnpacker newUnpacker(byte[] contents) {
247282
* @param contents
248283
* @return
249284
*/
250-
public MessageUnpacker newUnpacker(byte[] contents, int offset, int length) {
285+
public MessageUnpacker newUnpacker(byte[] contents, int offset, int length)
286+
{
251287
return newUnpacker(new ArrayBufferInput(contents, offset, length));
252288
}
253-
254289
}
255290
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public class MessageUnpacker
7373

7474
private static final byte HEAD_BYTE_REQUIRED = (byte) 0xc1;
7575

76-
private final boolean allowStringAsBinary;
77-
private final boolean allowBinaryAsString;
76+
private final boolean allowReadingStringAsBinary;
77+
private final boolean allowReadingBinaryAsString;
7878
private final CodingErrorAction actionOnMalformedString;
7979
private final CodingErrorAction actionOnUnmappableString;
8080
private final int stringSizeLimit;
@@ -134,10 +134,10 @@ public MessageUnpacker(MessageBufferInput in, MessagePack.UnpackerConfig config)
134134
{
135135
this.in = checkNotNull(in, "MessageBufferInput is null");
136136
// We need to copy the configuration parameters since the config object is mutable
137-
this.allowStringAsBinary = config.allowStringAsBinary;
138-
this.allowBinaryAsString = config.allowBinaryAsString;
137+
this.allowReadingStringAsBinary = config.allowReadingStringAsBinary;
138+
this.allowReadingBinaryAsString = config.allowReadingBinaryAsString;
139139
this.actionOnMalformedString = config.actionOnMalformedString;
140-
this.actionOnUnmappableString = config.actionOnUnmappableString;
140+
this.actionOnUnmappableString = config.actionOnUnmappableString;
141141
this.stringSizeLimit = config.stringSizeLimit;
142142
this.stringDecoderBufferSize = config.stringDecoderBufferSize;
143143
}
@@ -1149,7 +1149,7 @@ public int unpackRawStringHeader()
11491149
return len;
11501150
}
11511151

1152-
if (allowBinaryAsString) {
1152+
if (allowReadingBinaryAsString) {
11531153
len = tryReadBinaryHeader(b);
11541154
if (len >= 0) {
11551155
return len;
@@ -1170,7 +1170,7 @@ public int unpackBinaryHeader()
11701170
return len;
11711171
}
11721172

1173-
if (allowStringAsBinary) {
1173+
if (allowReadingStringAsBinary) {
11741174
len = tryReadStringHeader(b);
11751175
if (len >= 0) {
11761176
return len;

0 commit comments

Comments
 (0)