• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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// remote消息中变量类型名(key)与对应的读parcel方法名(value)的映射(参考parcel.h)
16const DATA_READ_MAP = new Map(
17    [["int8_t", "ReadInt8Unaligned"], ["uint8_t", "ReadUint8Unaligned"],
18     ["int16_t", "ReadInt16Unaligned"], ["uint16_t", "ReadUint16Unaligned"],
19     ["int32_t", "ReadInt32"], ["uint32_t", "ReadUint32"], ["int64_t", "ReadInt64"], ["uint64_t", "ReadUint64"],
20     ["float", "ReadFloat"], ["double", "ReadDouble"], ["char *", "ReadCString"], ["std::string", "ReadString"],
21     ["string", "ReadString"], ["bool", "ReadBoolUnaligned"]
22]);
23
24// remote消息中变量类型名(key)与对应的写parcel方法名(value)的映射(参考parcel.h)
25const DATA_WRITE_MAP = new Map(
26    [["int8_t", "WriteInt8Unaligned"], ["uint8_t", "ReadUint8Unaligned"],
27     ["int16_t", "WriteInt16Unaligned"], ["uint16_t", "WriteUint16Unaligned"],
28     ["int32_t", "WriteInt32"], ["uint32_t", "WriteUint32"], ["int64_t", "WriteInt64"], ["uint64_t", "WriteUint64"],
29     ["float", "WriteFloat"], ["double", "WriteDouble"], ["char *", "WriteCString"], ["std::string", "WriteString"],
30     ["string", "WriteString"], ["bool", "WriteBoolUnaligned"]
31]);
32
33// 常用类型转换表, 将C语言常见类型(key)转换为remote data读写函数使用的类型(value)
34// 例如 ErrCode 类型在框架中的系统原型为int类型,这里映射成int32_t,
35// 因为int32_t类型在 DATA_WRITE_MAP/DATA_READ_MAP 表中有对应的读写数据方法(WriteInt32/ReadInt32)
36const TYPE_DEF_MAP = new Map(
37    [["ErrCode", "int32_t"], ["char", "int8_t"], ["short", "int16_t"], ["int", "int32_t"], ["long", "int64_t"],
38    ["unsigned char", "uint8_t"], ["unsigned short", "uint16_t"], ["unsigned int", "uint32_t"],
39    ["unsigned long", "uint64_t"]
40]);
41
42function getParcelType(srcType) {
43    let parcelType = TYPE_DEF_MAP.get(srcType);
44    return parcelType === undefined ? srcType : parcelType;
45}
46
47module.exports = {
48    DATA_WRITE_MAP, DATA_READ_MAP, getParcelType
49}