psi: using binary.BigEndian.PutUin32 to put crc32 into the psi

This commit is contained in:
saxon 2019-01-07 16:23:38 +10:30
parent fa0154ad3d
commit 26f26cbeee
1 changed files with 2 additions and 4 deletions

View File

@ -27,6 +27,7 @@ LICENSE
package psi
import (
"encoding/binary"
"hash/crc32"
"math/bits"
)
@ -41,10 +42,7 @@ func addCrc(out []byte) []byte {
// updateCrc updates the crc of bytes slice, writing the checksum into the last four bytes.
func updateCrc(b []byte) []byte {
crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), b[1:len(b)-4])
b[len(b)-4] = byte(crc32 >> 24)
b[len(b)-3] = byte(crc32 >> 16)
b[len(b)-2] = byte(crc32 >> 8)
b[len(b)-1] = byte(crc32)
binary.BigEndian.PutUint32(b[len(b)-4:], crc32)
return b
}