根据 protobuf 数据,提供不同格式的序列化
介绍
protobuf-format-cj 可以根据 protobuf 数据,提供不同格式的序列化。
特性
- 🚀 支持protobuf数据序列化成json/xml/html/chouchdb格式
.
├── doc
├── src
└── test
│ ├── DOC
│ ├── HLT
│ └── LLT
├── LICENSE.txt
├── cjpm.toml
├── README.md
└── README.OpenSource
doc文档目录,用于存API接口文档src是库源码目录test存放 HLT 测试用例、LLT 自测用例、和文档示例用例
接口说明
主要类和函数接口说明详见 API
使用说明
编译(win/linux)
需要依赖 protobuf4cj, 可在 https://gitcode.com/Cangjie-TPC/protobuf4cj.git 处编译获取 将构建完成的的 protobuf 文件夹复制到项目根目录下面
cjpm build
功能示例
json序列化
示例代码如下:
需要与protobuf数据类文件 test/LLT/proto/route_guide.pb.cj 一起编译执行
import std.unittest.*
import std.unittest.testmacro.*
import protobufFormat.*
import std.io.*
@Test
public class Example01 {
@TestCase
public func Example01Test(): Unit {
var str0 = ##"{"latitude":1,"longitude":10}"##
var a = Point()
a.longitude = 10
a.latitude = 1
let json = JsonFormat();
let out = ByteBuffer();
json.print(a, out);
out.flush()
let result = String.fromUtf8(out.bytes());
@Assert(str0, result)
}
}
执行结果如下:
[ PASSED ] CASE: Example01Test
约束与限制
在下述版本验证通过:
Cangjie Version: 1.0.0
开源协议
本项目基于 BSD 3-Clause "New" or "Revised" License ,请自由的享受和参与开源。
参与贡献
欢迎给我们提交PR,欢迎给我们提交Issue,欢迎参与任何形式的贡献。