Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
1f89aa94
Commit
1f89aa94
authored
Aug 11, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5f517fdc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
7 deletions
+31
-7
go/neo/pkt.go
go/neo/pkt.go
+31
-7
No files found.
go/neo/pkt.go
View file @
1f89aa94
...
...
@@ -22,6 +22,7 @@ package neo
import
(
"fmt"
"reflect"
"unsafe"
)
...
...
@@ -54,8 +55,7 @@ func (pkt *PktBuf) Payload() []byte {
}
// Strings dumps a packet
// XXX -> use .Dump() for full dump?
// Strings dumps a packet in human-readable form
func
(
pkt
*
PktBuf
)
String
()
string
{
if
len
(
pkt
.
Data
)
<
PktHeadLen
{
return
fmt
.
Sprintf
(
"(! < PktHeadLen) % x"
,
pkt
.
Data
)
...
...
@@ -65,15 +65,39 @@ func (pkt *PktBuf) String() string {
s
:=
fmt
.
Sprintf
(
".%d"
,
ntoh32
(
h
.
ConnId
))
msgCode
:=
ntoh16
(
h
.
MsgCode
)
msgLen
:=
ntoh32
(
h
.
MsgLen
)
data
:=
pkt
.
Payload
()
msgType
:=
msgTypeRegistry
[
msgCode
]
if
msgType
==
nil
{
s
+=
fmt
.
Sprintf
(
" ? (%d)"
,
msgCode
)
}
else
{
s
+=
fmt
.
Sprintf
(
" %s"
,
msgType
)
s
+=
fmt
.
Sprintf
(
" ? (%d) #%d [%d]: % x"
,
msgCode
,
msgLen
,
len
(
data
),
data
)
return
s
}
s
+=
fmt
.
Sprintf
(
" #%d | "
,
ntoh32
(
h
.
MsgLen
))
// XXX dup wrt Conn.Recv
msg
:=
reflect
.
New
(
msgType
)
.
Interface
()
.
(
Msg
)
n
,
err
:=
msg
.
neoMsgDecode
(
data
)
if
err
!=
nil
{
s
+=
fmt
.
Sprintf
(
" (%s) %v; #%d [%d]: % x"
,
msgType
,
err
,
msgLen
,
len
(
data
),
data
)
}
s
+=
fmt
.
Sprintf
(
" %s %+v"
,
msgType
.
Name
(),
msg
)
if
n
<
len
(
data
)
{
tail
:=
data
[
n
:
]
s
+=
fmt
.
Sprintf
(
" ; [%d]tail: % x"
,
len
(
tail
),
tail
)
}
s
+=
fmt
.
Sprintf
(
"% x"
,
pkt
.
Payload
())
// XXX better decode
return
s
}
// Dump dumps a packet in raw form
func
(
pkt
*
PktBuf
)
Dump
()
string
{
if
len
(
pkt
.
Data
)
<
PktHeadLen
{
return
fmt
.
Sprintf
(
"(! < PktHeadLen) % x"
,
pkt
.
Data
)
}
h
:=
pkt
.
Header
()
data
:=
pkt
.
Payload
()
return
fmt
.
Sprintf
(
".%d (%d) #%d [%d]: % x"
,
ntoh32
(
h
.
ConnId
),
ntoh16
(
h
.
MsgCode
),
ntoh32
(
h
.
MsgLen
),
len
(
data
),
data
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment