ini icon indicating copy to clipboard operation
ini copied to clipboard

MapTo cannot parse values as uint8

Open rolandjitsu opened this issue 4 years ago • 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.

rolandjitsu avatar Sep 11 '21 06:09 rolandjitsu

https://github.com/go-ini/ini/blob/5e97220809ffaa826f787728501264e9114cb834/struct.go#L211-L212

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

laojianzi avatar Sep 16 '21 07:09 laojianzi

https://github.com/go-ini/ini/blob/5e97220809ffaa826f787728501264e9114cb834/struct.go#L211-L212

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.

rolandjitsu avatar Sep 16 '21 08:09 rolandjitsu

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

My guess :disappointed_relieved:

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

laojianzi avatar Sep 16 '21 09:09 laojianzi