1 /* 2 * Copyright (c) 2025-2026 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 NETWORKSLICEUTIL_H 17 #define NETWORKSLICEUTIL_H 18 19 #include <cstdint> 20 #include <string> 21 #include <vector> 22 #include <sstream> 23 #include <nlohmann/json.hpp> 24 #include <bit> 25 #include <set> 26 #include "netmgr_ext_log_wrapper.h" 27 #include "networkslicecommconfig.h" 28 29 namespace OHOS { 30 namespace NetManagerStandard { 31 std::vector<std::string> Split(const std::string &str, const std::string delimiter); 32 uint8_t ConvertInt2UnsignedByte(int value); 33 std::string ByteToHexStr(uint8_t byte); 34 short GetShort(int& startIndex, std::vector<uint8_t> buffer, bool isLitterEndian = false); 35 int32_t GetInt(int& startIndex, std::vector<uint8_t> buffer, bool isLitterEndian = false); 36 uint32_t vectorToUint32(const std::vector<uint8_t>& vec); 37 std::array<uint8_t, 16> vectorToIPv6Array(const std::vector<uint8_t>& vec); 38 int ConvertUnsignedShort2Int(short value); 39 short ConvertInt2UnsignedShort(int value); 40 std::string transIpv6AddrToStr(std::array<uint8_t, NetworkSliceCommConfig::LEN_IPV6ADDR> Ipv6Addr); 41 void PutShort(std::vector<uint8_t>& buffer, short value, bool isLitterEndian = true); 42 void PutInt(std::vector<uint8_t>& buffer, int value, bool isLitterEndian = true); 43 std::vector<uint8_t> ConvertstringTouInt8Vector(const std::string& str); 44 std::string ConvertIntListToString(const std::vector<int>& intList); 45 std::vector<uint8_t> uInt32ToVector(uint32_t value); 46 std::string ConvertIntSetToString(const std::set<int>& intList); 47 std::string ConvertUint8vecToString(const std::vector<uint8_t>& vec); 48 std::string GetSha256Str(const std::string &str); 49 } 50 } 51 52 #endif //NETWORKSLICEUTIL_H 53