Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / chip-tool / commands / payload / AdditionalDataParseCommand.cpp
1 /*
2  *   Copyright (c) 2020 Project CHIP Authors
3  *   All rights reserved.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  */
18
19 #include "AdditionalDataParseCommand.h"
20 #include <setup_payload/AdditionalDataPayload.h>
21 #include <setup_payload/AdditionalDataPayloadParser.h>
22 #include <string>
23
24 using namespace ::chip;
25 using namespace ::chip::SetupPayloadData;
26
27 CHIP_ERROR AdditionalDataParseCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
28 {
29     std::vector<uint8_t> payloadData;
30     AdditionalDataPayload resultPayload;
31     CHIP_ERROR err = CHIP_NO_ERROR;
32     std::string payloadString(mPayload);
33
34     // Decode input payload
35     size_t len = payloadString.length();
36
37     for (size_t i = 0; i < len; i += 2)
38     {
39         auto str  = payloadString.substr(i, 2);
40         uint8_t x = (uint8_t) stoi(str, 0, 16);
41         payloadData.push_back(x);
42     }
43     err = AdditionalDataPayloadParser(payloadData.data(), (uint32_t) payloadData.size()).populatePayload(resultPayload);
44     SuccessOrExit(err);
45     ChipLogProgress(chipTool, "AdditionalDataParseCommand, RotatingDeviceId=%s", resultPayload.rotatingDeviceId.c_str());
46 exit:
47     return err;
48 }