Golang encoding/gob.Encoder.Encode() function example
package encoding/gob
Encode transmits the data item represented by the empty interface value, guaranteeing that all necessary type information has been transmitted first.
Golang encoding/gob.Encoder.Encode() function usage example
func encode_gob(data interface{}) ([]byte, error) {
buff := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buff)
err := enc.Encode(data) // <----- here
if err != nil {
return nil, err
}
return buff.Bytes(), err
}
References :
http://golang.org/pkg/encoding/gob/#Encoder.Encode
https://www.socketloop.com/references/golang-encoding-gob-newencoder-function-examples
Advertisement
Something interesting
Tutorials
+10.5k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+7.7k Golang : Write multiple lines or divide string into multiple lines
+17.2k Golang : Write file with io.WriteString
+27.7k Golang : Save map/struct to JSON or XML file
+16k Golang : How to remove certain lines from a file
+10.6k Golang : md5 hash of a string
+12.4k Golang : Activate web camera and broadcast out base64 encoded images
+8k Golang : Detect number of active displays and the display's resolution
+38k Golang : UDP client server read write example
+13.2k Golang : How to shuffle elements in array or slice?
+20.5k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+5.8k Golang : Levenshtein distance example