本文整理汇总了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
示例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
示例16: TestKISS
func TestKISS(t *testing.T) {
v := aprs.ParseFrame(christmasMsg)
bc := EncodeAPRSCommand(v)
t.Logf("Command:\n" + hex.Dump(bc))
br := EncodeAPRSResponse(v)
t.Logf("Response:\n" + hex.Dump(br))
}
开发者ID:dustin,项目名称:go-aprs,代码行数:8,代码来源:encode_test.go
示例17: TestBind
func TestBind(t *testing.T) {
tx := []byte{
0x00, 0x00, 0x00, 0x2A, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x73, 0x6D, 0x70, 0x70, 0x63, 0x6C, 0x69, 0x65,
0x6E, 0x74, 0x31, 0x00, 0x70, 0x61, 0x73, 0x73,
0x77, 0x6F, 0x72, 0x64, 0x00, 0x00, 0x34, 0x00,
0x00, 0x00,
}
pdu := NewBindTransmitter()
f := pdu.Fields()
f.Set(pdufield.SystemID, "smppclient1")
f.Set(pdufield.Password, "password")
f.Set(pdufield.InterfaceVersion, 0x34)
pdu.Header().Seq = 1
var b bytes.Buffer
if err := pdu.SerializeTo(&b); err != nil {
t.Fatal(err)
}
l := uint32(b.Len())
if l != pdu.Header().Len {
t.Fatalf("unexpected len: want %d, have %d", l, pdu.Header().Len)
}
if !bytes.Equal(tx, b.Bytes()) {
t.Fatalf("unexpected bytes:\nwant:\n%s\nhave:\n%s",
hex.Dump(tx), hex.Dump(b.Bytes()))
}
pdu, err := Decode(&b)
if err != nil {
t.Fatal(err)
}
h := pdu.Header()
if h.ID != BindTransmitterID {
t.Fatalf("unexpected ID: want %d, have %d",
BindTransmitterID, h.ID)
}
if h.Seq != 1 {
t.Fatalf("unexpected Seq: want 1, have %d", h.Seq)
}
test := []struct {
n pdufield.Name
v string
}{
{pdufield.SystemID, "smppclient1"},
{pdufield.Password, "password"},
{pdufield.InterfaceVersion, strconv.Itoa(0x34)},
}
for _, el := range test {
f := pdu.Fields()[el.n]
if f == nil {
t.Fatalf("missing field: %s", el.n)
}
if f.String() != el.v {
t.Fatalf("unexpected value for %q: want %q, have %q",
el.n, el.v, f.String())
}
}
}
开发者ID:VDVsx,项目名称:go-smpp,代码行数:58,代码来源:types_test.go
示例18: TestDataVersioningAvoidsUnnecessaryTruncation
func TestDataVersioningAvoidsUnnecessaryTruncation(t *testing.T) {
t.Parallel()
in := mustEncodeTestMessage(t, "VerTwoDataTwoPtr", "(val = 9, duo = 8, ptr1 = (val = 77), ptr2 = (val = 55))", []byte{
0, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 2, 0, 2, 0,
9, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 1, 0, 0, 0,
4, 0, 0, 0, 1, 0, 0, 0,
77, 0, 0, 0, 0, 0, 0, 0,
55, 0, 0, 0, 0, 0, 0, 0,
})
want := mustEncodeTestMessage(t, "Wrap2x2", "(mightNotBeReallyEmpty = (val = 9, duo = 8, ptr1 = (val = 77), ptr2 = (val = 55)))", []byte{
0, 0, 0, 0, 8, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 2, 0, 2, 0,
9, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 1, 0, 0, 0,
4, 0, 0, 0, 1, 0, 0, 0,
77, 0, 0, 0, 0, 0, 0, 0,
55, 0, 0, 0, 0, 0, 0, 0,
})
msg, err := capnp.Unmarshal(in)
if err != nil {
t.Fatal("Unmarshal:", err)
}
// Read in the message as if it's an old client (less fields in schema).
oldRoot, err := air.ReadRootVerEmpty(msg)
if err != nil {
t.Fatal("ReadRootVerEmpty:", err)
}
// Store the larger message into another segment.
freshMsg, freshSeg, err := capnp.NewMessage(capnp.SingleSegment(nil))
if err != nil {
t.Fatal("NewMessage:", err)
}
wrapEmpty, err := air.NewRootWrapEmpty(freshSeg)
if err != nil {
t.Fatal("NewRootWrapEmpty:", err)
}
if err := wrapEmpty.SetMightNotBeReallyEmpty(oldRoot); err != nil {
t.Fatal("SetMightNotBeReallyEmpty:", err)
}
// Verify that it matches the expected serialization.
out, err := freshMsg.Marshal()
if err != nil {
t.Fatal("Marshal:", err)
}
if !bytes.Equal(out, want) {
t.Errorf("After copy, data is:\n%s\nwant:\n%s", hex.Dump(out), hex.Dump(want))
}
}
开发者ID:soargon,项目名称:go-capnproto2,代码行数:57,代码来源:integration_test.go
示例19: handler
func handler(w http.ResponseWriter, r *http.Request) {
u, err := url.Parse(r.FormValue("url"))
if err != nil {
serve(w, r, &Result{Err: err.Error()})
return
}
hostname := u.Host
if hostname == "" {
serve(w, r, &Result{Err: "Can't get Hostname"})
return
}
path := u.Path
if path == "" {
path = "/"
}
if u.RawQuery != "" {
path = fmt.Sprintf("%s?%s", u.Path, u.RawQuery)
}
fmt.Println(hostname)
fmt.Println(path)
endpoint := r.FormValue("endpoint")
var dstip net.IP
if endpoint == "" {
endpoint = hostname
}
ipstr := r.FormValue("ip")
if ipstr == "" {
dstaddrs, err := net.LookupIP(endpoint)
if err != nil {
serve(w, r, &Result{Err: err.Error()})
return
}
dstip = dstaddrs[0].To4()
} else {
dstip = net.ParseIP(ipstr)
}
fmt.Println(dstip)
if dstip == nil {
serve(w, r, &Result{Err: "ip error"})
return
}
c_fullpayload := make(chan int)
req, _ := http.NewRequest("GET", fmt.Sprintf("http://%s%s", dstip.String(), path), nil)
req.Host = hostname
go getfullbodysize(c_fullpayload, req)
pkt_count, payload_size, fullpayload, err := initcwndcheck.Detectinitcwnd(hostname, path, dstip)
fullpayloadsize := <-c_fullpayload
if err != nil {
serve(w, r, &Result{pkt_count, payload_size, fullpayloadsize, hex.Dump(fullpayload), err.Error(), dstip.String()})
} else {
serve(w, r, &Result{pkt_count, payload_size, fullpayloadsize, hex.Dump(fullpayload), "", dstip.String()})
}
}
开发者ID:turbobytes,项目名称:initcwndcheck,代码行数:56,代码来源:server.go
示例20: TestPack
func TestPack(t *testing.T) {
for _, test := range compressionTests {
orig := make([]byte, len(test.original))
copy(orig, test.original)
compressed := Pack(nil, orig)
if !bytes.Equal(compressed, test.compressed) {
t.Errorf("Pack(nil,\n%s\n) =\n%s\n; want\n%s", hex.Dump(test.original), hex.Dump(compressed), hex.Dump(test.compressed))
}
}
}
开发者ID:startupit69,项目名称:go-capnproto2,代码行数:10,代码来源:packed_test.go
注:本文中的encoding/hex.Dump函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论