Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
mobject-store
Commits
50b8c379
Commit
50b8c379
authored
Oct 17, 2017
by
Matthieu Dorier
Browse files
some write operations now copy their parameters
parent
a3645a19
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/write-actions.h
View file @
50b8c379
...
...
@@ -86,17 +86,22 @@ typedef struct wr_action_ZERO {
typedef
struct
wr_action_OMAP_SET
{
struct
wr_action_BASE
base
;
char
const
*
const
*
keys
;
char
const
*
const
*
vals
;
const
size_t
*
lens
;
size_t
num
;
char
data
[
1
];
}
*
wr_action_omap_set_t
;
// data above is meant to hold keys, lengths, and values,
// all put together in the same contiguous buffer.
// The buffer holds a series of [key,len,value] segments
// where key is a null-terminated string, len is a size_t,
// and value is a len-sized segment.
typedef
struct
wr_action_RM_KEYS
{
struct
wr_action_BASE
base
;
char
const
*
const
*
keys
;
size_t
keys_len
;
char
keys
[
1
];
}
*
wr_action_omap_rm_keys_t
;
// keys above is meant to hold keys in a contiguous buffer.
// The keys are null-terminated strings.
#endif
src/write-op.c
View file @
50b8c379
...
...
@@ -5,6 +5,7 @@
*/
#include <stdlib.h>
#include <string.h>
#include "mobject-store-config.h"
#include "utlist.h"
#include "libmobject-store.h"
...
...
@@ -162,13 +163,31 @@ void mobject_store_write_op_omap_set(mobject_store_write_op_t write_op,
{
MOBJECT_ASSERT
(
write_op
!=
MOBJECT_WRITE_OP_NULL
,
"invalid mobject_store_write_op_t obect"
);
wr_action_omap_set_t
action
=
(
wr_action_omap_set_t
)
calloc
(
1
,
sizeof
(
*
action
));
// compute the size required to embed the keys and values
size_t
i
;
size_t
extra_size
=
sizeof
(
lens
[
0
])
*
num
;
for
(
i
=
0
;
i
<
num
;
i
++
)
{
extra_size
+=
strlen
(
keys
[
i
])
+
1
;
extra_size
+=
lens
[
i
];
}
wr_action_omap_set_t
action
=
(
wr_action_omap_set_t
)
calloc
(
1
,
sizeof
(
*
action
)
-
1
+
extra_size
);
action
->
base
.
type
=
WRITE_OPCODE_OMAP_SET
;
action
->
keys
=
keys
;
action
->
vals
=
vals
;
action
->
lens
=
lens
;
action
->
num
=
num
;
char
*
data
=
action
->
data
;
for
(
i
=
0
;
i
<
num
;
i
++
)
{
// serialize key
strcpy
(
data
,
keys
[
i
]);
data
+=
strlen
(
keys
[
i
])
+
1
;
// serialize size of value
memcpy
(
data
,
&
lens
[
i
],
sizeof
(
lens
[
i
]));
data
+=
sizeof
(
lens
[
i
]);
// serialize value
memcpy
(
data
,
vals
[
i
],
lens
[
i
]);
data
+=
lens
[
i
];
}
WRITE_ACTION_UPCAST
(
base
,
action
);
DL_APPEND
(
write_op
->
actions
,
base
);
}
...
...
@@ -179,11 +198,24 @@ void mobject_store_write_op_omap_rm_keys(mobject_store_write_op_t write_op,
{
MOBJECT_ASSERT
(
write_op
!=
MOBJECT_WRITE_OP_NULL
,
"invalid mobject_store_write_op_t obect"
);
wr_action_omap_rm_keys_t
action
=
(
wr_action_omap_rm_keys_t
)
calloc
(
1
,
sizeof
(
*
action
));
// find out the extra memory to allocate
size_t
i
;
size_t
extra_mem
=
0
;
for
(
i
=
0
;
i
<
keys_len
;
i
++
)
{
extra_mem
+=
strlen
(
keys
[
i
])
+
1
;
}
wr_action_omap_rm_keys_t
action
=
(
wr_action_omap_rm_keys_t
)
calloc
(
1
,
sizeof
(
*
action
)
-
1
+
extra_mem
);
action
->
base
.
type
=
WRITE_OPCODE_OMAP_RM_KEYS
;
action
->
keys
=
keys
;
action
->
keys_len
=
keys_len
;
char
*
data
=
action
->
keys
;
// serialize the keys
for
(
i
=
0
;
i
<
keys_len
;
i
++
)
{
strcpy
(
data
,
keys
[
i
]);
data
+=
strlen
(
keys
[
i
])
+
1
;
}
WRITE_ACTION_UPCAST
(
base
,
action
);
DL_APPEND
(
write_op
->
actions
,
base
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment