Class WireFormatCodec

java.lang.Object
com.aim2be.platform.schema.WireFormatCodec

public final class WireFormatCodec extends Object
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).

  • Field Details

    • CONFLUENT_MAGIC_BYTE

      public static final byte CONFLUENT_MAGIC_BYTE
      Confluent magic byte sentinel: 0x00.
      See Also:
    • APICURIO_PREFIX_LENGTH

      public static final int APICURIO_PREFIX_LENGTH
      Apicurio prefix length: 8 bytes (long, big-endian).
      See Also:
    • CONFLUENT_PREFIX_LENGTH

      public static final int CONFLUENT_PREFIX_LENGTH
      Confluent 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 to payload.
      Parameters:
      globalId - the Apicurio-assigned global ID; any 64-bit value
      payload - 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 Confluent 0x00 + 4-byte schemaId prefix to payload.
      Parameters:
      schemaId - the Confluent-style schema ID; any 32-bit value
      payload - the schema-encoded body; not null
      Returns:
      a new byte array of length 5 + payload.length
    • parseApicurioPrefix

      public static WireFormatCodec.ParsedRecord parseApicurioPrefix(byte[] wireBytes)
      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 - if wireBytes is shorter than 8 bytes
    • parseConfluentPrefix

      public static WireFormatCodec.ParsedRecord parseConfluentPrefix(byte[] wireBytes)
      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 - if wireBytes is shorter than 5 bytes or the leading magic byte is not 0x00