Package org.mockserver.async.serde
Class ConfluentWireFormat
java.lang.Object
org.mockserver.async.serde.ConfluentWireFormat
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 ClassesModifier and TypeClassDescriptionstatic final classThe result of decoding a wire-format message: the embedded schema id and the remaining serialized payload bytes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSize in bytes of the wire-format header (magic byte + 4-byte schema id).static final byteThe Confluent magic byte that prefixes every schema-registry-framed message. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfluentWireFormat.Decodeddecode(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 booleanisWireFormat(byte[] data)
-
Field Details
-
MAGIC_BYTE
public static final byte MAGIC_BYTEThe Confluent magic byte that prefixes every schema-registry-framed message.- See Also:
-
HEADER_SIZE
public static final int HEADER_SIZESize 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
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
-