Standard library / encoding

encoding.BinaryUnmarshaler

Interface for restoring a value from binary data. An implementation retaining the supplied bytes must copy them. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type BinaryUnmarshaler interface {  UnmarshalBinary(data []byte) error}

Working Example

Example Snippetgo
package main
import (  "encoding"  "fmt"  "time")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  t := time.Unix(0, 0).UTC()  b, e := t.MarshalBinary()  must(e)  var out time.Time  var x encoding.BinaryUnmarshaler = &out  must(x.UnmarshalBinary(b))  fmt.Println(out.Equal(t))}
Go Reference