By default, the serialized result in the buffer is little-endian (i.e. the least significant byte of the value is
stored in the smallest address). In the example below, t[0] = 16#35, t[1] = 16#12. As return value of the
Serialize function, nextValueOffset = start offset + value byte length = 2 + 2 = 4.
USING System.Serialization;
FUNCTION SerDe_Demo
VAR_TEMP
data : ARRAY[0..5] OF BYTE;
nextValueOffset: INT;
END_VAR
// data = [0x0, 0x0, 0x35, 0x12, 0x0, 0x0]
// nextValueOffset = 4
nextValueOffset := Serialize(2, UINT#16#1235, data);
END_FUNCTION
The endianness can be specified/changed by passing an additional argument to the Serialize function or by using the
SerializeLitte or SerializeBig function, respectively:
USING System.Serialization;
FUNCTION SerDe_Demo
VAR_TEMP
data : ARRAY[0..5] OF BYTE;
nextValueOffset : UDINT;
END_VAR
// Serialization using big endianness
// data = [0x0, 0x0, 0x12, 0x35, 0x0, 0x0]
// nextValueOffset = 4
nextValueOffset := Serialize(UDINT#2, UINT#16#1235, data, Endianness#Big);
// Alternative for a serialization using big endianness
// data = [0x0, 0x0, 0x12, 0x35, 0x0, 0x0]
// nextValueOffset = 4
nextValueOffset := SerializeBig(UDINT#2, UINT#16#1235, data);
END_FUNCTION