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


Golang hex.Dump函数代码示例

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


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

示例6: Pipe

func Pipe(local net.Conn, remote net.Conn) {
	local_chan := chanFromConn(local)
	remote_chan := chanFromConn(remote)
	for {
		select {
		case b1 := <-local_chan:
			if b1 == nil {
				return
			}
			out_str := fmt.Sprintf("id: %09d,%v,LOCAL>>>>>\n%s%s\n", access_id, time.Now(), hex.Dump(b1), hex.EncodeToString(b1))
			fmt.Print(out_str)
			if access_log != nil {
				access_log.Print(out_str)
			}
			remote.Write(b1)

		case b2 := <-remote_chan:
			if b2 == nil {
				return
			}
			out_str := fmt.Sprintf("id: %09d,%v,REMOTE<<<<<\n%s%s\n", access_id, time.Now(), hex.Dump(b2), hex.EncodeToString(b2))
			fmt.Print(out_str)
			if access_log != nil {
				access_log.Print(out_str)
			}
			local.Write(b2)
		}
	}
}
开发者ID:wangmingle,项目名称:reverseproxy,代码行数:29,代码来源:main.go

示例7: TestVoidUnionSetters

func TestVoidUnionSetters(t *testing.T) {
	t.Parallel()
	want := mustEncodeTestMessage(t, "VoidUnion", "(b = void)", []byte{
		0, 0, 0, 0, 2, 0, 0, 0,
		0, 0, 0, 0, 1, 0, 0, 0,
		1, 0, 0, 0, 0, 0, 0, 0,
	})

	msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatal(err)
	}
	voidUnion, err := air.NewRootVoidUnion(seg)
	if err != nil {
		t.Fatal(err)
	}
	voidUnion.SetB()

	act, err := msg.Marshal()
	if err != nil {
		t.Fatal("msg.Marshal():", err)
	}
	if !bytes.Equal(act, want) {
		t.Errorf("msg.Marshal() =\n%s\n; want:\n%s", hex.Dump(act), hex.Dump(want))
	}
}
开发者ID:soargon,项目名称:go-capnproto2,代码行数:26,代码来源:integration_test.go

示例8: GetNextN

func (i *iterator) GetNextN(it int) ([]byte, bool) {
	if i.dBug {
		i.deBug()
	}
	if i.mark+it < i.markEnd {
		markIn := i.mark
		i.mark += it
		i.bRemaining -= it

		fmt.Println(hex.Dump(i.srcIn[markIn:i.mark]))

		return i.srcIn[markIn:i.mark], true
	} else {
		if i.mark+it > i.markEnd {
			log.Println("i exceeds markEnd")
			return nil, false
		} else if i.mark+it == i.markEnd {
			markIn := i.mark
			i.mark += it
			i.bRemaining -= it

			fmt.Println(hex.Dump(i.srcIn[markIn:i.mark]))

			return i.srcIn[markIn:i.mark], true
		}
	}
	return nil, false
}
开发者ID:tbytes,项目名称:goIPP,代码行数:28,代码来源:iter.go

示例9: main

func main() {
	ee, _ := hex.DecodeString("0dd90007150b3908050b39c51243b0b80005800021bcc09082102d53cc00082efc1e012d43cc000000000100000fd9000f1300120813000fc46743b25400158000213d1ed082102cb9526ade833b9ee34eb34a04fdb4a1c6d96586a8")
	fmt.Printf("a\n%s\n\n", hex.Dump(ee))
	eee := doRS(ee[:72])
	fmt.Printf("b\n%s\n\n", hex.Dump(eee))
	return
	testMessage := "31db57800c92ae60148006745f105011a02c31c9832db2cf4e5a832df0c2fcb7cb4833d70c342d4810d9336008b3b0cf5f5e741e00002d0eaac08210000000ff0c51b92000000000efd304011a1518011b0300c5aba371de58c598c33d2658c372631b8e58c430434ab658c5aba371de581e00002d0eaac08210000000ff0c51b72000000000efd304011a1518011b0300c5aba371de58c598c33d2658c372631b8e58c430434ab658c5aba371de582180067403503455014a02c15cd832df0c35cda8015543e0c35c30d4b520c704cd803312830cefc30801cf0cb481234b8013f2813310cb4ca079c114c30cb8c30c30f5e7402180067403503455014a02ca092832df0c35cda8015543e0c36c30d0b520c704cd803312830c6f370c60073c32da048d2e004fca04cc432d3781e704530c30db1c31c7d79d2180067403503455014a02c83d4832df0c35cda8015543e0cf5c30ccb520c704cd803312830def370ca0073c32d2048d2e004fca04cc432d3181e704530c37cb1c31dfd79d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
	f, err := decodeDumpFmt(testMessage)
	fmt.Printf("%s\n", hex.Dump(f))
	if err != nil {
		panic(err)
	}
	p := createPacket(f)

	fmt.Printf("%d\n", len(p))

	fOut, err := os.Create("uat.bin")
	if err != nil {
		panic(err)
	}
	defer fOut.Close()
	outByte := iqFileOut(p)
	fmt.Printf("len=%d\n", len(outByte))
	fmt.Printf("%s\n", hex.Dump(outByte))
	for i := 0; i < 10000; i++ {
		fOut.Write(outByte)
	}
}
开发者ID:cyoung,项目名称:adsbtest,代码行数:28,代码来源:uat.go

示例10: TestFilterEncode

func TestFilterEncode(t *testing.T) {
	for _, i := range encode_filters {
		p, err := CompileFilter(i.filter_str)
		if err != nil {
			t.Errorf("Problem compiling %s - %s\n", i.filter_str, err)
		}
		fBytes, error := hex.DecodeString(i.filter_encoded)
		if error != nil {
			t.Errorf("Error decoding byte string: %s\n", i.filter_encoded)
		}
		if !bytes.Equal(p.Bytes(), fBytes) {
			l := len(fBytes)
			pBytes := p.Bytes()
			if l > len(pBytes) {
				l = len(pBytes)
			}
			for i := 0; i < l; i++ {
				if pBytes[i] != fBytes[i] {
					l = i
					break
				}
			}
			t.Errorf("Filter does not match ref bytes (first difference at byte %d) %s\n\n%s\n%s",
				l, i.filter_str, hex.Dump(p.Bytes()), hex.Dump(fBytes))
		}
	}
}
开发者ID:GJP123,项目名称:ldap,代码行数:27,代码来源:filter_test.go

示例11: TestBinaryMarshaling

func TestBinaryMarshaling(t *testing.T) {
	paths := []string{
		"pattern_1.splice",
		"pattern_2.splice",
		"pattern_3.splice",
		"pattern_4.splice",
		"pattern_5.splice"}

	for _, fp := range paths {
		b, err := ioutil.ReadFile(path.Join("sequences", fp))
		if err != nil {
			t.Fatalf("something went wrong decoding %s - %v", fp, err)
		}
		p := &Pattern{}
		if err := p.UnmarshalBinary(b); err != nil {
			t.Fatalf("something went wrong decoding %s - %v", fp, err)
		}
		b2, err := p.MarshalBinary()
		if err != nil {
			t.Fatalf("something went wrong decoding %s - %v", fp, err)
		}
		if !bytes.Equal(b[:len(b2)], b2) {
			t.Logf("failed")
			fmt.Println(fp)
			fmt.Println(hex.Dump(b))
			fmt.Println("---")
			fmt.Println(hex.Dump(b2))
			fmt.Println()
			t.Fatalf("%s wasn't decoded as expect.", fp)
		}
	}
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:32,代码来源:decoder_test.go

示例12: TestPattern

func TestPattern(t *testing.T) {
	fbuf, err := ioutil.ReadFile("fixtures/pattern_1.splice")
	if err != nil {
		t.Fatal(err)
	}

	buf := bytes.NewBuffer(fbuf)
	p, err := DecodeReader(buf)
	if err != nil {
		t.Fatal(err)
	}

	wbuf := bytes.NewBuffer([]byte{})
	_, err = p.WriteTo(wbuf)
	if err != nil {
		t.Fatal(err)
	}

	if d := bytes.Compare(fbuf, wbuf.Bytes()); d != 0 {
		t.Errorf("Difference between what was read and what was written: %d", d)
		t.Log("original\n", hex.Dump(fbuf))
		t.Log("new\n", hex.Dump(wbuf.Bytes()))

	}

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

示例13: forward_tap_to_phys

func forward_tap_to_phys(phys_conn *net.UDPConn, tap_conn *TapConn, peer_addr *net.UDPAddr, key []byte, chan_disc_peer chan net.UDPAddr) {
	/* Raw tap frame received */
	frame := make([]byte, TAP_MTU+14)
	/* Encapsulated frame and error */
	var enc_frame []byte
	var invalid error = nil
	/* Discovered peer */
	var disc_peer_addr net.UDPAddr

	/* Initialize our HMAC-SHA256 hash context */
	hmac_h := hmac.New(sha256.New, key)

	/* If a peer was specified, fill in our discovered peer information */
	if peer_addr != nil {
		disc_peer_addr.IP = peer_addr.IP
		disc_peer_addr.Port = peer_addr.Port
	} else {
		/* Otherwise, wait for the forward_phys_to_tap() goroutine to discover a peer */
		disc_peer_addr = <-chan_disc_peer
	}

	log.Printf("Starting tap->phys forwarding with peer %s:%d...\n", disc_peer_addr.IP, disc_peer_addr.Port)

	for {
		/* Read a raw frame from our tap device */
		n, err := tap_conn.Read(frame)
		if err != nil {
			log.Fatalf("Error reading from tap device!: %s\n", err)
		}

		if DEBUG == 2 {
			log.Println("<- tap  | Plaintext frame to peer:")
			log.Println("\n" + hex.Dump(frame[0:n]))
		}

		/* Encapsulate the frame */
		enc_frame, invalid = encap_frame(frame[0:n], hmac_h)

		/* Skip it if it's invalid */
		if invalid != nil {
			if DEBUG >= 1 {
				log.Printf("-> phys | Frame discarded! Size: %d, Reason: %s\n", n, invalid.Error())
				log.Println("\n" + hex.Dump(frame[0:n]))
			}
			continue
		}

		if DEBUG == 2 {
			log.Println("-> phys | Encapsulated frame to peer:")
			log.Println("\n" + hex.Dump(enc_frame))
		}

		/* Send the encapsulated frame to our peer through UDP */
		_, err = phys_conn.WriteToUDP(enc_frame, &disc_peer_addr)
		if err != nil {
			log.Fatalf("Error writing to UDP socket!: %s\n", err)
		}
	}
}
开发者ID:karlpilkington,项目名称:tinytaptunnel,代码行数:59,代码来源:tinytaptunnel.go

示例14: compare

func compare(t *testing.T, src, dst []byte) {
	if bytes.Equal(src, dst) {
		return
	}
	t.Log(hex.Dump(src))
	t.Log(hex.Dump(dst))
	t.Fatal("invalid output")
}
开发者ID:bamiaux,项目名称:iobit,代码行数:8,代码来源:writer_test.go

示例15: hdump

func hdump(emitId func(), name string, r *pcat.Record) {
	emitId()
	fmt.Printf("#--%s\n#--Query\n%s#--Reply\n%s\n",
		name,
		hex.Dump(r.Query),
		hex.Dump(r.Reply),
	)
}
开发者ID:cznic,项目名称:dns,代码行数:8,代码来源:do.go


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