# `IEC60870.CS101.Queue`
[🔗](https://github.com/Ultraluv/ex_iec60870/blob/main/lib/iec60870/cs101/queue.ex#L1)

FIFO Queue for CS101 ASDUs (`cs101_queue.c`).
Used for Class 1 / Class 2 queues in `CS101.Slave` and user data queue in `CS101.Master`.

# `pos_neg_integer`

```elixir
@type pos_neg_integer() :: integer()
```

# `t`

```elixir
@type t() :: %IEC60870.CS101.Queue{
  count: non_neg_integer(),
  max_size: pos_neg_integer() | pos_integer(),
  q: :queue.queue(IEC60870.ASDU.t())
}
```

# `dequeue`

```elixir
@spec dequeue(t()) :: {:ok, IEC60870.ASDU.t(), t()} | :empty
```

Dequeues the oldest ASDU. Returns `{:ok, asdu, updated_queue}` or `:empty`.

# `empty?`

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

# `enqueue`

```elixir
@spec enqueue(t(), IEC60870.ASDU.t()) :: {:ok, t()}
```

Enqueues an ASDU into the ring buffer queue.
Matching `CS101_Queue_enqueue` in `cs101_queue.c`, when the queue is full (`count >= max_size`),
the oldest entry in the queue is removed/overwritten to make room for the newest entry.

# `flush`

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

Flushes all entries from the queue.

# `full?`

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

# `has_waiting_asdu?`

```elixir
@spec has_waiting_asdu?(t()) :: {boolean(), term()}
```

Checks whether the queue has a waiting ASDU and returns `{boolean(), first_asdu_type_id}`,
matching `CS101_Queue_hasWaitingAsdu` in `cs101_queue.c`.

# `new`

```elixir
@spec new(integer()) :: t()
```

# `size`

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

---

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