You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Task]: Go SDK: coder.RegisterCoder needs more precise docstring #21930
coder.RegisterCoder should specify the accepted forms of the "enc" and "dec" arguments. Same for NewCustomCoder.
// 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.
// NewCustomCoder creates a coder for the supplied parameters defining a// particular encoding strategy.
The implementation seems to rely on this code:
funcvalidateEncoder(t reflect.Type, encodeinterface{}) error {
// Check if it uses the real type in question.iferr:=funcx.Satisfy(encode, funcx.Replace(encodeSig, typex.TType, t)); err!=nil {
returnerrors.WithContext(err, "validateEncoder: validating signature")
}
// TODO(lostluck): 2019.02.03 - Determine if there are encode allocation bottlenecks.returnnil
}
funcvalidateDecoder(t reflect.Type, decodeinterface{}) error {
// Check if it uses the real type in question.iferr:=funcx.Satisfy(decode, funcx.Replace(decodeSig, typex.TType, t)); err!=nil {
returnerrors.WithContext(err, "validateDecoder: validating signature")
}
// TODO(lostluck): 2019.02.03 - Expand cases to avoid []byte -> interface{} conversion// in exec, & a beam Decoder interface.returnnil
}
Aha, here is what I'm now seeing in the docs. This should at least be linked from the mentioned functions.
// CustomCoder contains possibly untyped encode/decode user functions that are// type-bound at runtime. Universal coders can thus be used for many different// types, but each CustomCoder instance will be bound to a specific type.typeCustomCoderstruct {
// Name is the coder name. Informational only.Namestring// Type is the underlying concrete type that is being coded. It is// available to Enc and Dec. It must be a concrete type.Type reflect.Type// Enc is the encoding function : T -> []byte. It may optionally take a// reflect.Type parameter and return an error as well.Enc*funcx.Fn// Dec is the decoding function: []byte -> T. It may optionally take a// reflect.Type parameter and return an error as well.Dec*funcx.FnIDstring// (optional) This coder's ID if translated from a pipeline proto.
}
changed the title [-][Feature Request]: Go SDK: coder.RegisterCoder needs more precise docstring[/-][+][Task]: Go SDK: coder.RegisterCoder needs more precise docstring[/+]on Jun 17, 2022
Made it a task instead of a new feature, as it's updating the documentation.
My main regret from that API is not making it a factory function. As it stands they need to be pure functions, or global state that needs to be made threadsafe. There's no other option.
Specifically, it's not possible to have "per coder" state, it's either no state or global, which means users have to ensure any state is thread safe, unlike everything else which allows bundle scoped state, which avoids the need for thread safety since an instance is only used by a single bundle at a time.
Activity
gonzojive commentedon Jun 17, 2022
Aha, here is what I'm now seeing in the docs. This should at least be linked from the mentioned functions.
[-][Feature Request]: Go SDK: coder.RegisterCoder needs more precise docstring[/-][+][Task]: Go SDK: coder.RegisterCoder needs more precise docstring[/+]lostluck commentedon Jun 17, 2022
Made it a task instead of a new feature, as it's updating the documentation.
My main regret from that API is not making it a factory function. As it stands they need to be pure functions, or global state that needs to be made threadsafe. There's no other option.
Specifically, it's not possible to have "per coder" state, it's either no state or global, which means users have to ensure any state is thread safe, unlike everything else which allows bundle scoped state, which avoids the need for thread safety since an instance is only used by a single bundle at a time.
Subramanya-Veeregowda commentedon Mar 24, 2026
i would like to work on this issue.IS it still open?
nitinware commentedon Sep 7, 2026
.take-issue
nitinware commentedon Sep 16, 2026
submitted pr: #40050 for fix of this issue.
Improve docstrings for coder.RegisterCoder and NewCustomCoder (#40050)