mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-19 01:30:26 +08:00
feat(head): use uniform head extract & crc64 -> md5
This commit is contained in:
22
gold/head/raw.go
Normal file
22
gold/head/raw.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package head
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
// CRC64 extract packet header checksum
|
||||
func CRC64(data []byte) uint64 {
|
||||
return binary.LittleEndian.Uint64(data[52:PacketHeadLen])
|
||||
}
|
||||
|
||||
// CalcCRC64 calculate packet header checksum
|
||||
func CalcCRC64(data []byte) uint64 {
|
||||
m := md5.Sum(data[:52])
|
||||
return binary.LittleEndian.Uint64(m[:8])
|
||||
}
|
||||
|
||||
// Hash extract 32 bytes blake2b hash from raw bytes
|
||||
func Hash(data []byte) []byte {
|
||||
return data[20:52]
|
||||
}
|
||||
Reference in New Issue
Block a user