You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
732 B

9 years ago
  1. package common
  2. import (
  3. "bytes"
  4. )
  5. func Fingerprint(slice []byte) []byte {
  6. fingerprint := make([]byte, 6)
  7. copy(fingerprint, slice)
  8. return fingerprint
  9. }
  10. func IsZeros(slice []byte) bool {
  11. for _, byt := range slice {
  12. if byt != byte(0) {
  13. return false
  14. }
  15. }
  16. return true
  17. }
  18. func RightPadBytes(slice []byte, l int) []byte {
  19. if l < len(slice) {
  20. return slice
  21. }
  22. padded := make([]byte, l)
  23. copy(padded[0:len(slice)], slice)
  24. return padded
  25. }
  26. func LeftPadBytes(slice []byte, l int) []byte {
  27. if l < len(slice) {
  28. return slice
  29. }
  30. padded := make([]byte, l)
  31. copy(padded[l-len(slice):], slice)
  32. return padded
  33. }
  34. func TrimmedString(b []byte) string {
  35. trimSet := string([]byte{0})
  36. return string(bytes.TrimLeft(b, trimSet))
  37. }