1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd netbsd openbsd
9 // This file contains duplicates of encoding/binary package.
11 // This package is supposed to be used by the net package of standard
12 // library. Therefore the package set used in the package must be the
13 // same as net package.
16 littleEndian binaryLittleEndian
17 bigEndian binaryBigEndian
20 type binaryByteOrder interface {
23 PutUint16([]byte, uint16)
24 PutUint32([]byte, uint32)
28 type binaryLittleEndian struct{}
30 func (binaryLittleEndian) Uint16(b []byte) uint16 {
31 _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
32 return uint16(b[0]) | uint16(b[1])<<8
35 func (binaryLittleEndian) PutUint16(b []byte, v uint16) {
36 _ = b[1] // early bounds check to guarantee safety of writes below
41 func (binaryLittleEndian) Uint32(b []byte) uint32 {
42 _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
43 return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
46 func (binaryLittleEndian) PutUint32(b []byte, v uint32) {
47 _ = b[3] // early bounds check to guarantee safety of writes below
54 func (binaryLittleEndian) Uint64(b []byte) uint64 {
55 _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
56 return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
57 uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
60 type binaryBigEndian struct{}
62 func (binaryBigEndian) Uint16(b []byte) uint16 {
63 _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
64 return uint16(b[1]) | uint16(b[0])<<8
67 func (binaryBigEndian) PutUint16(b []byte, v uint16) {
68 _ = b[1] // early bounds check to guarantee safety of writes below
73 func (binaryBigEndian) Uint32(b []byte) uint32 {
74 _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
75 return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
78 func (binaryBigEndian) PutUint32(b []byte, v uint32) {
79 _ = b[3] // early bounds check to guarantee safety of writes below
86 func (binaryBigEndian) Uint64(b []byte) uint64 {
87 _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
88 return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
89 uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56