@Override public int readIndex() throws IOException { parser.advance(Symbol.UNION); Symbol.UnionAdjustAction top = (Symbol.UnionAdjustAction) parser.popSymbol(); parser.pushSymbol(top.symToParse); return top.rindex; }
protected ParsingDecoder(Symbol root) throws IOException { this.parser = new SkipParser(root, this, this); }
private void advance(Symbol symbol) throws IOException { this.parser.processTrailingImplicitActions(); if (in.getCurrentToken() == null && this.parser.depth() == 1) throw new EOFException(); parser.advance(symbol); }
/** * Skips the repeater at the top the stack. */ public final void skipRepeater() throws IOException { int target = pos; Symbol repeater = stack[--pos]; assert repeater.kind == Symbol.Kind.REPEATER; pushProduction(repeater); skipTo(target); }
/** * Pushes the given symbol on to the skip and skips it. * @param symToSkip The symbol that should be skipped. */ public final void skipSymbol(Symbol symToSkip) throws IOException { int target = pos; pushSymbol(symToSkip); skipTo(target); } }
@Override public long skipArray() throws IOException { parser.advance(Symbol.ARRAY_START); for (long c = in.skipArray(); c != 0; c = in.skipArray()) { while (c-- > 0) { parser.skipRepeater(); } } parser.advance(Symbol.ARRAY_END); return 0; }
@Override public long arrayNext() throws IOException { parser.processTrailingImplicitActions(); long result = in.arrayNext(); if (result == 0) { parser.advance(Symbol.ARRAY_END); } return result; }
private void checkFixed(int size) throws IOException { parser.advance(Symbol.FIXED); Symbol.IntCheckAction top = (Symbol.IntCheckAction) parser.popSymbol(); if (size != top.size) { throw new AvroTypeException( "Incorrect length for fixed binary: expected " + top.size + " but received " + size + " bytes."); } }
parser.skipSymbol(symToSkip); } else if (top instanceof Symbol.WriterUnionAction) { Symbol.Alternative branches = (Symbol.Alternative) parser.popSymbol(); parser.pushSymbol(branches.getSymbol(in.readIndex())); } else if (top instanceof Symbol.ErrorAction) { throw new AvroTypeException(((Symbol.ErrorAction) top).msg);
@Override public void skipAction() throws IOException { Symbol top = parser.popSymbol(); if (top instanceof Symbol.ResolvingAction) { parser.pushSymbol(((Symbol.ResolvingAction) top).writer); } else if (top instanceof Symbol.SkipAction) { parser.pushSymbol(((Symbol.SkipAction) top).symToSkip); } else if (top instanceof Symbol.WriterUnionAction) { Symbol.Alternative branches = (Symbol.Alternative) parser.popSymbol(); parser.pushSymbol(branches.getSymbol(in.readIndex())); } else if (top instanceof Symbol.ErrorAction) { throw new AvroTypeException(((Symbol.ErrorAction) top).msg); } else if (top instanceof Symbol.DefaultStartAction) { Symbol.DefaultStartAction dsa = (Symbol.DefaultStartAction) top; backup = in; in = DecoderFactory.get() .binaryDecoder(dsa.contents, null); } else if (top == Symbol.DEFAULT_END_ACTION) { in = backup; } } }
/** Re-initialize, reading from a new underlying Decoder. */ public ValidatingDecoder configure(Decoder in) throws IOException { this.parser.reset(); this.in = in; return this; }
@Override public void readNull() throws IOException { parser.advance(Symbol.NULL); in.readNull(); }
@Override public void skipAction() throws IOException { parser.popSymbol(); }
/** * Consume any more data that has been written by the writer but not * needed by the reader so that the the underlying decoder is in proper * shape for the next record. This situation happens when, for example, * the writer writes a record with two fields and the reader needs only the * first field. * * This function should be called after completely decoding an object but * before next object can be decoded from the same underlying decoder * either directly or through another resolving decoder. If the same resolving * decoder is used for the next object as well, calling this method is * optional; the state of this resolving decoder ensures that any leftover * portions are consumed before the next object is decoded. * @throws IOException */ public final void drain() throws IOException { parser.processImplicitActions(); }
/** * Skips data by calling <code>skipXyz</code> or * <code>readXyz</code> methods on <code>this</code>, until the * parser stack reaches the target level. */ public final void skipTo(int target) throws IOException { outer: while (target < pos) { Symbol top = stack[pos - 1]; while (top.kind != Symbol.Kind.TERMINAL) { if (top.kind == Symbol.Kind.IMPLICIT_ACTION || top.kind == Symbol.Kind.EXPLICIT_ACTION) { skipHandler.skipAction(); } else { --pos; pushProduction(top); } continue outer; } skipHandler.skipTopSymbol(); } }
@Override public long skipMap() throws IOException { parser.advance(Symbol.MAP_START); for (long c = in.skipMap(); c != 0; c = in.skipMap()) { while (c-- > 0) { parser.skipRepeater(); } } parser.advance(Symbol.MAP_END); return 0; }
@Override public long arrayNext() throws IOException { parser.processTrailingImplicitActions(); long result = in.arrayNext(); if (result == 0) { parser.advance(Symbol.ARRAY_END); } return result; }
/** * Skips the repeater at the top the stack. */ public final void skipRepeater() throws IOException { int target = pos; Symbol repeater = stack[--pos]; assert repeater.kind == Symbol.Kind.REPEATER; pushProduction(repeater); skipTo(target); }
parser.skipSymbol(symToSkip); } else if (top instanceof Symbol.WriterUnionAction) { Symbol.Alternative branches = (Symbol.Alternative) parser.popSymbol(); parser.pushSymbol(branches.getSymbol(in.readIndex())); } else if (top instanceof Symbol.ErrorAction) { throw new AvroTypeException(((Symbol.ErrorAction) top).msg);