Bounded iterative traversal with preflighted allocation/capacity checks. More...
Functions | |
| JSONBOURNE_API void * | jsonbourne_val_write_opts (const jsonbourne_val *val, void *(*alc_fn)(void *, size_t), void(*free_fn)(void *, void *), void *alc_ctx, size_t *out_len) |
| Validate a DOM and allocate minified JSON output. | |
| JSONBOURNE_API void * | jsonbourne_val_write (const jsonbourne_val *val, size_t *out_len) |
| Allocate minified JSON using malloc. | |
| JSONBOURNE_API void * | jsonbourne_val_write_pretty_opts (const jsonbourne_val *val, const char *indent, const char *newline, void *(*alc_fn)(void *, size_t), void(*free_fn)(void *, void *), void *alc_ctx, size_t *out_len) |
| Validate and allocate pretty output with explicit formatting/ownership. | |
| JSONBOURNE_API void * | jsonbourne_val_write_pretty (const jsonbourne_val *val, const char *indent, const char *newline, size_t *out_len) |
| Allocate pretty JSON using malloc. | |
| JSONBOURNE_API int | jsonbourne_val_write_buf (const jsonbourne_val *val, char *buf, size_t cap, size_t *out_len) |
| Preflight minified output, then write only if the caller buffer fits. | |
| JSONBOURNE_API int | jsonbourne_val_write_pretty_buf (const jsonbourne_val *val, const char *indent, const char *newline, char *buf, size_t cap, size_t *out_len) |
| Preflight pretty output without allocating storage. | |
| JSONBOURNE_API jsonbourne_val * | jsonbourne_val_copy_opts (const jsonbourne_val *val, void *(*alc_fn)(void *, size_t), void *alc_ctx) |
| Deep-copy a validated value into one independent allocation. | |
| JSONBOURNE_API jsonbourne_val * | jsonbourne_val_copy (const jsonbourne_val *val) |
| Make an independently owned deep copy using malloc. | |
Detailed Description
Bounded iterative traversal with preflighted allocation/capacity checks.
Function Documentation
◆ jsonbourne_val_copy()
| JSONBOURNE_API jsonbourne_val * jsonbourne_val_copy | ( | const jsonbourne_val * | val | ) |
Make an independently owned deep copy using malloc.
- Parameters
-
[in] val Accessible source root.
- Returns
- Copy released once with free(), or NULL on failure.
- See also
- jsonbourne_val_copy_opts()
Definition at line 1907 of file jsonbourne.c.
◆ jsonbourne_val_copy_opts()
| JSONBOURNE_API jsonbourne_val * jsonbourne_val_copy_opts | ( | const jsonbourne_val * | val, |
| void *(* | alc_fn )(void *, size_t), | ||
| void * | alc_ctx ) |
Deep-copy a validated value into one independent allocation.
- Parameters
-
[in] val Accessible source DOM; no source storage is borrowed by the copy. [in] alc_fn Optional malloc-aligned allocator; NULL uses malloc. [in] alc_ctx Opaque allocation context.
- Returns
- Owning copy, or NULL for invalid DOM, nesting/size limits or allocation.
- Note
- Source coordinates are deliberately not copied: they describe the original document, not the storage or provenance of the new tree. Custom allocators retain their own release policy, including rejected storage.
Definition at line 1870 of file jsonbourne.c.
◆ jsonbourne_val_write()
| JSONBOURNE_API void * jsonbourne_val_write | ( | const jsonbourne_val * | val, |
| size_t * | out_len ) |
Allocate minified JSON using malloc.
- Parameters
-
[in] val Accessible, stable DOM root. [out] out_len Optional NUL-inclusive output size; zero on failure.
- Returns
- Output released with free(), or NULL on failure.
Definition at line 1640 of file jsonbourne.c.
◆ jsonbourne_val_write_buf()
| JSONBOURNE_API int jsonbourne_val_write_buf | ( | const jsonbourne_val * | val, |
| char * | buf, | ||
| size_t | cap, | ||
| size_t * | out_len ) |
Preflight minified output, then write only if the caller buffer fits.
- Parameters
-
[in] val Accessible DOM disjoint from the output buffer. [out] buf Destination; NULL measures without writing. [in] cap Destination capacity in bytes, including room for NUL. [out] out_len Optional required NUL-inclusive size; zero for an invalid DOM.
- Return values
-
1 Complete output, including NUL, was written. 0 Validation failed or storage is absent/insufficient.
- Note
- A valid size probe returns 0 with the required length. Insufficient storage stays untouched because traversal is measured before the first write.
Preflight before writing; insufficient buffers are left untouched.
Definition at line 1690 of file jsonbourne.c.
◆ jsonbourne_val_write_opts()
| JSONBOURNE_API void * jsonbourne_val_write_opts | ( | const jsonbourne_val * | val, |
| void *(* | alc_fn )(void *, size_t), | ||
| void(* | free_fn )(void *, void *), | ||
| void * | alc_ctx, | ||
| size_t * | out_len ) |
Validate a DOM and allocate minified JSON output.
- Parameters
-
[in] val Accessible root; must remain stable through both passes. [in] alc_fn Optional output allocator; NULL uses malloc. [in] free_fn Optional matching failure-release callback. If absent, failed output allocations are released with free(). [in] alc_ctx Opaque context passed to allocation/release callbacks. [out] out_len Optional output bytes INCLUDING NUL; zero on failure.
- Returns
- NUL-terminated output, or NULL for invalid DOM, limits or allocation.
- Note
- Successful output belongs to the caller and is never released here. Custom storage must be free-compatible unless free_fn supplies its release.
Definition at line 1635 of file jsonbourne.c.
◆ jsonbourne_val_write_pretty()
| JSONBOURNE_API void * jsonbourne_val_write_pretty | ( | const jsonbourne_val * | val, |
| const char * | indent, | ||
| const char * | newline, | ||
| size_t * | out_len ) |
Allocate pretty JSON using malloc.
- Parameters
-
[in] val Accessible, stable DOM root. [in] indent JSON whitespace; NULL selects two spaces. [in] newline JSON whitespace; NULL selects LF. [out] out_len Optional NUL-inclusive size; zero on failure.
- Returns
- Output released with free(), or NULL on failure.
Definition at line 1651 of file jsonbourne.c.
◆ jsonbourne_val_write_pretty_buf()
| JSONBOURNE_API int jsonbourne_val_write_pretty_buf | ( | const jsonbourne_val * | val, |
| const char * | indent, | ||
| const char * | newline, | ||
| char * | buf, | ||
| size_t | cap, | ||
| size_t * | out_len ) |
Preflight pretty output without allocating storage.
- Parameters
-
[in] val Accessible DOM, stable and disjoint from buf. [in] indent JSON whitespace; NULL selects two spaces. [in] newline JSON whitespace; NULL selects LF. [out] buf Output destination; NULL probes the required size. [in] cap Destination extent including terminator space. [out] out_len Optional required NUL-inclusive size; zero on validation failure.
- Return values
-
1 Complete pretty output was written. 0 Invalid input/formatting or absent/insufficient storage.
- See also
- jsonbourne_val_write_buf() for size-probe and untouched-buffer behavior.
Definition at line 1694 of file jsonbourne.c.
◆ jsonbourne_val_write_pretty_opts()
| JSONBOURNE_API void * jsonbourne_val_write_pretty_opts | ( | const jsonbourne_val * | val, |
| const char * | indent, | ||
| const char * | newline, | ||
| void *(* | alc_fn )(void *, size_t), | ||
| void(* | free_fn )(void *, void *), | ||
| void * | alc_ctx, | ||
| size_t * | out_len ) |
Validate and allocate pretty output with explicit formatting/ownership.
- Parameters
-
[in] val Accessible DOM root, stable throughout both passes. [in] indent NUL-terminated JSON whitespace; NULL selects two spaces. [in] newline NUL-terminated JSON whitespace; NULL selects LF. [in] alc_fn Optional output allocator; NULL uses malloc. [in] free_fn Optional failure-release callback; NULL falls back to free(). [in] alc_ctx Opaque allocation/release context. [out] out_len Optional NUL-inclusive size; zero on failure.
- Returns
- Caller-owned output, or NULL on failure.
- Note
- Restricting formatting to JSON whitespace keeps pretty output valid JSON.
- See also
- jsonbourne_val_write_opts() for custom allocation release rules.
Definition at line 1644 of file jsonbourne.c.