Skip to content

Commit

Permalink
Factor user data serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed May 20, 2024
1 parent 6dc003a commit 2582691
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 101 deletions.
19 changes: 15 additions & 4 deletions src/cconfigspace_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ _ccs_object_deserialize_with_opts_check(
&otype, buffer_size, buffer));
CCS_REFUTE(
otype != expected_type, CCS_RESULT_ERROR_INVALID_TYPE);
CCS_VALIDATE(_ccs_object_deserialize_with_opts_type(
object_ret, expected_type, format, version, buffer_size,
buffer, opts));
CCS_VALIDATE(_ccs_object_deserialize_with_opts(
object_ret, format, version, buffer_size, buffer,
opts));
} break;
default:
CCS_RAISE(
Expand All @@ -222,21 +222,32 @@ _ccs_object_deserialize_with_opts(
const char **buffer,
_ccs_object_deserialize_options_t *opts)
{
ccs_result_t err = CCS_RESULT_SUCCESS;
ccs_object_t obj;
switch (format) {
case CCS_SERIALIZE_FORMAT_BINARY: {
ccs_object_type_t otype;
CCS_VALIDATE(_ccs_peek_bin_ccs_object_type(
&otype, buffer_size, buffer));
CCS_VALIDATE(_ccs_object_deserialize_with_opts_type(
object_ret, otype, format, version, buffer_size, buffer,
&obj, otype, format, version, buffer_size, buffer,
opts));
} break;
default:
CCS_RAISE(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE_ERR_GOTO(
err,
_ccs_object_deserialize_user_data(
obj, format, version, buffer_size, buffer, opts),
errobj);
*object_ret = obj;
return CCS_RESULT_SUCCESS;
errobj:
ccs_release_object(obj);
return err;
}

#endif //_CCONFIG_SPACE_SPACE_DESERIALIZE_H
3 changes: 0 additions & 3 deletions src/configuration_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ _ccs_configuration_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*configuration_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/configuration_space_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ _ccs_configuration_space_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*configuration_space_ret, format, version,
buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
5 changes: 3 additions & 2 deletions src/context_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ _ccs_deserialize_bin_ccs_context_data(
data->num_parameters, sizeof(ccs_parameter_t));
CCS_REFUTE(!data->parameters, CCS_RESULT_ERROR_OUT_OF_MEMORY);
for (size_t i = 0; i < data->num_parameters; i++)
CCS_VALIDATE(_ccs_parameter_deserialize(
data->parameters + i,
CCS_VALIDATE(_ccs_object_deserialize_with_opts_check(
(ccs_object_t *)data->parameters + i,
CCS_OBJECT_TYPE_PARAMETER,
CCS_SERIALIZE_FORMAT_BINARY, version,
buffer_size, buffer, opts));
}
Expand Down
28 changes: 10 additions & 18 deletions src/distribution_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,6 @@ _ccs_deserialize_bin_distribution_roulette(
return res;
}

static inline ccs_result_t
_ccs_distribution_deserialize(
ccs_distribution_t *distribution_ret,
ccs_serialize_format_t format,
uint32_t version,
size_t *buffer_size,
const char **buffer,
_ccs_object_deserialize_options_t *opts);

struct _ccs_distribution_mixture_data_mock_s {
_ccs_distribution_common_data_t common_data;
size_t num_distributions;
Expand Down Expand Up @@ -208,9 +199,11 @@ _ccs_deserialize_bin_ccs_distribution_mixture_data(
for (size_t i = 0; i < data->num_distributions; i++) {
CCS_VALIDATE(_ccs_deserialize_bin_ccs_float(
data->weights + i, buffer_size, buffer));
CCS_VALIDATE(_ccs_distribution_deserialize(
data->distributions + i, CCS_SERIALIZE_FORMAT_BINARY,
version, buffer_size, buffer, &new_opts));
CCS_VALIDATE(_ccs_object_deserialize_with_opts_check(
(ccs_object_t *)data->distributions + i,
CCS_OBJECT_TYPE_DISTRIBUTION,
CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size,
buffer, &new_opts));
}
return CCS_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -276,9 +269,11 @@ _ccs_deserialize_bin_ccs_distribution_multivariate_data(
data->num_distributions, sizeof(ccs_distribution_t));
CCS_REFUTE(!data->distributions, CCS_RESULT_ERROR_OUT_OF_MEMORY);
for (size_t i = 0; i < data->num_distributions; i++)
CCS_VALIDATE(_ccs_distribution_deserialize(
data->distributions + i, CCS_SERIALIZE_FORMAT_BINARY,
version, buffer_size, buffer, &new_opts));
CCS_VALIDATE(_ccs_object_deserialize_with_opts_check(
(ccs_object_t *)data->distributions + i,
CCS_OBJECT_TYPE_DISTRIBUTION,
CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size,
buffer, &new_opts));
return CCS_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -394,9 +389,6 @@ _ccs_distribution_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*distribution_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/distribution_space_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ _ccs_distribution_space_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*distribution_space_ret, format, version,
buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/evaluation_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ _ccs_evaluation_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*evaluation_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
26 changes: 4 additions & 22 deletions src/expression_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ struct _ccs_expression_data_mock_s {
};
typedef struct _ccs_expression_data_mock_s _ccs_expression_data_mock_t;

static inline ccs_result_t
_ccs_deserialize_bin_expression(
ccs_expression_t *expression_ret,
uint32_t version,
size_t *buffer_size,
const char **buffer,
_ccs_object_deserialize_options_t *opts);

static ccs_result_t
_ccs_expression_deserialize(
ccs_expression_t *expression_ret,
ccs_serialize_format_t format,
uint32_t version,
size_t *buffer_size,
const char **buffer,
_ccs_object_deserialize_options_t *opts);

static inline ccs_result_t
_ccs_deserialize_bin_ccs_expression_data(
_ccs_expression_data_mock_t *data,
Expand All @@ -46,8 +29,10 @@ _ccs_deserialize_bin_ccs_expression_data(
CCS_REFUTE(!data->nodes, CCS_RESULT_ERROR_OUT_OF_MEMORY);
for (size_t i = 0; i < data->num_nodes; i++) {
ccs_expression_t expr;
CCS_VALIDATE(_ccs_expression_deserialize(
&expr, CCS_SERIALIZE_FORMAT_BINARY, version,
CCS_VALIDATE(_ccs_object_deserialize_with_opts_check(
(ccs_object_t *)&expr,
CCS_OBJECT_TYPE_EXPRESSION,
CCS_SERIALIZE_FORMAT_BINARY, version,
buffer_size, buffer, opts));
data->nodes[i].type = CCS_DATA_TYPE_OBJECT;
data->nodes[i].value.o = expr;
Expand Down Expand Up @@ -241,9 +226,6 @@ _ccs_expression_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*expression_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/feature_space_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ _ccs_feature_space_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*feature_space_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/features_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ _ccs_features_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*features_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/map_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ _ccs_map_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*map_ret, format, version, buffer_size, buffer,
opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/objective_space_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ _ccs_objective_space_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*objective_space_ret, format, version,
buffer_size, buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/parameter_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ _ccs_parameter_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*parameter_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/rng_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ _ccs_rng_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*rng_ret, format, version, buffer_size, buffer,
opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/tree_configuration_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ _ccs_tree_configuration_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*configuration_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
24 changes: 8 additions & 16 deletions src/tree_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ struct _ccs_tree_data_mock_s {
};
typedef struct _ccs_tree_data_mock_s _ccs_tree_data_mock_t;

static inline ccs_result_t
_ccs_tree_deserialize(
ccs_tree_t *tree_ret,
ccs_serialize_format_t format,
uint32_t version,
size_t *buffer_size,
const char **buffer,
_ccs_object_deserialize_options_t *opts);

static inline ccs_result_t
_ccs_deserialize_bin_ccs_tree_data(
_ccs_tree_data_mock_t *data,
Expand All @@ -45,10 +36,14 @@ _ccs_deserialize_bin_ccs_tree_data(
CCS_VALIDATE(_ccs_deserialize_bin_ccs_bool(
&present, buffer_size, buffer));
if (present)
CCS_VALIDATE(_ccs_tree_deserialize(
data->children + i,
CCS_SERIALIZE_FORMAT_BINARY, version,
buffer_size, buffer, &new_opts));
CCS_VALIDATE(
_ccs_object_deserialize_with_opts_check(
(ccs_object_t *)data->children +
i,
CCS_OBJECT_TYPE_TREE,
CCS_SERIALIZE_FORMAT_BINARY,
version, buffer_size, buffer,
&new_opts));
}
}
CCS_VALIDATE(_ccs_deserialize_bin_ccs_float(
Expand Down Expand Up @@ -135,9 +130,6 @@ _ccs_tree_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*tree_ret, format, version, buffer_size, buffer,
opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/tree_space_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ _ccs_tree_space_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*tree_space_ret, format, version, buffer_size,
buffer, opts));
return CCS_RESULT_SUCCESS;
}

Expand Down
3 changes: 0 additions & 3 deletions src/tuner_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ _ccs_tuner_deserialize(
CCS_RESULT_ERROR_INVALID_VALUE,
"Unsupported serialization format: %d", format);
}
CCS_VALIDATE(_ccs_object_deserialize_user_data(
(ccs_object_t)*tuner_ret, format, version, buffer_size, buffer,
opts));
return CCS_RESULT_SUCCESS;
}

Expand Down

0 comments on commit 2582691

Please sign in to comment.