json-stream-lite - v1.0.17
    Preparing search index...

    Class JsonEntity<T>Abstract

    Abstract base class for all JSON entities. Provides common functionality for parsing, reading, and consuming JSON values.

    Type Parameters

    • T

      The type of value this entity represents

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new JSON entity.

      Type Parameters

      • T

        The type of value this entity represents

      Parameters

      • Optionalbuffer: ByteStream | ByteBuffer

        Optional ByteBuffer or ByteStream to read from

      Returns JsonEntity<T>

    Properties

    buffer: ByteBuffer
    consumed: boolean = false

    Accessors

    • get bufferLength(): number

      Gets the current length of the buffer.

      Returns number

      The number of bytes in the buffer

    • get entityType(): string

      Gets the type name of this entity.

      Returns string

      The constructor name of this entity

    • set maxBufferSize(size: number): void

      Sets the maximum buffer size before compaction occurs.

      Parameters

      • size: number

        The maximum buffer size in bytes

      Returns void

    Methods

    • Consumes the entity by reading it if not already consumed.

      Returns void

    • Asynchronously consumes the entity by reading it if not already consumed.

      Returns Promise<void>

    • Feeds input data into the buffer.

      Parameters

      • ...input: JsonStreamInput[]

        One or more strings, numbers, arrays of numbers, or Uint8Arrays to add to the buffer

      Returns void

    • Abstract method that subclasses must implement to parse their specific type.

      Returns T

      The parsed value of type T

    • Reads and parses the entity, consuming it in the process.

      Returns T

      The parsed value

      Error if the entity has already been consumed

    • Asynchronously reads and parses the entity from a stream.

      Returns Promise<T>

      A promise that resolves to the parsed value

      Error if the entity has already been consumed

    • Skips whitespace characters in the buffer.

      Returns void

    • Attempts to parse by executing a callback, reverting buffer state on failure.

      Type Parameters

      Parameters

      • cb: (entity: this) => T

        The callback function to execute

      Returns T | undefined

      The result of the callback, or undefined if parsing needs more data

      Error if the entity has already been consumed