Skip to content

Commit d94c391

Browse files
committed
Update documentation
1 parent a90756f commit d94c391

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

php_simdjson.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ PHP_FUNCTION (simdjson_is_valid) {
129129
ZVAL_BOOL(return_value, is_json);
130130
}
131131

132+
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_parse_default(const char *json, size_t len, zval *return_value, bool associative, size_t depth) {
133+
return php_simdjson_parse(simdjson_get_parser(), json, len, return_value, associative, depth);
134+
}
135+
132136
PHP_FUNCTION (simdjson_decode) {
133137
zend_bool associative = 0;
134138
zend_long depth = SIMDJSON_PARSE_DEFAULT_DEPTH;

php_simdjson.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ typedef uint8_t simdjson_php_error_code;
116116
/* NOTE: Callers should check if len is greater than 4GB - simdjson will always return a non zero error code for those */
117117

118118
/* FIXME add php_simdjson_get_default_singleton_parser api */
119-
/* FIXME add php_simdjson_decode_with_default_singleton_parser(return_value, json, len, bool assoc) */
119+
/* FIXME add php_simdjson_decode_with_default_singleton_parser(return_value, json, len, bool associative) */
120120

121121
/**
122122
* Returns the error message corresponding to a given error code returned by a call to simdjson_php.
@@ -133,6 +133,8 @@ PHP_SIMDJSON_API void php_simdjson_throw_jsonexception(simdjson_php_error_code c
133133
*
134134
* Callers may use this instead of the shared singleton parser when memory usage is a concern
135135
* (e.g. the PECLs are likely to be used load a string that's megabytes long in a long-lived php process)
136+
*
137+
* Callers should free this parser before or during the request shutdown phase.
136138
*/
137139
PHP_SIMDJSON_API struct simdjson_php_parser* php_simdjson_create_parser(void);
138140
/**
@@ -143,13 +145,20 @@ PHP_SIMDJSON_API void php_simdjson_free_parser(struct simdjson_php_parser* parse
143145
* Returns true if the given json string is valid
144146
*/
145147
PHP_SIMDJSON_API bool php_simdjson_is_valid(struct simdjson_php_parser* parser, const char *json, size_t len, size_t depth);
148+
/**
149+
* Parses the given string into a return code, using the default singleton parser.
150+
*
151+
* This must be called after simdjson's request initialization phase and before simdjson's request shutdown phase.
152+
* (e.g. PECLs should not use this during module or request initialization/shutdown)
153+
*/
154+
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_parse_default(const char *json, size_t len, zval *return_value, bool associative, size_t depth);
146155
/**
147156
* Parses the given string into a return code.
148157
*
149158
* If the returned error code is 0, then return_value contains the parsed value.
150159
* If the returned error code is non-0, then return_value will not be initialized.
151160
*/
152-
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_parse(struct simdjson_php_parser* parser, const char *json, size_t len, zval *return_value, bool assoc, size_t depth);
161+
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_parse(struct simdjson_php_parser* parser, const char *json, size_t len, zval *return_value, bool associative, size_t depth);
153162
/**
154163
* Parses the part of the given string at the json pointer 'key' into a PHP value at return_value
155164
*
@@ -161,7 +170,7 @@ PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_parse(struct simdjson_php_
161170
*
162171
* @see https://www.rfc-editor.org/rfc/rfc6901.html
163172
*/
164-
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_key_value(struct simdjson_php_parser* parser, const char *json, size_t len, const char *key, zval *return_value, bool assoc, size_t depth);
173+
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_key_value(struct simdjson_php_parser* parser, const char *json, size_t len, const char *key, zval *return_value, bool associative, size_t depth);
165174
/**
166175
* Checks if the json pointer 'key' exists in the given json string.
167176
*

src/simdjson_bindings.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,27 +349,27 @@ PHP_SIMDJSON_API bool php_simdjson_is_valid(simdjson_php_parser* parser, const c
349349

350350
/* }}} */
351351

352-
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_parse(simdjson_php_parser* parser, const char *json, size_t len, zval *return_value, bool assoc, size_t depth) /* {{{ */ {
352+
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_parse(simdjson_php_parser* parser, const char *json, size_t len, zval *return_value, bool associative, size_t depth) /* {{{ */ {
353353
simdjson::dom::element doc;
354354
simdjson::error_code error = build_parsed_json_cust(parser, doc, json, len, true, depth);
355355
if (error) {
356356
return error;
357357
}
358358

359-
if (assoc) {
359+
if (associative) {
360360
return create_array(doc, return_value);
361361
} else {
362362
return create_object(doc, return_value);
363363
}
364364
}
365365
/* }}} */
366-
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_key_value(simdjson_php_parser* parser, const char *json, size_t len, const char *key, zval *return_value, bool assoc,
366+
PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_key_value(simdjson_php_parser* parser, const char *json, size_t len, const char *key, zval *return_value, bool associative,
367367
size_t depth) /* {{{ */ {
368368
simdjson::dom::element doc;
369369
simdjson::dom::element element;
370370
SIMDJSON_TRY(build_parsed_json_cust(parser, doc, json, len, true, depth));
371371
SIMDJSON_TRY(get_key_with_optional_prefix(doc, key).get(element));
372-
if (assoc) {
372+
if (associative) {
373373
return create_array(element, return_value);
374374
} else {
375375
return create_object(element, return_value);

0 commit comments

Comments
 (0)