public Mutation deserialize(DataInputPlus in, int version, SerializationHelper.Flag flag) throws IOException { if (version < MessagingService.VERSION_20) in.readUTF(); // read pre-2.0 keyspace name ByteBuffer key = null; int size; if (version < MessagingService.VERSION_30) { key = ByteBufferUtil.readWithShortLength(in); size = in.readInt(); } else { size = (int)in.readUnsignedVInt(); } assert size > 0; PartitionUpdate update = PartitionUpdate.serializer.deserialize(in, version, flag, key); if (size == 1) return new Mutation(update); Map<UUID, PartitionUpdate> modifications = new HashMap<>(size); DecoratedKey dk = update.partitionKey(); modifications.put(update.metadata().cfId, update); for (int i = 1; i < size; ++i) { update = PartitionUpdate.serializer.deserialize(in, version, flag, dk); modifications.put(update.metadata().cfId, update); } return new Mutation(update.metadata().ksName, dk, modifications); }
/** * Serialize a partition update as a byte buffer. * * @param update the partition update to serialize. * @param version the version to serialize the update into. * * @return a newly allocated byte buffer containing the serialized update. */ public static ByteBuffer toBytes(PartitionUpdate update, int version) { try (DataOutputBuffer out = new DataOutputBuffer()) { serializer.serialize(update, out, version); return out.asNewBuffer(); } catch (IOException e) { throw new RuntimeException(e); } }
public long serializedSize(Mutation mutation, int version) { int size = 0; if (version < MessagingService.VERSION_20) size += TypeSizes.sizeof(mutation.getKeyspaceName()); if (version < MessagingService.VERSION_30) { int keySize = mutation.key().getKey().remaining(); size += TypeSizes.sizeof((short) keySize) + keySize; size += TypeSizes.sizeof(mutation.modifications.size()); } else { size += TypeSizes.sizeofUnsignedVInt(mutation.modifications.size()); } for (Map.Entry<UUID, PartitionUpdate> entry : mutation.modifications.entrySet()) size += PartitionUpdate.serializer.serializedSize(entry.getValue(), version); return size; } }
/** * Deserialize a partition update from a provided byte buffer. * * @param bytes the byte buffer that contains the serialized update. * @param version the version with which the update is serialized. * @param key the partition key for the update. This is only used if {@code version < 3.0} * and can be {@code null} otherwise. * * @return the deserialized update or {@code null} if {@code bytes == null}. */ public static PartitionUpdate fromBytes(ByteBuffer bytes, int version, DecoratedKey key) { if (bytes == null) return null; try { return serializer.deserialize(new DataInputBuffer(bytes, true), version, SerializationHelper.Flag.LOCAL, version < MessagingService.VERSION_30 ? key : null); } catch (IOException e) { throw new RuntimeException(e); } }
public Mutation deserialize(DataInputPlus in, int version, SerializationHelper.Flag flag) throws IOException { if (version < MessagingService.VERSION_20) in.readUTF(); // read pre-2.0 keyspace name ByteBuffer key = null; int size; if (version < MessagingService.VERSION_30) { key = ByteBufferUtil.readWithShortLength(in); size = in.readInt(); } else { size = (int)in.readUnsignedVInt(); } assert size > 0; PartitionUpdate update = PartitionUpdate.serializer.deserialize(in, version, flag, key); if (size == 1) return new Mutation(update); Map<UUID, PartitionUpdate> modifications = new HashMap<>(size); DecoratedKey dk = update.partitionKey(); modifications.put(update.metadata().cfId, update); for (int i = 1; i < size; ++i) { update = PartitionUpdate.serializer.deserialize(in, version, flag, dk); modifications.put(update.metadata().cfId, update); } return new Mutation(update.metadata().ksName, dk, modifications); }
/** * Deserialize a partition update from a provided byte buffer. * * @param bytes the byte buffer that contains the serialized update. * @param version the version with which the update is serialized. * @param key the partition key for the update. This is only used if {@code version < 3.0} * and can be {@code null} otherwise. * * @return the deserialized update or {@code null} if {@code bytes == null}. */ public static PartitionUpdate fromBytes(ByteBuffer bytes, int version, DecoratedKey key) { if (bytes == null) return null; try { return serializer.deserialize(new DataInputBuffer(bytes, true), version, SerializationHelper.Flag.LOCAL, version < MessagingService.VERSION_30 ? key : null); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Deserialize a partition update from a provided byte buffer. * * @param bytes the byte buffer that contains the serialized update. * @param version the version with which the update is serialized. * @param key the partition key for the update. This is only used if {@code version < 3.0} * and can be {@code null} otherwise. * * @return the deserialized update or {@code null} if {@code bytes == null}. */ public static PartitionUpdate fromBytes(ByteBuffer bytes, int version, DecoratedKey key) { if (bytes == null) return null; try { return serializer.deserialize(new DataInputBuffer(bytes, true), version, SerializationHelper.Flag.LOCAL, version < MessagingService.VERSION_30 ? key : null); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Deserialize a partition update from a provided byte buffer. * * @param bytes the byte buffer that contains the serialized update. * @param version the version with which the update is serialized. * @param key the partition key for the update. This is only used if {@code version < 3.0} * and can be {@code null} otherwise. * * @return the deserialized update or {@code null} if {@code bytes == null}. */ public static PartitionUpdate fromBytes(ByteBuffer bytes, int version, DecoratedKey key) { if (bytes == null) return null; try { return serializer.deserialize(new DataInputBuffer(bytes, true), version, SerializationHelper.Flag.LOCAL, version < MessagingService.VERSION_30 ? key : null); } catch (IOException e) { throw new RuntimeException(e); } }
public Mutation deserialize(DataInputPlus in, int version, SerializationHelper.Flag flag) throws IOException { if (version < MessagingService.VERSION_20) in.readUTF(); // read pre-2.0 keyspace name ByteBuffer key = null; int size; if (version < MessagingService.VERSION_30) { key = ByteBufferUtil.readWithShortLength(in); size = in.readInt(); } else { size = (int)in.readUnsignedVInt(); } assert size > 0; PartitionUpdate update = PartitionUpdate.serializer.deserialize(in, version, flag, key); if (size == 1) return new Mutation(update); Map<UUID, PartitionUpdate> modifications = new HashMap<>(size); DecoratedKey dk = update.partitionKey(); modifications.put(update.metadata().cfId, update); for (int i = 1; i < size; ++i) { update = PartitionUpdate.serializer.deserialize(in, version, flag, dk); modifications.put(update.metadata().cfId, update); } return new Mutation(update.metadata().ksName, dk, modifications); }
/** * Serialize a partition update as a byte buffer. * * @param update the partition update to serialize. * @param version the version to serialize the update into. * * @return a newly allocated byte buffer containing the serialized update. */ public static ByteBuffer toBytes(PartitionUpdate update, int version) { try (DataOutputBuffer out = new DataOutputBuffer()) { serializer.serialize(update, out, version); return out.buffer(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Serialize a partition update as a byte buffer. * * @param update the partition update to serialize. * @param version the version to serialize the update into. * * @return a newly allocated byte buffer containing the serialized update. */ public static ByteBuffer toBytes(PartitionUpdate update, int version) { try (DataOutputBuffer out = new DataOutputBuffer()) { serializer.serialize(update, out, version); return out.buffer(); } catch (IOException e) { throw new RuntimeException(e); } }
public void serialize(Mutation mutation, DataOutputPlus out, int version) throws IOException { if (version < MessagingService.VERSION_20) out.writeUTF(mutation.getKeyspaceName()); /* serialize the modifications in the mutation */ int size = mutation.modifications.size(); if (version < MessagingService.VERSION_30) { ByteBufferUtil.writeWithShortLength(mutation.key().getKey(), out); out.writeInt(size); } else { out.writeUnsignedVInt(size); } assert size > 0; for (Map.Entry<UUID, PartitionUpdate> entry : mutation.modifications.entrySet()) PartitionUpdate.serializer.serialize(entry.getValue(), out, version); }
public void serialize(Mutation mutation, DataOutputPlus out, int version) throws IOException { if (version < MessagingService.VERSION_20) out.writeUTF(mutation.getKeyspaceName()); /* serialize the modifications in the mutation */ int size = mutation.modifications.size(); if (version < MessagingService.VERSION_30) { ByteBufferUtil.writeWithShortLength(mutation.key().getKey(), out); out.writeInt(size); } else { out.writeUnsignedVInt(size); } assert size > 0; for (Map.Entry<UUID, PartitionUpdate> entry : mutation.modifications.entrySet()) PartitionUpdate.serializer.serialize(entry.getValue(), out, version); }
public long serializedSize(Mutation mutation, int version) { int size = 0; if (version < MessagingService.VERSION_20) size += TypeSizes.sizeof(mutation.getKeyspaceName()); if (version < MessagingService.VERSION_30) { int keySize = mutation.key().getKey().remaining(); size += TypeSizes.sizeof((short) keySize) + keySize; size += TypeSizes.sizeof(mutation.modifications.size()); } else { size += TypeSizes.sizeofUnsignedVInt(mutation.modifications.size()); } for (Map.Entry<UUID, PartitionUpdate> entry : mutation.modifications.entrySet()) size += PartitionUpdate.serializer.serializedSize(entry.getValue(), version); return size; } }
public void serialize(Mutation mutation, DataOutputPlus out, int version) throws IOException { if (version < MessagingService.VERSION_20) out.writeUTF(mutation.getKeyspaceName()); /* serialize the modifications in the mutation */ int size = mutation.modifications.size(); if (version < MessagingService.VERSION_30) { ByteBufferUtil.writeWithShortLength(mutation.key().getKey(), out); out.writeInt(size); } else { out.writeUnsignedVInt(size); } assert size > 0; for (Map.Entry<UUID, PartitionUpdate> entry : mutation.modifications.entrySet()) PartitionUpdate.serializer.serialize(entry.getValue(), out, version); }
public PrepareResponse deserialize(DataInputPlus in, int version) throws IOException { boolean success = in.readBoolean(); Commit inProgress = Commit.serializer.deserialize(in, version); Commit mostRecent; if (version < MessagingService.VERSION_30) { UUID ballot = UUIDSerializer.serializer.deserialize(in, version); PartitionUpdate update = PartitionUpdate.serializer.deserialize(in, version, SerializationHelper.Flag.LOCAL, inProgress.update.partitionKey()); mostRecent = new Commit(ballot, update); } else { mostRecent = Commit.serializer.deserialize(in, version); } return new PrepareResponse(success, inProgress, mostRecent); }
/** * Serialize a partition update as a byte buffer. * * @param update the partition update to serialize. * @param version the version to serialize the update into. * * @return a newly allocated byte buffer containing the serialized update. */ public static ByteBuffer toBytes(PartitionUpdate update, int version) { try (DataOutputBuffer out = new DataOutputBuffer()) { serializer.serialize(update, out, version); return out.buffer(); } catch (IOException e) { throw new RuntimeException(e); } }
public long serializedSize(Mutation mutation, int version) { int size = 0; if (version < MessagingService.VERSION_20) size += TypeSizes.sizeof(mutation.getKeyspaceName()); if (version < MessagingService.VERSION_30) { int keySize = mutation.key().getKey().remaining(); size += TypeSizes.sizeof((short) keySize) + keySize; size += TypeSizes.sizeof(mutation.modifications.size()); } else { size += TypeSizes.sizeofUnsignedVInt(mutation.modifications.size()); } for (Map.Entry<UUID, PartitionUpdate> entry : mutation.modifications.entrySet()) size += PartitionUpdate.serializer.serializedSize(entry.getValue(), version); return size; } }
public long serializedSize(PrepareResponse response, int version) { long size = TypeSizes.sizeof(response.promised) + Commit.serializer.serializedSize(response.inProgressCommit, version); if (version < MessagingService.VERSION_30) { size += UUIDSerializer.serializer.serializedSize(response.mostRecentCommit.ballot, version); size += PartitionUpdate.serializer.serializedSize(response.mostRecentCommit.update, version); } else { size += Commit.serializer.serializedSize(response.mostRecentCommit, version); } return size; } }
public PrepareResponse deserialize(DataInputPlus in, int version) throws IOException { boolean success = in.readBoolean(); Commit inProgress = Commit.serializer.deserialize(in, version); Commit mostRecent; if (version < MessagingService.VERSION_30) { UUID ballot = UUIDSerializer.serializer.deserialize(in, version); PartitionUpdate update = PartitionUpdate.serializer.deserialize(in, version, SerializationHelper.Flag.LOCAL, inProgress.update.partitionKey()); mostRecent = new Commit(ballot, update); } else { mostRecent = Commit.serializer.deserialize(in, version); } return new PrepareResponse(success, inProgress, mostRecent); }