/** * Return the version zero hash for the given wavelet name. */ public static ProtocolHashedVersion createVersionZero(WaveletName waveletName) { byte[] initialHash = HASH_FACTORY.createVersionZero(waveletName).getHistoryHash(); return ProtocolHashedVersion.newBuilder() .setVersion(0) .setHistoryHash(ByteString.copyFrom(initialHash)) .build(); }
/** Serializes a HashedVersion POJO to a protobuf. */ public static ProtocolHashedVersion serialize(HashedVersion hashedVersion) { return ProtocolHashedVersion.newBuilder().setVersion(hashedVersion.getVersion()). setHistoryHash(ByteString.copyFrom(hashedVersion.getHistoryHash())).build(); }
/** * Sets correct version hash to delta. * * @param delta the source delta. * @param waveletSnapshot to append delta. * @param waveletName name of wavelet. * @return the delta to import. * @throws InvalidParticipantAddress deserialize of participant error. */ ProtocolWaveletDelta setVersionHash(ProtocolWaveletDelta delta, CommittedWaveletSnapshot waveletSnapshot, WaveletName waveletName) throws InvalidParticipantAddress { ProtocolWaveletDelta.Builder newDelta = ProtocolWaveletDelta.newBuilder(delta); if (waveletSnapshot == null) { ProtocolHashedVersion ver = ProtocolHashedVersion.newBuilder(delta.getHashedVersion()). setHistoryHash(ByteString.copyFrom(HASH_FACTORY.createVersionZero(waveletName).getHistoryHash())). build(); newDelta.setHashedVersion(ver); } else { ProtocolHashedVersion ver = ProtocolHashedVersion.newBuilder(delta.getHashedVersion()). setHistoryHash(ByteString.copyFrom(waveletSnapshot.snapshot.getHashedVersion().getHistoryHash())). build(); newDelta.setHashedVersion(ver); } return newDelta.build(); } }
/** * Return the updated ProtocolHashedVersion for the given input. * * @param appliedDeltaBytes raw bytes of appliedDelta * @param appliedAt version delta was applied at, must match appliedDelta * @param operationsApplied number of operations applied, must match appliedDelta * @return new ProtocolHashedVersion */ public static ProtocolHashedVersion create(ByteString appliedDeltaBytes, ProtocolHashedVersion appliedAt, int operationsApplied) { // TODO(thorogood): verify appliedAt and operationsApplied against the raw bytes? return ProtocolHashedVersion.newBuilder() .setVersion(appliedAt.getVersion() + operationsApplied) .setHistoryHash(nextHash(appliedAt.getHistoryHash(), appliedDeltaBytes)) .build(); }