FAQ
Hi

I have a map with interface values that I'm trying to gob encode/decode

http://play.golang.org/p/3tGR-m_SkQ

type I interface {
     F()
}
a := make(map[int]I)

type S struct
func (s *S) F() {}

I can gob encode an S in *a*, but it fails on decoding.
if I make *a* of type map[int]interface{} it works fine, but I would rather
not lose that information as I only want a specific set of things in the
map. (more specific that 'anything' more general than one struct)

All the examples I've seen of gob with interfaces is of the empty
interface{}.
How can I decode non empty interfaces?

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/d/optout.

Search Discussions

  • Matthew Zimmerman at Dec 2, 2014 at 7:14 pm
    http://play.golang.org/p/mxUx42tnnr

    As it was, S{} doesn't implement interface I since F() required a pointer
    receiver. &S{} implements interface I.
    On Tue Dec 02 2014 at 2:06:42 PM Pieter Slabbert wrote:

    Hi

    I have a map with interface values that I'm trying to gob encode/decode

    http://play.golang.org/p/3tGR-m_SkQ

    type I interface {
    F()
    }
    a := make(map[int]I)

    type S struct
    func (s *S) F() {}

    I can gob encode an S in *a*, but it fails on decoding.
    if I make *a* of type map[int]interface{} it works fine, but I would
    rather not lose that information as I only want a specific set of things in
    the map. (more specific that 'anything' more general than one struct)

    All the examples I've seen of gob with interfaces is of the empty
    interface{}.
    How can I decode non empty interfaces?

    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/d/optout.
    --
    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.
  • Pieter Slabbert at Dec 2, 2014 at 7:23 pm
    Thanks!
    That worked. Will have to remember to look more carefully at what I'm
    registering.
    On Tuesday, 2 December 2014 21:06:37 UTC+2, Pieter Slabbert wrote:

    Hi

    I have a map with interface values that I'm trying to gob encode/decode

    http://play.golang.org/p/3tGR-m_SkQ

    type I interface {
    F()
    }
    a := make(map[int]I)

    type S struct
    func (s *S) F() {}

    I can gob encode an S in *a*, but it fails on decoding.
    if I make *a* of type map[int]interface{} it works fine, but I would
    rather not lose that information as I only want a specific set of things in
    the map. (more specific that 'anything' more general than one struct)

    All the examples I've seen of gob with interfaces is of the empty
    interface{}.
    How can I decode non empty interfaces?

    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 2, '14 at 7:06p
activeDec 2, '14 at 7:23p
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase