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

.

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