Static
URNEncode the input iterable into a byte output stream. Elements can be encoded in two different ways:
-1
is encoded in the first position (instead of the length), andThen, 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)
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.
a context that holds relevant pipeline attributes such as other coders already in the pipeline.
Generated using TypeDoc
A coder for a 'list' or a series of elements of the same type.