Merge

Description: Applies a set of changes (the output of a Diff operation) to a buffer.
Returns: Buffer
Usage: Script Only.
Function Groups: Configuration Management
Related to: Combine | Diff | Merge2
Format: Merge(SourceBuff, DiffBuff)
Parameters:  
SourceBuff
Required. The buffer or stream to be modified.
DiffBuff
Required. The buffer or stream containing formatted instructions for how to modify the source buffer.
Comments:

The source buffer must be identical to the origin buffer used to create the Diff buffer in the first place. This operation cannot fail, but will produce unexpected results if either input buffer is corrupt or if the wrong origin buffer is used. This function is synchronous and returns the result of the operation.

The operations in the DiffBuff are formatted as follows:

  • The low 31 bits of the first four bytes hold the length of the data portion, measured in bytes.
  • The highest bit of those first four bytes will be a 0 to indicate that this is a delete operation or a 1 to indicate that this is an add operation.
  • The next four bytes hold the offset into the source buffer where the operation should take place.
  • The final "length" bytes (where length was defined in the first 31 bits) hold the data to be added in the case that this is an add operation.

"DiffBuff" could be the result from the Diff function.

Merge assumes that the diffs in DiffBuff are ordered and correct, hence does no checking for offsets outside SourceBuff, etc. It is the responsibility of the caller to get it right.

Merge relies on "Modify" operations being ordered as an "Add" in a particular location followed by a "Delete" in the same location. This is the ordering generated by the Diff function. Reversing the order will cause undesirable results.

Examples: