From ead9e66e7ba2f4077293d697327ebc33440e34d7 Mon Sep 17 00:00:00 2001 From: Vitor Barros Date: Fri, 11 Sep 2020 10:55:14 -0300 Subject: [PATCH] Add helper function to assign limit --- src/knot_protocol.c | 30 ++++++++++++++++++++++++++++++ src/knot_protocol.h | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/src/knot_protocol.c b/src/knot_protocol.c index 9fa6325..1c57d2f 100644 --- a/src/knot_protocol.c +++ b/src/knot_protocol.c @@ -131,6 +131,36 @@ int knot_value_type_is_valid(uint8_t type) return KNOT_ERR_INVALID; } +int knot_value_assign_limit(int value_type, knot_value_type value, + knot_value_type *limit) +{ + switch (value_type) { + case KNOT_VALUE_TYPE_INT: + limit->val_i = value.val_i; + break; + case KNOT_VALUE_TYPE_FLOAT: + limit->val_f = value.val_f; + break; + case KNOT_VALUE_TYPE_INT64: + limit->val_i64 = value.val_i64; + break; + case KNOT_VALUE_TYPE_UINT: + limit->val_u = value.val_u; + break; + case KNOT_VALUE_TYPE_UINT64: + limit->val_u64 = value.val_u64; + break; + case KNOT_VALUE_TYPE_BOOL: + /* TODO: Implement support for assigning limits to bool value */ + case KNOT_VALUE_TYPE_RAW: + /* Storage doesn't give support to raw */ + default: + return -EINVAL; + } + + return 0; +} + int knot_type_id_is_basic(uint16_t type_id) { if (type_id < KNOT_TYPE_ID_BASIC_MAX) diff --git a/src/knot_protocol.h b/src/knot_protocol.h index da7de00..72eedf2 100644 --- a/src/knot_protocol.h +++ b/src/knot_protocol.h @@ -170,6 +170,12 @@ typedef union __attribute__ ((packed)) { */ int knot_value_type_is_valid(uint8_t type); +/* + * Helper function to assign threshold limit + */ +int knot_value_assign_limit(int value_type, knot_value_type value, + knot_value_type *limit); + /* * Helper function to verify if type_id is in basic range */