tendermint/common/byteslice.go

45 lines
732 B
Go
Raw Normal View History

2014-10-30 03:32:09 -07:00
package common
2015-07-20 14:24:57 -04:00
import (
"bytes"
)
2015-03-16 02:23:35 -07:00
func Fingerprint(slice []byte) []byte {
2014-10-30 03:32:09 -07:00
fingerprint := make([]byte, 6)
2015-03-16 02:23:35 -07:00
copy(fingerprint, slice)
2014-10-30 03:32:09 -07:00
return fingerprint
}
2015-03-16 02:23:35 -07:00
2015-03-20 05:47:52 -07:00
func IsZeros(slice []byte) bool {
for _, byt := range slice {
if byt != byte(0) {
return false
}
}
return true
}
2015-03-16 02:23:35 -07:00
func RightPadBytes(slice []byte, l int) []byte {
if l < len(slice) {
return slice
}
padded := make([]byte, l)
copy(padded[0:len(slice)], slice)
return padded
}
func LeftPadBytes(slice []byte, l int) []byte {
if l < len(slice) {
return slice
}
padded := make([]byte, l)
copy(padded[l-len(slice):], slice)
return padded
}
2015-07-20 14:24:57 -04:00
func TrimmedString(b []byte) string {
trimSet := string([]byte{0})
return string(bytes.TrimLeft(b, trimSet))
}