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
da7d3914
Commit
da7d3914
authored
Jan 17, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
b54dbb73
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
t/neo/protogen.go
t/neo/protogen.go
+11
-9
No files found.
t/neo/protogen.go
View file @
da7d3914
...
...
@@ -211,7 +211,7 @@ func (d *decoder) decodeSlice(assignto string, obj types.Object, typ *types.Slic
d
.
emit
(
"for i := 0; uint32(i) < l; i++ {"
)
d
.
emit
(
"a := &%s[i]"
,
assignto
)
// XXX try to avoid (*) in a
d
.
decode
Object
(
"(*a)"
,
obj
,
typ
.
Elem
())
// XXX also obj.Elem() ?
d
.
decode
Type
(
"(*a)"
,
typ
.
Elem
(),
obj
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
// FIXME wrt slice of slice ?
d
.
emit
(
"nread += %v"
,
d
.
n
)
d
.
emit
(
"}"
)
...
...
@@ -233,18 +233,18 @@ func (d *decoder) decodeMap(assignto string, obj types.Object, typ *types.Map) {
//d.emit("if len(data) < l { return 0, ErrDecodeOverflow }")
d
.
emit
(
"m := %v"
,
assignto
)
d
.
emit
(
"for i := 0; uint32(i) < l; i++ {"
)
d
.
decode
Object
(
"key:"
,
obj
,
typ
.
Key
()
)
d
.
decode
Type
(
"key:"
,
typ
.
Key
(),
obj
)
switch
typ
.
Elem
()
.
Underlying
()
.
(
type
)
{
// basic types can be directly assigned to map entry
case
*
types
.
Basic
:
// XXX handle string
d
.
decode
Object
(
"m[key]"
,
obj
,
typ
.
Elem
()
)
d
.
decode
Type
(
"m[key]"
,
typ
.
Elem
(),
obj
)
// otherwise assign via temporary
default
:
d
.
emit
(
"var v %v"
,
typeName
(
typ
.
Elem
()))
d
.
decode
Object
(
"v"
,
obj
,
typ
.
Elem
()
)
d
.
decode
Type
(
"v"
,
typ
.
Elem
(),
obj
)
d
.
emit
(
"m[key] = v"
)
}
...
...
@@ -256,8 +256,10 @@ func (d *decoder) decodeMap(assignto string, obj types.Object, typ *types.Map) {
d
.
n
=
0
}
// top-level driver for emitting decode code for obj/type
func
(
d
*
decoder
)
decodeObject
(
assignto
string
,
obj
types
.
Object
,
typ
types
.
Type
)
{
// top-level driver for emitting decode code for type
// obj is object that uses this type in source program (so in case of an error
// we can point to source location for where it happenned)
func
(
d
*
decoder
)
decodeType
(
assignto
string
,
typ
types
.
Type
,
obj
types
.
Object
)
{
switch
u
:=
typ
.
Underlying
()
.
(
type
)
{
case
*
types
.
Basic
:
if
u
.
Kind
()
==
types
.
String
{
...
...
@@ -280,13 +282,13 @@ func (d *decoder) decodeObject(assignto string, obj types.Object, typ types.Type
// TODO optimize for [...]byte
var
i
int64
// XXX because `u.Len() int64`
for
i
=
0
;
i
<
u
.
Len
();
i
++
{
d
.
decode
Object
(
fmt
.
Sprintf
(
"%v[%v]"
,
assignto
,
i
),
obj
,
u
.
Elem
()
)
d
.
decode
Type
(
fmt
.
Sprintf
(
"%v[%v]"
,
assignto
,
i
),
u
.
Elem
(),
obj
)
}
case
*
types
.
Struct
:
for
i
:=
0
;
i
<
u
.
NumFields
();
i
++
{
v
:=
u
.
Field
(
i
)
d
.
decode
Object
(
assignto
+
"."
+
v
.
Name
(),
v
,
v
.
Type
()
)
d
.
decode
Type
(
assignto
+
"."
+
v
.
Name
(),
v
.
Type
(),
v
)
}
case
*
types
.
Slice
:
...
...
@@ -318,7 +320,7 @@ func gendecode(typespec *ast.TypeSpec) string {
typ
:=
info
.
Types
[
typespec
.
Type
]
.
Type
obj
:=
info
.
Defs
[
typespec
.
Name
]
d
.
decode
Object
(
"p"
,
obj
,
typ
)
d
.
decode
Type
(
"p"
,
typ
,
obj
)
d
.
emit
(
"return int(nread) + %v, nil"
,
d
.
n
)
d
.
emit
(
"}"
)
...
...
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