1
0
mirror of git://jb55.com/damus synced 2024-09-29 16:30:44 +00:00

tags: add u64 decoding function

This will be used for decoding expiries.
This commit is contained in:
William Casarin 2024-01-25 11:48:15 -08:00
parent 71c9bd63fc
commit 3cce42eea1

View File

@ -130,6 +130,22 @@ struct NdbTagElem: Sequence, Hashable, Equatable {
return id.id
}
func u64() -> UInt64? {
switch self.data() {
case .id:
return nil
case .str(let str):
var end_ptr = UnsafeMutablePointer<CChar>(nil as OpaquePointer?)
let res = strtoull(str.str, &end_ptr, 10)
if end_ptr?.pointee == 0 {
return res
} else {
return nil
}
}
}
func string() -> String {
switch self.data() {
case .id(let id):