Class JsonRpcCodec

java.lang.Object
dev.tachyonmcp.core.transport.jsonrpc.JsonRpcCodec

public final class JsonRpcCodec extends Object
Low-level JSON-RPC 2.0 codec: parse and serialize messages to/from Netty ByteBuf.
  • Method Details

    • parseRequest

      public static JsonRpcMessage parseRequest(io.netty.buffer.ByteBuf buf)
      Parses a JSON-RPC message from a ByteBuf.
    • serializeResponse

      public static byte[] serializeResponse(@Nullable RequestId id, @Nullable String resultJson)
      Serializes a JSON-RPC response.
    • serializeError

      public static byte[] serializeError(@Nullable RequestId id, int code, String message, @Nullable String dataJson)
      Serializes a JSON-RPC error response.
    • serializeNotificationAsString

      public static String serializeNotificationAsString(String method, String paramsJson)
      Serializes a JSON-RPC notification to a string.
    • serializeRequestAsString

      public static String serializeRequestAsString(RequestId id, String method, String paramsJson)
      Serializes a JSON-RPC request to a string.
    • readRawJson

      public static String readRawJson(tools.jackson.core.JsonParser p)
      Reads the remainder of the current JSON value as a raw JSON string.
    • readTreeValue

      public static tools.jackson.databind.JsonNode readTreeValue(tools.jackson.core.JsonParser p) throws IOException
      Reads the current JSON value as a JsonNode.
      Throws:
      IOException
    • readValue

      public static @Nullable Object readValue(String json)
      Deserializes a JSON string to a generic Java object (Map, List, String, Number, Boolean, or null).
    • readGenericValue

      public static @Nullable Object readGenericValue(tools.jackson.core.JsonParser p) throws IOException
      Reads the current JSON token as a generic Java value.
      Throws:
      IOException
    • toJsonParams

      public static String toJsonParams(@Nullable Object params)
      Serializes JSON-RPC params to a JSON string: strings pass through as already-serialized JSON, null becomes an empty object, everything else goes through writeValueAsString(java.lang.Object).
    • writeValueAsString

      public static @Nullable String writeValueAsString(@Nullable Object value)
      Serializes a Java object to a JSON string, using registered codecs when available.
    • writeJsonValue

      public static void writeJsonValue(tools.jackson.core.JsonGenerator gen, @Nullable Object value)
      Writes a Java object as a JSON value via the given generator.