event_easyjson.go raw
1 package nostr
2
3 import (
4 easyjson "github.com/mailru/easyjson"
5 jlexer "github.com/mailru/easyjson/jlexer"
6 jwriter "github.com/mailru/easyjson/jwriter"
7 )
8
9 // suppress unused package warning
10 var (
11 _ *jlexer.Lexer
12 _ *jwriter.Writer
13 _ easyjson.Marshaler
14 )
15
16 func easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Event) {
17 isTopLevel := in.IsStart()
18 if in.IsNull() {
19 if isTopLevel {
20 in.Consumed()
21 }
22 in.Skip()
23 return
24 }
25 in.Delim('{')
26 for !in.IsDelim('}') {
27 key := in.UnsafeFieldName(true)
28 in.WantColon()
29 if in.IsNull() {
30 in.Skip()
31 in.WantComma()
32 continue
33 }
34 switch key {
35 case "id":
36 out.ID = in.String()
37 case "pubkey":
38 out.PubKey = in.String()
39 case "created_at":
40 out.CreatedAt = Timestamp(in.Int64())
41 case "kind":
42 out.Kind = in.Int()
43 case "tags":
44 if in.IsNull() {
45 in.Skip()
46 out.Tags = nil
47 } else {
48 in.Delim('[')
49 if out.Tags == nil {
50 if !in.IsDelim(']') {
51 out.Tags = make(Tags, 0, 7)
52 } else {
53 out.Tags = Tags{}
54 }
55 } else {
56 out.Tags = (out.Tags)[:0]
57 }
58 for !in.IsDelim(']') {
59 var v1 Tag
60 if in.IsNull() {
61 in.Skip()
62 v1 = nil
63 } else {
64 in.Delim('[')
65 if !in.IsDelim(']') {
66 v1 = make(Tag, 0, 5)
67 } else {
68 v1 = Tag{}
69 }
70 for !in.IsDelim(']') {
71 var v2 string
72 v2 = in.String()
73 v1 = append(v1, v2)
74 in.WantComma()
75 }
76 in.Delim(']')
77 }
78 out.Tags = append(out.Tags, v1)
79 in.WantComma()
80 }
81 in.Delim(']')
82 }
83 case "content":
84 out.Content = in.String()
85 case "sig":
86 out.Sig = in.String()
87 }
88 in.WantComma()
89 }
90 in.Delim('}')
91 if isTopLevel {
92 in.Consumed()
93 }
94 }
95
96 func easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Event) {
97 out.RawByte('{')
98 first := true
99 _ = first
100 {
101 const prefix string = "\"kind\":"
102 out.RawString(prefix)
103 out.Int(in.Kind)
104 }
105 {
106 if in.ID != "" {
107 const prefix string = ",\"id\":"
108 out.RawString(prefix)
109 out.String(in.ID)
110 }
111 }
112 {
113 if in.PubKey != "" {
114 const prefix string = ",\"pubkey\":"
115 out.RawString(prefix)
116 out.String(in.PubKey)
117 }
118 }
119 {
120 const prefix string = ",\"created_at\":"
121 out.RawString(prefix)
122 out.Int64(int64(in.CreatedAt))
123 }
124 {
125 const prefix string = ",\"tags\":"
126 out.RawString(prefix)
127 out.RawByte('[')
128 for v3, v4 := range in.Tags {
129 if v3 > 0 {
130 out.RawByte(',')
131 }
132 out.RawByte('[')
133 for v5, v6 := range v4 {
134 if v5 > 0 {
135 out.RawByte(',')
136 }
137 out.String(v6)
138 }
139 out.RawByte(']')
140 }
141 out.RawByte(']')
142 }
143 {
144 const prefix string = ",\"content\":"
145 out.RawString(prefix)
146 out.String(in.Content)
147 }
148 {
149 if in.Sig != "" {
150 const prefix string = ",\"sig\":"
151 out.RawString(prefix)
152 out.String(in.Sig)
153 }
154 }
155 out.RawByte('}')
156 }
157
158 // MarshalJSON supports json.Marshaler interface
159 func (v Event) MarshalJSON() ([]byte, error) {
160 w := jwriter.Writer{NoEscapeHTML: true}
161 easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(&w, v)
162 return w.Buffer.BuildBytes(), w.Error
163 }
164
165 // MarshalEasyJSON supports easyjson.Marshaler interface
166 func (v Event) MarshalEasyJSON(w *jwriter.Writer) {
167 w.NoEscapeHTML = true
168 easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(w, v)
169 }
170
171 // UnmarshalJSON supports json.Unmarshaler interface
172 func (v *Event) UnmarshalJSON(data []byte) error {
173 r := jlexer.Lexer{Data: data}
174 easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(&r, v)
175 return r.Error()
176 }
177
178 // UnmarshalEasyJSON supports easyjson.Unmarshaler interface
179 func (v *Event) UnmarshalEasyJSON(l *jlexer.Lexer) {
180 easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(l, v)
181 }
182