nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 6ec38ab47fa3786fb29e22eb66364419b6f0288f
parent 8ab40779e4e1895033597c00fc88ae40cd07f9b2
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 27 Dec 2023 12:40:50 -0800

cursor: add pull_varint_u32

This is a varint helper that doesn't pull larger than uint32

Diffstat:
Msrc/cursor.h | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/cursor.h b/src/cursor.h @@ -332,6 +332,19 @@ static inline int cursor_pull_varint(struct cursor *cursor, uint64_t *n) return 10; // Successfully read 10 bytes for a full 64-bit integer } +static int cursor_pull_varint_u32(struct cursor *cursor, uint32_t *v) +{ + uint64_t bigval; + + if (!cursor_pull_varint(cursor, &bigval)) + return 0; + + if (bigval > UINT32_MAX) + return 0; + + *v = (uint32_t) bigval; + return 1; +} static inline int cursor_pull_int(struct cursor *cursor, int *i) {