@@ -55,6 +55,16 @@ public class AvroParserImpl extends AvroParser
55
55
*/
56
56
protected BinaryDecoder _decoder ;
57
57
58
+ /**
59
+ * Index of the union branch that was followed to reach the current token. This is cleared when the next token is read.
60
+ */
61
+ protected int _branchIndex ;
62
+
63
+ /**
64
+ * Index of the enum that was read as the current token. This is cleared when the next token is read.
65
+ */
66
+ protected int _enumIndex ;
67
+
58
68
/*
59
69
/**********************************************************
60
70
/* Life-cycle
@@ -101,6 +111,23 @@ protected void _releaseBuffers() throws IOException {
101
111
}
102
112
}
103
113
114
+ /**
115
+ * Skip to the end of the current structure (array/map/object); This is different from {@link #skipMap()} and {@link #skipArray()}
116
+ * because it operates at the parser level instead of at the decoder level and advances the parsing context in addition to consuming
117
+ * the data from the input.
118
+ *
119
+ * @throws IOException If there was an issue advancing through the underlying data stream
120
+ */
121
+ protected void skipValue () throws IOException {
122
+ if (_avroContext instanceof ArrayReader ) {
123
+ ((ArrayReader ) _avroContext ).skipValue (this );
124
+ } else if (_avroContext instanceof MapReader ) {
125
+ ((MapReader ) _avroContext ).skipValue (this );
126
+ } else if (_avroContext instanceof RecordReader ) {
127
+ ((RecordReader ) _avroContext ).skipValue (this );
128
+ }
129
+ }
130
+
104
131
@ Override
105
132
public JsonParser overrideFormatFeatures (int values , int mask ) {
106
133
int oldF = _formatFeatures ;
@@ -141,6 +168,8 @@ protected void _closeInput() throws IOException {
141
168
@ Override
142
169
public JsonToken nextToken () throws IOException
143
170
{
171
+ _branchIndex = -1 ;
172
+ _enumIndex = -1 ;
144
173
_binaryValue = null ;
145
174
if (_closed ) {
146
175
return null ;
@@ -331,11 +360,11 @@ public long skipMap() throws IOException {
331
360
// // // Misc other decoding
332
361
333
362
public int decodeIndex () throws IOException {
334
- return _decoder .readIndex ();
363
+ return ( _branchIndex = _decoder .readIndex () );
335
364
}
336
365
337
366
public int decodeEnum () throws IOException {
338
- return _decoder .readEnum ();
367
+ return ( _enumIndex = _decoder .readEnum () );
339
368
}
340
369
341
370
public boolean checkInputEnd () throws IOException {
@@ -347,6 +376,18 @@ public boolean checkInputEnd() throws IOException {
347
376
/* Methods for AvroReadContext impls, other
348
377
/**********************************************************
349
378
*/
379
+
380
+ protected int branchIndex () {
381
+ return _branchIndex ;
382
+ }
383
+
384
+ protected int enumIndex () {
385
+ return _enumIndex ;
386
+ }
387
+
388
+ protected boolean isRecord () {
389
+ return _avroContext instanceof RecordReader ;
390
+ }
350
391
351
392
protected void setAvroContext (AvroReadContext ctxt ) {
352
393
if (ctxt == null ) { // sanity check
0 commit comments