Table of Contents

Class ConfluentWireFormat

Namespace
Excalibur.Dispatch.Transport.Kafka
Assembly
Excalibur.Dispatch.Transport.Kafka.dll

Provides utilities for working with the Confluent Schema Registry wire format.

public static class ConfluentWireFormat
Inheritance
ConfluentWireFormat
Inherited Members

Remarks

The Confluent wire format prepends a 5-byte header to serialized messages:

+--------+--------+--------+--------+--------+--------+...
| Magic  |       Schema ID (4 bytes)        | Payload
| 0x00   |  Big-endian 32-bit integer       | N bytes
+--------+--------+--------+--------+--------+--------+...

This format is used by all Confluent Schema Registry-aware serializers.

Fields

HeaderSize

The size of the wire format header in bytes (1 magic + 4 schema ID).

public const int HeaderSize = 5

Field Value

int

MagicByte

The magic byte indicating Confluent wire format.

public const byte MagicByte = 0

Field Value

byte

Methods

GetPayload(ReadOnlySpan<byte>)

Gets the payload portion of a wire format message (after the header).

public static ReadOnlySpan<byte> GetPayload(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The source span containing the wire format message.

Returns

ReadOnlySpan<byte>

A span containing only the payload bytes.

Exceptions

InvalidOperationException

Thrown when the source is too short or has an invalid magic byte.

IsWireFormat(ReadOnlySpan<byte>)

Checks if the source bytes appear to be in Confluent wire format.

public static bool IsWireFormat(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The source bytes to check.

Returns

bool

true if the source has the correct header; otherwise, false.

ReadSchemaId(ReadOnlySpan<byte>)

Reads the schema ID from a wire format message.

public static int ReadSchemaId(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The source span containing the wire format message.

Returns

int

The schema ID extracted from the header.

Exceptions

InvalidOperationException

Thrown when the source is too short or has an invalid magic byte.

TryGetPayload(ReadOnlySpan<byte>, out ReadOnlySpan<byte>)

Attempts to get the payload portion of a wire format message.

public static bool TryGetPayload(ReadOnlySpan<byte> source, out ReadOnlySpan<byte> payload)

Parameters

source ReadOnlySpan<byte>

The source span containing the wire format message.

payload ReadOnlySpan<byte>

When successful, contains the payload bytes.

Returns

bool

true if the payload was extracted successfully; otherwise, false.

TryReadSchemaId(ReadOnlySpan<byte>, out int)

Attempts to read the schema ID from a wire format message.

public static bool TryReadSchemaId(ReadOnlySpan<byte> source, out int schemaId)

Parameters

source ReadOnlySpan<byte>

The source span containing the wire format message.

schemaId int

When successful, contains the schema ID.

Returns

bool

true if the schema ID was read successfully; otherwise, false.

WriteHeader(Span<byte>, int)

Writes the wire format header to the destination span.

public static void WriteHeader(Span<byte> destination, int schemaId)

Parameters

destination Span<byte>

The destination span (must be at least HeaderSize bytes).

schemaId int

The schema ID to write.

Exceptions

ArgumentException

Thrown when destination is smaller than HeaderSize bytes.