Class SseSerializer

java.lang.Object
dev.tachyonmcp.core.transport.netty.sse.SseSerializer

public final class SseSerializer extends Object
Serializes an outbound SseEvent into its text/event-stream wire framing, writing straight into a pooled buffer from alloc. Keeps the framing (a transport concern) out of SseEvent so the mcp.server model stays free of Netty types, and avoids the intermediate String a format() helper would allocate on the hot write path.
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.netty.buffer.ByteBuf
    encode(io.netty.buffer.ByteBufAllocator alloc, SseEvent event)
    Encodes event as id: …\nevent: …\ndata: …\n\n, splitting multi-line data into one data: line per \n (matching the SSE spec).
    static io.netty.buffer.ByteBuf
    encode(io.netty.buffer.ByteBufAllocator alloc, @Nullable String wireId, byte @Nullable [] body)
    Encodes a raw body as a message event, omitting the id: field when wireId is null, with one data: field per body line.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • encode

      public static io.netty.buffer.ByteBuf encode(io.netty.buffer.ByteBufAllocator alloc, SseEvent event)
      Encodes event as id: …\nevent: …\ndata: …\n\n, splitting multi-line data into one data: line per \n (matching the SSE spec). The returned buffer is owned by the caller and must be released after the write completes.
    • encode

      public static io.netty.buffer.ByteBuf encode(io.netty.buffer.ByteBufAllocator alloc, @Nullable String wireId, byte @Nullable [] body)
      Encodes a raw body as a message event, omitting the id: field when wireId is null, with one data: field per body line. A null or empty body produces one empty data: field. Encoding writes straight into a single pooled buffer (no String decode). The returned buffer is owned by the caller and must be released after the write completes.