Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
cfd55c2c
Commit
cfd55c2c
authored
Jan 19, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c00fc182
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
180 additions
and
37 deletions
+180
-37
t/neo/marshal.go
t/neo/marshal.go
+168
-33
t/neo/protogen.go
t/neo/protogen.go
+12
-4
No files found.
t/neo/marshal.go
View file @
cfd55c2c
...
@@ -10,7 +10,16 @@ import (
...
@@ -10,7 +10,16 @@ import (
func
(
p
*
Address
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
func
(
p
*
Address
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
var
nwrote
uint32
var
nwrote
uint32
// TODO strbytes
{
l
:=
uint32
(
len
(
p
.
Host
))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Host
)
nwrote
+=
4
+
l
}
binary
.
BigEndian
.
PutUint16
(
data
[
0
:
],
p
.
Port
)
binary
.
BigEndian
.
PutUint16
(
data
[
0
:
],
p
.
Port
)
return
int
(
nwrote
)
+
2
/*, nil*/
return
int
(
nwrote
)
+
2
/*, nil*/
...
@@ -44,12 +53,21 @@ overflow:
...
@@ -44,12 +53,21 @@ overflow:
func
(
p
*
NodeInfo
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
func
(
p
*
NodeInfo
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
var
nwrote
uint32
var
nwrote
uint32
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
(
p
.
NodeType
)))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
(
p
.
NodeType
)))
// TODO strbytes
{
binary
.
BigEndian
.
PutUint16
(
data
[
4
:
],
p
.
Address
.
Port
)
l
:=
uint32
(
len
(
p
.
Address
.
Host
))
binary
.
BigEndian
.
PutUint32
(
data
[
6
:
],
uint32
(
int32
(
p
.
UUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
l
)
binary
.
BigEndian
.
PutUint32
(
data
[
10
:
],
uint32
(
int32
(
p
.
NodeState
)))
data
=
data
[
8
:
]
float64_NEOEncode
(
data
[
14
:
],
p
.
IdTimestamp
)
if
uint32
(
len
(
data
))
<
l
{
return
int
(
nwrote
)
+
22
/*, nil*/
goto
overflow
}
copy
(
data
,
p
.
Address
.
Host
)
nwrote
+=
8
+
l
}
binary
.
BigEndian
.
PutUint16
(
data
[
0
:
],
p
.
Address
.
Port
)
binary
.
BigEndian
.
PutUint32
(
data
[
2
:
],
uint32
(
int32
(
p
.
UUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
6
:
],
uint32
(
int32
(
p
.
NodeState
)))
float64_NEOEncode
(
data
[
10
:
],
p
.
IdTimestamp
)
return
int
(
nwrote
)
+
18
/*, nil*/
overflow
:
overflow
:
panic
(
0
)
//return 0, ErrEncodeOverflow
panic
(
0
)
//return 0, ErrEncodeOverflow
...
@@ -144,7 +162,16 @@ overflow:
...
@@ -144,7 +162,16 @@ overflow:
func
(
p
*
Notify
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
func
(
p
*
Notify
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
var
nwrote
uint32
var
nwrote
uint32
// TODO strbytes
{
l
:=
uint32
(
len
(
p
.
Message
))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Message
)
nwrote
+=
4
+
l
}
return
int
(
nwrote
)
+
0
/*, nil*/
return
int
(
nwrote
)
+
0
/*, nil*/
overflow
:
overflow
:
...
@@ -176,8 +203,17 @@ overflow:
...
@@ -176,8 +203,17 @@ overflow:
func
(
p
*
Error
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
func
(
p
*
Error
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
var
nwrote
uint32
var
nwrote
uint32
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
p
.
Code
)
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
p
.
Code
)
// TODO strbytes
{
return
int
(
nwrote
)
+
4
/*, nil*/
l
:=
uint32
(
len
(
p
.
Message
))
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
l
)
data
=
data
[
8
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Message
)
nwrote
+=
8
+
l
}
return
int
(
nwrote
)
+
0
/*, nil*/
overflow
:
overflow
:
panic
(
0
)
//return 0, ErrEncodeOverflow
panic
(
0
)
//return 0, ErrEncodeOverflow
...
@@ -251,11 +287,29 @@ func (p *RequestIdentification) NEOEncode(data []byte) int /*(int, error)*/ {
...
@@ -251,11 +287,29 @@ func (p *RequestIdentification) NEOEncode(data []byte) int /*(int, error)*/ {
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
p
.
ProtocolVersion
)
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
p
.
ProtocolVersion
)
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
uint32
(
int32
(
p
.
NodeType
)))
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
uint32
(
int32
(
p
.
NodeType
)))
binary
.
BigEndian
.
PutUint32
(
data
[
8
:
],
uint32
(
int32
(
p
.
UUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
8
:
],
uint32
(
int32
(
p
.
UUID
)))
// TODO strbytes
{
binary
.
BigEndian
.
PutUint16
(
data
[
12
:
],
p
.
Address
.
Port
)
l
:=
uint32
(
len
(
p
.
Address
.
Host
))
// TODO strbytes
binary
.
BigEndian
.
PutUint32
(
data
[
12
:
],
l
)
float64_NEOEncode
(
data
[
14
:
],
p
.
IdTimestamp
)
data
=
data
[
16
:
]
return
int
(
nwrote
)
+
22
/*, nil*/
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Address
.
Host
)
nwrote
+=
16
+
l
}
binary
.
BigEndian
.
PutUint16
(
data
[
0
:
],
p
.
Address
.
Port
)
{
l
:=
uint32
(
len
(
p
.
Name
))
binary
.
BigEndian
.
PutUint32
(
data
[
2
:
],
l
)
data
=
data
[
6
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Name
)
nwrote
+=
6
+
l
}
float64_NEOEncode
(
data
[
0
:
],
p
.
IdTimestamp
)
return
int
(
nwrote
)
+
8
/*, nil*/
overflow
:
overflow
:
panic
(
0
)
//return 0, ErrEncodeOverflow
panic
(
0
)
//return 0, ErrEncodeOverflow
...
@@ -305,10 +359,19 @@ func (p *AcceptIdentification) NEOEncode(data []byte) int /*(int, error)*/ {
...
@@ -305,10 +359,19 @@ func (p *AcceptIdentification) NEOEncode(data []byte) int /*(int, error)*/ {
binary
.
BigEndian
.
PutUint32
(
data
[
8
:
],
p
.
NumPartitions
)
binary
.
BigEndian
.
PutUint32
(
data
[
8
:
],
p
.
NumPartitions
)
binary
.
BigEndian
.
PutUint32
(
data
[
12
:
],
p
.
NumReplicas
)
binary
.
BigEndian
.
PutUint32
(
data
[
12
:
],
p
.
NumReplicas
)
binary
.
BigEndian
.
PutUint32
(
data
[
16
:
],
uint32
(
int32
(
p
.
YourUUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
16
:
],
uint32
(
int32
(
p
.
YourUUID
)))
// TODO strbytes
{
binary
.
BigEndian
.
PutUint16
(
data
[
20
:
],
p
.
Primary
.
Port
)
l
:=
uint32
(
len
(
p
.
Primary
.
Host
))
binary
.
BigEndian
.
PutUint32
(
data
[
20
:
],
l
)
data
=
data
[
24
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Primary
.
Host
)
nwrote
+=
24
+
l
}
binary
.
BigEndian
.
PutUint16
(
data
[
0
:
],
p
.
Primary
.
Port
)
// TODO slice
// TODO slice
return
int
(
nwrote
)
+
2
2
/*, nil*/
return
int
(
nwrote
)
+
2
/*, nil*/
overflow
:
overflow
:
panic
(
0
)
//return 0, ErrEncodeOverflow
panic
(
0
)
//return 0, ErrEncodeOverflow
...
@@ -1350,11 +1413,38 @@ overflow:
...
@@ -1350,11 +1413,38 @@ overflow:
func
(
p
*
StoreTransaction
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
func
(
p
*
StoreTransaction
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
var
nwrote
uint32
var
nwrote
uint32
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
Tid
))
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
Tid
))
// TODO strbytes
{
// TODO strbytes
l
:=
uint32
(
len
(
p
.
User
))
// TODO strbytes
binary
.
BigEndian
.
PutUint32
(
data
[
8
:
],
l
)
data
=
data
[
12
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
User
)
nwrote
+=
12
+
l
}
{
l
:=
uint32
(
len
(
p
.
Description
))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Description
)
nwrote
+=
4
+
l
}
{
l
:=
uint32
(
len
(
p
.
Extension
))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Extension
)
nwrote
+=
4
+
l
}
// TODO slice
// TODO slice
return
int
(
nwrote
)
+
8
/*, nil*/
return
int
(
nwrote
)
+
0
/*, nil*/
overflow
:
overflow
:
panic
(
0
)
//return 0, ErrEncodeOverflow
panic
(
0
)
//return 0, ErrEncodeOverflow
...
@@ -1691,12 +1781,39 @@ overflow:
...
@@ -1691,12 +1781,39 @@ overflow:
func
(
p
*
AnswerTransactionInformation
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
func
(
p
*
AnswerTransactionInformation
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
var
nwrote
uint32
var
nwrote
uint32
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
Tid
))
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
Tid
))
// TODO strbytes
{
// TODO strbytes
l
:=
uint32
(
len
(
p
.
User
))
// TODO strbytes
binary
.
BigEndian
.
PutUint32
(
data
[
8
:
],
l
)
(
data
[
8
:
])[
0
]
=
bool2byte
(
p
.
Packed
)
data
=
data
[
12
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
User
)
nwrote
+=
12
+
l
}
{
l
:=
uint32
(
len
(
p
.
Description
))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Description
)
nwrote
+=
4
+
l
}
{
l
:=
uint32
(
len
(
p
.
Extension
))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Extension
)
nwrote
+=
4
+
l
}
(
data
[
0
:
])[
0
]
=
bool2byte
(
p
.
Packed
)
// TODO slice
// TODO slice
return
int
(
nwrote
)
+
9
/*, nil*/
return
int
(
nwrote
)
+
1
/*, nil*/
overflow
:
overflow
:
panic
(
0
)
//return 0, ErrEncodeOverflow
panic
(
0
)
//return 0, ErrEncodeOverflow
...
@@ -2459,12 +2576,30 @@ overflow:
...
@@ -2459,12 +2576,30 @@ overflow:
func
(
p
*
CheckPartition
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
func
(
p
*
CheckPartition
)
NEOEncode
(
data
[]
byte
)
int
/*(int, error)*/
{
var
nwrote
uint32
var
nwrote
uint32
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
p
.
Partition
)
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
p
.
Partition
)
// TODO strbytes
{
// TODO strbytes
l
:=
uint32
(
len
(
p
.
Source
.
UpstreamName
))
binary
.
BigEndian
.
PutUint16
(
data
[
4
:
],
p
.
Source
.
Address
.
Port
)
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
l
)
binary
.
BigEndian
.
PutUint64
(
data
[
6
:
],
uint64
(
p
.
MinTID
))
data
=
data
[
8
:
]
binary
.
BigEndian
.
PutUint64
(
data
[
14
:
],
uint64
(
p
.
MaxTID
))
if
uint32
(
len
(
data
))
<
l
{
return
int
(
nwrote
)
+
22
/*, nil*/
goto
overflow
}
copy
(
data
,
p
.
Source
.
UpstreamName
)
nwrote
+=
8
+
l
}
{
l
:=
uint32
(
len
(
p
.
Source
.
Address
.
Host
))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
}
copy
(
data
,
p
.
Source
.
Address
.
Host
)
nwrote
+=
4
+
l
}
binary
.
BigEndian
.
PutUint16
(
data
[
0
:
],
p
.
Source
.
Address
.
Port
)
binary
.
BigEndian
.
PutUint64
(
data
[
2
:
],
uint64
(
p
.
MinTID
))
binary
.
BigEndian
.
PutUint64
(
data
[
10
:
],
uint64
(
p
.
MaxTID
))
return
int
(
nwrote
)
+
18
/*, nil*/
overflow
:
overflow
:
panic
(
0
)
//return 0, ErrEncodeOverflow
panic
(
0
)
//return 0, ErrEncodeOverflow
...
...
t/neo/protogen.go
View file @
cfd55c2c
...
@@ -268,15 +268,23 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
...
@@ -268,15 +268,23 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
d
.
emit
(
"%s= %s"
,
assignto
,
decoded
)
d
.
emit
(
"%s= %s"
,
assignto
,
decoded
)
}
}
// emit code for decode next string or []byte
// emit code to encode/decode next string or []byte
// len u32
// [len]byte
// TODO []byte support
// TODO []byte support
func
(
e
*
encoder
)
genStrBytes
(
path
string
)
{
func
(
e
*
encoder
)
genStrBytes
(
path
string
)
{
e
.
emit
(
"// TODO strbytes"
)
e
.
emit
(
"{"
)
e
.
emit
(
"l := uint32(len(%s))"
,
path
)
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
e
.
emit
(
"if uint32(len(data)) < l { goto overflow }"
)
e
.
emit
(
"copy(data, %v)"
,
path
)
e
.
emit
(
"nwrote += %v + l"
,
e
.
n
)
e
.
emit
(
"}"
)
e
.
n
=
0
}
}
func
(
d
*
decoder
)
genStrBytes
(
assignto
string
)
{
func
(
d
*
decoder
)
genStrBytes
(
assignto
string
)
{
// len u32
// [len]byte
d
.
emit
(
"{"
)
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
...
...
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