Skip to content

Commit

Permalink
checked range of task_id
Browse files Browse the repository at this point in the history
  • Loading branch information
lixungeng committed Dec 30, 2023
1 parent 9e94025 commit c8ff85d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pb/ocr_protobuf.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ message OcrRespond {

message OcrRequest {
int32 unknow = 1; //必定为0
// 核查了好几次,在腾讯proto文件中,这个task_id确实是64位的。但在,在执行过程中,高32位会被丢弃,且第32位为1会出错。
// 也就是协议上是有64位的uint64,实际上只有31位。必须是>0的整形数字,范围是[12147483647]
uint64 task_id = 2;

message OcrInputBuffer {
Expand Down
5 changes: 3 additions & 2 deletions src/wechatocr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ CWeChatOCR::CWeChatOCR(LPCWSTR exe, LPCWSTR wcdir)
}
}

#define OCR_MAX_TASK_ID 32 //最大同时发送任务ID, 默认32, 一定要<=32
#define OCR_MAX_TASK_ID INT_MAX
bool CWeChatOCR::doOCR(crefstr imgpath, result_t* res)
{
if (m_state == STATE_INVALID || (m_state == STATE_PENDING && !wait_connection(2000)))
return false;

int found_id = -1;
m_mutex.lock();
for (int i = 1; i <= OCR_MAX_TASK_ID; ++i)
// TODO: task_id本身可以是任何正整形数,但是这里要不要限制同时并发任务数呢?
for (uint32_t i = 1; i <= OCR_MAX_TASK_ID; ++i)
{
if (m_idpath.insert(std::make_pair(i, std::pair<string,result_t*>(imgpath,res))).second)
{
Expand Down

0 comments on commit c8ff85d

Please sign in to comment.