Coder for byte-array data types.

Hierarchy

  • BytesCoder

Implements

Constructors

Properties

Methods

Constructors

Properties

type: string = "bytescoder"
INSTANCE: BytesCoder = ...
URN: string = "beam:coder:bytes:v1"

Methods

  • Decode the input byte stream into a byte array. If context is needsDelimiters, the first bytes will be interpreted as a var-int32 encoding the length of the data.

    If the context is wholeStream, the whole input stream is decoded as-is.

    Returns

    Parameters

    • reader: Reader

      a reader to access the input byte stream

    • context: Context

      whether the data is encoded with delimiters (Context.needsDelimiters), or without (Context.wholeStream).

    Returns Uint8Array

  • Encode the input element (a byte-string) into the output byte stream from writer. If context is needsDelimiters, the byte string is encoded prefixed with a varint representing its length.

    If the context is wholeStream, the byte string is encoded as-is.

    For example:

    const w1 = new Writer()
    const data = new TextEncoder().encode("bytes")
    new BytesCoder().encode(data, w1, Context.needsDelimiters)
    console.log(w1.finish()) // ==> prints Uint8Array(6) [ 5, 98, 121, 116, 101, 115 ], where 5 is the length prefix.
    const w2 = new Writer()
    new BytesCoder().encode("bytes", w1, Context.wholeStream)
    console.log(w2.finish()) // ==> prints Uint8Array(5) [ 98, 121, 116, 101, 115 ], without the length prefix

    Parameters

    • value: Uint8Array

      a byte array to encode. This represents an element to be encoded.

    • writer: Writer

      a writer to access the stream of bytes with encoded data

    • 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