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
3d4bc65f
Commit
3d4bc65f
authored
Jan 14, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X draft of varable length tracking
parent
f596b330
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
259 additions
and
88 deletions
+259
-88
t/neo/marshal.go
t/neo/marshal.go
+252
-87
t/neo/protogen.go
t/neo/protogen.go
+7
-1
No files found.
t/neo/marshal.go
View file @
3d4bc65f
This diff is collapsed.
Click to expand it.
t/neo/protogen.go
View file @
3d4bc65f
...
@@ -213,6 +213,7 @@ func (d *decoder) emitstrbytes(assignto string) {
...
@@ -213,6 +213,7 @@ func (d *decoder) emitstrbytes(assignto string) {
d
.
emit
(
"if uint32(len(data)) < l { return 0, ErrDecodeOverflow }"
)
d
.
emit
(
"if uint32(len(data)) < l { return 0, ErrDecodeOverflow }"
)
d
.
emit
(
"%v = string(data[:l])"
,
assignto
)
d
.
emit
(
"%v = string(data[:l])"
,
assignto
)
d
.
emit
(
"data = data[l:]"
)
d
.
emit
(
"data = data[l:]"
)
d
.
emit
(
"nread += %v + l"
,
d
.
n
)
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
d
.
n
=
0
d
.
n
=
0
}
}
...
@@ -223,6 +224,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
...
@@ -223,6 +224,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
// [len]item
// [len]item
d
.
emit
(
"{ l := %v"
,
d
.
decodedBasic
(
nil
,
types
.
Typ
[
types
.
Uint32
]))
d
.
emit
(
"{ l := %v"
,
d
.
decodedBasic
(
nil
,
types
.
Typ
[
types
.
Uint32
]))
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"nread += %v"
,
d
.
n
)
d
.
n
=
0
d
.
n
=
0
d
.
emit
(
"%v = make(%v, l)"
,
assignto
,
typeName
(
typ
))
d
.
emit
(
"%v = make(%v, l)"
,
assignto
,
typeName
(
typ
))
// TODO size check
// TODO size check
...
@@ -233,6 +235,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
...
@@ -233,6 +235,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
// XXX try to avoid (*) in a
// XXX try to avoid (*) in a
d
.
emitobjtype
(
"(*a)"
,
obj
,
typ
.
Elem
())
// XXX also obj.Elem() ?
d
.
emitobjtype
(
"(*a)"
,
obj
,
typ
.
Elem
())
// XXX also obj.Elem() ?
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
// FIXME wrt slice of slice ?
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
// FIXME wrt slice of slice ?
d
.
emit
(
"nread += %v"
,
d
.
n
)
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
//d.emit("%v = string(data[:l])", assignto)
//d.emit("%v = string(data[:l])", assignto)
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
...
@@ -244,6 +247,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) {
...
@@ -244,6 +247,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) {
// [len](key, value)
// [len](key, value)
d
.
emit
(
"{ l := %v"
,
d
.
decodedBasic
(
nil
,
types
.
Typ
[
types
.
Uint32
]))
d
.
emit
(
"{ l := %v"
,
d
.
decodedBasic
(
nil
,
types
.
Typ
[
types
.
Uint32
]))
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"nread += %v"
,
d
.
n
)
d
.
n
=
0
d
.
n
=
0
d
.
emit
(
"%v = make(%v, l)"
,
assignto
,
typeName
(
typ
))
d
.
emit
(
"%v = make(%v, l)"
,
assignto
,
typeName
(
typ
))
// TODO size check
// TODO size check
...
@@ -267,6 +271,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) {
...
@@ -267,6 +271,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) {
}
}
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
// FIXME wrt map of map ?
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
// FIXME wrt map of map ?
d
.
emit
(
"nread += %v"
,
d
.
n
)
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
//d.emit("%v = string(data[:l])", assignto)
//d.emit("%v = string(data[:l])", assignto)
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
...
@@ -326,6 +331,7 @@ func gendecode(typespec *ast.TypeSpec) string {
...
@@ -326,6 +331,7 @@ func gendecode(typespec *ast.TypeSpec) string {
d
:=
decoder
{}
d
:=
decoder
{}
// prologue
// prologue
d
.
emit
(
"func (p *%s) NEODecode(data []byte) (int, error) {"
,
typespec
.
Name
.
Name
)
d
.
emit
(
"func (p *%s) NEODecode(data []byte) (int, error) {"
,
typespec
.
Name
.
Name
)
d
.
emit
(
"var nread uint32"
)
//n := 0
//n := 0
//t := typespec.Type.(*ast.StructType) // must be
//t := typespec.Type.(*ast.StructType) // must be
...
@@ -336,7 +342,7 @@ func gendecode(typespec *ast.TypeSpec) string {
...
@@ -336,7 +342,7 @@ func gendecode(typespec *ast.TypeSpec) string {
d
.
emitobjtype
(
"p"
,
obj
,
typ
)
d
.
emitobjtype
(
"p"
,
obj
,
typ
)
d
.
emit
(
"return
%v /* + TODO variable part */, nil"
,
d
.
n
)
// FIXME n is wrong after reset
d
.
emit
(
"return
int(nread) + %v, nil"
,
d
.
n
)
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
return
d
.
buf
.
String
()
return
d
.
buf
.
String
()
...
...
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