# `DdDataStreams.Carrier`
[🔗](https://github.com/rockneurotiko/dd_data_streams/blob/main/lib/dd_data_streams/carrier.ex#L1)

Broker-specific carriers for the pathway header.

A carrier is the part of an inbound or outbound message that holds the
pathway header: a flat attribute map or header list for Pub/Sub, Kafka and
RabbitMQ, or the `_datadog` JSON message attribute for SQS. `Flat` and
`Sqs` implement the behaviour; `adapter/1` selects one from the carrier's
shape, so `DdDataStreams.Checkpoints` stays free of broker conditionals.

# `fetch`

```elixir
@callback fetch(carrier :: term(), key :: String.t()) ::
  {:ok, DdDataStreams.Pathway.t()} | :absent | {:error, :malformed}
```

# `get`

```elixir
@callback get(carrier :: term(), key :: String.t()) :: DdDataStreams.Pathway.t() | nil
```

# `put`

```elixir
@callback put(carrier :: term(), pathway :: DdDataStreams.Pathway.t(), key :: String.t()) ::
  term()
```

# `size`

```elixir
@callback size(carrier :: term()) :: non_neg_integer()
```

# `adapter`

```elixir
@spec adapter(term()) :: module()
```

Selects the adapter that understands `carrier`'s shape.

# `fetch`

```elixir
@spec fetch(term(), String.t()) ::
  {:ok, DdDataStreams.Pathway.t()} | :absent | {:error, :malformed}
```

Reads the pathway out of `carrier` under `key`, like `get/2`, but tells a
header that is absent from one that is present and cannot be read.

# `get`

```elixir
@spec get(term(), String.t()) :: DdDataStreams.Pathway.t() | nil
```

Reads the pathway out of `carrier` under `key`, using the adapter selected by
its shape.

# `put`

```elixir
@spec put(term(), DdDataStreams.Pathway.t()) :: term()
```

# `put`

```elixir
@spec put(term(), DdDataStreams.Pathway.t(), String.t()) :: term()
```

Writes `pathway` into `carrier` under `key`, using the adapter selected by
its shape.

# `size`

```elixir
@spec size(term()) :: non_neg_integer()
```

Measures the size in bytes of the carrier entries.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
