---
name: "bson_new_from_buffer"
section: "3"
platform: "linux"
package: "libbson-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/bson_new_from_buffer"
---

# bson\_new\_from\_buffer(3)

## SYNOPSIS

```
bson_t *
bson_new_from_buffer (uint8_t **buf,
                      size_t *buf_len,
                      bson_realloc_func realloc_func,
                      void *realloc_func_ctx);
```

## PARAMETERS

- •

  **buf**: An out-pointer to a buffer containing a serialized BSON document, or to NULL.

- •

  **buf\_len**: An out-pointer to the length of the buffer in bytes.

- •

  **realloc\_func**: Optional *bson\_realloc\_func* for reallocating the buffer.

- •

  **realloc\_func\_ctx**: Optional pointer that will be passed as **ctx** to **realloc\_func**.

## DESCRIPTION

Creates a new *bson\_t* using the data provided.

The **realloc\_func**, if provided, is called to resize **buf** if the document is later expanded, for example by a call to one of the **bson\_append** functions.

If **\*buf** is initially NULL then it is allocated, using **realloc\_func** or the default allocator, and initialized with an empty BSON document, and **\*buf\_len** is set to 5, the size of an empty document.

## RETURNS

A newly-allocated *bson\_t* on success, or NULL.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
