Skip to content

proposal: encoding/gob: RegisteredTypes method #71602

Open
@laskoviymishka

Description

Proposal Details

Description:

Starting from Go 1.23, direct access to encoding/gob.nameToConcreteType is no longer possible due to the removal of internal symbol linking. While this change improves encapsulation, it also removes the ability to retrieve a list of all registered types in the gob package.

I propose adding a new function:

func RegisteredTypes() iter.Seq2[string, reflect.Type]

Use Case

Many applications rely on reflection or introspection to determine which types have been registered with gob.Register. Without access to this list, debugging serialization issues or dynamically inspecting registered types becomes more difficult.

For example here is how we track that gob.Registry is stable (since we rely on it to communicate between worker and agent). Agent and worker may be a separate binaries, so if agent has some missed type in registry - it will fail to start.

var nameToConcreteType sync.Map // map[string]reflect.Type

func RegisteredTypes() iter.Seq2[string, reflect.Type] {
	return func(yield func(string, reflect.Type) bool) {
		nameToConcreteType.Range(func(k, v any) bool {
			return yield(k.(string), v.(reflect.Type))
		})
	}
}

Instead of this, there would be a dedicated gob.RegisteredTypes with all binary known types.

Proposed Implementation

Internally, gob.Register already maintains a map of registered types. The new RegisteredTypes function would simply iterate over this map and return a list of registered types with their names.

Alternative Workarounds

Currently, developers need to maintain their own registry manually, which adds extra level of abstraction on top of gob.Register with unnecessary complexity and risks inconsistency.

Would the Go team consider adding this function to restore this functionality in an officially supported way?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    • Status

      Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions