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
63dfa906
Commit
63dfa906
authored
Jan 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1e542169
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
136 deletions
+10
-136
t/neo/marshal.go
t/neo/marshal.go
+0
-129
t/neo/protogen.go
t/neo/protogen.go
+10
-7
No files found.
t/neo/marshal.go
View file @
63dfa906
This diff is collapsed.
Click to expand it.
t/neo/protogen.go
View file @
63dfa906
...
...
@@ -211,7 +211,7 @@ func (b *Buffer) emit(format string, a ...interface{}) {
// interface of codegenerator for coder/decoder
type
CodecCodeGen
interface
{
// tell codegen it should generate code for top-level function
setFunc
(
recvName
,
typeName
string
)
setFunc
(
recvName
,
typeName
string
,
typ
types
.
Type
)
// emit code to process basic fixed types (not string)
// userType is type actually used in source (for which typ is underlying), or nil
...
...
@@ -237,14 +237,16 @@ type CodecCodeGen interface {
type
commonCoder
struct
{
recvName
string
// receiver/type for top-level func
typeName
string
// or empty
typ
types
.
Type
varN
int
// suffix to add to variables (size0, size1, ...) - for nested computations
varUsed
map
[
string
]
bool
// whether a variable was used
}
func
(
c
*
commonCoder
)
setFunc
(
recvName
,
typeName
string
)
{
func
(
c
*
commonCoder
)
setFunc
(
recvName
,
typeName
string
,
typ
types
.
Type
)
{
c
.
recvName
=
recvName
c
.
typeName
=
typeName
c
.
typ
=
typ
}
// get variable name for varname
...
...
@@ -367,9 +369,11 @@ func (d *decoder) generatedCode() string {
}
code
.
emit
(
"return %v, nil"
,
retexpr
)
code
.
emit
(
"
\n
overflow:"
)
code
.
emit
(
"return 0, ErrDecodeOverflow"
)
code
.
emit
(
"goto overflow"
)
// TODO check if overflow used at all and remove
// overflow is not used only for empty structs
if
(
&
types
.
StdSizes
{
8
,
8
})
.
Sizeof
(
d
.
typ
)
>
0
{
code
.
emit
(
"
\n
overflow:"
)
code
.
emit
(
"return 0, ErrDecodeOverflow"
)
}
code
.
emit
(
"}
\n
"
)
return
code
.
String
()
...
...
@@ -638,12 +642,11 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod
// generate encoder/decode funcs for a type declaration typespec
func
generateCodecCode
(
typespec
*
ast
.
TypeSpec
,
codec
CodecCodeGen
)
string
{
codec
.
setFunc
(
"p"
,
typespec
.
Name
.
Name
)
// type & object which refers to this type
typ
:=
info
.
Types
[
typespec
.
Type
]
.
Type
obj
:=
info
.
Defs
[
typespec
.
Name
]
codec
.
setFunc
(
"p"
,
typespec
.
Name
.
Name
,
typ
)
codegenType
(
"p"
,
typ
,
obj
,
codec
)
return
codec
.
generatedCode
()
...
...
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