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
c49c72d0
Commit
c49c72d0
authored
8 years ago
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d0a883df
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
46 deletions
+65
-46
t/neo/proto.go
t/neo/proto.go
+31
-33
t/neo/protogen.go
t/neo/protogen.go
+34
-13
No files found.
t/neo/proto.go
View file @
c49c72d0
...
...
@@ -4,8 +4,8 @@ package neo
// XXX move imports out of here
import
(
"encoding/binary"
"math"
//
"encoding/binary"
//
"math"
)
const
(
...
...
@@ -105,28 +105,27 @@ type Address struct {
}
// NOTE if Host == "" -> Port not added to wire (see py.PAddress):
/*
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
}
*/
// 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
...
...
@@ -180,15 +179,13 @@ type RowInfo struct {
/*
// XXX link request <-> answer ?
// XXX naming -> PktHeader ?
type PktHead struct {
ConnId be32 // NOTE is .msgid in py
MsgCode be16
Len be32 // whole packet length (including header)
}
*/
// // XXX link request <-> answer ?
// // XXX naming -> PktHeader ?
// type PktHead struct {
// ConnId be32 // NOTE is .msgid in py
// MsgCode be16
// Len be32 // whole packet length (including header)
// }
// TODO generate .Encode() / .Decode()
...
...
@@ -704,7 +701,7 @@ type AnswerPack struct {
// ctl -> A
// A -> M
type CheckReplicas struct {
PartitionDict
map
[
uint32
/*PNumber*/
]
UUID
// partition -> source
PartitionDict map[uint32
]UUID // partition -> source (PNumber)
MinTID Tid
MaxTID Tid
...
...
@@ -795,3 +792,4 @@ type NotifyReady struct {
// replication
// TODO
*/
This diff is collapsed.
Click to expand it.
t/neo/protogen.go
View file @
c49c72d0
...
...
@@ -21,11 +21,13 @@ import (
"bytes"
"fmt"
"go/ast"
"go/format"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
"os"
)
// information about one packet type
...
...
@@ -75,6 +77,7 @@ func main() {
//return
f
:=
fv
[
0
]
// proto.go comes first
out
:=
Buffer
{}
for
_
,
decl
:=
range
f
.
Decls
{
// we look for types (which can be only under GenDecl)
...
...
@@ -98,7 +101,7 @@ func main() {
//fmt.Println(t)
//ast.Print(fset, t)
gendecode
(
typespec
)
out
.
WriteString
(
gendecode
(
typespec
)
)
/*
PacketType{name: typename, msgCode: ncode}
...
...
@@ -133,6 +136,18 @@ func main() {
//fmt.Println(gdecl)
//ast.Print(fset, gdecl)
}
// format & emit out
outf
,
err
:=
format
.
Source
(
out
.
Bytes
())
if
err
!=
nil
{
panic
(
err
)
// should not happen
}
_
,
err
=
os
.
Stdout
.
Write
(
outf
)
//_, err = os.Stdout.Write(out.Bytes())
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
/*
...
...
@@ -174,18 +189,18 @@ type Buffer struct {
bytes
.
Buffer
}
func
(
b
*
Buffer
)
Printf
(
format
string
,
a
...
interface
{})
(
n
int
,
err
error
)
{
return
fmt
.
Fprintf
(
b
,
format
,
a
...
)
func
(
b
*
Buffer
)
Printf
ln
(
format
string
,
a
...
interface
{})
(
n
int
,
err
error
)
{
return
fmt
.
Fprintf
(
b
,
format
+
"
\n
"
,
a
...
)
}
func
gendecode
(
typespec
*
ast
.
TypeSpec
)
string
{
buf
:=
Buffer
{}
emit
f
:=
buf
.
Printf
emit
:=
buf
.
Printfln
typename
:=
typespec
.
Name
.
Name
t
:=
typespec
.
Type
.
(
*
ast
.
StructType
)
// must be
emit
f
(
"func (p *%s) NEODecode(data []byte) int {
\n
"
,
typename
)
emit
(
"func (p *%s) NEODecode(data []byte) (int, error) {
"
,
typename
)
n
:=
0
// current decode pos in data
...
...
@@ -215,7 +230,13 @@ func gendecode(typespec *ast.TypeSpec) string {
}
emitstrbytes
:=
func
(
fieldname
string
)
{
emitf
(
"{ l := %v"
,
decodeBasic
(
types
.
Typ
[
types
.
Uint32
]))
emit
(
"{ l := %v"
,
decodeBasic
(
types
.
Typ
[
types
.
Uint32
]))
emit
(
"data = data[%v:]"
,
n
)
emit
(
"if len(data) < l { return 0, ErrDecodeOverflow }"
)
emit
(
"p.%v = string(data[:l])"
,
fieldname
)
emit
(
"data = data[l:]"
)
emit
(
"}"
)
n
=
0
}
...
...
@@ -231,7 +252,7 @@ func gendecode(typespec *ast.TypeSpec) string {
continue
}
emit
f
(
"p.%s = %s"
,
fieldname
,
decodeBasic
(
u
))
emit
(
"p.%s = %s"
,
fieldname
,
decodeBasic
(
u
))
case
*
types
.
Slice
:
// TODO
...
...
@@ -260,10 +281,10 @@ func gendecode(typespec *ast.TypeSpec) string {
// len u32
// [len] items
emit
f
("length = Uint32(data[%s:])", n)
emit("length = Uint32(data[%s:])", n)
n += 4
emit
f
("for ; length != 0; length-- {")
emit
f
("}")
emit("for ; length != 0; length-- {")
emit("}")
...
...
@@ -271,7 +292,7 @@ func gendecode(typespec *ast.TypeSpec) string {
case *ast.MapType:
// len u32
// [len] key, value
emit
f
("length = Uint32(data[%s:])", n)
emit("length = Uint32(data[%s:])", n)
n += 4
keysize := wiresize(fieldtype.Key)
...
...
@@ -286,7 +307,7 @@ func gendecode(typespec *ast.TypeSpec) string {
}
}
fmt
.
Fprintf
(
&
buf
,
"}
\n
"
)
// TODO format.Source(buf.Bytes()) (XXX -> better at top-level for whole file
)
emit
(
"return %v /* + TODO variable part */, nil"
,
n
)
emit
(
"}"
)
return
buf
.
String
()
}
This diff is collapsed.
Click to expand it.
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