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 {
h := buf.Header()
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
msg.NEOMsgEncode(buf.Payload())
......@@ -1427,7 +1427,7 @@ func (c *Conn) Expect(msgv ...proto.Msg) (which int, err error) {
}
for i, msg := range msgv {
if msg.NEOMsgCode() == msgCode {
if proto.MsgCode(msg) == msgCode {
_, err := msg.NEOMsgDecode(payload)
if err != nil {
return -1, c.err("decode", err)
......
......@@ -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) {
data := make([]byte, msg.NEOMsgEncodedLen())
msg.NEOMsgEncode(data)
t.xverifyPkt(pkt, connid, msg.NEOMsgCode(), data)
t.xverifyPkt(pkt, connid, proto.MsgCode(msg), data)
}
// delay a bit.
......
......@@ -32,6 +32,11 @@ import (
"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.
//
// 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
// it under the terms of the GNU General Public License version 3, or (at your
......@@ -113,9 +113,9 @@ type PktHeader struct {
type Msg interface {
// 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.
NEOMsgCode() uint16
neoMsgCode() uint16
// NEOMsgEncodedLen returns how much space is needed to encode current message payload.
NEOMsgEncodedLen() int
......
// Copyright (C) 2016-2020 Nexedi SA and Contributors.
// Copyright (C) 2016-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// 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) {
}()
// msg.encode() == expected
msgCode := msg.NEOMsgCode()
msgCode := msg.neoMsgCode()
n := msg.NEOMsgEncodedLen()
msgType := MsgType(msgCode)
if msgType != typ {
......
......@@ -25,7 +25,7 @@ NEO. Protocol module. Code generator
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:
NEOMsgCode() uint16
neoMsgCode() uint16
NEOMsgEncodedLen() int
NEOMsgEncode(buf []byte)
NEOMsgDecode(data []byte) (nread int, err error)
......@@ -355,7 +355,7 @@ import (
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("}\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