MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::FlowOptionsParser Class Reference

#include <FlowOptionsParser.hpp>

Public Member Functions

 FlowOptionsParser ()=default
 FlowOptionsParser (std::string const &in_flowOptions)
template<typename T>
T get (std::string const &field) const
std::optional< std::uint32_t > getMaxCommitBatchSizeHint () const
std::optional< std::uint32_t > getMaxSyncBatchSizeHint () const

Private Attributes

std::optional< std::uint32_t > _maxCommitBatchSizeHint
std::optional< std::uint32_t > _maxSyncBatchSizeHint
picojson::object _root

Detailed Description

Parses flow options and extracts valid attributes.

Definition at line 17 of file FlowOptionsParser.hpp.

Constructor & Destructor Documentation

◆ FlowOptionsParser() [1/2]

mxl::lib::FlowOptionsParser::FlowOptionsParser ( )
default

◆ FlowOptionsParser() [2/2]

mxl::lib::FlowOptionsParser::FlowOptionsParser ( std::string const & in_flowOptions)

Parses a json of flow options

Parameters
in_flowOptionsThe flow options
Exceptions
std::runtime_erroron any parse error

Definition at line 12 of file FlowOptionsParser.cpp.

13 {
14 if (in_options.empty())
15 {
16 return;
17 }
18
19 //
20 // Parse the json options
21 //
22 auto jsonValue = picojson::value{};
23 auto const err = parseJson(jsonValue, in_options);
24 if (!err.empty())
25 {
26 throw std::invalid_argument{"Invalid JSON options. " + err};
27 }
28
29 // Confirm that the root is a json object
30 if (!jsonValue.is<picojson::object>())
31 {
32 throw std::invalid_argument{"Expected a JSON object"};
33 }
34 _root = jsonValue.get<picojson::object>();
35
36 auto maxCommitBatchSizeHintIt = _root.find("maxCommitBatchSizeHint");
37 if (maxCommitBatchSizeHintIt != _root.end())
38 {
39 if (!maxCommitBatchSizeHintIt->second.is<double>())
40 {
41 throw std::invalid_argument{"maxCommitBatchSizeHint must be a number."};
42 }
43
44 auto const v = jsonToInteger<std::uint32_t>(maxCommitBatchSizeHintIt->second, "maxCommitBatchSizeHint");
45 if (v < 1U)
46 {
47 throw std::invalid_argument{"maxCommitBatchSizeHint must be greater or equal to 1."};
48 }
50 }
51
52 auto maxSyncBatchSizeHintIt = _root.find("maxSyncBatchSizeHint");
53 if (maxSyncBatchSizeHintIt != _root.end())
54 {
55 if (!maxSyncBatchSizeHintIt->second.is<double>())
56 {
57 throw std::invalid_argument{"maxSyncBatchSizeHint must be a number."};
58 }
59
60 auto const v = jsonToInteger<std::uint32_t>(maxSyncBatchSizeHintIt->second, "maxSyncBatchSizeHint");
61 if (v < 1U)
62 {
63 throw std::invalid_argument{"maxSyncBatchSizeHint must be greater or equal to 1."};
64 }
66 if ((_maxSyncBatchSizeHint.value() % _maxCommitBatchSizeHint.value_or(1) != 0))
67 {
68 throw std::invalid_argument{"maxSyncBatchSizeHint must be a multiple of maxCommitBatchSizeHint."};
69 }
70 }
71 }
std::optional< std::uint32_t > _maxSyncBatchSizeHint
std::optional< std::uint32_t > _maxCommitBatchSizeHint
T jsonToInteger(picojson::value const &value, std::string_view name)
std::string parseJson(picojson::value &out, std::string_view text, JsonLimits const &limits={})

Member Function Documentation

◆ get()

template<typename T>
T mxl::lib::FlowOptionsParser::get ( std::string const & field) const
nodiscard

Generic accessor for json fields.

Parameters
in_fieldThe field name.
Returns
The field value if found.
Exceptions
Ifthe field is not found or T is incompatible

◆ getMaxCommitBatchSizeHint()

std::optional< std::uint32_t > mxl::lib::FlowOptionsParser::getMaxCommitBatchSizeHint ( ) const
nodiscard

Accessor for the 'maxCommitBatchSizeHint' field, which expresses the largest expected batch size in samples (for continuous flows) or slices (for discrete flows), in which new data is written to this this flow by its producer. For continuous flows, this value must be less than half of the buffer length. For discrete flows, this must be greater or equal to 1.

Definition at line 73 of file FlowOptionsParser.cpp.

74 {
76 }

◆ getMaxSyncBatchSizeHint()

std::optional< std::uint32_t > mxl::lib::FlowOptionsParser::getMaxSyncBatchSizeHint ( ) const
nodiscard

Accessor for the 'maxSyncBatchSizeHint' field, which expresses the largest expected batch size in samples (for continuous flows) or slices (for discrete flows), at which availability of new data is signaled to waiting consumers. This must be a multiple of the commit batch size greater or equal to 1.

Definition at line 78 of file FlowOptionsParser.cpp.

79 {
81 }

Member Data Documentation

◆ _maxCommitBatchSizeHint

std::optional<std::uint32_t> mxl::lib::FlowOptionsParser::_maxCommitBatchSizeHint
private
See also
mxlCommonFlowInfo::maxCommitBatchSizeHint

Definition at line 61 of file FlowOptionsParser.hpp.

◆ _maxSyncBatchSizeHint

std::optional<std::uint32_t> mxl::lib::FlowOptionsParser::_maxSyncBatchSizeHint
private
See also
mxlCommonFlowInfo::maxSyncBatchSizeHint

Definition at line 59 of file FlowOptionsParser.hpp.

◆ _root

picojson::object mxl::lib::FlowOptionsParser::_root
private

The parsed flow object.

Definition at line 63 of file FlowOptionsParser.hpp.


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