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

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

示例1: TestNeedle

func TestNeedle(t *testing.T) {
    var (
        err       error
        n, tn     *Needle
        br        *bufio.Reader
        data1     = []byte("tes1")
        checksum1 = crc32.Update(0, _crc32Table, data1)
        data2     = []byte("tes2")
        checksum2 = crc32.Update(0, _crc32Table, data2)
        buf       = &bytes.Buffer{}
    )
    // WriteFrom
    if _, err = buf.Write(data1); err != nil {
        t.Error(err)
        t.FailNow()
    }
    n = NewWriter(3, 3, 4)
    defer n.Close()
    if err = n.ReadFrom(buf); err != nil {
        t.Error(err)
        t.FailNow()
    }
    t.Log(n)
    tn = new(Needle)
    tn.buffer = n.Buffer()
    // Parse
    if err = tn.Parse(); err != nil {
        t.Error(err)
        t.FailNow()
    }
    t.Log(n)
    compareNeedle(t, tn, 3, 3, data1, FlagOK, checksum1)
    buf.Write(data2)
    n = NewWriter(4, 4, 4)
    defer n.Close()
    if err = n.ReadFrom(buf); err != nil {
        t.Error(err)
        t.FailNow()
    }
    tn = new(Needle)
    tn.buffer = n.Buffer()
    if err = tn.Parse(); err != nil {
        t.Error(err)
        t.FailNow()
    }
    compareNeedle(t, tn, 4, 4, data2, FlagOK, checksum2)
    // ParseFrom
    if _, err = buf.Write(n.Buffer()); err != nil {
        t.Error(err)
        t.FailNow()
    }
    br = bufio.NewReader(buf)
    tn = new(Needle)
    if err = tn.ParseFrom(br); err != nil {
        t.Error(err)
        t.FailNow()
    }
    t.Log(tn)
    compareNeedle(t, tn, 4, 4, data2, FlagOK, checksum2)
}

开发者ID:Terry-Mao,项目名称:bfs,代码行数:60,代码来源:needle_test.go

示例2: finishBlock

func (w *Writer) finishBlock() (blockHandle, error) {
    if w.nEntries == 0 {
        w.restarts = w.restarts[:1]
        w.restarts[0] = 0
    }
    tmp4 := w.tmp[:4]
    for _, x := range w.restarts {
        binary.LittleEndian.PutUint32(tmp4, x)
        w.buf.Write(tmp4)
    }
    binary.LittleEndian.PutUint32(tmp4, uint32(len(w.restarts)))
    w.buf.Write(tmp4)

    b := w.buf.Bytes()
    w.tmp[0] = 0

    checksum := crc32.Update(0, table, b)
    checksum = crc32.Update(checksum, table, w.tmp[:1])
    checksum = uint32(checksum>>15|checksum<<17) + 0xa282ead8
    binary.LittleEndian.PutUint32(w.tmp[1:5], checksum)

    if _, err := w.writer.Write(b); err != nil {
        return blockHandle{}, err
    }
    if _, err := w.writer.Write(w.tmp[:5]); err != nil {
        return blockHandle{}, err
    }
    bh := blockHandle{int64(w.offset), int64(len(b))}
    w.offset += uint64(len(b)) + BlockTrailerLen

    w.buf.Reset()
    w.nEntries = 0
    w.restarts = w.restarts[:0]
    return bh, nil
}

开发者ID:jmptrader,项目名称:esdb,代码行数:35,代码来源:writer.go

示例3: calcNewCRC32

func calcNewCRC32(path string, newHeader *BinaryHeader) (uint32, error) {
    buf := &bytes.Buffer{}
    err := binary.Write(buf, binary.BigEndian, newHeader)
    if err != nil {
        return 0, err
    }

    header := buf.Bytes()
    crc := crc32.Checksum(header[:28], crc32.IEEETable) // before crc32
    crc = crc32.Update(crc, crc32.IEEETable, header[32:])

    f, err := os.Open(path)
    if err != nil {
        return 0, err
    }
    defer f.Close()

    if _, err := f.Seek(int64(len(header)), os.SEEK_SET); err != nil {
        return 0, err
    }

    data := make([]byte, 4*1024*1024)
    for {
        n, err := f.Read(data)
        crc = crc32.Update(crc, crc32.IEEETable, data[:n])
        if err != nil {
            if err != io.EOF {
                return 0, err
            }
            break
        }
    }
    return crc, nil
}

开发者ID:nobu-k,项目名称:jubamodel,代码行数:34,代码来源:rewrite_version.go

示例4: FillNeedleBuf

// FillNeedleBuf fill needle buf with photo.
func FillNeedleBuf(key, cookie int64, data, buf []byte) (size int32) {
    var (
        n        int
        padding  int32
        checksum = crc32.Update(0, crc32Table, data)
    )
    size = int32(NeedleHeaderSize + len(data) + NeedleFooterSize)
    padding = NeedlePaddingSize - (size % NeedlePaddingSize)
    size += padding
    // header
    copy(buf[:needleMagicSize], needleHeaderMagic)
    n += needleMagicSize
    BigEndian.PutInt64(buf[n:], cookie)
    n += needleCookieSize
    BigEndian.PutInt64(buf[n:], key)
    n += needleKeySize
    buf[n] = NeedleStatusOK
    n += needleFlagSize
    BigEndian.PutInt32(buf[n:], int32(len(data)))
    n += needleSizeSize
    // data
    copy(buf[n:], data)
    n += len(data)
    // footer
    copy(buf[n:], needleFooterMagic)
    n += needleMagicSize
    BigEndian.PutUint32(buf[n:], checksum)
    n += needleChecksumSize
    copy(buf[n:], needlePadding[padding])
    return
}

开发者ID:w3-golang,项目名称:bfs,代码行数:32,代码来源:needle.go

示例5: ParseNeedleData

// ParseNeedleData parse a needle data part.
func ParseNeedleData(buf []byte, n *Needle) (err error) {
    var (
        bn       int32
        checksum uint32
    )
    n.Data = buf[:n.Size]
    bn += n.Size
    n.FooterMagic = buf[bn : bn+needleMagicSize]
    if bytes.Compare(n.FooterMagic, needleFooterMagic) != 0 {
        err = ErrNeedleFooterMagic
        return
    }
    bn += needleMagicSize
    checksum = crc32.Update(0, crc32Table, n.Data)
    n.Checksum = BigEndian.Uint32(buf[bn : bn+needleChecksumSize])
    if n.Checksum != checksum {
        err = ErrNeedleChecksum
        return
    }
    bn += needleChecksumSize
    n.Padding = buf[bn : bn+n.PaddingSize]
    log.Printf("padding: %d, %v vs %v\n", n.PaddingSize, n.Padding, needlePadding[n.PaddingSize])
    if bytes.Compare(n.Padding, needlePadding[n.PaddingSize]) != 0 {
        err = ErrNeedlePaddingNotMatch
        return
    }
    return
}

开发者ID:w3-golang,项目名称:bfs,代码行数:29,代码来源:needle.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng