use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class CompactRawLongSerialiserTest method test.
private void test(final long value) throws SerialisationException {
// Given When
final byte[] b = serialiser.serialise(value);
final Object o = ((ToBytesSerialiser) serialiser).deserialise(b, 0, b.length);
// Then
assertEquals(Long.class, o.getClass());
assertEquals(value, o);
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
CompactRawSerialisationUtils.write(value, new DataOutputStream(stream));
final long result = CompactRawSerialisationUtils.read(new DataInputStream(new ByteArrayInputStream(stream.toByteArray())));
assertEquals(result, value);
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class MapSerialiser method serialise.
@Override
public byte[] serialise(final Map object) throws SerialisationException {
LengthValueBytesSerialiserUtil.LengthValueBuilder builder = new LengthValueBytesSerialiserUtil.LengthValueBuilder();
try {
for (final Object o : object.entrySet()) {
if (o instanceof Map.Entry) {
Map.Entry entry = (Map.Entry) o;
final ToBytesSerialiser keySerialiser = getKeySerialiser();
final ToBytesSerialiser valueSerialiser = getValueSerialiser();
checkSerialiers(keySerialiser, valueSerialiser);
builder.appendLengthValueFromObjectToByteStream(keySerialiser, entry.getKey());
builder.appendLengthValueFromObjectToByteStream(valueSerialiser, entry.getValue());
} else {
throw new SerialisationException("Was not able to process EntrySet of Map");
}
}
} catch (final IOException e) {
throw new SerialisationException(e.getMessage(), e);
}
return builder.toArray();
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class MultiSerialiserStorage method canHandle.
/**
* @param handleClass class to check
* @return {@link ToBytesSerialiser#canHandle(Class)}
* @see ToBytesSerialiser
*/
public boolean canHandle(final Class handleClass) {
boolean rtn = false;
final Byte key = classToKey.get(handleClass);
if (null != key) {
Serialiser serialiser = keyToSerialiser.get(key);
rtn = null != serialiser && serialiser.canHandle(handleClass);
}
return rtn;
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class MultiSerialiserStorageTest method shouldUpdateToNewerValueToSerialiser.
@Test
public void shouldUpdateToNewerValueToSerialiser() throws Exception {
// give
byte serialiserEncoding = BYTE + 1;
// when
mss.put(serialiserEncoding, SERIALISER_CLASS2, SUPPORTED_CLASS);
mss.put(BYTE, SERIALISER_CLASS, SUPPORTED_CLASS);
// then
checkBasicPut();
assertEquals(BYTE, (byte) mss.getKeyFromValue(VALUE));
ToBytesSerialiser actualClassFromByte2 = mss.getSerialiserFromKey(serialiserEncoding);
assertNotNull(actualClassFromByte2, "Byte key not found");
assertEquals(SERIALISER_CLASS2, actualClassFromByte2, "Wrong SerialiserClass returned for key");
ToBytesSerialiser actualClassFromValue2 = mss.getSerialiserFromValue(Integer.MAX_VALUE);
assertNotNull(actualClassFromValue2, "Value class not found");
assertEquals(SERIALISER_CLASS, actualClassFromValue2, "Wrong SerialiserClass, should have updated to newer SerialiserClass");
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class MultiSerialiserStorageTest method shouldNotRetainOldSerialiserWhenKeyIsOverWritten.
@Test
public void shouldNotRetainOldSerialiserWhenKeyIsOverWritten() throws Exception {
// when
mss.put(BYTE, SERIALISER_CLASS, SUPPORTED_CLASS);
mss.put(BYTE, SERIALISER_CLASS2, SUPPORTED_CLASS);
// then
assertNotNull(mss.getKeyFromValue(VALUE));
assertEquals((Object) BYTE, mss.getKeyFromValue(VALUE), "Wrong key for value");
ToBytesSerialiser actualClassFromByte = mss.getSerialiserFromKey(BYTE);
assertNotNull(actualClassFromByte, "Byte key not found");
assertEquals(SERIALISER_CLASS2, actualClassFromByte, "Wrong new SerialiserClass returned for key");
ToBytesSerialiser actualClassFromValue = mss.getSerialiserFromValue(Integer.MAX_VALUE);
assertNotNull(actualClassFromValue, "Value class not found");
assertEquals(SERIALISER_CLASS2, actualClassFromValue, "Wrong new SerialiserClass returned for value class");
}
Aggregations