Skip to content

Commit

Permalink
Merge pull request #26 from hextrust-0/uint64-funcs
Browse files Browse the repository at this point in the history
Add PutUint64 and GetUint64 funcs
  • Loading branch information
markkurossi authored May 8, 2024
2 parents b5a40b7 + f3499e3 commit 0788eda
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/encoding/binary/getput.mpcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,56 @@ func PutUint32(d []byte, offset int, v uint32) []byte {
func GetUint32LSB(d []byte) uint32 {
return uint32(d[0]) | uint32(d[1])<<8 | uint32(d[2])<<16 | uint32(d[3])<<24
}


// GetUint64 gets a MSB-encoded uint64 value from the argument buffer.
func GetUint64(d []byte) uint64 {
return uint64(d[0])<<56 | uint64(d[1])<<48 | uint64(d[2])<<40 | uint64(d[3])<<32 |
uint64(d[4])<<24 | uint64(d[5])<<16 | uint64(d[6])<<8 | uint64(d[7])
}

// PutUint64 puts the uint64 value v to the buffer d starting from the
// offset offset in MSB-order.
func PutUint64(d []byte, offset int, v uint64) []byte {
d[offset+0] = byte(v >> 56)
d[offset+1] = byte(v >> 48)
d[offset+2] = byte(v >> 40)
d[offset+3] = byte(v >> 32)
d[offset+4] = byte(v >> 24)
d[offset+5] = byte(v >> 16)
d[offset+6] = byte(v >> 8)
d[offset+7] = byte(v)
return d
}

// GetUint64LSB gets a LSB-encoded uint64 value from the argument buffer.
func GetUint64LSB(d []byte) uint64 {
return uint64(d[0]) | uint64(d[1])<<8 | uint64(d[2])<<16 | uint64(d[3])<<24 |
uint64(d[4])<<32 | uint64(d[5])<<40 | uint64(d[6])<<48 | uint64(d[7])<<56
}

// GetUint64 gets a MSB-encoded uint64 value from the argument buffer.
func GetUint64(d []byte) uint64 {

Check failure on line 85 in pkg/encoding/binary/getput.mpcl

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

function GetUint64 already defined
return uint64(d[0])<<56 | uint64(d[1])<<48 | uint64(d[2])<<40 | uint64(d[3])<<32 |
uint64(d[4])<<24 | uint64(d[5])<<16 | uint64(d[6])<<8 | uint64(d[7])
}

// PutUint64 puts the uint64 value v to the buffer d starting from the
// offset offset in MSB-order.
func PutUint64(d []byte, offset int, v uint64) []byte {
d[offset+0] = byte(v >> 56)
d[offset+1] = byte(v >> 48)
d[offset+2] = byte(v >> 40)
d[offset+3] = byte(v >> 32)
d[offset+4] = byte(v >> 24)
d[offset+5] = byte(v >> 16)
d[offset+6] = byte(v >> 8)
d[offset+7] = byte(v)
return d
}

// GetUint64LSB gets a LSB-encoded uint64 value from the argument buffer.
func GetUint64LSB(d []byte) uint64 {
return uint64(d[0]) | uint64(d[1])<<8 | uint64(d[2])<<16 | uint64(d[3])<<24 |
uint64(d[4])<<32 | uint64(d[5])<<40 | uint64(d[6])<<48 | uint64(d[7])<<56
}

0 comments on commit 0788eda

Please sign in to comment.