github.com/monax/eris-db@v0.25.0/binary/byteslice.go (about) 1 // Copyright 2017 Monax Industries Limited 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package binary 16 17 func Fingerprint(slice []byte) []byte { 18 fingerprint := make([]byte, 6) 19 copy(fingerprint, slice) 20 return fingerprint 21 } 22 23 func IsZeros(slice []byte) bool { 24 for _, byt := range slice { 25 if byt != byte(0) { 26 return false 27 } 28 } 29 return true 30 } 31 32 func RightPadBytes(slice []byte, l int) []byte { 33 if l < len(slice) { 34 return slice 35 } 36 padded := make([]byte, l) 37 copy(padded[0:len(slice)], slice) 38 return padded 39 } 40 41 func LeftPadBytes(slice []byte, l int) []byte { 42 if l < len(slice) { 43 return slice 44 } 45 padded := make([]byte, l) 46 copy(padded[l-len(slice):], slice) 47 return padded 48 }