Search in sources :

Example 1 with SubstateDeserializationException

use of com.radixdlt.engine.parser.exceptions.SubstateDeserializationException in project radixdlt by radixdlt.

the class VirtualSubstateDeserialization method keyToSubstate.

public Particle keyToSubstate(byte typeByte, ByteBuffer buf) throws DeserializeException {
    var deserializer = byteToDeserializer.get(typeByte);
    if (deserializer == null) {
        throw new DeserializeException("Unknown byte type: " + typeByte);
    }
    try {
        var key = deserializer.keyDeserializer().deserialize(buf);
        var rawSubstate = deserializer.virtualMapper().map(key);
        if (buf.hasRemaining()) {
            throw new TrailingBytesException("Buffer has " + buf.remaining() + " bytes remaining.");
        }
        return rawSubstate;
    } catch (Exception e) {
        throw new SubstateDeserializationException(deserializer.substateClass(), e);
    }
}
Also used : TrailingBytesException(com.radixdlt.engine.parser.exceptions.TrailingBytesException) SubstateDeserializationException(com.radixdlt.engine.parser.exceptions.SubstateDeserializationException) DeserializeException(com.radixdlt.serialization.DeserializeException) SubstateDeserializationException(com.radixdlt.engine.parser.exceptions.SubstateDeserializationException) TrailingBytesException(com.radixdlt.engine.parser.exceptions.TrailingBytesException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Example 2 with SubstateDeserializationException

use of com.radixdlt.engine.parser.exceptions.SubstateDeserializationException in project radixdlt by radixdlt.

the class SubstateDeserialization method deserialize.

public Particle deserialize(ByteBuffer buf) throws DeserializeException {
    var typeByte = buf.get();
    var deserializer = byteToDeserializer.get(typeByte);
    if (deserializer == null) {
        throw new DeserializeException("Unknown byte type: " + typeByte);
    }
    try {
        return deserializer.deserializer().deserialize(buf);
    } catch (Exception e) {
        throw new SubstateDeserializationException(deserializer.substateClass(), e);
    }
}
Also used : SubstateDeserializationException(com.radixdlt.engine.parser.exceptions.SubstateDeserializationException) DeserializeException(com.radixdlt.serialization.DeserializeException) SubstateDeserializationException(com.radixdlt.engine.parser.exceptions.SubstateDeserializationException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Aggregations

SubstateDeserializationException (com.radixdlt.engine.parser.exceptions.SubstateDeserializationException)2 DeserializeException (com.radixdlt.serialization.DeserializeException)2 TrailingBytesException (com.radixdlt.engine.parser.exceptions.TrailingBytesException)1