Skip to main content

blob.writen(value, dataType)

Writes a value into the blob


Device + Agent


Name Type Description
value Integer or float The value to be written to the blob
dataType Constant A single-byte constant indicating the value’s data type




This method writes a single value of a specified type into the target blob at the byte indicated by the target’s read/write pointer. The written value’s type is specified by a single-byte integer. For convenience, you can use Squirrel’s character representation rather than numeric values, for example:

aBlob.writen(myFloat, 'f');

this is equivalent to:

aBlob.writen(myFloat, 102);

but makes the value type much more clear. When using characters to represent integers this way, you must use single quotes as delimiters.

The method’s first argument — the number to be written into the blob — must be an integer or float. Other data types will not be cast into these types by the method: zeros will be written instead. The number of zeros will match the number of bytes specified by the dataType constant.

Of Squirrel’s own data types only float and integer (both are 32-bit values) can be stored in the blob (using the ‘i’ and ‘f’ markers), but writen() additionally supports a number of the most common 8-bit and 16-bit standard variable types. The following table lists the data types supported and their data type strings:

Constant Type
'c' / 99 8-bit signed integer
'b' / 98 8-bit unsigned integer
's' / 115 16-bit signed integer
'w' / 119 16-bit unsigned integer
'i' / 105 32-bit signed integer
'f' / 102 32-bit float
'd' / 100 64-bit float

Note a written 64-bit value — an IEEE 754 double-precision float — will only have the precision of the 32-bit standard Squirrel float from which it was derived.

All imps are little endian, so multi-byte values will written into a blob or read from it in order of least byte significance. For example, if a 16-bit unsigned integer is written into a blob (the 'w' option, above), the least-significant byte is written first (at blob pointer location n) and followed by the most-significant byte (at blob pointer location n+1).

Example Code