記錄libubox裡面blobmsg使用範例
更新記錄
item | note |
---|---|
20160812 | 第一版 |
目錄
BLOB
- 二進位大型物件(英语:binary large object ,或英语:basic large object,縮寫為Blob、BLOB、BLOb)
BlobMsg
blobmsg裡面的是是由許多組(name+data)
所以name是唯一的
若設定相同的iname,此時還是以第一次設定為主
1 | blobmsg_add_string(buf, "message", "Hello, world!"); |
圖片出處:BLOB二进制对象
example
example
解析blob資料
1 | static const struct blobmsg_policy pol[] = { |
- 建立blob資料
1 | static void |
- 測試
1 | gk350a :[~]# ./blobmsg-example |
- struct blob
- blobmsg_buf_init(struct blob_buf *buf)
- blob_buf_init(buf, BLOBMSG_TYPE_TABLE)
1 | buf->grow = blob_buffer_grow |
- blob_buffer_grow(struct blob_buf *buf, int minlen)
- 是realloc
1 | new = realloc(buf->buf, buf->buflen + delta); |
- blob_add(struct blob_buf buf, struct blob_attr pos, int id, int payload)
1 | blob_buf_grow(buf, required) // buf->grow(buf, required) |
blobmsg_add_string
blobmsg_add_string(struct blob_buf buf, const char name, const char *string)
- blobmsg_add_field(buf, BLOBMSG_TYPE_STRING, name, string, strlen(string) + 1);
1 | attr = blobmsg_new(buf, type, name, len, &data_dest); // struct blob_attr *attr; |
blobmsg_open_table
blobmsg_open_table(struct blob_buf buf, const char name)
- blobmsg_open_nested(buf, name, false);
1 | struct blob_attr *head; |
blobmsg_add_u32
blobmsg_add_u32(struct blob_buf buf, const char name, uint32_t val)
1 | val = cpu_to_be32(val); |
blobmsg_parse
int blobmsg_parse(const struct blobmsg_policy policy, int policy_len,
struct blob_attr **tb, void data, unsigned int len)