44f58403创建于 6月24日历史提交
/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "message_parcel.h"
#include "sane_device.h"
#include "scan_log.h"
#include "scan_constant.h"

namespace OHOS::Scan {
bool SaneDevice::Marshalling(Parcel &parcel) const
{
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.WriteString(name_), false);
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.WriteString(vendor_), false);
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.WriteString(model_), false);
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.WriteString(type_), false);
    return true;
}

SaneDevice* SaneDevice::Unmarshalling(Parcel &parcel)
{
    auto obj = std::make_unique<SaneDevice>();
    if (obj == nullptr) {
        SCAN_HILOGE("obj is a nullptr.");
        return nullptr;
    }
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.ReadString(obj->name_), nullptr);
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.ReadString(obj->vendor_), nullptr);
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.ReadString(obj->model_), nullptr);
    CHECK_PARCEL_OP_AND_RETURN_VAL(parcel.ReadString(obj->type_), nullptr);
    return obj.release();
}

void SaneDevice::Dump()
{
    SCAN_HILOGI("SaneDevice:[%{private}s] [%{public}s] [%{public}s] [%{public}s]",
        name_.c_str(), vendor_.c_str(), model_.c_str(), type_.c_str());
}
}   // namespace OHOS::Scan