---
name: "bson_iter_init_from_data_at_offset"
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_iter_init_from_data_at_offset"
---

# bson\_iter\_init\_from\_data\_at\_offset(3)

## SYNOPSIS

```
bool
bson_iter_init_from_data_at_offset (bson_iter_t *iter,
                                    const uint8_t *data,
                                    size_t length,
                                    uint32_t offset,
                                    uint32_t keylen);
```

## PARAMETERS

- •

  **iter**: A *bson\_iter\_t*.

- •

  **data**: A buffer to initialize with. This is not validated.

- •

  **length**: The length of **data** in bytes. This is not validated.

- •

  **offset**: The offset of the field to start iterating. This is not validated. This should be an offset previously obtained from *bson\_iter\_offset()*.

- •

  **keylen**: The string length of the key of the field to start iterating. This is not validated. This should be a length previously obtained from *bson\_iter\_key\_len()*.

## DESCRIPTION

Creates a *bson\_iter\_t* and starts iteration on a field at the offset.

*bson\_iter\_init\_from\_data\_at\_offset()* is useful for situations where the progress of a *bson\_iter\_t* must be saved and restored without relying on the *bson\_iter\_t* data layout. Saving the progress could be accomplished by:

- •

  Saving the current field's key length with *bson\_iter\_key\_len()*

- •

  Saving the current offset with *bson\_iter\_offset()*

- •

  Saving the data pointer of the iterated *bson\_t* with *bson\_get\_data()*

- •

  Saving the data length of the iterated *bson\_t* with the **len** struct field

Then later, these saved values can be passed to *bson\_iter\_init\_from\_data\_at\_offset()* to reconstruct the *bson\_iter\_t* in constant time.

## RETURNS

Returns true if the iter was successfully initialized.

**SEE ALSO:**

```
bson_iter_key_len()
```

```
bson_iter_offset()
```

```
bson_get_data()
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
