mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-30 17:50:12 +02:00
meaningless optimizations.
This commit is contained in:
parent
1e4848d84d
commit
0ccc1b8e9c
19
envelopes.go
19
envelopes.go
@ -94,7 +94,9 @@ func (v EventEnvelope) MarshalJSON() ([]byte, error) {
|
||||
w := jwriter.Writer{NoEscapeHTML: true}
|
||||
w.RawString(`["EVENT",`)
|
||||
if v.SubscriptionID != nil {
|
||||
w.RawString(`"` + *v.SubscriptionID + `",`)
|
||||
w.RawString(`"`)
|
||||
w.RawString(*v.SubscriptionID)
|
||||
w.RawString(`",`)
|
||||
}
|
||||
v.Event.MarshalEasyJSON(&w)
|
||||
w.RawString(`]`)
|
||||
@ -129,8 +131,9 @@ func (v *ReqEnvelope) UnmarshalJSON(data []byte) error {
|
||||
|
||||
func (v ReqEnvelope) MarshalJSON() ([]byte, error) {
|
||||
w := jwriter.Writer{NoEscapeHTML: true}
|
||||
w.RawString(`["REQ",`)
|
||||
w.RawString(`"` + v.SubscriptionID + `"`)
|
||||
w.RawString(`["REQ","`)
|
||||
w.RawString(v.SubscriptionID)
|
||||
w.RawString(`"`)
|
||||
for _, filter := range v.Filters {
|
||||
w.RawString(`,`)
|
||||
filter.MarshalEasyJSON(&w)
|
||||
@ -192,8 +195,9 @@ func (v *CountEnvelope) UnmarshalJSON(data []byte) error {
|
||||
|
||||
func (v CountEnvelope) MarshalJSON() ([]byte, error) {
|
||||
w := jwriter.Writer{NoEscapeHTML: true}
|
||||
w.RawString(`["COUNT",`)
|
||||
w.RawString(`"` + v.SubscriptionID + `"`)
|
||||
w.RawString(`["COUNT","`)
|
||||
w.RawString(v.SubscriptionID)
|
||||
w.RawString(`"`)
|
||||
if v.Count != nil {
|
||||
w.RawString(`,{"count":`)
|
||||
w.RawString(strconv.FormatInt(*v.Count, 10))
|
||||
@ -355,8 +359,9 @@ func (v *OKEnvelope) UnmarshalJSON(data []byte) error {
|
||||
|
||||
func (v OKEnvelope) MarshalJSON() ([]byte, error) {
|
||||
w := jwriter.Writer{NoEscapeHTML: true}
|
||||
w.RawString(`["OK",`)
|
||||
w.RawString(`"` + v.EventID + `",`)
|
||||
w.RawString(`["OK","`)
|
||||
w.RawString(v.EventID)
|
||||
w.RawString(`",`)
|
||||
ok := "false"
|
||||
if v.OK {
|
||||
ok = "true"
|
||||
|
2
event.go
2
event.go
@ -57,7 +57,7 @@ func (evt *Event) CheckID() bool {
|
||||
func (evt *Event) Serialize() []byte {
|
||||
// the serialization process is just putting everything into a JSON array
|
||||
// so the order is kept. See NIP-01
|
||||
dst := make([]byte, 0)
|
||||
dst := make([]byte, 0, 100+len(evt.Content)+len(evt.Tags)*80)
|
||||
|
||||
// the header portion is easy to serialize
|
||||
// [0,"pubkey",created_at,kind,[
|
||||
|
Loading…
x
Reference in New Issue
Block a user