Standard library / encoding

encoding.BinaryMarshaler

Interface for producing a binary encoding of a value. Implementations should document the binary format and return errors for invalid state. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type BinaryMarshaler interface {  MarshalBinary() (data []byte, err error)}

Working Example

Example Snippetgo
package main
import (  "encoding"  "fmt"  "time")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var x encoding.BinaryMarshaler = time.Unix(0, 0).UTC()  b, e := x.MarshalBinary()  must(e)  fmt.Println(len(b) > 0)}
Go Reference