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
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
cdc5f8f4
Commit
cdc5f8f4
authored
Jan 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
f076b1b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
40 deletions
+51
-40
t/neo/marshal.go
t/neo/marshal.go
+14
-28
t/neo/protogen.go
t/neo/protogen.go
+37
-12
No files found.
t/neo/marshal.go
View file @
cdc5f8f4
...
...
@@ -1456,7 +1456,7 @@ overflow:
// 43. StoreObject
func
(
p
*
StoreObject
)
NEOEncodedLen
()
int
{
return
58
+
len
(
p
.
Data
)
*
1
return
58
+
len
(
p
.
Data
)
}
func
(
p
*
StoreObject
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1487,11 +1487,8 @@ func (p *StoreObject) NEOEncode(data []byte) {
l
:=
uint32
(
len
(
p
.
Data
))
binary
.
BigEndian
.
PutUint32
(
data
[
37
:
],
l
)
data
=
data
[
41
:
]
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
Data
[
i
]
(
data
[
0
:
])[
0
]
=
(
*
a
)
data
=
data
[
1
:
]
}
copy
(
data
,
p
.
Data
)
data
=
data
[
l
:
]
}
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
DataSerial
))
binary
.
BigEndian
.
PutUint64
(
data
[
8
:
],
uint64
(
p
.
Tid
))
...
...
@@ -1529,17 +1526,13 @@ func (p *StoreObject) NEODecode(data []byte) (int, error) {
{
l
:=
binary
.
BigEndian
.
Uint32
(
data
[
37
:
])
data
=
data
[
41
:
]
nread
+=
41
if
uint32
(
len
(
data
))
<
17
+
l
*
1
{
nread
+=
41
+
l
if
uint32
(
len
(
data
))
<
17
+
l
{
goto
overflow
}
nread
+=
l
*
1
p
.
Data
=
make
([]
byte
,
l
)
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
Data
[
i
]
(
*
a
)
=
(
data
[
0
:
])[
0
]
data
=
data
[
1
:
]
}
copy
(
p
.
Data
,
data
[
:
l
])
data
=
data
[
l
:
]
}
p
.
DataSerial
=
Tid
(
binary
.
BigEndian
.
Uint64
(
data
[
0
:
]))
p
.
Tid
=
Tid
(
binary
.
BigEndian
.
Uint64
(
data
[
8
:
]))
...
...
@@ -1743,7 +1736,7 @@ overflow:
// 49. AnswerGetObject
func
(
p
*
AnswerGetObject
)
NEOEncodedLen
()
int
{
return
57
+
len
(
p
.
Data
)
*
1
return
57
+
len
(
p
.
Data
)
}
func
(
p
*
AnswerGetObject
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1775,11 +1768,8 @@ func (p *AnswerGetObject) NEOEncode(data []byte) {
l
:=
uint32
(
len
(
p
.
Data
))
binary
.
BigEndian
.
PutUint32
(
data
[
45
:
],
l
)
data
=
data
[
49
:
]
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
Data
[
i
]
(
data
[
0
:
])[
0
]
=
(
*
a
)
data
=
data
[
1
:
]
}
copy
(
data
,
p
.
Data
)
data
=
data
[
l
:
]
}
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
DataSerial
))
}
...
...
@@ -1816,17 +1806,13 @@ func (p *AnswerGetObject) NEODecode(data []byte) (int, error) {
{
l
:=
binary
.
BigEndian
.
Uint32
(
data
[
45
:
])
data
=
data
[
49
:
]
nread
+=
49
if
uint32
(
len
(
data
))
<
8
+
l
*
1
{
nread
+=
49
+
l
if
uint32
(
len
(
data
))
<
8
+
l
{
goto
overflow
}
nread
+=
l
*
1
p
.
Data
=
make
([]
byte
,
l
)
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
Data
[
i
]
(
*
a
)
=
(
data
[
0
:
])[
0
]
data
=
data
[
1
:
]
}
copy
(
p
.
Data
,
data
[
:
l
])
data
=
data
[
l
:
]
}
p
.
DataSerial
=
Tid
(
binary
.
BigEndian
.
Uint64
(
data
[
0
:
]))
return
8
+
int
(
nread
),
nil
...
...
t/neo/protogen.go
View file @
cdc5f8f4
...
...
@@ -222,8 +222,8 @@ type CodecCodeGen interface {
genSlice
(
path
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
genMap
(
path
string
,
typ
*
types
.
Map
,
obj
types
.
Object
)
//
XXX particular case of slice
genS
trBytes
(
path
string
)
//
particular case of slice or array with 1-byte elem
genS
lice1
(
path
string
,
typ
types
.
Type
)
// get generated code.
// for top-level functions this is whole function including return and closing }
...
...
@@ -514,12 +514,12 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
// len u32
// [len]byte
// TODO []byte support
func
(
s
*
sizer
)
genS
trBytes
(
path
string
)
{
func
(
s
*
sizer
)
genS
lice1
(
path
string
,
typ
types
.
Type
)
{
s
.
size
.
Add
(
4
)
s
.
size
.
AddExpr
(
"len(%s)"
,
path
)
}
func
(
e
*
encoder
)
genS
trBytes
(
path
string
)
{
func
(
e
*
encoder
)
genS
lice1
(
path
string
,
typ
types
.
Type
)
{
e
.
emit
(
"{"
)
e
.
emit
(
"l := uint32(len(%s))"
,
path
)
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
...
...
@@ -530,7 +530,7 @@ func (e *encoder) genStrBytes(path string) {
e
.
n
=
0
}
func
(
d
*
decoder
)
genS
trBytes
(
assignto
string
)
{
func
(
d
*
decoder
)
genS
lice1
(
assignto
string
,
typ
types
.
Type
)
{
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
...
...
@@ -541,7 +541,22 @@ func (d *decoder) genStrBytes(assignto string) {
d
.
overflowCheckpoint
()
d
.
overflowCheckSize
.
AddExpr
(
"l"
)
d
.
emit
(
"%v= string(data[:l])"
,
assignto
)
switch
t
:=
typ
.
(
type
)
{
case
*
types
.
Basic
:
if
t
.
Kind
()
!=
types
.
String
{
log
.
Panicf
(
"bad basic type in slice1: %v"
,
t
)
}
d
.
emit
(
"%v= string(data[:l])"
,
assignto
)
case
*
types
.
Slice
:
// TODO not copy, but reference data from original
d
.
emit
(
"%v= make(%v, l)"
,
assignto
,
typeName
(
typ
))
d
.
emit
(
"copy(%v, data[:l])"
,
assignto
)
default
:
log
.
Panicf
(
"bad type in slice1: %v"
,
typ
)
}
d
.
emit
(
"data = data[l:]"
)
d
.
emit
(
"}"
)
}
...
...
@@ -776,7 +791,7 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod
switch
u
:=
typ
.
Underlying
()
.
(
type
)
{
case
*
types
.
Basic
:
if
u
.
Kind
()
==
types
.
String
{
codegen
.
genS
trBytes
(
path
)
codegen
.
genS
lice1
(
path
,
u
)
break
}
...
...
@@ -793,14 +808,24 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod
}
case
*
types
.
Array
:
// TODO optimize for [...]byte
var
i
int64
// XXX because `u.Len() int64`
for
i
=
0
;
i
<
u
.
Len
();
i
++
{
codegenType
(
fmt
.
Sprintf
(
"%v[%v]"
,
path
,
i
),
u
.
Elem
(),
obj
,
codegen
)
elemSize
,
_
:=
typeSizeFixed
(
u
.
Elem
())
// [...]byte or [...]uint8 - just straight copy
if
false
&&
elemSize
==
1
{
//codegen.genStrBytes(path+"[:]") // FIXME
codegen
.
genSlice1
(
path
,
u
)
// FIXME
}
else
{
var
i
int64
// XXX because `u.Len() int64`
for
i
=
0
;
i
<
u
.
Len
();
i
++
{
codegenType
(
fmt
.
Sprintf
(
"%v[%v]"
,
path
,
i
),
u
.
Elem
(),
obj
,
codegen
)
}
}
case
*
types
.
Slice
:
codegen
.
genSlice
(
path
,
u
,
obj
)
if
elemSize
,
_
:=
typeSizeFixed
(
u
.
Elem
());
elemSize
==
1
{
codegen
.
genSlice1
(
path
,
u
)
}
else
{
codegen
.
genSlice
(
path
,
u
,
obj
)
}
case
*
types
.
Map
:
codegen
.
genMap
(
path
,
u
,
obj
)
...
...
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