mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-18 22:14:35 +00:00
little fixes to vm and endianess
This commit is contained in:
+10
-2
@@ -22,10 +22,18 @@ func (p Uint64Slice) Search(x uint64) int { return SearchUint64s(p, x) }
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
func PutUint64(dest []byte, i uint64) {
|
||||
func PutUint64LE(dest []byte, i uint64) {
|
||||
binary.LittleEndian.PutUint64(dest, i)
|
||||
}
|
||||
|
||||
func GetUint64(src []byte) uint64 {
|
||||
func GetUint64LE(src []byte) uint64 {
|
||||
return binary.LittleEndian.Uint64(src)
|
||||
}
|
||||
|
||||
func PutUint64BE(dest []byte, i uint64) {
|
||||
binary.BigEndian.PutUint64(dest, i)
|
||||
}
|
||||
|
||||
func GetUint64BE(src []byte) uint64 {
|
||||
return binary.BigEndian.Uint64(src)
|
||||
}
|
||||
|
||||
+4
-10
@@ -2,7 +2,6 @@ package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"sort"
|
||||
)
|
||||
|
||||
@@ -30,12 +29,9 @@ func (w Word256) Compare(other Word256) int {
|
||||
}
|
||||
|
||||
func Uint64ToWord256(i uint64) Word256 {
|
||||
word := Word256{}
|
||||
buf := [8]byte{}
|
||||
PutUint64(buf[:], i)
|
||||
word[24], word[25], word[26], word[27] = buf[7], buf[6], buf[5], buf[4]
|
||||
word[28], word[29], word[30], word[31] = buf[3], buf[2], buf[1], buf[0]
|
||||
return word
|
||||
PutUint64BE(buf[:], i)
|
||||
return LeftPadWord256(buf[:])
|
||||
}
|
||||
|
||||
func RightPadWord256(bz []byte) (word Word256) {
|
||||
@@ -49,10 +45,8 @@ func LeftPadWord256(bz []byte) (word Word256) {
|
||||
}
|
||||
|
||||
func Uint64FromWord256(word Word256) uint64 {
|
||||
buf := [8]byte{}
|
||||
buf[0], buf[1], buf[2], buf[3] = word[31], word[30], word[29], word[28]
|
||||
buf[4], buf[5], buf[6], buf[7] = word[27], word[26], word[25], word[24]
|
||||
return binary.LittleEndian.Uint64(buf[:])
|
||||
buf := word.Postfix(8)
|
||||
return GetUint64BE(buf)
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user