Hi all,
I've recently made use of
func parseBigInt(bytes []byte) *big.Int
On Thu, Feb 27, 2014 at 5:10 AM, egon <egon...@gmail.com> wrote:
> v := big.NewInt(0)
> v.SetBytes(bytes)
> bytes := v.Bytes()
Are you saying that this is how to read a two's complimented encoded
varint into a big.Int?
> Not sure why you would want to use those from asn1 instead?
For encoding I started out by using the standard library:
http://golang.org/pkg/math/big/#Int.Bytes
But then found out that this doesn't encode a varint in the same way
that other languages do, so I needed to find an interoperable
solution.
For decoding I started out by using:
http://golang.org/pkg/math/big/#Int.SetBytes
But found that this didn't produce the same value as when other
languages deserialize the same bytes.
So I began to look around for a two's compliment encoding for a
variant in Golang, and the only thing I found that worked
interoperably was the routines used internally in the asn1 module. So
because this worked, I decided to run with this solution for now.
However, if you're telling me that I'm missing a trick, please do let
me know.
I still don't understand your goal. A quick check of Cassandra documents suggests its BIGINT is a 64 bit int, and its VARINT is just an unlimited precision integer. Why do you need scale factors and various decimal libraries?
If you will show us the incoming bytestream format and describe your processing goals, you'll get better answers.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
On Thu, Feb 27, 2014 at 6:45 PM, Donovan Hide <donov...@gmail.com> wrote:
> Your code is very confusing. Write a simple test case for a set of numbers
> that you want to round trip. Don't write the code that implements the test.
> Post that set of tests.
OK, here's a test case with just the specification, leaving the
implementation blank: http://play.golang.org/p/3YWOtrO49x
> Before you were talking about rational numbers, i.e. fractional/decimal, but
> now you seem to be dealing with integers. A two's complement encoded int64
> is never going to be comparable to a possibly infinite length integer.
That's a fair point and I'm sorry for being so confusing. When I
started this discussion thread I tried to reduce my question down to
the crux of the matter so that people didn't need to filter out the
surrounding context. But the way I've tried to do that has made it
more confusing. Sorry about that.
> I know how easy it is do fall into the trap of "I know better" and "I'm
> taking the right approach"... so also assume that the people answering are
> 1000x smarter than you and can provide solutions that you never imagined
> (even if it may not be true).
I agree that humility is always a good personal characteristic to have.
I thought my original formulation of "Maybe I've overlooked something,
..." in the OP indicated some form of humility on by behalf. On
reflection, maybe that statement comes across as "I know better, but
I've still got a problem". Coming across as being not very sympathetic
and doesn't encourage people to help you.
In any case, what I've managed to do is to confuse and annoy people
who are just trying to help. I'm sorry for being so clumsy.
Ben
> Something like this, perhaps?
>
> http://play.golang.org/p/ADlfKNZYfZ
>
> I think it works better without the error returns from the
> Marshal and Unmarshal functions too - interpreting an
> empty slice as zero seems a reasonable trade-off.