extmod/modbtree: Use buffer protocol for keys/values.

This changes the btree implementation to use the buffer protocol for
reading key/values in all methods.  `str` and `bytes` objects are not the
only bytes-like objects that could be used.

Documentation and tests are also updated.

Addresses issue #8748.

Signed-off-by: David Lechner <david@pybricks.com>
This commit is contained in:
David Lechner
2022-06-10 12:28:56 -05:00
committed by Damien George
parent c118b5d0e4
commit a565811f23
3 changed files with 26 additions and 15 deletions

View File

@@ -11,8 +11,9 @@ value, a database also supports efficient ordered range scans (retrieval
of values with the keys in a given range). On the application interface
side, BTree database work as close a possible to a way standard `dict`
type works, one notable difference is that both keys and values must
be `bytes` objects (so, if you want to store objects of other types, you
need to serialize them to `bytes` first).
be `bytes`-like objects (so, if you want to store objects of other types, you
need to first serialize them to `str` or `bytes` or another type that supports
the buffer protocol).
The module is based on the well-known BerkelyDB library, version 1.xx.