go-ini/ini

MapTo cannot parse values as uint8

rolandjitsu opened this issue · 3 comments

Describe the bug
Parsing the following:

[mysection]
mykey=90

When using MapTo results in:

set field "mykey": unsupported type "uint8"

If the type is uint8:

type MySection struct {
	MeyKey uint8 `json:"mykey" ini:"mykey"`
}

To Reproduce
Just load the config and use MapTo:

cfg, _ := ini.Load([]byte(`
[mysection]
mykey=90
`))
mySec := &MySection{}
err := cfg.Section("mysection").MapTo(mySec)

Expected behavior
MapTo should be able to parse values as uint8.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here, or any suggestion to fix the problem.

ini/struct.go

Lines 211 to 212 in 5e97220

// byte is an alias for uint8, so supporting uint8 breaks support for byte
case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64:

Here's where the problem might lie
If you can, I suggest you switch to uint16 or a larger uint 😄

ini/struct.go

Lines 211 to 212 in 5e97220

// byte is an alias for uint8, so supporting uint8 breaks support for byte
case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64:

Here's where the problem might lie
If you can, I suggest you switch to uint16 or a larger uint 😄

That's what I did. Does the lib parse byte arrays? I wonder why that comment is there.

That's what I did. Does the lib parse byte arrays? I wonder why that comment is there.

My guess 😥

All values loaded in the ini are considered to be strings, if by default 1 string character is a byte, if a non-ASCII character is encountered it will not be parsed to a byte or will be lost

// String of length 1

"a" = [97] index 0 = 97 // Englische
"α" = [206, 177] index 0 = 206 or 0? // Greek
"啊" = [229, 149, 138] index 0 = 229 or 0? // Chinese