EOF when decoding with gob

1,259 views
Skip to first unread message

Jacob Arthur

unread,
Nov 14, 2013, 5:36:50 PM11/14/13
to golan...@googlegroups.com
I have been trying to figure out how to do some local persistence using gob encoding to a file.

Whenever I use normal types everything seems fine. If I try to use a struct whenever I try to decode the file it throws an EOF error and the decoding fails.
I'm guessing I just don't understand how to register my type with the gob package, I tried giving it an 'empty' value but still failed.

http://play.golang.org/p/Ega0ZCnJJb
[I removed all other error checking to demo where I am getting the error]

Thanks,
Jacob


Dan Kortschak

unread,
Nov 14, 2013, 5:47:31 PM11/14/13
to Jacob Arthur, golan...@googlegroups.com
gob depends on reflect, which in turn depends on publication of fields.
Your type's fields are not public. This fixes the problem:
http://play.golang.org/p/7L_8F2NAeY

Jacob Arthur

unread,
Nov 14, 2013, 5:49:05 PM11/14/13
to golan...@googlegroups.com, Jacob Arthur
Great! Thank you!
Reply all
Reply to author
Forward
0 new messages