Skip to content

Proposal for OpenHarmony Adaptation of msgpack-javascript. Closes #272 #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions OpenHarmony/ohos_msgpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
10 changes: 10 additions & 0 deletions OpenHarmony/ohos_msgpack/AppScope/app.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"app": {
"bundleName": "cn.openharmony.msgpack",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.2-rc.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "ohos_msgpack"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions OpenHarmony/ohos_msgpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 1.0.2-rc.0
- Fix Compilation Warnings

## 1.0.1
- 发布正式版本1.0.1

## 1.0.1-rc.0
- 现以基于msgpack2.8 版本进行升级,升级成为msgpack3.0版本,可以实现更为复杂的编码。

## 1.0.0-rc.0
- 基于msgpack 原库3.0.0-beta2 版本进行适配,使其可以运行在 OpenHarmony,并沿用其现有用法和特性。
- 提供了一种紧凑高效的二进制序列化格式。
5 changes: 5 additions & 0 deletions OpenHarmony/ohos_msgpack/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Copyright 2019 The MessagePack Community.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 changes: 21 additions & 0 deletions OpenHarmony/ohos_msgpack/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
OPEN SOURCE SOFTWARE NOTICE

Please note we provide an open source software notice for the third party open source software along with this software and/or this software component (in the following just “this SOFTWARE”). The open source software licenses are granted by the respective right holders.

Warranty Disclaimer
THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.

Copyright Notice and License Texts

----------------------------------------------------------------------
Software: msgpack-javascript v3.0.0-beta2
Copyright notice:
Copyright (c) 2019 The MessagePack Community.
License: ISC License

Copyright 2019 The MessagePack Community.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

47 changes: 47 additions & 0 deletions OpenHarmony/ohos_msgpack/OAT.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<oatconfig>
<filefilterlist>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for resources files policies">
<filteritem type="filename" name="*.png" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="*.gif" desc="README的动态图展示"/>
<filteritem type="filename" name="screenshot/msgpack.gif" desc="README的动态图展示"/>
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies">
<filteritem type="filename" name="hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="LICENSE" desc="版权文件,不添加版权头"/>
<filteritem type="filename" name="NOTICE" desc="NOTICE文件,不添加版权头"/>
<filteritem type="filename" name="TEST" desc="接口测试声明文件,不添加版权头"/>
<filteritem type="filename" name="hvigorw" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="hvigorw.bat" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="hvigor-wrapper.js" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filepath" name="entry/src/main/ohosTest/ets/test/test/**/.*" desc="源库测试用例代码,不修改版权头,以防有修改版权风险"/>
<filteritem type="filename" name="entry/src/main/ohosTest/ets/test/test/msgpacksuit/msgpack-test-suite.json" desc="json文件,不添加版权头"/>
<filteritem type="filename" name="entry/src/main/ets/entryability/EntryAbility.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filepath" name="library/.*" desc="源库代码,不修改版权头,以防有修改版权风险"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
<filteritem type="filename" name="hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="entry/src/main/ets/entryability/EntryAbility.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="LICENSE" desc="版权文件,不添加版权头"/>
<filteritem type="filename" name="NOTICE" desc="NOTICE文件,不添加版权头"/>
<filteritem type="filename" name="TEST" desc="接口测试声明文件,不添加版权头"/>
<filteritem type="filename" name="hvigorw" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="hvigorw.bat" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filename" name="hvigor-wrapper.js" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filepath" name="entry/src/main/ohosTest/ets/test/test/**/.*" desc="源库测试用例代码,不修改版权头,以防有修改版权风险"/>
<filteritem type="filename" name="entry/src/main/ohosTest/ets/test/test/msgpacksuit/msgpack-test-suite.json" desc="json文件,不添加版权头"/>
<filteritem type="filepath" name="library/.*" desc="源库代码,不修改版权头,以防有修改版权风险"/>
</filefilter>
</filefilterlist>
<policylist>
<policy name="projectPolicy" desc="匹配原库协议,符合开源要求">
<policyitem type="license" name="ISC" path=".*" group="defaultGroup" filefilter="defaultPolicyFilter" desc="标准ISC协议内容,符合开源要求"/>
</policy>
</policylist>
</oatconfig>


</configuration>
11 changes: 11 additions & 0 deletions OpenHarmony/ohos_msgpack/README.OpenSource
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"Name": "msgpack-javascript",
"License": "ISC License",
"License File": " LICENSE ",
"Version Number": "v3.0.0-beta2",
"Owner": "xiafeng@huawei.com",
"Upstream URL": "https://github.com/msgpack/msgpack-javascript",
"Description": "MessagePack is an extremely efficient object serialization library. It's like JSON, but very fast and small."
}
]
118 changes: 118 additions & 0 deletions OpenHarmony/ohos_msgpack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# msgpack-javascript

## Introduction
> MessagePack is a library that provides efficient object serialization. It is like JSON but offers higher efficiency and smaller data size.
> Currently, MessagePack 3.0 can be used to implement complex int64 encoding.

## How to Install
```shell
ohpm install @ohos/msgpack
```
For details, see [Installing an OpenHarmony HAR](https://gitcode.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.en.md).

## How to Use

### Encoding and Decoding
```javascript
import { encode,decode } from "@ohos/msgpack";

// Encode.
let encoded:Uint8Array = encode({ foo: "bar" });
// Decode.
let decodedObject = decode(encoded);
```

### Using Encoder and Decoder
```javascript
import { Encoder,Decoder } from "@ohos/msgpack";
// Reuse the encoder instance.
let encoder = new Encoder()
// Reuse the decoder instance.
let decoder = new Decoder()
// Encode.
let encoded:Uint8Array = encoder.encode({ foo: "bar" });
// Decode.
let decodedObject = decoder.decode(encoded);
// Decode a complex int64 object.
let data: ESObject =
{
ints: [0, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
nums: [Number.NaN, Math.PI, Math.E, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
bigints: [BigInt(0), BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1), BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1)],
};
// Encode the minimum int64 value.
return BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1);
// Encode and decode a common int64 value.
return BigInt(0);
// Encode the maximum int64 value.
return BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1);
```

### Encoding and Decoding an Array Object

```javascript
import { encode,decodeMulti } from "@ohos/msgpack";

let items = [
"foo",
10,
{
name: "bar",
},
[1, 2, 3],
];
// Encode the item array.
let encodedItems = items.map((item) => encode(item));
// Create a blank buffer for storing streams.
let encoded = new Uint8Array(encodedItems.reduce((p, c) => p + c.byteLength, 0));
let offset = 0;
// Store the encoded items in the buffer.
for (let encodedItem of encodedItems) {
encoded.set(encodedItem, offset);
offset += encodedItem.byteLength;
}
let result: Array<unknown> = [];
// Store the decoded items in the result array.
for (let item of decodeMulti(encoded)) {
result.push(item);
}
// The value of result is the same as that of items.
expect(result).assertDeepEquals(items);
```

## Directory Structure
````
|---- msgpackJavaScript
| |---- entry # Sample code
| |---- Index.ets # External APIs
|---- EncodeDecodePage.ets # Common encoding and decoding
|---- Encoding64DemoFour.ets # Decoding complex int64 objects
|---- Encoding64DemoOne.ets # Encoding the minimum int64 value
|---- Encoding64DemoThree.ets # Encoding and decoding the common int64 value
|---- Encoding64DemoTwo.ets # Encoding the maximum int64 value
|---- EncodeDecodeConstructorPage.ets # Using encoder and decoder
|---- MultiDecodePage.ets # Decoding complex objects
| |---- library # Library code
| |---- README_EN.MD # Brief introduction of the MessagePack library
````

## About obfuscation
- Code obfuscation, please see[Code Obfuscation](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/source-obfuscation.md)
- If you want the msgpack-javascript library not to be obfuscated during code obfuscation, you need to add corresponding exclusion rules in the obfuscation rule configuration file obfuscation-rules.txt:
```
-keep
./oh_modules/@ohos/msgpack
```

## Constraints

MessagePack has been verified only in the following version:

- DevEco Studio: 5.0.3.132, SDK: API12 (5.0.0.19)

## How to Contribute

If you find any problem during the use, submit an [Issue](https://gitcode.com/openharmony-tpc/openharmony_tpc_samples/issues) or a [PR](https://gitcode.com/openharmony-tpc/openharmony_tpc_samples) to us.

## License
This project is licensed under [ISC License](https://gitcode.com/openharmony-tpc/openharmony_tpc_samples/blob/master/ohos_msgpack/LICENSE).
119 changes: 119 additions & 0 deletions OpenHarmony/ohos_msgpack/README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# msgpack-javascript

## 简介
> MessagePack是一个非常高效的对象序列化库。它像JSON,但速度很快,而且很小。
> 现在MessagePack已经适配了3.0版本,可用于实现int64的复杂性编码。

## 下载安装
```shell
ohpm install @ohos/msgpack
```
OpenHarmony ohpm 环境配置等更多内容,请参考[如何安装 OpenHarmony ohpm 包](https://gitcode.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md)

## 使用说明

### 编解码
```javascript
import { encode,decode } from "@ohos/msgpack";

// 编码
let encoded:Uint8Array = encode({ foo: "bar" });
// 解码
let decodedObject = decode(encoded);
```

### 构造器编解码
```javascript
import { Encoder,Decoder } from "@ohos/msgpack";
// 编码可复用构造器
let encoder = new Encoder()
// 解码可复用构造器
let decoder = new Decoder()
// 编码
let encoded:Uint8Array = encoder.encode({ foo: "bar" });
// 解码
let decodedObject = decoder.decode(encoded);
// int64复杂对象解码
let data: ESObject =
{
ints: [0, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
nums: [Number.NaN, Math.PI, Math.E, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
bigints: [BigInt(0), BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1), BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1)],
};
// int64编码最小值
return BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1);
// int64普通编解码
return BigInt(0);
// int64编码最大值
return BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1);
```

### 数组对象编解码

```javascript
import { encode,decodeMulti } from "@ohos/msgpack";

let items = [
"foo",
10,
{
name: "bar",
},
[1, 2, 3],
];
// 将数组编码
let encodedItems = items.map((item) => encode(item));
// 创建空白缓存区用来后续存数据流
let encoded = new Uint8Array(encodedItems.reduce((p, c) => p + c.byteLength, 0));
let offset = 0;
// 空白缓存区存入数据流
for (let encodedItem of encodedItems) {
encoded.set(encodedItem, offset);
offset += encodedItem.byteLength;
}
let result: Array<unknown> = [];
// 解码后将数据存入result数组中
for (let item of decodeMulti(encoded)) {
result.push(item);
}
// result与items一致
expect(result).assertDeepEquals(items);
```

## 目录结构
````
|---- msgpackJavaScript
| |---- entry # 示例代码文件夹
| |---- Index.ets # 对外接口介绍
|---- EncodeDecodePage.ets # 普通编解码
|---- Encoding64DemoFour.ets # int64复杂对象解码
|---- Encoding64DemoOne.ets # int64编码最小值
|---- Encoding64DemoThree.ets # int64普通编解码
|---- Encoding64DemoTwo.ets # int64编码最大值
|---- EncodeDecodeConstructorPage.ets # 通过构造器编解码
|---- MultiDecodePage.ets # 复杂对象解码
| |---- library # 库代码文件夹
| |---- README.MD # 安装使用方法
````

## 关于混淆
- 代码混淆,请查看[代码混淆简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/source-obfuscation.md)
- 如果希望msgpack-javascript库在代码混淆过程中不会被混淆,需要在混淆规则配置文件obfuscation-rules.txt中添加相应的排除规则:
```
-keep
./oh_modules/@ohos/msgpack
```

## 约束与限制

在下述版本验证通过:

- DevEco Studio: 5.0.3.132, SDK: API12 (5.0.0.19)
- DevEco Studio: NEXT Beta1-5.0.3.806, SDK: API12 Release (5.0.0.66)

## 贡献代码

使用过程中发现任何问题都可以提 [Issue](https://gitcode.com/openharmony-tpc/openharmony_tpc_samples/issues) 给组件,当然,也非常欢迎发 [PR](https://gitcode.com/openharmony-tpc/openharmony_tpc_samples) 共建。

## 开源协议
本项目基于 [ISC License](https://gitcode.com/openharmony-tpc/openharmony_tpc_samples/blob/master/ohos_msgpack/LICENSE) ,请自由地享受和参与开源。
Loading