bencode fixes.
map->struct fixed. map->struct+map fixed.
This commit is contained in:
parent
cf16bc67de
commit
7f9f262959
2 changed files with 12 additions and 7 deletions
|
@ -241,8 +241,8 @@ func TestUnmarshal(t *testing.T) {
|
||||||
Q string "q"
|
Q string "q"
|
||||||
A map[string]string "a"
|
A map[string]string "a"
|
||||||
}
|
}
|
||||||
//innerDict := map[string]string{"id": "abcdefghij0123456789"}
|
innerDict := map[string]string{"id": "abcdefghij0123456789"}
|
||||||
//nestedDictionary := structNested{"aa", "q", "ping", innerDict}
|
nestedDictionary := structNested{"aa", "q", "ping", innerDict}
|
||||||
|
|
||||||
tests := []SVPair{
|
tests := []SVPair{
|
||||||
SVPair{"i100e", 100},
|
SVPair{"i100e", 100},
|
||||||
|
@ -256,8 +256,8 @@ func TestUnmarshal(t *testing.T) {
|
||||||
SVPair{"li42e3:abce", []any{42, "abc"}},
|
SVPair{"li42e3:abce", []any{42, "abc"}},
|
||||||
SVPair{"de", map[string]any{}},
|
SVPair{"de", map[string]any{}},
|
||||||
//SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
//SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
||||||
//SVPair{"d1:ai10e1:b3:fooe", structA{10, "foo"}},
|
SVPair{"d1:ai10e1:b3:fooe", structA{10, "foo"}},
|
||||||
//SVPair{"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe", nestedDictionary},
|
SVPair{"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe", nestedDictionary},
|
||||||
}
|
}
|
||||||
for _, sv := range tests {
|
for _, sv := range tests {
|
||||||
if err := checkUnmarshal(sv.s, sv.v); err != nil {
|
if err := checkUnmarshal(sv.s, sv.v); err != nil {
|
||||||
|
|
11
struct.go
11
struct.go
|
@ -109,11 +109,16 @@ func (b *structBuilder) String(s string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := b.val; v.Kind() {
|
switch b.val.Kind() {
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
v.SetString(s)
|
if !b.val.CanSet() {
|
||||||
|
x := ""
|
||||||
|
b.val = reflect.ValueOf(&x).Elem()
|
||||||
|
|
||||||
|
}
|
||||||
|
b.val.SetString(s)
|
||||||
case reflect.Interface:
|
case reflect.Interface:
|
||||||
v.Set(reflect.ValueOf(s))
|
b.val.Set(reflect.ValueOf(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue