Commit 812124a5 authored by Mark Wolfe's avatar Mark Wolfe Committed by Ian Lance Taylor

encoding/binary: add example for Read multi

Change-Id: I27ff99aa7abb070f6ae79c8f964aa9bd6a83b89d
Reviewed-on: https://go-review.googlesource.com/53730Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 590c5b08
...@@ -51,6 +51,30 @@ func ExampleRead() { ...@@ -51,6 +51,30 @@ func ExampleRead() {
// Output: 3.141592653589793 // Output: 3.141592653589793
} }
func ExampleRead_multi() {
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 {
fmt.Println("binary.Read failed:", err)
}
fmt.Println(data.PI)
fmt.Println(data.Uate)
fmt.Printf("% x\n", data.Mine)
fmt.Println(data.Too)
// Output:
// 3.141592653589793
// 255
// 01 02 03
// 61374
}
func ExampleByteOrder_put() { func ExampleByteOrder_put() {
b := make([]byte, 4) b := make([]byte, 4)
binary.LittleEndian.PutUint16(b[0:], 0x03e8) binary.LittleEndian.PutUint16(b[0:], 0x03e8)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment