Commit 7077ecf5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 65ff3185
...@@ -185,7 +185,6 @@ func RecvAndDecode(conn *Conn) (NEOPkt, error) { ...@@ -185,7 +185,6 @@ func RecvAndDecode(conn *Conn) (NEOPkt, error) {
} }
// decode packet // decode packet
// XXX maybe better generate switch on msgCode instead of reflect
pkth := pkt.Header() pkth := pkt.Header()
msgCode := ntoh16(pkth.MsgCode) msgCode := ntoh16(pkth.MsgCode)
msgType := pktTypeRegistry[msgCode] msgType := pktTypeRegistry[msgCode]
...@@ -259,15 +258,10 @@ func Expect(conn *Conn, msg NEOPkt) (err error) { ...@@ -259,15 +258,10 @@ func Expect(conn *Conn, msg NEOPkt) (err error) {
// XXX dup wrt RecvAndDecode // XXX dup wrt RecvAndDecode
pkth := pkt.Header() pkth := pkt.Header()
msgCode := ntoh16(pkth.MsgCode) msgCode := ntoh16(pkth.MsgCode)
msgType := pktTypeRegistry[msgCode]
if msgType == nil {
return &ProtoError{conn, fmt.Errorf("invalid msgCode (%d)", msgCode)}
}
// FIXME -> better compare on just msgCode if msgCode != msg.NEOPktMsgCode() {
if msgType != reflect.TypeOf(msg).Elem() {
// unexpected Error response // unexpected Error response
if msgType == reflect.TypeOf(Error{}) { if msgCode == (&Error{}).NEOPktMsgCode() {
errResp := Error{} errResp := Error{}
_, err = errResp.NEOPktDecode(pkt.Payload()) _, err = errResp.NEOPktDecode(pkt.Payload())
if err != nil { if err != nil {
...@@ -281,6 +275,11 @@ func Expect(conn *Conn, msg NEOPkt) (err error) { ...@@ -281,6 +275,11 @@ func Expect(conn *Conn, msg NEOPkt) (err error) {
return errDecode(&errResp) // XXX err ctx vs ^^^ errcontextf ? return errDecode(&errResp) // XXX err ctx vs ^^^ errcontextf ?
} }
msgType := pktTypeRegistry[msgCode]
if msgType == nil {
return &ProtoError{conn, fmt.Errorf("invalid msgCode (%d)", msgCode)}
}
return &ProtoError{conn, fmt.Errorf("unexpected packet: %v", msgType)} return &ProtoError{conn, fmt.Errorf("unexpected packet: %v", msgType)}
} }
......
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