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

encoding/gob: unable to encode constant.Value with default encoder #56696

Closed
JamesRTaylor opened this issue Nov 11, 2022 · 7 comments
Closed
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@JamesRTaylor
Copy link

JamesRTaylor commented Nov 11, 2022

What version of Go are you using (go version)?

go1.18.3

Does this issue reproduce with the latest release?

Unknown

What operating system and processor architecture are you using (go env)?

darwin/arm64

What did you do?

type ConstantValue struct {
Value constant.Value
}

func EnocdeDecodeRoundtrip(value ConstantValue) {
var b bytes.Buffer
e := gob.NewEncoder(&b)
if err := e.Encode(&value); err != nil {
panic(err)
}
var decodedValue ConstantValue
d := gob.NewDecoder(&b)
if err := d.Decode(&decodedValue); err != nil {
panic(err)
}
if value.Value.ExactString() != decodedValue.Value.ExactString() {
err := fmt.Errorf("Decoded value not the same as original. Expected %s, but got %s",
value.Value.ExactString(), decodedValue.Value.ExactString())
panic(err)
}
}

func TestConstantValueGobEncoding(t *testing.T) {
field := ConstantValue{constant.Make(int64(1))}
EnocdeDecodeRoundtrip(field)
}

What did you expect to see?

Expected to be able to encode and decode constant.Value

What did you see instead?

panic: gob: type not registered for interface: constant.int64Val

Workaround

I'm able to workaround the issue by creating a custom encoder, but it's a bit painful

@mengzhuo mengzhuo changed the title gob/encoding: unable to encode constant.Value with default encoder encoding/gob: unable to encode constant.Value with default encoder Nov 11, 2022
@robpike
Copy link
Contributor

robpike commented Nov 11, 2022

Your snippet is not complete. For example, there is no definition for ConstantValue.
Please provide a self-contained executable example to demonstrate the problem.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 11, 2022
@JamesRTaylor
Copy link
Author

Sorry about that, @robpike. I've added the struct definition.

@seankhliao
Copy link
Member

See https://pkg.go.dev/encoding/gob#Register

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2022
@JamesRTaylor
Copy link
Author

I know about gob.Register, but the implementing classes aren’t visible to be registerable, @robpike @seankhliao

@seankhliao
Copy link
Member

@JamesRTaylor
Copy link
Author

@JamesRTaylor
Copy link
Author

@seankhliao - did you see my example? Just curious if you've closed this issue as "gob encode/decode of constant.Value isn't supported" or if you're theorizing that it works? Without writing custom encoding/decoding methods for anything that contains a constant.Value, I'm not able to get it to work.

@golang golang locked and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants