By default, the buffer is interpreted as little-endian during deserialization (i.e. the smallest address stores the
least significant byte of the value). In the example below, value = UINT#16#1235. As return value of the
Deserialize function, nextValueOffset = start offset + value byte length = 0 + 2 = 2.
USING System.Serialization;
FUNCTION SerDe_Demo
VAR_TEMP
data : ARRAY[0..1] OF BYTE := [BYTE#16#35, BYTE#16#12];
value : UINT;
nextValueOffset : UDINT;
END_VAR
// value = 4661 (0x1235)
// nextValueOffset = 2
nextValueOffset := Deserialize(UDINT#0, data, value);
END_FUNCTION
The endianness can be specified/changed by passing an additional argument to the Deserialize function or by using the
DeserializeLitte or DeserializeBig function, respectively:
USING System.Serialization;
FUNCTION SerDe_Demo
VAR_TEMP
data : ARRAY[0..1] OF BYTE := [BYTE#16#35, BYTE#16#12];
value : UINT;
nextValueOffset : INT;
END_VAR
// Deserialization using big endianness
// value = 13586 (0x3512)
// nextValueOffset = 2
nextValueOffset := Deserialize(0, data, value, Endianness#Big);
// Alternative for a deserialization using big endianness
// value = 13586 (0x3512)
// nextValueOffset = 2
nextValueOffset := DeserializeBig(0, data, value);
END_FUNCTION