Standard library / encoding/gob
encoding/gob.Encoder.EncodeValue()
Encode a reflection value instead of an ordinary interface argument. Nil pointers are not supported. Expected stdout: 'go\n'.
Formal Syntax & Structure
go syntaxgo
func (enc *Encoder) EncodeValue(value reflect.Value) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| value | reflect.Value | Reflection value representing the item to transmit. |
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).EncodeValue(reflect.ValueOf("go"))) var s string must(gob.NewDecoder(&buf).Decode(&s)) fmt.Println(s)}