diff --git a/event_easyjson.go b/event_easyjson.go index 103efaa..fa6f63c 100644 --- a/event_easyjson.go +++ b/event_easyjson.go @@ -3,18 +3,10 @@ package nostr import ( "encoding/hex" - easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" ) -// suppress unused package warning -var ( - _ *jlexer.Lexer - _ *jwriter.Writer - _ easyjson.Marshaler -) - func easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Event) { isTopLevel := in.IsStart() if in.IsNull() { diff --git a/filter_easyjson.go b/filter_easyjson.go index dc6cfa1..4a71483 100644 --- a/filter_easyjson.go +++ b/filter_easyjson.go @@ -3,18 +3,10 @@ package nostr import ( "encoding/hex" - easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" ) -// suppress unused package warning -var ( - _ *jlexer.Lexer - _ *jwriter.Writer - _ easyjson.Marshaler -) - func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter) { isTopLevel := in.IsStart() if in.IsNull() { diff --git a/pointers.go b/pointers.go index 26a3aaa..20a7510 100644 --- a/pointers.go +++ b/pointers.go @@ -31,8 +31,8 @@ var ( // ProfilePointer represents a pointer to a Nostr profile. type ProfilePointer struct { - PublicKey PubKey `json:"pubkey"` - Relays []string `json:"relays,omitempty"` + PublicKey PubKey + Relays []string } // ProfilePointerFromTag creates a ProfilePointer from a "p" tag (but it doesn't have to be necessarily a "p" tag, could be something else). @@ -67,10 +67,10 @@ func (ep ProfilePointer) AsTag() Tag { // EventPointer represents a pointer to a nostr event. type EventPointer struct { - ID ID `json:"id"` - Relays []string `json:"relays,omitempty"` - Author PubKey `json:"author,omitempty"` - Kind Kind `json:"kind,omitempty"` + ID ID + Relays []string + Author PubKey + Kind Kind } // EventPointerFromTag creates an EventPointer from an "e" tag (but it could be other tag name, it isn't checked). @@ -114,10 +114,10 @@ func (ep EventPointer) AsTag() Tag { // EntityPointer represents a pointer to a nostr entity (addressable event). type EntityPointer struct { - PublicKey PubKey `json:"pubkey"` - Kind Kind `json:"kind,omitempty"` - Identifier string `json:"identifier,omitempty"` - Relays []string `json:"relays,omitempty"` + PublicKey PubKey + Kind Kind + Identifier string + Relays []string } // EntityPointerFromTag creates an EntityPointer from an "a" tag (but it doesn't check if the tag is really "a", it could be anything). diff --git a/pointers_easyjson.go b/pointers_easyjson.go new file mode 100644 index 0000000..b2ea8b0 --- /dev/null +++ b/pointers_easyjson.go @@ -0,0 +1,363 @@ +// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. + +package nostr + +import ( + "encoding/hex" + + jlexer "github.com/mailru/easyjson/jlexer" + jwriter "github.com/mailru/easyjson/jwriter" +) + +func easyjson33014d6eDecodeFiatjafComNostr(in *jlexer.Lexer, out *ProfilePointer) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "pubkey": + if in.IsNull() { + in.Skip() + } else { + hex.Decode(out.PublicKey[:], in.UnsafeBytes()) + } + case "relays": + if in.IsNull() { + in.Skip() + out.Relays = nil + } else { + in.Delim('[') + if out.Relays == nil { + if !in.IsDelim(']') { + out.Relays = make([]string, 0, 4) + } else { + out.Relays = []string{} + } + } else { + out.Relays = (out.Relays)[:0] + } + for !in.IsDelim(']') { + out.Relays = append(out.Relays, in.String()) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} + +func easyjson33014d6eEncodeFiatjafComNostr(out *jwriter.Writer, in ProfilePointer) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"pubkey\":" + out.RawString(prefix[1:]) + out.String(in.PublicKey.Hex()) + } + if len(in.Relays) != 0 { + const prefix string = ",\"relays\":" + out.RawString(prefix) + { + out.RawByte('[') + for v4, v5 := range in.Relays { + if v4 > 0 { + out.RawByte(',') + } + out.String(v5) + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v ProfilePointer) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson33014d6eEncodeFiatjafComNostr(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v ProfilePointer) MarshalEasyJSON(w *jwriter.Writer) { + easyjson33014d6eEncodeFiatjafComNostr(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *ProfilePointer) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson33014d6eDecodeFiatjafComNostr(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *ProfilePointer) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson33014d6eDecodeFiatjafComNostr(l, v) +} + +func easyjson33014d6eDecodeFiatjafComNostr1(in *jlexer.Lexer, out *EventPointer) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "id": + if in.IsNull() { + in.Skip() + } else { + hex.Decode(out.ID[:], in.UnsafeBytes()) + } + case "relays": + if in.IsNull() { + in.Skip() + out.Relays = nil + } else { + in.Delim('[') + if out.Relays == nil { + if !in.IsDelim(']') { + out.Relays = make([]string, 0, 4) + } else { + out.Relays = []string{} + } + } else { + out.Relays = (out.Relays)[:0] + } + for !in.IsDelim(']') { + out.Relays = append(out.Relays, in.String()) + in.WantComma() + } + in.Delim(']') + } + case "author": + if in.IsNull() { + in.Skip() + } else { + hex.Decode(out.Author[:], in.UnsafeBytes()) + } + case "kind": + out.Kind = Kind(in.Uint16()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} + +func easyjson33014d6eEncodeFiatjafComNostr1(out *jwriter.Writer, in EventPointer) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"id\":" + out.RawString(prefix[1:]) + out.String(in.ID.Hex()) + } + if len(in.Relays) != 0 { + const prefix string = ",\"relays\":" + out.RawString(prefix) + { + out.RawByte('[') + for v10, v11 := range in.Relays { + if v10 > 0 { + out.RawByte(',') + } + out.String(v11) + } + out.RawByte(']') + } + } + if true { + const prefix string = ",\"author\":" + out.RawString(prefix) + out.String(in.Author.Hex()) + } + if in.Kind != 0 { + const prefix string = ",\"kind\":" + out.RawString(prefix) + out.Uint(uint(in.Kind)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v EventPointer) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson33014d6eEncodeFiatjafComNostr1(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v EventPointer) MarshalEasyJSON(w *jwriter.Writer) { + easyjson33014d6eEncodeFiatjafComNostr1(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *EventPointer) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson33014d6eDecodeFiatjafComNostr1(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *EventPointer) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson33014d6eDecodeFiatjafComNostr1(l, v) +} + +func easyjson33014d6eDecodeFiatjafComNostr2(in *jlexer.Lexer, out *EntityPointer) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "pubkey": + if in.IsNull() { + in.Skip() + } else { + hex.Decode(out.PublicKey[:], in.UnsafeBytes()) + } + case "kind": + out.Kind = Kind(in.Uint16()) + case "identifier": + out.Identifier = in.String() + case "relays": + if in.IsNull() { + in.Skip() + out.Relays = nil + } else { + in.Delim('[') + if out.Relays == nil { + if !in.IsDelim(']') { + out.Relays = make([]string, 0, 4) + } else { + out.Relays = []string{} + } + } else { + out.Relays = (out.Relays)[:0] + } + for !in.IsDelim(']') { + out.Relays = append(out.Relays, in.String()) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} + +func easyjson33014d6eEncodeFiatjafComNostr2(out *jwriter.Writer, in EntityPointer) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"pubkey\":" + out.RawString(prefix[1:]) + out.String(in.PublicKey.Hex()) + } + if in.Kind != 0 { + const prefix string = ",\"kind\":" + out.RawString(prefix) + out.Uint(uint(in.Kind)) + } + if in.Identifier != "" { + const prefix string = ",\"identifier\":" + out.RawString(prefix) + out.String(in.Identifier) + } + if len(in.Relays) != 0 { + const prefix string = ",\"relays\":" + out.RawString(prefix) + { + out.RawByte('[') + for v16, v17 := range in.Relays { + if v16 > 0 { + out.RawByte(',') + } + out.String(v17) + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v EntityPointer) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson33014d6eEncodeFiatjafComNostr2(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v EntityPointer) MarshalEasyJSON(w *jwriter.Writer) { + easyjson33014d6eEncodeFiatjafComNostr2(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *EntityPointer) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson33014d6eDecodeFiatjafComNostr2(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *EntityPointer) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson33014d6eDecodeFiatjafComNostr2(l, v) +}