1 /* 2 * Copyright (c) 2023 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 #include "uid_range.h" 16 17 #include "netnative_log_wrapper.h" 18 19 namespace OHOS { 20 namespace NetManagerStandard { 21 22 namespace { 23 constexpr int32_t INVLID_VALUE = -1; 24 } 25 UidRange(int32_t begin,int32_t end)26UidRange::UidRange(int32_t begin, int32_t end) : begin_(begin), end_(end) {} 27 Size() const28uint32_t UidRange::Size() const 29 { 30 if (begin_ == INVLID_VALUE || end_ == INVLID_VALUE || end_ < begin_) { 31 return 0; 32 } 33 return static_cast<uint32_t>(end_ - begin_ + 1); 34 } 35 Marshalling(Parcel & parcel) const36bool UidRange::Marshalling(Parcel &parcel) const 37 { 38 return parcel.WriteInt32(begin_) && parcel.WriteInt32(end_); 39 } 40 Unmarshalling(Parcel & parcel)41sptr<UidRange> UidRange::Unmarshalling(Parcel &parcel) 42 { 43 sptr<UidRange> ptr = new (std::nothrow) UidRange(); 44 if (ptr == nullptr) { 45 NETNATIVE_LOGE("UidRange Unmarshalling new object is failed."); 46 return nullptr; 47 } 48 49 bool allOK = parcel.ReadInt32(ptr->begin_) && parcel.ReadInt32(ptr->end_); 50 return allOK ? ptr : nullptr; 51 } 52 } // namespace NetManagerStandard 53 } // namespace OHOS