commit b5ad3ed1a5697d78d19936f4008f1cdc333c29a2
parent 371e9fb4065a9e23f16868cd61eab19c435673de
Author: William Casarin <jb55@jb55.com>
Date: Wed, 27 Dec 2023 12:40:50 -0800
nostrdb/cursor: add pull_varint_u32
This is a varint helper that doesn't pull larger than uint32
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/nostrdb/src/cursor.h b/nostrdb/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)
{