removed ByteSize, etc.

This commit is contained in:
Jae Kwon
2014-06-05 02:33:50 -07:00
parent 576d8815fe
commit 2c97c84c6e
8 changed files with 148 additions and 104 deletions

33
binary/util.go Normal file
View File

@ -0,0 +1,33 @@
package binary
import (
"crypto/sha256"
"bytes"
)
func BinaryBytes(b Binary) ByteSlice {
buf := bytes.NewBuffer(nil)
b.WriteTo(buf)
return ByteSlice(buf.Bytes())
}
// NOTE: does not care about the type, only the binary representation.
func BinaryEqual(a, b Binary) bool {
aBytes := BinaryBytes(a)
bBytes := BinaryBytes(b)
return bytes.Equal(aBytes, bBytes)
}
// NOTE: does not care about the type, only the binary representation.
func BinaryCompare(a, b Binary) int {
aBytes := BinaryBytes(a)
bBytes := BinaryBytes(b)
return bytes.Compare(aBytes, bBytes)
}
func BinaryHash(b Binary) ByteSlice {
hasher := sha256.New()
_, err := b.WriteTo(hasher)
if err != nil { panic(err) }
return ByteSlice(hasher.Sum(nil))
}