Skip to content

Commit 9d8ce91

Browse files
committed
Tiny refactoring
1 parent a725954 commit 9d8ce91

File tree

2 files changed

+79
-84
lines changed

2 files changed

+79
-84
lines changed

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingByteArrayParser.java

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,88 +1836,4 @@ protected final boolean _decode7BitEncodedTail(int bytesToDecode, int buffered)
18361836
_inputCopyLen = 0;
18371837
return true;
18381838
}
1839-
1840-
/*
1841-
/**********************************************************************
1842-
/* Handling of nested scope, state
1843-
/**********************************************************************
1844-
*/
1845-
1846-
private final JsonToken _startArrayScope() throws IOException
1847-
{
1848-
_parsingContext = _parsingContext.createChildArrayContext(-1, -1);
1849-
_majorState = MAJOR_ARRAY_ELEMENT;
1850-
_majorStateAfterValue = MAJOR_ARRAY_ELEMENT;
1851-
return (_currToken = JsonToken.START_ARRAY);
1852-
}
1853-
1854-
private final JsonToken _startObjectScope() throws IOException
1855-
{
1856-
_parsingContext = _parsingContext.createChildObjectContext(-1, -1);
1857-
_majorState = MAJOR_OBJECT_FIELD;
1858-
_majorStateAfterValue = MAJOR_OBJECT_FIELD;
1859-
return (_currToken = JsonToken.START_OBJECT);
1860-
}
1861-
1862-
private final JsonToken _closeArrayScope() throws IOException
1863-
{
1864-
if (!_parsingContext.inArray()) {
1865-
_reportMismatchedEndMarker(']', '}');
1866-
}
1867-
JsonReadContext ctxt = _parsingContext.getParent();
1868-
_parsingContext = ctxt;
1869-
int st;
1870-
if (ctxt.inObject()) {
1871-
st = MAJOR_OBJECT_FIELD;
1872-
} else if (ctxt.inArray()) {
1873-
st = MAJOR_ARRAY_ELEMENT;
1874-
} else {
1875-
st = MAJOR_ROOT;
1876-
}
1877-
_majorState = st;
1878-
_majorStateAfterValue = st;
1879-
return (_currToken = JsonToken.END_ARRAY);
1880-
}
1881-
1882-
private final JsonToken _closeObjectScope() throws IOException
1883-
{
1884-
if (!_parsingContext.inObject()) {
1885-
_reportMismatchedEndMarker('}', ']');
1886-
}
1887-
JsonReadContext ctxt = _parsingContext.getParent();
1888-
_parsingContext = ctxt;
1889-
int st;
1890-
if (ctxt.inObject()) {
1891-
st = MAJOR_OBJECT_FIELD;
1892-
} else if (ctxt.inArray()) {
1893-
st = MAJOR_ARRAY_ELEMENT;
1894-
} else {
1895-
st = MAJOR_ROOT;
1896-
}
1897-
_majorState = st;
1898-
_majorStateAfterValue = st;
1899-
return (_currToken = JsonToken.END_OBJECT);
1900-
}
1901-
1902-
/*
1903-
/**********************************************************************
1904-
/* Error reporting
1905-
/**********************************************************************
1906-
*/
1907-
1908-
private void _reportMissingHeader(int unmaskedFirstByte) throws IOException
1909-
{
1910-
String msg;
1911-
int b = unmaskedFirstByte & 0xFF;
1912-
// let's speculate on problem a bit, too
1913-
if (b == '{' || b == '[') {
1914-
msg = "Input does not start with Smile format header (first byte = 0x"
1915-
+Integer.toHexString(b & 0xFF)+") -- rather, it starts with '"+((char) b)
1916-
+"' (plain JSON input?) -- can not parse";
1917-
} else {
1918-
msg = "Input does not start with Smile format header (first byte = 0x"
1919-
+Integer.toHexString(b & 0xFF)+") and parser has REQUIRE_HEADER enabled: can not parse";
1920-
}
1921-
throw new JsonParseException(this, msg);
1922-
}
19231839
}

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParserBase.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.fasterxml.jackson.core.*;
77
import com.fasterxml.jackson.core.io.IOContext;
8+
import com.fasterxml.jackson.core.json.JsonReadContext;
89
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
910
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
1011
import com.fasterxml.jackson.dataformat.smile.*;
@@ -380,6 +381,68 @@ public int readBinaryValue(Base64Variant b64variant, OutputStream out)
380381
return _binaryValue.length;
381382
}
382383

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+
383446
/*
384447
/**********************************************************************
385448
/* Internal methods, field name parsing
@@ -606,6 +669,22 @@ public void _initByteArrayBuilder()
606669
/**********************************************************************
607670
*/
608671

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+
609688
protected void _reportInvalidSharedName(int index) throws IOException
610689
{
611690
if (_seenNames == null) {

0 commit comments

Comments
 (0)