|
5 | 5 |
|
6 | 6 | import com.fasterxml.jackson.core.*;
|
7 | 7 | import com.fasterxml.jackson.core.io.IOContext;
|
| 8 | +import com.fasterxml.jackson.core.json.JsonReadContext; |
8 | 9 | import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
|
9 | 10 | import com.fasterxml.jackson.core.util.ByteArrayBuilder;
|
10 | 11 | import com.fasterxml.jackson.dataformat.smile.*;
|
@@ -380,6 +381,68 @@ public int readBinaryValue(Base64Variant b64variant, OutputStream out)
|
380 | 381 | return _binaryValue.length;
|
381 | 382 | }
|
382 | 383 |
|
| 384 | + /* |
| 385 | + /********************************************************************** |
| 386 | + /* Handling of nested scope, state |
| 387 | + /********************************************************************** |
| 388 | + */ |
| 389 | + |
| 390 | + protected final JsonToken _startArrayScope() throws IOException |
| 391 | + { |
| 392 | + _parsingContext = _parsingContext.createChildArrayContext(-1, -1); |
| 393 | + _majorState = MAJOR_ARRAY_ELEMENT; |
| 394 | + _majorStateAfterValue = MAJOR_ARRAY_ELEMENT; |
| 395 | + return (_currToken = JsonToken.START_ARRAY); |
| 396 | + } |
| 397 | + |
| 398 | + protected final JsonToken _startObjectScope() throws IOException |
| 399 | + { |
| 400 | + _parsingContext = _parsingContext.createChildObjectContext(-1, -1); |
| 401 | + _majorState = MAJOR_OBJECT_FIELD; |
| 402 | + _majorStateAfterValue = MAJOR_OBJECT_FIELD; |
| 403 | + return (_currToken = JsonToken.START_OBJECT); |
| 404 | + } |
| 405 | + |
| 406 | + protected final JsonToken _closeArrayScope() throws IOException |
| 407 | + { |
| 408 | + if (!_parsingContext.inArray()) { |
| 409 | + _reportMismatchedEndMarker(']', '}'); |
| 410 | + } |
| 411 | + JsonReadContext ctxt = _parsingContext.getParent(); |
| 412 | + _parsingContext = ctxt; |
| 413 | + int st; |
| 414 | + if (ctxt.inObject()) { |
| 415 | + st = MAJOR_OBJECT_FIELD; |
| 416 | + } else if (ctxt.inArray()) { |
| 417 | + st = MAJOR_ARRAY_ELEMENT; |
| 418 | + } else { |
| 419 | + st = MAJOR_ROOT; |
| 420 | + } |
| 421 | + _majorState = st; |
| 422 | + _majorStateAfterValue = st; |
| 423 | + return (_currToken = JsonToken.END_ARRAY); |
| 424 | + } |
| 425 | + |
| 426 | + protected final JsonToken _closeObjectScope() throws IOException |
| 427 | + { |
| 428 | + if (!_parsingContext.inObject()) { |
| 429 | + _reportMismatchedEndMarker('}', ']'); |
| 430 | + } |
| 431 | + JsonReadContext ctxt = _parsingContext.getParent(); |
| 432 | + _parsingContext = ctxt; |
| 433 | + int st; |
| 434 | + if (ctxt.inObject()) { |
| 435 | + st = MAJOR_OBJECT_FIELD; |
| 436 | + } else if (ctxt.inArray()) { |
| 437 | + st = MAJOR_ARRAY_ELEMENT; |
| 438 | + } else { |
| 439 | + st = MAJOR_ROOT; |
| 440 | + } |
| 441 | + _majorState = st; |
| 442 | + _majorStateAfterValue = st; |
| 443 | + return (_currToken = JsonToken.END_OBJECT); |
| 444 | + } |
| 445 | + |
383 | 446 | /*
|
384 | 447 | /**********************************************************************
|
385 | 448 | /* Internal methods, field name parsing
|
@@ -606,6 +669,22 @@ public void _initByteArrayBuilder()
|
606 | 669 | /**********************************************************************
|
607 | 670 | */
|
608 | 671 |
|
| 672 | + protected void _reportMissingHeader(int unmaskedFirstByte) throws IOException |
| 673 | + { |
| 674 | + String msg; |
| 675 | + int b = unmaskedFirstByte & 0xFF; |
| 676 | + // let's speculate on problem a bit, too |
| 677 | + if (b == '{' || b == '[') { |
| 678 | + msg = "Input does not start with Smile format header (first byte = 0x" |
| 679 | + +Integer.toHexString(b & 0xFF)+") -- rather, it starts with '"+((char) b) |
| 680 | + +"' (plain JSON input?) -- can not parse"; |
| 681 | + } else { |
| 682 | + msg = "Input does not start with Smile format header (first byte = 0x" |
| 683 | + +Integer.toHexString(b & 0xFF)+") and parser has REQUIRE_HEADER enabled: can not parse"; |
| 684 | + } |
| 685 | + throw new JsonParseException(this, msg); |
| 686 | + } |
| 687 | + |
609 | 688 | protected void _reportInvalidSharedName(int index) throws IOException
|
610 | 689 | {
|
611 | 690 | if (_seenNames == null) {
|
|
0 commit comments