]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/binary: add examples for ByteOrder functions
authorRoss Light <light@google.com>
Sat, 15 Jul 2017 20:53:42 +0000 (14:53 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 15 Jul 2017 21:15:16 +0000 (21:15 +0000)
Change-Id: Iec9a7bf61566ee08c4d15adb39d43c7a29c79122
Reviewed-on: https://go-review.googlesource.com/48962
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>

src/encoding/binary/example_test.go

index c0fec7385f1f4ea97a011a0b08e9f5683e0259dd..2b52a47d129cf7a0968680874ad714251a4238b5 100644 (file)
@@ -50,3 +50,21 @@ func ExampleRead() {
        fmt.Print(pi)
        // Output: 3.141592653589793
 }
+
+func ExampleByteOrder_put() {
+       b := make([]byte, 4)
+       binary.LittleEndian.PutUint16(b[0:], 0x03e8)
+       binary.LittleEndian.PutUint16(b[2:], 0x07d0)
+       fmt.Printf("% x\n", b)
+       // Output:
+       // e8 03 d0 07
+}
+
+func ExampleByteOrder_get() {
+       b := []byte{0xe8, 0x03, 0xd0, 0x07}
+       x1 := binary.LittleEndian.Uint16(b[0:])
+       x2 := binary.LittleEndian.Uint16(b[2:])
+       fmt.Printf("%#04x %#04x\n", x1, x2)
+       // Output:
+       // 0x03e8 0x07d0
+}