Class MessagePackIO.Writer

java.lang.Object
io.fluxzero.common.serialization.MessagePackIO.Writer
All Implemented Interfaces:
AutoCloseable
Enclosing class:
MessagePackIO

public static final class MessagePackIO.Writer extends Object implements AutoCloseable
A reusable heap-array writer. Returned byte arrays are independent snapshots.
  • Constructor Details

    • Writer

      public Writer()
  • Method Details

    • packLong

      public MessagePackIO.Writer packLong(long value)
      Writes the smallest signed or unsigned integer representation of a Java long.
    • packInt

      public MessagePackIO.Writer packInt(int value)
      Writes a Java integer in its smallest MessagePack representation.
    • packByte

      public MessagePackIO.Writer packByte(byte value)
      Writes a Java byte in its smallest MessagePack representation.
    • packNil

      public MessagePackIO.Writer packNil()
      Writes nil.
    • packBoolean

      public MessagePackIO.Writer packBoolean(boolean value)
      Writes a boolean.
    • packString

      public MessagePackIO.Writer packString(String value)
      Writes UTF-8, replacing malformed UTF-16 with '?' like the previous writer.
    • packArrayHeader

      public MessagePackIO.Writer packArrayHeader(int size)
      Writes an array header; callers write its elements separately.
    • packBinaryHeader

      public MessagePackIO.Writer packBinaryHeader(int size)
      Writes a binary header; callers write its payload separately.
    • writePayload

      public MessagePackIO.Writer writePayload(byte[] bytes)
      Copies unframed payload bytes into this writer.
    • addPayload

      public MessagePackIO.Writer addPayload(byte[] bytes)
      Appends unframed bytes, retaining large arrays until clear/close. Callers must not mutate the array before taking the output snapshot. This preserves the historical large-payload copy boundary.
    • toByteArray

      public byte[] toByteArray()
      Returns an independent copy of all bytes written since the last clear.
    • getBufferSize

      public int getBufferSize()
      Returns written bytes, for bounding writer pools after serialization.
    • clear

      public void clear()
      Resets the writer and releases completed chunks, retaining only its current small buffer.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable