commit bd7487d34d684d776cb051baa36ca9ad92b6b193
parent 216483511329764e5c89f1092238f51c80f2c498
Author: William Casarin <jb55@jb55.com>
Date: Sat, 22 Jul 2023 13:49:52 -0700
add kind parsing support
Diffstat:
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/nostrdb.c b/nostrdb.c
@@ -448,7 +448,12 @@ int ndb_note_from_json(const char *json, int len, struct ndb_note **note,
} else if (start[0] == 'k' && jsoneq(json, tok, tok_len, "kind")) {
// kind
tok = &parser.toks[i+1];
- //printf("json_kind %.*s\n", toksize(tok), json + tok->start);
+ start = json + tok->start;
+ if (tok->type != JSMN_PRIMITIVE || tok_len <= 0)
+ return 0;
+ if (!parse_unsigned_int(start, toksize(tok),
+ &parser.builder.note->kind))
+ return 0;
} else if (start[0] == 'c') {
if (jsoneq(json, tok, tok_len, "created_at")) {
// created_at
diff --git a/nostrdb.h b/nostrdb.h
@@ -136,6 +136,11 @@ static inline uint32_t ndb_note_created_at(struct ndb_note *note)
return note->created_at;
}
+static inline uint32_t ndb_note_kind(struct ndb_note *note)
+{
+ return note->kind;
+}
+
static inline const char * ndb_note_content(struct ndb_note *note)
{
return ndb_note_str(note, ¬e->content);
diff --git a/test.c b/test.c
@@ -122,6 +122,7 @@ static void test_parse_contact_list()
assert(!strcmp(expected_content, ndb_note_content(note)));
assert(ndb_note_created_at(note) == 1689904312);
+ assert(ndb_note_kind(note) == 3);
write_file("test_contacts_ndb_note", (unsigned char *)note, size);
printf("wrote test_contacts_ndb_note (raw ndb_note)\n");