Newer
Older
json "github.com/goccy/go-json"
var jpool = jsoniter.NewIterator(jsoniter.ConfigCompatibleWithStandardLibrary).Pool()
RequestMarshaling
ctx context.Context
}
func (r *Request) UnmarshalJSON(xs []byte) error {
return json.Unmarshal(xs, &r.RequestMarshaling)
}
func (r *Request) MarshalJSON() ([]byte, error) {
return json.Marshal(r.RequestMarshaling)
}
type RequestMarshaling struct {
func NewRequestInt(ctx context.Context, id int, method string, params any) *Request {
r := &Request{ctx: ctx}
pms, _ := json.Marshal(params)
r.ID = codec.NewNumberIDPtr(int64(id))
r.Method = method
r.Params = pms
return r
Edward Lee
committed
func NewRequest(ctx context.Context, id string, method string, params any) *Request {
r := &Request{ctx: ctx}
pms, _ := json.Marshal(params)
func (r *Request) errorResponse(err error) *Response {
mw := NewReaderResponseWriterMsg(r)
mw.Send(nil, err)
return mw.Response()
}
func (r *Request) isNotification() bool {
return r.ID == nil && len(r.Method) > 0
}
func (r *Request) isCall() bool {
return r.hasValidID() && len(r.Method) > 0
}
func (r *Request) ParamArray(a ...any) error {
var params []json.RawMessage
err := json.Unmarshal(v, &a[idx])
if err != nil {
return err
}
} else {
break
}
}
return nil
}
Edward Lee
committed
}
Edward Lee
committed
}
func (r *Request) WithContext(ctx context.Context) *Request {
if ctx == nil {
panic("nil context")
}
r.ctx = ctx
r2 := new(Request)
*r2 = *r
r2.ctx = ctx
r2.ID = r.ID
r2.Method = r.Method
r2.Params = r.Params
r2.Peer = r.Peer
Edward Lee
committed
func (r *Request) Iter(fn func(j *jsoniter.Iterator) error) error {