ziggythehamster edited a comment on pull request #840:
URL: https://github.com/apache/avro/pull/840#issuecomment-640154458


   Here's the Java decoder: 
https://github.com/apache/avro/blob/93ec41bacf678a875d3696dec72a84901482602a/lang/java/avro/src/main/java/org/apache/avro/Conversions.java#L82-L88
   
   and the Java encoder: 
https://github.com/apache/avro/blob/93ec41bacf678a875d3696dec72a84901482602a/lang/java/avro/src/main/java/org/apache/avro/Conversions.java#L90-L95
   
   and since I'm not a Java programmer, I looked at the docs for Java 
BigDecimal and see this statement:
   
   > The value of the number represented by the BigDecimal is therefore 
(unscaledValue × 10-scale).
   
   Excellent, because Ruby's 
[BigDecimal#split](https://ruby-doc.org/stdlib-2.7.1/libdoc/bigdecimal/rdoc/BigDecimal.html#method-i-split)
 method will give you the significant digits and exponent which I think is the 
same.
   
   Of course, you now need to figure out what Java's BigInteger `toByteArray` 
is doing exactly, and [here's the docs for 
that](https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html#toByteArray--).
 Almost a decade ago, someone on Stack Overflow worked on a [version of 
this](https://stackoverflow.com/questions/5284369/ruby-return-byte-array-containing-twos-complement-representation-of-bignum-fi)...
 and it's been longer than that since I took any CS classes, so hopefully 
someone with a bit more freshness there can take this information and run with 
it :).
   
   Finally, once you've got the array of integers, you'll need to use 
[Array#pack](https://ruby-doc.org/core-2.7.1/Array.html#method-i-pack) to make 
it a string. I think you need the pattern `C*`.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to