good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit ba87d417 authored by a's avatar a
Browse files

remove extra field

parent f6070ae7
No related branches found
No related tags found
No related merge requests found
Pipeline #31292 passed
...@@ -17,8 +17,6 @@ func NewNull() json.RawMessage { ...@@ -17,8 +17,6 @@ func NewNull() json.RawMessage {
return json.RawMessage("null") return json.RawMessage("null")
} }
type ExtraFields map[string]json.RawMessage
// A value of this type can a JSON-RPC request, notification, successful response or // A value of this type can a JSON-RPC request, notification, successful response or
// error response. Which one it is depends on the fields. // error response. Which one it is depends on the fields.
type Message struct { type Message struct {
...@@ -28,8 +26,6 @@ type Message struct { ...@@ -28,8 +26,6 @@ type Message struct {
Error error `json:"error,omitempty"` Error error `json:"error,omitempty"`
Result io.ReadCloser `json:"result,omitempty"` Result io.ReadCloser `json:"result,omitempty"`
ExtraFields ExtraFields `json:"-"`
} }
func NewStringReader(x string) io.ReadCloser { func NewStringReader(x string) io.ReadCloser {
...@@ -52,11 +48,6 @@ func MarshalMessage(m *Message, enc *jx.Encoder) (err error) { ...@@ -52,11 +48,6 @@ func MarshalMessage(m *Message, enc *jx.Encoder) (err error) {
e.Str(m.Method) e.Str(m.Method)
}) })
} }
for k, v := range m.ExtraFields {
e.Field(k, func(e *jx.Encoder) {
e.Raw(v)
})
}
if m.Error != nil { if m.Error != nil {
e.Field("error", func(e *jx.Encoder) { e.Field("error", func(e *jx.Encoder) {
EncodeError(e, m.Error) EncodeError(e, m.Error)
...@@ -91,17 +82,6 @@ func MarshalMessage(m *Message, enc *jx.Encoder) (err error) { ...@@ -91,17 +82,6 @@ func MarshalMessage(m *Message, enc *jx.Encoder) (err error) {
func UnmarshalMessage(m *Message, dec *jx.Decoder) error { func UnmarshalMessage(m *Message, dec *jx.Decoder) error {
err := dec.Obj(func(d *jx.Decoder, key string) (err error) { err := dec.Obj(func(d *jx.Decoder, key string) (err error) {
switch key { switch key {
default:
val, err := d.Raw()
if err != nil {
return err
}
buf := bytes.NewBuffer(make(json.RawMessage, len(val)))
buf.Write(val)
if m.ExtraFields == nil {
m.ExtraFields = ExtraFields{}
}
m.ExtraFields[key] = buf.Bytes()
case "jsonrpc": case "jsonrpc":
value, err := d.Str() value, err := d.Str()
if err != nil { if err != nil {
...@@ -216,31 +196,6 @@ func IsBatchMessage(raw json.RawMessage) bool { ...@@ -216,31 +196,6 @@ func IsBatchMessage(raw json.RawMessage) bool {
return false return false
} }
func (m ExtraFields) SetExtraField(name string, v any) (err error) {
switch name {
case "id", "jsonrpc", "method", "params", "result", "error":
return fmt.Errorf("%w: %q", ErrIllegalExtraField, name)
}
if v == nil {
delete(m, name)
}
val, err := json.Marshal(v)
if err != nil {
return err
}
m[name] = val
return nil
}
func (m ExtraFields) Clear() {
for k := range m {
delete(m, k)
}
}
func (m *Message) SetExtraField(name string, v any) error {
return m.ExtraFields.SetExtraField(name, v)
}
// parseMessage parses raw bytes as a (batch of) JSON-RPC message(s). There are no error // parseMessage parses raw bytes as a (batch of) JSON-RPC message(s). There are no error
// checks in this function because the raw message has already been syntax-checked when it // checks in this function because the raw message has already been syntax-checked when it
// is called. Any non-JSON-RPC messages in the input return the zero value of // is called. Any non-JSON-RPC messages in the input return the zero value of
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
type ResponseWriter interface { type ResponseWriter interface {
Send(v any, err error) error Send(v any, err error) error
Notify(method string, v any) error Notify(method string, v any) error
ExtraFields() ExtraFields
} }
// BatchElem is an element in a batch request. // BatchElem is an element in a batch request.
...@@ -119,7 +118,6 @@ func (r *Request) WithContext(ctx context.Context) *Request { ...@@ -119,7 +118,6 @@ func (r *Request) WithContext(ctx context.Context) *Request {
r2.Method = r.Method r2.Method = r.Method
r2.Params = r.Params r2.Params = r.Params
r2.Error = r.Error r2.Error = r.Error
r2.ExtraFields = r.ExtraFields
r2.Peer = r.Peer r2.Peer = r.Peer
return r2 return r2
} }
...@@ -40,7 +40,6 @@ func (c *streamingRespWriter) Send(v any, e error) (err error) { ...@@ -40,7 +40,6 @@ func (c *streamingRespWriter) Send(v any, e error) (err error) {
ce := &callEnv{ ce := &callEnv{
err: c.err, err: c.err,
id: c.msg.ID, id: c.msg.ID,
extrafields: c.msg.ExtraFields,
} }
// only override error if not already set // only override error if not already set
if ce.err == nil { if ce.err == nil {
...@@ -67,10 +66,6 @@ func (c *streamingRespWriter) Send(v any, e error) (err error) { ...@@ -67,10 +66,6 @@ func (c *streamingRespWriter) Send(v any, e error) (err error) {
return nil return nil
} }
func (c *streamingRespWriter) ExtraFields() jsonrpc.ExtraFields {
return c.msg.ExtraFields
}
func (c *streamingRespWriter) Notify(method string, v any) error { func (c *streamingRespWriter) Notify(method string, v any) error {
err := c.cr.mu.Acquire(c.ctx, 1) err := c.cr.mu.Acquire(c.ctx, 1)
if err != nil { if err != nil {
...@@ -80,7 +75,6 @@ func (c *streamingRespWriter) Notify(method string, v any) error { ...@@ -80,7 +75,6 @@ func (c *streamingRespWriter) Notify(method string, v any) error {
err = c.cr.notify(c.ctx, &notifyEnv{ err = c.cr.notify(c.ctx, &notifyEnv{
method: method, method: method,
dat: v, dat: v,
extra: c.msg.ExtraFields,
}) })
if err != nil { if err != nil {
return err return err
......
...@@ -61,10 +61,6 @@ func (c *batchingRespWriter) Send(v any, e error) (err error) { ...@@ -61,10 +61,6 @@ func (c *batchingRespWriter) Send(v any, e error) (err error) {
return nil return nil
} }
func (c *batchingRespWriter) ExtraFields() jsonrpc.ExtraFields {
return c.msg.ExtraFields
}
func (c *batchingRespWriter) Notify(method string, v any) error { func (c *batchingRespWriter) Notify(method string, v any) error {
err := c.cr.mu.Acquire(c.ctx, 1) err := c.cr.mu.Acquire(c.ctx, 1)
if err != nil { if err != nil {
...@@ -74,7 +70,6 @@ func (c *batchingRespWriter) Notify(method string, v any) error { ...@@ -74,7 +70,6 @@ func (c *batchingRespWriter) Notify(method string, v any) error {
err = c.cr.notify(c.ctx, &notifyEnv{ err = c.cr.notify(c.ctx, &notifyEnv{
method: method, method: method,
dat: v, dat: v,
extra: c.msg.ExtraFields,
}) })
if err != nil { if err != nil {
return err return err
......
...@@ -132,7 +132,6 @@ func produceOutputMessage(inputMessage *jsonrpc.Message) (out *jsonrpc.Message, ...@@ -132,7 +132,6 @@ func produceOutputMessage(inputMessage *jsonrpc.Message) (out *jsonrpc.Message,
err = jsonrpc.NewInvalidRequestError("invalid request") err = jsonrpc.NewInvalidRequestError("invalid request")
} }
out = inputMessage out = inputMessage
out.ExtraFields = jsonrpc.ExtraFields{}
out.Error = nil out.Error = nil
// zero length method is always invalid request // zero length method is always invalid request
if len(out.Method) == 0 { if len(out.Method) == 0 {
...@@ -241,7 +240,6 @@ func (s *Server) serveBatch(ctx context.Context, ...@@ -241,7 +240,6 @@ func (s *Server) serveBatch(ctx context.Context,
v: v.payload, v: v.payload,
err: v.err, err: v.err,
id: v.msg.ID, id: v.msg.ID,
extrafields: v.msg.ExtraFields,
}) })
if err != nil { if err != nil {
return err return err
...@@ -288,7 +286,6 @@ type callEnv struct { ...@@ -288,7 +286,6 @@ type callEnv struct {
v any v any
err error err error
id *jsonrpc.ID id *jsonrpc.ID
extrafields jsonrpc.ExtraFields
} }
func (c *callResponder) send(ctx context.Context, env *callEnv) (err error) { func (c *callResponder) send(ctx context.Context, env *callEnv) (err error) {
...@@ -305,13 +302,6 @@ func (c *callResponder) send(ctx context.Context, env *callEnv) (err error) { ...@@ -305,13 +302,6 @@ func (c *callResponder) send(ctx context.Context, env *callEnv) (err error) {
e.Raw(env.id.RawMessage()) e.Raw(env.id.RawMessage())
}) })
} }
if env.extrafields != nil {
for k, v := range env.extrafields {
e.Field(k, func(e *jx.Encoder) {
e.Raw(v)
})
}
}
if env.err != nil { if env.err != nil {
e.Field("error", func(e *jx.Encoder) { e.Field("error", func(e *jx.Encoder) {
jsonrpc.EncodeError(e, env.err) jsonrpc.EncodeError(e, env.err)
...@@ -359,7 +349,6 @@ func (c *callResponder) send(ctx context.Context, env *callEnv) (err error) { ...@@ -359,7 +349,6 @@ func (c *callResponder) send(ctx context.Context, env *callEnv) (err error) {
type notifyEnv struct { type notifyEnv struct {
method string method string
dat any dat any
extra jsonrpc.ExtraFields
} }
func (c *callResponder) notify(ctx context.Context, env *notifyEnv) (err error) { func (c *callResponder) notify(ctx context.Context, env *notifyEnv) (err error) {
...@@ -373,7 +362,6 @@ func (c *callResponder) notify(ctx context.Context, env *notifyEnv) (err error) ...@@ -373,7 +362,6 @@ func (c *callResponder) notify(ctx context.Context, env *notifyEnv) (err error)
} else { } else {
msg.Params = buf.Bytes() msg.Params = buf.Bytes()
} }
msg.ExtraFields = env.extra
// add the method // add the method
msg.Method = env.method msg.Method = env.method
enc := jx.GetEncoder() enc := jx.GetEncoder()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment