<commit_before>/*
 * Copyright 2014-2017 MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PHONGO_BSON_H
#define PHONGO_BSON_H

#include <bson.h>

/* PHP Core stuff */
#include <php.h>

#define BSON_UNSERIALIZE_FUNC_NAME    "bsonUnserialize"
#define BSON_SERIALIZE_FUNC_NAME      "bsonSerialize"

#define PHONGO_ODM_FIELD_NAME "__pclass"

typedef enum {
	PHONGO_BSON_NONE      = 0x00,
	PHONGO_BSON_ADD_ID    = 0x01,
	PHONGO_BSON_RETURN_ID = 0x02
} php_phongo_bson_flags_t;

typedef enum {
	PHONGO_TYPEMAP_NONE,
	PHONGO_TYPEMAP_NATIVE_ARRAY,
	PHONGO_TYPEMAP_NATIVE_OBJECT,
	PHONGO_TYPEMAP_CLASS
} php_phongo_bson_typemap_types;

typedef struct {
	php_phongo_bson_typemap_types  document_type;
	zend_class_entry              *document;
	php_phongo_bson_typemap_types  array_type;
	zend_class_entry              *array;
	php_phongo_bson_typemap_types  root_type;
	zend_class_entry              *root;
	zend_class_entry              *binary;
	zend_class_entry              *decimal128;
	zend_class_entry              *javascript;
	zend_class_entry              *maxkey;
	zend_class_entry              *minkey;
	zend_class_entry              *objectid;
	zend_class_entry              *regex;
	zend_class_entry              *timestamp;
	zend_class_entry              *utcdatetime;
} php_phongo_bson_typemap;

typedef struct {
#if PHP_VERSION_ID >= 70000
	zval                     zchild;
#else
	zval                    *zchild;
#endif
	php_phongo_bson_typemap  map;
	zend_class_entry        *odm;
	bool                     is_visiting_array;
} php_phongo_bson_state;

#if PHP_VERSION_ID >= 70000
#define PHONGO_BSON_STATE_INITIALIZER  { {{ 0 }}, { PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL}, NULL, 0 }
#else
#define PHONGO_BSON_STATE_INITIALIZER  { NULL, { PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL}, NULL, 0 }
#endif

void php_phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson, bson_t **bson_out TSRMLS_DC);
int php_phongo_bson_to_zval_ex(const unsigned char *data, int data_len, php_phongo_bson_state *state);
#if PHP_VERSION_ID >= 70000
int php_phongo_bson_to_zval(const unsigned char *data, int data_len, zval *out);
#else
int php_phongo_bson_to_zval(const unsigned char *data, int data_len, zval **out);
#endif
bool php_phongo_bson_typemap_to_state(zval *typemap, php_phongo_bson_typemap *map TSRMLS_DC);

PHP_FUNCTION(MongoDB_BSON_toPHP);
PHP_FUNCTION(MongoDB_BSON_fromPHP);
PHP_FUNCTION(MongoDB_BSON_toJSON);
PHP_FUNCTION(MongoDB_BSON_toExtendedJSON);
PHP_FUNCTION(MongoDB_BSON_fromJSON);

#endif	/* PHONGO_BSON_H */
<commit_msg>PHPC-640: Specify TypeWrapper class entries in PHONGO_BSON_STATE_INITIALIZER<commit_after>/*
 * Copyright 2014-2017 MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PHONGO_BSON_H
#define PHONGO_BSON_H

#include <bson.h>

/* PHP Core stuff */
#include <php.h>

#define BSON_UNSERIALIZE_FUNC_NAME    "bsonUnserialize"
#define BSON_SERIALIZE_FUNC_NAME      "bsonSerialize"

#define PHONGO_ODM_FIELD_NAME "__pclass"

typedef enum {
	PHONGO_BSON_NONE      = 0x00,
	PHONGO_BSON_ADD_ID    = 0x01,
	PHONGO_BSON_RETURN_ID = 0x02
} php_phongo_bson_flags_t;

typedef enum {
	PHONGO_TYPEMAP_NONE,
	PHONGO_TYPEMAP_NATIVE_ARRAY,
	PHONGO_TYPEMAP_NATIVE_OBJECT,
	PHONGO_TYPEMAP_CLASS
} php_phongo_bson_typemap_types;

typedef struct {
	php_phongo_bson_typemap_types  document_type;
	zend_class_entry              *document;
	php_phongo_bson_typemap_types  array_type;
	zend_class_entry              *array;
	php_phongo_bson_typemap_types  root_type;
	zend_class_entry              *root;
	zend_class_entry              *binary;
	zend_class_entry              *decimal128;
	zend_class_entry              *javascript;
	zend_class_entry              *maxkey;
	zend_class_entry              *minkey;
	zend_class_entry              *objectid;
	zend_class_entry              *regex;
	zend_class_entry              *timestamp;
	zend_class_entry              *utcdatetime;
} php_phongo_bson_typemap;

typedef struct {
#if PHP_VERSION_ID >= 70000
	zval                     zchild;
#else
	zval                    *zchild;
#endif
	php_phongo_bson_typemap  map;
	zend_class_entry        *odm;
	bool                     is_visiting_array;
} php_phongo_bson_state;

#if PHP_VERSION_ID >= 70000
#define PHONGO_BSON_STATE_INITIALIZER  { {{ 0 }}, { PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, NULL, 0 }
#else
#define PHONGO_BSON_STATE_INITIALIZER  { NULL, { PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, NULL, 0 }
#endif

void php_phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson, bson_t **bson_out TSRMLS_DC);
int php_phongo_bson_to_zval_ex(const unsigned char *data, int data_len, php_phongo_bson_state *state);
#if PHP_VERSION_ID >= 70000
int php_phongo_bson_to_zval(const unsigned char *data, int data_len, zval *out);
#else
int php_phongo_bson_to_zval(const unsigned char *data, int data_len, zval **out);
#endif
bool php_phongo_bson_typemap_to_state(zval *typemap, php_phongo_bson_typemap *map TSRMLS_DC);

PHP_FUNCTION(MongoDB_BSON_toPHP);
PHP_FUNCTION(MongoDB_BSON_fromPHP);
PHP_FUNCTION(MongoDB_BSON_toJSON);
PHP_FUNCTION(MongoDB_BSON_toExtendedJSON);
PHP_FUNCTION(MongoDB_BSON_fromJSON);

#endif	/* PHONGO_BSON_H */

{'fraction_non_alphanumeric': 0.07288943564508689, 'fraction_numerical': 0.013378440719667846, 'mean_word_length': 4.178343949044586, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '41974', 'n_tokens_mistral': 2527, 'n_tokens_neox': 2448, 'n_words': 528}