# `Grizzly.ZWave.ParamSpec`
[🔗](https://github.com/smartrent/grizzly/blob/v9.1.4/lib/grizzly/zwave/param_spec.ex#L1)

Data structure describing a parameter for a Z-Wave command.

# `t`

```elixir
@type t() :: %Grizzly.ZWave.ParamSpec{
  default: any(),
  name: atom(),
  opts: keyword(),
  required: boolean(),
  size: non_neg_integer() | :variable,
  type: type()
}
```

# `type`

```elixir
@type type() ::
  :int
  | :uint
  | :boolean
  | :binary
  | :enum
  | :constant
  | :reserved
  | :bitmask
  | {:length, atom()}
  | :any
```

# `decode_value`

Decodes an Elixir term from a bitstring according to the parameter specification.

# `encode_value`

```elixir
@spec encode_value(t(), term(), keyword()) :: bitstring()
```

Encodes an Elixir term into a bitstring according to the parameter specification.

# `include_when_decoding?`

```elixir
@spec include_when_decoding?(t()) :: boolean()
```

Whether the parameter should be included in the resulting list of parameters
when decoding a command.

# `num_bits`

```elixir
@spec num_bits(t()) :: non_neg_integer() | :variable
```

Returns the size of the parameter in bits (or :variable) for variable-length params.

## Examples

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :uint, size: 16}
    iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
    16

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :binary, size: 32}
    iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
    32

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: :variable}
    iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
    :variable

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: {:variable, :another_param}}
    iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
    :variable

# `take_bits`

```elixir
@spec take_bits(t(), bitstring(), keyword()) ::
  {:ok,
   {bits_taken :: non_neg_integer(), value :: bitstring(), rest :: bitstring()}}
  | {:error, Grizzly.ZWave.DecodeError.t()}
```

Takes the number of bits specified by the param spec from the front of the bitstring.

Returns `{:ok, {value, rest}}` where `value` is the taken bits and `rest` is the
remaining bits. If there are not enough bits to take, an error is returned.

## Examples

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :uint, size: 8}
    iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, [])
    {:ok, {8, <<0x01>>, <<0x02, 0x03>>}}

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: 16}
    iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, [])
    {:ok, {16, <<0x01, 0x02>>, <<0x03>>}}

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: :variable}
    iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, [])
    {:ok, {24, <<0x01, 0x02, 0x03>>, <<>>}}

    iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: {:variable, :length_param}}
    iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, length_param: 2)
    {:ok, {16, <<0x01, 0x02>>, <<0x03>>}}

# `validate`

Validate a command spec.

# `validate!`

Validate a command spec, raising on error.

---

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