# `Sycophant.Serializable.Decoder`

Decodes plain maps back into Sycophant structs using `"__type__"` discriminators.

Provides `encode/1` and `decode/1` convenience functions for full JSON
round-tripping, as well as `from_map/2` for working with already-parsed maps.

## Examples

    # Full JSON round-trip
    json = Sycophant.Serializable.Decoder.encode(response)
    restored = Sycophant.Serializable.Decoder.decode(json)

    # From a pre-parsed map
    map = %{"__type__" => "Usage", "input_tokens" => 10, "output_tokens" => 25}
    usage = Sycophant.Serializable.Decoder.from_map(map)

## Tool Registry

When decoding `Tool` structs, pass a `:tool_registry` option to restore
function references (which cannot be serialized):

    registry = %{"get_weather" => &MyApp.get_weather/1}
    Sycophant.Serializable.Decoder.decode(json, tool_registry: registry)

# `decode`

```elixir
@spec decode(
  String.t(),
  keyword()
) :: struct()
```

Decodes a JSON string back into the appropriate Sycophant struct.

# `encode`

```elixir
@spec encode(struct()) :: String.t()
```

Serializes a struct to a JSON string via `Sycophant.Serializable`.

# `from_map`

```elixir
@spec from_map(
  map(),
  keyword()
) :: struct()
```

Reconstructs a Sycophant struct from a plain map using its `__type__` discriminator.

---

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