Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: encoding/gob: Preserve object tree when serializing / deserializing #30285

Closed
lhhong opened this issue Feb 17, 2019 · 1 comment
Closed

Comments

@lhhong
Copy link

lhhong commented Feb 17, 2019

Motivation

Consider using gob in the following scenario

type A struct {
    BVal *B
    CVal *C
}
type B struct {
    CVal *C
}
type C int

var originalC C = 3
originalB := &B{CVal: &originalC}
originalA := A{BVal: originalB, CVal: &originalC}

newA := **Serialize and Deserialize with gob**(originalA)

CVal in originalA is pointing to the same address as CVal in originalB. However, CVal in newA and newB would be a copy of each other without sharing the same address. It would be nice if the references are preserved when serializing.

Justification

Preservation of these references will be useful when using gob on data structures relying on the object tree. These could be indexes to data, efficient storage of data, etc. There will sometimes be the need to persists these data structures to disk or transmit them to another go runtime, most conveniently performed with gob. It could also potentially reduce payload of the serialized data as repetitions could be omitted.

@gopherbot gopherbot added this to the Proposal milestone Feb 17, 2019
@rsc
Copy link
Contributor

rsc commented Feb 27, 2019

It would be nice but it is not how gob is defined. It is also a fair amount more expensive. Probably if you need non-tree data structures you should use a different encoder. The definition of gob is basically fixed (immutable) at this point.

@rsc rsc closed this as completed Feb 27, 2019
@golang golang locked and limited conversation to collaborators Feb 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants