Skip to Content
CloudBlueprint EditorBytes to Map Parser

Bytes to Map Parser

Overview

This prefab parses a raw BYTES input into a structured MAP. It is specifically designed to work with binary data from systems that use word-based addressing, which is common in industrial datasheets for devices like PLCs, sensors, and Modbus-compatible hardware.

It allows you to copy memory addresses directly from a datasheet, and the prefab will handle the conversion to the correct byte position automatically.

How it Works

The core logic revolves around two key constants: word_size_bytes and the schema. For each field defined in the schema, the parser calculates the starting byte position using the formula:

byte_address = word_address * word_size_bytes

This allows you to think in terms of “words” or “registers” (as defined in your device’s documentation) without doing manual byte math.

Configuration

Constants

ConstantTypeDescription
word_size_bytesINTRequired. The size of a single ‘word’ in bytes. This is used as a multiplier for the word_address. Common values are 1 (for 8-bit registers), 2 (for 16-bit registers), or 4 (for 32-bit registers).
schemaJSONRequired. A JSON array of objects, where each object defines a field to be parsed from the byte array. See the Schema Fields section below for details on how to structure each object.

Schema Fields

Each object in the schema array defines one key-value pair for the output map.

KeyTypeRequired?Description
keyStringYesThe key name for this value in the output MAP.
word_addressIntegerYesThe starting address of the data in “words”. This is the value you would typically copy from a technical datasheet. Can be a decimal (122) or a hex string ("0x7A").
typeStringYesThe data type to parse. See the Data Types table below for all possible values.
endianStringYesThe endianness (“byte order”) for multi-byte data types. Can be le (Little-Endian) or be (Big-Endian).
lengthIntegerNoRequired only for STRING and BYTES types. Specifies the exact number of bytes to read for that field.
scaleFloatNoA multiplier to apply to a numeric value after parsing. The formula is final_value = (raw_value * scale) + offset. Defaults to 1.0.
offsetFloatNoAn additive value to apply to a numeric value after parsing and scaling. The formula is final_value = (raw_value * scale) + offset. Defaults to 0.0.

Data Types (for the type field)

ValueDescriptionSize (Bytes)
I88-bit Signed Integer1
U88-bit Unsigned Integer1
I1616-bit Signed Integer2
U1616-bit Unsigned Integer2
I3232-bit Signed Integer4
U3232-bit Unsigned Integer4
I6464-bit Signed Integer8
U6464-bit Unsigned Integer8
F3232-bit Float4
F6464-bit Float8
BOOLBoolean (true if byte is not 0)1
STRINGUTF-8 Stringlength
BYTESRaw Byte Arraylength

Ports

  • Inputs: input:BYTES - Receives the raw byte array to be parsed.
  • Outputs: output:MAP - Sends a map containing the parsed key-value data.

Example

Imagine a sensor sends a 12-byte data packet. The datasheet specifies that the memory is addressed in 16-bit words (word_size_bytes: 2).

Sample Input (BYTES): [0x01, 0x9A, 0x00, 0x01, 0x43, 0x48, 0x00, 0x00, 0x61, 0x62, 0x63, 0x00]

Datasheet Information:

  • Word Address 0: Device Status (U16)
  • Word Address 2: Temperature (F32), value must be multiplied by 0.1 and then have 5 subtracted.
  • Word Address 4: Device ID (String), 3 bytes long.

Configuration

word_size_bytes

2

schema

[ { "key": "device_status", "word_address": 0, "type": "U16", "endian": "be" }, { "key": "temperature", "word_address": 2, "type": "F32", "endian": "be", "scale": 0.1, "offset": -5.0 }, { "key": "device_id", "word_address": 4, "type": "STRING", "endian": "be", "length": 3 } ]

Resulting Output (MAP)

Based on the input bytes and the schema, the output map will be:

{ "device_status": 410, "temperature": -2.9999999821186066, "device_id": "abc" }

Calculation Walkthrough:

  • device_status: Starts at word_address 0. Byte position = 0 * 2 = 0. Reads 2 bytes [0x01, 0x9A] as a Big-Endian U16, which is 410.
  • temperature: Starts at word_address 2. Byte position = 2 * 2 = 4. Reads 4 bytes [0x43, 0x48, 0x00, 0x00] as a Big-Endian F32, which is 200.0. The final value is (200.0 * 0.1) - 5.0 = 15.0.
  • device_id: Starts at word_address 4. Byte position = 4 * 2 = 8. Reads length of 3 bytes from that position: [0x61, 0x62, 0x63], which is the UTF-8 string "abc".
Last updated on