View Source KafkaEx.Auth.SASL.Codec behaviour (kafka_ex v0.15.0)

Behaviour defining the codec interface for SASL protocol messages.

Implementations must handle:

  • Building request frames (API versions, handshake, authenticate)
  • Parsing response frames with correlation ID validation
  • Selecting optimal protocol versions based on broker capabilities

This abstraction allows for different encoding strategies while maintaining a consistent interface for the SASL authentication flow.

Summary

Types

@type api_versions_map() :: %{required(integer()) => {integer(), integer()}}
@type error() :: {:error, term()}

Callbacks

Link to this callback

api_versions_request(corr, version, client_id)

View Source
@callback api_versions_request(
  corr :: integer(),
  version :: integer(),
  client_id :: binary()
) :: binary()
Link to this callback

authenticate_request(auth_bytes, corr, version, client_id)

View Source
@callback authenticate_request(
  auth_bytes :: binary() | nil,
  corr :: integer(),
  version :: integer(),
  client_id :: binary()
) :: binary()
Link to this callback

handshake_request(mechanism, corr, version, client_id)

View Source
@callback handshake_request(
  mechanism :: binary(),
  corr :: integer(),
  version :: integer(),
  client_id :: binary()
) :: binary()
Link to this callback

parse_api_versions_response(data, expected_corr)

View Source
@callback parse_api_versions_response(data :: binary(), expected_corr :: integer()) ::
  api_versions_map() | error()
Link to this callback

parse_authenticate_response(data, expected_corr, version)

View Source
@callback parse_authenticate_response(
  data :: binary(),
  expected_corr :: integer(),
  version :: integer()
) ::
  {:ok, binary() | nil} | error()
Link to this callback

parse_handshake_response(data, expected_corr, mechanism, version)

View Source
@callback parse_handshake_response(
  data :: binary(),
  expected_corr :: integer(),
  mechanism :: binary(),
  version :: integer()
) :: :ok | error()
Link to this callback

pick_authenticate_version(api_versions)

View Source
@callback pick_authenticate_version(api_versions :: api_versions_map() | error()) ::
  non_neg_integer()
Link to this callback

pick_handshake_version(api_versions)

View Source
@callback pick_handshake_version(api_versions :: api_versions_map() | error()) ::
  non_neg_integer()