parent
35642c832b
commit
e236cbf145
|
@ -159,15 +159,15 @@ func (e *Encoder) reflectValue(v reflect.Value) {
|
|||
}
|
||||
e.writeString("e")
|
||||
case reflect.Slice:
|
||||
if v.IsNil() {
|
||||
e.writeString("le")
|
||||
break
|
||||
}
|
||||
if v.Type().Elem().Kind() == reflect.Uint8 {
|
||||
s := v.Bytes()
|
||||
e.reflectByteSlice(s)
|
||||
break
|
||||
}
|
||||
if v.IsNil() {
|
||||
e.writeString("le")
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
case reflect.Array:
|
||||
e.writeString("l")
|
||||
|
|
|
@ -53,6 +53,7 @@ var random_encode_tests = []random_encode_test{
|
|||
{[4]byte{1, 2, 3, 4}, "li1ei2ei3ei4ee"},
|
||||
{nil, ""},
|
||||
{[]byte{}, "0:"},
|
||||
{[]byte(nil), "0:"},
|
||||
{"", "0:"},
|
||||
{[]int{}, "le"},
|
||||
{map[string]int{}, "de"},
|
||||
|
|
|
@ -15,3 +15,11 @@ func TestUnmarshalPex(t *testing.T) {
|
|||
require.EqualValues(t, 1286, pem.Added[0].Port)
|
||||
require.EqualValues(t, 0x100*0xb+0xc, pem.Added[1].Port)
|
||||
}
|
||||
|
||||
func TestEmptyPexMsg(t *testing.T) {
|
||||
pm := PexMsg{}
|
||||
b, err := bencode.Marshal(pm)
|
||||
t.Logf("%q", b)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, bencode.Unmarshal(b, &pm))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue