class RBMBackedTimestampSetSerialiser implements ToBytesSerialiser<RBMBackedTimestampSet> {

    @Override
    public byte[] serialise(final RBMBackedTimestampSet rbmBackedTimestampSet) throws SerialisationException {
        if (null == rbmBackedTimestampSet) {
            return EMPTY_BYTES;
        }
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream dos = new DataOutputStream(baos);
        try {
            dos.write(CompactRawSerialisationUtils.writeLong(rbmBackedTimestampSet.getTimeBucket().ordinal()));
            rbmBackedTimestampSet.getRbm().serialize(dos);
        } catch (final IOException e) {
            throw new SerialisationException("Exception writing serialised RBMBackedTimestampSet to ByteArrayOutputStream",
                    e);
        }
        return baos.toByteArray();
    }

}