Commit a551361b authored by Levin Zimmermann's avatar Levin Zimmermann

go/neo/proto/msgpack: Fix msgcode increment logic

In pre-msgpack protocol, the msgcode increment logic is like this:

Notify 	 add +1 to next msgcode
Request  add +0 to next msgcode   (next msg is answer & should therefore be the same)
Answer 	 add +1 to next msgcode

('Answer' msgcode is adjusted by 'AnswerBit')

In post-msgpack protocol, the logic is a bit different:

Notify 	 add +1 to next msgcode
Request  add +0 to next msgcode   (next msg is answer & should therefore be the same)
Answer 	 add +2 to next msgcode

So here we produce gaps after Request/Answer pairs.

NOTE: In the current version, this patch breaks the functionality of
the pre-msgpack protocol, because for both protocols the same
msgcodes are used. To still support 'N' we need to use different
msgcodes depending on if 'N' or 'M' is used.
parent e53b0089
......@@ -371,12 +371,18 @@ import (
// generate code for this type to implement neo.Msg
var msgCode MsgCode
msgCode.answer = specAnnotation.answer || strings.HasPrefix(typename, "Answer")
msgCode.msgSerial = msgSerial
// increment msgSerial only by +1 when going from
// request1->request2 in `Request1 Answer1 Request2`.
// Unlike as it was in pre-msgpack protocol, the global
// increment is still +1, only for the answer packet
// itself it's the same as the request packet. This means
// in the post-msgpack protocol there are gaps.
if msgCode.answer && typename != "Error" {
msgSerial--
msgCode.msgSerial = msgSerial - 1
}
msgCode.msgSerial = msgSerial
fmt.Fprintf(&buf, "// %s. %s\n\n", msgCode, typename)
......
This diff is collapsed.
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