Skip to content

Commit

Permalink
Factored internal object serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed May 20, 2024
1 parent 45963e5 commit ed997ab
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 142 deletions.
4 changes: 0 additions & 4 deletions src/binding_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ _ccs_serialize_bin_ccs_binding_data(
static inline ccs_result_t
_ccs_serialize_bin_size_ccs_binding(ccs_binding_t binding, size_t *cum_size)
{
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)binding);
*cum_size += _ccs_serialize_bin_size_ccs_binding_data(binding->data);
return CCS_RESULT_SUCCESS;
}
Expand All @@ -184,8 +182,6 @@ _ccs_serialize_bin_ccs_binding(
size_t *buffer_size,
char **buffer)
{
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)binding, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_binding_data(
binding->data, buffer_size, buffer));
return CCS_RESULT_SUCCESS;
Expand Down
20 changes: 7 additions & 13 deletions src/cconfigspace_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,13 @@ _ccs_object_deserialize_with_opts(
ccs_result_t err = CCS_RESULT_SUCCESS;
ccs_object_t obj, handle;
_ccs_object_internal_t obj_internal;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY: {
CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal(
&obj_internal, buffer_size, buffer, &handle));
CCS_VALIDATE(_ccs_object_deserialize_with_opts_type(
&obj, obj_internal.type, format, version, buffer_size,
buffer, opts));
} break;
default:
CCS_RAISE(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}

CCS_VALIDATE(_ccs_deserialize_ccs_object_internal(
&obj_internal, format, version, buffer_size, buffer, opts,
&handle));
CCS_VALIDATE(_ccs_object_deserialize_with_opts_type(
&obj, obj_internal.type, format, version, buffer_size, buffer,
opts));
CCS_VALIDATE_ERR_GOTO(
err,
_ccs_object_deserialize_user_data(
Expand Down
97 changes: 85 additions & 12 deletions src/cconfigspace_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,26 @@ _ccs_serialize_bin_size_ccs_object_internal(_ccs_object_internal_t *obj)
_ccs_serialize_bin_size_ccs_object((ccs_object_t)obj);
}

static inline ccs_result_t
_ccs_serialize_size_ccs_object_internal(
_ccs_object_internal_t *obj,
ccs_serialize_format_t format,
size_t *cum_size,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY: {
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(obj);
} break;
default:
CCS_RAISE(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
return CCS_RESULT_SUCCESS;
}

static inline ccs_result_t
_ccs_serialize_bin_ccs_object_internal(
_ccs_object_internal_t *obj,
Expand All @@ -1225,6 +1245,28 @@ _ccs_serialize_bin_ccs_object_internal(
return CCS_RESULT_SUCCESS;
}

static inline ccs_result_t
_ccs_serialize_ccs_object_internal(
_ccs_object_internal_t *obj,
ccs_serialize_format_t format,
size_t *buffer_size,
char **buffer,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY: {
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
obj, buffer_size, buffer));
} break;
default:
CCS_RAISE(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
return CCS_RESULT_SUCCESS;
}

static inline ccs_result_t
_ccs_deserialize_bin_ccs_object_internal(
_ccs_object_internal_t *obj,
Expand Down Expand Up @@ -1253,6 +1295,43 @@ _ccs_peek_bin_ccs_object_internal(
return CCS_RESULT_SUCCESS;
}

struct _ccs_object_deserialize_options_s {
ccs_map_t handle_map;
ccs_bool_t map_values;
_ccs_file_descriptor_state_t **ppfd_state;
void *vector;
void *data;
ccs_object_deserialize_callback_t deserialize_callback;
void *deserialize_user_data;
};
typedef struct _ccs_object_deserialize_options_s
_ccs_object_deserialize_options_t;

static inline ccs_result_t
_ccs_deserialize_ccs_object_internal(
_ccs_object_internal_t *obj,
ccs_serialize_format_t format,
uint32_t version,
size_t *buffer_size,
const char **buffer,
_ccs_object_deserialize_options_t *opts,
ccs_object_t *handle_ret)
{
(void)version;
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY: {
CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal(
obj, buffer_size, buffer, handle_ret));
} break;
default:
CCS_RAISE(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
return CCS_RESULT_SUCCESS;
}

static inline ccs_result_t
_ccs_object_handle_check_add(
ccs_map_t map,
Expand All @@ -1268,18 +1347,6 @@ _ccs_object_handle_check_add(
return CCS_RESULT_SUCCESS;
}

struct _ccs_object_deserialize_options_s {
ccs_map_t handle_map;
ccs_bool_t map_values;
_ccs_file_descriptor_state_t **ppfd_state;
void *vector;
void *data;
ccs_object_deserialize_callback_t deserialize_callback;
void *deserialize_user_data;
};
typedef struct _ccs_object_deserialize_options_s
_ccs_object_deserialize_options_t;

static inline ccs_result_t
_ccs_object_serialize_user_data_size(
ccs_object_t object,
Expand Down Expand Up @@ -1407,6 +1474,9 @@ _ccs_object_serialize_size_with_opts(
_ccs_object_serialize_options_t *opts)
{
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;

CCS_VALIDATE(_ccs_serialize_size_ccs_object_internal(
obj, format, cum_size, opts));
CCS_VALIDATE(obj->ops->serialize_size(object, format, cum_size, opts));
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
Expand All @@ -1422,6 +1492,9 @@ _ccs_object_serialize_with_opts(
_ccs_object_serialize_options_t *opts)
{
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;

CCS_VALIDATE(_ccs_serialize_ccs_object_internal(
obj, format, buffer_size, buffer, opts));
CCS_VALIDATE(
obj->ops->serialize(object, format, buffer_size, buffer, opts));
CCS_VALIDATE(_ccs_object_serialize_user_data(
Expand Down
4 changes: 0 additions & 4 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ _ccs_serialize_bin_size_ccs_configuration(
size_t *cum_size,
_ccs_object_serialize_options_t *opts)
{
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)configuration);
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_configuration_data(
configuration->data, cum_size, opts));
return CCS_RESULT_SUCCESS;
Expand All @@ -69,8 +67,6 @@ _ccs_serialize_bin_ccs_configuration(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)configuration, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_configuration_data(
configuration->data, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
Expand Down
5 changes: 0 additions & 5 deletions src/configuration_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ _ccs_serialize_bin_size_ccs_configuration_space(
{
_ccs_configuration_space_data_t *data =
(_ccs_configuration_space_data_t *)(configuration_space->data);
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)configuration_space);
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_configuration_space_data(
data, cum_size, opts));
return CCS_RESULT_SUCCESS;
Expand All @@ -195,9 +193,6 @@ _ccs_serialize_bin_ccs_configuration_space(
{
_ccs_configuration_space_data_t *data =
(_ccs_configuration_space_data_t *)(configuration_space->data);
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)configuration_space, buffer_size,
buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_configuration_space_data(
data, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
Expand Down
4 changes: 0 additions & 4 deletions src/context_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ _ccs_serialize_bin_size_ccs_context(
size_t *cum_size,
_ccs_object_serialize_options_t *opts)
{
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)context);
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_context_data(
context->data, cum_size, opts));
return CCS_RESULT_SUCCESS;
Expand All @@ -323,8 +321,6 @@ _ccs_serialize_bin_ccs_context(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)context, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_context_data(
context->data, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
Expand Down
4 changes: 0 additions & 4 deletions src/distribution_mixture.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ _ccs_serialize_bin_size_ccs_distribution_mixture(
{
_ccs_distribution_mixture_data_t *data =
(_ccs_distribution_mixture_data_t *)(distribution->data);
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)distribution);
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_distribution_mixture_data(
data, cum_size, opts));
return CCS_RESULT_SUCCESS;
Expand All @@ -92,8 +90,6 @@ _ccs_serialize_bin_ccs_distribution_mixture(
{
_ccs_distribution_mixture_data_t *data =
(_ccs_distribution_mixture_data_t *)(distribution->data);
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)distribution, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_mixture_data(
data, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
Expand Down
4 changes: 0 additions & 4 deletions src/distribution_multivariate.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ _ccs_serialize_bin_size_ccs_distribution_multivariate(
{
_ccs_distribution_multivariate_data_t *data =
(_ccs_distribution_multivariate_data_t *)(distribution->data);
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)distribution);
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_distribution_multivariate_data(
data, cum_size, opts));
return CCS_RESULT_SUCCESS;
Expand All @@ -85,8 +83,6 @@ _ccs_serialize_bin_ccs_distribution_multivariate(
{
_ccs_distribution_multivariate_data_t *data =
(_ccs_distribution_multivariate_data_t *)(distribution->data);
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)distribution, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_multivariate_data(
data, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
Expand Down
6 changes: 1 addition & 5 deletions src/distribution_normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ _ccs_serialize_bin_size_ccs_distribution_normal(ccs_distribution_t distribution)
{
_ccs_distribution_normal_data_t *data =
(_ccs_distribution_normal_data_t *)(distribution->data);
return _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)distribution) +
_ccs_serialize_bin_size_ccs_distribution_normal_data(data);
return _ccs_serialize_bin_size_ccs_distribution_normal_data(data);
}

static inline ccs_result_t
Expand All @@ -83,8 +81,6 @@ _ccs_serialize_bin_ccs_distribution_normal(
{
_ccs_distribution_normal_data_t *data =
(_ccs_distribution_normal_data_t *)(distribution->data);
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)distribution, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_normal_data(
data, buffer_size, buffer));
return CCS_RESULT_SUCCESS;
Expand Down
6 changes: 1 addition & 5 deletions src/distribution_roulette.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ _ccs_serialize_bin_size_ccs_distribution_roulette(
{
_ccs_distribution_roulette_data_t *data =
(_ccs_distribution_roulette_data_t *)(distribution->data);
return _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)distribution) +
_ccs_serialize_bin_size_ccs_distribution_roulette_data(data);
return _ccs_serialize_bin_size_ccs_distribution_roulette_data(data);
}

static inline ccs_result_t
Expand All @@ -69,8 +67,6 @@ _ccs_serialize_bin_ccs_distribution_roulette(
{
_ccs_distribution_roulette_data_t *data =
(_ccs_distribution_roulette_data_t *)(distribution->data);
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)distribution, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_roulette_data(
data, buffer_size, buffer));
return CCS_RESULT_SUCCESS;
Expand Down
5 changes: 0 additions & 5 deletions src/distribution_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ _ccs_serialize_bin_size_ccs_distribution_space(
{
_ccs_distribution_space_data_t *data =
(_ccs_distribution_space_data_t *)(distribution_space->data);
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)distribution_space);
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_distribution_space_data(
data, cum_size, opts));
return CCS_RESULT_SUCCESS;
Expand All @@ -101,9 +99,6 @@ _ccs_serialize_bin_ccs_distribution_space(
{
_ccs_distribution_space_data_t *data =
(_ccs_distribution_space_data_t *)(distribution_space->data);
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)distribution_space, buffer_size,
buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_space_data(
data, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
Expand Down
6 changes: 1 addition & 5 deletions src/distribution_uniform.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ _ccs_serialize_bin_size_ccs_distribution_uniform(ccs_distribution_t distribution
{
_ccs_distribution_uniform_data_t *data =
(_ccs_distribution_uniform_data_t *)(distribution->data);
return _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)distribution) +
_ccs_serialize_bin_size_ccs_distribution_uniform_data(data);
return _ccs_serialize_bin_size_ccs_distribution_uniform_data(data);
}

static inline ccs_result_t
Expand All @@ -94,8 +92,6 @@ _ccs_serialize_bin_ccs_distribution_uniform(
{
_ccs_distribution_uniform_data_t *data =
(_ccs_distribution_uniform_data_t *)(distribution->data);
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)distribution, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_uniform_data(
data, buffer_size, buffer));
return CCS_RESULT_SUCCESS;
Expand Down
4 changes: 0 additions & 4 deletions src/evaluation.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ _ccs_serialize_bin_size_ccs_evaluation(
size_t *cum_size,
_ccs_object_serialize_options_t *opts)
{
*cum_size += _ccs_serialize_bin_size_ccs_object_internal(
(_ccs_object_internal_t *)evaluation);
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_evaluation_data(
evaluation->data, cum_size, opts));
return CCS_RESULT_SUCCESS;
Expand All @@ -73,8 +71,6 @@ _ccs_serialize_bin_ccs_evaluation(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal(
(_ccs_object_internal_t *)evaluation, buffer_size, buffer));
CCS_VALIDATE(_ccs_serialize_bin_ccs_evaluation_data(
evaluation->data, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
Expand Down
Loading

0 comments on commit ed997ab

Please sign in to comment.