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. 4 5 // +build solaris 6 7 package lif 8 9 // This file contains duplicates of encoding/binary package. 10 // 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. 14 15 var littleEndian binaryLittleEndian 16 17 type binaryByteOrder interface { 18 Uint16([]byte) uint16 19 Uint32([]byte) uint32 20 Uint64([]byte) uint64 21 PutUint16([]byte, uint16) 22 PutUint32([]byte, uint32) 23 PutUint64([]byte, uint64) 24 } 25 26 type binaryLittleEndian struct{} 27 28 func (binaryLittleEndian) Uint16(b []byte) uint16 { 29 _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808 30 return uint16(b[0]) | uint16(b[1])<<8 31 } 32 33 func (binaryLittleEndian) PutUint16(b []byte, v uint16) { 34 _ = b[1] // early bounds check to guarantee safety of writes below 35 b[0] = byte(v) 36 b[1] = byte(v >> 8) 37 } 38 39 func (binaryLittleEndian) Uint32(b []byte) uint32 { 40 _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808 41 return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 42 } 43 44 func (binaryLittleEndian) PutUint32(b []byte, v uint32) { 45 _ = b[3] // early bounds check to guarantee safety of writes below 46 b[0] = byte(v) 47 b[1] = byte(v >> 8) 48 b[2] = byte(v >> 16) 49 b[3] = byte(v >> 24) 50 } 51 52 func (binaryLittleEndian) Uint64(b []byte) uint64 { 53 _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808 54 return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | 55 uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 56 } 57 58 func (binaryLittleEndian) PutUint64(b []byte, v uint64) { 59 _ = b[7] // early bounds check to guarantee safety of writes below 60 b[0] = byte(v) 61 b[1] = byte(v >> 8) 62 b[2] = byte(v >> 16) 63 b[3] = byte(v >> 24) 64 b[4] = byte(v >> 32) 65 b[5] = byte(v >> 40) 66 b[6] = byte(v >> 48) 67 b[7] = byte(v >> 56) 68 } 69