Optionaldata: number | Buffer<ArrayBufferLike>the current position inside the buffer
Staticmaxhard ceiling on the number of elements a single array length prefix may declare.
The length is read straight off the wire as a UInt32, so without a ceiling a tiny message can declare billions of elements and drive the decoder to loop and allocate to match. Mirrors the cap the Variant value path has always enforced (Variant.maxArrayLength); the generic path that decodes every structured-type array field never had one. Adjustable so a deployment that legitimately exchanges larger arrays can raise it.
StaticmaxStaticmaxhow deep decoders may nest recursive types (ExtensionObject, Variant, DiagnosticInfo) while reading from this stream.
These types can nest without ever making the message larger than the negotiated limit, so a message well under the size cap can still drive the decoder deep enough to exhaust the call stack. OPC UA Part 6 §5.1.8/§5.1.9 anticipates this and requires a decoder to support at least 100 levels and to report an error beyond what it supports; §5.2.2.12 says the same for the self-recursive DiagnosticInfo. One shared budget across the three types bounds what actually matters - total stack depth - regardless of how a message mixes them.
Set to 128, comfortably above the 100 the spec requires us to support (so a message that legitimately nests 100 deep still decodes whichever way you count the outermost level) and far below the depth at which the call stack would actually overflow.
Staticmaxvalidate a wire array length before a decoder loops over it.
Two independent bounds:
the element count just read from the stream
signal that the decoder is about to descend one level into a recursive type. Throws BinaryStreamMaxNestingLevelExceededError once the depth passes BinaryStream.maxNestingLevel, before the recursive call is made and before any further stack frame is consumed. Every successful call must be paired with exitNestingLevel, which is why callers use try/finally.
mark that the decoder has finished one level of a recursive type. Pair with a preceding successful enterNestingLevel via try/finally so the depth is restored even when the nested decode throws.
write a 32 bit unsigned integer at an absolute position previously returned by reserveUInt32, without moving the cursor.
read a single signed byte (8 bits) from the stream.
the value read
read a byte stream to the stream. The method reads the length of the byte array from the stream as a 32 bits integer before reading the byte stream.
read a single 64-bit floating point number from the stream.
read a single 32-bit floating point number from the stream.
read a single signed 16-bit integer from the stream.
read a single signed 32-bit integer from the stream.
read a single unsigned 16-bit integer from the stream.
read a single unsigned 32-bit integer from the stream.
read a single unsigned byte (8 bits) from the stream.
reserve room for a 32 bit unsigned integer whose value is not known yet, and return the position at which it can later be written with patchUInt32.
This lets a length-prefixed body be written in a single pass: reserve the slot, encode the body, then patch in the byte count. The alternative - computing the size up front - means encoding the body twice, which compounds for nested structures.
set the cursor to the begining of the stream
a buffer or byte array write
Optionaloffset: number
the offset position (default =0)
Optionallength: number
the number of byte to write
write a byte stream to the stream. The method writes the length of the byte array into the stream as a 32 bits integer before the byte stream.
the buffer to write.
write a single 64 bit floating number to the stream.
the value to write
write a single 32 bit floating number to the stream.
the value to write
write a single 16 bit signed integer to the stream.
the value to write
write a single signed byte (8 bits) to the stream. value must be in the range of [-127,128]
the value to write
write a single 32 bit signed integer to the stream.
the value to write
write a single 16 bit unsigned integer to the stream.
the value to write
write a single 32 bit unsigned integer to the stream.
the value to write
write a single unsigned byte (8 bits) to the stream.
the value to write
Staticcreatecreate a stream that reallocates its buffer as needed, up to maxLength bytes.
Encoding a message whose size is not known up front otherwise means encoding it twice: once into a BinaryStreamSizeCalculator to learn the length, then again for real. Both passes walk the whole object graph, and measuring shows the sizing pass costs about as much as the real one.
starting capacity; a good guess avoids reallocation entirely
hard ceiling - exceeding it throws BinaryStreamMaxSizeExceededError
a BinaryStream can be use to perform sequential read or write inside a buffer. The BinaryStream maintains a cursor up to date as the caller operates on the stream using the various read/write methods. It uses the Little Endian It uses the Little Endian convention.
data can either be:
example: