Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(508)

Side by Side Diff: snappy/crc/crc.go

Issue 5167058: snappy: add a reader and writer for the frame format.
Patch Set: diff -r fa2afaefa608 https://code.google.com/p/snappy-go/ Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « snappy/crc/Makefile ('k') | snappy/reader.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 The Snappy-Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package crc implements the checksum used in snappy's frame format.
6 //
7 // The algorithm is CRC-32 with Castagnoli's polynomial, followed by a bit
8 // rotation and an additional delta. The additional processing is to lessen the
9 // probability that arbitrary data coincidentally contains bytes that look like
10 // a checksum.
11 //
12 // To calculate the uint32 checksum of some data:
13 // var u uint32 = crc.New(data).Value()
14 package crc
15
16 import (
17 "hash/crc32"
18 )
19
20 var table = crc32.MakeTable(crc32.Castagnoli)
21
22 type CRC uint32
23
24 func New(b []byte) CRC {
25 return CRC(0).Update(b)
26 }
27
28 func (c CRC) Update(b []byte) CRC {
29 return CRC(crc32.Update(uint32(c), table, b))
30 }
31
32 func (c CRC) Value() uint32 {
33 return uint32(c>>15|c<<17) + 0xa282ead8
34 }
OLDNEW
« no previous file with comments | « snappy/crc/Makefile ('k') | snappy/reader.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b