A coder for a key-value pair.

Type Parameters

  • K

  • V

Hierarchy

  • KVCoder

Implements

Constructors

Properties

Methods

Constructors

Properties

keyCoder: Coder<K>
type: string = "kvcoder"
valueCoder: Coder<V>
URN: string = "beam:coder:kv:v1"

Methods

  • Encode the input element (a key-value pair) into a byte output stream. They key and value are encoded one after the other (first key, then value). The key is encoded with Context.needsDelimiters, while the value is encoded with the input context of the KVCoder.

    For example:

    let w1 = new Writer()
    let data = {'key': 'k1', 'value': 'v1'}
    new KVCoder(new StrUtf8Coder(), new StrUtf8Coder()).encode(data, w1, Context.needsDelimiters)
    console.log(w1.finish()) // ==> prints Uint8Array(6) [ 2, 107, 49, 2, 118, 49 ]
    // Note that bytes with value 2 represent length prefixes, and other bytes represent the encoded strings.

    Parameters

    • element: KV<K, V>

      the element to be encoded into an output byte stream

    • writer: Writer

      the writer that interfaces with the output byte stream

    • context: Context

      whether to encode the data with delimiters (Context.needsDelimiters), or without (Context.wholeStream).

    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