存储和检索接口的字节表示形式

I have a need to store and retrieve the byte representation of interface{} values. To clarify i'm not trying to store the underlying values packed into a slice, whatever size they may be, but looking for a way to store pointers to said values.

The reason I can't just go type MyType interface{}; var arr []MyType is because I am packing non uniform amounts of other bytes within this array.

To implement this I am looking at the reflect and unsafe packages, and I see methods like UnsafeAddr which return a pointer. Could I use store that pointer and then decode it back into my interface{} value later?

Another function I see is InterfaceData which gives back a 2 byte array representation, but is there any way to turn that back into an interface value again?

My high level goal is this:

// store the pointer to dataIn in the slice b
func putPtr(b []byte, dataIn interface{}) { ... }

// return the pointed to interface value from within b
func getInter(b []byte) interface{} { ... }

Whatever reason you have for this, it is guaranteed to not work in the general case. Once you hide a pointer from the garbage collector (GC) awareness and then reincarnate it by any trick possible, it (the pointer) may be not valid anymore. It's the whole principle how the GC works.

To bypass this failure, one has to keep the pointer visible to the GC elsewhere, it must remain reachable for the GC not to collect it at any (unpredictable) moment.

But if one has a normal and reachable representation of the pointer available then there really is no need for any other (like encoded in []byte) representation in the first place