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
58f78727
Commit
58f78727
authored
Jan 25, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
af3ac0d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
23 deletions
+18
-23
t/neo/protogen.go
t/neo/protogen.go
+18
-23
No files found.
t/neo/protogen.go
View file @
58f78727
...
...
@@ -267,6 +267,7 @@ type CodeGenerator interface {
// common part of codegenerators
type
commonCodeGen
struct
{
buf
Buffer
// code is emitted here
recvName
string
// receiver/type for top-level func
typeName
string
// or empty
typ
types
.
Type
...
...
@@ -274,6 +275,10 @@ type commonCodeGen struct {
varUsed
map
[
string
]
bool
// whether a variable was used
}
func
(
c
*
commonCodeGen
)
emit
(
format
string
,
a
...
interface
{})
{
c
.
buf
.
emit
(
format
,
a
...
)
}
func
(
c
*
commonCodeGen
)
setFunc
(
recvName
,
typeName
string
,
typ
types
.
Type
)
{
c
.
recvName
=
recvName
c
.
typeName
=
typeName
...
...
@@ -341,26 +346,23 @@ func (s *SymSize) Reset() {
// XXX naming ok?
// XXX -> Gen_NEOEncodedLen ?
type
sizeCodeGen
struct
{
Buffer
// buffer for code
size
SymSize
// currently accumulated packet size
commonCodeGen
size
SymSize
// currently accumulated packet size
}
// encoder generates code to encode a packet
type
encoder
struct
{
Buffer
// XXX
n
int
// current write position in data
commonCodeGen
n
int
// current write position in data
}
// decoder generates code to decode a packet
type
decoder
struct
{
// buffers for generated code
// current delayed overflow check will be inserted in between buf & bufCur
buf
Buffer
bufCur
Buffer
commonCodeGen
// done buffer for generated code
// current delayed overflow check will be inserted in between buf & bufDone
bufDone
Buffer
// current read position in data.
n
int
...
...
@@ -370,8 +372,6 @@ type decoder struct {
// whether overflow was already checked for current decodings
overflowChecked
bool
commonCodeGen
}
var
_
CodeGenerator
=
(
*
sizeCodeGen
)(
nil
)
...
...
@@ -387,7 +387,7 @@ func (s *sizeCodeGen) generatedCode() string {
code
.
emit
(
"var %s int"
,
s
.
var_
(
"size"
))
}
code
.
Write
(
s
.
Bytes
())
// XXX -> s.buf.Bytes() ?
code
.
Write
(
s
.
buf
.
Bytes
())
// epilogue
size
:=
s
.
size
.
String
()
...
...
@@ -405,7 +405,7 @@ func (e *encoder) generatedCode() string {
// prologue
code
.
emit
(
"func (%s *%s) NEOEncode(data []byte) {"
,
e
.
recvName
,
e
.
typeName
)
code
.
Write
(
e
.
Bytes
())
// XXX -> e.buf.Bytes() ?
code
.
Write
(
e
.
buf
.
Bytes
())
// epilogue
code
.
emit
(
"}
\n
"
)
...
...
@@ -413,11 +413,6 @@ func (e *encoder) generatedCode() string {
return
code
.
String
()
}
// XXX place?
func
(
d
*
decoder
)
emit
(
format
string
,
a
...
interface
{})
{
d
.
bufCur
.
emit
(
format
,
a
...
)
}
// XXX place?
// data <- data[pos:]
// pos <- 0
...
...
@@ -448,13 +443,13 @@ func (d *decoder) resetPos() {
func
(
d
*
decoder
)
overflowCheckpoint
()
{
//d.buf.emit("// overflow check point")
if
!
d
.
overflowCheckSize
.
IsZero
()
{
d
.
buf
.
emit
(
"if uint32(len(data)) < %v { goto overflow }"
,
&
d
.
overflowCheckSize
)
d
.
buf
Done
.
emit
(
"if uint32(len(data)) < %v { goto overflow }"
,
&
d
.
overflowCheckSize
)
}
d
.
overflowCheckSize
.
Reset
()
d
.
buf
.
Write
(
d
.
bufCur
.
Bytes
())
d
.
buf
Cur
.
Reset
()
d
.
buf
Done
.
Write
(
d
.
buf
.
Bytes
())
d
.
buf
.
Reset
()
}
func
(
d
*
decoder
)
generatedCode
()
string
{
...
...
@@ -467,7 +462,7 @@ func (d *decoder) generatedCode() string {
code
.
emit
(
"var %v uint32"
,
d
.
var_
(
"nread"
))
}
code
.
Write
(
d
.
buf
.
Bytes
())
code
.
Write
(
d
.
buf
Done
.
Bytes
())
// epilogue
retexpr
:=
fmt
.
Sprintf
(
"%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