@@ -212,11 +212,28 @@ private Feature(boolean defaultState) {
212
212
*/
213
213
protected byte [] _binaryValue ;
214
214
215
+ /**
216
+ * Helper variables used when dealing with chunked content.
217
+ */
218
+ private int _chunkLeft , _chunkEnd ;
219
+
215
220
/**
216
221
* We will keep track of tag value for possible future use.
217
222
*/
218
223
protected int _tagValue = -1 ;
219
224
225
+ /**
226
+ * Flag that indicates that the current token has not yet
227
+ * been fully processed, and needs to be finished for
228
+ * some access (or skipped to obtain the next token)
229
+ */
230
+ protected boolean _tokenIncomplete = false ;
231
+
232
+ /**
233
+ * Type byte of the current token
234
+ */
235
+ protected int _typeByte ;
236
+
220
237
/*
221
238
/**********************************************************
222
239
/* Input source config, state (from ex StreamBasedParserBase)
@@ -246,29 +263,6 @@ private Feature(boolean defaultState) {
246
263
*/
247
264
protected boolean _bufferRecyclable ;
248
265
249
- /*
250
- /**********************************************************
251
- /* Additional parsing state
252
- /**********************************************************
253
- */
254
-
255
- /**
256
- * Flag that indicates that the current token has not yet
257
- * been fully processed, and needs to be finished for
258
- * some access (or skipped to obtain the next token)
259
- */
260
- protected boolean _tokenIncomplete = false ;
261
-
262
- /**
263
- * Type byte of the current token
264
- */
265
- protected int _typeByte ;
266
-
267
- /**
268
- * Helper variables used when dealing with chunked content.
269
- */
270
- private int _chunkLeft , _chunkEnd ;
271
-
272
266
/*
273
267
/**********************************************************
274
268
/* Symbol handling, decoding
@@ -379,10 +373,10 @@ public void setCodec(ObjectCodec c) {
379
373
_objectCodec = c ;
380
374
}
381
375
382
- /*
383
- /**********************************************************
384
- /* Versioned
385
- /**********************************************************
376
+ /*
377
+ /**********************************************************
378
+ /* Versioned
379
+ /**********************************************************
386
380
*/
387
381
388
382
@ Override
@@ -619,24 +613,25 @@ public JsonToken nextToken() throws IOException
619
613
return _handleCBOREOF ();
620
614
}
621
615
}
622
- int ch = _inputBuffer [_inputPtr ++];
623
- int type = (ch >> 5 ) & 0x7 ;
616
+ int ch = _inputBuffer [_inputPtr ++] & 0xFF ;
617
+ int type = (ch >> 5 );
618
+ int lowBits = ch & 0x1F ;
624
619
625
620
// One special case: need to consider tag as prefix first:
626
621
if (type == 6 ) {
627
- _tagValue = Integer .valueOf (_decodeTag (ch & 0x1F ));
622
+ _tagValue = Integer .valueOf (_decodeTag (lowBits ));
628
623
if (_inputPtr >= _inputEnd ) {
629
624
if (!loadMore ()) {
630
625
return _handleCBOREOF ();
631
626
}
632
627
}
633
- ch = _inputBuffer [_inputPtr ++];
634
- type = (ch >> 5 ) & 0x7 ;
628
+ ch = _inputBuffer [_inputPtr ++] & 0xFF ;
629
+ type = (ch >> 5 );
630
+ lowBits = ch & 0x1F ;
635
631
} else {
636
632
_tagValue = -1 ;
637
633
}
638
634
639
- final int lowBits = ch & 0x1F ;
640
635
switch (type ) {
641
636
case 0 : // positive int
642
637
_numTypesValid = NR_INT ;
@@ -758,7 +753,8 @@ public JsonToken nextToken() throws IOException
758
753
759
754
case 6 : // another tag; not allowed
760
755
_reportError ("Multiple tags not allowed per value (first tag: " +_tagValue +")" );
761
-
756
+
757
+ case 7 :
762
758
default : // misc: tokens, floats
763
759
switch (lowBits ) {
764
760
case 20 :
@@ -797,9 +793,8 @@ public JsonToken nextToken() throws IOException
797
793
// Object end-marker can't occur here
798
794
_reportUnexpectedBreak ();
799
795
}
800
- _invalidToken ( ch );
796
+ return ( _currToken = _decodeSimpleValue ( lowBits , ch ) );
801
797
}
802
- return null ;
803
798
}
804
799
805
800
protected String _numberToName (int ch , boolean neg ) throws IOException
@@ -939,23 +934,24 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
939
934
return false ;
940
935
}
941
936
}
942
- int ch = _inputBuffer [_inputPtr ++];
943
- int type = (ch >> 5 ) & 0x7 ;
937
+ int ch = _inputBuffer [_inputPtr ++] & 0xFF ;
938
+ int type = (ch >> 5 );
939
+ int lowBits = ch & 0x1F ;
944
940
945
941
// 01-Nov-2019, tatu: We may actually need tag so decode it, but do not assign
946
942
// (that'd override tag we already have)
947
943
int tagValue = -1 ;
948
944
if (type == 6 ) {
949
- tagValue = _decodeTag (ch & 0x1F );
945
+ tagValue = _decodeTag (lowBits );
950
946
if ((_inputPtr >= _inputEnd ) && !loadMore ()) {
951
947
_handleCBOREOF ();
952
948
return false ;
953
949
}
954
- ch = _inputBuffer [_inputPtr ++];
955
- type = (ch >> 5 ) & 0x7 ;
950
+ ch = _inputBuffer [_inputPtr ++] & 0xFF ;
951
+ type = (ch >> 5 );
952
+ lowBits = ch & 0x1F ;
956
953
}
957
-
958
- final int lowBits = ch & 0x1F ;
954
+
959
955
switch (type ) {
960
956
case 0 : // positive int
961
957
_numTypesValid = NR_INT ;
@@ -1285,25 +1281,26 @@ public String nextTextValue() throws IOException
1285
1281
return null ;
1286
1282
}
1287
1283
}
1288
- int ch = _inputBuffer [_inputPtr ++];
1289
- int type = (ch >> 5 ) & 0x7 ;
1284
+ int ch = _inputBuffer [_inputPtr ++] & 0xFF ;
1285
+ int type = (ch >> 5 );
1286
+ int lowBits = ch & 0x1F ;
1290
1287
1291
1288
// One special case: need to consider tag as prefix first:
1292
1289
if (type == 6 ) {
1293
- _tagValue = Integer .valueOf (_decodeTag (ch & 0x1F ));
1290
+ _tagValue = Integer .valueOf (_decodeTag (lowBits ));
1294
1291
if (_inputPtr >= _inputEnd ) {
1295
1292
if (!loadMore ()) {
1296
1293
_handleCBOREOF ();
1297
1294
return null ;
1298
1295
}
1299
1296
}
1300
- ch = _inputBuffer [_inputPtr ++];
1301
- type = (ch >> 5 ) & 0x7 ;
1297
+ ch = _inputBuffer [_inputPtr ++] & 0xFF ;
1298
+ type = (ch >> 5 );
1299
+ lowBits = ch & 0x1F ;
1302
1300
} else {
1303
1301
_tagValue = -1 ;
1304
1302
}
1305
-
1306
- final int lowBits = ch & 0x1F ;
1303
+
1307
1304
switch (type ) {
1308
1305
case 0 : // positive int
1309
1306
_numTypesValid = NR_INT ;
@@ -1425,6 +1422,7 @@ public String nextTextValue() throws IOException
1425
1422
case 6 : // another tag; not allowed
1426
1423
_reportError ("Multiple tags not allowed per value (first tag: " +_tagValue +")" );
1427
1424
1425
+ case 7 :
1428
1426
default : // misc: tokens, floats
1429
1427
switch (lowBits ) {
1430
1428
case 20 :
@@ -1471,10 +1469,9 @@ public String nextTextValue() throws IOException
1471
1469
// Object end-marker can't occur here
1472
1470
_reportUnexpectedBreak ();
1473
1471
}
1474
- _invalidToken (ch );
1472
+ _currToken = _decodeSimpleValue (lowBits , ch );
1473
+ return null ;
1475
1474
}
1476
- // otherwise fall back to generic handling:
1477
- return (nextToken () == JsonToken .VALUE_STRING ) ? getText () : null ;
1478
1475
}
1479
1476
1480
1477
@ Override
@@ -3118,6 +3115,44 @@ protected JsonToken _decodeUndefinedValue() throws IOException {
3118
3115
return JsonToken .VALUE_NULL ;
3119
3116
}
3120
3117
3118
+ /**
3119
+ * Helper method that deals with details of decoding unallocated "simple values"
3120
+ * and exposing them as expected token.
3121
+ *<p>
3122
+ * As of Jackson 2.12, simple values are exposed as
3123
+ * {@link JsonToken#VALUE_NUMBER_INT}s,
3124
+ * but in later versions this is planned to be changed to separate value type.
3125
+ *
3126
+ * @since 2.12
3127
+ */
3128
+ public JsonToken _decodeSimpleValue (int lowBits , int ch ) throws IOException {
3129
+ if (lowBits > 24 ) {
3130
+ _invalidToken (ch );
3131
+ }
3132
+ if (lowBits < 24 ) {
3133
+ _numberInt = lowBits ;
3134
+ } else { // need another byte
3135
+ if (_inputPtr >= _inputEnd ) {
3136
+ loadMoreGuaranteed ();
3137
+ }
3138
+ _numberInt = _inputBuffer [_inputPtr ++] & 0xFF ;
3139
+ // As per CBOR spec, values below 32 not allowed to avoid
3140
+ // confusion (as well as guarantee uniqueness of encoding)
3141
+ if (_numberInt < 32 ) {
3142
+ throw _constructError ("Invalid second byte for simple value: 0x"
3143
+ +Integer .toHexString (_numberInt )+" (only values 0x20 - 0xFF allowed)" );
3144
+ }
3145
+ }
3146
+
3147
+ // 25-Nov-2020, tatu: Although ideally we should report these
3148
+ // as `JsonToken.VALUE_EMBEDDED_OBJECT`, due to late addition
3149
+ // of handling in 2.12, simple value in 2.12 will be reported
3150
+ // as simple ints.
3151
+
3152
+ _numTypesValid = NR_INT ;
3153
+ return (JsonToken .VALUE_NUMBER_INT );
3154
+ }
3155
+
3121
3156
/*
3122
3157
/**********************************************************
3123
3158
/* Internal methods, UTF8 decoding
@@ -3285,7 +3320,6 @@ protected ByteArrayBuilder _getByteArrayBuilder() {
3285
3320
return _byteArrayBuilder ;
3286
3321
}
3287
3322
3288
- @ SuppressWarnings ("deprecation" )
3289
3323
protected void _closeInput () throws IOException {
3290
3324
if (_inputStream != null ) {
3291
3325
if (_ioContext .isResourceManaged () || isEnabled (JsonParser .Feature .AUTO_CLOSE_SOURCE )) {
0 commit comments