Class JsonCounter


@Internal public final class JsonCounter extends Object
This class takes in JSON data and does simple parsing to detect boundaries between json nodes. For example, this class can recognize the separation between the two JSON objects in {"foo":"bar"} {"bar":"baz"}.
Public for fuzzing.
  • Constructor Details

    • JsonCounter

      public JsonCounter()
  • Method Details

    • feed

      public void feed(io.netty.buffer.ByteBuf buf) throws JsonSyntaxException
      Parse some input data. If buf is readable, this method always advances (always consumes at least one byte).
      buf - The input buffer
      JsonSyntaxException - If there is a syntax error in the JSON. Note that not all syntax errors are detected by this class.
    • unwrapTopLevelArray

      public void unwrapTopLevelArray()
      Enable top-level array unwrapping: If the input starts with an array, that array's elements are returned as individual JSON nodes, not the array all at once.
      Must be called before any data is processed, but can be called after noTokenization().
    • noTokenization

      public void noTokenization()
      Do not perform any tokenization, assume that there is only one root-level value. There is still some basic validation (ensuring the input isn't utf-16 or utf-32).
    • pollFlushedRegion

      @Nullable public JsonCounter.BufferRegion pollFlushedRegion()
      Check for any new flushed data from the last feed(ByteBuf) operation.
      The region that contains a JSON node, relative to position(), or null if the JSON node has not completed yet.
    • position

      public long position()
      The current position counter of the parser. Increases by exactly one for each byte consumed by feed(io.netty.buffer.ByteBuf).
      The current position
    • isBuffering

      public boolean isBuffering()
      Whether we are currently in the buffering state, i.e. there is a JSON node, but it's not done yet or we can't know for sure that it's done (e.g. for numbers). This is used to flush any remaining buffering data when EOF is reached.
      true if we are currently buffering
    • bufferStart

      public long bufferStart()
      If we are buffering, the start position() of the region that is being buffered.
      The buffer region start
      IllegalStateException - if we aren't buffering