8#ifndef META_OCEAN_IO_SERIALIZATION_DATA_SERIALIZER_H
9#define META_OCEAN_IO_SERIALIZATION_DATA_SERIALIZER_H
26namespace Serialization
48 static constexpr ChannelId invalidChannelId();
85 inline ChannelConfiguration(
const std::string& sampleType,
const std::string& name,
const std::string& contentType);
91 inline const std::string& sampleType()
const;
97 inline const std::string& name()
const;
103 inline const std::string& contentType()
const;
109 inline bool isValid()
const;
149 inline size_t operator()(
const Channel& channel)
const;
176 inline bool isValid()
const;
183 inline bool operator==(
const Channel& channel)
const;
262 inline bool writeSample(
OutputBitstream& outputBitstream)
const override;
268 inline const std::string& type()
const override;
327 [[nodiscard]]
static constexpr bool isConfigurationChannelId(
const uint32_t channelValue);
334 [[nodiscard]]
static constexpr uint32_t makeConfigurationChannelId(
const ChannelId channelId);
341 [[nodiscard]]
static constexpr ChannelId extractChannelId(
const uint32_t channelValue);
352 bool succeeded_ =
true;
365 size_t seed = std::hash<std::string>()(channelConfiguration.
sampleType_);
366 seed ^= std::hash<std::string>{}(channelConfiguration.
name_) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
367 seed ^= std::hash<std::string>{}(channelConfiguration.
contentType_) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
397 return !sampleType_.empty() && !name_.empty() && !contentType_.empty();
402 return sampleType_ == channelConfiguration.
sampleType_ && name_ == channelConfiguration.
name_ && contentType_ == channelConfiguration.
contentType_;
407 size_t seed = std::hash<uint32_t>()(channel.
channelId_);
415 channelId_(channelId)
437 constexpr uint32_t highestBit = 1u << 31u;
439 return channelValue & highestBit;
447 constexpr uint32_t highestBit = 1u << 31u;
449 return channelId | highestBit;
454 constexpr uint32_t highestBit = 1u << 31u;
456 return ChannelId(channelValue & ~highestBit);
467 DataSample(dataTimestamp, sampleCreationTimestamp),
480 return inputBitstream.
read<std::string>(sampleType_) && inputBitstream.
read<std::string>(name_) && inputBitstream.
read<std::string>(contentType_);
490 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:50
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:56
bool operator==(const ChannelConfiguration &channelConfiguration) const
Returns whether two channel configurations are equal.
Definition DataSerializer.h:400
std::string name_
The name of the channel.
Definition DataSerializer.h:124
std::string contentType_
The content type.
Definition DataSerializer.h:127
ChannelConfiguration()=default
Creates a new invalid channel configuration.
bool isValid() const
Returns whether this channel configuration is valid.
Definition DataSerializer.h:395
const std::string & sampleType() const
Returns the sample type.
Definition DataSerializer.h:380
const std::string & contentType() const
Returns the content type.
Definition DataSerializer.h:390
const std::string & name() const
Returns the name of the channel.
Definition DataSerializer.h:385
std::string sampleType_
The sample type.
Definition DataSerializer.h:121
This class implements a channel with configuration and channel id.
Definition DataSerializer.h:136
Channel()=default
Creates a new invalid channel.
bool operator==(const Channel &channel) const
Returns whether two channels are equal.
Definition DataSerializer.h:430
ChannelId channelId() const
Returns the channel id.
Definition DataSerializer.h:420
bool isValid() const
Returns whether this channel is valid.
Definition DataSerializer.h:425
ChannelId channelId_
The channel id.
Definition DataSerializer.h:188
This class implements a data sample holding channel configuration information.
Definition DataSerializer.h:227
bool readSample(InputBitstream &inputBitstream) override
Reads the sample from an input bitstream.
Definition DataSerializer.h:473
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:483
const std::string & type() const override
Returns the type of the sample.
Definition DataSerializer.h:493
This class implements the base class for data serializers.
Definition DataSerializer.h:38
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:442
static constexpr ChannelId invalidChannelId()
Returns an invalid channel id.
Definition DataSerializer.h:358
std::unordered_map< ChannelConfiguration, ChannelId, ChannelConfiguration::Hash > ChannelConfigurationMap
Definition of a map mapping channel configurations to channel ids.
Definition DataSerializer.h:214
Timestamp startTimestamp_
The timestamp when the serializer was started.
Definition DataSerializer.h:346
virtual bool hasStopped() const
Returns whether the serializer has stopped but does not check wehther remaining samples have not yet ...
std::pair< ChannelId, UniqueDataSample > SamplePair
Definition of a pair holding a channel id and a unique data sample.
Definition DataSerializer.h:217
std::vector< Channel > Channels
Definition of a vector holding channels.
Definition DataSerializer.h:192
Lock lock_
The lock for thread-safe access.
Definition DataSerializer.h:355
static constexpr bool isConfigurationChannelId(const uint32_t channelValue)
Returns whether the given channel value has the configuration bit set.
Definition DataSerializer.h:435
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:42
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:200
@ S_IDLE
The serializer has not yet been initialized or started.
Definition DataSerializer.h:202
@ S_INITIALIZED
The serializer has been initialized and is ready to start.
Definition DataSerializer.h:204
@ S_STARTED
The serializer has been started and is currently actively processing data samples.
Definition DataSerializer.h:206
@ S_STOPPING
The serializer is currently stopping but may still process remaining data samples.
Definition DataSerializer.h:208
virtual ~DataSerializer()=default
Destructs the data serializer.
virtual bool hasFinished() const =0
Returns whether the serializer has stopped and all remaining samples have been processed or retrieved...
static constexpr ChannelId extractChannelId(const uint32_t channelValue)
Extracts the channel id from a channel value by clearing the configuration bit.
Definition DataSerializer.h:452
This class implements a data timestamp which can hold either a double or int64_t value.
Definition DataTimestamp.h:32
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:64
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
Definition of a hash function for Channel objects.
Definition DataSerializer.h:143
size_t operator()(const Channel &channel) const
Calculates the hash value for a given channel.
Definition DataSerializer.h:405
Definition of a hash function for ChannelConfiguration objects.
Definition DataSerializer.h:63
size_t operator()(const ChannelConfiguration &channelConfiguration) const
Calculates the hash value for a given channel configuration.
Definition DataSerializer.h:363