blob blobmsg blobmsg_json使用

Blob :二进制大对象

Blobmsg :二进制对象网络序列化。

blobmsg_json   用于json对象的序列化

参考链接:https://www.cnblogs.com/embedded-linux/p/6792359.html

一 : blob 的使用  (熟悉使用blob的各种api)

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#include <getopt.h>
#include <sys/signal.h>
#include "libubox/uloop.h"
#include "libubox/ustream.h"
#include "libubox/utils.h"
#include "libubus.h"
#include "json-c/json.h"
#include "libubox/blob.h"
#include "libubox/blobmsg.h"
#include "libubox/blobmsg_json.h"
#include "libubox/ulog.h"
#include "libubox/runqueue.h"
#include <libubox/list.h>
#include <libubox/uloop.h>
#include <libubox/ustream.h>
#include "termios.h"
  int main()
{

static struct blob_buf b;
struct blob_attr *attr1,*attr2;
char * str,*str1;
void *ptr;
struct blob_attr * pos;
int rem=0;
blob_buf_init(&b, 0);

//设置blob数据
attr1=blob_put_string(&b, 1, "hello");

attr2=blob_put_u8(&b, 2, 100);

//获取blob数据
str=blob_get_string(attr1);
int a1=blob_get_u8(attr2);

//打印数据

printf("str=%s\n",str);    
printf("a1=%d\n",a1);

//输出有效数据地址  和 id
ptr=blob_data(attr1);   // blob_data
printf("ptr=%p\n",ptr);   
printf("id =%d",blob_id(attr1));  //blob_id

printf(" 有效存储空间大小  blob_len =%d\n",blob_len(attr1));       // blob_len 
printf("完全存储空间大小  blob_raw_len =%d\n",blob_raw_len(attr1));   // blob_raw_len
printf("blob属性填补后空间存储大小  blob_pad_len =%d\n",blob_raw_len(attr1)); //blob_raw_len


rem=12;
__blob_for_each_attr(pos,attr1,rem)  //遍历
{
  str1=blob_get_string(pos);
  printf("str1 =%s\n",str1);
}
return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值