blob: 47d10a71c15c8fd728361fd7c8e28a71897b6212 [file] [log] [blame]
// +build ignore,OMIT
package main
import (
"encoding/binary"
"image/color"
"io"
"log"
"os"
)
// GOPHER OMIT
type Gopher struct {
Name string
Age int32
FurColor color.Color
}
// BINWRITER OMIT
type binWriter struct {
w io.Writer
err error
}
// WRITE OMIT
// Write writes a value into its writer using little endian.
func (w *binWriter) Write(v interface{}) {
if w.err != nil {
return
}
w.err = binary.Write(w.w, binary.LittleEndian, v)
}
// DUMP OMIT
func (g *Gopher) DumpBinary(w io.Writer) error {
bw := &binWriter{w: w}
bw.Write(int32(len(g.Name)))
bw.Write([]byte(g.Name))
bw.Write(g.Age)
bw.Write(g.FurColor)
return bw.err
}
// MAIN OMIT
func main() {
w := os.Stdout
g := &Gopher{
Name: "Gophertiti",
Age: 3383,
FurColor: color.RGBA{B: 255},
}
if err := g.DumpBinary(w); err != nil {
log.Fatal("DumpBinary: %v", err)
}
}