Commit 80492be0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent baf7f580
......@@ -132,6 +132,7 @@ func xconnError(err error) error {
// Prepare pktBuf with content.
func _mkpkt(enc proto.Encoding, connid uint32, msgcode uint16, payload []byte) *pktBuf {
// XXX -> enc.PktHeadEncode + enc.MsgEncode
switch enc {
case 'N':
pkt := &pktBuf{make([]byte, proto.PktHeaderLenN+len(payload))}
......@@ -185,8 +186,8 @@ func (t *T) xverifyPkt(pkt *pktBuf, connid uint32, msgcode uint16, payload []byt
// Verify pktBuf to match expected message.
func (t *T) xverifyPktMsg(pkt *pktBuf, connid uint32, msg proto.Msg) {
data := make([]byte, t.enc.NEOMsgEncodedLen(msg))
t.enc.NEOMsgEncode(msg, data)
data := make([]byte, t.enc.MsgEncodedLen(msg))
t.enc.MsgEncode(msg, data)
t.xverifyPkt(pkt, connid, proto.MsgCode(msg), data)
}
......
......@@ -92,7 +92,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
// msg.encode() == expected
msgCode := msg.neoMsgCode()
n := enc.NEOMsgEncodedLen(msg)
n := enc.MsgEncodedLen(msg)
msgType := MsgType(msgCode)
if msgType != typ {
t.Errorf("%c/%v: msgCode = %v which corresponds to %v", enc, typ, msgCode, msgType)
......@@ -102,7 +102,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
}
buf := make([]byte, n)
enc.NEOMsgEncode(msg, buf)
enc.MsgEncode(msg, buf)
if string(buf) != encoded {
t.Errorf("%c/%v: encode result unexpected:", enc, typ)
t.Errorf("\thave: %s", hexpkg.EncodeToString(buf))
......@@ -132,13 +132,13 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
}
}()
enc.NEOMsgEncode(msg, buf[:l])
enc.MsgEncode(msg, buf[:l])
}()
}
// msg.decode() == expected
data := []byte(encoded + "noise")
n, err := enc.NEOMsgDecode(msg2, data)
n, err := enc.MsgDecode(msg2, data)
if err != nil {
t.Errorf("%c/%v: decode error %v", enc, typ, err)
}
......@@ -152,7 +152,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
// decode must detect buffer overflow
for l := len(encoded) - 1; l >= 0; l-- {
n, err = enc.NEOMsgDecode(msg2, data[:l])
n, err = enc.MsgDecode(msg2, data[:l])
if !(n == 0 && err == ErrDecodeOverflow) {
t.Errorf("%c/%v: decode overflow not detected on [:%v]", enc, typ, l)
}
......@@ -375,14 +375,14 @@ func TestMsgMarshalAllOverflowLightly(t *testing.T) {
for _, enc := range []Encoding{'N', 'M'} {
// zero-value for a type
msg := reflect.New(typ).Interface().(Msg)
l := enc.NEOMsgEncodedLen(msg)
l := enc.MsgEncodedLen(msg)
zerol := make([]byte, l)
if enc != 'N' { // M-encoding of zero-value is not all zeros
enc.NEOMsgEncode(msg, zerol)
enc.MsgEncode(msg, zerol)
}
// decoding will turn nil slice & map into empty allocated ones.
// we need it so that reflect.DeepEqual works for msg encode/decode comparison
n, err := enc.NEOMsgDecode(msg, zerol)
n, err := enc.MsgDecode(msg, zerol)
if !(n == l && err == nil) {
t.Errorf("%c/%v: zero-decode unexpected: %v, %v ; want %v, nil", enc, typ, n, err, l)
}
......@@ -416,7 +416,7 @@ func TestMsgDecodeLenOverflow(t *testing.T) {
}
}()
n, err := enc.NEOMsgDecode(tt.msg, data)
n, err := enc.MsgDecode(tt.msg, data)
if !(n == 0 && err == ErrDecodeOverflow) {
t.Errorf("%T: decode %x\nhave: %d, %v\nwant: %d, %v", tt.msg, data,
n, err, 0, ErrDecodeOverflow)
......
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