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
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
f0da8664
Commit
f0da8664
authored
Jul 03, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e507f6d7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
2 deletions
+47
-2
go/zodb/storage/zeo/zrpc.go
go/zodb/storage/zeo/zrpc.go
+47
-2
No files found.
go/zodb/storage/zeo/zrpc.go
View file @
f0da8664
...
@@ -74,6 +74,7 @@ type zLink struct {
...
@@ -74,6 +74,7 @@ type zLink struct {
ver
string
// protocol version in use (without "Z" or "M" prefix)
ver
string
// protocol version in use (without "Z" or "M" prefix)
encoding
byte
// protocol encoding in use ('Z' or 'M')
encoding
byte
// protocol encoding in use ('Z' or 'M')
// XXX ^^^ better -> codec inteface{ pktEncode, pktDecode } ?
}
}
// (called after handshake)
// (called after handshake)
...
@@ -172,12 +173,15 @@ func (zl *zLink) serveRecv1(pkb *pktBuf) error {
...
@@ -172,12 +173,15 @@ func (zl *zLink) serveRecv1(pkb *pktBuf) error {
return
nil
return
nil
}
}
// tuple corresponds to py tuple.
type
tuple
[]
interface
{}
// msg represents 1 message.
// msg represents 1 message.
type
msg
struct
{
type
msg
struct
{
msgid
int64
msgid
int64
flags
msgFlags
flags
msgFlags
method
string
method
string
arg
interface
{}
// can be e.g. (arg1, arg2, ...)
arg
interface
{}
// can be e.g.
tuple
(arg1, arg2, ...)
}
}
type
msgFlags
int64
type
msgFlags
int64
...
@@ -199,6 +203,15 @@ func (zl *zLink) pktDecode(pkb *pktBuf) (msg, error) {
...
@@ -199,6 +203,15 @@ func (zl *zLink) pktDecode(pkb *pktBuf) (msg, error) {
}
}
}
}
// pktEncode encodes message into raw packet.
func
(
zl
*
zLink
)
pktEncode
(
m
msg
)
*
pktBuf
{
switch
zl
.
encoding
{
case
'Z'
:
return
pktEncodeZ
(
m
)
case
'M'
:
return
pktEncodeM
(
m
)
default
:
panic
(
"bug"
)
}
}
// pktDecodeZ decodes raw Z (pickle) packet into message.
// pktDecodeZ decodes raw Z (pickle) packet into message.
func
pktDecodeZ
(
pkb
*
pktBuf
)
(
msg
,
error
)
{
func
pktDecodeZ
(
pkb
*
pktBuf
)
(
msg
,
error
)
{
var
m
msg
var
m
msg
...
@@ -237,11 +250,34 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) {
...
@@ -237,11 +250,34 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) {
return
m
,
nil
return
m
,
nil
}
}
// pktEncodeZ encodes message into raw Z (pickle) packet.
func
pktEncodeZ
(
m
msg
)
*
pktBuf
{
pkb
:=
allocPkb
()
p
:=
pickle
.
NewEncoder
(
pkb
)
// tuple -> pickle.Tuple
arg
:=
m
.
arg
tup
,
ok
:=
arg
.
(
tuple
)
if
ok
{
arg
=
pickle
.
Tuple
(
tup
)
}
err
:=
p
.
Encode
(
pickle
.
Tuple
{
m
.
msgid
,
m
.
flags
,
m
.
method
,
arg
})
if
err
!=
nil
{
panic
(
err
)
// all our types are expected to be supported by pickle
}
return
pkb
}
// pktDecodeM decodes raw M (msgpack) packet into message.
// pktDecodeM decodes raw M (msgpack) packet into message.
func
pktDecodeM
(
pkb
*
pktBuf
)
(
msg
,
error
)
{
func
pktDecodeM
(
pkb
*
pktBuf
)
(
msg
,
error
)
{
panic
(
"TODO"
)
panic
(
"TODO"
)
}
}
func
pktEncodeM
(
m
msg
)
*
pktBuf
{
panic
(
"TODO"
)
}
// Call makes 1 RPC call to server, waits for reply and returns it.
// Call makes 1 RPC call to server, waits for reply and returns it.
func
(
zl
*
zLink
)
Call
(
ctx
context
.
Context
,
method
string
,
argv
...
interface
{})
(
reply
msg
,
_
error
)
{
func
(
zl
*
zLink
)
Call
(
ctx
context
.
Context
,
method
string
,
argv
...
interface
{})
(
reply
msg
,
_
error
)
{
...
@@ -268,15 +304,24 @@ func (zl *zLink) _call(ctx context.Context, method string, argv ...interface{})
...
@@ -268,15 +304,24 @@ func (zl *zLink) _call(ctx context.Context, method string, argv ...interface{})
zl
.
callMu
.
Unlock
()
zl
.
callMu
.
Unlock
()
// (msgid, async, method, argv)
// (msgid, async, method, argv)
pkb
:=
zl
.
pktEncode
(
msg
{
msgid
:
callID
,
flags
:
0
,
// XXX was false
method
:
method
,
arg
:
tuple
(
argv
),
})
/*
pkb := allocPkb()
pkb := allocPkb()
p := pickle.NewEncoder(pkb)
p := pickle.NewEncoder(pkb)
err := p.Encode(pickle.Tuple{callID, false, method, pickle.Tuple(argv)})
err := p.Encode(pickle.Tuple{callID, false, method, pickle.Tuple(argv)})
if err != nil {
if err != nil {
panic(err) // all our types are expected to be supported by pickle
panic(err) // all our types are expected to be supported by pickle
}
}
*/
// ok, pkt is ready to go
// ok, pkt is ready to go
err
=
zl
.
sendPkt
(
pkb
)
// XXX ctx cancel
err
:
=
zl
.
sendPkt
(
pkb
)
// XXX ctx cancel
if
err
!=
nil
{
if
err
!=
nil
{
return
msg
{},
err
return
msg
{},
err
}
}
...
...
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