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
51d087af
Commit
51d087af
authored
Sep 11, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
035449f9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
11 deletions
+57
-11
go/neo/proto.go
go/neo/proto.go
+3
-3
go/neo/protogen.go
go/neo/protogen.go
+49
-3
go/neo/zproto-marshal.go
go/neo/zproto-marshal.go
+5
-5
No files found.
go/neo/proto.go
View file @
51d087af
...
@@ -595,7 +595,7 @@ type StoreObject struct {
...
@@ -595,7 +595,7 @@ type StoreObject struct {
Serial
zodb
.
Tid
Serial
zodb
.
Tid
Compression
bool
Compression
bool
Checksum
Checksum
Checksum
Checksum
Data
[]
byte
// TODO separately (for writev)
Data
[]
byte
// TODO
encode ->
separately (for writev)
DataSerial
zodb
.
Tid
DataSerial
zodb
.
Tid
Tid
zodb
.
Tid
Tid
zodb
.
Tid
}
}
...
@@ -646,8 +646,8 @@ type AnswerObject struct {
...
@@ -646,8 +646,8 @@ type AnswerObject struct {
NextSerial
zodb
.
Tid
// XXX but there it is out of sync
NextSerial
zodb
.
Tid
// XXX but there it is out of sync
Compression
bool
Compression
bool
Checksum
Checksum
Checksum
Checksum
// Data []byte // TODO separately (for writev)
// Data []byte // TODO
encode ->
separately (for writev)
Data
*
zodb
.
Buf
Data
*
zodb
.
Buf
// TODO encode -> separately (for writev)
DataSerial
zodb
.
Tid
DataSerial
zodb
.
Tid
}
}
...
...
go/neo/protogen.go
View file @
51d087af
...
@@ -116,8 +116,8 @@ func typeName(typ types.Type) string {
...
@@ -116,8 +116,8 @@ func typeName(typ types.Type) string {
return
types
.
TypeString
(
typ
,
qf
)
return
types
.
TypeString
(
typ
,
qf
)
}
}
// type of neo.customCodec
var
neo_customCodec
*
types
.
Interface
// type of neo.customCodec
var
neo_customCodec
*
types
.
Interface
var
zodbBuf
types
.
Type
// type of zodb.Buf
// bytes.Buffer + bell & whistles
// bytes.Buffer + bell & whistles
type
Buffer
struct
{
type
Buffer
struct
{
...
@@ -243,7 +243,7 @@ func main() {
...
@@ -243,7 +243,7 @@ func main() {
log
.
SetFlags
(
0
)
log
.
SetFlags
(
0
)
// go through proto.go and AST'ify & typecheck it
// go through proto.go and AST'ify & typecheck it
zodbPkg
=
loadPkg
(
"lab.nexedi.com/kirr/neo/go/zodb"
,
"../zodb/zodb.go"
)
zodbPkg
=
loadPkg
(
"lab.nexedi.com/kirr/neo/go/zodb"
,
"../zodb/zodb.go"
,
"../zodb/buffer.go"
)
neoPkg
=
loadPkg
(
"lab.nexedi.com/kirr/neo/go/neo"
,
"proto.go"
,
"packed.go"
)
neoPkg
=
loadPkg
(
"lab.nexedi.com/kirr/neo/go/neo"
,
"proto.go"
,
"packed.go"
)
// extract neo.customCodec
// extract neo.customCodec
...
@@ -257,6 +257,13 @@ func main() {
...
@@ -257,6 +257,13 @@ func main() {
log
.
Fatal
(
"customCodec is not interface (got %v)"
,
cc
.
Type
())
log
.
Fatal
(
"customCodec is not interface (got %v)"
,
cc
.
Type
())
}
}
// extract zodb.Buf
__
:=
zodbPkg
.
Scope
()
.
Lookup
(
"Buf"
)
if
__
==
nil
{
log
.
Fatal
(
"cannot find `zodb.Buf`"
)
}
zodbBuf
=
__
.
Type
()
// prologue
// prologue
f
:=
fileMap
[
"proto.go"
]
f
:=
fileMap
[
"proto.go"
]
buf
:=
Buffer
{}
buf
:=
Buffer
{}
...
@@ -455,6 +462,9 @@ type CodeGenerator interface {
...
@@ -455,6 +462,9 @@ type CodeGenerator interface {
genArray1
(
path
string
,
typ
*
types
.
Array
)
genArray1
(
path
string
,
typ
*
types
.
Array
)
genSlice1
(
path
string
,
typ
types
.
Type
)
genSlice1
(
path
string
,
typ
types
.
Type
)
// zodb.Buf
genBuf
(
path
string
)
// generate code for a custom type which implements its own
// generate code for a custom type which implements its own
// encoding/decoding via implementing neo.customCodec interface.
// encoding/decoding via implementing neo.customCodec interface.
genCustom
(
path
string
)
genCustom
(
path
string
)
...
@@ -913,6 +923,33 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
...
@@ -913,6 +923,33 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
}
}
// emit code to size/encode/decode zodb.Buf
// same as slice1 but buffer is allocated via zodb.BufAlloc
func
(
s
*
sizer
)
genBuf
(
path
string
)
{
s
.
genSlice1
(
path
+
".Data"
,
nil
)
// XXX typ unused
}
func
(
e
*
encoder
)
genBuf
(
path
string
)
{
e
.
genSlice1
(
path
+
".Data"
,
nil
)
// XXX typ unused
}
func
(
d
*
decoder
)
genBuf
(
path
string
)
{
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
d
.
resetPos
()
d
.
overflowCheck
()
d
.
overflow
.
AddExpr
(
"l"
)
// TODO eventually do not copy but reference original
d
.
emit
(
"%v= zodb.BufAlloc(l)"
,
path
)
d
.
emit
(
"copy(%v.Data, data[:l])"
,
path
)
d
.
emit
(
"data = data[l:]"
)
d
.
emit
(
"}"
)
}
// emit code to size/encode/decode slice
// emit code to size/encode/decode slice
// len u32
// len u32
// [len]item
// [len]item
...
@@ -1120,12 +1157,19 @@ func (d *decoder) genCustom(path string) {
...
@@ -1120,12 +1157,19 @@ func (d *decoder) genCustom(path string) {
// obj is object that uses this type in source program (so in case of an error
// 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)
// we can point to source location for where it happened)
func
codegenType
(
path
string
,
typ
types
.
Type
,
obj
types
.
Object
,
codegen
CodeGenerator
)
{
func
codegenType
(
path
string
,
typ
types
.
Type
,
obj
types
.
Object
,
codegen
CodeGenerator
)
{
// neo.customCodec
if
types
.
Implements
(
typ
,
neo_customCodec
)
||
if
types
.
Implements
(
typ
,
neo_customCodec
)
||
types
.
Implements
(
types
.
NewPointer
(
typ
),
neo_customCodec
)
{
types
.
Implements
(
types
.
NewPointer
(
typ
),
neo_customCodec
)
{
codegen
.
genCustom
(
path
)
codegen
.
genCustom
(
path
)
return
return
}
}
// zodb.Buf
if
tptr
,
ok
:=
typ
.
Underlying
()
.
(
*
types
.
Pointer
);
ok
&&
tptr
.
Elem
()
==
zodbBuf
{
codegen
.
genBuf
(
path
)
return
}
switch
u
:=
typ
.
Underlying
()
.
(
type
)
{
switch
u
:=
typ
.
Underlying
()
.
(
type
)
{
case
*
types
.
Basic
:
case
*
types
.
Basic
:
// go puts string into basic, but it is really slice1
// go puts string into basic, but it is really slice1
...
@@ -1167,6 +1211,8 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGene
...
@@ -1167,6 +1211,8 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGene
case
*
types
.
Map
:
case
*
types
.
Map
:
codegen
.
genMap
(
path
,
u
,
obj
)
codegen
.
genMap
(
path
,
u
,
obj
)
case
*
types
.
Pointer
:
default
:
default
:
log
.
Fatalf
(
"%v: %v has unsupported type %v (%v)"
,
pos
(
obj
),
log
.
Fatalf
(
"%v: %v has unsupported type %v (%v)"
,
pos
(
obj
),
obj
.
Name
(),
typ
,
u
)
obj
.
Name
(),
typ
,
u
)
...
...
go/neo/zproto-marshal.go
View file @
51d087af
...
@@ -1930,7 +1930,7 @@ func (*AnswerObject) neoMsgCode() uint16 {
...
@@ -1930,7 +1930,7 @@ func (*AnswerObject) neoMsgCode() uint16 {
}
}
func
(
p
*
AnswerObject
)
neoMsgEncodedLen
()
int
{
func
(
p
*
AnswerObject
)
neoMsgEncodedLen
()
int
{
return
57
+
len
(
p
.
Data
)
return
57
+
len
(
p
.
Data
.
Data
)
}
}
func
(
p
*
AnswerObject
)
neoMsgEncode
(
data
[]
byte
)
{
func
(
p
*
AnswerObject
)
neoMsgEncode
(
data
[]
byte
)
{
...
@@ -1940,10 +1940,10 @@ func (p *AnswerObject) neoMsgEncode(data []byte) {
...
@@ -1940,10 +1940,10 @@ func (p *AnswerObject) neoMsgEncode(data []byte) {
(
data
[
24
:
])[
0
]
=
bool2byte
(
p
.
Compression
)
(
data
[
24
:
])[
0
]
=
bool2byte
(
p
.
Compression
)
copy
(
data
[
25
:
],
p
.
Checksum
[
:
])
copy
(
data
[
25
:
],
p
.
Checksum
[
:
])
{
{
l
:=
uint32
(
len
(
p
.
Data
))
l
:=
uint32
(
len
(
p
.
Data
.
Data
))
binary
.
BigEndian
.
PutUint32
(
data
[
45
:
],
l
)
binary
.
BigEndian
.
PutUint32
(
data
[
45
:
],
l
)
data
=
data
[
49
:
]
data
=
data
[
49
:
]
copy
(
data
,
p
.
Data
)
copy
(
data
,
p
.
Data
.
Data
)
data
=
data
[
l
:
]
data
=
data
[
l
:
]
}
}
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
DataSerial
))
binary
.
BigEndian
.
PutUint64
(
data
[
0
:
],
uint64
(
p
.
DataSerial
))
...
@@ -1966,8 +1966,8 @@ func (p *AnswerObject) neoMsgDecode(data []byte) (int, error) {
...
@@ -1966,8 +1966,8 @@ func (p *AnswerObject) neoMsgDecode(data []byte) (int, error) {
goto
overflow
goto
overflow
}
}
nread
+=
8
+
l
nread
+=
8
+
l
p
.
Data
=
make
([]
byte
,
l
)
p
.
Data
=
zodb
.
BufAlloc
(
l
)
copy
(
p
.
Data
,
data
[
:
l
])
copy
(
p
.
Data
.
Data
,
data
[
:
l
])
data
=
data
[
l
:
]
data
=
data
[
l
:
]
}
}
p
.
DataSerial
=
zodb
.
Tid
(
binary
.
BigEndian
.
Uint64
(
data
[
0
:
]))
p
.
DataSerial
=
zodb
.
Tid
(
binary
.
BigEndian
.
Uint64
(
data
[
0
:
]))
...
...
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