| 1 |
package binarydist |
| 2 |
|
| 3 |
// SignMagLittleEndian is the numeric encoding used by the bsdiff tools. |
| 4 |
// It implements binary.ByteOrder using a sign-magnitude format |
| 5 |
// and little-endian byte order. Only methods Uint64 and String |
| 6 |
// have been written; the rest panic. |
| 7 |
type signMagLittleEndian struct{} |
| 8 |
|
| 9 |
func (signMagLittleEndian) Uint16(b []byte) uint16 { panic("unimplemented") } |
| 10 |
|
| 11 |
func (signMagLittleEndian) PutUint16(b []byte, v uint16) { panic("unimplemented") } |
| 12 |
|
| 13 |
func (signMagLittleEndian) Uint32(b []byte) uint32 { panic("unimplemented") } |
| 14 |
|
| 15 |
func (signMagLittleEndian) PutUint32(b []byte, v uint32) { panic("unimplemented") } |
| 16 |
|
| 17 |
func (signMagLittleEndian) Uint64(b []byte) uint64 { |
| 18 |
y := int64(b[0]) | |
| 19 |
int64(b[1])<<8 | |
| 20 |
int64(b[2])<<16 | |
| 21 |
int64(b[3])<<24 | |
| 22 |
int64(b[4])<<32 | |
| 23 |
int64(b[5])<<40 | |
| 24 |
int64(b[6])<<48 | |
| 25 |
int64(b[7]&0x7f)<<56 |
| 26 |
|
| 27 |
if b[7]&0x80 != 0 { |
| 28 |
y = -y |
| 29 |
} |
| 30 |
return uint64(y) |
| 31 |
} |
| 32 |
|
| 33 |
func (signMagLittleEndian) PutUint64(b []byte, v uint64) { |
| 34 |
x := int64(v) |
| 35 |
neg := x < 0 |
| 36 |
if neg { |
| 37 |
x = -x |
| 38 |
} |
| 39 |
|
| 40 |
b[0] = byte(x) |
| 41 |
b[1] = byte(x >> 8) |
| 42 |
b[2] = byte(x >> 16) |
| 43 |
b[3] = byte(x >> 24) |
| 44 |
b[4] = byte(x >> 32) |
| 45 |
b[5] = byte(x >> 40) |
| 46 |
b[6] = byte(x >> 48) |
| 47 |
b[7] = byte(x >> 56) |
| 48 |
if neg { |
| 49 |
b[7] |= 0x80 |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
func (signMagLittleEndian) String() string { return "signMagLittleEndian" } |