• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #define MLOG_TAG "Media_Client"
16 
17 #include "mdk_record_reader.h"
18 
19 #include <string>
20 
21 #include "media_log.h"
22 
23 namespace OHOS::Media::CloudSync {
GetAssetValue(const std::map<std::string,MDKRecordField> & fields,const std::string & key) const24 std::optional<MDKAsset> MDKRecordReader::GetAssetValue(
25     const std::map<std::string, MDKRecordField> &fields, const std::string &key) const
26 {
27     std::optional<MDKAsset> valueOpt;
28     auto it = fields.find(key);
29     if (it == fields.end()) {
30         return valueOpt;
31     }
32     MDKAsset value;
33     MDKLocalErrorCode errorCode = it->second.GetAsset(value);
34     if (errorCode != MDKLocalErrorCode::NO_ERROR) {
35         return valueOpt;
36     }
37     return value;
38 }
GetStringValue(const std::map<std::string,MDKRecordField> & fields,const std::string & key) const39 std::optional<std::string> MDKRecordReader::GetStringValue(
40     const std::map<std::string, MDKRecordField> &fields, const std::string &key) const
41 {
42     std::optional<std::string> valueOpt;
43     auto it = fields.find(key);
44     if (it == fields.end()) {
45         return valueOpt;
46     }
47     std::string value;
48     MDKLocalErrorCode errorCode = it->second.GetString(value);
49     if (errorCode != MDKLocalErrorCode::NO_ERROR) {
50         return valueOpt;
51     }
52     return value;
53 }
GetLongValue(const std::map<std::string,MDKRecordField> & fields,const std::string & key) const54 std::optional<int64_t> MDKRecordReader::GetLongValue(
55     const std::map<std::string, MDKRecordField> &fields, const std::string &key) const
56 {
57     std::optional<int64_t> valueOpt;
58     auto it = fields.find(key);
59     if (it == fields.end()) {
60         return valueOpt;
61     }
62     int64_t value;
63     MDKLocalErrorCode errorCode = it->second.GetLong(value);
64     if (errorCode != MDKLocalErrorCode::NO_ERROR) {
65         return valueOpt;
66     }
67     return value;
68 }
GetIntValue(const std::map<std::string,MDKRecordField> & fields,const std::string & key) const69 std::optional<int32_t> MDKRecordReader::GetIntValue(
70     const std::map<std::string, MDKRecordField> &fields, const std::string &key) const
71 {
72     std::optional<int32_t> resultOpt;
73     std::optional<int64_t> valueOpt = this->GetLongValue(fields, key);
74     if (valueOpt) {
75         resultOpt = static_cast<int32_t>(valueOpt.value());
76     }
77     return resultOpt;
78 }
GetBoolValue(const std::map<std::string,MDKRecordField> & fields,const std::string & key) const79 std::optional<bool> MDKRecordReader::GetBoolValue(
80     const std::map<std::string, MDKRecordField> &fields, const std::string &key) const
81 {
82     std::optional<bool> valueOpt;
83     auto it = fields.find(key);
84     if (it == fields.end()) {
85         return valueOpt;
86     }
87     bool value;
88     MDKLocalErrorCode errorCode = it->second.GetBool(value);
89     if (errorCode != MDKLocalErrorCode::NO_ERROR) {
90         return valueOpt;
91     }
92     return value;
93 }
94 }  // namespace OHOS::Media::CloudSync