github.com/Cloud-Foundations/Dominator@v0.3.4/lib/hash/marshal.go (about)

     1  package hash
     2  
     3  func (h Hash) marshalText() ([]byte, error) {
     4  	retval := make([]byte, 0, 2*len(h))
     5  	for _, byteVal := range h {
     6  		retval = append(retval, formatNibble(byteVal>>4))
     7  		retval = append(retval, formatNibble(byteVal&0xf))
     8  	}
     9  	return retval, nil
    10  }
    11  
    12  func formatNibble(nibble byte) byte {
    13  	if nibble < 10 {
    14  		return '0' + nibble
    15  	}
    16  	return 'a' + nibble - 10
    17  }