types FEATURE add hash callback for the types plugins
Since the representation of the value can be type-specific, it make
sense to let the plugin count the hash of the value instead of always
using the canonical representation (and force the plugin to create
such a representation) instead of creating hash from its specific
(e.g. binary) representation.
diff --git a/src/validation.c b/src/validation.c
index 1a0c396..8895531 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -1038,8 +1038,9 @@
LY_ARRAY_COUNT_TYPE u, v, x = 0;
LY_ERR ret = LY_SUCCESS;
uint32_t hash, i, size = 0;
- ly_bool dynamic;
- const char *str;
+ size_t key_len;
+ ly_bool dyn;
+ const void *hash_key;
struct hash_table **uniqtables = NULL;
struct lyd_value *val;
struct ly_ctx *ctx = snode->module->ctx;
@@ -1104,11 +1105,11 @@
break;
}
- /* get canonical string value */
- str = val->realtype->plugin->print(ctx, val, LY_VALUE_JSON, NULL, &dynamic, NULL);
- hash = dict_hash_multi(hash, str, strlen(str));
- if (dynamic) {
- free((char *)str);
+ /* get hash key */
+ hash_key = val->realtype->plugin->hash(val, &dyn, &key_len);
+ hash = dict_hash_multi(hash, hash_key, key_len);
+ if (dyn) {
+ free((void *)hash_key);
}
}
if (!val) {