Package io.jooby.trpc

Interface TrpcReader

All Superinterfaces:
AutoCloseable

public interface TrpcReader extends AutoCloseable
A stateful, sequential reader used at runtime to extract arguments from a tRPC network payload.

When a tRPC client sends a request for a multi-argument method, it packs the arguments into a JSON array (a tuple). This reader acts as a cursor over that array. The Jooby Annotation Processor (APT) generates routing code that calls the next*() methods on this interface sequentially, perfectly matching the order of parameters in the target Java method.

Zero-Boxing Performance:

To maximize throughput, this interface provides dedicated methods for extracting primitive types (e.g., nextInt(String), nextBoolean(String)). This allows the underlying JSON parser (like Jackson or AvajeJsonb) to read numbers and booleans directly off the byte stream without ever boxing them into heap-allocated objects like Integer or Boolean.

Because it holds resources (like an open JsonParser), it implements AutoCloseable and must be closed after the final argument is read.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Reads the next token in the stream as a primitive boolean.
    double
    Reads the next token in the stream as a primitive 64-bit floating-point number.
    int
    Reads the next token in the stream as a primitive 32-bit integer.
    boolean
    Peeks at the next token in the JSON stream to determine if it is a literal null.
    long
    Reads the next token in the stream as a primitive 64-bit integer.
    <T> T
    nextObject(String name, TrpcDecoder<T> decoder)
    Reads the next token (which may be a complex JSON object or array) and deserializes it using a pre-resolved type decoder.
    Reads the next token in the stream as a String.

    Methods inherited from interface java.lang.AutoCloseable

    close
  • Method Details

    • nextIsNull

      boolean nextIsNull(String name)
      Peeks at the next token in the JSON stream to determine if it is a literal null.
      Parameters:
      name - The logical name of the parameter being evaluated (used for context or error reporting).
      Returns:
      true if the next token is null; false otherwise.
    • nextInt

      int nextInt(String name)
      Reads the next token in the stream as a primitive 32-bit integer.
      Parameters:
      name - The logical name of the parameter.
      Returns:
      The extracted integer value.
    • nextLong

      long nextLong(String name)
      Reads the next token in the stream as a primitive 64-bit integer.
      Parameters:
      name - The logical name of the parameter.
      Returns:
      The extracted long value.
    • nextBoolean

      boolean nextBoolean(String name)
      Reads the next token in the stream as a primitive boolean.
      Parameters:
      name - The logical name of the parameter.
      Returns:
      The extracted boolean value.
    • nextDouble

      double nextDouble(String name)
      Reads the next token in the stream as a primitive 64-bit floating-point number.
      Parameters:
      name - The logical name of the parameter.
      Returns:
      The extracted double value.
    • nextString

      String nextString(String name)
      Reads the next token in the stream as a String.
      Parameters:
      name - The logical name of the parameter.
      Returns:
      The extracted String value, or null if the token is a JSON null.
    • nextObject

      <T> T nextObject(String name, TrpcDecoder<T> decoder)
      Reads the next token (which may be a complex JSON object or array) and deserializes it using a pre-resolved type decoder.

      This method delegates the heavy lifting of mapping arbitrary JSON structures to the underlying JSON engine (Jackson, Gson, etc.) via the provided TrpcDecoder.

      Type Parameters:
      T - The target Java type.
      Parameters:
      name - The logical name of the parameter.
      decoder - The optimized decoder created during application startup to handle this specific type.
      Returns:
      The fully deserialized Java object, or null if the token is a JSON null.