diff --git a/src/encoding/binary/example_test.go b/src/encoding/binary/example_test.go index e99aef288d..6f892c2b8d 100644 --- a/src/encoding/binary/example_test.go +++ b/src/encoding/binary/example_test.go @@ -52,18 +52,20 @@ func ExampleRead() { } func ExampleRead_multi() { - data := struct { + b := []byte{0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40, 0xff, 0x01, 0x02, 0x03, 0xbe, 0xef} + r := bytes.NewReader(b) + + var data struct { PI float64 Uate uint8 Mine [3]byte Too uint16 - }{} - b := []byte{0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40, 0xff, 0x01, 0x02, 0x03, 0xbe, 0xef} - buf := bytes.NewReader(b) - err := binary.Read(buf, binary.LittleEndian, &data) - if err != nil { + } + + if err := binary.Read(r, binary.LittleEndian, &data); err != nil { fmt.Println("binary.Read failed:", err) } + fmt.Println(data.PI) fmt.Println(data.Uate) fmt.Printf("% x\n", data.Mine)