Binary packet header for the Longbridge v1 protocol.
The header layout differs by packet type:
Request (11 bytes):
type:4|ver:1|gzip:1|resv:2 | cmd_code:8 | request_id:32 | timeout:16 | body_len:24Response (10 bytes):
type:4|ver:1|gzip:1|resv:2 | cmd_code:8 | request_id:32 | status_code:8 | body_len:24Push (5 bytes):
type:4|ver:1|gzip:1|resv:2 | cmd_code:8 | body_len:24After the body, optional nonce (8 bytes) and signature (16 bytes) when verify is enabled.
Summary
Functions
Packs a header struct into its binary representation. Returns iodata.
Unpacks binary data into a header struct.
Returns {:ok, header, remaining_binary} or {:error, reason}.
Extract optional nonce and signature from data following the body.
Only called when verify is true.
Returns {nonce, signature, remaining}.
Types
@type packet_type() :: :request | :response | :push
@type t() :: %Longbridge.Protocol.Header{ body_length: non_neg_integer(), cmd_code: non_neg_integer(), gzip: boolean(), nonce: non_neg_integer() | nil, request_id: non_neg_integer() | nil, signature: binary() | nil, status_code: non_neg_integer() | nil, timeout: non_neg_integer() | nil, type: packet_type(), verify: boolean() }
Functions
Packs a header struct into its binary representation. Returns iodata.
Unpacks binary data into a header struct.
Returns {:ok, header, remaining_binary} or {:error, reason}.
Extract optional nonce and signature from data following the body.
Only called when verify is true.
Returns {nonce, signature, remaining}.