-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry.go
More file actions
40 lines (34 loc) · 2 KB
/
Copy pathregistry.go
File metadata and controls
40 lines (34 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package gobspect
// registerBuiltins pre-registers all built-in opaque decoders on ins.
// Called by New() before applying user options, so any RegisterDecoder call
// after New() will override a built-in for that type name.
func registerBuiltins(ins *Inspector) {
// time.Time: implements GobEncoder (via GobEncode → MarshalBinary).
// The gob wire type uses CommonType.Name = "Time" (reflect.Type.Name()).
ins.decoders["Time"] = decodeTime
// math/big.Int and math/big.Rat both have TypeName="" in the gob wire
// when encoded directly, because they use pointer receivers and gob sets
// CommonType.Name = reflect.Type.Name() on the pointer type, which is "".
// A format-based heuristic distinguishes them at decode time.
// Registered as an unnamed decoder so user-registered unnamed decoders
// tried before it can override the behavior for a specific application.
ins.RegisterUnnamedDecoder(decodeBigAuto)
// uuid.UUID (github.com/google/uuid and github.com/gofrs/uuid).
// TypeName will be "uuid.UUID" when the type is encoded via an interface
// and registered with gob.Register.
ins.decoders["uuid.UUID"] = decodeUUID
// math/big.Float: registered under a descriptive key for callers who know
// the concrete type. Because *big.Float uses a pointer receiver for
// GobEncode, the wire TypeName is "" just like big.Int and big.Rat, so
// auto-detection via this key is not possible without explicit registration.
ins.decoders["math/big.Float"] = decodeBigFloat
// shopspring/decimal.Decimal: two common import-path aliases are registered
// so callers can look up the decoder regardless of which alias is in use.
ins.decoders["decimal.Decimal"] = decodeShopspringDecimal
ins.decoders["shopspring/decimal.Decimal"] = decodeShopspringDecimal
// net/netip types (BinaryMarshaler). TypeName is the CommonType.Name
// the gob encoder produces for each type.
ins.decoders["netip.Addr"] = decodeNetipAddr
ins.decoders["netip.Prefix"] = decodeNetipPrefix
ins.decoders["netip.AddrPort"] = decodeNetipAddrPort
}