incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Lin <>
Subject Re: CQL decimal encoding
Date Tue, 25 Feb 2014 16:19:17 GMT
sounds like maybe the bytes aren't being converted to big endian before
sending the bytes to to Cassandra.

In my C# driver, this is what I do.

1. I get the bytes for the scale and unscaled value
2. I reverse both byte arrays
3. I copy the bytes to a new byte array

here is the actual C# code.

        public byte[] ToByteArray()
            byte[] scale = BitConverter.GetBytes(Scale);
            byte[] unscaledValue = UnscaledValue.ToByteArray();


            byte[] bytes = new byte[unscaledValue.Length + scale.Length];
            Array.Copy(scale, 0, bytes, 0, scale.Length);
            Array.Copy(unscaledValue, 0, bytes, scale.Length,
            return bytes;

hope that helps

On Tue, Feb 25, 2014 at 10:56 AM, Ben Hood <> wrote:

> On Tue, Feb 25, 2014 at 12:50 PM, Peter Lin <> wrote:
> >
> > if I have time this week, I'll try to make a patch for the spec. Can't
> > promise I can get to it this week, but having come across this issue with
> > FluentCassandra, I'd like to help others avoid it.
> So I may be running into an encoding bug with my serialization. I can
> round trip serialization to and from Cassandra successfully, but I
> seem to have a discrepancy with cqlsh for some values.
> For example, I've encoded 0.131 as \x00\x00\x00\x03\x83. This round
> trips successfully with the gocql driver, but cqlsh renders it as
> "-0.125". If I try to read the column, my driver gets the value 0.131
> back.
> So how do I start to debug the data that cqlsh is processing?
> Cheers,
> Ben

View raw message