FAQ
Hi,

I'm integrating with an existing code base that passes events around using
RPC. The event can have a payload of type interface{} and I want to use
that payload for calling methods on an RPC style interface on the other end
of the RPC endpoint. The problem is that type information is lost during
the intermediate serialization. I've created an example of what I'm talking
about:

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

I use reflection to create a value of the right type for the given method.
When I attempt to decode the value into a pointer of that type I get the
following error:

could not decode: gob: type mismatch in decoder: want struct type main.Obj;
got non-struct

It appears as though I have the right type so I'm not sure where I'm going
wrong. Any help would be greatly appreciated.

Regards,
Daniel

--
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

  • Djherbis at Mar 31, 2015 at 1:47 am
    The type that you are gob-encoding is a map[string]interface{}, you're
    trying to decode into a *main.Obj. The decoder is complaining that it was
    expecting a main.Obj (since that's what you asked it to decode), but it
    found a map (a non-struct) instead.
    On Monday, March 30, 2015 at 8:54:15 PM UTC-4, Daniel Garcia wrote:

    Hi,

    I'm integrating with an existing code base that passes events around using
    RPC. The event can have a payload of type interface{} and I want to use
    that payload for calling methods on an RPC style interface on the other end
    of the RPC endpoint. The problem is that type information is lost during
    the intermediate serialization. I've created an example of what I'm talking
    about:

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

    I use reflection to create a value of the right type for the given method.
    When I attempt to decode the value into a pointer of that type I get the
    following error:

    could not decode: gob: type mismatch in decoder: want struct type
    main.Obj; got non-struct

    It appears as though I have the right type so I'm not sure where I'm going
    wrong. Any help would be greatly appreciated.

    Regards,
    Daniel
    --
    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.
  • Daniel Garcia at Mar 31, 2015 at 2:04 pm
    Hi,

    On Monday, March 30, 2015 at 8:47:49 PM UTC-5, djhe...@gmail.com wrote:

    The type that you are gob-encoding is a map[string]interface{}, you're
    trying to decode into a *main.Obj. The decoder is complaining that it was
    expecting a main.Obj (since that's what you asked it to decode), but it
    found a map (a non-struct) instead.
    Thanks for your help. I was clearly misinterpreting the error message and
    confusing the datatype of reflected argument with the concrete arg. I'm all
    fixed up.

    Regards,
    Daniel

    --
    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.
  • Djherbis at Mar 31, 2015 at 1:51 am
    Here's one way you could decode the object you
    want: http://play.golang.org/p/ln9esJ2X6Q

    I only made changes near the end of your main since I'm assuming the stuff
    above it is connected to the existing RPC stuff you can't change.
    On Monday, March 30, 2015 at 8:54:15 PM UTC-4, Daniel Garcia wrote:

    Hi,

    I'm integrating with an existing code base that passes events around using
    RPC. The event can have a payload of type interface{} and I want to use
    that payload for calling methods on an RPC style interface on the other end
    of the RPC endpoint. The problem is that type information is lost during
    the intermediate serialization. I've created an example of what I'm talking
    about:

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

    I use reflection to create a value of the right type for the given method.
    When I attempt to decode the value into a pointer of that type I get the
    following error:

    could not decode: gob: type mismatch in decoder: want struct type
    main.Obj; got non-struct

    It appears as though I have the right type so I'm not sure where I'm going
    wrong. Any help would be greatly appreciated.

    Regards,
    Daniel
    --
    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
postedMar 31, '15 at 12:54a
activeMar 31, '15 at 2:04p
posts4
users2
websitegolang.org

2 users in discussion

Daniel Garcia: 2 posts Djherbis: 2 posts

People

Translate

site design / logo © 2022 Grokbase