Standard library / encoding/gob
encoding/gob.Decoder.DecodeValue()
Decode into a settable reflection value or a non-nil pointer. An invalid reflection value discards an item. Expected stdout: '7\n'.
Formal Syntax & Structure
go syntaxgo
func (dec *Decoder) DecodeValue(v reflect.Value) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| v | reflect.Value | Settable reflection value or non-nil pointer; invalid value discards the next item. |
Return Value
error
Nil on success; otherwise the operation error.
Working Example
Example Snippetgo
package main
import ( "bytes" "encoding/gob" "fmt" "reflect")
func must(e error) { if e != nil { panic(e) }}
func main() { var buf bytes.Buffer must(gob.NewEncoder(&buf).Encode(7)) var n int must(gob.NewDecoder(&buf).DecodeValue(reflect.ValueOf(&n).Elem())) fmt.Println(n)}