/** * Builds a transformed delta from an applied delta and its transformed ops. */ public static TransformedWaveletDelta buildTransformedDelta( ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDeltaBytes, WaveletDelta transformed) throws InvalidProtocolBufferException { ProtocolAppliedWaveletDelta appliedDelta = appliedDeltaBytes.getMessage(); Preconditions.checkArgument( getHashedVersionAppliedAt(appliedDeltaBytes).equals(transformed.getTargetVersion())); Preconditions.checkArgument(appliedDelta.getOperationsApplied() == transformed.size()); HashedVersion resultingVersion = HASH_FACTORY.create(appliedDeltaBytes.getByteArray(), transformed.getTargetVersion(), appliedDelta.getOperationsApplied()); return TransformedWaveletDelta.cloneOperations(resultingVersion, appliedDelta.getApplicationTimestamp(), transformed); }
long opsApplied = applicationResult.getResultingVersion().getVersion() - expectedVersion.getVersion(); if (opsApplied != appliedDelta.getMessage().getOperationsApplied()) { throw new OperationException("Operations applied here do not match the authoritative" + " server claim (got " + opsApplied + ", expected " + appliedDelta.getMessage().getOperationsApplied() + ".");
/** * Calculates the hashed version after an applied delta is applied. */ public static HashedVersion calculateResultingHashedVersion( ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta) throws InvalidProtocolBufferException { return HASH_FACTORY.create( appliedDelta.getByteArray(), getHashedVersionAppliedAt(appliedDelta), appliedDelta.getMessage().getOperationsApplied()); }