Yes, it has enough information about the type, but not about values.
This should illustrate:
type A struct {
X *int
Y int
}
type B struct {
X int
Y int
}
Send A and the receiver knows that the type has an X and a Y both with
take values that are int, but it doesn't know (or care) that one is a
pointer and one in a concrete value.
Send (illegal syntax to simplify) A{&1, 2} and you can receive in B as
B{1, 2}. If you send A{&0, 2} or A{nil, 2} the value received in B will
be B{0, 2}. This is not interesting, but in the case of receiving into
an A, you get both as A{nil, 2}, because nil is the zero value and it
not sent, and &0 is the zero value for a dereferenced *int. So how can
we differentiate these?
A{nil, 2} // nil is the zero value, so send {Y:2}. Same as now.
A{&0, 2} // &0 is not the zero value for *int, so send {X:0, Y:2}
then when the decoder sees a gob struct of {X:0, Y:2} it will
{X:0, Y:2} -> A{&0, 2} which keeps the correct state for the *int field,
or
{X:0, Y:2} -> B{0, 2} which is no change from the current situation.
I can't see way you can distinguish an absent pointer field that is zero
from an absent pointer field that is nil unless you send some
information. This does that.
As far as the non-pointer fields go, they are purely a convenience
thing; just properly condition your receiving variable prior to decoding
into it.
On Wed, 2013-02-20 at 18:08 -0800, David DENG wrote:
> I didn't check the source code but in the document
> <
http://golang.org/doc/articles/gobs_of_data.html>says: "*Thus when we
> send
> our first type T, the gob encoder sends a description of T*". So, I