PHPC-2146: Refactor typemap struct and BSON encoding/decoding of zvals #1369
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHPC-2146
Best reviewed commit by commit. This PR introduces some refactorings that I made while prototyping raw BSON support. No functional changes are introduced as part of this PR. This improves the following:
php_phongo_bson_to_zval
andphp_phongo_bson_to_zval_ex
now take aconst bson_t*
instead ofchar*
andint
. Previously, the function would create a new BSON reader to create abson_t
, which is unnecessary as we start out with abson_t
to begin with.php_phongo_bson_data_to_zval
andphp_phongo_bson_data_to_zval_ex
were added to accept achar*
before passing this on tophp_phongo_bson_to_zval_ex
.php_phongo_bson_typemap
was updated to no longer contain aphp_phongo_bson_typemap_types
andzend_class_entry*
for each type. Instead, a newphp_phongo_bson_typemap_element
struct containing the type and class entry was added. While better structuring data that belongs together, this also makes it easier to add new fields to the type map (in my prototype, I needed to add a potentialzval*
to this struct which would've madephp_phongo_bson_typemap
have even more fields without this refactoring.php_phongo_bson_visit_document
(including handling forenum
on PHP 8.1+) was extracted tophp_phongo_bson_init_document_object
to make the code more concise.php_phongo_bson_visit_document
andphp_phongo_bson_visit_array
were refactored to avoid the duplication of the logic adding the resulting data structure to the parent. This will make it easier to add more options to the type map.php_phongo_bson_visit_array
.