2018-12-20 17:33:31 +08:00
|
|
|
|
## wbuffer\_t
|
|
|
|
|
### 概述
|
2018-12-27 15:28:20 +08:00
|
|
|
|
Write Buffer。用于数据打包。
|
|
|
|
|
|
|
|
|
|
示例:
|
|
|
|
|
|
|
|
|
|
```c
|
|
|
|
|
uint8_t buff[128];
|
|
|
|
|
wbuffer_t wbuffer;
|
|
|
|
|
rbuffer_t rbuffer;
|
|
|
|
|
const char* str = NULL;
|
|
|
|
|
wbuffer_init(&wbuffer, buff, sizeof(buff));
|
|
|
|
|
|
|
|
|
|
wbuffer_write_string(&wbuffer, "hello awtk");
|
|
|
|
|
|
|
|
|
|
rbuffer_init(&rbuffer, wbuffer.data, wbuffer.cursor);
|
|
|
|
|
rbuffer_read_string(&rbuffer, &str);
|
|
|
|
|
```
|
2018-12-27 15:50:18 +08:00
|
|
|
|
|
2018-12-27 15:28:20 +08:00
|
|
|
|
```c
|
|
|
|
|
wbuffer_t wbuffer;
|
|
|
|
|
wbuffer_init_extendable(&wbuffer);
|
|
|
|
|
|
|
|
|
|
wbuffer_write_string(&wbuffer, "hello awtk");
|
|
|
|
|
|
|
|
|
|
wbuffer_deinit(&wbuffer);
|
|
|
|
|
```
|
|
|
|
|
> 如果初始化为extendable,则最后需要调用wbuffer\_deinit释放资源。
|
|
|
|
|
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
2019-01-15 14:34:05 +08:00
|
|
|
|
|
|
|
|
|
----------------------------------
|
2018-12-20 17:33:31 +08:00
|
|
|
|
### 函数
|
|
|
|
|
<p id="wbuffer_t_methods">
|
|
|
|
|
|
|
|
|
|
| 函数名称 | 说明 |
|
|
|
|
|
| -------- | ------------ |
|
2018-12-27 15:28:20 +08:00
|
|
|
|
| <a href="#wbuffer_t_wbuffer_deinit">wbuffer\_deinit</a> | 释放资源。 |
|
2018-12-21 12:11:40 +08:00
|
|
|
|
| <a href="#wbuffer_t_wbuffer_init">wbuffer\_init</a> | 初始wbuffer对象。 |
|
2018-12-27 15:28:20 +08:00
|
|
|
|
| <a href="#wbuffer_t_wbuffer_init_extendable">wbuffer\_init\_extendable</a> | 初始wbuffer对象,自动扩展buffer,使用完成后需要调用wbuffer\_deinit释放资源。 |
|
2018-12-21 12:11:40 +08:00
|
|
|
|
| <a href="#wbuffer_t_wbuffer_skip">wbuffer\_skip</a> | 跳过指定的长度。 |
|
|
|
|
|
| <a href="#wbuffer_t_wbuffer_write_binary">wbuffer\_write\_binary</a> | 写入指定长度的二进制数据。 |
|
|
|
|
|
| <a href="#wbuffer_t_wbuffer_write_float">wbuffer\_write\_float</a> | 写入float数据。 |
|
|
|
|
|
| <a href="#wbuffer_t_wbuffer_write_string">wbuffer\_write\_string</a> | 写入字符串。 |
|
|
|
|
|
| <a href="#wbuffer_t_wbuffer_write_uint16">wbuffer\_write\_uint16</a> | 写入uint16数据。 |
|
|
|
|
|
| <a href="#wbuffer_t_wbuffer_write_uint32">wbuffer\_write\_uint32</a> | 写入uint32数据。 |
|
|
|
|
|
| <a href="#wbuffer_t_wbuffer_write_uint8">wbuffer\_write\_uint8</a> | 写入uint8数据。 |
|
2018-12-20 17:33:31 +08:00
|
|
|
|
### 属性
|
|
|
|
|
<p id="wbuffer_t_properties">
|
|
|
|
|
|
2019-01-17 15:56:15 +08:00
|
|
|
|
| 属性名称 | 类型 | 说明 |
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| -------- | ----- | ------------ |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
| <a href="#wbuffer_t_capacity">capacity</a> | uint32\_t | 缓存区最大容量。 |
|
|
|
|
|
| <a href="#wbuffer_t_cursor">cursor</a> | uint32\_t | 当前写入位置。 |
|
|
|
|
|
| <a href="#wbuffer_t_data">data</a> | uint8\_t* | 缓存区。 |
|
2018-12-27 15:28:20 +08:00
|
|
|
|
| <a href="#wbuffer_t_extendable">extendable</a> | bool\_t | 容量是否可扩展。 |
|
|
|
|
|
#### wbuffer\_deinit 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
|
|
|
|
> <p id="wbuffer_t_wbuffer_deinit"> 释放资源。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ret_t wbuffer_deinit (wbuffer_t* wbuffer);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
2018-12-20 17:33:31 +08:00
|
|
|
|
#### wbuffer\_init 函数
|
2018-12-21 18:29:29 +08:00
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
|
|
|
|
> <p id="wbuffer_t_wbuffer_init"> 初始wbuffer对象。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
wbuffer_t* wbuffer_init (wbuffer_t* wbuffer, uint8_t* data, uint16_t capacity);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | wbuffer\_t* | wbuffer对象本身。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
|
|
|
|
| data | uint8\_t* | 缓冲区。 |
|
|
|
|
|
| capacity | uint16\_t | 缓冲区的容量。 |
|
2018-12-27 15:28:20 +08:00
|
|
|
|
#### wbuffer\_init\_extendable 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
|
|
|
|
> <p id="wbuffer_t_wbuffer_init_extendable"> 初始wbuffer对象,自动扩展buffer,使用完成后需要调用wbuffer\_deinit释放资源。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
wbuffer_t* wbuffer_init_extendable (wbuffer_t* wbuffer);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | wbuffer\_t* | wbuffer对象本身。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
#### wbuffer\_skip 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2018-12-21 18:29:29 +08:00
|
|
|
|
> <p id="wbuffer_t_wbuffer_skip"> 跳过指定的长度。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
2018-12-27 15:28:20 +08:00
|
|
|
|
ret_t wbuffer_skip (wbuffer_t* wbuffer, int32_t delta);
|
2018-12-21 11:39:05 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
2018-12-27 15:28:20 +08:00
|
|
|
|
| delta | int32\_t | 跳过的偏移量,正数往前负数往回跳。 |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
#### wbuffer\_write\_binary 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2018-12-21 18:29:29 +08:00
|
|
|
|
> <p id="wbuffer_t_wbuffer_write_binary"> 写入指定长度的二进制数据。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ret_t wbuffer_write_binary (wbuffer_t* wbuffer, void* data, uint32_t size);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
|
|
|
|
| data | void* | 写入的数据。 |
|
|
|
|
|
| size | uint32\_t | 写入的数据长度。 |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
#### wbuffer\_write\_float 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2018-12-21 18:29:29 +08:00
|
|
|
|
> <p id="wbuffer_t_wbuffer_write_float"> 写入float数据。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ret_t wbuffer_write_float (wbuffer_t* wbuffer, float_t value);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
|
|
|
|
| value | float\_t | 写入的数据。 |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
#### wbuffer\_write\_string 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2018-12-21 18:29:29 +08:00
|
|
|
|
> <p id="wbuffer_t_wbuffer_write_string"> 写入字符串。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ret_t wbuffer_write_string (wbuffer_t* wbuffer, char* data);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
|
|
|
|
| data | char* | 写入的字符串。 |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
#### wbuffer\_write\_uint16 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2018-12-21 18:29:29 +08:00
|
|
|
|
> <p id="wbuffer_t_wbuffer_write_uint16"> 写入uint16数据。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ret_t wbuffer_write_uint16 (wbuffer_t* wbuffer, uint16_t value);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
|
|
|
|
| value | uint16\_t | 写入的数据。 |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
#### wbuffer\_write\_uint32 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2018-12-21 18:29:29 +08:00
|
|
|
|
> <p id="wbuffer_t_wbuffer_write_uint32"> 写入uint32数据。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ret_t wbuffer_write_uint32 (wbuffer_t* wbuffer, uint32_t value);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
|
|
|
|
| value | uint32\_t | 写入的数据。 |
|
2018-12-21 18:29:29 +08:00
|
|
|
|
#### wbuffer\_write\_uint8 函数
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2018-12-21 18:29:29 +08:00
|
|
|
|
> <p id="wbuffer_t_wbuffer_write_uint8"> 写入uint8数据。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 11:39:05 +08:00
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ret_t wbuffer_write_uint8 (wbuffer_t* wbuffer, uint8_t value);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
2018-12-20 17:33:31 +08:00
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| wbuffer | wbuffer\_t* | wbuffer对象。 |
|
|
|
|
|
| value | uint8\_t | 写入的数据。 |
|
|
|
|
|
#### capacity 属性
|
|
|
|
|
-----------------------
|
2018-12-21 11:39:05 +08:00
|
|
|
|
> <p id="wbuffer_t_capacity"> 缓存区最大容量。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 类型:uint32\_t
|
|
|
|
|
|
|
|
|
|
| 特性 | 是否支持 |
|
|
|
|
|
| -------- | ----- |
|
|
|
|
|
| 可直接读取 | 是 |
|
|
|
|
|
| 可直接修改 | 否 |
|
|
|
|
|
#### cursor 属性
|
|
|
|
|
-----------------------
|
2018-12-21 11:39:05 +08:00
|
|
|
|
> <p id="wbuffer_t_cursor"> 当前写入位置。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 类型:uint32\_t
|
|
|
|
|
|
|
|
|
|
| 特性 | 是否支持 |
|
|
|
|
|
| -------- | ----- |
|
|
|
|
|
| 可直接读取 | 是 |
|
|
|
|
|
| 可直接修改 | 否 |
|
|
|
|
|
#### data 属性
|
|
|
|
|
-----------------------
|
2018-12-21 11:39:05 +08:00
|
|
|
|
> <p id="wbuffer_t_data"> 缓存区。
|
2018-12-20 17:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 类型:uint8\_t*
|
|
|
|
|
|
|
|
|
|
| 特性 | 是否支持 |
|
|
|
|
|
| -------- | ----- |
|
|
|
|
|
| 可直接读取 | 是 |
|
|
|
|
|
| 可直接修改 | 否 |
|
2018-12-27 15:28:20 +08:00
|
|
|
|
#### extendable 属性
|
|
|
|
|
-----------------------
|
|
|
|
|
> <p id="wbuffer_t_extendable"> 容量是否可扩展。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 类型:bool\_t
|
|
|
|
|
|
|
|
|
|
| 特性 | 是否支持 |
|
|
|
|
|
| -------- | ----- |
|
|
|
|
|
| 可直接读取 | 是 |
|
|
|
|
|
| 可直接修改 | 否 |
|