123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include "base/resource/internal_resource.h" 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include <map> 1923b3eb3cSopenharmony_ci 2023b3eb3cSopenharmony_ci// binary/errorcode.json 2123b3eb3cSopenharmony_ci// Use objcopy transform to compiled object file. 2223b3eb3cSopenharmony_ci// The following parameters represent the beginning and end of the file. 2323b3eb3cSopenharmony_ciextern uint8_t _binary_errorcode_json_start[]; 2423b3eb3cSopenharmony_ciextern uint8_t _binary_errorcode_json_end[]; 2523b3eb3cSopenharmony_ci 2623b3eb3cSopenharmony_ci// binary/indexletter_bar.json 2723b3eb3cSopenharmony_ci// Use objcopy transform to compiled object file. 2823b3eb3cSopenharmony_ci// The following parameters represent the beginning and end of the file. 2923b3eb3cSopenharmony_ciextern uint8_t _binary_indexletter_bar_json_start[]; 3023b3eb3cSopenharmony_ciextern uint8_t _binary_indexletter_bar_json_end[]; 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_ci// binary/entry.json 3323b3eb3cSopenharmony_ci// Use objcopy transform to compiled object file. 3423b3eb3cSopenharmony_ci// The following parameters represent the beginning and end of the file. 3523b3eb3cSopenharmony_ciextern uint8_t _binary_entry_json_start[]; 3623b3eb3cSopenharmony_ciextern uint8_t _binary_entry_json_end[]; 3723b3eb3cSopenharmony_ci 3823b3eb3cSopenharmony_cinamespace OHOS::Ace { 3923b3eb3cSopenharmony_cinamespace { 4023b3eb3cSopenharmony_ci 4123b3eb3cSopenharmony_cistruct ResourceData final { 4223b3eb3cSopenharmony_ci ResourceData(const uint8_t* buf, size_t size) : buf(buf), size(size) {} 4323b3eb3cSopenharmony_ci ~ResourceData() = default; 4423b3eb3cSopenharmony_ci 4523b3eb3cSopenharmony_ci const uint8_t* buf; 4623b3eb3cSopenharmony_ci size_t size; 4723b3eb3cSopenharmony_ci}; 4823b3eb3cSopenharmony_ci 4923b3eb3cSopenharmony_ci} // namespace 5023b3eb3cSopenharmony_ci 5123b3eb3cSopenharmony_ciInternalResource::InternalResource() = default; 5223b3eb3cSopenharmony_ci 5323b3eb3cSopenharmony_ciInternalResource::~InternalResource() = default; 5423b3eb3cSopenharmony_ci 5523b3eb3cSopenharmony_ciconst uint8_t* InternalResource::GetResource(const ResourceId id, size_t& size) const 5623b3eb3cSopenharmony_ci{ 5723b3eb3cSopenharmony_ci static const std::map<InternalResource::ResourceId, ResourceData> RESOURCE_MAP = { 5823b3eb3cSopenharmony_ci { InternalResource::ResourceId::ERRORINFO_JSON, 5923b3eb3cSopenharmony_ci ResourceData(_binary_errorcode_json_start, 6023b3eb3cSopenharmony_ci static_cast<size_t>(_binary_errorcode_json_end - _binary_errorcode_json_start)) }, 6123b3eb3cSopenharmony_ci { InternalResource::ResourceId::INDEXLETTER_BAR_JSON, 6223b3eb3cSopenharmony_ci ResourceData(_binary_indexletter_bar_json_start, 6323b3eb3cSopenharmony_ci static_cast<size_t>(_binary_indexletter_bar_json_end - _binary_indexletter_bar_json_start)) }, 6423b3eb3cSopenharmony_ci { InternalResource::ResourceId::ENTRY_JSON, 6523b3eb3cSopenharmony_ci ResourceData( 6623b3eb3cSopenharmony_ci _binary_entry_json_start, static_cast<size_t>(_binary_entry_json_end - _binary_entry_json_start)) }, 6723b3eb3cSopenharmony_ci }; 6823b3eb3cSopenharmony_ci auto iter = RESOURCE_MAP.find(id); 6923b3eb3cSopenharmony_ci if (iter != RESOURCE_MAP.end()) { 7023b3eb3cSopenharmony_ci size = iter->second.size; 7123b3eb3cSopenharmony_ci return iter->second.buf; 7223b3eb3cSopenharmony_ci } 7323b3eb3cSopenharmony_ci return nullptr; 7423b3eb3cSopenharmony_ci} 7523b3eb3cSopenharmony_ci 7623b3eb3cSopenharmony_ci} // namespace OHOS::Ace 77