trying to understand how gob(golang) work

88 views
Skip to first unread message

WALID BELRHALMIA

unread,
Sep 23, 2015, 12:18:44 AM9/23/15
to golang-nuts

in my ambitions to understand how gob work . i have severals question .

i know that gob serialize a go type like struct map or interface(we must register it's real type) but :

func (dec *Decoder) Decode(e interface{}) error
Decode reads the next value from the input stream and stores it in the data represented by the       
empty interface value.
If e is nil, the value will be discarded. 
Otherwise, the value underlying e must be a pointer to the correct type for the next data item received.
If the input is at EOF, Decode returns io.EOF and does not modify e.

i didn't understand nothing in this documentation . what they mean by ( reads the next value from the input stream ) they are one data that we could send it's a struct or a map but not many .what they mean by If e is nil, the value will be discarded. please expert explain to me i'am disasperate all day and ididn't find nothing

Charles Haynes

unread,
Sep 23, 2015, 1:58:47 AM9/23/15
to WALID BELRHALMIA, golang-nuts
You can call encode multiple times on the same encoder. Similarly you can call decode multiple times on the same decoder.

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

This is true of the JSON encoder/decoder as well.

-- Charles

--
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.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages