summaryrefslogtreecommitdiffstats
path: root/src/rpc-server/trex_rpc_cmd_api.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc-server/trex_rpc_cmd_api.h')
-rw-r--r--src/rpc-server/trex_rpc_cmd_api.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/rpc-server/trex_rpc_cmd_api.h b/src/rpc-server/trex_rpc_cmd_api.h
index de0f5b58..2536f69c 100644
--- a/src/rpc-server/trex_rpc_cmd_api.h
+++ b/src/rpc-server/trex_rpc_cmd_api.h
@@ -114,6 +114,7 @@ protected:
FIELD_TYPE_UINT64,
FIELD_TYPE_INT,
FIELD_TYPE_DOUBLE,
+ FIELD_TYPE_UDOUBLE,
FIELD_TYPE_BOOL,
FIELD_TYPE_STR,
FIELD_TYPE_OBJ,
@@ -184,6 +185,11 @@ protected:
return parent[param].asDouble();
}
+ template<typename T> double parse_udouble(const Json::Value &parent, const T &param, Json::Value &result) {
+ check_field_type(parent, param, FIELD_TYPE_UDOUBLE, result);
+ return parent[param].asDouble();
+ }
+
template<typename T> bool parse_bool(const Json::Value &parent, const T &param, Json::Value &result) {
check_field_type(parent, param, FIELD_TYPE_BOOL, result);
return parent[param].asBool();
@@ -256,6 +262,20 @@ protected:
return parse_double(parent, param, result);
}
+ template<typename T> double parse_udouble(const Json::Value &parent, const T &param, Json::Value &result, double def) {
+ /* if not exists - default */
+ if (parent[param] == Json::Value::null) {
+ if (def < 0) {
+ std::stringstream ss;
+ ss << "default value of '" << param << "' is negative (please report)";
+ generate_parse_err(result, ss.str());
+ } else {
+ return def;
+ }
+ }
+ return parse_udouble(parent, param, result);
+ }
+
template<typename T> bool parse_bool(const Json::Value &parent, const T &param, Json::Value &result, bool def) {
/* if not exists - default */
if (parent[param] == Json::Value::null) {