Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BinaryDeltaTypeImpl<V, S, C>

Implementation of DeltaType

inheritdoc

Type parameters

  • V

  • S

  • C

Hierarchy

  • BinaryDeltaTypeImpl

Implements

Index

Constructors

constructor

  • new BinaryDeltaTypeImpl(implementation: {}, vToC: (value: S) => C, cToV: (value: C) => V | null): BinaryDeltaTypeImpl
  • Create a new instance of BinaryDeltaTypeImpl

    Parameters

    • implementation: {}

      constructor function to create new instances of the type T

    • vToC: (value: S) => C

      conversion function to calculate a CBOR buffer from the value

        • (value: S): C
        • Parameters

          • value: S

          Returns C

    • cToV: (value: C) => V | null

      conversion function to calculate the value from a CBOR buffer

        • (value: C): V | null
        • Parameters

          • value: C

          Returns V | null

    Returns BinaryDeltaTypeImpl

Properties

Private Readonly binaryDiff

binaryDiff: MyersBinaryDiff = new MyersBinaryDiff()

The Myers Binary Difference algorithm to calculate the differences

Private Readonly cToV

cToV: (value: C | Uint8Array) => V | null

Conversion function to calculate the value from a CBOR buffer

Type declaration

    • (value: C | Uint8Array): V | null
    • Parameters

      • value: C | Uint8Array

      Returns V | null

Private Readonly implementation

implementation: {}

Constructor function to create new instances of the type T

Type declaration

Private Readonly vToC

vToC: (value: S) => C

Conversion function to calculate a CBOR buffer from the value

Type declaration

    • (value: S): C
    • Parameters

      • value: S

      Returns C

Methods

apply

  • Apply a delta to a value.

    throws

    an InvalidDataError if the value or delta is invalid

    Parameters

    Returns V | null

    the new value generated applying the delta to the old value

applyImpl

  • applyImpl(oldValueObj: S, delta: BinaryDelta, oldBuffer?: C): { cbor: C; value: V | null }
  • Apply a delta to a buffer or a value, returning the new value together with the modified CBOR buffer

    throws

    an InvalidDataError if the value or delta is invalid

    Parameters

    • oldValueObj: S
    • delta: BinaryDelta

      the delta to apply

    • Optional oldBuffer: C

      the old CBOR buffer

    Returns { cbor: C; value: V | null }

    the new value and CBOR buffer generated applying the delta to the old value

    • cbor: C
    • value: V | null

diff

  • 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.

    Parameters

    • oldValueObj: S

      the old value

    • newValueObj: S

      the new value

    Returns BinaryDeltaImpl

    the delta between values

isValueCheaper

  • isValueCheaper(value: S, 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.

    throws

    an error if the value or delta is invalid

    Parameters

    • value: S

      the value to compare

    • delta: BinaryDelta

      the delta to compare

    Returns boolean

    true if the value is considered cheaper than the delta

name

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

    Returns string

    the name

noChange

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

    Returns BinaryDeltaImpl

    unique object representing no change in value

readDelta

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

    throws

    an error if the binary is invalid

    Parameters

    • buffer: Uint8Array
    • 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 BinaryDeltaImpl

    the delta

writeDelta

  • Serialise a delta to binary.

    throws

    an error if the delta cannot be serialised

    deprecated

    since version 6.11. Buffer has been replaced by Uint8Array. Use writeDeltaToArray instead. This will be removed in a future release.

    Parameters

    Returns Buffer

    the serialised form of the delta

writeDeltaToArray

  • Serialise a delta to binary.

    throws

    an error if the delta cannot be serialised

    Parameters

    Returns Uint8Array

    the serialised form of the delta

Copyright © 2025 DiffusionData Ltd. All Rights Reserved.