Skip to content

Commit

Permalink
Factor object user data serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed May 20, 2024
1 parent 2582691 commit a6a9cff
Show file tree
Hide file tree
Showing 25 changed files with 24 additions and 124 deletions.
8 changes: 6 additions & 2 deletions src/cconfigspace_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1403,12 +1403,14 @@ static inline ccs_result_t
_ccs_object_serialize_size_with_opts(
ccs_object_t object,
ccs_serialize_format_t format,
size_t *buffer_size,
size_t *cum_size,
_ccs_object_serialize_options_t *opts)
{
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;
CCS_VALIDATE(
obj->ops->serialize_size(object, format, buffer_size, opts));
obj->ops->serialize_size(object, format, cum_size, opts));
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -1423,6 +1425,8 @@ _ccs_object_serialize_with_opts(
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;
CCS_VALIDATE(
obj->ops->serialize(object, format, buffer_size, buffer, opts));
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
4 changes: 0 additions & 4 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ _ccs_configuration_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -117,8 +115,6 @@ _ccs_configuration_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
4 changes: 0 additions & 4 deletions src/configuration_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ _ccs_configuration_space_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -244,8 +242,6 @@ _ccs_configuration_space_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, 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 @@ -116,8 +116,6 @@ _ccs_distribution_mixture_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -139,8 +137,6 @@ _ccs_distribution_mixture_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, 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 @@ -110,8 +110,6 @@ _ccs_distribution_multivariate_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -133,8 +131,6 @@ _ccs_distribution_multivariate_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
6 changes: 2 additions & 4 deletions src/distribution_normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ _ccs_distribution_normal_serialize_size(
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_distribution_normal(
Expand All @@ -107,8 +108,6 @@ _ccs_distribution_normal_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -120,6 +119,7 @@ _ccs_distribution_normal_serialize(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY:
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_normal(
Expand All @@ -130,8 +130,6 @@ _ccs_distribution_normal_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
6 changes: 2 additions & 4 deletions src/distribution_roulette.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ _ccs_distribution_roulette_serialize_size(
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_distribution_roulette(
Expand All @@ -93,8 +94,6 @@ _ccs_distribution_roulette_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -106,6 +105,7 @@ _ccs_distribution_roulette_serialize(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY:
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_roulette(
Expand All @@ -116,8 +116,6 @@ _ccs_distribution_roulette_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
10 changes: 0 additions & 10 deletions src/distribution_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ _ccs_distribution_space_serialize_size(
err, CCS_RESULT_ERROR_INVALID_VALUE, end,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE_ERR_GOTO(
err,
_ccs_object_serialize_user_data_size(
object, format, cum_size, opts),
end);
end:
CCS_OBJ_UNLOCK(object);
return err;
Expand Down Expand Up @@ -166,11 +161,6 @@ _ccs_distribution_space_serialize(
err, CCS_RESULT_ERROR_INVALID_VALUE, end,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE_ERR_GOTO(
err,
_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts),
end);
end:
CCS_OBJ_UNLOCK(object);
return err;
Expand Down
6 changes: 2 additions & 4 deletions src/distribution_uniform.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ _ccs_distribution_uniform_serialize_size(
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_distribution_uniform(
Expand All @@ -118,8 +119,6 @@ _ccs_distribution_uniform_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -131,6 +130,7 @@ _ccs_distribution_uniform_serialize(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY:
CCS_VALIDATE(_ccs_serialize_bin_ccs_distribution_uniform(
Expand All @@ -141,8 +141,6 @@ _ccs_distribution_uniform_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
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 @@ -97,8 +97,6 @@ _ccs_evaluation_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -120,8 +118,6 @@ _ccs_evaluation_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
12 changes: 0 additions & 12 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ _ccs_expression_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -204,8 +202,6 @@ _ccs_expression_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -1128,8 +1124,6 @@ _ccs_expression_literal_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -1151,8 +1145,6 @@ _ccs_expression_literal_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -1257,8 +1249,6 @@ _ccs_expression_variable_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -1280,8 +1270,6 @@ _ccs_expression_variable_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
4 changes: 0 additions & 4 deletions src/feature_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ _ccs_feature_space_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -62,8 +60,6 @@ _ccs_feature_space_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
6 changes: 2 additions & 4 deletions src/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _ccs_features_serialize_size(
size_t *cum_size,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY:
CCS_VALIDATE(_ccs_serialize_bin_size_ccs_binding(
Expand All @@ -30,8 +31,6 @@ _ccs_features_serialize_size(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data_size(
object, format, cum_size, opts));
return CCS_RESULT_SUCCESS;
}

Expand All @@ -43,6 +42,7 @@ _ccs_features_serialize(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY:
CCS_VALIDATE(_ccs_serialize_bin_ccs_binding(
Expand All @@ -53,8 +53,6 @@ _ccs_features_serialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
12 changes: 2 additions & 10 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ _ccs_map_serialize_size(
size_t *cum_size,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
ccs_result_t err = CCS_RESULT_SUCCESS;
CCS_OBJ_RDLOCK(object);
switch (format) {
Expand All @@ -117,11 +118,6 @@ _ccs_map_serialize_size(
err, CCS_RESULT_ERROR_INVALID_VALUE, end,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE_ERR_GOTO(
err,
_ccs_object_serialize_user_data_size(
object, format, cum_size, opts),
end);
end:
CCS_OBJ_UNLOCK(object);
return err;
Expand All @@ -135,6 +131,7 @@ _ccs_map_serialize(
char **buffer,
_ccs_object_serialize_options_t *opts)
{
(void)opts;
ccs_result_t err = CCS_RESULT_SUCCESS;
CCS_OBJ_RDLOCK(object);
switch (format) {
Expand All @@ -150,11 +147,6 @@ _ccs_map_serialize(
err, CCS_RESULT_ERROR_INVALID_VALUE, end,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE_ERR_GOTO(
err,
_ccs_object_serialize_user_data(
object, format, buffer_size, buffer, opts),
end);
end:
CCS_OBJ_UNLOCK(object);
return err;
Expand Down
Loading

0 comments on commit a6a9cff

Please sign in to comment.