FAQ
Hi,

I'm trying to use Gob to save some data structures. It seems to be really
clean, which is very nice. However, I'm getting an error involving
interfaces, and I'm not sure how to fix the issue. The relevant piece of
code is http://play.golang.org/p/daRidNhjuL (Though the actual code is more
complicated)


Running it like this, I get the error,
gob: local interface type *nnet.reshaper can only be decoded from remote
interface type; received concrete type sigmoidneuron = struct { }

The gob package doc says "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 the value can be skipped if it cannot be stored),
followed by the usual encoding of concrete (dynamic) value stored in the
interface value."

I also found a "working as intended" issue which gives the code
http://play.golang.org/p/FO3hNdzRkL

Is there a way to dynamically register the underlying types of the
interface value as I encode them? I tried

gob.Register(neur.reshaper)

gob.Register(& neur.reshaper)

gob.Register(reflect.ValueOf(neur.reshaper))

and

gob.Register(reflect.TypeOf(neur.reshaper))

None of which work. It even did not work when I added

gob.Register(&sigmoidneuron{})

gob.Register(&linearneuron{})

To all of the places where gob is active as in

http://play.golang.org/p/3WHq789HtH

I'm confused. Thanks

--
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/groups/opt_out.

Search Discussions

  • Steven Blenkinsop at Feb 26, 2013 at 4:10 am
    http://play.golang.org/p/vDde_rjoPc

    See lines 39 and 57. 57 is just registering the concrete type. The problem
    on line 39 was this:

    var i interface{} = neur.reshaper

    i is now an interface{} containing a *sigmoidneuron. There's no way to know
    that the value assigned to i was a reshaper. If you want to preserve the
    interface, you have to use a pointer to it:

    var i interface{} = &neur.reshaper

    i is now an interface{} containing a *reshaper which points to a reshaper
    containing a *sigmoidneuron.


    On Mon, Feb 25, 2013 at 10:12 PM, Brendan Tracey
    wrote:
    Hi,

    I'm trying to use Gob to save some data structures. It seems to be really
    clean, which is very nice. However, I'm getting an error involving
    interfaces, and I'm not sure how to fix the issue. The relevant piece of
    code is http://play.golang.org/p/daRidNhjuL (Though the actual code is
    more complicated)


    Running it like this, I get the error,
    gob: local interface type *nnet.reshaper can only be decoded from remote
    interface type; received concrete type sigmoidneuron = struct { }

    The gob package doc says "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 the value can be skipped if it cannot be stored),
    followed by the usual encoding of concrete (dynamic) value stored in the
    interface value."

    I also found a "working as intended" issue which gives the code
    http://play.golang.org/p/FO3hNdzRkL

    Is there a way to dynamically register the underlying types of the
    interface value as I encode them? I tried

    gob.Register(neur.reshaper)

    gob.Register(& neur.reshaper)

    gob.Register(reflect.ValueOf(neur.reshaper))

    and

    gob.Register(reflect.TypeOf(neur.reshaper))

    None of which work. It even did not work when I added

    gob.Register(&sigmoidneuron{})

    gob.Register(&linearneuron{})

    To all of the places where gob is active as in

    http://play.golang.org/p/3WHq789HtH

    I'm confused. Thanks

    --
    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/groups/opt_out.

    --
    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/groups/opt_out.
  • Brendan Tracey at Feb 26, 2013 at 4:50 am
    Ahhh, that makes sense. Works great now, thanks!
    On Monday, February 25, 2013 8:10:19 PM UTC-8, Steven Blenkinsop wrote:

    http://play.golang.org/p/vDde_rjoPc

    See lines 39 and 57. 57 is just registering the concrete type. The problem
    on line 39 was this:

    var i interface{} = neur.reshaper

    i is now an interface{} containing a *sigmoidneuron. There's no way to
    know that the value assigned to i was a reshaper. If you want to preserve
    the interface, you have to use a pointer to it:

    var i interface{} = &neur.reshaper

    i is now an interface{} containing a *reshaper which points to a reshaper
    containing a *sigmoidneuron.


    On Mon, Feb 25, 2013 at 10:12 PM, Brendan Tracey <tracey....@gmail.com<javascript:>
    wrote:
    Hi,

    I'm trying to use Gob to save some data structures. It seems to be really
    clean, which is very nice. However, I'm getting an error involving
    interfaces, and I'm not sure how to fix the issue. The relevant piece of
    code is http://play.golang.org/p/daRidNhjuL (Though the actual code is
    more complicated)


    Running it like this, I get the error,
    gob: local interface type *nnet.reshaper can only be decoded from remote
    interface type; received concrete type sigmoidneuron = struct { }

    The gob package doc says "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 the value can be skipped if it cannot be stored),
    followed by the usual encoding of concrete (dynamic) value stored in the
    interface value."

    I also found a "working as intended" issue which gives the code
    http://play.golang.org/p/FO3hNdzRkL

    Is there a way to dynamically register the underlying types of the
    interface value as I encode them? I tried

    gob.Register(neur.reshaper)

    gob.Register(& neur.reshaper)

    gob.Register(reflect.ValueOf(neur.reshaper))

    and

    gob.Register(reflect.TypeOf(neur.reshaper))

    None of which work. It even did not work when I added

    gob.Register(&sigmoidneuron{})

    gob.Register(&linearneuron{})

    To all of the places where gob is active as in

    http://play.golang.org/p/3WHq789HtH

    I'm confused. Thanks

    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 26, '13 at 3:12a
activeFeb 26, '13 at 4:50a
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase