---
name: "mtbl_source"
section: "3"
platform: "linux"
package: "libmtbl-dev"
version: "1.6.1-1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mtbl_source"
---

# mtbl\_source(3)

obtain key-value entries from a data source

## NAME

mtbl\_source - obtain key-value entries from a data source

## SYNOPSIS

**#include \<mtbl.h\>**

```
struct mtbl_iter *
mtbl_source_iter(const struct mtbl_source *s);
```

```
struct mtbl_iter *
mtbl_source_get(const struct mtbl_source *s, const uint8_t *key, size_t len_key);
```

```
struct mtbl_iter *
mtbl_source_get_prefix(
        const struct mtbl_source *s,
        const uint8_t *prefix, size_t len_prefix);
```

```
struct mtbl_iter *
mtbl_source_get_range(
        const struct mtbl_source *s,
        const uint8_t *key0, size_t len_key0,
        const uint8_t *key1, size_t len_key1);
```

```
mtbl_res
mtbl_source_write(const struct mtbl_source *s, struct mtbl_writer *w);
```

```
void
mtbl_source_destroy(struct mtbl_source **s);
```

## DESCRIPTION

The **mtbl\_source** interface provides an abstraction for reading key-value entries from mtbl data sources.

**mtbl\_source\_iter**() provides an iterator over all of the entries in the data source.

**mtbl\_source\_get**() provides an exact match iterator which returns all entries whose key matches the key provided in the arguments *key* and *len\_key*.

**mtbl\_source\_get\_prefix**() provides a prefix iterator which returns all entries whose keys start with *prefix* and are at least *len\_prefix* bytes long.

**mtbl\_source\_get\_range**() provides a range iterator which returns all entries whose keys are between *key0* and *key1* inclusive.

**mtbl\_source\_write**() is a convenience function for reading all of the entries from a source and writing them to an **mtbl\_writer** object. It is equivalent to calling **mtbl\_writer\_add**() on all of the entries returned from **mtbl\_source\_iter**().

## RETURN VALUE

**mtbl\_source\_iter**(), **mtbl\_source\_get**(), **mtbl\_source\_get\_prefix**(), and **mtbl\_source\_get\_range**() return **mtbl\_iter** objects.

**mtbl\_source\_write**() returns **mtbl\_res\_success** if all of the entries in the data source were successfully written to the **mtbl\_writer** argument, and **mtbl\_res\_failure** otherwise.

## SEE ALSO

[**mtbl\_iter**(3)](/mtbl_iter/3.md)
