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
+9.4k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+15.1k Golang : Send email with attachment(RFC2822) using Gmail API example
+7.7k Golang : Rename part of filename
+5.1k HTTP common errors and their meaning explained
+5.6k Golang : Intercept, inject and replay HTTP traffics from web server
+20.2k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+25.4k Golang : Create PDF file from HTML file
+14.4k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+22.5k Golang : Securing password with salt
+20.1k Golang : Append content to a file
+10.6k Golang : Convert file unix timestamp to UTC time example
+14.5k Elastic Search : Mapping date format and sort by date