@@ -49,106 +49,6 @@ public class CBORGenerator extends GeneratorBase
4949 */
5050 private final static int MAX_LONG_STRING_BYTES = (MAX_LONG_STRING_CHARS * 3 ) + 3 ;
5151
52- /**
53- * Enumeration that defines all togglable features for CBOR generator.
54- */
55- public enum Feature implements FormatFeature {
56- /**
57- * Feature that determines whether generator should try to use smallest
58- * (size-wise) integer representation: if true, will use smallest
59- * representation that is enough to retain value; if false, will use
60- * length indicated by argument type (4-byte for <code>int</code>,
61- * 8-byte for <code>long</code> and so on).
62- */
63- WRITE_MINIMAL_INTS (true ),
64-
65- /**
66- * Feature that determines whether CBOR "Self-Describe Tag" (value
67- * 55799, encoded as 3-byte sequence of <code>0xD9, 0xD9, 0xF7</code>)
68- * should be written at the beginning of document or not.
69- * <p>
70- * Default value is {@code false} meaning that type tag will not be
71- * written at the beginning of a new document.
72- */
73- WRITE_TYPE_HEADER (false ),
74-
75- /**
76- * Feature that determines if an invalid surrogate encoding found in the
77- * incoming String should fail with an exception or silently be output
78- * as the Unicode 'REPLACEMENT CHARACTER' (U+FFFD) or not; if not,
79- * an exception will be thrown to indicate invalid content.
80- * <p>
81- * Default value is {@code false} (for backwards compatibility) meaning that
82- * an invalid surrogate will result in exception ({@code StreamWriteException}).
83- */
84- LENIENT_UTF_ENCODING (false ),
85-
86- /**
87- * Feature that determines if string references are generated based on the
88- * <a href="http://cbor.schmorp.de/stringref">stringref</a>) extension. This can save
89- * storage space, parsing time, and pool string memory when parsing. Readers of the output
90- * must also support the stringref extension to properly decode the data. Extra overhead may
91- * be added to generation time and memory usage to compute the shared binary and text
92- * strings.
93- * <p>
94- * Default value is {@code false} meaning that the stringref extension will not be used.
95- *
96- * @since 2.15
97- */
98- STRINGREF (false ),
99-
100- /**
101- * Feature that determines whether generator should try to write doubles
102- * as floats: if {@code true}, will write a {@code double} as a 4-byte float if no
103- * precision loss will occur; if {@code false}, will always write a {@code double}
104- * as an 8-byte double.
105- * <p>
106- * Default value is {@code false} meaning that doubles will always be written as
107- * 8-byte values.
108- *
109- * @since 2.15
110- */
111- WRITE_MINIMAL_DOUBLES (false ),
112- ;
113-
114- protected final boolean _defaultState ;
115- protected final int _mask ;
116-
117- /**
118- * Method that calculates bit set (flags) of all features that are
119- * enabled by default.
120- */
121- public static int collectDefaults () {
122- int flags = 0 ;
123- for (Feature f : values ()) {
124- if (f .enabledByDefault ()) {
125- flags |= f .getMask ();
126- }
127- }
128- return flags ;
129- }
130-
131- private Feature (boolean defaultState ) {
132- _defaultState = defaultState ;
133- _mask = (1 << ordinal ());
134- }
135-
136- @ Override
137- public boolean enabledByDefault () {
138- return _defaultState ;
139- }
140-
141- @ Override
142- public boolean enabledIn (int flags ) {
143- return (flags & getMask ()) != 0 ;
144- }
145-
146- @ Override
147- public int getMask () {
148- return _mask ;
149- }
150- }
151-
15252 /**
15353 * To simplify certain operations, we require output buffer length to allow
15454 * outputting of contiguous 256 character UTF-8 encoded String value. Length
@@ -176,7 +76,7 @@ public int getMask() {
17676
17777 /**
17878 * Bit flag composed of bits that indicate which
179- * {@link CBORGenerator.Feature }s are enabled.
79+ * {@link CBORWriteFeature }s are enabled.
18080 */
18181 protected final int _formatFeatures ;
18282
@@ -280,11 +180,11 @@ public CBORGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt,
280180 ? DupDetector .rootDetector (this )
281181 : null ;
282182 _streamWriteContext = CBORWriteContext .createRootContext (dups );
283- _cfgMinimalInts = Feature .WRITE_MINIMAL_INTS .enabledIn (formatFeatures );
284- _cfgMinimalDoubles = Feature .WRITE_MINIMAL_DOUBLES .enabledIn (formatFeatures );
183+ _cfgMinimalInts = CBORWriteFeature .WRITE_MINIMAL_INTS .enabledIn (formatFeatures );
184+ _cfgMinimalDoubles = CBORWriteFeature .WRITE_MINIMAL_DOUBLES .enabledIn (formatFeatures );
285185 _out = out ;
286186 _bufferRecyclable = true ;
287- _stringRefs = Feature .STRINGREF .enabledIn (formatFeatures ) ? new HashMap <>() : null ;
187+ _stringRefs = CBORWriteFeature .STRINGREF .enabledIn (formatFeatures ) ? new HashMap <>() : null ;
288188 _outputBuffer = ioCtxt .allocWriteEncodingBuffer (BYTE_BUFFER_FOR_OUTPUT );
289189 _outputEnd = _outputBuffer .length ;
290190 _charBuffer = ioCtxt .allocConcatBuffer ();
@@ -317,13 +217,13 @@ public CBORGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt,
317217 ? DupDetector .rootDetector (this )
318218 : null ;
319219 _streamWriteContext = CBORWriteContext .createRootContext (dups );
320- _cfgMinimalInts = Feature .WRITE_MINIMAL_INTS .enabledIn (formatFeatures );
321- _cfgMinimalDoubles = Feature .WRITE_MINIMAL_DOUBLES .enabledIn (formatFeatures );
220+ _cfgMinimalInts = CBORWriteFeature .WRITE_MINIMAL_INTS .enabledIn (formatFeatures );
221+ _cfgMinimalDoubles = CBORWriteFeature .WRITE_MINIMAL_DOUBLES .enabledIn (formatFeatures );
322222 _out = out ;
323223 _bufferRecyclable = bufferRecyclable ;
324224 _outputTail = offset ;
325225 _outputBuffer = outputBuffer ;
326- _stringRefs = Feature .STRINGREF .enabledIn (formatFeatures ) ? new HashMap <>() : null ;
226+ _stringRefs = CBORWriteFeature .STRINGREF .enabledIn (formatFeatures ) ? new HashMap <>() : null ;
327227 _outputEnd = _outputBuffer .length ;
328228 _charBuffer = ioCtxt .allocConcatBuffer ();
329229 _charBufferLength = _charBuffer .length ;
@@ -422,7 +322,7 @@ public CBORGenerator disable(Feature f) {
422322 }
423323 */
424324
425- public final boolean isEnabled (Feature f ) {
325+ public final boolean isEnabled (CBORWriteFeature f ) {
426326 return (_formatFeatures & f .getMask ()) != 0 ;
427327 }
428328
@@ -1653,7 +1553,7 @@ private final int _encode2(int i, int outputPtr, String str, int len,
16531553 private int _invalidSurrogateStart (int code , byte [] outBuf , int outputPtr )
16541554 throws JacksonException
16551555 {
1656- if (isEnabled (Feature .LENIENT_UTF_ENCODING )) {
1556+ if (isEnabled (CBORWriteFeature .LENIENT_UTF_ENCODING )) {
16571557 return _appendReplacementChar (outBuf , outputPtr );
16581558 }
16591559 // Will be called in two distinct cases: either first character is
@@ -1675,7 +1575,7 @@ private int _invalidSurrogateEnd(int surr1, int surr2,
16751575 byte [] outBuf , int outputPtr )
16761576 throws JacksonException
16771577 {
1678- if (isEnabled (Feature .LENIENT_UTF_ENCODING )) {
1578+ if (isEnabled (CBORWriteFeature .LENIENT_UTF_ENCODING )) {
16791579 return _appendReplacementChar (outBuf , outputPtr );
16801580 }
16811581 _reportError (String .format (
0 commit comments