File: README.md

package info (click to toggle)
golang-github-howeyc-crc16 0.0~git20171223.2b2a61e-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 84 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[![GoDoc](https://godoc.org/github.com/howeyc/crc16?status.svg)](https://godoc.org/github.com/howeyc/crc16) [![Build Status](https://secure.travis-ci.org/howeyc/crc16.png?branch=master)](http://travis-ci.org/howeyc/crc16)

# CRC16
A Go package implementing the 16-bit Cyclic Redundancy Check, or CRC-16, checksum.

## Usage
To generate the hash of a byte slice, use the [`crc16.Checksum()`](https://godoc.org/github.com/howeyc/crc16#Checksum) function:
```golang
import "github.com/howeyc/crc16"

data := byte("test")
checksum := crc16.Checksum(data, crc16.IBMTable)
```

The package provides [the following](https://godoc.org/github.com/howeyc/crc16#pkg-variables) hashing tables. For each of these tables, a shorthand can be used.
```golang
// This is the same as crc16.Checksum(data, crc16.IBMTable)
checksum := crc16.ChecksumIBM(data)
```

Using the [hash.Hash](https://godoc.org/hash#Hash) interface also works.
```go
h := crc16.New(crc16.IBMTable)
data := byte("test")
data2 := byte("data")
h.Write(data)
h.Write(data2)
checksum := h.Sum(nil)
```

## Changelog
* 2017.03.27 - Added MBus checksum
* 2017.05.27 - Added checksum function without XOR
* 2017.12.08 - Implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to allow saving and recreating their internal state.