FAQ
Hi all,

I am running into a problem with gob with some code. A simplified
example is here:

https://play.golang.org/p/hx8A5iqF-p

From the gob documentation:

"Pointers are not transmitted, but the things they point to are
transmitted; that is, the values are flattened. [...] Interface values
are transmitted as a string identifying the concrete type being sent
(a name that must be pre-defined by calling Register), followed by a
byte count of the length of the following data"

So, it is clear why decoding does not work: while encoding the only
slice member, the value is flattened. In the gob, Foo is stored and
not *Foo. During decoding, the assignability check fails, because
Frob() is implemented on Foo and not Foo. The decoding problem is
easily fixed by implementing Frob() on Foo.

But what if I actually only want to implement Frob() with a pointer
receiver? Wouldn't it make sense if gob tried if taking the address of
the value would fulfil the interface when the value doesn't fulfil the
interface? Or am I missing something?

Kind regards,
Daniël de Kok

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Daniël de Kok at Aug 31, 2015 at 9:42 am

    On Fri, Aug 28, 2015 at 11:13 AM, Daniël de Kok wrote:
    So, it is clear why decoding does not work: while encoding the only
    slice member, the value is flattened. In the gob, Foo is stored and
    not *Foo. During decoding, the assignability check fails, because
    Frob() is implemented on Foo and not Foo.
    s/implemented on Foo/implemented on *Foo/

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 28, '15 at 9:14a
activeAug 31, '15 at 9:42a
posts2
users1
websitegolang.org

1 user in discussion

Daniël de Kok: 2 posts

People

Translate

site design / logo © 2021 Grokbase