refactor(frontend): 重构数据解析逻辑
- 新增 StopAndParseCapture 函数,整合停止抓包和解析数据流程 -重构 ReadRawJsonFile 函数,返回解析后的 ParsedResult 对象 - 优化数据解析流程,提高代码可读性和性能 - 调整前端 CapturePage组件,使用新的解析接口
This commit is contained in:
@@ -101,3 +101,33 @@ func (cs *CaptureService) processData(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// StopAndParseCapture 停止抓包并解析数据
|
||||
func (cs *CaptureService) StopAndParseCapture(parser *ParserService) (*model.ParsedResult, error) {
|
||||
cs.mutex.Lock()
|
||||
defer cs.mutex.Unlock()
|
||||
|
||||
if !cs.isCapturing {
|
||||
return nil, fmt.Errorf("capture not running")
|
||||
}
|
||||
|
||||
cs.packetCapture.Stop()
|
||||
cs.isCapturing = false
|
||||
cs.logger.Info("Packet capture stopped (StopAndParseCapture)")
|
||||
|
||||
// 处理所有收集的数据
|
||||
cs.packetCapture.ProcessAllData()
|
||||
|
||||
// 获取抓包数据
|
||||
rawData := cs.packetCapture.GetCapturedData()
|
||||
if len(rawData) == 0 {
|
||||
return nil, fmt.Errorf("no captured data")
|
||||
}
|
||||
|
||||
// 解析数据
|
||||
result, _, err := parser.ParseHexData(rawData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("解析数据失败: %v", err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user