FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
fix40::FixFrameDecoder Class Reference

FIX 消息帧解码器 More...

#include <fix_frame_decoder.hpp>

Collaboration diagram for fix40::FixFrameDecoder:
Collaboration graph

Public Member Functions

 FixFrameDecoder (size_t max_buffer_size, size_t max_body_length)
 构造帧解码器
 
bool can_append (size_t len) const
 检查是否可以追加指定长度的数据
 
void append (const char *data, size_t len)
 向内部缓冲区追加数据
 
bool next_message (std::string &message)
 尝试从缓冲区提取下一条完整消息
 

Detailed Description

FIX 消息帧解码器

由于 TCP 是流式协议,接收到的数据可能包含多条消息(粘包) 或不完整的消息(拆包)。该类负责缓存数据并提取完整的 FIX 消息。

工作原理
  1. 查找消息起始标记 "8=FIX.4.0\x01"
  2. 解析 BodyLength (9=) 获取消息体长度
  3. 计算完整消息长度并提取
使用示例
FixFrameDecoder decoder(1048576, 4096);
// 接收数据
decoder.append(buffer, bytes_read);
// 提取完整消息
std::string msg;
while (decoder.next_message(msg)) {
process_message(msg);
}
FIX 消息帧解码器
Definition fix_frame_decoder.hpp:41

Constructor & Destructor Documentation

◆ FixFrameDecoder()

fix40::FixFrameDecoder::FixFrameDecoder ( size_t  max_buffer_size,
size_t  max_body_length 
)
explicit

构造帧解码器

Parameters
max_buffer_size缓冲区最大大小(字节),防止内存耗尽
max_body_length消息体最大长度(字节),防止解析超长消息

Member Function Documentation

◆ append()

void fix40::FixFrameDecoder::append ( const char *  data,
size_t  len 
)

向内部缓冲区追加数据

Parameters
data数据指针
len数据长度
Exceptions
std::runtime_error缓冲区溢出时抛出异常
Here is the caller graph for this function:

◆ can_append()

bool fix40::FixFrameDecoder::can_append ( size_t  len) const

检查是否可以追加指定长度的数据

Parameters
len要追加的数据长度
Returns
true 可以追加(不会溢出)
false 追加后会超出缓冲区限制
Here is the caller graph for this function:

◆ next_message()

bool fix40::FixFrameDecoder::next_message ( std::string &  message)

尝试从缓冲区提取下一条完整消息

Parameters
[out]message输出参数,存放提取的消息
Returns
true 成功提取一条完整消息
false 数据不足,无法提取完整消息
Note
应循环调用直到返回 false,以处理粘包情况
Exceptions
std::runtime_errorBodyLength 无效时抛出异常
Here is the caller graph for this function:

The documentation for this class was generated from the following files: