| 1 |
// Copyright 2022 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package a |
| 6 |
|
| 7 |
type MarshalOptions struct { |
| 8 |
*typedArshalers[MarshalOptions] |
| 9 |
} |
| 10 |
|
| 11 |
func Marshal(in interface{}) (out []byte, err error) { |
| 12 |
return MarshalOptions{}.Marshal(in) |
| 13 |
} |
| 14 |
|
| 15 |
func (mo MarshalOptions) Marshal(in interface{}) (out []byte, err error) { |
| 16 |
err = mo.MarshalNext(in) |
| 17 |
return nil, err |
| 18 |
} |
| 19 |
|
| 20 |
func (mo MarshalOptions) MarshalNext(in interface{}) error { |
| 21 |
a := new(arshaler) |
| 22 |
a.marshal = func(MarshalOptions) error { return nil } |
| 23 |
return a.marshal(mo) |
| 24 |
} |
| 25 |
|
| 26 |
type arshaler struct { |
| 27 |
marshal func(MarshalOptions) error |
| 28 |
} |
| 29 |
|
| 30 |
type typedArshalers[Options any] struct { |
| 31 |
m M |
| 32 |
} |
| 33 |
|
| 34 |
func (a *typedArshalers[Options]) lookup(fnc func(Options) error) (func(Options) error, bool) { |
| 35 |
a.m.Load(nil) |
| 36 |
return fnc, false |
| 37 |
} |
| 38 |
|
| 39 |
type M struct {} |
| 40 |
|
| 41 |
func (m *M) Load(key any) (value any, ok bool) { |
| 42 |
return |
| 43 |
} |