Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "cnt_notify_res_helper.h"
12 : #include "binary_stream.h"
13 : namespace Hccl {
14 : BaseMemTransport::LocCntNotifyRes
15 5 : CntNotifyResHelper::GetCntNotifyRes(const unordered_map<u32, vector<LocalCntNotify*>>& topicIdCntNotifyVecMap) const
16 : {
17 5 : u32 cntNotifyNum = 0;
18 5 : for (auto& it : topicIdCntNotifyVecMap) {
19 0 : cntNotifyNum += it.second.size();
20 : }
21 :
22 5 : BinaryStream binaryStream;
23 5 : BaseMemTransport::LocCntNotifyRes result;
24 5 : binaryStream << cntNotifyNum;
25 :
26 5 : u32 cntNotifyIndex = 0;
27 5 : for (auto& it : topicIdCntNotifyVecMap) {
28 0 : auto topicId = it.first;
29 0 : u32 pos = 0;
30 0 : for (auto& notify : it.second) {
31 0 : binaryStream << topicId;
32 0 : binaryStream << pos;
33 0 : binaryStream << cntNotifyIndex;
34 0 : result.vec.push_back(notify);
35 0 : cntNotifyIndex++;
36 0 : pos++;
37 : }
38 : }
39 5 : binaryStream.Dump(result.desc);
40 5 : return result;
41 5 : }
42 :
43 4 : u32 CntNotifyResHelper::GetIndex(vector<char>& desc, u32 topicId, u32 pos) const
44 : {
45 4 : BinaryStream binaryStream(desc);
46 4 : u32 cntNotifyNum = 0;
47 4 : binaryStream >> cntNotifyNum;
48 4 : for (u32 index = 0; index < cntNotifyNum; index++) {
49 : u32 theTopicId;
50 : u32 thePos;
51 : u32 theCntNotifyIndex;
52 0 : binaryStream >> theTopicId;
53 0 : binaryStream >> thePos;
54 0 : binaryStream >> theCntNotifyIndex;
55 0 : if (theTopicId == topicId && thePos == pos) {
56 0 : return theCntNotifyIndex;
57 : }
58 : }
59 12 : HCCL_ERROR("cannot find topicId=%u, pos=%u in desc=%s", topicId, pos, Bytes2hex(desc.data(), desc.size()).c_str());
60 4 : return 0;
61 4 : }
62 : } // namespace Hccl
|