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

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

示例1: DumpBinlog

func (mc *mysqlConn) DumpBinlog(filename string, position uint32) (driver.Rows, error) {
    ServerId := uint32(1) // Must be non-zero to avoid getting EOF packet
    flags := uint16(0)

    e := mc.writeCommandPacket(COM_BINLOG_DUMP, position, flags, ServerId, filename)
    if e != nil {
        return nil, e
    }

    for {
        pkt, e := mc.readPacket()
        if e != nil {
            return nil, e
        } else if pkt[0] == 254 { // EOF packet
            break
        }
        if pkt[0] == 0 {
            var header EventHeader
            if e := header.Read(pkt[1:]); e != nil {
                return nil, e
            }
            header.Print()
            fmt.Printf("Event Data:\n%s\n\n", hex.Dump(pkt[20:]))
        } else {
            fmt.Printf("Unknown packet:\n%s\n\n", hex.Dump(pkt))
        }
    }

    return nil, nil
}

开发者ID:orenmazor,项目名称:go-mysql-binlog,代码行数:30,代码来源:binlog.go

示例2: TestPattern_Encode

func TestPattern_Encode(t *testing.T) {
    for _, f := range []string{
        "pattern_1.splice",
        "pattern_2.splice",
        "pattern_3.splice",
        "pattern_4.splice",
        "pattern_5.splice",
    } {
        raw, err := ioutil.ReadFile(path.Join("fixtures", f))
        if err != nil {
            t.Fatalf("unable to read %s, %v", f, err)
        }

        decoded, err := Decode(bytes.NewBuffer(raw))
        if err != nil {
            t.Fatalf("unable to decode %s, %v", f, err)
        }

        encoded := bytes.NewBuffer([]byte{})
        if err := decoded.Encode(encoded); err != nil {
            t.Fatalf("unable to encode %s, %v", f, err)
        }

        rawEncoded := encoded.Bytes()
        if !bytes.HasPrefix(raw, rawEncoded) {
            t.Errorf(
                "encoded did not match raw for %s.\nExpected:\n\n%s\n\nActual:\n\n%s",
                f,
                hex.Dump(raw),
                hex.Dump(rawEncoded),
            )
        }
    }
}

开发者ID:billyboar,项目名称:GCSolutions,代码行数:34,代码来源:pattern_test.go

示例3: Write

// Write implements io.Writer.
func (w SecureWriter) Write(buf []byte) (int, error) {
    if uint64(len(buf)) > maxMessageSize {
        return 0, fmt.Errorf("input is too large. Got %d bytes, max: %d", len(buf), maxMessageSize)
    }

    // Create a nonce.
    nonce, err := NewNonce()
    if err != nil {
        return 0, err
    }
    debugf("Write: nonce\n%s\n", hex.Dump(nonce[:]))

    // Encrypt the message with the nonce prefix.
    sealed := box.SealAfterPrecomputation(nonce[:], buf, nonce, w.key)

    debugf("Write: sealed %d bytes\n%s\n", len(sealed), hex.Dump(sealed))

    // Write a fixed header indicating how long the message is.
    header := uint64(len(sealed))
    headerSize := binary.Size(header)
    if err := binary.Write(w.w, binary.BigEndian, header); err != nil {
        return headerSize, err
    }

    // Write the message.
    messageSize, err := w.w.Write(sealed)

    // Return the size of the header and the message.
    return headerSize + messageSize, err
}

开发者ID:billyboar,项目名称:GCSolutions,代码行数:31,代码来源:io.go

示例4: FmtAt

func (h *Hexer) FmtAt(offset, n int64) string {

    grab := int64(16)

    _, err := h.Seek(offset, 0)
    if err != nil {
        return ""
    }
    leftover := n % grab
    var buf = make([]byte, n+leftover)
    _, err = h.Read(buf)

    if err != nil {
        return ""
    }

    st := ""
    i := int64(0)
    for i = int64(0); i < int64(n/grab); i++ {
        stT := hex.Dump(buf[i*grab : i*grab+16])
        os := fmt.Sprintf("%08x", offset+i*grab)
        stT = strings.Replace(stT, "00000000", os, 1)
        st = st + stT
    }
    if leftover > 0 {
        stT := hex.Dump(buf[n-leftover : n])
        os := fmt.Sprintf("%08x", offset+n-leftover)
        stT = strings.Replace(stT, "00000000", os, 1)
        st = st + stT
    }
    return st
}

开发者ID:dmarkham,项目名称:dmarkham-downtown-eat-drink-go-aug-20,代码行数:32,代码来源:hexseeker.go

示例5: TestDecodeEncodePattern

func TestDecodeEncodePattern(t *testing.T) {
    tData := []string{
        "pattern_1.splice",
        "pattern_2.splice",
        "pattern_3.splice",
    }

    for _, exp := range tData {
        expected, err := ioutil.ReadFile(path.Join("fixtures", exp))
        decoded := Pattern{}
        err = Unmarshal(expected, &decoded)
        if err != nil {
            t.Fatal(err)
        }

        actual, err := Marshal(decoded)

        if !bytes.Equal(actual, expected) {
            t.Errorf("%s was incorrectly encoded", exp)
            t.Log("Expected\n" + hex.Dump(expected))
            t.Log("Got\n" + hex.Dump(actual))
            t.Logf("First diff at index %#x", firstDiff(actual, expected))
        }

    }

}

开发者ID:billyboar,项目名称:GCSolutions,代码行数:27,代码来源:write_test.go

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