A behaviour for log buffer implementations, most notably for the BACnet.Stack.TrendLogger module.
The behaviour contains the functions from the BACnet.Stack.LogBuffer module,
the default log buffer implementation used by BACnet.Stack.TrendLogger.
Using a behaviour allows exchanging the implementation with a different one, for example backed by SQLite.
Summary
Types
The item that gets check in into the log buffer.
A module implementing the Log Buffer Behaviour.
The data structure representing the log buffer.
Callbacks
Checks in an item.
Checks out the oldest item in the log buffer.
Drops the specified amount of oldest items from the log buffer.
Creates a new log buffer from the given list, with an optional max size. The head of the list will be the oldest entry in the log buffer.
Get the size of the log buffer.
Creates a new log buffer with an optional max size.
Peeks into the log buffer and returns the oldest item without removing it.
Peeks into the log buffer and returns the newest item without removing it.
Reads the specified count, starting from the given position (offset), from the log buffer.
Creates a list from the log buffer.
Truncates the log buffer to size zero.
Types
Callbacks
Checks in an item.
If the log buffer has a max size, the max size will be maintained (meaning the oldest item gets dropped on overflow).
Checks out the oldest item in the log buffer.
If the log buffer is empty, nil will be returned as item.
@callback drop(buffer :: t(), amount :: pos_integer()) :: t()
Drops the specified amount of oldest items from the log buffer.
@callback from_list(source :: list(), max_size :: pos_integer() | nil) :: t()
Creates a new log buffer from the given list, with an optional max size. The head of the list will be the oldest entry in the log buffer.
If a max size is specified, the list will be truncated to the max size (from the end). The queue length will be calculated in any case. This operation is O(n).
@callback get_size(buffer :: t()) :: non_neg_integer()
Get the size of the log buffer.
@callback new(max_size :: pos_integer() | nil) :: t()
Creates a new log buffer with an optional max size.
Peeks into the log buffer and returns the oldest item without removing it.
Peeks into the log buffer and returns the newest item without removing it.
@callback read_range(buffer :: t(), offset :: non_neg_integer(), count :: pos_integer()) :: [item()]
Reads the specified count, starting from the given position (offset), from the log buffer.
Creates a list from the log buffer.
Truncates the log buffer to size zero.