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 "peer_info.h"
12 : #include "json_parser.h"
13 : #include "invalid_params_exception.h"
14 :
15 : namespace Hccl {
16 :
17 115 : void PeerInfo::Deserialize(const nlohmann::json& peerInfoJson)
18 : {
19 115 : std::string msgId = "[PeerInfo::Deserialize] error occurs when parser object of propName \"local_id\"";
20 117 : TRY_CATCH_THROW(InvalidParamsException, msgId, localId = GetJsonPropertyUInt(peerInfoJson, "local_id"););
21 :
22 113 : if (localId > MAX_PEER_LOCAL_ID) {
23 0 : THROW<InvalidParamsException>(
24 : "[PeerInfo::%s] localId[%u] is out of range [0, %u].", __func__, localId, MAX_PEER_LOCAL_ID);
25 : }
26 115 : }
27 :
28 4 : std::string PeerInfo::Describe() const { return StringFormat("PeerInfo{local_id=%u}", localId); }
29 :
30 90 : void PeerInfo::GetBinStream(BinaryStream& binaryStream) const { binaryStream << localId; }
31 :
32 70 : PeerInfo::PeerInfo(BinaryStream& binaryStream) { binaryStream >> localId; }
33 :
34 : } // namespace Hccl
|