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
b6f9859c
Commit
b6f9859c
authored
Jan 19, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
cfd55c2c
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
495 additions
and
651 deletions
+495
-651
t/neo/marshal.go
t/neo/marshal.go
+461
-637
t/neo/proto.go
t/neo/proto.go
+6
-3
t/neo/protogen.go
t/neo/protogen.go
+28
-11
No files found.
t/neo/marshal.go
View file @
b6f9859c
This diff is collapsed.
Click to expand it.
t/neo/proto.go
View file @
b6f9859c
...
@@ -94,9 +94,12 @@ var ErrDecodeOverflow = errors.New("decode: bufer overflow")
...
@@ -94,9 +94,12 @@ var ErrDecodeOverflow = errors.New("decode: bufer overflow")
// NEOEncoder is interface for marshaling objects to wire format in NEO
// NEOEncoder is interface for marshaling objects to wire format in NEO
type
NEOEncoder
interface
{
type
NEOEncoder
interface
{
// NEOEncodedLen() int ?
// compute how much space is needed to encode
// XXX len(buf) must be >= NEOEncodedLen()
NEOEncodedLen
()
int
NEOEncode
(
buf
[]
byte
)
(
nwrote
int
)
// perform the encoding.
// len(buf) must be >= NEOEncodedLen() // XXX check in tests it will panic
NEOEncode
(
buf
[]
byte
)
}
}
// NEODecoder is interface for unmarshalling objects from wire format in NEO
// NEODecoder is interface for unmarshalling objects from wire format in NEO
...
...
t/neo/protogen.go
View file @
b6f9859c
...
@@ -212,8 +212,8 @@ func (d *decoder) generatedCode() string {
...
@@ -212,8 +212,8 @@ func (d *decoder) generatedCode() string {
}
}
func
(
e
*
encoder
)
genPrologue
(
recvName
,
typeName
string
)
{
func
(
e
*
encoder
)
genPrologue
(
recvName
,
typeName
string
)
{
e
.
emit
(
"func (%s *%s) NEOEncode(data []byte)
int /*(int, error)*/
{"
,
recvName
,
typeName
)
e
.
emit
(
"func (%s *%s) NEOEncode(data []byte) {"
,
recvName
,
typeName
)
e
.
emit
(
"var nwrote uint32"
)
//
e.emit("var nwrote uint32")
}
}
func
(
d
*
decoder
)
genPrologue
(
recvName
,
typeName
string
)
{
func
(
d
*
decoder
)
genPrologue
(
recvName
,
typeName
string
)
{
...
@@ -222,10 +222,10 @@ func (d *decoder) genPrologue(recvName, typeName string) {
...
@@ -222,10 +222,10 @@ func (d *decoder) genPrologue(recvName, typeName string) {
}
}
func
(
e
*
encoder
)
genEpilogue
()
{
func
(
e
*
encoder
)
genEpilogue
()
{
e
.
emit
(
"return int(nwrote) + %v /*, nil*/"
,
e
.
n
)
//
e.emit("return int(nwrote) + %v /*, nil*/", e.n)
e
.
emit
(
"
\n
overflow:"
)
//
e.emit("\noverflow:")
e
.
emit
(
"panic(0) //return 0, ErrEncodeOverflow"
)
//
e.emit("panic(0) //return 0, ErrEncodeOverflow")
e
.
emit
(
"goto overflow"
)
// TODO remove
//
e.emit("goto overflow") // TODO remove
e
.
emit
(
"}
\n
"
)
e
.
emit
(
"}
\n
"
)
}
}
...
@@ -268,7 +268,7 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
...
@@ -268,7 +268,7 @@ 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 to encode/decode
next
string or []byte
// emit code to encode/decode string or []byte
// len u32
// len u32
// [len]byte
// [len]byte
// TODO []byte support
// TODO []byte support
...
@@ -296,14 +296,31 @@ func (d *decoder) genStrBytes(assignto string) {
...
@@ -296,14 +296,31 @@ func (d *decoder) genStrBytes(assignto string) {
d
.
n
=
0
d
.
n
=
0
}
}
// emit code to encode/decode slice
// len u32
// [len]item
// TODO optimize for []byte
func
(
e
*
encoder
)
genSlice
(
path
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
{
func
(
e
*
encoder
)
genSlice
(
path
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
{
e
.
emit
(
"// TODO slice"
)
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
(
"nwrote += %v"
,
e
.
n
)
e
.
n
=
0
// TODO size check
// TODO if size(item)==const - check l in one go
e
.
emit
(
"for i := 0; uint32(i) <l; i++ {"
)
e
.
emit
(
"a := &%s[i]"
,
path
)
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
e
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
// FIXME wrt slice of slice ?
e
.
emit
(
"nwrote += %v"
,
e
.
n
)
e
.
emit
(
"}"
)
// see vvv
e
.
emit
(
"}"
)
e
.
n
=
0
}
}
// TODO optimize for []byte
func
(
d
*
decoder
)
genSlice
(
assignto
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
{
func
(
d
*
decoder
)
genSlice
(
assignto
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
{
// len u32
// [len]item
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