GetOctetCountByFirstOctet
Short summary
This function returns octets amount by first octet
- Return type:
BYTE
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| firstByte | BYTE | first byte of an octet sequence | input |
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