Commit ea797d9e authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: Unexport Msg.NEOMsgCode

It is internal detail that ideally should not get outside of proto
package. Don't clutter documentation of all messages with it.

-> For now access message code via proto.MsgCode(msg) from outside.
parent e7a58934
...@@ -1326,7 +1326,7 @@ func pktEncode(connId uint32, msg proto.Msg) *pktBuf { ...@@ -1326,7 +1326,7 @@ func pktEncode(connId uint32, msg proto.Msg) *pktBuf {
h := buf.Header() h := buf.Header()
h.ConnId = packed.Hton32(connId) h.ConnId = packed.Hton32(connId)
h.MsgCode = packed.Hton16(msg.NEOMsgCode()) h.MsgCode = packed.Hton16(proto.MsgCode(msg))
h.MsgLen = packed.Hton32(uint32(l)) // XXX casting: think again h.MsgLen = packed.Hton32(uint32(l)) // XXX casting: think again
msg.NEOMsgEncode(buf.Payload()) msg.NEOMsgEncode(buf.Payload())
...@@ -1427,7 +1427,7 @@ func (c *Conn) Expect(msgv ...proto.Msg) (which int, err error) { ...@@ -1427,7 +1427,7 @@ func (c *Conn) Expect(msgv ...proto.Msg) (which int, err error) {
} }
for i, msg := range msgv { for i, msg := range msgv {
if msg.NEOMsgCode() == msgCode { if proto.MsgCode(msg) == msgCode {
_, err := msg.NEOMsgDecode(payload) _, err := msg.NEOMsgDecode(payload)
if err != nil { if err != nil {
return -1, c.err("decode", err) return -1, c.err("decode", err)
......
...@@ -159,7 +159,7 @@ func (t *T) xverifyPkt(pkt *pktBuf, connid uint32, msgcode uint16, payload []byt ...@@ -159,7 +159,7 @@ func (t *T) xverifyPkt(pkt *pktBuf, connid uint32, msgcode uint16, payload []byt
func (t *T) xverifyPktMsg(pkt *pktBuf, connid uint32, msg proto.Msg) { func (t *T) xverifyPktMsg(pkt *pktBuf, connid uint32, msg proto.Msg) {
data := make([]byte, msg.NEOMsgEncodedLen()) data := make([]byte, msg.NEOMsgEncodedLen())
msg.NEOMsgEncode(data) msg.NEOMsgEncode(data)
t.xverifyPkt(pkt, connid, msg.NEOMsgCode(), data) t.xverifyPkt(pkt, connid, proto.MsgCode(msg), data)
} }
// delay a bit. // delay a bit.
......
...@@ -32,6 +32,11 @@ import ( ...@@ -32,6 +32,11 @@ import (
"time" "time"
) )
// MsgCode returns code the corresponds to type of the message.
func MsgCode(msg Msg) uint16 {
return msg.neoMsgCode()
}
// MsgType looks up message type by message code. // MsgType looks up message type by message code.
// //
// Nil is returned if message code is not valid. // Nil is returned if message code is not valid.
......
// Copyright (C) 2006-2020 Nexedi SA and Contributors. // Copyright (C) 2006-2021 Nexedi SA and Contributors.
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your // it under the terms of the GNU General Public License version 3, or (at your
...@@ -113,9 +113,9 @@ type PktHeader struct { ...@@ -113,9 +113,9 @@ type PktHeader struct {
type Msg interface { type Msg interface {
// marshal/unmarshal into/from wire format: // marshal/unmarshal into/from wire format:
// NEOMsgCode returns message code needed to be used for particular message type // neoMsgCode returns message code needed to be used for particular message type
// on the wire. // on the wire.
NEOMsgCode() uint16 neoMsgCode() uint16
// NEOMsgEncodedLen returns how much space is needed to encode current message payload. // NEOMsgEncodedLen returns how much space is needed to encode current message payload.
NEOMsgEncodedLen() int NEOMsgEncodedLen() int
......
// Copyright (C) 2016-2020 Nexedi SA and Contributors. // Copyright (C) 2016-2021 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
...@@ -90,7 +90,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) { ...@@ -90,7 +90,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}() }()
// msg.encode() == expected // msg.encode() == expected
msgCode := msg.NEOMsgCode() msgCode := msg.neoMsgCode()
n := msg.NEOMsgEncodedLen() n := msg.NEOMsgEncodedLen()
msgType := MsgType(msgCode) msgType := MsgType(msgCode)
if msgType != typ { if msgType != typ {
......
...@@ -25,7 +25,7 @@ NEO. Protocol module. Code generator ...@@ -25,7 +25,7 @@ NEO. Protocol module. Code generator
This program generates marshalling code for message types defined in proto.go . This program generates marshalling code for message types defined in proto.go .
For every type 4 methods are generated in accordance with neo.Msg interface: For every type 4 methods are generated in accordance with neo.Msg interface:
NEOMsgCode() uint16 neoMsgCode() uint16
NEOMsgEncodedLen() int NEOMsgEncodedLen() int
NEOMsgEncode(buf []byte) NEOMsgEncode(buf []byte)
NEOMsgDecode(data []byte) (nread int, err error) NEOMsgDecode(data []byte) (nread int, err error)
...@@ -355,7 +355,7 @@ import ( ...@@ -355,7 +355,7 @@ import (
fmt.Fprintf(&buf, "// %s. %s\n\n", msgCode, typename) fmt.Fprintf(&buf, "// %s. %s\n\n", msgCode, typename)
buf.emit("func (*%s) NEOMsgCode() uint16 {", typename) buf.emit("func (*%s) neoMsgCode() uint16 {", typename)
buf.emit("return %s", msgCode) buf.emit("return %s", msgCode)
buf.emit("}\n") buf.emit("}\n")
......
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