use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class MultiSerialiser method deserialise.
@Override
public Object deserialise(final byte[] bytes) throws SerialisationException {
try {
byte keyByte = bytes[0];
ToBytesSerialiser serialiser = nullCheck(supportedSerialisers.getSerialiserFromKey(keyByte));
return serialiser.deserialise(bytes, 1, bytes.length - 1);
} catch (final SerialisationException e) {
// re-throw SerialisationException
throw e;
} catch (final Exception e) {
// wraps other exceptions.
throw new SerialisationException(e.getMessage(), e);
}
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class StoreTest method shouldFindInvalidSerialiser.
@Test
public void shouldFindInvalidSerialiser() throws Exception {
final Class<StringToStringSerialiser> invalidSerialiserClass = StringToStringSerialiser.class;
Schema invalidSchema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("string").destination("invalidString").directed("true").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).type("string", new TypeDefinition.Builder().clazz(String.class).serialiser(new StringSerialiser()).build()).type("invalidString", new TypeDefinition.Builder().clazz(String.class).serialiser(invalidSerialiserClass.newInstance()).build()).type("true", Boolean.class).build();
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
final Class<ToBytesSerialiser> validSerialiserInterface = ToBytesSerialiser.class;
try {
new StoreImpl() {
@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return validSerialiserInterface;
}
}.initialise("graphId", invalidSchema, properties);
fail("Should have thrown exception");
} catch (final SchemaException e) {
assertTrue(e.getMessage().contains(invalidSerialiserClass.getSimpleName()));
}
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class ByteEntityRangeFactory method getKeyFromEdgeId.
protected Key getKeyFromEdgeId(final Object source, final Object destination, final boolean directed, final boolean endKey) throws RangeFactoryException {
final ToBytesSerialiser vertexSerialiser = (ToBytesSerialiser) schema.getVertexSerialiser();
final byte directionFlag = directed ? ByteEntityPositions.CORRECT_WAY_DIRECTED_EDGE : ByteEntityPositions.UNDIRECTED_EDGE;
byte[] sourceValue;
try {
sourceValue = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(source));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise Edge Source", e);
}
byte[] destinationValue;
try {
destinationValue = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(destination));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise Edge Destination", e);
}
byte[] key = getKey(endKey, directionFlag, sourceValue, destinationValue);
return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project gaffer-doc by gchq.
the class PropertiesWalkthrough method getSerialisers.
private static List<Serialiser> getSerialisers() {
final List<Serialiser> serialisers = getSubClassInstances(Serialiser.class);
serialisers.removeIf(c -> {
boolean contains = false;
for (final ToBytesSerialiser serialiser : TO_BYTES_SERIALISERS) {
if (serialiser.getClass().equals(c.getClass())) {
contains = true;
break;
}
}
return contains;
});
return serialisers;
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class MapSerialiser method deserialise.
@Override
public Map<? extends Object, ? extends Object> deserialise(final byte[] bytes) throws SerialisationException {
Map map;
if (null == getMapClass()) {
map = new HashMap<>();
} else {
try {
map = getMapClass().newInstance();
} catch (final IllegalAccessException | IllegalArgumentException | SecurityException | InstantiationException e) {
throw new SerialisationException("Failed to create map instance" + e.getMessage(), e);
}
}
final int arrayLength = bytes.length;
int carriage = 0;
while (carriage < arrayLength) {
final ToBytesSerialiser keySerialiser = getKeySerialiser();
final ToBytesSerialiser valueSerialiser = getValueSerialiser();
checkSerialiers(keySerialiser, valueSerialiser);
LengthValueBytesSerialiserUtil.ObjectCarriage c = LengthValueBytesSerialiserUtil.deserialiseNextObject(keySerialiser, carriage, bytes);
LengthValueBytesSerialiserUtil.ObjectCarriage c2 = LengthValueBytesSerialiserUtil.deserialiseNextObject(valueSerialiser, c.getCarriage(), bytes);
map.put(c.getObject(), c2.getObject());
carriage = c2.getCarriage();
}
return map;
}
Aggregations