nostrdb

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

commit 1e300b5487c243daa034f6af3a0fb2ff657928ef
parent 885643cea41b1504b00eedbd372041e848e2164c
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 27 Aug 2023 15:06:28 -0700

swift: gen codable instances

Diffstat:
MMakefile | 2+-
Mbindings/swift/NdbProfile.swift | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -66,7 +66,7 @@ bindings/c/%_json_parser.h: schemas/%.fbs bindings/c/.dir bindings-swift: bindings/swift/NdbProfile.swift bindings/swift/NdbProfile.swift: schemas/profile.fbs bindings/swift - flatc --swift $< + flatc --gen-json-emit --swift $< @mv profile_generated.swift $@ bindings/swift/NdbMeta.swift: schemas/meta.fbs bindings/swift diff --git a/bindings/swift/NdbProfile.swift b/bindings/swift/NdbProfile.swift @@ -115,6 +115,45 @@ public struct NdbProfile: FlatBufferObject, Verifiable { } } +extension NdbProfile: Encodable { + + enum CodingKeys: String, CodingKey { + case name = "name" + case website = "website" + case about = "about" + case lud16 = "lud16" + case banner = "banner" + case displayName = "display_name" + case reactions = "reactions" + case picture = "picture" + case nip05 = "nip05" + case damusDonation = "damus_donation" + case damusDonationV2 = "damus_donation_v2" + case lud06 = "lud06" + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(name, forKey: .name) + try container.encodeIfPresent(website, forKey: .website) + try container.encodeIfPresent(about, forKey: .about) + try container.encodeIfPresent(lud16, forKey: .lud16) + try container.encodeIfPresent(banner, forKey: .banner) + try container.encodeIfPresent(displayName, forKey: .displayName) + if reactions != true { + try container.encodeIfPresent(reactions, forKey: .reactions) + } + try container.encodeIfPresent(picture, forKey: .picture) + try container.encodeIfPresent(nip05, forKey: .nip05) + if damusDonation != 0 { + try container.encodeIfPresent(damusDonation, forKey: .damusDonation) + } + if damusDonationV2 != 0 { + try container.encodeIfPresent(damusDonationV2, forKey: .damusDonationV2) + } + try container.encodeIfPresent(lud06, forKey: .lud06) + } +} + public struct NdbProfileRecord: FlatBufferObject, Verifiable { static func validateVersion() { FlatBuffersVersion_23_5_26() } @@ -163,3 +202,20 @@ public struct NdbProfileRecord: FlatBufferObject, Verifiable { } } +extension NdbProfileRecord: Encodable { + + enum CodingKeys: String, CodingKey { + case profile = "profile" + case receivedAt = "received_at" + case lnurl = "lnurl" + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(profile, forKey: .profile) + if receivedAt != 0 { + try container.encodeIfPresent(receivedAt, forKey: .receivedAt) + } + try container.encodeIfPresent(lnurl, forKey: .lnurl) + } +} +