Commit 0983b672 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent aae27bf2
......@@ -1391,14 +1391,8 @@ func (c *Conn) err(op string, e error) error {
// XXX do we also need traceConnSend?
// XXX think again; XXX move to proto?
const (
encN = proto.Encoding('N')
encM = proto.Encoding('M')
)
// pktEncode allocates pktBuf and encodes msg into it.
//func (e Encoding) pktEncode(connId uint32, msg proto.Msg) *pktBuf {
// XXX move to proto ? -> YES: Encoding.PktEncode + .PktDecode
func pktEncode(e proto.Encoding, connId uint32, msg proto.Msg) *pktBuf {
switch e {
......@@ -1424,7 +1418,9 @@ func pktDecodeHead(e proto.Encoding, pkt *pktBuf) (connID uint32, msgCode uint16
func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf {
l := encN.NEOMsgEncodedLen(msg)
const enc = proto.Encoding('N')
l := enc.NEOMsgEncodedLen(msg)
buf := pktAlloc(proto.PktHeaderLenN + l)
h := buf.HeaderN()
......@@ -1432,7 +1428,7 @@ func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf {
h.MsgCode = packed.Hton16(proto.MsgCode(msg))
h.MsgLen = packed.Hton32(uint32(l)) // XXX casting: think again
encN.NEOMsgEncode(msg, buf.PayloadN())
enc.NEOMsgEncode(msg, buf.PayloadN())
return buf
}
......@@ -1452,12 +1448,14 @@ func pktDecodeHeadN(pkt *pktBuf) (connID uint32, msgCode uint16, payload []byte,
}
func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
const enc = proto.Encoding('M')
// [3](connID, msgCode, argv)
msgCode := proto.MsgCode(msg)
hroom := msgpack.ArrayHeadSize(3) +
msgpack.Uint32Size(connId) +
msgpack.Uint16Size(msgCode)
l := encM.NEOMsgEncodedLen(msg)
l := enc.NEOMsgEncodedLen(msg)
buf := pktAlloc(hroom + l)
......@@ -1469,7 +1467,7 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
if i != hroom {
panic("bug")
}
encM.NEOMsgEncode(msg, b[hroom:])
enc.NEOMsgEncode(msg, b[hroom:])
return buf
}
......
......@@ -232,7 +232,7 @@ func rxHello(errctx string, rx *fwd.Reader) (enc proto.Encoding, version uint32,
badMagic := false
switch {
case bytes.Equal(b[:3], []byte{0,0,0}):
peerEnc = encN
peerEnc = 'N'
peerVer = uint32(b[3])
case bytes.Equal(b, []byte{0x92, 0xc4, 3, 'N'}): // start of "fixarray<2> bin8 'N | EO' ...
......@@ -247,7 +247,7 @@ func rxHello(errctx string, rx *fwd.Reader) (enc proto.Encoding, version uint32,
break
}
peerEnc = encM
peerEnc = 'M'
rxM := msgp.Reader{R: rx}
peerVer, err = rxM.ReadUint32()
if err != nil {
......
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