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
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
Stefane Fermigier
neo
Commits
033d03cb
Commit
033d03cb
authored
Sep 03, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
4db15124
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
19 deletions
+58
-19
go/neo/proto.go
go/neo/proto.go
+27
-19
go/neo/protogen.go
go/neo/protogen.go
+31
-0
No files found.
go/neo/proto.go
View file @
033d03cb
...
...
@@ -206,25 +206,33 @@ type Address struct {
}
// NOTE if Host == "" -> Port not added to wire (see py.PAddress):
// func (a *Address) neoMsgEncode(b []byte) int {
// n := string_NEOEncode(a.Host, b[0:])
// if a.Host != "" {
// BigEndian.PutUint16(b[n:], a.Port)
// n += 2
// }
// return n
// }
//
// func (a *Address) NEODecode(b []byte) int {
// n := string_NEODecode(&a.Host, b)
// if a.Host != "" {
// a.Port = BigEndian.Uint16(b[n:])
// n += 2
// } else {
// a.Port = 0
// }
// return n
// }
func
(
a
*
Address
)
neoEncodedLen
()
int
{
l
:=
string_neoEncodedLen
(
a
.
Host
)
if
a
.
Host
!=
""
{
l
+=
2
}
return
l
}
func
(
a
*
Address
)
neoEncode
(
b
[]
byte
)
int
{
n
:=
string_neoEncode
(
a
.
Host
,
b
[
0
:
])
if
a
.
Host
!=
""
{
BigEndian
.
PutUint16
(
b
[
n
:
],
a
.
Port
)
n
+=
2
}
return
n
}
func
(
a
*
Address
)
neoDecode
(
b
[]
byte
)
int
{
n
:=
string_neoDecode
(
&
a
.
Host
,
b
)
if
a
.
Host
!=
""
{
a
.
Port
=
BigEndian
.
Uint16
(
b
[
n
:
])
n
+=
2
}
else
{
a
.
Port
=
0
}
return
n
}
// A SHA1 hash
type
Checksum
[
20
]
byte
...
...
go/neo/protogen.go
View file @
033d03cb
...
...
@@ -438,6 +438,10 @@ type CodeGenerator interface {
genArray1
(
path
string
,
typ
*
types
.
Array
)
genSlice1
(
path
string
,
typ
types
.
Type
)
// generate code for a custom type which implements its own encoding/decodeing
// XXX review text
genCustom
(
path
string
,
typ
types
.
Type
)
// XXX + obj?
// get generated code.
generatedCode
()
string
}
...
...
@@ -1063,11 +1067,38 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
d
.
emit
(
"}"
)
}
// emit code to size/encode/decode custom type
// XXX typ not needed
func
(
s
*
sizer
)
genCustom
(
path
string
,
typ
*
types
.
Type
)
{
s
.
size
.
AddExpr
(
"%s.neoEncodedLen()"
,
path
)
}
// XXX typ unused
func
(
e
*
encoder
)
genCustom
(
path
string
,
typ
*
types
.
Type
)
{
e
.
emit
(
"{"
)
e
.
emit
(
"n := %s.neoEncodedLen()"
,
path
)
e
.
emit
(
"%s.neoEncode(data[%v:])"
,
e
.
n
)
e
.
emit
(
"data = data[%v + n:]"
,
e
.
n
)
e
.
emit
(
"}"
)
e
.
n
=
0
}
func
(
e
*
decoder
)
genCustom
(
path
string
)
{
d
.
emit
(
"{"
)
d
.
emit
(
"n := %s.neoDecode(data[%v ..."
)
// XXX error!
d
.
emit
(
"}"
)
}
// top-level driver for emitting size/encode/decode code for a 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 happened)
func
codegenType
(
path
string
,
typ
types
.
Type
,
obj
types
.
Object
,
codegen
CodeGenerator
)
{
if
types
.
Implements
(
typ
,
neoCustomXXX
)
{
codegen
.
genCustom
(
path
,
typ
)
return
}
switch
u
:=
typ
.
Underlying
()
.
(
type
)
{
case
*
types
.
Basic
:
// go puts string into basic, but it is really slice1
...
...
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