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 (
// ---- 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.
func pktDecode(pkb *pktBuf) (msg, error) {
var m msg
......
......@@ -183,12 +183,12 @@ func (zl *zLink) Call(ctx context.Context, method string, argv ...interface{}) (
zl.callMu.Unlock()
// (msgid, async, method, argv)
pkb := allocPkb()
p := pickle.NewEncoder(pkb)
err = p.Encode(pickle.Tuple{callID, false, method, pickle.Tuple(argv)})
if err != nil {
panic(err) // all our types are expected to be supported by pickle
}
pkb := pktEncode(msg{
msgid: callID,
flags: 0,
method: method,
arg: pickle.Tuple(argv),
})
// ok, pkt is ready to go
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