From 56610a32e66b441bb0193e03480e1f32614d8234 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 29 Mar 2026 09:15:22 -0300 Subject: [PATCH] constant ints must be casted so they work with gomobile. --- eventstore/codec/betterbinary/codec.go | 12 ++++++------ eventstore/mmm/mmmm.go | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/eventstore/codec/betterbinary/codec.go b/eventstore/codec/betterbinary/codec.go index 8417ef4..c9190c2 100644 --- a/eventstore/codec/betterbinary/codec.go +++ b/eventstore/codec/betterbinary/codec.go @@ -40,12 +40,12 @@ func Marshal(evt nostr.Event, buf []byte) error { buf[0] = 0 if evt.Kind > MaxKind { - return fmt.Errorf("kind is too big: %d, max is %d", evt.Kind, MaxKind) + return fmt.Errorf("kind is too big: %d, max is %d", evt.Kind, uint16(MaxKind)) } binary.LittleEndian.PutUint16(buf[1:3], uint16(evt.Kind)) if evt.CreatedAt > MaxCreatedAt { - return fmt.Errorf("created_at is too big: %d, max is %d", evt.CreatedAt, MaxCreatedAt) + return fmt.Errorf("created_at is too big: %d, max is %d", evt.CreatedAt, uint32(MaxCreatedAt)) } binary.LittleEndian.PutUint32(buf[3:7], uint32(evt.CreatedAt)) @@ -58,7 +58,7 @@ func Marshal(evt nostr.Event, buf []byte) error { ntags := len(evt.Tags) if ntags > MaxTagCount { - return fmt.Errorf("can't encode too many tags: %d, max is %d", ntags, MaxTagCount) + return fmt.Errorf("can't encode too many tags: %d, max is %d", ntags, uint16(MaxTagCount)) } binary.LittleEndian.PutUint16(buf[137:139], uint16(ntags)) @@ -68,7 +68,7 @@ func Marshal(evt nostr.Event, buf []byte) error { itemCount := len(tag) if itemCount > MaxTagItemCount { - return fmt.Errorf("can't encode a tag with so many items: %d, max is %d", itemCount, MaxTagItemCount) + return fmt.Errorf("can't encode a tag with so many items: %d, max is %d", itemCount, uint8(MaxTagItemCount)) } buf[tagBase+tagOffset] = uint8(itemCount) @@ -76,7 +76,7 @@ func Marshal(evt nostr.Event, buf []byte) error { for _, item := range tag { itemSize := len(item) if itemSize > MaxTagItemSize { - return fmt.Errorf("tag item is too large: %d, max is %d", itemSize, MaxTagItemSize) + return fmt.Errorf("tag item is too large: %d, max is %d", itemSize, uint16(MaxTagItemSize)) } binary.LittleEndian.PutUint16(buf[tagBase+tagOffset+itemOffset:], uint16(itemSize)) @@ -91,7 +91,7 @@ func Marshal(evt nostr.Event, buf []byte) error { // content if contentLength := len(evt.Content); contentLength > MaxContentSize { - return fmt.Errorf("content is too large: %d, max is %d", contentLength, MaxContentSize) + return fmt.Errorf("content is too large: %d, max is %d", contentLength, uint16(MaxContentSize)) } else { binary.LittleEndian.PutUint16(buf[tagBase+tagsSectionLength:], uint16(contentLength)) } diff --git a/eventstore/mmm/mmmm.go b/eventstore/mmm/mmmm.go index 1da424d..f0f71b3 100644 --- a/eventstore/mmm/mmmm.go +++ b/eventstore/mmm/mmmm.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "errors" "fmt" + "math" "os" "path/filepath" "slices" @@ -50,7 +51,7 @@ func (b *MultiMmapManager) String() string { } const ( - MMAP_INFINITE_SIZE = 1 << 40 + MMAP_INFINITE_SIZE = math.MaxInt maxuint16 = 65535 maxuint32 = 4294967295 ) @@ -84,7 +85,7 @@ func (b *MultiMmapManager) Init() error { if err != nil { return fmt.Errorf("failed to open events file at %s: %w", b.mmapfPath, err) } - mmapf, err := syscall.Mmap(int(file.Fd()), 0, MMAP_INFINITE_SIZE, + mmapf, err := syscall.Mmap(int(file.Fd()), 0, int(MMAP_INFINITE_SIZE), syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED) if err != nil { return fmt.Errorf("failed to mmap events file at %s: %w", b.mmapfPath, err)