damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 0263c11a94615882eb5e5111a8a6c45ee0ca6f03
parent 6d43754e715ecfc59c531e43598352a2430df917
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 22 Jul 2023 07:40:20 -0700

ndb: add content and owned_size

Diffstat:
Mnostrdb/NdbNote.swift | 8++++++++
Mnostrdb/Test/NdbTests.swift | 2+-
Mnostrdb/nostrdb.c | 1-
3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift @@ -17,6 +17,14 @@ struct NdbNote { self.owned = data } + var owned_size: Int? { + return owned?.count + } + + var content: String { + String(cString: ndb_note_content(note), encoding: .utf8) ?? "" + } + var id: Data { Data(buffer: UnsafeBufferPointer(start: ndb_note_id(note), count: 32)) } diff --git a/nostrdb/Test/NdbTests.swift b/nostrdb/Test/NdbTests.swift @@ -28,7 +28,7 @@ final class NdbTests: XCTestCase { XCTAssertEqual(hex_encode(note.id), id) XCTAssertEqual(hex_encode(note.pubkey), pubkey) - XCTAssertEqual(note.tags().reduce(0, { sum, _ in sum + 1 }), 786) + XCTAssertEqual(note.owned_size, 59106) XCTAssertEqual(note.tags().reduce(0, { sum, _ in sum + 1 }), 786) //let tags = note.tags() diff --git a/nostrdb/nostrdb.c b/nostrdb/nostrdb.c @@ -409,7 +409,6 @@ static int parse_unsigned_int(const char *start, int len, unsigned int *num) } - int ndb_note_from_json(const char *json, int len, struct ndb_note **note, unsigned char *buf, int bufsize) {