Skip to main content

GetOctetCountByFirstOctet

Short summary

This function returns octets amount by first octet

  • Return type: BYTE

Parameters

NameTypeCommentKind
firstByteBYTEfirst byte of an octet sequenceinput

Code

Declaration

FUNCTION INTERNAL GetOctetCountByFirstOctet : BYTE(0..4)
VAR_INPUT
(* first byte of an octet sequence *)
firstByte : BYTE;
END_VAR

Implementation

CASE firstByte OF
16#00..16#7F: // ASCII, 1 byte
GetOctetCountByFirstOctet := 1;
16#C2..16#DF: // 2-byte utf-8
GetOctetCountByFirstOctet := 2;
16#E0..16#EF: // 3-byte utf-8
GetOctetCountByFirstOctet := 3;
16#F0..16#F4: // 4-byte utf-8
GetOctetCountByFirstOctet := 4;
ELSE // not first byte or invalid utf-8 byte found
GetOctetCountByFirstOctet := 0;
END_CASE