From 8ebb2d0594780dab90a18d8b69499cbc59a58758 Mon Sep 17 00:00:00 2001 From: a <a@tuxpa.in> Date: Thu, 26 Oct 2023 05:39:21 -0500 Subject: [PATCH] rawmessage optimization --- pkg/server/server.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index e006669..e9e9e7d 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -237,15 +237,25 @@ func (c *callResponder) send(ctx context.Context, env *callEnv) (err error) { // if there is no error, we try to marshal the result e.Field("result", func(e *jx.Encoder) { if v.dat != nil { - err = json.NewEncoder(e).EncodeWithOption(v.dat, func(eo *json.EncodeOption) { - eo.DisableNewline = true - }) - if err != nil { + switch c := v.dat.(type) { + case json.RawMessage: + e.Raw(c) + default: + err = json.NewEncoder(e).EncodeWithOption(v.dat, func(eo *json.EncodeOption) { + eo.DisableNewline = true + }) } } else { e.Null() } }) + // a json encoding error here is possibly fatal.... try to encode the error, but there are no promises + if err != nil { + e.Field("error", func(e *jx.Encoder) { + codec.EncodeError(e, m.Error) + }) + return + } } }) } -- GitLab