Package com.aim2be.platform.schema
Class WireFormatCodec
java.lang.Object
com.aim2be.platform.schema.WireFormatCodec
Pure utility for encoding / decoding the on-wire schema-ID prefix.
Two layouts (see WireFormat):
- Apicurio 8-byte big-endian globalId prefix
- Confluent 0x00 magic + 4-byte big-endian schemaId prefix
Zero Spring dependencies — testable as a unit. All four methods validate
lengths and magic bytes; malformed input throws WireFormatException
(unchecked — see WireFormatException for rationale).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of parsing a wire-prefixed byte array. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intApicurio prefix length: 8 bytes (long, big-endian).static final byteConfluent magic byte sentinel: 0x00.static final intConfluent prefix length: 1 magic byte + 4-byte int (big-endian) = 5 bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic WireFormatCodec.ParsedRecordparseApicurioPrefix(byte[] wireBytes) Parses an Apicurio-prefixed wire byte array.static WireFormatCodec.ParsedRecordparseConfluentPrefix(byte[] wireBytes) Parses a Confluent-prefixed wire byte array.static byte[]prependApicurioPrefix(long globalId, byte[] payload) Prepends the Apicurio 8-byte big-endian globalId topayload.static byte[]prependConfluentPrefix(int schemaId, byte[] payload) Prepends the Confluent0x00 + 4-byte schemaIdprefix topayload.
-
Field Details
-
CONFLUENT_MAGIC_BYTE
public static final byte CONFLUENT_MAGIC_BYTEConfluent magic byte sentinel: 0x00.- See Also:
-
APICURIO_PREFIX_LENGTH
public static final int APICURIO_PREFIX_LENGTHApicurio prefix length: 8 bytes (long, big-endian).- See Also:
-
CONFLUENT_PREFIX_LENGTH
public static final int CONFLUENT_PREFIX_LENGTHConfluent prefix length: 1 magic byte + 4-byte int (big-endian) = 5 bytes.- See Also:
-
-
Method Details
-
prependApicurioPrefix
public static byte[] prependApicurioPrefix(long globalId, byte[] payload) Prepends the Apicurio 8-byte big-endian globalId topayload.- Parameters:
globalId- the Apicurio-assigned global ID; any 64-bit valuepayload- the schema-encoded body; not null- Returns:
- a new byte array of length
8 + payload.length
-
prependConfluentPrefix
public static byte[] prependConfluentPrefix(int schemaId, byte[] payload) Prepends the Confluent0x00 + 4-byte schemaIdprefix topayload.- Parameters:
schemaId- the Confluent-style schema ID; any 32-bit valuepayload- the schema-encoded body; not null- Returns:
- a new byte array of length
5 + payload.length
-
parseApicurioPrefix
Parses an Apicurio-prefixed wire byte array.- Parameters:
wireBytes- the bytes received off the wire; not null- Returns:
- the parsed
(globalId, payload)pair - Throws:
WireFormatException- ifwireBytesis shorter than 8 bytes
-
parseConfluentPrefix
Parses a Confluent-prefixed wire byte array.- Parameters:
wireBytes- the bytes received off the wire; not null- Returns:
- the parsed
(schemaId, payload)pair — the id is widened to a long but always fits in 32 bits - Throws:
WireFormatException- ifwireBytesis shorter than 5 bytes or the leading magic byte is not 0x00
-