use .UnsafeBytes() on easyjson since we're decoding hex anyway.

This commit is contained in:
fiatjaf
2025-04-14 21:45:26 -03:00
parent 67cb0ea8fb
commit f9e4a5efa3
2 changed files with 15 additions and 19 deletions

View File

@@ -35,9 +35,9 @@ func easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Event)
} }
switch key { switch key {
case "id": case "id":
hex.Decode(out.ID[:], []byte(in.String())) hex.Decode(out.ID[:], in.UnsafeBytes())
case "pubkey": case "pubkey":
hex.Decode(out.PubKey[:], []byte(in.String())) hex.Decode(out.PubKey[:], in.UnsafeBytes())
case "created_at": case "created_at":
out.CreatedAt = Timestamp(in.Int64()) out.CreatedAt = Timestamp(in.Int64())
case "kind": case "kind":
@@ -58,26 +58,24 @@ func easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Event)
out.Tags = (out.Tags)[:0] out.Tags = (out.Tags)[:0]
} }
for !in.IsDelim(']') { for !in.IsDelim(']') {
var v1 Tag var v Tag
if in.IsNull() { if in.IsNull() {
in.Skip() in.Skip()
v1 = nil v = nil
} else { } else {
in.Delim('[') in.Delim('[')
if !in.IsDelim(']') { if !in.IsDelim(']') {
v1 = make(Tag, 0, 5) v = make(Tag, 0, 5)
} else { } else {
v1 = Tag{} v = Tag{}
} }
for !in.IsDelim(']') { for !in.IsDelim(']') {
var v2 string v = append(v, in.String())
v2 = in.String()
v1 = append(v1, v2)
in.WantComma() in.WantComma()
} }
in.Delim(']') in.Delim(']')
} }
out.Tags = append(out.Tags, v1) out.Tags = append(out.Tags, v)
in.WantComma() in.WantComma()
} }
in.Delim(']') in.Delim(']')
@@ -85,7 +83,7 @@ func easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Event)
case "content": case "content":
out.Content = in.String() out.Content = in.String()
case "sig": case "sig":
hex.Decode(out.Sig[:], []byte(in.String())) hex.Decode(out.Sig[:], in.UnsafeBytes())
} }
in.WantComma() in.WantComma()
} }

View File

@@ -52,7 +52,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
} }
for !in.IsDelim(']') { for !in.IsDelim(']') {
id := [32]byte{} id := [32]byte{}
hex.Decode(id[:], []byte(in.String())) hex.Decode(id[:], in.UnsafeBytes())
out.IDs = append(out.IDs, id) out.IDs = append(out.IDs, id)
in.WantComma() in.WantComma()
} }
@@ -96,7 +96,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
} }
for !in.IsDelim(']') { for !in.IsDelim(']') {
pk := [32]byte{} pk := [32]byte{}
hex.Decode(pk[:], []byte(in.String())) hex.Decode(pk[:], in.UnsafeBytes())
out.Authors = append(out.Authors, pk) out.Authors = append(out.Authors, pk)
in.WantComma() in.WantComma()
} }
@@ -128,7 +128,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
out.LimitZero = true out.LimitZero = true
} }
case "search": case "search":
out.Search = string(in.String()) out.Search = in.String()
default: default:
if len(key) > 1 && key[0] == '#' { if len(key) > 1 && key[0] == '#' {
tagValues := make([]string, 0, 40) tagValues := make([]string, 0, 40)
@@ -144,9 +144,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
tagValues = (tagValues)[:0] tagValues = (tagValues)[:0]
} }
for !in.IsDelim(']') { for !in.IsDelim(']') {
var v3 string tagValues = append(tagValues, in.String())
v3 = string(in.String())
tagValues = append(tagValues, v3)
in.WantComma() in.WantComma()
} }
in.Delim(']') in.Delim(']')
@@ -259,7 +257,7 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
} else { } else {
out.RawString(prefix) out.RawString(prefix)
} }
out.String(string(in.Search)) out.String(in.Search)
} }
for tag, values := range in.Tags { for tag, values := range in.Tags {
const prefix string = ",\"authors\":" const prefix string = ",\"authors\":"
@@ -275,7 +273,7 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
if i > 0 { if i > 0 {
out.RawByte(',') out.RawByte(',')
} }
out.String(string(v)) out.String(v)
} }
out.RawByte(']') out.RawByte(']')
} }