Byte Length
Converts the input to bytes (string = UTF-8, int = minimal length, bool = 1 byte) and returns the byte count
Overview
Computes the byte length of the input value and outputs it as an integer (Int). If the input is already Bytes, it returns data.byteLength directly; otherwise it converts the value using toBytesAuto first (String โ UTF-8 byte count, Int ≥ 0 โ minimal-length byte count where 0 is 1 byte, Bool โ 1 byte).
When to Use
- Measuring the byte length of a plaintext, ciphertext, or header to feed into Int to Bytes (for length-prefixed framing) or Byte Slicer.
- Checking key or signature byte sizes during protocol debugging.
Parameter Configuration
Byte Length requires no configuration parameters.
Port I/O Specification
See Ports & Connections for general wiring rules, data type colors, and dynamic port creation.
Input Ports
Port Nature: Fixed Input Ports (1 total).
| Port Name | Port ID | Data Type | Required | Visibility Condition | Description |
|---|---|---|---|---|---|
Value |
in |
Any |
Required | Always visible |
Output Ports
Port Nature: Fixed Output Ports (1 total).
| Port Name | Port ID | Data Type | Visibility Condition | Description |
|---|---|---|---|---|
Length |
length |
Int |
Always visible | Measured byte count as an integer (Int). |
Error Cases
When any of the following conditions occurs at runtime, this node transitions to an ERROR state and downstream nodes connected to its outputs do not execute.
| Error Code | Default Engine Message | Trigger Condition |
|---|---|---|
BYTES_INVALID_ARGUMENT |
Invalid argument value | Raised when an argument (such as bit shift count, byte length, or negative integer) is invalid or negative. |
BYTES_INT_OVERFLOW |
The integer cannot be represented with the given length and sign | Raised when the integer value cannot fit within the specified fixed or port byte length. |
Examples
Prepending a 2-Byte Length Header to a Payload
Measure a payload's byte count, encode it as 2 big-endian bytes, and concatenate.
- Connect your payload bytes to Byte Length.
- Connect the
Lengthoutput to Int to Bytes (Fixed length = 2,Big Endian), and concatenate the 2-byte header with the payload in Byte Concatenator.