use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class TupleCodecTest method should_parse_full_tuple.
@Test
public void should_parse_full_tuple() {
TupleValue tuple = parse("(1,NULL,'a')");
assertThat(tuple.getInt(0)).isEqualTo(1);
assertThat(tuple.isNull(1)).isTrue();
assertThat(tuple.getString(2)).isEqualTo("a");
verify(intCodec).parse("1");
verify(doubleCodec).parse("NULL");
verify(textCodec).parse("'a'");
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class DefaultTupleValueTest method should_serialize_and_deserialize.
@Test
public void should_serialize_and_deserialize() {
DefaultTupleType type = new DefaultTupleType(ImmutableList.of(DataTypes.INT, DataTypes.TEXT), attachmentPoint);
TupleValue in = type.newValue();
in = in.setBytesUnsafe(0, Bytes.fromHexString("0x00000001"));
in = in.setBytesUnsafe(1, Bytes.fromHexString("0x61"));
TupleValue out = SerializationHelper.serializeAndDeserialize(in);
assertThat(out.getType()).isEqualTo(in.getType());
assertThat(out.getType().isDetached()).isTrue();
assertThat(Bytes.toHexString(out.getBytesUnsafe(0))).isEqualTo("0x00000001");
assertThat(Bytes.toHexString(out.getBytesUnsafe(1))).isEqualTo("0x61");
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class DefaultTupleValueTest method should_not_equate_instances_with_same_binary_representation_but_different_types.
@Test
public void should_not_equate_instances_with_same_binary_representation_but_different_types() {
TupleType tupleType1 = DataTypes.tupleOf(DataTypes.INT);
TupleType tupleType2 = DataTypes.tupleOf(DataTypes.VARINT);
TupleValue tuple1 = tupleType1.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x00000001"));
TupleValue tuple2 = tupleType2.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x00000001"));
assertThat(tuple1).isNotEqualTo(tuple2);
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class DefaultTupleValue method equals.
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TupleValue)) {
return false;
}
TupleValue that = (TupleValue) o;
if (!type.equals(that.getType())) {
return false;
}
for (int i = 0; i < values.length; i++) {
DataType innerThisType = type.getComponentTypes().get(i);
DataType innerThatType = that.getType().getComponentTypes().get(i);
if (!innerThisType.equals(innerThatType)) {
return false;
}
Object thisValue = this.codecRegistry().codecFor(innerThisType).decode(this.getBytesUnsafe(i), this.protocolVersion());
Object thatValue = that.codecRegistry().codecFor(innerThatType).decode(that.getBytesUnsafe(i), that.protocolVersion());
if (!Objects.equals(thisValue, thatValue)) {
return false;
}
}
return true;
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class TupleValueSerializer method readDynamicCustomValue.
@Override
public TupleValue readDynamicCustomValue(Buffer buffer, GraphBinaryReader context) throws IOException {
// read the type first
DataType type = ComplexTypeSerializerUtil.decodeTypeDefinition(buffer, driverContext);
assert type instanceof TupleType : "GraphBinary TupleValue deserializer was called on a value that is not encoded as a TupleValue.";
TupleType tupleType = (TupleType) type;
TupleValue value = tupleType.newValue();
// then decode the values from the buffer
return ComplexTypeSerializerUtil.decodeValue(buffer, value, tupleType.getComponentTypes().size());
}
Aggregations