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

Support for Unsigned Integer values #173

Open
akuleshov7 opened this issue Dec 28, 2022 · 3 comments
Open

Support for Unsigned Integer values #173

akuleshov7 opened this issue Dec 28, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@akuleshov7
Copy link
Owner

Would you mind elaborating on why unsigneds can't be supported?

I'd recommend making a new GitHub issue 'support unsigned ints' (I could make the issue if you like) and adding the link in the source code, then it's easier to track and follow progress.

Originally posted by @aSemy in #171 (comment)

@akuleshov7
Copy link
Owner Author

    @Serializable
    data class UnsingedIntegers(
        val s: UInt,
        val b: UByte,
        val i: UInt,
        val l: ULong,
    )

      var testUnsigned = """
              s = 5
              b = 5
              i = 5
              l = 5
      """.trimIndent()
      println(Toml.decodeFromString<UnsingedIntegers>(testUnsigned))

Will cause error:

Index -1 out of bounds for length 4
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 4
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:359)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at com.akuleshov7.ktoml.decoders.TomlMainDecoder.getCurrentNode(TomlMainDecoder.kt:81)

@akuleshov7 akuleshov7 added the enhancement New feature or request label Jan 2, 2023
@akuleshov7 akuleshov7 added this to the 0.2.12 milestone Jan 2, 2023
@akuleshov7 akuleshov7 pinned this issue Jan 2, 2023
@aSemy
Copy link
Collaborator

aSemy commented Jan 2, 2023

I think that UInt.MAX_VALUE is -1, so the current way of validating won't work for unsigned nums.

I'd prefer refracting the logic to match how KsX JSON does it #171 (comment)

@akuleshov7
Copy link
Owner Author

akuleshov7 commented Jan 2, 2023

I think that UInt.MAX_VALUE is -1, so the current way of validating won't work for unsigned nums.

I'd prefer refracting the logic to match how KsX JSON does it #171 (comment)

Actually the logic should be the same: parsing to the biggest available type (ULong) and checking bounds: UInt.MAX_VALUE.toULong() = 4294967295

I think that with floating-point numbers KsX approach is not so good, as I have described in #175 (comment) . One year ago I was fixing Double behaviour in Kotlin 1.7 and to my mind there can be such pitfall like I describe...

@akuleshov7 akuleshov7 added the help wanted Extra attention is needed label May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants