func mustCheckSumFile(path string) uint64 { content, err := kmgFile.ReadFile(path) if err != nil { panic(err) } return xxhash.Checksum64(content) }
func BenchmarkXxhash64Cgo(b *testing.B) { var bv uint64 for i := 0; i < b.N; i++ { bv = C.Checksum64(in) } benchVal64 = bv }
func testEquality(t *testing.T, v []byte) { ch64, ch32 := cxx.Checksum64(v), cxx.Checksum32(v) if h := N.Checksum64(v); ch64 != h { t.Fatalf("Checksum64 doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch64, h) } if h := N.Checksum32(v); ch32 != h { t.Fatalf("Checksum32 doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch32, h) } h64 := N.New64() h64.Write(v) if h := h64.Sum64(); ch64 != h { t.Fatalf("Sum64() doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch64, h) } h32 := N.New32() h32.Write(v) if h := h32.Sum32(); ch32 != h { t.Fatalf("Sum32() doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch32, h) } }
func BenchmarkXXChecksum64ShortCgo(b *testing.B) { var bv uint64 k := []byte("Test-key-100") for i := 0; i < b.N; i++ { bv += CGO.Checksum64(k) } }
func BenchmarkXxhash64CgoVeryShort(b *testing.B) { var bv uint64 k := []byte("Test-key-100") for i := 0; i < b.N; i++ { bv = C.Checksum64(k) } benchVal64 = bv }
func checkFileWithMd5(path string, shouldMd5 uint64) (ok bool) { content, err := kmgFile.ReadFile(path) if err != nil { if !os.IsNotExist(err) { panic(err) } return false } return xxhash.Checksum64(content) == shouldMd5 }
func TestNewMessage(t *testing.T) { id := MessageId(5) content := []byte("foobar") message := NewMessage(id, content) header := ReadHeader(message) assert.Equal(t, START_VALUE, header.Magic) assert.Equal(t, id, header.MessageId) assert.Equal(t, len(content), int(header.ContentLength)) assert.Equal(t, string(content), string(message[INDEX_CONTENT:])) assert.Equal(t, xxhash.Checksum64(message[INDEX_CONTENT:]), header.ContentHash) }
func NewMessage(id MessageId, content []byte) RawMessage { contentLen := len(content) size := HEADER_LENGTH + contentLen buffer := make([]byte, size) buffer[INDEX_START] = START_VALUE byteOrder.PutUint64(buffer[INDEX_ID:], uint64(id)) byteOrder.PutUint32(buffer[INDEX_LENGTH:], uint32(contentLen)) byteOrder.PutUint64(buffer[INDEX_HASH:], xxhash.Checksum64(content)) copy(buffer[INDEX_CONTENT:], content) return RawMessage(buffer) }
func TestHash64CgoShort(t *testing.T) { r := C.Checksum64(in) if r != expected64 { t.Errorf("expected 0x%x, got 0x%x.", expected64, r) } }
func HashPassword(password string) string { pHash := xxhash.Checksum64([]byte(password)) var passBytes []byte passBytes = strconv.AppendUint(passBytes, pHash, 10) return string(passBytes) }
func BenchmarkXxhash64CgoVeryShort(b *testing.B) { k := []byte("Test-key-100") for i := 0; i < b.N; i++ { C.Checksum64(k) } }
func BenchmarkXxhash64Cgo(b *testing.B) { for i := 0; i < b.N; i++ { C.Checksum64(in) } }
func BenchmarkXXChecksum64Cgo(b *testing.B) { var bv uint64 for i := 0; i < b.N; i++ { bv += CGO.Checksum64(in) } }