Class ConfluentWireFormat
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
MagicByte
The magic byte indicating Confluent wire format.
public const byte MagicByte = 0
Field Value
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
sourceReadOnlySpan<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
sourceReadOnlySpan<byte>The source bytes to check.
Returns
ReadSchemaId(ReadOnlySpan<byte>)
Reads the schema ID from a wire format message.
public static int ReadSchemaId(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<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
sourceReadOnlySpan<byte>The source span containing the wire format message.
payloadReadOnlySpan<byte>When successful, contains the payload bytes.
Returns
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
sourceReadOnlySpan<byte>The source span containing the wire format message.
schemaIdintWhen successful, contains the schema ID.
Returns
WriteHeader(Span<byte>, int)
Writes the wire format header to the destination span.
public static void WriteHeader(Span<byte> destination, int schemaId)
Parameters
destinationSpan<byte>The destination span (must be at least HeaderSize bytes).
schemaIdintThe schema ID to write.
Exceptions
- ArgumentException
Thrown when
destinationis smaller than HeaderSize bytes.