# `ToonEx.Btoon.TypedArray`
[🔗](https://github.com/ohhi-vn/toon_ex/blob/v1.6.0/lib/toon_ex/btoon/types.ex#L114)

A homogeneous numeric array stored as a contiguous binary buffer.

Encoding emits tag `0x0C` (TypedArray): element type, element count,
alignment padding and the raw little-endian buffer. Decoding with
`typed_arrays: :views` returns this struct so callers can read the raw
bytes without per-element copies.

## Examples

    iex> ta = Btoon.TypedArray.new(:float64, <<1.5::64-little-float, 2.5::64-little-float>>)
    iex> Btoon.TypedArray.type(ta)
    :float64
    iex> Btoon.TypedArray.to_list(ta)
    [1.5, 2.5]

# `t`

```elixir
@type t() :: %ToonEx.Btoon.TypedArray{
  data: binary(),
  type: ToonEx.Btoon.Types.element_type()
}
```

# `data`

```elixir
@spec data(t()) :: binary()
```

Returns the raw buffer.

# `from_list`

```elixir
@spec from_list([number()]) :: t()
```

Builds a typed array from a list of numbers, picking the narrowest type
that represents every value losslessly (`:int8`..`:int64` for integers,
`:float32`/`:float64` for floats).

# `length`

```elixir
@spec length(t()) :: non_neg_integer()
```

Number of elements in the typed array.

# `new`

```elixir
@spec new(ToonEx.Btoon.Types.element_type(), binary()) :: t()
```

Builds a typed array from a raw buffer.

The buffer length must be a multiple of the element size of `type`.

# `to_list`

```elixir
@spec to_list(t()) :: [number()]
```

Converts the raw buffer into a list of numbers.

# `type`

```elixir
@spec type(t()) :: ToonEx.Btoon.Types.element_type()
```

Returns the element type atom.

---

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