-
Notifications
You must be signed in to change notification settings - Fork 184
Add codec for BigInteger #235
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
Conversation
Applicable to any numeric type with scale 0 [resolves pgjdbc#233]
BigInteger doDecode(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format format, @Nullable Class<? extends BigInteger> type) { | ||
Assert.requireNonNull(buffer, "byteBuf must not be null"); | ||
|
||
return this.decodeNumber(buffer, dataType, format, BigInteger.class, it -> new BigInteger(it.toString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code potentially throws NumberFormatException
when the scale is > 0.
I did not find any defensive code in the other subclasses of AbstractNumericCodec
so I did not add checks to see if construction of the BigInteger
is possible using the decoded value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our codecs downcast values if they are requested to do so. E.g. a FLOAT8
column result can be consumed as Double
, Long
, Int
etc. I think we should do the same here and return the BigInteger
value.
I will take care of this aspect during the merge.
Applicable to any numeric type with scale 0
[resolves #233]