Commit e7798278 authored by Matthieu Dorier's avatar Matthieu Dorier

added encoding/decoding functions for omap iterator

parent b504a051
......@@ -9,7 +9,8 @@ src_libmobject_store_la_SOURCES = \
src/prepare-read-op.c \
src/write-op-visitor.c \
src/read-op-visitor.c \
src/omap-iter-impl.c
src/omap-iter-impl.c \
src/proc-omap-iter.c
noinst_HEADERS += \
src/log.h \
......@@ -26,4 +27,5 @@ noinst_HEADERS += \
src/write-op-visitor.h \
src/read-op-visitor.h \
src/buffer-union.h \
src/omap-iter-impl.h
src/omap-iter-impl.h \
src/proc-omap-iter.h
......@@ -16,6 +16,8 @@ void omap_iter_create(mobject_store_omap_iter_t* iter)
void omap_iter_free(mobject_store_omap_iter_t iter)
{
if(!iter) return;
omap_iter_node_t elt, tmp;
DL_FOREACH_SAFE(iter->head, elt, tmp) {
......@@ -32,16 +34,21 @@ void omap_iter_append(mobject_store_omap_iter_t iter,
const char* key, const char* val,
size_t val_size)
{
MOBJECT_ASSERT(iter, "trying to append to a NULL iterator");
omap_iter_node_t item = (omap_iter_node_t)calloc(1, sizeof(*item));
item->key = strdup(key);
item->value_size = val_size;
item->value = (char*)malloc(val_size);
item->key = strdup(key);
item->key_size = strlen(key)+1;
item->value_size = val_size;
item->value = (char*)malloc(val_size);
memcpy(item->value, val, val_size);
DL_APPEND(iter->head, item);
if(iter->current == NULL)
iter->current = iter->head;
iter->num_items += 1;
}
int mobject_store_omap_get_next(mobject_store_omap_iter_t iter,
......
......@@ -8,19 +8,18 @@
#include "libmobject-store.h"
#define OMAP_ITER_OWNS_KEY 0x1
#define OMAP_ITER_OWNS_VALUE 0x2
typedef struct omap_iter_node* omap_iter_node_t;
struct omap_iter_node {
char* key;
char* value;
size_t key_size;
size_t value_size;
omap_iter_node_t prev, next;
};
struct mobject_store_omap_iter {
size_t num_items;
omap_iter_node_t head;
omap_iter_node_t current;
};
......
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <margo.h>
#include "utlist.h"
#include "proc-omap-iter.h"
hg_return_t hg_proc_mobject_store_omap_iter_t(hg_proc_t proc, mobject_store_omap_iter_t* iter)
{
omap_iter_node_t node;
hg_return_t ret = HG_SUCCESS;
switch(hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_hg_size_t(proc, &((*iter)->num_items));
if(ret != HG_SUCCESS) return ret;
DL_FOREACH((*iter)->head, node) {
ret = hg_proc_hg_size_t(proc, &(node->key_size));
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_memcpy(proc, &(node->key), node->key_size);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_size_t(proc, &(node->value_size));
if(ret != HG_SUCCESS) return ret;
ret = hg_memcpy(proc, node->value, node->value_size);
if(ret != HG_SUCCESS) return ret;
}
break;
case HG_DECODE:
omap_iter_create(iter);
ret = hg_proc_hg_size_t(proc, &((*iter)->num_items));
if(ret != HG_SUCCESS) return ret;
unsigned i;
size_t key_size, val_size;
char* key;
char* val;
for(i = 0; i < (*iter)->num_items; i++) {
ret = hg_proc_hg_size_t(proc, &key_size);
key = (char*)malloc(key_size);
ret = hg_proc_memcpy(proc, key, key_size);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_size_t(proc, &val_size);
if(ret != HG_SUCCESS) return ret;
val - (char*)malloc(val_size);
ret = hg_proc_memcpy(proc, val, val_size);
omap_iter_append(*iter, key, val, val_size);
}
break;
case HG_FREE:
omap_iter_free(*iter);
break;
}
return HG_SUCCESS;
}
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __MOBJECT_PROC_OMAP_ITER_H
#define __MOBJECT_PROC_OMAP_ITER_H
#include "omap-iter-impl.h"
hg_return_t hg_proc_mobject_store_omap_iter_t(hg_proc_t proc, mobject_store_omap_iter_t* iter);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment