The Binary Data plugin allows raw access to an allocated section of memory (often referred to as a buffer). For example it could allocate 16 bytes of memory, and read and write anywhere in that buffer as individual bytes, 32-bit integers, floating point numbers, text, and so on.
A comprehensive description of how binary data/computer memory storage works is out of the scope of this manual. However there is lots of information on the Internet that covers it, and most computer science or computing courses will also cover it. The Binary Data object is also useful even if you do not access its contents: it integrates with other plugins like AJAX and Local Storage, allowing binary data such as images to be stored or transferred in useful ways.
Binary Data properties
- The default endian to use when reading and writing binary values.
Binary Data conditions
- Compare length
- Compare the length of the data buffer, in bytes.
- Compare value
- Read a value of a given data type at an offset in the data buffer, and then compare that value to another number.
Binary Data actions
- Copy data from another (or the same) Binary Data object. This does not change the size of the buffer. The Start and Length specify the range of data in the source Binary Data object to copy, defaulting to copying the entire buffer. The Target is a byte offset to write the copy at.
- Fill a range of the buffer with copies of the same value. For example this can be used to fill an entire range of the buffer with zero bytes. The Offset and Length can be used to specify a byte range to fill, but they default to covering the entire buffer.
- Set endian
- Change the endian used when reading and writing values.
- Set from base64
- Set the contents of the Binary Data object from the contents of a base64-encoded string. This decodes the base64 string to binary and changes the buffer size to fit it.
- Set from Binary Data
- Set the contents of the Binary Data object to a copy of another Binary Data object. This changes the size of the buffer to be the same as the other object.
- Set from text
- Set the contents of the Binary Data object to a text string encoded as UTF-8. This changes the size of the buffer to fit.
- Set length
- Set the size of the memory buffer in bytes. Note Binary Data initially has a zero sized buffer, so this must be used first before any reads or writes can complete. The existing data is preserved when changing the size; if the new size is smaller, data is truncated, and if the new size is larger, zero bytes are added.
- Set value
- Write a value of a given data type at a byte offset in the memory buffer. The entire value must be within the bounds of the buffer, otherwise the write is ignored. For example a 4-byte Uint32 value cannot be written anywhere in a 3-byte buffer, because all four bytes must be inside the buffer.
Binary Data expressions
- Return the current length of the buffer in bytes.
- Return the entire contents of the data buffer encoded as a base64 string. This is useful when binary data must be stored in a text-based format like JSON.
- Return a URL that can be used locally to load the binary data. For example if the Binary Data represents an image, this URL can be passed the Sprite object's Load image from URL action to load the image from the Binary Data object.
- Read a value of the corresponding type from the buffer at a byte offset. The entire value must be within the bounds of the buffer, otherwise it returns 0. For example a 4-byte Uint32 value cannot be read from a 3-byte buffer, because all four bytes must be inside the buffer.
- GetText(byteOffset, length)
- Decode text in the UTF-8 encoding in a range of the buffer in bytes, and return the string. If the UTF-8 encoding is invalid, or any part of the range is outside the buffer, an empty string is returned.
Construct 3 Manual
You are here:
Search this manual:
This manual entry was last updated on 18 Mar, 2019 at 16:52