当前位置: 首页>>代码示例>>Golang>>正文


Golang crc32.NewIEEE函数代码示例

本文整理汇总了Golang中hash/crc32.NewIEEE函数的典型用法代码示例。如果您正苦于以下问题:Golang NewIEEE函数的具体用法?Golang NewIEEE怎么用?Golang NewIEEE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewIEEE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMultiCoreChecksummedWriter

func TestMultiCoreChecksummedWriter(t *testing.T) {
	buf := &bytes.Buffer{}
	cw := NewMultiCoreChecksummedWriter(buf, 16, crc32.NewIEEE, runtime.GOMAXPROCS(0))
	if cw == nil {
		t.Fatal(cw)
	}
	n, err := cw.Write([]byte("12345678901234567890"))
	if n != 20 {
		t.Fatal(n)
	}
	if err != nil {
		t.Fatal(err)
	}
	hash := crc32.NewIEEE()
	hash.Write([]byte("1234567890123456"))
	n, err = cw.Write([]byte("ghijklmnopqrstuvwxyz"))
	if n != 20 {
		t.Fatal(n)
	}
	if err != nil {
		t.Fatal(err)
	}
	hash2 := crc32.NewIEEE()
	hash2.Write([]byte("7890ghijklmnopqr"))
	err = cw.Close()
	if err != nil {
		t.Fatal(err)
	}
	hash3 := crc32.NewIEEE()
	hash3.Write([]byte("stuvwxyz"))
	if !bytes.Equal(buf.Bytes(), []byte("1234567890123456"+string(hash.Sum(nil))+"7890ghijklmnopqr"+string(hash2.Sum(nil))+"stuvwxyz"+string(hash3.Sum(nil)))) {
		t.Fatalf("%#v", string(buf.Bytes()))
	}
}
开发者ID:wreese,项目名称:valuestore,代码行数:34,代码来源:checksummedio_test.go

示例2: makeOuts

func makeOuts(testIntents []*intents.Intent, demux *Demultiplexer, outChecksum map[string]hash.Hash, demuxOuts map[string]*RegularCollectionReceiver, outLengths map[string]*int, errCh chan<- error) {
	for _, dbc := range testIntents {
		ns := dbc.Namespace()
		sum := crc32.NewIEEE()
		muxOut := &RegularCollectionReceiver{
			Intent: dbc,
			Demux:  demux,
			Origin: ns,
		}
		outLength := 0

		outChecksum[ns] = sum
		demuxOuts[ns] = muxOut
		outLengths[ns] = &outLength

		demuxOuts[ns].Open()
		go func() {
			bs := make([]byte, db.MaxBSONSize)
			var err error
			for {
				var length int
				length, err = muxOut.Read(bs)
				if err != nil {
					break
				}
				sum.Write(bs[:length])
				outLength += len(bs[:length])
			}
			if err == io.EOF {
				err = nil
			}
			errCh <- err
		}()
	}
}
开发者ID:Machyne,项目名称:mongo,代码行数:35,代码来源:multiplexer_roundtrip_test.go

示例3: ChecksumValid

func (m *Dot11) ChecksumValid() bool {
	// only for CTRL and MGMT frames
	h := crc32.NewIEEE()
	h.Write(m.Contents)
	h.Write(m.Payload)
	return m.Checksum == h.Sum32()
}
开发者ID:nplanel,项目名称:gopacket,代码行数:7,代码来源:dot11.go

示例4: run

func (d *decoder) run() error {
	// init hash
	d.crcHash = crc32.NewIEEE()
	// for each part
	for {
		// create a part
		d.part = new(Part)
		// read the header
		if err := d.readHeader(); err != nil {
			return err
		}
		// read part header if available
		if d.multipart {
			if err := d.readPartHeader(); err != nil {
				return err
			}
		}
		// decode the part body
		if err := d.readBody(); err != nil {
			return err
		}
		// add part to list
		d.parts = append(d.parts, d.part)
		// validate part
		if err := d.part.validate(); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:dominikh,项目名称:yenc,代码行数:30,代码来源:yenc.go

示例5: Open

// Open returns a ReadCloser that provides access to the File's contents.
// Multiple files may be read concurrently.
func (f *File) Open() (rc io.ReadCloser, err error) {
	bodyOffset, err := f.findBodyOffset()
	if err != nil {
		return
	}
	size := int64(f.CompressedSize64)
	r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset, size)
	switch f.Method {
	case Store: // (no compression)
		rc = ioutil.NopCloser(r)
	case Deflate:
		rc, err = zlib.NewReader(r)
		if err != nil {
			return
		}
	default:
		err = ErrAlgorithm
		return
	}
	var desr io.Reader
	if f.hasDataDescriptor() {
		desr = io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset+size, dataDescriptorLen)
	}
	rc = &checksumReader{rc, crc32.NewIEEE(), f, desr, nil}
	return
}
开发者ID:uwedeportivo,项目名称:torrentzip,代码行数:28,代码来源:reader.go

示例6: handleIndex

// handleIndex returns the index XML file to the client.
func (s *EC2HTTPTestStorage) handleIndex(w http.ResponseWriter, req *http.Request) {
	lbr := &listBucketResult{
		Name:        "juju-dist",
		Prefix:      "",
		Marker:      "",
		MaxKeys:     1000,
		IsTruncated: false,
	}
	names := []string{}
	for name := range s.files {
		names = append(names, name)
	}
	sort.Strings(names)
	for _, name := range names {
		h := crc32.NewIEEE()
		h.Write([]byte(s.files[name]))
		contents := &contents{
			Key:          name,
			LastModified: time.Now(),
			ETag:         fmt.Sprintf("%x", h.Sum(nil)),
			Size:         len([]byte(s.files[name])),
			StorageClass: "STANDARD",
		}
		lbr.Contents = append(lbr.Contents, contents)
	}
	buf, err := xml.Marshal(lbr)
	if err != nil {
		http.Error(w, fmt.Sprintf("500 %v", err), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "application/xml")
	w.Write(buf)
}
开发者ID:CSRedRat,项目名称:juju-core,代码行数:34,代码来源:storage.go

示例7: decode

// decode deserializes one log entry from the passed io.Reader.
func (e *logEntry) decode(r io.Reader) error {
	header := make([]byte, 24)

	if _, err := r.Read(header); err != nil {
		return err
	}

	command := make([]byte, binary.LittleEndian.Uint32(header[20:24]))

	if _, err := r.Read(command); err != nil {
		return err
	}

	crc := binary.LittleEndian.Uint32(header[:4])

	check := crc32.NewIEEE()
	check.Write(header[4:])
	check.Write(command)

	if crc != check.Sum32() {
		return errInvalidChecksum
	}

	e.Term = binary.LittleEndian.Uint64(header[4:12])
	e.Index = binary.LittleEndian.Uint64(header[12:20])
	e.Command = command

	return nil
}
开发者ID:0x434D53,项目名称:raft,代码行数:30,代码来源:log.go

示例8: UnmarshalBinary

// UnmarshalBinary reads header from the provided data slice.
func (h *header) UnmarshalBinary(data []byte) error {
	// header length
	if len(data) != HeaderLen {
		return errors.New("xz: wrong file header length")
	}

	// magic header
	if !bytes.Equal(headerMagic, data[:6]) {
		return errHeaderMagic
	}

	// checksum
	crc := crc32.NewIEEE()
	crc.Write(data[6:8])
	if uint32LE(data[8:]) != crc.Sum32() {
		return errors.New("xz: invalid checksum for file header")
	}

	// stream flags
	if data[6] != 0 {
		return errInvalidFlags
	}
	flags := data[7]
	if err := verifyFlags(flags); err != nil {
		return err
	}

	h.flags = flags
	return nil
}
开发者ID:ulikunitz,项目名称:xz,代码行数:31,代码来源:format.go

示例9: MarshalBinary

// MarshalBinary converts footer values into an xz file footer. Note
// that the footer value is checked for correctness.
func (f *footer) MarshalBinary() (data []byte, err error) {
	if err = verifyFlags(f.flags); err != nil {
		return nil, err
	}
	if !(minIndexSize <= f.indexSize && f.indexSize <= maxIndexSize) {
		return nil, errors.New("xz: index size out of range")
	}
	if f.indexSize%4 != 0 {
		return nil, errors.New(
			"xz: index size not aligned to four bytes")
	}

	data = make([]byte, footerLen)

	// backward size (index size)
	s := (f.indexSize / 4) - 1
	putUint32LE(data[4:], uint32(s))
	// flags
	data[9] = f.flags
	// footer magic
	copy(data[10:], footerMagic)

	// CRC-32
	crc := crc32.NewIEEE()
	crc.Write(data[4:10])
	putUint32LE(data, crc.Sum32())

	return data, nil
}
开发者ID:ulikunitz,项目名称:xz,代码行数:31,代码来源:format.go

示例10: SmallIndexer

func SmallIndexer(gene genome.Gene) (index []byte) {
	hash := crc32.NewIEEE()
	// 	//TODO: fix me
	hash.Write(gene)
	index = hash.Sum()
	return
}
开发者ID:ericfode,项目名称:Datazome,代码行数:7,代码来源:smallIndexer.go

示例11: newRequest

// Used internally to create and initialize a new request.
func newRequest(request *http.Request, conn net.Conn, startTime time.Time) *Request {
	fReq := new(Request)
	fReq.Context = make(map[string]interface{})
	fReq.HttpRequest = request
	fReq.StartTime = startTime
	fReq.connection = conn
	if conn != nil {
		fReq.RemoteAddr = conn.RemoteAddr().(*net.TCPAddr)
	}

	// create a semi-unique id to track a connection in the logs
	// ID is the least significant decimal digits of time with some randomization
	// the last 3 zeros of time.Nanoseconds appear to always be zero
	var ut = fReq.StartTime.UnixNano()
	fReq.ID = fmt.Sprintf("%010x", (ut-(ut-(ut%1e12)))+int64(rand.Intn(999)))
	fReq.PipelineStageStats = list.New()
	fReq.pipelineHash = crc32.NewIEEE()

	// Support for 100-continue requests
	// http.Server (and presumably google app engine) already handle this
	// case.  So we don't need to do anything if we don't own the
	// connection.
	if conn != nil && request.Header.Get("Expect") == "100-continue" {
		request.Body = &continueReader{req: fReq, r: request.Body}
	}

	return fReq
}
开发者ID:dcmrlee,项目名称:falcore,代码行数:29,代码来源:request.go

示例12: TestFileBigWriteWeirdBlockSize

func TestFileBigWriteWeirdBlockSize(t *testing.T) {
	client := getClient(t)

	baleet(t, "/_test/create/4.txt")
	mkdirp(t, "/_test/create")
	writer, err := client.CreateFile("/_test/create/4.txt", 1, 1050000, 0755)
	require.NoError(t, err)

	mobydick, err := os.Open("test/mobydick.txt")
	require.NoError(t, err)

	n, err := io.Copy(writer, mobydick)
	require.NoError(t, err)
	assert.EqualValues(t, 1257276, n)

	err = writer.Close()
	require.NoError(t, err)

	reader, err := client.Open("/_test/create/4.txt")
	require.NoError(t, err)

	hash := crc32.NewIEEE()
	n, err = io.Copy(hash, reader)
	assert.Nil(t, err)
	assert.EqualValues(t, 1257276, n)
	assert.EqualValues(t, 0x199d1ae6, hash.Sum32())
}
开发者ID:Microsoft,项目名称:colinmarc-hdfs,代码行数:27,代码来源:file_writer_test.go

示例13: ProcessBuffer

func ProcessBuffer(c <-chan m.MetricDefinition) {
	buf := make(map[uint32][]m.MetricDefinition)

	// flush buffer 10 times every second
	t := time.NewTicker(time.Millisecond * 100)
	for {
		select {
		case b := <-c:
			if b.OrgId != 0 {
				//get hash.
				h := crc32.NewIEEE()
				h.Write([]byte(b.Name))
				hash := h.Sum32() % uint32(1024)
				if _, ok := buf[hash]; !ok {
					buf[hash] = make([]m.MetricDefinition, 0)
				}
				buf[hash] = append(buf[hash], b)
			}
		case <-t.C:
			//copy contents of buffer
			for hash, metrics := range buf {
				currentBuf := make([]m.MetricDefinition, len(metrics))
				copy(currentBuf, metrics)
				delete(buf, hash)
				//log.Info(fmt.Sprintf("flushing %d items in buffer now", len(currentBuf)))
				msgString, err := json.Marshal(currentBuf)
				if err != nil {
					log.Error(0, "Failed to marshal metrics payload.", err)
				} else {
					go Publish(fmt.Sprintf("%d", hash), msgString)
				}
			}
		}
	}
}
开发者ID:reduxdj,项目名称:grafana,代码行数:35,代码来源:metricpublisher.go

示例14: newReader

func newReader(fn string) (*reader, error) {
	f, err := os.OpenFile(fn, os.O_RDONLY, 0)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	fi, err := f.Stat()
	if err != nil {
		return nil, err
	}

	var data gommap.MMap
	var zero bool
	if fi.Size() <= 0 {
		zero = true
	} else {
		data, err = gommap.Map(f.Fd(), gommap.PROT_READ, gommap.MAP_SHARED)
		if err != nil {
			return nil, err
		}
	}

	r := &reader{
		cs:   crc32.NewIEEE(),
		data: data,
		zero: zero,
		done: zero, // noop reader if zero-byte file
	}
	r.bv.Data = data

	return r, nil
}
开发者ID:rboyer,项目名称:wal,代码行数:33,代码来源:reader.go

示例15: checksumsPass

func checksumsPass(romname string, rom *clrmamepro.Block, f io.Reader) bool {
	crc := crc32.NewIEEE()
	md := md5.New()
	sha := sha1.New()
	checksums := io.MultiWriter(crc, md, sha)

	_, err := io.Copy(checksums, f)
	if err != nil {
		die("checksumming ROM %q: %v", romname, err)
	}

	compare := func(h hash.Hash, expected string) bool {
		return strings.ToUpper(fmt.Sprintf("%x", h.Sum(nil))) == strings.ToUpper(expected)
	}
	if !compare(crc, rom.Texts[fCRC32]) {
		alert("BAD CRC32", romname)
		return false
	}
	if !compare(md, rom.Texts[fMD5]) {
		alert("BAD MD5", romname)
		return false
	}
	if !compare(sha, rom.Texts[fSHA1]) {
		alert("BAD SHA1", romname)
		return false
	}

	return true
}
开发者ID:andlabs,项目名称:nointrochk,代码行数:29,代码来源:check.go


注:本文中的hash/crc32.NewIEEE函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。