8#ifndef META_OCEAN_IO_SERIALIZATION_DATA_SERIALIZER_H
9#define META_OCEAN_IO_SERIALIZATION_DATA_SERIALIZER_H
26namespace Serialization
46 static constexpr ChannelId invalidChannelId();
81 inline ChannelConfiguration(
const std::string& sampleType,
const std::string& name,
const std::string& contentType);
87 inline const std::string& sampleType()
const;
93 inline const std::string& name()
const;
99 inline const std::string& contentType()
const;
105 inline bool isValid()
const;
143 inline size_t operator()(
const Channel& channel)
const;
170 inline bool isValid()
const;
177 inline bool operator==(
const Channel& channel)
const;
257 inline bool writeSample(
OutputBitstream& outputBitstream)
const override;
263 inline const std::string& type()
const override;
315 [[nodiscard]]
static constexpr bool isConfigurationChannelId(
const uint32_t channelValue);
322 [[nodiscard]]
static constexpr uint32_t makeConfigurationChannelId(
const ChannelId channelId);
329 [[nodiscard]]
static constexpr ChannelId extractChannelId(
const uint32_t channelValue);
340 bool succeeded_ =
true;
356 size_t seed = std::hash<std::string>()(channelConfiguration.
sampleType_);
357 seed ^= std::hash<std::string>{}(channelConfiguration.
name_) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
358 seed ^= std::hash<std::string>{}(channelConfiguration.
contentType_) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
388 return !sampleType_.empty() && !name_.empty() && !contentType_.empty();
393 return sampleType_ == channelConfiguration.
sampleType_ && name_ == channelConfiguration.
name_ && contentType_ == channelConfiguration.
contentType_;
398 size_t seed = std::hash<uint32_t>()(channel.
channelId_);
406 channelId_(channelId)
428 constexpr uint32_t highestBit = 1u << 31u;
430 return channelValue & highestBit;
438 constexpr uint32_t highestBit = 1u << 31u;
440 return channelId | highestBit;
445 constexpr uint32_t highestBit = 1u << 31u;
447 return ChannelId(channelValue & ~highestBit);
458 DataSample(dataTimestamp, sampleCreationTimestamp),
471 return inputBitstream.
read<std::string>(sampleType_) && inputBitstream.
read<std::string>(name_) && inputBitstream.
read<std::string>(contentType_);
481 return outputBitstream.
write<std::string>(sampleType_) && outputBitstream.
write<std::string>(name_) && outputBitstream.
write<std::string>(contentType_);
This class implements an output bitstream.
Definition Bitstream.h:215
bool write(const T &value)
Writes a data object to the stream and moves the internal position inside the bitstream accordingly.
This class implements a base class for data samples.
Definition DataSample.h:46
virtual bool readSample(InputBitstream &inputBitstream)
Reads the sample from an input bitstream.
virtual bool writeSample(OutputBitstream &outputBitstream) const
Writes the sample to an output bitstream.
This class holds channel configuration (sample type, name, and content type).
Definition DataSerializer.h:52
bool operator==(const ChannelConfiguration &channelConfiguration) const
Returns whether two channel configurations are equal.
Definition DataSerializer.h:391
std::string name_
The name of the channel.
Definition DataSerializer.h:120
std::string contentType_
The content type.
Definition DataSerializer.h:123
ChannelConfiguration()=default
Creates a new invalid channel configuration.
bool isValid() const
Returns whether this channel configuration is valid.
Definition DataSerializer.h:386
const std::string & sampleType() const
Returns the sample type.
Definition DataSerializer.h:371
const std::string & contentType() const
Returns the content type.
Definition DataSerializer.h:381
const std::string & name() const
Returns the name of the channel.
Definition DataSerializer.h:376
std::string sampleType_
The sample type.
Definition DataSerializer.h:117
This class implements a channel with configuration and channel id.
Definition DataSerializer.h:130
Channel()=default
Creates a new invalid channel.
bool operator==(const Channel &channel) const
Returns whether two channels are equal.
Definition DataSerializer.h:421
ChannelId channelId() const
Returns the channel id.
Definition DataSerializer.h:411
bool isValid() const
Returns whether this channel is valid.
Definition DataSerializer.h:416
ChannelId channelId_
The channel id.
Definition DataSerializer.h:182
This class implements a data sample holding channel configuration information.
Definition DataSerializer.h:222
bool readSample(InputBitstream &inputBitstream) override
Reads the sample from an input bitstream.
Definition DataSerializer.h:464
DataSampleChannelConfiguration()=default
Creates a new invalid data sample channel configuration.
bool writeSample(OutputBitstream &outputBitstream) const override
Writes the sample to an output bitstream.
Definition DataSerializer.h:474
const std::string & type() const override
Returns the type of the sample.
Definition DataSerializer.h:484
This class implements the base class for data serializers.
Definition DataSerializer.h:36
std::queue< SamplePair > SampleQueue
Definition of a queue holding sample pairs.
Definition DataSerializer.h:214
static constexpr uint32_t makeConfigurationChannelId(const ChannelId channelId)
Creates a configuration channel id from a regular channel id by setting the highest bit.
Definition DataSerializer.h:433
SampleQueue sampleQueue_
The queue holding samples which are pending to be processed.
Definition DataSerializer.h:343
static constexpr ChannelId invalidChannelId()
Returns an invalid channel id.
Definition DataSerializer.h:349
std::unordered_map< ChannelConfiguration, ChannelId, ChannelConfiguration::Hash > ChannelConfigurationMap
Definition of a map mapping channel configurations to channel ids.
Definition DataSerializer.h:208
virtual bool hasStopped() const =0
Returns whether the serializer has stopped.
Timestamp startTimestamp_
The timestamp when the serializer was started.
Definition DataSerializer.h:334
std::pair< ChannelId, UniqueDataSample > SamplePair
Definition of a pair holding a channel id and a unique data sample.
Definition DataSerializer.h:211
std::vector< Channel > Channels
Definition of a vector holding channels.
Definition DataSerializer.h:186
Lock lock_
The lock for thread-safe access.
Definition DataSerializer.h:346
static constexpr bool isConfigurationChannelId(const uint32_t channelValue)
Returns whether the given channel value has the configuration bit set.
Definition DataSerializer.h:426
virtual bool start()=0
Starts the serializer.
virtual bool stop()=0
Stops the serializer.
virtual bool isStarted() const =0
Returns whether the serializer has been started.
uint32_t ChannelId
Definition of a channel id.
Definition DataSerializer.h:40
virtual bool stopAndWait(const double timeout=60.0)
Stops the serializer and waits until the serializer has stopped.
State
Definition of individual states the serializer can have.
Definition DataSerializer.h:194
@ S_IDLE
The serializer has not yet been initialized or started.
Definition DataSerializer.h:196
@ S_INITIALIZED
The serializer has been initialized and is ready to start.
Definition DataSerializer.h:198
@ S_STARTED
The serializer has been started and is currently actively processing data samples.
Definition DataSerializer.h:200
@ S_STOPPING
The serializer is currently stopping but may still process remaining data samples.
Definition DataSerializer.h:202
virtual ~DataSerializer()=default
Destructs the data serializer.
static constexpr ChannelId extractChannelId(const uint32_t channelValue)
Extracts the channel id from a channel value by clearing the configuration bit.
Definition DataSerializer.h:443
This class implements a data timestamp which can hold either a double or int64_t value.
Definition DataTimestamp.h:29
This class implements a recursive lock object.
Definition Lock.h:31
This class implements a thread.
Definition Thread.h:115
This class implements a timestamp.
Definition Timestamp.h:63
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
Definition of a hash function for Channel objects.
Definition DataSerializer.h:137
size_t operator()(const Channel &channel) const
Calculates the hash value for a given channel.
Definition DataSerializer.h:396
Definition of a hash function for ChannelConfiguration objects.
Definition DataSerializer.h:59
size_t operator()(const ChannelConfiguration &channelConfiguration) const
Calculates the hash value for a given channel configuration.
Definition DataSerializer.h:354