Class JsonCounter

java.lang.Object
io.micronaut.http.server.netty.jackson.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).
      Parameters:
      buf - The input buffer
      Throws:
      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.
      Returns:
      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).
      Returns:
      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.
      Returns:
      true if we are currently buffering
    • bufferStart

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