Skip to content

Commit f42ab36

Browse files
encoding/gob: add RegisteredNames()
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. Relates: #67401 Closes: #71602
1 parent 7a2f757 commit f42ab36

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Diff for: src/encoding/gob/type.go

+11
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,17 @@ func Register(value any) {
899899
RegisterName(name, value)
900900
}
901901

902+
// RegisteredNames is list of registered type names that registered
903+
// with [Register] or [RegisterName] methods
904+
func RegisteredNames() []string {
905+
var val []string
906+
nameToConcreteType.Range(func(k, v any) bool {
907+
val = append(val, k.(string))
908+
return true
909+
})
910+
return val
911+
}
912+
902913
func registerBasics() {
903914
Register(int(0))
904915
Register(int8(0))

Diff for: src/encoding/gob/type_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,10 @@ func TestTypeRace(t *testing.T) {
260260
close(c)
261261
wg.Wait()
262262
}
263+
264+
func TestRegisteredNames(t *testing.T) {
265+
names := RegisteredNames()
266+
if len(names) < 34 {
267+
t.Errorf("registered names should contains all primitive type")
268+
}
269+
}

0 commit comments

Comments
 (0)