Golang encoding/gob.Decoder.Decode() function example
package encoding/gob
Decode reads the next value from the input stream and stores it in the data represented by the empty interface value. If e (1st parameter) 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.
Golang encoding/gob.Decoder.Decode() function usage example
type Item struct {
Data interface{}
Name string
}
func decode_gob(data []byte, output *Item) error {
buffer := bytes.NewBuffer(data)
decoder := gob.NewDecoder(buffer)
return decoder.Decode(&output) // <-- here
}
Reference :
Advertisement
Something interesting
Tutorials
+10.4k Golang : Meaning of omitempty in struct's field tag
+9.3k Golang : Timeout example
+9.9k Golang : Function wrapper that takes arguments and return result example
+7.5k Golang : How to handle file size larger than available memory panic issue
+13.6k Golang : Set image canvas or background to transparent
+9k Golang : Go as a script or running go with shebang/hashbang style
+9.5k Golang : Extract or copy items from map based on value
+8.1k Golang : Tell color name with OpenCV example
+7.9k Golang : Trim everything onward after a word
+9.5k Golang : Get all countries currencies code in JSON format
+13.4k Golang : Get constant name from value