A coder for a 'list' or a series of elements of the same type.

Type Parameters

  • T

Hierarchy

  • IterableCoder

Implements

Constructors

Properties

Methods

Constructors

Properties

elementCoder: Coder<T>
type: string = "iterablecoder"
URN: string = "beam:coder:iterable:v1"

Methods

  • Decode an element from an incoming stream of bytes.

    Parameters

    • reader: Reader

      a reader that interfaces the coder with the input byte stream

    • context: Context

      the context within which the element should be encoded

    Returns Iterable<T>

  • Encode the input iterable into a byte output stream. Elements can be encoded in two different ways:

    • If the length of the input iterable is known a-priori, then the length is encoded with a 32-bit fixed-length integer.
    • If the length of the input iterable is not known a-priori, then a 32-bit integer with a value of -1 is encoded in the first position (instead of the length), and

    Then, each element is encoded individually in Context.needsDelimiters.

    For example:

    let w1 = new Writer()
    let data = ["a", "b", "c"]
    new IterableCoder(new StrUtf8Coder()).encode(data, w1, Context.needsDelimiters)
    console.log(w1.finish()) // ==> prints
    // Uint8Array(10) [
    // 0, 0, 0, 3, 1,
    // 97, 1, 98, 1, 99
    // ]
    // The first 4 bytes represent the 32-bit-encoded length of the iterable (0,0,0,3),
    // and the next 6 bytes represent each of the elements in the iterable with their length
    // encoded as a prefixed var int (1), and their values afterwards (97, 98, 99).
    let w2 = new Writer()
    let data = ["a", "b", "c"]
    let encodeIterable = function* gen() {yield *data}
    new IterableCoder(new StrUtf8Coder()).encode(encodeIterable, w2, Context.needsDelimiters)
    console.log(w2.finish()) // ==> prints
    // Uint8Array(11) [
    // 255, 255, 255, 255,
    // 3, 1, 97, 1, 98,
    // 1, 99, 0,
    // ]
    // The first 4 bytes represent the 32-bit-encoded -1 to represent unknown length of the
    // iterable, the next byte represents the length of the upcoming batch (3),
    // and the next 6 bytes represent each of the elements in the iterable with their length
    // encoded as a prefixed var int (1), and their values afterwards (97, 98, 99).
    // Finally, the last byte tags the end of the iterable as a zero (0)

    Parameters

    • element: Iterable<T>
    • writer: Writer
    • context: Context

    Returns void

  • Convert this coder into its protocol buffer representation for the Runner API. A coder in protobuf format can be shared with other components such as Beam runners, SDK workers; and reconstructed into its runtime representation if necessary.

    Parameters

    • pipelineContext: ProtoContext

      a context that holds relevant pipeline attributes such as other coders already in the pipeline.

    Returns Coder

Generated using TypeDoc