多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# package crc32 `import "hash/crc32"` crc32包实现了32位循环冗余校验(CRC-32)的校验和算法,参见: [http://en.wikipedia.org/wiki/Cyclic_redundancy_check](http://en.wikipedia.org/wiki/Cyclic_redundancy_check) ## Index * [Constants](#pkg-constants) * [Variables](#pkg-variables) * [type Table](#Table) * [func MakeTable(poly uint32) \*Table](#MakeTable) * [func Checksum(data []byte, tab \*Table) uint32](#Checksum) * [func ChecksumIEEE(data []byte) uint32](#ChecksumIEEE) * [func Update(crc uint32, tab \*Table, p []byte) uint32](#Update) * [func New(tab \*Table) hash.Hash32](#New) * [func NewIEEE() hash.Hash32](#NewIEEE) ## Constants ``` const ( // 最常用的CRC-32多项式;用于以太网、v.42、fddi、gzip、zip、png、mpeg-2…… IEEE = 0xedb88320 // 卡斯塔尼奥利多项式,用在iSCSI;有比IEEE更好的错误探测特性 // http://dx.doi.org/10.1109/26.231911 Castagnoli = 0x82f63b78 // 库普曼多项式;错误探测特性也比IEEE好 // http://dx.doi.org/10.1109/DSN.2002.1028931 Koopman = 0xeb31d82e ) ``` 预定义的多项式。 ``` const Size = 4 ``` CRC-32校验和的字节长度。 ## Variables ``` var IEEETable = MakeTable(IEEE) ``` IEEETable是IEEE多项式对应的Table。 ## type [Table](https://github.com/golang/go/blob/master/src/hash/crc32/crc32.go#L36 "View Source") ``` type Table [256]uint32 ``` 长度256的uint32切片,代表一个用于高效运作的多项式。 ### func [MakeTable](https://github.com/golang/go/blob/master/src/hash/crc32/crc32.go#L53 "View Source") ``` func MakeTable(poly uint32) *Table ``` 返回一个代表poly指定的多项式的Table。 ## func [Checksum](https://github.com/golang/go/blob/master/src/hash/crc32/crc32.go#L131 "View Source") ``` func Checksum(data []byte, tab *Table) uint32 ``` 返回数据data使用tab代表的多项式计算出的CRC-32校验和。 ## func [ChecksumIEEE](https://github.com/golang/go/blob/master/src/hash/crc32/crc32.go#L135 "View Source") ``` func ChecksumIEEE(data []byte) uint32 ``` 返回数据data使用IEEE多项式计算出的CRC-32校验和。 ## func [Update](https://github.com/golang/go/blob/master/src/hash/crc32/crc32.go#L110 "View Source") ``` func Update(crc uint32, tab *Table, p []byte) uint32 ``` 返回将切片p的数据采用tab表示的多项式添加到crc之后计算出的新校验和。 ## func [New](https://github.com/golang/go/blob/master/src/hash/crc32/crc32.go#L89 "View Source") ``` func New(tab *Table) hash.Hash32 ``` 创建一个使用tab代表的多项式计算CRC-32校验和的hash.Hash32接口。 ## func [NewIEEE](https://github.com/golang/go/blob/master/src/hash/crc32/crc32.go#L93 "View Source") ``` func NewIEEE() hash.Hash32 ``` 创建一个使用IEEE多项式计算CRC-32校验和的hash.Hash32接口。