-
Notifications
You must be signed in to change notification settings - Fork 6
/
big16.go
66 lines (53 loc) · 1.76 KB
/
big16.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018 The Cacophony Project. All rights reserved.
// Use of this source code is governed by the Apache License Version 2.0;
// see the LICENSE file for further details.
// Source code in this file comes from the periph project
// (https://periph.io/).
package lepton3
import "encoding/binary"
// Big16 translates big endian 16bits words but everything larger is in little
// endian.
//
// It implements binary.ByteOrder.
var Big16 big16
type big16 struct{}
func (big16) Uint16(b []byte) uint16 {
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
return uint16(b[1]) | uint16(b[0])<<8
}
func (big16) PutUint16(b []byte, v uint16) {
_ = b[1] // early bounds check to guarantee safety of writes below
b[0] = byte(v >> 8)
b[1] = byte(v)
}
func (big16) Uint32(b []byte) uint32 {
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
return uint32(b[1]) | uint32(b[0])<<8 | uint32(b[3])<<16 | uint32(b[2])<<24
}
func (big16) PutUint32(b []byte, v uint32) {
_ = b[3] // early bounds check to guarantee safety of writes below
b[1] = byte(v)
b[0] = byte(v >> 8)
b[3] = byte(v >> 16)
b[2] = byte(v >> 24)
}
func (big16) Uint64(b []byte) uint64 {
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
return uint64(b[1]) | uint64(b[0])<<8 | uint64(b[3])<<16 | uint64(b[2])<<24 |
uint64(b[5])<<32 | uint64(b[4])<<40 | uint64(b[7])<<48 | uint64(b[6])<<56
}
func (big16) PutUint64(b []byte, v uint64) {
_ = b[7] // early bounds check to guarantee safety of writes below
b[1] = byte(v)
b[0] = byte(v >> 8)
b[3] = byte(v >> 16)
b[2] = byte(v >> 24)
b[5] = byte(v >> 32)
b[4] = byte(v >> 40)
b[7] = byte(v >> 48)
b[6] = byte(v >> 56)
}
func (big16) String() string {
return "big16"
}
var _ binary.ByteOrder = Big16