Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PutUint64 and GetUint64 funcs #26

Merged
merged 2 commits into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
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
}
Loading