小编hal*_*nhg的帖子

如何使用msgpack-c正确解压缩和提取数据?

我目前正在尝试在用C编写的项目中使用msgpack.我正在使用msgpack来序列化结构的内容,然后通过网络发送,然后反序列化为相应的结构.另一边.

我正在尝试做的简明版本:

#include <stdio.h>
#include <msgpack.h>
#include <stdbool.h>

typedef someStruct{
uint32_t a;
uint32_t b;
float    c;
} someStruct;

int main (void){
    someStruct data;
    /* ... Fill 'data' with some data for test purposes ...*/

    msgpack_sbuffer* buff = msgpack_sbuffer_new();
    msgpack_packer* pck = msgpack_packer_new(buff, msgpack_sbuffer_write);        

    someStruct* structs = malloc(sizeof(someStruct) * 10);

    /* ... Fill 'structs' with members containing test data ... */
    // Serialize
    msgpack_pack_array (pck, 10);

    int i;
    for(i = 0 ; i < 10 ; i++){
    msgpack_pack_array (pck, 3);
    msgpack_pack_uint32 …
Run Code Online (Sandbox Code Playgroud)

c serialization deserialization msgpack

7
推荐指数
1
解决办法
7505
查看次数

标签 统计

c ×1

deserialization ×1

msgpack ×1

serialization ×1