Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestEncoder_RegisterEncodeFunc(t *testing.T) {
}
}

//BenchmarkMarshal-4 295726 11902 ns/op
// BenchmarkMarshal-4 295726 11902 ns/op
func BenchmarkMarshal(b *testing.B) {
data := getMockData2()

Expand Down
12 changes: 11 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package urlquery

import (
"bytes"
"fmt"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -246,7 +247,16 @@ func (p *parser) parseValue(rv reflect.Value, parentNode string) {
return
}

rv.Set(v)
srcType := v.Type()
targetType := rv.Type()

if srcType.AssignableTo(targetType) {
rv.Set(v)
} else if v.CanConvert(targetType) {
rv.Set(v.Convert(targetType))
} else {
panic(fmt.Sprintf("parseValue: value of type %s is not assignable to type %s", srcType, targetType))
}
}

// parse text to specified-type value
Expand Down
4 changes: 2 additions & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ func TestParser_parseForSlice_CanSet(t *testing.T) {
parser.parseForSlice(v, "")
}

//mock multi-layer nested structure,
//BenchmarkUnmarshal-4 208219 14873 ns/op
// mock multi-layer nested structure,
// BenchmarkUnmarshal-4 208219 14873 ns/op
func BenchmarkUnmarshal(b *testing.B) {
var data = "Id=1&name=test&child[desc]=c1&child[Long]=10&childPtr[Long]=2&childPtr[Description]=b" +
"&children[0][desc]=d1&children[1][Long]=12&children[5][desc]=d5&children[5][Long]=50&desc=rtt" +
Expand Down