自述文件

用于 BSON 格式转换的库

构建库

./configure
make

安装库

sudo make install

构建 Lua 封装器

安装依赖

sudo apt-get install lua5.2 liblua5.2 liblua5.2-dev

构建库

./configure --with-lua-wrapper=yes
make

使用 Lua 库

bson = require("bson4lua");

bsonBytes = bson.to_bytes({
	doubleValue = {
		type = 0x01, --Double type
		value = 3.141592653589793
	},
	intValue = {
		type = 0x10, --Int32 Type
		value = 360
	},
	stringValue = {
		type = 0x02, --String type
		value = "A string of characters"
	}
});

print(bsonBytes:byte(1, string.len(bsonBytes)));

bsonTable = bson.to_table(string.char(0x05, 0x00, 0x00, 0x00, 0x00)); --Empty BSON document

print("Table: ");
for k, v in pairs(bsonTable) do
    print(k, v);
end

苹果平台

iOS、MacOS、tvOS 和 watchOS 平台有 CocoaPod。添加到您的 podfile 文件中

pod 'BiSON'

安卓平台

Android 平台有 jCenter 工件。将以下内容添加到您的 build.gradle 文件中

dependencies {
    api 'com.smartdevicelink:bson_java_port:1.2.5'
}

构建并运行示例程序

cd examples
gcc -o sample sample.c -lbson
./sample

构建并运行单元测试

运行单元测试需要安装带有 pkg-config 文件 (.pc) 的 check 框架。在 Ubuntu 上,请通过运行以下命令安装它

sudo apt-get install check

安装框架后,使用 --with-tests 选项调用 configure,构建库,然后运行 make check

./configure --with-tests
make
make check