Search documentation of bb

# BB.Message.Option (bb v0.8.0)

View Source

Custom Spark.Options types for message primitives.

Provides type functions for use in payload schemas to validate tagged tuple primitives like `{:vec3, x, y, z}` and `{:quaternion, x, y, z, w}`.

## Usage

    import BB.Message.Option

    @schema Spark.Options.new!([
      position: [type: vec3_type(), required: true],
      orientation: [type: quaternion_type(), required: true]
    ])

# Summary

## Functions

quaternion_type()

Returns a Spark.Options type for validating `{:quaternion, x, y, z, w}` tuples.

validate_quaternion(value, opts)

Validates a quaternion tagged tuple.

validate_vec3(value, opts)

Validates a vec3 tagged tuple.

vec3_type()

Returns a Spark.Options type for validating `{:vec3, x, y, z}` tuples.

# Functions

# quaternion_type()

    @spec quaternion_type() :: {:custom, module(), atom(), list()}

Returns a Spark.Options type for validating `{:quaternion, x, y, z, w}` tuples.

## Examples

    iex> BB.Message.Option.quaternion_type()
    {:custom, BB.Message.Option, :validate_quaternion, [[]]}

# validate_quaternion(value, opts)

    @spec validate_quaternion(
      term(),
      keyword()
    ) :: {:ok, tuple()} | {:error, String.t()}

Validates a quaternion tagged tuple.

## Examples

    iex> BB.Message.Option.validate_quaternion({:quaternion, 0.0, 0.0, 0.0, 1.0}, [])
    {:ok, {:quaternion, 0.0, 0.0, 0.0, 1.0}}

    iex> BB.Message.Option.validate_quaternion({:quaternion, 0, 0, 0, 1}, [])
    {:error, "expected {:quaternion, x, y, z, w} with float values, got: {:quaternion, 0, 0, 0, 1}"}

# validate_vec3(value, opts)

    @spec validate_vec3(
      term(),
      keyword()
    ) :: {:ok, tuple()} | {:error, String.t()}

Validates a vec3 tagged tuple.

## Examples

    iex> BB.Message.Option.validate_vec3({:vec3, 1.0, 2.0, 3.0}, [])
    {:ok, {:vec3, 1.0, 2.0, 3.0}}

    iex> BB.Message.Option.validate_vec3({:vec3, 1, 2, 3}, [])
    {:error, "expected {:vec3, x, y, z} with float values, got: {:vec3, 1, 2, 3}"}

    iex> BB.Message.Option.validate_vec3("not a vec3", [])
    {:error, "expected {:vec3, x, y, z} with float values, got: \"not a vec3\""}

# vec3_type()

    @spec vec3_type() :: {:custom, module(), atom(), list()}

Returns a Spark.Options type for validating `{:vec3, x, y, z}` tuples.

## Examples

    iex> BB.Message.Option.vec3_type()
    {:custom, BB.Message.Option, :validate_vec3, [[]]}