• Public
  • Public/Protected
  • All

Interface DeltaType<ValueType, SourceType, CBORType>

Optional extension provided by DataType implementations that support incremental changes to values.

A data type can optionally support incremental changes to values, represented by one or more types of delta. A delta is the difference between two values. For large or composite values that change in small steps, it is more efficient to transmit an initial value followed by a delta for each change than to transmit a complete value for each change.

Each implementation specifies a value type and a delta type. Two values, oldValue and new Value, can be compared to produce a delta using DeltaType.diff. The delta can be separately applied to oldValue to create newValue using DeltaType.apply.

Deferred parsing
Implementations can choose not to fully validate values when they are read, but instead defer parsing until it is required. Consequently, all methods that accept values may throw an error.


Type parameters

  • ValueType

    the value type of the data type

  • SourceType

    the type(s) from which a value can be constructed

  • CBORType

    the binary type containing the CBOR data


  • DeltaType




  • apply(oldValue: SourceType, delta: BinaryDelta): ValueType | null
  • Apply a delta to a value.


    an error if the value or delta is invalid


    • oldValue: SourceType
    • delta: BinaryDelta

      the delta to apply

    Returns ValueType | null

    the new value generated applying the delta to the old value


  • diff(oldValue: SourceType, newValue: SourceType): BinaryDelta
  • Create a delta from two values.

    If there are many differences between oldValue and newValue, the result might require more bytes to transmit than the new value, or be computationally expensive to apply. In this case, it is better to discard oldValue and publish newValue in its place. This can be checked using DeltaType.isValueCheaper.

    The implementation can return the special constant DeltaType.noChange to indicate the old value and new value are equivalent and there is no change to publish.


    • oldValue: SourceType

      the old value

    • newValue: SourceType

      the new value

    Returns BinaryDelta

    the delta between values


  • isValueCheaper(value: SourceType, delta: BinaryDelta): boolean
  • Calculate if value is cheaper than the delta. The result is typically determined by the length of the serialised form, but may also consider the complexity of the delta.


    an error if the value or delta is invalid


    • value: SourceType

      the value to compare

    • delta: BinaryDelta

      the delta to compare

    Returns boolean

    true if the value is considered cheaper than the delta


  • name(): string
  • The name of this delta type

    Returns string

    the name


  • Constant returned by DeltaType.diff to indicate that both values are equivalent.

    Returns BinaryDelta

    unique object representing no change in value


  • readDelta(buffer: Buffer, offset?: undefined | number, length?: undefined | number): BinaryDelta
  • Parse a delta from binary.

    When running the Diffusion Client in a browser context, access to the Buffer api is made available through diffusion.buffer.


    an error if the binary is invalid


    • buffer: Buffer
    • Optional offset: undefined | number

      the offset from which to start reading from the buffer

    • Optional length: undefined | number

      the length of data to read from the buffer

    Returns BinaryDelta

    the delta


  • Serialise a delta to binary.


    an error if the delta cannot be serialised


    Returns Buffer

    the serialised form of the delta