Record Class RecordHeader

java.lang.Object
java.lang.Record
io.krabka.streams.columnar.RecordHeader
Record Components:
key - the header key
value - the header value bytes, or null for a null-valued header

public record RecordHeader(String key, byte[] value) extends Record
One immutable Kafka record header.

Unlike Kafka's own header type, this record defensively copies its value bytes in both directions and implements value-based equals(Object) and hashCode(), which makes it safe to use in assertions and as map or set elements.

Example

var traceId = new RecordHeader("trace-id", "abc123".getBytes(UTF_8));
driver.pipeInput("input", 0, key, value, 0L, List.of(traceId));
  • Constructor Summary

    Constructors
    Constructor
    Description
    RecordHeader(String key, byte[] value)
    Copies the value so later mutation of the input array cannot change the header.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
    Compares headers by key and value content.
    int
    Hashes the key and value content consistently with equals(Object).
    key()
    Returns the value of the key record component.
    final String
    Returns a string representation of this record class.
    byte[]
    Returns a copy of the header value.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RecordHeader

      public RecordHeader(String key, byte[] value)
      Copies the value so later mutation of the input array cannot change the header.
      Parameters:
      key - the header key
      value - the header value bytes, or null for a null-valued header
      Throws:
      NullPointerException - if key is null
  • Method Details

    • value

      public byte[] value()
      Returns a copy of the header value.
      Returns:
      a fresh copy of the value bytes, or null for a null-valued header
    • equals

      public boolean equals(Object other)
      Compares headers by key and value content.
      Specified by:
      equals in class Record
      Parameters:
      other - the object to compare with
      Returns:
      true when other is a header with an equal key and equal value bytes
    • hashCode

      public int hashCode()
      Hashes the key and value content consistently with equals(Object).
      Specified by:
      hashCode in class Record
      Returns:
      the content-based hash code
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • key

      public String key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component