FAQ
Why does the encoding/gob package require types to be registered before
they can be encoded? As far as I know, none of the other encoding/*
packages have that requirement.

Luke

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

  • Volker Dobler at Aug 12, 2013 at 1:11 pm

    Am Montag, 12. August 2013 14:38:34 UTC+2 schrieb Luke Mauldin:

    Why does the encoding/gob package require types to be registered before
    they can be encoded? As far as I know, none of the other encoding/*
    packages have that requirement.
    I think it is about speed.

    V.

    --
    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.
  • Rob Pike at Aug 12, 2013 at 1:14 pm
    It's only items that will be received as interface values that need to
    be registered. The recipient decoder knows only what the stream says,
    which is the interface pair (type, value), and unlike with other
    decoders or concrete (non-interface types) with gob encoding, there is
    no value extant of the appropriate concrete type to decode into.
    Registration is needed on the receiver (decoder), only, so it can have
    an example of the concrete type to duplicate when it wants to store
    the received value.

    In short, other decoders are passed a concrete type to decode into,
    *int say or *Foo, but gob's interface values are decoded by the
    receiver with no information except what the stream says. It needs a
    little help.

    Try using encoding/binary to encode an int32 and decode it into a
    value of type interface{} and you'll see the problem. (Hint: you
    can't, not directly.)

    -rob

    --
    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
postedAug 12, '13 at 12:38p
activeAug 12, '13 at 1:14p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase