package kind import ( "runtime" "git.smesh.lol/nostr/pkg/ints" "git.smesh.lol/nostr/pkg/lol/chk" ) type Integer interface { ~int32 | ~int8 | ~int16 | ~int64 | ~uint32 | ~uint8 | ~uint16 | ~uint64 } type K struct { K uint16 } func New[V Integer](k V) (kp *K) { return &K{uint16(k)} } func (k *K) ToInt() (n int32) { if k == nil { return 0 } return int32(k.K) } func (k *K) ToU16() (n uint16) { if k == nil { return 0 } return k.K } func (k *K) ToI32() (n int32) { if k == nil { return 0 } return int32(k.K) } func (k *K) ToU64() (n uint64) { if k == nil { return 0 } return uint64(k.K) } func (k *K) Name() (buf []byte) { return []byte(GetString(k.K)) } func (k *K) Equal(k2 uint16) (ok bool) { if k == nil { return false } return k.K == k2 } var Privileged []*K var Directory []*K var _kindsReady bool func initKinds() { if _kindsReady { return } _kindsReady = true // Every allocation here is stored into a package global, so it must // outlive this call. The current frame arena is released on return, so // borrow the root arena for the duration; a global pointing at a // released frame arena is a dangling pointer as soon as the pooled // arena is unmapped. runtime.SovereignSetArena(runtime.RootArena()) Map = map[uint16]string{} ProfileMetadata = &K{0} SetMetadata = &K{0} TextNote = &K{1} RecommendRelay = &K{2} FollowList = &K{3} Follows = &K{3} EncryptedDirectMessage = &K{4} EventDeletion = &K{5} Deletion = &K{5} Repost = &K{6} Reaction = &K{7} BadgeAward = &K{8} ChatMessage = &K{9} GroupChatThreadedReply = &K{10} Thread = &K{11} GroupThreadReply = &K{12} Seal = &K{13} DirectMessage = &K{14} FileMessage = &K{15} GenericRepost = &K{16} ReactionToWebsite = &K{17} Picture = &K{20} VideoEventHorizontal = &K{34235} VideoEventVertical = &K{34236} MLSKeyPackage = &K{443} MLSWelcome = &K{444} MLSGroupEvent = &K{445} ChannelCreation = &K{40} ChannelMetadata = &K{41} ChannelMessage = &K{42} ChannelHideMessage = &K{43} ChannelMuteUser = &K{44} Bid = &K{1021} BidConfirmation = &K{1022} OpenTimestamps = &K{1040} GiftWrap = &K{1059} GiftWrapWithKind4 = &K{1060} FileMetadata = &K{1063} LiveChatMessage = &K{1311} BitcoinBlock = &K{1517} LiveStream = &K{1808} ProblemTracker = &K{1971} MemoryHole = &K{1984} Reporting = &K{1984} Label = &K{1985} CommunityPostApproval = &K{4550} JobRequestStart = &K{5000} JobRequestEnd = &K{5999} JobResultStart = &K{6000} JobResultEnd = &K{6999} JobFeedback = &K{7000} ZapGoal = &K{9041} ZapRequest = &K{9734} Zap = &K{9735} Highlights = &K{9802} ReplaceableStart = &K{10000} MuteList = &K{10000} BlockList = &K{10000} PinList = &K{10001} RelayListMetadata = &K{10002} BookmarkList = &K{10003} CommunitiesList = &K{10004} PublicChatsList = &K{10005} BlockedRelaysList = &K{10006} SearchRelaysList = &K{10007} RelayGroupConfig = &K{10008} InterestsList = &K{10015} UserEmojiList = &K{10030} DMRelaysList = &K{10050} KeyPackageRelaysList = &K{10051} FileStorageServerList = &K{10096} JWTBinding = &K{13004} NWCWalletServiceInfo = &K{13194} WalletServiceInfo = &K{13194} ReplaceableEnd = &K{19999} EphemeralStart = &K{20000} LightningPubRPC = &K{21000} ClientAuthentication = &K{22242} NWCWalletRequest = &K{23194} WalletRequest = &K{23194} NWCWalletResponse = &K{23195} WalletResponse = &K{23195} NWCNotification = &K{23196} WalletNotificationNip4 = &K{23196} WalletNotification = &K{23197} NostrConnect = &K{24133} HTTPAuth = &K{27235} EphemeralEnd = &K{29999} ParameterizedReplaceableStart = &K{30000} CategorizedPeopleList = &K{30000} FollowSets = &K{30000} CategorizedBookmarksList = &K{30001} GenericLists = &K{30001} RelaySets = &K{30002} BookmarkSets = &K{30003} CurationSets = &K{30004} ProfileBadges = &K{30008} BadgeDefinition = &K{30009} InterestSets = &K{30015} StallDefinition = &K{30017} ProductDefinition = &K{30018} MarketplaceUIUX = &K{30019} ProductSoldAsAuction = &K{30020} Article = &K{30023} LongFormContent = &K{30023} DraftLongFormContent = &K{30024} EmojiSets = &K{30030} ApplicationSpecificData = &K{30078} LiveEvent = &K{30311} UserStatuses = &K{30315} ClassifiedListing = &K{30402} DraftClassifiedListing = &K{30403} DateBasedCalendarEvent = &K{31922} TimeBasedCalendarEvent = &K{31923} Calendar = &K{31924} CalendarEventRSVP = &K{31925} HandlerRecommendation = &K{31989} HandlerInformation = &K{31990} WaveLakeTrack = &K{32123} CommunityDefinition = &K{34550} ACLEvent = &K{39998} PolicyConfig = &K{12345} ParameterizedReplaceableEnd = &K{40000} Privileged = []*K{ EncryptedDirectMessage, GiftWrap, GiftWrapWithKind4, JWTBinding, ApplicationSpecificData, Seal, DirectMessage, FileMessage, MLSKeyPackage, KeyPackageRelaysList, ChannelCreation, ChannelMetadata, ChannelMessage, ChannelHideMessage, ChannelMuteUser, } Directory = []*K{ ProfileMetadata, FollowList, EventDeletion, Reporting, RelayListMetadata, MuteList, DMRelaysList, } runtime.SovereignRestoreArena(runtime.RootArena()) } // Ensure materializes the kind table. Callers that read a package-level // kind pointer directly (kind.NewS(kind.MuteList)) must call this first: // the pointers are nil until initKinds runs, and boxing a nil pointer // crashes whichever index scan dereferences it. func Ensure() { initKinds() } func IsChannelKind(k uint16) (ok bool) { initKinds() return k >= ChannelCreation.K && k <= ChannelMuteUser.K } func IsDiscoverableChannelKind(k uint16) (ok bool) { initKinds() return k == ChannelCreation.K || k == ChannelMetadata.K } func IsPrivileged(k uint16) (ok bool) { initKinds() for i := range Privileged { if k == Privileged[i].K { return true } } return false } func (k *K) Marshal(dst []byte) (buf []byte) { return ints.New(k.ToU64()).Marshal(dst) } func (k *K) Unmarshal(b []byte) (r []byte, err error) { n := ints.New(0) if r, err = n.Unmarshal(b); chk.T(err) { return } k.K = n.Uint16() return } func GetString(t uint16) (s string) { initKinds() return Map[t] } func IsEphemeral(k uint16) (ok bool) { initKinds() return k >= EphemeralStart.K && k < EphemeralEnd.K } func IsReplaceable(k uint16) (ok bool) { initKinds() return k == ProfileMetadata.K || k == FollowList.K || (k >= ReplaceableStart.K && k < ReplaceableEnd.K) } func IsParameterizedReplaceable(k uint16) (ok bool) { initKinds() return k >= ParameterizedReplaceableStart.K && k < ParameterizedReplaceableEnd.K } func IsDirectoryEvent(k uint16) (ok bool) { initKinds() for i := range Directory { if k == Directory[i].K { return true } } return false } var ( ProfileMetadata *K SetMetadata *K TextNote *K RecommendRelay *K FollowList *K Follows *K EncryptedDirectMessage *K EventDeletion *K Deletion *K Repost *K Reaction *K BadgeAward *K ChatMessage *K GroupChatThreadedReply *K Thread *K GroupThreadReply *K Seal *K DirectMessage *K FileMessage *K GenericRepost *K ReactionToWebsite *K Picture *K VideoEventHorizontal *K VideoEventVertical *K MLSKeyPackage *K MLSWelcome *K MLSGroupEvent *K ChannelCreation *K ChannelMetadata *K ChannelMessage *K ChannelHideMessage *K ChannelMuteUser *K Bid *K BidConfirmation *K OpenTimestamps *K GiftWrap *K GiftWrapWithKind4 *K FileMetadata *K LiveChatMessage *K BitcoinBlock *K LiveStream *K ProblemTracker *K MemoryHole *K Reporting *K Label *K CommunityPostApproval *K JobRequestStart *K JobRequestEnd *K JobResultStart *K JobResultEnd *K JobFeedback *K ZapGoal *K ZapRequest *K Zap *K Highlights *K ReplaceableStart *K MuteList *K BlockList *K PinList *K RelayListMetadata *K BookmarkList *K CommunitiesList *K PublicChatsList *K BlockedRelaysList *K SearchRelaysList *K RelayGroupConfig *K InterestsList *K UserEmojiList *K DMRelaysList *K KeyPackageRelaysList *K FileStorageServerList *K JWTBinding *K NWCWalletServiceInfo *K WalletServiceInfo *K ReplaceableEnd *K EphemeralStart *K LightningPubRPC *K ClientAuthentication *K NWCWalletRequest *K WalletRequest *K NWCWalletResponse *K WalletResponse *K NWCNotification *K WalletNotificationNip4 *K WalletNotification *K NostrConnect *K HTTPAuth *K EphemeralEnd *K ParameterizedReplaceableStart *K CategorizedPeopleList *K FollowSets *K CategorizedBookmarksList *K GenericLists *K RelaySets *K BookmarkSets *K CurationSets *K ProfileBadges *K BadgeDefinition *K InterestSets *K StallDefinition *K ProductDefinition *K MarketplaceUIUX *K ProductSoldAsAuction *K Article *K LongFormContent *K DraftLongFormContent *K EmojiSets *K ApplicationSpecificData *K LiveEvent *K UserStatuses *K ClassifiedListing *K DraftClassifiedListing *K DateBasedCalendarEvent *K TimeBasedCalendarEvent *K Calendar *K CalendarEventRSVP *K HandlerRecommendation *K HandlerInformation *K WaveLakeTrack *K CommunityDefinition *K ACLEvent *K PolicyConfig *K ParameterizedReplaceableEnd *K Map map[uint16]string )