Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
aae43a0e
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
大约 1 年 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
aae43a0e
编写于
5月 28, 2022
作者:
Y
yangguangzhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rpc api bugfix
Signed-off-by:
N
yangguangzhao
<
yangguangzhao1@huawei.com
>
上级
f60f015b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
112 addition
and
120 deletion
+112
-120
ipc/native/src/napi/src/napi_ashmem.cpp
ipc/native/src/napi/src/napi_ashmem.cpp
+22
-13
ipc/native/src/napi/src/napi_message_parcel.cpp
ipc/native/src/napi/src/napi_message_parcel.cpp
+90
-107
未找到文件。
ipc/native/src/napi/src/napi_ashmem.cpp
浏览文件 @
aae43a0e
...
@@ -268,23 +268,32 @@ napi_value NAPIAshmem::WriteToAshmem(napi_env env, napi_callback_info info)
...
@@ -268,23 +268,32 @@ napi_value NAPIAshmem::WriteToAshmem(napi_env env, napi_callback_info info)
napi_value
thisVar
=
nullptr
;
napi_value
thisVar
=
nullptr
;
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
NAPI_ASSERT
(
env
,
argc
==
3
,
"requires 1 parameter"
);
NAPI_ASSERT
(
env
,
argc
==
3
,
"requires 1 parameter"
);
bool
is
Typed
Array
=
false
;
bool
isArray
=
false
;
napi_is_
typedarray
(
env
,
argv
[
0
],
&
isTyped
Array
);
napi_is_
array
(
env
,
argv
[
0
],
&
is
Array
);
NAPI_ASSERT
(
env
,
is
Typed
Array
==
true
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
isArray
==
true
,
"type mismatch for parameter 1"
);
napi_valuetype
valueType
=
napi_null
;
napi_valuetype
valueType
=
napi_null
;
napi_typeof
(
env
,
argv
[
1
],
&
valueType
);
napi_typeof
(
env
,
argv
[
1
],
&
valueType
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 2"
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 2"
);
napi_typeof
(
env
,
argv
[
2
],
&
valueType
);
napi_typeof
(
env
,
argv
[
2
],
&
valueType
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 3"
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 3"
);
napi_typedarray_type
typedarrayType
=
napi_uint8_array
;
size_t
typedarrayLength
=
0
;
std
::
vector
<
int32_t
>
array
;
void
*
typedarrayBufferPtr
=
nullptr
;
uint32_t
arrayLength
=
0
;
napi_value
tmpArrayBuffer
=
nullptr
;
napi_get_array_length
(
env
,
argv
[
0
],
&
arrayLength
);
size_t
byteOffset
=
0
;
napi_get_typedarray_info
(
env
,
argv
[
0
],
&
typedarrayType
,
&
typedarrayLength
,
&
typedarrayBufferPtr
,
for
(
size_t
i
=
0
;
i
<
arrayLength
;
i
++
)
{
&
tmpArrayBuffer
,
&
byteOffset
);
bool
hasElement
=
false
;
NAPI_ASSERT
(
env
,
typedarrayType
==
napi_int8_array
,
"array type mismatch for parameter 1"
);
napi_has_element
(
env
,
argv
[
0
],
i
,
&
hasElement
);
DBINDER_LOGI
(
"ashmem WriteBuffer typedarrayLength = %{public}d"
,
(
int
)(
typedarrayLength
));
NAPI_ASSERT
(
env
,
hasElement
==
true
,
"parameter check error"
);
napi_value
element
=
nullptr
;
napi_get_element
(
env
,
argv
[
0
],
i
,
&
element
);
int32_t
value
=
0
;
napi_get_value_int32
(
env
,
element
,
&
value
);
array
.
push_back
(
value
);
}
uint32_t
size
=
0
;
uint32_t
size
=
0
;
napi_get_value_uint32
(
env
,
argv
[
1
],
&
size
);
napi_get_value_uint32
(
env
,
argv
[
1
],
&
size
);
uint32_t
offset
=
0
;
uint32_t
offset
=
0
;
...
@@ -293,7 +302,7 @@ napi_value NAPIAshmem::WriteToAshmem(napi_env env, napi_callback_info info)
...
@@ -293,7 +302,7 @@ napi_value NAPIAshmem::WriteToAshmem(napi_env env, napi_callback_info info)
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiAshmem
);
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiAshmem
);
NAPI_ASSERT
(
env
,
napiAshmem
!=
nullptr
,
"napiAshmem is null"
);
NAPI_ASSERT
(
env
,
napiAshmem
!=
nullptr
,
"napiAshmem is null"
);
// need check size offset and capacity
// need check size offset and capacity
bool
result
=
napiAshmem
->
GetAshmem
()
->
WriteToAshmem
(
typedarrayBufferPtr
,
size
,
offset
);
bool
result
=
napiAshmem
->
GetAshmem
()
->
WriteToAshmem
(
array
.
data
()
,
size
,
offset
);
napi_value
napiValue
=
nullptr
;
napi_value
napiValue
=
nullptr
;
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
return
napiValue
;
return
napiValue
;
...
...
ipc/native/src/napi/src/napi_message_parcel.cpp
浏览文件 @
aae43a0e
...
@@ -282,24 +282,16 @@ napi_value NAPI_MessageParcel::JS_writeChar(napi_env env, napi_callback_info inf
...
@@ -282,24 +282,16 @@ napi_value NAPI_MessageParcel::JS_writeChar(napi_env env, napi_callback_info inf
napi_valuetype
valueType
=
napi_null
;
napi_valuetype
valueType
=
napi_null
;
napi_typeof
(
env
,
argv
[
0
],
&
valueType
);
napi_typeof
(
env
,
argv
[
0
],
&
valueType
);
NAPI_ASSERT
(
env
,
valueType
==
napi_
string
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
valueType
==
napi_
number
,
"type mismatch for parameter 1"
);
size_t
bufferSize
=
0
;
uint32_t
value
=
0
;
size_t
strLength
=
0
;
napi_get_value_uint32
(
env
,
argv
[
0
],
&
value
);
napi_get_value_string_utf8
(
env
,
argv
[
0
],
nullptr
,
0
,
&
bufferSize
);
DBINDER_LOGI
(
"messageparcel writeChar bufferSize = %{public}d"
,
(
int
)
bufferSize
);
char
buffer
[
bufferSize
+
1
];
napi_get_value_string_utf8
(
env
,
argv
[
0
],
buffer
,
bufferSize
+
1
,
&
strLength
);
NAPI_MessageParcel
*
napiParcel
=
nullptr
;
NAPI_MessageParcel
*
napiParcel
=
nullptr
;
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
NAPI_ASSERT
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
);
NAPI_ASSERT
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
);
CHECK_WRITE_CAPACITY
(
env
,
BYTE_SIZE_32
,
napiParcel
);
CHECK_WRITE_CAPACITY
(
env
,
BYTE_SIZE_32
,
napiParcel
);
std
::
string
parcelString
=
buffer
;
bool
result
=
napiParcel
->
nativeParcel_
->
WriteUint8
(
static_cast
<
uint8_t
>
(
value
));
std
::
u16string
tmp
=
to_utf16
(
parcelString
);
auto
value
=
reinterpret_cast
<
uint16_t
*>
(
tmp
.
data
());
bool
result
=
napiParcel
->
nativeParcel_
->
WriteUint16
(
*
value
);
napi_value
napiValue
=
nullptr
;
napi_value
napiValue
=
nullptr
;
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
return
napiValue
;
return
napiValue
;
...
@@ -313,29 +305,38 @@ napi_value NAPI_MessageParcel::JS_writeByteArray(napi_env env, napi_callback_inf
...
@@ -313,29 +305,38 @@ napi_value NAPI_MessageParcel::JS_writeByteArray(napi_env env, napi_callback_inf
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
NAPI_ASSERT
(
env
,
argc
==
1
,
"requires 1 parameter"
);
NAPI_ASSERT
(
env
,
argc
==
1
,
"requires 1 parameter"
);
bool
isTypedArray
=
false
;
bool
isArray
=
false
;
napi_is_typedarray
(
env
,
argv
[
0
],
&
isTypedArray
);
napi_is_array
(
env
,
argv
[
0
],
&
isArray
);
NAPI_ASSERT
(
env
,
isTypedArray
==
true
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
isArray
==
true
,
"type mismatch for parameter 1"
);
napi_typedarray_type
typedarrayType
=
napi_uint8_array
;
size_t
typedarrayLength
=
0
;
void
*
typedarrayBufferPtr
=
nullptr
;
napi_value
tmpArrayBuffer
=
nullptr
;
size_t
byteOffset
=
0
;
napi_get_typedarray_info
(
env
,
argv
[
0
],
&
typedarrayType
,
&
typedarrayLength
,
&
typedarrayBufferPtr
,
&
tmpArrayBuffer
,
&
byteOffset
);
NAPI_ASSERT
(
env
,
typedarrayType
==
napi_int8_array
,
"array type mismatch for parameter 1"
)
;
uint32_t
arrayLength
=
0
;
DBINDER_LOGI
(
"messageparcel WriteBuffer typedarrayLength = %{public}d"
,
(
int
)(
typedarrayLength
)
);
napi_get_array_length
(
env
,
argv
[
0
],
&
arrayLength
);
NAPI_MessageParcel
*
napiParcel
=
nullptr
;
NAPI_MessageParcel
*
napiParcel
=
nullptr
;
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
NAPI_ASSERT
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
);
NAPI_ASSERT
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
);
size_t
len
=
(
typedarrayLength
/
BYTE_SIZE_32
)
+
((
typedarrayLength
%
BYTE_SIZE_32
)
==
0
?
0
:
1
);
DBINDER_LOGI
(
"messageparcel WriteBuffer len = %{public}d"
,
(
int
)(
len
));
CHECK_WRITE_CAPACITY
(
env
,
BYTE_SIZE_8
*
(
arrayLength
+
1
),
napiParcel
);
CHECK_WRITE_CAPACITY
(
env
,
BYTE_SIZE_32
*
(
len
+
1
),
napiParcel
);
size_t
pos
=
napiParcel
->
nativeParcel_
->
GetWritePosition
();
napiParcel
->
nativeParcel_
->
WriteUint32
(
typedarrayLength
);
napiParcel
->
nativeParcel_
->
WriteUint32
(
arrayLength
);
bool
result
=
napiParcel
->
nativeParcel_
->
WriteBuffer
(
typedarrayBufferPtr
,
typedarrayLength
);
bool
result
=
false
;
for
(
size_t
i
=
0
;
i
<
arrayLength
;
i
++
)
{
bool
hasElement
=
false
;
napi_has_element
(
env
,
argv
[
0
],
i
,
&
hasElement
);
NAPI_ASSERT
(
env
,
hasElement
==
true
,
"parameter check error"
);
napi_value
element
=
nullptr
;
napi_get_element
(
env
,
argv
[
0
],
i
,
&
element
);
uint32_t
value
=
0
;
napi_get_value_uint32
(
env
,
element
,
&
value
);
result
=
napiParcel
->
nativeParcel_
->
WriteUint8
(
static_cast
<
uint8_t
>
(
value
));
if
(
!
result
)
{
napiParcel
->
nativeParcel_
->
RewindWrite
(
pos
);
break
;
}
}
napi_value
napiValue
=
nullptr
;
napi_value
napiValue
=
nullptr
;
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
return
napiValue
;
return
napiValue
;
...
@@ -657,18 +658,10 @@ napi_value NAPI_MessageParcel::JS_writeCharArray(napi_env env, napi_callback_inf
...
@@ -657,18 +658,10 @@ napi_value NAPI_MessageParcel::JS_writeCharArray(napi_env env, napi_callback_inf
napi_value
element
=
nullptr
;
napi_value
element
=
nullptr
;
napi_get_element
(
env
,
argv
[
0
],
i
,
&
element
);
napi_get_element
(
env
,
argv
[
0
],
i
,
&
element
);
size_t
bufferSize
=
0
;
uint32_t
value
=
0
;
size_t
strLength
=
0
;
napi_get_value_uint32
(
env
,
element
,
&
value
);
napi_get_value_string_utf8
(
env
,
element
,
nullptr
,
0
,
&
bufferSize
);
DBINDER_LOGI
(
"messageparcel writeChar bufferSize = %{public}d"
,
(
int
)
bufferSize
);
result
=
napiParcel
->
nativeParcel_
->
WriteUint8
(
static_cast
<
uint8_t
>
(
value
));
char
buffer
[
bufferSize
+
1
];
napi_get_value_string_utf8
(
env
,
element
,
buffer
,
bufferSize
+
1
,
&
strLength
);
DBINDER_LOGI
(
"messageparcel writeChar strLength = %{public}d"
,
(
int
)
strLength
);
std
::
string
parcelString
=
buffer
;
std
::
u16string
tmp
=
to_utf16
(
parcelString
);
auto
value
=
reinterpret_cast
<
uint16_t
*>
(
tmp
.
data
());
result
=
napiParcel
->
nativeParcel_
->
WriteUint16
(
*
value
);
if
(
!
result
)
{
if
(
!
result
)
{
napiParcel
->
nativeParcel_
->
RewindWrite
(
pos
);
napiParcel
->
nativeParcel_
->
RewindWrite
(
pos
);
break
;
break
;
...
@@ -1034,13 +1027,9 @@ napi_value NAPI_MessageParcel::JS_readChar(napi_env env, napi_callback_info info
...
@@ -1034,13 +1027,9 @@ napi_value NAPI_MessageParcel::JS_readChar(napi_env env, napi_callback_info info
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
NAPI_ASSERT_BASE
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
,
0
);
NAPI_ASSERT_BASE
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
,
0
);
uint16_t
value
=
napiParcel
->
nativeParcel_
->
ReadUint16
();
uint8_t
value
=
napiParcel
->
nativeParcel_
->
ReadUint8
();
char
ch
[
2
]
=
{
0
};
if
(
sprintf_s
(
ch
,
sizeof
(
ch
)
/
sizeof
(
ch
[
0
]),
"%c"
,
value
)
<
0
)
{
return
nullptr
;
}
napi_value
result
=
nullptr
;
napi_value
result
=
nullptr
;
napi_create_
string_utf8
(
env
,
ch
,
1
,
&
result
);
napi_create_
uint32
(
env
,
static_cast
<
uint32_t
>
(
value
)
,
&
result
);
return
result
;
return
result
;
}
}
...
@@ -1308,55 +1297,48 @@ napi_value NAPI_MessageParcel::JS_readByteArray(napi_env env, napi_callback_info
...
@@ -1308,55 +1297,48 @@ napi_value NAPI_MessageParcel::JS_readByteArray(napi_env env, napi_callback_info
uint32_t
maxBytesLen
=
40960
;
uint32_t
maxBytesLen
=
40960
;
uint32_t
arrayBufferLength
=
napiParcel
->
nativeParcel_
->
ReadUint32
();
uint32_t
arrayBufferLength
=
napiParcel
->
nativeParcel_
->
ReadUint32
();
NAPI_ASSERT
(
env
,
arrayBufferLength
<
maxBytesLen
,
"byte array length too large"
);
NAPI_ASSERT
(
env
,
arrayBufferLength
<
maxBytesLen
,
"byte array length too large"
);
size_t
len
=
(
arrayBufferLength
/
BYTE_SIZE_
32
)
+
((
arrayBufferLength
%
BYTE_SIZE_32
)
==
0
?
0
:
1
);
size_t
len
=
(
arrayBufferLength
/
BYTE_SIZE_
8
)
+
((
arrayBufferLength
%
BYTE_SIZE_8
)
==
0
?
0
:
1
);
DBINDER_LOGI
(
"messageparcel WriteBuffer typedarrayLength = %{public}d"
,
(
int
)(
len
));
DBINDER_LOGI
(
"messageparcel WriteBuffer typedarrayLength = %{public}d"
,
(
int
)(
len
));
uint32_t
arrayLength
=
napiParcel
->
nativeParcel_
->
ReadUint32
();
if
(
argc
>
0
)
{
if
(
argc
>
0
)
{
NAPI_ASSERT
(
env
,
argc
==
1
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
argc
==
1
,
"type mismatch for parameter 1"
);
CHECK_READ_LENGTH
(
env
,
len
,
BYTE_SIZE_
32
,
napiParcel
);
CHECK_READ_LENGTH
(
env
,
len
,
BYTE_SIZE_
8
,
napiParcel
);
napi_value
argv
[
1
]
=
{
0
};
napi_value
argv
[
1
]
=
{
0
};
void
*
data
=
nullptr
;
void
*
data
=
nullptr
;
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
&
data
);
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
&
data
);
bool
isTypedArray
=
false
;
bool
isArray
=
false
;
napi_is_typedarray
(
env
,
argv
[
0
],
&
isTypedArray
);
napi_is_array
(
env
,
argv
[
0
],
&
isArray
);
NAPI_ASSERT
(
env
,
isTypedArray
==
true
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
isArray
==
true
,
"type mismatch for parameter 1"
);
napi_typedarray_type
arrayType
;
size_t
arrayLength
=
0
;
void
*
arrayBufferPtr
=
nullptr
;
napi_value
tmpArrayBuffer
=
nullptr
;
size_t
byteOffset
=
0
;
napi_get_typedarray_info
(
env
,
argv
[
0
],
&
arrayType
,
&
arrayLength
,
&
arrayBufferPtr
,
&
tmpArrayBuffer
,
&
byteOffset
);
NAPI_ASSERT
(
env
,
arrayType
==
napi_int8_array
,
"array type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
arrayLength
==
arrayBufferLength
,
"array size mismatch for length"
);
const
uint8_t
*
arrayAddr
=
napiParcel
->
nativeParcel_
->
ReadUnpadBuffer
(
arrayBufferLength
);
NAPI_ASSERT
(
env
,
arrayAddr
!=
nullptr
,
"buffer is nullptr"
);
errno_t
status
=
memcpy_s
(
arrayBufferPtr
,
arrayBufferLength
,
arrayAddr
,
arrayBufferLength
);
NAPI_ASSERT
(
env
,
status
==
EOK
,
"memcpy_s is failed"
);
for
(
uint32_t
i
=
0
;
i
<
arrayLength
;
i
++
)
{
uint8_t
val
=
napiParcel
->
nativeParcel_
->
ReadUint8
();
napi_value
num
=
nullptr
;
napi_create_uint32
(
env
,
val
,
&
num
);
napi_set_element
(
env
,
argv
[
0
],
i
,
num
);
}
napi_value
napiValue
=
nullptr
;
napi_value
napiValue
=
nullptr
;
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
true
,
&
napiValue
));
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
true
,
&
napiValue
));
return
napiValue
;
return
napiValue
;
}
}
CHECK_READ_LENGTH
(
env
,
len
,
BYTE_SIZE_32
,
napiParcel
);
if
(
arrayLength
<=
0
)
{
napi_value
arrayBuffer
=
nullptr
;
napi_value
result
=
nullptr
;
void
*
arrayBufferPtr
=
nullptr
;
napi_create_array
(
env
,
&
result
);
napi_create_arraybuffer
(
env
,
arrayBufferLength
,
&
arrayBufferPtr
,
&
arrayBuffer
);
return
result
;
napi_value
typedarray
=
nullptr
;
napi_create_typedarray
(
env
,
napi_int8_array
,
arrayBufferLength
,
arrayBuffer
,
0
,
&
typedarray
);
if
(
arrayBufferLength
==
0
)
{
return
typedarray
;
}
}
CHECK_READ_LENGTH
(
env
,
(
size_t
)
arrayLength
,
BYTE_SIZE_8
,
napiParcel
);
napi_value
result
=
nullptr
;
napi_create_array_with_length
(
env
,
(
size_t
)
arrayLength
,
&
result
);
const
uint8_t
*
arrayAddr
=
napiParcel
->
nativeParcel_
->
ReadUnpadBuffer
(
arrayBufferLength
);
for
(
uint32_t
i
=
0
;
i
<
(
uint32_t
)
arrayLength
;
i
++
)
{
NAPI_ASSERT
(
env
,
arrayAddr
!=
nullptr
,
"buffer is nullptr"
);
uint8_t
val
=
napiParcel
->
nativeParcel_
->
ReadUint8
();
errno_t
status
=
memcpy_s
(
arrayBufferPtr
,
arrayBufferLength
,
arrayAddr
,
arrayBufferLength
);
napi_value
num
=
nullptr
;
NAPI_ASSERT
(
env
,
status
==
EOK
,
"memcpy_s is failed"
);
napi_create_int32
(
env
,
val
,
&
num
);
return
typedarray
;
napi_set_element
(
env
,
result
,
i
,
num
);
}
return
result
;
}
}
napi_value
NAPI_MessageParcel
::
JS_readShortArray
(
napi_env
env
,
napi_callback_info
info
)
napi_value
NAPI_MessageParcel
::
JS_readShortArray
(
napi_env
env
,
napi_callback_info
info
)
...
@@ -1676,7 +1658,7 @@ napi_value NAPI_MessageParcel::JS_readCharArray(napi_env env, napi_callback_info
...
@@ -1676,7 +1658,7 @@ napi_value NAPI_MessageParcel::JS_readCharArray(napi_env env, napi_callback_info
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
NAPI_ASSERT
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
);
NAPI_ASSERT
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
);
int32_t
arrayLength
=
napiParcel
->
nativeParcel_
->
ReadI
nt32
();
uint32_t
arrayLength
=
napiParcel
->
nativeParcel_
->
ReadUi
nt32
();
if
(
argc
>
0
)
{
if
(
argc
>
0
)
{
NAPI_ASSERT
(
env
,
argc
==
1
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
argc
==
1
,
"type mismatch for parameter 1"
);
CHECK_READ_LENGTH
(
env
,
(
size_t
)
arrayLength
,
BYTE_SIZE_32
,
napiParcel
);
CHECK_READ_LENGTH
(
env
,
(
size_t
)
arrayLength
,
BYTE_SIZE_32
,
napiParcel
);
...
@@ -1689,13 +1671,9 @@ napi_value NAPI_MessageParcel::JS_readCharArray(napi_env env, napi_callback_info
...
@@ -1689,13 +1671,9 @@ napi_value NAPI_MessageParcel::JS_readCharArray(napi_env env, napi_callback_info
NAPI_ASSERT
(
env
,
isArray
==
true
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
isArray
==
true
,
"type mismatch for parameter 1"
);
for
(
uint32_t
i
=
0
;
i
<
(
uint32_t
)
arrayLength
;
i
++
)
{
for
(
uint32_t
i
=
0
;
i
<
(
uint32_t
)
arrayLength
;
i
++
)
{
uint16_t
val
=
napiParcel
->
nativeParcel_
->
ReadUint16
();
uint8_t
val
=
napiParcel
->
nativeParcel_
->
ReadUint8
();
char
ch
[
2
]
=
{
0
};
if
(
sprintf_s
(
ch
,
sizeof
(
ch
)
/
sizeof
(
ch
[
0
]),
"%c"
,
val
)
<
0
)
{
return
nullptr
;
}
napi_value
num
=
nullptr
;
napi_value
num
=
nullptr
;
napi_create_
string_utf8
(
env
,
ch
,
1
,
&
num
);
napi_create_
uint32
(
env
,
static_cast
<
uint32_t
>
(
val
)
,
&
num
);
napi_set_element
(
env
,
argv
[
0
],
i
,
num
);
napi_set_element
(
env
,
argv
[
0
],
i
,
num
);
}
}
napi_value
napiValue
=
nullptr
;
napi_value
napiValue
=
nullptr
;
...
@@ -1713,13 +1691,9 @@ napi_value NAPI_MessageParcel::JS_readCharArray(napi_env env, napi_callback_info
...
@@ -1713,13 +1691,9 @@ napi_value NAPI_MessageParcel::JS_readCharArray(napi_env env, napi_callback_info
napi_create_array_with_length
(
env
,
(
size_t
)
arrayLength
,
&
result
);
napi_create_array_with_length
(
env
,
(
size_t
)
arrayLength
,
&
result
);
for
(
uint32_t
i
=
0
;
i
<
(
uint32_t
)
arrayLength
;
i
++
)
{
for
(
uint32_t
i
=
0
;
i
<
(
uint32_t
)
arrayLength
;
i
++
)
{
uint16_t
val
=
napiParcel
->
nativeParcel_
->
ReadUint16
();
uint8_t
val
=
napiParcel
->
nativeParcel_
->
ReadUint8
();
char
ch
[
2
]
=
{
0
};
if
(
sprintf_s
(
ch
,
sizeof
(
ch
)
/
sizeof
(
ch
[
0
]),
"%c"
,
val
)
<
0
)
{
return
nullptr
;
}
napi_value
num
=
nullptr
;
napi_value
num
=
nullptr
;
napi_create_
string_utf8
(
env
,
ch
,
1
,
&
num
);
napi_create_
uint32
(
env
,
static_cast
<
uint32_t
>
(
val
)
,
&
num
);
napi_set_element
(
env
,
result
,
i
,
num
);
napi_set_element
(
env
,
result
,
i
,
num
);
}
}
return
result
;
return
result
;
...
@@ -2190,18 +2164,27 @@ napi_value NAPI_MessageParcel::JS_WriteRawData(napi_env env, napi_callback_info
...
@@ -2190,18 +2164,27 @@ napi_value NAPI_MessageParcel::JS_WriteRawData(napi_env env, napi_callback_info
napi_value
thisVar
=
nullptr
;
napi_value
thisVar
=
nullptr
;
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
NAPI_ASSERT
(
env
,
argc
==
2
,
"requires 2 parameter"
);
NAPI_ASSERT
(
env
,
argc
==
2
,
"requires 2 parameter"
);
bool
isTypedArray
=
false
;
bool
isArray
=
false
;
napi_is_typedarray
(
env
,
argv
[
0
],
&
isTypedArray
);
napi_is_array
(
env
,
argv
[
0
],
&
isArray
);
NAPI_ASSERT
(
env
,
isTypedArray
==
true
,
"type mismatch for parameter 1"
);
NAPI_ASSERT
(
env
,
isArray
==
true
,
"type mismatch for parameter 1"
);
napi_typedarray_type
typedarrayType
=
napi_uint8_array
;
size_t
typedarrayLength
=
0
;
std
::
vector
<
int32_t
>
array
;
void
*
typedarrayBufferPtr
=
nullptr
;
uint32_t
arrayLength
=
0
;
napi_value
tmpArrayBuffer
=
nullptr
;
napi_get_array_length
(
env
,
argv
[
0
],
&
arrayLength
);
size_t
byteOffset
=
0
;
napi_get_typedarray_info
(
env
,
argv
[
0
],
&
typedarrayType
,
&
typedarrayLength
,
&
typedarrayBufferPtr
,
for
(
size_t
i
=
0
;
i
<
arrayLength
;
i
++
)
{
&
tmpArrayBuffer
,
&
byteOffset
);
bool
hasElement
=
false
;
NAPI_ASSERT
(
env
,
typedarrayType
==
napi_int8_array
,
"array type mismatch for parameter 1"
);
napi_has_element
(
env
,
argv
[
0
],
i
,
&
hasElement
);
// get Array size
NAPI_ASSERT
(
env
,
hasElement
==
true
,
"parameter check error"
);
napi_value
element
=
nullptr
;
napi_get_element
(
env
,
argv
[
0
],
i
,
&
element
);
int32_t
value
=
0
;
napi_get_value_int32
(
env
,
element
,
&
value
);
array
.
push_back
(
value
);
}
napi_valuetype
valueType
=
napi_null
;
napi_valuetype
valueType
=
napi_null
;
napi_typeof
(
env
,
argv
[
1
],
&
valueType
);
napi_typeof
(
env
,
argv
[
1
],
&
valueType
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 2"
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 2"
);
...
@@ -2210,7 +2193,7 @@ napi_value NAPI_MessageParcel::JS_WriteRawData(napi_env env, napi_callback_info
...
@@ -2210,7 +2193,7 @@ napi_value NAPI_MessageParcel::JS_WriteRawData(napi_env env, napi_callback_info
NAPI_MessageParcel
*
napiParcel
=
nullptr
;
NAPI_MessageParcel
*
napiParcel
=
nullptr
;
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
NAPI_ASSERT_BASE
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
,
0
);
NAPI_ASSERT_BASE
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
,
0
);
bool
result
=
napiParcel
->
nativeParcel_
->
WriteRawData
(
typedarrayBufferPtr
,
size
);
bool
result
=
napiParcel
->
nativeParcel_
->
WriteRawData
(
array
.
data
()
,
size
);
napi_value
napiValue
=
nullptr
;
napi_value
napiValue
=
nullptr
;
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
napiValue
));
return
napiValue
;
return
napiValue
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录