types CHANGE redesign storing canonical values
Canonical values are not available for all the types and the type's
printer should be used to get string representation instead of trying to
get string value directly from the lyd_value. So, the canonical value is
now much more hidden in lyd_value structure. On the other hand, there is
newly available original string representation of the value (some of the
types already needed it), which is always present no matter of the
value's type.
diff --git a/src/tree_data.h b/src/tree_data.h
index d6babc2..589a3e0 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -145,14 +145,9 @@
* @brief YANG data representation
*/
struct lyd_value {
- const char *canonized; /**< Canonical string representation of value (for comparison, printing,...), canonized according to the
- rules implemented in the type's canonization callback (if any). Note that not all the types
- have a canonical representation, so this value can be even NULL (identityref or instance-identifiers
- are built-in examples of such a case). The lyd_value::realtype's print callback provides possibility
- to get correct string representation of the value for the specific data format. */
+ const char *original; /**< Original string representation of the value. It is never NULL, but (canonical) string representation
+ of the value should be always obtained via the type's printer callback (lyd_value::realtype::plugin::print). */
union {
- const char *string; /**< original, non-canonized string value. Useful for example for unions where the type (and therefore
- the canonization rules) can change by changing value (e.g. leafref target) somewhere else. */
int8_t boolean; /**< 0 as false, 1 as true */
int64_t dec64; /**< decimal64: value = dec64 / 10^fraction-digits */
int8_t int8; /**< 8-bit signed integer */
@@ -198,13 +193,16 @@
}; /**< The union is just a list of shorthands to possible values stored by a type's plugin. libyang itself uses the lyd_value::realtype
plugin's callbacks to work with the data. */
- struct lysc_type *realtype; /**< pointer to the real type of the data stored in the value structure. This type can differ from the type
+ struct lysc_type *realtype; /**< pointer to the real type of the data stored in the value structure. This type can differ from the type
in the schema node of the data node since the type's store plugin can use other types/plugins for
storing data. Speaking about built-in types, this is the case of leafref which stores data as its
target type. In contrast, union type also use its subtype's callbacks, but inside an internal data
lyd_value::subvalue structure, so here is the pointer to the union type.
In general, this type is used to get free callback for this lyd_value structure, so it must reflect
the type used to store data directly in the same lyd_value instance. */
+ void *canonical_cache; /**< Generic cache for type plugins to store data necessary to print canonical value. It can be the canonical
+ value itself or anything else useful to print the canonical form of the value. Plugin is responsible for
+ freeing the cache in its free callback. */
};
/**
@@ -472,9 +470,10 @@
* @param[in] name_len Optional length of the @p name argument in case it is not NULL-terminated string.
* @param[in] nodetype Optional mask for the nodetype of the node to find, 0 is understood as all nodetypes.
* @param[in] value Optional restriction for lyd_node_term nodes to select node with the specific value. Note that this
- * search restriction is limited to compare canonical representation of the type. Some of the types have no canonical
- * representation and 2 different strings can represent the same value (e.g. different prefixes of the same namespace in instance-identifiers).
- * In this case there is more advanced lyd_value_compare() to check if the values matches.
+ * search restriction is limited to compare original string representation of the @p first value. Some of the types have
+ * canonical representation defined so the same value can be represented by multiple lexical representation. In such a
+ * case the @p value not matching the original representation of @p first may still be the same.
+ * For such a case there is more advanced lyd_value_compare() to check if the values matches.
* @param[in] value_len Optional length of the @p value argument in case it is not NULL-terminated string.
* @return The sibling node of the @p first (or itself), satisfying the given restrictions.
* @return NULL in case there is no node satisfying the restrictions.