• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "base/resource/internal_resource.h"
17 
18 #include <functional>
19 #include <map>
20 #include <utility>
21 
22 // binary/errorcode.json
23 // Use objcopy transform to compiled object file.
24 // The following parameters represent the beginning and end of the file.
25 extern uint8_t _binary_errorcode_json_start[];
26 extern uint8_t _binary_errorcode_json_end[];
27 
28 // binary/indexletter_bar.json
29 // Use objcopy transform to compiled object file.
30 // The following parameters represent the beginning and end of the file.
31 extern uint8_t _binary_indexletter_bar_json_start[];
32 extern uint8_t _binary_indexletter_bar_json_end[];
33 
34 // binary/entry.json
35 // Use objcopy transform to compiled object file.
36 // The following parameters represent the beginning and end of the file.
37 extern uint8_t _binary_entry_json_start[];
38 extern uint8_t _binary_entry_json_end[];
39 
40 namespace OHOS::Ace {
41 namespace {
42 
43 struct ResourceData final {
ResourceDataOHOS::Ace::__anonaa82342e0111::ResourceData44     ResourceData(const uint8_t* buf, size_t size) : buf(buf), size(size) {}
45     ~ResourceData() = default;
46 
47     const uint8_t* buf;
48     size_t size;
49 };
50 
51 } // namespace
52 
53 InternalResource::InternalResource() = default;
54 
55 InternalResource::~InternalResource() = default;
56 
GetResource(const ResourceId id,size_t & size) const57 const uint8_t* InternalResource::GetResource(const ResourceId id, size_t& size) const
58 {
59     static const std::map<InternalResource::ResourceId, ResourceData> RESOURCE_MAP = {
60         { InternalResource::ResourceId::ERRORINFO_JSON,
61             ResourceData(_binary_errorcode_json_start,
62                 static_cast<size_t>(_binary_errorcode_json_end - _binary_errorcode_json_start)) },
63         { InternalResource::ResourceId::INDEXLETTER_BAR_JSON,
64             ResourceData(_binary_indexletter_bar_json_start,
65                 static_cast<size_t>(_binary_indexletter_bar_json_end - _binary_indexletter_bar_json_start)) },
66         { InternalResource::ResourceId::ENTRY_JSON,
67             ResourceData(
68                 _binary_entry_json_start, static_cast<size_t>(_binary_entry_json_end - _binary_entry_json_start)) },
69     };
70     auto iter = RESOURCE_MAP.find(id);
71     if (iter != RESOURCE_MAP.end()) {
72         size = iter->second.size;
73         return iter->second.buf;
74     }
75     return nullptr;
76 }
77 
78 } // namespace OHOS::Ace
79