[Task]: Go SDK: coder.RegisterCoder needs more precise docstring
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 4.7k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 196
Description
### What would you like to happen?
[coder.RegisterCoder](https://pkg.go.dev/github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder#RegisterCoder) should specify the accepted forms of the "enc" and "dec" arguments. Same for `NewCustomCoder`.
```go
// RegisterCoder registers a user defined coder for a given type, and will
// be used if there is no beam coder for that type. Must be called prior to beam.Init(),
// preferably in an init() function.
//
// Coders are encoder and decoder pairs, and operate around []bytes.
//
// The coder used for a given type follows this ordering:
// 1. Coders for Known Beam types.
// 2. Coders registered for specific types
// 3. Coders registered for interfaces types
// 4. Default coder (JSON)
//
// Types of kind Interface, are handled specially by the registry, so they may be iterated
// over to check if element types implement them.
//
// Repeated registrations of the same type overrides prior ones.
```
```go
// NewCustomCoder creates a coder for the supplied parameters defining a
// particular encoding strategy.
```
The implementation seems to rely on this code:
```go
func validateEncoder(t reflect.Type, encode interface{}) error {
// Check if it uses the real type in question.
if err := funcx.Satisfy(encode, funcx.Replace(encodeSig, typex.TType, t)); err != nil {
return errors.WithContext(err, "validateEncoder: validating signature")
}
// TODO(lostluck): 2019.02.03 - Determine if there are encode allocation bottlenecks.
return nil
}
func validateDecoder(t reflect.Type, decode interface{}) error {
// Check if it uses the real type in question.
if err := funcx.Satisfy(decode, funcx.Replace(decodeSig, typex.TType, t)); err != nil {
return errors.WithContext(err, "validateDecoder: validating signature")
}
// TODO(lostluck): 2019.02.03 - Expand cases to avoid []byte -> interface{} conversion
// in exec, & a beam Decoder interface.
return nil
}
```
### Issue Priority
Priority: 2
### Issue Component
Component: sdk-go
Contributor guide
Assessment
This issue has not been assessed yet.