Skip to content

Commit

Permalink
Merge pull request #669 from ryfow/floats-in-dynamic-composite
Browse files Browse the repository at this point in the history
Fix deserialization of Floats in Composites.
  • Loading branch information
zznate committed Sep 23, 2014
2 parents 9008239 + 6261350 commit b9d09b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package me.prettyprint.cassandra.serializers;

import static me.prettyprint.hector.api.ddl.ComparatorType.FLOATTYPE;

import java.nio.ByteBuffer;

import me.prettyprint.hector.api.ddl.ComparatorType;

/**
* Uses IntSerializer via translating Float objects to and from raw long bytes form.
*
Expand All @@ -25,4 +29,9 @@ public Float fromByteBuffer(ByteBuffer bytes) {
return Float.intBitsToFloat(IntegerSerializer.get().fromByteBuffer(bytes));
}

@Override
public ComparatorType getComparatorType() {
return FLOATTYPE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static me.prettyprint.hector.api.ddl.ComparatorType.TIMEUUIDTYPE;
import static me.prettyprint.hector.api.ddl.ComparatorType.UTF8TYPE;
import static me.prettyprint.hector.api.ddl.ComparatorType.UUIDTYPE;
import static me.prettyprint.hector.api.ddl.ComparatorType.FLOATTYPE;

import java.math.BigInteger;
import java.nio.ByteBuffer;
Expand All @@ -27,6 +28,7 @@
import me.prettyprint.cassandra.serializers.SerializerTypeInferer;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.serializers.UUIDSerializer;
import me.prettyprint.cassandra.serializers.FloatSerializer;
import me.prettyprint.cassandra.utils.ByteBufferOutputStream;
import me.prettyprint.hector.api.Serializer;

Expand Down Expand Up @@ -87,20 +89,24 @@ public static ComponentEquality fromByte(byte equality) {
LongSerializer.get().getComparatorType().getTypeName())
.put(StringSerializer.class,
StringSerializer.get().getComparatorType().getTypeName())
.put(FloatSerializer.class,
FloatSerializer.get().getComparatorType().getTypeName())
.put(UUIDSerializer.class,
UUIDSerializer.get().getComparatorType().getTypeName()).build();

static final ImmutableClassToInstanceMap<Serializer> SERIALIZERS = new ImmutableClassToInstanceMap.Builder<Serializer>()
.put(AsciiSerializer.class, AsciiSerializer.get())
.put(BigIntegerSerializer.class, BigIntegerSerializer.get())
.put(ByteBufferSerializer.class, ByteBufferSerializer.get())
.put(FloatSerializer.class, FloatSerializer.get())
.put(LongSerializer.class, LongSerializer.get())
.put(StringSerializer.class, StringSerializer.get())
.put(UUIDSerializer.class, UUIDSerializer.get()).build();

public static final BiMap<Byte, String> DEFAULT_ALIAS_TO_COMPARATOR_MAPPING = new ImmutableBiMap.Builder<Byte, String>()
.put((byte) 'a', ASCIITYPE.getTypeName())
.put((byte) 'b', BYTESTYPE.getTypeName())
.put((byte) 'f', FLOATTYPE.getTypeName())
.put((byte) 'i', INTEGERTYPE.getTypeName())
.put((byte) 'x', LEXICALUUIDTYPE.getTypeName())
.put((byte) 'l', LONGTYPE.getTypeName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public void testDynamicSerialization() throws Exception {
o = c.get(0);
assertTrue(o instanceof Long);

// test serialization and deserialization of floats
c = new DynamicComposite();
c.add(new Float(10));
b = c.serialize();
c = new DynamicComposite();
c.deserialize(b);
o = c.get(0);
assertTrue(o instanceof Float);

// test serialization and deserialization of random UUIDS
c = new DynamicComposite();
c.add(UUID.randomUUID());
Expand Down

0 comments on commit b9d09b0

Please sign in to comment.