//
//  message_accumulator.h
//  Tightbeam

#ifndef TIGHTBEAM_MESSAGE_ACCUMULATOR_H
#define TIGHTBEAM_MESSAGE_ACCUMULATOR_H

#include <sys/cdefs.h>
__ptrcheck_abi_assume_single()

#include <Tightbeam/tightbeam.h>
#include <Tightbeam/tb_list.h>

TB_ASSUME_NONNULL_BEGIN
__TB_BEGIN_DECLS

/// Copy the received memory to an accumulator. This will append the new bytes 
/// to the end of the accumulator for the message identifier contained in the
/// buffer. When the current message accumulator is full this will return a new
/// `tb_transport_message_buffer_t` and automatically free the associated
/// accumulator.
///
/// @param accumulator_list
/// A list of the current accumulators that should be used when accumulating
/// the provided message.
///
/// @param message
/// The message to accumulate.
///
/// @return If the accumulator is full this will return a new transport buffer,
/// otherwise NULL.
TB_EXPORT
_Nullable tb_transport_message_buffer_t
tb_message_accumulator_accumulate(tb_list_t accumulator_list,
        tb_message_t message);

__TB_END_DECLS
TB_ASSUME_NONNULL_END

#endif /* TIGHTBEAM_MESSAGE_ACCUMULATOR_H */
