Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapTo cannot parse values as uint8 #302

Open
rolandjitsu opened this issue Sep 11, 2021 · 3 comments
Open

MapTo cannot parse values as uint8 #302

rolandjitsu opened this issue Sep 11, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@rolandjitsu
Copy link

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 rolandjitsu changed the title set field "mykey": unsupported type "uint8" MapTo cannot parse values as uint8 Sep 11, 2021
@laojianzi
Copy link

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 😄

@rolandjitsu
Copy link
Author

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.

@laojianzi
Copy link

laojianzi commented Sep 16, 2021

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

@unknwon unknwon added the bug Something isn't working label Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants