Code

data: Added sdb_data_sizeof().
authorSebastian Harl <sh@tokkee.org>
Sun, 19 Oct 2014 20:21:45 +0000 (22:21 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 19 Oct 2014 20:21:45 +0000 (22:21 +0200)
This function returns the size of the data-type for a given type.

src/core/data.c
src/include/core/data.h

index f489367a42218e35a94bbf64afbff7d6255442fb..9890aafb65c80fded00ba1db13db3390908bfef9 100644 (file)
@@ -646,5 +646,24 @@ sdb_data_parse(char *str, int type, sdb_data_t *data)
        return 0;
 } /* sdb_data_parse */
 
+size_t
+sdb_data_sizeof(int type)
+{
+       sdb_data_t v;
+       if (type == SDB_TYPE_INTEGER)
+               return sizeof(v.data.integer);
+       else if (type == SDB_TYPE_DECIMAL)
+               return sizeof(v.data.decimal);
+       else if (type == SDB_TYPE_STRING)
+               return sizeof(v.data.string);
+       else if (type == SDB_TYPE_DATETIME)
+               return sizeof(v.data.datetime);
+       else if (type == SDB_TYPE_BINARY)
+               return sizeof(v.data.binary);
+       else if (type == SDB_TYPE_REGEX)
+               return sizeof(v.data.re);
+       return 0;
+} /* sdb_data_sizeof */
+
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */
 
index 514c4d524ce2dd04dc463ff6b7e51254dede129f..c8c7482e796f4438aeafdb8eebe4588223636e7b 100644 (file)
@@ -257,6 +257,17 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted);
 int
 sdb_data_parse(char *str, int type, sdb_data_t *data);
 
+/*
+ * sdb_data_sizeof:
+ * Return the size of the data-type identified by the specified type.
+ *
+ * Returns:
+ *  - the size of the data-type on success
+ *  - 0 else
+ */
+size_t
+sdb_data_sizeof(int type);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif