Interface MetadataWriter


public interface MetadataWriter
Writes stage metadata values to a buffer during encoding. Supports method chaining.

This is a dedicated interface rather than Lucene's DataOutput or Elasticsearch's StreamOutput because the block layout places stage metadata after the payload on disk ([bitmap][payload][stage metadata]), while transform stages produce metadata before the payload during encoding. The encode pipeline buffers metadata in memory and flushes it after the payload is written (see EncodingContext.writeStageMetadata(org.apache.lucene.store.DataOutput)).

This design favors the decode path: the decoder reads bitmap, payload, then metadata in a single forward pass with no buffering or seeking. Since decoding is far more frequent than encoding, the buffering cost is pushed to the encode side (once per block).

By decoupling stages from the buffering strategy, each stage writes metadata through this minimal interface without knowledge of the block layout or metadata ordering. This also simplifies backwards compatibility: the block layout or metadata ordering can change without modifying any stage implementation.

See Also:
  • Method Details

    • writeByte

      MetadataWriter writeByte(byte value)
      Writes a single byte.
      Parameters:
      value - the byte to write
      Returns:
      this writer for chaining
    • writeZInt

      MetadataWriter writeZInt(int value)
      Writes a zigzag-encoded variable-length integer.
      Parameters:
      value - the integer to write
      Returns:
      this writer for chaining
    • writeZLong

      MetadataWriter writeZLong(long value)
      Writes a zigzag-encoded variable-length long.
      Parameters:
      value - the long to write
      Returns:
      this writer for chaining
    • writeLong

      MetadataWriter writeLong(long value)
      Writes a fixed 8-byte long in Lucene format.
      Parameters:
      value - the long to write
      Returns:
      this writer for chaining
    • writeInt

      MetadataWriter writeInt(int value)
      Writes a fixed 4-byte integer in Lucene format.
      Parameters:
      value - the integer to write
      Returns:
      this writer for chaining
    • writeVInt

      MetadataWriter writeVInt(int value)
      Writes a variable-length integer.
      Parameters:
      value - the integer to write
      Returns:
      this writer for chaining
    • writeVLong

      MetadataWriter writeVLong(long value)
      Writes a variable-length long.
      Parameters:
      value - the long to write
      Returns:
      this writer for chaining
    • writeBytes

      MetadataWriter writeBytes(byte[] bytes, int offset, int length)
      Writes bytes from the given array.
      Parameters:
      bytes - the source array
      offset - the offset in the array
      length - the number of bytes to write
      Returns:
      this writer for chaining
    • writeBytes

      default MetadataWriter writeBytes(byte[] bytes)
      Writes all bytes from the given array.
      Parameters:
      bytes - the source array
      Returns:
      this writer for chaining
    • empty

      default void empty()
      Marks the stage as applied without writing any metadata. Use this for stages that always transform values but don't need to store any parameters for decoding.