public static void toggleEventCorruption(EventCorruptionType type, DbusEvent event)
throws InvalidEventException
{
// Regardless of the underlying event type (e.g., readable), we're writing to its
// internal state, so "convert" it to a writable event.
DbusEventInternalWritable writableEvent = makeWritable(event); // bruuuuuuutal...
switch (type)
{
case LENGTH:
int newSize = writableEvent.size() ^ CORRUPTION_PATTERN;
writableEvent.setSize(newSize);
break;
case HEADERCRC:
long headerCrc = writableEvent.headerCrc() ^ CORRUPTION_PATTERN;
writableEvent.setHeaderCrc(headerCrc);
break;
case PAYLOAD:
if (writableEvent.payloadLength() > 0)
{
byte[] payload = new byte[writableEvent.payloadLength()];
writableEvent.value().get(payload);
payload[0] ^= CORRUPTION_PATTERN;
writableEvent.setValue(payload);
}
break;
case PAYLOADCRC:
long payloadCrc = writableEvent.bodyCrc() ^ CORRUPTION_PATTERN;
writableEvent.setValueCrc(payloadCrc);
break;
}
}