OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / tmlibs / common / byteslice.go
1 package common
2
3 import (
4         "bytes"
5 )
6
7 // Fingerprint returns the first 6 bytes of a byte slice.
8 // If the slice is less than 6 bytes, the fingerprint
9 // contains trailing zeroes.
10 func Fingerprint(slice []byte) []byte {
11         fingerprint := make([]byte, 6)
12         copy(fingerprint, slice)
13         return fingerprint
14 }
15
16 func IsZeros(slice []byte) bool {
17         for _, byt := range slice {
18                 if byt != byte(0) {
19                         return false
20                 }
21         }
22         return true
23 }
24
25 func RightPadBytes(slice []byte, l int) []byte {
26         if l < len(slice) {
27                 return slice
28         }
29         padded := make([]byte, l)
30         copy(padded[0:len(slice)], slice)
31         return padded
32 }
33
34 func LeftPadBytes(slice []byte, l int) []byte {
35         if l < len(slice) {
36                 return slice
37         }
38         padded := make([]byte, l)
39         copy(padded[l-len(slice):], slice)
40         return padded
41 }
42
43 func TrimmedString(b []byte) string {
44         trimSet := string([]byte{0})
45         return string(bytes.TrimLeft(b, trimSet))
46
47 }