1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HILOG_MSG_WRAPPER_H 17 #define HILOG_MSG_WRAPPER_H 18 19 #include <cstring> 20 #include <iostream> 21 #include <securec.h> 22 23 #include <hilog/log.h> 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 28 class HilogMsgWrapper { 29 public: HilogMsgWrapper(const std::vector<char> & _msgBuffer)30 explicit HilogMsgWrapper(const std::vector<char> & _msgBuffer) : msgBuffer(_msgBuffer) 31 {} HilogMsgWrapper(std::vector<char> && _msgBuffer)32 explicit HilogMsgWrapper(std::vector<char> && _msgBuffer) 33 { 34 std::swap(msgBuffer, _msgBuffer); 35 } GetHilogMsg()36 HilogMsg& GetHilogMsg() 37 { 38 return *reinterpret_cast<HilogMsg*>(msgBuffer.data()); 39 } 40 GetRawData()41 const std::vector<char> & GetRawData() const 42 { 43 return msgBuffer; 44 } 45 46 private: 47 std::vector<char> msgBuffer; 48 }; 49 } // namespace HiviewDFX 50 } // namespace OHOS 51 #endif /* HILOG_MSG_WRAPPER_H */ 52