Commit ca7e96e0 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/zeo: Factor-out code to prepare pkt from message into pktEncode

parent 362e555a
...@@ -50,6 +50,17 @@ const ( ...@@ -50,6 +50,17 @@ const (
// ---- message encode/decode ↔ packet ---- // ---- message encode/decode ↔ packet ----
// pktEncode encodes message into raw packet.
func pktEncode(m msg) *pktBuf {
pkb := allocPkb()
p := pickle.NewEncoder(pkb)
err := p.Encode(pickle.Tuple{m.msgid, m.flags, m.method, m.arg})
if err != nil {
panic(err) // all our types are expected to be supported by pickle
}
return pkb
}
// pktDecode decodes raw packet into message. // pktDecode decodes raw packet into message.
func pktDecode(pkb *pktBuf) (msg, error) { func pktDecode(pkb *pktBuf) (msg, error) {
var m msg var m msg
......
...@@ -183,12 +183,12 @@ func (zl *zLink) Call(ctx context.Context, method string, argv ...interface{}) ( ...@@ -183,12 +183,12 @@ 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 := allocPkb() pkb := pktEncode(msg{
p := pickle.NewEncoder(pkb) msgid: callID,
err = p.Encode(pickle.Tuple{callID, false, method, pickle.Tuple(argv)}) flags: 0,
if err != nil { method: method,
panic(err) // all our types are expected to be supported by pickle arg: pickle.Tuple(argv),
} })
// 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment