Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS-12: Fix datatype constraints check for NcDatatypeDescriptorStruct #413

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions Development/nmos/control_protocol_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,38 +266,28 @@ namespace nmos
if (!value_.has_field(field_name)) { throw control_protocol_exception("missing " + utility::us2s(field_name) + " in " + utility::us2s(datatype_name)); }

// is field nullable
if (nmos::fields::nc::is_nullable(nc_field_descriptor) != value_.is_null()) { throw control_protocol_exception(utility::us2s(field_name) + " is not nullable"); }
if (!nmos::fields::nc::is_nullable(nc_field_descriptor) && value_.at(field_name).is_null()) { throw control_protocol_exception(utility::us2s(field_name) + " is not nullable"); }

// if field value is null continue to next field
if (value_.at(field_name).is_null()) continue;

// is field sequenceable
if (nmos::fields::nc::is_sequence(nc_field_descriptor) != value_.is_array()) { throw control_protocol_exception(utility::us2s(field_name) + " is not sequenceable"); }
if (nmos::fields::nc::is_sequence(nc_field_descriptor) != value_.at(field_name).is_array()) { throw control_protocol_exception(utility::us2s(field_name) + " is not sequenceable"); }

// check against field constraints if presented
const auto& constraints = nmos::fields::nc::constraints(nc_field_descriptor);
if (constraints.is_null())
{
// no field constraints, move to check the constraints of its typeName
const auto& field_type_name = nc_field_descriptor.at(nmos::fields::nc::type_name);
// check constraints of its typeName
const auto& field_type_name = nc_field_descriptor.at(nmos::fields::nc::type_name);

if (!field_type_name.is_null())
{
auto value = value_.at(field_name);
if (!field_type_name.is_null())
{
auto value = value_.at(field_name);

if (value.is_array())
{
for (const auto& val : value.as_array())
{
// do typename constraints validation
datatype_constraints_validation(val, { details::get_datatype_descriptor(field_type_name, params.get_control_protocol_datatype_descriptor), params.get_control_protocol_datatype_descriptor });
}
}
else
{
// do typename constraints validation
datatype_constraints_validation(value, { details::get_datatype_descriptor(field_type_name, params.get_control_protocol_datatype_descriptor), params.get_control_protocol_datatype_descriptor });
}
}
// do typename constraints validation
datatype_constraints_validation(value, { details::get_datatype_descriptor(field_type_name, params.get_control_protocol_datatype_descriptor), params.get_control_protocol_datatype_descriptor });
}
else

// check against field constraints if present
const auto& constraints = nmos::fields::nc::constraints(nc_field_descriptor);
if (!constraints.is_null())
{
// do field constraints validation
const auto& value = value_.at(field_name);
Expand Down
Loading
Loading