aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver/hash-table.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-04-23 07:03:17 +0200
committerMattias Andrée <maandree@operamail.com>2014-04-23 07:03:17 +0200
commit739a3cfb154625effad019ac5a97deffc5175585 (patch)
tree58ccdd17cbef96dcdcdd4330a668cfe7c7f0feff /src/libmdsserver/hash-table.c
parentadd missed include (diff)
downloadmds-739a3cfb154625effad019ac5a97deffc5175585.tar.gz
mds-739a3cfb154625effad019ac5a97deffc5175585.tar.bz2
mds-739a3cfb154625effad019ac5a97deffc5175585.tar.xz
add value remapping to hash table unmarshaling
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/hash-table.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libmdsserver/hash-table.c b/src/libmdsserver/hash-table.c
index a02e6a9..b56600b 100644
--- a/src/libmdsserver/hash-table.c
+++ b/src/libmdsserver/hash-table.c
@@ -430,12 +430,13 @@ void hash_table_marshal(const hash_table_t* restrict this, char* restrict data)
/**
* Unmarshals a hash table
*
- * @param this Memory slot in which to store the new hash table
- * @param data In buffer with the marshalled data
- * @return Non-zero one error, errno will be set accordingly.
- * Destroy the list on error.
+ * @param this Memory slot in which to store the new hash table
+ * @param data In buffer with the marshalled data
+ * @param remapper Function that translates values, `NULL` if not translation takes place
+ * @return Non-zero one error, errno will be set accordingly.
+ * Destroy the list on error.
*/
-int hash_table_unmarshal(hash_table_t* restrict this, char* restrict data)
+int hash_table_unmarshal(hash_table_t* restrict this, char* restrict data, remap_func* remapper)
{
size_t i, n;
@@ -477,6 +478,8 @@ int hash_table_unmarshal(hash_table_t* restrict this, char* restrict data)
}
bucket->key = ((size_t*)data)[0];
bucket->value = ((size_t*)data)[1];
+ if (remapper != NULL)
+ bucket->value = remapper(bucket->value);
bucket->hash = ((size_t*)data)[2];
data += 3 * sizeof(size_t) / sizeof(char);
}