@@ -235,17 +235,9 @@ public static MessageUnpacker newDefaultUnpacker(byte[] contents, int offset, in
235235 */
236236 public static class PackerConfig
237237 {
238- /**
239- * Use String.getBytes() for converting Java Strings that are smaller than this threshold into UTF8.
240- * Note that this parameter is subject to change.
241- */
242- public int smallStringOptimizationThreshold = 512 ;
238+ private int smallStringOptimizationThreshold = 512 ;
243239
244- /**
245- * When the next payload size exceeds this threshold, MessagePacker will call MessageBufferOutput.flush() before
246- * packing the data.
247- */
248- public int bufferFlushThreshold = 8192 ;
240+ private int bufferFlushThreshold = 8192 ;
249241
250242 /**
251243 * Create a packer that outputs the packed data to a given output
@@ -289,42 +281,57 @@ public MessageBufferPacker newBufferPacker()
289281 {
290282 return new MessageBufferPacker (this );
291283 }
284+
285+ /**
286+ * Use String.getBytes() for converting Java Strings that are smaller than this threshold into UTF8.
287+ * Note that this parameter is subject to change.
288+ */
289+ public PackerConfig setSmallStringOptimizationThreshold (int bytes )
290+ {
291+ this .smallStringOptimizationThreshold = bytes ;
292+ return this ;
293+ }
294+
295+ public int getSmallStringOptimizationThreshold ()
296+ {
297+ return smallStringOptimizationThreshold ;
298+ }
299+
300+ /**
301+ * When the next payload size exceeds this threshold, MessagePacker will call MessageBufferOutput.flush() before
302+ * packing the data.
303+ */
304+ public PackerConfig setBufferFlushThreshold (int bytes )
305+ {
306+ this .bufferFlushThreshold = bytes ;
307+ return this ;
308+ }
309+
310+ public int getBufferFlushThreshold ()
311+ {
312+ return bufferFlushThreshold ;
313+ }
292314 }
293315
294316 /**
295317 * MessageUnpacker configuration.
296318 */
297319 public static class UnpackerConfig
298320 {
299- /**
300- * Allow unpackBinaryHeader to read str format family (default:true)
301- */
302- public boolean allowReadingStringAsBinary = true ;
321+ private boolean allowReadingStringAsBinary = true ;
303322
304- /**
305- * Allow unpackRawStringHeader and unpackString to read bin format family (default: true)
306- */
307- public boolean allowReadingBinaryAsString = true ;
323+ private boolean allowReadingBinaryAsString = true ;
308324
309- /**
310- * Action when encountered a malformed input
311- */
312- public CodingErrorAction actionOnMalformedString = CodingErrorAction .REPLACE ;
325+ private CodingErrorAction actionOnMalformedString = CodingErrorAction .REPLACE ;
313326
314- /**
315- * Action when an unmappable character is found
316- */
317- public CodingErrorAction actionOnUnmappableString = CodingErrorAction .REPLACE ;
327+ private CodingErrorAction actionOnUnmappableString = CodingErrorAction .REPLACE ;
318328
319- /**
320- * unpackString size limit. (default: Integer.MAX_VALUE)
321- */
322- public int stringSizeLimit = Integer .MAX_VALUE ;
329+ private int stringSizeLimit = Integer .MAX_VALUE ;
323330
324331 /**
325332 *
326333 */
327- public int stringDecoderBufferSize = 8192 ;
334+ private int stringDecoderBufferSize = 8192 ;
328335
329336 /**
330337 * Create an unpacker that reads the data from a given input
@@ -380,5 +387,89 @@ public MessageUnpacker newUnpacker(byte[] contents, int offset, int length)
380387 {
381388 return newUnpacker (new ArrayBufferInput (contents , offset , length ));
382389 }
390+
391+ /**
392+ * Allow unpackBinaryHeader to read str format family (default:true)
393+ */
394+ public UnpackerConfig setAllowReadingStringAsBinary (boolean enable )
395+ {
396+ this .allowReadingStringAsBinary = enable ;
397+ return this ;
398+ }
399+
400+ public boolean getAllowReadingStringAsBinary ()
401+ {
402+ return allowReadingStringAsBinary ;
403+ }
404+
405+ /**
406+ * Allow unpackString and unpackRawStringHeader and unpackString to read bin format family (default: true)
407+ */
408+ public UnpackerConfig setAllowReadingBinaryAsString (boolean enable )
409+ {
410+ this .allowReadingBinaryAsString = enable ;
411+ return this ;
412+ }
413+
414+ public boolean getAllowReadingBinaryAsString ()
415+ {
416+ return allowReadingBinaryAsString ;
417+ }
418+
419+ /**
420+ * Action when encountered a malformed input (default: REPLACE)
421+ */
422+ public UnpackerConfig setActionOnMalformedString (CodingErrorAction action )
423+ {
424+ this .actionOnMalformedString = action ;
425+ return this ;
426+ }
427+
428+ public CodingErrorAction getActionOnMalformedString ()
429+ {
430+ return actionOnMalformedString ;
431+ }
432+
433+ /**
434+ * Action when an unmappable character is found (default: REPLACE)
435+ */
436+ public UnpackerConfig setActionOnUnmappableString (CodingErrorAction action )
437+ {
438+ this .actionOnUnmappableString = action ;
439+ return this ;
440+ }
441+
442+ public CodingErrorAction getActionOnUnmappableString ()
443+ {
444+ return actionOnUnmappableString ;
445+ }
446+
447+ /**
448+ * unpackString size limit. (default: Integer.MAX_VALUE)
449+ */
450+ public UnpackerConfig setStringSizeLimit (int bytes )
451+ {
452+ this .stringSizeLimit = bytes ;
453+ return this ;
454+ }
455+
456+ public int getStringSizeLimit ()
457+ {
458+ return stringSizeLimit ;
459+ }
460+
461+ /**
462+ *
463+ */
464+ public UnpackerConfig setStringDecoderBufferSize (int bytes )
465+ {
466+ this .stringDecoderBufferSize = bytes ;
467+ return this ;
468+ }
469+
470+ public int getStringDecoderBufferSize ()
471+ {
472+ return stringDecoderBufferSize ;
473+ }
383474 }
384475}
0 commit comments