Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractAccumulator

An abstract accumulator that accumulates JSON values from tokens and passes the result to a SpanParserConsumer.

Hierarchy

Index

Constructors

constructor

  • Create an AbstractAccumulator

    Parameters

    • tokeniser: Tokeniser

      the CBOR tokeniser

    • base: JSONPointer

      the base JSON pointer to accumulate from

    • start: number

      the offset of the start token

    • next: number

      the index of the next token

    • expectBreak: boolean

    Returns AbstractAccumulator

Properties

Private accumulatedTokens

accumulatedTokens: number = 0

The number of accumulated tokens

Private Readonly base

The base JSON pointer to accumulate from

Private expectBreak

expectBreak: boolean

If true, we need to account for a break terminator.

nextOffset

nextOffset: number

The buffer position of the next token

Readonly startOffset

startOffset: number

The buffer position of the start token

Private Readonly tokenRange

tokenRange: number[][] = []

The token ranges of the accumulated tokens

Protected Readonly tokeniser

tokeniser: Tokeniser

The CBOR tokeniser

Private totalTokens

totalTokens: number = 0

The total number of tokens encountered

Methods

accumulated

  • accumulated(): number
  • Get the number of accumulated tokens

    Returns number

    the number of accumulated tokens

add

  • add(next: number): boolean
  • Add tokens to the accumulator

    Parameters

    • next: number

      the next offset up to which to add tokens

    Returns boolean

    false

Abstract currentPointer

  • Get the current JSON pointer

    Parameters

    • base: JSONPointer

      the total number of tokens encountered so far

    • total: number

    Returns JSONPointer

newArray

  • Create a new ArrayAccumulator from the current token position

    Parameters

    • start: number

      the offset of the start token

    • next: number

      the index of the next token

    Returns ArrayAccumulator

    a new array accumulator

newObject

  • Create a new ObjectAccumulator from the current token position

    Parameters

    • start: number

      the offset of the start token

    • next: number

      the index of the next token

    Returns ObjectAccumulator

    a new object accumulator

notEmptyAndSplitBy

  • notEmptyAndSplitBy(offset: number): boolean
  • Check if the offset splits the accumulator content

    Parameters

    • offset: number

      the offset to check

    Returns boolean

    true if the accumulator has encountered any tokens and the offset is greater than the starting offset

setNextStart

  • setNextStart(offset: number): void
  • Increase the next offset without adding tokens

    Parameters

    • offset: number

    Returns void

skip

  • skip(): void
  • Skip one token

    Returns void

splitStructureEnd

  • Signal the end of a split structure

    Parameters

    Returns void

Abstract take

  • Take a single token

    Parameters

    • consumer: SpanParserConsumer

      the consumer that will receive the tokens

    • base: JSONPointer

      the base JSON pointer to accumulate from

    • firstAccumulatedIndex: number

      the index of the first accumulated token

    • index: number

      the index of the current token

    • start: number

      the buffer offset of the first token

    • length: number

      the number of bytes in the buffer

    Returns void

takeAll

  • Take all tokens. Passes all accumulated tokens to the abstract take method.

    Parameters

    Returns void

toString

  • toString(): string
  • Convert the accumulator to a string

    Returns string

    a string representation of the accumulator

total

  • total(): number
  • Get the total number of tokens encountered

    Returns number

    the total number of tokens encountered

Copyright © 2025 DiffusionData Ltd. All Rights Reserved.