Skip to content

Commit

Permalink
nson: test encoder with events from the wild.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Jul 5, 2023
1 parent 6f03e6b commit 7ba3844
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 33 deletions.
8 changes: 3 additions & 5 deletions nson/nson.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
var NotNSON = fmt.Errorf("not nson")

// Unmarshal turns a NSON string into a nostr.Event struct
func Unmarshal(data string) (evt *nostr.Event, err error) {
func Unmarshal(data string, evt *nostr.Event) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("failed to decode nson: %v", r)
Expand All @@ -54,14 +54,12 @@ func Unmarshal(data string) (evt *nostr.Event, err error) {

// check if it's nson
if data[NSON_MARKER_START:NSON_MARKER_END] != ",\"nson\":" {
return nil, NotNSON
return NotNSON
}

// nson values
nsonSize, nsonDescriptors := parseDescriptors(data)

evt = &nostr.Event{}

// static fields
evt.ID = data[ID_START:ID_END]
evt.PubKey = data[PUBKEY_START:PUBKEY_END]
Expand Down Expand Up @@ -104,7 +102,7 @@ func Unmarshal(data string) (evt *nostr.Event, err error) {
evt.Tags[t] = tag
}

return evt, err
return err
}

func Marshal(evt nostr.Event) (string, error) {
Expand Down
Loading

0 comments on commit 7ba3844

Please sign in to comment.