UniRec  3.2.0
Public Member Functions | Private Member Functions | Private Attributes | Friends
Nemea::UnirecRecordView Class Reference

Provides a view into a UniRec record. More...

#include <unirecRecordView.hpp>

Public Member Functions

 UnirecRecordView (const void *unirecRecordData, ur_template_t *unirecTemplate, uint64_t sequenceNumber=0)
 Constructs a UnirecRecordView object. More...
 
const void * data () const noexcept
 Returns a const pointer to the data of the UniRec record. More...
 
size_t size () const noexcept
 Returns the size of the UniRec record. More...
 
uint64_t getSequenceNumber () const noexcept
 Gets the sequence number of the record. More...
 
template<typename T >
add_const_t< T > getFieldAsType (ur_field_id_t fieldID) const
 Gets the value of a field as a type T. More...
 
template<typename T >
add_const_t< UnirecArray< T > > getFieldAsUnirecArray (ur_field_id_t fieldID) const
 Gets the value of a field as a UnirecArray. More...
 

Private Member Functions

template<typename T >
add_const_t< T > getFieldAsStringType (ur_field_id_t fieldID) const
 

Private Attributes

const void * m_recordData
 
ur_template_tm_unirecTemplate
 
uint64_t m_sequenceNumber
 

Friends

class UnirecRecord
 

Detailed Description

Provides a view into a UniRec record.

The UnirecRecordView class offers a lightweight way to access and inspect the contents of a UniRec record. It provides methods for retrieving field values as various types, including arrays, strings, and other fundamental types. The class does not own the record data and is intended for read-only operations.

Definition at line 40 of file unirecRecordView.hpp.

Constructor & Destructor Documentation

◆ UnirecRecordView()

Nemea::UnirecRecordView::UnirecRecordView ( const void *  unirecRecordData,
ur_template_t unirecTemplate,
uint64_t  sequenceNumber = 0 
)
inline

Constructs a UnirecRecordView object.

Parameters
unirecRecordDataPointer to the UniRec record data.
unirecTemplatePointer to the UniRec template for the record.
sequenceNumberThe sequence number of the record.

Definition at line 48 of file unirecRecordView.hpp.

Member Function Documentation

◆ data()

const void* Nemea::UnirecRecordView::data ( ) const
inlinenoexcept

Returns a const pointer to the data of the UniRec record.

Returns
A pointer to the data of the UniRec record.

Definition at line 60 of file unirecRecordView.hpp.

◆ getFieldAsStringType()

template<typename T >
add_const_t<T> Nemea::UnirecRecordView::getFieldAsStringType ( ur_field_id_t  fieldID) const
inlineprivate

Definition at line 169 of file unirecRecordView.hpp.

◆ getFieldAsType()

template<typename T >
add_const_t<T> Nemea::UnirecRecordView::getFieldAsType ( ur_field_id_t  fieldID) const
inline

Gets the value of a field as a type T.

This function retrieves the value of a field and converts it to the specified type T. It performs type checking to ensure that the field type matches the expected type.

Template Parameters
TThe type of the field to get.
Parameters
fieldIDThe ID of the field to get.
Returns
The value of the field as a type T object.
Exceptions
std::runtime_errorIf the field type does not match the expected type.
// memory allocation in std::string
std::string stringValue = urRecordView.getFieldAsType<std::string>(fieldID);
// no memory allocation
std::string_view stringValue = urRecordView.getFieldAsType<std::string_view>(fieldID);
// Get pointer to unirec field value
int* intValuePtr = urRecordView.getFieldAsType<int*>(fieldID);
// Get reference to unirec field value
int& intValueRef = urRecordView.getFieldAsType<int&>(fieldID);
// Get value of unirec field
int intValue = urRecordView.getFieldAsType<int>(fieldID);

Definition at line 117 of file unirecRecordView.hpp.

◆ getFieldAsUnirecArray()

template<typename T >
add_const_t<UnirecArray<T> > Nemea::UnirecRecordView::getFieldAsUnirecArray ( ur_field_id_t  fieldID) const
inline

Gets the value of a field as a UnirecArray.

This function retrieves the value of a field as a UnirecArray object, which provides a view into a contiguous array of values associated with the specified unirec field ID.

Template Parameters
TThe element type of the array.
Parameters
fieldIDThe ID of the field to get.
Returns
A UnirecArray<T> object representing the array.
// Get array of int values as UnirecArray
UnirecArray<int> array = urRecordView.getFieldAsUnirecArray<int>(fieldID);

Definition at line 159 of file unirecRecordView.hpp.

◆ getSequenceNumber()

uint64_t Nemea::UnirecRecordView::getSequenceNumber ( ) const
inlinenoexcept

Gets the sequence number of the record.

The sequence number represents the order of UniRec records when they are processed. Sequential numbers are currently supported by libtrap only for the Unix socket interface. If there is a gap between sequential numbers, it indicates data loss, which can occur when the internal buffers overflow due to the data not being retrieved in a timely manner. A sequential number of 0 signifies that sequential numbering is not supported. Sequential numbers start from 1 and increase for each new record.

Returns
The sequence number of the record.
Note
0 signifies that sequential numbering is not supported by the interface.

Definition at line 83 of file unirecRecordView.hpp.

◆ size()

size_t Nemea::UnirecRecordView::size ( ) const
inlinenoexcept

Returns the size of the UniRec record.

Returns
The size of the UniRec record.

Definition at line 67 of file unirecRecordView.hpp.

Friends And Related Function Documentation

◆ UnirecRecord

friend class UnirecRecord
friend

Definition at line 180 of file unirecRecordView.hpp.

Field Documentation

◆ m_recordData

const void* Nemea::UnirecRecordView::m_recordData
private

Definition at line 176 of file unirecRecordView.hpp.

◆ m_sequenceNumber

uint64_t Nemea::UnirecRecordView::m_sequenceNumber
private

Definition at line 178 of file unirecRecordView.hpp.

◆ m_unirecTemplate

ur_template_t* Nemea::UnirecRecordView::m_unirecTemplate
private

Definition at line 177 of file unirecRecordView.hpp.


The documentation for this class was generated from the following file: