-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/gob: unable to encode constant.Value with default encoder #56696
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
Comments
Your snippet is not complete. For example, there is no definition for ConstantValue. |
Sorry about that, @robpike. I've added the struct definition. |
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 |
I know about gob.Register, but the implementing classes aren’t visible to be registerable, @robpike @seankhliao |
@seankhliao - did you see my example? Just curious if you've closed this issue as "gob encode/decode of |
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
The text was updated successfully, but these errors were encountered: