+ private static class Proxy implements Externalizable {
+ private static final long serialVersionUID = 1L;
+
+ private InstallSnapshot installSnapshot;
+
+ // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
+ // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
+ @SuppressWarnings("checkstyle:RedundantModifier")
+ public Proxy() {
+ }
+
+ Proxy(final InstallSnapshot installSnapshot) {
+ this.installSnapshot = installSnapshot;
+ }
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ out.writeLong(installSnapshot.getTerm());
+ out.writeObject(installSnapshot.leaderId);
+ out.writeLong(installSnapshot.lastIncludedIndex);
+ out.writeLong(installSnapshot.lastIncludedTerm);
+ out.writeInt(installSnapshot.chunkIndex);
+ out.writeInt(installSnapshot.totalChunks);
+
+ out.writeByte(installSnapshot.lastChunkHashCode.isPresent() ? 1 : 0);
+ if (installSnapshot.lastChunkHashCode.isPresent()) {
+ out.writeInt(installSnapshot.lastChunkHashCode.getAsInt());
+ }
+
+ out.writeByte(installSnapshot.serverConfig.isPresent() ? 1 : 0);
+ if (installSnapshot.serverConfig.isPresent()) {
+ out.writeObject(installSnapshot.serverConfig.get());
+ }
+
+ out.writeObject(installSnapshot.data);
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+ long term = in.readLong();
+ String leaderId = (String) in.readObject();
+ long lastIncludedIndex = in.readLong();
+ long lastIncludedTerm = in.readLong();
+ int chunkIndex = in.readInt();
+ int totalChunks = in.readInt();
+
+ OptionalInt lastChunkHashCode = in.readByte() == 1 ? OptionalInt.of(in.readInt()) : OptionalInt.empty();
+ Optional<ServerConfigurationPayload> serverConfig = in.readByte() == 1
+ ? Optional.of((ServerConfigurationPayload)in.readObject()) : Optional.empty();
+
+ byte[] data = (byte[])in.readObject();
+
+ installSnapshot = new InstallSnapshot(term, leaderId, lastIncludedIndex, lastIncludedTerm, data,
+ chunkIndex, totalChunks, lastChunkHashCode, serverConfig);
+ }
+
+ private Object readResolve() {
+ return installSnapshot;
+ }