ExCEP. Codec. Frame
(ex_cep v0.1.1)
Copy Markdown
APDU framing codec for CSG CEP TS2.2 Section 4.6–4.8.
Frame Layout
+-----------------------------------+------------------+------------------------+
| Fixed 32-byte Header | ASDU (0..65535B) | Optional SM2 Sig (64B) |
+-----------------------------------+------------------+------------------------+32-Byte Header (Table 1)
- Bytes 0..3: Sync bytes
<<0xEB, 0x90, 0xEB, 0x90>> - Bytes 4..5: ASDU wire length (
uint16, big-endian, max 65535) - Byte 6: Control byte (Figure 5):
bit0(0x01): Signature flag (1 = 64-byte SM2 signature appended)bit1(0x02): Auth flag (1 = binary authentication ASDU)bit2(0x04): Compression flag (1 = deflate/zlib compressed ASDU)bit3..bit7: Reserved (0)
- Byte 7: Reserved (
0x00) - Bytes 8..31:
GatewayId(24 bytes, 1..23 byte UTF-8 string, NUL-terminated & NUL-padded)
Summary
Functions
Decodes a single complete APDU frame binary.
Decodes the next complete frame from buffer.
Extracts all complete APDU frames from a TCP byte stream buffer.
Encodes a %Frame{} into wire binary.
Reconstructs the exact raw wire bytes of a decoded %Frame{} (header + wire ASDU + optional 64B signature).
Returns the 4-byte sync header <<0xEB, 0x90, 0xEB, 0x90>>.
Types
Functions
Decodes a single complete APDU frame binary.
Options
:signer-{module, opts}for SM2 signature verification whensigned?: true:verify_signature- boolean (defaulttruewhen:signeris provided,falseotherwise)
@spec decode_ctrl(non_neg_integer()) :: {boolean(), boolean(), boolean()}
@spec decode_next(binary(), keyword()) :: {:ok, t(), binary()} | {:more, binary()} | {:error, term()}
Decodes the next complete frame from buffer.
Returns {:ok, frame, rest}, {:more, remaining_buffer}, or {:error, reason}.
Extracts all complete APDU frames from a TCP byte stream buffer.
Returns {:ok, frames, rest_buffer} or {:error, reason, rest_buffer}.
Automatically skips leading garbage bytes until the 0xEB 0x90 0xEB 0x90 sync header.
Encodes a %Frame{} into wire binary.
Options
:signer-{module, opts}implementingExCEP.Crypto.Signer(required whensigned?: trueandframe.signature == nil):deflate_mode-:zlib(default, RFC 1950) or:raw(RFC 1951 raw deflate):cipher- optional{module, opts}implementingExCEP.Transport.Cipher(e.g. SM4)
@spec encode_ctrl(boolean(), boolean(), boolean()) :: non_neg_integer()
Reconstructs the exact raw wire bytes of a decoded %Frame{} (header + wire ASDU + optional 64B signature).
@spec sync_bytes() :: <<_::32>>
Returns the 4-byte sync header <<0xEB, 0x90, 0xEB, 0x90>>.