Commit e4ff923f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f0da8664
// Copyright (C) 2018-2019 Nexedi SA and Contributors. // Copyright (C) 2018-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -205,6 +205,8 @@ func (r rpc) excError(exc string, argv []interface{}) error { ...@@ -205,6 +205,8 @@ func (r rpc) excError(exc string, argv []interface{}) error {
// zeo5Error decodes arg of reply with msgExcept flag set and returns // zeo5Error decodes arg of reply with msgExcept flag set and returns
// corresponding error. // corresponding error.
func (r rpc) zeo5Error(arg interface{}) error { func (r rpc) zeo5Error(arg interface{}) error {
// XXX check r.zl.encoding == 'Z' before using pickles?
// ('type', (arg1, arg2, arg3, ...)) // ('type', (arg1, arg2, arg3, ...))
texc, ok := arg.(pickle.Tuple) texc, ok := arg.(pickle.Tuple)
if !ok || len(texc) != 2 { if !ok || len(texc) != 2 {
...@@ -225,6 +227,8 @@ func (r rpc) zeo5Error(arg interface{}) error { ...@@ -225,6 +227,8 @@ func (r rpc) zeo5Error(arg interface{}) error {
// //
// nil is returned if arg does not represent an exception. // nil is returned if arg does not represent an exception.
func (r rpc) zeo4Error(arg interface{}) error { func (r rpc) zeo4Error(arg interface{}) error {
// XXX check r.zl.encoding == 'Z' before using pickles?
// (exc_class, exc_inst), e.g. // (exc_class, exc_inst), e.g.
// ogórek.Tuple{ // ogórek.Tuple{
// ogórek.Class{Module:"ZODB.POSException", Name:"POSKeyError"}, // ogórek.Class{Module:"ZODB.POSException", Name:"POSKeyError"},
......
...@@ -31,7 +31,8 @@ import ( ...@@ -31,7 +31,8 @@ import (
"net" "net"
"sync" "sync"
pickle "github.com/kisielk/og-rek" msgpack "github.com/shamaton/msgpack"
pickle "github.com/kisielk/og-rek"
"github.com/someonegg/gocontainer/rbuf" "github.com/someonegg/gocontainer/rbuf"
"lab.nexedi.com/kirr/go123/xbytes" "lab.nexedi.com/kirr/go123/xbytes"
...@@ -246,10 +247,21 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) { ...@@ -246,10 +247,21 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) {
return m, derrf(".%d: method: got %T; expected str", m.msgid, tpkt[2]) return m, derrf(".%d: method: got %T; expected str", m.msgid, tpkt[2])
} }
m.arg = tpkt[3] m.arg = tpkt[3] // XXX pickle.Tuple -> tuple
return m, nil return m, nil
} }
// pktDecodeM decodes raw M (msgpack) packet into message.
func pktDecodeM(pkb *pktBuf) (msg, error) {
var m msg
err := msgpack.DecodeStructAsArray(pkb.Payload(), &m)
if err != nil {
return m, err
}
return m, nil
}
// pktEncodeZ encodes message into raw Z (pickle) packet. // pktEncodeZ encodes message into raw Z (pickle) packet.
func pktEncodeZ(m msg) *pktBuf { func pktEncodeZ(m msg) *pktBuf {
pkb := allocPkb() pkb := allocPkb()
...@@ -269,13 +281,15 @@ func pktEncodeZ(m msg) *pktBuf { ...@@ -269,13 +281,15 @@ func pktEncodeZ(m msg) *pktBuf {
return pkb return pkb
} }
// pktDecodeM decodes raw M (msgpack) packet into message. // pktEncodeM encodes message into raw M (msgpack) packet.
func pktDecodeM(pkb *pktBuf) (msg, error) {
panic("TODO")
}
func pktEncodeM(m msg) *pktBuf { func pktEncodeM(m msg) *pktBuf {
panic("TODO") pkb := allocPkb()
data, err := msgpack.EncodeStructAsArray(m)
if err != nil {
panic(err) // all our types are expected to be supported by msgpack
}
pkb.Write(data) // XXX extra copy
return pkb
} }
......
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