simplify easyjson even more, rename functions, assume ids and pubkeys will always be safe hex strings that do not need to be escaped and eliminate unnecessary variables that would probably be eliminated by the compiler anyway.
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
jwriter "github.com/mailru/easyjson/jwriter"
|
||||
)
|
||||
|
||||
func easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Event) {
|
||||
func easyjsonDecodeEvent(in *jlexer.Lexer, out *Event) {
|
||||
isTopLevel := in.IsStart()
|
||||
if in.IsNull() {
|
||||
if isTopLevel {
|
||||
@@ -75,89 +75,74 @@ func easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Event)
|
||||
}
|
||||
}
|
||||
|
||||
func easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Event) {
|
||||
func easyjsonEncodeEvent(out *jwriter.Writer, in Event) {
|
||||
out.RawByte('{')
|
||||
first := true
|
||||
_ = first
|
||||
{
|
||||
const prefix string = "\"kind\":"
|
||||
out.RawString(prefix)
|
||||
out.Int(int(in.Kind))
|
||||
|
||||
out.RawString("\"kind\":")
|
||||
out.Int(int(in.Kind))
|
||||
|
||||
if in.ID != ZeroID {
|
||||
out.RawString(",\"id\":\"")
|
||||
out.RawString(hex.EncodeToString(in.ID[:]))
|
||||
}
|
||||
{
|
||||
if in.ID != [32]byte{} {
|
||||
const prefix string = ",\"id\":"
|
||||
out.RawString(prefix)
|
||||
out.String(hex.EncodeToString(in.ID[:]))
|
||||
|
||||
if in.PubKey != ZeroPK {
|
||||
out.RawString("\",\"pubkey\":\"")
|
||||
out.RawString(hex.EncodeToString(in.PubKey[:]))
|
||||
}
|
||||
|
||||
out.RawString("\",\"created_at\":")
|
||||
out.Int64(int64(in.CreatedAt))
|
||||
|
||||
out.RawString(",\"tags\":")
|
||||
out.RawByte('[')
|
||||
for v3, v4 := range in.Tags {
|
||||
if v3 > 0 {
|
||||
out.RawByte(',')
|
||||
}
|
||||
}
|
||||
{
|
||||
if in.PubKey != [32]byte{} {
|
||||
const prefix string = ",\"pubkey\":"
|
||||
out.RawString(prefix)
|
||||
out.String(hex.EncodeToString(in.PubKey[:]))
|
||||
}
|
||||
}
|
||||
{
|
||||
const prefix string = ",\"created_at\":"
|
||||
out.RawString(prefix)
|
||||
out.Int64(int64(in.CreatedAt))
|
||||
}
|
||||
{
|
||||
const prefix string = ",\"tags\":"
|
||||
out.RawString(prefix)
|
||||
out.RawByte('[')
|
||||
for v3, v4 := range in.Tags {
|
||||
if v3 > 0 {
|
||||
for v5, v6 := range v4 {
|
||||
if v5 > 0 {
|
||||
out.RawByte(',')
|
||||
}
|
||||
out.RawByte('[')
|
||||
for v5, v6 := range v4 {
|
||||
if v5 > 0 {
|
||||
out.RawByte(',')
|
||||
}
|
||||
out.String(v6)
|
||||
}
|
||||
out.RawByte(']')
|
||||
out.String(v6)
|
||||
}
|
||||
out.RawByte(']')
|
||||
}
|
||||
{
|
||||
const prefix string = ",\"content\":"
|
||||
out.RawString(prefix)
|
||||
out.String(in.Content)
|
||||
}
|
||||
{
|
||||
if in.Sig != [64]byte{} {
|
||||
const prefix string = ",\"sig\":"
|
||||
out.RawString(prefix)
|
||||
out.String(hex.EncodeToString(in.Sig[:]))
|
||||
}
|
||||
out.RawByte(']')
|
||||
|
||||
out.RawString(",\"content\":")
|
||||
out.String(in.Content)
|
||||
|
||||
if in.Sig != [64]byte{} {
|
||||
out.RawString(",\"sig\":\"")
|
||||
out.RawString(hex.EncodeToString(in.Sig[:]) + "\"")
|
||||
}
|
||||
|
||||
out.RawByte('}')
|
||||
}
|
||||
|
||||
// MarshalJSON supports json.Marshaler interface
|
||||
func (v Event) MarshalJSON() ([]byte, error) {
|
||||
w := jwriter.Writer{NoEscapeHTML: true}
|
||||
easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(&w, v)
|
||||
easyjsonEncodeEvent(&w, v)
|
||||
return w.Buffer.BuildBytes(), w.Error
|
||||
}
|
||||
|
||||
// MarshalEasyJSON supports easyjson.Marshaler interface
|
||||
func (v Event) MarshalEasyJSON(w *jwriter.Writer) {
|
||||
w.NoEscapeHTML = true
|
||||
easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(w, v)
|
||||
easyjsonEncodeEvent(w, v)
|
||||
}
|
||||
|
||||
// UnmarshalJSON supports json.Unmarshaler interface
|
||||
func (v *Event) UnmarshalJSON(data []byte) error {
|
||||
r := jlexer.Lexer{Data: data}
|
||||
easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(&r, v)
|
||||
easyjsonDecodeEvent(&r, v)
|
||||
return r.Error()
|
||||
}
|
||||
|
||||
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
|
||||
func (v *Event) UnmarshalEasyJSON(l *jlexer.Lexer) {
|
||||
easyjsonF642ad3eDecodeGithubComNbdWtfGoNostr(l, v)
|
||||
easyjsonDecodeEvent(l, v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user