# `ADS.Codepage`
[🔗](https://github.com/tallakt/yaads/blob/v0.1.0/lib/ads/codepage.ex#L26)

The code page of the strings of one byte to a character a TwinCAT system has: its PLC's
`STRING`s, the names and comments of its symbols and types, and the strings of its system
service and router, such as its host name, routes and adapters. Windows-1252 unless told
otherwise, with `codepage:` to `ADS.Client`, `ADS.Discovery` and the mix tasks, as Beckhoff's own
libraries read them on Western Windows; a system on Windows of another language has that one's.

[Codepagex](https://hex.pm/packages/codepagex) converts them. yaads has these compiled in:
`:ascii`, `:iso_8859_1`, and Windows' code pages of one byte to a character, `:windows_874` and
`:windows_1250` to `:windows_1258`. The application adds others in its config, by Codepagex's
aliases or names, and recompiles yaads (`mix deps.compile yaads --force`):

    # config/config.exs
    config :yaads, :codepages, [:windows_932, "VENDORS/MICSFT/WINDOWS/CP949"]

An encoding Codepagex itself has, as configured for the application, is taken too.

What comes out is UTF-8, always: a byte the code page has no character for is `"\uFFFD"`.

# `t`

```elixir
@type t() :: atom() | String.t()
```

An alias of Codepagex's, such as `:windows_1251`, or a full name.

# `available`

```elixir
@spec available() :: [String.t()]
```

The code pages compiled into yaads, by Codepagex's full names.

# `check!`

```elixir
@spec check!(t()) :: t()
```

The code page, if yaads or Codepagex has it; else an `ArgumentError` that says how to add it.

    iex> ADS.Codepage.check!(:windows_1251)
    :windows_1251

# `decode`

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

A string from the code page, in UTF-8.

    iex> ADS.Codepage.decode(<<"Gr", 0xFC, 0xDF, "e ", 0x80>>)
    "Grüße €"
    iex> ADS.Codepage.decode(<<0xC0, 0xE1, 0x98>>, :windows_1251)
    "Аб�"

# `default`

```elixir
@spec default() :: t()
```

Windows-1252.

# `encode!`

```elixir
@spec encode!(String.t(), t()) :: binary()
```

A string in the code page; `ArgumentError` for one with characters it doesn't have.

    iex> ADS.Codepage.encode!("Grüße €")
    <<"Gr", 0xFC, 0xDF, "e ", 0x80>>

---

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