binary: fix encoding, was using uint8 for tags length, which was obviously not working.

This commit is contained in:
fiatjaf
2023-12-10 21:13:34 -03:00
parent 7ecbc0a7cf
commit c55b509653
3 changed files with 19 additions and 7 deletions

View File

@@ -23,8 +23,10 @@ func UnmarshalBinary(data []byte, evt *Event) (err error) {
evt.Content = string(data[136 : 136+contentLength])
curr := 136 + contentLength
ntags := int(data[curr])
evt.Tags = make(nostr.Tags, ntags)
nTags := binary.BigEndian.Uint16(data[curr : curr+2])
curr++
evt.Tags = make(nostr.Tags, nTags)
for t := range evt.Tags {
curr = curr + 1
@@ -57,7 +59,10 @@ func MarshalBinary(evt *Event) []byte {
copy(buf[136:], content)
curr := 136 + len(content)
buf[curr] = uint8(len(evt.Tags))
binary.BigEndian.PutUint16(buf[curr:curr+2], uint16(len(evt.Tags)))
curr++
for _, tag := range evt.Tags {
curr++
buf[curr] = uint8(len(tag))