Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/java/org/apache/cassandra/dht/RandomPartitioner.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ public final boolean accordSupported()
@Override
public final void accordSerialize(Token token, DataOutputPlus out) throws IOException
{
byte[] bytes = increment(((BigIntegerToken)token).token.toByteArray());
Invariants.require(bytes.length <= 16);
byte[] bytes = toAccordSerializedBytes(token);
if (bytes.length < 16)
out.write(ZERO_BYTES, 0, 16 - bytes.length);
out.write(bytes);
Expand All @@ -435,8 +434,7 @@ public final void accordSerialize(Token token, DataOutputPlus out) throws IOExce
@Override
public final void accordSerialize(Token token, ByteBuffer out)
{
byte[] bytes = increment(((BigIntegerToken)token).token.toByteArray());
Invariants.require(bytes.length <= 16);
byte[] bytes = toAccordSerializedBytes(token);
if (bytes.length < 16)
out.put(ZERO_BYTES, 0, 16 - bytes.length);
out.put(bytes);
Expand All @@ -448,23 +446,33 @@ public final Token accordDeserialize(DataInputPlus in, int length) throws IOExce
Invariants.require(length == 16);
byte[] bytes = new byte[16];
in.readFully(bytes);
decrement(bytes);
return new BigIntegerToken(new BigInteger(bytes));
return fromAccordSerializedBytes(bytes);
}

@Override
public final Token accordDeserialize(ByteBuffer in, int length)
{
byte[] bytes = new byte[16];
in.get(bytes);
decrement(bytes);
return new BigIntegerToken(new BigInteger(bytes));
return fromAccordSerializedBytes(bytes);
}

@Override
public final <V> Token accordDeserialize(V src, ValueAccessor<V> accessor, int offset, int length)
{
byte[] bytes = accessor.toArray(src, offset, 16);
return fromAccordSerializedBytes(bytes);
}

private static byte[] toAccordSerializedBytes(Token token)
{
byte[] bytes = increment(((BigIntegerToken) token).token.toByteArray());
Invariants.require(bytes.length <= 16);
return bytes;
}

private static Token fromAccordSerializedBytes(byte[] bytes)
{
decrement(bytes);
return new BigIntegerToken(new BigInteger(bytes));
}
Expand Down