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.
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 {
24 PutUint16([]byte, uint16)
25 PutUint32([]byte, uint32)
26 PutUint64([]byte, uint64)
29 type binaryLittleEndian
struct{}
31 func (binaryLittleEndian
) Uint16(b
[]byte) uint16 {
32 _
= b
[1] // bounds check hint to compiler; see golang.org/issue/14808
33 return uint16(b
[0]) |
uint16(b
[1])<<8
36 func (binaryLittleEndian
) PutUint16(b
[]byte, v
uint16) {
37 _
= b
[1] // early bounds check to guarantee safety of writes below
42 func (binaryLittleEndian
) Uint32(b
[]byte) uint32 {
43 _
= b
[3] // bounds check hint to compiler; see golang.org/issue/14808
44 return uint32(b
[0]) |
uint32(b
[1])<<8 |
uint32(b
[2])<<16 |
uint32(b
[3])<<24
47 func (binaryLittleEndian
) PutUint32(b
[]byte, v
uint32) {
48 _
= b
[3] // early bounds check to guarantee safety of writes below
55 func (binaryLittleEndian
) Uint64(b
[]byte) uint64 {
56 _
= b
[7] // bounds check hint to compiler; see golang.org/issue/14808
57 return uint64(b
[0]) |
uint64(b
[1])<<8 |
uint64(b
[2])<<16 |
uint64(b
[3])<<24 |
58 uint64(b
[4])<<32 |
uint64(b
[5])<<40 |
uint64(b
[6])<<48 |
uint64(b
[7])<<56
61 func (binaryLittleEndian
) PutUint64(b
[]byte, v
uint64) {
62 _
= b
[7] // early bounds check to guarantee safety of writes below
73 type binaryBigEndian
struct{}
75 func (binaryBigEndian
) Uint16(b
[]byte) uint16 {
76 _
= b
[1] // bounds check hint to compiler; see golang.org/issue/14808
77 return uint16(b
[1]) |
uint16(b
[0])<<8
80 func (binaryBigEndian
) PutUint16(b
[]byte, v
uint16) {
81 _
= b
[1] // early bounds check to guarantee safety of writes below
86 func (binaryBigEndian
) Uint32(b
[]byte) uint32 {
87 _
= b
[3] // bounds check hint to compiler; see golang.org/issue/14808
88 return uint32(b
[3]) |
uint32(b
[2])<<8 |
uint32(b
[1])<<16 |
uint32(b
[0])<<24
91 func (binaryBigEndian
) PutUint32(b
[]byte, v
uint32) {
92 _
= b
[3] // early bounds check to guarantee safety of writes below
99 func (binaryBigEndian
) Uint64(b
[]byte) uint64 {
100 _
= b
[7] // bounds check hint to compiler; see golang.org/issue/14808
101 return uint64(b
[7]) |
uint64(b
[6])<<8 |
uint64(b
[5])<<16 |
uint64(b
[4])<<24 |
102 uint64(b
[3])<<32 |
uint64(b
[2])<<40 |
uint64(b
[1])<<48 |
uint64(b
[0])<<56
105 func (binaryBigEndian
) PutUint64(b
[]byte, v
uint64) {
106 _
= b
[7] // early bounds check to guarantee safety of writes below