Class ConfluentWireFormat

java.lang.Object
org.mockserver.async.serde.ConfluentWireFormat

public final class ConfluentWireFormat extends Object
Encoder/decoder for the Confluent Schema Registry wire format used by Kafka Avro/Protobuf messages.

The wire format frames a serialized payload with a 5-byte header:

   byte 0       : magic byte (always 0x00)
   bytes 1..4   : 4-byte big-endian schema id (as registered in the Schema Registry)
   bytes 5..n   : the serialized payload (Avro binary, Protobuf, …)
 

This class handles only the framing — it is codec-agnostic and broker-free, so it is trivially unit-testable. It lets MockServer interoperate with real Confluent Avro producers/consumers without pulling in the Confluent Community License serde stack (see docs/code/async-messaging.md).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    The result of decoding a wire-format message: the embedded schema id and the remaining serialized payload bytes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Size in bytes of the wire-format header (magic byte + 4-byte schema id).
    static final byte
    The Confluent magic byte that prefixes every schema-registry-framed message.
  • Method Summary

    Modifier and Type
    Method
    Description
    decode(byte[] data)
    Decode the wire-format header, returning the embedded schema id and the remaining serialized payload.
    static byte[]
    encode(int schemaId, byte[] payload)
    Frame a serialized payload with the Confluent wire-format header.
    static boolean
    isWireFormat(byte[] data)
     

    Methods inherited from class java.lang.Object

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

    • MAGIC_BYTE

      public static final byte MAGIC_BYTE
      The Confluent magic byte that prefixes every schema-registry-framed message.
      See Also:
    • HEADER_SIZE

      public static final int HEADER_SIZE
      Size in bytes of the wire-format header (magic byte + 4-byte schema id).
      See Also:
  • Method Details

    • encode

      public static byte[] encode(int schemaId, byte[] payload)
      Frame a serialized payload with the Confluent wire-format header.
      Parameters:
      schemaId - the schema id to embed (as registered in the Schema Registry)
      payload - the already-serialized payload (e.g. Avro binary)
      Returns:
      the framed bytes: [0x00][schemaId:4][payload]
    • isWireFormat

      public static boolean isWireFormat(byte[] data)
      Returns:
      true if the given bytes carry the Confluent wire-format header (at least 5 bytes, leading with the magic byte).
    • decode

      public static ConfluentWireFormat.Decoded decode(byte[] data)
      Decode the wire-format header, returning the embedded schema id and the remaining serialized payload.
      Parameters:
      data - the framed bytes
      Returns:
      the decoded schema id + payload
      Throws:
      IllegalArgumentException - if the bytes do not carry the wire-format header