// Register with gob so that DeepCopy can recognize all of our objects. This is creating a static list, but it appears that gob itself wants a static list
// Register with gob so that DeepCopy can recognize all of our objects. This is creating a static list, but it appears that gob itself wants a static list
gobName:=getGobTypeName(obj)
gob.RegisterName(gobName,obj)
}
// getGobTypeName creates a fully unique type name for the object being passed through. There is a bug in the gob encoder's name mechanism that they are unwilling to fix
// due to backwards compatibility concerns. See https://github.com/golang/go/blob/master/src/encoding/gob/type.go#L857 . This gives us a fully qualified name to avoid
// conflicts amongst our objects and since we all agree on the names, this should be safe
funcgetGobTypeName(valueinterface{})string{
// mostly copied from gob/type.go
// Default to printed representation for unnamed types
rt:=reflect.TypeOf(value)
name:=rt.String()
// But for named types (or pointers to them), qualify with import path (but see inner comment).
// Dereference one pointer looking for a named type.
star:=""
ifrt.Name()==""{
ifpt:=rt;pt.Kind()==reflect.Ptr{
star="*"
// NOTE: The following line should be rt = pt.Elem() to implement
// what the comment above claims, but fixing it would break compatibility
// with existing gobs.
//
// Given package p imported as "full/p" with these definitions:
// package p
// type T1 struct { ... }
// this table shows the intended and actual strings used by gob to
// name the types:
//
// Type Correct string Actual string
//
// T1 full/p.T1 full/p.T1
// *T1 *full/p.T1 *p.T1
//
// The missing full path cannot be fixed without breaking existing gob decoders.
rt=pt.Elem()// TWEAKED HERE
}
}
ifrt.Name()!=""{
ifrt.PkgPath()==""{
name=star+rt.Name()
}else{
name=star+rt.PkgPath()+"."+rt.Name()
}
}
returnname
}
// KnownTypes returns an array of the types that are known for a particular version.