static DefaultConsumablePartition fromBytes(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); ProcessState processState = ProcessState.fromByte(bb.get()); int keyLength = bb.getInt(); byte[] stringBytes = new byte[keyLength]; bb.get(stringBytes, 0, keyLength); long timestamp = bb.getLong(); int numFailures = bb.getInt(); return new DefaultConsumablePartition(GSON.fromJson(Bytes.toString(stringBytes), PartitionKey.class), processState, timestamp, numFailures); }
@Override public int hashCode() { int result = partitionKey.hashCode(); result = 31 * result + processState.hashCode(); result = 31 * result + numFailures; result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); return result; } }
public byte[] toBytes() { byte[] partitionKeyBytes = Bytes.toBytes(GSON.toJson(partitionKey)); // 1 byte for the ProcessState int numBytes = 1; numBytes += Bytes.SIZEOF_INT; numBytes += partitionKeyBytes.length; numBytes += Bytes.SIZEOF_LONG; numBytes += Bytes.SIZEOF_INT; ByteBuffer bb = ByteBuffer.allocate(numBytes); bb.put(processState.toByte()); bb.putInt(partitionKeyBytes.length); bb.put(partitionKeyBytes); bb.putLong(getTimestamp()); bb.putInt(getNumFailures()); return bb.array(); }