ToonEx.Btoon.TypedArray (toon_ex v1.3.1)

Copy Markdown View Source

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]

Summary

Functions

Returns the raw buffer.

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).

Number of elements in the typed array.

Builds a typed array from a raw buffer.

Converts the raw buffer into a list of numbers.

Returns the element type atom.

Types

t()

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

Functions

data(typed_array)

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

Returns the raw buffer.

from_list(values)

@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(typed_array)

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

Number of elements in the typed array.

new(type, data)

Builds a typed array from a raw buffer.

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

to_list(typed_array)

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

Converts the raw buffer into a list of numbers.

type(typed_array)

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

Returns the element type atom.