3
3
"github.com/chromedp/cdproto-gen/pdl"
4
4
) %}
5
5
6
- // ExtraTimestampTemplate is a special template for the Timestamp type that
6
+ // ExtraTimestampTemplate is a special template for the [ Timestamp] type that
7
7
// defines its JSON unmarshaling.
8
8
{% func ExtraTimestampTemplate(t *pdl.Type, d *pdl.Domain) %}{%code
9
9
typ := t.Name
@@ -24,28 +24,21 @@ func init() {
24
24
}
25
25
{% endif %}
26
26
27
- // MarshalEasyJSON satisfies easyjson.Marshaler .
28
- func (t {%s= typ %}) MarshalEasyJSON(out *jwriter.Writer ) {
27
+ // MarshalText satisfies [encoding.TextMarshaler] .
28
+ func (t {%s= typ %}) MarshalText() ([]byte, error ) {
29
29
v := {% if monotonic %}float64(time.Time(t).Sub(*{%s= typ %}Epoch))/float64(time.Second){% else %}float64(time.Time(t).UnixNano()/int64({%s= timeRes %})){% endif %}
30
-
31
- out.Buffer.EnsureSpace(20)
32
- out.Buffer.Buf = strconv.AppendFloat(out.Buffer.Buf, v, 'f', -1, 64)
33
- }
34
-
35
- // MarshalJSON satisfies json.Marshaler.
36
- func (t {%s= typ %}) MarshalJSON() ([]byte, error) {
37
- return easyjson.Marshal(t)
38
- }
39
-
40
- // UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
41
- func (t *{%s= typ %}) UnmarshalEasyJSON(in *jlexer.Lexer) {{% if monotonic %}
42
- *t = {%s= typ %}({%s= typ %}Epoch.Add(time.Duration(in.Float64()*float64(time.Second)))){% else %}
43
- *t = {%s= typ %}(time.Unix(0, int64(in.Float64()*float64({%s= timeRes %})))){% endif %}
30
+ return strconv.AppendFloat(make([]byte, 20), v, 'f', -1, 64), nil
44
31
}
45
32
46
- // UnmarshalJSON satisfies json.Unmarshaler.
47
- func (t *{%s= typ %}) UnmarshalJSON(buf []byte) error {
48
- return easyjson.Unmarshal(buf, t)
33
+ // UnmarshalText satisfies [encoding.TextUnmarshaler].
34
+ func (t *{%s= typ %}) UnmarshalText(buf []byte) error {
35
+ f, err := strconv.ParseFloat(string(buf), 64)
36
+ if err != nil {
37
+ return err
38
+ }{% if monotonic %}
39
+ *t = {%s= typ %}({%s= typ %}Epoch.Add(time.Duration(f*float64(time.Second)))){% else %}
40
+ *t = {%s= typ %}(time.Unix(0, int64(f*float64({%s= timeRes %})))){% endif %}
41
+ return nil
49
42
}
50
43
{% endfunc %}
51
44
@@ -333,40 +326,32 @@ const EmptyNodeID = NodeID(0)
333
326
334
327
// ExtraFixStringUnmarshaler is a template that forces values to be parsed properly.
335
328
{% func ExtraFixStringUnmarshaler(typ, parseFunc, extra string) %}
336
- // UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
337
- func (t *{%s= typ %}) UnmarshalEasyJSON(in *jlexer.Lexer) {
338
- buf := in.Raw()
329
+ // UnmarshalText satisfies [encoding.TextUnmarshaler].
330
+ func (t *{%s= typ %}) UnmarshalText(buf []byte) error {
339
331
if l := len(buf); l > 2 && buf[0] == '"' && buf[l-1] == '"' {
340
332
buf = buf[1:l-1]
341
333
}
342
334
{% if parseFunc != "" %}
343
335
v, err := strconv.{%s= parseFunc %}(string(buf){%s= extra %})
344
336
if err != nil {
345
- in.AddError( err)
337
+ return err
346
338
}
347
339
{% endif %}
348
340
*t = {%s= typ %}({% if parseFunc != "" %}v{% else %}buf{% endif %})
349
- }
350
-
351
- // UnmarshalJSON satisfies json.Unmarshaler.
352
- func (t *{%s= typ %}) UnmarshalJSON(buf []byte) error {
353
- return easyjson.Unmarshal(buf, t)
341
+ return nil
354
342
}
355
343
{% endfunc %}
356
344
357
345
358
346
// ExtraCookiePartitionKeyUnmarshaler is a template that handles unmarshaling
359
347
// Network.CookiePartitionKey.
360
348
{% func ExtraCookiePartitionKeyUnmarshaler(typ string) %}
361
- // UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
362
- func (t *{%s= typ %}) UnmarshalEasyJSONZZ(in *jlexer.Lexer) {
363
- buf := in.Raw()
349
+ // UnmarshalText satisfies [encoding.TextUnmarshaler].
350
+ func (t *{%s= typ %}) UnmarshalText(buf []byte) error {
364
351
if l := len(buf); l > 2 && buf[0] == '"' && buf[l-1] == '"' {
365
352
var err error
366
- if t.TopLevelSite, err = strconv.Unquote(string(buf)); err != nil {
367
- in.AddError(err)
368
- }
369
- return
353
+ t.TopLevelSite, err = strconv.Unquote(string(buf));
354
+ return err
370
355
}
371
356
dec := json.NewDecoder(bytes.NewReader(buf))
372
357
dec.DisallowUnknownFields()
@@ -375,10 +360,10 @@ func (t *{%s= typ %}) UnmarshalEasyJSONZZ(in *jlexer.Lexer) {
375
360
HasCrossSiteAncestor bool `json:"hasCrossSiteAncestor"`
376
361
}
377
362
if err := dec.Decode(&v); err != nil {
378
- in.AddError( err)
379
- } else {
380
- t.TopLevelSite, t.HasCrossSiteAncestor = v.TopLevelSite, v.HasCrossSiteAncestor
381
- }
363
+ return err
364
+ }
365
+ t.TopLevelSite, t.HasCrossSiteAncestor = v.TopLevelSite, v.HasCrossSiteAncestor
366
+ return nil
382
367
}
383
368
{% endfunc %}
384
369
@@ -389,7 +374,7 @@ func (t *{%s= typ %}) UnmarshalEasyJSONZZ(in *jlexer.Lexer) {
389
374
// Executor is the common interface for executing a command.
390
375
type Executor interface {
391
376
// Execute executes the command.
392
- Execute(context.Context, string, easyjson.Marshaler, easyjson.Unmarshaler ) error
377
+ Execute(context.Context, string, any, any ) error
393
378
}
394
379
395
380
// contextKey is the context key type.
@@ -412,7 +397,7 @@ func ExecutorFromContext(ctx context.Context) Executor {
412
397
413
398
// Execute uses the context's message executor to send a command or event
414
399
// method marshaling the provided parameters, and unmarshaling to res.
415
- func Execute(ctx context.Context, method string, params easyjson.Marshaler , res easyjson.Unmarshaler ) error {
400
+ func Execute(ctx context.Context, method string, params, res any ) error {
416
401
if executor := ctx.Value(executorKey); executor != nil {
417
402
return executor.(Executor).Execute(ctx, method, params, res)
418
403
}
@@ -465,37 +450,31 @@ type empty struct{}
465
450
var emptyVal = &empty{}
466
451
467
452
// UnmarshalMessage unmarshals the message result or params.
468
- func UnmarshalMessage(msg *Message) (interface{} , error) {
469
- var v easyjson.Unmarshaler
453
+ func UnmarshalMessage(msg *Message) (any , error) {
454
+ var v any
470
455
switch msg.Method {{% for _, d := range domains %}{% for _, c := range d.Commands %}
471
456
case {%s= CommandMethodType(c, d) %}:{% if len(c.Returns) == 0 %}
472
457
return emptyVal, nil{% else %}
473
- v = new({%s= genutil.PackageName(d) %}.{%s= CommandReturnsType(c) %}){% endif %}
474
- {% endfor %}{% for _, e := range d.Events %}
458
+ v = new({%s= genutil.PackageName(d) %}.{%s= CommandReturnsType(c) %}){% endif %}{% endfor %}{% for _, e := range d.Events %}
475
459
case {%s= EventMethodType(e, d) %}:
476
- v = new({%s= genutil.PackageName(d) %}.{%s= EventType(e) %})
477
- {% endfor %}{% endfor %}
460
+ v = new({%s= genutil.PackageName(d) %}.{%s= EventType(e) %}){% endfor %}
461
+ {% endfor %}
478
462
default:
479
463
return nil, cdp.ErrUnknownCommandOrEvent(msg.Method)
480
464
}
481
465
482
- var buf easyjson.RawMessage
466
+ var buf jsontext.Value
483
467
switch {
484
468
case msg.Params != nil:
485
469
buf = msg.Params
486
-
487
470
case msg.Result != nil:
488
471
buf = msg.Result
489
-
490
472
default:
491
473
return nil, cdp.ErrMsgMissingParamsOrResult
492
474
}
493
-
494
- err := easyjson.Unmarshal(buf, v)
495
- if err != nil {
475
+ if err := jsonv2.Unmarshal(buf, v); err != nil {
496
476
return nil, err
497
477
}
498
-
499
478
return v, nil
500
479
}
501
480
{% endfunc %}
0 commit comments