GorillaStream.Compression.Decoder.DeltaDecoding (gorilla_stream v3.0.3)

Copy Markdown View Source

Delta-of-delta decoding for timestamps in the Gorilla compression algorithm.

This module reverses the delta-of-delta encoding process to reconstruct the original timestamps from the compressed bitstream.

The decoding process:

  1. Read the first timestamp (64 bits)
  2. Read the first delta (variable length)
  3. For subsequent values, read delta-of-delta values and reconstruct timestamps:
    • '0' bit: delta-of-delta is 0 (same interval as previous)
    • '10' + 7 bits: delta-of-delta in range [-63, 64]
    • '110' + 9 bits: delta-of-delta in range [-255, 256]
    • '1110' + 12 bits: delta-of-delta in range [-2047, 2048]
    • '1111' + 32 bits: delta-of-delta as 32-bit signed integer

Summary

Functions

Decodes timestamp bitstream back into a list of timestamps.

Gets information about a timestamp bitstream without full decoding.

Validates that a timestamp bitstream can be properly decoded.

Functions

decode(timestamp_bits, metadata)

Decodes timestamp bitstream back into a list of timestamps.

Parameters

  • timestamp_bits: Bitstream containing encoded timestamps
  • metadata: Metadata containing count and first timestamp info

Returns

  • {:ok, timestamps}: List of decoded timestamps
  • {:error, reason}: If decoding fails

get_bitstream_info(timestamp_bits, metadata)

Gets information about a timestamp bitstream without full decoding.

Parameters

  • timestamp_bits: Bitstream to analyze
  • metadata: Metadata with count information

Returns

  • {:ok, info} with basic information, or {:error, reason}

validate_bitstream(timestamp_bits, expected_count)

Validates that a timestamp bitstream can be properly decoded.

Parameters

  • timestamp_bits: Bitstream to validate
  • expected_count: Expected number of timestamps

Returns

  • :ok if valid, {:error, reason} if invalid