usertools: remove unused imports in devbind
[dpdk.git] / lib / librte_telemetry / telemetry_json.h
index a2ce489..ad270b9 100644 (file)
@@ -102,6 +102,22 @@ rte_tel_json_add_array_u64(char *buf, const int len, const int used,
        return ret == 0 ? used : end + ret;
 }
 
+/*
+ * Add a new element with raw JSON value to the JSON array stored in the
+ * provided buffer.
+ */
+static inline int
+rte_tel_json_add_array_json(char *buf, const int len, const int used,
+               const char *str)
+{
+       int ret, end = used - 1; /* strip off final delimiter */
+       if (used <= 2) /* assume empty, since minimum is '[]' */
+               return __json_snprintf(buf, len, "[%s]", str);
+
+       ret = __json_snprintf(buf + end, len - end, ",%s]", str);
+       return ret == 0 ? used : end + ret;
+}
+
 /**
  * Add a new element with uint64_t value to the JSON object stored in the
  * provided buffer.
@@ -155,4 +171,21 @@ rte_tel_json_add_obj_str(char *buf, const int len, const int used,
        return ret == 0 ? used : end + ret;
 }
 
+/**
+ * Add a new element with raw JSON value to the JSON object stored in the
+ * provided buffer.
+ */
+static inline int
+rte_tel_json_add_obj_json(char *buf, const int len, const int used,
+               const char *name, const char *val)
+{
+       int ret, end = used - 1;
+       if (used <= 2) /* assume empty, since minimum is '{}' */
+               return __json_snprintf(buf, len, "{\"%s\":%s}", name, val);
+
+       ret = __json_snprintf(buf + end, len - end, ",\"%s\":%s}",
+                       name, val);
+       return ret == 0 ? used : end + ret;
+}
+
 #endif /*_RTE_TELEMETRY_JSON_H_*/