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
4a177116
Commit
4a177116
authored
Jan 23, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
732db7ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
t/neo/protogen.go
t/neo/protogen.go
+19
-7
No files found.
t/neo/protogen.go
View file @
4a177116
...
...
@@ -230,6 +230,8 @@ type CodecCodeGen interface {
type
sizer
struct
{
Buffer
// XXX
n
int
symLenv
[]
string
// symbolic lengths TODO
sizeVarUsed
bool
// whether size var was used
}
type
encoder
struct
{
...
...
@@ -239,9 +241,10 @@ type encoder struct {
type
decoder
struct
{
Buffer
// buffer for generated code
n
int
// current decode position in data
n
int
// current decode position in data
}
var
_
CodecCodeGen
=
(
*
sizer
)(
nil
)
var
_
CodecCodeGen
=
(
*
encoder
)(
nil
)
var
_
CodecCodeGen
=
(
*
decoder
)(
nil
)
...
...
@@ -259,7 +262,9 @@ func (d *decoder) generatedCode() string {
func
(
s
*
sizer
)
genPrologue
(
recvName
,
typeName
string
)
{
s
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
recvName
,
typeName
)
s
.
emit
(
"var size int"
)
if
s
.
sizeVarUsed
{
s
.
emit
(
"var size int"
)
}
}
func
(
e
*
encoder
)
genPrologue
(
recvName
,
typeName
string
)
{
...
...
@@ -271,9 +276,16 @@ func (d *decoder) genPrologue(recvName, typeName string) {
d
.
emit
(
"var nread uint32"
)
}
func
(
e
*
sizer
)
genEpilogue
()
{
e
.
emit
(
"return size + %v"
,
e
.
n
)
e
.
emit
(
"}
\n
"
)
func
(
s
*
sizer
)
genEpilogue
()
{
size
:=
fmt
.
Sprintf
(
"%v"
,
s
.
n
)
if
len
(
s
.
symLenv
)
>
0
{
size
+=
" + "
+
strings
.
Join
(
s
.
synLenv
,
" + "
)
}
if
s
.
sizeVarUsed
{
size
+=
" + size"
)
}
s
.
emit
(
"return %v"
,
size
)
s
.
emit
(
"}
\n
"
)
}
func
(
e
*
encoder
)
genEpilogue
()
{
...
...
@@ -329,8 +341,8 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
// TODO []byte support
func
(
s
*
sizer
)
genStrBytes
(
path
string
)
{
s
.
n
+=
4
s
.
emit
(
"size += %v + len(%s)"
,
s
.
n
,
path
)
s
.
n
=
0
s
.
symLenv
=
append
(
s
.
symLenv
,
fmt
.
Sprintf
(
"len(%s)"
,
path
)
)
//
s.n = 0
}
func
(
e
*
encoder
)
genStrBytes
(
path
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